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
;
374 ProcessItemEvent(item
, event
, dragType
);
377 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
379 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
382 event
.Position(&x
, &y
);
384 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
385 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
386 bool dragging
= event
.Dragging();
389 int dx
= (int)abs((x
- firstDragX
));
390 int dy
= (int)abs((y
- firstDragY
));
391 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
396 // If we've ignored the tolerance once, then ALWAYS ignore
397 // tolerance in this drag, even if we come back within
398 // the tolerance range.
400 checkTolerance
= FALSE
;
403 if (event
.LeftDClick())
407 handlerDialog
->ReleaseMouse();
408 m_mouseCaptured
= FALSE
;
411 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
413 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
415 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
416 wxClientDC
dc(handlerDialog
);
417 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
418 oldDragX
= x
; oldDragY
= y
;
419 if (!m_mouseCaptured
)
421 handlerDialog
->CaptureMouse();
422 m_mouseCaptured
= TRUE
;
425 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
427 wxClientDC
dc(handlerDialog
);
428 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
429 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
430 oldDragX
= x
; oldDragY
= y
;
432 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
434 wxClientDC
dc(handlerDialog
);
435 dragMode
= wxDRAG_MODE_NONE
;
436 checkTolerance
= TRUE
;
438 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
439 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
442 dragType
= wxDRAG_TYPE_NONE
;
446 handlerDialog
->ReleaseMouse();
447 m_mouseCaptured
= FALSE
;
450 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
452 wxClientDC
dc(handlerDialog
);
453 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
454 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
455 oldDragX
= x
; oldDragY
= y
;
457 if (!m_mouseCaptured
)
459 handlerDialog
->CaptureMouse();
460 m_mouseCaptured
= TRUE
;
463 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
465 oldDragX
= x
; oldDragY
= y
;
467 // Obsolete; no longer try to right-drag
468 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
470 dragMode
= wxDRAG_MODE_NONE
;
471 checkTolerance
= TRUE
;
473 dragType
= wxDRAG_TYPE_NONE
;
477 handlerDialog
->ReleaseMouse();
478 m_mouseCaptured
= FALSE
;
481 else if (event
.IsButton())
483 checkTolerance
= TRUE
;
485 if (event
.LeftDown())
488 dragMode
= wxDRAG_MODE_START_LEFT
;
491 dragType
= selectionHandle
;
493 if (!m_mouseCaptured
)
495 handlerDialog
->CaptureMouse();
496 m_mouseCaptured
= TRUE
;
499 else if (event
.RightDown())
503 handlerDialog
->ReleaseMouse();
504 m_mouseCaptured
= FALSE
;
508 childHandler
->OnRightClick(x
, y
, keys
);
510 OnRightClick(x
, y
, keys
);
512 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
516 dragMode = wxDRAG_MODE_START_RIGHT;
519 dragType = selectionHandle;
521 if (!m_mouseCaptured)
523 handlerDialog->CaptureMouse();
524 m_mouseCaptured = TRUE;
528 else if (event
.LeftUp())
531 childHandler
->OnLeftClick(x
, y
, keys
);
533 OnLeftClick(x
, y
, keys
);
535 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
539 handlerDialog
->ReleaseMouse();
540 m_mouseCaptured
= FALSE
;
543 else if (event
.RightUp())
547 childHandler->OnRightClick(x, y, keys);
549 OnRightClick(x, y, keys);
551 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
555 handlerDialog->ReleaseMouse();
556 m_mouseCaptured = FALSE;
563 // Calls DrawSelectionHandles for all items if
565 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
567 if (!GetEvtHandlerEnabled())
572 wxNode
*node
= handlerDialog
->GetChildren()->First();
575 wxWindow
*win
= (wxWindow
*)node
->Data();
576 if (win
->IsKindOf(CLASSINFO(wxControl
)))
578 wxControl
*item
= (wxControl
*)win
;
579 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
581 // Don't draw handles for an item that's being moved: it'll
583 if (childHandler
->IsSelected() && (item
!= dragItem
))
584 childHandler
->DrawSelectionHandles(dc
);
592 * Event handler for controls
595 int wxResourceEditorControlHandler::dragOffsetX
= 0;
596 int wxResourceEditorControlHandler::dragOffsetY
= 0;
598 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
599 wxEvtHandler
*oldHandler
)
601 handlerControl
= control
;
602 handlerOldHandler
= oldHandler
;
612 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
617 * Manipulation and drawing of items in Edit Mode
620 void wxResourceEditorControlHandler::SelectItem(bool select
)
625 // Returns TRUE or FALSE
626 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
628 int xpos
, ypos
, width
, height
;
629 handlerControl
->GetPosition(&xpos
, &ypos
);
630 handlerControl
->GetSize(&width
, &height
);
632 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
635 // Calculate position of the 8 handles
636 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
638 int xpos
, ypos
, width
, height
;
639 handlerControl
->GetPosition(&xpos
, &ypos
);
640 handlerControl
->GetSize(&width
, &height
);
641 int middleX
= (xpos
+ (width
/2));
642 int middleY
= (ypos
+ (height
/2));
644 // Start from top middle, clockwise.
653 hx
[0] = (int)(middleX
- (handleSize
/2));
654 hy
[0] = ypos
- handleSize
- handleMargin
;
656 hx
[1] = xpos
+ width
+ handleMargin
;
657 hy
[1] = ypos
- handleSize
- handleMargin
;
659 hx
[2] = xpos
+ width
+ handleMargin
;
660 hy
[2] = (int)(middleY
- (handleSize
/2));
662 hx
[3] = xpos
+ width
+ handleMargin
;
663 hy
[3] = ypos
+ height
+ handleMargin
;
665 hx
[4] = (int)(middleX
- (handleSize
/2));
666 hy
[4] = ypos
+ height
+ handleMargin
;
668 hx
[5] = xpos
- handleSize
- handleMargin
;
669 hy
[5] = ypos
+ height
+ handleMargin
;
671 hx
[6] = xpos
- handleSize
- handleMargin
;
672 hy
[6] = (int)(middleY
- (handleSize
/2));
674 hx
[7] = xpos
- handleSize
- handleMargin
;
675 hy
[7] = ypos
- handleSize
- handleMargin
;
678 // Returns 0 (no hit), 1 - 8 for which selection handle
679 // (clockwise from top middle)
680 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
685 CalcSelectionHandles(hx
, hy
);
688 for (i
= 0; i
< 8; i
++)
690 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
696 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
698 dc
.SetOptimization(FALSE
);
700 dc
.SetLogicalFunction(wxCOPY
);
701 dc
.SetPen(wxBLACK_PEN
);
702 dc
.SetBrush(wxBLACK_BRUSH
);
704 dc
.SetOptimization(TRUE
);
709 CalcSelectionHandles(hx
, hy
);
712 for (i
= 0; i
< 8; i
++)
714 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
718 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
720 dc
.DrawRectangle(x
, y
, w
, h
);
723 // If selectionHandle is zero, not dragging the selection handle.
724 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
726 int xpos
, ypos
, width
, height
;
727 handlerControl
->GetPosition(&xpos
, &ypos
);
728 handlerControl
->GetSize(&width
, &height
);
732 // dc.DestroyClippingRegion();
734 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
736 // Erase selection handles
737 // DrawSelectionHandles(dc, TRUE);
739 dc
.SetOptimization(FALSE
);
741 dc
.SetLogicalFunction(wxXOR
);
743 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
745 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
747 dc
.SetOptimization(TRUE
);
749 if (selectionHandle
> 0)
753 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
759 dragOffsetX
= (x
- xpos
);
760 dragOffsetY
= (y
- ypos
);
762 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
764 // Also draw bounding boxes for other selected items
765 wxNode
*node
= panel
->GetChildren()->First();
768 wxWindow
*win
= (wxWindow
*)node
->Data();
769 if (win
->IsKindOf(CLASSINFO(wxControl
)))
771 wxControl
*item
= (wxControl
*)win
;
772 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
773 if ((item
!= handlerControl
) && handler
->IsSelected())
776 item
->GetPosition(&x1
, &y1
);
777 item
->GetSize(&w1
, &h1
);
778 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
787 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
789 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
790 int xpos
, ypos
, width
, height
;
791 handlerControl
->GetPosition(&xpos
, &ypos
);
792 handlerControl
->GetSize(&width
, &height
);
794 if (selectionHandle
> 0)
804 int x1
, y1
, width1
, height1
;
806 switch (selectionHandle
)
812 height1
= (ypos
+ height
) - y
;
818 height1
= (y
- ypos
);
829 width1
= (xpos
+ width
) - x
;
836 height1
= (ypos
+ height
) - y
;
842 height1
= (y
- ypos
);
847 width1
= (xpos
+ width
) - x
;
853 width1
= (xpos
+ width
) - x
;
854 height1
= (ypos
+ height
) - y
;
859 dc
.SetLogicalFunction(wxXOR
);
860 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
862 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
864 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
871 dc
.SetLogicalFunction(wxXOR
);
872 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
874 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
876 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
878 // Also draw bounding boxes for other selected items
879 wxNode
*node
= panel
->GetChildren()->First();
882 wxWindow
*win
= (wxWindow
*)node
->Data();
883 if (win
->IsKindOf(CLASSINFO(wxControl
)))
885 wxControl
*item
= (wxControl
*)win
;
886 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
887 if ((item
!= handlerControl
) && handler
->IsSelected())
890 item
->GetPosition(&x1
, &y1
);
891 item
->GetSize(&w1
, &h1
);
892 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
893 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
894 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
903 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
905 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
909 int xpos
, ypos
, width
, height
;
910 handlerControl
->GetPosition(&xpos
, &ypos
);
911 handlerControl
->GetSize(&width
, &height
);
913 if (selectionHandle
> 0)
915 int x1
, y1
, width1
, height1
;
917 switch (selectionHandle
)
923 height1
= (ypos
+ height
) - y
;
929 height1
= (y
- ypos
);
940 width1
= (xpos
+ width
) - x
;
947 height1
= (ypos
+ height
) - y
;
953 height1
= (y
- ypos
);
958 width1
= (xpos
+ width
) - x
;
964 width1
= (xpos
+ width
) - x
;
965 height1
= (ypos
+ height
) - y
;
968 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
972 handlerControl
->Move((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
973 OldOnMove((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
975 // Also move other selected items
976 wxNode
*node
= panel
->GetChildren()->First();
979 wxWindow
*win
= (wxWindow
*)node
->Data();
980 if (win
->IsKindOf(CLASSINFO(wxControl
)))
982 wxControl
*item
= (wxControl
*)win
;
983 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
984 if ((item
!= handlerControl
) && handler
->IsSelected())
987 item
->GetPosition(&x1
, &y1
);
988 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
989 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
991 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
992 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
998 dc
.SetOptimization(FALSE
);
1000 dc
.SetLogicalFunction(wxCOPY
);
1001 dc
.SetPen(wxBLACK_PEN
);
1002 dc
.SetBrush(wxBLACK_BRUSH
);
1004 dc
.SetOptimization(TRUE
);
1006 // Force it to repaint the selection handles (if any)
1007 // since the panel thinks we're still within a drag and
1008 // won't paint the handles.
1010 DrawSelectionHandles(dc
);
1017 // These functions call OnItemEvent, OnItemMove and OnItemSize
1019 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1022 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1023 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1026 wxWindow
*panel
= handlerControl
->GetParent();
1027 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1029 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1030 if ( !panelHandler
->GetEvtHandlerEnabled() )
1036 panelHandler
->OnItemEvent(handlerControl
, event
);
1039 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1041 wxWindow
*panel
= handlerControl
->GetParent();
1042 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1045 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1046 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1049 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1051 wxWindow
*panel
= handlerControl
->GetParent();
1052 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1055 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1056 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1059 void wxResourceEditorControlHandler::OnSelect(bool select
)
1061 wxWindow
*panel
= handlerControl
->GetParent();
1062 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1065 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1066 panelHandler
->OnItemSelect(handlerControl
, select
);
1069 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1071 wxWindow
*panel
= handlerControl
->GetParent();
1072 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1075 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1076 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1079 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1081 wxWindow
*panel
= handlerControl
->GetParent();
1082 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1085 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1086 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);