1 /*
2 * This file is part of wxSmith plugin for Code::Blocks Studio
3 * Copyright (C) 2006-2007 Bartlomiej Swiecki
4 *
5 * wxSmith is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * wxSmith is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * $Revision: 10771 $
19 * $Id: wxsdialog.cpp 10771 2016-02-06 14:29:31Z mortenmacfly $
20 * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/contrib/wxSmith/wxwidgets/defitems/wxsdialog.cpp $
21 */
22
23 #include <wx/app.h> // wxTheApp
24 #include <wx/frame.h> // wxFRAME_SHAPED
25 #include <wx/settings.h> // wxSystemSettings, wxSYS_COLOUR_BTNFACE
26 #include "wxsdialog.h"
27 #include "../wxsgridpanel.h"
28
29 namespace
30 {
31 wxsRegisterItem<wxsDialog> Reg( _T("Dialog"), wxsTContainer, _T(""), 0 );
32
33 WXS_ST_BEGIN(wxsDialogStyles,_T("wxDEFAULT_DIALOG_STYLE"))
34 WXS_ST_CATEGORY("wxDialog")
35 WXS_ST(wxSTAY_ON_TOP)
36 WXS_ST(wxCAPTION)
37 WXS_ST(wxDEFAULT_DIALOG_STYLE)
38 WXS_ST(wxSYSTEM_MENU)
39 WXS_ST(wxRESIZE_BORDER)
40 WXS_ST(wxCLOSE_BOX)
41 WXS_ST(wxDIALOG_NO_PARENT)
42 WXS_ST(wxTAB_TRAVERSAL)
43 WXS_ST(wxMAXIMIZE_BOX)
44 WXS_ST(wxMINIMIZE_BOX)
45 WXS_ST(wxFRAME_SHAPED)
46 WXS_EXST(wxDIALOG_EX_CONTEXTHELP)
47 WXS_EXST(wxDIALOG_EX_METAL)
48 WXS_ST_DEFAULTS()
49 WXS_ST_END()
50
51 WXS_EV_BEGIN(wxsDialogEvents)
52 WXS_EVI(EVT_INIT_DIALOG,wxEVT_INIT_DIALOG,wxInitDialogEvent,Init)
53 WXS_EVI(EVT_CLOSE,wxEVT_CLOSE_WINDOW,wxCloseEvent,Close)
54 WXS_EV_DEFAULTS()
55 WXS_EV_END()
56 }
57
wxsDialog(wxsItemResData * Data)58 wxsDialog::wxsDialog(wxsItemResData* Data):
59 wxsContainer(
60 Data,
61 &Reg.Info,
62 wxsDialogEvents,
63 wxsDialogStyles),
64 Title(_("Dialog")),
65 Centered(true)
66 {}
67
OnBuildCreatingCode()68 void wxsDialog::OnBuildCreatingCode()
69 {
70 switch ( GetLanguage() )
71 {
72 case wxsCPP:
73 {
74 AddHeader(_T("<wx/dialog.h>"),GetInfo().ClassName,hfInPCH);
75 Codef(_T("%C(%W, %I, %t, wxDefaultPosition, wxDefaultSize, %T, %N);\n"),Title.wx_str());
76 if ( !GetBaseProps()->m_Size.IsDefault || (GetPropertiesFlags()&flSource && IsRootItem() && GetBaseProps()->m_SizeFromArg) )
77 {
78 Codef(_T("%ASetClientSize(%S);\n"));
79 }
80 if ( !GetBaseProps()->m_Position.IsDefault || (GetPropertiesFlags()&flSource && IsRootItem() && GetBaseProps()->m_PositionFromArg) )
81 {
82 Codef(_T("%AMove(%P);\n"));
83 }
84 BuildSetupWindowCode();
85 AddChildrenCode();
86 if ( Centered )
87 {
88 Codef(_T("%ACenter();\n"));
89 }
90
91 return;
92 }
93
94 case wxsUnknownLanguage: // fall-through
95 default:
96 {
97 wxsCodeMarks::Unknown(_T("wxsDialog::OnBuildCreatingCode"),GetLanguage());
98 }
99 }
100 }
101
OnBuildPreview(wxWindow * Parent,long Flags)102 wxObject* wxsDialog::OnBuildPreview(wxWindow* Parent,long Flags)
103 {
104 wxWindow* NewItem = 0;
105 wxDialog* Dlg = 0;
106
107 // In case of frame and dialog when in "Exact" mode, we do not create
108 // new object, but use Parent and call Create for it.
109 if ( Flags & pfExact )
110 {
111 Dlg = wxDynamicCast(Parent,wxDialog);
112 if ( Dlg )
113 {
114 Dlg->Create(0,GetId(),Title,wxDefaultPosition,wxDefaultSize,Style());
115 Dlg->SetClientSize(Size(wxTheApp->GetTopWindow()));
116 Dlg->Move(Pos(wxTheApp->GetTopWindow()));
117 }
118 NewItem = Dlg;
119 SetupWindow(NewItem,Flags);
120 AddChildrenPreview(NewItem,Flags);
121 if ( Centered )
122 {
123 Dlg->Centre();
124 }
125 }
126 else
127 {
128 NewItem = new wxsGridPanel(Parent,GetId(),wxPoint(0,0),Size(Parent),0);
129 NewItem->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
130 SetupWindow(NewItem,Flags);
131 AddChildrenPreview(NewItem,Flags);
132
133 // wxPanel tends to behave very strange when it has children and no sizer,
134 // we have to manually resize it's content
135 if ( !GetChildCount() || GetChild(0)->GetType()!=wxsTSizer )
136 {
137 wxSize NewSize = Size(Parent);
138 if ( !NewSize.IsFullySpecified() )
139 {
140 NewSize.SetDefaults(wxSize(400,450));
141 NewItem->SetSize(NewSize);
142 NewItem->SetInitialSize(NewSize);
143 if ( GetChildCount() == 1 )
144 {
145 // If there's only one child it's size gets dialog's size
146 wxWindow* ChildPreview = wxDynamicCast(GetChild(0)->GetLastPreview(),wxWindow);
147 if ( ChildPreview )
148 {
149 ChildPreview->SetSize(0,0,NewItem->GetClientSize().GetWidth(),NewItem->GetClientSize().GetHeight());
150 }
151 }
152 }
153 else
154 {
155 NewItem->SetSize(NewSize);
156 NewItem->SetInitialSize(NewSize);
157 }
158 }
159 }
160
161 return NewItem;
162 }
163
OnEnumContainerProperties(cb_unused long Flags)164 void wxsDialog::OnEnumContainerProperties(cb_unused long Flags)
165 {
166 WXS_SHORT_STRING(wxsDialog,Title,_("Title"),_T("title"),_T(""),false)
167 WXS_BOOL(wxsDialog,Centered,_("Centered"),_T("centered"),false);
168 }
169