]> git.saurik.com Git - wxWidgets.git/commitdiff
generate wxEVT_GRID_{COL,ROW}_SIZE events when the user double clicks the separating...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 29 Apr 2009 21:59:10 +0000 (21:59 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 29 Apr 2009 21:59:10 +0000 (21:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60435 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/grid.h
include/wx/generic/private/grid.h
interface/wx/grid.h
src/generic/grid.cpp

index 0e8c1b9ff33b89f764a91682bf3bb50987683ff6..9490b030c8f53d9db8f453b8251a2ac1a2e0f640 100644 (file)
@@ -1956,10 +1956,10 @@ protected:
     // it was processed (but not vetoed) and 0 if it wasn't processed
     int SendEvent(const wxEventType evtType,
                   int row, int col,
-                  wxMouseEvent& e);
+                  const wxMouseEvent& e);
     int SendEvent(const wxEventType evtType,
                   const wxGridCellCoords& coords,
-                  wxMouseEvent& e)
+                  const wxMouseEvent& e)
         { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); }
     int SendEvent(const wxEventType evtType,
                   int row, int col,
@@ -1971,6 +1971,11 @@ protected:
     int SendEvent(const wxEventType evtType, const wxString& s = wxString())
         { return SendEvent(evtType, m_currentCellCoords, s); }
 
+    // send wxEVT_GRID_{ROW,COL}_SIZE
+    void SendSizeEvent(wxEventType type,
+                       int row, int col,
+                       const wxMouseEvent& mouseEv);
+
     void OnPaint( wxPaintEvent& );
     void OnSize( wxSizeEvent& );
     void OnKeyDown( wxKeyEvent& );
@@ -2084,14 +2089,14 @@ private:
     void DoUpdateResizeColWidth(int w);
     void DoStartMoveCol(int col);
 
-    void DoEndDragResizeRow();
-    void DoEndDragResizeCol(wxMouseEvent *event = NULL);
+    void DoEndDragResizeRow(const wxMouseEvent& event);
+    void DoEndDragResizeCol(const wxMouseEvent& event);
     void DoEndMoveCol(int pos);
 
 
     // common implementations of methods defined for both rows and columns
     void DeselectLine(int line, const wxGridOperations& oper);
-    void DoEndDragResizeLine(const wxGridOperations& oper);
+    bool DoEndDragResizeLine(const wxGridOperations& oper);
     int PosToLinePos(int pos, bool clipToMinMax,
                      const wxGridOperations& oper) const;
     int PosToLine(int pos, bool clipToMinMax,
index e8fc6ec0370982d302bb57c55eee391a0f5e4efb..d0a284428429885e13f59350358353866c53e30f 100644 (file)
@@ -195,7 +195,12 @@ private:
 
         // as this is done by the user we should notify the main program about
         // it
-        GetOwner()->SendEvent(wxEVT_GRID_COL_SIZE, -1, idx);
+
+        // make up a dummy event for the grid event to use -- unfortunately we
+        // can't do anything else here
+        wxMouseEvent e;
+        e.SetState(wxGetMouseState());
+        GetOwner()->SendSizeEvent(wxEVT_GRID_COL_SIZE, -1, idx, e);
     }
 
     // overridden to react to the columns order changes in the customization
@@ -226,7 +231,12 @@ private:
 
     void OnEndResize(wxHeaderCtrlEvent& event)
     {
-        GetOwner()->DoEndDragResizeCol();
+        // we again need to pass a mouse event to be used for the grid event
+        // generation but we don't have it here so use a dummy one as in
+        // UpdateColumnVisibility()
+        wxMouseEvent e;
+        e.SetState(wxGetMouseState());
+        GetOwner()->DoEndDragResizeCol(e);
 
         event.Skip();
     }
index 197ba0b46f41785dd62131c128fd9c69caf37de9..5fbea265acb5f13ed66f1a4138b9a98c3b0b4485 100644 (file)
@@ -3639,18 +3639,16 @@ public:
     This event class contains information about a row/column resize event.
 
     @beginEventTable{wxGridSizeEvent}
-    @event{EVT_GRID_COL_SIZE(func)}
-        The user resized a column by dragging it. Processes a
-        @c wxEVT_GRID_COL_SIZE event type.
-    @event{EVT_GRID_ROW_SIZE(func)}
-        The user resized a row by dragging it. Processes a
-        @c wxEVT_GRID_ROW_SIZE event type.
     @event{EVT_GRID_CMD_COL_SIZE(id, func)}
-        The user resized a column by dragging it; variant taking a window
-        identifier. Processes a @c wxEVT_GRID_COL_SIZE event type.
+        The user resized a column, corresponds to @c wxEVT_GRID_COL_SIZE event
+        type.
     @event{EVT_GRID_CMD_ROW_SIZE(id, func)}
-        The user resized a row by dragging it; variant taking a window
-        identifier. Processes a @c wxEVT_GRID_ROW_SIZE event type.
+        The user resized a row, corresponds to @c wxEVT_GRID_ROW_SIZE event
+        type.
+    @event{EVT_GRID_COL_SIZE(func)}
+        Same as EVT_GRID_CMD_COL_SIZE() but uses `wxID_ANY` id.
+    @event{EVT_GRID_ROW_SIZE(func)}
+        Same as EVT_GRID_CMD_ROW_SIZE() but uses `wxID_ANY` id.
     @endEventTable
 
     @library{wxadv}
index 231630ea0223e243db7fc1ebdf732001a639bdbd..c11346662edeb4f95438f9df4dcde6ea8a2bcca6 100644 (file)
@@ -2969,8 +2969,12 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
         if ( row != wxNOT_FOUND && CanDragRowSize(row) )
         {
             // adjust row height depending on label text
+            //
+            // TODO: generate RESIZING event, see #10754
             AutoSizeRowLabelSize( row );
 
+            SendSizeEvent(wxEVT_GRID_ROW_SIZE, row, -1, event);
+
             ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
             m_dragLastPos = -1;
         }
@@ -2990,14 +2994,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
     else if ( event.LeftUp() )
     {
         if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
-        {
-            DoEndDragResizeRow();
-
-            // Note: we are ending the event *after* doing
-            // default processing in this case
-            //
-            SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
-        }
+            DoEndDragResizeRow(event);
 
         ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
         m_dragLastPos = -1;
@@ -3318,8 +3315,12 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
         else
         {
             // adjust column width depending on label text
+            //
+            // TODO: generate RESIZING event, see #10754
             AutoSizeColLabelSize( colEdge );
 
+            SendSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event);
+
             ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
             m_dragLastPos = -1;
         }
@@ -3332,7 +3333,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
         switch ( m_cursorMode )
         {
             case WXGRID_CURSOR_RESIZE_COL:
-                DoEndDragResizeCol();
+                DoEndDragResizeCol(event);
                 break;
 
             case WXGRID_CURSOR_MOVE_COL:
@@ -3754,17 +3755,12 @@ wxGrid::DoGridCellLeftUp(wxMouseEvent& event, const wxGridCellCoords& coords)
     else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
     {
         ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
-        DoEndDragResizeRow();
-
-        // Note: we are ending the event *after* doing
-        // default processing in this case
-        //
-        SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
+        DoEndDragResizeRow(event);
     }
     else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
     {
         ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
-        DoEndDragResizeCol();
+        DoEndDragResizeCol(event);
     }
 
     m_dragLastPos = -1;
@@ -3894,10 +3890,11 @@ void wxGrid::ProcessGridCellMouseEvent(wxMouseEvent& event)
     }
 }
 
-void wxGrid::DoEndDragResizeLine(const wxGridOperations& oper)
+// this function returns true only if the size really changed
+bool wxGrid::DoEndDragResizeLine(const wxGridOperations& oper)
 {
     if ( m_dragLastPos == -1 )
-        return;
+        return false;
 
     const wxGridOperations& doper = oper.Dual();
 
@@ -3921,9 +3918,12 @@ void wxGrid::DoEndDragResizeLine(const wxGridOperations& oper)
 
     // do resize the line
     const int lineStart = oper.GetLineStartPos(this, m_dragRowOrCol);
+    const int lineSizeOld = oper.GetLineSize(this, m_dragRowOrCol);
     oper.SetLineSize(this, m_dragRowOrCol,
                      wxMax(m_dragLastPos - lineStart,
                            oper.GetMinimalLineSize(this, m_dragRowOrCol)));
+    const bool
+        sizeChanged = oper.GetLineSize(this, m_dragRowOrCol) != lineSizeOld;
 
     m_dragLastPos = -1;
 
@@ -3986,24 +3986,24 @@ void wxGrid::DoEndDragResizeLine(const wxGridOperations& oper)
 
     // show the edit control back again
     ShowCellEditControl();
+
+    return sizeChanged;
 }
 
-void wxGrid::DoEndDragResizeRow()
+void wxGrid::DoEndDragResizeRow(const wxMouseEvent& event)
 {
-    DoEndDragResizeLine(wxGridRowOperations());
+    // TODO: generate RESIZING event, see #10754
+
+    if ( DoEndDragResizeLine(wxGridRowOperations()) )
+        SendSizeEvent(wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event);
 }
 
-void wxGrid::DoEndDragResizeCol(wxMouseEvent *event)
+void wxGrid::DoEndDragResizeCol(const wxMouseEvent& event)
 {
-    DoEndDragResizeLine(wxGridColumnOperations());
+    // TODO: generate RESIZING event, see #10754
 
-    // Note: we are ending the event *after* doing
-    // default processing in this case
-    //
-    if ( event )
-        SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, *event );
-    else
-        SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol );
+    if ( DoEndDragResizeLine(wxGridColumnOperations()) )
+        SendSizeEvent(wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event);
 }
 
 void wxGrid::DoStartMoveCol(int col)
@@ -4177,37 +4177,40 @@ wxGrid::DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t),
     return (m_table->*funcAppend)(num);
 }
 
-//
-// ----- event handlers
-//
+// ----------------------------------------------------------------------------
+// event generation helpers
+// ----------------------------------------------------------------------------
+
+void
+wxGrid::SendSizeEvent(wxEventType type,
+                      int row, int col,
+                      const wxMouseEvent& mouseEv)
+{
+   int rowOrCol = row == -1 ? col : row;
+
+   wxGridSizeEvent gridEvt( GetId(),
+           type,
+           this,
+           rowOrCol,
+           mouseEv.GetX() + GetRowLabelSize(),
+           mouseEv.GetY() + GetColLabelSize(),
+           mouseEv);
+
+   GetEventHandler()->ProcessEvent(gridEvt);
+}
 
 // Generate a grid event based on a mouse event and return:
 //  -1 if the event was vetoed
 //  +1 if the event was processed (but not vetoed)
 //   0 if the event wasn't handled
 int
-wxGrid::SendEvent(const wxEventType type,
+wxGrid::SendEvent(wxEventType type,
                   int row, int col,
-                  wxMouseEvent& mouseEv)
+                  const wxMouseEvent& mouseEv)
 {
    bool claimed, vetoed;
 
-   if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
-   {
-       int rowOrCol = (row == -1 ? col : row);
-
-       wxGridSizeEvent gridEvt( GetId(),
-               type,
-               this,
-               rowOrCol,
-               mouseEv.GetX() + GetRowLabelSize(),
-               mouseEv.GetY() + GetColLabelSize(),
-               mouseEv);
-
-       claimed = GetEventHandler()->ProcessEvent(gridEvt);
-       vetoed = !gridEvt.IsAllowed();
-   }
-   else if ( type == wxEVT_GRID_RANGE_SELECT )
+   if ( type == wxEVT_GRID_RANGE_SELECT )
    {
        // Right now, it should _never_ end up here!
        wxGridRangeSelectEvent gridEvt( GetId(),
@@ -4270,28 +4273,13 @@ wxGrid::SendEvent(const wxEventType type,
 int
 wxGrid::SendEvent(const wxEventType type, int row, int col, const wxString& s)
 {
-   bool claimed, vetoed;
-
-    if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
-    {
-        int rowOrCol = (row == -1 ? col : row);
-
-        wxGridSizeEvent gridEvt( GetId(), type, this, rowOrCol );
-
-        claimed = GetEventHandler()->ProcessEvent(gridEvt);
-        vetoed  = !gridEvt.IsAllowed();
-    }
-    else
-    {
-        wxGridEvent gridEvt( GetId(), type, this, row, col );
-        gridEvt.SetString(s);
+    wxGridEvent gridEvt( GetId(), type, this, row, col );
+    gridEvt.SetString(s);
 
-        claimed = GetEventHandler()->ProcessEvent(gridEvt);
-        vetoed  = !gridEvt.IsAllowed();
-     }
+    const bool claimed = GetEventHandler()->ProcessEvent(gridEvt);
 
     // A Veto'd event may not be `claimed' so test this first
-    if (vetoed)
+    if ( !gridEvt.IsAllowed() )
         return -1;
 
     return claimed ? 1 : 0;