1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets propsize sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers
33 #include "wx/statline.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
38 // the application icon
39 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
40 #include "mondrian.xpm"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 // Define a new application type, each program should derive a class from wxApp
48 class MyApp
: public wxApp
51 // override base class virtuals
52 // ----------------------------
54 // this one is called on application startup and is a good place for the app
55 // initialization (doing it here and not in the ctor allows to have an error
56 // return: if OnInit() returns false, the application terminates)
57 virtual bool OnInit();
60 // Define a new frame type: this is going to be our main frame
61 class MyFrame
: public wxFrame
65 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
67 // event handlers (these functions should _not_ be virtual)
68 void OnQuit(wxCommandEvent
& event
);
69 void OnAbout(wxCommandEvent
& event
);
72 // any class wishing to process wxWidgets events must use this macro
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 // IDs for the controls and the menu commands
87 // ----------------------------------------------------------------------------
88 // event tables and other macros for wxWidgets
89 // ----------------------------------------------------------------------------
91 // the event tables connect the wxWidgets events with the functions (event
92 // handlers) which process them. It can be also done at run-time, but for the
93 // simple menu events like this the static method is much simpler.
94 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
95 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
96 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
99 // Create a new application object: this macro will allow wxWidgets to create
100 // the application object during program execution (it's better than using a
101 // static object for many reasons) and also declares the accessor function
102 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
106 // ============================================================================
108 // ============================================================================
110 // ----------------------------------------------------------------------------
111 // the application class
112 // ----------------------------------------------------------------------------
114 // `Main program' equivalent: the program execution "starts" here
117 // Create the main application window
118 MyFrame
*frame
= new MyFrame(_T("Proportional resize"),
119 wxPoint(50, 50), wxSize(450, 340));
121 // Show it and tell the application that it's our main window
122 // @@@ what does it do exactly, in fact? is it necessary here?
126 // success: wxApp::OnRun() will be called which will enter the main message
127 // loop and the application will run. If we returned false here, the
128 // application would exit immediately.
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
137 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
138 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
140 // set the frame icon
141 SetIcon(wxICON(mondrian
));
144 wxMenu
*menuFile
= new wxMenu(_T(""), wxMENU_TEAROFF
);
146 menuFile
->Append(wxID_ABOUT
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
147 menuFile
->AppendSeparator();
148 menuFile
->Append(Minimal_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
150 // now append the freshly created menu to the menu bar...
151 wxMenuBar
*menuBar
= new wxMenuBar();
152 menuBar
->Append(menuFile
, _T("&File"));
154 // ... and attach this menu bar to the frame
158 // create a status bar just for fun (by default with 1 pane only)
160 SetStatusText(_T("Resize the frame to see how controls react"));
161 #endif // wxUSE_STATUSBAR
164 #define AddLine(orient) \
165 Add( new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxSize(2,2), orient), \
168 #define AddLine(orient) \
170 #endif // wxUSE_STATLINE
172 #define AddButton(label,align) Add( \
173 new wxButton( this, wxID_ANY, label, wxDefaultPosition, wxSize(100,50)), \
176 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
177 // top row -- top-aligned
178 wxBoxSizer
*hsizer1
= new wxBoxSizer( wxHORIZONTAL
);
179 hsizer1
->AddButton( _T("one"), wxALIGN_LEFT
| wxALIGN_TOP
);
180 hsizer1
->AddLine(wxVERTICAL
);
181 hsizer1
->AddButton( _T("two"), wxALIGN_CENTER_HORIZONTAL
| wxALIGN_TOP
);
182 hsizer1
->AddLine(wxVERTICAL
);
183 hsizer1
->AddButton( _T("three"), wxALIGN_RIGHT
| wxALIGN_TOP
);
185 topsizer
->Add(hsizer1
, 1, wxEXPAND
);
186 topsizer
->AddLine(wxHORIZONTAL
);
188 wxBoxSizer
*hsizer2
= new wxBoxSizer( wxHORIZONTAL
);
189 hsizer2
->AddButton( _T("four"), wxALIGN_LEFT
| wxALIGN_CENTER_VERTICAL
);
190 hsizer2
->AddLine(wxVERTICAL
);
191 // sizer that preserves it's shape
192 wxBoxSizer
*vsizer
= new wxBoxSizer( wxVERTICAL
);
194 new wxButton( this, wxID_ANY
, _T("up"), wxDefaultPosition
, wxSize(100,25) ),
198 new wxButton( this, wxID_ANY
, _T("down"), wxDefaultPosition
, wxSize(100,25) ),
201 hsizer2
->Add(vsizer
, 1, wxSHAPED
| wxALIGN_CENTER
);
202 hsizer2
->AddLine(wxVERTICAL
);
203 hsizer2
->AddButton( _T("six"), wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
);
205 topsizer
->Add(hsizer2
, 1, wxEXPAND
);
206 topsizer
->AddLine(wxHORIZONTAL
);
208 wxBoxSizer
*hsizer3
= new wxBoxSizer( wxHORIZONTAL
);
209 hsizer3
->AddButton( _T("seven"), wxALIGN_LEFT
| wxALIGN_BOTTOM
);
210 hsizer3
->AddLine(wxVERTICAL
);
211 hsizer3
->AddButton( _T("eight"), wxALIGN_CENTER_HORIZONTAL
| wxALIGN_BOTTOM
);
212 hsizer3
->AddLine(wxVERTICAL
);
213 // wxEXPAND should have no effect
214 hsizer3
->AddButton( _T("nine"), wxEXPAND
| wxALIGN_RIGHT
| wxALIGN_BOTTOM
);
216 topsizer
->Add(hsizer3
, 1, wxEXPAND
);
218 // set frame to minimum size
219 topsizer
->Fit( this );
221 // don't allow frame to get smaller than what the sizers tell ye
222 // topsizer->SetSizeHints( this );
224 SetSizer( topsizer
);
230 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
232 // true is to force the frame to close
236 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
239 msg
.Printf( _T("This is the about dialog of proportional sizer test.\n")
243 #endif // wxBETA_NUMBER
247 #endif // wxBETA_NUMBER
250 wxMessageBox(msg
, _T("About Shaped Sizer"), wxOK
| wxICON_INFORMATION
, this);