diff --git a/samples/animate/anitest.cpp b/samples/animate/anitest.cpp index 29f49c5ed0..edd1f669e2 100644 --- a/samples/animate/anitest.cpp +++ b/samples/animate/anitest.cpp @@ -115,8 +115,7 @@ MyFrame::MyFrame(wxWindow *parent, const wxPoint& pos, const wxSize& size, const long style) - : wxFrame(parent, id, title, pos, size, - style | wxNO_FULL_REPAINT_ON_RESIZE) + : wxFrame(parent, id, title, pos, size, style) { SetIcon(wxICON(sample)); diff --git a/samples/collpane/collpane.cpp b/samples/collpane/collpane.cpp index c80e18fd41..7b9c0bb061 100644 --- a/samples/collpane/collpane.cpp +++ b/samples/collpane/collpane.cpp @@ -172,8 +172,7 @@ wxEND_EVENT_TABLE() // My frame constructor MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, "wxCollapsiblePane sample", - wxDefaultPosition, wxSize(420, 300), - wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) + wxDefaultPosition, wxSize(420, 300)) { SetIcon(wxICON(sample)); diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 5eb2730ea0..e3a33b19ca 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -524,7 +524,7 @@ wxEND_EVENT_TABLE() MyCanvas::MyCanvas(MyFrame *parent) : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE) + wxHSCROLL | wxVSCROLL) { m_owner = parent; m_show = File_ShowDefault; @@ -2162,8 +2162,7 @@ wxEND_EVENT_TABLE() // frame constructor MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size, - wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) + : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size) { // set the frame icon SetIcon(wxICON(sample)); diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index cdafb201ab..ce39390099 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -363,9 +363,7 @@ void MyFrame::InitToolBar(wxToolBar* toolBar) // Define a constructor for my canvas MyCanvas::MyCanvas(wxFrame *parent, const wxPoint& pos, const wxSize& size) : wxScrolledWindow(parent, wxID_ANY, pos, size, - wxSUNKEN_BORDER | - wxNO_FULL_REPAINT_ON_RESIZE | - wxVSCROLL | wxHSCROLL), + wxSUNKEN_BORDER | wxVSCROLL | wxHSCROLL), MenuEventLogger("canvas", parent) { diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index bcc0476e69..d1382516aa 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -954,15 +954,10 @@ static const wxString _fs_windowstyle_labels[] = { "wxTRANSPARENT_WINDOW", "wxTAB_TRAVERSAL", "wxWANTS_CHARS", -#if wxNO_FULL_REPAINT_ON_RESIZE - "wxNO_FULL_REPAINT_ON_RESIZE", -#endif "wxVSCROLL", "wxALWAYS_SHOW_SB", "wxCLIP_CHILDREN", -#if wxFULL_REPAINT_ON_RESIZE "wxFULL_REPAINT_ON_RESIZE", -#endif }; static const long _fs_windowstyle_values[] = { @@ -974,15 +969,10 @@ static const long _fs_windowstyle_values[] = { wxTRANSPARENT_WINDOW, wxTAB_TRAVERSAL, wxWANTS_CHARS, -#if wxNO_FULL_REPAINT_ON_RESIZE - wxNO_FULL_REPAINT_ON_RESIZE, -#endif wxVSCROLL, wxALWAYS_SHOW_SB, wxCLIP_CHILDREN, -#if wxFULL_REPAINT_ON_RESIZE wxFULL_REPAINT_ON_RESIZE -#endif }; static const wxString _fs_framestyle_labels[] = { @@ -1982,7 +1972,7 @@ void FormMain::CreateGrid( int style, int extraStyle ) FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, -1, title, pos, size, (wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCAPTION| - wxTAB_TRAVERSAL|wxCLOSE_BOX|wxNO_FULL_REPAINT_ON_RESIZE) ) + wxTAB_TRAVERSAL|wxCLOSE_BOX) ) { SetIcon(wxICON(sample)); diff --git a/samples/sashtest/sashtest.cpp b/samples/sashtest/sashtest.cpp index cc6ee1590c..16d5e188bb 100644 --- a/samples/sashtest/sashtest.cpp +++ b/samples/sashtest/sashtest.cpp @@ -46,7 +46,6 @@ bool MyApp::OnInit(void) frame = new MyFrame(NULL, wxID_ANY, "Sash Demo", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE | - wxNO_FULL_REPAINT_ON_RESIZE | wxHSCROLL | wxVSCROLL); // Give it an icon (this is ignored in MDI mode: uses resources) @@ -223,9 +222,7 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) { // Make another frame, containing a canvas MyChild *subframe = new MyChild(frame, "Canvas Frame", - wxPoint(10, 10), wxSize(300, 300), - wxDEFAULT_FRAME_STYLE | - wxNO_FULL_REPAINT_ON_RESIZE); + wxPoint(10, 10), wxSize(300, 300)); subframe->SetTitle(wxString::Format("Canvas Frame %d", winNumber)); winNumber ++; @@ -282,8 +279,7 @@ wxEND_EVENT_TABLE() // Define a constructor for my canvas MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size) - : wxScrolledWindow(parent, wxID_ANY, pos, size, - wxSUNKEN_BORDER | wxNO_FULL_REPAINT_ON_RESIZE) + : wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER) { SetBackgroundColour(* wxWHITE); } @@ -350,9 +346,8 @@ wxBEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) EVT_MENU(SASHTEST_CHILD_QUIT, MyChild::OnQuit) wxEND_EVENT_TABLE() -MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, -const long style): - wxMDIChildFrame(parent, wxID_ANY, title, pos, size, style) +MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size): + wxMDIChildFrame(parent, wxID_ANY, title, pos, size) { canvas = NULL; my_children.Append(this); diff --git a/samples/sashtest/sashtest.h b/samples/sashtest/sashtest.h index 81e7a3c9ca..af940c2a56 100644 --- a/samples/sashtest/sashtest.h +++ b/samples/sashtest/sashtest.h @@ -54,7 +54,7 @@ class MyChild: public wxMDIChildFrame { public: MyCanvas *canvas; - MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style); + MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size); ~MyChild(void); void OnActivate(wxActivateEvent& event); void OnQuit(wxCommandEvent& event); diff --git a/samples/splitter/splitter.cpp b/samples/splitter/splitter.cpp index a91357af61..523aa5d07a 100644 --- a/samples/splitter/splitter.cpp +++ b/samples/splitter/splitter.cpp @@ -214,8 +214,7 @@ wxEND_EVENT_TABLE() // My frame constructor MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, "wxSplitterWindow sample", - wxDefaultPosition, wxSize(420, 300), - wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) + wxDefaultPosition, wxSize(420, 300)) { SetIcon(wxICON(sample)); @@ -551,7 +550,7 @@ void MySplitterWindow::OnUnsplitEvent(wxSplitterEvent& event) MyCanvas::MyCanvas(wxWindow* parent, bool mirror) : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE) + wxHSCROLL | wxVSCROLL) { m_mirror = mirror; SetScrollbars(20, 20, 5, 5); diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index bb77b0cbbc..9c4f95c11b 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -291,8 +291,7 @@ wxBEGIN_EVENT_TABLE (AppFrame, wxFrame) wxEND_EVENT_TABLE () AppFrame::AppFrame (const wxString &title) - : wxFrame ((wxFrame *)NULL, wxID_ANY, title, wxDefaultPosition, wxSize(750,550), - wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) + : wxFrame ((wxFrame *)NULL, wxID_ANY, title, wxDefaultPosition, wxSize(750,550)) { SetIcon(wxICON(sample)); diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 0c42388dac..90e1a3d4c8 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -98,7 +98,7 @@ public: const wxString& title = "wxToolBar Sample", const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE); + long style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN); virtual ~MyFrame(); void PopulateToolbar(wxToolBarBase* toolBar); diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index fbdc36e528..06bc4a7ac5 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -1311,7 +1311,6 @@ WidgetsPage::WidgetsPage(WidgetsBookCtrl *book, const char *const icon[]) : wxPanel(book, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxNO_FULL_REPAINT_ON_RESIZE | wxCLIP_CHILDREN | wxTAB_TRAVERSAL) { diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 7ae8040aef..d62407a637 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -9400,47 +9400,65 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction) wxCoord w, h; dc.SetFont( GetLabelFont() ); + bool noContent = (extentMax == 0); bool addMargin = true; if ( column ) { if ( m_useNativeHeader ) { - w = GetGridColHeader()->GetColumnTitleWidth(colOrRow); + wxHeaderCtrl* header = GetGridColHeader(); + w = header->GetColumnTitleWidth(colOrRow); // GetColumnTitleWidth already adds margins internally. addMargin = false; h = 0; + + // GetColumnTitleWidth uses GetTextExtent and not + // GetMultiLineTextExtent so use the same funtion. + if ( header->GetTextExtent(GetColLabelValue(colOrRow)).x > 0 ) + noContent = false; } else { dc.GetMultiLineTextExtent( GetColLabelValue(colOrRow), &w, &h ); if ( GetColLabelTextOrientation() == wxVERTICAL ) w = h; + + noContent = noContent && (w == 0); } } else { dc.GetMultiLineTextExtent( GetRowLabelValue(colOrRow), &w, &h ); + noContent = noContent && (h == 0); } - extent = column ? w : h; - if ( extent > extentMax ) - extentMax = extent; - - if ( !extentMax ) + if ( noContent ) { // empty column - give default extent (notice that if extentMax is less // than default extent but != 0, it's OK) extentMax = column ? m_defaultColWidth : m_defaultRowHeight; } - else if ( addMargin ) + else { - // leave some space around text - if ( column ) - extentMax += 10; - else - extentMax += 6; + const int margin = column ? 10 : 6; + + // The current extentMax is the max extent of columns/rows values + // so always add margin. + extentMax += margin; + + // The current extent is the extent of the column/row title. + extent = column ? w : h; + + // Add the margin to the current extent only if needed. + if ( addMargin ) + extent += margin; + + // Find out the final max extent when the margin affected to the max extent + // and the current extent. + if ( extent > extentMax ) + extentMax = extent; } if ( column ) diff --git a/src/propgrid/manager.cpp b/src/propgrid/manager.cpp index de2c1ba9d7..60a7613ce6 100644 --- a/src/propgrid/manager.cpp +++ b/src/propgrid/manager.cpp @@ -505,7 +505,6 @@ void wxPropertyGridManager::Init1() // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager. #define wxPG_MAN_PROPGRID_FORCED_FLAGS ( wxBORDER_THEME | \ - wxNO_FULL_REPAINT_ON_RESIZE| \ wxCLIP_CHILDREN) // Which flags can be passed to underlying wxPropertyGrid. diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 8d7f9fe671..5ee3fe180f 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -16,9 +16,11 @@ #ifndef WX_PRECOMP #include "wx/app.h" + #include "wx/dcclient.h" #endif // WX_PRECOMP #include "wx/grid.h" +#include "wx/headerctrl.h" #include "testableframe.h" #include "asserthelper.h" #include "wx/uiaction.h" @@ -70,18 +72,21 @@ private: WXUISIM_TEST( ReadOnly ); WXUISIM_TEST( ResizeScrolledHeader ); WXUISIM_TEST( ColumnMinWidth ); + WXUISIM_TEST( AutoSizeColumn ); CPPUNIT_TEST( PseudoTest_NativeHeader ); NONGTK_TEST( LabelClick ); NONGTK_TEST( SortClick ); CPPUNIT_TEST( ColumnOrder ); WXUISIM_TEST( ResizeScrolledHeader ); WXUISIM_TEST( ColumnMinWidth ); + WXUISIM_TEST( AutoSizeColumn ); CPPUNIT_TEST( DeleteAndAddRowCol ); CPPUNIT_TEST( PseudoTest_NativeLabels ); NONGTK_TEST( LabelClick ); NONGTK_TEST( SortClick ); CPPUNIT_TEST( ColumnOrder ); WXUISIM_TEST( WindowAsEditorControl ); + WXUISIM_TEST( AutoSizeColumn ); CPPUNIT_TEST_SUITE_END(); void CellEdit(); @@ -108,10 +113,23 @@ private: void WindowAsEditorControl(); void ResizeScrolledHeader(); void ColumnMinWidth(); + void AutoSizeColumn(); void PseudoTest_NativeHeader() { ms_nativeheader = true; } void PseudoTest_NativeLabels() { ms_nativeheader = false; ms_nativelabels = true; } + // The helper function to determine the width of the column label depending + // on whether the native column is used. + int GetColumnLabelWidth(wxClientDC& dc, int col, int margin) const + { + if (ms_nativeheader) + return m_grid->GetGridColHeader()->GetColumnTitleWidth(col); + + int w, h; + dc.GetMultiLineTextExtent(m_grid->GetColLabelValue(col), &w, &h); + return w + margin; + } + static bool ms_nativeheader; static bool ms_nativelabels; @@ -950,4 +968,91 @@ void GridTestCase::ColumnMinWidth() #endif } +void GridTestCase::AutoSizeColumn() +{ + // Hardcoded margin for columns. + const int margin = 10; + int maxWidth; + + wxGridCellAttr *attr = m_grid->GetOrCreateCellAttr(0, 0); + wxGridCellRenderer *renderer = attr->GetRenderer(m_grid, 0, 0); + REQUIRE(renderer != NULL); + + wxClientDC dcCell(m_grid->GetGridWindow()); + + wxClientDC dcLabel(m_grid->GetGridWindow()); + dcLabel.SetFont(m_grid->GetLabelFont()); + + const wxString shortStr = "W"; + const wxString mediumStr = "WWWW"; + const wxString longStr = "WWWWWWWW"; + const wxString multilineStr = mediumStr + "\n" + longStr; + + SECTION("Empty column") + { + m_grid->SetColLabelValue(0, wxEmptyString); + maxWidth = m_grid->GetDefaultColSize(); + } + + SECTION("Autosize by the title") + { + m_grid->SetColLabelValue(0, mediumStr); + maxWidth = GetColumnLabelWidth(dcLabel, 0, margin); + } + + SECTION("Autosize by cells") + { + m_grid->SetColLabelValue(0, wxEmptyString); + m_grid->SetCellValue(0, 0, mediumStr); + m_grid->SetCellValue(1, 0, shortStr); + m_grid->SetCellValue(3, 0, longStr); + maxWidth = renderer->GetBestWidth(*m_grid, *attr, dcCell, 3, 0, + m_grid->GetRowHeight(3)) + + margin; + } + + SECTION("Autosize with the longest title") + { + m_grid->SetColLabelValue(0, multilineStr); + m_grid->SetCellValue(0, 0, mediumStr); + m_grid->SetCellValue(1, 0, shortStr); + maxWidth = GetColumnLabelWidth(dcLabel, 0, margin); + } + + SECTION("Autosize with the longest cell") + { + m_grid->SetColLabelValue(0, mediumStr); + m_grid->SetCellValue(0, 0, mediumStr); + m_grid->SetCellValue(1, 0, shortStr); + m_grid->SetCellValue(3, 0, multilineStr); + maxWidth = renderer->GetBestWidth(*m_grid, *attr, dcCell, 3, 0, + m_grid->GetRowHeight(3)) + + margin; + } + + SECTION("Autosize with the same values") + { + m_grid->SetColLabelValue(0, mediumStr); + m_grid->SetCellValue(0, 0, mediumStr); + m_grid->SetCellValue(1, 0, mediumStr); + m_grid->SetCellValue(3, 0, mediumStr); + + const int labelWidth = GetColumnLabelWidth(dcLabel, 0, margin); + + const int cellWidth = + renderer->GetBestWidth(*m_grid, *attr, dcCell, 3, 0, + m_grid->GetRowHeight(3)) + + margin; + + // We can't be sure which size will be greater because of different fonts + // so just calculate the maximum width. + maxWidth = wxMax(labelWidth, cellWidth); + } + + m_grid->AutoSizeColumn(0); + + wxYield(); + CHECK(m_grid->GetColSize(0) == maxWidth); +} + #endif //wxUSE_GRID