]>
git.saurik.com Git - wxWidgets.git/blob - samples/taskbar/tbtest.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTaskBarIcon demo
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
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"
30 #include "wx/taskbar.h"
34 MyDialog
*dialog
= NULL
;
38 bool MyApp::OnInit(void)
40 // Create the main frame window
41 dialog
= new MyDialog(NULL
, wxID_ANY
, wxT("wxTaskBarIcon Test Dialog"), wxDefaultPosition
, wxSize(365, 290));
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
)
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
)
67 #if defined(__WXCOCOA__)
72 void MyDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
77 void MyDialog::OnExit(wxCommandEvent
& WXUNUSED(event
))
82 void MyDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
87 void MyDialog::Init(void)
89 (void)new wxStaticText(this, wxID_ANY
, _T("Press 'Hide me' to hide me, Exit to quit."),
92 (void)new wxStaticText(this, wxID_ANY
, _T("Double-click on the taskbar icon to show me again."),
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();
99 m_taskBarIcon
= new MyTaskBarIcon();
100 #if defined(__WXCOCOA__)
101 m_dockIcon
= new MyTaskBarIcon(wxTaskBarIcon::DOCK
);
103 if (!m_taskBarIcon
->SetIcon(wxICON(sample
), wxT("wxTaskBarIcon Sample")))
104 wxMessageBox(wxT("Could not set icon."));
116 BEGIN_EVENT_TABLE(MyTaskBarIcon
, wxTaskBarIcon
)
117 EVT_MENU(PU_RESTORE
, MyTaskBarIcon::OnMenuRestore
)
118 EVT_MENU(PU_EXIT
, MyTaskBarIcon::OnMenuExit
)
119 EVT_MENU(PU_NEW_ICON
,MyTaskBarIcon::OnMenuSetNewIcon
)
120 EVT_MENU(PU_CHECKMARK
,MyTaskBarIcon::OnMenuCheckmark
)
121 EVT_UPDATE_UI(PU_CHECKMARK
,MyTaskBarIcon::OnMenuUICheckmark
)
122 EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon::OnLeftButtonDClick
)
125 void MyTaskBarIcon::OnMenuRestore(wxCommandEvent
& )
130 void MyTaskBarIcon::OnMenuExit(wxCommandEvent
& )
135 static bool check
= true;
137 void MyTaskBarIcon::OnMenuCheckmark(wxCommandEvent
& )
141 void MyTaskBarIcon::OnMenuUICheckmark(wxUpdateUIEvent
&event
)
143 event
.Check( check
);
146 void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent
&)
148 wxIcon
icon(smile_xpm
);
150 if (!SetIcon(icon
, wxT("wxTaskBarIcon Sample - a different icon")))
151 wxMessageBox(wxT("Could not set new icon."));
155 wxMenu
*MyTaskBarIcon::CreatePopupMenu()
157 wxMenu
*menu
= new wxMenu
;
159 menu
->Append(PU_RESTORE
, _T("&Restore TBTest"));
160 menu
->Append(PU_NEW_ICON
,_T("&Set New Icon"));
161 menu
->Append(PU_CHECKMARK
, _T("Checkmark"),wxT( "" ), wxITEM_CHECK
);
162 menu
->Append(PU_EXIT
, _T("E&xit"));
167 void MyTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent
&)