]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/vscroll/vstest.cpp
compilation fix for wxOSX_USE_EXPERIMENTAL_FONTDIALOG==0 (closes #10834)
[wxWidgets.git] / samples / vscroll / vstest.cpp
index 2e23b2ec41565559f7c9f6e855e6dc07b549db4d..c8af46184e51e660ab4f9d382555f514188cf100 100644 (file)
@@ -48,7 +48,7 @@
 // definitions
 // ----------------------------------------------------------------------------
 
-#define MAX_LINES 200
+#define MAX_LINES 10000
 
 // ----------------------------------------------------------------------------
 // private classes
@@ -72,6 +72,7 @@ public:
     // event handlers (these functions should _not_ be virtual)
     void OnQuit(wxCommandEvent& event);
     void OnModeVScroll(wxCommandEvent& event);
+    void OnModeHScroll(wxCommandEvent& event);
     void OnModeHVScroll(wxCommandEvent& event);
     void OnAbout(wxCommandEvent& event);
 
@@ -90,11 +91,11 @@ public:
     }
 
 private:
-    // any class wishing to process wxWidgets events must use this macro
-    DECLARE_EVENT_TABLE()
-
     // either a wxVScrolledWindow or a wxHVScrolled window, depending on current mode
     wxPanel *m_scrollWindow;
+
+    // any class wishing to process wxWidgets events must use this macro
+    DECLARE_EVENT_TABLE()
 };
 
 class VScrollWindow : public wxVScrolledWindow
@@ -104,12 +105,12 @@ public:
     {
         m_frame = frame;
 
-        SetLineCount(MAX_LINES);
+        SetRowCount(MAX_LINES);
 
         int i;
         for ( i = 0; i < MAX_LINES; ++i )
-            m_heights[i] = rand()%25+16; // low: 15; high: 40
-    
+            m_heights[i] = rand()%25+16; // low: 16; high: 40
+
         m_changed = true;
     }
 
@@ -145,7 +146,7 @@ public:
         {
             dc.DrawLine(0, y, clientSize.GetWidth(), y);
 
-            wxCoord hLine = OnGetLineHeight(line);
+            wxCoord hLine = OnGetRowHeight(line);
             dc.DrawText(wxString::Format(_T("Line %lu"), (unsigned long)line),
                         2, y + (hLine - hText) / 2);
 
@@ -161,10 +162,18 @@ public:
         event.Skip();
     }
 
+    void OnMouse(wxMouseEvent& event)
+    {
+        if(event.LeftDown())
+            CaptureMouse();
+        else if(event.LeftUp())
+            ReleaseMouse();
+        event.Skip();
+    }
 
-    virtual wxCoord OnGetLineHeight(size_t n) const
+    virtual wxCoord OnGetRowHeight(size_t n) const
     {
-        wxASSERT( n < GetLineCount() );
+        wxASSERT( n < GetRowCount() );
 
         return m_heights[n];
     }
@@ -183,6 +192,104 @@ BEGIN_EVENT_TABLE(VScrollWindow, wxVScrolledWindow)
     EVT_IDLE(VScrollWindow::OnIdle)
     EVT_PAINT(VScrollWindow::OnPaint)
     EVT_SCROLLWIN(VScrollWindow::OnScroll)
+    EVT_MOUSE_EVENTS(VScrollWindow::OnMouse)
+END_EVENT_TABLE()
+
+class HScrollWindow : public wxHScrolledWindow
+{
+public:
+    HScrollWindow(wxFrame *frame) : wxHScrolledWindow(frame, wxID_ANY)
+    {
+        m_frame = frame;
+
+        SetColumnCount(MAX_LINES);
+
+        int i;
+        for ( i = 0; i < MAX_LINES; ++i )
+            m_heights[i] = rand()%25+16; // low: 15; high: 40
+
+        m_changed = true;
+    }
+
+    void OnIdle(wxIdleEvent&)
+    {
+#if wxUSE_STATUSBAR
+        m_frame->SetStatusText(wxString::Format
+                               (
+                                    _T("Page size = %d, pos = %d, max = %d"),
+                                    GetScrollThumb(wxVERTICAL),
+                                    GetScrollPos(wxVERTICAL),
+                                    GetScrollRange(wxVERTICAL)
+                               ));
+#endif // wxUSE_STATUSBAR
+        m_changed = false;
+    }
+
+    void OnPaint(wxPaintEvent&)
+    {
+        wxPaintDC dc(this);
+
+        dc.SetPen(*wxBLACK_PEN);
+
+        const size_t lineFirst = GetVisibleBegin(),
+                     lineLast = GetVisibleEnd();
+
+        const wxCoord hText = dc.GetCharHeight();
+
+        wxSize clientSize = GetClientSize();
+
+        wxCoord x = 0;
+        for ( size_t line = lineFirst; line < lineLast; line++ )
+        {
+            dc.DrawLine(x, 0, x, clientSize.GetHeight());
+
+            wxCoord wLine = OnGetColumnWidth(line);
+            dc.DrawRotatedText(wxString::Format(_T("Line %lu"), (unsigned long)line),
+                               x + (wLine - hText) / 2, clientSize.GetHeight() - 5, 90);
+
+            x += wLine;
+            dc.DrawLine(x, 0, x, 1000);
+        }
+    }
+
+    void OnScroll(wxScrollWinEvent& event)
+    {
+        m_changed = true;
+
+        event.Skip();
+    }
+
+    void OnMouse(wxMouseEvent& event)
+    {
+        if(event.LeftDown())
+            CaptureMouse();
+        else if(event.LeftUp())
+            ReleaseMouse();
+        event.Skip();
+    }
+
+    virtual wxCoord OnGetColumnWidth(size_t n) const
+    {
+        wxASSERT( n < GetColumnCount() );
+
+        return m_heights[n];
+    }
+
+private:
+    wxFrame *m_frame;
+
+    int m_heights[MAX_LINES];
+
+    bool m_changed;
+
+    DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(HScrollWindow, wxHScrolledWindow)
+    EVT_IDLE(HScrollWindow::OnIdle)
+    EVT_PAINT(HScrollWindow::OnPaint)
+    EVT_SCROLLWIN(HScrollWindow::OnScroll)
+    EVT_MOUSE_EVENTS(HScrollWindow::OnMouse)
 END_EVENT_TABLE()
 
 class HVScrollWindow : public wxHVScrolledWindow
@@ -192,8 +299,8 @@ public:
     {
         m_frame = frame;
 
-        SetRowColumnCounts(MAX_LINES, MAX_LINES);
-        
+        SetRowColumnCount(MAX_LINES, MAX_LINES);
+
         int i;
         for ( i = 0; i < MAX_LINES; ++i )
         {
@@ -231,7 +338,7 @@ public:
                      rowLast = GetVisibleRowsEnd();
         const size_t columnFirst = GetVisibleColumnsBegin(),
                      columnLast = GetVisibleColumnsEnd();
-        
+
         const wxCoord hText = dc.GetCharHeight();
 
         wxSize clientSize = GetClientSize();
@@ -255,12 +362,12 @@ public:
                             x + 2, y + rowHeight / 2 - hText);
                 dc.DrawText(wxString::Format(_T("Col %lu"), (unsigned long)col),
                             x + 2, y + rowHeight / 2);
-                
+
                 x += colWidth;
                 if ( row == rowFirst)
                     dc.DrawLine(x, 0, x, clientSize.GetHeight());
             }
-            
+
             y += rowHeight;
             dc.DrawLine(0, y, clientSize.GetWidth(), y);
         }
@@ -273,6 +380,14 @@ public:
         event.Skip();
     }
 
+    void OnMouse(wxMouseEvent& event)
+    {
+        if(event.LeftDown())
+            CaptureMouse();
+        else if(event.LeftUp())
+            ReleaseMouse();
+        event.Skip();
+    }
 
     virtual wxCoord OnGetRowHeight(size_t n) const
     {
@@ -303,6 +418,7 @@ BEGIN_EVENT_TABLE(HVScrollWindow, wxHVScrolledWindow)
     EVT_IDLE(HVScrollWindow::OnIdle)
     EVT_PAINT(HVScrollWindow::OnPaint)
     EVT_SCROLLWIN(HVScrollWindow::OnScroll)
+    EVT_MOUSE_EVENTS(HVScrollWindow::OnMouse)
 END_EVENT_TABLE()
 
 // ----------------------------------------------------------------------------
@@ -321,6 +437,7 @@ enum
     VScroll_About = wxID_ABOUT,
 
     VScroll_VScrollMode = wxID_HIGHEST + 1,
+    VScroll_HScrollMode,
     VScroll_HVScrollMode
 };
 
@@ -334,6 +451,7 @@ enum
 BEGIN_EVENT_TABLE(VarScrollFrame, wxFrame)
     EVT_MENU(VScroll_Quit,  VarScrollFrame::OnQuit)
     EVT_MENU(VScroll_VScrollMode, VarScrollFrame::OnModeVScroll)
+    EVT_MENU(VScroll_HScrollMode, VarScrollFrame::OnModeHScroll)
     EVT_MENU(VScroll_HVScrollMode, VarScrollFrame::OnModeHVScroll)
     EVT_MENU(VScroll_About, VarScrollFrame::OnAbout)
     EVT_SIZE(VarScrollFrame::OnSize)
@@ -357,6 +475,9 @@ IMPLEMENT_APP(VarScrollApp)
 // 'Main program' equivalent: the program execution "starts" here
 bool VarScrollApp::OnInit()
 {
+    if ( !wxApp::OnInit() )
+        return false;
+
     // create the main application window
     VarScrollFrame *frame = new VarScrollFrame;
 
@@ -397,14 +518,18 @@ VarScrollFrame::VarScrollFrame()
 #ifdef wxHAS_RADIO_MENU_ITEMS
     menuMode->AppendRadioItem(VScroll_VScrollMode, _T("&Vertical\tAlt-V"),
                               _T("Vertical scrolling only"));
+    menuMode->AppendRadioItem(VScroll_HScrollMode, _T("&Horizontal\tAlt-H"),
+                              _T("Horizontal scrolling only"));
     menuMode->AppendRadioItem(VScroll_HVScrollMode,
-                              _T("&Horizontal/Vertical\tAlt-H"),
+                              _T("Hori&zontal/Vertical\tAlt-Z"),
                               _T("Horizontal and vertical scrolling"));
     menuMode->Check(VScroll_VScrollMode, true);
 #else
     menuMode->Append(VScroll_VScrollMode, _T("&Vertical\tAlt-V"),
                      _T("Vertical scrolling only"));
-    menuMode->Append(VScroll_HVScrollMode, _T("&Horizontal/Vertical\tAlt-H"),
+    menuMode->Append(VScroll_HScrollMode, _T("&Horizontal\tAlt-H"),
+                     _T("Horizontal scrolling only"));
+    menuMode->Append(VScroll_HVScrollMode, _T("Hori&zontal/Vertical\tAlt-Z"),
                      _T("Horizontal and vertical scrolling"));
 #endif
 
@@ -433,7 +558,9 @@ VarScrollFrame::VarScrollFrame()
     // create our one and only child -- it will take our entire client area
     if ( menuMode->IsChecked(VScroll_VScrollMode) )
         m_scrollWindow = new VScrollWindow(this);
-    else if ( menuMode->IsChecked(VScroll_VScrollMode) )
+    else if ( menuMode->IsChecked(VScroll_HScrollMode) )
+        m_scrollWindow = new HScrollWindow(this);
+    else
         m_scrollWindow = new HVScrollWindow(this);
 }
 
@@ -451,11 +578,20 @@ void VarScrollFrame::OnModeVScroll(wxCommandEvent& WXUNUSED(event))
 {
     if ( m_scrollWindow )
         m_scrollWindow->Destroy();
-    
+
     m_scrollWindow = new VScrollWindow(this);
     SendSizeEvent();
 }
 
+void VarScrollFrame::OnModeHScroll(wxCommandEvent& WXUNUSED(event))
+{
+    if ( m_scrollWindow )
+        m_scrollWindow->Destroy();
+
+    m_scrollWindow = new HScrollWindow(this);
+    SendSizeEvent();
+}
+
 void VarScrollFrame::OnModeHVScroll(wxCommandEvent& WXUNUSED(event))
 {
     if ( m_scrollWindow )