]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/extdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: extended generic dialog
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "extdlgg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dialog.h"
27 #include "wx/button.h"
31 #include "wx/statline.h"
34 #include "wx/generic/extdlgg.h"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 #define BUTTON_AREA_MARGIN 10
42 #if !USE_SHARED_LIBRARY
43 IMPLEMENT_DYNAMIC_CLASS(wxExtDialog
, wxDialog
)
45 BEGIN_EVENT_TABLE(wxExtDialog
, wxDialog
)
46 EVT_SIZE(wxExtDialog::OnSize
)
47 EVT_BUTTON(wxID_YES
, wxExtDialog::OnYes
)
48 EVT_BUTTON(wxID_NO
, wxExtDialog::OnNo
)
49 EVT_BUTTON(wxID_CANCEL
, wxExtDialog::OnCancel
)
53 wxExtDialog::wxExtDialog( wxWindow
*parent
, wxWindowID id
,
54 const wxString
& title
, long extraStyle
,
55 const wxPoint
& pos
, const wxSize
& size
,
56 long style
, const wxString
&name
)
58 Create( parent
, id
, title
, extraStyle
, pos
, size
, style
, name
);
61 bool wxExtDialog::Create( wxWindow
*parent
, wxWindowID id
,
62 const wxString
& title
, long extraStyle
,
63 const wxPoint
& pos
, const wxSize
& size
,
64 long style
, const wxString
&name
)
66 if (!wxDialog::Create( parent
, id
, title
, pos
, size
, style
, name
))
69 m_extraStyle
= extraStyle
;
71 m_clientWindowMargin
= 10;
73 if (m_windowStyle
& wxED_BUTTONS_RIGHT
)
75 m_spacePerButton
.x
= wxButton::GetDefaultSize().x
+ 18;
76 m_spacePerButton
.y
= wxButton::GetDefaultSize().y
+ 8;
80 m_spacePerButton
.x
= wxButton::GetDefaultSize().x
+ 8;
81 m_spacePerButton
.y
= wxButton::GetDefaultSize().y
+ 18;
84 #if defined(__WXGTK__) || defined(__WXMOTIF__)
85 // Under Motif and GTK, the default button has a big frame around
86 // it and to avoid overlapping buttons we make the margin bigger.
87 // We could give other platforms a bigger margin as well, but this
88 // wouldn't be standard L&F.
89 m_spacePerButton
.x
+= 10;
90 m_spacePerButton
.y
+= 10;
93 wxButton
*ok
= (wxButton
*) NULL
;
94 wxButton
*cancel
= (wxButton
*) NULL
;
95 wxButton
*yes
= (wxButton
*) NULL
;
96 wxButton
*no
= (wxButton
*) NULL
;
99 if (m_extraStyle
& wxYES_NO
)
101 yes
= new wxButton( this, wxID_YES
, _("Yes") );
102 m_buttons
.Append( yes
);
103 no
= new wxButton( this, wxID_NO
, _("No") );
104 m_buttons
.Append( no
);
107 if (m_extraStyle
& wxYES
)
109 yes
= new wxButton( this, wxID_YES
, _("Yes") );
110 m_buttons
.Append( yes
);
113 if (m_extraStyle
& wxNO
)
115 no
= new wxButton( this, wxID_NO
, _("No") );
116 m_buttons
.Append( no
);
119 if (m_extraStyle
& wxOK
)
121 ok
= new wxButton( this, wxID_OK
, _("OK") );
122 m_buttons
.Append( ok
);
125 if (m_extraStyle
& wxFORWARD
)
126 AddButton( new wxButton( this, wxID_FORWARD
, _("Forward") ) );
128 if (m_extraStyle
& wxBACKWARD
)
129 AddButton( new wxButton( this, wxID_BACKWARD
, _("Backward") ) );
131 if (m_extraStyle
& wxSETUP
)
132 AddButton( new wxButton( this, wxID_SETUP
, _("Setup") ) );
134 if (m_extraStyle
& wxMORE
)
135 AddButton( new wxButton( this, wxID_MORE
, _("More...") ) );
137 if (m_extraStyle
& wxHELP
)
138 AddButton( new wxButton( this, wxID_HELP
, _("Help") ) );
140 if (m_extraStyle
& wxCANCEL
)
142 cancel
= new wxButton( this, wxID_CANCEL
, _("Cancel") );
143 m_buttons
.Append( cancel
);
146 if ((m_extraStyle
& wxNO_DEFAULT
) == 0)
161 if (style
& wxED_STATIC_LINE
)
163 int line_style
= wxLI_HORIZONTAL
;
164 if (style
& wxED_BUTTONS_RIGHT
) line_style
= wxLI_VERTICAL
;
166 m_statLine
= new wxStaticLine( this, -1, wxDefaultPosition
, wxDefaultSize
, line_style
);
169 m_statLine
= (wxStaticLine
*) NULL
;
172 if (m_extraStyle
& wxCENTRE
)
178 void wxExtDialog::AddButton( wxButton
*button
)
180 m_buttons
.Append( button
);
183 void wxExtDialog::SetDefaultButton( wxWindowID button
)
185 wxNode
*node
= m_buttons
.First();
188 wxButton
*but
= (wxButton
*) node
->Data();
189 if (but
->GetId() == button
)
198 void wxExtDialog::EnableButton( wxWindowID button
, bool enable
)
200 wxNode
*node
= m_buttons
.First();
203 wxButton
*but
= (wxButton
*) node
->Data();
204 if (but
->GetId() == button
)
212 bool wxExtDialog::ButtonIsEnabled( wxWindowID button
)
214 wxNode
*node
= m_buttons
.First();
217 wxButton
*but
= (wxButton
*) node
->Data();
218 if (but
->GetId() == button
)
219 return but
->IsEnabled();
224 void wxExtDialog::OnSize( wxSizeEvent
&WXUNUSED(event
) )
226 wxSize
client_size( GetClientSize() );
227 wxSize
button_area( LayoutButtons() );
229 if (HasFlag(wxED_BUTTONS_RIGHT
))
230 client_size
.x
-= button_area
.x
;
232 client_size
.y
-= button_area
.y
;
236 if (m_windowStyle
& wxED_CLIENT_MARGIN
)
237 m_clientWindow
->SetSize( m_clientWindowMargin
,
238 m_clientWindowMargin
,
239 client_size
.x
- 2*m_clientWindowMargin
,
240 client_size
.y
- 2*m_clientWindowMargin
);
242 m_clientWindow
->SetSize( 0, 0, client_size
.x
, client_size
.y
);
244 if (m_clientWindow
->GetAutoLayout())
245 m_clientWindow
->Layout();
249 void wxExtDialog::OnYes(wxCommandEvent
& event
)
251 EndModal( wxID_YES
);
254 void wxExtDialog::OnNo(wxCommandEvent
& event
)
259 void wxExtDialog::OnCancel(wxCommandEvent
& event
)
261 /* allow cancellation via ESC/Close button except if
262 only YES and NO are specified. */
263 if ((m_extraStyle
& wxYES_NO
) != wxYES_NO
|| (m_extraStyle
& wxCANCEL
))
265 EndModal( wxID_CANCEL
);
269 wxSize
wxExtDialog::GetButtonAreaSize()
271 if (m_buttons
.GetCount() == 0) return wxSize(0,0);
275 if (m_windowStyle
& wxED_BUTTONS_RIGHT
)
277 ret
.x
= m_spacePerButton
.x
;
278 ret
.y
= m_buttons
.GetCount()*m_spacePerButton
.y
+ 2*BUTTON_AREA_MARGIN
;
281 ret
.x
+= wxStaticLine::GetDefaultSize();
286 ret
.x
= m_buttons
.GetCount()*m_spacePerButton
.x
+ 2*BUTTON_AREA_MARGIN
;
287 ret
.y
= m_spacePerButton
.y
;
290 ret
.y
+= wxStaticLine::GetDefaultSize();
297 wxSize
wxExtDialog::LayoutButtons()
299 if (m_buttons
.GetCount() == 0) return wxSize(0,0);
301 wxSize
area_used( GetButtonAreaSize() );
302 wxSize
client_area( GetClientSize() );
304 if (m_windowStyle
& wxED_BUTTONS_RIGHT
)
306 area_used
.y
= client_area
.y
;
307 wxSize
area_used_by_buttons( area_used
);
310 area_used_by_buttons
.x
-= wxStaticLine::GetDefaultSize();
313 int space_for_each_button
= (client_area
.y
-2*BUTTON_AREA_MARGIN
) / m_buttons
.GetCount();
315 wxNode
*node
= m_buttons
.First();
318 wxButton
*button
= (wxButton
*)node
->Data();
320 wxSize
button_size( button
->GetSize() );
321 if (button_size
.x
< wxButton::GetDefaultSize().x
) button_size
.x
= wxButton::GetDefaultSize().x
;
323 int center_of_button_y
= n
*space_for_each_button
+ space_for_each_button
/2;
324 int button_y
= BUTTON_AREA_MARGIN
+ center_of_button_y
- button_size
.y
/2;
326 int center_of_button_x
= client_area
.x
- area_used_by_buttons
.x
/2;
327 int button_x
= center_of_button_x
- button_size
.x
/2;
329 button
->SetSize( button_x
, button_y
, button_size
.x
, button_size
.y
);
337 m_statLine
->SetSize( client_area
.x
- area_used_by_buttons
.x
- wxStaticLine::GetDefaultSize(),
339 wxStaticLine::GetDefaultSize(),
345 area_used
.x
= client_area
.x
;
346 wxSize
area_used_by_buttons( area_used
);
349 area_used_by_buttons
.y
-= wxStaticLine::GetDefaultSize();
352 int space_for_each_button
= (client_area
.x
-2*BUTTON_AREA_MARGIN
) / m_buttons
.GetCount();
354 wxNode
*node
= m_buttons
.First();
357 wxButton
*button
= (wxButton
*)node
->Data();
359 wxSize
button_size( button
->GetSize() );
360 if (button_size
.x
< wxButton::GetDefaultSize().x
) button_size
.x
= wxButton::GetDefaultSize().x
;
362 int center_of_button_x
= n
*space_for_each_button
+ space_for_each_button
/2;
363 int button_x
= BUTTON_AREA_MARGIN
+ center_of_button_x
- button_size
.x
/2;
365 int center_of_button_y
= client_area
.y
- area_used_by_buttons
.y
/2;
366 int button_y
= center_of_button_y
- button_size
.y
/2;
368 button
->SetSize( button_x
, button_y
, button_size
.x
, button_size
.y
);
376 m_statLine
->SetSize( 0,
377 client_area
.y
- area_used_by_buttons
.y
- wxStaticLine::GetDefaultSize(),
379 wxStaticLine::GetDefaultSize() );