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"
37 IMPLEMENT_CLASS(wxResourceEditorDialogHandler
, wxEvtHandler
)
38 IMPLEMENT_CLASS(wxResourceEditorControlHandler
, wxEvtHandler
)
40 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler
, wxEvtHandler
)
41 EVT_PAINT(wxResourceEditorDialogHandler::OnPaint
)
42 EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent
)
43 EVT_SIZE(wxResourceEditorDialogHandler::OnSize
)
46 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler
, wxEvtHandler
)
47 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent
)
51 * Dialog box event handler
54 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
,
55 wxEvtHandler
*oldHandler
, wxResourceManager
*manager
)
57 handlerDialog
= dialog
;
58 handlerResource
= resource
;
59 handlerOldHandler
= oldHandler
;
60 resourceManager
= manager
;
62 dragMode
= wxDRAG_MODE_NONE
;
63 dragType
= wxDRAG_TYPE_NONE
;
70 checkTolerance
= TRUE
;
71 m_mouseCaptured
= FALSE
;
75 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
79 void wxResourceEditorDialogHandler::OnItemSelect(wxControl
*item
, bool select
)
82 resourceManager
->AddSelection(item
);
84 resourceManager
->RemoveSelection(item
);
87 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent
& WXUNUSED(event
))
89 wxPaintDC
dc(handlerDialog
);
91 PaintSelectionHandles(dc
);
94 // Add event handlers for all children
95 void wxResourceEditorDialogHandler::AddChildHandlers(void)
97 wxNode
*node
= handlerDialog
->GetChildren().First();
100 wxControl
*child
= (wxControl
*)node
->Data();
101 wxEvtHandler
*childHandler
= child
->GetEventHandler();
102 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
== child
)
103 child
->PushEventHandler(new wxResourceEditorControlHandler(child
, childHandler
));
108 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
110 if (keys
& wxKEY_CTRL
)
112 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
116 // Deselect all items if click on panel
117 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
119 int needsRefresh
= 0;
120 wxNode
*node
= handlerDialog
->GetChildren().First();
123 wxControl
*item
= (wxControl
*)node
->Data();
124 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
125 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
128 OnItemSelect(item
, FALSE
);
129 childHandler
->SelectItem(FALSE
);
133 if (needsRefresh
> 0)
135 wxClientDC
dc(handlerDialog
);
137 handlerDialog
->Refresh();
142 // Round down to take account of dialog units
143 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
144 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
146 wxPoint pt
= handlerDialog
->ConvertPixelsToDialog(wxPoint(x
, y
));
148 // Convert back so we've rounded down
149 pt
= handlerDialog
->ConvertDialogToPixels(pt
);
150 pt
= handlerDialog
->ConvertPixelsToDialog(pt
);
151 pt
= handlerDialog
->ConvertDialogToPixels(pt
);
156 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
159 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
161 case RESED_BMPBUTTON
:
162 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
164 case RESED_STATICTEXT
:
165 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
167 case RESED_STATICBMP
:
168 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
170 case RESED_TEXTCTRL_SINGLE
:
171 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
173 case RESED_TEXTCTRL_MULTIPLE
:
174 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
177 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
180 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxComboBox", x
, y
);
183 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
186 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
188 case RESED_RADIOBUTTON
:
189 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioButton", x
, y
);
192 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
195 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
198 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
200 case RESED_STATICBOX
:
201 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
203 case RESED_SCROLLBAR
:
204 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
210 // Now switch pointer on.
211 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
213 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
217 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int WXUNUSED(keys
))
219 wxMenu
*menu
= resourceManager
->GetPopupMenu();
220 menu
->SetClientData((char *)handlerDialog
);
221 handlerDialog
->PopupMenu(menu
, x
, y
);
224 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int WXUNUSED(x
), int WXUNUSED(y
), int keys
)
226 if (keys
& wxKEY_CTRL
)
228 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
233 // If this is a wxStaticBox and the pointer isn't an arrow, chances
234 // are that we really meant to place an item on the panel.
236 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
238 OnLeftClick(x, y, keys);
243 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
245 if (childHandler
->IsSelected())
247 childHandler
->SelectItem(FALSE
);
248 OnItemSelect(item
, FALSE
);
250 wxClientDC
dc(handlerDialog
);
252 handlerDialog
->Refresh();
256 childHandler
->SelectItem(TRUE
);
257 OnItemSelect(item
, TRUE
);
259 // Deselect other items if shift is not pressed
260 int needsRefresh
= 0;
261 if (!(keys
& wxKEY_SHIFT
))
263 wxNode
*node
= item
->GetParent()->GetChildren().First();
266 wxControl
*child
= (wxControl
*)node
->Data();
267 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
268 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
270 childHandler2
->SelectItem(FALSE
);
271 OnItemSelect(child
, FALSE
);
278 wxClientDC
dc(handlerDialog
);
279 childHandler
->DrawSelectionHandles(dc
);
281 if (needsRefresh
> 0)
284 handlerDialog
->Refresh();
289 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int WXUNUSED(keys
))
292 if (keys & wxKEY_CTRL)
294 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
299 wxMenu
*menu
= resourceManager
->GetPopupMenu();
300 menu
->SetClientData((char *)item
);
301 handlerDialog
->PopupMenu(menu
, x
, y
);
304 // Under Windows 95, you can resize a panel interactively depending on
306 void wxResourceEditorDialogHandler::OnSize(wxSizeEvent
& event
)
308 // Update the associated resource
310 handlerDialog
->GetClientSize(& w
, & h
);
312 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
313 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
315 wxSize sz
= handlerDialog
->ConvertPixelsToDialog(wxSize(w
, h
));
318 resource
->SetSize(resource
->GetX(), resource
->GetY(), w
, h
);
321 // An event outside any items: may be a drag event.
322 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
324 if (GetEvtHandlerEnabled())
326 // If we're dragging an item or selection handle,
327 // continue dragging.
328 if (dragMode
!= wxDRAG_MODE_NONE
)
330 ProcessItemEvent(dragItem
, event
, dragType
);
335 event
.Position(&x
, &y
);
337 // Find which selection handle we're on, if any
338 wxNode
*node
= handlerDialog
->GetChildren().First();
341 wxWindow
*win
= (wxWindow
*)node
->Data();
342 if (win
->IsKindOf(CLASSINFO(wxControl
)))
344 wxControl
*item
= (wxControl
*)win
;
345 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
346 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
349 ProcessItemEvent(item
, event
, selHandle
);
356 // We're not on an item or selection handle.
357 // so... check for a left or right click event
358 // to send to the application.
360 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
361 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
367 handlerDialog
->ReleaseMouse();
368 m_mouseCaptured
= FALSE
;
371 OnLeftClick(x
, y
, keys
);
373 else if (event
.RightDown())
377 handlerDialog
->ReleaseMouse();
378 m_mouseCaptured
= FALSE
;
381 OnRightClick(x
, y
, keys
);
383 else if (event
.LeftDClick())
387 handlerDialog
->ReleaseMouse();
388 m_mouseCaptured
= FALSE
;
390 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
397 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
399 if (!GetEvtHandlerEnabled())
402 // Not a selection handle event: just a normal item event.
403 // Transform to panel coordinates.
405 item
->GetPosition(&x
, &y
);
407 event
.m_x
= event
.m_x
+ x
;
408 event
.m_y
= event
.m_y
+ y
;
410 ProcessItemEvent(item
, event
, dragType
);
413 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
415 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
418 event
.Position(&x
, &y
);
420 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
421 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
422 bool dragging
= event
.Dragging();
425 int dx
= (int)abs((x
- firstDragX
));
426 int dy
= (int)abs((y
- firstDragY
));
427 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
432 // If we've ignored the tolerance once, then ALWAYS ignore
433 // tolerance in this drag, even if we come back within
434 // the tolerance range.
436 checkTolerance
= FALSE
;
439 if (event
.LeftDClick())
443 handlerDialog
->ReleaseMouse();
444 m_mouseCaptured
= FALSE
;
447 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
449 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
451 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
452 wxClientDC
dc(handlerDialog
);
453 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
454 oldDragX
= x
; oldDragY
= y
;
455 if (!m_mouseCaptured
)
457 handlerDialog
->CaptureMouse();
458 m_mouseCaptured
= TRUE
;
461 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
463 wxClientDC
dc(handlerDialog
);
464 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
465 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
466 oldDragX
= x
; oldDragY
= y
;
468 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
470 wxClientDC
dc(handlerDialog
);
471 dragMode
= wxDRAG_MODE_NONE
;
472 checkTolerance
= TRUE
;
474 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
475 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
478 dragType
= wxDRAG_TYPE_NONE
;
482 handlerDialog
->ReleaseMouse();
483 m_mouseCaptured
= FALSE
;
486 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
488 wxClientDC
dc(handlerDialog
);
489 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
490 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
491 oldDragX
= x
; oldDragY
= y
;
493 if (!m_mouseCaptured
)
495 handlerDialog
->CaptureMouse();
496 m_mouseCaptured
= TRUE
;
499 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
501 oldDragX
= x
; oldDragY
= y
;
503 // Obsolete; no longer try to right-drag
504 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
506 dragMode
= wxDRAG_MODE_NONE
;
507 checkTolerance
= TRUE
;
509 dragType
= wxDRAG_TYPE_NONE
;
513 handlerDialog
->ReleaseMouse();
514 m_mouseCaptured
= FALSE
;
517 else if (event
.IsButton())
519 checkTolerance
= TRUE
;
521 if (event
.LeftDown())
524 dragMode
= wxDRAG_MODE_START_LEFT
;
527 dragType
= selectionHandle
;
529 if (!m_mouseCaptured
)
531 handlerDialog
->CaptureMouse();
532 m_mouseCaptured
= TRUE
;
535 else if (event
.RightDown())
539 handlerDialog
->ReleaseMouse();
540 m_mouseCaptured
= FALSE
;
544 childHandler
->OnRightClick(x
, y
, keys
);
546 OnRightClick(x
, y
, keys
);
548 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
552 dragMode = wxDRAG_MODE_START_RIGHT;
555 dragType = selectionHandle;
557 if (!m_mouseCaptured)
559 handlerDialog->CaptureMouse();
560 m_mouseCaptured = TRUE;
564 else if (event
.LeftUp())
567 childHandler
->OnLeftClick(x
, y
, keys
);
569 OnLeftClick(x
, y
, keys
);
571 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
575 handlerDialog
->ReleaseMouse();
576 m_mouseCaptured
= FALSE
;
579 else if (event
.RightUp())
583 childHandler->OnRightClick(x, y, keys);
585 OnRightClick(x, y, keys);
587 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
591 handlerDialog->ReleaseMouse();
592 m_mouseCaptured = FALSE;
599 // Calls DrawSelectionHandles for all items if
601 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
603 if (!GetEvtHandlerEnabled())
608 wxNode
*node
= handlerDialog
->GetChildren().First();
611 wxWindow
*win
= (wxWindow
*)node
->Data();
612 if (win
->IsKindOf(CLASSINFO(wxControl
)))
614 wxControl
*item
= (wxControl
*)win
;
615 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
617 // Don't draw handles for an item that's being moved: it'll
619 if (childHandler
->IsSelected() && (item
!= dragItem
))
620 childHandler
->DrawSelectionHandles(dc
);
628 * Event handler for controls
631 int wxResourceEditorControlHandler::dragOffsetX
= 0;
632 int wxResourceEditorControlHandler::dragOffsetY
= 0;
634 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
635 wxEvtHandler
*oldHandler
)
637 handlerControl
= control
;
638 handlerOldHandler
= oldHandler
;
648 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
653 * Manipulation and drawing of items in Edit Mode
656 void wxResourceEditorControlHandler::SelectItem(bool select
)
661 // Returns TRUE or FALSE
662 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
664 int xpos
, ypos
, width
, height
;
665 handlerControl
->GetPosition(&xpos
, &ypos
);
666 handlerControl
->GetSize(&width
, &height
);
668 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
671 // Calculate position of the 8 handles
672 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
674 int xpos
, ypos
, width
, height
;
675 handlerControl
->GetPosition(&xpos
, &ypos
);
676 handlerControl
->GetSize(&width
, &height
);
677 int middleX
= (xpos
+ (width
/2));
678 int middleY
= (ypos
+ (height
/2));
680 // Start from top middle, clockwise.
689 hx
[0] = (int)(middleX
- (handleSize
/2));
690 hy
[0] = ypos
- handleSize
- handleMargin
;
692 hx
[1] = xpos
+ width
+ handleMargin
;
693 hy
[1] = ypos
- handleSize
- handleMargin
;
695 hx
[2] = xpos
+ width
+ handleMargin
;
696 hy
[2] = (int)(middleY
- (handleSize
/2));
698 hx
[3] = xpos
+ width
+ handleMargin
;
699 hy
[3] = ypos
+ height
+ handleMargin
;
701 hx
[4] = (int)(middleX
- (handleSize
/2));
702 hy
[4] = ypos
+ height
+ handleMargin
;
704 hx
[5] = xpos
- handleSize
- handleMargin
;
705 hy
[5] = ypos
+ height
+ handleMargin
;
707 hx
[6] = xpos
- handleSize
- handleMargin
;
708 hy
[6] = (int)(middleY
- (handleSize
/2));
710 hx
[7] = xpos
- handleSize
- handleMargin
;
711 hy
[7] = ypos
- handleSize
- handleMargin
;
714 // Returns 0 (no hit), 1 - 8 for which selection handle
715 // (clockwise from top middle)
716 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
721 CalcSelectionHandles(hx
, hy
);
724 for (i
= 0; i
< 8; i
++)
726 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
732 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
734 dc
.SetOptimization(FALSE
);
736 dc
.SetLogicalFunction(wxCOPY
);
737 dc
.SetPen(* wxBLACK_PEN
);
738 dc
.SetBrush(* wxBLACK_BRUSH
);
740 dc
.SetOptimization(TRUE
);
745 CalcSelectionHandles(hx
, hy
);
748 for (i
= 0; i
< 8; i
++)
750 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
754 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
756 dc
.DrawRectangle(x
, y
, w
, h
);
759 // If selectionHandle is zero, not dragging the selection handle.
760 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
762 int xpos
, ypos
, width
, height
;
763 handlerControl
->GetPosition(&xpos
, &ypos
);
764 handlerControl
->GetSize(&width
, &height
);
768 // dc.DestroyClippingRegion();
770 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
772 // Erase selection handles
773 // DrawSelectionHandles(dc, TRUE);
775 dc
.SetOptimization(FALSE
);
777 dc
.SetLogicalFunction(wxINVERT
);
779 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
781 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
783 dc
.SetOptimization(TRUE
);
785 if (selectionHandle
> 0)
789 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
795 dragOffsetX
= (x
- xpos
);
796 dragOffsetY
= (y
- ypos
);
798 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
800 // Also draw bounding boxes for other selected items
801 wxNode
*node
= panel
->GetChildren().First();
804 wxWindow
*win
= (wxWindow
*)node
->Data();
805 if (win
->IsKindOf(CLASSINFO(wxControl
)))
807 wxControl
*item
= (wxControl
*)win
;
808 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
809 if ((item
!= handlerControl
) && handler
->IsSelected())
812 item
->GetPosition(&x1
, &y1
);
813 item
->GetSize(&w1
, &h1
);
814 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
823 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
825 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
826 int xpos
, ypos
, width
, height
;
827 handlerControl
->GetPosition(&xpos
, &ypos
);
828 handlerControl
->GetSize(&width
, &height
);
830 if (selectionHandle
> 0)
840 int x1
, y1
, width1
, height1
;
842 switch (selectionHandle
)
848 height1
= (ypos
+ height
) - y
;
854 height1
= (y
- ypos
);
865 width1
= (xpos
+ width
) - x
;
872 height1
= (ypos
+ height
) - y
;
878 height1
= (y
- ypos
);
883 width1
= (xpos
+ width
) - x
;
889 width1
= (xpos
+ width
) - x
;
890 height1
= (ypos
+ height
) - y
;
895 dc
.SetLogicalFunction(wxINVERT
);
896 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
898 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
900 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
907 dc
.SetLogicalFunction(wxINVERT
);
908 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
910 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
912 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
914 // Also draw bounding boxes for other selected items
915 wxNode
*node
= panel
->GetChildren().First();
918 wxWindow
*win
= (wxWindow
*)node
->Data();
919 if (win
->IsKindOf(CLASSINFO(wxControl
)))
921 wxControl
*item
= (wxControl
*)win
;
922 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
923 if ((item
!= handlerControl
) && handler
->IsSelected())
926 item
->GetPosition(&x1
, &y1
);
927 item
->GetSize(&w1
, &h1
);
928 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
929 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
930 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
939 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
941 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
945 int xpos
, ypos
, width
, height
;
946 handlerControl
->GetPosition(&xpos
, &ypos
);
947 handlerControl
->GetSize(&width
, &height
);
949 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
);
950 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
->GetParent());
952 if (selectionHandle
> 0)
954 int x1
, y1
, width1
, height1
;
956 switch (selectionHandle
)
962 height1
= (ypos
+ height
) - y
;
968 height1
= (y
- ypos
);
979 width1
= (xpos
+ width
) - x
;
986 height1
= (ypos
+ height
) - y
;
992 height1
= (y
- ypos
);
997 width1
= (xpos
+ width
) - x
;
1003 width1
= (xpos
+ width
) - x
;
1004 height1
= (ypos
+ height
) - y
;
1007 // Update the associated resource
1008 // We need to convert to dialog units if this is not a dialog or panel, but
1009 // the parent resource specifies dialog units.
1012 int resourceWidth
= width1
;
1013 int resourceHeight
= height1
;
1015 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1017 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(x1
, y1
));
1018 wxSize sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxSize(width1
, height1
));
1020 // Convert back so we've rounded down
1021 sz
= handlerControl
->GetParent()->ConvertDialogToPixels(sz
);
1022 sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(sz
);
1023 resourceWidth
= sz
.x
; resourceHeight
= sz
.y
;
1025 sz
= handlerControl
->GetParent()->ConvertDialogToPixels(sz
);
1029 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1030 pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(pt
);
1031 resourceX
= pt
.x
; resourceY
= pt
.y
;
1033 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1037 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
1038 resource
->SetSize(resourceX
, resourceY
, resourceWidth
, resourceHeight
);
1042 // Correction 31/12/98. We need to round down the values to take into account
1043 // the fact that several pixels map to the same dialog unit.
1045 int newX
= (int)(x
- dragOffsetX
);
1046 int newY
= (int)(y
- dragOffsetY
);
1047 int resourceX
= newX
;
1048 int resourceY
= newY
;
1050 // Update the associated resource
1051 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1053 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1054 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1055 pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(pt
);
1056 resourceX
= pt
.x
; resourceY
= pt
.y
;
1057 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1059 // Having converted it several times, we know it'll map to dialog units exactly.
1063 handlerControl
->Move(newX
, newY
);
1064 OldOnMove(newX
, newY
);
1066 resource
->SetSize(resourceX
, resourceY
, resource
->GetWidth(), resource
->GetHeight());
1068 // Also move other selected items
1069 wxNode
*node
= panel
->GetChildren().First();
1072 wxWindow
*win
= (wxWindow
*)node
->Data();
1073 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1075 wxControl
*item
= (wxControl
*)win
;
1076 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1077 if ((item
!= handlerControl
) && handler
->IsSelected())
1080 item
->GetPosition(&x1
, &y1
);
1081 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1082 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1084 // Update the associated resource
1085 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1086 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1088 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(x2
, y2
));
1089 pt
= item
->GetParent()->ConvertDialogToPixels(pt
);
1090 pt
= item
->GetParent()->ConvertPixelsToDialog(pt
);
1092 resourceX
= pt
.x
; resourceY
= pt
.y
;
1093 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1095 // Having converted it several times, we know it'll map to dialog units exactly
1101 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
1102 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1104 resource
->SetSize(resourceX
, resourceY
, resource
->GetWidth(), resource
->GetHeight());
1108 node
= node
->Next();
1111 dc
.SetOptimization(FALSE
);
1113 dc
.SetLogicalFunction(wxCOPY
);
1114 dc
.SetPen(* wxBLACK_PEN
);
1115 dc
.SetBrush(* wxBLACK_BRUSH
);
1117 dc
.SetOptimization(TRUE
);
1119 // Force it to repaint the selection handles (if any)
1120 // since the panel thinks we're still within a drag and
1121 // won't paint the handles.
1123 DrawSelectionHandles(dc
);
1130 // These functions call OnItemEvent, OnItemMove and OnItemSize
1132 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1135 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1136 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1139 wxWindow
*panel
= handlerControl
->GetParent();
1140 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1142 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1143 if ( !panelHandler
->GetEvtHandlerEnabled() )
1149 panelHandler
->OnItemEvent(handlerControl
, event
);
1152 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1154 wxWindow
*panel
= handlerControl
->GetParent();
1155 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1158 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1159 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1162 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1164 wxWindow
*panel
= handlerControl
->GetParent();
1165 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1168 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1169 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1172 void wxResourceEditorControlHandler::OnSelect(bool select
)
1174 wxWindow
*panel
= handlerControl
->GetParent();
1175 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1178 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1179 panelHandler
->OnItemSelect(handlerControl
, select
);
1182 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1184 wxWindow
*panel
= handlerControl
->GetParent();
1185 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1188 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1189 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1192 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1194 wxWindow
*panel
= handlerControl
->GetParent();
1195 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1198 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1199 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);