]>
Commit | Line | Data |
---|---|---|
bbf1f0e5 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbtest.cpp | |
3 | // Purpose: wxTaskBarIcon demo | |
4 | // Author: Julian Smart | |
329fa151 | 5 | // Modified by: |
bbf1f0e5 KB |
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 | ||
0dc6da2d VS |
28 | #include "smile.xpm" |
29 | ||
e015d1f7 | 30 | #include "wx/taskbar.h" |
bbf1f0e5 KB |
31 | #include "tbtest.h" |
32 | ||
329fa151 | 33 | // Declare two frames |
bbf1f0e5 KB |
34 | MyDialog *dialog = NULL; |
35 | ||
36 | IMPLEMENT_APP(MyApp) | |
37 | ||
38 | bool MyApp::OnInit(void) | |
39 | { | |
bbf1f0e5 | 40 | // Create the main frame window |
2a21ac15 | 41 | dialog = new MyDialog(NULL, wxID_ANY, wxT("wxTaskBarIcon Test Dialog"), wxDefaultPosition, wxSize(365, 290)); |
bbf1f0e5 | 42 | |
27301f26 | 43 | dialog->Show(true); |
bbf1f0e5 | 44 | |
27301f26 | 45 | return true; |
bbf1f0e5 KB |
46 | } |
47 | ||
69ecd30f | 48 | |
bbf1f0e5 KB |
49 | BEGIN_EVENT_TABLE(MyDialog, wxDialog) |
50 | EVT_BUTTON(wxID_OK, MyDialog::OnOK) | |
51 | EVT_BUTTON(wxID_EXIT, MyDialog::OnExit) | |
d66d9d5b | 52 | EVT_CLOSE(MyDialog::OnCloseWindow) |
bbf1f0e5 KB |
53 | END_EVENT_TABLE() |
54 | ||
69ecd30f RD |
55 | |
56 | ||
bbf1f0e5 KB |
57 | MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title, |
58 | const wxPoint& pos, const wxSize& size, const long windowStyle): | |
59 | wxDialog(parent, id, title, pos, size, windowStyle) | |
60 | { | |
61 | Init(); | |
62 | } | |
63 | ||
1e6d9c20 VS |
64 | MyDialog::~MyDialog() |
65 | { | |
66 | delete m_taskBarIcon; | |
a5593369 DE |
67 | #if defined(__WXCOCOA__) |
68 | delete m_dockIcon; | |
69 | #endif | |
1e6d9c20 VS |
70 | } |
71 | ||
256b8649 | 72 | void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event)) |
bbf1f0e5 | 73 | { |
27301f26 | 74 | Show(false); |
bbf1f0e5 KB |
75 | } |
76 | ||
256b8649 | 77 | void MyDialog::OnExit(wxCommandEvent& WXUNUSED(event)) |
bbf1f0e5 | 78 | { |
27301f26 | 79 | Close(true); |
bbf1f0e5 KB |
80 | } |
81 | ||
256b8649 | 82 | void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
bbf1f0e5 KB |
83 | { |
84 | Destroy(); | |
85 | } | |
86 | ||
87 | void MyDialog::Init(void) | |
88 | { | |
0063a4dc | 89 | (void)new wxStaticText(this, wxID_ANY, _T("Press 'Hide me' to hide me, Exit to quit."), |
e0221ef7 | 90 | wxPoint(10, 20)); |
bbf1f0e5 | 91 | |
27301f26 | 92 | (void)new wxStaticText(this, wxID_ANY, _T("Double-click on the taskbar icon to show me again."), |
e0221ef7 | 93 | wxPoint(10, 40)); |
69ecd30f | 94 | |
ab1ca7b3 | 95 | (void)new wxButton(this, wxID_EXIT, _T("Exit"), wxPoint(185, 230), wxSize(80, 25)); |
0063a4dc | 96 | (new wxButton(this, wxID_OK, _T("Hide me"), wxPoint(100, 230), wxSize(80, 25)))->SetDefault(); |
e0221ef7 | 97 | Centre(wxBOTH); |
1e6d9c20 | 98 | |
329fa151 | 99 | m_taskBarIcon = new MyTaskBarIcon(); |
a5593369 DE |
100 | #if defined(__WXCOCOA__) |
101 | m_dockIcon = new MyTaskBarIcon(wxTaskBarIcon::DOCK); | |
102 | #endif | |
329fa151 | 103 | if (!m_taskBarIcon->SetIcon(wxICON(sample), wxT("wxTaskBarIcon Sample"))) |
1e6d9c20 | 104 | wxMessageBox(wxT("Could not set icon.")); |
bbf1f0e5 KB |
105 | } |
106 | ||
69ecd30f RD |
107 | |
108 | enum { | |
109 | PU_RESTORE = 10001, | |
ab85e6cd | 110 | PU_NEW_ICON, |
69ecd30f RD |
111 | PU_EXIT, |
112 | }; | |
113 | ||
114 | ||
115 | BEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon) | |
116 | EVT_MENU(PU_RESTORE, MyTaskBarIcon::OnMenuRestore) | |
117 | EVT_MENU(PU_EXIT, MyTaskBarIcon::OnMenuExit) | |
ab85e6cd | 118 | EVT_MENU(PU_NEW_ICON,MyTaskBarIcon::OnMenuSetNewIcon) |
329fa151 | 119 | EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon::OnLeftButtonDClick) |
69ecd30f RD |
120 | END_EVENT_TABLE() |
121 | ||
a42b93aa | 122 | void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& ) |
69ecd30f | 123 | { |
27301f26 | 124 | dialog->Show(true); |
69ecd30f RD |
125 | } |
126 | ||
a42b93aa | 127 | void MyTaskBarIcon::OnMenuExit(wxCommandEvent& ) |
69ecd30f | 128 | { |
27301f26 | 129 | dialog->Close(true); |
69ecd30f RD |
130 | } |
131 | ||
ab85e6cd JS |
132 | void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&) |
133 | { | |
0dc6da2d | 134 | wxIcon icon(smile_xpm); |
ab85e6cd | 135 | |
0dc6da2d | 136 | if (!SetIcon(icon, wxT("wxTaskBarIcon Sample - a different icon"))) |
ab85e6cd | 137 | wxMessageBox(wxT("Could not set new icon.")); |
ab85e6cd | 138 | } |
69ecd30f | 139 | |
bbf1f0e5 | 140 | // Overridables |
dae73d74 | 141 | wxMenu *MyTaskBarIcon::CreatePopupMenu() |
bbf1f0e5 | 142 | { |
dae73d74 VS |
143 | wxMenu *menu = new wxMenu; |
144 | ||
145 | menu->Append(PU_RESTORE, _T("&Restore TBTest")); | |
146 | menu->Append(PU_NEW_ICON,_T("&Set New Icon")); | |
147 | menu->Append(PU_EXIT, _T("E&xit")); | |
329fa151 | 148 | |
dae73d74 | 149 | return menu; |
bbf1f0e5 KB |
150 | } |
151 | ||
329fa151 | 152 | void MyTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent&) |
bbf1f0e5 | 153 | { |
27301f26 | 154 | dialog->Show(true); |
bbf1f0e5 | 155 | } |