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
)
45 EVT_MENU(OBJECT_MENU_EDIT
, wxResourceEditorDialogHandler::OnObjectEdit
)
46 EVT_MENU(OBJECT_MENU_DELETE
, wxResourceEditorDialogHandler::OnObjectDelete
)
49 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler
, wxEvtHandler
)
50 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent
)
54 * Dialog box event handler
57 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
,
58 wxEvtHandler
*oldHandler
, wxResourceManager
*manager
)
60 handlerDialog
= dialog
;
61 handlerResource
= resource
;
62 handlerOldHandler
= oldHandler
;
63 resourceManager
= manager
;
65 dragMode
= wxDRAG_MODE_NONE
;
66 dragType
= wxDRAG_TYPE_NONE
;
73 checkTolerance
= TRUE
;
74 m_mouseCaptured
= FALSE
;
78 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
82 void wxResourceEditorDialogHandler::OnItemSelect(wxControl
*item
, bool select
)
85 resourceManager
->AddSelection(item
);
87 resourceManager
->RemoveSelection(item
);
90 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent
& WXUNUSED(event
))
92 wxPaintDC
dc(handlerDialog
);
94 PaintSelectionHandles(dc
);
97 // Add event handlers for all children
98 void wxResourceEditorDialogHandler::AddChildHandlers(void)
100 wxNode
*node
= handlerDialog
->GetChildren().First();
103 wxControl
*child
= (wxControl
*)node
->Data();
104 wxEvtHandler
*childHandler
= child
->GetEventHandler();
105 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
== child
)
106 child
->PushEventHandler(new wxResourceEditorControlHandler(child
, childHandler
));
111 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
113 if (keys
& wxKEY_CTRL
)
115 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
119 // Deselect all items if click on panel
120 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
122 int needsRefresh
= 0;
123 wxNode
*node
= handlerDialog
->GetChildren().First();
126 wxControl
*item
= (wxControl
*)node
->Data();
127 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
128 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
131 OnItemSelect(item
, FALSE
);
132 childHandler
->SelectItem(FALSE
);
136 if (needsRefresh
> 0)
138 wxClientDC
dc(handlerDialog
);
140 handlerDialog
->Refresh();
145 // Round down to take account of dialog units
146 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
147 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
149 wxPoint pt
= handlerDialog
->ConvertPixelsToDialog(wxPoint(x
, y
));
151 // Convert back so we've rounded down
152 pt
= handlerDialog
->ConvertDialogToPixels(pt
);
153 pt
= handlerDialog
->ConvertPixelsToDialog(pt
);
154 pt
= handlerDialog
->ConvertDialogToPixels(pt
);
159 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
162 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
164 case RESED_BMPBUTTON
:
165 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
167 case RESED_STATICTEXT
:
168 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
170 case RESED_STATICBMP
:
171 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
173 case RESED_TEXTCTRL_SINGLE
:
174 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
176 case RESED_TEXTCTRL_MULTIPLE
:
177 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
180 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
183 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxComboBox", x
, y
);
186 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
189 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
191 case RESED_RADIOBUTTON
:
192 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioButton", x
, y
);
195 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
198 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
201 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
203 case RESED_STATICBOX
:
204 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
206 case RESED_SCROLLBAR
:
207 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
213 // Now switch pointer on.
214 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
216 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
220 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int WXUNUSED(keys
))
222 wxMenu
*menu
= resourceManager
->GetPopupMenu();
223 menu
->SetClientData((char *)handlerDialog
);
225 wxString
str("wxDialog : ");
226 str
+= handlerDialog
->GetName();
228 menu
->SetLabel(OBJECT_MENU_TITLE
,str
);
230 handlerDialog
->PopupMenu(menu
, x
, y
);
233 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int WXUNUSED(x
), int WXUNUSED(y
), int keys
)
235 if (keys
& wxKEY_CTRL
)
237 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
242 // If this is a wxStaticBox and the pointer isn't an arrow, chances
243 // are that we really meant to place an item on the panel.
245 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
247 OnLeftClick(x, y, keys);
252 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
254 if (childHandler
->IsSelected())
256 childHandler
->SelectItem(FALSE
);
257 OnItemSelect(item
, FALSE
);
259 wxClientDC
dc(handlerDialog
);
261 handlerDialog
->Refresh();
265 childHandler
->SelectItem(TRUE
);
266 OnItemSelect(item
, TRUE
);
268 // Deselect other items if shift is not pressed
269 int needsRefresh
= 0;
270 if (!(keys
& wxKEY_SHIFT
))
272 wxNode
*node
= item
->GetParent()->GetChildren().First();
275 wxControl
*child
= (wxControl
*)node
->Data();
276 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
277 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
279 childHandler2
->SelectItem(FALSE
);
280 OnItemSelect(child
, FALSE
);
287 wxClientDC
dc(handlerDialog
);
288 childHandler
->DrawSelectionHandles(dc
);
290 if (needsRefresh
> 0)
293 handlerDialog
->Refresh();
298 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int WXUNUSED(keys
))
301 if (keys & wxKEY_CTRL)
303 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
308 wxMenu
*menu
= resourceManager
->GetPopupMenu();
309 menu
->SetClientData((char *)item
);
311 wxWindow
*win
= (wxWindow
*)item
;
313 wxWindowPropertyInfo
*info
= resourceManager
->CreatePropertyInfoForWindow(win
);
316 info
->SetResource(resourceManager
->FindResourceForWindow(win
));
318 str
= win
->GetClassInfo()->GetClassName();
320 if (win
->GetName() != "")
321 str
+= win
->GetName();
323 menu
->SetLabel(OBJECT_MENU_TITLE
,str
);
326 handlerDialog
->PopupMenu(menu
, x
, y
);
329 // Under Windows 95, you can resize a panel interactively depending on
331 void wxResourceEditorDialogHandler::OnSize(wxSizeEvent
& event
)
333 // Update the associated resource
335 handlerDialog
->GetClientSize(& w
, & h
);
337 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
338 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
340 wxSize sz
= handlerDialog
->ConvertPixelsToDialog(wxSize(w
, h
));
343 resource
->SetSize(resource
->GetX(), resource
->GetY(), w
, h
);
346 // An event outside any items: may be a drag event.
347 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
349 if (GetEvtHandlerEnabled())
351 // If we're dragging an item or selection handle,
352 // continue dragging.
353 if (dragMode
!= wxDRAG_MODE_NONE
)
355 if (dragType
!= wxDRAG_TYPE_BOUNDING_BOX
&&
358 ProcessItemEvent(dragItem
, event
, dragType
);
364 event
.GetPosition(&x
, &y
);
366 // Find which selection handle we're on, if any
367 wxNode
*node
= handlerDialog
->GetChildren().First();
370 wxWindow
*win
= (wxWindow
*)node
->Data();
371 if (win
->IsKindOf(CLASSINFO(wxControl
)))
373 wxControl
*item
= (wxControl
*)win
;
374 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
375 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
378 ProcessItemEvent(item
, event
, selHandle
);
385 // We're not on an item or selection handle.
386 // so... check for a left or right click event
387 // to send to the application.
389 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
390 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
394 if (event
.Dragging() &&
395 (dragType
== wxDRAG_TYPE_BOUNDING_BOX
))
398 if (dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
400 wxClientDC
dc(handlerDialog
);
401 OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, NULL
);
402 OnDragContinue(TRUE
, x
, y
, keys
, dc
, NULL
);
403 oldDragX
= x
; oldDragY
= y
;
406 else if (event.LeftUp() && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
409 wxClientDC dc(handlerDialog);
410 OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, NULL);
411 OnDragContinue(TRUE, x, y, keys, dc, NULL);
412 oldDragX = x; oldDragY = y;
418 if (event
.LeftDown())
420 if (!m_mouseCaptured
)
422 handlerDialog
->CaptureMouse();
423 m_mouseCaptured
= TRUE
;
426 // Starting to draw a bounding box around
427 // some numbe of controls on the dialog
429 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
432 dragMode
= wxDRAG_MODE_START_LEFT
;
435 dragType
= wxDRAG_TYPE_BOUNDING_BOX
;
436 wxClientDC
dc(handlerDialog
);
437 OnDragBegin(x
, y
, keys
, dc
, 0);
438 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
439 oldDragX
= x
; oldDragY
= y
;
444 else if (event
.LeftUp())
448 handlerDialog
->ReleaseMouse();
449 m_mouseCaptured
= FALSE
;
452 if (dragType
== wxDRAG_TYPE_BOUNDING_BOX
)
454 // Determine the bounds of the surrounding box
455 int upperLeftX
= (x
< firstDragX
) ? x
: firstDragX
;
456 int upperLeftY
= (y
< firstDragY
) ? y
: firstDragY
;
457 int lowerRightX
= (x
> firstDragX
) ? x
: firstDragX
;
458 int lowerRightY
= (y
> firstDragY
) ? y
: firstDragY
;
463 bool widgetWithinBounds
= FALSE
;
465 int needsRefresh
= 0;
467 wxClientDC
dc(handlerDialog
);
469 // Determine what widgets which fall within the bounding box
471 wxNode
*node
= handlerDialog
->GetChildren().First();
474 widgetWithinBounds
= FALSE
;
475 wxWindow
*win
= (wxWindow
*)node
->Data();
476 if (win
->IsKindOf(CLASSINFO(wxControl
)))
478 wxControl
*item
= (wxControl
*)win
;
479 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
481 // Unselect all widgets that are currently selected
482 if (!(keys
& wxKEY_SHIFT
) && childHandler
->IsSelected())
485 OnItemSelect(item
, FALSE
);
486 childHandler
->SelectItem(FALSE
);
489 // Get X,Y and WIDTH,HEIGHT of the widget to be able
490 // to determine if any portion of it is within the bounded
492 childHandler
->handlerControl
->GetPosition(&xpos
, &ypos
);
493 childHandler
->handlerControl
->GetSize(&width
, &height
);
495 // Check if the current widget is inside the rectangle
496 // that was just bounded
497 if (xpos
>= upperLeftX
&& xpos
<= lowerRightX
)
499 if (ypos
>= upperLeftY
&& ypos
<= lowerRightY
)
500 widgetWithinBounds
= TRUE
;
501 else if (ypos
+height
>= upperLeftY
&& ypos
+height
<= lowerRightY
)
502 widgetWithinBounds
= TRUE
;
504 else if (xpos
+width
>= upperLeftX
&& xpos
<= lowerRightX
)
506 if (ypos
>= upperLeftY
&& ypos
<= lowerRightY
)
507 widgetWithinBounds
= TRUE
;
508 else if (ypos
+height
>= upperLeftY
&& ypos
+height
<= lowerRightY
)
509 widgetWithinBounds
= TRUE
;
512 if (widgetWithinBounds
)
514 childHandler
->SelectItem(TRUE
);
515 OnItemSelect(item
, TRUE
);
517 // childHandler->DrawSelectionHandles(dc);
524 OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, NULL
);
525 OnDragEnd(x
, y
, keys
, dc
, NULL
);
527 if (needsRefresh
> 0)
530 handlerDialog
->Refresh();
533 // Always paint, in case the bounding box overlapped with
534 // the handles of any selected widgets, that way when the
535 // bounding box is cleared, the handles don't get partially
536 // erased where the overlap occured
537 PaintSelectionHandles(dc
);
539 dragMode
= wxDRAG_MODE_NONE
;
540 checkTolerance
= TRUE
;
542 dragType
= wxDRAG_TYPE_NONE
;
545 OnLeftClick(x
, y
, keys
);
547 else if (event
.RightDown())
551 handlerDialog
->ReleaseMouse();
552 m_mouseCaptured
= FALSE
;
555 OnRightClick(x
, y
, keys
);
557 else if (event
.LeftDClick())
561 handlerDialog
->ReleaseMouse();
562 m_mouseCaptured
= FALSE
;
564 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
571 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
573 if (!GetEvtHandlerEnabled())
576 // Not a selection handle event: just a normal item event.
577 // Transform to panel coordinates.
579 item
->GetPosition(&x
, &y
);
581 event
.m_x
= event
.m_x
+ x
;
582 event
.m_y
= event
.m_y
+ y
;
584 ProcessItemEvent(item
, event
, dragType
);
587 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
589 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
592 event
.GetPosition(&x
, &y
);
594 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
595 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
596 bool dragging
= event
.Dragging();
600 int dx
= (int)abs((x
- firstDragX
));
601 int dy
= (int)abs((y
- firstDragY
));
602 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
607 // If we've ignored the tolerance once, then ALWAYS ignore
608 // tolerance in this drag, even if we come back within
609 // the tolerance range.
611 checkTolerance
= FALSE
;
614 if (event
.LeftDClick())
618 handlerDialog
->ReleaseMouse();
619 m_mouseCaptured
= FALSE
;
622 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
624 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
626 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
627 wxClientDC
dc(handlerDialog
);
628 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
629 oldDragX
= x
; oldDragY
= y
;
630 if (!m_mouseCaptured
)
632 handlerDialog
->CaptureMouse();
633 m_mouseCaptured
= TRUE
;
636 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
638 wxClientDC
dc(handlerDialog
);
639 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
640 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
641 oldDragX
= x
; oldDragY
= y
;
643 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
645 wxClientDC
dc(handlerDialog
);
646 dragMode
= wxDRAG_MODE_NONE
;
647 checkTolerance
= TRUE
;
649 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
650 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
653 dragType
= wxDRAG_TYPE_NONE
;
657 handlerDialog
->ReleaseMouse();
658 m_mouseCaptured
= FALSE
;
661 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
663 wxClientDC
dc(handlerDialog
);
664 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
665 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
666 oldDragX
= x
; oldDragY
= y
;
668 if (!m_mouseCaptured
)
670 handlerDialog
->CaptureMouse();
671 m_mouseCaptured
= TRUE
;
674 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
676 oldDragX
= x
; oldDragY
= y
;
678 // Obsolete; no longer try to right-drag
679 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
681 dragMode
= wxDRAG_MODE_NONE
;
682 checkTolerance
= TRUE
;
684 dragType
= wxDRAG_TYPE_NONE
;
688 handlerDialog
->ReleaseMouse();
689 m_mouseCaptured
= FALSE
;
692 else if (event
.IsButton())
694 checkTolerance
= TRUE
;
696 if (event
.LeftDown())
699 dragMode
= wxDRAG_MODE_START_LEFT
;
702 dragType
= selectionHandle
;
704 if (!m_mouseCaptured
)
706 handlerDialog
->CaptureMouse();
707 m_mouseCaptured
= TRUE
;
710 else if (event
.RightDown())
714 handlerDialog
->ReleaseMouse();
715 m_mouseCaptured
= FALSE
;
719 childHandler
->OnRightClick(x
, y
, keys
);
721 OnRightClick(x
, y
, keys
);
723 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
727 dragMode = wxDRAG_MODE_START_RIGHT;
730 dragType = selectionHandle;
732 if (!m_mouseCaptured)
734 handlerDialog->CaptureMouse();
735 m_mouseCaptured = TRUE;
739 else if (event
.LeftUp())
742 childHandler
->OnLeftClick(x
, y
, keys
);
744 OnLeftClick(x
, y
, keys
);
746 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
750 handlerDialog
->ReleaseMouse();
751 m_mouseCaptured
= FALSE
;
754 else if (event
.RightUp())
758 childHandler->OnRightClick(x, y, keys);
760 OnRightClick(x, y, keys);
762 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
766 handlerDialog->ReleaseMouse();
767 m_mouseCaptured = FALSE;
774 // Calls DrawSelectionHandles for all items if
776 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
778 if (!GetEvtHandlerEnabled())
783 wxNode
*node
= handlerDialog
->GetChildren().First();
786 wxWindow
*win
= (wxWindow
*)node
->Data();
787 if (win
->IsKindOf(CLASSINFO(wxControl
)))
789 wxControl
*item
= (wxControl
*)win
;
790 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
792 // Don't draw handles for an item that's being moved: it'll
794 if (childHandler
->IsSelected() && (item
!= dragItem
))
795 childHandler
->DrawSelectionHandles(dc
);
804 void wxResourceEditorDialogHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
806 dc
.DrawRectangle(x
, y
, w
, h
);
810 void wxResourceEditorDialogHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
815 dc.SetOptimization(FALSE);
817 dc.SetLogicalFunction(wxINVERT);
819 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
821 dc.SetBrush(* wxTRANSPARENT_BRUSH);
823 dc.SetOptimization(TRUE);
826 // DrawBoundingBox(dc, xpos, ypos, width, height);
830 } //wxResourceEditorDialogHandler::OnDragBegin()
833 void wxResourceEditorDialogHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
835 int upperLeftX
= (x
< firstDragX
) ? x
: firstDragX
;
836 int upperLeftY
= (y
< firstDragY
) ? y
: firstDragY
;
837 int lowerRightX
= (x
> firstDragX
) ? x
: firstDragX
;
838 int lowerRightY
= (y
> firstDragY
) ? y
: firstDragY
;
841 dc
.SetLogicalFunction(wxINVERT
);
842 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
844 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
846 DrawBoundingBox(dc
, (int)upperLeftX
, upperLeftY
,
847 lowerRightX
-upperLeftX
, lowerRightY
-upperLeftY
);
851 } // wxResourceEditorDialogHandler::OnDragContinue()
854 void wxResourceEditorDialogHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
859 dc.SetOptimization(FALSE);
861 dc.SetLogicalFunction(wxCOPY);
862 dc.SetPen(* wxBLACK_PEN);
863 dc.SetBrush(* wxBLACK_BRUSH);
865 dc.SetOptimization(TRUE);
870 } // wxResourceEditorDialogHandler::OnDragEnd()
872 void wxResourceEditorDialogHandler::OnObjectEdit(wxCommandEvent
& event
)
874 wxMenu
* menu
= (wxMenu
*) event
.GetEventObject();
876 wxWindow
*data
= (wxWindow
*)menu
->GetClientData();
880 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
883 void wxResourceEditorDialogHandler::OnObjectDelete(wxCommandEvent
& event
)
885 wxMenu
* menu
= (wxMenu
*) event
.GetEventObject();
887 wxWindow
*data
= (wxWindow
*)menu
->GetClientData();
891 // Before deleting a dialog, give the user a last chance
892 // change their mind, in case they accidentally right
893 // clicked the dialog rather than the widget they were
895 if (data
->IsKindOf(CLASSINFO(wxPanel
)))
897 wxString
str(wxT("Deleting dialog : "));
898 str
+= data
->GetName();
899 if (wxMessageBox(wxT("Are you sure?"), str
, wxYES_NO
| wxCENTRE
) == wxNO
)
903 wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data
);
905 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
906 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
907 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
913 * Event handler for controls
916 int wxResourceEditorControlHandler::dragOffsetX
= 0;
917 int wxResourceEditorControlHandler::dragOffsetY
= 0;
919 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
920 wxEvtHandler
*oldHandler
)
922 handlerControl
= control
;
923 handlerOldHandler
= oldHandler
;
933 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
938 * Manipulation and drawing of items in Edit Mode
941 void wxResourceEditorControlHandler::SelectItem(bool select
)
946 // Returns TRUE or FALSE
947 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
949 int xpos
, ypos
, width
, height
;
950 handlerControl
->GetPosition(&xpos
, &ypos
);
951 handlerControl
->GetSize(&width
, &height
);
953 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
956 // Calculate position of the 8 handles
957 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
959 int xpos
, ypos
, width
, height
;
960 handlerControl
->GetPosition(&xpos
, &ypos
);
961 handlerControl
->GetSize(&width
, &height
);
962 int middleX
= (xpos
+ (width
/2));
963 int middleY
= (ypos
+ (height
/2));
965 // Start from top middle, clockwise.
974 hx
[0] = (int)(middleX
- (handleSize
/2));
975 hy
[0] = ypos
- handleSize
- handleMargin
;
977 hx
[1] = xpos
+ width
+ handleMargin
;
978 hy
[1] = ypos
- handleSize
- handleMargin
;
980 hx
[2] = xpos
+ width
+ handleMargin
;
981 hy
[2] = (int)(middleY
- (handleSize
/2));
983 hx
[3] = xpos
+ width
+ handleMargin
;
984 hy
[3] = ypos
+ height
+ handleMargin
;
986 hx
[4] = (int)(middleX
- (handleSize
/2));
987 hy
[4] = ypos
+ height
+ handleMargin
;
989 hx
[5] = xpos
- handleSize
- handleMargin
;
990 hy
[5] = ypos
+ height
+ handleMargin
;
992 hx
[6] = xpos
- handleSize
- handleMargin
;
993 hy
[6] = (int)(middleY
- (handleSize
/2));
995 hx
[7] = xpos
- handleSize
- handleMargin
;
996 hy
[7] = ypos
- handleSize
- handleMargin
;
999 // Returns 0 (no hit), 1 - 8 for which selection handle
1000 // (clockwise from top middle)
1001 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
1006 CalcSelectionHandles(hx
, hy
);
1009 for (i
= 0; i
< 8; i
++)
1011 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
1017 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
1019 dc
.SetOptimization(FALSE
);
1021 dc
.SetLogicalFunction(wxCOPY
);
1022 dc
.SetPen(* wxBLACK_PEN
);
1023 dc
.SetBrush(* wxBLACK_BRUSH
);
1025 dc
.SetOptimization(TRUE
);
1030 CalcSelectionHandles(hx
, hy
);
1033 for (i
= 0; i
< 8; i
++)
1035 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
1039 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
1041 dc
.DrawRectangle(x
, y
, w
, h
);
1044 // If selectionHandle is zero, not dragging the selection handle.
1045 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
1047 int xpos
, ypos
, width
, height
;
1048 handlerControl
->GetPosition(&xpos
, &ypos
);
1049 handlerControl
->GetSize(&width
, &height
);
1053 // dc.DestroyClippingRegion();
1055 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
1057 // Erase selection handles
1058 // DrawSelectionHandles(dc, TRUE);
1060 dc
.SetOptimization(FALSE
);
1062 dc
.SetLogicalFunction(wxINVERT
);
1064 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
1066 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1068 dc
.SetOptimization(TRUE
);
1070 if (selectionHandle
> 0)
1074 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
1080 dragOffsetX
= (x
- xpos
);
1081 dragOffsetY
= (y
- ypos
);
1083 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
1085 // Also draw bounding boxes for other selected items
1086 wxNode
*node
= panel
->GetChildren().First();
1089 wxWindow
*win
= (wxWindow
*)node
->Data();
1090 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1092 wxControl
*item
= (wxControl
*)win
;
1093 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1094 if ((item
!= handlerControl
) && handler
->IsSelected())
1097 item
->GetPosition(&x1
, &y1
);
1098 item
->GetSize(&w1
, &h1
);
1099 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
1102 node
= node
->Next();
1108 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
1110 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
1111 int xpos
, ypos
, width
, height
;
1112 handlerControl
->GetPosition(&xpos
, &ypos
);
1113 handlerControl
->GetSize(&width
, &height
);
1115 if (selectionHandle
> 0)
1125 int x1
, y1
, width1
, height1
;
1127 switch (selectionHandle
)
1133 height1
= (ypos
+ height
) - y
;
1139 height1
= (y
- ypos
);
1144 width1
= (x
- xpos
);
1150 width1
= (xpos
+ width
) - x
;
1156 width1
= (x
- xpos
);
1157 height1
= (ypos
+ height
) - y
;
1162 width1
= (x
- xpos
);
1163 height1
= (y
- ypos
);
1168 width1
= (xpos
+ width
) - x
;
1174 width1
= (xpos
+ width
) - x
;
1175 height1
= (ypos
+ height
) - y
;
1180 dc
.SetLogicalFunction(wxINVERT
);
1181 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
1183 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1185 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
1192 dc
.SetLogicalFunction(wxINVERT
);
1193 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
1195 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1197 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
1199 // Also draw bounding boxes for other selected items
1200 wxNode
*node
= panel
->GetChildren().First();
1203 wxWindow
*win
= (wxWindow
*)node
->Data();
1204 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1206 wxControl
*item
= (wxControl
*)win
;
1207 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1208 if ((item
!= handlerControl
) && handler
->IsSelected())
1211 item
->GetPosition(&x1
, &y1
);
1212 item
->GetSize(&w1
, &h1
);
1213 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1214 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1215 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
1218 node
= node
->Next();
1224 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
1226 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
1230 int xpos
, ypos
, width
, height
;
1231 handlerControl
->GetPosition(&xpos
, &ypos
);
1232 handlerControl
->GetSize(&width
, &height
);
1234 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
);
1235 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
->GetParent());
1237 if (selectionHandle
> 0)
1239 int x1
, y1
, width1
, height1
;
1241 switch (selectionHandle
)
1247 height1
= (ypos
+ height
) - y
;
1253 height1
= (y
- ypos
);
1258 width1
= (x
- xpos
);
1264 width1
= (xpos
+ width
) - x
;
1270 width1
= (x
- xpos
);
1271 height1
= (ypos
+ height
) - y
;
1276 width1
= (x
- xpos
);
1277 height1
= (y
- ypos
);
1282 width1
= (xpos
+ width
) - x
;
1288 width1
= (xpos
+ width
) - x
;
1289 height1
= (ypos
+ height
) - y
;
1292 // Update the associated resource
1293 // We need to convert to dialog units if this is not a dialog or panel, but
1294 // the parent resource specifies dialog units.
1297 int resourceWidth
= width1
;
1298 int resourceHeight
= height1
;
1300 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1302 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(x1
, y1
));
1303 wxSize sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxSize(width1
, height1
));
1305 // Convert back so we've rounded down
1306 sz
= handlerControl
->GetParent()->ConvertDialogToPixels(sz
);
1307 sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(sz
);
1308 resourceWidth
= sz
.x
; resourceHeight
= sz
.y
;
1310 sz
= handlerControl
->GetParent()->ConvertDialogToPixels(sz
);
1314 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1315 pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(pt
);
1316 resourceX
= pt
.x
; resourceY
= pt
.y
;
1318 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1322 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
1323 resource
->SetSize(resourceX
, resourceY
, resourceWidth
, resourceHeight
);
1327 // Correction 31/12/98. We need to round down the values to take into account
1328 // the fact that several pixels map to the same dialog unit.
1330 int newX
= (int)(x
- dragOffsetX
);
1331 int newY
= (int)(y
- dragOffsetY
);
1332 int resourceX
= newX
;
1333 int resourceY
= newY
;
1335 // Update the associated resource
1336 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1338 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1339 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1340 pt
= handlerControl
->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.
1348 handlerControl
->Move(newX
, newY
);
1349 OldOnMove(newX
, newY
);
1351 resource
->SetSize(resourceX
, resourceY
, resource
->GetWidth(), resource
->GetHeight());
1353 // Also move other selected items
1354 wxNode
*node
= panel
->GetChildren().First();
1357 wxWindow
*win
= (wxWindow
*)node
->Data();
1358 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1360 wxControl
*item
= (wxControl
*)win
;
1361 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1362 if ((item
!= handlerControl
) && handler
->IsSelected())
1365 item
->GetPosition(&x1
, &y1
);
1366 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1367 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1372 // Update the associated resource
1373 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1374 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1376 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(x2
, y2
));
1377 pt
= item
->GetParent()->ConvertDialogToPixels(pt
);
1378 pt
= item
->GetParent()->ConvertPixelsToDialog(pt
);
1380 resourceX
= pt
.x
; resourceY
= pt
.y
;
1381 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1383 // Having converted it several times, we know it'll map to dialog units exactly
1389 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
1390 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1392 resource
->SetSize(resourceX
, resourceY
, resource
->GetWidth(), resource
->GetHeight());
1396 node
= node
->Next();
1399 dc
.SetOptimization(FALSE
);
1401 dc
.SetLogicalFunction(wxCOPY
);
1402 dc
.SetPen(* wxBLACK_PEN
);
1403 dc
.SetBrush(* wxBLACK_BRUSH
);
1405 dc
.SetOptimization(TRUE
);
1407 // Force it to repaint the selection handles (if any)
1408 // since the panel thinks we're still within a drag and
1409 // won't paint the handles.
1411 DrawSelectionHandles(dc
);
1418 // These functions call OnItemEvent, OnItemMove and OnItemSize
1420 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1423 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1424 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1427 wxWindow
*panel
= handlerControl
->GetParent();
1428 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1430 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1431 if ( !panelHandler
->GetEvtHandlerEnabled() )
1437 panelHandler
->OnItemEvent(handlerControl
, event
);
1440 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1442 wxWindow
*panel
= handlerControl
->GetParent();
1443 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1446 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1447 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1450 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1452 wxWindow
*panel
= handlerControl
->GetParent();
1453 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1456 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1457 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1460 void wxResourceEditorControlHandler::OnSelect(bool select
)
1462 wxWindow
*panel
= handlerControl
->GetParent();
1463 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1466 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1467 panelHandler
->OnItemSelect(handlerControl
, select
);
1470 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1472 wxWindow
*panel
= handlerControl
->GetParent();
1473 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1476 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1477 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1480 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1482 wxWindow
*panel
= handlerControl
->GetParent();
1483 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1486 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1487 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);