1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dialog handler
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
15 #define wxDRAG_MODE_NONE 0
16 #define wxDRAG_MODE_START_LEFT 1
17 #define wxDRAG_MODE_CONTINUE_LEFT 2
18 #define wxDRAG_MODE_START_RIGHT 3
19 #define wxDRAG_MODE_CONTINUE_RIGHT 4
20 #define wxDRAG_TYPE_NONE 0
21 #define wxDRAG_TYPE_ITEM 100
22 #define wxDRAG_TYPE_BOUNDING_BOX 200
27 class wxResourceEditorDialogHandler
: public wxEvtHandler
29 DECLARE_CLASS(wxResourceEditorDialogHandler
)
31 wxResourceManager
*resourceManager
;
32 wxPanel
*handlerDialog
;
33 wxItemResource
*handlerResource
;
34 wxEvtHandler
*handlerOldHandler
;
48 wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
, wxEvtHandler
*oldHandler
,
49 wxResourceManager
*manager
);
50 ~wxResourceEditorDialogHandler(void);
52 void OnPaint(wxPaintEvent
& event
);
53 void OnMouseEvent(wxMouseEvent
& event
);
54 void OnSize(wxSizeEvent
& event
);
56 virtual void OnItemEvent(wxControl
*win
, wxMouseEvent
& event
);
57 virtual void OnLeftClick(int x
, int y
, int keys
);
58 virtual void OnRightClick(int x
, int y
, int keys
);
59 virtual void OnItemLeftClick(wxControl
*item
, int x
, int y
, int keys
);
60 virtual void OnItemRightClick(wxControl
*item
, int x
, int y
, int keys
);
61 virtual void OnItemSelect(wxControl
*item
, bool select
);
62 virtual void OnItemMove(
63 wxControl
*WXUNUSED(item
), int WXUNUSED(x
), int WXUNUSED(y
) ) {};
64 virtual void OnItemSize(
65 wxControl
*WXUNUSED(item
), int WXUNUSED(w
), int WXUNUSED(h
) ) {};
67 void AddChildHandlers(void);
68 void PaintSelectionHandles(wxDC
& dc
);
69 void ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
);
71 virtual void DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
);
72 virtual void OnDragBegin(int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
73 virtual void OnDragContinue(bool paintIt
, int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
74 virtual void OnDragEnd(int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
78 inline long GetTreeItem() const { return m_treeItem; }
79 inline void SetTreeItem(long item) { m_treeItem = item; }
85 class wxResourceEditorControlHandler
: public wxEvtHandler
87 DECLARE_CLASS(wxResourceEditorControlHandler
)
89 // wxResourceManager *resourceManager;
90 wxControl
*handlerControl
;
91 // wxItemResource *handlerResource;
92 wxEvtHandler
*handlerOldHandler
;
95 int handleSize
; // selection handle size
96 int handleMargin
; // Distance between item edge and handle edge
98 static int dragOffsetX
; // Distance between pointer at start of drag and
99 static int dragOffsetY
; // top-left of item
101 wxResourceEditorControlHandler(wxControl
*control
, wxEvtHandler
*oldHandler
);
102 ~wxResourceEditorControlHandler(void);
104 void OnMouseEvent(wxMouseEvent
& event
);
106 // Manipulation and drawing of items in Edit Mode
108 // Calculate position of the 8 handles
109 virtual void CalcSelectionHandles(int *hx
, int *hy
);
110 virtual void DrawSelectionHandles(wxDC
& dc
, bool erase
= FALSE
);
111 virtual void DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
);
112 virtual void SelectItem(bool select
);
113 virtual inline bool IsSelected(void) { return isSelected
; }
115 // Returns TRUE or FALSE
116 virtual bool HitTest(int x
, int y
);
118 // Returns 0 (no hit), 1 - 8 for which selection handle
119 // (clockwise from top middle)
120 virtual int SelectionHandleHitTest(int x
, int y
);
122 // If selectionHandle is zero, not dragging the selection handle.
123 virtual void OnDragBegin(int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
124 virtual void OnDragContinue(bool paintIt
, int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
125 virtual void OnDragEnd(int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
127 // These functions call panel functions
129 virtual void OldOnMove(int x
, int y
);
130 virtual void OldOnSize(int w
, int h
);
131 virtual void OnLeftClick(int x
, int y
, int keys
);
132 virtual void OnRightClick(int x
, int y
, int keys
);
133 virtual void OnSelect(bool select
);
137 inline long GetTreeItem() const { return m_treeItem; }
138 inline void SetTreeItem(long item) { m_treeItem = item; }
141 DECLARE_EVENT_TABLE()
144 // This dialog, for testing dialogs, has to intercept commands before
145 // they go up the hierarchy and accidentally set off arbitrary
146 // Dialog Editor functionality
147 class ResourceEditorDialogTester
: public wxDialog
150 ResourceEditorDialogTester() {}
152 bool ProcessEvent(wxEvent
& event
);