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