OSDN Git Service

'Filter' mode is implemented (experimentally)
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Thu, 11 Oct 2012 11:52:16 +0000 (11:52 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Thu, 11 Oct 2012 11:52:16 +0000 (11:52 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@290 a2be9bc6-48de-4e38-9406-05402d4bc13c

15 files changed:
Makefile
MolLib/MainView.h
MolLib/Ruby_bind/Molby_extern.h
MolLib/Ruby_bind/ruby_bind.c
wxSources/ConsoleFrame.cpp
wxSources/MoleculeView.cpp
wxSources/MyApp.cpp
wxSources/MyApp.h
wxSources/MyDocManager.cpp
wxSources/MyDocManager.h
wxSources/MyDocument.cpp
wxSources/MyDocument.h
wxSources/MyIPCSupport.cpp [new file with mode: 0755]
wxSources/MyIPCSupport.h [new file with mode: 0755]
xcode-build/Molby.xcodeproj/project.pbxproj

index dc59638..aa714df 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ ifeq ($(TARGET_PLATFORM),MSW)
 endif
 
 WXLIB_LIST = core,base,gl,adv
-OBJECTS = ConsoleFrame.o GlobalParameterFrame.o GlobalParameterFilesFrame.o MoleculeView.o MyApp.o MyCommand.o MyDocument.o MyGLCanvas.o MySlider.o MyClipboardData.o ProgressFrame.o MyListCtrl.o MyDocManager.o wxKillAddition.o docview.o RubyDialogFrame.o MyVersion.o MyThread.o
+OBJECTS = ConsoleFrame.o GlobalParameterFrame.o GlobalParameterFilesFrame.o MoleculeView.o MyApp.o MyCommand.o MyDocument.o MyGLCanvas.o MySlider.o MyClipboardData.o ProgressFrame.o MyListCtrl.o MyDocManager.o wxKillAddition.o docview.o RubyDialogFrame.o MyIPCSupport.o MyVersion.o MyThread.o
 LIBS = MolLib.a Ruby_bind.a
 RUBY_EXTLIB = scanf.rb
 
index 93b61cc..b2e79d8 100755 (executable)
@@ -262,7 +262,7 @@ STUB void MainViewCallback_selectMatrixCellForMode(MainView *mview, int mode);
 //STUB int MainViewCallback_getTag(MainView *mview);
 STUB MainView *MainViewCallback_viewWithTag(int tag);
 STUB MainView *MainViewCallback_activeView(void);
-STUB MainView *MainViewCallback_newFromFile(const char *fname);
+//STUB MainView *MainViewCallback_newFromFile(const char *fname);
 STUB int MainViewCallback_importFromFile(MainView *mview, const char *fname);
 STUB void MainViewCallback_getFilename(MainView *mview, char *buf, int bufsize);
 //STUB void MainViewCallback_moleculeReplaced(MainView *mview, struct Molecule *mol);
index ec65a78..e226200 100755 (executable)
@@ -36,7 +36,8 @@ extern RubyValue Molby_evalRubyScriptOnMolecule(const char *script, Molecule *mo
 extern RubyValue Molby_evalRubyScriptOnActiveMoleculeWithInterrupt(const char *script, int *status); */
 extern void Molby_showRubyValue(RubyValue value);
 extern int Ruby_methodType(const char *className, const char *methodName);
-
+extern void Molby_buildARGV(int argc, const char **argv);
+       
 STUB char *MyAppCallback_getGlobalSettings(const char *key);
 STUB void MyAppCallback_setGlobalSettings(const char *key, const char *value);
 STUB int MyAppCallback_getGlobalSettingsWithType(const char *key, int type, void *ptr);
index c94918f..465604a 100644 (file)
@@ -646,6 +646,8 @@ s_Kernel_ExecuteScript(VALUE self, VALUE fname)
 {
        int status;
        VALUE retval = (VALUE)MyAppCallback_executeScriptFromFile(StringValuePtr(fname), &status);
+       if (retval == (VALUE)6 && status == -1)
+               rb_raise(rb_eMolbyError, "Cannot open script file: %s", StringValuePtr(fname));
        if (status != 0)
                rb_jump_tag(status);
        return retval;
@@ -10280,3 +10282,15 @@ Molby_startup(const char *script, const char *dir)
                        MyAppCallback_showScriptMessage("Done.\n");
        }
 }
+
+void
+Molby_buildARGV(int argc, const char **argv)
+{
+       int i;
+    rb_ary_clear(rb_argv);
+    for (i = 0; i < argc; i++) {
+               VALUE arg = rb_tainted_str_new2(argv[i]);
+               OBJ_FREEZE(arg);
+               rb_ary_push(rb_argv, arg);
+    }
+}
index b1bb93f..5e2675f 100755 (executable)
  GNU General Public License for more details.
  */
 
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+#include "wx/wx.h"
+#endif
+
 #include "ConsoleFrame.h"
 
 #include "wx/menu.h"
 #include "wx/regex.h"
 #include "wx/colour.h"
+#include "wx/sizer.h"
 
 #include "MyApp.h"
 #include "../MolLib/Ruby_bind/Molby_extern.h"
@@ -49,10 +56,15 @@ void
 ConsoleFrame::OnCreate()
 {
        //  Make a text view
-#warning "TODO: Set the sizer for the text control properly"
        int width, height;
+
        GetClientSize(&width, &height);
-       textCtrl = new wxTextCtrl(this, wxID_ANY, _T(""), wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_RICH);
+       textCtrl = new wxTextCtrl(this, wxID_ANY, _T(""), wxPoint(0, 0), wxSize(100, 100), wxTE_MULTILINE | wxTE_RICH);
+
+       wxBoxSizer *consoleSizer = new wxBoxSizer(wxHORIZONTAL);
+       consoleSizer->Add(textCtrl, 1, wxEXPAND | wxALL, 2);
+       this->SetSizer(consoleSizer);
+       consoleSizer->SetSizeHints(this);
        
        //  Connect "OnKeyDown" event handler
        textCtrl->Connect(-1, wxEVT_KEY_DOWN, wxKeyEventHandler(ConsoleFrame::OnKeyDown), NULL, this);
@@ -73,9 +85,20 @@ ConsoleFrame::CreateConsoleFrame(wxMDIParentFrame *parent)
        wxPoint origin(10, 24);
        wxSize size(640, 200);
 #endif
-       ConsoleFrame *frame = new ConsoleFrame(parent, _T("Console"), origin, size, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
-       
+       ConsoleFrame *frame = new ConsoleFrame(parent, _T("Console"), origin, wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
+
        frame->OnCreate();
+
+       if (wxGetApp().IsFilterMode()) {
+#if defined(__WXMSW__)
+               frame->Maximize();
+#else
+               frame->SetSize(800, 480);
+#endif
+       } else {
+               frame->SetSize(640, 200);
+       }
+               
        return frame;
 }
 
index bde9126..5192a54 100755 (executable)
@@ -675,7 +675,8 @@ void
 MoleculeView::OnActivate(wxActivateEvent &event)
 {
        if (!event.GetActive()) {
-               listctrl->EndEditText(true);
+               if (listctrl != NULL)
+                       listctrl->EndEditText(true);
        }
        event.Skip();
 }
@@ -970,6 +971,7 @@ MainViewCallback_activeView(void)
   //   return MainViewCallback_viewWithTag(sLastMainViewTag);
 }
 
+/*
 MainView *
 MainViewCallback_newFromFile(const char *fname)
 {
@@ -983,6 +985,7 @@ MainViewCallback_newFromFile(const char *fname)
   }
   return MainViewCallback_activeView();
 }
+*/
 
 int
 MainViewCallback_importFromFile(MainView *mview, const char *fname)
index daac33b..f5da639 100755 (executable)
 #include "GlobalParameterFilesFrame.h"
 #include "MyMBConv.h"
 
+#if defined(__WXMSW__)
+#include "MyIPCSupport.h"
+#endif
+
 #include "../MolLib/MolLib.h"
 #include "../MolLib/Ruby_bind/Molby.h"
 #include "../MolLib/Missing.h"
@@ -62,6 +66,7 @@
 #include <CoreFoundation/CoreFoundation.h>
 #undef T_DATA
 #include <Carbon/Carbon.h>
+#include "wx/mac/carbon/private.h"
 #include <sys/wait.h>  /* for waitpid()  */
 #endif
 
@@ -79,6 +84,7 @@ BEGIN_EVENT_TABLE(MyApp, wxApp)
        //EVT_KEY_DOWN(MyApp::OnChar)
        //EVT_MOUSE_EVENTS(MyApp::OnMouseEvent)
        EVT_COMMAND(MyDocumentEvent_scriptMenuModified, MyDocumentEvent, MyApp::OnScriptMenuModified)
+       EVT_COMMAND(MyDocumentEvent_openFilesByIPC, MyDocumentEvent, MyApp::OnOpenFilesByIPC)
        EVT_UPDATE_UI_RANGE(myMenuID_MyFirstMenuItem, myMenuID_MyLastMenuItem, MyApp::OnUpdateUI)
        EVT_MENU(myMenuID_ExecuteScript, MyApp::OnExecuteScript)
        EVT_MENU(myMenuID_OpenConsoleWindow, MyApp::OnOpenConsoleWindow)
@@ -163,6 +169,15 @@ MyApp::MyApp(void)
        consoleFrame = NULL;
        m_CountNamedFragments = 0;
        m_NamedFragments = (char **)(-1);  /*  Will be set to NULL after Ruby interpreter is initialized  */
+       m_pendingFilesToOpen = NULL;
+       m_filterScriptName = NULL;
+       m_filterScriptBaseName = NULL;
+#if defined(__WXMSW__)
+       m_checker = NULL;
+       m_ipcServiceName = NULL;
+       m_server = NULL;
+       m_client = NULL;
+#endif
 }
 
 bool MyApp::OnInit(void)
@@ -172,18 +187,68 @@ bool MyApp::OnInit(void)
        wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), 1);
 #endif
 
+       //  Check if invoked as a filter mode
+       if (argc > 2) {
+               wxString arg1(argv[1]);
+               wxString arg2(argv[2]);
+               if (arg1 == wxT("--filter") && (arg2.EndsWith(wxT(".rb")) || arg2.EndsWith(wxT(".mrb")))) {
+                       char *p;
+                       m_filterScriptName = strdup(arg2.mb_str(wxConvFile));
+                       p = strrchr(m_filterScriptName, '/');
+#if defined(__WXMSW__)
+                       if (p == NULL)
+                               p = strrchr(m_filterScriptName, '\\');
+#endif
+                       if (p == NULL)
+                               p = m_filterScriptName;
+                       m_filterScriptBaseName = strdup(p);
+               }
+       }
+       
 #if __WXMSW__
        {
                //  Check if the same application is already running
-               char *buf;
-               asprintf(&buf, "Molby-%s", (const char *)wxGetUserId().mb_str(WX_DEFAULT_CONV));
+               char *buf, *p;
+               if (m_filterScriptBaseName != NULL) {
+                       p = m_filterScriptBaseName;
+               } else p = "";
+               asprintf(&buf, "Molby%s-%s", p, (const char *)wxGetUserId().mb_str(WX_DEFAULT_CONV));
                wxString name(buf, WX_DEFAULT_CONV);
-               malloc(16);
+               m_ipcServiceName = new wxString(name);
+               m_ipcServiceName->Prepend(wxT("IPC-"));
                free(buf);
                m_checker = new wxSingleInstanceChecker(name);
                if (m_checker->IsAnotherRunning()) {
-                       wxLogError(_T("Molby is already running."));
+                       //  Make a connection with the other instance and ask for opening the file(s)
+                       wxString files;
+                       wxConnectionBase *connection;
+                       if (m_filterScriptName != NULL) {
+                               //  Skip the "--filter" option and the script name
+                               argc -= 2;
+                               argv += 2;
+                       }
+                       while (argc > 1) {
+                               files.append(argv[1]);
+                               files.append(wxT("\n"));
+                               argc--;
+                               argv++;
+                       }
+                       m_client = new MyClient;
+                       connection = m_client->MakeConnection(wxT("localhost"), *m_ipcServiceName, MOLBY_IPC_TOPIC);
+                       if (connection == NULL) {
+                               wxLogError(wxT("Molby is already running; please shut it down and retry"));
+                               delete m_client;
+                               return false;
+                       }
+                       connection->Execute(files);
+                       delete m_client;
                        return false;
+               } else {
+                       m_server = new MyServer;
+                       if (m_server->Create(*m_ipcServiceName) == false) {
+                               delete m_server;
+                               m_server = NULL;
+                       }
                }
        }
 #endif
@@ -307,12 +372,21 @@ bool MyApp::OnInit(void)
                wxString fnamestr(fname, wxConvFile);
                Molby_startup(wxFileExists(fnamestr) ? fname : NULL, (const char *)dirname.mb_str(wxConvFile));
                
-       /*      wxSetWorkingDirectory(cwd); */
                {
                        wxString docHome(MyAppCallback_getDocumentHomeDir(), wxConvFile);
                        wxSetWorkingDirectory(docHome);
                        
                }
+               if (IsFilterMode()) {
+                       MyAppCallback_setConsoleColor(3);
+                       MyAppCallback_showScriptMessage("***********************************************************\n");
+                       MyAppCallback_showScriptMessage(" Molby is now running in the filter mode.\n");
+                       MyAppCallback_showScriptMessage(" When you open files, they will be processed by\n");
+                       MyAppCallback_showScriptMessage(" the script '%s'.\n", m_filterScriptBaseName);
+                       MyAppCallback_showScriptMessage(" You can process any file, not necessarily molecular files.\n");
+                       MyAppCallback_showScriptMessage("***********************************************************\n");
+                       MyAppCallback_setConsoleColor(0);
+               }
                MyAppCallback_showScriptMessage("%% ");
                
                /*  Build the predefined fragments menu  */
@@ -322,18 +396,26 @@ bool MyApp::OnInit(void)
 
        }
        
-       /*  Open given files as MyDocument  */
+       /*  Open given files: Ruby script is executed, other files are opened as a document  */
+       if (IsFilterMode()) {
+               argc -= 2;
+               argv += 2;
+       }
        if (argc == 1) {
-#if __WXMSW__
-               m_docManager->CreateDocument(wxEmptyString, wxDOC_NEW);
+#if defined(__WXMSW__)
+               if (!IsFilterMode())
+                       m_docManager->CreateDocument(wxEmptyString, wxDOC_NEW);
 #endif
        } else {
-               while (argc > 1) {
-                       wxString file(argv[1]);
-                       m_docManager->CreateDocument(file, wxDOC_SILENT);
+               int i;
+               wxString files;
+               for (i = 1; i < argc; i++) {
+                       files.append(argv[i]);
+                       files.append(wxT("\n"));
                        argc--;
                        argv++;
                }
+               OnOpenFiles(files);
        }
        
        return true;
@@ -349,6 +431,7 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit
        
        //// Make a menubar
        wxMenu *file_menu = new wxMenu;
+       bool filter_mode = IsFilterMode();
 
        file_menu->Append(wxID_NEW, _T("&New...\tCtrl-N"));
        file_menu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
@@ -359,22 +442,24 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit
                m_docManager->FileHistoryUseMenu(*out_file_history_menu);  //  Should be removed when menu is discarded
        }
        /*  Build "Open Predefined"  */
-       wxMenu *predefined_menu = new wxMenu;
-       file_menu->Append(myMenuID_PredefinedFragment, _T("Open Predefined"), predefined_menu);
-       
-       file_menu->AppendSeparator();
-       file_menu->Append(wxID_CLOSE, _T("&Close\tCtrl-W"));
-       file_menu->Append(wxID_SAVE, _T("&Save\tCtrl-S"));
-       file_menu->Append(wxID_SAVEAS, _T("Save &As..."));      
+       if (!filter_mode) {
+               wxMenu *predefined_menu = new wxMenu;
+               file_menu->Append(myMenuID_PredefinedFragment, _T("Open Predefined"), predefined_menu);
        
-       file_menu->AppendSeparator();
-       file_menu->Append(myMenuID_Import, _T("Import..."));    
-       file_menu->Append(myMenuID_Export, _T("Export..."));    
-       
-       file_menu->AppendSeparator();
-       file_menu->Append(wxID_PRINT, _T("&Print...\tCtrl-P"));
-       file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
-       file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
+               file_menu->AppendSeparator();
+               file_menu->Append(wxID_CLOSE, _T("&Close\tCtrl-W"));
+               file_menu->Append(wxID_SAVE, _T("&Save\tCtrl-S"));
+               file_menu->Append(wxID_SAVEAS, _T("Save &As..."));      
+               
+               file_menu->AppendSeparator();
+               file_menu->Append(myMenuID_Import, _T("Import..."));    
+               file_menu->Append(myMenuID_Export, _T("Export..."));    
+               
+               file_menu->AppendSeparator();
+               file_menu->Append(wxID_PRINT, _T("&Print...\tCtrl-P"));
+               file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
+               file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
+       }
        
        file_menu->AppendSeparator();
 #if defined(__WXMAC__)
@@ -393,85 +478,98 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit
        edit_menu->Append(wxID_CLEAR, _T("Clear"));
        edit_menu->AppendSeparator();
        edit_menu->Append(wxID_SELECTALL, _T("Select All\tCtrl-A"));
-       edit_menu->Append(myMenuID_SelectFragment, _T("Select Fragment\tCtrl-F"));
-       edit_menu->Append(myMenuID_SelectReverse, _T("Select Reverse"));
-       edit_menu->AppendSeparator();
-       wxMenu *create_parameter_menu = new wxMenu;
-       create_parameter_menu->Append(myMenuID_CreateNewVdwParameter, _T("Vdw"));
-       create_parameter_menu->Append(myMenuID_CreateNewBondParameter, _T("Bond"));
-       create_parameter_menu->Append(myMenuID_CreateNewAngleParameter, _T("Angle"));
-       create_parameter_menu->Append(myMenuID_CreateNewDihedralParameter, _T("Dihedral"));
-       create_parameter_menu->Append(myMenuID_CreateNewImproperParameter, _T("Improper"));
-       create_parameter_menu->Append(myMenuID_CreateNewVdwPairParameter, _T("Vdw Pair"));
-       create_parameter_menu->Append(myMenuID_CreateNewVdwCutoffParameter, _T("Vdw Cutoff"));
-       edit_menu->Append(myMenuID_CreateNewAtom, _T("Create New Atom\tCtrl-I"));
-       edit_menu->Append(myMenuID_CreateNewParameter, _T("Create New Parameter"), create_parameter_menu);
-       edit_menu->AppendSeparator();
-       wxMenu *add_hydrogen_menu = new wxMenu;
-       add_hydrogen_menu->Append(myMenuID_AddHydrogenSp3, _T("Tetrahedral sp3"));
-       add_hydrogen_menu->Append(myMenuID_AddHydrogenSp2, _T("Trigonal sp2"));
-       add_hydrogen_menu->Append(myMenuID_AddHydrogenLinear, _T("Linear sp"));
-       add_hydrogen_menu->Append(myMenuID_AddHydrogenPyramidal, _T("Pyramidal (like NH2)"));
-       add_hydrogen_menu->Append(myMenuID_AddHydrogenBent, _T("Bent (like OH)"));
-       edit_menu->Append(myMenuID_AddHydrogen, _T("Add Hydrogen"), add_hydrogen_menu);
+       if (!filter_mode) {
+               edit_menu->Append(myMenuID_SelectFragment, _T("Select Fragment\tCtrl-F"));
+               edit_menu->Append(myMenuID_SelectReverse, _T("Select Reverse"));
+               edit_menu->AppendSeparator();
+               wxMenu *create_parameter_menu = new wxMenu;
+               create_parameter_menu->Append(myMenuID_CreateNewVdwParameter, _T("Vdw"));
+               create_parameter_menu->Append(myMenuID_CreateNewBondParameter, _T("Bond"));
+               create_parameter_menu->Append(myMenuID_CreateNewAngleParameter, _T("Angle"));
+               create_parameter_menu->Append(myMenuID_CreateNewDihedralParameter, _T("Dihedral"));
+               create_parameter_menu->Append(myMenuID_CreateNewImproperParameter, _T("Improper"));
+               create_parameter_menu->Append(myMenuID_CreateNewVdwPairParameter, _T("Vdw Pair"));
+               create_parameter_menu->Append(myMenuID_CreateNewVdwCutoffParameter, _T("Vdw Cutoff"));
+               edit_menu->Append(myMenuID_CreateNewAtom, _T("Create New Atom\tCtrl-I"));
+               edit_menu->Append(myMenuID_CreateNewParameter, _T("Create New Parameter"), create_parameter_menu);
+               edit_menu->AppendSeparator();
+               wxMenu *add_hydrogen_menu = new wxMenu;
+               add_hydrogen_menu->Append(myMenuID_AddHydrogenSp3, _T("Tetrahedral sp3"));
+               add_hydrogen_menu->Append(myMenuID_AddHydrogenSp2, _T("Trigonal sp2"));
+               add_hydrogen_menu->Append(myMenuID_AddHydrogenLinear, _T("Linear sp"));
+               add_hydrogen_menu->Append(myMenuID_AddHydrogenPyramidal, _T("Pyramidal (like NH2)"));
+               add_hydrogen_menu->Append(myMenuID_AddHydrogenBent, _T("Bent (like OH)"));
+               edit_menu->Append(myMenuID_AddHydrogen, _T("Add Hydrogen"), add_hydrogen_menu);
+       }
        
        if (out_edit_menu != NULL)
                *out_edit_menu = edit_menu;     // Should be associated with the command processor if available
        
        wxMenu *show_menu = new wxMenu;
-       show_menu->Append(myMenuID_FitToScreen, _T("Fit To Screen\tCtrl-T"));
-       show_menu->Append(myMenuID_CenterSelection, _T("Center Selection"));
-       show_menu->AppendSeparator();
-       show_menu->Append(myMenuID_ShowUnitCell, _T("Show Unit Cell"), _T(""), wxITEM_CHECK);
-/*     show_menu->Append(myMenuID_ShowPeriodicBox, _T("Show Periodic Box"), _T(""), wxITEM_CHECK); */
-       show_menu->Append(myMenuID_ShowHydrogens, _T("Show Hydrogen Atoms"), _T(""), wxITEM_CHECK);
-       show_menu->Append(myMenuID_ShowDummyAtoms, _T("Show Dummy Atoms"), _T(""), wxITEM_CHECK);
-       show_menu->Append(myMenuID_ShowExpandedAtoms, _T("Show Expanded Atoms"), _T(""), wxITEM_CHECK);
-       show_menu->Append(myMenuID_ShowEllipsoids, _T("Show Ellipsoids"), _T(""), wxITEM_CHECK);
-       show_menu->Append(myMenuID_ShowRotationCenter, _T("Show Rotation Center"), _T(""), wxITEM_CHECK);
-       show_menu->AppendSeparator();
-       show_menu->Append(myMenuID_HideSelected, _T("Hide Selected"), _T(""));
-       show_menu->Append(myMenuID_HideUnselected, _T("Hide Unselected"), _T(""));
-       show_menu->Append(myMenuID_HideReverse, _T("Hide Reverse"), _T(""));
-       show_menu->Append(myMenuID_ShowAllAtoms, _T("Show All Atoms"), _T(""));
-       show_menu->AppendSeparator();
-       show_menu->Append(myMenuID_ShowGraphite, _T("Show Graphite..."));
-       show_menu->AppendSeparator();
-       show_menu->Append(myMenuID_LineMode, _T("Line Mode"), _T(""), wxITEM_CHECK);
+       if (!filter_mode) {
+               show_menu->Append(myMenuID_FitToScreen, _T("Fit To Screen\tCtrl-T"));
+               show_menu->Append(myMenuID_CenterSelection, _T("Center Selection"));
+               show_menu->AppendSeparator();
+               show_menu->Append(myMenuID_ShowUnitCell, _T("Show Unit Cell"), _T(""), wxITEM_CHECK);
+       /*      show_menu->Append(myMenuID_ShowPeriodicBox, _T("Show Periodic Box"), _T(""), wxITEM_CHECK); */
+               show_menu->Append(myMenuID_ShowHydrogens, _T("Show Hydrogen Atoms"), _T(""), wxITEM_CHECK);
+               show_menu->Append(myMenuID_ShowDummyAtoms, _T("Show Dummy Atoms"), _T(""), wxITEM_CHECK);
+               show_menu->Append(myMenuID_ShowExpandedAtoms, _T("Show Expanded Atoms"), _T(""), wxITEM_CHECK);
+               show_menu->Append(myMenuID_ShowEllipsoids, _T("Show Ellipsoids"), _T(""), wxITEM_CHECK);
+               show_menu->Append(myMenuID_ShowRotationCenter, _T("Show Rotation Center"), _T(""), wxITEM_CHECK);
+               show_menu->AppendSeparator();
+               show_menu->Append(myMenuID_HideSelected, _T("Hide Selected"), _T(""));
+               show_menu->Append(myMenuID_HideUnselected, _T("Hide Unselected"), _T(""));
+               show_menu->Append(myMenuID_HideReverse, _T("Hide Reverse"), _T(""));
+               show_menu->Append(myMenuID_ShowAllAtoms, _T("Show All Atoms"), _T(""));
+               show_menu->AppendSeparator();
+               show_menu->Append(myMenuID_ShowGraphite, _T("Show Graphite..."));
+               show_menu->AppendSeparator();
+               show_menu->Append(myMenuID_LineMode, _T("Line Mode"), _T(""), wxITEM_CHECK);
+       }
 
        wxMenu *md_menu = new wxMenu;
-       md_menu->Append(myMenuID_MolecularDynamics, _T("Molecular Dynamics..."));
-       md_menu->Append(myMenuID_Minimize, _T("Minimize..."));
-       md_menu->Append(myMenuID_StopMDRun, _T("Stop\tCtrl-."));
-       md_menu->AppendSeparator();
-//     md_menu->Append(myMenuID_ReadParameters, _T("Read Parameters..."));     
-       md_menu->Append(myMenuID_ViewGlobalParameters, _T("View Global Parameters..."));
-       md_menu->Append(myMenuID_ViewParameterFilesList, _T("Load/Unload Global Parameters..."));
-       md_menu->AppendSeparator();
-       md_menu->Append(myMenuID_DefinePeriodicBox, _T("Define Unit Cell..."));
-       md_menu->Append(myMenuID_ShowPeriodicImage, _T("Show Periodic Image..."));
-/*     md_menu->Append(myMenuID_PressureControl, _T("Pressure Control...")); */
-/*     md_menu->Append(myMenuID_DefineSymmetry, _T("Define Symmetry Operations..."));
-       md_menu->Append(myMenuID_ExpandBySymmetry, _T("Expand by Symmetry...")); */
-       md_menu->AppendSeparator();
+       if (!filter_mode) {
+               md_menu->Append(myMenuID_MolecularDynamics, _T("Molecular Dynamics..."));
+               md_menu->Append(myMenuID_Minimize, _T("Minimize..."));
+               md_menu->Append(myMenuID_StopMDRun, _T("Stop\tCtrl-."));
+               md_menu->AppendSeparator();
+       //      md_menu->Append(myMenuID_ReadParameters, _T("Read Parameters..."));     
+               md_menu->Append(myMenuID_ViewGlobalParameters, _T("View Global Parameters..."));
+               md_menu->Append(myMenuID_ViewParameterFilesList, _T("Load/Unload Global Parameters..."));
+               md_menu->AppendSeparator();
+               md_menu->Append(myMenuID_DefinePeriodicBox, _T("Define Unit Cell..."));
+               md_menu->Append(myMenuID_ShowPeriodicImage, _T("Show Periodic Image..."));
+       /*      md_menu->Append(myMenuID_PressureControl, _T("Pressure Control...")); */
+       /*      md_menu->Append(myMenuID_DefineSymmetry, _T("Define Symmetry Operations..."));
+               md_menu->Append(myMenuID_ExpandBySymmetry, _T("Expand by Symmetry...")); */
+               md_menu->AppendSeparator();
+       }
+       
        wxMenu *md_tools_menu = new wxMenu;
-       md_tools_menu->Append(myMenuID_RunAntechamber, _T("Antechamber/parmchk..."));
-       md_tools_menu->Append(myMenuID_RunResp, _T("GAMESS/RESP..."));
-       md_tools_menu->Append(myMenuID_CreateSanderInput, _T("Create SANDER input..."));
-       md_tools_menu->Append(myMenuID_ImportAmberLib, _T("Import AMBER Lib..."));
-       md_tools_menu->Append(myMenuID_ImportAmberFrcmod, _T("Import AMBER Frcmod..."));
-       md_menu->Append(myMenuID_MDTools, _T("Tools"), md_tools_menu);
+       if (!filter_mode) {
+               md_tools_menu->Append(myMenuID_RunAntechamber, _T("Antechamber/parmchk..."));
+               md_tools_menu->Append(myMenuID_RunResp, _T("GAMESS/RESP..."));
+               md_tools_menu->Append(myMenuID_CreateSanderInput, _T("Create SANDER input..."));
+               md_tools_menu->Append(myMenuID_ImportAmberLib, _T("Import AMBER Lib..."));
+               md_tools_menu->Append(myMenuID_ImportAmberFrcmod, _T("Import AMBER Frcmod..."));
+               md_menu->Append(myMenuID_MDTools, _T("Tools"), md_tools_menu);
+       }
 
        wxMenu *qc_menu = new wxMenu;
-       qc_menu->Append(myMenuID_CreateGamessInput, _T("Create GAMESS input..."));
-       qc_menu->Append(myMenuID_CreateMOCube, _T("Create MO cube..."));
+       if (!filter_mode) {
+               qc_menu->Append(myMenuID_CreateGamessInput, _T("Create GAMESS input..."));
+               qc_menu->Append(myMenuID_CreateMOCube, _T("Create MO cube..."));
+       }
        
        wxMenu *script_menu = new wxMenu;
-       script_menu->Append(myMenuID_ExecuteScript, _T("Execute Script..."));
-       script_menu->Append(myMenuID_OpenConsoleWindow, _T("Open Console Window..."));
-       script_menu->Append(myMenuID_EmptyConsoleWindow, _T("Empty Console Window"));
-       script_menu->AppendSeparator();
-       countNonCustomScriptMenu = script_menu->GetMenuItemCount();
+       if (!filter_mode) {
+               script_menu->Append(myMenuID_ExecuteScript, _T("Execute Script..."));
+               script_menu->Append(myMenuID_OpenConsoleWindow, _T("Open Console Window..."));
+               script_menu->Append(myMenuID_EmptyConsoleWindow, _T("Empty Console Window"));
+               script_menu->AppendSeparator();
+               countNonCustomScriptMenu = script_menu->GetMenuItemCount();
+       }
 
        wxMenu *help_menu = new wxMenu;
        help_menu->Append(wxID_ABOUT, _T("&About...\tF1"));
@@ -480,10 +578,12 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit
        
        menu_bar->Append(file_menu, _T("&File"));
        menu_bar->Append(edit_menu, _T("&Edit"));
-       menu_bar->Append(show_menu, _T("Show"));
-       menu_bar->Append(md_menu, _T("MM/MD"));
-       menu_bar->Append(qc_menu, _T("QChem"));
-       menu_bar->Append(script_menu, _T("&Script"));
+       if (!filter_mode) {
+               menu_bar->Append(show_menu, _T("Show"));
+               menu_bar->Append(md_menu, _T("MM/MD"));
+               menu_bar->Append(qc_menu, _T("QChem"));
+               menu_bar->Append(script_menu, _T("&Script"));
+       }
        menu_bar->Append(help_menu, _T("&Help"));
        
        UpdateScriptMenu(menu_bar);
@@ -500,8 +600,62 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit
 void
 MyApp::MacNewFile()
 {
-       m_docManager->CreateDocument(_T(""), wxDOC_NEW);
+       /*  Do nothing in filter mode  */
+       if (!IsFilterMode())
+               m_docManager->CreateDocument(_T(""), wxDOC_NEW);
 }
+
+void
+MyApp::MacOpenFile(const wxString &fileName)
+{
+       wxString files(fileName);
+       OnOpenFiles(files);
+}
+
+/*  Open given files: instead of calling MacOpenFile() for each entry, build a file list
+    and call MyApp::OnOpenFiles()  */
+short
+MyApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
+{
+    AEDescList docList;
+    AEKeyword keywd;
+    DescType returnedType;
+    Size actualSize;
+    long itemsInList;
+    OSErr err;
+    short i;
+       
+    err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList, &docList);
+    if (err != noErr)
+        return err;
+       
+    err = AECountItems(&docList, &itemsInList);
+    if (err != noErr)
+        return err;
+       
+    ProcessSerialNumber PSN ;
+    PSN.highLongOfPSN = 0 ;
+    PSN.lowLongOfPSN = kCurrentProcess ;
+    SetFrontProcess( &PSN ) ;
+       
+    wxString fName, fNameList;
+    FSRef theRef ;
+       
+    for (i = 1; i <= itemsInList; i++)
+    {
+        AEGetNthPtr(
+                                       &docList, i, typeFSRef, &keywd, &returnedType,
+                                       (Ptr)&theRef, sizeof(theRef), &actualSize);
+        fName = wxMacFSRefToPath( &theRef ) ;
+               fNameList.append(fName);
+               fNameList.append(wxT("\n"));
+    }
+       
+       OnOpenFiles(fNameList);
+       
+    return noErr;
+}
+
 #endif
 
 int MyApp::OnExit(void)
@@ -510,6 +664,7 @@ int MyApp::OnExit(void)
     delete m_docManager;
 #if __WXMSW__
        delete m_checker;
+       delete m_server;
 #endif
     return 0;
 }
@@ -949,6 +1104,7 @@ MyApp::OnExecuteScript(wxCommandEvent &event)
        wxFileDialog *dialog = new wxFileDialog(NULL, _T("Choose Script File"), _T(""), _T(""), _T("All files (*.*)|*.*"), wxFD_OPEN | wxFD_CHANGE_DIR | wxFD_FILE_MUST_EXIST);
        if (dialog->ShowModal() == wxID_OK) {
                int status;
+               RubyValue retval;
                wxString path = dialog->GetPath();
                
                //  Command line: execute_script('pathname')
@@ -962,8 +1118,10 @@ MyApp::OnExecuteScript(wxCommandEvent &event)
                wxGetApp().AppendConsoleMessage("\n");
                MyAppCallback_setConsoleColor(0);
 
-               MyAppCallback_executeScriptFromFile((const char *)(path.mb_str(wxConvFile)), &status);
-               if (status != 0)
+               retval = MyAppCallback_executeScriptFromFile((const char *)(path.mb_str(wxConvFile)), &status);
+               if (retval == (RubyValue)6 && status == -1)
+                       MyAppCallback_errorMessageBox("Cannot open Ruby script %s", (const char *)path.mb_str(wxConvFile));
+               else if (status != 0)
                        Molby_showError(status);
        }
        dialog->Destroy();
@@ -979,6 +1137,82 @@ MyApp::OnActivate(wxActivateEvent &event)
        event.Skip();
 }
 
+void
+MyApp::RequestOpenFilesByIPC(wxString& files)
+{
+       if (m_pendingFilesToOpen != NULL)
+               m_pendingFilesToOpen->Append(files);
+       else
+               m_pendingFilesToOpen = new wxString(files);
+       wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_openFilesByIPC);
+       wxPostEvent(this, myEvent);
+}
+
+void
+MyApp::OnOpenFilesByIPC(wxCommandEvent& event)
+{
+       if (m_pendingFilesToOpen == NULL)
+               return;
+       OnOpenFiles(*m_pendingFilesToOpen);
+       delete m_pendingFilesToOpen;
+       m_pendingFilesToOpen = NULL;
+}
+
+bool
+MyApp::OnOpenFiles(wxString &files)
+{
+       Int start, end;
+       Int nargs = 0;
+       const char **args = NULL;
+       bool success = true;
+       int status;
+       RubyValue retval;
+       start = 0;
+       while (1) {
+               end = files.find(wxT("\n"), start);
+               wxString file = files.Mid(start, (end == wxString::npos ? wxString::npos : end - start));
+               if (file.Len() == 0)
+                       break;
+               if (IsFilterMode()) {
+                       /*  Filter mode: build ARGV and call the given script (later)  */
+                       AssignArray(&args, &nargs, sizeof(char *), nargs, NULL);
+                       args[nargs - 1] = strdup(file.mb_str(wxConvFile));
+               } else {
+                       if (file.EndsWith(wxT(".rb")) || file.EndsWith(wxT(".mrb"))) {
+                               /*  Execute the file as a Ruby script  */
+                               retval = MyAppCallback_executeScriptFromFile((const char *)file.mb_str(wxConvFile), &status);
+                               if (status != 0) {
+                                       if (retval == (RubyValue)6 && status == -1)
+                                               MyAppCallback_errorMessageBox("Cannot open Ruby script: %s", (const char *)file.mb_str(wxConvFile));
+                                       else
+                                               Molby_showError(status);
+                                       return false;
+                               }
+                       }
+                       if (NULL == wxGetApp().DocManager()->CreateDocument(file, wxDOC_SILENT))
+                               success = false;
+               }
+               if (end == wxString::npos)
+                       break;
+               start = end + 1;
+       }
+       if (IsFilterMode()) {
+               Molby_buildARGV(nargs, args);
+               for (start = 0; start < nargs; start++)
+                       free((void *)args[start]);
+               
+               retval = MyAppCallback_executeScriptFromFile(m_filterScriptName, &status);
+               if (status != 0) {
+                       if (retval == (RubyValue)6 && status == -1)
+                               MyAppCallback_errorMessageBox("Cannot open Ruby script: %s", m_filterScriptName);
+                       else
+                               Molby_showError(status);
+                       return false;
+               }
+       }
+       return success;
+}
+
 wxString
 MyApp::DefaultSettingsPath()
 {
@@ -1547,16 +1781,24 @@ MyAppCallback_executeScriptFromFile(const char *cpath, int *status)
        } else pp = p;
        
        /*  Read the content of the file  */
-       wxFile file;
-       if (file.Open((const wxChar *)path, wxFile::read)) {
-               wxFileOffset len = file.Length();
+       FILE *fp = fopen(cpath, "rb");
+       if (fp != NULL) {
+               off_t len;
+               fseek(fp, 0, SEEK_END);
+               len = ftell(fp);
+               fseek(fp, 0, SEEK_SET);
                script = (char *)malloc(len + 1);
-               if (script != NULL) {
-                       file.Read(script, len);
+               if (script!= NULL) {
+                       fread(script, 1, len, fp);
                        script[len] = 0;
                }
+               fclose(fp);
+       }
+
+       if (script == NULL) {
+               *status = -1;
+               return (RubyValue)6;  /*  Cannot open file  */
        }
-       file.Close();
        
        /*  Check the encoding specification, and if present convert it to default encoding  */
        {
@@ -1565,7 +1807,9 @@ MyAppCallback_executeScriptFromFile(const char *cpath, int *status)
                while (n < 2) {  /*  Check the first two lines  */
                        while (*lp && isspace(*lp))
                                lp++;
-                       if (*lp++ != '#')  /*  Check only the comment line  */
+                       if (*lp == 0 || *lp++ != '#')  /*  Check only the comment line  */
+                               break;
+                       if (*lp == 0)
                                break;
                        if (*lp == '!') { /*  Shebang line  */
                                while (*lp && *lp != '\n')
index 8a2bb0d..d0ba1ef 100755 (executable)
 #include "wx/hashmap.h"
 #include "wx/process.h"
 
-#if __WXMSW__
+#if defined(__WXMSW__)
 #include "wx/snglinst.h"
 #endif
 
 #include "MyDocManager.h"
 
 class MyDocManager;
+
+#if defined(__WXMSW__)
+class MyServer;
+class MyClient;
+#endif
+
 class wxMenuBar;
 class wxMenu;
 class wxProgressDialog;
@@ -171,9 +177,20 @@ class MyApp: public wxApp
 
        void OnActivate(wxActivateEvent &event);
 
+       void RequestOpenFilesByIPC(wxString& files);
+       void OnOpenFilesByIPC(wxCommandEvent& event);
+       
+       bool OnOpenFiles(wxString &files);
+
+       bool IsFilterMode() { return (m_filterScriptName != NULL); }
+       const char *FilterScriptBaseName() { return m_filterScriptBaseName; }
+
        MyListCtrl *GetGlobalParameterListCtrl();
-#if __WXMAC__
+       
+#if defined(__WXMAC__)
        virtual void MacNewFile();
+       virtual void MacOpenFile(const wxString &fileName);
+       virtual short MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply));
 #endif
        
 protected:
@@ -198,9 +215,18 @@ protected:
 
        int m_CountNamedFragments;
        char **m_NamedFragments;
-       
-#if __WXMSW__
+
+       wxString *m_pendingFilesToOpen;  /*  Files to be processed by OnOpenFilesByIPC()  */
+
+       char *m_filterScriptName;         /*  Ruby script when invoked as a filter mode  */
+       char *m_filterScriptBaseName;     /*  The file name (without directories) of the filter script  */
+
+#if defined(__WXMSW__)
+public:
        wxSingleInstanceChecker *m_checker;
+       wxString *m_ipcServiceName;
+       MyServer *m_server;
+       MyClient *m_client;
 #endif
        
 private:
index 2a48981..8ede83f 100644 (file)
  GNU General Public License for more details.
  */
 
+#include "wx/filedlg.h"
 #include "MyDocManager.h"
 #include "MyMBConv.h"
+#include "MyApp.h"
+#include "../MolLib/Ruby_bind/Molby_extern.h"
 
 BEGIN_EVENT_TABLE(MyDocManager, wxDocManager)
+EVT_MENU(wxID_OPEN, MyDocManager::OnFileOpen)
 EVT_MENU(wxID_SAVE, MyDocManager::OnFileSave)
 EVT_MENU(wxID_SAVEAS, MyDocManager::OnFileSaveAs)
 END_EVENT_TABLE()
@@ -45,6 +49,42 @@ MyDocManager::SetDocumentTypesEnabled(const char **extensions, bool flag)
        }
 }
 
+/*
+wxDocument*
+MyDocManager::CreateDocument(const wxString& path, long flags)
+{
+       return wxDocManager::CreateDocument(path, flags);
+}
+*/
+
+void
+MyDocManager::OnFileOpen(wxCommandEvent& event)
+{
+       if (wxGetApp().IsFilterMode()) {
+               /*  Select files to give to the script  */
+               int result = 0;
+               wxString tstr(wxT("Choose File(s) to be processed by "));
+               wxString files;
+               tstr.Append(wxString(wxGetApp().FilterScriptBaseName(), wxConvFile));
+               wxFileDialog *dialog = new wxFileDialog(NULL, tstr, wxT(""), wxT(""), wxT("All files (*.*)|*.*"), wxFD_OPEN | wxFD_MULTIPLE);
+               if (dialog->ShowModal() == wxID_OK) {
+                       int i, n;
+                       wxArrayString paths;
+                       dialog->GetPaths(paths);
+                       n = paths.GetCount();
+                       for (i = 0; i < n; i++) {
+                               files.Append(paths[i]);
+                               files.Append(wxT("\n"));
+                       }
+                       result = 1;
+               }
+               dialog->Destroy();
+               wxGetApp().OnOpenFiles(files);
+       } else {
+               wxDocManager::OnFileOpen(event);
+       }
+}
+
 void
 MyDocManager::OnFileSave(wxCommandEvent& event)
 {
index 12f446b..be51fe7 100644 (file)
@@ -22,6 +22,8 @@
 
 class MyDocManager: public wxDocManager {
 public:
+//     wxDocument* CreateDocument(const wxString& path, long flags);
+       void OnFileOpen(wxCommandEvent& event);
        void OnFileSave(wxCommandEvent& event);
        void OnFileSaveAs(wxCommandEvent& event);
        void SetDocumentTypesEnabled(const char **extensions, bool flag);
index 32ddd60..896dc00 100755 (executable)
@@ -1496,10 +1496,17 @@ MyDocumentFromMolecule(Molecule *mp)
 Molecule *
 MoleculeCallback_openNewMolecule(const char *fname)
 {
-  MainView *mview = MainViewCallback_newFromFile(fname);
-  if (mview != NULL)
-    return mview->mol;
-  else return NULL;
+       wxDocument *doc;
+       MyDocManager *manager = wxGetApp().DocManager();
+       if (fname == NULL || *fname == 0) {
+               doc = manager->CreateDocument(wxT(""), wxDOC_NEW);
+       } else {
+               wxString fnamestr(fname, wxConvFile);
+               doc = manager->CreateDocument(fnamestr, wxDOC_SILENT);
+       }
+       if (doc == NULL)
+               return NULL;
+       else return ((MyDocument *)doc)->GetMolecule();
 }
 
 void
index f4c114f..4d06cef 100755 (executable)
@@ -31,7 +31,8 @@ enum {
        MyDocumentEvent_scriptMenuModified,
        MyDocumentEvent_updateDisplay,
        MyDocumentEvent_insertFrameFromMD,
-       MyDocumentEvent_threadTerminated
+       MyDocumentEvent_threadTerminated,
+       MyDocumentEvent_openFilesByIPC
 };
 
 class MyDocument: public wxDocument
diff --git a/wxSources/MyIPCSupport.cpp b/wxSources/MyIPCSupport.cpp
new file mode 100755 (executable)
index 0000000..7e94aeb
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ *  MyIPCSupport.cpp
+ *  Molby
+ *
+ *  Created by Toshi Nagata on 12/10/10.
+ *  Copyright 2012 Toshi Nagata. All rights reserved.
+ *
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation version 2 of the License.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ */
+
+// For compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+#include "wx/wx.h"
+#endif
+
+
+#if defined(__WXMSW__)
+
+#include "MyIPCSupport.h"
+#include "MyApp.h"
+
+wxString *gIPCServiceName = NULL;
+
+bool
+MyClientConnection::OnDisconnect()
+{
+       wxGetApp().m_client->Disconnect();
+}
+
+MyClient::MyClient()
+{
+       m_clientConnection = NULL;
+}
+
+MyClient::~MyClient()
+{
+       Disconnect();
+}
+       
+void
+MyClient::Disconnect()
+{
+       if (m_clientConnection != NULL) {
+               m_clientConnection->Disconnect();
+               m_clientConnection = NULL;
+       }
+}
+
+wxConnectionBase *
+MyClient::OnMakeConnection()
+{
+       if (m_clientConnection == NULL)
+               m_clientConnection = new MyClientConnection;
+       return m_clientConnection;
+}
+
+bool
+MyServerConnection::OnDisconnect()
+{
+       wxGetApp().m_server->Disconnect();
+}
+
+bool
+MyServerConnection::OnExecute(const wxString& topic, wxChar* data, int size, wxIPCFormat format)
+{
+       if (topic == MOLBY_IPC_TOPIC) {
+               wxString files(data);
+               wxGetApp().RequestOpenFilesByIPC(files);
+               return true;
+       } else return false;
+}
+
+MyServer::MyServer()
+{
+       m_serverConnection = NULL;
+}
+
+MyServer::~MyServer()
+{
+       Disconnect();
+}
+
+void
+MyServer::Disconnect()
+{
+       if (m_serverConnection != NULL) {
+               m_serverConnection->Disconnect();
+               m_serverConnection = NULL;
+       }
+}
+
+wxConnectionBase *
+MyServer::OnAcceptConnection(const wxString &topic)
+{
+    if (topic == MOLBY_IPC_TOPIC) {
+               if (m_serverConnection == NULL)
+                       m_serverConnection = new MyServerConnection();
+        return m_serverConnection;
+    }
+    return NULL;
+}
+
+#endif  // defined(__WXMSW__)
diff --git a/wxSources/MyIPCSupport.h b/wxSources/MyIPCSupport.h
new file mode 100755 (executable)
index 0000000..8253dd5
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *  MyIPCSupport.h
+ *  Molby
+ *
+ *  Created by Toshi Nagata on 12/10/10.
+ *  Copyright 2010 Toshi Nagata. All rights reserved.
+ *
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation version 2 of the License.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ */
+
+// For compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
+
+#if defined(__WXMSW__)
+
+#include "wx/ipc.h"
+
+#define MOLBY_IPC_TOPIC wxT("MOLBY_IPC_TOPIC")
+
+extern wxString *gIPCServiceName;
+
+class MyClientConnection: public wxConnection
+{
+public:
+       virtual bool OnDisconnect();
+};
+
+class MyClient: public wxClient
+{
+public:
+       MyClient();
+       ~MyClient();
+       void Disconnect();
+    wxConnectionBase *OnMakeConnection();
+       MyClientConnection *m_clientConnection;
+};
+
+class MyServerConnection: public wxConnection
+{
+public:
+       virtual bool OnDisconnect();
+       virtual bool OnExecute(const wxString& topic, wxChar* data, int size, wxIPCFormat format);
+};
+
+class MyServer: public wxServer
+{
+public:
+       MyServer();
+       ~MyServer();
+       void Disconnect();
+    wxConnectionBase *OnAcceptConnection(const wxString& topic);
+       MyServerConnection *m_serverConnection;
+};
+
+#endif // defined(__WXMSW__)
index 3c57324..4b0c1e3 100755 (executable)
@@ -81,6 +81,7 @@
                E4D5ADA611808A2C00B1D8A4 /* cmdtool_stubs.c in Sources */ = {isa = PBXBuildFile; fileRef = E4D5ADA511808A2C00B1D8A4 /* cmdtool_stubs.c */; };
                E4E2D5C510A249820007644A /* GlobalParameterFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4E2D5C410A249820007644A /* GlobalParameterFrame.cpp */; };
                E4E470C910AE6F8600F72B68 /* GlobalParameterFilesFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4E470C810AE6F8600F72B68 /* GlobalParameterFilesFrame.cpp */; };
+               E4ED76E516256FC5006A1820 /* MyIPCSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4ED76E316256FC5006A1820 /* MyIPCSupport.cpp */; };
                E4FFA9050EE960650045EDF9 /* RubyDialogFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4FFA9040EE960650045EDF9 /* RubyDialogFrame.cpp */; };
                E4FFA95E0EEAADCA0045EDF9 /* ruby_dialog.c in Sources */ = {isa = PBXBuildFile; fileRef = E433CE770EC7099B00675985 /* ruby_dialog.c */; };
 /* End PBXBuildFile section */
                E4E2D5C410A249820007644A /* GlobalParameterFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GlobalParameterFrame.cpp; path = ../wxSources/GlobalParameterFrame.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 1; };
                E4E470C710AE6F8600F72B68 /* GlobalParameterFilesFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GlobalParameterFilesFrame.h; path = ../wxSources/GlobalParameterFilesFrame.h; sourceTree = SOURCE_ROOT; };
                E4E470C810AE6F8600F72B68 /* GlobalParameterFilesFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GlobalParameterFilesFrame.cpp; path = ../wxSources/GlobalParameterFilesFrame.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 1; };
+               E4ED76E316256FC5006A1820 /* MyIPCSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MyIPCSupport.cpp; path = ../wxSources/MyIPCSupport.cpp; sourceTree = SOURCE_ROOT; };
+               E4ED76E416256FC5006A1820 /* MyIPCSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MyIPCSupport.h; path = ../wxSources/MyIPCSupport.h; sourceTree = SOURCE_ROOT; };
                E4FFA9030EE960650045EDF9 /* RubyDialogFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RubyDialogFrame.h; path = ../wxSources/RubyDialogFrame.h; sourceTree = SOURCE_ROOT; };
                E4FFA9040EE960650045EDF9 /* RubyDialogFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RubyDialogFrame.cpp; path = ../wxSources/RubyDialogFrame.cpp; sourceTree = SOURCE_ROOT; };
 /* End PBXFileReference section */
                                E496A76E0EDD392F00499646 /* MyClipboardData.cpp */,
                                E44CEED5100E1E9C0040BD51 /* ProgressFrame.h */,
                                E44CEED4100E1E9C0040BD51 /* ProgressFrame.cpp */,
+                               E4ED76E316256FC5006A1820 /* MyIPCSupport.cpp */,
+                               E4ED76E416256FC5006A1820 /* MyIPCSupport.h */,
                                E472B7C41087F63200F931F3 /* MyVersion.c */,
                                E4A1802711897F8600B394E7 /* wxKillAddition.cpp */,
                                E43CCD8E0EB20BC800108D2D /* MolLib */,
                                E4A1802811897F8600B394E7 /* wxKillAddition.cpp in Sources */,
                                9E12580F119EC42E00E95DC3 /* docview.cpp in Sources */,
                                E445145415F1DA5B0050171E /* MainViewCommon.c in Sources */,
+                               E4ED76E516256FC5006A1820 /* MyIPCSupport.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };