1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWindows sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
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" wxWindows headers
37 #include "wx/statline.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
42 // the application icon
43 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
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 wxWindows events must use this macro
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 // IDs for the controls and the menu commands
92 // ----------------------------------------------------------------------------
93 // event tables and other macros for wxWindows
94 // ----------------------------------------------------------------------------
96 // the event tables connect the wxWindows events with the functions (event
97 // handlers) which process them. It can be also done at run-time, but for the
98 // simple menu events like this the static method is much simpler.
99 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
100 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
101 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
104 // Create a new application object: this macro will allow wxWindows to create
105 // the application object during program execution (it's better than using a
106 // static object for many reasons) and also declares the accessor function
107 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
111 // ============================================================================
113 // ============================================================================
115 // ----------------------------------------------------------------------------
116 // the application class
117 // ----------------------------------------------------------------------------
119 // `Main program' equivalent: the program execution "starts" here
122 // Create the main application window
123 MyFrame
*frame
= new MyFrame("Proportional resize",
124 wxPoint(50, 50), wxSize(450, 340));
126 // Show it and tell the application that it's our main window
127 // @@@ what does it do exactly, in fact? is it necessary here?
131 // success: wxApp::OnRun() will be called which will enter the main message
132 // loop and the application will run. If we returned FALSE here, the
133 // application would exit immediately.
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
142 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
143 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
145 // set the frame icon
146 SetIcon(wxICON(mondrian
));
149 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
151 menuFile
->Append(Minimal_About
, "&About...\tCtrl-A", "Show about dialog");
152 menuFile
->AppendSeparator();
153 menuFile
->Append(Minimal_Quit
, "E&xit\tAlt-X", "Quit this program");
155 // now append the freshly created menu to the menu bar...
156 wxMenuBar
*menuBar
= new wxMenuBar();
157 menuBar
->Append(menuFile
, "&File");
159 // ... and attach this menu bar to the frame
163 // create a status bar just for fun (by default with 1 pane only)
165 SetStatusText("Resize the frame to see how controls react");
166 #endif // wxUSE_STATUSBAR
168 #define AddLine(orient) \
169 Add( new wxStaticLine( this, -1, wxDefaultPosition, wxSize(2,2), orient), \
171 #define AddButton(label,align) Add( \
172 new wxButton( this, -1, label, wxDefaultPosition, wxSize(100,50)), \
175 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
176 // top row -- top-aligned
177 wxBoxSizer
*hsizer1
= new wxBoxSizer( wxHORIZONTAL
);
178 hsizer1
->AddButton( "one", wxALIGN_LEFT
| wxALIGN_TOP
);
179 hsizer1
->AddLine(wxVERTICAL
);
180 hsizer1
->AddButton( "two", wxALIGN_CENTER_HORIZONTAL
| wxALIGN_TOP
);
181 hsizer1
->AddLine(wxVERTICAL
);
182 hsizer1
->AddButton( "three", wxALIGN_RIGHT
| wxALIGN_TOP
);
184 topsizer
->Add(hsizer1
, 1, wxEXPAND
);
185 topsizer
->AddLine(wxHORIZONTAL
);
187 wxBoxSizer
*hsizer2
= new wxBoxSizer( wxHORIZONTAL
);
188 hsizer2
->AddButton( "four", wxALIGN_LEFT
| wxALIGN_CENTER_VERTICAL
);
189 hsizer2
->AddLine(wxVERTICAL
);
190 // sizer that preserves it's shape
191 wxBoxSizer
*vsizer
= new wxBoxSizer( wxVERTICAL
);
193 new wxButton( this, -1, "up", wxDefaultPosition
, wxSize(100,25)), \
196 new wxButton( this, -1, "down", wxDefaultPosition
, wxSize(100,25)), \
198 hsizer2
->Add(vsizer
, 1, wxSHAPED
| wxALIGN_CENTER
);
199 hsizer2
->AddLine(wxVERTICAL
);
200 hsizer2
->AddButton( "six", wxALIGN_RIGHT
| wxALIGN_CENTER_VERTICAL
);
202 topsizer
->Add(hsizer2
, 1, wxEXPAND
);
203 topsizer
->AddLine(wxHORIZONTAL
);
205 wxBoxSizer
*hsizer3
= new wxBoxSizer( wxHORIZONTAL
);
206 hsizer3
->AddButton( "seven", wxALIGN_LEFT
| wxALIGN_BOTTOM
);
207 hsizer3
->AddLine(wxVERTICAL
);
208 hsizer3
->AddButton( "eight", wxALIGN_CENTER_HORIZONTAL
| wxALIGN_BOTTOM
);
209 hsizer3
->AddLine(wxVERTICAL
);
210 // wxEXPAND should have no effect
211 hsizer3
->AddButton( "nine", wxEXPAND
| wxALIGN_RIGHT
| wxALIGN_BOTTOM
);
213 topsizer
->Add(hsizer3
, 1, wxEXPAND
);
215 // set frame to minimum size
216 topsizer
->Fit( this );
218 // don't allow frame to get smaller than what the sizers tell ye
219 // topsizer->SetSizeHints( this );
221 SetSizer( topsizer
);
222 SetAutoLayout( TRUE
);
228 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
230 // TRUE is to force the frame to close
234 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
237 msg
.Printf( _T("This is the about dialog of proportional sizer test.\n")
241 #endif // wxBETA_NUMBER
245 #endif // wxBETA_NUMBER
248 wxMessageBox(msg
, "About Shaped Sizer", wxOK
| wxICON_INFORMATION
, this);