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