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"
33 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
36 #include <strstream.h>
47 IMPLEMENT_CLASS(wxResourceEditorDialogHandler
, wxEvtHandler
)
48 IMPLEMENT_CLASS(wxResourceEditorControlHandler
, wxEvtHandler
)
50 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler
, wxEvtHandler
)
51 EVT_PAINT(wxResourceEditorDialogHandler::OnPaint
)
52 EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent
)
53 EVT_SIZE(wxResourceEditorDialogHandler::OnSize
)
56 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler
, wxEvtHandler
)
57 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent
)
61 * Dialog box event handler
64 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
,
65 wxEvtHandler
*oldHandler
, wxResourceManager
*manager
)
67 handlerDialog
= dialog
;
68 handlerResource
= resource
;
69 handlerOldHandler
= oldHandler
;
70 resourceManager
= manager
;
72 dragMode
= wxDRAG_MODE_NONE
;
73 dragType
= wxDRAG_TYPE_NONE
;
80 checkTolerance
= TRUE
;
81 m_mouseCaptured
= FALSE
;
85 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
89 void wxResourceEditorDialogHandler::OnItemSelect(wxControl
*item
, bool select
)
92 resourceManager
->AddSelection(item
);
94 resourceManager
->RemoveSelection(item
);
97 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent
& WXUNUSED(event
))
99 wxPaintDC
dc(handlerDialog
);
101 PaintSelectionHandles(dc
);
104 // Add event handlers for all children
105 void wxResourceEditorDialogHandler::AddChildHandlers(void)
107 wxNode
*node
= handlerDialog
->GetChildren()->First();
110 wxControl
*child
= (wxControl
*)node
->Data();
111 wxEvtHandler
*childHandler
= child
->GetEventHandler();
112 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
== child
)
113 child
->PushEventHandler(new wxResourceEditorControlHandler(child
, childHandler
));
118 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
120 if (keys
& wxKEY_CTRL
)
122 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
126 // Deselect all items if click on panel
127 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
129 int needsRefresh
= 0;
130 wxNode
*node
= handlerDialog
->GetChildren()->First();
133 wxControl
*item
= (wxControl
*)node
->Data();
134 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
135 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
138 OnItemSelect(item
, FALSE
);
139 childHandler
->SelectItem(FALSE
);
143 if (needsRefresh
> 0)
145 wxClientDC
dc(handlerDialog
);
147 handlerDialog
->Refresh();
152 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
155 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
157 case RESED_BMPBUTTON
:
158 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
160 case RESED_STATICTEXT
:
161 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
163 case RESED_STATICBMP
:
164 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
166 case RESED_TEXTCTRL_SINGLE
:
167 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
169 case RESED_TEXTCTRL_MULTIPLE
:
170 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
173 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
176 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxComboBox", x
, y
);
179 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
182 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
184 case RESED_RADIOBUTTON
:
185 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioButton", x
, y
);
188 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
191 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
194 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
196 case RESED_STATICBOX
:
197 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
199 case RESED_SCROLLBAR
:
200 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
206 // Now switch pointer on.
207 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
209 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
213 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int WXUNUSED(keys
))
215 wxMenu
*menu
= resourceManager
->GetPopupMenu();
216 menu
->SetClientData((char *)handlerDialog
);
217 handlerDialog
->PopupMenu(menu
, x
, y
);
220 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int WXUNUSED(x
), int WXUNUSED(y
), int keys
)
222 if (keys
& wxKEY_CTRL
)
224 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
229 // If this is a wxStaticBox and the pointer isn't an arrow, chances
230 // are that we really meant to place an item on the panel.
232 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
234 OnLeftClick(x, y, keys);
239 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
241 if (childHandler
->IsSelected())
243 childHandler
->SelectItem(FALSE
);
244 OnItemSelect(item
, FALSE
);
246 wxClientDC
dc(handlerDialog
);
248 handlerDialog
->Refresh();
252 childHandler
->SelectItem(TRUE
);
253 OnItemSelect(item
, TRUE
);
255 // Deselect other items if shift is not pressed
256 int needsRefresh
= 0;
257 if (!(keys
& wxKEY_SHIFT
))
259 wxNode
*node
= item
->GetParent()->GetChildren()->First();
262 wxControl
*child
= (wxControl
*)node
->Data();
263 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
264 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
266 childHandler2
->SelectItem(FALSE
);
267 OnItemSelect(child
, FALSE
);
274 wxClientDC
dc(handlerDialog
);
275 childHandler
->DrawSelectionHandles(dc
);
277 if (needsRefresh
> 0)
280 handlerDialog
->Refresh();
285 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int WXUNUSED(keys
))
288 if (keys & wxKEY_CTRL)
290 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
295 wxMenu
*menu
= resourceManager
->GetPopupMenu();
296 menu
->SetClientData((char *)item
);
297 handlerDialog
->PopupMenu(menu
, x
, y
);
300 // Under Windows 95, you can resize a panel interactively depending on
302 void wxResourceEditorDialogHandler::OnSize(wxSizeEvent
& event
)
304 // Update the associated resource
306 handlerDialog
->GetClientSize(& w
, & h
);
308 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
309 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
311 wxSize sz
= handlerDialog
->ConvertPixelsToDialog(wxSize(w
, h
));
314 resource
->SetSize(resource
->GetX(), resource
->GetY(), w
, h
);
317 // An event outside any items: may be a drag event.
318 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
320 if (GetEvtHandlerEnabled())
322 // If we're dragging an item or selection handle,
323 // continue dragging.
324 if (dragMode
!= wxDRAG_MODE_NONE
)
326 ProcessItemEvent(dragItem
, event
, dragType
);
331 event
.Position(&x
, &y
);
333 // Find which selection handle we're on, if any
334 wxNode
*node
= handlerDialog
->GetChildren()->First();
337 wxWindow
*win
= (wxWindow
*)node
->Data();
338 if (win
->IsKindOf(CLASSINFO(wxControl
)))
340 wxControl
*item
= (wxControl
*)win
;
341 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
342 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
345 ProcessItemEvent(item
, event
, selHandle
);
352 // We're not on an item or selection handle.
353 // so... check for a left or right click event
354 // to send to the application.
356 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
357 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
363 handlerDialog
->ReleaseMouse();
364 m_mouseCaptured
= FALSE
;
367 OnLeftClick(x
, y
, keys
);
369 else if (event
.RightDown())
373 handlerDialog
->ReleaseMouse();
374 m_mouseCaptured
= FALSE
;
377 OnRightClick(x
, y
, keys
);
379 else if (event
.LeftDClick())
383 handlerDialog
->ReleaseMouse();
384 m_mouseCaptured
= FALSE
;
386 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
393 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
395 if (!GetEvtHandlerEnabled())
398 // Not a selection handle event: just a normal item event.
399 // Transform to panel coordinates.
401 item
->GetPosition(&x
, &y
);
403 event
.m_x
= event
.m_x
+ x
;
404 event
.m_y
= event
.m_y
+ y
;
406 ProcessItemEvent(item
, event
, dragType
);
409 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
411 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
414 event
.Position(&x
, &y
);
416 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
417 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
418 bool dragging
= event
.Dragging();
421 int dx
= (int)abs((x
- firstDragX
));
422 int dy
= (int)abs((y
- firstDragY
));
423 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
428 // If we've ignored the tolerance once, then ALWAYS ignore
429 // tolerance in this drag, even if we come back within
430 // the tolerance range.
432 checkTolerance
= FALSE
;
435 if (event
.LeftDClick())
439 handlerDialog
->ReleaseMouse();
440 m_mouseCaptured
= FALSE
;
443 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
445 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
447 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
448 wxClientDC
dc(handlerDialog
);
449 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
450 oldDragX
= x
; oldDragY
= y
;
451 if (!m_mouseCaptured
)
453 handlerDialog
->CaptureMouse();
454 m_mouseCaptured
= TRUE
;
457 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
459 wxClientDC
dc(handlerDialog
);
460 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
461 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
462 oldDragX
= x
; oldDragY
= y
;
464 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
466 wxClientDC
dc(handlerDialog
);
467 dragMode
= wxDRAG_MODE_NONE
;
468 checkTolerance
= TRUE
;
470 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
471 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
474 dragType
= wxDRAG_TYPE_NONE
;
478 handlerDialog
->ReleaseMouse();
479 m_mouseCaptured
= FALSE
;
482 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
484 wxClientDC
dc(handlerDialog
);
485 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
486 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
487 oldDragX
= x
; oldDragY
= y
;
489 if (!m_mouseCaptured
)
491 handlerDialog
->CaptureMouse();
492 m_mouseCaptured
= TRUE
;
495 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
497 oldDragX
= x
; oldDragY
= y
;
499 // Obsolete; no longer try to right-drag
500 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
502 dragMode
= wxDRAG_MODE_NONE
;
503 checkTolerance
= TRUE
;
505 dragType
= wxDRAG_TYPE_NONE
;
509 handlerDialog
->ReleaseMouse();
510 m_mouseCaptured
= FALSE
;
513 else if (event
.IsButton())
515 checkTolerance
= TRUE
;
517 if (event
.LeftDown())
520 dragMode
= wxDRAG_MODE_START_LEFT
;
523 dragType
= selectionHandle
;
525 if (!m_mouseCaptured
)
527 handlerDialog
->CaptureMouse();
528 m_mouseCaptured
= TRUE
;
531 else if (event
.RightDown())
535 handlerDialog
->ReleaseMouse();
536 m_mouseCaptured
= FALSE
;
540 childHandler
->OnRightClick(x
, y
, keys
);
542 OnRightClick(x
, y
, keys
);
544 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
548 dragMode = wxDRAG_MODE_START_RIGHT;
551 dragType = selectionHandle;
553 if (!m_mouseCaptured)
555 handlerDialog->CaptureMouse();
556 m_mouseCaptured = TRUE;
560 else if (event
.LeftUp())
563 childHandler
->OnLeftClick(x
, y
, keys
);
565 OnLeftClick(x
, y
, keys
);
567 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
571 handlerDialog
->ReleaseMouse();
572 m_mouseCaptured
= FALSE
;
575 else if (event
.RightUp())
579 childHandler->OnRightClick(x, y, keys);
581 OnRightClick(x, y, keys);
583 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
587 handlerDialog->ReleaseMouse();
588 m_mouseCaptured = FALSE;
595 // Calls DrawSelectionHandles for all items if
597 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
599 if (!GetEvtHandlerEnabled())
604 wxNode
*node
= handlerDialog
->GetChildren()->First();
607 wxWindow
*win
= (wxWindow
*)node
->Data();
608 if (win
->IsKindOf(CLASSINFO(wxControl
)))
610 wxControl
*item
= (wxControl
*)win
;
611 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
613 // Don't draw handles for an item that's being moved: it'll
615 if (childHandler
->IsSelected() && (item
!= dragItem
))
616 childHandler
->DrawSelectionHandles(dc
);
624 * Event handler for controls
627 int wxResourceEditorControlHandler::dragOffsetX
= 0;
628 int wxResourceEditorControlHandler::dragOffsetY
= 0;
630 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
631 wxEvtHandler
*oldHandler
)
633 handlerControl
= control
;
634 handlerOldHandler
= oldHandler
;
644 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
649 * Manipulation and drawing of items in Edit Mode
652 void wxResourceEditorControlHandler::SelectItem(bool select
)
657 // Returns TRUE or FALSE
658 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
660 int xpos
, ypos
, width
, height
;
661 handlerControl
->GetPosition(&xpos
, &ypos
);
662 handlerControl
->GetSize(&width
, &height
);
664 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
667 // Calculate position of the 8 handles
668 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
670 int xpos
, ypos
, width
, height
;
671 handlerControl
->GetPosition(&xpos
, &ypos
);
672 handlerControl
->GetSize(&width
, &height
);
673 int middleX
= (xpos
+ (width
/2));
674 int middleY
= (ypos
+ (height
/2));
676 // Start from top middle, clockwise.
685 hx
[0] = (int)(middleX
- (handleSize
/2));
686 hy
[0] = ypos
- handleSize
- handleMargin
;
688 hx
[1] = xpos
+ width
+ handleMargin
;
689 hy
[1] = ypos
- handleSize
- handleMargin
;
691 hx
[2] = xpos
+ width
+ handleMargin
;
692 hy
[2] = (int)(middleY
- (handleSize
/2));
694 hx
[3] = xpos
+ width
+ handleMargin
;
695 hy
[3] = ypos
+ height
+ handleMargin
;
697 hx
[4] = (int)(middleX
- (handleSize
/2));
698 hy
[4] = ypos
+ height
+ handleMargin
;
700 hx
[5] = xpos
- handleSize
- handleMargin
;
701 hy
[5] = ypos
+ height
+ handleMargin
;
703 hx
[6] = xpos
- handleSize
- handleMargin
;
704 hy
[6] = (int)(middleY
- (handleSize
/2));
706 hx
[7] = xpos
- handleSize
- handleMargin
;
707 hy
[7] = ypos
- handleSize
- handleMargin
;
710 // Returns 0 (no hit), 1 - 8 for which selection handle
711 // (clockwise from top middle)
712 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
717 CalcSelectionHandles(hx
, hy
);
720 for (i
= 0; i
< 8; i
++)
722 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
728 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
730 dc
.SetOptimization(FALSE
);
732 dc
.SetLogicalFunction(wxCOPY
);
733 dc
.SetPen(wxBLACK_PEN
);
734 dc
.SetBrush(wxBLACK_BRUSH
);
736 dc
.SetOptimization(TRUE
);
741 CalcSelectionHandles(hx
, hy
);
744 for (i
= 0; i
< 8; i
++)
746 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
750 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
752 dc
.DrawRectangle(x
, y
, w
, h
);
755 // If selectionHandle is zero, not dragging the selection handle.
756 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
758 int xpos
, ypos
, width
, height
;
759 handlerControl
->GetPosition(&xpos
, &ypos
);
760 handlerControl
->GetSize(&width
, &height
);
764 // dc.DestroyClippingRegion();
766 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
768 // Erase selection handles
769 // DrawSelectionHandles(dc, TRUE);
771 dc
.SetOptimization(FALSE
);
773 dc
.SetLogicalFunction(wxXOR
);
775 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
777 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
779 dc
.SetOptimization(TRUE
);
781 if (selectionHandle
> 0)
785 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
791 dragOffsetX
= (x
- xpos
);
792 dragOffsetY
= (y
- ypos
);
794 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
796 // Also draw bounding boxes for other selected items
797 wxNode
*node
= panel
->GetChildren()->First();
800 wxWindow
*win
= (wxWindow
*)node
->Data();
801 if (win
->IsKindOf(CLASSINFO(wxControl
)))
803 wxControl
*item
= (wxControl
*)win
;
804 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
805 if ((item
!= handlerControl
) && handler
->IsSelected())
808 item
->GetPosition(&x1
, &y1
);
809 item
->GetSize(&w1
, &h1
);
810 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
819 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
821 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
822 int xpos
, ypos
, width
, height
;
823 handlerControl
->GetPosition(&xpos
, &ypos
);
824 handlerControl
->GetSize(&width
, &height
);
826 if (selectionHandle
> 0)
836 int x1
, y1
, width1
, height1
;
838 switch (selectionHandle
)
844 height1
= (ypos
+ height
) - y
;
850 height1
= (y
- ypos
);
861 width1
= (xpos
+ width
) - x
;
868 height1
= (ypos
+ height
) - y
;
874 height1
= (y
- ypos
);
879 width1
= (xpos
+ width
) - x
;
885 width1
= (xpos
+ width
) - x
;
886 height1
= (ypos
+ height
) - y
;
891 dc
.SetLogicalFunction(wxXOR
);
892 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
894 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
896 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
903 dc
.SetLogicalFunction(wxXOR
);
904 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
906 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
908 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
910 // Also draw bounding boxes for other selected items
911 wxNode
*node
= panel
->GetChildren()->First();
914 wxWindow
*win
= (wxWindow
*)node
->Data();
915 if (win
->IsKindOf(CLASSINFO(wxControl
)))
917 wxControl
*item
= (wxControl
*)win
;
918 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
919 if ((item
!= handlerControl
) && handler
->IsSelected())
922 item
->GetPosition(&x1
, &y1
);
923 item
->GetSize(&w1
, &h1
);
924 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
925 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
926 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
935 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
937 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
941 int xpos
, ypos
, width
, height
;
942 handlerControl
->GetPosition(&xpos
, &ypos
);
943 handlerControl
->GetSize(&width
, &height
);
945 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
);
946 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
->GetParent());
948 if (selectionHandle
> 0)
950 int x1
, y1
, width1
, height1
;
952 switch (selectionHandle
)
958 height1
= (ypos
+ height
) - y
;
964 height1
= (y
- ypos
);
975 width1
= (xpos
+ width
) - x
;
982 height1
= (ypos
+ height
) - y
;
988 height1
= (y
- ypos
);
993 width1
= (xpos
+ width
) - x
;
999 width1
= (xpos
+ width
) - x
;
1000 height1
= (ypos
+ height
) - y
;
1003 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
1005 // Also update the associated resource
1006 // We need to convert to dialog units if this is not a dialog or panel, but
1007 // the parent resource specifies dialog units.
1008 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1010 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(x1
, y1
));
1011 x1
= pt
.x
; y1
= pt
.y
;
1012 wxSize sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxSize(width1
, height1
));
1013 width1
= sz
.x
; height1
= sz
.y
;
1015 resource
->SetSize(x1
, y1
, width1
, height1
);
1019 int newX
= (int)(x
- dragOffsetX
);
1020 int newY
= (int)(y
- dragOffsetY
);
1021 handlerControl
->Move(newX
, newY
);
1022 OldOnMove(newX
, newY
);
1024 // Also update the associated resource
1025 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1027 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1028 newX
= pt
.x
; newY
= pt
.y
;
1030 resource
->SetSize(newX
, newY
, resource
->GetWidth(), resource
->GetHeight());
1032 // Also move other selected items
1033 wxNode
*node
= panel
->GetChildren()->First();
1036 wxWindow
*win
= (wxWindow
*)node
->Data();
1037 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1039 wxControl
*item
= (wxControl
*)win
;
1040 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1041 if ((item
!= handlerControl
) && handler
->IsSelected())
1044 item
->GetPosition(&x1
, &y1
);
1045 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1046 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1048 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
1049 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1051 // Also update the associated resource
1052 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1053 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1055 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1056 x2
= pt
.x
; y2
= pt
.y
;
1058 resource
->SetSize(x2
, y2
, resource
->GetWidth(), resource
->GetHeight());
1062 node
= node
->Next();
1065 dc
.SetOptimization(FALSE
);
1067 dc
.SetLogicalFunction(wxCOPY
);
1068 dc
.SetPen(wxBLACK_PEN
);
1069 dc
.SetBrush(wxBLACK_BRUSH
);
1071 dc
.SetOptimization(TRUE
);
1073 // Force it to repaint the selection handles (if any)
1074 // since the panel thinks we're still within a drag and
1075 // won't paint the handles.
1077 DrawSelectionHandles(dc
);
1084 // These functions call OnItemEvent, OnItemMove and OnItemSize
1086 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1089 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1090 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1093 wxWindow
*panel
= handlerControl
->GetParent();
1094 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1096 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1097 if ( !panelHandler
->GetEvtHandlerEnabled() )
1103 panelHandler
->OnItemEvent(handlerControl
, event
);
1106 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1108 wxWindow
*panel
= handlerControl
->GetParent();
1109 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1112 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1113 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1116 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1118 wxWindow
*panel
= handlerControl
->GetParent();
1119 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1122 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1123 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1126 void wxResourceEditorControlHandler::OnSelect(bool select
)
1128 wxWindow
*panel
= handlerControl
->GetParent();
1129 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1132 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1133 panelHandler
->OnItemSelect(handlerControl
, select
);
1136 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1138 wxWindow
*panel
= handlerControl
->GetParent();
1139 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1142 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1143 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1146 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1148 wxWindow
*panel
= handlerControl
->GetParent();
1149 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1152 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1153 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);