The Battle for Wesnoth  1.19.0-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 
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/image.hpp"
23 #include "gui/widgets/listbox.hpp"
26 #include "gui/widgets/text_box.hpp"
27 #include "gui/widgets/window.hpp"
28 
29 #include "font/pango/escape.hpp"
30 #include "formatter.hpp"
31 #include "formula/string_utils.hpp"
33 #include "gettext.hpp"
34 #include "log.hpp"
36 #include "preferences/game.hpp"
37 #include "preferences/lobby.hpp"
39 #include "wml_exception.hpp"
40 
41 static lg::log_domain log_lobby("lobby");
42 #define DBG_LB LOG_STREAM(debug, log_lobby)
43 #define LOG_LB LOG_STREAM(info, log_lobby)
44 #define ERR_LB LOG_STREAM(err, log_lobby)
45 
46 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
47 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
48 
49 namespace gui2
50 {
51 
52 // ------------ WIDGET -----------{
53 
54 REGISTER_WIDGET(chatbox)
55 
56 chatbox::chatbox(const implementation::builder_chatbox& builder)
57  : container_base(builder, type())
58  , roomlistbox_(nullptr)
59  , chat_log_container_(nullptr)
60  , chat_input_(nullptr)
61  , active_window_(0)
62  , active_window_changed_callback_()
63  , log_(nullptr)
64 {
65  // We only implement a RECEIVE_KEYBOARD_FOCUS handler; LOSE_KEYBOARD_FOCUS
66  // isn't needed. This handler forwards focus to the input textbox, meaning
67  // if keyboard_focus is called on a chatbox, distributor::keyboard_focus_
68  // will immediately be set to the input textbox, which will then handle focus
69  // loss itself when applicable. Nothing else happens in the interim while
70  // keyboard_focus_ equals `this` to warrent cleanup.
71  connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
72  std::bind(&chatbox::signal_handler_receive_keyboard_focus, this, std::placeholders::_2));
73 }
74 
76 {
77  roomlistbox_ = find_widget<listbox>(this, "room_list", false, true);
78 
79  // We need to bind a lambda here since switch_to_window is overloaded.
80  // A lambda alone would be more verbose because it'd need to specify all the parameters.
82  std::bind([this]() { switch_to_window(roomlistbox_->get_selected_row()); }));
83 
84  chat_log_container_ = find_widget<multi_page>(this, "chat_log_container", false, true);
85 
86  chat_input_ = find_widget<text_box>(this, "chat_input", false, true);
87 
89  std::bind(&chatbox::chat_input_keypress_callback, this, std::placeholders::_5));
90 }
91 
92 void chatbox::load_log(std::map<std::string, chatroom_log>& log, bool show_lobby)
93 {
94  for(const auto& l : log) {
95  const bool is_lobby = l.first == "lobby";
96 
97  if(!show_lobby && is_lobby && !l.second.whisper) {
98  continue;
99  }
100 
101  find_or_create_window(l.first, l.second.whisper, true, !is_lobby, l.second.log);
102  }
103 
104  log_ = &log;
105 }
106 
108 {
110 
111  // Clear pending messages notification in room listbox
113  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::hidden);
114 
115  t.pending_messages = 0;
116 
119  }
120 }
121 
123 {
125 }
126 
127 void chatbox::switch_to_window(std::size_t id)
128 {
129  active_window_ = id;
130  assert(active_window_ < open_windows_.size());
131 
134 
135  // Grab input focus
137 
139 }
140 
141 void chatbox::chat_input_keypress_callback(const SDL_Keycode key)
142 {
143  std::string input = chat_input_->get_value();
144  if(input.empty() || chat_input_->is_composing()) {
145  return;
146  }
147 
149 
150  switch(key) {
151  case SDLK_RETURN:
152  case SDLK_KP_ENTER: {
153  if(input[0] == '/') {
154  // TODO: refactor do_speak so it uses context information about
155  // opened window, so e.g. /ignore in a whisper session ignores
156  // the other party without having to specify it's nick.
157  chat_handler::do_speak(input);
158  } else {
159  if(t.whisper) {
160  send_whisper(t.name, input);
161  add_whisper_sent(t.name, input);
162  } else {
163  send_chat_room_message(t.name, input);
164  add_chat_room_message_sent(t.name, input);
165  }
166  }
167 
169  chat_input_->set_value("");
170 
171  break;
172  }
173 
174  case SDLK_TAB: {
175  auto* li = mp::get_lobby_info();
176  if(!li) {
177  break;
178  }
179 
180  // TODO: very inefficient! Very! D:
181  std::vector<std::string> matches;
182  for(const auto& ui : li->users()) {
183  if(ui.name != preferences::login()) {
184  matches.push_back(ui.name);
185  }
186  }
187 
188  const bool line_start = utils::word_completion(input, matches);
189 
190  if(matches.empty()) {
191  return;
192  }
193 
194  if(matches.size() == 1) {
195  input.append(line_start ? ": " : " ");
196  } else {
197  std::string completion_list = utils::join(matches, " ");
198  append_to_chatbox(completion_list);
199  }
200 
201  chat_input_->set_value(input);
202 
203  break;
204  }
205 
206  default:
207  break;
208  }
209 }
210 
211 void chatbox::append_to_chatbox(const std::string& text, const bool force_scroll)
212 {
213  append_to_chatbox(text, active_window_, force_scroll);
214 }
215 
216 void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const bool force_scroll)
217 {
219 
220  scroll_label& log = find_widget<scroll_label>(&grid, "log_text", false);
221  const bool chatbox_at_end = log.vertical_scrollbar_at_end();
222  const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
223 
224  const std::string before_message = log.get_label().empty() ? "" : "\n";
225  const std::string new_text = formatter()
226  << log.get_label() << before_message << "<span color='#bcb088'>" << preferences::get_chat_timestamp(std::time(0)) << text << "</span>";
227 
228  log.set_use_markup(true);
229  log.set_label(new_text);
230 
231  if(log_ != nullptr) {
232  try {
233  const std::string& room_name = open_windows_[id].name;
234  log_->at(room_name).log = new_text;
235  } catch(const std::out_of_range&) {
236  }
237  }
238 
239  if(chatbox_at_end || force_scroll) {
241  } else {
242  log.set_vertical_scrollbar_item_position(chatbox_position);
243  }
244 }
245 
246 void chatbox::send_chat_message(const std::string& message, bool /*allies_only*/)
247 {
248  add_chat_message(std::time(nullptr), preferences::login(), 0, message);
249 
250  ::config c {"message", ::config {"message", message, "sender", preferences::login()}};
251  send_to_server(c);
252 }
253 
255 {
256  const auto id = active_window_;
258  scroll_label& log = find_widget<scroll_label>(&grid, "log_text", false);
259  log.set_label("");
260 }
261 
262 void chatbox::user_relation_changed(const std::string& /*name*/)
263 {
266  }
267 }
268 
269 void chatbox::add_chat_message(const std::time_t& /*time*/,
270  const std::string& speaker,
271  int /*side*/,
272  const std::string& message,
274 {
275  std::string text;
276 
277  // FIXME: the chat_command_handler class (which handles chat commands) dispatches a
278  // message consisting of '/me insert text here' in the case the '/me' or '/emote'
279  // commands are used, so we need to do some manual preprocessing here.
280  if(message.compare(0, 4, "/me ") == 0) {
281  text = formatter() << "<i>" << speaker << " " << font::escape_text(message.substr(4)) << "</i>";
282  } else {
283  text = formatter() << "<b>" << speaker << ":</b> " << font::escape_text(message);
284  }
285 
286  append_to_chatbox(text);
287 }
288 
289 void chatbox::add_whisper_sent(const std::string& receiver, const std::string& message)
290 {
291  if(whisper_window_active(receiver)) {
296  } else {
297  add_active_window_whisper(VGETTEXT("whisper to $receiver", {{"receiver", receiver}}), message, true);
298  }
299 }
300 
301 void chatbox::add_whisper_received(const std::string& sender, const std::string& message)
302 {
303  bool can_go_to_active = !preferences::whisper_friends_only() || preferences::is_friend(sender);
304  bool can_open_new = preferences::auto_open_whisper_windows() && can_go_to_active;
305 
306  if(whisper_window_open(sender, can_open_new)) {
307  if(whisper_window_active(sender)) {
309 
311  } else {
314 
316  }
317  } else if(can_go_to_active) {
320  } else {
321  LOG_LB << "Ignoring whisper from " << sender;
322  }
323 }
324 
325 void chatbox::add_chat_room_message_sent(const std::string& room, const std::string& message)
326 {
327  lobby_chat_window* t = room_window_open(room, false);
328  if(!t) {
329  LOG_LB << "Cannot add sent message to ui for room " << room << ", player not in the room";
330  return;
331  }
332 
333  if(!room_window_active(room)) {
335  }
336 
338 }
339 
340 void chatbox::add_chat_room_message_received(const std::string& room,
341  const std::string& speaker,
342  const std::string& message)
343 {
345 
346  if(room_window_active(room)) {
349  } else {
350  add_room_window_message(room, speaker, message);
353  }
354 
355  if(speaker == "server") {
359  } else if (preferences::is_friend(speaker)) {
361  }
362 
363  do_notify(notify_mode, speaker, message);
364 }
365 
366 bool chatbox::whisper_window_active(const std::string& name)
367 {
369  return t.name == name && t.whisper == true;
370 }
371 
372 bool chatbox::room_window_active(const std::string& room)
373 {
375  return t.name == room && t.whisper == false;
376 }
377 
378 lobby_chat_window* chatbox::room_window_open(const std::string& room, const bool open_new, const bool allow_close)
379 {
380  return find_or_create_window(room, false, open_new, allow_close,
381  VGETTEXT("Joined <i>$name</i>", { { "name", translation::dsgettext("wesnoth-lib", room.c_str()) } }));
382 }
383 
384 lobby_chat_window* chatbox::whisper_window_open(const std::string& name, bool open_new)
385 {
386  return find_or_create_window(name, true, open_new, true,
387  VGETTEXT("Started private message with <i>$name</i>. "
388  "If you do not want to receive messages from this player, type <i>/ignore $name</i>", { { "name", name } }));
389 }
390 
392  const bool whisper,
393  const bool open_new,
394  const bool allow_close,
395  const std::string& initial_text)
396 {
397  for(auto& t : open_windows_) {
398  if(t.name == name && t.whisper == whisper) {
399  return &t;
400  }
401  }
402 
403  if(!open_new) {
404  return nullptr;
405  }
406 
407  open_windows_.emplace_back(name, whisper);
408 
409  //
410  // Add a new chat log page.
411  //
413  item["use_markup"] = "true";
414  item["label"] = initial_text;
415  widget_data data{{"log_text", item}};
416 
417  if(log_ != nullptr) {
418  log_->emplace(name, chatroom_log{item["label"], whisper});
419  }
420 
422 
423  //
424  // Add a new room window tab.
425  //
426  data.clear();
427  item.clear();
428 
429  if(!whisper) {
430  item["label"] = translation::dsgettext("wesnoth-lib", name.c_str());
431  } else {
432  item["label"] = "<" + name + ">";
433  }
434 
435  data.emplace("room", item);
436 
437  grid& row_grid = roomlistbox_->add_row(data);
438 
439  //
440  // Set up the Close Window button.
441  //
442  button& close_button = find_widget<button>(&row_grid, "close_window", false);
443 
444  if(!allow_close) {
446  } else {
447  connect_signal_mouse_left_click(close_button,
448  std::bind(&chatbox::close_window_button_callback, this, open_windows_.back().name, std::placeholders::_3, std::placeholders::_4));
449  }
450 
451  return &open_windows_.back();
452 }
453 
454 void chatbox::close_window_button_callback(std::string room_name, bool& handled, bool& halt)
455 {
456  const int index = std::distance(open_windows_.begin(), std::find_if(open_windows_.begin(), open_windows_.end(),
457  [&room_name](const lobby_chat_window& room) { return room.name == room_name; }
458  ));
459 
461 
462  handled = halt = true;
463 }
464 
465 void chatbox::send_to_server(const ::config& cfg)
466 {
467  mp::send_to_server(cfg);
468 }
469 
470 void chatbox::increment_waiting_whispers(const std::string& name)
471 {
472  if(lobby_chat_window* t = whisper_window_open(name, false)) {
473  ++t->pending_messages;
474 
475  if(t->pending_messages == 1) {
476  DBG_LB << "do whisper pending mark row " << (t - &open_windows_[0]) << " with " << t->name;
477 
479  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::visible);
480  }
481  }
482 }
483 
484 void chatbox::increment_waiting_messages(const std::string& room)
485 {
486  if(lobby_chat_window* t = room_window_open(room, false)) {
487  ++t->pending_messages;
488 
489  if(t->pending_messages == 1) {
490  int idx = t - &open_windows_[0];
491 
492  DBG_LB << "do room pending mark row " << idx << " with " << t->name;
493 
495  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::visible);
496  }
497  }
498 }
499 
500 void chatbox::add_whisper_window_whisper(const std::string& sender, const std::string& message)
501 {
502  lobby_chat_window* t = whisper_window_open(sender, false);
503  if(!t) {
504  ERR_LB << "Whisper window not open in add_whisper_window_whisper for " << sender;
505  return;
506  }
507 
508  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
509  append_to_chatbox(text, t - &open_windows_[0], false);
510 }
511 
512 void chatbox::add_active_window_whisper(const std::string& sender,
513  const std::string& message,
514  const bool force_scroll)
515 {
516  const std::string text = formatter() << "<b>" << "whisper: " << sender << ":</b> " << font::escape_text(message);
517  append_to_chatbox(text, force_scroll);
518 }
519 
520 void chatbox::close_window(std::size_t idx)
521 {
522  const lobby_chat_window& t = open_windows_[idx];
523 
524  DBG_LB << "Close window " << idx << " - " << t.name;
525 
526  // Can't close the lobby!
527  if((t.name == "lobby" && t.whisper == false) || open_windows_.size() == 1) {
528  return;
529  }
530 
531  // Check if we're closing the currently-active window.
532  const bool active_changed = idx == active_window_;
533 
534  if(active_window_ == open_windows_.size() - 1) {
535  --active_window_;
536  }
537 
538  if(log_ != nullptr) {
539  log_->erase(t.name);
540  }
541 
542  open_windows_.erase(open_windows_.begin() + idx);
543 
544  roomlistbox_->remove_row(idx);
546 
549 
550  if(active_changed) {
552  }
553 }
554 
555 void chatbox::add_room_window_message(const std::string& room,
556  const std::string& sender,
557  const std::string& message)
558 {
559  lobby_chat_window* t = room_window_open(room, false);
560  if(!t) {
561  ERR_LB << "Room window not open in add_room_window_message for " << room;
562  return;
563  }
564 
565  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
566  append_to_chatbox(text, t - &open_windows_[0], false);
567 }
568 
569 void chatbox::add_active_window_message(const std::string& sender,
570  const std::string& message,
571  const bool force_scroll)
572 {
573  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
574  append_to_chatbox(text, force_scroll);
575 }
576 
577 void chatbox::process_message(const ::config& data, bool whisper /*= false*/)
578 {
579  std::string sender = data["sender"];
580  DBG_LB << "process message from " << sender << " " << (whisper ? "(w)" : "")
581  << ", len " << data["message"].str().size();
582 
583  if(preferences::is_ignored(sender)) {
584  return;
585  }
586 
587  const std::string& message = data["message"];
588  //preferences::parse_admin_authentication(sender, message); TODO: replace
589 
590  if(whisper) {
591  add_whisper_received(sender, message);
592  } else {
594 
595  std::string room = data["room"];
596 
597  // Attempt to send to the currently active room first.
598  if(room.empty()) {
599  LOG_LB << "Message without a room from " << sender << ", falling back to active window";
600  room = open_windows_[active_window_].name;
601  }
602 
603  // If we still don't have a name, fall back to lobby.
604  if(room.empty()) {
605  LOG_LB << "Message without a room from " << sender << ", assuming lobby";
606  room = "lobby";
607  }
608 
609  if(log_ != nullptr && data["type"].str() == "motd") {
610  if(log_->at("lobby").received_motd == message) {
611  LOG_LB << "Ignoring repeated motd";
612  return;
613  } else {
614  log_->at("lobby").received_motd = message;
615  }
616  }
617 
619  }
620 
621  // Notify plugins about the message
622  ::config plugin_data = data;
623  plugin_data["whisper"] = whisper;
624  plugins_manager::get()->notify_event("chat", plugin_data);
625 }
626 
627 void chatbox::process_network_data(const ::config& data)
628 {
629  if(const auto message = data.optional_child("message")) {
631  } else if(const auto whisper = data.optional_child("whisper")) {
632  process_message(*whisper, true);
633  }
634 }
635 
637 {
638  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
639 
640  // Forward focus to the input textbox.
642 }
643 
644 // }---------- DEFINITION ---------{
645 
648 {
649  load_resolutions<resolution>(cfg);
650 }
651 
653  : resolution_definition(cfg), grid()
654 {
655  state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", missing_mandatory_wml_tag("chatbox_definition][resolution", "background")));
656  state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", missing_mandatory_wml_tag("chatbox_definition][resolution", "foreground")));
657 
658  auto child = VALIDATE_WML_CHILD(cfg, "grid", missing_mandatory_wml_tag("chatbox_definition][resolution", "grid"));
659  grid = std::make_shared<builder_grid>(child);
660 }
661 // }---------- BUILDER -----------{
662 
663 namespace implementation
664 {
665 
666 builder_chatbox::builder_chatbox(const config& cfg)
667  : builder_styled_widget(cfg)
668 {
669 }
670 
671 std::unique_ptr<widget> builder_chatbox::build() const
672 {
673  auto widget = std::make_unique<chatbox>(*this);
674 
675  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
676  << "' with definition '" << definition << "'.";
677 
678  const auto conf = widget->cast_config_to<chatbox_definition>();
679  assert(conf);
680 
681  widget->init_grid(*conf->grid);
682  widget->finalize_setup();
683 
684  return widget;
685 }
686 
687 } // namespace implementation
688 
689 // }------------ END --------------
690 
691 } // namespace gui2
double t
Definition: astarsearch.cpp:63
#define LOG_LB
Definition: chatbox.cpp:43
#define ERR_LB
Definition: chatbox.cpp:44
#define LOG_HEADER
Definition: chatbox.cpp:47
static lg::log_domain log_lobby("lobby")
#define DBG_LB
Definition: chatbox.cpp:42
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
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:372
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:378
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:391
virtual void clear_messages() override
Definition: chatbox.cpp:254
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:512
void append_to_chatbox(const std::string &text, const bool force_scroll=false)
Definition: chatbox.cpp:211
virtual void user_relation_changed(const std::string &name) override
Inherited form chat_handler.
Definition: chatbox.cpp:262
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
Definition: chatbox.cpp:246
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:569
void close_window(std::size_t idx)
Definition: chatbox.cpp:520
void add_whisper_window_whisper(const std::string &sender, const std::string &message)
Add a whisper message to the whisper window.
Definition: chatbox.cpp:500
void close_window_button_callback(std::string room_name, bool &handled, bool &halt)
Definition: chatbox.cpp:454
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:325
multi_page * chat_log_container_
Definition: chatbox.hpp:126
void process_message(const ::config &data, bool whisper=false)
Definition: chatbox.cpp:577
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:384
void switch_to_window(lobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
Definition: chatbox.cpp:122
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:289
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:269
void process_network_data(const ::config &data)
Definition: chatbox.cpp:627
void increment_waiting_whispers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
Definition: chatbox.cpp:470
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:484
void signal_handler_receive_keyboard_focus(const event::ui_event event)
Definition: chatbox.cpp:636
void send_to_server(const ::config &cfg) override
Definition: chatbox.cpp:465
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:340
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
Definition: chatbox.cpp:92
virtual void add_whisper_received(const std::string &sender, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:301
void finalize_setup()
Initializes the internal sub-widget pointers.
Definition: chatbox.cpp:75
void chat_input_keypress_callback(const SDL_Keycode key)
Definition: chatbox.cpp:141
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:555
void active_window_changed()
Definition: chatbox.cpp:107
std::vector< lobby_chat_window > open_windows_
Definition: chatbox.hpp:130
bool whisper_window_active(const std::string &name)
Definition: chatbox.cpp:366
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:59
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:230
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:243
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
Definition: listbox.cpp:79
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:268
const grid & page_grid(const unsigned page) const
Returns the grid for the page.
Definition: multi_page.cpp:119
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
Definition: multi_page.cpp:75
grid & add_page(const widget_item &item)
Adds single page to the grid.
Definition: multi_page.cpp:43
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition: multi_page.cpp:104
Label showing a text.
virtual void set_label(const t_string &label) override
See styled_widget::set_label.
virtual void set_use_markup(bool use_markup) override
See styled_widget::set_use_markup.
@ 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.
const t_string & get_label() const
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:149
Base class for all widgets.
Definition: widget.hpp:53
void set_visible(const visibility visible)
Definition: widget.cpp:470
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:
void keyboard_capture(widget *widget)
Definition: window.cpp:1215
void notify_event(const std::string &name, const config &data)
Definition: manager.cpp:144
static plugins_manager * get()
Definition: manager.cpp:58
bool empty() const
Definition: tstring.hpp:186
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
#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(const std::string &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:34
std::map< std::string, t_string > widget_item
Definition: widget.hpp:31
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:412
Contains the implementation details for lexical_cast and shouldn't be used directly.
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
bool is_ignored(const std::string &nick)
Definition: game.cpp:273
bool whisper_friends_only()
Definition: lobby.cpp:21
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:860
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
Definition: game.cpp:301
std::string login()
bool is_friend(const std::string &nick)
Definition: game.cpp:261
bool auto_open_whisper_windows()
Definition: lobby.cpp:31
std::string dsgettext(const char *domainname, const char *msgid)
Definition: gettext.cpp:434
std::size_t index(const std::string &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:194
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
chatbox_definition(const config &cfg)
Definition: chatbox.cpp:646
virtual std::unique_ptr< widget > build() const override
Definition: chatbox.cpp:671
std::string definition
Parameters for the styled_widget.
Base class of a resolution, contains the common keys for a resolution.
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)