]>
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 wxDialogBase::wxDialogBase()
61 void wxDialogBase::Init()
65 // the dialogs have this flag on by default to prevent the events from the
66 // dialog controls from reaching the parent frame which is usually
67 // undesirable and can lead to unexpected and hard to find bugs
68 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS
);
70 #ifdef wxTopLevelWindowNative // FIXME - temporary hack, should be always used!
71 m_container
.SetContainerWindow(this);
75 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
77 wxSizer
*wxDialogBase::CreateTextSizer( const wxString
& message
)
79 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
81 wxString text
= message
;
83 // I admit that this is complete bogus, but it makes
84 // message boxes work for pda screens temporarily..
88 max_width
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
93 wxBoxSizer
*box
= new wxBoxSizer( wxVERTICAL
);
95 // get line height for empty lines
97 wxFont
font( GetFont() );
100 GetTextExtent( wxT("H"), (int*)NULL
, &y
, (int*)NULL
, (int*)NULL
, &font
);
102 size_t last_space
= 0;
104 for ( size_t pos
= 0; pos
< text
.length(); pos
++ )
111 wxStaticText
*s
= new wxStaticText( this, -1, line
);
122 // this is used as accel mnemonic prefix in the wxWindows
123 // controls but in the static messages created by
124 // CreateTextSizer() (used by wxMessageBox, for example), we
125 // don't want this special meaning, so we need to quote it
128 // fall through to add it normally too
131 if (text
[pos
] == wxT(' '))
134 line
+= message
[pos
];
139 GetTextExtent( line
, &width
, (int*)NULL
, (int*)NULL
, (int*)NULL
, &font
);
141 if (width
> max_width
)
143 // exception if there was no previous space
147 int diff
= pos
-last_space
;
148 int len
= line
.Len();
149 line
.Remove( len
-diff
, diff
);
151 wxStaticText
*s
= new wxStaticText( this, -1, line
);
162 // remaining text behind last '\n'
165 wxStaticText
*s2
= new wxStaticText( this, -1, line
);
172 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
176 wxSizer
*wxDialogBase::CreateButtonSizer( long flags
)
178 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
180 // If we have a PDA screen, put yes/no button over
181 // all other buttons, otherwise on the left side.
182 wxBoxSizer
*box
= is_pda
? new wxBoxSizer( wxVERTICAL
) : new wxBoxSizer( wxHORIZONTAL
);
184 wxBoxSizer
*inner_yes_no
= NULL
;
186 // Only create sizer containing yes/no
187 // if it is actually required
188 if ( (flags
& wxYES_NO
) != 0 )
190 inner_yes_no
= new wxBoxSizer( wxHORIZONTAL
);
191 box
->Add( inner_yes_no
, 0, wxBOTTOM
, 10 );
194 wxBoxSizer
*inner_rest
= new wxBoxSizer( wxHORIZONTAL
);
195 box
->Add( inner_rest
, 0, 0, 0 );
197 #if defined(__WXMSW__) || defined(__WXMAC__)
198 static const int margin
= 6;
200 static const int margin
= 10;
203 wxButton
*ok
= (wxButton
*) NULL
;
204 wxButton
*cancel
= (wxButton
*) NULL
;
205 wxButton
*yes
= (wxButton
*) NULL
;
206 wxButton
*no
= (wxButton
*) NULL
;
208 // always show an OK button, unless we have both YES and NO
209 if ( (flags
& wxYES_NO
) != wxYES_NO
)
214 yes
= new wxButton( this, wxID_YES
, _("Yes"),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
);
215 inner_yes_no
->Add( yes
, 0, wxLEFT
|wxRIGHT
, margin
);
219 no
= new wxButton( this, wxID_NO
, _("No"),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
);
220 inner_yes_no
->Add( no
, 0, wxLEFT
|wxRIGHT
, margin
);
225 ok
= new wxButton( this, wxID_OK
, _("OK"),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
);
226 inner_rest
->Add( ok
, 0, wxLEFT
|wxRIGHT
, margin
);
229 if (flags
& wxFORWARD
)
230 inner_rest
->Add( new wxButton( this, wxID_FORWARD
, _("Forward"),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
), 0, wxLEFT
|wxRIGHT
, margin
);
232 if (flags
& wxBACKWARD
)
233 inner_rest
->Add( new wxButton( this, wxID_BACKWARD
, _("Backward"),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
), 0, wxLEFT
|wxRIGHT
, margin
);
236 inner_rest
->Add( new wxButton( this, wxID_SETUP
, _("Setup"),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
), 0, wxLEFT
|wxRIGHT
, margin
);
239 inner_rest
->Add( new wxButton( this, wxID_MORE
, _("More..."),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
), 0, wxLEFT
|wxRIGHT
, margin
);
242 inner_rest
->Add( new wxButton( this, wxID_HELP
, _("Help"),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
), 0, wxLEFT
|wxRIGHT
, margin
);
244 if (flags
& wxCANCEL
)
246 cancel
= new wxButton( this, wxID_CANCEL
, _("Cancel"),wxDefaultPosition
,wxDefaultSize
,wxCLIP_SIBLINGS
);
247 inner_rest
->Add( cancel
, 0, wxLEFT
|wxRIGHT
, margin
);
250 // choose the default button
251 if (flags
& wxNO_DEFAULT
)
276 #endif // wxUSE_BUTTON