1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/dialog.cpp 
   3 // Purpose:     wxDialog class 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #include "wx/dialog.h" 
  21     #include "wx/settings.h" 
  26 #include "wx/os2/private.h" 
  27 #include "wx/evtloop.h" 
  28 #include "wx/scopedptr.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 
  36 IMPLEMENT_DYNAMIC_CLASS(wxDialog
, wxTopLevelWindow
) 
  38 // ---------------------------------------------------------------------------- 
  40 // ---------------------------------------------------------------------------- 
  42 // this is simply a container for any data we need to implement modality which 
  43 // allows us to avoid changing wxDialog each time the implementation changes 
  44 class wxDialogModalData
 
  47     wxDialogModalData(wxDialog 
*dialog
) : m_evtLoop(dialog
) { } 
  60     wxModalEventLoop m_evtLoop
; 
  63 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxDialogModalData
); 
  65 // ============================================================================ 
  67 // ============================================================================ 
  69 // ---------------------------------------------------------------------------- 
  70 // wxDialog construction 
  71 // ---------------------------------------------------------------------------- 
  77     m_pWindowDisabler 
= NULL
; 
  79     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)); 
  80 } // end of wxDialog::Init 
  82 bool wxDialog::Create( wxWindow
*       pParent
, 
  84                        const wxString
& rsTitle
, 
  88                        const wxString
& rsName 
) 
  91     SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
); 
  94     // Save focus before doing anything which can potentially change it 
  96     m_pOldFocus 
= FindFocus(); 
  99     // All dialogs should really have this style 
 101     lStyle 
|= wxTAB_TRAVERSAL
; 
 103     if (!wxTopLevelWindow::Create( pParent
 
 113     SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
)); 
 116     // Must defer setting the title until after dialog is created and sized 
 118     if (!rsTitle
.IsNull()) 
 121 } // end of wxDialog::Create 
 123 #if WXWIN_COMPATIBILITY_2_6 
 126 wxDialog::wxDialog(wxWindow 
*parent
, 
 127                    const wxString
& title
, 
 128                    bool WXUNUSED(modal
), 
 134                    const wxString
& name
) 
 138     Create(parent
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(w
, h
), style
, name
); 
 141 void wxDialog::SetModal(bool WXUNUSED(bFlag
)) 
 143     // nothing to do, obsolete method 
 144 } // end of wxDialog::SetModal 
 146 #endif // WXWIN_COMPATIBILITY_2_6 
 148 wxDialog::~wxDialog() 
 152     // this will also reenable all the other windows for a modal dialog 
 154 } // end of wxDialog::~wxDialog 
 156 // ---------------------------------------------------------------------------- 
 157 // showing the dialogs 
 158 // ---------------------------------------------------------------------------- 
 160 #if WXWIN_COMPATIBILITY_2_6 
 162 bool wxDialog::IsModalShowing() const 
 165 } // end of wxDialog::IsModalShowing 
 167 #endif // WXWIN_COMPATIBILITY_2_6 
 169 bool wxDialog::Show( bool bShow 
) 
 171     if ( bShow 
== IsShown() ) 
 174     if (!bShow 
&& m_modalData 
) 
 176         // we need to do this before calling wxDialogBase version because if we 
 177         // had disabled other app windows, they must be reenabled right now as 
 178         // if they stay disabled Windows will activate another window (one 
 179         // which is enabled, anyhow) when we're hidden in the base class Show() 
 180         // and we will lose activation 
 181         m_modalData
->ExitLoop(); 
 183         if (m_pWindowDisabler
) 
 185             delete m_pWindowDisabler
; 
 186             m_pWindowDisabler 
= NULL
; 
 193         if (CanDoLayoutAdaptation()) 
 194             DoLayoutAdaptation(); 
 196         // this usually will result in TransferDataToWindow() being called 
 197         // which will change the controls values so do it before showing as 
 198         // otherwise we could have some flicker 
 202     wxDialogBase::Show(bShow
); 
 204     wxString title 
= GetTitle(); 
 206         ::WinSetWindowText((HWND
)GetHwnd(), title
.c_str()); 
 210         // dialogs don't get WM_SIZE message after creation unlike most (all?) 
 211         // other windows and so could start their life not laid out correctly 
 212         // if we didn't call Layout() from here 
 214         // NB: normally we should call it just the first time but doing it 
 215         //     every time is simpler than keeping a flag 
 220 } // end of wxDialog::Show 
 223 // Replacement for Show(true) for modal dialogs - returns return code 
 225 int wxDialog::ShowModal() 
 227     wxASSERT_MSG( !IsModal(), _T("wxDialog::ShowModal() reentered?") ); 
 229     m_endModalCalled 
= false; 
 233     // EndModal may have been called from InitDialog handler (called from 
 234     // inside Show()), which would cause an infinite loop if we didn't take it 
 236     if ( !m_endModalCalled 
) 
 238         // modal dialog needs a parent window, so try to find one 
 239         wxWindow 
*parent 
= GetParent(); 
 242             parent 
= FindSuitableParent(); 
 245         // remember where the focus was 
 246         wxWindow 
*oldFocus 
= m_pOldFocus
; 
 249             // VZ: do we really want to do this? 
 253         // We have to remember the HWND because we need to check 
 254         // the HWND still exists (oldFocus can be garbage when the dialog 
 255         // exits, if it has been destroyed) 
 256         HWND hwndOldFocus 
= oldFocus 
? GetHwndOf(oldFocus
) : NULL
; 
 260         // Before entering the modal loop, reset the "is in OnIdle()" flag (see 
 261         // comment in app.cpp) 
 263         extern bool                     gbInOnIdle
; 
 264         bool                            bWasInOnIdle 
= gbInOnIdle
; 
 268         // enter and run the modal loop 
 270             wxDialogModalDataTiedPtr 
modalData(&m_modalData
, 
 271                                                new wxDialogModalData(this)); 
 272             modalData
->RunLoop(); 
 274         gbInOnIdle 
= bWasInOnIdle
; 
 277         // Note that this code MUST NOT access the dialog object's data 
 278         // in case the object has been deleted (which will be the case 
 279         // for a modal dialog that has been destroyed before calling EndModal). 
 280         if ( oldFocus 
&& (oldFocus 
!= this) && ::WinIsWindow(vHabmain
, hwndOldFocus
)) 
 282             // This is likely to prove that the object still exists 
 283             if (wxFindWinFromHandle((WXHWND
) hwndOldFocus
) == oldFocus
) 
 284                 oldFocus
->SetFocus(); 
 288     return GetReturnCode(); 
 289 } // end of wxDialog::ShowModal 
 291 void wxDialog::EndModal( 
 295     wxASSERT_MSG( IsModal(), _T("EndModal() called for non modal dialog") ); 
 297     m_endModalCalled 
= true; 
 298     SetReturnCode(nRetCode
); 
 301 } // end of wxDialog::EndModal 
 303 MRESULT 
wxDialog::OS2WindowProc( WXUINT uMessage
, WXWPARAM wParam
, WXLPARAM lParam 
) 
 306     bool     bProcessed 
= false; 
 312             // If we can't close, tell the system that we processed the 
 313             // message - otherwise it would close us 
 315             bProcessed 
= !Close(); 
 320         rc 
= wxWindow::OS2WindowProc( uMessage
 
 325 } // end of wxDialog::OS2WindowProc