1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dialog handler
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
32 #if defined(__WINDOWS__) && !defined(__GNUWIN32__)
35 #include <strstream.h>
44 IMPLEMENT_CLASS(wxResourceEditorDialogHandler
, wxEvtHandler
)
45 IMPLEMENT_CLASS(wxResourceEditorControlHandler
, wxEvtHandler
)
47 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler
, wxEvtHandler
)
48 EVT_PAINT(wxResourceEditorDialogHandler::OnPaint
)
49 EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent
)
52 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler
, wxEvtHandler
)
53 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent
)
57 * Dialog box event handler
60 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel
*dialog
, wxItemResource
*resource
,
61 wxEvtHandler
*oldHandler
, wxResourceManager
*manager
)
63 handlerDialog
= dialog
;
64 handlerResource
= resource
;
65 handlerOldHandler
= oldHandler
;
66 resourceManager
= manager
;
68 dragMode
= wxDRAG_MODE_NONE
;
69 dragType
= wxDRAG_TYPE_NONE
;
76 checkTolerance
= TRUE
;
77 m_mouseCaptured
= FALSE
;
81 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
85 void wxResourceEditorDialogHandler::OnItemSelect(wxControl
*item
, bool select
)
88 resourceManager
->AddSelection(item
);
90 resourceManager
->RemoveSelection(item
);
93 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent
& event
)
95 wxPaintDC
dc(handlerDialog
);
97 PaintSelectionHandles(dc
);
100 // Add event handlers for all children
101 void wxResourceEditorDialogHandler::AddChildHandlers(void)
103 wxNode
*node
= handlerDialog
->GetChildren()->First();
106 wxControl
*child
= (wxControl
*)node
->Data();
107 wxEvtHandler
*childHandler
= child
->GetEventHandler();
108 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
== child
)
109 child
->PushEventHandler(new wxResourceEditorControlHandler(child
, childHandler
));
114 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
116 if (keys
& wxKEY_CTRL
)
118 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
122 // Deselect all items if click on panel
123 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER
)
125 int needsRefresh
= 0;
126 wxNode
*node
= handlerDialog
->GetChildren()->First();
129 wxControl
*item
= (wxControl
*)node
->Data();
130 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
131 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
134 OnItemSelect(item
, FALSE
);
135 childHandler
->SelectItem(FALSE
);
139 if (needsRefresh
> 0)
141 wxClientDC
dc(handlerDialog
);
143 handlerDialog
->Refresh();
148 wxResourceManager
* manager
= resourceManager
;
150 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
153 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
155 case RESED_BMPBUTTON
:
156 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxBitmapButton", x
, y
, TRUE
);
158 case RESED_STATICTEXT
:
159 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
161 case RESED_STATICBMP
:
162 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
164 case RESED_TEXTCTRL_SINGLE
:
165 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
167 case RESED_TEXTCTRL_MULTIPLE
:
168 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
171 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
174 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
177 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
180 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
183 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
186 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
188 case RESED_STATICBOX
:
189 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
191 case RESED_SCROLLBAR
:
192 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
198 // Now switch pointer on.
199 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER
)
201 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
206 void wxResourceEditorDialogHandler::OnLeftClick(int x
, int y
, int keys
)
208 if (keys
& wxKEY_CTRL
)
210 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog
);
214 // Deselect all items if click on panel
215 if (resourceManager
->GetEditorPalette()->currentlySelected
== PALETTE_ARROW
)
217 int needsRefresh
= 0;
218 wxNode
*node
= handlerDialog
->GetChildren()->First();
221 wxControl
*item
= (wxControl
*)node
->Data();
222 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
223 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
226 OnItemSelect(item
, FALSE
);
227 childHandler
->SelectItem(FALSE
);
231 if (needsRefresh
> 0)
233 wxClientDC
dc(handlerDialog
);
235 handlerDialog
->Refresh();
240 wxResourceManager
* manager
= resourceManager
;
242 switch (resourceManager
->GetEditorPalette()->currentlySelected
)
246 case PALETTE_DIALOG_BOX
:
252 case PALETTE_TEXT_WINDOW
:
255 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
);
257 case PALETTE_BITMAP_BUTTON
:
258 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxButton", x
, y
, TRUE
);
260 case PALETTE_MESSAGE
:
261 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticText", x
, y
);
263 case PALETTE_BITMAP_MESSAGE
:
264 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBitmap", x
, y
, TRUE
);
267 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (single-line)", x
, y
);
269 case PALETTE_MULTITEXT
:
270 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxTextCtrl (multi-line)", x
, y
);
273 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxChoice", x
, y
);
275 case PALETTE_CHECKBOX
:
276 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxCheckBox", x
, y
);
278 case PALETTE_RADIOBOX
:
279 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxRadioBox", x
, y
);
281 case PALETTE_LISTBOX
:
282 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxListBox", x
, y
);
285 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxSlider", x
, y
);
288 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxGauge", x
, y
);
290 case PALETTE_GROUPBOX
:
291 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxStaticBox", x
, y
);
293 case PALETTE_SCROLLBAR
:
294 resourceManager
->CreatePanelItem(handlerResource
, handlerDialog
, "wxScrollBar", x
, y
);
300 // Now switch pointer on.
301 if (manager
->GetEditorPalette()->currentlySelected
!= PALETTE_ARROW
)
303 manager
->GetEditorPalette()->ToggleTool(manager
->GetEditorPalette()->currentlySelected
, FALSE
);
304 manager
->GetEditorPalette()->ToggleTool(PALETTE_ARROW
, TRUE
);
305 manager
->GetEditorPalette()->currentlySelected
= PALETTE_ARROW
;
310 void wxResourceEditorDialogHandler::OnRightClick(int x
, int y
, int keys
)
312 wxMenu
*menu
= resourceManager
->GetPopupMenu();
313 menu
->SetClientData((char *)handlerDialog
);
314 handlerDialog
->PopupMenu(menu
, x
, y
);
317 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl
*item
, int x
, int y
, int keys
)
319 if (keys
& wxKEY_CTRL
)
321 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
325 // If this is a wxStaticBox and the pointer isn't an arrow, chances
326 // are that we really meant to place an item on the panel.
328 if ((item
->GetClassInfo() == CLASSINFO(wxStaticBox
)) && resourceManager
->GetEditorPalette()->currentlySelected
!= PALETTE_ARROW
)
330 OnLeftClick(x
, y
, keys
);
334 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
336 if (childHandler
->IsSelected())
338 childHandler
->SelectItem(FALSE
);
339 OnItemSelect(item
, FALSE
);
341 wxClientDC
dc(handlerDialog
);
343 handlerDialog
->Refresh();
347 childHandler
->SelectItem(TRUE
);
348 OnItemSelect(item
, TRUE
);
350 // Deselect other items if shift is not pressed
351 int needsRefresh
= 0;
352 if (!(keys
& wxKEY_SHIFT
))
354 wxNode
*node
= item
->GetParent()->GetChildren()->First();
357 wxControl
*child
= (wxControl
*)node
->Data();
358 wxResourceEditorControlHandler
*childHandler2
= (wxResourceEditorControlHandler
*)child
->GetEventHandler();
359 if (child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler2
->IsSelected() && child
!= item
)
361 childHandler2
->SelectItem(FALSE
);
362 OnItemSelect(child
, FALSE
);
369 wxClientDC
dc(handlerDialog
);
370 childHandler
->DrawSelectionHandles(dc
);
372 if (needsRefresh
> 0)
375 handlerDialog
->Refresh();
380 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl
*item
, int x
, int y
, int keys
)
383 if (keys & wxKEY_CTRL)
385 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
390 wxMenu
*menu
= resourceManager
->GetPopupMenu();
391 menu
->SetClientData((char *)item
);
392 handlerDialog
->PopupMenu(menu
, x
, y
);
395 // An event outside any items: may be a drag event.
396 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent
& event
)
398 if (GetEvtHandlerEnabled())
400 // If we're dragging an item or selection handle,
401 // continue dragging.
402 if (dragMode
!= wxDRAG_MODE_NONE
)
404 ProcessItemEvent(dragItem
, event
, dragType
);
409 event
.Position(&x
, &y
);
411 // Find which selection handle we're on, if any
412 wxNode
*node
= handlerDialog
->GetChildren()->First();
415 wxWindow
*win
= (wxWindow
*)node
->Data();
416 if (win
->IsKindOf(CLASSINFO(wxControl
)))
418 wxControl
*item
= (wxControl
*)win
;
419 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
420 int selHandle
= childHandler
->SelectionHandleHitTest(x
, y
);
423 ProcessItemEvent(item
, event
, selHandle
);
430 // We're not on an item or selection handle.
431 // so... check for a left or right click event
432 // to send to the application.
434 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
435 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
441 handlerDialog
->ReleaseMouse();
442 m_mouseCaptured
= FALSE
;
445 OnLeftClick(x
, y
, keys
);
447 else if (event
.RightUp())
451 handlerDialog
->ReleaseMouse();
452 m_mouseCaptured
= FALSE
;
455 OnRightClick(x
, y
, keys
);
462 void wxResourceEditorDialogHandler::OnItemEvent(wxControl
*item
, wxMouseEvent
& event
)
464 if (!GetEvtHandlerEnabled())
467 // Not a selection handle event: just a normal item event.
468 // Transform to panel coordinates.
470 item
->GetPosition(&x
, &y
);
472 event
.m_x
= event
.m_x
+ x
;
473 event
.m_y
= event
.m_y
+ y
;
474 ProcessItemEvent(item
, event
, dragType
);
477 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl
*item
, wxMouseEvent
& event
, int selectionHandle
)
479 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
482 event
.Position(&x
, &y
);
484 if (event
.ShiftDown()) keys
= keys
| wxKEY_SHIFT
;
485 if (event
.ControlDown()) keys
= keys
| wxKEY_CTRL
;
486 bool dragging
= event
.Dragging();
489 int dx
= (int)abs((x
- firstDragX
));
490 int dy
= (int)abs((y
- firstDragY
));
491 if (checkTolerance
&& (dx
<= dragTolerance
) && (dy
<= dragTolerance
))
496 // If we've ignored the tolerance once, then ALWAYS ignore
497 // tolerance in this drag, even if we come back within
498 // the tolerance range.
500 checkTolerance
= FALSE
;
503 if (event
.LeftDClick())
507 handlerDialog
->ReleaseMouse();
508 m_mouseCaptured
= FALSE
;
511 wxResourceManager::GetCurrentResourceManager()->EditWindow(item
);
513 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_LEFT
)
515 dragMode
= wxDRAG_MODE_CONTINUE_LEFT
;
516 wxClientDC
dc(handlerDialog
);
517 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
518 oldDragX
= x
; oldDragY
= y
;
519 if (!m_mouseCaptured
)
521 handlerDialog
->CaptureMouse();
522 m_mouseCaptured
= TRUE
;
525 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
527 wxClientDC
dc(handlerDialog
);
528 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
529 childHandler
->OnDragContinue(TRUE
, x
, y
, keys
, dc
, selectionHandle
);
530 oldDragX
= x
; oldDragY
= y
;
532 else if (event
.LeftUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_LEFT
)
534 wxClientDC
dc(handlerDialog
);
535 dragMode
= wxDRAG_MODE_NONE
;
536 checkTolerance
= TRUE
;
538 childHandler
->OnDragContinue(FALSE
, oldDragX
, oldDragY
, keys
, dc
, selectionHandle
);
539 childHandler
->OnDragEnd(x
, y
, keys
, dc
, selectionHandle
);
542 dragType
= wxDRAG_TYPE_NONE
;
546 handlerDialog
->ReleaseMouse();
547 m_mouseCaptured
= FALSE
;
550 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_START_RIGHT
)
552 wxClientDC
dc(handlerDialog
);
553 dragMode
= wxDRAG_MODE_CONTINUE_RIGHT
;
554 childHandler
->OnDragBegin(x
, y
, keys
, dc
, selectionHandle
);
555 oldDragX
= x
; oldDragY
= y
;
557 if (!m_mouseCaptured
)
559 handlerDialog
->CaptureMouse();
560 m_mouseCaptured
= TRUE
;
563 else if (dragging
&& dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
565 oldDragX
= x
; oldDragY
= y
;
567 else if (event
.RightUp() && dragItem
&& dragMode
== wxDRAG_MODE_CONTINUE_RIGHT
)
569 dragMode
= wxDRAG_MODE_NONE
;
570 checkTolerance
= TRUE
;
572 dragType
= wxDRAG_TYPE_NONE
;
576 handlerDialog
->ReleaseMouse();
577 m_mouseCaptured
= FALSE
;
580 else if (event
.IsButton())
582 checkTolerance
= TRUE
;
584 if (event
.LeftDown())
587 dragMode
= wxDRAG_MODE_START_LEFT
;
590 dragType
= selectionHandle
;
592 if (!m_mouseCaptured
)
594 handlerDialog
->CaptureMouse();
595 m_mouseCaptured
= TRUE
;
598 else if (event
.RightDown())
601 dragMode
= wxDRAG_MODE_START_RIGHT
;
604 dragType
= selectionHandle
;
606 if (!m_mouseCaptured
)
608 handlerDialog
->CaptureMouse();
609 m_mouseCaptured
= TRUE
;
612 else if (event
.LeftUp())
615 childHandler
->OnLeftClick(x
, y
, keys
);
617 OnLeftClick(x
, y
, keys
);
619 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
623 handlerDialog
->ReleaseMouse();
624 m_mouseCaptured
= FALSE
;
627 else if (event
.RightUp())
630 childHandler
->OnRightClick(x
, y
, keys
);
632 OnRightClick(x
, y
, keys
);
634 dragItem
= NULL
; dragMode
= wxDRAG_MODE_NONE
; dragType
= wxDRAG_TYPE_NONE
;
638 handlerDialog
->ReleaseMouse();
639 m_mouseCaptured
= FALSE
;
645 // Calls DrawSelectionHandles for all items if
647 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC
& dc
)
649 if (!GetEvtHandlerEnabled())
654 wxNode
*node
= handlerDialog
->GetChildren()->First();
657 wxWindow
*win
= (wxWindow
*)node
->Data();
658 if (win
->IsKindOf(CLASSINFO(wxControl
)))
660 wxControl
*item
= (wxControl
*)win
;
661 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
663 // Don't draw handles for an item that's being moved: it'll
665 if (childHandler
->IsSelected() && (item
!= dragItem
))
666 childHandler
->DrawSelectionHandles(dc
);
674 * Event handler for controls
677 int wxResourceEditorControlHandler::dragOffsetX
= 0;
678 int wxResourceEditorControlHandler::dragOffsetY
= 0;
680 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl
*control
,
681 wxEvtHandler
*oldHandler
)
683 handlerControl
= control
;
684 handlerOldHandler
= oldHandler
;
694 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
699 * Manipulation and drawing of items in Edit Mode
702 void wxResourceEditorControlHandler::SelectItem(bool select
)
707 // Returns TRUE or FALSE
708 bool wxResourceEditorControlHandler::HitTest(int x
, int y
)
710 int xpos
, ypos
, width
, height
;
711 handlerControl
->GetPosition(&xpos
, &ypos
);
712 handlerControl
->GetSize(&width
, &height
);
714 return ((x
>= xpos
) && (x
<= (xpos
+ width
)) && (y
>= ypos
) && (y
<= (ypos
+ height
)));
717 // Calculate position of the 8 handles
718 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx
, int *hy
)
720 int xpos
, ypos
, width
, height
;
721 handlerControl
->GetPosition(&xpos
, &ypos
);
722 handlerControl
->GetSize(&width
, &height
);
723 int middleX
= (xpos
+ (width
/2));
724 int middleY
= (ypos
+ (height
/2));
726 // Start from top middle, clockwise.
735 hx
[0] = (int)(middleX
- (handleSize
/2));
736 hy
[0] = ypos
- handleSize
- handleMargin
;
738 hx
[1] = xpos
+ width
+ handleMargin
;
739 hy
[1] = ypos
- handleSize
- handleMargin
;
741 hx
[2] = xpos
+ width
+ handleMargin
;
742 hy
[2] = (int)(middleY
- (handleSize
/2));
744 hx
[3] = xpos
+ width
+ handleMargin
;
745 hy
[3] = ypos
+ height
+ handleMargin
;
747 hx
[4] = (int)(middleX
- (handleSize
/2));
748 hy
[4] = ypos
+ height
+ handleMargin
;
750 hx
[5] = xpos
- handleSize
- handleMargin
;
751 hy
[5] = ypos
+ height
+ handleMargin
;
753 hx
[6] = xpos
- handleSize
- handleMargin
;
754 hy
[6] = (int)(middleY
- (handleSize
/2));
756 hx
[7] = xpos
- handleSize
- handleMargin
;
757 hy
[7] = ypos
- handleSize
- handleMargin
;
760 // Returns 0 (no hit), 1 - 8 for which selection handle
761 // (clockwise from top middle)
762 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x
, int y
)
767 CalcSelectionHandles(hx
, hy
);
770 for (i
= 0; i
< 8; i
++)
772 if ((x
>= hx
[i
]) && (x
<= (hx
[i
] + handleSize
)) && (y
>= hy
[i
]) && (y
<= (hy
[i
] + handleSize
)))
778 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC
& dc
, bool WXUNUSED(erase
))
780 dc
.SetOptimization(FALSE
);
782 dc
.SetLogicalFunction(wxCOPY
);
783 dc
.SetPen(wxBLACK_PEN
);
784 dc
.SetBrush(wxBLACK_BRUSH
);
786 dc
.SetOptimization(TRUE
);
791 CalcSelectionHandles(hx
, hy
);
794 for (i
= 0; i
< 8; i
++)
796 dc
.DrawRectangle(hx
[i
], hy
[i
], handleSize
, handleSize
);
800 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC
& dc
, int x
, int y
, int w
, int h
)
802 dc
.DrawRectangle(x
, y
, w
, h
);
805 // If selectionHandle is zero, not dragging the selection handle.
806 void wxResourceEditorControlHandler::OnDragBegin(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
808 int xpos
, ypos
, width
, height
;
809 handlerControl
->GetPosition(&xpos
, &ypos
);
810 handlerControl
->GetSize(&width
, &height
);
814 // dc.DestroyClippingRegion();
816 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
817 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
819 // Erase selection handles
820 // DrawSelectionHandles(dc, TRUE);
822 dc
.SetOptimization(FALSE
);
824 dc
.SetLogicalFunction(wxXOR
);
826 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
828 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
830 dc
.SetOptimization(TRUE
);
832 if (selectionHandle
> 0)
836 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
842 dragOffsetX
= (x
- xpos
);
843 dragOffsetY
= (y
- ypos
);
845 DrawBoundingBox(dc
, xpos
, ypos
, width
, height
);
847 // Also draw bounding boxes for other selected items
848 wxNode
*node
= panel
->GetChildren()->First();
851 wxWindow
*win
= (wxWindow
*)node
->Data();
852 if (win
->IsKindOf(CLASSINFO(wxControl
)))
854 wxControl
*item
= (wxControl
*)win
;
855 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
856 if ((item
!= handlerControl
) && handler
->IsSelected())
859 item
->GetPosition(&x1
, &y1
);
860 item
->GetSize(&w1
, &h1
);
861 handler
->DrawBoundingBox(dc
, x1
, y1
, w1
, h1
);
870 void wxResourceEditorControlHandler::OnDragContinue(bool paintIt
, int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
872 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
873 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
875 int xpos
, ypos
, width
, height
;
876 handlerControl
->GetPosition(&xpos
, &ypos
);
877 handlerControl
->GetSize(&width
, &height
);
879 if (selectionHandle
> 0)
889 int x1
, y1
, width1
, height1
;
891 switch (selectionHandle
)
897 height1
= (ypos
+ height
) - y
;
903 height1
= (y
- ypos
);
914 width1
= (xpos
+ width
) - x
;
921 height1
= (ypos
+ height
) - y
;
927 height1
= (y
- ypos
);
932 width1
= (xpos
+ width
) - x
;
938 width1
= (xpos
+ width
) - x
;
939 height1
= (ypos
+ height
) - y
;
944 dc
.SetLogicalFunction(wxXOR
);
945 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
947 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
949 DrawBoundingBox(dc
, x1
, y1
, width1
, height1
);
956 dc
.SetLogicalFunction(wxXOR
);
957 wxPen
pen(wxColour(0, 0, 0), 1, wxDOT
);
959 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
961 DrawBoundingBox(dc
, (int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
), width
, height
);
963 // Also draw bounding boxes for other selected items
964 wxNode
*node
= panel
->GetChildren()->First();
967 wxWindow
*win
= (wxWindow
*)node
->Data();
968 if (win
->IsKindOf(CLASSINFO(wxControl
)))
970 wxControl
*item
= (wxControl
*)win
;
971 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
972 if ((item
!= handlerControl
) && handler
->IsSelected())
975 item
->GetPosition(&x1
, &y1
);
976 item
->GetSize(&w1
, &h1
);
977 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
978 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
979 handler
->DrawBoundingBox(dc
, x2
, y2
, w1
, h1
);
988 void wxResourceEditorControlHandler::OnDragEnd(int x
, int y
, int WXUNUSED(keys
), wxDC
& dc
, int selectionHandle
)
990 wxPanel
*panel
= (wxPanel
*)handlerControl
->GetParent();
991 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
995 int xpos
, ypos
, width
, height
;
996 handlerControl
->GetPosition(&xpos
, &ypos
);
997 handlerControl
->GetSize(&width
, &height
);
999 if (selectionHandle
> 0)
1001 int x1
, y1
, width1
, height1
;
1003 switch (selectionHandle
)
1009 height1
= (ypos
+ height
) - y
;
1015 height1
= (y
- ypos
);
1020 width1
= (x
- xpos
);
1026 width1
= (xpos
+ width
) - x
;
1032 width1
= (x
- xpos
);
1033 height1
= (ypos
+ height
) - y
;
1038 width1
= (x
- xpos
);
1039 height1
= (y
- ypos
);
1044 width1
= (xpos
+ width
) - x
;
1050 width1
= (xpos
+ width
) - x
;
1051 height1
= (ypos
+ height
) - y
;
1054 handlerControl
->SetSize(x1
, y1
, width1
, height1
);
1058 handlerControl
->Move((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
1059 OldOnMove((int)(x
- dragOffsetX
), (int)(y
- dragOffsetY
));
1061 // Also move other selected items
1062 wxNode
*node
= panel
->GetChildren()->First();
1065 wxWindow
*win
= (wxWindow
*)node
->Data();
1066 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1068 wxControl
*item
= (wxControl
*)win
;
1069 wxResourceEditorControlHandler
*handler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1070 if ((item
!= handlerControl
) && handler
->IsSelected())
1073 item
->GetPosition(&x1
, &y1
);
1074 int x2
= (int)(x1
+ (x
- dragOffsetX
) - xpos
);
1075 int y2
= (int)(y1
+ (y
- dragOffsetY
) - ypos
);
1077 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->OldOnMove(x2
, y2
);
1078 ((wxResourceEditorControlHandler
*)item
->GetEventHandler())->DrawSelectionHandles(dc
);
1081 node
= node
->Next();
1084 dc
.SetOptimization(FALSE
);
1086 dc
.SetLogicalFunction(wxCOPY
);
1087 dc
.SetPen(wxBLACK_PEN
);
1088 dc
.SetBrush(wxBLACK_BRUSH
);
1090 dc
.SetOptimization(TRUE
);
1092 // Force it to repaint the selection handles (if any)
1093 // since the panel thinks we're still within a drag and
1094 // won't paint the handles.
1096 DrawSelectionHandles(dc
);
1103 // These functions call OnItemEvent, OnItemMove and OnItemSize
1105 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent
& event
)
1108 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1109 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1112 wxWindow
*panel
= handlerControl
->GetParent();
1113 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1115 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1116 if ( !panelHandler
->GetEvtHandlerEnabled() )
1122 panelHandler
->OnItemEvent(handlerControl
, event
);
1125 void wxResourceEditorControlHandler::OldOnMove(int x
, int y
)
1127 wxWindow
*panel
= handlerControl
->GetParent();
1128 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1131 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1132 panelHandler
->OnItemMove(handlerControl
, x
, y
);
1135 void wxResourceEditorControlHandler::OldOnSize(int w
, int h
)
1137 wxWindow
*panel
= handlerControl
->GetParent();
1138 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1141 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1142 panelHandler
->OnItemSize(handlerControl
, w
, h
);
1145 void wxResourceEditorControlHandler::OnSelect(bool select
)
1147 wxWindow
*panel
= handlerControl
->GetParent();
1148 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1151 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1152 panelHandler
->OnItemSelect(handlerControl
, select
);
1155 void wxResourceEditorControlHandler::OnLeftClick(int x
, int y
, int keys
)
1157 wxWindow
*panel
= handlerControl
->GetParent();
1158 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1161 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1162 panelHandler
->OnItemLeftClick(handlerControl
, x
, y
, keys
);
1165 void wxResourceEditorControlHandler::OnRightClick(int x
, int y
, int keys
)
1167 wxWindow
*panel
= handlerControl
->GetParent();
1168 if ( !panel
->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler
)) )
1171 wxResourceEditorDialogHandler
*panelHandler
= (wxResourceEditorDialogHandler
*)panel
->GetEventHandler();
1172 panelHandler
->OnItemRightClick(handlerControl
, x
, y
, keys
);