]> git.saurik.com Git - wxWidgets.git/blob - samples/taskbar/tbtest.cpp
use Windows standard icons instead of our own (patch 443856)
[wxWidgets.git] / samples / taskbar / tbtest.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tbtest.cpp
3 // Purpose: wxTaskBarIcon demo
4 // Author: Julian Smart
5 // Modified by:
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 #include <wx/msw/taskbar.h>
24 #include "tbtest.h"
25
26 // Declare two frames
27 MyDialog *dialog = NULL;
28
29 IMPLEMENT_APP(MyApp)
30
31 bool MyApp::OnInit(void)
32 {
33 wxIcon icon(wxT("mondrian_icon"));
34
35 if (!m_taskBarIcon.SetIcon(icon, wxT("wxTaskBarIcon Sample")))
36 wxMessageBox(wxT("Could not set icon."));
37
38 // Create the main frame window
39 dialog = new MyDialog(NULL, -1, wxT("wxTaskBarIcon Test Dialog"), wxPoint(-1, -1), wxSize(365, 290), wxDIALOG_MODELESS|wxDEFAULT_DIALOG_STYLE);
40
41 dialog->Show(TRUE);
42
43 return TRUE;
44 }
45
46
47 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
48 EVT_BUTTON(wxID_OK, MyDialog::OnOK)
49 EVT_BUTTON(wxID_EXIT, MyDialog::OnExit)
50 EVT_CLOSE(MyDialog::OnCloseWindow)
51 END_EVENT_TABLE()
52
53
54
55 MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title,
56 const wxPoint& pos, const wxSize& size, const long windowStyle):
57 wxDialog(parent, id, title, pos, size, windowStyle)
58 {
59 Init();
60 }
61
62 void MyDialog::OnOK(wxCommandEvent& event)
63 {
64 Show(FALSE);
65 }
66
67 void MyDialog::OnExit(wxCommandEvent& event)
68 {
69 Close(TRUE);
70 }
71
72 void MyDialog::OnCloseWindow(wxCloseEvent& event)
73 {
74 Destroy();
75 }
76
77 void MyDialog::Init(void)
78 {
79 int dialogWidth = 365;
80 int dialogHeight = 290;
81
82 wxStaticText* stat = new wxStaticText(this, -1, "Press OK to hide me, Exit to quit.",
83 wxPoint(10, 20));
84
85 wxStaticText* stat2 = new wxStaticText(this, -1, "Double-click on the taskbar icon to show me again.",
86 wxPoint(10, 40));
87
88 wxButton *okButton = new wxButton(this, wxID_OK, "OK", wxPoint(100, 230), wxSize(80, 25));
89 wxButton *exitButton = new wxButton(this, wxID_EXIT, "Exit", wxPoint(185, 230), wxSize(80, 25));
90 okButton->SetDefault();
91 this->Centre(wxBOTH);
92 }
93
94
95 enum {
96 PU_RESTORE = 10001,
97 PU_NEW_ICON,
98 PU_EXIT,
99 };
100
101
102 BEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon)
103 EVT_MENU(PU_RESTORE, MyTaskBarIcon::OnMenuRestore)
104 EVT_MENU(PU_EXIT, MyTaskBarIcon::OnMenuExit)
105 EVT_MENU(PU_NEW_ICON,MyTaskBarIcon::OnMenuSetNewIcon)
106 END_EVENT_TABLE()
107
108 void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& )
109 {
110 dialog->Show(TRUE);
111 }
112
113 void MyTaskBarIcon::OnMenuExit(wxCommandEvent& )
114 {
115 dialog->Close(TRUE);
116
117 // Nudge wxWindows into destroying the dialog, since
118 // with a hidden window no messages will get sent to put
119 // it into idle processing.
120 wxGetApp().ProcessIdle();
121 }
122
123 void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&)
124 {
125 #ifdef __WXMSW__
126 wxIcon icon(wxT("wxDEFAULT_FRAME"));
127
128 if (!SetIcon(icon, wxT("wxTaskBarIcon Sample")))
129 wxMessageBox(wxT("Could not set new icon."));
130 #endif
131 }
132
133 // Overridables
134 void MyTaskBarIcon::OnMouseMove(wxEvent&)
135 {
136 }
137
138 void MyTaskBarIcon::OnLButtonDown(wxEvent&)
139 {
140 }
141
142 void MyTaskBarIcon::OnLButtonUp(wxEvent&)
143 {
144 }
145
146 void MyTaskBarIcon::OnRButtonDown(wxEvent&)
147 {
148 }
149
150 void MyTaskBarIcon::OnRButtonUp(wxEvent&)
151 {
152 wxMenu menu;
153
154 menu.Append(PU_RESTORE, "&Restore TBTest");
155 #ifdef __WXMSW__
156 menu.Append(PU_NEW_ICON,"&Set New Icon");
157 #endif
158 menu.Append(PU_EXIT, "E&xit");
159
160 PopupMenu(&menu);
161 }
162
163 void MyTaskBarIcon::OnLButtonDClick(wxEvent&)
164 {
165 dialog->Show(TRUE);
166 }
167
168 void MyTaskBarIcon::OnRButtonDClick(wxEvent&)
169 {
170 }
171
172
173
174