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();
382 if (dragItem
) childHandler
= (wxResourceEditorControlHandler
*)dragItem
->GetEventHandler();
385 event
.Position(&x
, &y
);
387 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
388 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
389 bool dragging
= event
.Dragging();
392 int dx
= (int)abs((x
- firstDragX
));
393 int dy
= (int)abs((y
- firstDragY
));
394 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
399 // If we've ignored the tolerance once, then ALWAYS ignore
400 // tolerance in this drag, even if we come back within
401 // the tolerance range.
403 checkTolerance
= FALSE
;
406 if (event
.LeftDClick())
410 handlerDialog
->ReleaseMouse();
411 m_mouseCaptured
= FALSE
;
414 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
416 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
418 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
419 wxClientDC
dc(handlerDialog
);
420 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
421 oldDragX
= x
; oldDragY
= y
;
422 if (!m_mouseCaptured
)
424 handlerDialog
->CaptureMouse();
425 m_mouseCaptured
= TRUE
;
428 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
430 wxClientDC
dc(handlerDialog
);
431 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
432 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
433 oldDragX
= x
; oldDragY
= y
;
435 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
437 wxClientDC
dc(handlerDialog
);
438 dragMode
= wxDRAG_MODE_NONE
;
439 checkTolerance
= TRUE
;
441 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
442 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
445 dragType
= wxDRAG_TYPE_NONE
;
449 handlerDialog
->ReleaseMouse();
450 m_mouseCaptured
= FALSE
;
453 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
455 wxClientDC
dc(handlerDialog
);
456 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
457 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
458 oldDragX
= x
; oldDragY
= y
;
460 if (!m_mouseCaptured
)
462 handlerDialog
->CaptureMouse();
463 m_mouseCaptured
= TRUE
;
466 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
468 oldDragX
= x
; oldDragY
= y
;
470 // Obsolete; no longer try to right-drag
471 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
473 dragMode
= wxDRAG_MODE_NONE
;
474 checkTolerance
= TRUE
;
476 dragType
= wxDRAG_TYPE_NONE
;
480 handlerDialog
->ReleaseMouse();
481 m_mouseCaptured
= FALSE
;
484 else if (event
.IsButton())
486 checkTolerance
= TRUE
;
488 if (event
.LeftDown())
491 dragMode
= wxDRAG_MODE_START_LEFT
;
494 dragType
= selectionHandle
;
496 if (!m_mouseCaptured
)
498 handlerDialog
->CaptureMouse();
499 m_mouseCaptured
= TRUE
;
502 else if (event
.RightDown())
506 handlerDialog
->ReleaseMouse();
507 m_mouseCaptured
= FALSE
;
511 childHandler
->OnRightClick(x
, y
, keys
);
513 OnRightClick(x
, y
, keys
);
515 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
519 dragMode = wxDRAG_MODE_START_RIGHT;
522 dragType = selectionHandle;
524 if (!m_mouseCaptured)
526 handlerDialog->CaptureMouse();
527 m_mouseCaptured = TRUE;
531 else if (event
.LeftUp())
534 childHandler
->OnLeftClick(x
, y
, keys
);
536 OnLeftClick(x
, y
, keys
);
538 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
542 handlerDialog
->ReleaseMouse();
543 m_mouseCaptured
= FALSE
;
546 else if (event
.RightUp())
550 childHandler->OnRightClick(x, y, keys);
552 OnRightClick(x, y, keys);
554 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
558 handlerDialog->ReleaseMouse();
559 m_mouseCaptured = FALSE;
566 // Calls DrawSelectionHandles for all items if
568 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
570 if (!GetEvtHandlerEnabled())
575 wxNode
*node
= handlerDialog
->GetChildren()->First();
578 wxWindow
*win
= (wxWindow
*)node
->Data();
579 if (win
->IsKindOf(CLASSINFO(wxControl
)))
581 wxControl
*item
= (wxControl
*)win
;
582 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
584 // Don't draw handles for an item that's being moved: it'll
586 if (childHandler
->IsSelected() && (item
!= dragItem
))
587 childHandler
->DrawSelectionHandles(dc
);
595 * Event handler for controls
598 int wxResourceEditorControlHandler::dragOffsetX
= 0;
599 int wxResourceEditorControlHandler::dragOffsetY
= 0;
601 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
602 wxEvtHandler
*oldHandler
)
604 handlerControl
= control
;
605 handlerOldHandler
= oldHandler
;
615 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
620 * Manipulation and drawing of items in Edit Mode
623 void wxResourceEditorControlHandler::SelectItem(bool select
)
628 // Returns TRUE or FALSE
629 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
631 int xpos
, ypos
, width
, height
;
632 handlerControl
->GetPosition(&xpos
, &ypos
);
633 handlerControl
->GetSize(&width
, &height
);
635 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
638 // Calculate position of the 8 handles
639 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
641 int xpos
, ypos
, width
, height
;
642 handlerControl
->GetPosition(&xpos
, &ypos
);
643 handlerControl
->GetSize(&width
, &height
);
644 int middleX
= (xpos
+ (width
/2));
645 int middleY
= (ypos
+ (height
/2));
647 // Start from top middle, clockwise.
656 hx
[0] = (int)(middleX
- (handleSize
/2));
657 hy
[0] = ypos
- handleSize
- handleMargin
;
659 hx
[1] = xpos
+ width
+ handleMargin
;
660 hy
[1] = ypos
- handleSize
- handleMargin
;
662 hx
[2] = xpos
+ width
+ handleMargin
;
663 hy
[2] = (int)(middleY
- (handleSize
/2));
665 hx
[3] = xpos
+ width
+ handleMargin
;
666 hy
[3] = ypos
+ height
+ handleMargin
;
668 hx
[4] = (int)(middleX
- (handleSize
/2));
669 hy
[4] = ypos
+ height
+ handleMargin
;
671 hx
[5] = xpos
- handleSize
- handleMargin
;
672 hy
[5] = ypos
+ height
+ handleMargin
;
674 hx
[6] = xpos
- handleSize
- handleMargin
;
675 hy
[6] = (int)(middleY
- (handleSize
/2));
677 hx
[7] = xpos
- handleSize
- handleMargin
;
678 hy
[7] = ypos
- handleSize
- handleMargin
;
681 // Returns 0 (no hit), 1 - 8 for which selection handle
682 // (clockwise from top middle)
683 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
688 CalcSelectionHandles(hx
, hy
);
691 for (i
= 0; i
< 8; i
++)
693 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
699 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
701 dc
.SetOptimization(FALSE
);
703 dc
.SetLogicalFunction(wxCOPY
);
704 dc
.SetPen(wxBLACK_PEN
);
705 dc
.SetBrush(wxBLACK_BRUSH
);
707 dc
.SetOptimization(TRUE
);
712 CalcSelectionHandles(hx
, hy
);
715 for (i
= 0; i
< 8; i
++)
717 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
721 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
723 dc
.DrawRectangle(x
, y
, w
, h
);
726 // If selectionHandle is zero, not dragging the selection handle.
727 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
729 int xpos
, ypos
, width
, height
;
730 handlerControl
->GetPosition(&xpos
, &ypos
);
731 handlerControl
->GetSize(&width
, &height
);
735 // dc.DestroyClippingRegion();
737 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
739 // Erase selection handles
740 // DrawSelectionHandles(dc, TRUE);
742 dc
.SetOptimization(FALSE
);
744 dc
.SetLogicalFunction(wxXOR
);
746 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
748 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
750 dc
.SetOptimization(TRUE
);
752 if (selectionHandle
> 0)
756 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
762 dragOffsetX
= (x
- xpos
);
763 dragOffsetY
= (y
- ypos
);
765 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
767 // Also draw bounding boxes for other selected items
768 wxNode
*node
= panel
->GetChildren()->First();
771 wxWindow
*win
= (wxWindow
*)node
->Data();
772 if (win
->IsKindOf(CLASSINFO(wxControl
)))
774 wxControl
*item
= (wxControl
*)win
;
775 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
776 if ((item
!= handlerControl
) && handler
->IsSelected())
779 item
->GetPosition(&x1
, &y1
);
780 item
->GetSize(&w1
, &h1
);
781 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
790 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
792 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
793 int xpos
, ypos
, width
, height
;
794 handlerControl
->GetPosition(&xpos
, &ypos
);
795 handlerControl
->GetSize(&width
, &height
);
797 if (selectionHandle
> 0)
807 int x1
, y1
, width1
, height1
;
809 switch (selectionHandle
)
815 height1
= (ypos
+ height
) - y
;
821 height1
= (y
- ypos
);
832 width1
= (xpos
+ width
) - x
;
839 height1
= (ypos
+ height
) - y
;
845 height1
= (y
- ypos
);
850 width1
= (xpos
+ width
) - x
;
856 width1
= (xpos
+ width
) - x
;
857 height1
= (ypos
+ height
) - y
;
862 dc
.SetLogicalFunction(wxXOR
);
863 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
865 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
867 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
874 dc
.SetLogicalFunction(wxXOR
);
875 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
877 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
879 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
881 // Also draw bounding boxes for other selected items
882 wxNode
*node
= panel
->GetChildren()->First();
885 wxWindow
*win
= (wxWindow
*)node
->Data();
886 if (win
->IsKindOf(CLASSINFO(wxControl
)))
888 wxControl
*item
= (wxControl
*)win
;
889 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
890 if ((item
!= handlerControl
) && handler
->IsSelected())
893 item
->GetPosition(&x1
, &y1
);
894 item
->GetSize(&w1
, &h1
);
895 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
896 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
897 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
906 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
908 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
912 int xpos
, ypos
, width
, height
;
913 handlerControl
->GetPosition(&xpos
, &ypos
);
914 handlerControl
->GetSize(&width
, &height
);
916 if (selectionHandle
> 0)
918 int x1
, y1
, width1
, height1
;
920 switch (selectionHandle
)
926 height1
= (ypos
+ height
) - y
;
932 height1
= (y
- ypos
);
943 width1
= (xpos
+ width
) - x
;
950 height1
= (ypos
+ height
) - y
;
956 height1
= (y
- ypos
);
961 width1
= (xpos
+ width
) - x
;
967 width1
= (xpos
+ width
) - x
;
968 height1
= (ypos
+ height
) - y
;
971 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
975 handlerControl
->Move((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
976 OldOnMove((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
978 // Also move other selected items
979 wxNode
*node
= panel
->GetChildren()->First();
982 wxWindow
*win
= (wxWindow
*)node
->Data();
983 if (win
->IsKindOf(CLASSINFO(wxControl
)))
985 wxControl
*item
= (wxControl
*)win
;
986 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
987 if ((item
!= handlerControl
) && handler
->IsSelected())
990 item
->GetPosition(&x1
, &y1
);
991 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
992 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
994 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
995 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1001 dc
.SetOptimization(FALSE
);
1003 dc
.SetLogicalFunction(wxCOPY
);
1004 dc
.SetPen(wxBLACK_PEN
);
1005 dc
.SetBrush(wxBLACK_BRUSH
);
1007 dc
.SetOptimization(TRUE
);
1009 // Force it to repaint the selection handles (if any)
1010 // since the panel thinks we're still within a drag and
1011 // won't paint the handles.
1013 DrawSelectionHandles(dc
);
1020 // These functions call OnItemEvent, OnItemMove and OnItemSize
1022 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1025 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1026 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1029 wxWindow
*panel
= handlerControl
->GetParent();
1030 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1032 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1033 if ( !panelHandler
->GetEvtHandlerEnabled() )
1039 panelHandler
->OnItemEvent(handlerControl
, event
);
1042 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1044 wxWindow
*panel
= handlerControl
->GetParent();
1045 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1048 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1049 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1052 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1054 wxWindow
*panel
= handlerControl
->GetParent();
1055 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1058 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1059 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1062 void wxResourceEditorControlHandler::OnSelect(bool select
)
1064 wxWindow
*panel
= handlerControl
->GetParent();
1065 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1068 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1069 panelHandler
->OnItemSelect(handlerControl
, select
);
1072 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1074 wxWindow
*panel
= handlerControl
->GetParent();
1075 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1078 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1079 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1082 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1084 wxWindow
*panel
= handlerControl
->GetParent();
1085 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1088 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1089 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);