]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/scrlwing.cpp
corrected CodeWarrior project target names and generated application names
[wxWidgets.git] / src / generic / scrlwing.cpp
index 3897dca59f809ee87f6173dab696fe3bc505ac09..ce07d296b2388bc28eb2fae7c53f5b4932fd10ce 100644 (file)
@@ -57,9 +57,7 @@
 #endif
 #endif
 
-#ifndef __WXGTK__
 IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow)
-#endif
 
 // ----------------------------------------------------------------------------
 // wxScrollHelperEvtHandler: intercept the events from the window and forward
@@ -169,6 +167,13 @@ void wxAutoScrollTimer::Notify()
 
 bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
 {
+    wxEventType evType = event.GetEventType();
+
+    if ( evType == wxEVT_SIZE )
+    {
+        m_scrollHelper->HandleOnSize((wxSizeEvent &)event);
+    }
+
     if ( wxEvtHandler::ProcessEvent(event) )
         return TRUE;
 
@@ -176,8 +181,6 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
     // ProcessEvent() above
     event.Skip(FALSE);
 
-    wxEventType evType = event.GetEventType();
-
     if ( evType == wxEVT_PAINT )
     {
         m_scrollHelper->HandleOnPaint((wxPaintEvent &)event);
@@ -211,10 +214,6 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
         m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event);
     }
 #endif // wxUSE_MOUSEWHEEL
-    else if ( evType == wxEVT_SIZE )
-    {
-        m_scrollHelper->HandleOnSize((wxSizeEvent &)event);
-    }
     else if ( evType == wxEVT_CHAR )
     {
         m_scrollHelper->HandleOnChar((wxKeyEvent &)event);
@@ -274,6 +273,8 @@ wxScrollHelper::~wxScrollHelper()
 
     if ( m_targetWindow )
         m_targetWindow->PopEventHandler(TRUE /* do delete it */);
+    if ( m_win && m_win != m_targetWindow)
+        m_win->PopEventHandler(TRUE /* do delete it */);
 }
 
 // ----------------------------------------------------------------------------
@@ -321,22 +322,22 @@ void wxScrollHelper::SetScrollbars(int pixelsPerUnitX,
 
         int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine;
         int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine;
-        if (m_targetWindow->m_backingPixmap &&
-           !((m_targetWindow->m_pixmapWidth == totalPixelWidth) &&
-             (m_targetWindow->m_pixmapHeight == totalPixelHeight)))
+        if (m_targetWindow->GetBackingPixmap() &&
+           !((m_targetWindow->GetPixmapWidth() == totalPixelWidth) &&
+             (m_targetWindow->GetPixmapHeight() == totalPixelHeight)))
         {
-            XFreePixmap (dpy, (Pixmap) m_targetWindow->m_backingPixmap);
-            m_targetWindow->m_backingPixmap = (WXPixmap) 0;
+            XFreePixmap (dpy, (Pixmap) m_targetWindow->GetBackingPixmap());
+            m_targetWindow->SetBackingPixmap((WXPixmap) 0);
         }
 
-        if (!m_targetWindow->m_backingPixmap &&
+        if (!m_targetWindow->GetBackingPixmap() &&
            (noUnitsX != 0) && (noUnitsY != 0))
         {
             int depth = wxDisplayDepth();
-            m_pixmapWidth = totalPixelWidth;
-            m_pixmapHeight = totalPixelHeight;
-            m_backingPixmap = (WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
-            m_pixmapWidth, m_pixmapHeight, depth);
+            m_targetWindow->SetPixmapWidth(totalPixelWidth);
+            m_targetWindow->SetPixmapHeight(totalPixelHeight);
+            m_targetWindow->SetBackingPixmap((WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
+              m_targetWindow->GetPixmapWidth(), m_targetWindow->GetPixmapHeight(), depth));
         }
 
     }
@@ -359,7 +360,17 @@ void wxScrollHelper::SetScrollbars(int pixelsPerUnitX,
 void wxScrollHelper::SetTargetWindow( wxWindow *target )
 {
     wxASSERT_MSG( target, wxT("target window must not be NULL") );
+    // FIXME: There is a potential problem with this way of deleting
+    // event handlers, basically you can not be sure that you delete
+    // the event handler that was create by this wxScrollHelper.
+    // Remove the old event handler from the previous target scroll window.
+    if (m_targetWindow && m_targetWindow != m_win)
+        m_targetWindow->PopEventHandler(TRUE /* Delete old event handler*/);
     m_targetWindow = target;
+    // Install a new event handler, which will intercept the events we're
+    // interested in from the target scroll window.
+    if (m_targetWindow != m_win)
+        m_targetWindow->PushEventHandler(new wxScrollHelperEvtHandler(this));
 }
 
 wxWindow *wxScrollHelper::GetTargetWindow() const
@@ -386,12 +397,12 @@ void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event)
     if (orient == wxHORIZONTAL)
     {
         m_xScrollPosition += nScrollInc;
-        m_targetWindow->SetScrollPos(wxHORIZONTAL, m_xScrollPosition, FALSE);
+        m_targetWindow->SetScrollPos(wxHORIZONTAL, m_xScrollPosition);
     }
     else
     {
         m_yScrollPosition += nScrollInc;
-        m_targetWindow->SetScrollPos(wxVERTICAL, m_yScrollPosition, FALSE);
+        m_targetWindow->SetScrollPos(wxVERTICAL, m_yScrollPosition);
     }
 
     bool needsRefresh = FALSE;
@@ -679,7 +690,7 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos )
         m_xScrollPosition = wxMax( 0, m_xScrollPosition );
 
         if (old_x != m_xScrollPosition) {
-            m_targetWindow->SetScrollPos( wxHORIZONTAL, m_xScrollPosition, FALSE );
+            m_targetWindow->SetScrollPos( wxHORIZONTAL, m_xScrollPosition );
             m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0,
                                           GetRect() );
         }
@@ -700,7 +711,7 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos )
         m_yScrollPosition = wxMax( 0, m_yScrollPosition );
 
         if (old_y != m_yScrollPosition) {
-            m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition, FALSE );
+            m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition );
             m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine,
                                           GetRect() );
         }
@@ -811,6 +822,9 @@ void wxScrollHelper::HandleOnChar(wxKeyEvent& event)
         szy = -1;
     }
 
+    int xScrollOld = m_xScrollPosition,
+        yScrollOld = m_yScrollPosition;
+
     int dsty;
     switch ( event.KeyCode() )
     {
@@ -853,6 +867,22 @@ void wxScrollHelper::HandleOnChar(wxKeyEvent& event)
             // not for us
             event.Skip();
     }
+
+    if ( m_xScrollPosition != xScrollOld )
+    {
+        wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition,
+                               wxHORIZONTAL);
+        event.SetEventObject(m_win);
+        m_win->GetEventHandler()->ProcessEvent(event);
+    }
+
+    if ( m_yScrollPosition != yScrollOld )
+    {
+        wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition,
+                               wxVERTICAL);
+        event.SetEventObject(m_win);
+        m_win->GetEventHandler()->ProcessEvent(event);
+    }
 }
 
 // ----------------------------------------------------------------------------
@@ -960,9 +990,24 @@ void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event)
     {
         lines *= event.GetLinesPerAction();
 
-        int vsx, vsy;
-        GetViewStart(&vsx, &vsy);
-        Scroll(-1, vsy - lines);
+        wxScrollWinEvent newEvent;
+
+        newEvent.SetPosition(0);
+        newEvent.SetOrientation(wxVERTICAL);
+        newEvent.m_eventObject = m_win;
+        if (lines > 0)
+            newEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
+        else
+            newEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
+
+        int times = abs(lines);
+        for (; times > 0; times --)
+            m_win->GetEventHandler()->ProcessEvent(newEvent);
+
+        /* Old Way */
+        // int vsx, vsy;
+        // GetViewStart(&vsx, &vsy);
+        // Scroll(-1, vsy - lines);
     }
 }