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