1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/dialog.cpp
3 // Purpose: wxDialog class
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/dialog.h"
20 #include "wx/settings.h"
25 #include "wx/os2/private.h"
26 #include "wx/evtloop.h"
27 #include "wx/scopedptr.h"
28 #include "wx/modalhook.h"
30 #define wxDIALOG_DEFAULT_X 300
31 #define wxDIALOG_DEFAULT_Y 300
33 #define wxDIALOG_DEFAULT_WIDTH 500
34 #define wxDIALOG_DEFAULT_HEIGHT 500
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // this is simply a container for any data we need to implement modality which
42 // allows us to avoid changing wxDialog each time the implementation changes
43 class wxDialogModalData
46 wxDialogModalData(wxDialog
*dialog
) : m_evtLoop(dialog
) { }
59 wxModalEventLoop m_evtLoop
;
62 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxDialogModalData
);
64 // ============================================================================
66 // ============================================================================
68 // ----------------------------------------------------------------------------
69 // wxDialog construction
70 // ----------------------------------------------------------------------------
76 m_pWindowDisabler
= NULL
;
78 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
79 } // end of wxDialog::Init
81 bool wxDialog::Create( wxWindow
* pParent
,
83 const wxString
& rsTitle
,
87 const wxString
& rsName
)
90 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
93 // Save focus before doing anything which can potentially change it
95 m_pOldFocus
= FindFocus();
98 // All dialogs should really have this style
100 lStyle
|= wxTAB_TRAVERSAL
;
102 if (!wxTopLevelWindow::Create( pParent
112 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
115 // Must defer setting the title until after dialog is created and sized
117 if ( !rsTitle
.empty() )
120 } // end of wxDialog::Create
122 #if WXWIN_COMPATIBILITY_2_6
125 wxDialog::wxDialog(wxWindow
*parent
,
126 const wxString
& title
,
127 bool WXUNUSED(modal
),
133 const wxString
& name
)
137 Create(parent
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(w
, h
), style
, name
);
140 void wxDialog::SetModal(bool WXUNUSED(bFlag
))
142 // nothing to do, obsolete method
143 } // end of wxDialog::SetModal
145 #endif // WXWIN_COMPATIBILITY_2_6
147 wxDialog::~wxDialog()
151 // this will also reenable all the other windows for a modal dialog
153 } // end of wxDialog::~wxDialog
155 // ----------------------------------------------------------------------------
156 // showing the dialogs
157 // ----------------------------------------------------------------------------
159 #if WXWIN_COMPATIBILITY_2_6
161 bool wxDialog::IsModalShowing() const
164 } // end of wxDialog::IsModalShowing
166 #endif // WXWIN_COMPATIBILITY_2_6
168 bool wxDialog::Show( bool bShow
)
170 if ( bShow
== IsShown() )
173 if (!bShow
&& m_modalData
)
175 // we need to do this before calling wxDialogBase version because if we
176 // had disabled other app windows, they must be reenabled right now as
177 // if they stay disabled Windows will activate another window (one
178 // which is enabled, anyhow) when we're hidden in the base class Show()
179 // and we will lose activation
180 m_modalData
->ExitLoop();
182 wxDELETE(m_pWindowDisabler
);
188 if (CanDoLayoutAdaptation())
189 DoLayoutAdaptation();
191 // this usually will result in TransferDataToWindow() being called
192 // which will change the controls values so do it before showing as
193 // otherwise we could have some flicker
197 wxDialogBase::Show(bShow
);
199 wxString title
= GetTitle();
201 ::WinSetWindowText((HWND
)GetHwnd(), title
.c_str());
205 // dialogs don't get WM_SIZE message after creation unlike most (all?)
206 // other windows and so could start their life not laid out correctly
207 // if we didn't call Layout() from here
209 // NB: normally we should call it just the first time but doing it
210 // every time is simpler than keeping a flag
215 } // end of wxDialog::Show
218 // Replacement for Show(true) for modal dialogs - returns return code
220 int wxDialog::ShowModal()
222 WX_HOOK_MODAL_DIALOG();
224 wxASSERT_MSG( !IsModal(), wxT("wxDialog::ShowModal() reentered?") );
226 m_endModalCalled
= false;
230 // EndModal may have been called from InitDialog handler (called from
231 // inside Show()), which would cause an infinite loop if we didn't take it
233 if ( !m_endModalCalled
)
235 // modal dialog needs a parent window, so try to find one
236 wxWindow
* const parent
= GetParentForModalDialog();
238 // remember where the focus was
239 wxWindow
*oldFocus
= m_pOldFocus
;
242 // VZ: do we really want to do this?
246 // We have to remember the HWND because we need to check
247 // the HWND still exists (oldFocus can be garbage when the dialog
248 // exits, if it has been destroyed)
249 HWND hwndOldFocus
= oldFocus
? GetHwndOf(oldFocus
) : NULL
;
253 // Before entering the modal loop, reset the "is in OnIdle()" flag (see
254 // comment in app.cpp)
256 extern bool gbInOnIdle
;
257 bool bWasInOnIdle
= gbInOnIdle
;
261 // enter and run the modal loop
263 wxDialogModalDataTiedPtr
modalData(&m_modalData
,
264 new wxDialogModalData(this));
265 modalData
->RunLoop();
267 gbInOnIdle
= bWasInOnIdle
;
270 // Note that this code MUST NOT access the dialog object's data
271 // in case the object has been deleted (which will be the case
272 // for a modal dialog that has been destroyed before calling EndModal).
273 if ( oldFocus
&& (oldFocus
!= this) && ::WinIsWindow(vHabmain
, hwndOldFocus
))
275 // This is likely to prove that the object still exists
276 if (wxFindWinFromHandle((WXHWND
) hwndOldFocus
) == oldFocus
)
277 oldFocus
->SetFocus();
281 return GetReturnCode();
282 } // end of wxDialog::ShowModal
284 void wxDialog::EndModal(
288 wxASSERT_MSG( IsModal(), wxT("EndModal() called for non modal dialog") );
290 m_endModalCalled
= true;
291 SetReturnCode(nRetCode
);
294 } // end of wxDialog::EndModal
296 MRESULT
wxDialog::OS2WindowProc( WXUINT uMessage
, WXWPARAM wParam
, WXLPARAM lParam
)
299 bool bProcessed
= false;
305 // If we can't close, tell the system that we processed the
306 // message - otherwise it would close us
308 bProcessed
= !Close();
313 rc
= wxWindow::OS2WindowProc( uMessage
318 } // end of wxDialog::OS2WindowProc