summaryrefslogtreecommitdiff
path: root/wx+/grid.h
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-08-31 20:07:13 -0400
committerB Stack <bgstack15@gmail.com>2020-08-31 20:07:13 -0400
commit8a27fa9c617533e76673ce61a65e2ba869b52208 (patch)
treeacfdfb3e1046db87040477033fda0df76d92916a /wx+/grid.h
parentMerge branch '11.0' into 'master' (diff)
downloadFreeFileSync-8a27fa9c617533e76673ce61a65e2ba869b52208.tar.gz
FreeFileSync-8a27fa9c617533e76673ce61a65e2ba869b52208.tar.bz2
FreeFileSync-8a27fa9c617533e76673ce61a65e2ba869b52208.zip
add upstream 11.1
Diffstat (limited to 'wx+/grid.h')
-rw-r--r--wx+/grid.h86
1 files changed, 42 insertions, 44 deletions
diff --git a/wx+/grid.h b/wx+/grid.h
index 05710e3f..43a1d2a0 100644
--- a/wx+/grid.h
+++ b/wx+/grid.h
@@ -19,28 +19,33 @@
//a user-friendly, extensible and high-performance grid control
namespace zen
{
-enum class ColumnType { NONE = -1 }; //user-defiend column type
-enum class HoverArea { NONE = -1 }; //user-defined area for mouse selections for a given row (may span multiple columns or split a single column into multiple areas)
-
-//wxContextMenuEvent? => automatically generated by wxWidgets when right mouse down/up is not handled; even OS-dependent in which case event is generated
-//=> inappropriate! client decides when to show context! => simulate right mouse click when WXK_WINDOWS_MENU button is pressed
-//=> same behavior as earlier wxWidgets: https://github.com/wxWidgets/wxWidgets/commit/2c69d27c0d225d3a331c773da466686153185320#diff-9f11c8f2cb1f734f7c0c1071aba491a5
+enum class ColumnType { none = -1 }; //user-defiend column type
+enum class HoverArea { none = -1 }; //user-defined area for mouse selections for a given row (may span multiple columns or split a single column into multiple areas)
//------------------------ events ------------------------------------------------
-extern const wxEventType EVENT_GRID_MOUSE_LEFT_DOUBLE; //
-extern const wxEventType EVENT_GRID_MOUSE_LEFT_DOWN; //
-extern const wxEventType EVENT_GRID_MOUSE_LEFT_UP; //generates: GridClickEvent
-extern const wxEventType EVENT_GRID_MOUSE_RIGHT_DOWN; //
-extern const wxEventType EVENT_GRID_MOUSE_RIGHT_UP; //
+//example: wnd.Bind(EVENT_GRID_COL_LABEL_LEFT_CLICK, [this](GridClickEvent& event) { onGridLeftClick(event); });
+
+struct GridClickEvent;
+struct GridSelectEvent;
+struct GridLabelClickEvent;
+struct GridColumnResizeEvent;
+struct GridContextMenuEvent;
+
+wxDECLARE_EVENT(EVENT_GRID_MOUSE_LEFT_DOUBLE, GridClickEvent);
+wxDECLARE_EVENT(EVENT_GRID_MOUSE_LEFT_DOWN, GridClickEvent);
+wxDECLARE_EVENT(EVENT_GRID_MOUSE_RIGHT_DOWN, GridClickEvent);
-extern const wxEventType EVENT_GRID_SELECT_RANGE; //generates: GridSelectEvent
+wxDECLARE_EVENT(EVENT_GRID_SELECT_RANGE, GridSelectEvent);
//NOTE: neither first nor second row need to match EVENT_GRID_MOUSE_LEFT_DOWN/EVENT_GRID_MOUSE_LEFT_UP: user holding SHIFT; moving out of window...
-extern const wxEventType EVENT_GRID_COL_LABEL_MOUSE_LEFT; //generates: GridLabelClickEvent
-extern const wxEventType EVENT_GRID_COL_LABEL_MOUSE_RIGHT; //
-extern const wxEventType EVENT_GRID_COL_RESIZE; //generates: GridColumnResizeEvent
+wxDECLARE_EVENT(EVENT_GRID_COL_LABEL_MOUSE_LEFT, GridLabelClickEvent);
+wxDECLARE_EVENT(EVENT_GRID_COL_LABEL_MOUSE_RIGHT, GridLabelClickEvent);
+wxDECLARE_EVENT(EVENT_GRID_COL_RESIZE, GridColumnResizeEvent);
+
+//wxContextMenuEvent? => generated by wxWidgets when right mouse down/up is not handled; even OS-dependent in which case event is generated
+//=> inappropriate! we know better when to show context!
+wxDECLARE_EVENT(EVENT_GRID_CONTEXT_MENU, GridContextMenuEvent);
-//example: wnd.Connect(EVENT_GRID_COL_LABEL_LEFT_CLICK, GridClickEventHandler(MyDlg::OnLeftClick), nullptr, this);
struct GridClickEvent : public wxEvent
{
@@ -49,7 +54,7 @@ struct GridClickEvent : public wxEvent
GridClickEvent* Clone() const override { return new GridClickEvent(*this); }
const ptrdiff_t row_; //-1 for invalid position, >= rowCount if out of range
- const HoverArea hoverArea_; //may be HoverArea::NONE
+ const HoverArea hoverArea_; //may be HoverArea::none
const wxPoint mousePos_; //client coordinates
};
@@ -71,7 +76,7 @@ struct GridLabelClickEvent : public wxEvent
GridLabelClickEvent(wxEventType et, ColumnType colType) : wxEvent(0 /*winid*/, et), colType_(colType) {}
GridLabelClickEvent* Clone() const override { return new GridLabelClickEvent(*this); }
- const ColumnType colType_; //may be ColumnType::NONE
+ const ColumnType colType_; //may be ColumnType::none
};
struct GridColumnResizeEvent : public wxEvent
@@ -83,16 +88,13 @@ struct GridColumnResizeEvent : public wxEvent
const int offset_;
};
-using GridClickEventFunction = void (wxEvtHandler::*)(GridClickEvent&);
-using GridSelectEventFunction = void (wxEvtHandler::*)(GridSelectEvent&);
-using GridLabelClickEventFunction = void (wxEvtHandler::*)(GridLabelClickEvent&);
-using GridColumnResizeEventFunction = void (wxEvtHandler::*)(GridColumnResizeEvent&);
-
-#define GridClickEventHandler(func) (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(GridClickEventFunction, &func)
-#define GridSelectEventHandler(func) (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(GridSelectEventFunction, &func)
-#define GridLabelClickEventHandler(func) (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(GridLabelClickEventFunction, &func)
-#define GridColumnResizeEventHandler(func)(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(GridColumnResizeEventFunction, &func)
+struct GridContextMenuEvent : public wxEvent
+{
+ explicit GridContextMenuEvent(const wxPoint& mousePos) : wxEvent(0 /*winid*/, EVENT_GRID_CONTEXT_MENU), mousePos_(mousePos) {}
+ GridContextMenuEvent* Clone() const override { return new GridContextMenuEvent(*this); }
+ const wxPoint mousePos_; //client coordinates
+};
//------------------------------------------------------------------------------------------------------------
class Grid;
@@ -110,8 +112,8 @@ public:
virtual void renderRowBackgound(wxDC& dc, const wxRect& rect, size_t row, bool enabled, bool selected); //default implementation
virtual void renderCell (wxDC& dc, const wxRect& rect, size_t row, ColumnType colType, bool enabled, bool selected, HoverArea rowHover);
virtual int getBestSize (wxDC& dc, size_t row, ColumnType colType); //must correspond to renderCell()!
+ virtual HoverArea getRowMouseHover (wxDC& dc, size_t row, ColumnType colType, int cellRelativePosX, int cellWidth) { return HoverArea::none; }
virtual std::wstring getToolTip (size_t row, ColumnType colType) const { return std::wstring(); }
- virtual HoverArea getRowMouseHover (size_t row, ColumnType colType, int cellRelativePosX, int cellWidth) { return HoverArea::NONE; }
//label area:
virtual std::wstring getColumnLabel(ColumnType colType) const = 0;
@@ -126,7 +128,6 @@ public:
static void drawCellText(wxDC& dc, const wxRect& rect, const std::wstring& text,
int alignment = wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, const wxSize* textExtentHint = nullptr); //returns text extent
static wxRect drawCellBorder (wxDC& dc, const wxRect& rect); //returns inner rectangle
- static void drawCellBackground(wxDC& dc, const wxRect& rect, bool enabled, bool selected, const wxColor& backgroundColor);
static wxRect drawColumnLabelBackground(wxDC& dc, const wxRect& rect, bool highlighted); //returns inner rectangle
static void drawColumnLabelText (wxDC& dc, const wxRect& rect, const std::wstring& text, bool enabled);
@@ -135,8 +136,8 @@ public:
enum class GridEventPolicy
{
- ALLOW,
- DENY
+ allow,
+ deny
};
@@ -148,7 +149,7 @@ public:
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
- const wxString& name = wxPanelNameStr);
+ const wxString& name = wxASCII_STR(wxPanelNameStr));
size_t getRowCount() const;
@@ -156,7 +157,7 @@ public:
struct ColAttributes
{
- ColumnType type = ColumnType::NONE;
+ ColumnType type = ColumnType::none;
//first, client width is partitioned according to all available stretch factors, then "offset_" is added
//universal model: a non-stretched column has stretch factor 0 with the "offset" becoming identical to final width!
int offset = 0;
@@ -185,9 +186,11 @@ public:
void showScrollBars(ScrollBarStatus horizontal, ScrollBarStatus vertical);
std::vector<size_t> getSelectedRows() const { return selection_.get(); }
+
void selectRow(size_t row, GridEventPolicy rangeEventPolicy);
void selectAllRows (GridEventPolicy rangeEventPolicy); //turn off range selection event when calling this function in an event handler to avoid recursion!
void clearSelection(GridEventPolicy rangeEventPolicy); //
+ void selectRange(size_t rowFirst, size_t rowLast, bool positive, GridEventPolicy rangeEventPolicy); //select [rowFirst, rowLast)
void scrollDelta(int deltaX, int deltaY); //in scroll units
@@ -201,7 +204,7 @@ public:
struct ColumnPosInfo
{
- ColumnType colType = ColumnType::NONE; //ColumnType::NONE no column at x position!
+ ColumnType colType = ColumnType::none; //ColumnType::none no column at x position!
int cellRelativePosX = 0;
int colWidth = 0;
};
@@ -226,10 +229,7 @@ public:
//############################################################################################################
private:
- void onPaintEvent(wxPaintEvent& event);
- void onSizeEvent(wxSizeEvent& event) { updateWindowSizes(); event.Skip(); }
void onKeyDown(wxKeyEvent& event);
- void onKeyUp (wxKeyEvent& event);
void updateWindowSizes(bool updateScrollbar = true);
@@ -256,7 +256,7 @@ private:
public:
void init(size_t rowCount) { selected_.resize(rowCount); clear(); }
- size_t maxSize() const { return selected_.size(); }
+ size_t gridSize() const { return selected_.size(); }
std::vector<size_t> get() const
{
@@ -267,9 +267,7 @@ private:
return result;
}
- void selectRow(size_t row) { selectRange(row, row + 1, true); }
- void selectAll () { selectRange(0, selected_.size(), true); }
- void clear () { selectRange(0, selected_.size(), false); }
+ void clear() { selectRange(0, selected_.size(), false); }
bool isSelected(size_t row) const { return row < selected_.size() ? selected_[row] != 0 : false; }
@@ -291,14 +289,14 @@ private:
struct VisibleColumn
{
- ColumnType type = ColumnType::NONE;
+ ColumnType type = ColumnType::none;
int offset = 0;
int stretch = 0; //>= 0
};
struct ColumnWidth
{
- ColumnType type = ColumnType::NONE;
+ ColumnType type = ColumnType::none;
int width = 0;
};
std::vector<ColumnWidth> getColWidths() const; //
@@ -332,7 +330,7 @@ private:
void moveColumn(size_t colFrom, size_t colTo);
ptrdiff_t clientPosToMoveTargetColumn(const wxPoint& pos) const; //return < 0 on error
- ColumnType colToType(size_t col) const; //returns ColumnType::NONE on error
+ ColumnType colToType(size_t col) const; //returns ColumnType::none on error
/* Grid window layout:
_______________________________
bgstack15