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"
38 IMPLEMENT_CLASS(wxResourceEditorDialogHandler
, wxEvtHandler
)
39 IMPLEMENT_CLASS(wxResourceEditorControlHandler
, wxEvtHandler
)
41 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler
, wxEvtHandler
)
42 EVT_PAINT(wxResourceEditorDialogHandler::OnPaint
)
43 EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent
)
44 EVT_SIZE(wxResourceEditorDialogHandler::OnSize
)
47 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler
, wxEvtHandler
)
48 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent
)
52 * Dialog box event handler
55 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
,
56 wxEvtHandler
*oldHandler
, wxResourceManager
*manager
)
58 handlerDialog
= dialog
;
59 handlerResource
= resource
;
60 handlerOldHandler
= oldHandler
;
61 resourceManager
= manager
;
63 dragMode
= wxDRAG_MODE_NONE
;
64 dragType
= wxDRAG_TYPE_NONE
;
71 checkTolerance
= TRUE
;
72 m_mouseCaptured
= FALSE
;
76 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
80 void wxResourceEditorDialogHandler::OnItemSelect(wxControl
*item
, bool select
)
83 resourceManager
->AddSelection(item
);
85 resourceManager
->RemoveSelection(item
);
88 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent
& WXUNUSED(event
))
90 wxPaintDC
dc(handlerDialog
);
92 PaintSelectionHandles(dc
);
95 // Add event handlers for all children
96 void wxResourceEditorDialogHandler::AddChildHandlers(void)
98 wxNode
*node
= handlerDialog
->GetChildren().First();
101 wxControl
*child
= (wxControl
*)node
->Data();
102 wxEvtHandler
*childHandler
= child
->GetEventHandler();
103 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
== child
)
104 child
->PushEventHandler(new wxResourceEditorControlHandler(child
, childHandler
));
109 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
111 if (keys
& wxKEY_CTRL
)
113 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
117 // Deselect all items if click on panel
118 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
120 int needsRefresh
= 0;
121 wxNode
*node
= handlerDialog
->GetChildren().First();
124 wxControl
*item
= (wxControl
*)node
->Data();
125 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
126 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
129 OnItemSelect(item
, FALSE
);
130 childHandler
->SelectItem(FALSE
);
134 if (needsRefresh
> 0)
136 wxClientDC
dc(handlerDialog
);
138 handlerDialog
->Refresh();
143 // Round down to take account of dialog units
144 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
145 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
147 wxPoint pt
= handlerDialog
->ConvertPixelsToDialog(wxPoint(x
, y
));
149 // Convert back so we've rounded down
150 pt
= handlerDialog
->ConvertDialogToPixels(pt
);
151 pt
= handlerDialog
->ConvertPixelsToDialog(pt
);
152 pt
= handlerDialog
->ConvertDialogToPixels(pt
);
157 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
160 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
162 case RESED_BMPBUTTON
:
163 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
165 case RESED_STATICTEXT
:
166 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
168 case RESED_STATICBMP
:
169 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
171 case RESED_TEXTCTRL_SINGLE
:
172 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
174 case RESED_TEXTCTRL_MULTIPLE
:
175 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
178 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
181 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxComboBox", x
, y
);
184 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
187 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
189 case RESED_RADIOBUTTON
:
190 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioButton", x
, y
);
193 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
196 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
199 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
201 case RESED_STATICBOX
:
202 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
204 case RESED_SCROLLBAR
:
205 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
211 // Now switch pointer on.
212 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
214 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
218 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int WXUNUSED(keys
))
220 wxMenu
*menu
= resourceManager
->GetPopupMenu();
221 menu
->SetClientData((char *)handlerDialog
);
223 wxString
str("wxDialog : ");
224 str
+= handlerDialog
->GetName();
226 menu
->SetLabel(OBJECT_MENU_TITLE
,str
);
228 handlerDialog
->PopupMenu(menu
, x
, y
);
231 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int WXUNUSED(x
), int WXUNUSED(y
), int keys
)
233 if (keys
& wxKEY_CTRL
)
235 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
240 // If this is a wxStaticBox and the pointer isn't an arrow, chances
241 // are that we really meant to place an item on the panel.
243 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
245 OnLeftClick(x, y, keys);
250 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
252 if (childHandler
->IsSelected())
254 childHandler
->SelectItem(FALSE
);
255 OnItemSelect(item
, FALSE
);
257 wxClientDC
dc(handlerDialog
);
259 handlerDialog
->Refresh();
263 childHandler
->SelectItem(TRUE
);
264 OnItemSelect(item
, TRUE
);
266 // Deselect other items if shift is not pressed
267 int needsRefresh
= 0;
268 if (!(keys
& wxKEY_SHIFT
))
270 wxNode
*node
= item
->GetParent()->GetChildren().First();
273 wxControl
*child
= (wxControl
*)node
->Data();
274 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
275 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
277 childHandler2
->SelectItem(FALSE
);
278 OnItemSelect(child
, FALSE
);
285 wxClientDC
dc(handlerDialog
);
286 childHandler
->DrawSelectionHandles(dc
);
288 if (needsRefresh
> 0)
291 handlerDialog
->Refresh();
296 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int WXUNUSED(keys
))
299 if (keys & wxKEY_CTRL)
301 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
306 wxMenu
*menu
= resourceManager
->GetPopupMenu();
307 menu
->SetClientData((char *)item
);
309 wxWindow
*win
= (wxWindow
*)item
;
311 wxWindowPropertyInfo
*info
= resourceManager
->CreatePropertyInfoForWindow(win
);
314 info
->SetResource(resourceManager
->FindResourceForWindow(win
));
316 str
= win
->GetClassInfo()->GetClassName();
318 if (win
->GetName() != "")
319 str
+= win
->GetName();
321 menu
->SetLabel(OBJECT_MENU_TITLE
,str
);
324 handlerDialog
->PopupMenu(menu
, x
, y
);
327 // Under Windows 95, you can resize a panel interactively depending on
329 void wxResourceEditorDialogHandler::OnSize(wxSizeEvent
& event
)
331 // Update the associated resource
333 handlerDialog
->GetClientSize(& w
, & h
);
335 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
336 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
338 wxSize sz
= handlerDialog
->ConvertPixelsToDialog(wxSize(w
, h
));
341 resource
->SetSize(resource
->GetX(), resource
->GetY(), w
, h
);
344 // An event outside any items: may be a drag event.
345 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
347 if (GetEvtHandlerEnabled())
349 // If we're dragging an item or selection handle,
350 // continue dragging.
351 if (dragMode
!= wxDRAG_MODE_NONE
)
353 if (dragType
!= wxDRAG_TYPE_BOUNDING_BOX
&&
356 ProcessItemEvent(dragItem
, event
, dragType
);
362 event
.GetPosition(&x
, &y
);
364 // Find which selection handle we're on, if any
365 wxNode
*node
= handlerDialog
->GetChildren().First();
368 wxWindow
*win
= (wxWindow
*)node
->Data();
369 if (win
->IsKindOf(CLASSINFO(wxControl
)))
371 wxControl
*item
= (wxControl
*)win
;
372 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
373 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
376 ProcessItemEvent(item
, event
, selHandle
);
383 // We're not on an item or selection handle.
384 // so... check for a left or right click event
385 // to send to the application.
387 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
388 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
392 if (event
.Dragging() &&
393 (dragType
== wxDRAG_TYPE_BOUNDING_BOX
))
396 if (dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
398 wxClientDC
dc(handlerDialog
);
399 OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, NULL
);
400 OnDragContinue(TRUE
, x
, y
, keys
, dc
, NULL
);
401 oldDragX
= x
; oldDragY
= y
;
404 else if (event.LeftUp() && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
407 wxClientDC dc(handlerDialog);
408 OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, NULL);
409 OnDragContinue(TRUE, x, y, keys, dc, NULL);
410 oldDragX = x; oldDragY = y;
416 if (event
.LeftDown())
418 if (!m_mouseCaptured
)
420 handlerDialog
->CaptureMouse();
421 m_mouseCaptured
= TRUE
;
424 // Starting to draw a bounding box around
425 // some numbe of controls on the dialog
427 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
430 dragMode
= wxDRAG_MODE_START_LEFT
;
433 dragType
= wxDRAG_TYPE_BOUNDING_BOX
;
434 wxClientDC
dc(handlerDialog
);
435 OnDragBegin(x
, y
, keys
, dc
, NULL
);
436 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
437 oldDragX
= x
; oldDragY
= y
;
442 else if (event
.LeftUp())
446 handlerDialog
->ReleaseMouse();
447 m_mouseCaptured
= FALSE
;
450 if (dragType
== wxDRAG_TYPE_BOUNDING_BOX
)
452 // Determine the bounds of the surrounding box
453 int upperLeftX
= (x
< firstDragX
) ? x
: firstDragX
;
454 int upperLeftY
= (y
< firstDragY
) ? y
: firstDragY
;
455 int lowerRightX
= (x
> firstDragX
) ? x
: firstDragX
;
456 int lowerRightY
= (y
> firstDragY
) ? y
: firstDragY
;
461 bool widgetWithinBounds
= FALSE
;
463 int needsRefresh
= 0;
465 wxClientDC
dc(handlerDialog
);
467 // Determine what widgets which fall within the bounding box
469 wxNode
*node
= handlerDialog
->GetChildren().First();
472 widgetWithinBounds
= FALSE
;
473 wxWindow
*win
= (wxWindow
*)node
->Data();
474 if (win
->IsKindOf(CLASSINFO(wxControl
)))
476 wxControl
*item
= (wxControl
*)win
;
477 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
479 // Unselect all widgets that are currently selected
480 if (!(keys
& wxKEY_SHIFT
) && childHandler
->IsSelected())
483 OnItemSelect(item
, FALSE
);
484 childHandler
->SelectItem(FALSE
);
487 // Get X,Y and WIDTH,HEIGHT of the widget to be able
488 // to determine if any portion of it is within the bounded
490 childHandler
->handlerControl
->GetPosition(&xpos
, &ypos
);
491 childHandler
->handlerControl
->GetSize(&width
, &height
);
493 // Check if the current widget is inside the rectangle
494 // that was just bounded
495 if (xpos
>= upperLeftX
&& xpos
<= lowerRightX
)
497 if (ypos
>= upperLeftY
&& ypos
<= lowerRightY
)
498 widgetWithinBounds
= TRUE
;
499 else if (ypos
+height
>= upperLeftY
&& ypos
+height
<= lowerRightY
)
500 widgetWithinBounds
= TRUE
;
502 else if (xpos
+width
>= upperLeftX
&& xpos
<= lowerRightX
)
504 if (ypos
>= upperLeftY
&& ypos
<= lowerRightY
)
505 widgetWithinBounds
= TRUE
;
506 else if (ypos
+height
>= upperLeftY
&& ypos
+height
<= lowerRightY
)
507 widgetWithinBounds
= TRUE
;
510 if (widgetWithinBounds
)
512 childHandler
->SelectItem(TRUE
);
513 OnItemSelect(item
, TRUE
);
515 // childHandler->DrawSelectionHandles(dc);
522 OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, NULL
);
523 OnDragEnd(x
, y
, keys
, dc
, NULL
);
525 if (needsRefresh
> 0)
528 handlerDialog
->Refresh();
531 // Always paint, in case the bounding box overlapped with
532 // the handles of any selected widgets, that way when the
533 // bounding box is cleared, the handles don't get partially
534 // erased where the overlap occured
535 PaintSelectionHandles(dc
);
537 dragMode
= wxDRAG_MODE_NONE
;
538 checkTolerance
= TRUE
;
540 dragType
= wxDRAG_TYPE_NONE
;
543 OnLeftClick(x
, y
, keys
);
545 else if (event
.RightDown())
549 handlerDialog
->ReleaseMouse();
550 m_mouseCaptured
= FALSE
;
553 OnRightClick(x
, y
, keys
);
555 else if (event
.LeftDClick())
559 handlerDialog
->ReleaseMouse();
560 m_mouseCaptured
= FALSE
;
562 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
569 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
571 if (!GetEvtHandlerEnabled())
574 // Not a selection handle event: just a normal item event.
575 // Transform to panel coordinates.
577 item
->GetPosition(&x
, &y
);
579 event
.m_x
= event
.m_x
+ x
;
580 event
.m_y
= event
.m_y
+ y
;
582 ProcessItemEvent(item
, event
, dragType
);
585 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
587 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
590 event
.GetPosition(&x
, &y
);
592 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
593 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
594 bool dragging
= event
.Dragging();
598 int dx
= (int)abs((x
- firstDragX
));
599 int dy
= (int)abs((y
- firstDragY
));
600 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
605 // If we've ignored the tolerance once, then ALWAYS ignore
606 // tolerance in this drag, even if we come back within
607 // the tolerance range.
609 checkTolerance
= FALSE
;
612 if (event
.LeftDClick())
616 handlerDialog
->ReleaseMouse();
617 m_mouseCaptured
= FALSE
;
620 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
622 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
624 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
625 wxClientDC
dc(handlerDialog
);
626 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
627 oldDragX
= x
; oldDragY
= y
;
628 if (!m_mouseCaptured
)
630 handlerDialog
->CaptureMouse();
631 m_mouseCaptured
= TRUE
;
634 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
636 wxClientDC
dc(handlerDialog
);
637 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
638 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
639 oldDragX
= x
; oldDragY
= y
;
641 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
643 wxClientDC
dc(handlerDialog
);
644 dragMode
= wxDRAG_MODE_NONE
;
645 checkTolerance
= TRUE
;
647 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
648 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
651 dragType
= wxDRAG_TYPE_NONE
;
655 handlerDialog
->ReleaseMouse();
656 m_mouseCaptured
= FALSE
;
659 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
661 wxClientDC
dc(handlerDialog
);
662 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
663 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
664 oldDragX
= x
; oldDragY
= y
;
666 if (!m_mouseCaptured
)
668 handlerDialog
->CaptureMouse();
669 m_mouseCaptured
= TRUE
;
672 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
674 oldDragX
= x
; oldDragY
= y
;
676 // Obsolete; no longer try to right-drag
677 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
679 dragMode
= wxDRAG_MODE_NONE
;
680 checkTolerance
= TRUE
;
682 dragType
= wxDRAG_TYPE_NONE
;
686 handlerDialog
->ReleaseMouse();
687 m_mouseCaptured
= FALSE
;
690 else if (event
.IsButton())
692 checkTolerance
= TRUE
;
694 if (event
.LeftDown())
697 dragMode
= wxDRAG_MODE_START_LEFT
;
700 dragType
= selectionHandle
;
702 if (!m_mouseCaptured
)
704 handlerDialog
->CaptureMouse();
705 m_mouseCaptured
= TRUE
;
708 else if (event
.RightDown())
712 handlerDialog
->ReleaseMouse();
713 m_mouseCaptured
= FALSE
;
717 childHandler
->OnRightClick(x
, y
, keys
);
719 OnRightClick(x
, y
, keys
);
721 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
725 dragMode = wxDRAG_MODE_START_RIGHT;
728 dragType = selectionHandle;
730 if (!m_mouseCaptured)
732 handlerDialog->CaptureMouse();
733 m_mouseCaptured = TRUE;
737 else if (event
.LeftUp())
740 childHandler
->OnLeftClick(x
, y
, keys
);
742 OnLeftClick(x
, y
, keys
);
744 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
748 handlerDialog
->ReleaseMouse();
749 m_mouseCaptured
= FALSE
;
752 else if (event
.RightUp())
756 childHandler->OnRightClick(x, y, keys);
758 OnRightClick(x, y, keys);
760 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
764 handlerDialog->ReleaseMouse();
765 m_mouseCaptured = FALSE;
772 // Calls DrawSelectionHandles for all items if
774 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
776 if (!GetEvtHandlerEnabled())
781 wxNode
*node
= handlerDialog
->GetChildren().First();
784 wxWindow
*win
= (wxWindow
*)node
->Data();
785 if (win
->IsKindOf(CLASSINFO(wxControl
)))
787 wxControl
*item
= (wxControl
*)win
;
788 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
790 // Don't draw handles for an item that's being moved: it'll
792 if (childHandler
->IsSelected() && (item
!= dragItem
))
793 childHandler
->DrawSelectionHandles(dc
);
802 void wxResourceEditorDialogHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
804 dc
.DrawRectangle(x
, y
, w
, h
);
808 void wxResourceEditorDialogHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
813 dc.SetOptimization(FALSE);
815 dc.SetLogicalFunction(wxINVERT);
817 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
819 dc.SetBrush(* wxTRANSPARENT_BRUSH);
821 dc.SetOptimization(TRUE);
824 // DrawBoundingBox(dc, xpos, ypos, width, height);
828 } //wxResourceEditorDialogHandler::OnDragBegin()
831 void wxResourceEditorDialogHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
833 int upperLeftX
= (x
< firstDragX
) ? x
: firstDragX
;
834 int upperLeftY
= (y
< firstDragY
) ? y
: firstDragY
;
835 int lowerRightX
= (x
> firstDragX
) ? x
: firstDragX
;
836 int lowerRightY
= (y
> firstDragY
) ? y
: firstDragY
;
839 dc
.SetLogicalFunction(wxINVERT
);
840 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
842 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
844 DrawBoundingBox(dc
, (int)upperLeftX
, upperLeftY
,
845 lowerRightX
-upperLeftX
, lowerRightY
-upperLeftY
);
849 } // wxResourceEditorDialogHandler::OnDragContinue()
852 void wxResourceEditorDialogHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
857 dc.SetOptimization(FALSE);
859 dc.SetLogicalFunction(wxCOPY);
860 dc.SetPen(* wxBLACK_PEN);
861 dc.SetBrush(* wxBLACK_BRUSH);
863 dc.SetOptimization(TRUE);
868 } // wxResourceEditorDialogHandler::OnDragEnd()
874 * Event handler for controls
877 int wxResourceEditorControlHandler::dragOffsetX
= 0;
878 int wxResourceEditorControlHandler::dragOffsetY
= 0;
880 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
881 wxEvtHandler
*oldHandler
)
883 handlerControl
= control
;
884 handlerOldHandler
= oldHandler
;
894 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
899 * Manipulation and drawing of items in Edit Mode
902 void wxResourceEditorControlHandler::SelectItem(bool select
)
907 // Returns TRUE or FALSE
908 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
910 int xpos
, ypos
, width
, height
;
911 handlerControl
->GetPosition(&xpos
, &ypos
);
912 handlerControl
->GetSize(&width
, &height
);
914 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
917 // Calculate position of the 8 handles
918 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
920 int xpos
, ypos
, width
, height
;
921 handlerControl
->GetPosition(&xpos
, &ypos
);
922 handlerControl
->GetSize(&width
, &height
);
923 int middleX
= (xpos
+ (width
/2));
924 int middleY
= (ypos
+ (height
/2));
926 // Start from top middle, clockwise.
935 hx
[0] = (int)(middleX
- (handleSize
/2));
936 hy
[0] = ypos
- handleSize
- handleMargin
;
938 hx
[1] = xpos
+ width
+ handleMargin
;
939 hy
[1] = ypos
- handleSize
- handleMargin
;
941 hx
[2] = xpos
+ width
+ handleMargin
;
942 hy
[2] = (int)(middleY
- (handleSize
/2));
944 hx
[3] = xpos
+ width
+ handleMargin
;
945 hy
[3] = ypos
+ height
+ handleMargin
;
947 hx
[4] = (int)(middleX
- (handleSize
/2));
948 hy
[4] = ypos
+ height
+ handleMargin
;
950 hx
[5] = xpos
- handleSize
- handleMargin
;
951 hy
[5] = ypos
+ height
+ handleMargin
;
953 hx
[6] = xpos
- handleSize
- handleMargin
;
954 hy
[6] = (int)(middleY
- (handleSize
/2));
956 hx
[7] = xpos
- handleSize
- handleMargin
;
957 hy
[7] = ypos
- handleSize
- handleMargin
;
960 // Returns 0 (no hit), 1 - 8 for which selection handle
961 // (clockwise from top middle)
962 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
967 CalcSelectionHandles(hx
, hy
);
970 for (i
= 0; i
< 8; i
++)
972 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
978 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
980 dc
.SetOptimization(FALSE
);
982 dc
.SetLogicalFunction(wxCOPY
);
983 dc
.SetPen(* wxBLACK_PEN
);
984 dc
.SetBrush(* wxBLACK_BRUSH
);
986 dc
.SetOptimization(TRUE
);
991 CalcSelectionHandles(hx
, hy
);
994 for (i
= 0; i
< 8; i
++)
996 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
1000 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
1002 dc
.DrawRectangle(x
, y
, w
, h
);
1005 // If selectionHandle is zero, not dragging the selection handle.
1006 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
1008 int xpos
, ypos
, width
, height
;
1009 handlerControl
->GetPosition(&xpos
, &ypos
);
1010 handlerControl
->GetSize(&width
, &height
);
1014 // dc.DestroyClippingRegion();
1016 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
1018 // Erase selection handles
1019 // DrawSelectionHandles(dc, TRUE);
1021 dc
.SetOptimization(FALSE
);
1023 dc
.SetLogicalFunction(wxINVERT
);
1025 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
1027 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1029 dc
.SetOptimization(TRUE
);
1031 if (selectionHandle
> 0)
1035 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
1041 dragOffsetX
= (x
- xpos
);
1042 dragOffsetY
= (y
- ypos
);
1044 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
1046 // Also draw bounding boxes for other selected items
1047 wxNode
*node
= panel
->GetChildren().First();
1050 wxWindow
*win
= (wxWindow
*)node
->Data();
1051 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1053 wxControl
*item
= (wxControl
*)win
;
1054 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1055 if ((item
!= handlerControl
) && handler
->IsSelected())
1058 item
->GetPosition(&x1
, &y1
);
1059 item
->GetSize(&w1
, &h1
);
1060 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
1063 node
= node
->Next();
1069 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
1071 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
1072 int xpos
, ypos
, width
, height
;
1073 handlerControl
->GetPosition(&xpos
, &ypos
);
1074 handlerControl
->GetSize(&width
, &height
);
1076 if (selectionHandle
> 0)
1086 int x1
, y1
, width1
, height1
;
1088 switch (selectionHandle
)
1094 height1
= (ypos
+ height
) - y
;
1100 height1
= (y
- ypos
);
1105 width1
= (x
- xpos
);
1111 width1
= (xpos
+ width
) - x
;
1117 width1
= (x
- xpos
);
1118 height1
= (ypos
+ height
) - y
;
1123 width1
= (x
- xpos
);
1124 height1
= (y
- ypos
);
1129 width1
= (xpos
+ width
) - x
;
1135 width1
= (xpos
+ width
) - x
;
1136 height1
= (ypos
+ height
) - y
;
1141 dc
.SetLogicalFunction(wxINVERT
);
1142 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
1144 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1146 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
1153 dc
.SetLogicalFunction(wxINVERT
);
1154 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
1156 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1158 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
1160 // Also draw bounding boxes for other selected items
1161 wxNode
*node
= panel
->GetChildren().First();
1164 wxWindow
*win
= (wxWindow
*)node
->Data();
1165 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1167 wxControl
*item
= (wxControl
*)win
;
1168 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1169 if ((item
!= handlerControl
) && handler
->IsSelected())
1172 item
->GetPosition(&x1
, &y1
);
1173 item
->GetSize(&w1
, &h1
);
1174 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1175 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1176 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
1179 node
= node
->Next();
1185 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
1187 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
1191 int xpos
, ypos
, width
, height
;
1192 handlerControl
->GetPosition(&xpos
, &ypos
);
1193 handlerControl
->GetSize(&width
, &height
);
1195 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
);
1196 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
->GetParent());
1198 if (selectionHandle
> 0)
1200 int x1
, y1
, width1
, height1
;
1202 switch (selectionHandle
)
1208 height1
= (ypos
+ height
) - y
;
1214 height1
= (y
- ypos
);
1219 width1
= (x
- xpos
);
1225 width1
= (xpos
+ width
) - x
;
1231 width1
= (x
- xpos
);
1232 height1
= (ypos
+ height
) - y
;
1237 width1
= (x
- xpos
);
1238 height1
= (y
- ypos
);
1243 width1
= (xpos
+ width
) - x
;
1249 width1
= (xpos
+ width
) - x
;
1250 height1
= (ypos
+ height
) - y
;
1253 // Update the associated resource
1254 // We need to convert to dialog units if this is not a dialog or panel, but
1255 // the parent resource specifies dialog units.
1258 int resourceWidth
= width1
;
1259 int resourceHeight
= height1
;
1261 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1263 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(x1
, y1
));
1264 wxSize sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxSize(width1
, height1
));
1266 // Convert back so we've rounded down
1267 sz
= handlerControl
->GetParent()->ConvertDialogToPixels(sz
);
1268 sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(sz
);
1269 resourceWidth
= sz
.x
; resourceHeight
= sz
.y
;
1271 sz
= handlerControl
->GetParent()->ConvertDialogToPixels(sz
);
1275 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1276 pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(pt
);
1277 resourceX
= pt
.x
; resourceY
= pt
.y
;
1279 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1283 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
1284 resource
->SetSize(resourceX
, resourceY
, resourceWidth
, resourceHeight
);
1288 // Correction 31/12/98. We need to round down the values to take into account
1289 // the fact that several pixels map to the same dialog unit.
1291 int newX
= (int)(x
- dragOffsetX
);
1292 int newY
= (int)(y
- dragOffsetY
);
1293 int resourceX
= newX
;
1294 int resourceY
= newY
;
1296 // Update the associated resource
1297 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1299 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1300 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1301 pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(pt
);
1302 resourceX
= pt
.x
; resourceY
= pt
.y
;
1303 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1305 // Having converted it several times, we know it'll map to dialog units exactly.
1309 handlerControl
->Move(newX
, newY
);
1310 OldOnMove(newX
, newY
);
1312 resource
->SetSize(resourceX
, resourceY
, resource
->GetWidth(), resource
->GetHeight());
1314 // Also move other selected items
1315 wxNode
*node
= panel
->GetChildren().First();
1318 wxWindow
*win
= (wxWindow
*)node
->Data();
1319 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1321 wxControl
*item
= (wxControl
*)win
;
1322 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1323 if ((item
!= handlerControl
) && handler
->IsSelected())
1326 item
->GetPosition(&x1
, &y1
);
1327 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1328 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1333 // Update the associated resource
1334 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1335 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1337 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(x2
, y2
));
1338 pt
= item
->GetParent()->ConvertDialogToPixels(pt
);
1339 pt
= item
->GetParent()->ConvertPixelsToDialog(pt
);
1341 resourceX
= pt
.x
; resourceY
= pt
.y
;
1342 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1344 // Having converted it several times, we know it'll map to dialog units exactly
1350 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
1351 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1353 resource
->SetSize(resourceX
, resourceY
, resource
->GetWidth(), resource
->GetHeight());
1357 node
= node
->Next();
1360 dc
.SetOptimization(FALSE
);
1362 dc
.SetLogicalFunction(wxCOPY
);
1363 dc
.SetPen(* wxBLACK_PEN
);
1364 dc
.SetBrush(* wxBLACK_BRUSH
);
1366 dc
.SetOptimization(TRUE
);
1368 // Force it to repaint the selection handles (if any)
1369 // since the panel thinks we're still within a drag and
1370 // won't paint the handles.
1372 DrawSelectionHandles(dc
);
1379 // These functions call OnItemEvent, OnItemMove and OnItemSize
1381 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1384 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1385 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1388 wxWindow
*panel
= handlerControl
->GetParent();
1389 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1391 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1392 if ( !panelHandler
->GetEvtHandlerEnabled() )
1398 panelHandler
->OnItemEvent(handlerControl
, event
);
1401 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1403 wxWindow
*panel
= handlerControl
->GetParent();
1404 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1407 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1408 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1411 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1413 wxWindow
*panel
= handlerControl
->GetParent();
1414 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1417 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1418 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1421 void wxResourceEditorControlHandler::OnSelect(bool select
)
1423 wxWindow
*panel
= handlerControl
->GetParent();
1424 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1427 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1428 panelHandler
->OnItemSelect(handlerControl
, select
);
1431 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1433 wxWindow
*panel
= handlerControl
->GetParent();
1434 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1437 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1438 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1441 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1443 wxWindow
*panel
= handlerControl
->GetParent();
1444 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1447 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1448 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);