]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/gridg.cpp
wxFrame::size There is always a hack to solve your problems.
[wxWidgets.git] / src / generic / gridg.cpp
index 6e12f5183592af737a7d1f57b827e94505d1f3a7..1db2cede13c45cf149f97a51634140ce9703ef11 100644 (file)
@@ -33,9 +33,9 @@
 
 // Set to zero to use no double-buffering
 #ifdef __WXMSW__
-#define USE_DOUBLE_BUFFERING 1
+#define wxUSE_DOUBLE_BUFFERING 1
 #else
-#define USE_DOUBLE_BUFFERING 0
+#define wxUSE_DOUBLE_BUFFERING 0
 #endif
 
 #define wxGRID_DRAG_NONE       0
 IMPLEMENT_DYNAMIC_CLASS(wxGenericGrid, wxPanel)
 
 BEGIN_EVENT_TABLE(wxGenericGrid, wxPanel)
-       EVT_SIZE(wxGenericGrid::OnSize)
-       EVT_PAINT(wxGenericGrid::OnPaint)
-       EVT_ERASE_BACKGROUND(wxGenericGrid::OnEraseBackground)
-       EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent)
+    EVT_SIZE(wxGenericGrid::OnSize)
+    EVT_PAINT(wxGenericGrid::OnPaint)
+    EVT_ERASE_BACKGROUND(wxGenericGrid::OnEraseBackground)
+    EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent)
     EVT_TEXT(wxGRID_TEXT_CTRL, wxGenericGrid::OnText)
     EVT_COMMAND_SCROLL(wxGRID_HSCROLL, wxGenericGrid::OnGridScroll)
     EVT_COMMAND_SCROLL(wxGRID_VSCROLL, wxGenericGrid::OnGridScroll)
@@ -418,7 +418,7 @@ void wxGenericGrid::OnPaint(wxPaintEvent& WXUNUSED(event))
   int w, h;
   GetClientSize(&w, &h);
 
-  bool useDoubleBuffering = (bool) USE_DOUBLE_BUFFERING;
+  bool useDoubleBuffering = (bool) wxUSE_DOUBLE_BUFFERING;
   if (useDoubleBuffering)
   {
     // Reuse the old bitmap if possible
@@ -898,15 +898,6 @@ void wxGenericGrid::AdjustScrollbars(void)
   int cw, ch;
   GetClientSize(&cw, &ch);
   
-  // To calculate the number of steps for each scrollbar,
-  // we need to see how much will fit onto the canvas
-  // at the present size. So:
-  // 1) Find the *last* row r1 such that when it's at the top of the
-  //    window, all the remaining rows are visible.
-  // 2) There should therefore be r1 - 1 steps in the scrollbar.
-  // Similarly with columns.
-
-  // IGNORE THE ABOVE, it's crap.
   // We find the view size by seeing how many rows/cols fit on
   // the current view.
   // BUT... this means that the scrollbar should be adjusted every time
@@ -927,16 +918,12 @@ void wxGenericGrid::AdjustScrollbars(void)
   int noHorizSteps = 0;
   int noVertSteps = 0;
   
-  if (m_totalGridWidth <= cw)
+  if (m_totalGridWidth + vertScrollBarWidth <= cw)
     noHorizSteps = 0;
   else
   {
     noHorizSteps = 0;
     int widthCount = 0;
-/*
-    if (GetLabelSize(wxVERTICAL) > 0)
-      noHorizSteps ++;
-*/
 
     int i;
        int nx = 0;
@@ -954,16 +941,12 @@ void wxGenericGrid::AdjustScrollbars(void)
     
     noHorizSteps += nx;
   }
-  if (m_totalGridHeight <= ch)
+  if (m_totalGridHeight + horizScrollBarHeight <= ch)
     noVertSteps = 0;
   else
   {
     noVertSteps = 0;
     int heightCount = 0;
-/*
-    if (GetLabelSize(wxHORIZONTAL) > 0)
-      noVertSteps ++;
-*/
 
     int i;
        int ny = 0;
@@ -981,7 +964,7 @@ void wxGenericGrid::AdjustScrollbars(void)
     noVertSteps += ny;
   }
   
-  if (m_totalGridWidth <= cw)
+  if (m_totalGridWidth + vertScrollBarWidth <= cw)
   {
        if ( m_hScrollBar )
        m_hScrollBar->Show(FALSE);
@@ -989,20 +972,20 @@ void wxGenericGrid::AdjustScrollbars(void)
   }
   else
   {
-       if ( m_hScrollBar )
-       m_hScrollBar->Show(TRUE);
+      if ( m_hScrollBar )
+          m_hScrollBar->Show(TRUE);
   }
 
-  if (m_totalGridHeight <= ch)
+  if (m_totalGridHeight + horizScrollBarHeight <= ch)
   {
-       if ( m_vScrollBar )
-       m_vScrollBar->Show(FALSE);
-    SetScrollPosY(0);
+      if ( m_vScrollBar )
+          m_vScrollBar->Show(FALSE);
+      SetScrollPosY(0);
   }
   else
   {
-       if ( m_vScrollBar )
-       m_vScrollBar->Show(TRUE);
+      if ( m_vScrollBar )
+          m_vScrollBar->Show(TRUE);
   }
 
   UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed
@@ -1017,12 +1000,7 @@ void wxGenericGrid::AdjustScrollbars(void)
   if (m_hScrollBar)
   {
     int nCols = GetCols();
-/*
-    m_hScrollBar->SetPageSize(wxMax(noHorizSteps, 1));
-    m_hScrollBar->SetViewLength(wxMax(noHorizSteps, 1));
-    m_hScrollBar->SetObjectLength(nCols);
-*/
-    m_hScrollBar->SetScrollbar(m_hScrollBar->GetPosition(), wxMax(noHorizSteps, 1), nCols, wxMax(noHorizSteps, 1));
+    m_hScrollBar->SetScrollbar(m_hScrollBar->GetPosition(), wxMax(noHorizSteps, 1), (noHorizSteps == 0) ? 1 : nCols, wxMax(noHorizSteps, 1));
 
     m_hScrollBar->SetSize(m_leftOfSheet, ch - m_scrollWidth -2,
       cw - vertScrollBarWidth - m_leftOfSheet, m_scrollWidth);
@@ -1031,13 +1009,8 @@ void wxGenericGrid::AdjustScrollbars(void)
   if (m_vScrollBar)
   {
     int nRows = GetRows();
-/*
-    m_vScrollBar->SetPageSize(wxMax(noVertSteps, 1));
-    m_vScrollBar->SetViewLength(wxMax(noVertSteps, 1));
-    m_vScrollBar->SetObjectLength(nRows);
-*/
 
-    m_vScrollBar->SetScrollbar(m_vScrollBar->GetPosition(), wxMax(noVertSteps, 1), nRows, wxMax(noVertSteps, 1));
+    m_vScrollBar->SetScrollbar(m_vScrollBar->GetPosition(), wxMax(noVertSteps, 1), (noVertSteps == 0) ? 1 : nRows, wxMax(noVertSteps, 1));
     m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
        m_scrollWidth, ch - m_topOfSheet - horizScrollBarHeight);
   }
@@ -2348,7 +2321,12 @@ void wxGenericGrid::SetGridCursor(int row, int col)
   
   m_wCursorRow = row;
   m_wCursorColumn = col;
-  SetCurrentRect(row, col);
+
+  int cw, ch;
+  GetClientSize(&cw, &ch);
+
+  SetCurrentRect(row, col, cw, ch);
+
   if (m_currentRectVisible)
     HighlightCell(& dc);
 
@@ -2444,6 +2422,7 @@ void wxGenericGrid::OnGridScroll(wxScrollEvent& ev)
   }
 
   win->UpdateDimensions();
+
   win->SetCurrentRect(win->GetCursorRow(), win->GetCursorColumn());
 
   // Because rows and columns can be arbitrary sizes,