]>
git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/dlgcmn.cpp
3 // Purpose: common (to all ports) wxDialog functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "dialogbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/button.h"
33 #include "wx/dialog.h"
34 #include "wx/dcclient.h"
36 #include "wx/settings.h"
37 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/containr.h"
43 //--------------------------------------------------------------------------
45 //--------------------------------------------------------------------------
47 // FIXME - temporary hack in absence of wxtopLevelWindow, should be always used
48 #ifdef wxTopLevelWindowNative
49 BEGIN_EVENT_TABLE(wxDialogBase
, wxTopLevelWindow
)
50 WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase
)
53 WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase
)
56 void wxDialogBase::Init()
60 // the dialogs have this flag on by default to prevent the events from the
61 // dialog controls from reaching the parent frame which is usually
62 // undesirable and can lead to unexpected and hard to find bugs
63 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS
);
65 #ifdef wxTopLevelWindowNative // FIXME - temporary hack, should be always used!
66 m_container
.SetContainerWindow(this);
70 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
72 wxSizer
*wxDialogBase::CreateTextSizer( const wxString
& message
)
74 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
76 wxString text
= message
;
78 // I admit that this is complete bogus, but it makes
79 // message boxes work for pda screens temporarily..
83 max_width
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
88 wxBoxSizer
*box
= new wxBoxSizer( wxVERTICAL
);
90 // get line height for empty lines
92 wxFont
font( GetFont() );
95 GetTextExtent( wxT("H"), (int*)NULL
, &y
, (int*)NULL
, (int*)NULL
, &font
);
97 size_t last_space
= 0;
99 for ( size_t pos
= 0; pos
< text
.length(); pos
++ )
106 wxStaticText
*s
= new wxStaticText( this, wxID_ANY
, line
);
108 line
= wxEmptyString
;
117 // this is used as accel mnemonic prefix in the wxWidgets
118 // controls but in the static messages created by
119 // CreateTextSizer() (used by wxMessageBox, for example), we
120 // don't want this special meaning, so we need to quote it
123 // fall through to add it normally too
126 if (text
[pos
] == wxT(' '))
129 line
+= message
[pos
];
134 GetTextExtent( line
, &width
, (int*)NULL
, (int*)NULL
, (int*)NULL
, &font
);
136 if (width
> max_width
)
138 // exception if there was no previous space
142 int diff
= pos
-last_space
;
143 int len
= line
.Len();
144 line
.Remove( len
-diff
, diff
);
146 wxStaticText
*s
= new wxStaticText( this, wxID_ANY
, line
);
151 line
= wxEmptyString
;
157 // remaining text behind last '\n'
160 wxStaticText
*s2
= new wxStaticText( this, wxID_ANY
, line
);
167 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
171 wxSizer
*wxDialogBase::CreateButtonSizer( long flags
)
173 return CreateStdDialogButtonSizer( flags
);
176 wxStdDialogButtonSizer
*wxDialogBase::CreateStdDialogButtonSizer( long flags
)
178 wxStdDialogButtonSizer
*sizer
= new wxStdDialogButtonSizer();
180 wxButton
*yes
= NULL
;
184 ok
= new wxButton(this, wxID_OK
);
185 sizer
->AddButton(ok
);
188 if (flags
& wxCANCEL
){
189 wxButton
*cancel
= new wxButton(this, wxID_CANCEL
);
190 sizer
->AddButton(cancel
);
194 yes
= new wxButton(this, wxID_YES
);
195 sizer
->AddButton(yes
);
199 no
= new wxButton(this, wxID_NO
);
200 sizer
->AddButton(no
);
204 wxButton
*help
= new wxButton(this, wxID_HELP
);
205 sizer
->AddButton(help
);
210 if (flags
& wxNO_DEFAULT
)
236 #endif // wxUSE_BUTTON