]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/dlghndlr.cpp
no message
[wxWidgets.git] / utils / dialoged / src / dlghndlr.cpp
index 7eb928ae6a6d83b2a333ab46ea91459ef53fbfa4..b63762d66d3d6b61b50131156f3352cde333800a 100644 (file)
 #include <math.h>
 #include <string.h>
 
+#if wxUSE_IOSTREAMH
 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
 #include <strstrea.h>
 #else
 #include <strstream.h>
 #endif
+#else
+#include <strstream>
+#endif
 
 #include "reseditr.h"
 #include "winprop.h"
-#include "editrpal.h"
 #include "dlghndlr.h"
 #include "edlist.h"
 
@@ -47,6 +50,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)
@@ -90,7 +94,7 @@ void wxResourceEditorDialogHandler::OnItemSelect(wxControl *item, bool select)
     resourceManager->RemoveSelection(item);
 }
 
-void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& event)
+void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
        wxPaintDC dc(handlerDialog);
 
@@ -145,8 +149,6 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
     return;
   }
 
-  wxResourceManager* manager = resourceManager;
-
   switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection())
   {
         case RESED_BUTTON:
@@ -170,12 +172,18 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
         case RESED_CHOICE:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxChoice", x, y);
           break;
+        case RESED_COMBOBOX:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxComboBox", x, y);
+          break;
         case RESED_CHECKBOX:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxCheckBox", x, y);
           break;
         case RESED_RADIOBOX:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioBox", x, y);
           break;
+        case RESED_RADIOBUTTON:
+          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioButton", x, y);
+          break;
         case RESED_LISTBOX:
           resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxListBox", x, y);
           break;
@@ -202,126 +210,22 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
   }
 }
 
-#if 0
-void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
-{
-  if (keys & wxKEY_CTRL)
-  {
-    wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog);
-    return;
-  }
-
-  // Deselect all items if click on panel
-  if (resourceManager->GetEditorPalette()->currentlySelected == PALETTE_ARROW)
-  {
-    int needsRefresh = 0;
-    wxNode *node = handlerDialog->GetChildren()->First();
-    while (node)
-    {
-      wxControl *item = (wxControl *)node->Data();
-         wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
-      if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected())
-      {
-        needsRefresh ++;
-        OnItemSelect(item, FALSE);
-        childHandler->SelectItem(FALSE);
-      }
-      node = node->Next();
-    }
-    if (needsRefresh > 0)
-    {
-         wxClientDC dc(handlerDialog);
-      dc.Clear();
-      handlerDialog->Refresh();
-    }
-    return;
-  }
-
-  wxResourceManager* manager = resourceManager;
-
-  switch (resourceManager->GetEditorPalette()->currentlySelected)
-  {
-        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:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxButton", x, y);
-          break;
-        case PALETTE_BITMAP_BUTTON:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxButton", x, y, TRUE);
-          break;
-        case PALETTE_MESSAGE:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticText", x, y);
-          break;
-        case PALETTE_BITMAP_MESSAGE:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticBitmap", x, y, TRUE);
-          break;
-        case PALETTE_TEXT:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxTextCtrl (single-line)", x, y);
-          break;
-        case PALETTE_MULTITEXT:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxTextCtrl (multi-line)", x, y);
-          break;
-        case PALETTE_CHOICE:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxChoice", x, y);
-          break;
-        case PALETTE_CHECKBOX:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxCheckBox", x, y);
-          break;
-        case PALETTE_RADIOBOX:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxRadioBox", x, y);
-          break;
-        case PALETTE_LISTBOX:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxListBox", x, y);
-          break;
-        case PALETTE_SLIDER:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxSlider", x, y);
-          break;
-        case PALETTE_GAUGE:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxGauge", x, y);
-          break;
-        case PALETTE_GROUPBOX:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxStaticBox", x, y);
-          break;
-        case PALETTE_SCROLLBAR:
-          resourceManager->CreatePanelItem(handlerResource, handlerDialog, "wxScrollBar", x, y);
-          break;
-        default:
-          break;
-  }
-
-  // Now switch pointer on.
-  if (manager->GetEditorPalette()->currentlySelected != PALETTE_ARROW)
-  {
-    manager->GetEditorPalette()->ToggleTool(manager->GetEditorPalette()->currentlySelected, FALSE);
-    manager->GetEditorPalette()->ToggleTool(PALETTE_ARROW, TRUE);
-    manager->GetEditorPalette()->currentlySelected = PALETTE_ARROW;
-  }
-}
-#endif
-
-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);
   handlerDialog->PopupMenu(menu, x, y);
 }
 
-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)
   {
     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.
@@ -330,6 +234,7 @@ void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int x, int
     OnLeftClick(x,  y, keys);
     return;
   }
+*/
   
   wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
 
@@ -377,7 +282,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)
@@ -392,6 +297,23 @@ void wxResourceEditorDialogHandler::OnItemRightClick(wxControl *item, int x, int
   handlerDialog->PopupMenu(menu, x, y);
 }
 
+// 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.
 void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event)
 {
@@ -444,7 +366,7 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event)
 
         OnLeftClick(x, y, keys);
     }
-    else if (event.RightUp())
+    else if (event.RightDown())
     {
         if (m_mouseCaptured)
         {
@@ -454,6 +376,15 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event)
 
         OnRightClick(x, y, keys);
     }
+    else if (event.LeftDClick())
+    {
+        if (m_mouseCaptured)
+        {
+            handlerDialog->ReleaseMouse();
+            m_mouseCaptured = FALSE;
+        }
+        wxResourceManager::GetCurrentResourceManager()->EditWindow(handlerDialog);
+    }
   }
   else
        event.Skip();
@@ -471,13 +402,14 @@ void wxResourceEditorDialogHandler::OnItemEvent(wxControl *item, wxMouseEvent& e
 
   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);
   int keys = 0;
@@ -564,6 +496,7 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
   { 
     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;
@@ -597,6 +530,20 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
     }
     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;
@@ -608,6 +555,7 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
         handlerDialog->CaptureMouse();
         m_mouseCaptured = TRUE;
       }
+      */
     }
     else if (event.LeftUp())
     {
@@ -626,6 +574,7 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
     }
     else if (event.RightUp())
     {
+      /*
       if (dragItem)
         childHandler->OnRightClick(x, y, keys);
       else
@@ -638,6 +587,7 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve
         handlerDialog->ReleaseMouse();
         m_mouseCaptured = FALSE;
       }
+      */
     }
   }
 }
@@ -814,7 +764,6 @@ 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);
@@ -867,11 +816,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);
@@ -988,7 +935,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();
 
@@ -996,6 +942,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;
@@ -1052,11 +1001,33 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys),
         break;
     }
     handlerControl->SetSize(x1, y1, width1, height1);
+
+    // Also 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.
+    if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+    {
+        wxPoint pt = handlerControl->GetParent()->ConvertPixelsToDialog(wxPoint(x1, y1));
+        x1 = pt.x; y1 = pt.y;
+        wxSize sz = handlerControl->GetParent()->ConvertPixelsToDialog(wxSize(width1, height1));
+        width1 = sz.x; height1 = sz.y;
+    }
+    resource->SetSize(x1, y1, width1, height1);
   }
   else
   {
-    handlerControl->Move((int)(x - dragOffsetX), (int)(y - dragOffsetY));
-    OldOnMove((int)(x - dragOffsetX), (int)(y - dragOffsetY));
+    int newX = (int)(x - dragOffsetX);
+    int newY = (int)(y - dragOffsetY);
+    handlerControl->Move(newX, newY);
+    OldOnMove(newX, newY);
+
+    // Also update the associated resource
+    if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+    {
+        wxPoint pt = handlerControl->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY));
+        newX = pt.x; newY = pt.y;
+    }
+    resource->SetSize(newX, newY, resource->GetWidth(), resource->GetHeight());
 
     // Also move other selected items
     wxNode *node = panel->GetChildren()->First();
@@ -1076,6 +1047,16 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys),
           item->Move(x2, y2);
           ((wxResourceEditorControlHandler *)item->GetEventHandler())->OldOnMove(x2, y2);
           ((wxResourceEditorControlHandler *)item->GetEventHandler())->DrawSelectionHandles(dc);
+
+          // Also update the associated resource
+          resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
+          if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+          {
+            wxPoint pt = item->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY));
+            x2 = pt.x; y2 = pt.y;
+          }
+          resource->SetSize(x2, y2, resource->GetWidth(), resource->GetHeight());
+
         }
       }
       node = node->Next();