The Battle for Wesnoth  1.17.21+dev
window.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2023
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * This file contains the window object, this object is a top level container
19  * which has the event management as well.
20  */
21 
22 #pragma once
23 
24 #include "formula/callable.hpp"
25 #include "formula/function.hpp"
30 #include "gui/widgets/panel.hpp"
31 #include "gui/widgets/retval.hpp"
32 
33 #include "sdl/texture.hpp"
34 
35 #include <functional>
36 #include <map>
37 #include <memory>
38 #include <string>
39 #include <vector>
40 
41 struct point;
42 
43 namespace gui2
44 {
45 
46 class widget;
47 namespace event { struct message; }
48 
49 // ------------ WIDGET -----------{
50 
51 namespace dialogs { class modal_dialog; }
52 class debug_layout_graph;
53 class pane;
54 
55 namespace event
56 {
57 class distributor;
58 } // namespace event
59 
60 /**
61  * @ingroup GUIWidgetWML
62  *
63  * base class of top level items, the only item which needs to store the final canvases to draw on.
64  * A window is a kind of panel see the panel for which fields exist.
65  */
66 class window : public panel, public top_level_drawable
67 {
68  friend class debug_layout_graph;
69  friend std::unique_ptr<window> build(const builder_window::window_resolution&);
70  friend struct window_implementation;
72  friend class pane;
73 
74 public:
75  explicit window(const builder_window::window_resolution& definition);
76 
77  virtual ~window();
78 
79  /**
80  * Returns the instance of a window.
81  *
82  * @param handle The instance id of the window.
83  *
84  * @returns The window or nullptr.
85  */
86  static window* window_instance(const unsigned handle);
87 
88  /** Gets the retval for the default buttons. */
89  static retval get_retval_by_id(const std::string& id);
90 
92 
93  /**
94  * Shows the window, running an event loop until it should close.
95  *
96  * @param auto_close_timeout The time in ms after which the window will
97  * automatically close, if 0 it doesn't close.
98  * @note the timeout is a minimum time and
99  * there's no guarantee about how fast it closes
100  * after the minimum.
101  *
102  * @returns The close code of the window, predefined
103  * values are listed in retval.
104  */
105  int show(unsigned auto_close_timeout = 0);
106 
107  /**
108  * Shows the window as a tooltip.
109  *
110  * A tooltip can't be interacted with and is just shown.
111  *
112  * @todo implement @p auto_close_timeout.
113  *
114  * @p auto_close_timeout The time in ms after which the window will
115  * automatically close, if 0 it doesn't close.
116  * @note the timeout is a minimum time and
117  * there's no guarantee about how fast it closes
118  * after the minimum.
119  */
120  void show_tooltip(/*const unsigned auto_close_timeout = 0*/);
121 
122  /**
123  * Shows the window non modal.
124  *
125  * A tooltip can be interacted with unlike the tooltip.
126  *
127  * @todo implement @p auto_close_timeout.
128  *
129  * @p auto_close_timeout The time in ms after which the window will
130  * automatically close, if 0 it doesn't close.
131  * @note the timeout is a minimum time and
132  * there's no guarantee about how fast it closes
133  * after the minimum.
134  */
135  void show_non_modal(/*const unsigned auto_close_timeout = 0*/);
136 
137  /**
138  * Draws the window.
139  *
140  * This routine draws the window if needed, it's called from the event
141  * handler. This is done by a drawing event. When a window is shown it
142  * manages an SDL timer which fires a drawing event every X milliseconds,
143  * that event calls this routine. Don't call it manually.
144  */
145  void draw();
146 
147  /** Hides the window. It will not draw until it is shown again. */
148  void hide();
149 
150  /**
151  * Lays out the window.
152  *
153  * This part does the pre and post processing for the actual layout
154  * algorithm.
155  *
156  * See @ref layout_algorithm for more information.
157  *
158  * This is also called by draw_manager to finalize screen layout.
159  */
160  virtual void layout() override;
161 
162  /** Called by draw_manager when it believes a redraw is necessary. */
163  virtual bool expose(const rect& region) override;
164 
165  /** The current draw location of the window, on the screen. */
166  virtual rect screen_location() override;
167 
168  /** The status of the window. */
169  enum class status {
170  NEW, /**< The window is new and not yet shown. */
171  SHOWING, /**< The window is being shown. */
172  REQUEST_CLOSE, /**< The window has been requested to be closed but still needs to evaluate the request. */
173  CLOSED /**< The window has been closed. */
174  };
175 
176  /**
177  * Requests to close the window.
178  *
179  * At the moment the request is always honored but that might change in the
180  * future.
181  */
182  void close()
183  {
185  }
186 
187  /**
188  * Helper class to block invalidate_layout.
189  *
190  * Some widgets can handling certain layout aspects without help. For
191  * example a listbox can handle hiding and showing rows without help but
192  * setting the visibility calls invalidate_layout(). When this blocker is
193  * Instantiated the call to invalidate_layout() becomes a nop.
194  *
195  * @note The class can't be used recursively.
196  */
198  {
199  public:
202 
203  private:
205  };
206 
207  /** Is invalidate_layout blocked, see invalidate_layout_blocker. */
209  {
211  }
212 
213  /**
214  * Updates the size of the window.
215  *
216  * If the window has automatic placement set this function recalculates the
217  * window. To be used after creation and after modification or items which
218  * can have different sizes eg listboxes.
219  */
220  void invalidate_layout();
221 
222  /** See @ref widget::find_at. */
223  virtual widget* find_at(const point& coordinate,
224  const bool must_be_active) override;
225 
226  /** See @ref widget::find_at. */
227  virtual const widget* find_at(const point& coordinate,
228  const bool must_be_active) const override;
229 
230  /** Inherited from widget. */
232  {
233  return owner_;
234  }
235 
236  /** See @ref widget::find. */
237  widget* find(const std::string& id, const bool must_be_active) override;
238 
239  /** See @ref widget::find. */
240  const widget* find(const std::string& id,
241  const bool must_be_active) const override;
242 
243 #if 0
244  /** @todo Implement these functions. */
245  /**
246  * Register a widget that prevents easy closing.
247  *
248  * Duplicate registration are ignored. See click_dismiss_ for more info.
249  *
250  * @param id The id of the widget to register.
251  */
252  void add_click_dismiss_blocker(const std::string& id);
253 
254  /**
255  * Unregister a widget the prevents easy closing.
256  *
257  * Removing a non registered id is allowed but will do nothing. See
258  * click_dismiss_ for more info.
259  *
260  * @param id The id of the widget to register.
261  */
262  void remove_click_dismiss_blocker(const std::string& id);
263 #endif
264 
265  /**
266  * Does the window close easily?
267  *
268  * The behavior can change at run-time, but that might cause oddities
269  * with the easy close button (when one is needed).
270  *
271  * @returns Whether or not the window closes easily.
272  */
273  bool does_click_dismiss() const
274  {
276  }
277 
278  /**
279  * Disable the enter key.
280  *
281  * This is added to block dialogs from being closed automatically.
282  *
283  * @todo this function should be merged with the hotkey support once
284  * that has been added.
285  */
286  void set_enter_disabled(const bool enter_disabled)
287  {
288  enter_disabled_ = enter_disabled;
289  }
290 
291  /**
292  * Disable the escape key.
293  *
294  * This is added to block dialogs from being closed automatically.
295  *
296  * @todo this function should be merged with the hotkey support once
297  * that has been added.
298  */
299  void set_escape_disabled(const bool escape_disabled)
300  {
301  escape_disabled_ = escape_disabled;
302  }
303 
304  /**
305  * Initializes a linked size group.
306  *
307  * Note at least one of fixed_width or fixed_height must be true.
308  *
309  * @param id The id of the group.
310  * @param fixed_width Does the group have a fixed width?
311  * @param fixed_height Does the group have a fixed height?
312  */
313  void init_linked_size_group(const std::string& id,
314  const bool fixed_width,
315  const bool fixed_height);
316 
317  /**
318  * Is the linked size group defined for this window?
319  *
320  * @param id The id of the group.
321  *
322  * @returns True if defined, false otherwise.
323  */
324  bool has_linked_size_group(const std::string& id);
325 
326  /**
327  * Adds a widget to a linked size group.
328  *
329  * The group needs to exist, which is done by calling
330  * init_linked_size_group. A widget may only be member of one group.
331  * @todo Untested if a new widget is added after showing the widgets.
332  *
333  * @param id The id of the group.
334  * @param widget The widget to add to the group.
335  */
336  void add_linked_widget(const std::string& id, widget* widget);
337 
338  /**
339  * Removes a widget from a linked size group.
340  *
341  * The group needs to exist, which is done by calling
342  * init_linked_size_group. If the widget is no member of the group the
343  * function does nothing.
344  *
345  * @param id The id of the group.
346  * @param widget The widget to remove from the group.
347  */
348  void remove_linked_widget(const std::string& id, const widget* widget);
349 
350  /***** ***** ***** setters / getters for members ***** ****** *****/
351 
352  /**
353  * Sets there return value of the window.
354  *
355  * @param retval The return value for the window.
356  * @param close_window Close the window after setting the value.
357  */
358  void set_retval(const int retval, const bool close_window = true)
359  {
360  retval_ = retval;
361  if(close_window)
362  close();
363  }
364 
366  {
367  return retval_;
368  }
369 
371  {
372  owner_ = owner;
373  }
374 
376  {
378  }
379 
380  bool get_need_layout() const
381  {
382  return need_layout_;
383  }
384 
385  void set_variable(const std::string& key, const wfl::variant& value)
386  {
387  variables_.add(key, value);
388  queue_redraw();
389  }
390  point get_linked_size(const std::string& linked_group_id) const
391  {
392  std::map<std::string, linked_size>::const_iterator it = linked_size_.find(linked_group_id);
393  if(it != linked_size_.end()) {
394  return point(it->second.width, it->second.height);
395  }
396 
397  return point(-1, -1);
398  }
399 
400  enum class exit_hook {
401  /** Always run hook */
402  on_all,
403  /** Run hook *only* if result is OK. */
404  on_ok,
405  };
406 
407  /**
408  * Sets the window's exit hook.
409  *
410  * A window will only close if the given function returns true under the specified mode.
411  */
412  void set_exit_hook(exit_hook mode, std::function<bool(window&)> func)
413  {
414  exit_hook_ = [mode, func](window& w) {
415  switch(mode) {
416  case exit_hook::on_all:
417  return func(w);
418  case exit_hook::on_ok:
419  return w.get_retval() != OK || func(w);
420  default:
421  return true;
422  }
423  };
424  }
425 
426  enum class show_mode {
427  none,
428  modal,
429  modeless,
430  tooltip
431  };
432 
433 private:
434  /** The status of the window. */
436 
437  /**
438  * The mode in which the window is shown.
439  *
440  * This is used to determine whether or not to remove the tip.
441  */
443 
444  // return value of the window, 0 default.
445  int retval_;
446 
447  /** The dialog that owns the window. */
449 
450  /**
451  * When set the form needs a full layout redraw cycle.
452  *
453  * This happens when either a widget changes it's size or visibility or
454  * the window is resized.
455  */
457 
458  /** The variables of the canvas. */
460 
461  /** Is invalidate_layout blocked, see invalidate_layout_blocker. */
463 
464  /** Avoid drawing the window. */
465  bool hidden_;
466 
467  /** Do we wish to place the widget automatically? */
469 
470  /**
471  * Sets the horizontal placement.
472  *
473  * Only used if automatic_placement_ is true.
474  * The value should be a grid placement flag.
475  */
476  const unsigned horizontal_placement_;
477 
478  /**
479  * Sets the vertical placement.
480  *
481  * Only used if automatic_placement_ is true.
482  * The value should be a grid placement flag.
483  */
484  const unsigned vertical_placement_;
485 
486  /** The maximum width if automatic_placement_ is true. */
488 
489  /** The maximum height if automatic_placement_ is true. */
491 
492  /** The formula to calculate the x value of the dialog. */
494 
495  /** The formula to calculate the y value of the dialog. */
497 
498  /** The formula to calculate the width of the dialog. */
500 
501  /** The formula to calculate the height of the dialog. */
503 
504  /** The formula to determine whether the size is good. */
506 
507  /** The formula definitions available for the calculation formulas. */
509 
510  /** The settings for the tooltip. */
512 
513  /** The settings for the helptip. */
515 
516  /**
517  * Do we want to have easy close behavior?
518  *
519  * Easy closing means that whenever a mouse click is done the dialog will
520  * be closed. The widgets in the window may override this behavior by
521  * registering themselves as blockers. This is tested by the function
522  * disable_click_dismiss().
523  *
524  * The handling of easy close is done in the window, in order to do so a
525  * window either needs a click_dismiss or an ok button. Both will be hidden
526  * when not needed and when needed first the ok is tried and then the
527  * click_dismiss button. this allows adding a click_dismiss button to the
528  * window definition and use the ok from the window instance.
529  *
530  * @todo After testing the click dismiss feature it should be documented in
531  * the wiki.
532  */
534 
535  /** Disable the enter key see our setter for more info. */
537 
538  /** Disable the escape key see our setter for more info. */
540 
541  /**
542  * Helper struct to force widgets the have the same size.
543  *
544  * Widget which are linked will get the same width and/or height. This
545  * can especially be useful for listboxes, but can also be used for other
546  * applications.
547  */
548  struct linked_size
549  {
550  linked_size(const bool width = false, const bool height = false)
551  : widgets(), width(width ? 0 : -1), height(height ? 0 : -1)
552  {
553  }
554 
555  /** The widgets linked. */
556  std::vector<widget*> widgets;
557 
558  /** The current width of all widgets in the group, -1 if the width is not linked. */
559  int width;
560 
561  /** The current height of all widgets in the group, -1 if the height is not linked. */
562  int height;
563  };
564 
565  /** List of the widgets, whose size are linked together. */
566  std::map<std::string, linked_size> linked_size_;
567 
568  /** List of widgets in the tabbing order. */
569  std::vector<widget*> tab_order;
570 
571  /**
572  * Layouts the linked widgets.
573  *
574  * See @ref layout_algorithm for more information.
575  */
576  void layout_linked_widgets();
577 
578  /**
579  * Handles a mouse click event for dismissing the dialog.
580  *
581  * @param mouse_button_mask The SDL_BUTTON mask for the button used to
582  * dismiss the click. If the caller is from the
583  * keyboard code the value should be 0.
584  *
585  * @return Whether the event should be considered as
586  * handled.
587  */
588  bool click_dismiss(const int mouse_button_mask);
589 
590  /**
591  * The state of the mouse button.
592  *
593  * When click dismissing a dialog in the past the DOWN event was used.
594  * This lead to a bug [1]. The obvious change was to switch to the UP
595  * event, this lead to another bug; the dialog was directly dismissed.
596  * Since the game map code uses the UP and DOWN event to select a unit
597  * there is no simple solution.
598  *
599  * Upon entry this value stores the mouse button state at entry. When a
600  * button is DOWN and goes UP that button does \em not trigger a dismissal
601  * of the dialog, instead that button's down state is removed from this
602  * variable. Therefore the next UP event does dismiss the dialog.
603  *
604  * [1] https://gna.org/bugs/index.php?18970
605  */
607 
608 public:
609  /** Static type getter that does not rely on the widget being constructed. */
610  static const std::string& type();
611 
612 private:
613  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
614  virtual const std::string& get_control_type() const override;
615 
616  /**
617  * In how many consecutive frames the window has changed. This is used to
618  * detect the situation where the title screen changes in every frame,
619  * forcing all other windows to redraw everything all the time.
620  */
621  unsigned int consecutive_changed_frames_ = 0u;
622 
623  /** Schedules windows on top of us (if any) to redraw. */
624  void redraw_windows_on_top() const;
625 
626  /**
627  * Finishes the initialization of the grid.
628  *
629  * @param content_grid The new contents for the content grid.
630  */
631  void finalize(const builder_grid& content_grid);
632 
633 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
634  debug_layout_graph* debug_layout_;
635 
636 public:
637  /** wrapper for debug_layout_graph::generate_dot_file. */
638  void generate_dot_file(const std::string& generator, const unsigned domain);
639 
640 private:
641 #else
642  void generate_dot_file(const std::string&, const unsigned)
643  {
644  }
645 #endif
646 
647  std::unique_ptr<event::distributor> event_distributor_;
648 
649 public:
650  /** Gets a reference to the window's distributor to allow some state peeking. */
652  {
653  return *event_distributor_;
654  }
655 
656  /** Returns the dialog mode for this window. */
657  show_mode mode() const
658  {
659  return show_mode_;
660  }
661 
662  // mouse and keyboard_capture should be renamed and stored in the
663  // dispatcher. Chaining probably should remain exclusive to windows.
664  void mouse_capture(const bool capture = true);
666 
667  /**
668  * Adds the widget to the keyboard chain.
669  *
670  * @todo rename to keyboard_add_to_chain.
671  * @param widget The widget to add to the chain. The widget
672  * should be valid widget, which hasn't been
673  * added to the chain yet.
674  */
676 
677  /**
678  * Remove the widget from the keyboard chain.
679  *
680  * @todo rename to keyboard_remove_from_chain.
681  *
682  * @param widget The widget to be removed from the chain.
683  */
685 
686  /**
687  * Add the widget to the tabbing order
688  * @param widget The widget to be added to the tabbing order
689  * @param at A hint for where to place the widget in the tabbing order
690  */
691  void add_to_tab_order(widget* widget, int at = -1);
692 
693 private:
694  /***** ***** ***** signal handlers ***** ****** *****/
695 
697  bool& handled,
698  const point& new_size);
699 
700  /**
701  * The handler for the click dismiss mouse 'event'.
702  *
703  * @param event See @ref event::dispatcher::fire.
704  * @param handled See @ref event::dispatcher::fire.
705  * @param halt See @ref event::dispatcher::fire.
706  * @param mouse_button_mask Forwared to @ref click_dismiss.
707  */
709  bool& handled,
710  bool& halt,
711  const int mouse_button_mask);
712 
714  bool& handled,
715  const SDL_Keycode key,
716  const SDL_Keymod mod,
717  bool handle_tab);
718 
720  bool& handled,
721  const event::message& message);
722 
724  bool& handled,
725  const event::message& message);
726 
728  bool& handled);
729 
731 
732  std::function<bool(window&)> exit_hook_;
733 };
734 
735 // }---------- DEFINITION ---------{
736 
738 {
739  explicit window_definition(const config& cfg);
740 
742  {
743  explicit resolution(const config& cfg);
744 
746  };
747 };
748 
749 // }------------ END --------------
750 
751 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Main class to show messages to the user.
Definition: message.hpp:36
Abstract base class for all modal dialogs.
Class to show the tips.
Definition: tooltip.cpp:58
The event handler class for the widget library.
Basic template class to generate new items.
A pane is a container where new members can be added and removed during run-time.
Definition: pane.hpp:44
A panel is a visible container to hold multiple widgets.
Definition: panel.hpp:59
A top-level drawable item (TLD), such as a window.
Base class for all widgets.
Definition: widget.hpp:54
void queue_redraw()
Indicates that this widget should be redrawn.
Definition: widget.cpp:442
friend class window
Definition: widget.hpp:56
Helper class to block invalidate_layout.
Definition: window.hpp:198
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:67
void set_enter_disabled(const bool enter_disabled)
Disable the enter key.
Definition: window.hpp:286
bool need_layout_
When set the form needs a full layout redraw cycle.
Definition: window.hpp:456
void set_retval(const int retval, const bool close_window=true)
Sets there return value of the window.
Definition: window.hpp:358
std::function< bool(window &)> exit_hook_
Definition: window.hpp:732
show_mode mode() const
Returns the dialog mode for this window.
Definition: window.hpp:657
const unsigned vertical_placement_
Sets the vertical placement.
Definition: window.hpp:484
bool invalidate_layout_blocked_
Is invalidate_layout blocked, see invalidate_layout_blocker.
Definition: window.hpp:462
typed_formula< bool > reevaluate_best_size_
The formula to determine whether the size is good.
Definition: window.hpp:505
typed_formula< unsigned > maximum_width_
The maximum width if automatic_placement_ is true.
Definition: window.hpp:487
void remove_from_keyboard_chain(widget *widget)
Remove the widget from the keyboard chain.
Definition: window.cpp:1142
void keyboard_capture(widget *widget)
Definition: window.cpp:1130
void invalidate_layout()
Updates the size of the window.
Definition: window.cpp:682
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
Definition: window.cpp:1136
void signal_handler_message_show_tooltip(const event::ui_event event, bool &handled, const event::message &message)
Definition: window.cpp:1255
void mouse_capture(const bool capture=true)
Definition: window.cpp:1124
typed_formula< unsigned > maximum_height_
The maximum height if automatic_placement_ is true.
Definition: window.hpp:490
virtual rect screen_location() override
The current draw location of the window, on the screen.
Definition: window.cpp:661
void show_tooltip()
Shows the window as a tooltip.
Definition: window.cpp:453
int mouse_button_state_
The state of the mouse button.
Definition: window.hpp:606
void finish_build(const builder_window::window_resolution &)
Definition: window.cpp:426
void hide()
Hides the window.
Definition: window.cpp:633
void show_non_modal()
Shows the window non modal.
Definition: window.cpp:485
std::unique_ptr< event::distributor > event_distributor_
Definition: window.hpp:647
void signal_handler_sdl_video_resize(const event::ui_event event, bool &handled, const point &new_size)
Definition: window.cpp:1164
void set_exit_hook(exit_hook mode, std::function< bool(window &)> func)
Sets the window's exit hook.
Definition: window.hpp:412
virtual ~window()
Definition: window.cpp:368
unsigned int consecutive_changed_frames_
In how many consecutive frames the window has changed.
Definition: window.hpp:621
static window * window_instance(const unsigned handle)
Returns the instance of a window.
Definition: window.cpp:408
void close()
Requests to close the window.
Definition: window.hpp:182
status
The status of the window.
Definition: window.hpp:169
@ CLOSED
The window has been closed.
@ NEW
The window is new and not yet shown.
@ SHOWING
The window is being shown.
@ REQUEST_CLOSE
The window has been requested to be closed but still needs to evaluate the request.
builder_window::window_resolution::tooltip_info tooltip_
The settings for the tooltip.
Definition: window.hpp:511
bool invalidate_layout_blocked() const
Is invalidate_layout blocked, see invalidate_layout_blocker.
Definition: window.hpp:208
void signal_handler_sdl_key_down(const event::ui_event event, bool &handled, const SDL_Keycode key, const SDL_Keymod mod, bool handle_tab)
Definition: window.cpp:1198
virtual void layout() override
Lays out the window.
Definition: window.cpp:759
void signal_handler_message_show_helptip(const event::ui_event event, bool &handled, const event::message &message)
Definition: window.cpp:1269
dialogs::modal_dialog * dialog()
Inherited from widget.
Definition: window.hpp:231
void layout_linked_widgets()
Layouts the linked widgets.
Definition: window.cpp:961
show_mode show_mode_
The mode in which the window is shown.
Definition: window.hpp:442
std::vector< widget * > tab_order
List of widgets in the tabbing order.
Definition: window.hpp:569
typed_formula< unsigned > h_
The formula to calculate the height of the dialog.
Definition: window.hpp:502
int show(unsigned auto_close_timeout=0)
Shows the window, running an event loop until it should close.
Definition: window.cpp:519
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
void signal_handler_request_placement(const event::ui_event event, bool &handled)
Definition: window.cpp:1283
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
Definition: window.cpp:699
friend class debug_layout_graph
Definition: window.hpp:68
bool escape_disabled_
Disable the escape key see our setter for more info.
Definition: window.hpp:539
bool does_click_dismiss() const
Does the window close easily?
Definition: window.hpp:273
void signal_handler_close_window()
Definition: window.cpp:1293
bool click_dismiss_
Do we want to have easy close behavior?
Definition: window.hpp:533
void redraw_windows_on_top() const
Schedules windows on top of us (if any) to redraw.
void set_escape_disabled(const bool escape_disabled)
Disable the escape key.
Definition: window.hpp:299
void add_linked_widget(const std::string &id, widget *widget)
Adds a widget to a linked size group.
Definition: window.cpp:725
const unsigned horizontal_placement_
Sets the horizontal placement.
Definition: window.hpp:476
static retval get_retval_by_id(const std::string &id)
Gets the retval for the default buttons.
Definition: window.cpp:413
bool get_need_layout() const
Definition: window.hpp:380
void set_click_dismiss(const bool click_dismiss)
Definition: window.hpp:375
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1148
const bool automatic_placement_
Do we wish to place the widget automatically?
Definition: window.hpp:468
void finalize(const builder_grid &content_grid)
Finishes the initialization of the grid.
Definition: window.cpp:1020
int get_retval()
Definition: window.hpp:365
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
builder_window::window_resolution::tooltip_info helptip_
The settings for the helptip.
Definition: window.hpp:514
bool hidden_
Avoid drawing the window.
Definition: window.hpp:465
bool click_dismiss(const int mouse_button_mask)
Handles a mouse click event for dismissing the dialog.
Definition: window.cpp:1007
typed_formula< unsigned > x_
The formula to calculate the x value of the dialog.
Definition: window.hpp:493
typed_formula< unsigned > y_
The formula to calculate the y value of the dialog.
Definition: window.hpp:496
void set_variable(const std::string &key, const wfl::variant &value)
Definition: window.hpp:385
point get_linked_size(const std::string &linked_group_id) const
Definition: window.hpp:390
void generate_dot_file(const std::string &, const unsigned)
Definition: window.hpp:642
virtual bool expose(const rect &region) override
Called by draw_manager when it believes a redraw is necessary.
Definition: window.cpp:649
wfl::map_formula_callable variables_
The variables of the canvas.
Definition: window.hpp:459
void remove_linked_widget(const std::string &id, const widget *widget)
Removes a widget from a linked size group.
Definition: window.cpp:739
void signal_handler_click_dismiss(const event::ui_event event, bool &handled, bool &halt, const int mouse_button_mask)
The handler for the click dismiss mouse 'event'.
Definition: window.cpp:1179
const event::distributor & get_distributor() const
Gets a reference to the window's distributor to allow some state peeking.
Definition: window.hpp:651
bool enter_disabled_
Disable the enter key see our setter for more info.
Definition: window.hpp:536
@ on_all
Always run hook.
@ on_ok
Run hook only if result is OK.
dialogs::modal_dialog * owner_
The dialog that owns the window.
Definition: window.hpp:448
void init_linked_size_group(const std::string &id, const bool fixed_width, const bool fixed_height)
Initializes a linked size group.
Definition: window.cpp:710
void draw()
Draws the window.
Definition: window.cpp:615
typed_formula< unsigned > w_
The formula to calculate the width of the dialog.
Definition: window.hpp:499
wfl::function_symbol_table functions_
The formula definitions available for the calculation formulas.
Definition: window.hpp:508
void set_owner(dialogs::modal_dialog *owner)
Definition: window.hpp:370
status status_
The status of the window.
Definition: window.hpp:435
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
Definition: window.cpp:688
std::map< std::string, linked_size > linked_size_
List of the widgets, whose size are linked together.
Definition: window.hpp:566
bool has_linked_size_group(const std::string &id)
Is the linked size group defined for this window?
Definition: window.cpp:720
friend std::unique_ptr< window > build(const builder_window::window_resolution &)
Builds a window.
map_formula_callable & add(const std::string &key, const variant &value)
Definition: callable.hpp:253
int w
Various uncategorised dialogs.
void point(int x, int y)
Draw a single point.
Definition: draw.cpp:193
ui_event
The event sent to the dispatcher.
Definition: handler.hpp:115
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
retval
Default window/dialog return values.
Definition: retval.hpp:30
@ OK
Dialog was closed with the OK button.
Definition: retval.hpp:35
std::shared_ptr< halo_record > handle
Definition: halo.hpp:31
static std::string at(const std::string &file, int line)
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
Helper struct to store information about the tips.
The message callbacks hold a reference to a message.
Definition: message.hpp:46
Helper struct to force widgets the have the same size.
Definition: window.hpp:549
int height
The current height of all widgets in the group, -1 if the height is not linked.
Definition: window.hpp:562
linked_size(const bool width=false, const bool height=false)
Definition: window.hpp:550
int width
The current width of all widgets in the group, -1 if the width is not linked.
Definition: window.hpp:559
std::vector< widget * > widgets
The widgets linked.
Definition: window.hpp:556
window_definition(const config &cfg)
Definition: window.cpp:1300
Helper to implement private functions without modifying the header.
Holds a 2D point.
Definition: point.hpp:25
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:47