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