]> git.saurik.com Git - wxWidgets.git/blob - samples/drawer/drawertest.cpp
add drawer sample
[wxWidgets.git] / samples / drawer / drawertest.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tbtest.cpp
3 // Purpose: wxTaskBarIcon demo
4 // Author: Julian Smart
5 // Modified by: Ryan Norton (Drawer)
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22
23 // the application icon (under Windows and OS/2 it is in resources)
24 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
25 #include "../sample.xpm"
26 #endif
27
28 #include "smile.xpm"
29
30 #include "wx/taskbar.h"
31
32 #if defined(__WXMAC__)
33 #include "wx/mac/private.h"
34 #endif
35
36 //include this sample's header
37 #include "tbtest.h"
38
39
40 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
41
42 //drawer
43 #include "wx/dcclient.h"
44 #include "wx/mac/carbon/drawer.h"
45
46 class MyDrawer : public wxDrawerWindow
47 {
48 public:
49 MyDrawer(wxWindow* p) : wxDrawerWindow(p, wxID_ANY, wxT(""), wxSize(200,200))
50 { }
51
52 void OnPaint(wxPaintEvent&)
53 {
54 wxPaintDC dc(this);
55 dc.DrawRectangle(30,30,60,60);
56 }
57
58 DECLARE_EVENT_TABLE()
59 };
60
61 BEGIN_EVENT_TABLE(MyDrawer, wxDrawerWindow)
62 EVT_PAINT(MyDrawer::OnPaint)
63 END_EVENT_TABLE()
64
65 #endif
66 //OSX 10.2+
67
68 MyDialog *dialog = NULL;
69
70 IMPLEMENT_APP(MyApp)
71
72 bool MyApp::OnInit(void)
73 {
74 // Create the main frame window
75 dialog = new MyDialog(NULL, wxID_ANY, wxT("wxTaskBarIcon Test Dialog"), wxDefaultPosition, wxSize(365, 290));
76
77 dialog->Show(true);
78
79 return true;
80 }
81
82
83 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
84 EVT_BUTTON(wxID_OK, MyDialog::OnOK)
85 EVT_BUTTON(wxID_EXIT, MyDialog::OnExit)
86 EVT_CLOSE(MyDialog::OnCloseWindow)
87 END_EVENT_TABLE()
88
89
90
91 MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title,
92 const wxPoint& pos, const wxSize& size, const long windowStyle):
93 wxDialog(parent, id, title, pos, size, windowStyle)
94 {
95 Init();
96 }
97
98 MyDialog::~MyDialog()
99 {
100 delete m_taskBarIcon;
101 }
102
103 void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event))
104 {
105 Show(false);
106 }
107
108 void MyDialog::OnExit(wxCommandEvent& WXUNUSED(event))
109 {
110 Close(true);
111 }
112
113 void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
114 {
115 Destroy();
116 }
117
118 void MyDialog::Init(void)
119 {
120 (void)new wxStaticText(this, wxID_ANY, _T("Press 'Hide me' to hide me, Exit to quit."),
121 wxPoint(10, 20));
122
123 (void)new wxStaticText(this, wxID_ANY, _T("Double-click on the taskbar icon to show me again."),
124 wxPoint(10, 40));
125
126 (void)new wxButton(this, wxID_EXIT, _T("Exit"), wxPoint(185, 230), wxSize(80, 25));
127 (new wxButton(this, wxID_OK, _T("Hide me"), wxPoint(100, 230), wxSize(80, 25)))->SetDefault();
128 Centre(wxBOTH);
129
130 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
131
132 MacSetMetalAppearance(true);
133 Show(TRUE);
134
135 MyDrawer* pMyDrawer = new MyDrawer(this);
136 pMyDrawer->Open(true);
137
138 m_taskBarIcon = new MyTaskBarIcon(pMyDrawer);
139 #else
140 m_taskBarIcon = new MyTaskBarIcon();
141 #endif
142
143 if (!m_taskBarIcon->SetIcon(wxICON(sample), wxT("wxTaskBarIcon Sample")))
144 wxMessageBox(wxT("Could not set icon."));
145 }
146
147
148 enum {
149 PU_RESTORE = 10001,
150
151 PU_NEW_ICON,
152 PU_OLD_ICON,
153
154 PU_OPEN_DRAWER,
155 PU_CLOSE_DRAWER,
156
157 PU_LEFT_DRAWER,
158 PU_RIGHT_DRAWER,
159 PU_TOP_DRAWER,
160 PU_BOTTOM_DRAWER,
161
162 PU_EXIT,
163 };
164
165
166 BEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon)
167 EVT_MENU(PU_RESTORE, MyTaskBarIcon::OnMenuRestore)
168 EVT_MENU(PU_EXIT, MyTaskBarIcon::OnMenuExit)
169 EVT_MENU(PU_NEW_ICON,MyTaskBarIcon::OnMenuSetNewIcon)
170 EVT_MENU(PU_OLD_ICON,MyTaskBarIcon::OnMenuSetOldIcon)
171 EVT_MENU(PU_OPEN_DRAWER,MyTaskBarIcon::OnMenuOpenDrawer)
172 EVT_MENU(PU_CLOSE_DRAWER,MyTaskBarIcon::OnMenuCloseDrawer)
173 EVT_MENU(PU_TOP_DRAWER,MyTaskBarIcon::OnMenuTopDrawer)
174 EVT_MENU(PU_BOTTOM_DRAWER,MyTaskBarIcon::OnMenuBottomDrawer)
175 EVT_MENU(PU_LEFT_DRAWER,MyTaskBarIcon::OnMenuLeftDrawer)
176 EVT_MENU(PU_RIGHT_DRAWER,MyTaskBarIcon::OnMenuRightDrawer)
177 EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon::OnLButtonDClick)
178 END_EVENT_TABLE()
179
180 void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& )
181 {
182 dialog->Show(true);
183 }
184
185 void MyTaskBarIcon::OnMenuExit(wxCommandEvent& )
186 {
187 dialog->Close(true);
188 }
189
190 void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&)
191 {
192 wxIcon icon(smile_xpm);
193
194 if (!SetIcon(icon, wxT("wxTaskBarIcon Sample - a different icon")))
195 wxMessageBox(wxT("Could not set new icon."));
196 }
197
198 void MyTaskBarIcon::OnMenuSetOldIcon(wxCommandEvent&)
199 {
200 wxIcon icon(wxT("wxDEFAULT_FRAME"));
201
202 if (!RemoveIcon())
203 wxMessageBox(wxT("Could not restore old icon."));
204 }
205
206 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
207
208 void MyTaskBarIcon::OnMenuOpenDrawer(wxCommandEvent&)
209 {
210 m_pMyDrawer->Open(true);
211 }
212
213 void MyTaskBarIcon::OnMenuCloseDrawer(wxCommandEvent&)
214 {
215 m_pMyDrawer->Close();
216 }
217
218 void MyTaskBarIcon::OnMenuLeftDrawer(wxCommandEvent&)
219 {
220 m_pMyDrawer->SetPreferredEdge(wxLEFT);
221 }
222
223 void MyTaskBarIcon::OnMenuRightDrawer(wxCommandEvent&)
224 {
225 m_pMyDrawer->SetPreferredEdge(wxRIGHT);
226 }
227
228 void MyTaskBarIcon::OnMenuTopDrawer(wxCommandEvent&)
229 {
230 m_pMyDrawer->SetPreferredEdge(wxTOP);
231 }
232
233 void MyTaskBarIcon::OnMenuBottomDrawer(wxCommandEvent&)
234 {
235 m_pMyDrawer->SetPreferredEdge(wxBOTTOM);
236 }
237 #endif
238
239 // Overridables
240 wxMenu *MyTaskBarIcon::CreatePopupMenu()
241 {
242 wxMenu *menu = new wxMenu;
243
244 menu->Append(PU_RESTORE, _T("&Restore TBTest"));
245 menu->Append(PU_NEW_ICON,_T("&Set New Icon"));
246 menu->Append(PU_OLD_ICON,_T("&Restore Old Icon"));
247 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
248 menu->AppendSeparator();
249 menu->Append(PU_OPEN_DRAWER,_T("Open Drawer"));
250 menu->Append(PU_CLOSE_DRAWER,_T("Close Drawer"));
251 menu->AppendSeparator();
252 menu->Append(PU_LEFT_DRAWER,_T("Set Drawer to come out on the LEFT side"));
253 menu->Append(PU_RIGHT_DRAWER,_T("Set Drawer to come out on the RIGHT side"));
254 menu->Append(PU_TOP_DRAWER,_T("Set Drawer to come out on the TOP side"));
255 menu->Append(PU_BOTTOM_DRAWER,_T("Set Drawer to come out on the BOTTOM side"));
256 #else
257 menu->AppendSeparator();
258 menu->Append(PU_EXIT, _T("E&xit"));
259 #endif
260 return menu;
261 }
262
263 void MyTaskBarIcon::OnLButtonDClick(wxTaskBarIconEvent&)
264 {
265 dialog->Show(true);
266 }