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 BatchTaskBarIcon::BatchTaskBarIcon(wxTaskBarIconType iconType) : wxTaskBarIcon(iconType)
45 {
46  Bind(wxEVT_TASKBAR_LEFT_DCLICK, &BatchTaskBarIcon::OnLeftButtonDClick, this);
47  Bind(wxEVT_MENU, &BatchTaskBarIcon::OnShowGUI, this, ID_SHOWGUI);
48  Bind(wxEVT_MENU, &BatchTaskBarIcon::OnStartBatch, this, ID_START);
49  Bind(wxEVT_MENU, &BatchTaskBarIcon::OnPauseBatch, this, ID_PAUSE);
50  Bind(wxEVT_MENU, &BatchTaskBarIcon::OnStopBatch, this, ID_STOP);
51  Bind(wxEVT_MENU, &BatchTaskBarIcon::OnAddProject, this, ID_ADDPROJECT);
53  Bind(wxEVT_MENU, &BatchTaskBarIcon::OnExit, this, ID_EXIT);
54 }
55 
56 // Overridables
58 {
59  wxMenu* menu = new wxMenu;
60  menu->Append(ID_SHOWGUI,_("&Show window"));
61  menu->AppendSeparator();
62  bool isRunning=wxGetApp().GetFrame()->IsRunning();
63  menu->Append(ID_START,_("Start batch"));
64  menu->Enable(ID_START,!isRunning);
65  if(wxGetApp().GetFrame()->IsPaused())
66  {
67  menu->Append(ID_PAUSE,_("Continue batch"));
68  }
69  else
70  {
71  menu->Append(ID_PAUSE,_("Pause batch"));
72  };
73  menu->Enable(ID_PAUSE,isRunning);
74  menu->Append(ID_STOP,_("Stop batch"));
75  menu->Enable(ID_STOP,isRunning);
76  menu->AppendSeparator();
77  menu->Append(ID_ADDPROJECT,_("Add project to stitching queue..."));
78  menu->Append(ID_ADDPROJECTASSISTANT,_("Add project to assistant queue..."));
79 #ifndef __WXMAC_OSX__
80  /*Mac has built-in quit menu*/
81  menu->AppendSeparator();
82  menu->Append(ID_EXIT, _("E&xit"));
83 #endif
84  return menu;
85 }
86 
87 void BatchTaskBarIcon::OnShowGUI(wxCommandEvent& e)
88 {
89  wxGetApp().GetFrame()->Show(true);
90  wxGetApp().GetFrame()->Iconize(false);
91  wxGetApp().GetFrame()->UpdateBatchVerboseStatus();
92 };
93 
94 void BatchTaskBarIcon::OnStartBatch(wxCommandEvent& e)
95 {
96  wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_start"));
97  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
98 };
99 
100 void BatchTaskBarIcon::OnPauseBatch(wxCommandEvent& e)
101 {
102  wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_pause"));
103  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
104 };
105 
106 void BatchTaskBarIcon::OnStopBatch(wxCommandEvent& e)
107 {
108  wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_cancel"));
109  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
110 };
111 
112 void BatchTaskBarIcon::OnAddProject(wxCommandEvent& e)
113 {
114  wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED ,XRCID("menu_add"));
115  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
116 };
117 
119 {
120  wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED ,XRCID("menu_add_assistant"));
121  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
122 };
123 
124 void BatchTaskBarIcon::OnExit(wxCommandEvent& e)
125 {
126  wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED ,XRCID("menu_exit"));
127  wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
128 };
129 
130 void BatchTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent& e)
131 {
132  wxCommandEvent dummy;
133  OnShowGUI(dummy);
134 };
135 
136 #if defined __WXMSW__ && wxUSE_TASKBARICON_BALLOONS
137 // wxMSW, version 2.9 offers a native balloon for the traybar notification
138 // we need to implement a own version for the other systems
139 #else
140 enum
141 {
142  TIMER_BALLOON=wxID_HIGHEST+207,
143 };
144 //declaration of the balloon tool tip
145 
146 TaskBarBalloon::TaskBarBalloon(wxString sTitle, wxString sMessage)
147  : wxFrame(NULL,-1,wxT("no title"),wxDefaultPosition,wxDefaultSize,wxNO_BORDER | wxSTAY_ON_TOP | wxFRAME_SHAPED | wxFRAME_NO_TASKBAR)
148 {
149  SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
150  wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
151 
152  wxStaticText* title = new wxStaticText(this, -1, sTitle);
153  wxFont titleFont = GetFont();
154  titleFont.SetWeight(wxFONTWEIGHT_BOLD);
155  title->SetFont(titleFont);
156  title->SetBackgroundColour(GetBackgroundColour());
157  mainSizer->Add(title,0,wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
158  wxStaticText* text = new wxStaticText(this, -1, sMessage);
159  text->SetBackgroundColour(GetBackgroundColour());
160  mainSizer->Add(text,1,wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 5);
161  SetSizer(mainSizer);
162  mainSizer->SetSizeHints( this );
163 
164  m_timer = new wxTimer(this,TIMER_BALLOON);
165  // here, we try to align the frame to the right bottom corner
166  Center();
167  int iX = 0, iY = 0;
168  GetPosition( &iX, &iY );
169  iX = (iX * 2) - 2;
170  iY = (iY * 2) - 2;
171  Move( iX, iY );
172  Bind(wxEVT_LEFT_DOWN, &TaskBarBalloon::OnClick, this);
173  Bind(wxEVT_KEY_DOWN, &TaskBarBalloon::OnKeyDown, this);
174  Bind(wxEVT_TIMER, &TaskBarBalloon::OnTimerTick, this);
175 }
176 
178 {
179  delete m_timer;
180 };
181 
183 void TaskBarBalloon::OnTimerTick(wxTimerEvent& e)
184 {
185  Destroy();
186 }
187 
188 void TaskBarBalloon::OnClick(wxMouseEvent& e)
189 {
190  Destroy();
191 };
192 
193 void TaskBarBalloon::OnKeyDown(wxKeyEvent& e)
194 {
195  Destroy();
196 };
197 
199 void TaskBarBalloon::showBalloon(unsigned int iTimeout)
200 {
201  Show(false);
202  Show(true);
203  m_timer->Start(iTimeout,wxTIMER_ONE_SHOT);
204 }
205 #endif
void OnLeftButtonDClick(wxTaskBarIconEvent &)
handler if double clicked on taskbar icon, opens window
void OnStopBatch(wxCommandEvent &e)
handler to stop batch
TaskBarBalloon(wxString sTitle, wxString sMessage)
void OnKeyDown(wxKeyEvent &e)
key down event in the balloon
BatchTaskBarIcon(wxTaskBarIconType iconType=wxTBI_DEFAULT_TYPE)
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
virtual wxMenu * CreatePopupMenu()
creates the popup menu
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