1 // 2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net> 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // === 17 /// 18 /// \file winapp.h 19 /// 20 21 #ifndef WIN_APP_H 22 #define WIN_APP_H 23 24 #include "gdef.h" 25 #include "gappbase.h" 26 #include "gexception.h" 27 #include "gtray.h" 28 #include "winform.h" 29 #include "configuration.h" 30 #include "output.h" 31 #include <memory> 32 33 /// \namespace Main 34 namespace Main 35 { 36 class WinApp ; 37 } 38 39 /// \class Main::WinApp 40 /// An application class instantiated in WinMain() and containing a 41 /// Main::WinForm object. 42 /// 43 /// WinMain() sets up slot/signal links from Main::Run to Main::WinApp so that 44 /// the Main::Run class can emit() progress events like "connecting to ..." and 45 /// the Main::WinApp class will display them (in the title bar, for instance). 46 /// 47 /// The class derives from Main::Output so that Main::CommandLine can call 48 /// output() to throw up message boxes. 49 /// 50 class Main::WinApp : public GGui::ApplicationBase , public Main::Output 51 { 52 public: 53 G_EXCEPTION( Error , "application error" ) ; 54 55 WinApp( HINSTANCE h , HINSTANCE p , const char * name ) ; 56 ///< Constructor. Initialise with init(). 57 58 virtual ~WinApp() ; 59 ///< Destructor. 60 61 void init( const Main::Configuration & cfg ) ; 62 ///< Initialises the object after construction. 63 64 int exitCode() const ; 65 ///< Returns an exit code. 66 67 void disableOutput() ; 68 ///< Disables subsequent calls to output(). 69 70 virtual void output( const std::string & message , bool error ) ; 71 ///< Puts up a message box. Override from Main::Output. 72 73 void onError( const std::string & message ) ; 74 ///< To be called when WinMain() catches an exception. 75 76 unsigned int columns() ; 77 ///< See Main::Output. 78 79 bool confirm() ; 80 ///< Puts up a confirmation message box. 81 82 void formOk() ; 83 ///< Called from the form's ok button handler. 84 85 void formDone() ; 86 ///< Called from the form's nc-destroy message handler. 87 88 void onRunEvent( std::string , std::string , std::string ) ; 89 ///< Slot for Main::Run::signal(). 90 91 private: 92 void doOpen() ; 93 void doClose() ; 94 void doQuit() ; 95 void hide() ; 96 virtual UINT resource() const ; 97 virtual DWORD windowStyle() const ; 98 virtual bool onCreate() ; 99 virtual bool onClose() ; 100 virtual void onTrayDoubleClick() ; 101 virtual void onTrayRightMouseButtonDown() ; 102 virtual void onDimension( int & , int & ) ; 103 virtual bool onSysCommand( SysCommand ) ; 104 virtual LRESULT onUser( WPARAM , LPARAM ) ; 105 void setStatus( const std::string & , const std::string & ) ; 106 107 private: 108 std::auto_ptr<GGui::Tray> m_tray ; 109 std::auto_ptr<Main::WinForm> m_form ; 110 std::auto_ptr<Main::Configuration> m_cfg ; 111 bool m_quit ; 112 bool m_use_tray ; 113 bool m_hidden ; 114 int m_exit_code ; 115 } ; 116 117 #endif 118 119