OSDN Git Service

Mac target is now buildable (not working yet)
authorToshi Nagata <alchemist.2005@nifty.com>
Mon, 12 Sep 2022 14:13:14 +0000 (23:13 +0900)
committerToshi Nagata <alchemist.2005@nifty.com>
Mon, 12 Sep 2022 14:13:14 +0000 (23:13 +0900)
MolLib/Types.h
build-xcode/Molby.xcodeproj/project.pbxproj
wxSources/MoleculeView.cpp
wxSources/MyApp.cpp
wxSources/MyApp.h
wxSources/MyListCtrl.cpp
wxSources/MyListCtrl.h
wxSources/MyProgressIndicator.cpp
wxSources/RubyDialogFrame.cpp

index e825cff..7f4a395 100755 (executable)
@@ -27,8 +27,8 @@
 
 #if defined(__WXMAC__) || defined(__CMDMAC__)
 /*  On Mac OS X, CLAPACK is in Accelerate.framework  */
-#include <vecLib/cblas.h>
-#include <vecLib/clapack.h>
+#include <cblas.h>
+#include <clapack.h>
 //#include <Accelerate/Accelerate.h>
 #else
 #include <f2c.h>
index b103eaa..db26010 100644 (file)
@@ -24,6 +24,7 @@
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
+               E403568428CF6A3D008E2C46 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E403568328CF6A3D008E2C46 /* QuartzCore.framework */; };
                E4059F9B28C46A6E0052B36B /* molby_icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = E4FC77D4183E4FF20064FB2E /* molby_icon.icns */; };
                E4059F9C28C46A6E0052B36B /* Scripts in Resources */ = {isa = PBXBuildFile; fileRef = E4FC77D6183E4FFE0064FB2E /* Scripts */; };
                E4059F9D28C46A6E0052B36B /* amber11 in Resources */ = {isa = PBXBuildFile; fileRef = E4FC77D8183E503E0064FB2E /* amber11 */; };
@@ -92,7 +93,6 @@
                E4059FDE28C46A6E0052B36B /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4FC7B58183E53710064FB2E /* WebKit.framework */; };
                E4059FDF28C46A6E0052B36B /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4FC7CAC183F953E0064FB2E /* AudioToolbox.framework */; };
                E4059FE728C46B330052B36B /* Molby_MacLegacy-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = E4059FE628C46B320052B36B /* Molby_MacLegacy-Info.plist */; };
-               E41251B628C4B1AB00E12983 /* listctrl_wx32.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E41251B528C4B1AB00E12983 /* listctrl_wx32.cpp */; };
                E41251B828CD92A100E12983 /* MyListCtrl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E41251B728CD92A100E12983 /* MyListCtrl.cpp */; };
                E41251B928CD92A100E12983 /* MyListCtrl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E41251B728CD92A100E12983 /* MyListCtrl.cpp */; };
                E41A7F962307D61200C65830 /* bitmaps in Resources */ = {isa = PBXBuildFile; fileRef = E41A7F952307D61200C65830 /* bitmaps */; };
                E420BE22188574F600A2B983 /* ProgressFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E420BE1D188574F600A2B983 /* ProgressFrame.cpp */; };
                E420BE23188574F600A2B983 /* RubyDialogFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E420BE1F188574F600A2B983 /* RubyDialogFrame.cpp */; };
                E420BE24188574F600A2B983 /* wxKillAddition.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E420BE21188574F600A2B983 /* wxKillAddition.cpp */; };
-               E45B94621A170B9A008E95EB /* docview.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E45B94611A170B9A008E95EB /* docview.cpp */; };
                E4653CB118A0CC7D0022377B /* textctrl_addition.mm in Sources */ = {isa = PBXBuildFile; fileRef = E4653CB018A0CC7D0022377B /* textctrl_addition.mm */; };
                E4ACACE718C6D32300F08B67 /* ortep3 in Resources */ = {isa = PBXBuildFile; fileRef = E4ACACE418C6D32300F08B67 /* ortep3 */; };
                E4D379A219C87C2200636D28 /* modalwindow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4D379A119C87C2200636D28 /* modalwindow.cpp */; };
 
 /* Begin PBXFileReference section */
                8D1107320486CEB800E47090 /* Molby.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Molby.app; sourceTree = BUILT_PRODUCTS_DIR; };
+               E403568328CF6A3D008E2C46 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = /System/Library/Frameworks/QuartzCore.framework; sourceTree = "<absolute>"; };
                E4059FE428C46A6E0052B36B /* Molby_MacLegacy.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Molby_MacLegacy.app; sourceTree = BUILT_PRODUCTS_DIR; };
                E4059FE628C46B320052B36B /* Molby_MacLegacy-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Molby_MacLegacy-Info.plist"; sourceTree = "<group>"; };
-               E41251B528C4B1AB00E12983 /* listctrl_wx32.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = listctrl_wx32.cpp; sourceTree = "<group>"; };
                E41251B728CD92A100E12983 /* MyListCtrl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MyListCtrl.cpp; sourceTree = "<group>"; };
                E41251BA28CD92AD00E12983 /* MyListCtrl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MyListCtrl.h; sourceTree = "<group>"; };
                E4196C65190B2FA500183E62 /* menu.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = menu.mm; sourceTree = "<group>"; };
                        files = (
                                E4FC7811183E50DC0064FB2E /* Accelerate.framework in Frameworks */,
                                E4FC7838183E50F00064FB2E /* AGL.framework in Frameworks */,
+                               E403568428CF6A3D008E2C46 /* QuartzCore.framework in Frameworks */,
                                E4FC784C183E51180064FB2E /* Carbon.framework in Frameworks */,
                                E4FC784D183E51180064FB2E /* Cocoa.framework in Frameworks */,
                                E4FC784E183E51180064FB2E /* GLUT.framework in Frameworks */,
                E4FC780D183E50AF0064FB2E /* Linked Frameworks */ = {
                        isa = PBXGroup;
                        children = (
+                               E403568328CF6A3D008E2C46 /* QuartzCore.framework */,
                                E4FC7CAC183F953E0064FB2E /* AudioToolbox.framework */,
                                E4FC7810183E50DC0064FB2E /* Accelerate.framework */,
                                E4FC7837183E50F00064FB2E /* AGL.framework */,
                                E420BDEE1885746700A2B983 /* GlobalParameterFrame.h */,
                                E420BDF31885749000A2B983 /* listctrl_private.h */,
                                E420BDF41885749000A2B983 /* listctrl.cpp */,
-                               E41251B528C4B1AB00E12983 /* listctrl_wx32.cpp */,
                                E4653CB018A0CC7D0022377B /* textctrl_addition.mm */,
                                E4196C65190B2FA500183E62 /* menu.mm */,
                                E420BDF51885749000A2B983 /* MoleculeView.cpp */,
                                E4FC77B7183E4F3F0064FB2E /* Object.c in Sources */,
                                E4FC77B8183E4F3F0064FB2E /* Parameter.c in Sources */,
                                E4FC77BA183E4F3F0064FB2E /* ruby_bind.c in Sources */,
-                               E41251B628C4B1AB00E12983 /* listctrl_wx32.cpp in Sources */,
                                E4FC77BB183E4F3F0064FB2E /* ruby_dialog.c in Sources */,
                                E4FC77BC183E4F3F0064FB2E /* ruby_md.c in Sources */,
                                E4FC77BD183E4F3F0064FB2E /* ruby_types.c in Sources */,
                                E4D379A219C87C2200636D28 /* modalwindow.cpp in Sources */,
                                E4D37E0E19CC831500636D28 /* modalwindow_osx.mm in Sources */,
                                E4D3806619CEC7B600636D28 /* MyTextCtrl.cpp in Sources */,
-                               E45B94621A170B9A008E95EB /* docview.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 6524180..a621a45 100755 (executable)
@@ -234,7 +234,7 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
                                wxBoxSizer *sizer31 = new wxBoxSizer(wxVERTICAL);
                                {       // "Rotate bond" button and mySlider
                                        #include "../bitmaps/rotate_bond.xpm"
-                                       wxBitmap bmp1(rotate_bond_xpm, wxBITMAP_TYPE_XPM);
+                                       wxBitmap bmp1(rotate_bond_xpm);
                                        wxBitmapButton *button1 = new wxBitmapButton(panel1, -1, bmp1, wxDefaultPosition, wxSize(21, 21), wxTOGGLEBUTTON_STYLE);
                                        sizer31->Add(button1, 0, 0, 0);
                                        button1->Disable();
@@ -257,7 +257,7 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
                                        wxBoxSizer *sizer321 = new wxBoxSizer(wxHORIZONTAL);
                                        {
                                                #include "../bitmaps/rotate_y.xpm"
-                                               wxBitmap bmp2(rotate_y_xpm, wxBITMAP_TYPE_XPM);
+                                               wxBitmap bmp2(rotate_y_xpm);
                                                wxBitmapButton *button2 = new wxBitmapButton(panel1, -1, bmp2, wxDefaultPosition, wxSize(21, 21), wxTOGGLEBUTTON_STYLE);
                                                sizer321->Add(button2, 0, 0, 0);
                                                button2->Disable();
@@ -273,7 +273,7 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
                                wxBoxSizer *sizer33 = new wxBoxSizer(wxVERTICAL);
                                {       // "Rotate bond" button and mySlider
                                        #include "../bitmaps/rotate_x.xpm"
-                                       wxBitmap bmp3(rotate_x_xpm, wxBITMAP_TYPE_XPM);
+                                       wxBitmap bmp3(rotate_x_xpm);
                                        wxBitmapButton *button3 = new wxBitmapButton(panel1, -1, bmp3, wxDefaultPosition, wxSize(21, 21), wxTOGGLEBUTTON_STYLE);
                                        button3->Disable();
                                        sizer33->Add(button3, 0, 0, 0);
@@ -298,13 +298,13 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
                                sizer4->Add(frameSlider, 1, wxALL | wxEXPAND, 1);
                        
                                #include "../bitmaps/jump_to_start.xpm"
-                               wxBitmap bmp41(jump_to_start_xpm, wxBITMAP_TYPE_XPM);
+                               wxBitmap bmp41(jump_to_start_xpm);
                                wxBitmapButton *button41 = new wxBitmapButton(frameControlPanel, myID_JumpToStartButton, bmp41, wxDefaultPosition, wxSize(16, height), wxTOGGLEBUTTON_STYLE);
                                sizer4->Add(button41, 0, wxEXPAND);
                                ConnectMouseDownEvents(button41, MoleculeView::OnFrameButtonAction, this);
 
                                #include "../bitmaps/play_backward.xpm"
-                               wxBitmap bmp42(play_backward_xpm, wxBITMAP_TYPE_XPM);
+                               wxBitmap bmp42(play_backward_xpm);
                                wxBitmapButton *button42 = new wxBitmapButton(frameControlPanel, myID_PlayBackwardButton, bmp42, wxDefaultPosition, wxSize(16, height), wxTOGGLEBUTTON_STYLE);
                                sizer4->Add(button42, 0, wxEXPAND);
                                ConnectMouseDownEvents(button42, MoleculeView::OnFrameButtonAction, this);
@@ -320,13 +320,13 @@ MoleculeView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
                                }
                        
                                #include "../bitmaps/play_forward.xpm"
-                               wxBitmap bmp43(play_forward_xpm, wxBITMAP_TYPE_XPM);
+                               wxBitmap bmp43(play_forward_xpm);
                                wxBitmapButton *button43 = new wxBitmapButton(frameControlPanel, myID_PlayForwardButton, bmp43, wxDefaultPosition, wxSize(16, height), wxTOGGLEBUTTON_STYLE);
                                sizer4->Add(button43, 0, wxEXPAND);
                                ConnectMouseDownEvents(button43, MoleculeView::OnFrameButtonAction, this);
 
                                #include "../bitmaps/jump_to_end.xpm"
-                               wxBitmap bmp44(jump_to_end_xpm, wxBITMAP_TYPE_XPM);
+                               wxBitmap bmp44(jump_to_end_xpm);
                                wxBitmapButton *button44 = new wxBitmapButton(frameControlPanel, myID_JumpToEndButton, bmp44, wxDefaultPosition, wxSize(16, height), wxTOGGLEBUTTON_STYLE);
                                sizer4->Add(button44, 0, wxEXPAND);
                                ConnectMouseDownEvents(button44, MoleculeView::OnFrameButtonAction, this);
index 90f3962..4d49593 100755 (executable)
@@ -113,24 +113,26 @@ END_EVENT_TABLE()
 //  Windows: the directory in which the application executable is located.
 //  UNIX: ?
 wxString
-MyApp::FindResourcePath()
+MyApp::InitResourcePath(int& argc, wxChar **argv)
 {
 #if defined(__WXMAC__)
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef ref = CFBundleCopyResourcesDirectoryURL(mainBundle);
        if (ref != NULL) {
-               UInt8 buffer[256];
+               UInt8 buffer[4096];
                if (CFURLGetFileSystemRepresentation(ref, true, buffer, sizeof buffer)) {
                        wxString dirname((const char *)buffer, WX_DEFAULT_CONV);
                        CFRelease(ref);
+            m_resourcePath = dirname;
                        return dirname;
                }
                CFRelease(ref);
        }
+    m_resourcePath = wxEmptyString;
        return wxEmptyString;
 #elif defined(__WXMSW__)
     wxString str;
-       wxString argv0 = wxTheApp->argv[0];
+       wxString argv0 = argv[0];
        //  Fix dosish path (when invoked from MSYS console, the path may be unix-like)
        //  Note: absolute paths like /c/Molby/... (== c:\Molby\...) is not supported
        {
@@ -141,28 +143,40 @@ MyApp::FindResourcePath()
        }
        //  Is it an absolute path?
     if (wxIsAbsolutePath(argv0)) {
-        return wxPathOnly(argv0);
+        m_resourcePath = wxPathOnly(argv0);
+        return m_resourcePath;
     } else {
         //  Is it a relative path?
         wxString currentDir = wxGetCwd();
         if (currentDir.Last() != wxFILE_SEP_PATH)
             currentDir += wxFILE_SEP_PATH;             
         str = currentDir + argv0;
-        if (wxFileExists(str))
-            return wxPathOnly(str);
+        if (wxFileExists(str)) {
+            m_resourcePath = wxPathOnly(str);
+            return m_resourcePath;
+        }
     }
        //  Search PATH
     wxPathList pathList;
     pathList.AddEnvList(wxT("PATH"));
     str = pathList.FindAbsoluteValidPath(argv0);
-    if (!str.IsEmpty())
-        return wxPathOnly(str);
-    return wxEmptyString;
+    if (!str.IsEmpty()) {
+        m_resourcePath = wxPathOnly(str);
+        return m_resourcePath;
+    }
+    m_resourcePath = wxEmptyString;
+    return m_resourcePath;
 #else
 #error "FindResourcePath is not defined for UNIXes."
 #endif
 }
 
+wxString
+MyApp::FindResourcePath()
+{
+    return wxGetApp().m_resourcePath;
+}
+
 MyApp::MyApp(void)
 {
     m_docManager = NULL;
@@ -211,9 +225,12 @@ bool MyApp::Initialize(int& argc, wxChar **argv)
             gSuppressConsole = 0;
 
         //  We need these parameters in FindResourcePath(), so we assign them here
-        this->argc = argc;
-        this->argv = argv;
+        //this->argc = argc;
+        //this->argv = argv;
 
+        //  Initialize the internal m_resourcePath member
+        InitResourcePath(argc, argv);
+        
         static const char fname[] = "startup.rb";
         wxString dirname = FindResourcePath();
         
@@ -379,6 +396,7 @@ bool MyApp::OnInit(void)
        {
                extern int gRevisionNumber;
                static const char fname[] = "startup.rb";
+        InitResourcePath(argc, argv);
                wxString dirname = FindResourcePath();
        
                dirname += wxFILE_SEP_PATH;
index 32cf4b9..4548a8f 100755 (executable)
@@ -187,7 +187,9 @@ class MyApp: public wxApp
 
        wxMenuBar *CreateMenuBar(int kind, wxMenu **out_file_history_menu = NULL, wxMenu **out_edit_menu = NULL);
 
-       static wxString FindResourcePath();
+    wxString InitResourcePath(int& argc, wxChar **argv);
+
+    static wxString FindResourcePath();
        static wxString DefaultSettingsPath();
 
        void LoadDefaultSettings();
@@ -273,6 +275,8 @@ protected:
 
        wxTopLevelWindow *m_frameToBeDestroyed;   /*  Used in CheckIfAllWindowsAreGone()  */
        
+    wxString m_resourcePath;
+
 #if defined(__WXMSW__)
 public:
        wxSingleInstanceChecker *m_checker;
index cee9951..2a8141a 100644 (file)
@@ -112,24 +112,60 @@ MyListCtrl::SetDataSource(MyListCtrlDataSource *source)
        RefreshTable();
 }
 
+int
+MyListCtrl::GetColumnCount()
+{
+    return colNames.Count();
+}
+
+bool
+MyListCtrl::DeleteColumn(int col)
+{
+    if (col < 0 || col >= GetColumnCount())
+        return false;
+    colNames.RemoveAt(col);
+    colWidths.erase(colWidths.begin() + col);
+    colFormats.erase(colFormats.begin() + col);
+    SetNeedsReload();
+    return true;
+}
+
+bool
+MyListCtrl::InsertColumn(int col, const wxString &heading, int format, int width)
+{
+    if (col < 0 || col > GetColumnCount())
+        return false;
+    colNames.Insert(heading, col);
+    colWidths.insert(colWidths.begin() + col, width);
+    colFormats.insert(colFormats.begin() + col, format);
+    SetNeedsReload();
+    return true;
+}
+
 void
-MyListCtrl::RefreshTable()
+MyListCtrl::SetColumnWidth(int col, int width)
+{
+    if (col < 0 || col > GetColumnCount())
+        return;
+    colWidths[col] = width;
+    SetNeedsReload();
+}
+
+void
+MyListCtrl::RefreshTable(bool refreshWindow)
 {
     if (dataSource == NULL) {
         nrows = ncols = 0;
     } else {
         int i;
         wxSize sz = header->GetSize();
-        nrows = dataSource->GetNumberOfRows(this);
-        ncols = dataSource->GetNumberOfColumns(this);
-        colWidths.resize(ncols, 10);
+        nrows = dataSource->GetItemCount(this);
+        ncols = GetColumnCount();
         pageWidth = 0;
         for (i = 0; i < ncols; i++) {
-            colWidths[i] = dataSource->GetColumnWidth(this, i);
             pageWidth += colWidths[i];
         }
         rowHeight = dataSource->GetRowHeight(this);
-        headerHeight = dataSource->GetHeaderHeight(this);
         //  "+4" is for drawing marker during cell dragging
         pageHeight = rowHeight * nrows + 4;
         //  Set the subwindow infos
@@ -140,7 +176,17 @@ MyListCtrl::RefreshTable()
         Fit();
         Layout();
     }
-    Refresh();
+    needsReload = false;
+    if (refreshWindow)
+        Refresh();
+}
+
+void
+MyListCtrl::SetNeedsReload(bool flag)
+{
+    needsReload = flag;
+    if (needsReload)
+        Refresh();
 }
 
 static wxBrush lightBlueBrush(wxColour(128, 128, 255));
@@ -151,6 +197,9 @@ MyListCtrl::OnPaint(wxPaintEvent &event)
     if (dataSource == NULL)
         return;
 
+    if (needsReload)
+        RefreshTable(false);
+
     wxPaintDC dc(scroll);
     scroll->DoPrepareDC(dc);
     int ox, oy;
@@ -183,9 +232,14 @@ MyListCtrl::OnPaint(wxPaintEvent &event)
                 }
                 if (y > sz.y + oy)
                     break;
-                str = dataSource->GetCellText(this, j, i);
-                if (dataSource->GetCellAttr(this, j, i, attr)) {
-                    // TODO: attribute change
+                str = dataSource->GetItemText(this, j, i);
+                float fg[4], bg[4];
+                int n = dataSource->SetItemColor(this, j, i, fg, bg);
+                if (n & 1) {
+                    //  TODO: Set foreground color
+                }
+                if (n & 2) {
+                    //  TODO: Set background color
                 }
                 if (IsRowSelected(j)) {
                     if (showDragTarget) {
@@ -234,12 +288,10 @@ MyListCtrl::OnPaintHeader(wxPaintEvent &event)
         for (i = 0; i < ncols; i++) {
             x1 = x + colWidths[i];
             if (x1 > 0) {
-                wxString str = dataSource->GetCellText(this, -1, i);
-                if (dataSource->GetCellAttr(this, -1, i, attr)) {
-                    //  TODO: do attribute change
-                }
+                wxString str = colNames[i];
                 dc.DrawText(str, x, 0);
             }
+            x = x1;
         }
     }
 }
@@ -256,6 +308,26 @@ MyListCtrl::PrepareSelectionChangeNotification()
     selectionChangeNotificationRequired = true;
 }
 
+int
+MyListCtrl::GetItemState(int item, int stateMask)
+{
+    if (stateMask & wxLIST_STATE_SELECTED)
+        return IsRowSelected(item) ? wxLIST_STATE_SELECTED : 0;
+    else return 0;
+}
+
+bool
+MyListCtrl::SetItemState(int item, int state, int stateMask)
+{
+    if (stateMask & wxLIST_STATE_SELECTED) {
+        if (state & wxLIST_STATE_SELECTED)
+            SelectRow(item);
+        else
+            UnselectRow(item);
+    }
+    return true;
+}
+
 bool
 MyListCtrl::IsRowSelected(int row)
 {
@@ -407,7 +479,7 @@ MyListCtrl::OnMotion(wxMouseEvent &event)
         if (mouseMode > 0 && !scroll->HasCapture()) {
             //  Start dragging
             scroll->CaptureMouse();
-            if (mouseMode != 3 && dataSource->IsDragEnabled(this, mouseRow)) {
+            if (mouseMode != 3 && dataSource->IsDragAndDropEnabled(this, mouseRow)) {
                 draggingRows = true;
             }
         }
@@ -435,7 +507,7 @@ MyListCtrl::OnLeftDClick(wxMouseEvent &event)
         }
         cx += colWidths[i];
     }
-    if (!dataSource->IsEditable(this, col, row))
+    if (!dataSource->IsItemEditable(this, row, col))
         return;
     StartEditText(col, row);
 }
@@ -443,9 +515,9 @@ MyListCtrl::OnLeftDClick(wxMouseEvent &event)
 void
 MyListCtrl::OnLeftUp(wxMouseEvent &event)
 {
-    int x, y, ux, uy, row, i;
+    int x, y, ux, uy, row;
     bool dragged = false;
-    bool selectionChanged = selectionChangeNotifiationRequired;
+    bool selectionChanged = selectionChangeNotificationRequired;
     x = event.GetX();
     y = event.GetY();
     scroll->CalcUnscrolledPosition(x, y, &ux, &uy);
@@ -485,7 +557,6 @@ MyListCtrl::OnScrollWin(wxScrollWinEvent &event)
     wxPoint cp = scroll->ScreenToClient(wxGetMousePosition());
     wxSize sz = scroll->GetClientSize();
     wxEventType etype = event.GetEventType();
-    wxEventType etype_org = etype;
     int vx, vy;
     int step = rowHeight;
     scroll->CalcUnscrolledPosition(0, 0, &vx, &vy);
@@ -570,9 +641,67 @@ MyListCtrl::FindItemAtPosition(const wxPoint &pos, int *row, int *col)
     return (r >= 0 && i >= 0);
 }
 
+//  The return rect is the client coordinate in MyListCtrl (not scroll)
+bool
+MyListCtrl::GetItemRectForRowAndColumn(wxRect &rect, int row, int col)
+{
+    int i, tx, ty, cx, cy;
+    if (col < 0 || col >= ncols || row < 0 || row >= nrows)
+        return false;
+    cy = rowHeight * row;
+    cx = 0;
+    for (i = 0; i < col; i++) {
+        cx += colWidths[i];
+    }
+    scroll->CalcScrolledPosition(cx, cy, &tx, &ty);
+    rect.x = tx;
+    rect.y = ty + headerHeight;
+    rect.width = colWidths[col];
+    rect.height = rowHeight;
+    return true;
+}
+
+
+bool
+MyListCtrl::EnsureVisible(int row, int col)
+{
+    wxRect r;
+    if (!GetItemRectForRowAndColumn(r, row, (col == -1 ? 0 : col)))
+        return false;
+    r.y -= headerHeight;  //  Convert to client coord in scroll
+    wxSize sz = scroll->GetClientSize();
+    int scx = -1, scy = -1;
+    int ux, uy;
+    scroll->CalcUnscrolledPosition(r.x, r.y, &ux, &uy);
+    if (col >= 0) {
+        if (r.x < 0) {
+            scx = floor(ux / rowHeight);
+        } else if (r.x + r.width > sz.x) {
+            scx = ceil((ux + r.width - sz.x) / rowHeight);
+            if (scx < 0)
+                scx = 0;
+        }
+    }  // If col is negative, then do not scroll horizontally
+    if (r.y < 0) {
+        scy = floor(uy / rowHeight);
+    } else if (r.y + r.height > sz.y) {
+        scy = ceil((uy + r.height - sz.y) / rowHeight);
+        if (scy < 0)
+            scy = 0;
+    }
+    if (scx >= 0 || scy >= 0) {
+        scroll->Scroll(scx, scy);
+        return true;
+    } else return false;
+}
+
 void
 MyListCtrl::StartEditText(int row, int col)
 {
+    wxRect r;
+    if (!GetItemRectForRowAndColumn(r, row, col))
+        return;
+    r.y -= headerHeight;  //  Convert to client coord in scroll
     int i, tx, ty;
     int cy = rowHeight * row;
     int cx = 0;
@@ -581,31 +710,14 @@ MyListCtrl::StartEditText(int row, int col)
     }
     scroll->CalcScrolledPosition(cx, cy, &tx, &ty);
     if (editText == NULL) {
-        editText = new wxTextCtrl(scroll, -1, "", wxPoint(tx - 2, ty - 2), wxSize(colWidths[col] + 4, rowHeight + 4), wxTE_PROCESS_ENTER);
+        editText = new wxTextCtrl(scroll, -1, "", wxPoint(r.x - 2, r.y - 2), wxSize(r.width + 4, r.height + 4), wxTE_PROCESS_ENTER);
         editText->Bind(wxEVT_CHAR, &MyListCtrl::OnCharInText, this);
     } else {
         FinalizeEdit();
-        editText->SetPosition(wxPoint(tx - 2, ty - 2));
-        editText->SetSize(wxSize(colWidths[col] + 4, rowHeight + 4));
-    }
-    wxSize sz = scroll->GetClientSize();
-    int scx = -1, scy = -1;
-    if (tx < 0) {
-        scx = floor(cx / rowHeight);
-    } else if (tx + colWidths[col] > sz.x) {
-        scx = ceil((colWidths[col] - sz.x) / rowHeight);
-        if (scx < 0)
-            scx = 0;
-    }
-    if (ty < 0) {
-        scy = floor(cy / rowHeight);
-    } else if (ty + rowHeight > sz.y) {
-        scy = ceil((cy + rowHeight - sz.y) / rowHeight);
-        if (scy < 0)
-            scy = 0;
+        editText->SetPosition(wxPoint(r.x - 2, r.y - 2));
+        editText->SetSize(wxSize(r.width + 4, r.height + 4));
     }
-    if (scx >= 0 || scy >= 0)
-        scroll->Scroll(scx, scy);
+    EnsureVisible(row, col);
     editText->Show();
     editText->SetFocus();
     editText->SelectAll();
@@ -618,6 +730,16 @@ MyListCtrl::StartEditText(int row, int col)
 }
 
 void
+MyListCtrl::FinalizeEdit()
+{
+    if (editText != NULL) {
+        wxString sval = editText->GetValue();
+        if (dataSource)
+            dataSource->SetItemText(this, editRow, editColumn, sval);
+    }
+}
+
+void
 MyListCtrl::EndEditText(bool setValueFlag)
 {
     if (!editText)
@@ -628,6 +750,7 @@ MyListCtrl::EndEditText(bool setValueFlag)
     editText->Destroy();
     editText = NULL;
 }
+
 void
 MyListCtrl::EndEditTextAndRestart(bool setValueFlag, int newRow, int newCol)
 {
@@ -659,7 +782,7 @@ MyListCtrl::OnCharInText(wxKeyEvent &event)
                     else
                         row++;
                 }
-            } while (row >= 0 && !dataSource->IsEditable(this, row, col));
+            } while (row >= 0 && !dataSource->IsItemEditable(this, row, col));
             if (row >= 0) {
                 StartEditText(row, col);
             } else {
@@ -687,7 +810,7 @@ MyListCtrl::OnCharInText(wxKeyEvent &event)
                         row = -1;
                 }
             }
-        } while (row >= 0 && !dataSource->IsEditable(this, row, col));
+        } while (row >= 0 && !dataSource->IsItemEditable(this, row, col));
         if (row >= 0)
             StartEditText(row, col);
         else
index e7bebc7..de7ae09 100644 (file)
@@ -19,6 +19,7 @@
 #define __MyListCtrl_h__
 
 #include "wx/scrolwin.h"
+#include "wx/listctrl.h" //  some constants are included for compatibility
 
 #include "wx/string.h"
 #include "wx/textctrl.h"
@@ -42,8 +43,26 @@ enum MyListColumnFormat {
 /*  Data source protocol  */
 class MyListCtrlDataSource {
 public:
-    virtual int GetNumberOfRows(MyListCtrl *ctrl) { return 0; }
-    virtual int GetNumberOfColumns(MyListCtrl *ctrl) { return 0; }
+    virtual int GetItemCount(MyListCtrl *ctrl) { return 0; }
+    virtual wxString GetItemText(MyListCtrl *ctrl, long row, long column) const { return _T(""); }
+    virtual int SetItemText(MyListCtrl *ctrl, long row, long column, const wxString &value) { return 0; }
+    virtual void DragSelectionToRow(MyListCtrl *ctrl, long row) {}
+    virtual bool IsItemEditable(MyListCtrl *ctrl, long row, long column) { return false; }
+    virtual bool IsDragAndDropEnabled(MyListCtrl *ctrl, long row = -1) { return false; }
+    virtual void OnSelectionChanged(MyListCtrl *ctrl) {}
+    
+    //  If a popup menu is attached to the cell, then returns a positive integer, and *menu_titles should
+    //  contain a malloc()'ed array of char* pointers (that are also malloc()'ed or strdup()'ed)
+    virtual int HasPopUpMenu(MyListCtrl *ctrl, long row, long column, char ***menu_titles) { return 0; }
+    virtual void OnPopUpMenuSelected(MyListCtrl *ctrl, long row, long column, int selected_index) {}
+    
+    //  Return 1 if foreground color should be modified, 2 if background color should be modified, 3 if both
+    virtual int SetItemColor(MyListCtrl *ctrl, long row, long col, float *fg, float *bg) { return 0; }
+
+    virtual int GetRowHeight(MyListCtrl *ctrl, long row = -1) { return 12; }
+
+/*    virtual int GetNumberOfRows(MyListCtrl *ctrl) { return 0; }
+//    virtual int GetNumberOfColumns(MyListCtrl *ctrl) { return 0; }
     virtual int GetColumnWidth(MyListCtrl *ctrl, int index) { return 0; }
     virtual int GetRowHeight(MyListCtrl *ctrl) { return 0; }
     virtual int GetHeaderHeight(MyListCtrl *ctrl) { return 0; }
@@ -59,17 +78,8 @@ public:
        //  contain a malloc()'ed array of char* pointers (that are also malloc()'ed or strdup()'ed)
        virtual int HasPopUpMenu(MyListCtrl *ctrl, int row, int col, char ***menu_titles) { return 0; }
        virtual void OnPopUpMenuSelected(MyListCtrl *ctrl, int row, int col, int selected_index) {}
-
-    //virtual int GetItemCount(MyListCtrl *ctrl) { return 0; }
-    //virtual wxString GetItemText(MyListCtrl *ctrl, long row, long column) const { return _T(""); }
-    //virtual int SetItemText(MyListCtrl *ctrl, long row, long column, const wxString &value) { return 0; }
-    //virtual void DragSelectionToRow(MyListCtrl *ctrl, long row) {}
-    //virtual bool IsItemEditable(MyListCtrl *ctrl, long row, long column) { return false; }
-    //virtual bool IsDragAndDropEnabled(MyListCtrl *ctrl) { return false; }
-    //virtual void OnSelectionChanged(MyListCtrl *ctrl) {}
+*/
     
-       //  Return 1 if foreground color should be modified, 2 if background color should be modified, 3 if both
-       //virtual int SetItemColor(MyListCtrl *ctrl, long row, long col, float *fg, float *bg) { return 0; }
 };
 
 class MyListCtrl: public wxWindow {
@@ -105,9 +115,16 @@ public:
 
        void SetDataSource(MyListCtrlDataSource *source);
 
-       void RefreshTable();
+    void SetNeedsReload(bool flag = true);
+       void RefreshTable(bool refreshWindow = true);
 
     void PrepareSelectionChangeNotification();
+    
+    // wxListCtrl compatibility: only wxLIST_STATE_SELECTED is implemented
+    int GetItemCount() { return (dataSource ? dataSource->GetItemCount(this) : 0); }
+    int GetItemState(int item, int stateMask);
+    bool SetItemState(int item, int state, int stateMask);
+
     bool IsRowSelected(int row);
     bool SelectRow(int row);
     bool UnselectRow(int row);
@@ -124,6 +141,9 @@ public:
 //     bool GetItemRectForRowAndColumn(wxRect &rect, int row, int column);
        bool FindItemAtPosition(const wxPoint &pos, int *col, int *row);
        
+    bool GetItemRectForRowAndColumn(wxRect &rect, int row, int column);
+    bool EnsureVisible(int row, int col = -1);
+
 //     void SetItemTextForColumn(long item, long column, const wxString &text);
 
        void StartEditText(int col, int row);
@@ -137,10 +157,13 @@ public:
        
 //     void OnPaintCallback(wxDC *dc);
 
-//     bool DeleteColumn(int col);
-//     bool InsertColumn(int col, const wxString &heading, int width = -1, int format = MyLIST_FORMAT_LEFT);
-//  int GetNumberOfColumns();
-    
+    int GetColumnCount();
+       bool DeleteColumn(int col);
+       bool InsertColumn(int col, const wxString &heading, int format = MyLIST_FORMAT_LEFT, int width = -1);
+    void SetHeaderHeight(int headerHeight);
+    int GetHeaderHeight() { return headerHeight; }
+    void SetColumnWidth(int col, int width);
+
     void OnPaintHeader(wxPaintEvent &event);
     void OnPaint(wxPaintEvent &event);
     void OnLeftDown(wxMouseEvent &event);
@@ -169,6 +192,7 @@ public:
        
        bool selectionChangeNotificationRequired;
        bool selectionChangeNotificationEnabled;
+    bool needsReload;
        int lastPopUpColumn, lastPopUpRow;
 
 private:
index 725168f..ef57ec6 100755 (executable)
@@ -54,21 +54,21 @@ MyProgressIndicator::MyProgressIndicator(wxWindow* parent, wxWindowID id, const
 #include "../bitmaps/pi09.xpm"
 #include "../bitmaps/pi10.xpm"
 #include "../bitmaps/pi11.xpm"
-               sStopMiniIcons[0] = new wxBitmap(stop_mini_grey, wxBITMAP_TYPE_XPM);
-               sStopMiniIcons[1] = new wxBitmap(stop_mini, wxBITMAP_TYPE_XPM);
-               sStopMiniIcons[2] = new wxBitmap(stop_mini_dark, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[0] = new wxBitmap(pi00, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[1] = new wxBitmap(pi01, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[2] = new wxBitmap(pi02, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[3] = new wxBitmap(pi03, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[4] = new wxBitmap(pi04, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[5] = new wxBitmap(pi05, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[6] = new wxBitmap(pi06, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[7] = new wxBitmap(pi07, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[8] = new wxBitmap(pi08, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[9] = new wxBitmap(pi09, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[10] = new wxBitmap(pi10, wxBITMAP_TYPE_XPM);
-               sProgressIndicatorIcons[11] = new wxBitmap(pi11, wxBITMAP_TYPE_XPM);
+               sStopMiniIcons[0] = new wxBitmap(stop_mini_grey);
+               sStopMiniIcons[1] = new wxBitmap(stop_mini);
+               sStopMiniIcons[2] = new wxBitmap(stop_mini_dark);
+               sProgressIndicatorIcons[0] = new wxBitmap(pi00);
+               sProgressIndicatorIcons[1] = new wxBitmap(pi01);
+               sProgressIndicatorIcons[2] = new wxBitmap(pi02);
+               sProgressIndicatorIcons[3] = new wxBitmap(pi03);
+               sProgressIndicatorIcons[4] = new wxBitmap(pi04);
+               sProgressIndicatorIcons[5] = new wxBitmap(pi05);
+               sProgressIndicatorIcons[6] = new wxBitmap(pi06);
+               sProgressIndicatorIcons[7] = new wxBitmap(pi07);
+               sProgressIndicatorIcons[8] = new wxBitmap(pi08);
+               sProgressIndicatorIcons[9] = new wxBitmap(pi09);
+               sProgressIndicatorIcons[10] = new wxBitmap(pi10);
+               sProgressIndicatorIcons[11] = new wxBitmap(pi11);
        }
 }
 
index b06da0c..a0bef83 100644 (file)
@@ -810,9 +810,9 @@ RubyDialogCallback_show(RubyDialog *dref)
 
 #if defined(__WXMAC__)
        {
-               extern void AddWindowsItemWithTitle(const char *title);
+               //extern void AddWindowsItemWithTitle(const char *title);
                wxString str = ((RubyDialogFrame *)dref)->GetLabel();
-               AddWindowsItemWithTitle(str.mb_str(WX_DEFAULT_CONV));
+               //AddWindowsItemWithTitle(str.mb_str(WX_DEFAULT_CONV));
        }
 #endif
 }