]>
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 | ||
4bc64712 VS |
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__) | |
1e6d9c20 | 25 | #include "../sample.xpm" |
4bc64712 VS |
26 | #endif |
27 | ||
e015d1f7 | 28 | #include "wx/taskbar.h" |
bbf1f0e5 KB |
29 | #include "tbtest.h" |
30 | ||
31 | // Declare two frames | |
32 | MyDialog *dialog = NULL; | |
33 | ||
34 | IMPLEMENT_APP(MyApp) | |
35 | ||
36 | bool MyApp::OnInit(void) | |
37 | { | |
bbf1f0e5 | 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 | ||
1e6d9c20 VS |
62 | MyDialog::~MyDialog() |
63 | { | |
64 | delete m_taskBarIcon; | |
65 | } | |
66 | ||
256b8649 | 67 | void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event)) |
bbf1f0e5 KB |
68 | { |
69 | Show(FALSE); | |
70 | } | |
71 | ||
256b8649 | 72 | void MyDialog::OnExit(wxCommandEvent& WXUNUSED(event)) |
bbf1f0e5 KB |
73 | { |
74 | Close(TRUE); | |
75 | } | |
76 | ||
256b8649 | 77 | void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
bbf1f0e5 KB |
78 | { |
79 | Destroy(); | |
80 | } | |
81 | ||
82 | void MyDialog::Init(void) | |
83 | { | |
ab1ca7b3 | 84 | (void)new wxStaticText(this, -1, _T("Press OK to hide me, Exit to quit."), |
e0221ef7 | 85 | wxPoint(10, 20)); |
bbf1f0e5 | 86 | |
ab1ca7b3 | 87 | (void)new wxStaticText(this, -1, _T("Double-click on the taskbar icon to show me again."), |
e0221ef7 | 88 | wxPoint(10, 40)); |
69ecd30f | 89 | |
ab1ca7b3 MB |
90 | (void)new wxButton(this, wxID_EXIT, _T("Exit"), wxPoint(185, 230), wxSize(80, 25)); |
91 | (new wxButton(this, wxID_OK, _T("OK"), wxPoint(100, 230), wxSize(80, 25)))->SetDefault(); | |
e0221ef7 | 92 | Centre(wxBOTH); |
1e6d9c20 VS |
93 | |
94 | ||
95 | m_taskBarIcon = new MyTaskBarIcon(); | |
96 | if (!m_taskBarIcon->SetIcon(wxICON(sample), wxT("wxTaskBarIcon Sample"))) | |
97 | wxMessageBox(wxT("Could not set icon.")); | |
bbf1f0e5 KB |
98 | } |
99 | ||
69ecd30f RD |
100 | |
101 | enum { | |
102 | PU_RESTORE = 10001, | |
ab85e6cd | 103 | PU_NEW_ICON, |
69ecd30f RD |
104 | PU_EXIT, |
105 | }; | |
106 | ||
107 | ||
108 | BEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon) | |
109 | EVT_MENU(PU_RESTORE, MyTaskBarIcon::OnMenuRestore) | |
110 | EVT_MENU(PU_EXIT, MyTaskBarIcon::OnMenuExit) | |
ab85e6cd | 111 | EVT_MENU(PU_NEW_ICON,MyTaskBarIcon::OnMenuSetNewIcon) |
4bc64712 VS |
112 | EVT_TASKBAR_RIGHT_UP (MyTaskBarIcon::OnRButtonUp) |
113 | EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon::OnLButtonDClick) | |
69ecd30f RD |
114 | END_EVENT_TABLE() |
115 | ||
a42b93aa | 116 | void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& ) |
69ecd30f RD |
117 | { |
118 | dialog->Show(TRUE); | |
119 | } | |
120 | ||
a42b93aa | 121 | void MyTaskBarIcon::OnMenuExit(wxCommandEvent& ) |
69ecd30f RD |
122 | { |
123 | dialog->Close(TRUE); | |
f6bcfd97 BP |
124 | |
125 | // Nudge wxWindows into destroying the dialog, since | |
126 | // with a hidden window no messages will get sent to put | |
127 | // it into idle processing. | |
128 | wxGetApp().ProcessIdle(); | |
69ecd30f RD |
129 | } |
130 | ||
ab85e6cd JS |
131 | void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&) |
132 | { | |
133 | #ifdef __WXMSW__ | |
134 | wxIcon icon(wxT("wxDEFAULT_FRAME")); | |
135 | ||
136 | if (!SetIcon(icon, wxT("wxTaskBarIcon Sample"))) | |
137 | wxMessageBox(wxT("Could not set new icon.")); | |
138 | #endif | |
139 | } | |
69ecd30f | 140 | |
bbf1f0e5 | 141 | // Overridables |
69ecd30f | 142 | void MyTaskBarIcon::OnRButtonUp(wxEvent&) |
bbf1f0e5 | 143 | { |
69ecd30f RD |
144 | wxMenu menu; |
145 | ||
ab1ca7b3 | 146 | menu.Append(PU_RESTORE, _T("&Restore TBTest")); |
ab85e6cd | 147 | #ifdef __WXMSW__ |
ab1ca7b3 | 148 | menu.Append(PU_NEW_ICON,_T("&Set New Icon")); |
ab85e6cd | 149 | #endif |
ab1ca7b3 | 150 | menu.Append(PU_EXIT, _T("E&xit")); |
69ecd30f RD |
151 | |
152 | PopupMenu(&menu); | |
bbf1f0e5 KB |
153 | } |
154 | ||
69ecd30f | 155 | void MyTaskBarIcon::OnLButtonDClick(wxEvent&) |
bbf1f0e5 KB |
156 | { |
157 | dialog->Show(TRUE); | |
158 | } | |
159 | ||
bbf1f0e5 | 160 | |
69ecd30f RD |
161 | |
162 |