]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/dlghndlr.cpp
cfa37ec97e1c64a8e02d4e3526bf66a8482279cf
[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 ProcessItemEvent(item, event, dragType);
375 }
376
377 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEvent& event, int selectionHandle)
378 {
379 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
380
381 long x, y;
382 event.Position(&x, &y);
383 int keys = 0;
384 if (event.ShiftDown()) keys = keys | wxKEY_SHIFT;
385 if (event.ControlDown()) keys = keys | wxKEY_CTRL;
386 bool dragging = event.Dragging();
387 if (dragging)
388 {
389 int dx = (int)abs((x - firstDragX));
390 int dy = (int)abs((y - firstDragY));
391 if (checkTolerance && (dx <= dragTolerance) && (dy <= dragTolerance))
392 {
393 return;
394 }
395 else
396 // If we've ignored the tolerance once, then ALWAYS ignore
397 // tolerance in this drag, even if we come back within
398 // the tolerance range.
399 {
400 checkTolerance = FALSE;
401 }
402 }
403 if (event.LeftDClick())
404 {
405 if (m_mouseCaptured)
406 {
407 handlerDialog->ReleaseMouse();
408 m_mouseCaptured = FALSE;
409 }
410
411 wxResourceManager::GetCurrentResourceManager()->EditWindow(item);
412 }
413 else if (dragging && dragItem && dragMode == wxDRAG_MODE_START_LEFT)
414 {
415 dragMode = wxDRAG_MODE_CONTINUE_LEFT;
416 wxClientDC dc(handlerDialog);
417 childHandler->OnDragBegin(x, y, keys, dc, selectionHandle);
418 oldDragX = x; oldDragY = y;
419 if (!m_mouseCaptured)
420 {
421 handlerDialog->CaptureMouse();
422 m_mouseCaptured = TRUE;
423 }
424 }
425 else if (dragging && dragItem && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
426 {
427 wxClientDC dc(handlerDialog);
428 childHandler->OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, selectionHandle);
429 childHandler->OnDragContinue(TRUE, x, y, keys, dc, selectionHandle);
430 oldDragX = x; oldDragY = y;
431 }
432 else if (event.LeftUp() && dragItem && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
433 {
434 wxClientDC dc(handlerDialog);
435 dragMode = wxDRAG_MODE_NONE;
436 checkTolerance = TRUE;
437
438 childHandler->OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, selectionHandle);
439 childHandler->OnDragEnd(x, y, keys, dc, selectionHandle);
440
441 dragItem = NULL;
442 dragType = wxDRAG_TYPE_NONE;
443
444 if (m_mouseCaptured)
445 {
446 handlerDialog->ReleaseMouse();
447 m_mouseCaptured = FALSE;
448 }
449 }
450 else if (dragging && dragItem && dragMode == wxDRAG_MODE_START_RIGHT)
451 {
452 wxClientDC dc(handlerDialog);
453 dragMode = wxDRAG_MODE_CONTINUE_RIGHT;
454 childHandler->OnDragBegin(x, y, keys, dc, selectionHandle);
455 oldDragX = x; oldDragY = y;
456
457 if (!m_mouseCaptured)
458 {
459 handlerDialog->CaptureMouse();
460 m_mouseCaptured = TRUE;
461 }
462 }
463 else if (dragging && dragItem && dragMode == wxDRAG_MODE_CONTINUE_RIGHT)
464 {
465 oldDragX = x; oldDragY = y;
466 }
467 // Obsolete; no longer try to right-drag
468 else if (event.RightUp() && dragItem && dragMode == wxDRAG_MODE_CONTINUE_RIGHT)
469 {
470 dragMode = wxDRAG_MODE_NONE;
471 checkTolerance = TRUE;
472 dragItem = NULL;
473 dragType = wxDRAG_TYPE_NONE;
474
475 if (m_mouseCaptured)
476 {
477 handlerDialog->ReleaseMouse();
478 m_mouseCaptured = FALSE;
479 }
480 }
481 else if (event.IsButton())
482 {
483 checkTolerance = TRUE;
484
485 if (event.LeftDown())
486 {
487 dragItem = item;
488 dragMode = wxDRAG_MODE_START_LEFT;
489 firstDragX = x;
490 firstDragY = y;
491 dragType = selectionHandle;
492
493 if (!m_mouseCaptured)
494 {
495 handlerDialog->CaptureMouse();
496 m_mouseCaptured = TRUE;
497 }
498 }
499 else if (event.RightDown())
500 {
501 if (m_mouseCaptured)
502 {
503 handlerDialog->ReleaseMouse();
504 m_mouseCaptured = FALSE;
505 }
506
507 if (item)
508 childHandler->OnRightClick(x, y, keys);
509 else
510 OnRightClick(x, y, keys);
511
512 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
513
514 /*
515 dragItem = item;
516 dragMode = wxDRAG_MODE_START_RIGHT;
517 firstDragX = x;
518 firstDragY = y;
519 dragType = selectionHandle;
520
521 if (!m_mouseCaptured)
522 {
523 handlerDialog->CaptureMouse();
524 m_mouseCaptured = TRUE;
525 }
526 */
527 }
528 else if (event.LeftUp())
529 {
530 if (dragItem)
531 childHandler->OnLeftClick(x, y, keys);
532 else
533 OnLeftClick(x, y, keys);
534
535 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
536
537 if (m_mouseCaptured)
538 {
539 handlerDialog->ReleaseMouse();
540 m_mouseCaptured = FALSE;
541 }
542 }
543 else if (event.RightUp())
544 {
545 /*
546 if (dragItem)
547 childHandler->OnRightClick(x, y, keys);
548 else
549 OnRightClick(x, y, keys);
550
551 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
552
553 if (m_mouseCaptured)
554 {
555 handlerDialog->ReleaseMouse();
556 m_mouseCaptured = FALSE;
557 }
558 */
559 }
560 }
561 }
562
563 // Calls DrawSelectionHandles for all items if
564 // edit mode is on.
565 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC& dc)
566 {
567 if (!GetEvtHandlerEnabled())
568 return;
569
570 dc.BeginDrawing();
571
572 wxNode *node = handlerDialog->GetChildren()->First();
573 while (node)
574 {
575 wxWindow *win = (wxWindow *)node->Data();
576 if (win->IsKindOf(CLASSINFO(wxControl)))
577 {
578 wxControl *item = (wxControl *)win;
579 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
580
581 // Don't draw handles for an item that's being moved: it'll
582 // smear.
583 if (childHandler->IsSelected() && (item != dragItem))
584 childHandler->DrawSelectionHandles(dc);
585 }
586 node = node->Next();
587 }
588 dc.EndDrawing();
589 }
590
591 /*
592 * Event handler for controls
593 */
594
595 int wxResourceEditorControlHandler::dragOffsetX = 0;
596 int wxResourceEditorControlHandler::dragOffsetY = 0;
597
598 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl *control,
599 wxEvtHandler *oldHandler)
600 {
601 handlerControl = control;
602 handlerOldHandler = oldHandler;
603
604 handleSize = 6;
605 handleMargin = 1;
606 isSelected = FALSE;
607 dragOffsetX = 0;
608 dragOffsetY = 0;
609 // m_treeItem = 0;
610 }
611
612 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
613 {
614 }
615
616 /*
617 * Manipulation and drawing of items in Edit Mode
618 */
619
620 void wxResourceEditorControlHandler::SelectItem(bool select)
621 {
622 isSelected = select;
623 }
624
625 // Returns TRUE or FALSE
626 bool wxResourceEditorControlHandler::HitTest(int x, int y)
627 {
628 int xpos, ypos, width, height;
629 handlerControl->GetPosition(&xpos, &ypos);
630 handlerControl->GetSize(&width, &height);
631
632 return ((x >= xpos) && (x <= (xpos + width)) && (y >= ypos) && (y <= (ypos + height)));
633 }
634
635 // Calculate position of the 8 handles
636 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx, int *hy)
637 {
638 int xpos, ypos, width, height;
639 handlerControl->GetPosition(&xpos, &ypos);
640 handlerControl->GetSize(&width, &height);
641 int middleX = (xpos + (width/2));
642 int middleY = (ypos + (height/2));
643
644 // Start from top middle, clockwise.
645 /*
646 7 0 1
647
648 6 2
649
650 5 4 3
651 */
652
653 hx[0] = (int)(middleX - (handleSize/2));
654 hy[0] = ypos - handleSize - handleMargin;
655
656 hx[1] = xpos + width + handleMargin;
657 hy[1] = ypos - handleSize - handleMargin;
658
659 hx[2] = xpos + width + handleMargin;
660 hy[2] = (int)(middleY - (handleSize/2));
661
662 hx[3] = xpos + width + handleMargin;
663 hy[3] = ypos + height + handleMargin;
664
665 hx[4] = (int)(middleX - (handleSize/2));
666 hy[4] = ypos + height + handleMargin;
667
668 hx[5] = xpos - handleSize - handleMargin;
669 hy[5] = ypos + height + handleMargin;
670
671 hx[6] = xpos - handleSize - handleMargin;
672 hy[6] = (int)(middleY - (handleSize/2));
673
674 hx[7] = xpos - handleSize - handleMargin;
675 hy[7] = ypos - handleSize - handleMargin;
676 }
677
678 // Returns 0 (no hit), 1 - 8 for which selection handle
679 // (clockwise from top middle)
680 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x, int y)
681 {
682 // Handle positions
683 int hx[8];
684 int hy[8];
685 CalcSelectionHandles(hx, hy);
686
687 int i;
688 for (i = 0; i < 8; i++)
689 {
690 if ((x >= hx[i]) && (x <= (hx[i] + handleSize)) && (y >= hy[i]) && (y <= (hy[i] + handleSize)))
691 return (i + 1);
692 }
693 return 0;
694 }
695
696 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC& dc, bool WXUNUSED(erase))
697 {
698 dc.SetOptimization(FALSE);
699
700 dc.SetLogicalFunction(wxCOPY);
701 dc.SetPen(wxBLACK_PEN);
702 dc.SetBrush(wxBLACK_BRUSH);
703
704 dc.SetOptimization(TRUE);
705
706 // Handle positions
707 int hx[8];
708 int hy[8];
709 CalcSelectionHandles(hx, hy);
710
711 int i;
712 for (i = 0; i < 8; i++)
713 {
714 dc.DrawRectangle(hx[i], hy[i], handleSize, handleSize);
715 }
716 }
717
718 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC& dc, int x, int y, int w, int h)
719 {
720 dc.DrawRectangle(x, y, w, h);
721 }
722
723 // If selectionHandle is zero, not dragging the selection handle.
724 void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
725 {
726 int xpos, ypos, width, height;
727 handlerControl->GetPosition(&xpos, &ypos);
728 handlerControl->GetSize(&width, &height);
729
730 dc.BeginDrawing();
731
732 // dc.DestroyClippingRegion();
733
734 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
735
736 // Erase selection handles
737 // DrawSelectionHandles(dc, TRUE);
738
739 dc.SetOptimization(FALSE);
740
741 dc.SetLogicalFunction(wxXOR);
742
743 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
744 dc.SetPen(pen);
745 dc.SetBrush(wxTRANSPARENT_BRUSH);
746
747 dc.SetOptimization(TRUE);
748
749 if (selectionHandle > 0)
750 {
751 panel->Refresh();
752
753 DrawBoundingBox(dc, xpos, ypos, width, height);
754 }
755 else
756 {
757 panel->Refresh();
758
759 dragOffsetX = (x - xpos);
760 dragOffsetY = (y - ypos);
761
762 DrawBoundingBox(dc, xpos, ypos, width, height);
763
764 // Also draw bounding boxes for other selected items
765 wxNode *node = panel->GetChildren()->First();
766 while (node)
767 {
768 wxWindow *win = (wxWindow *)node->Data();
769 if (win->IsKindOf(CLASSINFO(wxControl)))
770 {
771 wxControl *item = (wxControl *)win;
772 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
773 if ((item != handlerControl) && handler->IsSelected())
774 {
775 int x1, y1, w1, h1;
776 item->GetPosition(&x1, &y1);
777 item->GetSize(&w1, &h1);
778 handler->DrawBoundingBox(dc, x1, y1, w1, h1);
779 }
780 }
781 node = node->Next();
782 }
783 }
784 dc.EndDrawing();
785 }
786
787 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt), int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
788 {
789 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
790 int xpos, ypos, width, height;
791 handlerControl->GetPosition(&xpos, &ypos);
792 handlerControl->GetSize(&width, &height);
793
794 if (selectionHandle > 0)
795 {
796 /*
797 8 1 2
798
799 7 3
800
801 6 5 4
802 */
803
804 int x1, y1, width1, height1;
805
806 switch (selectionHandle)
807 {
808 case 1:
809 x1 = xpos;
810 y1 = y;
811 width1 = width;
812 height1 = (ypos + height) - y;
813 break;
814 case 5:
815 x1 = xpos;
816 y1 = ypos;
817 width1 = width;
818 height1 = (y - ypos);
819 break;
820 case 3:
821 x1 = xpos;
822 y1 = ypos;
823 width1 = (x - xpos);
824 height1 = height;
825 break;
826 case 7:
827 x1 = x;
828 y1 = ypos;
829 width1 = (xpos + width) - x;
830 height1 = height;
831 break;
832 case 2:
833 x1 = xpos;
834 y1 = y;
835 width1 = (x - xpos);
836 height1 = (ypos + height) - y;
837 break;
838 case 4:
839 x1 = xpos;
840 y1 = ypos;
841 width1 = (x - xpos);
842 height1 = (y - ypos);
843 break;
844 case 6:
845 x1 = x;
846 y1 = ypos;
847 width1 = (xpos + width) - x;
848 height1 = y - ypos;
849 break;
850 case 8:
851 x1 = x;
852 y1 = y;
853 width1 = (xpos + width) - x;
854 height1 = (ypos + height) - y;
855 break;
856 }
857 dc.BeginDrawing();
858
859 dc.SetLogicalFunction(wxXOR);
860 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
861 dc.SetPen(pen);
862 dc.SetBrush(wxTRANSPARENT_BRUSH);
863
864 DrawBoundingBox(dc, x1, y1, width1, height1);
865
866 dc.EndDrawing();
867 }
868 else
869 {
870 dc.BeginDrawing();
871 dc.SetLogicalFunction(wxXOR);
872 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
873 dc.SetPen(pen);
874 dc.SetBrush(wxTRANSPARENT_BRUSH);
875
876 DrawBoundingBox(dc, (int)(x - dragOffsetX), (int)(y - dragOffsetY), width, height);
877
878 // Also draw bounding boxes for other selected items
879 wxNode *node = panel->GetChildren()->First();
880 while (node)
881 {
882 wxWindow *win = (wxWindow *)node->Data();
883 if (win->IsKindOf(CLASSINFO(wxControl)))
884 {
885 wxControl *item = (wxControl *)win;
886 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
887 if ((item != handlerControl) && handler->IsSelected())
888 {
889 int x1, y1, w1, h1;
890 item->GetPosition(&x1, &y1);
891 item->GetSize(&w1, &h1);
892 int x2 = (int)(x1 + (x - dragOffsetX) - xpos);
893 int y2 = (int)(y1 + (y - dragOffsetY) - ypos);
894 handler->DrawBoundingBox(dc, x2, y2, w1, h1);
895 }
896 }
897 node = node->Next();
898 }
899 dc.EndDrawing();
900 }
901 }
902
903 void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
904 {
905 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
906
907 dc.BeginDrawing();
908
909 int xpos, ypos, width, height;
910 handlerControl->GetPosition(&xpos, &ypos);
911 handlerControl->GetSize(&width, &height);
912
913 if (selectionHandle > 0)
914 {
915 int x1, y1, width1, height1;
916
917 switch (selectionHandle)
918 {
919 case 1:
920 x1 = xpos;
921 y1 = y;
922 width1 = width;
923 height1 = (ypos + height) - y;
924 break;
925 case 5:
926 x1 = xpos;
927 y1 = ypos;
928 width1 = width;
929 height1 = (y - ypos);
930 break;
931 case 3:
932 x1 = xpos;
933 y1 = ypos;
934 width1 = (x - xpos);
935 height1 = height;
936 break;
937 case 7:
938 x1 = x;
939 y1 = ypos;
940 width1 = (xpos + width) - x;
941 height1 = height;
942 break;
943 case 2:
944 x1 = xpos;
945 y1 = y;
946 width1 = (x - xpos);
947 height1 = (ypos + height) - y;
948 break;
949 case 4:
950 x1 = xpos;
951 y1 = ypos;
952 width1 = (x - xpos);
953 height1 = (y - ypos);
954 break;
955 case 6:
956 x1 = x;
957 y1 = ypos;
958 width1 = (xpos + width) - x;
959 height1 = y - ypos;
960 break;
961 case 8:
962 x1 = x;
963 y1 = y;
964 width1 = (xpos + width) - x;
965 height1 = (ypos + height) - y;
966 break;
967 }
968 handlerControl->SetSize(x1, y1, width1, height1);
969 }
970 else
971 {
972 handlerControl->Move((int)(x - dragOffsetX), (int)(y - dragOffsetY));
973 OldOnMove((int)(x - dragOffsetX), (int)(y - dragOffsetY));
974
975 // Also move other selected items
976 wxNode *node = panel->GetChildren()->First();
977 while (node)
978 {
979 wxWindow *win = (wxWindow *)node->Data();
980 if (win->IsKindOf(CLASSINFO(wxControl)))
981 {
982 wxControl *item = (wxControl *)win;
983 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
984 if ((item != handlerControl) && handler->IsSelected())
985 {
986 int x1, y1;
987 item->GetPosition(&x1, &y1);
988 int x2 = (int)(x1 + (x - dragOffsetX) - xpos);
989 int y2 = (int)(y1 + (y - dragOffsetY) - ypos);
990 item->Move(x2, y2);
991 ((wxResourceEditorControlHandler *)item->GetEventHandler())->OldOnMove(x2, y2);
992 ((wxResourceEditorControlHandler *)item->GetEventHandler())->DrawSelectionHandles(dc);
993 }
994 }
995 node = node->Next();
996 }
997 }
998 dc.SetOptimization(FALSE);
999
1000 dc.SetLogicalFunction(wxCOPY);
1001 dc.SetPen(wxBLACK_PEN);
1002 dc.SetBrush(wxBLACK_BRUSH);
1003
1004 dc.SetOptimization(TRUE);
1005
1006 // Force it to repaint the selection handles (if any)
1007 // since the panel thinks we're still within a drag and
1008 // won't paint the handles.
1009 if (IsSelected())
1010 DrawSelectionHandles(dc);
1011
1012 dc.EndDrawing();
1013
1014 panel->Refresh();
1015 }
1016
1017 // These functions call OnItemEvent, OnItemMove and OnItemSize
1018 // by default.
1019 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent& event)
1020 {
1021 /*
1022 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1023 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1024 return;
1025 */
1026 wxWindow *panel = handlerControl->GetParent();
1027 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1028 return;
1029 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1030 if ( !panelHandler->GetEvtHandlerEnabled() )
1031 {
1032 event.Skip();
1033 return;
1034 }
1035
1036 panelHandler->OnItemEvent(handlerControl, event);
1037 }
1038
1039 void wxResourceEditorControlHandler::OldOnMove(int x, int y)
1040 {
1041 wxWindow *panel = handlerControl->GetParent();
1042 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1043 return;
1044
1045 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1046 panelHandler->OnItemMove(handlerControl, x, y);
1047 }
1048
1049 void wxResourceEditorControlHandler::OldOnSize(int w, int h)
1050 {
1051 wxWindow *panel = handlerControl->GetParent();
1052 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1053 return;
1054
1055 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1056 panelHandler->OnItemSize(handlerControl, w, h);
1057 }
1058
1059 void wxResourceEditorControlHandler::OnSelect(bool select)
1060 {
1061 wxWindow *panel = handlerControl->GetParent();
1062 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1063 return;
1064
1065 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1066 panelHandler->OnItemSelect(handlerControl, select);
1067 }
1068
1069 void wxResourceEditorControlHandler::OnLeftClick(int x, int y, int keys)
1070 {
1071 wxWindow *panel = handlerControl->GetParent();
1072 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1073 return;
1074
1075 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1076 panelHandler->OnItemLeftClick(handlerControl, x, y, keys);
1077 }
1078
1079 void wxResourceEditorControlHandler::OnRightClick(int x, int y, int keys)
1080 {
1081 wxWindow *panel = handlerControl->GetParent();
1082 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1083 return;
1084
1085 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1086 panelHandler->OnItemRightClick(handlerControl, x, y, keys);
1087 }
1088
1089