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
)
49 EVT_SIZE(wxResourceEditorDialogHandler::OnSize
)
52 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler
, wxEvtHandler
)
53 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent
)
57 * Dialog box event handler
60 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
,
61 wxEvtHandler
*oldHandler
, wxResourceManager
*manager
)
63 handlerDialog
= dialog
;
64 handlerResource
= resource
;
65 handlerOldHandler
= oldHandler
;
66 resourceManager
= manager
;
68 dragMode
= wxDRAG_MODE_NONE
;
69 dragType
= wxDRAG_TYPE_NONE
;
76 checkTolerance
= TRUE
;
77 m_mouseCaptured
= FALSE
;
81 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
85 void wxResourceEditorDialogHandler::OnItemSelect(wxControl
*item
, bool select
)
88 resourceManager
->AddSelection(item
);
90 resourceManager
->RemoveSelection(item
);
93 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent
& WXUNUSED(event
))
95 wxPaintDC
dc(handlerDialog
);
97 PaintSelectionHandles(dc
);
100 // Add event handlers for all children
101 void wxResourceEditorDialogHandler::AddChildHandlers(void)
103 wxNode
*node
= handlerDialog
->GetChildren()->First();
106 wxControl
*child
= (wxControl
*)node
->Data();
107 wxEvtHandler
*childHandler
= child
->GetEventHandler();
108 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
== child
)
109 child
->PushEventHandler(new wxResourceEditorControlHandler(child
, childHandler
));
114 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
116 if (keys
& wxKEY_CTRL
)
118 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
122 // Deselect all items if click on panel
123 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
125 int needsRefresh
= 0;
126 wxNode
*node
= handlerDialog
->GetChildren()->First();
129 wxControl
*item
= (wxControl
*)node
->Data();
130 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
131 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
134 OnItemSelect(item
, FALSE
);
135 childHandler
->SelectItem(FALSE
);
139 if (needsRefresh
> 0)
141 wxClientDC
dc(handlerDialog
);
143 handlerDialog
->Refresh();
148 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
151 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
153 case RESED_BMPBUTTON
:
154 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
156 case RESED_STATICTEXT
:
157 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
159 case RESED_STATICBMP
:
160 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
162 case RESED_TEXTCTRL_SINGLE
:
163 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
165 case RESED_TEXTCTRL_MULTIPLE
:
166 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
169 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
172 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxComboBox", x
, y
);
175 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
178 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
180 case RESED_RADIOBUTTON
:
181 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioButton", x
, y
);
184 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
187 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
190 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
192 case RESED_STATICBOX
:
193 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
195 case RESED_SCROLLBAR
:
196 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
202 // Now switch pointer on.
203 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
205 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
209 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int WXUNUSED(keys
))
211 wxMenu
*menu
= resourceManager
->GetPopupMenu();
212 menu
->SetClientData((char *)handlerDialog
);
213 handlerDialog
->PopupMenu(menu
, x
, y
);
216 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int WXUNUSED(x
), int WXUNUSED(y
), int keys
)
218 if (keys
& wxKEY_CTRL
)
220 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
225 // If this is a wxStaticBox and the pointer isn't an arrow, chances
226 // are that we really meant to place an item on the panel.
228 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
230 OnLeftClick(x, y, keys);
235 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
237 if (childHandler
->IsSelected())
239 childHandler
->SelectItem(FALSE
);
240 OnItemSelect(item
, FALSE
);
242 wxClientDC
dc(handlerDialog
);
244 handlerDialog
->Refresh();
248 childHandler
->SelectItem(TRUE
);
249 OnItemSelect(item
, TRUE
);
251 // Deselect other items if shift is not pressed
252 int needsRefresh
= 0;
253 if (!(keys
& wxKEY_SHIFT
))
255 wxNode
*node
= item
->GetParent()->GetChildren()->First();
258 wxControl
*child
= (wxControl
*)node
->Data();
259 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
260 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
262 childHandler2
->SelectItem(FALSE
);
263 OnItemSelect(child
, FALSE
);
270 wxClientDC
dc(handlerDialog
);
271 childHandler
->DrawSelectionHandles(dc
);
273 if (needsRefresh
> 0)
276 handlerDialog
->Refresh();
281 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int WXUNUSED(keys
))
284 if (keys & wxKEY_CTRL)
286 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
291 wxMenu
*menu
= resourceManager
->GetPopupMenu();
292 menu
->SetClientData((char *)item
);
293 handlerDialog
->PopupMenu(menu
, x
, y
);
296 // Under Windows 95, you can resize a panel interactively depending on
298 void wxResourceEditorDialogHandler::OnSize(wxSizeEvent
& event
)
300 // Update the associated resource
302 handlerDialog
->GetClientSize(& w
, & h
);
304 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
305 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
307 wxSize sz
= handlerDialog
->ConvertPixelsToDialog(wxSize(w
, h
));
310 resource
->SetSize(resource
->GetX(), resource
->GetY(), w
, h
);
313 // An event outside any items: may be a drag event.
314 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
316 if (GetEvtHandlerEnabled())
318 // If we're dragging an item or selection handle,
319 // continue dragging.
320 if (dragMode
!= wxDRAG_MODE_NONE
)
322 ProcessItemEvent(dragItem
, event
, dragType
);
327 event
.Position(&x
, &y
);
329 // Find which selection handle we're on, if any
330 wxNode
*node
= handlerDialog
->GetChildren()->First();
333 wxWindow
*win
= (wxWindow
*)node
->Data();
334 if (win
->IsKindOf(CLASSINFO(wxControl
)))
336 wxControl
*item
= (wxControl
*)win
;
337 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
338 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
341 ProcessItemEvent(item
, event
, selHandle
);
348 // We're not on an item or selection handle.
349 // so... check for a left or right click event
350 // to send to the application.
352 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
353 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
359 handlerDialog
->ReleaseMouse();
360 m_mouseCaptured
= FALSE
;
363 OnLeftClick(x
, y
, keys
);
365 else if (event
.RightDown())
369 handlerDialog
->ReleaseMouse();
370 m_mouseCaptured
= FALSE
;
373 OnRightClick(x
, y
, keys
);
375 else if (event
.LeftDClick())
379 handlerDialog
->ReleaseMouse();
380 m_mouseCaptured
= FALSE
;
382 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
389 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
391 if (!GetEvtHandlerEnabled())
394 // Not a selection handle event: just a normal item event.
395 // Transform to panel coordinates.
397 item
->GetPosition(&x
, &y
);
399 event
.m_x
= event
.m_x
+ x
;
400 event
.m_y
= event
.m_y
+ y
;
402 ProcessItemEvent(item
, event
, dragType
);
405 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
407 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
410 event
.Position(&x
, &y
);
412 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
413 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
414 bool dragging
= event
.Dragging();
417 int dx
= (int)abs((x
- firstDragX
));
418 int dy
= (int)abs((y
- firstDragY
));
419 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
424 // If we've ignored the tolerance once, then ALWAYS ignore
425 // tolerance in this drag, even if we come back within
426 // the tolerance range.
428 checkTolerance
= FALSE
;
431 if (event
.LeftDClick())
435 handlerDialog
->ReleaseMouse();
436 m_mouseCaptured
= FALSE
;
439 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
441 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
443 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
444 wxClientDC
dc(handlerDialog
);
445 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
446 oldDragX
= x
; oldDragY
= y
;
447 if (!m_mouseCaptured
)
449 handlerDialog
->CaptureMouse();
450 m_mouseCaptured
= TRUE
;
453 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
455 wxClientDC
dc(handlerDialog
);
456 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
457 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
458 oldDragX
= x
; oldDragY
= y
;
460 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
462 wxClientDC
dc(handlerDialog
);
463 dragMode
= wxDRAG_MODE_NONE
;
464 checkTolerance
= TRUE
;
466 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
467 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
470 dragType
= wxDRAG_TYPE_NONE
;
474 handlerDialog
->ReleaseMouse();
475 m_mouseCaptured
= FALSE
;
478 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
480 wxClientDC
dc(handlerDialog
);
481 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
482 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
483 oldDragX
= x
; oldDragY
= y
;
485 if (!m_mouseCaptured
)
487 handlerDialog
->CaptureMouse();
488 m_mouseCaptured
= TRUE
;
491 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
493 oldDragX
= x
; oldDragY
= y
;
495 // Obsolete; no longer try to right-drag
496 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
498 dragMode
= wxDRAG_MODE_NONE
;
499 checkTolerance
= TRUE
;
501 dragType
= wxDRAG_TYPE_NONE
;
505 handlerDialog
->ReleaseMouse();
506 m_mouseCaptured
= FALSE
;
509 else if (event
.IsButton())
511 checkTolerance
= TRUE
;
513 if (event
.LeftDown())
516 dragMode
= wxDRAG_MODE_START_LEFT
;
519 dragType
= selectionHandle
;
521 if (!m_mouseCaptured
)
523 handlerDialog
->CaptureMouse();
524 m_mouseCaptured
= TRUE
;
527 else if (event
.RightDown())
531 handlerDialog
->ReleaseMouse();
532 m_mouseCaptured
= FALSE
;
536 childHandler
->OnRightClick(x
, y
, keys
);
538 OnRightClick(x
, y
, keys
);
540 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
544 dragMode = wxDRAG_MODE_START_RIGHT;
547 dragType = selectionHandle;
549 if (!m_mouseCaptured)
551 handlerDialog->CaptureMouse();
552 m_mouseCaptured = TRUE;
556 else if (event
.LeftUp())
559 childHandler
->OnLeftClick(x
, y
, keys
);
561 OnLeftClick(x
, y
, keys
);
563 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
567 handlerDialog
->ReleaseMouse();
568 m_mouseCaptured
= FALSE
;
571 else if (event
.RightUp())
575 childHandler->OnRightClick(x, y, keys);
577 OnRightClick(x, y, keys);
579 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
583 handlerDialog->ReleaseMouse();
584 m_mouseCaptured = FALSE;
591 // Calls DrawSelectionHandles for all items if
593 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
595 if (!GetEvtHandlerEnabled())
600 wxNode
*node
= handlerDialog
->GetChildren()->First();
603 wxWindow
*win
= (wxWindow
*)node
->Data();
604 if (win
->IsKindOf(CLASSINFO(wxControl
)))
606 wxControl
*item
= (wxControl
*)win
;
607 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
609 // Don't draw handles for an item that's being moved: it'll
611 if (childHandler
->IsSelected() && (item
!= dragItem
))
612 childHandler
->DrawSelectionHandles(dc
);
620 * Event handler for controls
623 int wxResourceEditorControlHandler::dragOffsetX
= 0;
624 int wxResourceEditorControlHandler::dragOffsetY
= 0;
626 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
627 wxEvtHandler
*oldHandler
)
629 handlerControl
= control
;
630 handlerOldHandler
= oldHandler
;
640 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
645 * Manipulation and drawing of items in Edit Mode
648 void wxResourceEditorControlHandler::SelectItem(bool select
)
653 // Returns TRUE or FALSE
654 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
656 int xpos
, ypos
, width
, height
;
657 handlerControl
->GetPosition(&xpos
, &ypos
);
658 handlerControl
->GetSize(&width
, &height
);
660 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
663 // Calculate position of the 8 handles
664 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
666 int xpos
, ypos
, width
, height
;
667 handlerControl
->GetPosition(&xpos
, &ypos
);
668 handlerControl
->GetSize(&width
, &height
);
669 int middleX
= (xpos
+ (width
/2));
670 int middleY
= (ypos
+ (height
/2));
672 // Start from top middle, clockwise.
681 hx
[0] = (int)(middleX
- (handleSize
/2));
682 hy
[0] = ypos
- handleSize
- handleMargin
;
684 hx
[1] = xpos
+ width
+ handleMargin
;
685 hy
[1] = ypos
- handleSize
- handleMargin
;
687 hx
[2] = xpos
+ width
+ handleMargin
;
688 hy
[2] = (int)(middleY
- (handleSize
/2));
690 hx
[3] = xpos
+ width
+ handleMargin
;
691 hy
[3] = ypos
+ height
+ handleMargin
;
693 hx
[4] = (int)(middleX
- (handleSize
/2));
694 hy
[4] = ypos
+ height
+ handleMargin
;
696 hx
[5] = xpos
- handleSize
- handleMargin
;
697 hy
[5] = ypos
+ height
+ handleMargin
;
699 hx
[6] = xpos
- handleSize
- handleMargin
;
700 hy
[6] = (int)(middleY
- (handleSize
/2));
702 hx
[7] = xpos
- handleSize
- handleMargin
;
703 hy
[7] = ypos
- handleSize
- handleMargin
;
706 // Returns 0 (no hit), 1 - 8 for which selection handle
707 // (clockwise from top middle)
708 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
713 CalcSelectionHandles(hx
, hy
);
716 for (i
= 0; i
< 8; i
++)
718 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
724 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
726 dc
.SetOptimization(FALSE
);
728 dc
.SetLogicalFunction(wxCOPY
);
729 dc
.SetPen(wxBLACK_PEN
);
730 dc
.SetBrush(wxBLACK_BRUSH
);
732 dc
.SetOptimization(TRUE
);
737 CalcSelectionHandles(hx
, hy
);
740 for (i
= 0; i
< 8; i
++)
742 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
746 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
748 dc
.DrawRectangle(x
, y
, w
, h
);
751 // If selectionHandle is zero, not dragging the selection handle.
752 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
754 int xpos
, ypos
, width
, height
;
755 handlerControl
->GetPosition(&xpos
, &ypos
);
756 handlerControl
->GetSize(&width
, &height
);
760 // dc.DestroyClippingRegion();
762 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
764 // Erase selection handles
765 // DrawSelectionHandles(dc, TRUE);
767 dc
.SetOptimization(FALSE
);
769 dc
.SetLogicalFunction(wxXOR
);
771 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
773 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
775 dc
.SetOptimization(TRUE
);
777 if (selectionHandle
> 0)
781 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
787 dragOffsetX
= (x
- xpos
);
788 dragOffsetY
= (y
- ypos
);
790 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
792 // Also draw bounding boxes for other selected items
793 wxNode
*node
= panel
->GetChildren()->First();
796 wxWindow
*win
= (wxWindow
*)node
->Data();
797 if (win
->IsKindOf(CLASSINFO(wxControl
)))
799 wxControl
*item
= (wxControl
*)win
;
800 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
801 if ((item
!= handlerControl
) && handler
->IsSelected())
804 item
->GetPosition(&x1
, &y1
);
805 item
->GetSize(&w1
, &h1
);
806 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
815 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
817 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
818 int xpos
, ypos
, width
, height
;
819 handlerControl
->GetPosition(&xpos
, &ypos
);
820 handlerControl
->GetSize(&width
, &height
);
822 if (selectionHandle
> 0)
832 int x1
, y1
, width1
, height1
;
834 switch (selectionHandle
)
840 height1
= (ypos
+ height
) - y
;
846 height1
= (y
- ypos
);
857 width1
= (xpos
+ width
) - x
;
864 height1
= (ypos
+ height
) - y
;
870 height1
= (y
- ypos
);
875 width1
= (xpos
+ width
) - x
;
881 width1
= (xpos
+ width
) - x
;
882 height1
= (ypos
+ height
) - y
;
887 dc
.SetLogicalFunction(wxXOR
);
888 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
890 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
892 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
899 dc
.SetLogicalFunction(wxXOR
);
900 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
902 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
904 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
906 // Also draw bounding boxes for other selected items
907 wxNode
*node
= panel
->GetChildren()->First();
910 wxWindow
*win
= (wxWindow
*)node
->Data();
911 if (win
->IsKindOf(CLASSINFO(wxControl
)))
913 wxControl
*item
= (wxControl
*)win
;
914 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
915 if ((item
!= handlerControl
) && handler
->IsSelected())
918 item
->GetPosition(&x1
, &y1
);
919 item
->GetSize(&w1
, &h1
);
920 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
921 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
922 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
931 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
933 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
937 int xpos
, ypos
, width
, height
;
938 handlerControl
->GetPosition(&xpos
, &ypos
);
939 handlerControl
->GetSize(&width
, &height
);
941 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
);
942 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
->GetParent());
944 if (selectionHandle
> 0)
946 int x1
, y1
, width1
, height1
;
948 switch (selectionHandle
)
954 height1
= (ypos
+ height
) - y
;
960 height1
= (y
- ypos
);
971 width1
= (xpos
+ width
) - x
;
978 height1
= (ypos
+ height
) - y
;
984 height1
= (y
- ypos
);
989 width1
= (xpos
+ width
) - x
;
995 width1
= (xpos
+ width
) - x
;
996 height1
= (ypos
+ height
) - y
;
999 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
1001 // Also update the associated resource
1002 // We need to convert to dialog units if this is not a dialog or panel, but
1003 // the parent resource specifies dialog units.
1004 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1006 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(x1
, y1
));
1007 x1
= pt
.x
; y1
= pt
.y
;
1008 wxSize sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxSize(width1
, height1
));
1009 width1
= sz
.x
; height1
= sz
.y
;
1011 resource
->SetSize(x1
, y1
, width1
, height1
);
1015 int newX
= (int)(x
- dragOffsetX
);
1016 int newY
= (int)(y
- dragOffsetY
);
1017 handlerControl
->Move(newX
, newY
);
1018 OldOnMove(newX
, newY
);
1020 // Also update the associated resource
1021 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1023 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1024 newX
= pt
.x
; newY
= pt
.y
;
1026 resource
->SetSize(newX
, newY
, resource
->GetWidth(), resource
->GetHeight());
1028 // Also move other selected items
1029 wxNode
*node
= panel
->GetChildren()->First();
1032 wxWindow
*win
= (wxWindow
*)node
->Data();
1033 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1035 wxControl
*item
= (wxControl
*)win
;
1036 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1037 if ((item
!= handlerControl
) && handler
->IsSelected())
1040 item
->GetPosition(&x1
, &y1
);
1041 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1042 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1044 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
1045 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1047 // Also update the associated resource
1048 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1049 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1051 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1052 x2
= pt
.x
; y2
= pt
.y
;
1054 resource
->SetSize(x2
, y2
, resource
->GetWidth(), resource
->GetHeight());
1058 node
= node
->Next();
1061 dc
.SetOptimization(FALSE
);
1063 dc
.SetLogicalFunction(wxCOPY
);
1064 dc
.SetPen(wxBLACK_PEN
);
1065 dc
.SetBrush(wxBLACK_BRUSH
);
1067 dc
.SetOptimization(TRUE
);
1069 // Force it to repaint the selection handles (if any)
1070 // since the panel thinks we're still within a drag and
1071 // won't paint the handles.
1073 DrawSelectionHandles(dc
);
1080 // These functions call OnItemEvent, OnItemMove and OnItemSize
1082 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1085 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1086 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1089 wxWindow
*panel
= handlerControl
->GetParent();
1090 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1092 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1093 if ( !panelHandler
->GetEvtHandlerEnabled() )
1099 panelHandler
->OnItemEvent(handlerControl
, event
);
1102 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1104 wxWindow
*panel
= handlerControl
->GetParent();
1105 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1108 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1109 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1112 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1114 wxWindow
*panel
= handlerControl
->GetParent();
1115 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1118 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1119 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1122 void wxResourceEditorControlHandler::OnSelect(bool select
)
1124 wxWindow
*panel
= handlerControl
->GetParent();
1125 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1128 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1129 panelHandler
->OnItemSelect(handlerControl
, select
);
1132 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1134 wxWindow
*panel
= handlerControl
->GetParent();
1135 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1138 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1139 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1142 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1144 wxWindow
*panel
= handlerControl
->GetParent();
1145 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1148 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1149 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);