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