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
);
55 void OnObjectEdit(wxCommandEvent
& event
);
56 void OnObjectDelete(wxCommandEvent
& event
);
58 virtual void OnItemEvent(wxControl
*win
, wxMouseEvent
& event
);
59 virtual void OnLeftClick(int x
, int y
, int keys
);
60 virtual void OnRightClick(int x
, int y
, int keys
);
61 virtual void OnItemLeftClick(wxControl
*item
, int x
, int y
, int keys
);
62 virtual void OnItemRightClick(wxControl
*item
, int x
, int y
, int keys
);
63 virtual void OnItemSelect(wxControl
*item
, bool select
);
64 virtual void OnItemMove(
65 wxControl
*WXUNUSED(item
), int WXUNUSED(x
), int WXUNUSED(y
) ) {};
66 virtual void OnItemSize(
67 wxControl
*WXUNUSED(item
), int WXUNUSED(w
), int WXUNUSED(h
) ) {};
69 void AddChildHandlers(void);
70 void PaintSelectionHandles(wxDC
& dc
);
71 void ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
);
73 virtual void DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
);
74 virtual void OnDragBegin(int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
75 virtual void OnDragContinue(bool paintIt
, int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
76 virtual void OnDragEnd(int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
80 inline long GetTreeItem() const { return m_treeItem; }
81 inline void SetTreeItem(long item) { m_treeItem = item; }
87 class wxResourceEditorControlHandler
: public wxEvtHandler
89 DECLARE_CLASS(wxResourceEditorControlHandler
)
91 // wxResourceManager *resourceManager;
92 wxControl
*handlerControl
;
93 // wxItemResource *handlerResource;
94 wxEvtHandler
*handlerOldHandler
;
97 int handleSize
; // selection handle size
98 int handleMargin
; // Distance between item edge and handle edge
100 static int dragOffsetX
; // Distance between pointer at start of drag and
101 static int dragOffsetY
; // top-left of item
103 wxResourceEditorControlHandler(wxControl
*control
, wxEvtHandler
*oldHandler
);
104 ~wxResourceEditorControlHandler(void);
106 void OnMouseEvent(wxMouseEvent
& event
);
108 // Manipulation and drawing of items in Edit Mode
110 // Calculate position of the 8 handles
111 virtual void CalcSelectionHandles(int *hx
, int *hy
);
112 virtual void DrawSelectionHandles(wxDC
& dc
, bool erase
= FALSE
);
113 virtual void DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
);
114 virtual void SelectItem(bool select
);
115 virtual inline bool IsSelected(void) { return isSelected
; }
117 // Returns TRUE or FALSE
118 virtual bool HitTest(int x
, int y
);
120 // Returns 0 (no hit), 1 - 8 for which selection handle
121 // (clockwise from top middle)
122 virtual int SelectionHandleHitTest(int x
, int y
);
124 // If selectionHandle is zero, not dragging the selection handle.
125 virtual void OnDragBegin(int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
126 virtual void OnDragContinue(bool paintIt
, int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
127 virtual void OnDragEnd(int x
, int y
, int keys
, wxDC
& dc
, int selectionHandle
);
129 // These functions call panel functions
131 virtual void OldOnMove(int x
, int y
);
132 virtual void OldOnSize(int w
, int h
);
133 virtual void OnLeftClick(int x
, int y
, int keys
);
134 virtual void OnRightClick(int x
, int y
, int keys
);
135 virtual void OnSelect(bool select
);
139 inline long GetTreeItem() const { return m_treeItem; }
140 inline void SetTreeItem(long item) { m_treeItem = item; }
143 DECLARE_EVENT_TABLE()
146 // This dialog, for testing dialogs, has to intercept commands before
147 // they go up the hierarchy and accidentally set off arbitrary
148 // Dialog Editor functionality
149 class ResourceEditorDialogTester
: public wxDialog
152 ResourceEditorDialogTester() {}
154 bool ProcessEvent(wxEvent
& event
);