]>
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__) | |
25 | #include "mondrian.xpm" | |
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 | { | |
4bc64712 | 38 | if (!m_taskBarIcon.SetIcon(wxICON(mondrian), wxT("wxTaskBarIcon Sample"))) |
ab85e6cd | 39 | wxMessageBox(wxT("Could not set icon.")); |
bbf1f0e5 KB |
40 | |
41 | // Create the main frame window | |
ab85e6cd | 42 | dialog = new MyDialog(NULL, -1, wxT("wxTaskBarIcon Test Dialog"), wxPoint(-1, -1), wxSize(365, 290), wxDIALOG_MODELESS|wxDEFAULT_DIALOG_STYLE); |
bbf1f0e5 KB |
43 | |
44 | dialog->Show(TRUE); | |
45 | ||
46 | return TRUE; | |
47 | } | |
48 | ||
69ecd30f | 49 | |
bbf1f0e5 KB |
50 | BEGIN_EVENT_TABLE(MyDialog, wxDialog) |
51 | EVT_BUTTON(wxID_OK, MyDialog::OnOK) | |
52 | EVT_BUTTON(wxID_EXIT, MyDialog::OnExit) | |
d66d9d5b | 53 | EVT_CLOSE(MyDialog::OnCloseWindow) |
bbf1f0e5 KB |
54 | END_EVENT_TABLE() |
55 | ||
69ecd30f RD |
56 | |
57 | ||
bbf1f0e5 KB |
58 | MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title, |
59 | const wxPoint& pos, const wxSize& size, const long windowStyle): | |
60 | wxDialog(parent, id, title, pos, size, windowStyle) | |
61 | { | |
62 | Init(); | |
63 | } | |
64 | ||
65 | void MyDialog::OnOK(wxCommandEvent& event) | |
66 | { | |
67 | Show(FALSE); | |
68 | } | |
69 | ||
70 | void MyDialog::OnExit(wxCommandEvent& event) | |
71 | { | |
72 | Close(TRUE); | |
73 | } | |
74 | ||
75 | void MyDialog::OnCloseWindow(wxCloseEvent& event) | |
76 | { | |
77 | Destroy(); | |
78 | } | |
79 | ||
80 | void MyDialog::Init(void) | |
81 | { | |
ab1ca7b3 | 82 | (void)new wxStaticText(this, -1, _T("Press OK to hide me, Exit to quit."), |
e0221ef7 | 83 | wxPoint(10, 20)); |
bbf1f0e5 | 84 | |
ab1ca7b3 | 85 | (void)new wxStaticText(this, -1, _T("Double-click on the taskbar icon to show me again."), |
e0221ef7 | 86 | wxPoint(10, 40)); |
69ecd30f | 87 | |
ab1ca7b3 MB |
88 | (void)new wxButton(this, wxID_EXIT, _T("Exit"), wxPoint(185, 230), wxSize(80, 25)); |
89 | (new wxButton(this, wxID_OK, _T("OK"), wxPoint(100, 230), wxSize(80, 25)))->SetDefault(); | |
e0221ef7 | 90 | Centre(wxBOTH); |
bbf1f0e5 KB |
91 | } |
92 | ||
69ecd30f RD |
93 | |
94 | enum { | |
95 | PU_RESTORE = 10001, | |
ab85e6cd | 96 | PU_NEW_ICON, |
69ecd30f RD |
97 | PU_EXIT, |
98 | }; | |
99 | ||
100 | ||
101 | BEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon) | |
102 | EVT_MENU(PU_RESTORE, MyTaskBarIcon::OnMenuRestore) | |
103 | EVT_MENU(PU_EXIT, MyTaskBarIcon::OnMenuExit) | |
ab85e6cd | 104 | EVT_MENU(PU_NEW_ICON,MyTaskBarIcon::OnMenuSetNewIcon) |
4bc64712 VS |
105 | EVT_TASKBAR_RIGHT_UP (MyTaskBarIcon::OnRButtonUp) |
106 | EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon::OnLButtonDClick) | |
69ecd30f RD |
107 | END_EVENT_TABLE() |
108 | ||
a42b93aa | 109 | void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& ) |
69ecd30f RD |
110 | { |
111 | dialog->Show(TRUE); | |
112 | } | |
113 | ||
a42b93aa | 114 | void MyTaskBarIcon::OnMenuExit(wxCommandEvent& ) |
69ecd30f RD |
115 | { |
116 | dialog->Close(TRUE); | |
f6bcfd97 BP |
117 | |
118 | // Nudge wxWindows into destroying the dialog, since | |
119 | // with a hidden window no messages will get sent to put | |
120 | // it into idle processing. | |
121 | wxGetApp().ProcessIdle(); | |
69ecd30f RD |
122 | } |
123 | ||
ab85e6cd JS |
124 | void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&) |
125 | { | |
126 | #ifdef __WXMSW__ | |
127 | wxIcon icon(wxT("wxDEFAULT_FRAME")); | |
128 | ||
129 | if (!SetIcon(icon, wxT("wxTaskBarIcon Sample"))) | |
130 | wxMessageBox(wxT("Could not set new icon.")); | |
131 | #endif | |
132 | } | |
69ecd30f | 133 | |
bbf1f0e5 | 134 | // Overridables |
69ecd30f | 135 | void MyTaskBarIcon::OnRButtonUp(wxEvent&) |
bbf1f0e5 | 136 | { |
69ecd30f RD |
137 | wxMenu menu; |
138 | ||
ab1ca7b3 | 139 | menu.Append(PU_RESTORE, _T("&Restore TBTest")); |
ab85e6cd | 140 | #ifdef __WXMSW__ |
ab1ca7b3 | 141 | menu.Append(PU_NEW_ICON,_T("&Set New Icon")); |
ab85e6cd | 142 | #endif |
ab1ca7b3 | 143 | menu.Append(PU_EXIT, _T("E&xit")); |
69ecd30f RD |
144 | |
145 | PopupMenu(&menu); | |
bbf1f0e5 KB |
146 | } |
147 | ||
69ecd30f | 148 | void MyTaskBarIcon::OnLButtonDClick(wxEvent&) |
bbf1f0e5 KB |
149 | { |
150 | dialog->Show(TRUE); | |
151 | } | |
152 | ||
bbf1f0e5 | 153 | |
69ecd30f RD |
154 | |
155 |