]>
Commit | Line | Data |
---|---|---|
bbf1f0e5 KB |
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) | |
2f6c54eb | 9 | // Licence: wxWindows licence |
bbf1f0e5 KB |
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 | |
788233da | 20 | #include "wx/wx.h" |
bbf1f0e5 KB |
21 | #endif |
22 | ||
e015d1f7 | 23 | #include "wx/taskbar.h" |
bbf1f0e5 KB |
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 | { | |
ab85e6cd | 33 | wxIcon icon(wxT("mondrian_icon")); |
bbf1f0e5 | 34 | |
ab85e6cd JS |
35 | if (!m_taskBarIcon.SetIcon(icon, wxT("wxTaskBarIcon Sample"))) |
36 | wxMessageBox(wxT("Could not set icon.")); | |
bbf1f0e5 KB |
37 | |
38 | // Create the main frame window | |
ab85e6cd | 39 | dialog = new MyDialog(NULL, -1, wxT("wxTaskBarIcon Test Dialog"), wxPoint(-1, -1), wxSize(365, 290), wxDIALOG_MODELESS|wxDEFAULT_DIALOG_STYLE); |
bbf1f0e5 KB |
40 | |
41 | dialog->Show(TRUE); | |
42 | ||
43 | return TRUE; | |
44 | } | |
45 | ||
69ecd30f | 46 | |
bbf1f0e5 KB |
47 | BEGIN_EVENT_TABLE(MyDialog, wxDialog) |
48 | EVT_BUTTON(wxID_OK, MyDialog::OnOK) | |
49 | EVT_BUTTON(wxID_EXIT, MyDialog::OnExit) | |
d66d9d5b | 50 | EVT_CLOSE(MyDialog::OnCloseWindow) |
bbf1f0e5 KB |
51 | END_EVENT_TABLE() |
52 | ||
69ecd30f RD |
53 | |
54 | ||
bbf1f0e5 KB |
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 | { | |
e0221ef7 VZ |
79 | (void)new wxStaticText(this, -1, "Press OK to hide me, Exit to quit.", |
80 | wxPoint(10, 20)); | |
bbf1f0e5 | 81 | |
e0221ef7 VZ |
82 | (void)new wxStaticText(this, -1, "Double-click on the taskbar icon to show me again.", |
83 | wxPoint(10, 40)); | |
69ecd30f | 84 | |
e0221ef7 VZ |
85 | (void)new wxButton(this, wxID_EXIT, "Exit", wxPoint(185, 230), wxSize(80, 25)); |
86 | (new wxButton(this, wxID_OK, "OK", wxPoint(100, 230), wxSize(80, 25)))->SetDefault(); | |
87 | Centre(wxBOTH); | |
bbf1f0e5 KB |
88 | } |
89 | ||
69ecd30f RD |
90 | |
91 | enum { | |
92 | PU_RESTORE = 10001, | |
ab85e6cd | 93 | PU_NEW_ICON, |
69ecd30f RD |
94 | PU_EXIT, |
95 | }; | |
96 | ||
97 | ||
98 | BEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon) | |
99 | EVT_MENU(PU_RESTORE, MyTaskBarIcon::OnMenuRestore) | |
100 | EVT_MENU(PU_EXIT, MyTaskBarIcon::OnMenuExit) | |
ab85e6cd | 101 | EVT_MENU(PU_NEW_ICON,MyTaskBarIcon::OnMenuSetNewIcon) |
69ecd30f RD |
102 | END_EVENT_TABLE() |
103 | ||
a42b93aa | 104 | void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& ) |
69ecd30f RD |
105 | { |
106 | dialog->Show(TRUE); | |
107 | } | |
108 | ||
a42b93aa | 109 | void MyTaskBarIcon::OnMenuExit(wxCommandEvent& ) |
69ecd30f RD |
110 | { |
111 | dialog->Close(TRUE); | |
f6bcfd97 BP |
112 | |
113 | // Nudge wxWindows into destroying the dialog, since | |
114 | // with a hidden window no messages will get sent to put | |
115 | // it into idle processing. | |
116 | wxGetApp().ProcessIdle(); | |
69ecd30f RD |
117 | } |
118 | ||
ab85e6cd JS |
119 | void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&) |
120 | { | |
121 | #ifdef __WXMSW__ | |
122 | wxIcon icon(wxT("wxDEFAULT_FRAME")); | |
123 | ||
124 | if (!SetIcon(icon, wxT("wxTaskBarIcon Sample"))) | |
125 | wxMessageBox(wxT("Could not set new icon.")); | |
126 | #endif | |
127 | } | |
69ecd30f | 128 | |
bbf1f0e5 | 129 | // Overridables |
69ecd30f | 130 | void MyTaskBarIcon::OnMouseMove(wxEvent&) |
bbf1f0e5 KB |
131 | { |
132 | } | |
133 | ||
69ecd30f | 134 | void MyTaskBarIcon::OnLButtonDown(wxEvent&) |
bbf1f0e5 KB |
135 | { |
136 | } | |
137 | ||
69ecd30f | 138 | void MyTaskBarIcon::OnLButtonUp(wxEvent&) |
bbf1f0e5 KB |
139 | { |
140 | } | |
141 | ||
69ecd30f | 142 | void MyTaskBarIcon::OnRButtonDown(wxEvent&) |
bbf1f0e5 KB |
143 | { |
144 | } | |
145 | ||
69ecd30f | 146 | void MyTaskBarIcon::OnRButtonUp(wxEvent&) |
bbf1f0e5 | 147 | { |
69ecd30f RD |
148 | wxMenu menu; |
149 | ||
150 | menu.Append(PU_RESTORE, "&Restore TBTest"); | |
ab85e6cd JS |
151 | #ifdef __WXMSW__ |
152 | menu.Append(PU_NEW_ICON,"&Set New Icon"); | |
153 | #endif | |
69ecd30f RD |
154 | menu.Append(PU_EXIT, "E&xit"); |
155 | ||
156 | PopupMenu(&menu); | |
bbf1f0e5 KB |
157 | } |
158 | ||
69ecd30f | 159 | void MyTaskBarIcon::OnLButtonDClick(wxEvent&) |
bbf1f0e5 KB |
160 | { |
161 | dialog->Show(TRUE); | |
162 | } | |
163 | ||
69ecd30f | 164 | void MyTaskBarIcon::OnRButtonDClick(wxEvent&) |
bbf1f0e5 KB |
165 | { |
166 | } | |
167 | ||
168 | ||
69ecd30f RD |
169 | |
170 |