]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/dlghndlr.cpp
Added some anchor related methods to wxHtmlWindow as suggested on 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 #include "reseditr.h"
33 #include "winprop.h"
34 #include "dlghndlr.h"
35 #include "edlist.h"
36
37
38 IMPLEMENT_CLASS(wxResourceEditorDialogHandler, wxEvtHandler)
39 IMPLEMENT_CLASS(wxResourceEditorControlHandler, wxEvtHandler)
40
41 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler, wxEvtHandler)
42 EVT_PAINT(wxResourceEditorDialogHandler::OnPaint)
43 EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent)
44 EVT_SIZE(wxResourceEditorDialogHandler::OnSize)
45 EVT_MENU(OBJECT_MENU_EDIT, wxResourceEditorDialogHandler::OnObjectEdit)
46 EVT_MENU(OBJECT_MENU_DELETE, wxResourceEditorDialogHandler::OnObjectDelete)
47 END_EVENT_TABLE()
48
49 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler, wxEvtHandler)
50 EVT_MOUSE_EVENTS(wxResourceEditorControlHandler::OnMouseEvent)
51 END_EVENT_TABLE()
52
53 /*
54 * Dialog box event handler
55 */
56
57 wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel *dialog, wxItemResource *resource,
58 wxEvtHandler *oldHandler, wxResourceManager *manager)
59 {
60 handlerDialog = dialog;
61 handlerResource = resource;
62 handlerOldHandler = oldHandler;
63 resourceManager = manager;
64
65 dragMode = wxDRAG_MODE_NONE;
66 dragType = wxDRAG_TYPE_NONE;
67 dragItem = NULL;
68 firstDragX = 0;
69 firstDragY = 0;
70 oldDragX = 0;
71 oldDragY = 0;
72 dragTolerance = 3;
73 checkTolerance = TRUE;
74 m_mouseCaptured = FALSE;
75 // m_treeItem = 0;
76 }
77
78 wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
79 {
80 }
81
82 void wxResourceEditorDialogHandler::OnItemSelect(wxControl *item, bool select)
83 {
84 if (select)
85 resourceManager->AddSelection(item);
86 else
87 resourceManager->RemoveSelection(item);
88 }
89
90 void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& WXUNUSED(event))
91 {
92 wxPaintDC dc(handlerDialog);
93
94 PaintSelectionHandles(dc);
95 }
96
97 // Add event handlers for all children
98 void wxResourceEditorDialogHandler::AddChildHandlers(void)
99 {
100 wxNode *node = handlerDialog->GetChildren().First();
101 while ( node )
102 {
103 wxControl *child = (wxControl *)node->Data();
104 wxEvtHandler *childHandler = child->GetEventHandler();
105 if ( child->IsKindOf(CLASSINFO(wxControl)) && childHandler == child )
106 child->PushEventHandler(new wxResourceEditorControlHandler(child, childHandler));
107 node = node->Next();
108 }
109 }
110
111 void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
112 {
113 if (keys & wxKEY_CTRL)
114 {
115 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog);
116 return;
117 }
118
119 // Deselect all items if click on panel
120 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER)
121 {
122 int needsRefresh = 0;
123 wxNode *node = handlerDialog->GetChildren().First();
124 while (node)
125 {
126 wxControl *item = (wxControl *)node->Data();
127 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
128 if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected())
129 {
130 needsRefresh ++;
131 OnItemSelect(item, FALSE);
132 childHandler->SelectItem(FALSE);
133 }
134 node = node->Next();
135 }
136 if (needsRefresh > 0)
137 {
138 wxClientDC dc(handlerDialog);
139 dc.Clear();
140 handlerDialog->Refresh();
141 }
142 return;
143 }
144
145 // Round down to take account of dialog units
146 wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog);
147 if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
148 {
149 wxPoint pt = handlerDialog->ConvertPixelsToDialog(wxPoint(x, y));
150
151 // Convert back so we've rounded down
152 pt = handlerDialog->ConvertDialogToPixels(pt);
153 pt = handlerDialog->ConvertPixelsToDialog(pt);
154 pt = handlerDialog->ConvertDialogToPixels(pt);
155 x = pt.x;
156 y = pt.y;
157 }
158
159 switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
160 {
161 case RESED_BUTTON:
162 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxButton", x, y);
163 break;
164 case RESED_BMPBUTTON:
165 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxBitmapButton", x, y, TRUE);
166 break;
167 case RESED_STATICTEXT:
168 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticText", x, y);
169 break;
170 case RESED_STATICBMP:
171 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticBitmap", x, y, TRUE);
172 break;
173 case RESED_TEXTCTRL_SINGLE:
174 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxTextCtrl (single-line)", x, y);
175 break;
176 case RESED_TEXTCTRL_MULTIPLE:
177 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxTextCtrl (multi-line)", x, y);
178 break;
179 case RESED_CHOICE:
180 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxChoice", x, y);
181 break;
182 case RESED_COMBOBOX:
183 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxComboBox", x, y);
184 break;
185 case RESED_CHECKBOX:
186 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxCheckBox", x, y);
187 break;
188 case RESED_RADIOBOX:
189 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioBox", x, y);
190 break;
191 case RESED_RADIOBUTTON:
192 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioButton", x, y);
193 break;
194 case RESED_LISTBOX:
195 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxListBox", x, y);
196 break;
197 case RESED_SLIDER:
198 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxSlider", x, y);
199 break;
200 case RESED_GAUGE:
201 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxGauge", x, y);
202 break;
203 case RESED_STATICBOX:
204 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticBox", x, y);
205 break;
206 case RESED_SCROLLBAR:
207 resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxScrollBar", x, y);
208 break;
209 default:
210 break;
211 }
212
213 // Now switch pointer on.
214 if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER)
215 {
216 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
217 }
218 }
219
220 void wxResourceEditorDialogHandler::OnRightClick(int x, int y, int WXUNUSED(keys))
221 {
222 wxMenu *menu = resourceManager->GetPopupMenu();
223 menu->SetClientData((char *)handlerDialog);
224
225 wxString str("wxDialog : ");
226 str += handlerDialog->GetName();
227
228 menu->SetLabel(OBJECT_MENU_TITLE,str);
229
230 handlerDialog->PopupMenu(menu, x, y);
231 }
232
233 void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int WXUNUSED(x), int WXUNUSED(y), int keys)
234 {
235 if (keys & wxKEY_CTRL)
236 {
237 wxResourceManager::GetCurrentResourceManager()->EditWindow(item);
238 return;
239 }
240
241 /*
242 // If this is a wxStaticBox and the pointer isn't an arrow, chances
243 // are that we really meant to place an item on the panel.
244 // Fake this event.
245 if ((item->GetClassInfo() == CLASSINFO(wxStaticBox)) && resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
246 {
247 OnLeftClick(x, y, keys);
248 return;
249 }
250 */
251
252 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
253
254 if (childHandler->IsSelected())
255 {
256 childHandler->SelectItem(FALSE);
257 OnItemSelect(item, FALSE);
258
259 wxClientDC dc(handlerDialog);
260 dc.Clear();
261 handlerDialog->Refresh();
262 }
263 else
264 {
265 childHandler->SelectItem(TRUE);
266 OnItemSelect(item, TRUE);
267
268 // Deselect other items if shift is not pressed
269 int needsRefresh = 0;
270 if (!(keys & wxKEY_SHIFT))
271 {
272 wxNode *node = item->GetParent()->GetChildren().First();
273 while (node)
274 {
275 wxControl *child = (wxControl *)node->Data();
276 wxResourceEditorControlHandler *childHandler2 = (wxResourceEditorControlHandler *)child->GetEventHandler();
277 if (child->IsKindOf(CLASSINFO(wxControl)) && childHandler2->IsSelected() && child != item)
278 {
279 childHandler2->SelectItem(FALSE);
280 OnItemSelect(child, FALSE);
281 needsRefresh ++;
282 }
283 node = node->Next();
284 }
285 }
286
287 wxClientDC dc(handlerDialog);
288 childHandler->DrawSelectionHandles(dc);
289
290 if (needsRefresh > 0)
291 {
292 dc.Clear();
293 handlerDialog->Refresh();
294 }
295 }
296 }
297
298 void wxResourceEditorDialogHandler::OnItemRightClick(wxControl *item, int x, int y, int WXUNUSED(keys))
299 {
300 /*
301 if (keys & wxKEY_CTRL)
302 {
303 wxDebugMsg("Item %s, selected = %d\n", item->GetName(), item->IsSelected());
304 return;
305 }
306 */
307
308 wxMenu *menu = resourceManager->GetPopupMenu();
309 menu->SetClientData((char *)item);
310
311 wxWindow *win = (wxWindow *)item;
312
313 wxWindowPropertyInfo *info = resourceManager->CreatePropertyInfoForWindow(win);
314 if (info)
315 {
316 info->SetResource(resourceManager->FindResourceForWindow(win));
317 wxString str;
318 str = win->GetClassInfo()->GetClassName();
319 str += " : ";
320 if (win->GetName() != "")
321 str += win->GetName();
322
323 menu->SetLabel(OBJECT_MENU_TITLE,str);
324 }
325
326 handlerDialog->PopupMenu(menu, x, y);
327 }
328
329 // Under Windows 95, you can resize a panel interactively depending on
330 // window styles.
331 void wxResourceEditorDialogHandler::OnSize(wxSizeEvent& event)
332 {
333 // Update the associated resource
334 int w, h;
335 handlerDialog->GetClientSize(& w, & h);
336
337 wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog);
338 if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
339 {
340 wxSize sz = handlerDialog->ConvertPixelsToDialog(wxSize(w, h));
341 w = sz.x; h = sz.y;
342 }
343 resource->SetSize(resource->GetX(), resource->GetY(), w, h);
344 }
345
346 // An event outside any items: may be a drag event.
347 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event)
348 {
349 if (GetEvtHandlerEnabled())
350 {
351 // If we're dragging an item or selection handle,
352 // continue dragging.
353 if (dragMode != wxDRAG_MODE_NONE)
354 {
355 if (dragType != wxDRAG_TYPE_BOUNDING_BOX &&
356 dragItem != NULL)
357 {
358 ProcessItemEvent(dragItem, event, dragType);
359 return;
360 }
361 }
362
363 wxCoord x, y;
364 event.GetPosition(&x, &y);
365
366 // Find which selection handle we're on, if any
367 wxNode *node = handlerDialog->GetChildren().First();
368 while (node)
369 {
370 wxWindow *win = (wxWindow *)node->Data();
371 if (win->IsKindOf(CLASSINFO(wxControl)))
372 {
373 wxControl *item = (wxControl *)win;
374 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
375 int selHandle = childHandler->SelectionHandleHitTest(x, y);
376 if (selHandle > 0)
377 {
378 ProcessItemEvent(item, event, selHandle);
379 return;
380 }
381 }
382 node = node->Next();
383 }
384
385 // We're not on an item or selection handle.
386 // so... check for a left or right click event
387 // to send to the application.
388 int keys = 0;
389 if (event.ShiftDown()) keys = keys | wxKEY_SHIFT;
390 if (event.ControlDown()) keys = keys | wxKEY_CTRL;
391
392 if (node == NULL)
393 {
394 if (event.Dragging() &&
395 (dragType == wxDRAG_TYPE_BOUNDING_BOX))
396
397 {
398 if (dragMode == wxDRAG_MODE_CONTINUE_LEFT)
399 {
400 wxClientDC dc(handlerDialog);
401 OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, NULL);
402 OnDragContinue(TRUE, x, y, keys, dc, NULL);
403 oldDragX = x; oldDragY = y;
404 }
405 /*
406 else if (event.LeftUp() && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
407 {
408
409 wxClientDC dc(handlerDialog);
410 OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, NULL);
411 OnDragContinue(TRUE, x, y, keys, dc, NULL);
412 oldDragX = x; oldDragY = y;
413 }
414 */
415 }
416 }
417
418 if (event.LeftDown())
419 {
420 if (!m_mouseCaptured)
421 {
422 handlerDialog->CaptureMouse();
423 m_mouseCaptured = TRUE;
424 }
425
426 // Starting to draw a bounding box around
427 // some numbe of controls on the dialog
428 if (node == NULL &&
429 wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER)
430 {
431 dragItem = NULL;
432 dragMode = wxDRAG_MODE_START_LEFT;
433 firstDragX = x;
434 firstDragY = y;
435 dragType = wxDRAG_TYPE_BOUNDING_BOX;
436 wxClientDC dc(handlerDialog);
437 OnDragBegin(x, y, keys, dc, 0);
438 dragMode = wxDRAG_MODE_CONTINUE_LEFT;
439 oldDragX = x; oldDragY = y;
440 }
441
442 event.Skip();
443 }
444 else if (event.LeftUp())
445 {
446 if (m_mouseCaptured)
447 {
448 handlerDialog->ReleaseMouse();
449 m_mouseCaptured = FALSE;
450 }
451
452 if (dragType == wxDRAG_TYPE_BOUNDING_BOX)
453 {
454 // Determine the bounds of the surrounding box
455 int upperLeftX = (x < firstDragX) ? x : firstDragX;
456 int upperLeftY = (y < firstDragY) ? y : firstDragY;
457 int lowerRightX = (x > firstDragX) ? x : firstDragX;
458 int lowerRightY = (y > firstDragY) ? y : firstDragY;
459
460 int xpos,ypos;
461 int width,height;
462
463 bool widgetWithinBounds = FALSE;
464
465 int needsRefresh = 0;
466
467 wxClientDC dc(handlerDialog);
468
469 // Determine what widgets which fall within the bounding box
470 // and select them
471 wxNode *node = handlerDialog->GetChildren().First();
472 while (node)
473 {
474 widgetWithinBounds = FALSE;
475 wxWindow *win = (wxWindow *)node->Data();
476 if (win->IsKindOf(CLASSINFO(wxControl)))
477 {
478 wxControl *item = (wxControl *)win;
479 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
480
481 // Unselect all widgets that are currently selected
482 if (!(keys & wxKEY_SHIFT) && childHandler->IsSelected())
483 {
484 needsRefresh ++;
485 OnItemSelect(item, FALSE);
486 childHandler->SelectItem(FALSE);
487 }
488
489 // Get X,Y and WIDTH,HEIGHT of the widget to be able
490 // to determine if any portion of it is within the bounded
491 // area
492 childHandler->handlerControl->GetPosition(&xpos, &ypos);
493 childHandler->handlerControl->GetSize(&width, &height);
494
495 // Check if the current widget is inside the rectangle
496 // that was just bounded
497 if (xpos >= upperLeftX && xpos <= lowerRightX)
498 {
499 if (ypos >= upperLeftY && ypos <= lowerRightY)
500 widgetWithinBounds = TRUE;
501 else if (ypos+height >= upperLeftY && ypos+height <= lowerRightY)
502 widgetWithinBounds = TRUE;
503 }
504 else if (xpos+width >= upperLeftX && xpos <= lowerRightX)
505 {
506 if (ypos >= upperLeftY && ypos <= lowerRightY)
507 widgetWithinBounds = TRUE;
508 else if (ypos+height >= upperLeftY && ypos+height <= lowerRightY)
509 widgetWithinBounds = TRUE;
510 }
511
512 if (widgetWithinBounds)
513 {
514 childHandler->SelectItem(TRUE);
515 OnItemSelect(item, TRUE);
516
517 // childHandler->DrawSelectionHandles(dc);
518 }
519
520 }
521 node = node->Next();
522 }
523
524 OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, NULL);
525 OnDragEnd(x, y, keys, dc, NULL);
526
527 if (needsRefresh > 0)
528 {
529 dc.Clear();
530 handlerDialog->Refresh();
531 }
532
533 // Always paint, in case the bounding box overlapped with
534 // the handles of any selected widgets, that way when the
535 // bounding box is cleared, the handles don't get partially
536 // erased where the overlap occured
537 PaintSelectionHandles(dc);
538
539 dragMode = wxDRAG_MODE_NONE;
540 checkTolerance = TRUE;
541 dragItem = NULL;
542 dragType = wxDRAG_TYPE_NONE;
543 }
544 else
545 OnLeftClick(x, y, keys);
546 }
547 else if (event.RightDown())
548 {
549 if (m_mouseCaptured)
550 {
551 handlerDialog->ReleaseMouse();
552 m_mouseCaptured = FALSE;
553 }
554
555 OnRightClick(x, y, keys);
556 }
557 else if (event.LeftDClick())
558 {
559 if (m_mouseCaptured)
560 {
561 handlerDialog->ReleaseMouse();
562 m_mouseCaptured = FALSE;
563 }
564 wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog);
565 }
566 }
567 else
568 event.Skip();
569 }
570
571 void wxResourceEditorDialogHandler::OnItemEvent(wxControl *item, wxMouseEvent& event)
572 {
573 if (!GetEvtHandlerEnabled())
574 return;
575
576 // Not a selection handle event: just a normal item event.
577 // Transform to panel coordinates.
578 wxCoord x, y;
579 item->GetPosition(&x, &y);
580
581 event.m_x = event.m_x + x;
582 event.m_y = event.m_y + y;
583
584 ProcessItemEvent(item, event, dragType);
585 }
586
587 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEvent& event, int selectionHandle)
588 {
589 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
590
591 wxCoord x, y;
592 event.GetPosition(&x, &y);
593 int keys = 0;
594 if (event.ShiftDown()) keys = keys | wxKEY_SHIFT;
595 if (event.ControlDown()) keys = keys | wxKEY_CTRL;
596 bool dragging = event.Dragging();
597
598 if (dragging)
599 {
600 int dx = (int)abs((x - firstDragX));
601 int dy = (int)abs((y - firstDragY));
602 if (checkTolerance && (dx <= dragTolerance) && (dy <= dragTolerance))
603 {
604 return;
605 }
606 else
607 // If we've ignored the tolerance once, then ALWAYS ignore
608 // tolerance in this drag, even if we come back within
609 // the tolerance range.
610 {
611 checkTolerance = FALSE;
612 }
613 }
614 if (event.LeftDClick())
615 {
616 if (m_mouseCaptured)
617 {
618 handlerDialog->ReleaseMouse();
619 m_mouseCaptured = FALSE;
620 }
621
622 wxResourceManager::GetCurrentResourceManager()->EditWindow(item);
623 }
624 else if (dragging && dragItem && dragMode == wxDRAG_MODE_START_LEFT)
625 {
626 dragMode = wxDRAG_MODE_CONTINUE_LEFT;
627 wxClientDC dc(handlerDialog);
628 childHandler->OnDragBegin(x, y, keys, dc, selectionHandle);
629 oldDragX = x; oldDragY = y;
630 if (!m_mouseCaptured)
631 {
632 handlerDialog->CaptureMouse();
633 m_mouseCaptured = TRUE;
634 }
635 }
636 else if (dragging && dragItem && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
637 {
638 wxClientDC dc(handlerDialog);
639 childHandler->OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, selectionHandle);
640 childHandler->OnDragContinue(TRUE, x, y, keys, dc, selectionHandle);
641 oldDragX = x; oldDragY = y;
642 }
643 else if (event.LeftUp() && dragItem && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
644 {
645 wxClientDC dc(handlerDialog);
646 dragMode = wxDRAG_MODE_NONE;
647 checkTolerance = TRUE;
648
649 childHandler->OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, selectionHandle);
650 childHandler->OnDragEnd(x, y, keys, dc, selectionHandle);
651
652 dragItem = NULL;
653 dragType = wxDRAG_TYPE_NONE;
654
655 if (m_mouseCaptured)
656 {
657 handlerDialog->ReleaseMouse();
658 m_mouseCaptured = FALSE;
659 }
660 }
661 else if (dragging && dragItem && dragMode == wxDRAG_MODE_START_RIGHT)
662 {
663 wxClientDC dc(handlerDialog);
664 dragMode = wxDRAG_MODE_CONTINUE_RIGHT;
665 childHandler->OnDragBegin(x, y, keys, dc, selectionHandle);
666 oldDragX = x; oldDragY = y;
667
668 if (!m_mouseCaptured)
669 {
670 handlerDialog->CaptureMouse();
671 m_mouseCaptured = TRUE;
672 }
673 }
674 else if (dragging && dragItem && dragMode == wxDRAG_MODE_CONTINUE_RIGHT)
675 {
676 oldDragX = x; oldDragY = y;
677 }
678 // Obsolete; no longer try to right-drag
679 else if (event.RightUp() && dragItem && dragMode == wxDRAG_MODE_CONTINUE_RIGHT)
680 {
681 dragMode = wxDRAG_MODE_NONE;
682 checkTolerance = TRUE;
683 dragItem = NULL;
684 dragType = wxDRAG_TYPE_NONE;
685
686 if (m_mouseCaptured)
687 {
688 handlerDialog->ReleaseMouse();
689 m_mouseCaptured = FALSE;
690 }
691 }
692 else if (event.IsButton())
693 {
694 checkTolerance = TRUE;
695
696 if (event.LeftDown())
697 {
698 dragItem = item;
699 dragMode = wxDRAG_MODE_START_LEFT;
700 firstDragX = x;
701 firstDragY = y;
702 dragType = selectionHandle;
703
704 if (!m_mouseCaptured)
705 {
706 handlerDialog->CaptureMouse();
707 m_mouseCaptured = TRUE;
708 }
709 }
710 else if (event.RightDown())
711 {
712 if (m_mouseCaptured)
713 {
714 handlerDialog->ReleaseMouse();
715 m_mouseCaptured = FALSE;
716 }
717
718 if (item)
719 childHandler->OnRightClick(x, y, keys);
720 else
721 OnRightClick(x, y, keys);
722
723 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
724
725 /*
726 dragItem = item;
727 dragMode = wxDRAG_MODE_START_RIGHT;
728 firstDragX = x;
729 firstDragY = y;
730 dragType = selectionHandle;
731
732 if (!m_mouseCaptured)
733 {
734 handlerDialog->CaptureMouse();
735 m_mouseCaptured = TRUE;
736 }
737 */
738 }
739 else if (event.LeftUp())
740 {
741 if (dragItem)
742 childHandler->OnLeftClick(x, y, keys);
743 else
744 OnLeftClick(x, y, keys);
745
746 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
747
748 if (m_mouseCaptured)
749 {
750 handlerDialog->ReleaseMouse();
751 m_mouseCaptured = FALSE;
752 }
753 }
754 else if (event.RightUp())
755 {
756 /*
757 if (dragItem)
758 childHandler->OnRightClick(x, y, keys);
759 else
760 OnRightClick(x, y, keys);
761
762 dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
763
764 if (m_mouseCaptured)
765 {
766 handlerDialog->ReleaseMouse();
767 m_mouseCaptured = FALSE;
768 }
769 */
770 }
771 }
772 }
773
774 // Calls DrawSelectionHandles for all items if
775 // edit mode is on.
776 void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC& dc)
777 {
778 if (!GetEvtHandlerEnabled())
779 return;
780
781 dc.BeginDrawing();
782
783 wxNode *node = handlerDialog->GetChildren().First();
784 while (node)
785 {
786 wxWindow *win = (wxWindow *)node->Data();
787 if (win->IsKindOf(CLASSINFO(wxControl)))
788 {
789 wxControl *item = (wxControl *)win;
790 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
791
792 // Don't draw handles for an item that's being moved: it'll
793 // smear.
794 if (childHandler->IsSelected() && (item != dragItem))
795 childHandler->DrawSelectionHandles(dc);
796 }
797 node = node->Next();
798 }
799 dc.EndDrawing();
800 }
801
802
803
804 void wxResourceEditorDialogHandler::DrawBoundingBox(wxDC& dc, int x, int y, int w, int h)
805 {
806 dc.DrawRectangle(x, y, w, h);
807 }
808
809
810 void wxResourceEditorDialogHandler::OnDragBegin(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
811 {
812 /*
813 dc.BeginDrawing();
814
815 dc.SetOptimization(FALSE);
816
817 dc.SetLogicalFunction(wxINVERT);
818
819 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
820 dc.SetPen(pen);
821 dc.SetBrush(* wxTRANSPARENT_BRUSH);
822
823 dc.SetOptimization(TRUE);
824
825 // Refresh();
826 // DrawBoundingBox(dc, xpos, ypos, width, height);
827
828 dc.EndDrawing();
829 */
830 } //wxResourceEditorDialogHandler::OnDragBegin()
831
832
833 void wxResourceEditorDialogHandler::OnDragContinue(bool WXUNUSED(paintIt), int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
834 {
835 int upperLeftX = (x < firstDragX) ? x : firstDragX;
836 int upperLeftY = (y < firstDragY) ? y : firstDragY;
837 int lowerRightX = (x > firstDragX) ? x : firstDragX;
838 int lowerRightY = (y > firstDragY) ? y : firstDragY;
839
840 dc.BeginDrawing();
841 dc.SetLogicalFunction(wxINVERT);
842 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
843 dc.SetPen(pen);
844 dc.SetBrush(* wxTRANSPARENT_BRUSH);
845
846 DrawBoundingBox(dc, (int)upperLeftX, upperLeftY,
847 lowerRightX-upperLeftX, lowerRightY-upperLeftY);
848
849 dc.EndDrawing();
850
851 } // wxResourceEditorDialogHandler::OnDragContinue()
852
853
854 void wxResourceEditorDialogHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
855 {
856 /*
857 dc.BeginDrawing();
858
859 dc.SetOptimization(FALSE);
860
861 dc.SetLogicalFunction(wxCOPY);
862 dc.SetPen(* wxBLACK_PEN);
863 dc.SetBrush(* wxBLACK_BRUSH);
864
865 dc.SetOptimization(TRUE);
866
867 dc.EndDrawing();
868 */
869
870 } // wxResourceEditorDialogHandler::OnDragEnd()
871
872 void wxResourceEditorDialogHandler::OnObjectEdit(wxCommandEvent& event)
873 {
874 wxMenu* menu = (wxMenu*) event.GetEventObject();
875
876 wxWindow *data = (wxWindow *)menu->GetClientData();
877 if (!data)
878 return;
879
880 wxResourceManager::GetCurrentResourceManager()->EditWindow(data);
881 }
882
883 void wxResourceEditorDialogHandler::OnObjectDelete(wxCommandEvent& event)
884 {
885 wxMenu* menu = (wxMenu*) event.GetEventObject();
886
887 wxWindow *data = (wxWindow *)menu->GetClientData();
888 if (!data)
889 return;
890
891 // Before deleting a dialog, give the user a last chance
892 // change their mind, in case they accidentally right
893 // clicked the dialog rather than the widget they were
894 // aiming for.
895 if (data->IsKindOf(CLASSINFO(wxPanel)))
896 {
897 wxString str(wxT("Deleting dialog : "));
898 str += data->GetName();
899 if (wxMessageBox(wxT("Are you sure?"), str, wxYES_NO | wxCENTRE) == wxNO)
900 return;
901 }
902
903 wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data);
904
905 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data);
906 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data);
907 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data);
908 }
909
910
911
912 /*
913 * Event handler for controls
914 */
915
916 int wxResourceEditorControlHandler::dragOffsetX = 0;
917 int wxResourceEditorControlHandler::dragOffsetY = 0;
918
919 wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl *control,
920 wxEvtHandler *oldHandler)
921 {
922 handlerControl = control;
923 handlerOldHandler = oldHandler;
924
925 handleSize = 6;
926 handleMargin = 1;
927 isSelected = FALSE;
928 dragOffsetX = 0;
929 dragOffsetY = 0;
930 // m_treeItem = 0;
931 }
932
933 wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
934 {
935 }
936
937 /*
938 * Manipulation and drawing of items in Edit Mode
939 */
940
941 void wxResourceEditorControlHandler::SelectItem(bool select)
942 {
943 isSelected = select;
944 }
945
946 // Returns TRUE or FALSE
947 bool wxResourceEditorControlHandler::HitTest(int x, int y)
948 {
949 int xpos, ypos, width, height;
950 handlerControl->GetPosition(&xpos, &ypos);
951 handlerControl->GetSize(&width, &height);
952
953 return ((x >= xpos) && (x <= (xpos + width)) && (y >= ypos) && (y <= (ypos + height)));
954 }
955
956 // Calculate position of the 8 handles
957 void wxResourceEditorControlHandler::CalcSelectionHandles(int *hx, int *hy)
958 {
959 int xpos, ypos, width, height;
960 handlerControl->GetPosition(&xpos, &ypos);
961 handlerControl->GetSize(&width, &height);
962 int middleX = (xpos + (width/2));
963 int middleY = (ypos + (height/2));
964
965 // Start from top middle, clockwise.
966 /*
967 7 0 1
968
969 6 2
970
971 5 4 3
972 */
973
974 hx[0] = (int)(middleX - (handleSize/2));
975 hy[0] = ypos - handleSize - handleMargin;
976
977 hx[1] = xpos + width + handleMargin;
978 hy[1] = ypos - handleSize - handleMargin;
979
980 hx[2] = xpos + width + handleMargin;
981 hy[2] = (int)(middleY - (handleSize/2));
982
983 hx[3] = xpos + width + handleMargin;
984 hy[3] = ypos + height + handleMargin;
985
986 hx[4] = (int)(middleX - (handleSize/2));
987 hy[4] = ypos + height + handleMargin;
988
989 hx[5] = xpos - handleSize - handleMargin;
990 hy[5] = ypos + height + handleMargin;
991
992 hx[6] = xpos - handleSize - handleMargin;
993 hy[6] = (int)(middleY - (handleSize/2));
994
995 hx[7] = xpos - handleSize - handleMargin;
996 hy[7] = ypos - handleSize - handleMargin;
997 }
998
999 // Returns 0 (no hit), 1 - 8 for which selection handle
1000 // (clockwise from top middle)
1001 int wxResourceEditorControlHandler::SelectionHandleHitTest(int x, int y)
1002 {
1003 // Handle positions
1004 int hx[8];
1005 int hy[8];
1006 CalcSelectionHandles(hx, hy);
1007
1008 int i;
1009 for (i = 0; i < 8; i++)
1010 {
1011 if ((x >= hx[i]) && (x <= (hx[i] + handleSize)) && (y >= hy[i]) && (y <= (hy[i] + handleSize)))
1012 return (i + 1);
1013 }
1014 return 0;
1015 }
1016
1017 void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC& dc, bool WXUNUSED(erase))
1018 {
1019 dc.SetOptimization(FALSE);
1020
1021 dc.SetLogicalFunction(wxCOPY);
1022 dc.SetPen(* wxBLACK_PEN);
1023 dc.SetBrush(* wxBLACK_BRUSH);
1024
1025 dc.SetOptimization(TRUE);
1026
1027 // Handle positions
1028 int hx[8];
1029 int hy[8];
1030 CalcSelectionHandles(hx, hy);
1031
1032 int i;
1033 for (i = 0; i < 8; i++)
1034 {
1035 dc.DrawRectangle(hx[i], hy[i], handleSize, handleSize);
1036 }
1037 }
1038
1039 void wxResourceEditorControlHandler::DrawBoundingBox(wxDC& dc, int x, int y, int w, int h)
1040 {
1041 dc.DrawRectangle(x, y, w, h);
1042 }
1043
1044 // If selectionHandle is zero, not dragging the selection handle.
1045 void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
1046 {
1047 int xpos, ypos, width, height;
1048 handlerControl->GetPosition(&xpos, &ypos);
1049 handlerControl->GetSize(&width, &height);
1050
1051 dc.BeginDrawing();
1052
1053 // dc.DestroyClippingRegion();
1054
1055 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
1056
1057 // Erase selection handles
1058 // DrawSelectionHandles(dc, TRUE);
1059
1060 dc.SetOptimization(FALSE);
1061
1062 dc.SetLogicalFunction(wxINVERT);
1063
1064 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
1065 dc.SetPen(pen);
1066 dc.SetBrush(* wxTRANSPARENT_BRUSH);
1067
1068 dc.SetOptimization(TRUE);
1069
1070 if (selectionHandle > 0)
1071 {
1072 panel->Refresh();
1073
1074 DrawBoundingBox(dc, xpos, ypos, width, height);
1075 }
1076 else
1077 {
1078 panel->Refresh();
1079
1080 dragOffsetX = (x - xpos);
1081 dragOffsetY = (y - ypos);
1082
1083 DrawBoundingBox(dc, xpos, ypos, width, height);
1084
1085 // Also draw bounding boxes for other selected items
1086 wxNode *node = panel->GetChildren().First();
1087 while (node)
1088 {
1089 wxWindow *win = (wxWindow *)node->Data();
1090 if (win->IsKindOf(CLASSINFO(wxControl)))
1091 {
1092 wxControl *item = (wxControl *)win;
1093 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
1094 if ((item != handlerControl) && handler->IsSelected())
1095 {
1096 int x1, y1, w1, h1;
1097 item->GetPosition(&x1, &y1);
1098 item->GetSize(&w1, &h1);
1099 handler->DrawBoundingBox(dc, x1, y1, w1, h1);
1100 }
1101 }
1102 node = node->Next();
1103 }
1104 }
1105 dc.EndDrawing();
1106 }
1107
1108 void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt), int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
1109 {
1110 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
1111 int xpos, ypos, width, height;
1112 handlerControl->GetPosition(&xpos, &ypos);
1113 handlerControl->GetSize(&width, &height);
1114
1115 if (selectionHandle > 0)
1116 {
1117 /*
1118 8 1 2
1119
1120 7 3
1121
1122 6 5 4
1123 */
1124
1125 int x1, y1, width1, height1;
1126
1127 switch (selectionHandle)
1128 {
1129 case 1:
1130 x1 = xpos;
1131 y1 = y;
1132 width1 = width;
1133 height1 = (ypos + height) - y;
1134 break;
1135 case 5:
1136 x1 = xpos;
1137 y1 = ypos;
1138 width1 = width;
1139 height1 = (y - ypos);
1140 break;
1141 case 3:
1142 x1 = xpos;
1143 y1 = ypos;
1144 width1 = (x - xpos);
1145 height1 = height;
1146 break;
1147 case 7:
1148 x1 = x;
1149 y1 = ypos;
1150 width1 = (xpos + width) - x;
1151 height1 = height;
1152 break;
1153 case 2:
1154 x1 = xpos;
1155 y1 = y;
1156 width1 = (x - xpos);
1157 height1 = (ypos + height) - y;
1158 break;
1159 case 4:
1160 x1 = xpos;
1161 y1 = ypos;
1162 width1 = (x - xpos);
1163 height1 = (y - ypos);
1164 break;
1165 case 6:
1166 x1 = x;
1167 y1 = ypos;
1168 width1 = (xpos + width) - x;
1169 height1 = y - ypos;
1170 break;
1171 case 8:
1172 x1 = x;
1173 y1 = y;
1174 width1 = (xpos + width) - x;
1175 height1 = (ypos + height) - y;
1176 break;
1177 }
1178 dc.BeginDrawing();
1179
1180 dc.SetLogicalFunction(wxINVERT);
1181 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
1182 dc.SetPen(pen);
1183 dc.SetBrush(* wxTRANSPARENT_BRUSH);
1184
1185 DrawBoundingBox(dc, x1, y1, width1, height1);
1186
1187 dc.EndDrawing();
1188 }
1189 else
1190 {
1191 dc.BeginDrawing();
1192 dc.SetLogicalFunction(wxINVERT);
1193 wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
1194 dc.SetPen(pen);
1195 dc.SetBrush(* wxTRANSPARENT_BRUSH);
1196
1197 DrawBoundingBox(dc, (int)(x - dragOffsetX), (int)(y - dragOffsetY), width, height);
1198
1199 // Also draw bounding boxes for other selected items
1200 wxNode *node = panel->GetChildren().First();
1201 while (node)
1202 {
1203 wxWindow *win = (wxWindow *)node->Data();
1204 if (win->IsKindOf(CLASSINFO(wxControl)))
1205 {
1206 wxControl *item = (wxControl *)win;
1207 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
1208 if ((item != handlerControl) && handler->IsSelected())
1209 {
1210 int x1, y1, w1, h1;
1211 item->GetPosition(&x1, &y1);
1212 item->GetSize(&w1, &h1);
1213 int x2 = (int)(x1 + (x - dragOffsetX) - xpos);
1214 int y2 = (int)(y1 + (y - dragOffsetY) - ypos);
1215 handler->DrawBoundingBox(dc, x2, y2, w1, h1);
1216 }
1217 }
1218 node = node->Next();
1219 }
1220 dc.EndDrawing();
1221 }
1222 }
1223
1224 void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
1225 {
1226 wxPanel *panel = (wxPanel *)handlerControl->GetParent();
1227
1228 dc.BeginDrawing();
1229
1230 int xpos, ypos, width, height;
1231 handlerControl->GetPosition(&xpos, &ypos);
1232 handlerControl->GetSize(&width, &height);
1233
1234 wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl);
1235 wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl->GetParent());
1236
1237 if (selectionHandle > 0)
1238 {
1239 int x1, y1, width1, height1;
1240
1241 switch (selectionHandle)
1242 {
1243 case 1:
1244 x1 = xpos;
1245 y1 = y;
1246 width1 = width;
1247 height1 = (ypos + height) - y;
1248 break;
1249 case 5:
1250 x1 = xpos;
1251 y1 = ypos;
1252 width1 = width;
1253 height1 = (y - ypos);
1254 break;
1255 case 3:
1256 x1 = xpos;
1257 y1 = ypos;
1258 width1 = (x - xpos);
1259 height1 = height;
1260 break;
1261 case 7:
1262 x1 = x;
1263 y1 = ypos;
1264 width1 = (xpos + width) - x;
1265 height1 = height;
1266 break;
1267 case 2:
1268 x1 = xpos;
1269 y1 = y;
1270 width1 = (x - xpos);
1271 height1 = (ypos + height) - y;
1272 break;
1273 case 4:
1274 x1 = xpos;
1275 y1 = ypos;
1276 width1 = (x - xpos);
1277 height1 = (y - ypos);
1278 break;
1279 case 6:
1280 x1 = x;
1281 y1 = ypos;
1282 width1 = (xpos + width) - x;
1283 height1 = y - ypos;
1284 break;
1285 case 8:
1286 x1 = x;
1287 y1 = y;
1288 width1 = (xpos + width) - x;
1289 height1 = (ypos + height) - y;
1290 break;
1291 }
1292 // Update the associated resource
1293 // We need to convert to dialog units if this is not a dialog or panel, but
1294 // the parent resource specifies dialog units.
1295 int resourceX = x1;
1296 int resourceY = y1;
1297 int resourceWidth = width1;
1298 int resourceHeight = height1;
1299
1300 if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
1301 {
1302 wxPoint pt = handlerControl->GetParent()->ConvertPixelsToDialog(wxPoint(x1, y1));
1303 wxSize sz = handlerControl->GetParent()->ConvertPixelsToDialog(wxSize(width1, height1));
1304
1305 // Convert back so we've rounded down
1306 sz = handlerControl->GetParent()->ConvertDialogToPixels(sz);
1307 sz = handlerControl->GetParent()->ConvertPixelsToDialog(sz);
1308 resourceWidth = sz.x; resourceHeight = sz.y;
1309
1310 sz = handlerControl->GetParent()->ConvertDialogToPixels(sz);
1311 width1 = sz.x;
1312 height1 = sz.y;
1313
1314 pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
1315 pt = handlerControl->GetParent()->ConvertPixelsToDialog(pt);
1316 resourceX = pt.x; resourceY = pt.y;
1317
1318 pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
1319 x1 = pt.x;
1320 y1 = pt.y;
1321 }
1322 handlerControl->SetSize(x1, y1, width1, height1);
1323 resource->SetSize(resourceX, resourceY, resourceWidth, resourceHeight);
1324 }
1325 else
1326 {
1327 // Correction 31/12/98. We need to round down the values to take into account
1328 // the fact that several pixels map to the same dialog unit.
1329
1330 int newX = (int)(x - dragOffsetX);
1331 int newY = (int)(y - dragOffsetY);
1332 int resourceX = newX;
1333 int resourceY = newY;
1334
1335 // Update the associated resource
1336 if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
1337 {
1338 wxPoint pt = handlerControl->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY));
1339 pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
1340 pt = handlerControl->GetParent()->ConvertPixelsToDialog(pt);
1341 resourceX = pt.x; resourceY = pt.y;
1342 pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
1343
1344 // Having converted it several times, we know it'll map to dialog units exactly.
1345 newX = pt.x;
1346 newY = pt.y;
1347 }
1348 handlerControl->Move(newX, newY);
1349 OldOnMove(newX, newY);
1350
1351 resource->SetSize(resourceX, resourceY, resource->GetWidth(), resource->GetHeight());
1352
1353 // Also move other selected items
1354 wxNode *node = panel->GetChildren().First();
1355 while (node)
1356 {
1357 wxWindow *win = (wxWindow *)node->Data();
1358 if (win->IsKindOf(CLASSINFO(wxControl)))
1359 {
1360 wxControl *item = (wxControl *)win;
1361 wxResourceEditorControlHandler *handler = (wxResourceEditorControlHandler *)item->GetEventHandler();
1362 if ((item != handlerControl) && handler->IsSelected())
1363 {
1364 int x1, y1;
1365 item->GetPosition(&x1, &y1);
1366 int x2 = (int)(x1 + (x - dragOffsetX) - xpos);
1367 int y2 = (int)(y1 + (y - dragOffsetY) - ypos);
1368
1369 resourceX = x2;
1370 resourceY = y2;
1371
1372 // Update the associated resource
1373 resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
1374 if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
1375 {
1376 wxPoint pt = item->GetParent()->ConvertPixelsToDialog(wxPoint(x2, y2));
1377 pt = item->GetParent()->ConvertDialogToPixels(pt);
1378 pt = item->GetParent()->ConvertPixelsToDialog(pt);
1379
1380 resourceX = pt.x; resourceY = pt.y;
1381 pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
1382
1383 // Having converted it several times, we know it'll map to dialog units exactly
1384 x2 = pt.x;
1385 y2 = pt.y;
1386 }
1387
1388 item->Move(x2, y2);
1389 ((wxResourceEditorControlHandler *)item->GetEventHandler())->OldOnMove(x2, y2);
1390 ((wxResourceEditorControlHandler *)item->GetEventHandler())->DrawSelectionHandles(dc);
1391
1392 resource->SetSize(resourceX, resourceY, resource->GetWidth(), resource->GetHeight());
1393
1394 }
1395 }
1396 node = node->Next();
1397 }
1398 }
1399 dc.SetOptimization(FALSE);
1400
1401 dc.SetLogicalFunction(wxCOPY);
1402 dc.SetPen(* wxBLACK_PEN);
1403 dc.SetBrush(* wxBLACK_BRUSH);
1404
1405 dc.SetOptimization(TRUE);
1406
1407 // Force it to repaint the selection handles (if any)
1408 // since the panel thinks we're still within a drag and
1409 // won't paint the handles.
1410 if (IsSelected())
1411 DrawSelectionHandles(dc);
1412
1413 dc.EndDrawing();
1414
1415 panel->Refresh();
1416 }
1417
1418 // These functions call OnItemEvent, OnItemMove and OnItemSize
1419 // by default.
1420 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent& event)
1421 {
1422 /*
1423 if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
1424 (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
1425 return;
1426 */
1427 wxWindow *panel = handlerControl->GetParent();
1428 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1429 return;
1430 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1431 if ( !panelHandler->GetEvtHandlerEnabled() )
1432 {
1433 event.Skip();
1434 return;
1435 }
1436
1437 panelHandler->OnItemEvent(handlerControl, event);
1438 }
1439
1440 void wxResourceEditorControlHandler::OldOnMove(int x, int y)
1441 {
1442 wxWindow *panel = handlerControl->GetParent();
1443 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1444 return;
1445
1446 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1447 panelHandler->OnItemMove(handlerControl, x, y);
1448 }
1449
1450 void wxResourceEditorControlHandler::OldOnSize(int w, int h)
1451 {
1452 wxWindow *panel = handlerControl->GetParent();
1453 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1454 return;
1455
1456 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1457 panelHandler->OnItemSize(handlerControl, w, h);
1458 }
1459
1460 void wxResourceEditorControlHandler::OnSelect(bool select)
1461 {
1462 wxWindow *panel = handlerControl->GetParent();
1463 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1464 return;
1465
1466 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1467 panelHandler->OnItemSelect(handlerControl, select);
1468 }
1469
1470 void wxResourceEditorControlHandler::OnLeftClick(int x, int y, int keys)
1471 {
1472 wxWindow *panel = handlerControl->GetParent();
1473 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1474 return;
1475
1476 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1477 panelHandler->OnItemLeftClick(handlerControl, x, y, keys);
1478 }
1479
1480 void wxResourceEditorControlHandler::OnRightClick(int x, int y, int keys)
1481 {
1482 wxWindow *panel = handlerControl->GetParent();
1483 if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
1484 return;
1485
1486 wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
1487 panelHandler->OnItemRightClick(handlerControl, x, y, keys);
1488 }
1489
1490