Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_window.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_WINDOW_H
7 #define TB_WINDOW_H
8 
9 #include "tb_widgets_common.h"
10 #include "tb_widgets_listener.h"
11 
12 namespace tb {
13 
20 
21  WINDOW_SETTINGS_DEFAULT = WINDOW_SETTINGS_TITLEBAR | WINDOW_SETTINGS_RESIZABLE |
23 };
24 MAKE_ENUM_FLAG_COMBO(WINDOW_SETTINGS);
25 
33 class TBWindow : public TBWidget
34 {
35 public:
36  // For safe typecasting
37  TBOBJECT_SUBCLASS(TBWindow, TBWidget);
38 
39  TBWindow();
40  ~TBWindow();
41 
44  void Close();
45 
47  bool IsActive() const;
48 
52  void Activate();
53 
59  bool EnsureFocus();
60 
64  void SetLastFocus(TBWidget *last_focus) { m_last_focus.Set(last_focus); }
65 
67  void SetSettings(WINDOW_SETTINGS settings);
68  WINDOW_SETTINGS GetSettings() { return m_settings; }
69 
71  enum RESIZE_FIT {
75  };
77 
80 
84 
86  virtual bool SetText(const TBStr &text) { return m_textfield.SetText(text); }
87  virtual bool GetText(TBStr &text) const { return m_textfield.GetText(text); }
88  using TBWidget::GetText;
89 
92  int GetTitleHeight();
93 
94  virtual TBRect GetPaddingRect();
95  virtual PreferredSize OnCalculatePreferredSize(const SizeConstraints &constraints);
96 
97  virtual bool OnEvent(const TBWidgetEvent &ev);
98  virtual void OnAdded();
99  virtual void OnRemove();
100  virtual void OnChildAdded(TBWidget *child);
101  virtual void OnResized(int old_w, int old_h);
102 
103 protected:
104  TBMover m_mover;
105  TBResizer m_resizer;
106  TBTextField m_textfield;
107  TBWidget m_close_button;
108  WINDOW_SETTINGS m_settings;
109  TBWidgetSafePointer m_last_focus;
110  TBWindow *GetTopMostOtherWindow(bool only_activable_windows);
111  void SetWindowActiveState(bool active);
112  void DeActivate();
113 };
114 
115 } // namespace tb
116 
117 #endif // TB_WINDOW_H
void Activate()
Activate this window if it's not already activated.
Definition: tb_window.cpp:92
TBTextField is a one line text field that is not editable.
Definition: tb_widgets_common.h:59
void Set(TBWidget *widget)
Set the widget pointer that should be nulled if deleted.
Definition: tb_widgets_listener.cpp:90
RESIZE_FIT
RESIZE_FIT specifies how ResizeToFitContent should resize the window.
Definition: tb_window.h:71
virtual void OnChildAdded(TBWidget *child)
Called when a child widget has been added to this widget (before calling OnAdded on child)...
Definition: tb_window.cpp:245
Chrome less window without any other settings.
Definition: tb_window.h:15
Fit the preferred size of all content.
Definition: tb_window.h:72
The base TBWidget class.
Definition: tb_widgets.h:418
TBWidgetSafePointer keeps a pointer to a widget that will be set to nullptr if the widget is removed...
Definition: tb_widgets_listener.h:74
virtual bool GetText(TBStr &text) const
Get the text of this widget.
Definition: tb_widgets_common.h:69
virtual bool SetText(const TBStr &text)
Set the window title.
Definition: tb_window.h:86
Definition: tb_widgets.h:112
TBWindow is a TBWidget that provides some window-like features.
Definition: tb_window.h:33
virtual bool SetText(const TBStr &text)
Set the text of the text field.
Definition: tb_widgets_common.cpp:84
virtual bool OnEvent(const TBWidgetEvent &ev)
Callback for handling events.
Definition: tb_window.cpp:218
void Close()
Close this window.
Definition: tb_window.cpp:65
Fit the minimal or maximum size only if needed.
Definition: tb_window.h:74
Fit the minimal size of all content.
Definition: tb_window.h:73
void SetSettings(WINDOW_SETTINGS settings)
Set settings for how this window should look and behave.
Definition: tb_window.cpp:145
Specifies size constraints used during size calculations.
Definition: tb_widgets.h:321
Show a widget for closing the window.
Definition: tb_window.h:18
int GetTitleHeight()
< Make all versions in base class available.
Definition: tb_window.cpp:183
virtual PreferredSize OnCalculatePreferredSize(const SizeConstraints &constraints)
Calculate the preferred size for this widget.
Definition: tb_window.cpp:199
WINDOW_SETTINGS
Definition: tb_window.h:14
TBRect GetResizeToFitContentRect(RESIZE_FIT fit=RESIZE_FIT_PREFERRED)
Get a suitable rect for the window based on the contents and the given fit.
Definition: tb_window.cpp:37
virtual void OnResized(int old_w, int old_h)
Called when this widget has been resized.
Definition: tb_window.cpp:250
bool IsActive() const
Return true if this window is active.
Definition: tb_window.cpp:70
virtual void OnRemove()
Called when a this widget has been removed from its parent (after calling OnChildRemove on parent)...
Definition: tb_window.cpp:236
TBStr is a simple string class.
Definition: tb_str.h:62
Can be activated and deactivate other windows.
Definition: tb_window.h:19
Simple rectangle class.
Definition: tb_geometry.h:25
TBResizer is a lower right corner resize grip.
Definition: tb_widgets_common.h:451
void SetLastFocus(TBWidget *last_focus)
Set the widget that should be focused when this window is activated next time.
Definition: tb_window.h:64
virtual TBRect GetPaddingRect()
Get the rectangle inside any padding, relative to this widget.
Definition: tb_window.cpp:190
bool EnsureFocus()
Ensure that this window has focus by attempting to find a focusable child widget. ...
Definition: tb_window.cpp:116
PreferredSize contains size preferences for a TBWidget.
Definition: tb_widgets.h:277
Show a widget for resizing the window.
Definition: tb_window.h:17
virtual void OnAdded()
Called when this widget has been added to a parent (after calling OnChildAdded on parent)...
Definition: tb_window.cpp:229
Show a title bar that can also move the window.
Definition: tb_window.h:16
TBMover is moving its parent widget when dragged.
Definition: tb_widgets_common.h:439
TBStr GetText() const
Get the text of this widget.
Definition: tb_widgets.h:942
void ResizeToFitContent(RESIZE_FIT fit=RESIZE_FIT_PREFERRED)
Resize the window to fit the its content.
Definition: tb_window.cpp:60
virtual bool GetText(TBStr &text) const
Get the text of this widget.
Definition: tb_window.h:87