NIREP

C:/Programs/source/NIREP/Interface/wxNirepApp.h

00001 
00002 // Name:        wxnirepapp.h
00003 // Purpose:     Is the startup file that wxWidgets requires.  This will create
00004 //              the Interface which is the first interactive screen the user
00005 //              will see.  Also, this will display a splash screen when NIREP is
00006 //              started.  Finally, this file allows a user to double click an nd3
00007 //              file and have NIREP either start and create the display or if NIREP
00008 //              is already running, create the display.
00009 // Author:      James Harris II
00010 // Modified by: Gary E. Christensen
00011 // Created:     25/01/2008 15:55:45
00012 // RCS-ID:      
00013 // Copyright:   All rights reserved
00014 // Licence:     
00016 
00017 #ifndef _WXNIREPAPP_H_
00018 #define _WXNIREPAPP_H_
00019 
00020 #include "wx/image.h"
00021 #include "Interface.h"
00022 #include "wx/cmdline.h"  // Added 6/7/2010 GEC for cmd line processing
00023 #include "wx/ipc.h"      // Added 6/7/2010 GEC for inter process communication
00024 #include "wx/snglinst.h" // Added 6/7/2010 GEC for single instance checker 
00025 
00026 
00027 // Added 6/7/2010 GEC for command line parsing, Adapted from Chapt 20
00028 // Cross-Platform GUI Programming with wxWidgets by Julian Smart and Kevin Hock
00029 static const wxCmdLineEntryDesc g_cmdLineDesc[] = {
00030     //{ wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("displays help on the command line parameters") },
00031     //{ wxCMD_LINE_SWITCH, wxT("v"), wxT("version"), wxT("print version") },
00032     //{ wxCMD_LINE_PARAM, NULL, NULL, wxT("input file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
00033     { wxCMD_LINE_SWITCH, "h", "help", "displays help on the command line parameters" },
00034     { wxCMD_LINE_SWITCH, "v", "version", "print version" },
00035     { wxCMD_LINE_PARAM, NULL, NULL, "input file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
00036     { wxCMD_LINE_NONE }
00037 };
00038 
00040 //
00041 //  Programmer: Gary E. Christensen
00042 //  Date: 6/7/2010
00043 //  The following code insures that only a single instance of nirep is running at a time.
00044 //  The following code setups a server if it is the first instance of the program.
00045 //  Otherwise, it sets itself up as a client and makes a connection to the server.
00046 //  Assuming that the client started by double clicking on a display description, the
00047 //  client will pass the filename of the display description to the server and then exit.
00048 //  If the display description is already open, then the view will be brought to the forground.  
00049 //  Otherwise, nirep will open the dispaly description and bring the new window to the forground.
00050 //
00051 //  References: Chapt 20 in Cross-Platform, GUI Programming with wxWidgets by Julian Smart 
00052 //  and Kevin Hock with Stefan Csomor, 2006 Pearson Education, Inc.
00053 //  See wxWidgets-2.8.11\utils\helpview\src\helpview.h(cpp)
00054 //  See wxWidgets-2.8.11\samples\ipc\client.h(cpp) and server.h(cpp)
00055 //
00056 //  Notes: IPC is short for inter process communication.
00057 //
00059 #if wxUSE_IPC
00060 
00061 // Server class, for listening to connection requests
00062 class nirepServer : public wxServer{
00063 public:
00064         wxConnectionBase * OnAcceptConnection(const wxString & topic);
00065 };
00066 
00067 //Connection class, for use by both communicating instances
00068 class nirepConnection : public wxConnection{
00069 public:
00070         nirepConnection() {};
00071         ~nirepConnection() {};
00072 
00073         bool OnExecute(const wxString & topic, wxChar * data, int size, wxIPCFormat format);
00074 };
00075 
00076 // Client class, to be used by subsequent instances in OnInit
00077 class nirepClient : public wxClient{
00078 public:
00079         nirepClient() {};
00080         wxConnectionBase * OnMakeConnection() { return new nirepConnection; }
00081 };
00082 
00083 #endif
00084 
00089 class WxNIREPApp: public wxApp
00090 {    
00091     DECLARE_CLASS( WxNIREPApp )
00092     DECLARE_EVENT_TABLE()
00093 
00094 public:
00096     WxNIREPApp();
00097     ~WxNIREPApp();
00098 
00099     void Init();
00100 
00102     virtual bool OnInit();
00103 
00105     virtual int OnExit();
00106 
00107     void CreateStyles();
00108 
00109     wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
00110 
00111     wxRichTextPrinting* GetPrinting() const { return m_printing; }
00112 
00113     wxRichTextStyleSheet*   m_styleSheet;
00114     wxRichTextPrinting*     m_printing;
00115 
00116 private:
00117   Interface* mainWindow;
00118 
00119 // Added 6/7/2010 GEC for inter process communication and single instance
00120 #if wxUSE_IPC
00121     nirepServer * m_server;
00122         wxSingleInstanceChecker * m_singleInstanceChecker;
00123 #endif
00124 
00125 
00126 };
00127 
00128 DECLARE_APP(WxNIREPApp)
00129 
00130 #endif  // _WXNIREPAPP_H_
 All Classes Functions Variables Typedefs Enumerations Enumerator