]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/dlghndlr.cpp
Reenabled OSS support
[wxWidgets.git] / utils / dialoged / src / dlghndlr.cpp
index 3cea11c606a463fbd3c957b03d7f593b77e05804..721af4b4b0de206c751a8d75397636562af821c8 100644 (file)
 #include <math.h>
 #include <string.h>
 
-#if defined(__WINDOWS__) && !defined(__GNUWIN32__)
-#include <strstrea.h>
-#else
-#include <strstream.h>
-#endif
-
 #include "reseditr.h"
 #include "winprop.h"
-#include "editrpal.h"
 #include "dlghndlr.h"
-
-extern void wxResourceEditWindow(wxWindow *win);
+#include "edlist.h"
 
 IMPLEMENT_CLASS(wxResourceEditorDialogHandler, wxEvtHandler)
 IMPLEMENT_CLASS(wxResourceEditorControlHandler, wxEvtHandler)
@@ -48,6 +40,7 @@ IMPLEMENT_CLASS(wxResourceEditorControlHandler, wxEvtHandler)
 BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler, wxEvtHandler)
        EVT_PAINT(wxResourceEditorDialogHandler::OnPaint)
        EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent)
+       EVT_SIZE(wxResourceEditorDialogHandler::OnSize)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxResourceEditorControlHandler, wxEvtHandler)
@@ -75,6 +68,12 @@ wxResourceEditorDialogHandler::wxResourceEditorDialogHandler(wxPanel *dialog, wx
   oldDragY = 0;
   dragTolerance = 3;
   checkTolerance = TRUE;
+  m_mouseCaptured = FALSE;
+//  m_treeItem = 0;
+}
+
+wxResourceEditorDialogHandler::~wxResourceEditorDialogHandler(void)
+{
 }
 
 void wxResourceEditorDialogHandler::OnItemSelect(wxControl *item, bool select)
@@ -85,35 +84,7 @@ void wxResourceEditorDialogHandler::OnItemSelect(wxControl *item, bool select)
     resourceManager->RemoveSelection(item);
 }
 
-bool wxResourceEditorDialogHandler::OnClose(void)
-{
-  handlerDialog->PopEventHandler();
-
-  // Now reset all child event handlers
-  wxNode *node = handlerDialog->GetChildren()->First();
-  while ( node )
-  {
-       wxWindow *child = (wxWindow *)node->Data();
-       wxEvtHandler *childHandler = child->GetEventHandler();
-       if ( child->IsKindOf(CLASSINFO(wxControl)) && childHandler != child )
-       {
-               child->PopEventHandler();
-               delete childHandler;
-       }
-       node = node->Next();
-  }
-  
-  // Save the information before deleting the dialog.
-  resourceManager->InstantiateResourceFromWindow(handlerResource, handlerDialog, TRUE);
-  
-  resourceManager->DisassociateResource(handlerDialog, FALSE);
-
-  handlerDialog->Show(FALSE);
-  delete this;
-  return TRUE;
-}
-
-void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& event)
+void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
        wxPaintDC dc(handlerDialog);
 
@@ -123,7 +94,7 @@ void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& event)
 // Add event handlers for all children
 void wxResourceEditorDialogHandler::AddChildHandlers(void)
 {
-  wxNode *node = handlerDialog->GetChildren()->First();
+  wxNode *node = handlerDialog->GetChildren().First();
   while ( node )
   {
        wxControl *child = (wxControl *)node->Data();
@@ -138,15 +109,15 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
 {
   if (keys & wxKEY_CTRL)
   {
-    wxResourceEditWindow(handlerDialog);
+    wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog);
     return;
   }
 
   // Deselect all items if click on panel
-  if (resourceManager->GetEditorPalette()->currentlySelected == PALETTE_ARROW)
+  if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER)
   {
     int needsRefresh = 0;
-    wxNode *node = handlerDialog->GetChildren()->First();
+    wxNode *node = handlerDialog->GetChildren().First();
     while (node)
     {
       wxControl *item = (wxControl *)node->Data();
@@ -168,58 +139,68 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
     return;
   }
 
-  switch (resourceManager->GetEditorPalette()->currentlySelected)
+  // Round down to take account of dialog units
+  wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog);
+  if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
   {
-        case PALETTE_FRAME:
-          break;
-        case PALETTE_DIALOG_BOX:
-          break;
-        case PALETTE_PANEL:
-          break;
-        case PALETTE_CANVAS:
-          break;
-        case PALETTE_TEXT_WINDOW:
-          break;
-        case PALETTE_BUTTON:
+        wxPoint pt = handlerDialog->ConvertPixelsToDialog(wxPoint(x, y));
+
+        // Convert back so we've rounded down
+        pt = handlerDialog->ConvertDialogToPixels(pt);
+        pt = handlerDialog->ConvertPixelsToDialog(pt);
+        pt = handlerDialog->ConvertDialogToPixels(pt);
+        x = pt.x;
+        y = pt.y;
+  }
+
+  switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
+  {
+        case RESED_BUTTON:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxButton", x, y);
           break;
-        case PALETTE_BITMAP_BUTTON:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxButton", x, y, TRUE);
+        case RESED_BMPBUTTON:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxBitmapButton", x, y, TRUE);
           break;
-        case PALETTE_MESSAGE:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxMessage", x, y);
+        case RESED_STATICTEXT:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticText", x, y);
           break;
-        case PALETTE_BITMAP_MESSAGE:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxMessage", x, y, TRUE);
+        case RESED_STATICBMP:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticBitmap", x, y, TRUE);
           break;
-        case PALETTE_TEXT:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxText", x, y);
+        case RESED_TEXTCTRL_SINGLE:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxTextCtrl (single-line)", x, y);
           break;
-        case PALETTE_MULTITEXT:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxMultiText", x, y);
+        case RESED_TEXTCTRL_MULTIPLE:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxTextCtrl (multi-line)", x, y);
           break;
-        case PALETTE_CHOICE:
+        case RESED_CHOICE:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxChoice", x, y);
           break;
-        case PALETTE_CHECKBOX:
+        case RESED_COMBOBOX:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxComboBox", x, y);
+          break;
+        case RESED_CHECKBOX:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxCheckBox", x, y);
           break;
-        case PALETTE_RADIOBOX:
+        case RESED_RADIOBOX:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioBox", x, y);
           break;
-        case PALETTE_LISTBOX:
+        case RESED_RADIOBUTTON:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioButton", x, y);
+          break;
+        case RESED_LISTBOX:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxListBox", x, y);
           break;
-        case PALETTE_SLIDER:
+        case RESED_SLIDER:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxSlider", x, y);
           break;
-        case PALETTE_GAUGE:
+        case RESED_GAUGE:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxGauge", x, y);
           break;
-        case PALETTE_GROUPBOX:
+        case RESED_STATICBOX:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticBox", x, y);
           break;
-        case PALETTE_SCROLLBAR:
+        case RESED_SCROLLBAR:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxScrollBar", x, y);
           break;
         default:
@@ -227,33 +208,28 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
   }
 
   // Now switch pointer on.
-  if (resourceManager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
+  if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() != RESED_POINTER)
   {
-    resourceManager->GetEditorPalette()->ToggleTool(resourceManager->GetEditorPalette()->currentlySelected, FALSE);
-    resourceManager->GetEditorPalette()->ToggleTool(PALETTE_ARROW, TRUE);
-    resourceManager->GetEditorPalette()->currentlySelected = PALETTE_ARROW;
+    wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->SetItemState(RESED_POINTER, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
   }
 }
 
-void wxResourceEditorDialogHandler::OnRightClick(int x, int y, int keys)
+void wxResourceEditorDialogHandler::OnRightClick(int x, int y, int WXUNUSED(keys))
 {
   wxMenu *menu = resourceManager->GetPopupMenu();
   menu->SetClientData((char *)handlerDialog);
-#ifdef __MOTIF__
-  handlerDialog->FakePopupMenu(menu, x, y);
-#else
   handlerDialog->PopupMenu(menu, x, y);
-#endif
 }
 
-void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int x, int y, int keys)
+void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int WXUNUSED(x), int WXUNUSED(y), int keys)
 {
   if (keys & wxKEY_CTRL)
   {
-    wxResourceEditWindow(item);
+    wxResourceManager::GetCurrentResourceManager()->EditWindow(item);
     return;
   }
-  
+
+/*
   // If this is a wxStaticBox and the pointer isn't an arrow, chances
   // are that we really meant to place an item on the panel.
   // Fake this event.
@@ -262,6 +238,7 @@ void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int x, int
     OnLeftClick(x,  y, keys);
     return;
   }
+*/
   
   wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
 
@@ -283,7 +260,7 @@ void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int x, int
     int needsRefresh = 0;
     if (!(keys & wxKEY_SHIFT))
     {
-      wxNode *node = item->GetParent()->GetChildren()->First();
+      wxNode *node = item->GetParent()->GetChildren().First();
       while (node)
       {
         wxControl *child = (wxControl *)node->Data();
@@ -309,7 +286,7 @@ void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int x, int
   }
 }
 
-void wxResourceEditorDialogHandler::OnItemRightClick(wxControl *item, int x, int y, int keys)
+void wxResourceEditorDialogHandler::OnItemRightClick(wxControl *item, int x, int y, int WXUNUSED(keys))
 {
 /*
   if (keys & wxKEY_CTRL)
@@ -321,11 +298,24 @@ void wxResourceEditorDialogHandler::OnItemRightClick(wxControl *item, int x, int
 
   wxMenu *menu = resourceManager->GetPopupMenu();
   menu->SetClientData((char *)item);
-#ifdef __MOTIF__
-  handlerDialog->FakePopupMenu(menu, x, y);
-#else
   handlerDialog->PopupMenu(menu, x, y);
-#endif
+}
+
+// Under Windows 95, you can resize a panel interactively depending on
+// window styles.
+void wxResourceEditorDialogHandler::OnSize(wxSizeEvent& event)
+{
+    // Update the associated resource
+    int w, h;
+    handlerDialog->GetClientSize(& w, & h);
+
+    wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog);
+    if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+    {
+        wxSize sz = handlerDialog->ConvertPixelsToDialog(wxSize(w, h));
+        w = sz.x; h = sz.y;
+    }
+    resource->SetSize(resource->GetX(), resource->GetY(), w, h);
 }
 
 // An event outside any items: may be a drag event.
@@ -341,11 +331,11 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event)
       return;
     }
   
-    long x, y;
-    event.Position(&x, &y);
+    wxCoord x, y;
+    event.GetPosition(&x, &y);
 
     // Find which selection handle we're on, if any
-    wxNode *node = handlerDialog->GetChildren()->First();
+    wxNode *node = handlerDialog->GetChildren().First();
     while (node)
     {
       wxWindow *win = (wxWindow *)node->Data();
@@ -371,9 +361,34 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event)
     if (event.ControlDown()) keys = keys | wxKEY_CTRL;
 
     if (event.LeftUp())
-      OnLeftClick(x, y, keys);
-    else if (event.RightUp())
-      OnRightClick(x, y, keys);
+    {
+        if (m_mouseCaptured)
+        {
+            handlerDialog->ReleaseMouse();
+            m_mouseCaptured = FALSE;
+        }
+
+        OnLeftClick(x, y, keys);
+    }
+    else if (event.RightDown())
+    {
+        if (m_mouseCaptured)
+        {
+            handlerDialog->ReleaseMouse();
+            m_mouseCaptured = FALSE;
+        }
+
+        OnRightClick(x, y, keys);
+    }
+    else if (event.LeftDClick())
+    {
+        if (m_mouseCaptured)
+        {
+            handlerDialog->ReleaseMouse();
+            m_mouseCaptured = FALSE;
+        }
+        wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog);
+    }
   }
   else
        event.Skip();
@@ -386,20 +401,21 @@ void wxResourceEditorDialogHandler::OnItemEvent(wxControl *item, wxMouseEvent& e
 
   // Not a selection handle event: just a normal item event.
   // Transform to panel coordinates.
-  int x, y;
+  wxCoord x, y;
   item->GetPosition(&x, &y);
 
   event.m_x = event.m_x + x;
   event.m_y = event.m_y + y;
+  
   ProcessItemEvent(item, event, dragType);
 }
 
 void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEvent& event, int selectionHandle)
 {
   wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
-
-  long x, y;
-  event.Position(&x, &y);
+  
+  wxCoord x, y;
+  event.GetPosition(&x, &y);
   int keys = 0;
   if (event.ShiftDown()) keys = keys | wxKEY_SHIFT;
   if (event.ControlDown()) keys = keys | wxKEY_CTRL;
@@ -420,12 +436,27 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
         checkTolerance = FALSE;
       }
   }
-  if (dragging && dragItem && dragMode == wxDRAG_MODE_START_LEFT)
+  if (event.LeftDClick())
+  {
+      if (m_mouseCaptured)
+      {
+        handlerDialog->ReleaseMouse();
+        m_mouseCaptured = FALSE;
+      }
+
+      wxResourceManager::GetCurrentResourceManager()->EditWindow(item);
+  }
+  else if (dragging && dragItem && dragMode == wxDRAG_MODE_START_LEFT)
   {
     dragMode = wxDRAG_MODE_CONTINUE_LEFT;
        wxClientDC dc(handlerDialog);
     childHandler->OnDragBegin(x, y, keys, dc, selectionHandle);
     oldDragX = x; oldDragY = y;
+    if (!m_mouseCaptured)
+    {
+        handlerDialog->CaptureMouse();
+        m_mouseCaptured = TRUE;
+    }
   }
   else if (dragging && dragItem && dragMode == wxDRAG_MODE_CONTINUE_LEFT)
   { 
@@ -439,10 +470,18 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
        wxClientDC dc(handlerDialog);
     dragMode = wxDRAG_MODE_NONE;
     checkTolerance = TRUE;
+
     childHandler->OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, selectionHandle);
     childHandler->OnDragEnd(x, y, keys, dc, selectionHandle);
+
     dragItem = NULL;
     dragType = wxDRAG_TYPE_NONE;
+
+    if (m_mouseCaptured)
+    {
+        handlerDialog->ReleaseMouse();
+        m_mouseCaptured = FALSE;
+    }
   }
   else if (dragging && dragItem && dragMode == wxDRAG_MODE_START_RIGHT)
   {
@@ -450,17 +489,30 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
     dragMode = wxDRAG_MODE_CONTINUE_RIGHT;
     childHandler->OnDragBegin(x, y, keys, dc, selectionHandle);
     oldDragX = x; oldDragY = y;
+
+    if (!m_mouseCaptured)
+    {
+        handlerDialog->CaptureMouse();
+        m_mouseCaptured = TRUE;
+    }
   }
   else if (dragging && dragItem && dragMode == wxDRAG_MODE_CONTINUE_RIGHT)
   { 
     oldDragX = x; oldDragY = y;
   }
+  // Obsolete; no longer try to right-drag
   else if (event.RightUp() && dragItem && dragMode == wxDRAG_MODE_CONTINUE_RIGHT)
   {
     dragMode = wxDRAG_MODE_NONE;
     checkTolerance = TRUE;
     dragItem = NULL;
     dragType = wxDRAG_TYPE_NONE;
+
+    if (m_mouseCaptured)
+    {
+        handlerDialog->ReleaseMouse();
+        m_mouseCaptured = FALSE;
+    }
   }
   else if (event.IsButton())
   {
@@ -473,14 +525,41 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
       firstDragX = x;
       firstDragY = y;
       dragType = selectionHandle;
+
+      if (!m_mouseCaptured)
+      {
+        handlerDialog->CaptureMouse();
+        m_mouseCaptured = TRUE;
+      }
     }
     else if (event.RightDown())
     {
+      if (m_mouseCaptured)
+      {
+        handlerDialog->ReleaseMouse();
+        m_mouseCaptured = FALSE;
+      }
+
+      if (item)
+        childHandler->OnRightClick(x, y, keys);
+      else
+        OnRightClick(x, y, keys);
+
+      dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
+
+      /*
       dragItem = item;
       dragMode = wxDRAG_MODE_START_RIGHT;
       firstDragX = x;
       firstDragY = y;
       dragType = selectionHandle;
+
+      if (!m_mouseCaptured)
+      {
+        handlerDialog->CaptureMouse();
+        m_mouseCaptured = TRUE;
+      }
+      */
     }
     else if (event.LeftUp())
     {
@@ -490,15 +569,29 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
         OnLeftClick(x, y, keys);
 
       dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
+
+      if (m_mouseCaptured)
+      {
+        handlerDialog->ReleaseMouse();
+        m_mouseCaptured = FALSE;
+      }
     }
     else if (event.RightUp())
     {
+      /*
       if (dragItem)
         childHandler->OnRightClick(x, y, keys);
       else
         OnRightClick(x, y, keys);
 
       dragItem = NULL; dragMode = wxDRAG_MODE_NONE; dragType = wxDRAG_TYPE_NONE;
+
+      if (m_mouseCaptured)
+      {
+        handlerDialog->ReleaseMouse();
+        m_mouseCaptured = FALSE;
+      }
+      */
     }
   }
 }
@@ -512,7 +605,7 @@ void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC& dc)
 
   dc.BeginDrawing();
 
-  wxNode *node = handlerDialog->GetChildren()->First();
+  wxNode *node = handlerDialog->GetChildren().First();
   while (node)
   {
     wxWindow *win = (wxWindow *)node->Data();
@@ -549,6 +642,11 @@ wxResourceEditorControlHandler::wxResourceEditorControlHandler(wxControl *contro
   isSelected = FALSE;
   dragOffsetX = 0;
   dragOffsetY = 0;
+//  m_treeItem = 0;
+}
+
+wxResourceEditorControlHandler::~wxResourceEditorControlHandler(void)
+{
 }
 
 /*
@@ -636,8 +734,8 @@ void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC& dc, bool WXUNUSE
   dc.SetOptimization(FALSE);
 
   dc.SetLogicalFunction(wxCOPY);
-  dc.SetPen(wxBLACK_PEN);
-  dc.SetBrush(wxBLACK_BRUSH);
+  dc.SetPen(wxBLACK_PEN);
+  dc.SetBrush(wxBLACK_BRUSH);
 
   dc.SetOptimization(TRUE);
 
@@ -670,17 +768,17 @@ void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys
 //  dc.DestroyClippingRegion();
 
   wxPanel *panel = (wxPanel *)handlerControl->GetParent();
-  wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
 
   // Erase selection handles
 //  DrawSelectionHandles(dc, TRUE);
 
   dc.SetOptimization(FALSE);
 
-  dc.SetLogicalFunction(wxXOR);
+  dc.SetLogicalFunction(wxINVERT);
 
-  dc.SetPen(wxBLACK_DASHED_PEN);
-  dc.SetBrush(wxTRANSPARENT_BRUSH);
+  wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
+  dc.SetPen(pen);
+  dc.SetBrush(* wxTRANSPARENT_BRUSH);
 
   dc.SetOptimization(TRUE);
 
@@ -700,7 +798,7 @@ void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys
       DrawBoundingBox(dc, xpos, ypos, width, height);
 
       // Also draw bounding boxes for other selected items
-      wxNode *node = panel->GetChildren()->First();
+      wxNode *node = panel->GetChildren().First();
       while (node)
       {
         wxWindow *win = (wxWindow *)node->Data();
@@ -722,11 +820,9 @@ void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys
   dc.EndDrawing();
 }
 
-void wxResourceEditorControlHandler::OnDragContinue(bool paintIt, int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
+void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt), int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
 {
   wxPanel *panel = (wxPanel *)handlerControl->GetParent();
-  wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
-
   int xpos, ypos, width, height;
   handlerControl->GetPosition(&xpos, &ypos);
   handlerControl->GetSize(&width, &height);
@@ -796,9 +892,10 @@ void wxResourceEditorControlHandler::OnDragContinue(bool paintIt, int x, int y,
     }
     dc.BeginDrawing();
 
-    dc.SetLogicalFunction(wxXOR);
-    dc.SetPen(wxBLACK_DASHED_PEN);
-    dc.SetBrush(wxTRANSPARENT_BRUSH);
+    dc.SetLogicalFunction(wxINVERT);
+    wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
+    dc.SetPen(pen);
+    dc.SetBrush(* wxTRANSPARENT_BRUSH);
 
     DrawBoundingBox(dc, x1, y1, width1, height1);
 
@@ -807,15 +904,15 @@ void wxResourceEditorControlHandler::OnDragContinue(bool paintIt, int x, int y,
   else
   {
       dc.BeginDrawing();
-
-      dc.SetLogicalFunction(wxXOR);
-      dc.SetPen(wxBLACK_DASHED_PEN);
-      dc.SetBrush(wxTRANSPARENT_BRUSH);
+      dc.SetLogicalFunction(wxINVERT);
+      wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
+      dc.SetPen(pen);
+      dc.SetBrush(wxTRANSPARENT_BRUSH);
 
       DrawBoundingBox(dc, (int)(x - dragOffsetX), (int)(y - dragOffsetY), width, height);
 
       // Also draw bounding boxes for other selected items
-      wxNode *node = panel->GetChildren()->First();
+      wxNode *node = panel->GetChildren().First();
       while (node)
       {
         wxWindow *win = (wxWindow *)node->Data();
@@ -835,7 +932,6 @@ void wxResourceEditorControlHandler::OnDragContinue(bool paintIt, int x, int y,
         }
         node = node->Next();
       }
-
       dc.EndDrawing();
   }
 }
@@ -843,7 +939,6 @@ void wxResourceEditorControlHandler::OnDragContinue(bool paintIt, int x, int y,
 void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle)
 {
   wxPanel *panel = (wxPanel *)handlerControl->GetParent();
-  wxResourceEditorDialogHandler *panelHandler = (wxResourceEditorDialogHandler *)panel->GetEventHandler();
 
   dc.BeginDrawing();
 
@@ -851,6 +946,9 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys),
   handlerControl->GetPosition(&xpos, &ypos);
   handlerControl->GetSize(&width, &height);
 
+  wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl);
+  wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerControl->GetParent());
+
   if (selectionHandle > 0)
   {
     int x1, y1, width1, height1;
@@ -906,15 +1004,69 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys),
         height1 = (ypos + height) - y;
         break;
     }
+    // Update the associated resource
+    // We need to convert to dialog units if this is not a dialog or panel, but
+    // the parent resource specifies dialog units.
+    int resourceX = x1;
+    int resourceY = y1;
+    int resourceWidth = width1;
+    int resourceHeight = height1;
+
+    if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+    {
+        wxPoint pt = handlerControl->GetParent()->ConvertPixelsToDialog(wxPoint(x1, y1));
+        wxSize sz = handlerControl->GetParent()->ConvertPixelsToDialog(wxSize(width1, height1));
+
+        // Convert back so we've rounded down
+        sz = handlerControl->GetParent()->ConvertDialogToPixels(sz);
+        sz = handlerControl->GetParent()->ConvertPixelsToDialog(sz);
+        resourceWidth = sz.x; resourceHeight = sz.y;
+
+        sz = handlerControl->GetParent()->ConvertDialogToPixels(sz);
+        width1 = sz.x;
+        height1 = sz.y;
+
+        pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
+        pt = handlerControl->GetParent()->ConvertPixelsToDialog(pt);
+        resourceX = pt.x; resourceY = pt.y;
+
+        pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
+        x1 = pt.x;
+        y1 = pt.y;
+    }
     handlerControl->SetSize(x1, y1, width1, height1);
+    resource->SetSize(resourceX, resourceY, resourceWidth, resourceHeight);
   }
   else
   {
-    handlerControl->Move((int)(x - dragOffsetX), (int)(y - dragOffsetY));
-    OldOnMove((int)(x - dragOffsetX), (int)(y - dragOffsetY));
+    // Correction 31/12/98. We need to round down the values to take into account
+    // the fact that several pixels map to the same dialog unit.
+
+    int newX = (int)(x - dragOffsetX);
+    int newY = (int)(y - dragOffsetY);
+    int resourceX = newX;
+    int resourceY = newY;
+
+    // Update the associated resource
+    if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+    {
+        wxPoint pt = handlerControl->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY));
+        pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
+        pt = handlerControl->GetParent()->ConvertPixelsToDialog(pt);
+        resourceX = pt.x; resourceY = pt.y;
+        pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
+
+        // Having converted it several times, we know it'll map to dialog units exactly.
+        newX = pt.x;
+        newY = pt.y;
+    }
+    handlerControl->Move(newX, newY);
+    OldOnMove(newX, newY);
+
+    resource->SetSize(resourceX, resourceY, resource->GetWidth(), resource->GetHeight());
 
     // Also move other selected items
-    wxNode *node = panel->GetChildren()->First();
+    wxNode *node = panel->GetChildren().First();
     while (node)
     {
       wxWindow *win = (wxWindow *)node->Data();
@@ -928,20 +1080,39 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys),
           item->GetPosition(&x1, &y1);
           int x2 = (int)(x1 + (x - dragOffsetX) - xpos);
           int y2 = (int)(y1 + (y - dragOffsetY) - ypos);
+
+          // Update the associated resource
+          resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
+          if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+          {
+            wxPoint pt = item->GetParent()->ConvertPixelsToDialog(wxPoint(x2, y2));
+            pt = item->GetParent()->ConvertDialogToPixels(pt);
+            pt = item->GetParent()->ConvertPixelsToDialog(pt);
+
+            resourceX = pt.x; resourceY = pt.y;
+            pt = handlerControl->GetParent()->ConvertDialogToPixels(pt);
+
+            // Having converted it several times, we know it'll map to dialog units exactly
+            x2 = pt.x;
+            y2 = pt.y;
+          }
+
           item->Move(x2, y2);
           ((wxResourceEditorControlHandler *)item->GetEventHandler())->OldOnMove(x2, y2);
           ((wxResourceEditorControlHandler *)item->GetEventHandler())->DrawSelectionHandles(dc);
+
+          resource->SetSize(resourceX, resourceY, resource->GetWidth(), resource->GetHeight());
+
         }
       }
       node = node->Next();
     }
   }
-
   dc.SetOptimization(FALSE);
 
   dc.SetLogicalFunction(wxCOPY);
-  dc.SetPen(wxBLACK_PEN);
-  dc.SetBrush(wxBLACK_BRUSH);
+  dc.SetPen(wxBLACK_PEN);
+  dc.SetBrush(wxBLACK_BRUSH);
 
   dc.SetOptimization(TRUE);
 
@@ -960,9 +1131,11 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys),
 // by default.
 void wxResourceEditorControlHandler::OnMouseEvent(wxMouseEvent& event)
 {
+/*
   if ((event.m_eventType == wxEVENT_TYPE_LEFT_DCLICK) ||
       (event.m_eventType == wxEVENT_TYPE_RIGHT_DCLICK))
     return;
+*/
   wxWindow *panel = handlerControl->GetParent();
   if ( !panel->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorDialogHandler)) )
        return;