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