]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/dlghndlr.cpp
Cured some small doc typos; some WIN16 fixes; transferred DLL WinMain to
[wxWidgets.git] / utils / dialoged / src / dlghndlr.cpp
index cfa37ec97e1c64a8e02d4e3526bf66a8482279cf..ba3be91fd94fe819d9a00647983c339d3761c7b5 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"
@@ -46,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)
@@ -99,7 +104,7 @@ void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& WXUNUSED(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();
@@ -122,7 +127,7 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
   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();
@@ -144,6 +149,20 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys)
     return;
   }
 
+  // Round down to take account of dialog units
+  wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog);
+  if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+  {
+        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:
@@ -251,7 +270,7 @@ void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int WXUNUSE
     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();
@@ -292,6 +311,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)
 {
@@ -309,7 +345,7 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event)
     event.Position(&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();
@@ -354,6 +390,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();
@@ -371,13 +416,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;
@@ -569,7 +615,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();
@@ -698,8 +744,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);
 
@@ -742,7 +788,7 @@ void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys
 
   wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
   dc.SetPen(pen);
-  dc.SetBrush(wxTRANSPARENT_BRUSH);
+  dc.SetBrush(wxTRANSPARENT_BRUSH);
 
   dc.SetOptimization(TRUE);
 
@@ -762,7 +808,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();
@@ -859,7 +905,7 @@ void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt), int
     dc.SetLogicalFunction(wxXOR);
     wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
     dc.SetPen(pen);
-    dc.SetBrush(wxTRANSPARENT_BRUSH);
+    dc.SetBrush(wxTRANSPARENT_BRUSH);
 
     DrawBoundingBox(dc, x1, y1, width1, height1);
 
@@ -871,12 +917,12 @@ void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt), int
       dc.SetLogicalFunction(wxXOR);
       wxPen pen(wxColour(0, 0, 0), 1, wxDOT);
       dc.SetPen(pen);
-      dc.SetBrush(wxTRANSPARENT_BRUSH);
+      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();
@@ -910,6 +956,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;
@@ -965,15 +1014,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();
@@ -987,9 +1090,29 @@ 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();
@@ -998,8 +1121,8 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys),
   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);