]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/scroll/scroll.cpp
adding missing header for non-precomp build
[wxWidgets.git] / samples / scroll / scroll.cpp
index 2599f6787c85b9ef2f744af091a55f0f155ef583..98a9d01dad25e9bf0f366cae86159c9d7b12c22c 100644 (file)
@@ -452,7 +452,7 @@ public:
                            wxDefaultPosition, wxDefaultSize,
                            wxBORDER_SUNKEN)
     {
                            wxDefaultPosition, wxDefaultSize,
                            wxBORDER_SUNKEN)
     {
-        m_nLines = 100;
+        m_nLines = 50;
         m_winSync = NULL;
         m_inDoSync = false;
 
         m_winSync = NULL;
         m_inDoSync = false;
 
@@ -493,10 +493,7 @@ private:
         {
             m_inDoSync = true;
 
         {
             m_inDoSync = true;
 
-            int x, y;
-            GetViewStart(&x, &y);
-
-            m_winSync->Scroll(x, y);
+            m_winSync->Scroll(GetViewStart());
 
             m_inDoSync = false;
         }
 
             m_inDoSync = false;
         }
@@ -624,6 +621,7 @@ private:
     void OnTestAuto(wxCommandEvent& WXUNUSED(event)) { new MyAutoFrame(this); }
 
     void OnToggleSync(wxCommandEvent& event);
     void OnTestAuto(wxCommandEvent& WXUNUSED(event)) { new MyAutoFrame(this); }
 
     void OnToggleSync(wxCommandEvent& event);
+    void OnScrollbarVisibility(wxCommandEvent& event);
 
     MyScrolledWindowBase *m_win1,
                          *m_win2;
 
     MyScrolledWindowBase *m_win1,
                          *m_win2;
@@ -771,9 +769,7 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
 {
     wxLogMessage("Scrolling 2 units up.\n"
                  "The white square and the controls should move equally!");
 {
     wxLogMessage("Scrolling 2 units up.\n"
                  "The white square and the controls should move equally!");
-    int x,y;
-    GetViewStart( &x, &y );
-    Scroll( wxDefaultCoord, y+2 );
+    Scroll( wxDefaultCoord, GetViewStart().y+2 );
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
@@ -839,6 +835,7 @@ const wxWindowID Scroll_Test_Sub    = wxWindow::NewControlId();
 const wxWindowID Scroll_Test_Auto   = wxWindow::NewControlId();
 
 const wxWindowID Scroll_TglBtn_Sync = wxWindow::NewControlId();
 const wxWindowID Scroll_Test_Auto   = wxWindow::NewControlId();
 
 const wxWindowID Scroll_TglBtn_Sync = wxWindow::NewControlId();
+const wxWindowID Scroll_Radio_ShowScrollbar = wxWindow::NewControlId();
 
 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
     EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
 
 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
     EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
@@ -851,6 +848,7 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame)
     EVT_MENU(Scroll_Test_Auto, MyFrame::OnTestAuto)
 
     EVT_TOGGLEBUTTON(Scroll_TglBtn_Sync, MyFrame::OnToggleSync)
     EVT_MENU(Scroll_Test_Auto, MyFrame::OnTestAuto)
 
     EVT_TOGGLEBUTTON(Scroll_TglBtn_Sync, MyFrame::OnToggleSync)
+    EVT_RADIOBOX(Scroll_Radio_ShowScrollbar, MyFrame::OnScrollbarVisibility)
 END_EVENT_TABLE()
 
 MyFrame::MyFrame()
 END_EVENT_TABLE()
 
 MyFrame::MyFrame()
@@ -881,10 +879,12 @@ MyFrame::MyFrame()
     SetMenuBar( mbar );
 
 
     SetMenuBar( mbar );
 
 
+    wxPanel *panel = new wxPanel(this);
+
     const wxSizerFlags flagsExpand(wxSizerFlags(1).Expand());
 
     wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
     const wxSizerFlags flagsExpand(wxSizerFlags(1).Expand());
 
     wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
-    topsizer->Add(new wxStaticText(this, wxID_ANY,
+    topsizer->Add(new wxStaticText(panel, wxID_ANY,
         "The windows below should behave in the same way, even though\n"
         "they're implemented quite differently, see the code for details.\n"
         "\n"
         "The windows below should behave in the same way, even though\n"
         "they're implemented quite differently, see the code for details.\n"
         "\n"
@@ -893,20 +893,39 @@ MyFrame::MyFrame()
         "don't be surprised by this."),
         wxSizerFlags().Centre().Border());
 
         "don't be surprised by this."),
         wxSizerFlags().Centre().Border());
 
-    m_win1 = new MyScrolledWindowDumb(this);
-    m_win2 = new MyScrolledWindowSmart(this);
+    m_win1 = new MyScrolledWindowDumb(panel);
+    m_win2 = new MyScrolledWindowSmart(panel);
 
     wxSizer *sizerScrollWin = new wxBoxSizer(wxHORIZONTAL);
     sizerScrollWin->Add(m_win1, flagsExpand);
     sizerScrollWin->Add(m_win2, flagsExpand);
     topsizer->Add(sizerScrollWin, flagsExpand);
 
 
     wxSizer *sizerScrollWin = new wxBoxSizer(wxHORIZONTAL);
     sizerScrollWin->Add(m_win1, flagsExpand);
     sizerScrollWin->Add(m_win2, flagsExpand);
     topsizer->Add(sizerScrollWin, flagsExpand);
 
+    const wxSizerFlags
+        flagsHBorder(wxSizerFlags().Centre().Border(wxLEFT | wxRIGHT));
+
     wxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
     wxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
-    sizerBtns->Add(new wxToggleButton(this, Scroll_TglBtn_Sync, "&Synchronize"));
+
+    // the radio buttons are in the same order as wxSHOW_SB_XXX values but
+    // offset by 1
+    const wxString visibilities[] = { "&never", "&default", "&always" };
+    wxRadioBox *radio = new wxRadioBox(panel, Scroll_Radio_ShowScrollbar,
+                                       "Left &scrollbar visibility: ",
+                                       wxDefaultPosition, wxDefaultSize,
+                                       WXSIZEOF(visibilities), visibilities);
+    radio->SetSelection(wxSHOW_SB_DEFAULT + 1);
+    sizerBtns->Add(radio, flagsHBorder);
+
+    sizerBtns->Add(new wxToggleButton(panel, Scroll_TglBtn_Sync, "S&ynchronize"),
+                   flagsHBorder);
+
     topsizer->Add(sizerBtns, wxSizerFlags().Centre().Border());
 
     topsizer->Add(sizerBtns, wxSizerFlags().Centre().Border());
 
-    SetSizer(topsizer);
+    panel->SetSizer(topsizer);
 
 
+    wxSize size = panel->GetBestSize();
+    SetSizeHints(size);
+    SetClientSize(2*size);
 
     Show();
 }
 
     Show();
 }
@@ -925,6 +944,12 @@ void MyFrame::OnToggleSync(wxCommandEvent& event)
     }
 }
 
     }
 }
 
+void MyFrame::OnScrollbarVisibility(wxCommandEvent& event)
+{
+    m_win1->ShowScrollbars(wxSHOW_SB_NEVER,
+                           wxScrollbarVisibility(event.GetSelection() - 1));
+}
+
 void MyFrame::OnQuit(wxCommandEvent &WXUNUSED(event))
 {
     Close(true);
 void MyFrame::OnQuit(wxCommandEvent &WXUNUSED(event))
 {
     Close(true);
@@ -1059,20 +1084,14 @@ MyAutoScrollingWindow::DeviceCoordsToGraphicalChars(wxPoint pos) const
 {
     pos.x /= m_fontW;
     pos.y /= m_fontH;
 {
     pos.x /= m_fontW;
     pos.y /= m_fontH;
-    int vX, vY;
-    GetViewStart(&vX, &vY);
-    pos.x += vX;
-    pos.y += vY;
+    pos += GetViewStart();
     return pos;
 }
 
 wxPoint
 MyAutoScrollingWindow::GraphicalCharToDeviceCoords(wxPoint pos) const
 {
     return pos;
 }
 
 wxPoint
 MyAutoScrollingWindow::GraphicalCharToDeviceCoords(wxPoint pos) const
 {
-    int vX, vY;
-    GetViewStart(&vX, &vY);
-    pos.x -= vX;
-    pos.y -= vY;
+    pos -= GetViewStart();
     pos.x *= m_fontW;
     pos.y *= m_fontH;
     return pos;
     pos.x *= m_fontW;
     pos.y *= m_fontH;
     return pos;