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
& WXUNUSED(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 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
150 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
152 case RESED_BMPBUTTON
:
153 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
155 case RESED_STATICTEXT
:
156 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
158 case RESED_STATICBMP
:
159 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
161 case RESED_TEXTCTRL_SINGLE
:
162 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
164 case RESED_TEXTCTRL_MULTIPLE
:
165 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
168 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
171 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxComboBox", x
, y
);
174 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
177 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
179 case RESED_RADIOBUTTON
:
180 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioButton", x
, y
);
183 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
186 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
189 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
191 case RESED_STATICBOX
:
192 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
194 case RESED_SCROLLBAR
:
195 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
201 // Now switch pointer on.
202 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
204 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
208 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int WXUNUSED(keys
))
210 wxMenu
*menu
= resourceManager
->GetPopupMenu();
211 menu
->SetClientData((char *)handlerDialog
);
212 handlerDialog
->PopupMenu(menu
, x
, y
);
215 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int WXUNUSED(x
), int WXUNUSED(y
), int keys
)
217 if (keys
& wxKEY_CTRL
)
219 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
224 // If this is a wxStaticBox and the pointer isn't an arrow, chances
225 // are that we really meant to place an item on the panel.
227 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
229 OnLeftClick(x, y, keys);
234 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
236 if (childHandler
->IsSelected())
238 childHandler
->SelectItem(FALSE
);
239 OnItemSelect(item
, FALSE
);
241 wxClientDC
dc(handlerDialog
);
243 handlerDialog
->Refresh();
247 childHandler
->SelectItem(TRUE
);
248 OnItemSelect(item
, TRUE
);
250 // Deselect other items if shift is not pressed
251 int needsRefresh
= 0;
252 if (!(keys
& wxKEY_SHIFT
))
254 wxNode
*node
= item
->GetParent()->GetChildren()->First();
257 wxControl
*child
= (wxControl
*)node
->Data();
258 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
259 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
261 childHandler2
->SelectItem(FALSE
);
262 OnItemSelect(child
, FALSE
);
269 wxClientDC
dc(handlerDialog
);
270 childHandler
->DrawSelectionHandles(dc
);
272 if (needsRefresh
> 0)
275 handlerDialog
->Refresh();
280 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int WXUNUSED(keys
))
283 if (keys & wxKEY_CTRL)
285 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
290 wxMenu
*menu
= resourceManager
->GetPopupMenu();
291 menu
->SetClientData((char *)item
);
292 handlerDialog
->PopupMenu(menu
, x
, y
);
295 // An event outside any items: may be a drag event.
296 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
298 if (GetEvtHandlerEnabled())
300 // If we're dragging an item or selection handle,
301 // continue dragging.
302 if (dragMode
!= wxDRAG_MODE_NONE
)
304 ProcessItemEvent(dragItem
, event
, dragType
);
309 event
.Position(&x
, &y
);
311 // Find which selection handle we're on, if any
312 wxNode
*node
= handlerDialog
->GetChildren()->First();
315 wxWindow
*win
= (wxWindow
*)node
->Data();
316 if (win
->IsKindOf(CLASSINFO(wxControl
)))
318 wxControl
*item
= (wxControl
*)win
;
319 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
320 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
323 ProcessItemEvent(item
, event
, selHandle
);
330 // We're not on an item or selection handle.
331 // so... check for a left or right click event
332 // to send to the application.
334 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
335 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
341 handlerDialog
->ReleaseMouse();
342 m_mouseCaptured
= FALSE
;
345 OnLeftClick(x
, y
, keys
);
347 else if (event
.RightDown())
351 handlerDialog
->ReleaseMouse();
352 m_mouseCaptured
= FALSE
;
355 OnRightClick(x
, y
, keys
);
362 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
364 if (!GetEvtHandlerEnabled())
367 // Not a selection handle event: just a normal item event.
368 // Transform to panel coordinates.
370 item
->GetPosition(&x
, &y
);
372 event
.m_x
= event
.m_x
+ x
;
373 event
.m_y
= event
.m_y
+ y
;
375 ProcessItemEvent(item
, event
, dragType
);
378 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
380 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
383 event
.Position(&x
, &y
);
385 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
386 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
387 bool dragging
= event
.Dragging();
390 int dx
= (int)abs((x
- firstDragX
));
391 int dy
= (int)abs((y
- firstDragY
));
392 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
397 // If we've ignored the tolerance once, then ALWAYS ignore
398 // tolerance in this drag, even if we come back within
399 // the tolerance range.
401 checkTolerance
= FALSE
;
404 if (event
.LeftDClick())
408 handlerDialog
->ReleaseMouse();
409 m_mouseCaptured
= FALSE
;
412 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
414 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
416 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
417 wxClientDC
dc(handlerDialog
);
418 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
419 oldDragX
= x
; oldDragY
= y
;
420 if (!m_mouseCaptured
)
422 handlerDialog
->CaptureMouse();
423 m_mouseCaptured
= TRUE
;
426 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
428 wxClientDC
dc(handlerDialog
);
429 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
430 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
431 oldDragX
= x
; oldDragY
= y
;
433 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
435 wxClientDC
dc(handlerDialog
);
436 dragMode
= wxDRAG_MODE_NONE
;
437 checkTolerance
= TRUE
;
439 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
440 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
443 dragType
= wxDRAG_TYPE_NONE
;
447 handlerDialog
->ReleaseMouse();
448 m_mouseCaptured
= FALSE
;
451 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
453 wxClientDC
dc(handlerDialog
);
454 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
455 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
456 oldDragX
= x
; oldDragY
= y
;
458 if (!m_mouseCaptured
)
460 handlerDialog
->CaptureMouse();
461 m_mouseCaptured
= TRUE
;
464 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
466 oldDragX
= x
; oldDragY
= y
;
468 // Obsolete; no longer try to right-drag
469 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
471 dragMode
= wxDRAG_MODE_NONE
;
472 checkTolerance
= TRUE
;
474 dragType
= wxDRAG_TYPE_NONE
;
478 handlerDialog
->ReleaseMouse();
479 m_mouseCaptured
= FALSE
;
482 else if (event
.IsButton())
484 checkTolerance
= TRUE
;
486 if (event
.LeftDown())
489 dragMode
= wxDRAG_MODE_START_LEFT
;
492 dragType
= selectionHandle
;
494 if (!m_mouseCaptured
)
496 handlerDialog
->CaptureMouse();
497 m_mouseCaptured
= TRUE
;
500 else if (event
.RightDown())
504 handlerDialog
->ReleaseMouse();
505 m_mouseCaptured
= FALSE
;
509 childHandler
->OnRightClick(x
, y
, keys
);
511 OnRightClick(x
, y
, keys
);
513 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
517 dragMode = wxDRAG_MODE_START_RIGHT;
520 dragType = selectionHandle;
522 if (!m_mouseCaptured)
524 handlerDialog->CaptureMouse();
525 m_mouseCaptured = TRUE;
529 else if (event
.LeftUp())
532 childHandler
->OnLeftClick(x
, y
, keys
);
534 OnLeftClick(x
, y
, keys
);
536 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
540 handlerDialog
->ReleaseMouse();
541 m_mouseCaptured
= FALSE
;
544 else if (event
.RightUp())
548 childHandler->OnRightClick(x, y, keys);
550 OnRightClick(x, y, keys);
552 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
556 handlerDialog->ReleaseMouse();
557 m_mouseCaptured = FALSE;
564 // Calls DrawSelectionHandles for all items if
566 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
568 if (!GetEvtHandlerEnabled())
573 wxNode
*node
= handlerDialog
->GetChildren()->First();
576 wxWindow
*win
= (wxWindow
*)node
->Data();
577 if (win
->IsKindOf(CLASSINFO(wxControl
)))
579 wxControl
*item
= (wxControl
*)win
;
580 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
582 // Don't draw handles for an item that's being moved: it'll
584 if (childHandler
->IsSelected() && (item
!= dragItem
))
585 childHandler
->DrawSelectionHandles(dc
);
593 * Event handler for controls
596 int wxResourceEditorControlHandler::dragOffsetX
= 0;
597 int wxResourceEditorControlHandler::dragOffsetY
= 0;
599 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
600 wxEvtHandler
*oldHandler
)
602 handlerControl
= control
;
603 handlerOldHandler
= oldHandler
;
613 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
618 * Manipulation and drawing of items in Edit Mode
621 void wxResourceEditorControlHandler::SelectItem(bool select
)
626 // Returns TRUE or FALSE
627 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
629 int xpos
, ypos
, width
, height
;
630 handlerControl
->GetPosition(&xpos
, &ypos
);
631 handlerControl
->GetSize(&width
, &height
);
633 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
636 // Calculate position of the 8 handles
637 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
639 int xpos
, ypos
, width
, height
;
640 handlerControl
->GetPosition(&xpos
, &ypos
);
641 handlerControl
->GetSize(&width
, &height
);
642 int middleX
= (xpos
+ (width
/2));
643 int middleY
= (ypos
+ (height
/2));
645 // Start from top middle, clockwise.
654 hx
[0] = (int)(middleX
- (handleSize
/2));
655 hy
[0] = ypos
- handleSize
- handleMargin
;
657 hx
[1] = xpos
+ width
+ handleMargin
;
658 hy
[1] = ypos
- handleSize
- handleMargin
;
660 hx
[2] = xpos
+ width
+ handleMargin
;
661 hy
[2] = (int)(middleY
- (handleSize
/2));
663 hx
[3] = xpos
+ width
+ handleMargin
;
664 hy
[3] = ypos
+ height
+ handleMargin
;
666 hx
[4] = (int)(middleX
- (handleSize
/2));
667 hy
[4] = ypos
+ height
+ handleMargin
;
669 hx
[5] = xpos
- handleSize
- handleMargin
;
670 hy
[5] = ypos
+ height
+ handleMargin
;
672 hx
[6] = xpos
- handleSize
- handleMargin
;
673 hy
[6] = (int)(middleY
- (handleSize
/2));
675 hx
[7] = xpos
- handleSize
- handleMargin
;
676 hy
[7] = ypos
- handleSize
- handleMargin
;
679 // Returns 0 (no hit), 1 - 8 for which selection handle
680 // (clockwise from top middle)
681 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
686 CalcSelectionHandles(hx
, hy
);
689 for (i
= 0; i
< 8; i
++)
691 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
697 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
699 dc
.SetOptimization(FALSE
);
701 dc
.SetLogicalFunction(wxCOPY
);
702 dc
.SetPen(wxBLACK_PEN
);
703 dc
.SetBrush(wxBLACK_BRUSH
);
705 dc
.SetOptimization(TRUE
);
710 CalcSelectionHandles(hx
, hy
);
713 for (i
= 0; i
< 8; i
++)
715 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
719 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
721 dc
.DrawRectangle(x
, y
, w
, h
);
724 // If selectionHandle is zero, not dragging the selection handle.
725 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
727 int xpos
, ypos
, width
, height
;
728 handlerControl
->GetPosition(&xpos
, &ypos
);
729 handlerControl
->GetSize(&width
, &height
);
733 // dc.DestroyClippingRegion();
735 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
737 // Erase selection handles
738 // DrawSelectionHandles(dc, TRUE);
740 dc
.SetOptimization(FALSE
);
742 dc
.SetLogicalFunction(wxXOR
);
744 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
746 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
748 dc
.SetOptimization(TRUE
);
750 if (selectionHandle
> 0)
754 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
760 dragOffsetX
= (x
- xpos
);
761 dragOffsetY
= (y
- ypos
);
763 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
765 // Also draw bounding boxes for other selected items
766 wxNode
*node
= panel
->GetChildren()->First();
769 wxWindow
*win
= (wxWindow
*)node
->Data();
770 if (win
->IsKindOf(CLASSINFO(wxControl
)))
772 wxControl
*item
= (wxControl
*)win
;
773 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
774 if ((item
!= handlerControl
) && handler
->IsSelected())
777 item
->GetPosition(&x1
, &y1
);
778 item
->GetSize(&w1
, &h1
);
779 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
788 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
790 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
791 int xpos
, ypos
, width
, height
;
792 handlerControl
->GetPosition(&xpos
, &ypos
);
793 handlerControl
->GetSize(&width
, &height
);
795 if (selectionHandle
> 0)
805 int x1
, y1
, width1
, height1
;
807 switch (selectionHandle
)
813 height1
= (ypos
+ height
) - y
;
819 height1
= (y
- ypos
);
830 width1
= (xpos
+ width
) - x
;
837 height1
= (ypos
+ height
) - y
;
843 height1
= (y
- ypos
);
848 width1
= (xpos
+ width
) - x
;
854 width1
= (xpos
+ width
) - x
;
855 height1
= (ypos
+ height
) - y
;
860 dc
.SetLogicalFunction(wxXOR
);
861 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
863 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
865 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
872 dc
.SetLogicalFunction(wxXOR
);
873 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
875 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
877 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
879 // Also draw bounding boxes for other selected items
880 wxNode
*node
= panel
->GetChildren()->First();
883 wxWindow
*win
= (wxWindow
*)node
->Data();
884 if (win
->IsKindOf(CLASSINFO(wxControl
)))
886 wxControl
*item
= (wxControl
*)win
;
887 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
888 if ((item
!= handlerControl
) && handler
->IsSelected())
891 item
->GetPosition(&x1
, &y1
);
892 item
->GetSize(&w1
, &h1
);
893 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
894 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
895 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
904 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
906 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
910 int xpos
, ypos
, width
, height
;
911 handlerControl
->GetPosition(&xpos
, &ypos
);
912 handlerControl
->GetSize(&width
, &height
);
914 if (selectionHandle
> 0)
916 int x1
, y1
, width1
, height1
;
918 switch (selectionHandle
)
924 height1
= (ypos
+ height
) - y
;
930 height1
= (y
- ypos
);
941 width1
= (xpos
+ width
) - x
;
948 height1
= (ypos
+ height
) - y
;
954 height1
= (y
- ypos
);
959 width1
= (xpos
+ width
) - x
;
965 width1
= (xpos
+ width
) - x
;
966 height1
= (ypos
+ height
) - y
;
969 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
973 handlerControl
->Move((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
974 OldOnMove((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
976 // Also move other selected items
977 wxNode
*node
= panel
->GetChildren()->First();
980 wxWindow
*win
= (wxWindow
*)node
->Data();
981 if (win
->IsKindOf(CLASSINFO(wxControl
)))
983 wxControl
*item
= (wxControl
*)win
;
984 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
985 if ((item
!= handlerControl
) && handler
->IsSelected())
988 item
->GetPosition(&x1
, &y1
);
989 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
990 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
992 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
993 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
999 dc
.SetOptimization(FALSE
);
1001 dc
.SetLogicalFunction(wxCOPY
);
1002 dc
.SetPen(wxBLACK_PEN
);
1003 dc
.SetBrush(wxBLACK_BRUSH
);
1005 dc
.SetOptimization(TRUE
);
1007 // Force it to repaint the selection handles (if any)
1008 // since the panel thinks we're still within a drag and
1009 // won't paint the handles.
1011 DrawSelectionHandles(dc
);
1018 // These functions call OnItemEvent, OnItemMove and OnItemSize
1020 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1023 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1024 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1027 wxWindow
*panel
= handlerControl
->GetParent();
1028 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1030 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1031 if ( !panelHandler
->GetEvtHandlerEnabled() )
1037 panelHandler
->OnItemEvent(handlerControl
, event
);
1040 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1042 wxWindow
*panel
= handlerControl
->GetParent();
1043 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1046 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1047 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1050 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1052 wxWindow
*panel
= handlerControl
->GetParent();
1053 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1056 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1057 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1060 void wxResourceEditorControlHandler::OnSelect(bool select
)
1062 wxWindow
*panel
= handlerControl
->GetParent();
1063 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1066 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1067 panelHandler
->OnItemSelect(handlerControl
, select
);
1070 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1072 wxWindow
*panel
= handlerControl
->GetParent();
1073 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1076 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1077 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1080 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1082 wxWindow
*panel
= handlerControl
->GetParent();
1083 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1086 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1087 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);