Merge branch 'grid-select-none'

Add wxGrid::wxGridSelectNone selection mode.

Closes https://github.com/wxWidgets/wxWidgets/pull/2100
This commit is contained in:
Vadim Zeitlin
2020-10-31 17:16:34 +01:00
31 changed files with 133 additions and 119 deletions

View File

@@ -132,13 +132,6 @@ if(NOT MSVC)
endif()
endif()
wx_check_c_source_compiles(
"#define test(fmt, ...) printf(fmt, __VA_ARGS__)
test(\"%s %d %p\", \"test\", 1, 0);"
HAVE_VARIADIC_MACROS
stdio.h
)
#TODO: wxNO_VARIADIC_MACROS
if(wxUSE_STL AND CMAKE_CXX_STANDARD EQUAL 98)
wx_check_cxx_source_compiles("
std::vector<int> moo;

View File

@@ -164,6 +164,15 @@ set(TEST_GUI_DATA
image/horse_box_average_100x100.png
image/horse_box_average_150x150.png
image/horse_box_average_300x300.png
image/paste_input_background.png
image/paste_input_black.png
image/paste_input_overlay_transparent_border_opaque_square.png
image/paste_input_overlay_transparent_border_semitransparent_circle.png
image/paste_input_overlay_transparent_border_semitransparent_square.png
image/paste_result_background_plus_circle_plus_square.png
image/paste_result_background_plus_overlay_transparent_border_opaque_square.png
image/paste_result_background_plus_overlay_transparent_border_semitransparent_square.png
image/paste_result_no_background_square_over_circle.png
intl/ja/internat.mo
intl/ja/internat.po
)

View File

@@ -1457,7 +1457,8 @@ public:
wxGridSelectCells = 0, // allow selecting anything
wxGridSelectRows = 1, // allow selecting only entire rows
wxGridSelectColumns = 2, // allow selecting only entire columns
wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns
wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns,
wxGridSelectNone = 4 // disallow selecting anything
};
// Different behaviour of the TAB key when the end (or the beginning, for

View File

@@ -2945,7 +2945,16 @@ public:
@since 2.9.1
*/
wxGridSelectRowsOrColumns
wxGridSelectRowsOrColumns,
/**
The selection mode allowing no selections to be made at all.
The user won't be able to select any cells in this mode.
@since 3.1.5
*/
wxGridSelectNone
};
/**

View File

@@ -316,6 +316,7 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame )
EVT_MENU( ID_SELROWS, GridFrame::SelectRows )
EVT_MENU( ID_SELCOLS, GridFrame::SelectCols )
EVT_MENU( ID_SELROWSORCOLS, GridFrame::SelectRowsOrCols )
EVT_MENU( ID_SELNONE, GridFrame::SelectNone )
EVT_MENU( ID_FREEZE_OR_THAW, GridFrame::FreezeOrThaw )
@@ -536,6 +537,7 @@ GridFrame::GridFrame()
selectionMenu->Append( ID_SELROWS, "Select &rows" );
selectionMenu->Append( ID_SELCOLS, "Select col&umns" );
selectionMenu->Append( ID_SELROWSORCOLS, "Select rows &or columns" );
selectionMenu->Append( ID_SELNONE, "&Disallow selection" );
wxMenu *autosizeMenu = new wxMenu;
autosizeMenu->Append( ID_SIZE_ROW, "Selected &row data" );
@@ -1443,6 +1445,11 @@ void GridFrame::SelectRowsOrCols( wxCommandEvent& WXUNUSED(ev) )
grid->SetSelectionMode( wxGrid::wxGridSelectRowsOrColumns );
}
void GridFrame::SelectNone( wxCommandEvent& WXUNUSED(ev) )
{
grid->SetSelectionMode( wxGrid::wxGridSelectNone );
}
void GridFrame::FreezeOrThaw(wxCommandEvent& ev)
{
if ( ev.IsChecked() )

View File

@@ -76,6 +76,7 @@ class GridFrame : public wxFrame
void SelectRows( wxCommandEvent& );
void SelectCols( wxCommandEvent& );
void SelectRowsOrCols( wxCommandEvent& );
void SelectNone( wxCommandEvent& );
void FreezeOrThaw( wxCommandEvent& );
@@ -192,6 +193,7 @@ public:
ID_SELROWS,
ID_SELCOLS,
ID_SELROWSORCOLS,
ID_SELNONE,
ID_SET_CELL_FG_COLOUR,
ID_SET_CELL_BG_COLOUR,
ID_VTABLE,

View File

@@ -20,10 +20,7 @@
#define wxID_NO 5104
#include "resource.h"
#if !defined(__GNUWIN32__) && !defined(__BORLANDC__)
#include <commctrl.h>
#endif
#include <windows.h>
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////

View File

@@ -35,45 +35,45 @@ wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit(void)
{
if ( !wxApp::OnInit() )
return false;
if ( !wxApp::OnInit() )
return false;
// Create the main frame window
MyFrame *frame = new MyFrame(NULL, wxID_ANY, "wxWidgets Native Dialog Sample", wxPoint(0, 0), wxSize(300, 250));
// Create the main frame window
MyFrame* frame = new MyFrame(NULL, wxID_ANY, "wxWidgets Native Dialog Sample", wxDefaultPosition, wxDefaultSize);
#if wxUSE_STATUSBAR
// Give it a status line
frame->CreateStatusBar(2);
// Give it a status line
frame->CreateStatusBar(2);
#endif // wxUSE_STATUSBAR
// Make a menubar
wxMenu *file_menu = new wxMenu;
// Make a menubar
wxMenu* file_menu = new wxMenu;
file_menu->Append(RESOURCE_TEST1, "&Dialog box test", "Test dialog box resource");
file_menu->Append(RESOURCE_QUIT, "E&xit", "Quit program");
file_menu->Append(RESOURCE_TEST1, "&Dialog box test", "Test dialog box resource");
file_menu->Append(RESOURCE_QUIT, "E&xit", "Quit program");
wxMenuBar *menu_bar = new wxMenuBar;
wxMenuBar* menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, "&File");
menu_bar->Append(file_menu, "&File");
// Associate the menu bar with the frame
frame->SetMenuBar(menu_bar);
// Associate the menu bar with the frame
frame->SetMenuBar(menu_bar);
// Make a panel
frame->panel = new wxWindow(frame, wxID_ANY, wxPoint(0, 0), wxSize(400, 400), 0, "MyMainFrame");
frame->Show(true);
// Make a panel
frame->panel = new wxWindow(frame, wxID_ANY);
frame->Show(true);
return true;
return true;
}
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
EVT_MENU(RESOURCE_TEST1, MyFrame::OnTest1)
EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
EVT_MENU(RESOURCE_TEST1, MyFrame::OnTest1)
wxEND_EVENT_TABLE()
// Define my frame constructor
MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size):
wxFrame(parent, id, title, pos, size)
MyFrame::MyFrame(wxWindow* parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size) :
wxFrame(parent, id, title, pos, size)
{
SetIcon(wxICON(sample));
@@ -82,19 +82,19 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
Close(true);
}
void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event))
{
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
MyDialog dialog;
if (dialog.LoadNativeDialog(this, "dialog1"))
if ( dialog.LoadNativeDialog(this, "dialog1") )
{
dialog.ShowModal();
}
#else
wxMessageBox("No native dialog support","Platform limitation");
wxMessageBox("No native dialog support", "Platform limitation");
#endif
}

View File

@@ -9,31 +9,31 @@
/////////////////////////////////////////////////////////////////////////////
// Define a new application
class MyApp: public wxApp
class MyApp : public wxApp
{
public:
MyApp(void){}
public:
MyApp(void) {}
bool OnInit(void) wxOVERRIDE;
};
class MyFrame: public wxFrame
class MyFrame : public wxFrame
{
public:
wxWindow *panel;
MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size);
public:
wxWindow* panel;
MyFrame(wxWindow* parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnTest1(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
wxDECLARE_EVENT_TABLE();
};
class MyDialog : public wxDialog
{
public:
public:
void OnOk(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
wxDECLARE_EVENT_TABLE();
};
#define RESOURCE_QUIT 4

View File

@@ -74,6 +74,13 @@ static const int PADDING_RIGHTLEFT = 3;
namespace
{
// Flags for Walker() function defined below.
enum WalkFlags
{
Walk_All, // Visit all items.
Walk_ExpandedOnly // Visit only expanded items.
};
// The column is either the index of the column to be used for sorting or one
// of the special values in this enum:
enum
@@ -854,7 +861,8 @@ public:
// Some useful functions for row and item mapping
wxDataViewItem GetItemByRow( unsigned int row ) const;
int GetRowByItem( const wxDataViewItem & item ) const;
int GetRowByItem( const wxDataViewItem & item,
WalkFlags flags = Walk_All ) const;
wxDataViewTreeNode * GetTreeNodeByRow( unsigned int row ) const;
// We did not need this temporarily
@@ -2993,6 +3001,10 @@ void wxDataViewHeaderWindow::FinishEditing()
//-----------------------------------------------------------------------------
// Helper class for do operation on the tree node
//-----------------------------------------------------------------------------
namespace
{
class DoJob
{
public:
@@ -3010,7 +3022,8 @@ public:
virtual int operator() ( wxDataViewTreeNode * node ) = 0;
};
bool Walker( wxDataViewTreeNode * node, DoJob & func )
bool
Walker(wxDataViewTreeNode * node, DoJob & func, WalkFlags flags = Walk_All)
{
wxCHECK_MSG( node, false, "can't walk NULL node" );
@@ -3024,7 +3037,7 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func )
break;
}
if ( node->HasChildren() )
if ( node->HasChildren() && (flags != Walk_ExpandedOnly || node->IsOpen()) )
{
const wxDataViewTreeNodes& nodes = node->GetChildNodes();
@@ -3032,7 +3045,7 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func )
i != nodes.end();
++i )
{
if ( Walker(*i, func) )
if ( Walker(*i, func, flags) )
return true;
}
}
@@ -3040,6 +3053,8 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func )
return false;
}
} // anonymous namespace
bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
{
if (IsVirtualList())
@@ -3060,14 +3075,6 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData
parentNode->SetHasChildren(true);
// If the parent node isn't and hadn't been opened yet, we don't have
// anything to do here, all the items will be added to it when it's
// opened for the first time.
if ( !parentNode->IsOpen() && parentNode->GetChildNodes().empty() )
{
return true;
}
wxDataViewTreeNode *itemNode = new wxDataViewTreeNode(parentNode, item);
itemNode->SetHasChildren(GetModel()->IsContainer(item));
@@ -4137,7 +4144,7 @@ wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item,
xpos = 0;
}
const int row = GetRowByItem(item);
const int row = GetRowByItem(item, Walk_ExpandedOnly);
if ( row == -1 )
{
// This means the row is currently not visible at all.
@@ -4238,7 +4245,9 @@ private:
};
int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) const
int
wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item,
WalkFlags flags) const
{
const wxDataViewModel * model = GetModel();
if( model == NULL )
@@ -4268,7 +4277,7 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) const
// the parent chain was created by adding the deepest parent first.
// so if we want to start at the root node, we have to iterate backwards through the vector
ItemToRowJob job( item, parentChain.rbegin() );
if ( !Walker( m_root, job ) )
if ( !Walker( m_root, job, flags ) )
return -1;
return job.GetResult();

View File

@@ -4631,6 +4631,7 @@ wxGrid::DoGridCellLeftDown(wxMouseEvent& event,
// mode and is compatible with 2.8 behaviour (see #12062).
switch ( m_selection->GetSelectionMode() )
{
case wxGridSelectNone:
case wxGridSelectCells:
case wxGridSelectRowsOrColumns:
// nothing to do in these cases

View File

@@ -98,6 +98,13 @@ void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode )
if (selmode == m_selectionMode)
return;
if (selmode == wxGrid::wxGridSelectNone)
{
ClearSelection();
m_selectionMode = selmode;
return;
}
if ( m_selectionMode != wxGrid::wxGridSelectCells )
{
// if changing form row to column selection
@@ -127,6 +134,7 @@ void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode )
switch ( selmode )
{
case wxGrid::wxGridSelectCells:
case wxGrid::wxGridSelectNone:
wxFAIL_MSG("unreachable");
break;
@@ -160,7 +168,8 @@ void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode )
void wxGridSelection::SelectRow(int row, const wxKeyboardState& kbd)
{
if ( m_selectionMode == wxGrid::wxGridSelectColumns )
if ( m_selectionMode == wxGrid::wxGridSelectColumns ||
m_selectionMode == wxGrid::wxGridSelectNone )
return;
Select(wxGridBlockCoords(row, 0, row, m_grid->GetNumberCols() - 1),
@@ -169,7 +178,8 @@ void wxGridSelection::SelectRow(int row, const wxKeyboardState& kbd)
void wxGridSelection::SelectCol(int col, const wxKeyboardState& kbd)
{
if ( m_selectionMode == wxGrid::wxGridSelectRows )
if ( m_selectionMode == wxGrid::wxGridSelectRows ||
m_selectionMode == wxGrid::wxGridSelectNone )
return;
Select(wxGridBlockCoords(0, col, m_grid->GetNumberRows() - 1, col),
@@ -214,6 +224,10 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol,
else
allowed = 0;
break;
case wxGrid::wxGridSelectNone:
allowed = 0;
break;
}
wxASSERT_MSG(allowed != -1, "unknown selection mode?");
@@ -246,6 +260,10 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
const wxKeyboardState& kbd,
wxEventType eventType)
{
// In wxGridSelectNone mode, all blocks should already be deselected.
if ( m_selectionMode == wxGrid::wxGridSelectNone )
return;
const wxGridBlockCoords canonicalizedBlock = block.Canonicalize();
size_t count, n;
@@ -312,6 +330,10 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
else
splitOrientation = wxVERTICAL;
break;
case wxGrid::wxGridSelectNone:
wxFAIL_MSG("unreachable");
break;
}
wxASSERT_MSG( splitOrientation != -1, "unknown selection mode" );
@@ -517,10 +539,14 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart,
wxASSERT( blockStart.GetRow() != -1 && blockStart.GetCol() != -1 &&
blockEnd.GetRow() != -1 && blockEnd.GetCol() != -1 );
if ( m_selectionMode == wxGrid::wxGridSelectNone )
return false;
// If selection doesn't contain the current cell (which also covers the
// special case of nothing being selected yet), we have to create a new
// block containing it because it doesn't make sense to extend any existing
// block to non-selected current cell.
if ( !IsInSelection(m_grid->GetGridCursorCoords()) )
{
SelectBlock(blockStart, blockEnd, kbd, eventType);
@@ -574,6 +600,10 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart,
canChangeCol = true;
}
break;
case wxGrid::wxGridSelectNone:
wxFAIL_MSG("unreachable");
break;
}
if ( canChangeRow )
@@ -754,7 +784,8 @@ wxGridCellCoordsArray wxGridSelection::GetBlockSelectionBottomRight() const
// is, anyhow, the best we can do.
wxArrayInt wxGridSelection::GetRowSelection() const
{
if ( m_selectionMode == wxGrid::wxGridSelectColumns )
if ( m_selectionMode == wxGrid::wxGridSelectColumns ||
m_selectionMode == wxGrid::wxGridSelectNone )
return wxArrayInt();
wxIntSortedArray uniqueRows;
@@ -785,7 +816,8 @@ wxArrayInt wxGridSelection::GetRowSelection() const
// See comments for GetRowSelection().
wxArrayInt wxGridSelection::GetColSelection() const
{
if ( m_selectionMode == wxGrid::wxGridSelectRows )
if ( m_selectionMode == wxGrid::wxGridSelectRows ||
m_selectionMode == wxGrid::wxGridSelectNone )
return wxArrayInt();
wxIntSortedArray uniqueCols;

View File

@@ -300,7 +300,6 @@ wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd)
parent->AddChild(win);
win->SubclassWin(hWnd);
win->AdoptAttributesFromHWND();
win->SetupColours();
}
return win;

View File

@@ -18,9 +18,6 @@
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_ACTIVITYINDICATOR

View File

@@ -18,9 +18,6 @@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_DATEPICKCTRL

View File

@@ -19,9 +19,6 @@
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/evtloop.h"

View File

@@ -18,9 +18,6 @@
#include "wx/wxprec.h"
#if defined(__BORLANDC__)
#pragma hdrstop
#endif
#if wxUSE_GLCANVAS

View File

@@ -19,9 +19,6 @@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
//---------------------------------------------------------------------------
// Compilation guard

View File

@@ -18,9 +18,6 @@
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/nativewin.h"

View File

@@ -18,9 +18,6 @@
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/notifmsg.h"

View File

@@ -19,9 +19,6 @@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/overlay.h"

View File

@@ -18,9 +18,6 @@
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_PREFERENCES_EDITOR

View File

@@ -10,9 +10,6 @@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_SEARCHCTRL

View File

@@ -18,9 +18,6 @@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_STATBMP

View File

@@ -18,9 +18,6 @@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_STATLINE

View File

@@ -19,9 +19,6 @@
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/evtloop.h"

View File

@@ -18,9 +18,6 @@
#include "wx/wxprec.h"
#if defined(__BORLANDC__)
#pragma hdrstop
#endif
#if wxUSE_GLCANVAS

View File

@@ -18,9 +18,6 @@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_STATBMP

View File

@@ -66,9 +66,6 @@
<string name="cpp_implementation_preamble">"// For compilers that support precompilation, includes &quot;wx/wx.h&quot;.
#include &quot;wx/wxprec.h&quot;
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include &quot;wx/wx.h&quot;

View File

@@ -28,9 +28,6 @@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_STC

View File

@@ -297,6 +297,12 @@ TEST_CASE_METHOD(SingleSelectDataViewCtrlTestCase,
CHECK( rect1.y < rect2.y );
}
// This forces generic implementation to add m_grandchild to the tree, as
// it does it only on demand. We want the item to really be there to check
// that GetItemRect() returns an empty rectangle for collapsed items.
m_dvc->Expand(m_child1);
m_dvc->Collapse(m_child1);
const wxRect rectNotShown = m_dvc->GetItemRect(m_grandchild);
CHECK( rectNotShown == wxRect() );