]>
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()
59 m_affirmativeId
= wxID_OK
;
61 // the dialogs have this flag on by default to prevent the events from the
62 // dialog controls from reaching the parent frame which is usually
63 // undesirable and can lead to unexpected and hard to find bugs
64 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS
);
66 #ifdef wxTopLevelWindowNative // FIXME - temporary hack, should be always used!
67 m_container
.SetContainerWindow(this);
71 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
73 wxSizer
*wxDialogBase::CreateTextSizer( const wxString
& message
)
75 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
77 wxString text
= message
;
79 // I admit that this is complete bogus, but it makes
80 // message boxes work for pda screens temporarily..
84 max_width
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
89 wxBoxSizer
*box
= new wxBoxSizer( wxVERTICAL
);
91 // get line height for empty lines
93 wxFont
font( GetFont() );
96 GetTextExtent( wxT("H"), (int*)NULL
, &y
, (int*)NULL
, (int*)NULL
, &font
);
98 size_t last_space
= 0;
100 for ( size_t pos
= 0; pos
< text
.length(); pos
++ )
107 wxStaticText
*s
= new wxStaticText( this, wxID_ANY
, line
);
109 line
= wxEmptyString
;
118 // this is used as accel mnemonic prefix in the wxWidgets
119 // controls but in the static messages created by
120 // CreateTextSizer() (used by wxMessageBox, for example), we
121 // don't want this special meaning, so we need to quote it
124 // fall through to add it normally too
127 if (text
[pos
] == wxT(' '))
130 line
+= message
[pos
];
135 GetTextExtent( line
, &width
, (int*)NULL
, (int*)NULL
, (int*)NULL
, &font
);
137 if (width
> max_width
)
139 // exception if there was no previous space
143 int diff
= pos
-last_space
;
144 int len
= line
.Len();
145 line
.Remove( len
-diff
, diff
);
147 wxStaticText
*s
= new wxStaticText( this, wxID_ANY
, line
);
152 line
= wxEmptyString
;
158 // remaining text behind last '\n'
161 wxStaticText
*s2
= new wxStaticText( this, wxID_ANY
, line
);
168 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
172 wxSizer
*wxDialogBase::CreateButtonSizer( long flags
)
174 #ifdef __SMARTPHONE__
175 wxDialog
* dialog
= (wxDialog
*) this;
177 dialog
->SetLeftMenu(wxID_OK
);
180 if (flags
& wxCANCEL
){
181 dialog
->SetRightMenu(wxID_CANCEL
);
185 dialog
->SetLeftMenu(wxID_YES
);
189 dialog
->SetLeftMenu(wxID_NO
);
191 wxBoxSizer
* sizer
= new wxBoxSizer(wxHORIZONTAL
);
194 return CreateStdDialogButtonSizer( flags
);
198 wxStdDialogButtonSizer
*wxDialogBase::CreateStdDialogButtonSizer( long flags
)
200 wxStdDialogButtonSizer
*sizer
= new wxStdDialogButtonSizer();
202 wxButton
*yes
= NULL
;
206 ok
= new wxButton(this, wxID_OK
);
207 sizer
->AddButton(ok
);
210 if (flags
& wxCANCEL
){
211 wxButton
*cancel
= new wxButton(this, wxID_CANCEL
);
212 sizer
->AddButton(cancel
);
216 yes
= new wxButton(this, wxID_YES
);
217 sizer
->AddButton(yes
);
221 no
= new wxButton(this, wxID_NO
);
222 sizer
->AddButton(no
);
226 wxButton
*help
= new wxButton(this, wxID_HELP
);
227 sizer
->AddButton(help
);
232 if (flags
& wxNO_DEFAULT
)
255 SetAffirmativeId(wxID_OK
);
256 else if (flags
& wxYES
)
257 SetAffirmativeId(wxID_YES
);
263 #endif // wxUSE_BUTTON