1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dialog handler
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
32 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
35 #include <strstream.h>
43 IMPLEMENT_CLASS(wxResourceEditorDialogHandler
, wxEvtHandler
)
44 IMPLEMENT_CLASS(wxResourceEditorControlHandler
, wxEvtHandler
)
46 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler
, wxEvtHandler
)
47 EVT_PAINT(wxResourceEditorDialogHandler::OnPaint
)
48 EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent
)
51 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler
, wxEvtHandler
)
52 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent
)
56 * Dialog box event handler
59 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
,
60 wxEvtHandler
*oldHandler
, wxResourceManager
*manager
)
62 handlerDialog
= dialog
;
63 handlerResource
= resource
;
64 handlerOldHandler
= oldHandler
;
65 resourceManager
= manager
;
67 dragMode
= wxDRAG_MODE_NONE
;
68 dragType
= wxDRAG_TYPE_NONE
;
75 checkTolerance
= TRUE
;
76 m_mouseCaptured
= FALSE
;
80 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
84 void wxResourceEditorDialogHandler::OnItemSelect(wxControl
*item
, bool select
)
87 resourceManager
->AddSelection(item
);
89 resourceManager
->RemoveSelection(item
);
92 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent
& event
)
94 wxPaintDC
dc(handlerDialog
);
96 PaintSelectionHandles(dc
);
99 // Add event handlers for all children
100 void wxResourceEditorDialogHandler::AddChildHandlers(void)
102 wxNode
*node
= handlerDialog
->GetChildren()->First();
105 wxControl
*child
= (wxControl
*)node
->Data();
106 wxEvtHandler
*childHandler
= child
->GetEventHandler();
107 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
== child
)
108 child
->PushEventHandler(new wxResourceEditorControlHandler(child
, childHandler
));
113 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
115 if (keys
& wxKEY_CTRL
)
117 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
121 // Deselect all items if click on panel
122 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
124 int needsRefresh
= 0;
125 wxNode
*node
= handlerDialog
->GetChildren()->First();
128 wxControl
*item
= (wxControl
*)node
->Data();
129 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
130 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
133 OnItemSelect(item
, FALSE
);
134 childHandler
->SelectItem(FALSE
);
138 if (needsRefresh
> 0)
140 wxClientDC
dc(handlerDialog
);
142 handlerDialog
->Refresh();
147 wxResourceManager
* manager
= resourceManager
;
149 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
152 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
154 case RESED_BMPBUTTON
:
155 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
157 case RESED_STATICTEXT
:
158 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
160 case RESED_STATICBMP
:
161 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
163 case RESED_TEXTCTRL_SINGLE
:
164 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
166 case RESED_TEXTCTRL_MULTIPLE
:
167 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
170 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
173 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
176 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
178 case RESED_RADIOBUTTON
:
179 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioButton", x
, y
);
182 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
185 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
188 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
190 case RESED_STATICBOX
:
191 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
193 case RESED_SCROLLBAR
:
194 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
200 // Now switch pointer on.
201 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
203 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
208 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
210 if (keys
& wxKEY_CTRL
)
212 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
216 // Deselect all items if click on panel
217 if (resourceManager
->GetEditorPalette()->currentlySelected
== PALETTE_ARROW
)
219 int needsRefresh
= 0;
220 wxNode
*node
= handlerDialog
->GetChildren()->First();
223 wxControl
*item
= (wxControl
*)node
->Data();
224 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
225 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
228 OnItemSelect(item
, FALSE
);
229 childHandler
->SelectItem(FALSE
);
233 if (needsRefresh
> 0)
235 wxClientDC
dc(handlerDialog
);
237 handlerDialog
->Refresh();
242 wxResourceManager
* manager
= resourceManager
;
244 switch (resourceManager
->GetEditorPalette()->currentlySelected
)
248 case PALETTE_DIALOG_BOX
:
254 case PALETTE_TEXT_WINDOW
:
257 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
259 case PALETTE_BITMAP_BUTTON
:
260 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
, TRUE
);
262 case PALETTE_MESSAGE
:
263 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
265 case PALETTE_BITMAP_MESSAGE
:
266 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
269 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
271 case PALETTE_MULTITEXT
:
272 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
275 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
277 case PALETTE_CHECKBOX
:
278 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
280 case PALETTE_RADIOBOX
:
281 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
283 case PALETTE_LISTBOX
:
284 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
287 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
290 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
292 case PALETTE_GROUPBOX
:
293 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
295 case PALETTE_SCROLLBAR
:
296 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
302 // Now switch pointer on.
303 if (manager
->GetEditorPalette()->currentlySelected
!= PALETTE_ARROW
)
305 manager
->GetEditorPalette()->ToggleTool(manager
->GetEditorPalette()->currentlySelected
, FALSE
);
306 manager
->GetEditorPalette()->ToggleTool(PALETTE_ARROW
, TRUE
);
307 manager
->GetEditorPalette()->currentlySelected
= PALETTE_ARROW
;
312 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int keys
)
314 wxMenu
*menu
= resourceManager
->GetPopupMenu();
315 menu
->SetClientData((char *)handlerDialog
);
316 handlerDialog
->PopupMenu(menu
, x
, y
);
319 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int x
, int y
, int keys
)
321 if (keys
& wxKEY_CTRL
)
323 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
328 // If this is a wxStaticBox and the pointer isn't an arrow, chances
329 // are that we really meant to place an item on the panel.
331 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
333 OnLeftClick(x, y, keys);
338 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
340 if (childHandler
->IsSelected())
342 childHandler
->SelectItem(FALSE
);
343 OnItemSelect(item
, FALSE
);
345 wxClientDC
dc(handlerDialog
);
347 handlerDialog
->Refresh();
351 childHandler
->SelectItem(TRUE
);
352 OnItemSelect(item
, TRUE
);
354 // Deselect other items if shift is not pressed
355 int needsRefresh
= 0;
356 if (!(keys
& wxKEY_SHIFT
))
358 wxNode
*node
= item
->GetParent()->GetChildren()->First();
361 wxControl
*child
= (wxControl
*)node
->Data();
362 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
363 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
365 childHandler2
->SelectItem(FALSE
);
366 OnItemSelect(child
, FALSE
);
373 wxClientDC
dc(handlerDialog
);
374 childHandler
->DrawSelectionHandles(dc
);
376 if (needsRefresh
> 0)
379 handlerDialog
->Refresh();
384 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int keys
)
387 if (keys & wxKEY_CTRL)
389 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
394 wxMenu
*menu
= resourceManager
->GetPopupMenu();
395 menu
->SetClientData((char *)item
);
396 handlerDialog
->PopupMenu(menu
, x
, y
);
399 // An event outside any items: may be a drag event.
400 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
402 if (GetEvtHandlerEnabled())
404 // If we're dragging an item or selection handle,
405 // continue dragging.
406 if (dragMode
!= wxDRAG_MODE_NONE
)
408 ProcessItemEvent(dragItem
, event
, dragType
);
413 event
.Position(&x
, &y
);
415 // Find which selection handle we're on, if any
416 wxNode
*node
= handlerDialog
->GetChildren()->First();
419 wxWindow
*win
= (wxWindow
*)node
->Data();
420 if (win
->IsKindOf(CLASSINFO(wxControl
)))
422 wxControl
*item
= (wxControl
*)win
;
423 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
424 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
427 ProcessItemEvent(item
, event
, selHandle
);
434 // We're not on an item or selection handle.
435 // so... check for a left or right click event
436 // to send to the application.
438 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
439 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
445 handlerDialog
->ReleaseMouse();
446 m_mouseCaptured
= FALSE
;
449 OnLeftClick(x
, y
, keys
);
451 else if (event
.RightUp())
455 handlerDialog
->ReleaseMouse();
456 m_mouseCaptured
= FALSE
;
459 OnRightClick(x
, y
, keys
);
466 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
468 if (!GetEvtHandlerEnabled())
471 // Not a selection handle event: just a normal item event.
472 // Transform to panel coordinates.
474 item
->GetPosition(&x
, &y
);
476 event
.m_x
= event
.m_x
+ x
;
477 event
.m_y
= event
.m_y
+ y
;
478 ProcessItemEvent(item
, event
, dragType
);
481 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
483 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
486 event
.Position(&x
, &y
);
488 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
489 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
490 bool dragging
= event
.Dragging();
493 int dx
= (int)abs((x
- firstDragX
));
494 int dy
= (int)abs((y
- firstDragY
));
495 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
500 // If we've ignored the tolerance once, then ALWAYS ignore
501 // tolerance in this drag, even if we come back within
502 // the tolerance range.
504 checkTolerance
= FALSE
;
507 if (event
.LeftDClick())
511 handlerDialog
->ReleaseMouse();
512 m_mouseCaptured
= FALSE
;
515 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
517 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
519 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
520 wxClientDC
dc(handlerDialog
);
521 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
522 oldDragX
= x
; oldDragY
= y
;
523 if (!m_mouseCaptured
)
525 handlerDialog
->CaptureMouse();
526 m_mouseCaptured
= TRUE
;
529 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
531 wxClientDC
dc(handlerDialog
);
532 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
533 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
534 oldDragX
= x
; oldDragY
= y
;
536 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
538 wxClientDC
dc(handlerDialog
);
539 dragMode
= wxDRAG_MODE_NONE
;
540 checkTolerance
= TRUE
;
542 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
543 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
546 dragType
= wxDRAG_TYPE_NONE
;
550 handlerDialog
->ReleaseMouse();
551 m_mouseCaptured
= FALSE
;
554 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
556 wxClientDC
dc(handlerDialog
);
557 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
558 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
559 oldDragX
= x
; oldDragY
= y
;
561 if (!m_mouseCaptured
)
563 handlerDialog
->CaptureMouse();
564 m_mouseCaptured
= TRUE
;
567 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
569 oldDragX
= x
; oldDragY
= y
;
571 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
573 dragMode
= wxDRAG_MODE_NONE
;
574 checkTolerance
= TRUE
;
576 dragType
= wxDRAG_TYPE_NONE
;
580 handlerDialog
->ReleaseMouse();
581 m_mouseCaptured
= FALSE
;
584 else if (event
.IsButton())
586 checkTolerance
= TRUE
;
588 if (event
.LeftDown())
591 dragMode
= wxDRAG_MODE_START_LEFT
;
594 dragType
= selectionHandle
;
596 if (!m_mouseCaptured
)
598 handlerDialog
->CaptureMouse();
599 m_mouseCaptured
= TRUE
;
602 else if (event
.RightDown())
605 dragMode
= wxDRAG_MODE_START_RIGHT
;
608 dragType
= selectionHandle
;
610 if (!m_mouseCaptured
)
612 handlerDialog
->CaptureMouse();
613 m_mouseCaptured
= TRUE
;
616 else if (event
.LeftUp())
619 childHandler
->OnLeftClick(x
, y
, keys
);
621 OnLeftClick(x
, y
, keys
);
623 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
627 handlerDialog
->ReleaseMouse();
628 m_mouseCaptured
= FALSE
;
631 else if (event
.RightUp())
634 childHandler
->OnRightClick(x
, y
, keys
);
636 OnRightClick(x
, y
, keys
);
638 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
642 handlerDialog
->ReleaseMouse();
643 m_mouseCaptured
= FALSE
;
649 // Calls DrawSelectionHandles for all items if
651 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
653 if (!GetEvtHandlerEnabled())
658 wxNode
*node
= handlerDialog
->GetChildren()->First();
661 wxWindow
*win
= (wxWindow
*)node
->Data();
662 if (win
->IsKindOf(CLASSINFO(wxControl
)))
664 wxControl
*item
= (wxControl
*)win
;
665 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
667 // Don't draw handles for an item that's being moved: it'll
669 if (childHandler
->IsSelected() && (item
!= dragItem
))
670 childHandler
->DrawSelectionHandles(dc
);
678 * Event handler for controls
681 int wxResourceEditorControlHandler::dragOffsetX
= 0;
682 int wxResourceEditorControlHandler::dragOffsetY
= 0;
684 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
685 wxEvtHandler
*oldHandler
)
687 handlerControl
= control
;
688 handlerOldHandler
= oldHandler
;
698 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
703 * Manipulation and drawing of items in Edit Mode
706 void wxResourceEditorControlHandler::SelectItem(bool select
)
711 // Returns TRUE or FALSE
712 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
714 int xpos
, ypos
, width
, height
;
715 handlerControl
->GetPosition(&xpos
, &ypos
);
716 handlerControl
->GetSize(&width
, &height
);
718 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
721 // Calculate position of the 8 handles
722 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
724 int xpos
, ypos
, width
, height
;
725 handlerControl
->GetPosition(&xpos
, &ypos
);
726 handlerControl
->GetSize(&width
, &height
);
727 int middleX
= (xpos
+ (width
/2));
728 int middleY
= (ypos
+ (height
/2));
730 // Start from top middle, clockwise.
739 hx
[0] = (int)(middleX
- (handleSize
/2));
740 hy
[0] = ypos
- handleSize
- handleMargin
;
742 hx
[1] = xpos
+ width
+ handleMargin
;
743 hy
[1] = ypos
- handleSize
- handleMargin
;
745 hx
[2] = xpos
+ width
+ handleMargin
;
746 hy
[2] = (int)(middleY
- (handleSize
/2));
748 hx
[3] = xpos
+ width
+ handleMargin
;
749 hy
[3] = ypos
+ height
+ handleMargin
;
751 hx
[4] = (int)(middleX
- (handleSize
/2));
752 hy
[4] = ypos
+ height
+ handleMargin
;
754 hx
[5] = xpos
- handleSize
- handleMargin
;
755 hy
[5] = ypos
+ height
+ handleMargin
;
757 hx
[6] = xpos
- handleSize
- handleMargin
;
758 hy
[6] = (int)(middleY
- (handleSize
/2));
760 hx
[7] = xpos
- handleSize
- handleMargin
;
761 hy
[7] = ypos
- handleSize
- handleMargin
;
764 // Returns 0 (no hit), 1 - 8 for which selection handle
765 // (clockwise from top middle)
766 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
771 CalcSelectionHandles(hx
, hy
);
774 for (i
= 0; i
< 8; i
++)
776 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
782 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
784 dc
.SetOptimization(FALSE
);
786 dc
.SetLogicalFunction(wxCOPY
);
787 dc
.SetPen(wxBLACK_PEN
);
788 dc
.SetBrush(wxBLACK_BRUSH
);
790 dc
.SetOptimization(TRUE
);
795 CalcSelectionHandles(hx
, hy
);
798 for (i
= 0; i
< 8; i
++)
800 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
804 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
806 dc
.DrawRectangle(x
, y
, w
, h
);
809 // If selectionHandle is zero, not dragging the selection handle.
810 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
812 int xpos
, ypos
, width
, height
;
813 handlerControl
->GetPosition(&xpos
, &ypos
);
814 handlerControl
->GetSize(&width
, &height
);
818 // dc.DestroyClippingRegion();
820 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
821 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
823 // Erase selection handles
824 // DrawSelectionHandles(dc, TRUE);
826 dc
.SetOptimization(FALSE
);
828 dc
.SetLogicalFunction(wxXOR
);
830 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
832 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
834 dc
.SetOptimization(TRUE
);
836 if (selectionHandle
> 0)
840 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
846 dragOffsetX
= (x
- xpos
);
847 dragOffsetY
= (y
- ypos
);
849 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
851 // Also draw bounding boxes for other selected items
852 wxNode
*node
= panel
->GetChildren()->First();
855 wxWindow
*win
= (wxWindow
*)node
->Data();
856 if (win
->IsKindOf(CLASSINFO(wxControl
)))
858 wxControl
*item
= (wxControl
*)win
;
859 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
860 if ((item
!= handlerControl
) && handler
->IsSelected())
863 item
->GetPosition(&x1
, &y1
);
864 item
->GetSize(&w1
, &h1
);
865 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
874 void wxResourceEditorControlHandler::OnDragContinue(bool paintIt
, int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
876 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
877 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
879 int xpos
, ypos
, width
, height
;
880 handlerControl
->GetPosition(&xpos
, &ypos
);
881 handlerControl
->GetSize(&width
, &height
);
883 if (selectionHandle
> 0)
893 int x1
, y1
, width1
, height1
;
895 switch (selectionHandle
)
901 height1
= (ypos
+ height
) - y
;
907 height1
= (y
- ypos
);
918 width1
= (xpos
+ width
) - x
;
925 height1
= (ypos
+ height
) - y
;
931 height1
= (y
- ypos
);
936 width1
= (xpos
+ width
) - x
;
942 width1
= (xpos
+ width
) - x
;
943 height1
= (ypos
+ height
) - y
;
948 dc
.SetLogicalFunction(wxXOR
);
949 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
951 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
953 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
960 dc
.SetLogicalFunction(wxXOR
);
961 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
963 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
965 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
967 // Also draw bounding boxes for other selected items
968 wxNode
*node
= panel
->GetChildren()->First();
971 wxWindow
*win
= (wxWindow
*)node
->Data();
972 if (win
->IsKindOf(CLASSINFO(wxControl
)))
974 wxControl
*item
= (wxControl
*)win
;
975 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
976 if ((item
!= handlerControl
) && handler
->IsSelected())
979 item
->GetPosition(&x1
, &y1
);
980 item
->GetSize(&w1
, &h1
);
981 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
982 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
983 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
992 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
994 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
995 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
999 int xpos
, ypos
, width
, height
;
1000 handlerControl
->GetPosition(&xpos
, &ypos
);
1001 handlerControl
->GetSize(&width
, &height
);
1003 if (selectionHandle
> 0)
1005 int x1
, y1
, width1
, height1
;
1007 switch (selectionHandle
)
1013 height1
= (ypos
+ height
) - y
;
1019 height1
= (y
- ypos
);
1024 width1
= (x
- xpos
);
1030 width1
= (xpos
+ width
) - x
;
1036 width1
= (x
- xpos
);
1037 height1
= (ypos
+ height
) - y
;
1042 width1
= (x
- xpos
);
1043 height1
= (y
- ypos
);
1048 width1
= (xpos
+ width
) - x
;
1054 width1
= (xpos
+ width
) - x
;
1055 height1
= (ypos
+ height
) - y
;
1058 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
1062 handlerControl
->Move((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
1063 OldOnMove((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
1065 // Also move other selected items
1066 wxNode
*node
= panel
->GetChildren()->First();
1069 wxWindow
*win
= (wxWindow
*)node
->Data();
1070 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1072 wxControl
*item
= (wxControl
*)win
;
1073 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1074 if ((item
!= handlerControl
) && handler
->IsSelected())
1077 item
->GetPosition(&x1
, &y1
);
1078 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1079 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1081 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
1082 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1085 node
= node
->Next();
1088 dc
.SetOptimization(FALSE
);
1090 dc
.SetLogicalFunction(wxCOPY
);
1091 dc
.SetPen(wxBLACK_PEN
);
1092 dc
.SetBrush(wxBLACK_BRUSH
);
1094 dc
.SetOptimization(TRUE
);
1096 // Force it to repaint the selection handles (if any)
1097 // since the panel thinks we're still within a drag and
1098 // won't paint the handles.
1100 DrawSelectionHandles(dc
);
1107 // These functions call OnItemEvent, OnItemMove and OnItemSize
1109 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1112 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1113 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1116 wxWindow
*panel
= handlerControl
->GetParent();
1117 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1119 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1120 if ( !panelHandler
->GetEvtHandlerEnabled() )
1126 panelHandler
->OnItemEvent(handlerControl
, event
);
1129 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1131 wxWindow
*panel
= handlerControl
->GetParent();
1132 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1135 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1136 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1139 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1141 wxWindow
*panel
= handlerControl
->GetParent();
1142 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1145 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1146 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1149 void wxResourceEditorControlHandler::OnSelect(bool select
)
1151 wxWindow
*panel
= handlerControl
->GetParent();
1152 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1155 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1156 panelHandler
->OnItemSelect(handlerControl
, select
);
1159 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1161 wxWindow
*panel
= handlerControl
->GetParent();
1162 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1165 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1166 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1169 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1171 wxWindow
*panel
= handlerControl
->GetParent();
1172 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1175 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1176 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);