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