]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/utils/wxrcedit/splittree.cpp
added .chm support for Unix (Markus Sinner)
[wxWidgets.git] / contrib / utils / wxrcedit / splittree.cpp
index cb4ab5f7c2ccedbbd68d9e4cffce8ad9000ab343..263d9df88beb6ebc2faeafbda956df6bb1f8b27f 100644 (file)
@@ -18,7 +18,7 @@
 // ----------------------------------------------------------------------------
 // headers
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // headers
 // ----------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(__APPLE__)
     #pragma implementation "splittree.h"
 #endif
 
     #pragma implementation "splittree.h"
 #endif
 
     #include "wx/wx.h"
 #endif
 
     #include "wx/wx.h"
 #endif
 
-#include "wx/generic/treectlg.h"
+#ifdef __WXMSW__
+#include <windows.h>
+#include "wx/msw/winundef.h"
+#endif
 
 
-#include "splittree.h"
+#include "wx/gizmos/splittree.h"
+#include <math.h>
 
 /*
  * wxRemotelyScrolledTreeCtrl
 
 /*
  * wxRemotelyScrolledTreeCtrl
@@ -73,7 +77,7 @@ wxRemotelyScrolledTreeCtrl::~wxRemotelyScrolledTreeCtrl()
 
 void wxRemotelyScrolledTreeCtrl::HideVScrollbar()
 {
 
 void wxRemotelyScrolledTreeCtrl::HideVScrollbar()
 {
-#ifdef __WXMSW__
+#if defined(__WXMSW__) && USE_GENERIC_TREECTRL
     if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
     {
         ::ShowScrollBar((HWND) GetHWND(), SB_VERT, FALSE);
     if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
     {
         ::ShowScrollBar((HWND) GetHWND(), SB_VERT, FALSE);
@@ -88,6 +92,7 @@ void wxRemotelyScrolledTreeCtrl::HideVScrollbar()
 // Number of pixels per user unit (0 or -1 for no scrollbar)
 // Length of virtual canvas in user units
 // Length of page in user units
 // Number of pixels per user unit (0 or -1 for no scrollbar)
 // Length of virtual canvas in user units
 // Length of page in user units
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
 void wxRemotelyScrolledTreeCtrl::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
                              int noUnitsX, int noUnitsY,
                              int xPos, int yPos,
 void wxRemotelyScrolledTreeCtrl::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
                              int noUnitsX, int noUnitsY,
                              int xPos, int yPos,
@@ -104,9 +109,17 @@ void wxRemotelyScrolledTreeCtrl::SetScrollbars(int pixelsPerUnitX, int pixelsPer
             scrolledWindow->SetScrollbars(0, pixelsPerUnitY, 0, noUnitsY, 0, yPos, noRefresh);
         }
     }
             scrolledWindow->SetScrollbars(0, pixelsPerUnitY, 0, noUnitsY, 0, yPos, noRefresh);
         }
     }
+#else
+void wxRemotelyScrolledTreeCtrl::SetScrollbars(int WXUNUSED(pixelsPerUnitX), int WXUNUSED(pixelsPerUnitY),
+                             int WXUNUSED(noUnitsX), int WXUNUSED(noUnitsY),
+                             int WXUNUSED(xPos), int WXUNUSED(yPos),
+                             bool WXUNUSED(noRefresh))
+{
+#endif
 }
 
 // In case we're using the generic tree control.
 }
 
 // In case we're using the generic tree control.
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
 int wxRemotelyScrolledTreeCtrl::GetScrollPos(int orient) const
 {
     wxScrolledWindow* scrolledWindow = GetScrolledWindow();
 int wxRemotelyScrolledTreeCtrl::GetScrollPos(int orient) const
 {
     wxScrolledWindow* scrolledWindow = GetScrolledWindow();
@@ -122,6 +135,10 @@ int wxRemotelyScrolledTreeCtrl::GetScrollPos(int orient) const
             return scrolledWindow->GetScrollPos(orient);
         }
     }
             return scrolledWindow->GetScrollPos(orient);
         }
     }
+#else
+int wxRemotelyScrolledTreeCtrl::GetScrollPos(int WXUNUSED(orient)) const
+{
+#endif
     return 0;
 }
 
     return 0;
 }
 
@@ -132,6 +149,7 @@ void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
 {
     wxScrolledWindow* scrolledWindow = GetScrolledWindow();
 
 {
     wxScrolledWindow* scrolledWindow = GetScrolledWindow();
 
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
     if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
     {
 
     if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
     {
 
@@ -146,6 +164,7 @@ void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
         * y = y2;
     }
        else
         * y = y2;
     }
        else
+#endif
        {
                // x is wrong since the horizontal scrollbar is controlled by the
                // tree control, but we probably don't need it.
        {
                // x is wrong since the horizontal scrollbar is controlled by the
                // tree control, but we probably don't need it.
@@ -154,6 +173,7 @@ void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
 }
 
 // In case we're using the generic tree control.
 }
 
 // In case we're using the generic tree control.
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
 void wxRemotelyScrolledTreeCtrl::PrepareDC(wxDC& dc)
 {
     if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
 void wxRemotelyScrolledTreeCtrl::PrepareDC(wxDC& dc)
 {
     if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
@@ -170,23 +190,32 @@ void wxRemotelyScrolledTreeCtrl::PrepareDC(wxDC& dc)
         scrolledWindow->GetScrollPixelsPerUnit(& xppu2, & yppu2);
 
         dc.SetDeviceOrigin( -startX * xppu1, -startY * yppu2 );
         scrolledWindow->GetScrollPixelsPerUnit(& xppu2, & yppu2);
 
         dc.SetDeviceOrigin( -startX * xppu1, -startY * yppu2 );
-        dc.SetUserScale( win->GetScaleX(), win->GetScaleY() );
+        // dc.SetUserScale( win->GetScaleX(), win->GetScaleY() );
     }
     }
+#else
+void wxRemotelyScrolledTreeCtrl::PrepareDC(wxDC& WXUNUSED(dc))
+{
+#endif
 }
 
 // Scroll to the given line (in scroll units where each unit is
 // the height of an item)
 }
 
 // Scroll to the given line (in scroll units where each unit is
 // the height of an item)
-void wxRemotelyScrolledTreeCtrl::ScrollToLine(int posHoriz, int posVert)
+void wxRemotelyScrolledTreeCtrl::ScrollToLine(int WXUNUSED(posHoriz), int posVert)
 {
 #ifdef __WXMSW__
 {
 #ifdef __WXMSW__
+#if USE_GENERIC_TREECTRL
     if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
     if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
+#endif
     {
            UINT sbCode = SB_THUMBPOSITION;
            HWND vertScrollBar = 0;
            MSWDefWindowProc((WXUINT) WM_VSCROLL, MAKELONG(sbCode, posVert), (WXHWND) vertScrollBar);
     }
     {
            UINT sbCode = SB_THUMBPOSITION;
            HWND vertScrollBar = 0;
            MSWDefWindowProc((WXUINT) WM_VSCROLL, MAKELONG(sbCode, posVert), (WXHWND) vertScrollBar);
     }
+#if USE_GENERIC_TREECTRL
     else
 #endif
     else
 #endif
+#endif
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
     {
         wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
                win->Refresh();
     {
         wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
                win->Refresh();
@@ -200,6 +229,7 @@ void wxRemotelyScrolledTreeCtrl::ScrollToLine(int posHoriz, int posVert)
                }
                */
     }
                }
                */
     }
+#endif
 }
 
 void wxRemotelyScrolledTreeCtrl::OnSize(wxSizeEvent& event)
 }
 
 void wxRemotelyScrolledTreeCtrl::OnSize(wxSizeEvent& event)
@@ -226,6 +256,7 @@ void wxRemotelyScrolledTreeCtrl::OnExpand(wxTreeEvent& event)
 // Adjust the containing wxScrolledWindow's scrollbars appropriately
 void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars()
 {
 // Adjust the containing wxScrolledWindow's scrollbars appropriately
 void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars()
 {
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
     if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
        {
                // This is for the generic tree control.
     if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
        {
                // This is for the generic tree control.
@@ -236,6 +267,7 @@ void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars()
         return;
        }
        else
         return;
        }
        else
+#endif
        {
                // This is for the wxMSW tree control
                wxScrolledWindow* scrolledWindow = GetScrolledWindow();
        {
                // This is for the wxMSW tree control
                wxScrolledWindow* scrolledWindow = GetScrolledWindow();
@@ -244,14 +276,18 @@ void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars()
                        wxRect itemRect;
                        if (GetBoundingRect(GetRootItem(), itemRect))
                        {
                        wxRect itemRect;
                        if (GetBoundingRect(GetRootItem(), itemRect))
                        {
-                               int itemHeight = itemRect.GetHeight();
+                // Actually, the real height seems to be 1 less than reported
+                // (e.g. 16 instead of 16)
+                int itemHeight = itemRect.GetHeight() - 1;
                                
                                int w, h;
                                GetClientSize(&w, &h);
                                
                                wxRect rect(0, 0, 0, 0);
                                CalcTreeSize(rect);
                                
                                int w, h;
                                GetClientSize(&w, &h);
                                
                                wxRect rect(0, 0, 0, 0);
                                CalcTreeSize(rect);
-                               int treeViewHeight = rect.GetHeight()/itemHeight;
+
+                double f = ((double) (rect.GetHeight()) / (double) itemHeight)  ;
+                int treeViewHeight = (int) ceil(f);
                                
                                int scrollPixelsPerLine = itemHeight;
                                int scrollPos = - (itemRect.y / itemHeight);
                                
                                int scrollPixelsPerLine = itemHeight;
                                int scrollPos = - (itemRect.y / itemHeight);
@@ -299,9 +335,6 @@ void wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxRect& rect)
 
 void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& rect)
 {
 
 void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& rect)
 {
-       // TODO: implement GetFirst/NextVisibleItem
-       // for wxGenericTreeCtrl, plus GetBoundingRect.
-
        // More efficient implementation would be to find the last item (but how?)
        // Q: is the bounding rect relative to the top of the virtual tree workspace
        // or the top of the window? How would we convert?
        // More efficient implementation would be to find the last item (but how?)
        // Q: is the bounding rect relative to the top of the virtual tree workspace
        // or the top of the window? How would we convert?
@@ -311,9 +344,9 @@ void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& re
                rect = CombineRectangles(rect, itemSize);
        }
 
                rect = CombineRectangles(rect, itemSize);
        }
 
-       long cookie;
+       void* cookie;
        wxTreeItemId childId = GetFirstChild(id, cookie);
        wxTreeItemId childId = GetFirstChild(id, cookie);
-       while (childId != 0)
+       while (childId)
        {
                CalcTreeSize(childId, rect);
                childId = GetNextChild(childId, cookie);
        {
                CalcTreeSize(childId, rect);
                childId = GetNextChild(childId, cookie);
@@ -396,17 +429,17 @@ void wxTreeCompanionWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& re
 #endif
 }
 
 #endif
 }
 
-void wxTreeCompanionWindow::OnPaint(wxPaintEvent& event)
+void wxTreeCompanionWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
        wxPaintDC dc(this);
 
     if (!m_treeCtrl)
         return;
 
 {
        wxPaintDC dc(this);
 
     if (!m_treeCtrl)
         return;
 
-        wxPen pen(wxColour(_T("BLACK")), 1, wxSOLID);
+        wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
        dc.SetPen(pen);
        dc.SetBrush(* wxTRANSPARENT_BRUSH);
        dc.SetPen(pen);
        dc.SetBrush(* wxTRANSPARENT_BRUSH);
-       wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+       wxFont font(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
        dc.SetFont(font);
 
     wxSize clientSize = GetClientSize();
        dc.SetFont(font);
 
     wxSize clientSize = GetClientSize();
@@ -449,7 +482,7 @@ void wxTreeCompanionWindow::OnScroll(wxScrollWinEvent& event)
        Refresh(TRUE);
 }
 
        Refresh(TRUE);
 }
 
-void wxTreeCompanionWindow::OnExpand(wxTreeEvent& event)
+void wxTreeCompanionWindow::OnExpand(wxTreeEvent& WXUNUSED(event))
 {
        // TODO: something more optimized than simply refresh the whole
        // window when the tree is expanded/collapsed. Tricky.
 {
        // TODO: something more optimized than simply refresh the whole
        // window when the tree is expanded/collapsed. Tricky.
@@ -474,6 +507,10 @@ wxThinSplitterWindow::wxThinSplitterWindow(wxWindow* parent, wxWindowID id,
 {
 }
 
 {
 }
 
+wxThinSplitterWindow::~wxThinSplitterWindow()
+{
+}
+
 void wxThinSplitterWindow::SizeWindows()
 {
        // The client size may have changed inbetween
 void wxThinSplitterWindow::SizeWindows()
 {
        // The client size may have changed inbetween
@@ -484,14 +521,14 @@ void wxThinSplitterWindow::SizeWindows()
 }
 
 // Tests for x, y over sash
 }
 
 // Tests for x, y over sash
-bool wxThinSplitterWindow::SashHitTest(int x, int y, int tolerance)
+bool wxThinSplitterWindow::SashHitTest(int x, int y, int WXUNUSED(tolerance))
 {
        return wxSplitterWindow::SashHitTest(x, y, 4);
 }
 
 void wxThinSplitterWindow::DrawSash(wxDC& dc)
 {
 {
        return wxSplitterWindow::SashHitTest(x, y, 4);
 }
 
 void wxThinSplitterWindow::DrawSash(wxDC& dc)
 {
-    if ( m_sashPosition == 0 || !m_windowTwo)
+    if ( GetSashPosition() == 0 || !m_windowTwo)
         return;
     if (GetWindowStyle() & wxSP_NOSASH)
         return;
         return;
     if (GetWindowStyle() & wxSP_NOSASH)
         return;
@@ -511,7 +548,7 @@ void wxThinSplitterWindow::DrawSash(wxDC& dc)
                {
                        y1 = 2; h1 -= 3;
                }
                {
                        y1 = 2; h1 -= 3;
                }
-               dc.DrawRectangle(m_sashPosition, y1, m_sashSize, h1);
+               dc.DrawRectangle(GetSashPosition(), y1, GetSashSize(), h1);
        }
        else
        {
        }
        else
        {
@@ -525,7 +562,7 @@ void wxThinSplitterWindow::DrawSash(wxDC& dc)
                {
                        x1 = 2; w1 -= 3;
                }
                {
                        x1 = 2; w1 -= 3;
                }
-               dc.DrawRectangle(x1, m_sashPosition, w1, m_sashSize);
+               dc.DrawRectangle(x1, GetSashPosition(), w1, GetSashSize());
        }
        
     dc.SetPen(wxNullPen);
        }
        
     dc.SetPen(wxNullPen);
@@ -556,12 +593,12 @@ wxSplitterScrolledWindow::wxSplitterScrolledWindow(wxWindow* parent, wxWindowID
 {
 }
 
 {
 }
 
-void wxSplitterScrolledWindow::OnSize(wxSizeEvent& event)
+void wxSplitterScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
 {
        wxSize sz = GetClientSize();
 {
        wxSize sz = GetClientSize();
-       if (GetChildren().First())
+       if (GetChildren().GetFirst())
        {
        {
-               ((wxWindow*) GetChildren().First()->Data())->SetSize(0, 0, sz.x, sz.y);
+               ((wxWindow*) GetChildren().GetFirst()->GetData())->SetSize(0, 0, sz.x, sz.y);
        }
 }
 
        }
 }
 
@@ -571,9 +608,12 @@ void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event)
     // don't cause an infinite loop
     static bool inOnScroll = FALSE;
     if (inOnScroll)
     // don't cause an infinite loop
     static bool inOnScroll = FALSE;
     if (inOnScroll)
+    {
+        event.Skip();
         return;
         return;
+    }
     inOnScroll = TRUE;
     inOnScroll = TRUE;
-
+    
     int orient = event.GetOrientation();
 
     int nScrollInc = CalcScrollInc(event);
     int orient = event.GetOrientation();
 
     int nScrollInc = CalcScrollInc(event);
@@ -609,10 +649,10 @@ void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event)
     }
 
     // Find targets in splitter window and send the event to them
     }
 
     // Find targets in splitter window and send the event to them
-    wxNode* node = GetChildren().First();
+    wxNode* node = (wxNode *)GetChildren().GetFirst();
     while (node)
     {
     while (node)
     {
-        wxWindow* child = (wxWindow*) node->Data();
+        wxWindow* child = (wxWindow*) node->GetData();
         if (child->IsKindOf(CLASSINFO(wxSplitterWindow)))
         {
             wxSplitterWindow* splitter = (wxSplitterWindow*) child;
         if (child->IsKindOf(CLASSINFO(wxSplitterWindow)))
         {
             wxSplitterWindow* splitter = (wxSplitterWindow*) child;
@@ -622,7 +662,7 @@ void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event)
                 splitter->GetWindow2()->ProcessEvent(event);
             break;
         }
                 splitter->GetWindow2()->ProcessEvent(event);
             break;
         }
-        node = node->Next();
+        node = node->GetNext();
     }
 
 #ifdef __WXMAC__
     }
 
 #ifdef __WXMAC__