Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BatchTrayIcon.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
11 /*
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This software is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public
23  * License along with this software. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  */
27 
28 #include "BatchTrayIcon.h"
29 #include <wx/app.h>
30 #include <wx/menu.h>
31 #include "PTBatcherGUI.h"
32 
33 enum
34 {
35  ID_SHOWGUI=wxID_HIGHEST+101,
36  ID_START=wxID_HIGHEST+102,
37  ID_PAUSE=wxID_HIGHEST+103,
38  ID_STOP=wxID_HIGHEST+104,
39  ID_ADDPROJECT=wxID_HIGHEST+105,
40  ID_ADDPROJECTASSISTANT=wxID_HIGHEST+106,
41  ID_EXIT=wxID_HIGHEST+120
42 };
43 
44 BEGIN_EVENT_TABLE(BatchTaskBarIcon, wxTaskBarIcon)
45  EVT_TASKBAR_LEFT_DCLICK (BatchTaskBarIcon::OnLeftButtonDClick)
46  EVT_MENU(ID_SHOWGUI, BatchTaskBarIcon::OnShowGUI)
47  EVT_MENU(ID_START, BatchTaskBarIcon::OnStartBatch)
48  EVT_MENU(ID_PAUSE, BatchTaskBarIcon::OnPauseBatch)
49  EVT_MENU(ID_STOP, BatchTaskBarIcon::OnStopBatch)
50  EVT_MENU(ID_ADDPROJECT, BatchTaskBarIcon::OnAddProject)
51  EVT_MENU(ID_ADDPROJECTASSISTANT, BatchTaskBarIcon::OnAddProjectToAssistant)
52  EVT_MENU(ID_EXIT, BatchTaskBarIcon::OnExit)
54 
55 // Overridables
56 wxMenu* BatchTaskBarIcon::CreatePopupMenu()
57 {
58  wxMenu* menu = new wxMenu;
59  menu->Append(ID_SHOWGUI,_("&Show window"));
60  menu->AppendSeparator();
61  bool isRunning=wxGetApp().GetFrame()->IsRunning();
62  menu->Append(ID_START,_("Start batch"));
63  menu->Enable(ID_START,!isRunning);
64  if(wxGetApp().GetFrame()->IsPaused())
65  {
66  menu->Append(ID_PAUSE,_("Continue batch"));
67  }
68  else
69  {
70  menu->Append(ID_PAUSE,_("Pause batch"));
71  };
72  menu->Enable(ID_PAUSE,isRunning);
73  menu->Append(ID_STOP,_("Stop batch"));
74  menu->Enable(ID_STOP,isRunning);
75  menu->AppendSeparator();
76  menu->Append(ID_ADDPROJECT,_("Add project to stitching queue..."));
77  menu->Append(ID_ADDPROJECTASSISTANT,_("Add project to assistant queue..."));
78 #ifndef __WXMAC_OSX__
79  /*Mac has built-in quit menu*/
80  menu->AppendSeparator();
81  menu->Append(ID_EXIT, _("E&xit"));
82 #endif
83  return menu;
84 }
85 
86 void BatchTaskBarIcon::OnShowGUI(wxCommandEvent& e)
87 {
88  wxGetApp().GetFrame()->Show(true);
89  wxGetApp().GetFrame()->Iconize(false);
90  wxGetApp().GetFrame()->UpdateBatchVerboseStatus();
91 };
92 
93 void BatchTaskBarIcon::OnStartBatch(wxCommandEvent& e)
94 {
95  wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_start"));
96  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
97 };
98 
99 void BatchTaskBarIcon::OnPauseBatch(wxCommandEvent& e)
100 {
101  wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_pause"));
102  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
103 };
104 
105 void BatchTaskBarIcon::OnStopBatch(wxCommandEvent& e)
106 {
107  wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_cancel"));
108  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
109 };
110 
111 void BatchTaskBarIcon::OnAddProject(wxCommandEvent& e)
112 {
113  wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED ,XRCID("menu_add"));
114  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
115 };
116 
118 {
119  wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED ,XRCID("menu_add_assistant"));
120  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
121 };
122 
123 void BatchTaskBarIcon::OnExit(wxCommandEvent& e)
124 {
125  wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED ,XRCID("menu_exit"));
126  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
127 };
128 
129 void BatchTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent& e)
130 {
131  wxCommandEvent dummy;
132  OnShowGUI(dummy);
133 };
134 
135 #if defined __WXMSW__ && wxUSE_TASKBARICON_BALLOONS
136 // wxMSW, version 2.9 offers a native balloon for the traybar notification
137 // we need to implement a own version for the other systems
138 #else
139 enum
140 {
141  TIMER_BALLOON=wxID_HIGHEST+207,
142 };
143 //declaration of the balloon tool tip
144 BEGIN_EVENT_TABLE(TaskBarBalloon, wxFrame)
145  EVT_LEFT_DOWN(TaskBarBalloon::OnClick)
146  EVT_KEY_DOWN(TaskBarBalloon::OnKeyDown)
147  EVT_TIMER(TIMER_BALLOON,TaskBarBalloon::OnTimerTick)
149 
150 TaskBarBalloon::TaskBarBalloon(wxString sTitle, wxString sMessage)
151  : wxFrame(NULL,-1,wxT("no title"),wxDefaultPosition,wxDefaultSize,wxNO_BORDER | wxSTAY_ON_TOP | wxFRAME_SHAPED | wxFRAME_NO_TASKBAR)
152 {
153  SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
154  wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
155 
156  wxStaticText* title = new wxStaticText(this, -1, sTitle);
157  wxFont titleFont = GetFont();
158  titleFont.SetWeight(wxFONTWEIGHT_BOLD);
159  title->SetFont(titleFont);
160  title->SetBackgroundColour(GetBackgroundColour());
161  mainSizer->Add(title,0,wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
162  wxStaticText* text = new wxStaticText(this, -1, sMessage);
163  text->SetBackgroundColour(GetBackgroundColour());
164  mainSizer->Add(text,1,wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 5);
165  SetSizer(mainSizer);
166  mainSizer->SetSizeHints( this );
167 
168  m_timer = new wxTimer(this,TIMER_BALLOON);
169  // here, we try to align the frame to the right bottom corner
170  Center();
171  int iX = 0, iY = 0;
172  GetPosition( &iX, &iY );
173  iX = (iX * 2) - 2;
174  iY = (iY * 2) - 2;
175  Move( iX, iY );
176 }
177 
179 {
180  delete m_timer;
181 };
182 
184 void TaskBarBalloon::OnTimerTick(wxTimerEvent& e)
185 {
186  Destroy();
187 }
188 
189 void TaskBarBalloon::OnClick(wxMouseEvent& e)
190 {
191  Destroy();
192 };
193 
194 void TaskBarBalloon::OnKeyDown(wxKeyEvent& e)
195 {
196  Destroy();
197 };
198 
200 void TaskBarBalloon::showBalloon(unsigned int iTimeout)
201 {
202  Show(false);
203  Show(true);
204  m_timer->Start(iTimeout,wxTIMER_ONE_SHOT);
205 }
206 #endif
void OnLeftButtonDClick(wxTaskBarIconEvent &)
handler if double clicked on taskbar icon, opens window
void OnStopBatch(wxCommandEvent &e)
handler to stop batch
void OnKeyDown(wxKeyEvent &e)
key down event in the balloon
class to show a taskbar balloon
Definition: BatchTrayIcon.h:67
END_EVENT_TABLE()
void OnShowGUI(wxCommandEvent &e)
handler to open window
Batch processor for Hugin with GUI.
definition of tray/task bar icon for PTBatcherGUI
void OnPauseBatch(wxCommandEvent &e)
handler to pause batch
void OnStartBatch(wxCommandEvent &e)
handler to start batch
class for showing a taskbar/tray icon
Definition: BatchTrayIcon.h:33
virtual ~TaskBarBalloon()
void OnAddProject(wxCommandEvent &e)
handler to adding a project to stitching queue
void OnAddProjectToAssistant(wxCommandEvent &e)
handler to adding a project to assistant queue
void showBalloon(unsigned int iTimeout)
display the baloon and run the timer
void OnTimerTick(wxTimerEvent &e)
timer to close window
void OnExit(wxCommandEvent &e)
handler to exit PTBatcherGUI
wxTimer * m_timer
Definition: BatchTrayIcon.h:82
void OnClick(wxMouseEvent &e)
click on the balloon