1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dialog handler
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
33 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
36 #include <strstream.h>
47 IMPLEMENT_CLASS(wxResourceEditorDialogHandler
, wxEvtHandler
)
48 IMPLEMENT_CLASS(wxResourceEditorControlHandler
, wxEvtHandler
)
50 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler
, wxEvtHandler
)
51 EVT_PAINT(wxResourceEditorDialogHandler::OnPaint
)
52 EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent
)
53 EVT_SIZE(wxResourceEditorDialogHandler::OnSize
)
56 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler
, wxEvtHandler
)
57 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent
)
61 * Dialog box event handler
64 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
,
65 wxEvtHandler
*oldHandler
, wxResourceManager
*manager
)
67 handlerDialog
= dialog
;
68 handlerResource
= resource
;
69 handlerOldHandler
= oldHandler
;
70 resourceManager
= manager
;
72 dragMode
= wxDRAG_MODE_NONE
;
73 dragType
= wxDRAG_TYPE_NONE
;
80 checkTolerance
= TRUE
;
81 m_mouseCaptured
= FALSE
;
85 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
89 void wxResourceEditorDialogHandler::OnItemSelect(wxControl
*item
, bool select
)
92 resourceManager
->AddSelection(item
);
94 resourceManager
->RemoveSelection(item
);
97 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent
& WXUNUSED(event
))
99 wxPaintDC
dc(handlerDialog
);
101 PaintSelectionHandles(dc
);
104 // Add event handlers for all children
105 void wxResourceEditorDialogHandler::AddChildHandlers(void)
107 wxNode
*node
= handlerDialog
->GetChildren().First();
110 wxControl
*child
= (wxControl
*)node
->Data();
111 wxEvtHandler
*childHandler
= child
->GetEventHandler();
112 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
== child
)
113 child
->PushEventHandler(new wxResourceEditorControlHandler(child
, childHandler
));
118 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
120 if (keys
& wxKEY_CTRL
)
122 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
126 // Deselect all items if click on panel
127 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
129 int needsRefresh
= 0;
130 wxNode
*node
= handlerDialog
->GetChildren().First();
133 wxControl
*item
= (wxControl
*)node
->Data();
134 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
135 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
138 OnItemSelect(item
, FALSE
);
139 childHandler
->SelectItem(FALSE
);
143 if (needsRefresh
> 0)
145 wxClientDC
dc(handlerDialog
);
147 handlerDialog
->Refresh();
152 // Round down to take account of dialog units
153 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
154 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
156 wxPoint pt
= handlerDialog
->ConvertPixelsToDialog(wxPoint(x
, y
));
158 // Convert back so we've rounded down
159 pt
= handlerDialog
->ConvertDialogToPixels(pt
);
160 pt
= handlerDialog
->ConvertPixelsToDialog(pt
);
161 pt
= handlerDialog
->ConvertDialogToPixels(pt
);
166 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
169 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
171 case RESED_BMPBUTTON
:
172 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
174 case RESED_STATICTEXT
:
175 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
177 case RESED_STATICBMP
:
178 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
180 case RESED_TEXTCTRL_SINGLE
:
181 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
183 case RESED_TEXTCTRL_MULTIPLE
:
184 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
187 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
190 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxComboBox", x
, y
);
193 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
196 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
198 case RESED_RADIOBUTTON
:
199 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioButton", x
, y
);
202 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
205 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
208 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
210 case RESED_STATICBOX
:
211 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
213 case RESED_SCROLLBAR
:
214 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
220 // Now switch pointer on.
221 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
223 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
227 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int WXUNUSED(keys
))
229 wxMenu
*menu
= resourceManager
->GetPopupMenu();
230 menu
->SetClientData((char *)handlerDialog
);
231 handlerDialog
->PopupMenu(menu
, x
, y
);
234 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int WXUNUSED(x
), int WXUNUSED(y
), int keys
)
236 if (keys
& wxKEY_CTRL
)
238 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
243 // If this is a wxStaticBox and the pointer isn't an arrow, chances
244 // are that we really meant to place an item on the panel.
246 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
248 OnLeftClick(x, y, keys);
253 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
255 if (childHandler
->IsSelected())
257 childHandler
->SelectItem(FALSE
);
258 OnItemSelect(item
, FALSE
);
260 wxClientDC
dc(handlerDialog
);
262 handlerDialog
->Refresh();
266 childHandler
->SelectItem(TRUE
);
267 OnItemSelect(item
, TRUE
);
269 // Deselect other items if shift is not pressed
270 int needsRefresh
= 0;
271 if (!(keys
& wxKEY_SHIFT
))
273 wxNode
*node
= item
->GetParent()->GetChildren().First();
276 wxControl
*child
= (wxControl
*)node
->Data();
277 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
278 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
280 childHandler2
->SelectItem(FALSE
);
281 OnItemSelect(child
, FALSE
);
288 wxClientDC
dc(handlerDialog
);
289 childHandler
->DrawSelectionHandles(dc
);
291 if (needsRefresh
> 0)
294 handlerDialog
->Refresh();
299 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int WXUNUSED(keys
))
302 if (keys & wxKEY_CTRL)
304 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
309 wxMenu
*menu
= resourceManager
->GetPopupMenu();
310 menu
->SetClientData((char *)item
);
311 handlerDialog
->PopupMenu(menu
, x
, y
);
314 // Under Windows 95, you can resize a panel interactively depending on
316 void wxResourceEditorDialogHandler::OnSize(wxSizeEvent
& event
)
318 // Update the associated resource
320 handlerDialog
->GetClientSize(& w
, & h
);
322 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog
);
323 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
325 wxSize sz
= handlerDialog
->ConvertPixelsToDialog(wxSize(w
, h
));
328 resource
->SetSize(resource
->GetX(), resource
->GetY(), w
, h
);
331 // An event outside any items: may be a drag event.
332 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
334 if (GetEvtHandlerEnabled())
336 // If we're dragging an item or selection handle,
337 // continue dragging.
338 if (dragMode
!= wxDRAG_MODE_NONE
)
340 ProcessItemEvent(dragItem
, event
, dragType
);
345 event
.Position(&x
, &y
);
347 // Find which selection handle we're on, if any
348 wxNode
*node
= handlerDialog
->GetChildren().First();
351 wxWindow
*win
= (wxWindow
*)node
->Data();
352 if (win
->IsKindOf(CLASSINFO(wxControl
)))
354 wxControl
*item
= (wxControl
*)win
;
355 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
356 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
359 ProcessItemEvent(item
, event
, selHandle
);
366 // We're not on an item or selection handle.
367 // so... check for a left or right click event
368 // to send to the application.
370 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
371 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
377 handlerDialog
->ReleaseMouse();
378 m_mouseCaptured
= FALSE
;
381 OnLeftClick(x
, y
, keys
);
383 else if (event
.RightDown())
387 handlerDialog
->ReleaseMouse();
388 m_mouseCaptured
= FALSE
;
391 OnRightClick(x
, y
, keys
);
393 else if (event
.LeftDClick())
397 handlerDialog
->ReleaseMouse();
398 m_mouseCaptured
= FALSE
;
400 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
407 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
409 if (!GetEvtHandlerEnabled())
412 // Not a selection handle event: just a normal item event.
413 // Transform to panel coordinates.
415 item
->GetPosition(&x
, &y
);
417 event
.m_x
= event
.m_x
+ x
;
418 event
.m_y
= event
.m_y
+ y
;
420 ProcessItemEvent(item
, event
, dragType
);
423 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
425 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
428 event
.Position(&x
, &y
);
430 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
431 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
432 bool dragging
= event
.Dragging();
435 int dx
= (int)abs((x
- firstDragX
));
436 int dy
= (int)abs((y
- firstDragY
));
437 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
442 // If we've ignored the tolerance once, then ALWAYS ignore
443 // tolerance in this drag, even if we come back within
444 // the tolerance range.
446 checkTolerance
= FALSE
;
449 if (event
.LeftDClick())
453 handlerDialog
->ReleaseMouse();
454 m_mouseCaptured
= FALSE
;
457 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
459 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
461 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
462 wxClientDC
dc(handlerDialog
);
463 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
464 oldDragX
= x
; oldDragY
= y
;
465 if (!m_mouseCaptured
)
467 handlerDialog
->CaptureMouse();
468 m_mouseCaptured
= TRUE
;
471 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
473 wxClientDC
dc(handlerDialog
);
474 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
475 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
476 oldDragX
= x
; oldDragY
= y
;
478 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
480 wxClientDC
dc(handlerDialog
);
481 dragMode
= wxDRAG_MODE_NONE
;
482 checkTolerance
= TRUE
;
484 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
485 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
488 dragType
= wxDRAG_TYPE_NONE
;
492 handlerDialog
->ReleaseMouse();
493 m_mouseCaptured
= FALSE
;
496 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
498 wxClientDC
dc(handlerDialog
);
499 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
500 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
501 oldDragX
= x
; oldDragY
= y
;
503 if (!m_mouseCaptured
)
505 handlerDialog
->CaptureMouse();
506 m_mouseCaptured
= TRUE
;
509 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
511 oldDragX
= x
; oldDragY
= y
;
513 // Obsolete; no longer try to right-drag
514 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
516 dragMode
= wxDRAG_MODE_NONE
;
517 checkTolerance
= TRUE
;
519 dragType
= wxDRAG_TYPE_NONE
;
523 handlerDialog
->ReleaseMouse();
524 m_mouseCaptured
= FALSE
;
527 else if (event
.IsButton())
529 checkTolerance
= TRUE
;
531 if (event
.LeftDown())
534 dragMode
= wxDRAG_MODE_START_LEFT
;
537 dragType
= selectionHandle
;
539 if (!m_mouseCaptured
)
541 handlerDialog
->CaptureMouse();
542 m_mouseCaptured
= TRUE
;
545 else if (event
.RightDown())
549 handlerDialog
->ReleaseMouse();
550 m_mouseCaptured
= FALSE
;
554 childHandler
->OnRightClick(x
, y
, keys
);
556 OnRightClick(x
, y
, keys
);
558 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
562 dragMode = wxDRAG_MODE_START_RIGHT;
565 dragType = selectionHandle;
567 if (!m_mouseCaptured)
569 handlerDialog->CaptureMouse();
570 m_mouseCaptured = TRUE;
574 else if (event
.LeftUp())
577 childHandler
->OnLeftClick(x
, y
, keys
);
579 OnLeftClick(x
, y
, keys
);
581 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
585 handlerDialog
->ReleaseMouse();
586 m_mouseCaptured
= FALSE
;
589 else if (event
.RightUp())
593 childHandler->OnRightClick(x, y, keys);
595 OnRightClick(x, y, keys);
597 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
601 handlerDialog->ReleaseMouse();
602 m_mouseCaptured = FALSE;
609 // Calls DrawSelectionHandles for all items if
611 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
613 if (!GetEvtHandlerEnabled())
618 wxNode
*node
= handlerDialog
->GetChildren().First();
621 wxWindow
*win
= (wxWindow
*)node
->Data();
622 if (win
->IsKindOf(CLASSINFO(wxControl
)))
624 wxControl
*item
= (wxControl
*)win
;
625 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
627 // Don't draw handles for an item that's being moved: it'll
629 if (childHandler
->IsSelected() && (item
!= dragItem
))
630 childHandler
->DrawSelectionHandles(dc
);
638 * Event handler for controls
641 int wxResourceEditorControlHandler::dragOffsetX
= 0;
642 int wxResourceEditorControlHandler::dragOffsetY
= 0;
644 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
645 wxEvtHandler
*oldHandler
)
647 handlerControl
= control
;
648 handlerOldHandler
= oldHandler
;
658 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
663 * Manipulation and drawing of items in Edit Mode
666 void wxResourceEditorControlHandler::SelectItem(bool select
)
671 // Returns TRUE or FALSE
672 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
674 int xpos
, ypos
, width
, height
;
675 handlerControl
->GetPosition(&xpos
, &ypos
);
676 handlerControl
->GetSize(&width
, &height
);
678 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
681 // Calculate position of the 8 handles
682 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
684 int xpos
, ypos
, width
, height
;
685 handlerControl
->GetPosition(&xpos
, &ypos
);
686 handlerControl
->GetSize(&width
, &height
);
687 int middleX
= (xpos
+ (width
/2));
688 int middleY
= (ypos
+ (height
/2));
690 // Start from top middle, clockwise.
699 hx
[0] = (int)(middleX
- (handleSize
/2));
700 hy
[0] = ypos
- handleSize
- handleMargin
;
702 hx
[1] = xpos
+ width
+ handleMargin
;
703 hy
[1] = ypos
- handleSize
- handleMargin
;
705 hx
[2] = xpos
+ width
+ handleMargin
;
706 hy
[2] = (int)(middleY
- (handleSize
/2));
708 hx
[3] = xpos
+ width
+ handleMargin
;
709 hy
[3] = ypos
+ height
+ handleMargin
;
711 hx
[4] = (int)(middleX
- (handleSize
/2));
712 hy
[4] = ypos
+ height
+ handleMargin
;
714 hx
[5] = xpos
- handleSize
- handleMargin
;
715 hy
[5] = ypos
+ height
+ handleMargin
;
717 hx
[6] = xpos
- handleSize
- handleMargin
;
718 hy
[6] = (int)(middleY
- (handleSize
/2));
720 hx
[7] = xpos
- handleSize
- handleMargin
;
721 hy
[7] = ypos
- handleSize
- handleMargin
;
724 // Returns 0 (no hit), 1 - 8 for which selection handle
725 // (clockwise from top middle)
726 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
731 CalcSelectionHandles(hx
, hy
);
734 for (i
= 0; i
< 8; i
++)
736 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
742 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
744 dc
.SetOptimization(FALSE
);
746 dc
.SetLogicalFunction(wxCOPY
);
747 dc
.SetPen(* wxBLACK_PEN
);
748 dc
.SetBrush(* wxBLACK_BRUSH
);
750 dc
.SetOptimization(TRUE
);
755 CalcSelectionHandles(hx
, hy
);
758 for (i
= 0; i
< 8; i
++)
760 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
764 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
766 dc
.DrawRectangle(x
, y
, w
, h
);
769 // If selectionHandle is zero, not dragging the selection handle.
770 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
772 int xpos
, ypos
, width
, height
;
773 handlerControl
->GetPosition(&xpos
, &ypos
);
774 handlerControl
->GetSize(&width
, &height
);
778 // dc.DestroyClippingRegion();
780 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
782 // Erase selection handles
783 // DrawSelectionHandles(dc, TRUE);
785 dc
.SetOptimization(FALSE
);
787 dc
.SetLogicalFunction(wxXOR
);
789 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
791 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
793 dc
.SetOptimization(TRUE
);
795 if (selectionHandle
> 0)
799 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
805 dragOffsetX
= (x
- xpos
);
806 dragOffsetY
= (y
- ypos
);
808 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
810 // Also draw bounding boxes for other selected items
811 wxNode
*node
= panel
->GetChildren().First();
814 wxWindow
*win
= (wxWindow
*)node
->Data();
815 if (win
->IsKindOf(CLASSINFO(wxControl
)))
817 wxControl
*item
= (wxControl
*)win
;
818 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
819 if ((item
!= handlerControl
) && handler
->IsSelected())
822 item
->GetPosition(&x1
, &y1
);
823 item
->GetSize(&w1
, &h1
);
824 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
833 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt
), int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
835 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
836 int xpos
, ypos
, width
, height
;
837 handlerControl
->GetPosition(&xpos
, &ypos
);
838 handlerControl
->GetSize(&width
, &height
);
840 if (selectionHandle
> 0)
850 int x1
, y1
, width1
, height1
;
852 switch (selectionHandle
)
858 height1
= (ypos
+ height
) - y
;
864 height1
= (y
- ypos
);
875 width1
= (xpos
+ width
) - x
;
882 height1
= (ypos
+ height
) - y
;
888 height1
= (y
- ypos
);
893 width1
= (xpos
+ width
) - x
;
899 width1
= (xpos
+ width
) - x
;
900 height1
= (ypos
+ height
) - y
;
905 dc
.SetLogicalFunction(wxXOR
);
906 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
908 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
910 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
917 dc
.SetLogicalFunction(wxXOR
);
918 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
920 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
922 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
924 // Also draw bounding boxes for other selected items
925 wxNode
*node
= panel
->GetChildren().First();
928 wxWindow
*win
= (wxWindow
*)node
->Data();
929 if (win
->IsKindOf(CLASSINFO(wxControl
)))
931 wxControl
*item
= (wxControl
*)win
;
932 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
933 if ((item
!= handlerControl
) && handler
->IsSelected())
936 item
->GetPosition(&x1
, &y1
);
937 item
->GetSize(&w1
, &h1
);
938 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
939 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
940 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
949 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
951 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
955 int xpos
, ypos
, width
, height
;
956 handlerControl
->GetPosition(&xpos
, &ypos
);
957 handlerControl
->GetSize(&width
, &height
);
959 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
);
960 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl
->GetParent());
962 if (selectionHandle
> 0)
964 int x1
, y1
, width1
, height1
;
966 switch (selectionHandle
)
972 height1
= (ypos
+ height
) - y
;
978 height1
= (y
- ypos
);
989 width1
= (xpos
+ width
) - x
;
996 height1
= (ypos
+ height
) - y
;
1001 width1
= (x
- xpos
);
1002 height1
= (y
- ypos
);
1007 width1
= (xpos
+ width
) - x
;
1013 width1
= (xpos
+ width
) - x
;
1014 height1
= (ypos
+ height
) - y
;
1017 // Update the associated resource
1018 // We need to convert to dialog units if this is not a dialog or panel, but
1019 // the parent resource specifies dialog units.
1022 int resourceWidth
= width1
;
1023 int resourceHeight
= height1
;
1025 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1027 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(x1
, y1
));
1028 wxSize sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxSize(width1
, height1
));
1030 // Convert back so we've rounded down
1031 sz
= handlerControl
->GetParent()->ConvertDialogToPixels(sz
);
1032 sz
= handlerControl
->GetParent()->ConvertPixelsToDialog(sz
);
1033 resourceWidth
= sz
.x
; resourceHeight
= sz
.y
;
1035 sz
= handlerControl
->GetParent()->ConvertDialogToPixels(sz
);
1039 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1040 pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(pt
);
1041 resourceX
= pt
.x
; resourceY
= pt
.y
;
1043 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1047 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
1048 resource
->SetSize(resourceX
, resourceY
, resourceWidth
, resourceHeight
);
1052 // Correction 31/12/98. We need to round down the values to take into account
1053 // the fact that several pixels map to the same dialog unit.
1055 int newX
= (int)(x
- dragOffsetX
);
1056 int newY
= (int)(y
- dragOffsetY
);
1057 int resourceX
= newX
;
1058 int resourceY
= newY
;
1060 // Update the associated resource
1061 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1063 wxPoint pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1064 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1065 pt
= handlerControl
->GetParent()->ConvertPixelsToDialog(pt
);
1066 resourceX
= pt
.x
; resourceY
= pt
.y
;
1067 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1069 // Having converted it several times, we know it'll map to dialog units exactly.
1073 handlerControl
->Move(newX
, newY
);
1074 OldOnMove(newX
, newY
);
1076 resource
->SetSize(resourceX
, resourceY
, resource
->GetWidth(), resource
->GetHeight());
1078 // Also move other selected items
1079 wxNode
*node
= panel
->GetChildren().First();
1082 wxWindow
*win
= (wxWindow
*)node
->Data();
1083 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1085 wxControl
*item
= (wxControl
*)win
;
1086 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1087 if ((item
!= handlerControl
) && handler
->IsSelected())
1090 item
->GetPosition(&x1
, &y1
);
1091 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1092 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1094 // Update the associated resource
1095 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1096 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1098 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(x2
, y2
));
1099 pt
= item
->GetParent()->ConvertDialogToPixels(pt
);
1100 pt
= item
->GetParent()->ConvertPixelsToDialog(pt
);
1102 resourceX
= pt
.x
; resourceY
= pt
.y
;
1103 pt
= handlerControl
->GetParent()->ConvertDialogToPixels(pt
);
1105 // Having converted it several times, we know it'll map to dialog units exactly
1111 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
1112 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1114 resource
->SetSize(resourceX
, resourceY
, resource
->GetWidth(), resource
->GetHeight());
1118 node
= node
->Next();
1121 dc
.SetOptimization(FALSE
);
1123 dc
.SetLogicalFunction(wxCOPY
);
1124 dc
.SetPen(* wxBLACK_PEN
);
1125 dc
.SetBrush(* wxBLACK_BRUSH
);
1127 dc
.SetOptimization(TRUE
);
1129 // Force it to repaint the selection handles (if any)
1130 // since the panel thinks we're still within a drag and
1131 // won't paint the handles.
1133 DrawSelectionHandles(dc
);
1140 // These functions call OnItemEvent, OnItemMove and OnItemSize
1142 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1145 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1146 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1149 wxWindow
*panel
= handlerControl
->GetParent();
1150 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1152 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1153 if ( !panelHandler
->GetEvtHandlerEnabled() )
1159 panelHandler
->OnItemEvent(handlerControl
, event
);
1162 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1164 wxWindow
*panel
= handlerControl
->GetParent();
1165 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1168 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1169 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1172 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1174 wxWindow
*panel
= handlerControl
->GetParent();
1175 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1178 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1179 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1182 void wxResourceEditorControlHandler::OnSelect(bool select
)
1184 wxWindow
*panel
= handlerControl
->GetParent();
1185 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1188 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1189 panelHandler
->OnItemSelect(handlerControl
, select
);
1192 void wxResourceEditorControlHandler::OnLeftClick(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
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1202 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1204 wxWindow
*panel
= handlerControl
->GetParent();
1205 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1208 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1209 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);