]>
Commit | Line | Data |
---|---|---|
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 | // 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 | #include "tbtest.h" | |
32 | ||
33 | // Declare two frames | |
34 | MyDialog *dialog = NULL; | |
35 | ||
36 | IMPLEMENT_APP(MyApp) | |
37 | ||
38 | bool MyApp::OnInit(void) | |
39 | { | |
40 | // Create the main frame window | |
41 | dialog = new MyDialog(NULL, wxID_ANY, wxT("wxTaskBarIcon Test Dialog"), wxDefaultPosition, wxSize(365, 290)); | |
42 | ||
43 | dialog->Show(true); | |
44 | ||
45 | return true; | |
46 | } | |
47 | ||
48 | ||
49 | BEGIN_EVENT_TABLE(MyDialog, wxDialog) | |
50 | EVT_BUTTON(wxID_OK, MyDialog::OnOK) | |
51 | EVT_BUTTON(wxID_EXIT, MyDialog::OnExit) | |
52 | EVT_CLOSE(MyDialog::OnCloseWindow) | |
53 | END_EVENT_TABLE() | |
54 | ||
55 | ||
56 | ||
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 | ||
64 | MyDialog::~MyDialog() | |
65 | { | |
66 | delete m_taskBarIcon; | |
67 | #if defined(__WXCOCOA__) | |
68 | delete m_dockIcon; | |
69 | #endif | |
70 | } | |
71 | ||
72 | void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event)) | |
73 | { | |
74 | Show(false); | |
75 | } | |
76 | ||
77 | void MyDialog::OnExit(wxCommandEvent& WXUNUSED(event)) | |
78 | { | |
79 | Close(true); | |
80 | } | |
81 | ||
82 | void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) | |
83 | { | |
84 | Destroy(); | |
85 | } | |
86 | ||
87 | void MyDialog::Init(void) | |
88 | { | |
89 | (void)new wxStaticText(this, wxID_ANY, _T("Press 'Hide me' to hide me, Exit to quit."), | |
90 | wxPoint(10, 20)); | |
91 | ||
92 | (void)new wxStaticText(this, wxID_ANY, _T("Double-click on the taskbar icon to show me again."), | |
93 | wxPoint(10, 40)); | |
94 | ||
95 | (void)new wxButton(this, wxID_EXIT, _T("Exit"), wxPoint(185, 230), wxSize(80, 25)); | |
96 | (new wxButton(this, wxID_OK, _T("Hide me"), wxPoint(100, 230), wxSize(80, 25)))->SetDefault(); | |
97 | Centre(wxBOTH); | |
98 | ||
99 | m_taskBarIcon = new MyTaskBarIcon(); | |
100 | #if defined(__WXCOCOA__) | |
101 | m_dockIcon = new MyTaskBarIcon(wxTaskBarIcon::DOCK); | |
102 | #endif | |
103 | if (!m_taskBarIcon->SetIcon(wxICON(sample), wxT("wxTaskBarIcon Sample"))) | |
104 | wxMessageBox(wxT("Could not set icon.")); | |
105 | } | |
106 | ||
107 | ||
108 | enum { | |
109 | PU_RESTORE = 10001, | |
110 | PU_NEW_ICON, | |
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) | |
118 | EVT_MENU(PU_NEW_ICON,MyTaskBarIcon::OnMenuSetNewIcon) | |
119 | EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon::OnLeftButtonDClick) | |
120 | END_EVENT_TABLE() | |
121 | ||
122 | void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& ) | |
123 | { | |
124 | dialog->Show(true); | |
125 | } | |
126 | ||
127 | void MyTaskBarIcon::OnMenuExit(wxCommandEvent& ) | |
128 | { | |
129 | dialog->Close(true); | |
130 | } | |
131 | ||
132 | void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&) | |
133 | { | |
134 | wxIcon icon(smile_xpm); | |
135 | ||
136 | if (!SetIcon(icon, wxT("wxTaskBarIcon Sample - a different icon"))) | |
137 | wxMessageBox(wxT("Could not set new icon.")); | |
138 | } | |
139 | ||
140 | // Overridables | |
141 | wxMenu *MyTaskBarIcon::CreatePopupMenu() | |
142 | { | |
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")); | |
148 | ||
149 | return menu; | |
150 | } | |
151 | ||
152 | void MyTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent&) | |
153 | { | |
154 | dialog->Show(true); | |
155 | } |