1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/dialog.h"
31 #include "wx/button.h"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/stattext.h"
37 #include "wx/containr.h"
40 #include "wx/statline.h"
41 #include "wx/sysopt.h"
42 #include "wx/module.h"
43 #include "wx/bookctrl.h"
44 #include "wx/scrolwin.h"
45 #include "wx/textwrapper.h"
48 #include "wx/display.h"
51 extern WXDLLEXPORT_DATA(const char) wxDialogNameStr
[] = "dialog";
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 wxDEFINE_FLAGS( wxDialogStyle
)
58 wxBEGIN_FLAGS( wxDialogStyle
)
59 // new style border flags, we put them first to
60 // use them for streaming out
61 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
62 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
63 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
64 wxFLAGS_MEMBER(wxBORDER_RAISED
)
65 wxFLAGS_MEMBER(wxBORDER_STATIC
)
66 wxFLAGS_MEMBER(wxBORDER_NONE
)
68 // old style border flags
69 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
70 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
71 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
72 wxFLAGS_MEMBER(wxRAISED_BORDER
)
73 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
74 wxFLAGS_MEMBER(wxNO_BORDER
)
76 // standard window styles
77 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
78 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
81 wxFLAGS_MEMBER(wxWS_EX_VALIDATE_RECURSIVELY
)
82 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
83 wxFLAGS_MEMBER(wxCAPTION
)
84 #if WXWIN_COMPATIBILITY_2_6
85 wxFLAGS_MEMBER(wxTHICK_FRAME
)
86 #endif // WXWIN_COMPATIBILITY_2_6
87 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
88 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
89 #if WXWIN_COMPATIBILITY_2_6
90 wxFLAGS_MEMBER(wxRESIZE_BOX
)
91 #endif // WXWIN_COMPATIBILITY_2_6
92 wxFLAGS_MEMBER(wxCLOSE_BOX
)
93 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
94 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
95 wxEND_FLAGS( wxDialogStyle
)
97 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxDialog
, wxTopLevelWindow
, "wx/dialog.h")
99 wxBEGIN_PROPERTIES_TABLE(wxDialog
)
100 wxPROPERTY( Title
, wxString
, SetTitle
, GetTitle
, wxString(), \
101 0 /*flags*/, wxT("Helpstring"), wxT("group"))
103 wxPROPERTY_FLAGS( WindowStyle
, wxDialogStyle
, long, SetWindowStyleFlag
, \
104 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
105 wxT("Helpstring"), wxT("group")) // style
106 wxEND_PROPERTIES_TABLE()
108 wxEMPTY_HANDLERS_TABLE(wxDialog
)
110 wxCONSTRUCTOR_6( wxDialog
, wxWindow
*, Parent
, wxWindowID
, Id
, \
111 wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long, WindowStyle
)
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 BEGIN_EVENT_TABLE(wxDialogBase
, wxTopLevelWindow
)
118 EVT_BUTTON(wxID_ANY
, wxDialogBase::OnButton
)
120 EVT_CLOSE(wxDialogBase::OnCloseWindow
)
122 EVT_CHAR_HOOK(wxDialogBase::OnCharHook
)
125 wxDialogLayoutAdapter
* wxDialogBase::sm_layoutAdapter
= NULL
;
126 bool wxDialogBase::sm_layoutAdaptation
= false;
128 void wxDialogBase::Init()
131 m_affirmativeId
= wxID_OK
;
132 m_escapeId
= wxID_ANY
;
133 m_layoutAdaptationLevel
= 3;
134 m_layoutAdaptationDone
= FALSE
;
135 m_layoutAdaptationMode
= wxDIALOG_ADAPTATION_MODE_DEFAULT
;
137 // the dialogs have this flag on by default to prevent the events from the
138 // dialog controls from reaching the parent frame which is usually
139 // undesirable and can lead to unexpected and hard to find bugs
140 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS
);
143 wxWindow
*wxDialogBase::CheckIfCanBeUsedAsParent(wxWindow
*parent
) const
148 extern WXDLLIMPEXP_DATA_BASE(wxList
) wxPendingDelete
;
149 if ( wxPendingDelete
.Member(parent
) || parent
->IsBeingDeleted() )
151 // this window is being deleted and we shouldn't create any children
156 if ( parent
->HasExtraStyle(wxWS_EX_TRANSIENT
) )
158 // this window is not being deleted yet but it's going to disappear
159 // soon so still don't parent this window under it
163 if ( !parent
->IsShownOnScreen() )
165 // using hidden parent won't work correctly neither
169 // FIXME-VC6: this compiler requires an explicit const cast or it fails
171 if ( const_cast<const wxWindow
*>(parent
) == this )
173 // not sure if this can really happen but it doesn't hurt to guard
174 // against this clearly invalid situation
182 wxDialogBase::GetParentForModalDialog(wxWindow
*parent
, long style
) const
184 // creating a parent-less modal dialog will result (under e.g. wxGTK2)
185 // in an unfocused dialog, so try to find a valid parent for it unless we
186 // were explicitly asked not to
187 if ( style
& wxDIALOG_NO_PARENT
)
190 // first try the given parent
192 parent
= CheckIfCanBeUsedAsParent(wxGetTopLevelParent(parent
));
194 // then the currently active window
196 parent
= CheckIfCanBeUsedAsParent(
197 wxGetTopLevelParent(wxGetActiveWindow()));
199 // and finally the application main window
201 parent
= CheckIfCanBeUsedAsParent(wxTheApp
->GetTopWindow());
208 wxSizer
*wxDialogBase::CreateTextSizer(const wxString
& message
)
210 wxTextSizerWrapper
wrapper(this);
212 return CreateTextSizer(message
, wrapper
);
215 wxSizer
*wxDialogBase::CreateTextSizer(const wxString
& message
,
216 wxTextSizerWrapper
& wrapper
)
218 // I admit that this is complete bogus, but it makes
219 // message boxes work for pda screens temporarily..
221 const bool is_pda
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
224 widthMax
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
227 // '&' is used as accel mnemonic prefix in the wxWidgets controls but in
228 // the static messages created by CreateTextSizer() (used by wxMessageBox,
229 // for example), we don't want this special meaning, so we need to quote it
230 wxString
text(message
);
231 text
.Replace(wxT("&"), wxT("&&"));
233 return wrapper
.CreateSizer(text
, widthMax
);
236 #endif // wxUSE_STATTEXT
238 wxSizer
*wxDialogBase::CreateButtonSizer(long flags
)
240 #ifdef __SMARTPHONE__
241 wxDialog
* dialog
= (wxDialog
*) this;
243 dialog
->SetLeftMenu(wxID_OK
);
245 if ( flags
& wxCANCEL
)
246 dialog
->SetRightMenu(wxID_CANCEL
);
249 dialog
->SetLeftMenu(wxID_YES
);
252 dialog
->SetRightMenu(wxID_NO
);
255 #else // !__SMARTPHONE__
260 // PocketPC guidelines recommend for Ok/Cancel dialogs to use OK button
261 // located inside caption bar and implement Cancel functionality through
262 // Undo outside dialog. As native behaviour this will be default here but
263 // can be replaced with real wxButtons by setting the option below to 1
264 if ( (flags
& ~(wxCANCEL
|wxNO_DEFAULT
)) != wxOK
||
265 wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")) )
266 #endif // __POCKETPC__
268 return CreateStdDialogButtonSizer(flags
);
272 #endif // __POCKETPC__
274 #else // !wxUSE_BUTTON
278 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
280 #endif // __SMARTPHONE__/!__SMARTPHONE__
283 wxSizer
*wxDialogBase::CreateSeparatedSizer(wxSizer
*sizer
)
285 // Mac Human Interface Guidelines recommend not to use static lines as
287 #if wxUSE_STATLINE && !defined(__WXMAC__)
288 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
289 topsizer
->Add(new wxStaticLine(this),
290 wxSizerFlags().Expand().DoubleBorder(wxBOTTOM
));
291 topsizer
->Add(sizer
, wxSizerFlags().Expand());
293 #endif // wxUSE_STATLINE
298 wxSizer
*wxDialogBase::CreateSeparatedButtonSizer(long flags
)
300 wxSizer
*sizer
= CreateButtonSizer(flags
);
304 return CreateSeparatedSizer(sizer
);
309 wxStdDialogButtonSizer
*wxDialogBase::CreateStdDialogButtonSizer( long flags
)
311 wxStdDialogButtonSizer
*sizer
= new wxStdDialogButtonSizer();
314 wxButton
*yes
= NULL
;
319 ok
= new wxButton(this, wxID_OK
);
320 sizer
->AddButton(ok
);
323 if (flags
& wxCANCEL
)
325 wxButton
*cancel
= new wxButton(this, wxID_CANCEL
);
326 sizer
->AddButton(cancel
);
331 yes
= new wxButton(this, wxID_YES
);
332 sizer
->AddButton(yes
);
337 no
= new wxButton(this, wxID_NO
);
338 sizer
->AddButton(no
);
343 wxButton
*apply
= new wxButton(this, wxID_APPLY
);
344 sizer
->AddButton(apply
);
349 wxButton
*close
= new wxButton(this, wxID_CLOSE
);
350 sizer
->AddButton(close
);
355 wxButton
*help
= new wxButton(this, wxID_HELP
);
356 sizer
->AddButton(help
);
359 if (flags
& wxNO_DEFAULT
)
382 SetAffirmativeId(wxID_OK
);
383 else if (flags
& wxYES
)
384 SetAffirmativeId(wxID_YES
);
391 #endif // wxUSE_BUTTON
393 // ----------------------------------------------------------------------------
394 // standard buttons handling
395 // ----------------------------------------------------------------------------
397 void wxDialogBase::EndDialog(int rc
)
405 void wxDialogBase::AcceptAndClose()
407 if ( Validate() && TransferDataFromWindow() )
409 EndDialog(m_affirmativeId
);
413 void wxDialogBase::SetAffirmativeId(int affirmativeId
)
415 m_affirmativeId
= affirmativeId
;
418 void wxDialogBase::SetEscapeId(int escapeId
)
420 m_escapeId
= escapeId
;
423 bool wxDialogBase::EmulateButtonClickIfPresent(int id
)
426 wxButton
*btn
= wxDynamicCast(FindWindow(id
), wxButton
);
428 if ( !btn
|| !btn
->IsEnabled() || !btn
->IsShown() )
431 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, id
);
432 event
.SetEventObject(btn
);
433 btn
->GetEventHandler()->ProcessEvent(event
);
436 #else // !wxUSE_BUTTON
439 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
442 bool wxDialogBase::SendCloseButtonClickEvent()
444 int idCancel
= GetEscapeId();
448 // The user doesn't want this dialog to close "implicitly".
452 // this value is special: it means translate Esc to wxID_CANCEL
453 // but if there is no such button, then fall back to wxID_OK
454 if ( EmulateButtonClickIfPresent(wxID_CANCEL
) )
456 idCancel
= GetAffirmativeId();
460 // translate Esc to button press for the button with given id
461 if ( EmulateButtonClickIfPresent(idCancel
) )
468 bool wxDialogBase::IsEscapeKey(const wxKeyEvent
& event
)
470 // for most platforms, Esc key is used to close the dialogs
471 return event
.GetKeyCode() == WXK_ESCAPE
&&
472 event
.GetModifiers() == wxMOD_NONE
;
475 void wxDialogBase::OnCharHook(wxKeyEvent
& event
)
477 if ( event
.GetKeyCode() == WXK_ESCAPE
)
479 if ( SendCloseButtonClickEvent() )
481 // Skip the call to event.Skip() below, we did handle this key.
489 void wxDialogBase::OnButton(wxCommandEvent
& event
)
491 const int id
= event
.GetId();
492 if ( id
== GetAffirmativeId() )
496 else if ( id
== wxID_APPLY
)
499 TransferDataFromWindow();
501 // TODO: disable the Apply button until things change again
503 else if ( id
== GetEscapeId() ||
504 (id
== wxID_CANCEL
&& GetEscapeId() == wxID_ANY
) )
506 EndDialog(wxID_CANCEL
);
508 else // not a standard button
514 // ----------------------------------------------------------------------------
515 // compatibility methods for supporting the modality API
516 // ----------------------------------------------------------------------------
518 wxDEFINE_EVENT( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
, wxWindowModalDialogEvent
);
520 IMPLEMENT_DYNAMIC_CLASS(wxWindowModalDialogEvent
, wxCommandEvent
)
522 void wxDialogBase::ShowWindowModal ()
525 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
);
528 void wxDialogBase::SendWindowModalDialogEvent ( wxEventType type
)
530 wxWindowModalDialogEvent
event ( type
, GetId());
531 event
.SetEventObject(this);
533 if ( !GetEventHandler()->ProcessEvent(event
) )
535 // the event is not propagated upwards to the parent automatically
536 // because the dialog is a top level window, so do it manually as
537 // in 9 cases of 10 the message must be processed by the dialog
538 // owner and not the dialog itself
539 (void)GetParent()->GetEventHandler()->ProcessEvent(event
);
544 wxDialogModality
wxDialogBase::GetModality() const
546 return IsModal() ? wxDIALOG_MODALITY_APP_MODAL
: wxDIALOG_MODALITY_NONE
;
549 // ----------------------------------------------------------------------------
550 // other event handlers
551 // ----------------------------------------------------------------------------
553 void wxDialogBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
555 // We'll send a Cancel message by default, which may close the dialog.
557 // Check for looping if the Cancel event handler calls Close().
559 // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
560 // lists here? don't dare to change it now, but should be done later!
561 static wxList closing
;
563 if ( closing
.Member(this) )
566 closing
.Append(this);
568 if ( !SendCloseButtonClickEvent() )
570 // If the handler didn't close the dialog (e.g. because there is no
571 // button with matching id) we still want to close it when the user
572 // clicks the "x" button in the title bar, otherwise we shouldn't even
573 // have put it there.
575 // Notice that using wxID_CLOSE might have been a better choice but we
576 // use wxID_CANCEL for compatibility reasons.
577 EndDialog(wxID_CANCEL
);
580 closing
.DeleteObject(this);
583 void wxDialogBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
586 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
593 /// Do the adaptation
594 bool wxDialogBase::DoLayoutAdaptation()
596 if (GetLayoutAdapter())
598 wxWindow
* focusWindow
= wxFindFocusDescendant(this); // from event.h
599 if (GetLayoutAdapter()->DoLayoutAdaptation((wxDialog
*) this))
602 focusWindow
->SetFocus();
612 /// Can we do the adaptation?
613 bool wxDialogBase::CanDoLayoutAdaptation()
615 // Check if local setting overrides the global setting
616 bool layoutEnabled
= (GetLayoutAdaptationMode() == wxDIALOG_ADAPTATION_MODE_ENABLED
) || (IsLayoutAdaptationEnabled() && (GetLayoutAdaptationMode() != wxDIALOG_ADAPTATION_MODE_DISABLED
));
618 return (layoutEnabled
&& !m_layoutAdaptationDone
&& GetLayoutAdaptationLevel() != 0 && GetLayoutAdapter() != NULL
&& GetLayoutAdapter()->CanDoLayoutAdaptation((wxDialog
*) this));
621 /// Set scrolling adapter class, returning old adapter
622 wxDialogLayoutAdapter
* wxDialogBase::SetLayoutAdapter(wxDialogLayoutAdapter
* adapter
)
624 wxDialogLayoutAdapter
* oldLayoutAdapter
= sm_layoutAdapter
;
625 sm_layoutAdapter
= adapter
;
626 return oldLayoutAdapter
;
633 IMPLEMENT_CLASS(wxDialogLayoutAdapter
, wxObject
)
635 IMPLEMENT_CLASS(wxStandardDialogLayoutAdapter
, wxDialogLayoutAdapter
)
637 // Allow for caption size on wxWidgets < 2.9
638 #if defined(__WXGTK__) && !wxCHECK_VERSION(2,9,0)
639 #define wxEXTRA_DIALOG_HEIGHT 30
641 #define wxEXTRA_DIALOG_HEIGHT 0
644 /// Indicate that adaptation should be done
645 bool wxStandardDialogLayoutAdapter::CanDoLayoutAdaptation(wxDialog
* dialog
)
647 if (dialog
->GetSizer())
649 wxSize windowSize
, displaySize
;
650 return MustScroll(dialog
, windowSize
, displaySize
) != 0;
656 bool wxStandardDialogLayoutAdapter::DoLayoutAdaptation(wxDialog
* dialog
)
658 if (dialog
->GetSizer())
661 wxBookCtrlBase
* bookContentWindow
= wxDynamicCast(dialog
->GetContentWindow(), wxBookCtrlBase
);
663 if (bookContentWindow
)
665 // If we have a book control, make all the pages (that use sizers) scrollable
666 wxWindowList windows
;
667 for (size_t i
= 0; i
< bookContentWindow
->GetPageCount(); i
++)
669 wxWindow
* page
= bookContentWindow
->GetPage(i
);
671 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(page
, wxScrolledWindow
);
673 windows
.Append(scrolledWindow
);
674 else if (!scrolledWindow
&& page
->GetSizer())
676 // Create a scrolled window and reparent
677 scrolledWindow
= CreateScrolledWindow(page
);
678 wxSizer
* oldSizer
= page
->GetSizer();
680 wxSizer
* newSizer
= new wxBoxSizer(wxVERTICAL
);
681 newSizer
->Add(scrolledWindow
,1, wxEXPAND
, 0);
683 page
->SetSizer(newSizer
, false /* don't delete the old sizer */);
685 scrolledWindow
->SetSizer(oldSizer
);
687 ReparentControls(page
, scrolledWindow
);
689 windows
.Append(scrolledWindow
);
693 FitWithScrolling(dialog
, windows
);
696 #endif // wxUSE_BOOKCTRL
699 // If we have an arbitrary dialog, create a scrolling area for the main content, and a button sizer
700 // for the main buttons.
701 wxScrolledWindow
* scrolledWindow
= CreateScrolledWindow(dialog
);
703 int buttonSizerBorder
= 0;
705 // First try to find a wxStdDialogButtonSizer
706 wxSizer
* buttonSizer
= FindButtonSizer(true /* find std button sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
708 // Next try to find a wxBoxSizer containing the controls
709 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_STANDARD_SIZER
)
710 buttonSizer
= FindButtonSizer(false /* find ordinary sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
712 // If we still don't have a button sizer, collect any 'loose' buttons in the layout
713 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_ANY_SIZER
)
716 wxStdDialogButtonSizer
* stdButtonSizer
= new wxStdDialogButtonSizer
;
717 buttonSizer
= stdButtonSizer
;
719 FindLooseButtons(dialog
, stdButtonSizer
, dialog
->GetSizer(), count
);
721 stdButtonSizer
->Realize();
724 wxDELETE(buttonSizer
);
728 if (buttonSizerBorder
== 0)
729 buttonSizerBorder
= 5;
731 ReparentControls(dialog
, scrolledWindow
, buttonSizer
);
733 wxBoxSizer
* newTopSizer
= new wxBoxSizer(wxVERTICAL
);
734 wxSizer
* oldSizer
= dialog
->GetSizer();
736 dialog
->SetSizer(newTopSizer
, false /* don't delete old sizer */);
738 newTopSizer
->Add(scrolledWindow
, 1, wxEXPAND
|wxALL
, 0);
740 newTopSizer
->Add(buttonSizer
, 0, wxEXPAND
|wxALL
, buttonSizerBorder
);
742 scrolledWindow
->SetSizer(oldSizer
);
744 FitWithScrolling(dialog
, scrolledWindow
);
745 #endif // wxUSE_BUTTON
749 dialog
->SetLayoutAdaptationDone(true);
753 // Create the scrolled window
754 wxScrolledWindow
* wxStandardDialogLayoutAdapter::CreateScrolledWindow(wxWindow
* parent
)
756 wxScrolledWindow
* scrolledWindow
= new wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
|wxVSCROLL
|wxHSCROLL
|wxBORDER_NONE
);
757 return scrolledWindow
;
762 /// Find and remove the button sizer, if any
763 wxSizer
* wxStandardDialogLayoutAdapter::FindButtonSizer(bool stdButtonSizer
, wxDialog
* dialog
, wxSizer
* sizer
, int& retBorder
, int accumlatedBorder
)
765 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
766 node
; node
= node
->GetNext() )
768 wxSizerItem
*item
= node
->GetData();
769 wxSizer
*childSizer
= item
->GetSizer();
773 int newBorder
= accumlatedBorder
;
774 if (item
->GetFlag() & wxALL
)
775 newBorder
+= item
->GetBorder();
777 if (stdButtonSizer
) // find wxStdDialogButtonSizer
779 wxStdDialogButtonSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxStdDialogButtonSizer
);
782 sizer
->Detach(childSizer
);
783 retBorder
= newBorder
;
787 else // find a horizontal box sizer containing standard buttons
789 wxBoxSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxBoxSizer
);
790 if (buttonSizer
&& IsOrdinaryButtonSizer(dialog
, buttonSizer
))
792 sizer
->Detach(childSizer
);
793 retBorder
= newBorder
;
798 wxSizer
* s
= FindButtonSizer(stdButtonSizer
, dialog
, childSizer
, retBorder
, newBorder
);
806 /// Check if this sizer contains standard buttons, and so can be repositioned in the dialog
807 bool wxStandardDialogLayoutAdapter::IsOrdinaryButtonSizer(wxDialog
* dialog
, wxBoxSizer
* sizer
)
809 if (sizer
->GetOrientation() != wxHORIZONTAL
)
812 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
813 node
; node
= node
->GetNext() )
815 wxSizerItem
*item
= node
->GetData();
816 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
818 if (childButton
&& IsStandardButton(dialog
, childButton
))
824 /// Check if this is a standard button
825 bool wxStandardDialogLayoutAdapter::IsStandardButton(wxDialog
* dialog
, wxButton
* button
)
827 wxWindowID id
= button
->GetId();
829 return (id
== wxID_OK
|| id
== wxID_CANCEL
|| id
== wxID_YES
|| id
== wxID_NO
|| id
== wxID_SAVE
||
830 id
== wxID_APPLY
|| id
== wxID_HELP
|| id
== wxID_CONTEXT_HELP
|| dialog
->IsMainButtonId(id
));
833 /// Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
834 bool wxStandardDialogLayoutAdapter::FindLooseButtons(wxDialog
* dialog
, wxStdDialogButtonSizer
* buttonSizer
, wxSizer
* sizer
, int& count
)
836 wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
839 wxSizerItemList::compatibility_iterator next
= node
->GetNext();
840 wxSizerItem
*item
= node
->GetData();
841 wxSizer
*childSizer
= item
->GetSizer();
842 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
844 if (childButton
&& IsStandardButton(dialog
, childButton
))
846 sizer
->Detach(childButton
);
847 buttonSizer
->AddButton(childButton
);
852 FindLooseButtons(dialog
, buttonSizer
, childSizer
, count
);
859 #endif // wxUSE_BUTTON
861 /// Reparent the controls to the scrolled window
862 void wxStandardDialogLayoutAdapter::ReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
864 DoReparentControls(parent
, reparentTo
, buttonSizer
);
867 void wxStandardDialogLayoutAdapter::DoReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
869 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
872 wxWindowList::compatibility_iterator next
= node
->GetNext();
874 wxWindow
*win
= node
->GetData();
876 // Don't reparent the scrolled window or buttons in the button sizer
877 if (win
!= reparentTo
&& (!buttonSizer
|| !buttonSizer
->GetItem(win
)))
879 win
->Reparent(reparentTo
);
881 // Restore correct tab order
882 ::SetWindowPos((HWND
) win
->GetHWND(), HWND_BOTTOM
, -1, -1, -1, -1, SWP_NOMOVE
|SWP_NOSIZE
);
890 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
891 int wxStandardDialogLayoutAdapter::MustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
893 return DoMustScroll(dialog
, windowSize
, displaySize
);
896 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
897 int wxStandardDialogLayoutAdapter::DoMustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
899 wxSize minWindowSize
= dialog
->GetSizer()->GetMinSize();
900 windowSize
= dialog
->GetSize();
901 windowSize
= wxSize(wxMax(windowSize
.x
, minWindowSize
.x
), wxMax(windowSize
.y
, minWindowSize
.y
));
903 displaySize
= wxDisplay(wxDisplay::GetFromWindow(dialog
)).GetClientArea().GetSize();
905 displaySize
= wxGetClientDisplayRect().GetSize();
910 if (windowSize
.y
>= (displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
))
912 if (windowSize
.x
>= displaySize
.x
)
913 flags
|= wxHORIZONTAL
;
918 // A function to fit the dialog around its contents, and then adjust for screen size.
919 // If scrolled windows are passed, scrolling is enabled in the required orientation(s).
920 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
922 return DoFitWithScrolling(dialog
, windows
);
925 // A function to fit the dialog around its contents, and then adjust for screen size.
926 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
927 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
929 return DoFitWithScrolling(dialog
, scrolledWindow
);
932 // A function to fit the dialog around its contents, and then adjust for screen size.
933 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
934 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
936 wxWindowList windows
;
937 windows
.Append(scrolledWindow
);
938 return DoFitWithScrolling(dialog
, windows
);
941 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
943 wxSizer
* sizer
= dialog
->GetSizer();
947 sizer
->SetSizeHints(dialog
);
949 wxSize windowSize
, displaySize
;
950 int scrollFlags
= DoMustScroll(dialog
, windowSize
, displaySize
);
951 int scrollBarSize
= 20;
955 int scrollBarExtraX
= 0, scrollBarExtraY
= 0;
956 bool resizeHorizontally
= (scrollFlags
& wxHORIZONTAL
) != 0;
957 bool resizeVertically
= (scrollFlags
& wxVERTICAL
) != 0;
959 if (windows
.GetCount() != 0)
961 // Allow extra for a scrollbar, assuming we resizing in one direction only.
962 if ((resizeVertically
&& !resizeHorizontally
) && (windowSize
.x
< (displaySize
.x
- scrollBarSize
)))
963 scrollBarExtraX
= scrollBarSize
;
964 if ((resizeHorizontally
&& !resizeVertically
) && (windowSize
.y
< (displaySize
.y
- scrollBarSize
)))
965 scrollBarExtraY
= scrollBarSize
;
968 wxWindowList::compatibility_iterator node
= windows
.GetFirst();
971 wxWindow
*win
= node
->GetData();
972 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(win
, wxScrolledWindow
);
975 scrolledWindow
->SetScrollRate(resizeHorizontally
? 10 : 0, resizeVertically
? 10 : 0);
977 if (scrolledWindow
->GetSizer())
978 scrolledWindow
->GetSizer()->Fit(scrolledWindow
);
981 node
= node
->GetNext();
984 wxSize limitTo
= windowSize
+ wxSize(scrollBarExtraX
, scrollBarExtraY
);
985 if (resizeVertically
)
986 limitTo
.y
= displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
;
987 if (resizeHorizontally
)
988 limitTo
.x
= displaySize
.x
;
990 dialog
->SetMinSize(limitTo
);
991 dialog
->SetSize(limitTo
);
993 dialog
->SetSizeHints( limitTo
.x
, limitTo
.y
, dialog
->GetMaxWidth(), dialog
->GetMaxHeight() );
1000 * Module to initialise standard adapter
1003 class wxDialogLayoutAdapterModule
: public wxModule
1005 DECLARE_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
)
1007 wxDialogLayoutAdapterModule() {}
1008 virtual void OnExit() { delete wxDialogBase::SetLayoutAdapter(NULL
); }
1009 virtual bool OnInit() { wxDialogBase::SetLayoutAdapter(new wxStandardDialogLayoutAdapter
); return true; }
1012 IMPLEMENT_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
, wxModule
)