The Battle for Wesnoth  1.19.7+dev
chatbox.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "gui/widgets/chatbox.hpp"
18 
20 #include "gui/widgets/button.hpp"
21 #include "gui/widgets/image.hpp"
22 #include "gui/widgets/listbox.hpp"
25 #include "gui/widgets/text_box.hpp"
26 #include "gui/widgets/window.hpp"
27 
28 #include "font/pango/escape.hpp"
29 #include "formatter.hpp"
30 #include "formula/string_utils.hpp"
32 #include "gettext.hpp"
33 #include "log.hpp"
36 #include "serialization/markup.hpp"
37 #include "wml_exception.hpp"
38 
39 static lg::log_domain log_lobby("lobby");
40 #define DBG_LB LOG_STREAM(debug, log_lobby)
41 #define LOG_LB LOG_STREAM(info, log_lobby)
42 #define ERR_LB LOG_STREAM(err, log_lobby)
43 
44 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
45 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
46 
47 namespace gui2
48 {
49 
50 // ------------ WIDGET -----------{
51 
52 REGISTER_WIDGET(chatbox)
53 
54 chatbox::chatbox(const implementation::builder_chatbox& builder)
55  : container_base(builder, type())
56  , roomlistbox_(nullptr)
57  , chat_log_container_(nullptr)
58  , chat_input_(nullptr)
59  , active_window_(0)
60  , active_window_changed_callback_()
61  , log_(nullptr)
62 {
63  // We only implement a RECEIVE_KEYBOARD_FOCUS handler; LOSE_KEYBOARD_FOCUS
64  // isn't needed. This handler forwards focus to the input textbox, meaning
65  // if keyboard_focus is called on a chatbox, distributor::keyboard_focus_
66  // will immediately be set to the input textbox, which will then handle focus
67  // loss itself when applicable. Nothing else happens in the interim while
68  // keyboard_focus_ equals `this` to warrent cleanup.
69  connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
70  std::bind(&chatbox::signal_handler_receive_keyboard_focus, this, std::placeholders::_2));
71 }
72 
74 {
75  roomlistbox_ = find_widget<listbox>("room_list", false, true);
76 
77  // We need to bind a lambda here since switch_to_window is overloaded.
78  // A lambda alone would be more verbose because it'd need to specify all the parameters.
80  std::bind([this]() { switch_to_window(roomlistbox_->get_selected_row()); }));
81 
82  chat_log_container_ = find_widget<multi_page>("chat_log_container", false, true);
83 
84  chat_input_ = find_widget<text_box>("chat_input", false, true);
85 
87  std::bind(&chatbox::chat_input_keypress_callback, this, std::placeholders::_5));
88 }
89 
90 void chatbox::load_log(std::map<std::string, chatroom_log>& log, bool show_lobby)
91 {
92  const std::string new_tip = formatter()
93  << "\n"
94  // TRANSLATORS: This is the new chat text indicator
95  << markup::span_color("#FF0000", "============", _("NEW"), "============");
96 
97  for(auto& l : log) {
98  const bool is_lobby = l.first == "lobby";
99 
100  if(!show_lobby && is_lobby && !l.second.whisper) {
101  continue;
102  }
103 
104  const std::size_t new_tip_index = l.second.log.find(new_tip);
105 
106  if(new_tip_index != std::string::npos) {
107  l.second.log.replace(new_tip_index, new_tip.length(), "");
108  }
109  find_or_create_window(l.first, l.second.whisper, true, !is_lobby, l.second.log + new_tip);
110  }
111 
112  log_ = &log;
113 }
114 
116 {
118 
119  // Clear pending messages notification in room listbox
122 
123  t.pending_messages = 0;
124 
127  }
128 }
129 
131 {
133 }
134 
135 void chatbox::switch_to_window(std::size_t id)
136 {
137  active_window_ = id;
138  assert(active_window_ < open_windows_.size());
139 
142 
143  // Grab input focus
145 
147 }
148 
149 void chatbox::chat_input_keypress_callback(const SDL_Keycode key)
150 {
151  std::string input = chat_input_->get_value();
152  if(input.empty() || chat_input_->is_composing()) {
153  return;
154  }
155 
157 
158  switch(key) {
159  case SDLK_RETURN:
160  case SDLK_KP_ENTER: {
161  if(input[0] == '/') {
162  // TODO: refactor do_speak so it uses context information about
163  // opened window, so e.g. /ignore in a whisper session ignores
164  // the other party without having to specify it's nick.
165  chat_handler::do_speak(input);
166  } else {
167  if(t.whisper) {
168  send_whisper(t.name, input);
169  add_whisper_sent(t.name, input);
170  } else {
171  send_chat_room_message(t.name, input);
172  add_chat_room_message_sent(t.name, input);
173  }
174  }
175 
177  chat_input_->set_value("");
178 
179  break;
180  }
181 
182  case SDLK_TAB: {
183  auto* li = mp::get_lobby_info();
184  if(!li) {
185  break;
186  }
187 
188  std::vector<std::string> matches;
189  for(const auto& ui : li->users()) {
190  if(ui.name != prefs::get().login()) {
191  matches.push_back(ui.name);
192  }
193  }
194 
195  const bool line_start = utils::word_completion(input, matches);
196 
197  if(matches.empty()) {
198  return;
199  }
200 
201  if(matches.size() == 1) {
202  input.append(line_start ? ": " : " ");
203  } else {
204  std::string completion_list = utils::join(matches, " ");
205  append_to_chatbox(completion_list);
206  }
207 
208  chat_input_->set_value(input);
209 
210  break;
211  }
212 
213  default:
214  break;
215  }
216 }
217 
218 void chatbox::append_to_chatbox(const std::string& text, const bool force_scroll)
219 {
220  append_to_chatbox(text, active_window_, force_scroll);
221 }
222 
223 void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const bool force_scroll)
224 {
226  scroll_text& log = grid.find_widget<scroll_text>("log_text");
227 
228  const bool chatbox_at_end = log.vertical_scrollbar_at_end();
229  const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
230 
231  const std::string before_message = log.get_value().empty() ? "" : "\n";
232  const std::string new_text = formatter()
233  << log.get_value() << before_message << markup::span_color("#bcb088", prefs::get().get_chat_timestamp(std::chrono::system_clock::now()), text);
234 
235  log.set_use_markup(true);
236  log.set_value(new_text);
237 
238  if(log_ != nullptr) {
239  try {
240  const std::string& room_name = open_windows_[id].name;
241  log_->at(room_name).log = new_text;
242  } catch(const std::out_of_range&) {
243  }
244  }
245 
246  if(chatbox_at_end || force_scroll) {
248  } else {
249  log.set_vertical_scrollbar_item_position(chatbox_position);
250  }
251 }
252 
253 void chatbox::send_chat_message(const std::string& message, bool /*allies_only*/)
254 {
255  add_chat_message(std::time(nullptr), prefs::get().login(), 0, message);
256 
257  ::config c {"message", ::config {"message", message, "sender", prefs::get().login()}};
258  send_to_server(c);
259 }
260 
262 {
263  const auto id = active_window_;
265  scroll_text& log = grid.find_widget<scroll_text>("log_text");
266  log.set_label("");
267 }
268 
269 void chatbox::user_relation_changed(const std::string& /*name*/)
270 {
273  }
274 }
275 
276 void chatbox::add_chat_message(const std::time_t& /*time*/,
277  const std::string& speaker,
278  int /*side*/,
279  const std::string& message,
281 {
282  std::string text;
283  if(message.compare(0, 4, "/me ") == 0) {
284  text = formatter() << markup::italic(speaker, " ", font::escape_text(message.substr(4)));
285  } else {
286  text = formatter() << markup::bold(speaker, ":") << font::escape_text(message);
287  }
288 
289  append_to_chatbox(text);
290 }
291 
292 void chatbox::add_whisper_sent(const std::string& receiver, const std::string& message)
293 {
294  if(whisper_window_active(receiver)) {
295  add_active_window_message(prefs::get().login(), message, true);
296  } else if(lobby_chat_window* t = whisper_window_open(receiver, prefs::get().auto_open_whisper_windows())) {
298  add_active_window_message(prefs::get().login(), message, true);
299  } else {
300  add_active_window_whisper(VGETTEXT("whisper to $receiver", {{"receiver", receiver}}), message, true);
301  }
302 }
303 
304 void chatbox::add_whisper_received(const std::string& sender, const std::string& message)
305 {
306  bool can_go_to_active = !prefs::get().lobby_whisper_friends_only() || prefs::get().is_friend(sender);
307  bool can_open_new = prefs::get().auto_open_whisper_windows() && can_go_to_active;
308 
309  if(whisper_window_open(sender, can_open_new)) {
310  if(whisper_window_active(sender)) {
312 
314  } else {
317 
319  }
320  } else if(can_go_to_active) {
323  } else {
324  LOG_LB << "Ignoring whisper from " << sender;
325  }
326 }
327 
328 void chatbox::add_chat_room_message_sent(const std::string& room, const std::string& message)
329 {
330  lobby_chat_window* t = room_window_open(room, false);
331  if(!t) {
332  LOG_LB << "Cannot add sent message to ui for room " << room << ", player not in the room";
333  return;
334  }
335 
336  if(!room_window_active(room)) {
338  }
339 
340  add_active_window_message(prefs::get().login(), message, true);
341 }
342 
343 void chatbox::add_chat_room_message_received(const std::string& room,
344  const std::string& speaker,
345  const std::string& message)
346 {
348 
349  if(room_window_active(room)) {
352  } else {
353  add_room_window_message(room, speaker, message);
356  }
357 
358  if(speaker == "server") {
360  } else if (utils::word_match(message, prefs::get().login())) {
362  } else if (prefs::get().is_friend(speaker)) {
364  }
365 
366  do_notify(notify_mode, speaker, message);
367 }
368 
369 bool chatbox::whisper_window_active(const std::string& name)
370 {
372  return t.name == name && t.whisper == true;
373 }
374 
375 bool chatbox::room_window_active(const std::string& room)
376 {
378  return t.name == room && t.whisper == false;
379 }
380 
381 lobby_chat_window* chatbox::room_window_open(const std::string& room, const bool open_new, const bool allow_close)
382 {
383  return find_or_create_window(room, false, open_new, allow_close,
384  VGETTEXT("Joined <i>$name</i>", { { "name", translation::dsgettext("wesnoth-lib", room.c_str()) } }));
385 }
386 
387 lobby_chat_window* chatbox::whisper_window_open(const std::string& name, bool open_new)
388 {
389  return find_or_create_window(name, true, open_new, true,
390  VGETTEXT("Started private message with <i>$name</i>. "
391  "If you do not want to receive messages from this player, type <i>/ignore $name</i>", { { "name", name } }));
392 }
393 
395  const bool whisper,
396  const bool open_new,
397  const bool allow_close,
398  const std::string& initial_text)
399 {
400  for(auto& t : open_windows_) {
401  if(t.name == name && t.whisper == whisper) {
402  return &t;
403  }
404  }
405 
406  if(!open_new) {
407  return nullptr;
408  }
409 
410  open_windows_.emplace_back(name, whisper);
411 
412  //
413  // Add a new chat log page.
414  //
415  widget_item item;
416  item["use_markup"] = "true";
417  item["label"] = initial_text;
418  widget_data data{{"log_text", item}};
419 
420  if(log_ != nullptr) {
421  log_->emplace(name, chatroom_log{item["label"], whisper});
422  }
423 
425 
426  //
427  // Add a new room window tab.
428  //
429  data.clear();
430  item.clear();
431 
432  if(!whisper) {
433  item["label"] = translation::dsgettext("wesnoth-lib", name.c_str());
434  } else {
435  item["label"] = "<" + name + ">";
436  }
437 
438  data.emplace("room", item);
439 
440  grid& row_grid = roomlistbox_->add_row(data);
441 
442  //
443  // Set up the Close Window button.
444  //
445  button& close_button = row_grid.find_widget<button>("close_window");
446 
447  if(!allow_close) {
449  } else {
450  connect_signal_mouse_left_click(close_button,
451  std::bind(&chatbox::close_window_button_callback, this, open_windows_.back().name, std::placeholders::_3, std::placeholders::_4));
452  }
453 
454  return &open_windows_.back();
455 }
456 
457 void chatbox::close_window_button_callback(std::string room_name, bool& handled, bool& halt)
458 {
459  const int index = std::distance(open_windows_.begin(), std::find_if(open_windows_.begin(), open_windows_.end(),
460  [&room_name](const lobby_chat_window& room) { return room.name == room_name; }
461  ));
462 
464 
465  handled = halt = true;
466 }
467 
468 void chatbox::send_to_server(const ::config& cfg)
469 {
470  mp::send_to_server(cfg);
471 }
472 
473 void chatbox::increment_waiting_whispers(const std::string& name)
474 {
475  if(lobby_chat_window* t = whisper_window_open(name, false)) {
476  ++t->pending_messages;
477 
478  if(t->pending_messages == 1) {
479  DBG_LB << "do whisper pending mark row " << (t - &open_windows_[0]) << " with " << t->name;
480 
483  }
484  }
485 }
486 
487 void chatbox::increment_waiting_messages(const std::string& room)
488 {
489  if(lobby_chat_window* t = room_window_open(room, false)) {
490  ++t->pending_messages;
491 
492  if(t->pending_messages == 1) {
493  int idx = t - &open_windows_[0];
494 
495  DBG_LB << "do room pending mark row " << idx << " with " << t->name;
496 
499  }
500  }
501 }
502 
503 void chatbox::add_whisper_window_whisper(const std::string& sender, const std::string& message)
504 {
505  lobby_chat_window* t = whisper_window_open(sender, false);
506  if(!t) {
507  ERR_LB << "Whisper window not open in add_whisper_window_whisper for " << sender;
508  return;
509  }
510 
511  const std::string text = formatter() << markup::bold(sender, ": ") << font::escape_text(message);
512  append_to_chatbox(text, t - &open_windows_[0], false);
513 }
514 
515 void chatbox::add_active_window_whisper(const std::string& sender,
516  const std::string& message,
517  const bool force_scroll)
518 {
519  const std::string text = formatter() << markup::bold("whisper: ", sender, ": ") << font::escape_text(message);
520  append_to_chatbox(text, force_scroll);
521 }
522 
523 void chatbox::close_window(std::size_t idx)
524 {
525  const lobby_chat_window& t = open_windows_[idx];
526 
527  DBG_LB << "Close window " << idx << " - " << t.name;
528 
529  // Can't close the lobby!
530  if((t.name == "lobby" && t.whisper == false) || open_windows_.size() == 1) {
531  return;
532  }
533 
534  // Check if we're closing the currently-active window.
535  const bool active_changed = idx == active_window_;
536 
537  if(active_window_ == open_windows_.size() - 1) {
538  --active_window_;
539  }
540 
541  if(log_ != nullptr) {
542  log_->erase(t.name);
543  }
544 
545  open_windows_.erase(open_windows_.begin() + idx);
546 
547  roomlistbox_->remove_row(idx);
549 
552 
553  if(active_changed) {
555  }
556 }
557 
558 void chatbox::add_room_window_message(const std::string& room,
559  const std::string& sender,
560  const std::string& message)
561 {
562  lobby_chat_window* t = room_window_open(room, false);
563  if(!t) {
564  ERR_LB << "Room window not open in add_room_window_message for " << room;
565  return;
566  }
567 
568  const std::string text = formatter() << markup::bold(sender, ": ") << font::escape_text(message);
569  append_to_chatbox(text, t - &open_windows_[0], false);
570 }
571 
572 void chatbox::add_active_window_message(const std::string& sender,
573  const std::string& message,
574  const bool force_scroll)
575 {
576  const std::string text = formatter() << markup::bold(sender, ": ") << font::escape_text(message);
577  append_to_chatbox(text, force_scroll);
578 }
579 
580 void chatbox::process_message(const ::config& data, bool whisper /*= false*/)
581 {
582  std::string sender = data["sender"];
583  DBG_LB << "process message from " << sender << " " << (whisper ? "(w)" : "")
584  << ", len " << data["message"].str().size();
585 
586  if(prefs::get().is_ignored(sender)) {
587  return;
588  }
589 
590  const std::string& message = data["message"];
591  //prefs::get().parse_admin_authentication(sender, message); TODO: replace
592 
593  if(whisper) {
594  add_whisper_received(sender, message);
595  } else {
596  if (!prefs::get().parse_should_show_lobby_join(sender, message)) return;
597 
598  std::string room = data["room"];
599 
600  // Attempt to send to the currently active room first.
601  if(room.empty()) {
602  LOG_LB << "Message without a room from " << sender << ", falling back to active window";
603  room = open_windows_[active_window_].name;
604  }
605 
606  // If we still don't have a name, fall back to lobby.
607  if(room.empty()) {
608  LOG_LB << "Message without a room from " << sender << ", assuming lobby";
609  room = "lobby";
610  }
611 
612  if(log_ != nullptr && data["type"].str() == "motd") {
613  if(log_->at("lobby").received_motd == message) {
614  LOG_LB << "Ignoring repeated motd";
615  return;
616  } else {
617  log_->at("lobby").received_motd = message;
618  }
619  }
620 
622  }
623 
624  // Notify plugins about the message
625  ::config plugin_data = data;
626  plugin_data["whisper"] = whisper;
627  plugins_manager::get()->notify_event("chat", plugin_data);
628 }
629 
630 void chatbox::process_network_data(const ::config& data)
631 {
632  if(const auto message = data.optional_child("message")) {
634  } else if(const auto whisper = data.optional_child("whisper")) {
635  process_message(*whisper, true);
636  }
637 }
638 
640 {
641  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
642 
643  // Forward focus to the input textbox.
645 }
646 
647 // }---------- DEFINITION ---------{
648 
651 {
652  load_resolutions<resolution>(cfg);
653 }
654 
656  : resolution_definition(cfg), grid()
657 {
658  state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", missing_mandatory_wml_tag("chatbox_definition][resolution", "background")));
659  state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", missing_mandatory_wml_tag("chatbox_definition][resolution", "foreground")));
660 
661  auto child = VALIDATE_WML_CHILD(cfg, "grid", missing_mandatory_wml_tag("chatbox_definition][resolution", "grid"));
662  grid = std::make_shared<builder_grid>(child);
663 }
664 // }---------- BUILDER -----------{
665 
666 namespace implementation
667 {
668 
669 builder_chatbox::builder_chatbox(const config& cfg)
670  : builder_styled_widget(cfg)
671 {
672 }
673 
674 std::unique_ptr<widget> builder_chatbox::build() const
675 {
676  auto widget = std::make_unique<chatbox>(*this);
677 
678  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
679  << "' with definition '" << definition << "'.";
680 
681  const auto conf = widget->cast_config_to<chatbox_definition>();
682  assert(conf);
683 
684  widget->init_grid(*conf->grid);
685  widget->finalize_setup();
686 
687  return widget;
688 }
689 
690 } // namespace implementation
691 
692 // }------------ END --------------
693 
694 } // namespace gui2
double t
Definition: astarsearch.cpp:63
#define LOG_LB
Definition: chatbox.cpp:41
#define ERR_LB
Definition: chatbox.cpp:42
#define LOG_HEADER
Definition: chatbox.cpp:45
static lg::log_domain log_lobby("lobby")
#define DBG_LB
Definition: chatbox.cpp:40
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
virtual void send_chat_room_message(const std::string &room, const std::string &message)
virtual void send_whisper(const std::string &receiver, const std::string &message)
std::ostringstream wrapper.
Definition: formatter.hpp:40
Simple push button.
Definition: button.hpp:36
std::map< std::string, chatroom_log > * log_
Definition: chatbox.hpp:136
bool room_window_active(const std::string &room)
Definition: chatbox.cpp:375
lobby_chat_window * room_window_open(const std::string &room, const bool open_new, const bool allow_close=true)
Check if a room window for "room" is open, if open_new is true then it will be created if not found.
Definition: chatbox.cpp:381
text_box * chat_input_
Definition: chatbox.hpp:128
lobby_chat_window * find_or_create_window(const std::string &name, const bool whisper, const bool open_new, const bool allow_close, const std::string &initial_text)
Helper function to find and open a new window, used by *_window_open.
Definition: chatbox.cpp:394
virtual void clear_messages() override
Definition: chatbox.cpp:261
void add_active_window_whisper(const std::string &sender, const std::string &message, const bool force_scroll=false)
Add a whisper message to the current window which is not the whisper window for "name".
Definition: chatbox.cpp:515
void append_to_chatbox(const std::string &text, const bool force_scroll=false)
Definition: chatbox.cpp:218
virtual void user_relation_changed(const std::string &name) override
Inherited form chat_handler.
Definition: chatbox.cpp:269
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
Definition: chatbox.cpp:253
void add_active_window_message(const std::string &sender, const std::string &message, const bool force_scroll=false)
Add a message to the window for room "room".
Definition: chatbox.cpp:572
void close_window(std::size_t idx)
Definition: chatbox.cpp:523
void add_whisper_window_whisper(const std::string &sender, const std::string &message)
Add a whisper message to the whisper window.
Definition: chatbox.cpp:503
void close_window_button_callback(std::string room_name, bool &handled, bool &halt)
Definition: chatbox.cpp:457
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:328
multi_page * chat_log_container_
Definition: chatbox.hpp:126
void process_message(const ::config &data, bool whisper=false)
Definition: chatbox.cpp:580
lobby_chat_window * whisper_window_open(const std::string &name, bool open_new)
Check if a whisper window for user "name" is open, if open_new is true then it will be created if not...
Definition: chatbox.cpp:387
void switch_to_window(lobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
Definition: chatbox.cpp:130
std::size_t active_window_
Definition: chatbox.hpp:132
virtual void add_whisper_sent(const std::string &receiver, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:292
virtual void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &message, events::chat_handler::MESSAGE_TYPE type=events::chat_handler::MESSAGE_PRIVATE) override
Inherited form chat_handler.
Definition: chatbox.cpp:276
void process_network_data(const ::config &data)
Definition: chatbox.cpp:630
void increment_waiting_whispers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
Definition: chatbox.cpp:473
std::function< void(void)> active_window_changed_callback_
Definition: chatbox.hpp:134
listbox * roomlistbox_
Definition: chatbox.hpp:124
void increment_waiting_messages(const std::string &room)
Mark the room window for "room" as having one more pending message.
Definition: chatbox.cpp:487
void signal_handler_receive_keyboard_focus(const event::ui_event event)
Definition: chatbox.cpp:639
void send_to_server(const ::config &cfg) override
Definition: chatbox.cpp:468
virtual void add_chat_room_message_received(const std::string &room, const std::string &speaker, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:343
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
Definition: chatbox.cpp:90
virtual void add_whisper_received(const std::string &sender, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:304
void finalize_setup()
Initializes the internal sub-widget pointers.
Definition: chatbox.cpp:73
void chat_input_keypress_callback(const SDL_Keycode key)
Definition: chatbox.cpp:149
void add_room_window_message(const std::string &room, const std::string &sender, const std::string &message)
Add a message to the window for room "room".
Definition: chatbox.cpp:558
void active_window_changed()
Definition: chatbox.cpp:115
std::vector< lobby_chat_window > open_windows_
Definition: chatbox.hpp:130
bool whisper_window_active(const std::string &name)
Definition: chatbox.cpp:369
A generic container base class.
Main class to show messages to the user.
Definition: message.hpp:36
Base container class.
Definition: grid.hpp:32
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:92
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:267
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:280
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
Definition: listbox.cpp:112
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:305
const grid & page_grid(const unsigned page) const
Returns the grid for the page.
Definition: multi_page.cpp:134
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
Definition: multi_page.cpp:90
grid & add_page(const widget_item &item)
Adds single page to the grid.
Definition: multi_page.cpp:58
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition: multi_page.cpp:119
std::string get_value()
Definition: scroll_text.cpp:76
virtual void set_label(const t_string &label) override
Definition: scroll_text.cpp:62
void set_value(const t_string &label)
Definition: scroll_text.hpp:47
@ END
Go to the end position.
Definition: scrollbar.hpp:58
void scroll_vertical_scrollbar(const scrollbar_base::scroll_mode scroll)
Scrolls the vertical scrollbar.
unsigned get_vertical_scrollbar_item_position() const
Returns current position of the vertical scrollbar.
void set_vertical_scrollbar_item_position(const unsigned position)
Move the vertical scrollbar to a position.
virtual void set_use_markup(bool use_markup)
std::string get_value() const
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
bool is_composing() const
void save_to_history()
Saves the text in the widget to the history.
Definition: text_box.hpp:132
Base class for all widgets.
Definition: widget.hpp:55
void set_visible(const visibility visible)
Definition: widget.cpp:479
const std::string & id() const
Definition: widget.cpp:110
window * get_window()
Get the parent window.
Definition: widget.cpp:117
@ visible
The user sets the widget visible, that means:
@ hidden
The user sets the widget hidden, that means:
T * find_widget(const std::string_view id, const bool must_be_active, const bool must_exist)
Gets a widget with the wanted id.
Definition: widget.hpp:753
void keyboard_capture(widget *widget)
Definition: window.cpp:1207
void notify_event(const std::string &name, const config &data)
Definition: manager.cpp:144
static plugins_manager * get()
Definition: manager.cpp:58
static prefs & get()
bool is_ignored(const std::string &nick)
bool is_friend(const std::string &nick)
std::string login()
bool auto_open_whisper_windows()
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
static std::string _(const char *str)
Definition: gettext.hpp:93
#define DBG_GUI_G
Definition: log.hpp:41
#define DBG_GUI_E
Definition: log.hpp:35
This file contains the window object, this object is a top level container which has the event manage...
Standard logging facilities (interface).
std::string escape_text(std::string_view text)
Escapes the pango markup characters in a text.
Definition: escape.hpp:33
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard &signal)
Connects the signal for 'snooping' on the keypress.
Definition: dispatcher.cpp:172
ui_event
The event sent to the dispatcher.
Definition: handler.hpp:115
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:203
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:177
Generic file dialog.
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
std::map< std::string, t_string > widget_item
Definition: widget.hpp:33
Functions to load and save images from/to disk.
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::string italic(Args &&... data)
Definition: markup.hpp:140
std::string bold(Args &&... data)
Definition: markup.hpp:128
std::string span_color(const color_t &color, Args &&... data)
Definition: markup.hpp:68
lobby_info * get_lobby_info()
Returns the lobby_info object for the given session.
void do_notify(notify_mode mode, const std::string &sender, const std::string &message)
Definition: lobby_info.cpp:56
void send_to_server(const config &data)
Attempts to send given data to server if a connection is open.
notify_mode
Definition: lobby_info.hpp:154
std::string dsgettext(const char *domainname, const char *msgid)
Definition: gettext.cpp:434
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:70
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.
bool word_completion(std::string &text, std::vector< std::string > &wordlist)
Try to complete the last word of 'text' with the 'wordlist'.
std::string_view data
Definition: picture.cpp:178
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
chatbox_definition(const config &cfg)
Definition: chatbox.cpp:649
virtual std::unique_ptr< widget > build() const override
Definition: chatbox.cpp:674
std::string definition
Parameters for the styled_widget.
std::vector< state_definition > state
mock_char c
std::string missing_mandatory_wml_tag(const std::string &section, const std::string &tag)
Returns a standard message for a missing wml child (tag).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WML_CHILD(cfg, key, message)