Ticket #15077: grid_autosize.patch

File grid_autosize.patch, 6.8 KB (added by oneeyeman, 5 years ago)

Implementation patch

  • wxWidgets/include/wx/generic/grid.h

    diff -bru wxWidgets/include/wx/generic/grid.h /mnt/winxp/wxWidgets/include/wx/generic/grid.h
    old new  
    9292class WXDLLIMPEXP_FWD_ADV wxGridWindow;
    9393class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry;
    9494class WXDLLIMPEXP_FWD_ADV wxGridSelection;
    95 
     95class WXDLLIMPEXP_FWD_ADV wxGridSizeEvent;
    9696class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl;
    9797class WXDLLIMPEXP_FWD_CORE wxCheckBox;
    9898class WXDLLIMPEXP_FWD_CORE wxComboBox;
     
    21222122                           const wxMouseEvent& mouseEv);
    21232123
    21242124    void OnPaint( wxPaintEvent& );
     2125    void OnAutoSizeColumn( wxGridSizeEvent &event );
    21252126    void OnSize( wxSizeEvent& );
    21262127    void OnKeyDown( wxKeyEvent& );
    21272128    void OnKeyUp( wxKeyEvent& );
     
    26052606wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent );
    26062607wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent );
    26072608wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
     2609wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_AUTO_COL_SIZE, wxGridSizeEvent );
    26082610wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent );
    26092611wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGING, wxGridEvent );
    26102612wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGED, wxGridEvent );
     
    26562658#define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn)  wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
    26572659#define EVT_GRID_CMD_ROW_SIZE(id, fn)            wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
    26582660#define EVT_GRID_CMD_COL_SIZE(id, fn)            wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
     2661#define EVT_GRID_CMD_AUTO_COL_SIZE(id, fn)       wx__DECLARE_GRIDSIZEEVT(AUTO_COL_SIZE, id, fn)
    26592662#define EVT_GRID_CMD_COL_MOVE(id, fn)            wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
    26602663#define EVT_GRID_CMD_COL_SORT(id, fn)            wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
    26612664#define EVT_GRID_CMD_RANGE_SELECT(id, fn)        wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
     
    26802683#define EVT_GRID_LABEL_RIGHT_DCLICK(fn)  EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
    26812684#define EVT_GRID_ROW_SIZE(fn)            EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
    26822685#define EVT_GRID_COL_SIZE(fn)            EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
     2686#define EVT_GRID_AUTO_COL_SIZE(fn)       EVT_GRID_CMD_AUTO_COL_SIZE(wxID_ANY, fn)
    26832687#define EVT_GRID_COL_MOVE(fn)            EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
    26842688#define EVT_GRID_COL_SORT(fn)            EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
    26852689#define EVT_GRID_RANGE_SELECT(fn)        EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
  • wxWidgets/interface/wx/grid.h

    diff -bru wxWidgets/interface/wx/grid.h /mnt/winxp/wxWidgets/interface/wx/grid.h
    old new  
    47074707        type.
    47084708    @event{EVT_GRID_COL_SIZE(func)}
    47094709        Same as EVT_GRID_CMD_COL_SIZE() but uses `wxID_ANY` id.
     4710    @event{EVT_GRID_AUTO_COL_SIZE(func)}
     4711        This event is sent when the user double clicks the row divider. Default implementation 
     4712        sizes the column to fit the column label. Corresponds to @c wxEVT_GRID_AUTO_COL_SIZE event
     4713        This event is available since wx2.9.5
    47104714    @event{EVT_GRID_ROW_SIZE(func)}
    47114715        Same as EVT_GRID_CMD_ROW_SIZE() but uses `wxID_ANY` id.
    47124716    @endEventTable
     
    49204924wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
    49214925wxEventType wxEVT_GRID_ROW_SIZE;
    49224926wxEventType wxEVT_GRID_COL_SIZE;
     4927wxEventType wxEVT_GRID_AUTO_COL_SIZE;
    49234928wxEventType wxEVT_GRID_RANGE_SELECT;
    49244929wxEventType wxEVT_GRID_CELL_CHANGING;
    49254930wxEventType wxEVT_GRID_CELL_CHANGED;
  • wxWidgets/samples/grid/griddemo.cpp

    diff -bru wxWidgets/samples/grid/griddemo.cpp /mnt/winxp/wxWidgets/samples/grid/griddemo.cpp
    old new  
    226226    EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick )
    227227    EVT_GRID_ROW_SIZE( GridFrame::OnRowSize )
    228228    EVT_GRID_COL_SIZE( GridFrame::OnColSize )
     229    EVT_GRID_AUTO_COL_SIZE( GridFrame::OnColAutoSize )
    229230    EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
    230231    EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
    231232    EVT_GRID_CELL_CHANGING( GridFrame::OnCellValueChanging )
     
    11741175    ev.Skip();
    11751176}
    11761177
     1178void GridFrame::OnColAutoSize( wxGridSizeEvent &event )
     1179{
     1180    grid->AutoSizeColumn( event.GetRowOrCol() );
     1181}
    11771182
    11781183void GridFrame::OnSelectCell( wxGridEvent& ev )
    11791184{
  • wxWidgets/samples/grid/griddemo.h

    diff -bru wxWidgets/samples/grid/griddemo.h /mnt/winxp/wxWidgets/samples/grid/griddemo.h
    old new  
    9898    void OnCellLeftClick( wxGridEvent& );
    9999    void OnRowSize( wxGridSizeEvent& );
    100100    void OnColSize( wxGridSizeEvent& );
     101    void OnColAutoSize( wxGridSizeEvent& );
    101102    void OnSelectCell( wxGridEvent& );
    102103    void OnRangeSelected( wxGridRangeSelectEvent& );
    103104    void OnCellValueChanging( wxGridEvent& );
  • wxWidgets/src/generic/grid.cpp

    diff -bru wxWidgets/src/generic/grid.cpp /mnt/winxp/wxWidgets/src/generic/grid.cpp
    old new  
    146146wxDEFINE_EVENT( wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent );
    147147wxDEFINE_EVENT( wxEVT_GRID_ROW_SIZE, wxGridSizeEvent );
    148148wxDEFINE_EVENT( wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
     149wxDEFINE_EVENT( wxEVT_GRID_AUTO_COL_SIZE, wxGridSizeEvent );
    149150wxDEFINE_EVENT( wxEVT_GRID_COL_MOVE, wxGridEvent );
    150151wxDEFINE_EVENT( wxEVT_GRID_COL_SORT, wxGridEvent );
    151152wxDEFINE_EVENT( wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent );
     
    21522153/////////////////////////////////////////////////////////////////////
    21532154
    21542155BEGIN_EVENT_TABLE( wxGrid, wxScrolledWindow )
     2156    EVT_GRID_AUTO_COL_SIZE( wxGrid::OnAutoSizeColumn )
    21552157    EVT_PAINT( wxGrid::OnPaint )
    21562158    EVT_SIZE( wxGrid::OnSize )
    21572159    EVT_KEY_DOWN( wxGrid::OnKeyDown )
     
    37203722            // adjust column width depending on label text
    37213723            //
    37223724            // TODO: generate RESIZING event, see #10754
    3723             AutoSizeColLabelSize( colEdge );
     3725            SendGridSizeEvent(wxEVT_GRID_AUTO_COL_SIZE, -1, colEdge, event);
     3726//            AutoSizeColLabelSize( colEdge );
    37243727
    37253728            SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event);
    37263729
     
    47544757    return claimed ? 1 : 0;
    47554758}
    47564759
     4760void wxGrid::OnAutoSizeColumn(wxGridSizeEvent &event)
     4761{
     4762    AutoSizeColumn( event.GetRowOrCol() );
     4763}
     4764
    47574765void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
    47584766{
    47594767    // needed to prevent zillions of paint events on MSW