1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindows sample showing the features of wxDisplay class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".from here
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers explicitly
32 #include "wx/stattext.h"
34 #include "wx/layout.h"
37 #include "wx/notebook.h"
39 #include "wx/display.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 // Define a new application type, each program should derive a class from wxApp
46 class MyApp
: public wxApp
49 // override base class virtuals
50 // ----------------------------
52 // this one is called on application startup and is a good place for the app
53 // initialization (doing it here and not in the ctor allows to have an error
54 // return: if OnInit() returns false, the application terminates)
55 virtual bool OnInit();
58 // Define a new frame type: this is going to be our main frame
59 class MyFrame
: public wxFrame
63 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
,
64 long style
= wxDEFAULT_FRAME_STYLE
);
66 // event handlers (these functions should _not_ be virtual)
67 void OnQuit(wxCommandEvent
& event
);
68 void OnAbout(wxCommandEvent
& event
);
71 // any class wishing to process wxWindows events must use this macro
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 // IDs for the controls and the menu commands
85 // it is important for the id corresponding to the "About" command to have
86 // this standard value as otherwise it won't be handled properly under Mac
87 // (where it is special and put into the "Apple" menu)
88 Display_About
= wxID_ABOUT
91 // ----------------------------------------------------------------------------
92 // event tables and other macros for wxWindows
93 // ----------------------------------------------------------------------------
95 // the event tables connect the wxWindows 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(Display_Quit
, MyFrame
::OnQuit
)
100 EVT_MENU(Display_About
, MyFrame
::OnAbout
)
103 // Create a new application object: this macro will allow wxWindows 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(_("Display wxWindows Sample"),
123 wxPoint(50, 50), wxSize(450, 340));
125 // and show it (the frames, unlike simple controls, are not shown when
126 // created initially)
129 // success: wxApp::OnRun() will be called which will enter the main message
130 // loop and the application will run. If we returned FALSE here, the
131 // application would exit immediately.
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
140 MyFrame
::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
)
141 : wxFrame(NULL
, -1, title
, pos
, size
, style
)
143 // set the frame icon
144 SetIcon(wxICON(mondrian
));
148 wxMenu
*menuFile
= new wxMenu
;
150 // the "About" item should be in the help menu
151 wxMenu
*helpMenu
= new wxMenu
;
152 helpMenu
->Append(Display_About
, _("&About...\tF1"), _("Show about dialog"));
154 menuFile
->Append(Display_Quit
, _("E&xit\tAlt-X"), _("Quit this program"));
156 // now append the freshly created menu to the menu bar...
157 wxMenuBar
*menuBar
= new wxMenuBar();
158 menuBar
->Append(menuFile
, _("&File"));
159 menuBar
->Append(helpMenu
, _("&Help"));
161 // ... and attach this menu bar to the frame
163 #endif // wxUSE_MENUS
165 // create child controls
166 wxNotebook
*notebook
= new wxNotebook(this, -1);
167 const size_t count
= wxDisplay
::GetCount();
168 for ( size_t n
= 0; n
< count
; n
++ )
170 wxDisplay
display(n
);
172 wxWindow
*page
= new wxPanel(notebook
, -1);
174 // create 2 column flex grid sizer with growable 2nd column
175 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 10, 20);
176 sizer
->AddGrowableCol(1);
178 const wxRect
r(display
.GetGeometry());
179 sizer
->Add(new wxStaticText(page
, -1, _T("Geometry: ")));
180 sizer
->Add(new wxStaticText
184 wxString
::Format(_T("(%d, %d)-(%d, %d)"),
186 r
.x
+ r
.width
, r
.y
+ r
.height
)
189 sizer
->Add(new wxStaticText(page
, -1, _T("Depth: ")));
190 sizer
->Add(new wxStaticText
194 wxString
::Format(_T("%d bpp"), display
.GetDepth())
197 sizer
->Add(new wxStaticText(page
, -1, _T("Colour: ")));
198 sizer
->Add(new wxStaticText(page
, -1, display
.IsColour() ?
_T("Yes")
201 // add it to another sizer to have borders around it
202 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
203 sizerTop
->Add(sizer
, 1, wxALL
| wxEXPAND
, 10);
204 page
->SetSizer(sizerTop
);
206 notebook
->AddPage(page
,
207 wxString
::Format(_T("Display %lu"), (unsigned long)n
));
214 void MyFrame
::OnQuit(wxCommandEvent
& WXUNUSED(event
))
216 // TRUE is to force the frame to close
220 void MyFrame
::OnAbout(wxCommandEvent
& WXUNUSED(event
))
222 wxMessageBox(_T("Demo program for wxDisplay class.\n\n(c) 2003 Vadim Zeitlin"),
223 _T("About Display Sample"),
224 wxOK
| wxICON_INFORMATION
,