]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/dlghndlr.cpp
Various Dialog Editor-related mods; Dlg Ed. getting usable now under MSW.
[wxWidgets.git] / utils / dialoged / src / dlghndlr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dlghndlr.cpp
3 // Purpose: Dialog handler
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include <ctype.h>
28 #include <stdlib.h>
29 #include <math.h>
30 #include <string.h>
31
32 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
33 #include <strstrea.h>
34 #else
35 #include <strstream.h>
36 #endif
37
38 #include "reseditr.h"
39 #include "winprop.h"
40 #include "dlghndlr.h"
41 #include "edlist.h"
42
43 IMPLEMENT_CLASS(wxResourceEditorDialogHandler, wxEvtHandler)
44 IMPLEMENT_CLASS(wxResourceEditorControlHandler, wxEvtHandler)
45
46 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler, wxEvtHandler)
47 EVT_PAINT(wxResourceEditorDialogHandler::OnPaint)
48 EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent)
49 END_EVENT_TABLE()
50
51 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler, wxEvtHandler)
52 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent)
53 END_EVENT_TABLE()
54
55 /*
56 * Dialog box event handler
57 */
58
59 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel *dialog, wxItemResource *resource,
60 wxEvtHandler *oldHandler, wxResourceManager *manager)
61 {
62 handlerDialog = dialog;
63 handlerResource = resource;
64 handlerOldHandler = oldHandler;
65 resourceManager = manager;
66
67 dragMode = wxDRAG_MODE_NONE;
68 dragType = wxDRAG_TYPE_NONE;
69 dragItem = NULL;
70 firstDragX = 0;
71 firstDragY = 0;
72 oldDragX = 0;
73 oldDragY = 0;
74 dragTolerance = 3;
75 checkTolerance = TRUE;
76 m_mouseCaptured = FALSE;
77 // m_treeItem = 0;
78 }
79
80 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
81 {
82 }
83
84 void wxResourceEditorDialogHandler::OnItemSelect(wxControl *item, bool select)
85 {
86 if (select)
87 resourceManager->AddSelection(item);
88 else
89 resourceManager->RemoveSelection(item);
90 }
91
92 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& event)
93 {
94 wxPaintDC dc(handlerDialog);
95
96 PaintSelectionHandles(dc);
97 }
98
99 // Add event handlers for all children
100 void wxResourceEditorDialogHandler::AddChildHandlers(void)
101 {
102 wxNode *node = handlerDialog->GetChildren()->First();
103 while ( node )
104 {
105 wxControl *child = (wxControl *)node->Data();
106 wxEvtHandler *childHandler = child->GetEventHandler();
107 if ( child->IsKindOf(CLASSINFO(wxControl)) && childHandler == child )
108 child->PushEventHandler(new wxResourceEditorControlHandler(child, childHandler));
109 node = node->Next();
110 }
111 }
112
113 void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
114 {
115 if (keys & wxKEY_CTRL)
116 {
117 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog);
118 return;
119 }
120
121 // Deselect all items if click on panel
122 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER)
123 {
124 int needsRefresh = 0;
125 wxNode *node = handlerDialog->GetChildren()->First();
126 while (node)
127 {
128 wxControl *item = (wxControl *)node->Data();
129 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
130 if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected())
131 {
132 needsRefresh ++;
133 OnItemSelect(item, FALSE);
134 childHandler->SelectItem(FALSE);
135 }
136 node = node->Next();
137 }
138 if (needsRefresh > 0)
139 {
140 wxClientDC dc(handlerDialog);
141 dc.Clear();
142 handlerDialog->Refresh();
143 }
144 return;
145 }
146
147 wxResourceManager* manager = resourceManager;
148
149 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
150 {
151 case RESED_BUTTON:
152 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxButton", x, y);
153 break;
154 case RESED_BMPBUTTON:
155 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxBitmapButton", x, y, TRUE);
156 break;
157 case RESED_STATICTEXT:
158 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticText", x, y);
159 break;
160 case RESED_STATICBMP:
161 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticBitmap", x, y, TRUE);
162 break;
163 case RESED_TEXTCTRL_SINGLE:
164 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxTextCtrl (single-line)", x, y);
165 break;
166 case RESED_TEXTCTRL_MULTIPLE:
167 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxTextCtrl (multi-line)", x, y);
168 break;
169 case RESED_CHOICE:
170 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxChoice", x, y);
171 break;
172 case RESED_COMBOBOX:
173 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxComboBox", x, y);
174 break;
175 case RESED_CHECKBOX:
176 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxCheckBox", x, y);
177 break;
178 case RESED_RADIOBOX:
179 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioBox", x, y);
180 break;
181 case RESED_RADIOBUTTON:
182 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioButton", x, y);
183 break;
184 case RESED_LISTBOX:
185 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxListBox", x, y);
186 break;
187 case RESED_SLIDER:
188 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxSlider", x, y);
189 break;
190 case RESED_GAUGE:
191 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxGauge", x, y);
192 break;
193 case RESED_STATICBOX:
194 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticBox", x, y);
195 break;
196 case RESED_SCROLLBAR:
197 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxScrollBar", x, y);
198 break;
199 default:
200 break;
201 }
202
203 // Now switch pointer on.
204 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER)
205 {
206 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
207 }
208 }
209
210 void wxResourceEditorDialogHandler::OnRightClick(int x, int y, int keys)
211 {
212 wxMenu *menu = resourceManager->GetPopupMenu();
213 menu->SetClientData((char *)handlerDialog);
214 handlerDialog->PopupMenu(menu, x, y);
215 }
216
217 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int x, int y, int keys)
218 {
219 if (keys & wxKEY_CTRL)
220 {
221 wxResourceManager::GetCurrentResourceManager()->EditWindow(item);
222 return;
223 }
224
225 /*
226 // If this is a wxStaticBox and the pointer isn't an arrow, chances
227 // are that we really meant to place an item on the panel.
228 // Fake this event.
229 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
230 {
231 OnLeftClick(x, y, keys);
232 return;
233 }
234 */
235
236 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
237
238 if (childHandler->IsSelected())
239 {
240 childHandler->SelectItem(FALSE);
241 OnItemSelect(item, FALSE);
242
243 wxClientDC dc(handlerDialog);
244 dc.Clear();
245 handlerDialog->Refresh();
246 }
247 else
248 {
249 childHandler->SelectItem(TRUE);
250 OnItemSelect(item, TRUE);
251
252 // Deselect other items if shift is not pressed
253 int needsRefresh = 0;
254 if (!(keys & wxKEY_SHIFT))
255 {
256 wxNode *node = item->GetParent()->GetChildren()->First();
257 while (node)
258 {
259 wxControl *child = (wxControl *)node->Data();
260 wxResourceEditorControlHandler *childHandler2 = (wxResourceEditorControlHandler *)child->GetEventHandler();
261 if (child->IsKindOf(CLASSINFO(wxControl)) && childHandler2->IsSelected() && child != item)
262 {
263 childHandler2->SelectItem(FALSE);
264 OnItemSelect(child, FALSE);
265 needsRefresh ++;
266 }
267 node = node->Next();
268 }
269 }
270
271 wxClientDC dc(handlerDialog);
272 childHandler->DrawSelectionHandles(dc);
273
274 if (needsRefresh > 0)
275 {
276 dc.Clear();
277 handlerDialog->Refresh();
278 }
279 }
280 }
281
282 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl *item, int x, int y, int keys)
283 {
284 /*
285 if (keys & wxKEY_CTRL)
286 {
287 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
288 return;
289 }
290 */
291
292 wxMenu *menu = resourceManager->GetPopupMenu();
293 menu->SetClientData((char *)item);
294 handlerDialog->PopupMenu(menu, x, y);
295 }
296
297 // An event outside any items: may be a drag event.
298 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event)
299 {
300 if (GetEvtHandlerEnabled())
301 {
302 // If we're dragging an item or selection handle,
303 // continue dragging.
304 if (dragMode != wxDRAG_MODE_NONE)
305 {
306 ProcessItemEvent(dragItem, event, dragType);
307 return;
308 }
309
310 long x, y;
311 event.Position(&x, &y);
312
313 // Find which selection handle we're on, if any
314 wxNode *node = handlerDialog->GetChildren()->First();
315 while (node)
316 {
317 wxWindow *win = (wxWindow *)node->Data();
318 if (win->IsKindOf(CLASSINFO(wxControl)))
319 {
320 wxControl *item = (wxControl *)win;
321 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
322 int selHandle = childHandler->SelectionHandleHitTest(x, y);
323 if (selHandle > 0)
324 {
325 ProcessItemEvent(item, event, selHandle);
326 return;
327 }
328 }
329 node = node->Next();
330 }
331
332 // We're not on an item or selection handle.
333 // so... check for a left or right click event
334 // to send to the application.
335 int keys = 0;
336 if (event.ShiftDown()) keys = keys | wxKEY_SHIFT;
337 if (event.ControlDown()) keys = keys | wxKEY_CTRL;
338
339 if (event.LeftUp())
340 {
341 if (m_mouseCaptured)
342 {
343 handlerDialog->ReleaseMouse();
344 m_mouseCaptured = FALSE;
345 }
346
347 OnLeftClick(x, y, keys);
348 }
349 else if (event.RightUp())
350 {
351 if (m_mouseCaptured)
352 {
353 handlerDialog->ReleaseMouse();
354 m_mouseCaptured = FALSE;
355 }
356
357 OnRightClick(x, y, keys);
358 }
359 }
360 else
361 event.Skip();
362 }
363
364 void wxResourceEditorDialogHandler::OnItemEvent(wxControl *item, wxMouseEvent& event)
365 {
366 if (!GetEvtHandlerEnabled())
367 return;
368
369 // Not a selection handle event: just a normal item event.
370 // Transform to panel coordinates.
371 int x, y;
372 item->GetPosition(&x, &y);
373
374 event.m_x = event.m_x + x;
375 event.m_y = event.m_y + y;
376 ProcessItemEvent(item, event, dragType);
377 }
378
379 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEvent& event, int selectionHandle)
380 {
381 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
382
383 long x, y;
384 event.Position(&x, &y);
385 int keys = 0;
386 if (event.ShiftDown()) keys = keys | wxKEY_SHIFT;
387 if (event.ControlDown()) keys = keys | wxKEY_CTRL;
388 bool dragging = event.Dragging();
389 if (dragging)
390 {
391 int dx = (int)abs((x - firstDragX));
392 int dy = (int)abs((y - firstDragY));
393 if (checkTolerance && (dx <= dragTolerance) && (dy <= dragTolerance))
394 {
395 return;
396 }
397 else
398 // If we've ignored the tolerance once, then ALWAYS ignore
399 // tolerance in this drag, even if we come back within
400 // the tolerance range.
401 {
402 checkTolerance = FALSE;
403 }
404 }
405 if (event.LeftDClick())
406 {
407 if (m_mouseCaptured)
408 {
409 handlerDialog->ReleaseMouse();
410 m_mouseCaptured = FALSE;
411 }
412
413 wxResourceManager::GetCurrentResourceManager()->EditWindow(item);
414 }
415 else if (dragging && dragItem && dragMode == wxDRAG_MODE_START_LEFT)
416 {
417 dragMode = wxDRAG_MODE_CONTINUE_LEFT;
418 wxClientDC dc(handlerDialog);
419 childHandler->OnDragBegin(x, y, keys, dc, selectionHandle);
420 oldDragX = x; oldDragY = y;
421 if (!m_mouseCaptured)
422 {
423 handlerDialog->CaptureMouse();
424 m_mouseCaptured = TRUE;
425 }
426 }
427 else if (dragging && dragItem && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
428 {
429 wxClientDC dc(handlerDialog);
430 childHandler->OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, selectionHandle);
431 childHandler->OnDragContinue(TRUE, x, y, keys, dc, selectionHandle);
432 oldDragX = x; oldDragY = y;
433 }
434 else if (event.LeftUp() && dragItem && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
435 {
436 wxClientDC dc(handlerDialog);
437 dragMode = wxDRAG_MODE_NONE;
438 checkTolerance = TRUE;
439
440 childHandler->OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, selectionHandle);
441 childHandler->OnDragEnd(x, y, keys, dc, selectionHandle);
442
443 dragItem = NULL;
444 dragType = wxDRAG_TYPE_NONE;
445
446 if (m_mouseCaptured)
447 {
448 handlerDialog->ReleaseMouse();
449 m_mouseCaptured = FALSE;
450 }
451 }
452 else if (dragging && dragItem && dragMode == wxDRAG_MODE_START_RIGHT)
453 {
454 wxClientDC dc(handlerDialog);
455 dragMode = wxDRAG_MODE_CONTINUE_RIGHT;
456 childHandler->OnDragBegin(x, y, keys, dc, selectionHandle);
457 oldDragX = x; oldDragY = y;
458
459 if (!m_mouseCaptured)
460 {
461 handlerDialog->CaptureMouse();
462 m_mouseCaptured = TRUE;
463 }
464 }
465 else if (dragging && dragItem && dragMode == wxDRAG_MODE_CONTINUE_RIGHT)
466 {
467 oldDragX = x; oldDragY = y;
468 }
469 else if (event.RightUp() && dragItem && dragMode == wxDRAG_MODE_CONTINUE_RIGHT)
470 {
471 dragMode = wxDRAG_MODE_NONE;
472 checkTolerance = TRUE;
473 dragItem = NULL;
474 dragType = wxDRAG_TYPE_NONE;
475
476 if (m_mouseCaptured)
477 {
478 handlerDialog->ReleaseMouse();
479 m_mouseCaptured = FALSE;
480 }
481 }
482 else if (event.IsButton())
483 {
484 checkTolerance = TRUE;
485
486 if (event.LeftDown())
487 {
488 dragItem = item;
489 dragMode = wxDRAG_MODE_START_LEFT;
490 firstDragX = x;
491 firstDragY = y;
492 dragType = selectionHandle;
493
494 if (!m_mouseCaptured)
495 {
496 handlerDialog->CaptureMouse();
497 m_mouseCaptured = TRUE;
498 }
499 }
500 else if (event.RightDown())
501 {
502 dragItem = item;
503 dragMode = wxDRAG_MODE_START_RIGHT;
504 firstDragX = x;
505 firstDragY = y;
506 dragType = selectionHandle;
507
508 if (!m_mouseCaptured)
509 {
510 handlerDialog->CaptureMouse();
511 m_mouseCaptured = TRUE;
512 }
513 }
514 else if (event.LeftUp())
515 {
516 if (dragItem)
517 childHandler->OnLeftClick(x, y, keys);
518 else
519 OnLeftClick(x, y, keys);
520
521 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
522
523 if (m_mouseCaptured)
524 {
525 handlerDialog->ReleaseMouse();
526 m_mouseCaptured = FALSE;
527 }
528 }
529 else if (event.RightUp())
530 {
531 if (dragItem)
532 childHandler->OnRightClick(x, y, keys);
533 else
534 OnRightClick(x, y, keys);
535
536 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
537
538 if (m_mouseCaptured)
539 {
540 handlerDialog->ReleaseMouse();
541 m_mouseCaptured = FALSE;
542 }
543 }
544 }
545 }
546
547 // Calls DrawSelectionHandles for all items if
548 // edit mode is on.
549 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC& dc)
550 {
551 if (!GetEvtHandlerEnabled())
552 return;
553
554 dc.BeginDrawing();
555
556 wxNode *node = handlerDialog->GetChildren()->First();
557 while (node)
558 {
559 wxWindow *win = (wxWindow *)node->Data();
560 if (win->IsKindOf(CLASSINFO(wxControl)))
561 {
562 wxControl *item = (wxControl *)win;
563 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
564
565 // Don't draw handles for an item that's being moved: it'll
566 // smear.
567 if (childHandler->IsSelected() && (item != dragItem))
568 childHandler->DrawSelectionHandles(dc);
569 }
570 node = node->Next();
571 }
572 dc.EndDrawing();
573 }
574
575 /*
576 * Event handler for controls
577 */
578
579 int wxResourceEditorControlHandler::dragOffsetX = 0;
580 int wxResourceEditorControlHandler::dragOffsetY = 0;
581
582 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl *control,
583 wxEvtHandler *oldHandler)
584 {
585 handlerControl = control;
586 handlerOldHandler = oldHandler;
587
588 handleSize = 6;
589 handleMargin = 1;
590 isSelected = FALSE;
591 dragOffsetX = 0;
592 dragOffsetY = 0;
593 // m_treeItem = 0;
594 }
595
596 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
597 {
598 }
599
600 /*
601 * Manipulation and drawing of items in Edit Mode
602 */
603
604 void wxResourceEditorControlHandler::SelectItem(bool select)
605 {
606 isSelected = select;
607 }
608
609 // Returns TRUE or FALSE
610 bool wxResourceEditorControlHandler::HitTest(int x, int y)
611 {
612 int xpos, ypos, width, height;
613 handlerControl->GetPosition(&xpos, &ypos);
614 handlerControl->GetSize(&width, &height);
615
616 return ((x >= xpos) && (x <= (xpos + width)) && (y >= ypos) && (y <= (ypos + height)));
617 }
618
619 // Calculate position of the 8 handles
620 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx, int *hy)
621 {
622 int xpos, ypos, width, height;
623 handlerControl->GetPosition(&xpos, &ypos);
624 handlerControl->GetSize(&width, &height);
625 int middleX = (xpos + (width/2));
626 int middleY = (ypos + (height/2));
627
628 // Start from top middle, clockwise.
629 /*
630 7 0 1
631
632 6 2
633
634 5 4 3
635 */
636
637 hx[0] = (int)(middleX - (handleSize/2));
638 hy[0] = ypos - handleSize - handleMargin;
639
640 hx[1] = xpos + width + handleMargin;
641 hy[1] = ypos - handleSize - handleMargin;
642
643 hx[2] = xpos + width + handleMargin;
644 hy[2] = (int)(middleY - (handleSize/2));
645
646 hx[3] = xpos + width + handleMargin;
647 hy[3] = ypos + height + handleMargin;
648
649 hx[4] = (int)(middleX - (handleSize/2));
650 hy[4] = ypos + height + handleMargin;
651
652 hx[5] = xpos - handleSize - handleMargin;
653 hy[5] = ypos + height + handleMargin;
654
655 hx[6] = xpos - handleSize - handleMargin;
656 hy[6] = (int)(middleY - (handleSize/2));
657
658 hx[7] = xpos - handleSize - handleMargin;
659 hy[7] = ypos - handleSize - handleMargin;
660 }
661
662 // Returns 0 (no hit), 1 - 8 for which selection handle
663 // (clockwise from top middle)
664 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x, int y)
665 {
666 // Handle positions
667 int hx[8];
668 int hy[8];
669 CalcSelectionHandles(hx, hy);
670
671 int i;
672 for (i = 0; i < 8; i++)
673 {
674 if ((x >= hx[i]) && (x <= (hx[i] + handleSize)) && (y >= hy[i]) && (y <= (hy[i] + handleSize)))
675 return (i + 1);
676 }
677 return 0;
678 }
679
680 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC& dc, bool WXUNUSED(erase))
681 {
682 dc.SetOptimization(FALSE);
683
684 dc.SetLogicalFunction(wxCOPY);
685 dc.SetPen(wxBLACK_PEN);
686 dc.SetBrush(wxBLACK_BRUSH);
687
688 dc.SetOptimization(TRUE);
689
690 // Handle positions
691 int hx[8];
692 int hy[8];
693 CalcSelectionHandles(hx, hy);
694
695 int i;
696 for (i = 0; i < 8; i++)
697 {
698 dc.DrawRectangle(hx[i], hy[i], handleSize, handleSize);
699 }
700 }
701
702 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC& dc, int x, int y, int w, int h)
703 {
704 dc.DrawRectangle(x, y, w, h);
705 }
706
707 // If selectionHandle is zero, not dragging the selection handle.
708 void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
709 {
710 int xpos, ypos, width, height;
711 handlerControl->GetPosition(&xpos, &ypos);
712 handlerControl->GetSize(&width, &height);
713
714 dc.BeginDrawing();
715
716 // dc.DestroyClippingRegion();
717
718 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
719 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
720
721 // Erase selection handles
722 // DrawSelectionHandles(dc, TRUE);
723
724 dc.SetOptimization(FALSE);
725
726 dc.SetLogicalFunction(wxXOR);
727
728 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
729 dc.SetPen(pen);
730 dc.SetBrush(wxTRANSPARENT_BRUSH);
731
732 dc.SetOptimization(TRUE);
733
734 if (selectionHandle > 0)
735 {
736 panel->Refresh();
737
738 DrawBoundingBox(dc, xpos, ypos, width, height);
739 }
740 else
741 {
742 panel->Refresh();
743
744 dragOffsetX = (x - xpos);
745 dragOffsetY = (y - ypos);
746
747 DrawBoundingBox(dc, xpos, ypos, width, height);
748
749 // Also draw bounding boxes for other selected items
750 wxNode *node = panel->GetChildren()->First();
751 while (node)
752 {
753 wxWindow *win = (wxWindow *)node->Data();
754 if (win->IsKindOf(CLASSINFO(wxControl)))
755 {
756 wxControl *item = (wxControl *)win;
757 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
758 if ((item != handlerControl) && handler->IsSelected())
759 {
760 int x1, y1, w1, h1;
761 item->GetPosition(&x1, &y1);
762 item->GetSize(&w1, &h1);
763 handler->DrawBoundingBox(dc, x1, y1, w1, h1);
764 }
765 }
766 node = node->Next();
767 }
768 }
769 dc.EndDrawing();
770 }
771
772 void wxResourceEditorControlHandler::OnDragContinue(bool paintIt, int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
773 {
774 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
775 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
776
777 int xpos, ypos, width, height;
778 handlerControl->GetPosition(&xpos, &ypos);
779 handlerControl->GetSize(&width, &height);
780
781 if (selectionHandle > 0)
782 {
783 /*
784 8 1 2
785
786 7 3
787
788 6 5 4
789 */
790
791 int x1, y1, width1, height1;
792
793 switch (selectionHandle)
794 {
795 case 1:
796 x1 = xpos;
797 y1 = y;
798 width1 = width;
799 height1 = (ypos + height) - y;
800 break;
801 case 5:
802 x1 = xpos;
803 y1 = ypos;
804 width1 = width;
805 height1 = (y - ypos);
806 break;
807 case 3:
808 x1 = xpos;
809 y1 = ypos;
810 width1 = (x - xpos);
811 height1 = height;
812 break;
813 case 7:
814 x1 = x;
815 y1 = ypos;
816 width1 = (xpos + width) - x;
817 height1 = height;
818 break;
819 case 2:
820 x1 = xpos;
821 y1 = y;
822 width1 = (x - xpos);
823 height1 = (ypos + height) - y;
824 break;
825 case 4:
826 x1 = xpos;
827 y1 = ypos;
828 width1 = (x - xpos);
829 height1 = (y - ypos);
830 break;
831 case 6:
832 x1 = x;
833 y1 = ypos;
834 width1 = (xpos + width) - x;
835 height1 = y - ypos;
836 break;
837 case 8:
838 x1 = x;
839 y1 = y;
840 width1 = (xpos + width) - x;
841 height1 = (ypos + height) - y;
842 break;
843 }
844 dc.BeginDrawing();
845
846 dc.SetLogicalFunction(wxXOR);
847 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
848 dc.SetPen(pen);
849 dc.SetBrush(wxTRANSPARENT_BRUSH);
850
851 DrawBoundingBox(dc, x1, y1, width1, height1);
852
853 dc.EndDrawing();
854 }
855 else
856 {
857 dc.BeginDrawing();
858 dc.SetLogicalFunction(wxXOR);
859 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
860 dc.SetPen(pen);
861 dc.SetBrush(wxTRANSPARENT_BRUSH);
862
863 DrawBoundingBox(dc, (int)(x - dragOffsetX), (int)(y - dragOffsetY), width, height);
864
865 // Also draw bounding boxes for other selected items
866 wxNode *node = panel->GetChildren()->First();
867 while (node)
868 {
869 wxWindow *win = (wxWindow *)node->Data();
870 if (win->IsKindOf(CLASSINFO(wxControl)))
871 {
872 wxControl *item = (wxControl *)win;
873 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
874 if ((item != handlerControl) && handler->IsSelected())
875 {
876 int x1, y1, w1, h1;
877 item->GetPosition(&x1, &y1);
878 item->GetSize(&w1, &h1);
879 int x2 = (int)(x1 + (x - dragOffsetX) - xpos);
880 int y2 = (int)(y1 + (y - dragOffsetY) - ypos);
881 handler->DrawBoundingBox(dc, x2, y2, w1, h1);
882 }
883 }
884 node = node->Next();
885 }
886 dc.EndDrawing();
887 }
888 }
889
890 void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
891 {
892 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
893 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
894
895 dc.BeginDrawing();
896
897 int xpos, ypos, width, height;
898 handlerControl->GetPosition(&xpos, &ypos);
899 handlerControl->GetSize(&width, &height);
900
901 if (selectionHandle > 0)
902 {
903 int x1, y1, width1, height1;
904
905 switch (selectionHandle)
906 {
907 case 1:
908 x1 = xpos;
909 y1 = y;
910 width1 = width;
911 height1 = (ypos + height) - y;
912 break;
913 case 5:
914 x1 = xpos;
915 y1 = ypos;
916 width1 = width;
917 height1 = (y - ypos);
918 break;
919 case 3:
920 x1 = xpos;
921 y1 = ypos;
922 width1 = (x - xpos);
923 height1 = height;
924 break;
925 case 7:
926 x1 = x;
927 y1 = ypos;
928 width1 = (xpos + width) - x;
929 height1 = height;
930 break;
931 case 2:
932 x1 = xpos;
933 y1 = y;
934 width1 = (x - xpos);
935 height1 = (ypos + height) - y;
936 break;
937 case 4:
938 x1 = xpos;
939 y1 = ypos;
940 width1 = (x - xpos);
941 height1 = (y - ypos);
942 break;
943 case 6:
944 x1 = x;
945 y1 = ypos;
946 width1 = (xpos + width) - x;
947 height1 = y - ypos;
948 break;
949 case 8:
950 x1 = x;
951 y1 = y;
952 width1 = (xpos + width) - x;
953 height1 = (ypos + height) - y;
954 break;
955 }
956 handlerControl->SetSize(x1, y1, width1, height1);
957 }
958 else
959 {
960 handlerControl->Move((int)(x - dragOffsetX), (int)(y - dragOffsetY));
961 OldOnMove((int)(x - dragOffsetX), (int)(y - dragOffsetY));
962
963 // Also move other selected items
964 wxNode *node = panel->GetChildren()->First();
965 while (node)
966 {
967 wxWindow *win = (wxWindow *)node->Data();
968 if (win->IsKindOf(CLASSINFO(wxControl)))
969 {
970 wxControl *item = (wxControl *)win;
971 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
972 if ((item != handlerControl) && handler->IsSelected())
973 {
974 int x1, y1;
975 item->GetPosition(&x1, &y1);
976 int x2 = (int)(x1 + (x - dragOffsetX) - xpos);
977 int y2 = (int)(y1 + (y - dragOffsetY) - ypos);
978 item->Move(x2, y2);
979 ((wxResourceEditorControlHandler *)item->GetEventHandler())->OldOnMove(x2, y2);
980 ((wxResourceEditorControlHandler *)item->GetEventHandler())->DrawSelectionHandles(dc);
981 }
982 }
983 node = node->Next();
984 }
985 }
986 dc.SetOptimization(FALSE);
987
988 dc.SetLogicalFunction(wxCOPY);
989 dc.SetPen(wxBLACK_PEN);
990 dc.SetBrush(wxBLACK_BRUSH);
991
992 dc.SetOptimization(TRUE);
993
994 // Force it to repaint the selection handles (if any)
995 // since the panel thinks we're still within a drag and
996 // won't paint the handles.
997 if (IsSelected())
998 DrawSelectionHandles(dc);
999
1000 dc.EndDrawing();
1001
1002 panel->Refresh();
1003 }
1004
1005 // These functions call OnItemEvent, OnItemMove and OnItemSize
1006 // by default.
1007 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent& event)
1008 {
1009 /*
1010 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1011 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1012 return;
1013 */
1014 wxWindow *panel = handlerControl->GetParent();
1015 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1016 return;
1017 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1018 if ( !panelHandler->GetEvtHandlerEnabled() )
1019 {
1020 event.Skip();
1021 return;
1022 }
1023
1024 panelHandler->OnItemEvent(handlerControl, event);
1025 }
1026
1027 void wxResourceEditorControlHandler::OldOnMove(int x, int y)
1028 {
1029 wxWindow *panel = handlerControl->GetParent();
1030 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1031 return;
1032
1033 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1034 panelHandler->OnItemMove(handlerControl, x, y);
1035 }
1036
1037 void wxResourceEditorControlHandler::OldOnSize(int w, int h)
1038 {
1039 wxWindow *panel = handlerControl->GetParent();
1040 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1041 return;
1042
1043 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1044 panelHandler->OnItemSize(handlerControl, w, h);
1045 }
1046
1047 void wxResourceEditorControlHandler::OnSelect(bool select)
1048 {
1049 wxWindow *panel = handlerControl->GetParent();
1050 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1051 return;
1052
1053 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1054 panelHandler->OnItemSelect(handlerControl, select);
1055 }
1056
1057 void wxResourceEditorControlHandler::OnLeftClick(int x, int y, int keys)
1058 {
1059 wxWindow *panel = handlerControl->GetParent();
1060 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1061 return;
1062
1063 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1064 panelHandler->OnItemLeftClick(handlerControl, x, y, keys);
1065 }
1066
1067 void wxResourceEditorControlHandler::OnRightClick(int x, int y, int keys)
1068 {
1069 wxWindow *panel = handlerControl->GetParent();
1070 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1071 return;
1072
1073 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1074 panelHandler->OnItemRightClick(handlerControl, x, y, keys);
1075 }
1076
1077