implement column resizing events in wxHeaderCtrl

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57190 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-08 14:40:42 +00:00
parent 4bfd0ed552
commit aef252d9da
9 changed files with 295 additions and 70 deletions

View File

@@ -359,11 +359,6 @@ private:
m_sortAscending = true;
}
// like SetWidth() but does not ask the header window of the
// wxDataViewCtrl to reflect the width-change.
void SetInternalWidth(int width);
wxString m_title;
int m_width,
m_minWidth;
@@ -482,8 +477,11 @@ public: // utility functions not part of the API
// called by header window after reorder
void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos );
// updates the header window after a change in a column setting
void OnColumnChange();
// update the display after a change to an individual column
void OnColumnChange(unsigned int idx);
// update after a change to the number of columns
void OnColumnsCountChanged();
wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }

View File

@@ -13,6 +13,7 @@
#include "wx/event.h"
#include "wx/vector.h"
#include "wx/overlay.h"
// ----------------------------------------------------------------------------
// wxHeaderCtrl
@@ -64,6 +65,7 @@ private:
// event handlers
void OnPaint(wxPaintEvent& event);
void OnMouse(wxMouseEvent& event);
void OnCaptureLost(wxMouseCaptureLostEvent& event);
// return the horizontal start position of the given column
int GetColStart(unsigned int idx) const;
@@ -84,6 +86,17 @@ private:
// column 1 but close enough to the divider separating it from column 0)
int FindColumnAtPos(int x, bool& onSeparator) const;
// end any drag operation currently in progress (resizing or reordering)
void EndDragging();
// and the resizing operation currently in progress and generate an event
// about it with its cancelled flag set if width is -1
void EndResizing(int width);
// update the current position of the resizing marker if xPhysical is a
// valid physical coordinate value or remove it entirely if it is -1
void UpdateResizingMarker(int xPhysical);
// number of columns in the control currently
unsigned int m_numColumns;
@@ -91,9 +104,16 @@ private:
// index of the column under mouse or -1 if none
unsigned int m_hover;
// the column being resized or -1 if there is no resizing operation in
// progress
unsigned int m_colBeingResized;
// the horizontal scroll offset
int m_scrollOffset;
// the overlay display used during the dragging operations
wxOverlay m_overlay;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxHeaderCtrl)

View File

@@ -269,25 +269,45 @@ class WXDLLIMPEXP_CORE wxHeaderCtrlEvent : public wxNotifyEvent
{
public:
wxHeaderCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
: wxNotifyEvent(commandType, winid)
: wxNotifyEvent(commandType, winid),
m_col(-1),
m_width(0),
m_cancelled(false)
{
}
wxHeaderCtrlEvent(const wxHeaderCtrlEvent& event)
: wxNotifyEvent(event),
m_col(event.m_col)
m_col(event.m_col),
m_width(event.m_width),
m_cancelled(event.m_cancelled)
{
}
// the column which this event pertains to: valid for all header events
int GetColumn() const { return m_col; }
void SetColumn(int col) { m_col = col; }
// the width of the column: valid for column resizing/dragging events only
int GetWidth() const { return m_width; }
void SetWidth(int width) { m_width = width; }
// was the drag operation cancelled or did it complete successfully?
bool IsCancelled() const { return m_cancelled; }
void SetCancelled() { m_cancelled = true; }
virtual wxEvent *Clone() const { return new wxHeaderCtrlEvent(*this); }
protected:
// the column affected by the event
int m_col;
// the current width for the dragging events
int m_width;
// was the drag operation cancelled?
bool m_cancelled;
private:
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHeaderCtrlEvent)
};
@@ -303,6 +323,10 @@ extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK;
extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK;
extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_DRAG;
extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DRAGGING;
extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_DRAG;
typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&);
#define wxHeaderCtrlEventHandler(func) \
@@ -322,4 +346,8 @@ typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&);
#define EVT_HEADER_SEPARATOR_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(SEPARATOR_DCLICK, id, fn)
#define EVT_HEADER_BEGIN_DRAG(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_DRAG, id, fn)
#define EVT_HEADER_DRAGGING(id, fn) wx__DECLARE_HEADER_EVT(DRAGGING, id, fn)
#define EVT_HEADER_END_DRAG(id, fn) wx__DECLARE_HEADER_EVT(END_DRAG, id, fn)
#endif // _WX_HEADERCTRL_H_

View File

@@ -71,13 +71,10 @@ private:
enum Operation { Set, Insert };
void DoSetOrInsertItem(Operation oper, unsigned int idx);
// send an event of the given type for the given column, return true if it
// was processed
bool SendEvent(wxEventType evtType, unsigned int idx);
// send a click or double click event (depending on dblclk value) for the
// click with the given button on the given item
bool SendClickEvent(bool dblclk, int button, unsigned int idx);
// get the event type corresponding to a click or double click event
// (depending on dblclk value) with the specified (using MSW convention)
// mouse button
wxEventType GetClickEventType(bool dblclk, int button);
// the image list: initially NULL, created on demand