BatchTrayIcon.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00011 /*
00012  *  This program is free software; you can redistribute it and/or
00013  *  modify it under the terms of the GNU General Public
00014  *  License as published by the Free Software Foundation; either
00015  *  version 2 of the License, or (at your option) any later version.
00016  *
00017  *  This software is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  *  General Public License for more details.
00021  *
00022  *  You should have received a copy of the GNU General Public
00023  *  License along with this software; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 #include "BatchTrayIcon.h"
00029 #include <wx/app.h>
00030 #include <wx/menu.h>
00031 #include "PTBatcherGUI.h"
00032 
00033 enum
00034 {
00035     ID_SHOWGUI=wxID_HIGHEST+101,
00036     ID_START=wxID_HIGHEST+102,
00037     ID_PAUSE=wxID_HIGHEST+103,
00038     ID_STOP=wxID_HIGHEST+104,
00039     ID_ADDPROJECT=wxID_HIGHEST+105,
00040     ID_ADDPROJECTASSISTANT=wxID_HIGHEST+106,
00041     ID_EXIT=wxID_HIGHEST+120
00042 };
00043 
00044 BEGIN_EVENT_TABLE(BatchTaskBarIcon, wxTaskBarIcon)
00045     EVT_TASKBAR_LEFT_DCLICK  (BatchTaskBarIcon::OnLeftButtonDClick)
00046     EVT_MENU(ID_SHOWGUI, BatchTaskBarIcon::OnShowGUI)
00047     EVT_MENU(ID_START, BatchTaskBarIcon::OnStartBatch)
00048     EVT_MENU(ID_PAUSE, BatchTaskBarIcon::OnPauseBatch)
00049     EVT_MENU(ID_STOP, BatchTaskBarIcon::OnStopBatch)
00050     EVT_MENU(ID_ADDPROJECT, BatchTaskBarIcon::OnAddProject)
00051     EVT_MENU(ID_ADDPROJECTASSISTANT, BatchTaskBarIcon::OnAddProjectToAssistant)
00052     EVT_MENU(ID_EXIT, BatchTaskBarIcon::OnExit)
00053 END_EVENT_TABLE()
00054 
00055 // Overridables
00056 wxMenu* BatchTaskBarIcon::CreatePopupMenu()
00057 {
00058     wxMenu* menu = new wxMenu;
00059     menu->Append(ID_SHOWGUI,_("&Show window"));
00060     menu->AppendSeparator();
00061     bool isRunning=wxGetApp().GetFrame()->IsRunning();
00062     menu->Append(ID_START,_("Start batch"));
00063     menu->Enable(ID_START,!isRunning);
00064     if(wxGetApp().GetFrame()->IsPaused())
00065     {
00066         menu->Append(ID_PAUSE,_("Continue batch"));
00067     }
00068     else
00069     {
00070         menu->Append(ID_PAUSE,_("Pause batch"));
00071     };
00072     menu->Enable(ID_PAUSE,isRunning);
00073     menu->Append(ID_STOP,_("Stop batch"));
00074     menu->Enable(ID_STOP,isRunning);
00075     menu->AppendSeparator();
00076     menu->Append(ID_ADDPROJECT,_("Add project to stitching queue..."));
00077     menu->Append(ID_ADDPROJECTASSISTANT,_("Add project to assistant queue..."));
00078 #ifndef __WXMAC_OSX__
00079     /*Mac has built-in quit menu*/
00080     menu->AppendSeparator();
00081     menu->Append(ID_EXIT, _("E&xit"));
00082 #endif
00083     return menu;
00084 }
00085 
00086 void BatchTaskBarIcon::OnShowGUI(wxCommandEvent& e)
00087 {
00088     wxGetApp().GetFrame()->Show(true);
00089     wxGetApp().GetFrame()->Iconize(false);
00090     wxGetApp().GetFrame()->UpdateBatchVerboseStatus();
00091 };
00092 
00093 void BatchTaskBarIcon::OnStartBatch(wxCommandEvent& e)
00094 {
00095     wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_start"));
00096     wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
00097 };
00098 
00099 void BatchTaskBarIcon::OnPauseBatch(wxCommandEvent& e)
00100 {
00101     wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_pause"));
00102     wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
00103 };
00104 
00105 void BatchTaskBarIcon::OnStopBatch(wxCommandEvent& e)
00106 {
00107     wxCommandEvent ev(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_cancel"));
00108     wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
00109 };
00110 
00111 void BatchTaskBarIcon::OnAddProject(wxCommandEvent& e)
00112 {
00113     wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED ,XRCID("menu_add"));
00114     wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
00115 };
00116 
00117 void BatchTaskBarIcon::OnAddProjectToAssistant(wxCommandEvent& e)
00118 {
00119     wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED ,XRCID("menu_add_assistant"));
00120     wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
00121 };
00122 
00123 void BatchTaskBarIcon::OnExit(wxCommandEvent& e)
00124 {
00125     wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED  ,XRCID("menu_exit"));
00126     wxGetApp().GetFrame()->GetEventHandler()->AddPendingEvent(ev);
00127 };
00128 
00129 void BatchTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent& e)
00130 {
00131     wxCommandEvent dummy;
00132     OnShowGUI(dummy);
00133 };
00134 
00135 #if defined __WXMSW__ && wxUSE_TASKBARICON_BALLOONS && wxCHECK_VERSION(2,9,0)
00136 // wxMSW, version 2.9 offers a native balloon for the traybar notification
00137 // we need to implement a own version for the other systems
00138 #else
00139 enum
00140 {
00141     TIMER_BALLOON=wxID_HIGHEST+207,
00142 };
00143 //declaration of the balloon tool tip
00144 BEGIN_EVENT_TABLE(TaskBarBalloon, wxFrame)
00145     EVT_LEFT_DOWN(TaskBarBalloon::OnClick)
00146     EVT_KEY_DOWN(TaskBarBalloon::OnKeyDown)
00147     EVT_TIMER(TIMER_BALLOON,TaskBarBalloon::OnTimerTick)
00148 END_EVENT_TABLE()
00149 
00150 TaskBarBalloon::TaskBarBalloon(wxString sTitle, wxString sMessage)
00151     : wxFrame(NULL,-1,wxT("no title"),wxDefaultPosition,wxDefaultSize,wxNO_BORDER | wxSTAY_ON_TOP | wxFRAME_SHAPED | wxFRAME_NO_TASKBAR)
00152 {
00153     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
00154     wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
00155 
00156     wxStaticText* title = new wxStaticText(this, -1, sTitle);
00157     wxFont titleFont = GetFont();
00158     titleFont.SetWeight(wxFONTWEIGHT_BOLD);
00159     title->SetFont(titleFont);
00160     title->SetBackgroundColour(GetBackgroundColour());
00161     mainSizer->Add(title,0,wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
00162     wxStaticText* text = new wxStaticText(this, -1, sMessage);
00163     text->SetBackgroundColour(GetBackgroundColour());
00164     mainSizer->Add(text,1,wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 5);
00165     SetSizer(mainSizer);
00166     mainSizer->SetSizeHints( this );
00167 
00168     m_timer = new wxTimer(this,TIMER_BALLOON);
00169     // here, we try to align the frame to the right bottom corner
00170     Center();
00171     int iX = 0, iY = 0;
00172     GetPosition( &iX, &iY );
00173     iX = (iX * 2) - 2;
00174     iY = (iY * 2) - 2;
00175     Move( iX, iY );
00176 }
00177 
00178 TaskBarBalloon::~TaskBarBalloon()
00179 {
00180     delete m_timer;
00181 };
00182 
00184 void TaskBarBalloon::OnTimerTick(wxTimerEvent& e)
00185 {
00186     Destroy();
00187 }
00188 
00189 void TaskBarBalloon::OnClick(wxMouseEvent& e)
00190 {
00191     Destroy();
00192 };
00193 
00194 void TaskBarBalloon::OnKeyDown(wxKeyEvent& e)
00195 {
00196     Destroy();
00197 };
00198 
00200 void TaskBarBalloon::showBalloon(unsigned int iTimeout)
00201 {
00202     Show(false);
00203     Show(true);
00204     m_timer->Start(iTimeout,wxTIMER_ONE_SHOT);
00205 }
00206 #endif

Generated on Sun Apr 20 01:25:39 2014 for Hugintrunk by  doxygen 1.3.9.1