1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets propsize sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
19 #if defined(__GNUG__) && !defined(__APPLE__)
20 #pragma implementation "propsize.cpp"
21 #pragma interface "propsize.cpp"
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
31 // for all others, include the necessary headers (this file is usually all you
32 // need because it includes almost all "standard" wxWidgets headers
37 #include "wx/statline.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
42 // the application icon
43 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
44 #include "mondrian.xpm"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // Define a new application type, each program should derive a class from wxApp
52 class MyApp
: public wxApp
55 // override base class virtuals
56 // ----------------------------
58 // this one is called on application startup and is a good place for the app
59 // initialization (doing it here and not in the ctor allows to have an error
60 // return: if OnInit() returns false, the application terminates)
61 virtual bool OnInit();
64 // Define a new frame type: this is going to be our main frame
65 class MyFrame
: public wxFrame
69 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
71 // event handlers (these functions should _not_ be virtual)
72 void OnQuit(wxCommandEvent
& event
);
73 void OnAbout(wxCommandEvent
& event
);
76 // any class wishing to process wxWidgets events must use this macro
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 // IDs for the controls and the menu commands
91 // ----------------------------------------------------------------------------
92 // event tables and other macros for wxWidgets
93 // ----------------------------------------------------------------------------
95 // the event tables connect the wxWidgets events with the functions (event
96 // handlers) which process them. It can be also done at run-time, but for the
97 // simple menu events like this the static method is much simpler.
98 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
99 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
100 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
103 // Create a new application object: this macro will allow wxWidgets to create
104 // the application object during program execution (it's better than using a
105 // static object for many reasons) and also declares the accessor function
106 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
110 // ============================================================================
112 // ============================================================================
114 // ----------------------------------------------------------------------------
115 // the application class
116 // ----------------------------------------------------------------------------
118 // `Main program' equivalent: the program execution "starts" here
121 // Create the main application window
122 MyFrame
*frame
= new MyFrame(_T("Proportional resize"),
123 wxPoint(50, 50), wxSize(450, 340));
125 // Show it and tell the application that it's our main window
126 // @@@ what does it do exactly, in fact? is it necessary here?
130 // success: wxApp::OnRun() will be called which will enter the main message
131 // loop and the application will run. If we returned false here, the
132 // application would exit immediately.
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
141 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
142 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
144 // set the frame icon
145 SetIcon(wxICON(mondrian
));
148 wxMenu
*menuFile
= new wxMenu(_T(""), wxMENU_TEAROFF
);
150 menuFile
->Append(wxID_ABOUT
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
151 menuFile
->AppendSeparator();
152 menuFile
->Append(Minimal_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
154 // now append the freshly created menu to the menu bar...
155 wxMenuBar
*menuBar
= new wxMenuBar();
156 menuBar
->Append(menuFile
, _T("&File"));
158 // ... and attach this menu bar to the frame
162 // create a status bar just for fun (by default with 1 pane only)
164 SetStatusText(_T("Resize the frame to see how controls react"));
165 #endif // wxUSE_STATUSBAR
168 #define AddLine(orient) \
169 Add( new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxSize(2,2), orient), \
172 #define AddLine(orient) \
174 #endif // wxUSE_STATLINE
176 #define AddButton(label,align) Add( \
177 new wxButton( this, wxID_ANY, label, wxDefaultPosition, wxSize(100,50)), \
180 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
181 // top row -- top-aligned
182 wxBoxSizer
*hsizer1
= new wxBoxSizer( wxHORIZONTAL
);
183 hsizer1
->AddButton( _T("one"), wxALIGN_LEFT
| wxALIGN_TOP
);
184 hsizer1
->AddLine(wxVERTICAL
);
185 hsizer1
->AddButton( _T("two"), wxALIGN_CENTER_HORIZONTAL
| wxALIGN_TOP
);
186 hsizer1
->AddLine(wxVERTICAL
);
187 hsizer1
->AddButton( _T("three"), wxALIGN_RIGHT
| wxALIGN_TOP
);
189 topsizer
->Add(hsizer1
, 1, wxEXPAND
);
190 topsizer
->AddLine(wxHORIZONTAL
);
192 wxBoxSizer
*hsizer2
= new wxBoxSizer( wxHORIZONTAL
);
193 hsizer2
->AddButton( _T("four"), wxALIGN_LEFT
| wxALIGN_CENTER_VERTICAL
);
194 hsizer2
->AddLine(wxVERTICAL
);
195 // sizer that preserves it's shape
196 wxBoxSizer
*vsizer
= new wxBoxSizer( wxVERTICAL
);
198 new wxButton( this, wxID_ANY
, _T("up"), wxDefaultPosition
, wxSize(100,25) ),
202 new wxButton( this, wxID_ANY
, _T("down"), wxDefaultPosition
, wxSize(100,25) ),
205 hsizer2
->Add(vsizer
, 1, wxSHAPED
| wxALIGN_CENTER
);
206 hsizer2
->AddLine(wxVERTICAL
);
207 hsizer2
->AddButton( _T("six"), wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
);
209 topsizer
->Add(hsizer2
, 1, wxEXPAND
);
210 topsizer
->AddLine(wxHORIZONTAL
);
212 wxBoxSizer
*hsizer3
= new wxBoxSizer( wxHORIZONTAL
);
213 hsizer3
->AddButton( _T("seven"), wxALIGN_LEFT
| wxALIGN_BOTTOM
);
214 hsizer3
->AddLine(wxVERTICAL
);
215 hsizer3
->AddButton( _T("eight"), wxALIGN_CENTER_HORIZONTAL
| wxALIGN_BOTTOM
);
216 hsizer3
->AddLine(wxVERTICAL
);
217 // wxEXPAND should have no effect
218 hsizer3
->AddButton( _T("nine"), wxEXPAND
| wxALIGN_RIGHT
| wxALIGN_BOTTOM
);
220 topsizer
->Add(hsizer3
, 1, wxEXPAND
);
222 // set frame to minimum size
223 topsizer
->Fit( this );
225 // don't allow frame to get smaller than what the sizers tell ye
226 // topsizer->SetSizeHints( this );
228 SetSizer( topsizer
);
234 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
236 // true is to force the frame to close
240 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
243 msg
.Printf( _T("This is the about dialog of proportional sizer test.\n")
247 #endif // wxBETA_NUMBER
251 #endif // wxBETA_NUMBER
254 wxMessageBox(msg
, _T("About Shaped Sizer"), wxOK
| wxICON_INFORMATION
, this);