Ocean
WxDialog.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_WXWIDGETS_WX_DIALOG_H
9 #define META_OCEAN_PLATFORM_WXWIDGETS_WX_DIALOG_H
10 
12 
13 #include "ocean/base/Lock.h"
14 #include "ocean/base/ObjectRef.h"
15 #include "ocean/base/Timestamp.h"
16 
17 #include <wx/dialog.h>
18 #include <wx/evtloop.h>
19 
20 namespace Ocean
21 {
22 
23 namespace Platform
24 {
25 
26 namespace WxWidgets
27 {
28 
29 /**
30  * This class implements a modal dialog for WxWidgets which in addition to the standard wxDialog implementation forces the modal-event-loop to stop if the dialog ends (the modal state).
31  * @ingroup platformwxwidgets
32  */
33 class OCEAN_PLATFORM_WXWIDGETS_EXPORT WxDialog : public wxDialog
34 {
35  protected:
36 
37 #ifdef _WINDOWS
38 
39  /**
40  * This class implements an event loop.
41  */
42  class OCEAN_PLATFORM_WXWIDGETS_EXPORT EventLoop : public wxModalEventLoop
43  {
44  public:
45 
46  /**
47  * Creates a new event loop object.
48  * @param winModal The window which will be owner of the event loop
49  */
50  explicit EventLoop(wxWindow *winModal);
51 
52  /**
53  * Returns whether any event is available.
54  * @return True, if so
55  */
56  virtual bool Pending() const;
57 
58  /**
59  * Exits this currently running loop with the given exit code.
60  * @param returnCode The return code
61  */
62  virtual void Exit(int returnCode = 0);
63 
64  protected:
65 
66  /// The timestamp this event loop has been exited.
68  };
69 
70  /**
71  * Definition of an object reference for event loop objects.
72  */
74 
75 #endif
76 
77  public:
78 
79  /**
80  * Creates a new dialog object.
81  * @param parent The parent window, may be nullptr
82  * @param id The id of the new dialog
83  * @param title The title of the new dialog
84  * @param pos Horizontal and vertical position of the new dialog, in pixel with range (-infinity, infinity)x(-infinity, infinity)
85  * @param size The width and height of the new dialog, in pixel with range [0, infinity)x[0, infinity)
86  * @param style The style of the new dialog
87  * @param name The optional name of the new dialog
88  */
89  explicit WxDialog(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = wxDialogNameStr);
90 
91  /**
92  * Destructs a dialog object.
93  */
94  ~WxDialog() override;
95 
96 #ifdef OCEAN_PLATFORM_BUILD_WINDOWS
97 
98  /**
99  * Returns whether this dialog is currently showing modally.
100  * @return True, if so
101  */
102  virtual bool IsModal() const;
103 
104  /**
105  * Shows or hides this dialog (not modally).
106  * @param show True, to show the dialog; False, to hide the dialog
107  * @return True, if succeeded
108  */
109  virtual bool Show(bool show = true);
110 
111  /**
112  * Shows this dialog modally.
113  * @return The return code of the modal call
114  */
115  virtual int ShowModal();
116 
117  /**
118  * Ends the modally shown dialog.
119  * @param retCode The return code of the modal call
120  */
121  virtual void EndModal(int retCode);
122 
123  protected:
124 
125  /// The event loop of this dialog for modal executions.
127 
128  /// The lock for the event loop.
130 
131 #endif // OCEAN_PLATFORM_BUILD_WINDOWS
132 
133  /// True, if the modal execution of this dialog ends.
134  bool endModalCalled_ = false;
135 };
136 
137 }
138 
139 }
140 
141 }
142 
143 #endif // META_OCEAN_PLATFORM_WXWIDGETS_WX_DIALOG_H
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements an event loop.
Definition: WxDialog.h:43
virtual bool Pending() const
Returns whether any event is available.
EventLoop(wxWindow *winModal)
Creates a new event loop object.
Timestamp exitTimestamp_
The timestamp this event loop has been exited.
Definition: WxDialog.h:67
virtual void Exit(int returnCode=0)
Exits this currently running loop with the given exit code.
This class implements a modal dialog for WxWidgets which in addition to the standard wxDialog impleme...
Definition: WxDialog.h:34
virtual bool IsModal() const
Returns whether this dialog is currently showing modally.
virtual void EndModal(int retCode)
Ends the modally shown dialog.
~WxDialog() override
Destructs a dialog object.
ObjectRef< EventLoop > EventLoopRef
Definition of an object reference for event loop objects.
Definition: WxDialog.h:73
virtual int ShowModal()
Shows this dialog modally.
WxDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=wxDialogNameStr)
Creates a new dialog object.
virtual bool Show(bool show=true)
Shows or hides this dialog (not modally).
Lock eventLoopLock_
The lock for the event loop.
Definition: WxDialog.h:129
EventLoopRef eventLoop_
The event loop of this dialog for modal executions.
Definition: WxDialog.h:126
This class implements a timestamp.
Definition: Timestamp.h:36
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15