]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/reseditr.cpp
New wxHtml stuff, including a TagHandler for placing wxPython widgets
[wxWidgets.git] / utils / dialoged / src / reseditr.cpp
index 57b3d624c85b1188ef9910a00b788a546e398c11..e6157c5e8240dad2d24e22957e2619f626a6c715 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
-
-#ifdef __WXMSW__
-#include <windows.h>
-#endif
-
 #ifdef __WXMSW__
 #include "wx/help.h"
 #endif
@@ -71,7 +57,7 @@
 static void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event);
 wxResourceManager *wxResourceManager::sm_currentResourceManager = NULL;
 
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
 #include "bitmaps/load.xpm"
 #include "bitmaps/save.xpm"
 #include "bitmaps/new.xpm"
@@ -86,6 +72,11 @@ wxResourceManager *wxResourceManager::sm_currentResourceManager = NULL;
 #include "bitmaps/toback.xpm"
 #include "bitmaps/help.xpm"
 #include "bitmaps/wxwin.xpm"
+
+#include "bitmaps/dialog.xpm"
+#include "bitmaps/folder1.xpm"
+#include "bitmaps/folder2.xpm"
+#include "bitmaps/buttonsm.xpm"
 #endif
 
 /*
@@ -147,13 +138,14 @@ wxResourceManager::~wxResourceManager()
 bool wxResourceManager::Initialize()
 {
   // Set up the resource filename for each platform.
+  // TODO: This shold be replaced by wxConfig usage.
 #ifdef __WXMSW__
   // dialoged.ini in the Windows directory
-  char buf[256];
-  GetWindowsDirectory(buf, 256);
-  strcat(buf, "\\dialoged.ini");
-  m_optionsResourceFilename = buf;
-#elif defined(__WXGTK__)
+  wxString windowsDir = wxGetOSDirectory();
+  windowsDir += "\\dialoged.ini" ;
+
+  m_optionsResourceFilename = windowsDir;
+#elif defined(__WXGTK__) || defined(__WXMOTIF__)
   wxGetHomeDir( &m_optionsResourceFilename );
   m_optionsResourceFilename += "/.dialogedrc";
 #else
@@ -176,7 +168,7 @@ bool wxResourceManager::Initialize()
 #ifdef __WXMSW__
     m_bitmapImage = new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE);
 #endif
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
     m_bitmapImage = new wxBitmap( wxwin_xpm );
 #endif
   }
@@ -187,11 +179,16 @@ bool wxResourceManager::Initialize()
   wxIcon icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
   wxIcon icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
   wxIcon icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
+#else
+  wxIcon icon1( dialog_xpm );    
+  wxIcon icon2( folder1_xpm );    
+  wxIcon icon3( folder2_xpm );    
+  wxIcon icon4( buttonsm_xpm );    
+#endif
   m_imageList.Add(icon1);
   m_imageList.Add(icon2);
   m_imageList.Add(icon3);
   m_imageList.Add(icon4);
-#endif
 
   m_symbolTable.AddStandardSymbols();
 
@@ -312,8 +309,8 @@ bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *WXUNUSED(parent)
     c->right.SameAs      (m_editorFrame, wxRight, 0);
     c->bottom.SameAs     (m_editorFrame, wxBottom, 0);
     c->width.Unconstrained();
-#ifdef __WXGTK__
-    c->height.Absolute(140);
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+    c->height.Absolute(120);
 #else
     c->height.Absolute(60);
 #endif
@@ -330,10 +327,8 @@ bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *WXUNUSED(parent)
   else
   {
     wxFrame *fr = m_editorFrame;
-    if (m_editorFrame->OnClose())
+    if (m_editorFrame->Close())
     {
-      fr->Show(FALSE);
-      delete fr;
       m_editorFrame = NULL;
       m_editorPanel = NULL;
     }
@@ -384,7 +379,7 @@ bool wxResourceManager::Save(const wxString& filename)
 bool wxResourceManager::SaveAs()
 {
   wxString s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename), wxFileNameFromPath(WXSTRINGCAST m_currentFilename),
-    "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT));
+    "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT, wxTheApp->GetTopWindow()));
     
   if (s.IsNull() || s == "")
     return FALSE;
@@ -427,7 +422,7 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
     wxString str = filename;
     if (str == wxString(""))
     {
-      wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, NULL));
+      wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, wxTheApp->GetTopWindow()));
       if (!f.IsNull() && f != "")
         str = f;
       else
@@ -731,7 +726,11 @@ wxResourceEditorScrolledWindow *wxResourceManager::OnCreateEditorPanel(wxFrame *
 {
   wxResourceEditorScrolledWindow *panel = new wxResourceEditorScrolledWindow(parent, wxDefaultPosition, wxDefaultSize,
 //    wxSUNKEN_BORDER|wxCLIP_CHILDREN);
+#ifdef __WXMOTIF__
+    wxBORDER);
+#else
     wxSUNKEN_BORDER);
+#endif
 
   panel->SetScrollbars(10, 10, 100, 100);
 
@@ -756,7 +755,7 @@ wxToolBar *wxResourceManager::OnCreateToolBar(wxFrame *parent)
   wxBitmap ToolbarToFrontBitmap("TOFRONTTOOL");
   wxBitmap ToolbarHelpBitmap("HELPTOOL");
 #endif
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
   wxBitmap ToolbarLoadBitmap( load_xpm );
   wxBitmap ToolbarSaveBitmap( save_xpm);
   wxBitmap ToolbarNewBitmap( new_xpm );
@@ -788,47 +787,47 @@ wxToolBar *wxResourceManager::OnCreateToolBar(wxFrame *parent)
   int currentX = gap;
   toolbar->AddSeparator();
   toolbar->AddTool(TOOLBAR_NEW, ToolbarNewBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "New dialog");
+                   FALSE, currentX, -1, NULL, "New dialog");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_LOAD_FILE, ToolbarLoadBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Load");
+                   FALSE, currentX, -1, NULL, "Load");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_SAVE_FILE, ToolbarSaveBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Save");
+                   FALSE, currentX, -1, NULL, "Save");
   currentX += width + dx + gap;
   toolbar->AddSeparator();
   toolbar->AddTool(TOOLBAR_FORMAT_HORIZ, ToolbarVertBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Horizontal align");
+                   FALSE, currentX, -1, NULL, "Horizontal align");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN, ToolbarAlignTBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Top align");
+                   FALSE, currentX, -1, NULL, "Top align");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN, ToolbarAlignBBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Bottom align");
+                   FALSE, currentX, -1, NULL, "Bottom align");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_FORMAT_VERT, ToolbarHorizBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Vertical align");
+                   FALSE, currentX, -1, NULL, "Vertical align");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN, ToolbarAlignLBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Left align");
+                   FALSE, currentX, -1, NULL, "Left align");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN, ToolbarAlignRBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Right align");
+                   FALSE, currentX, -1, NULL, "Right align");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_COPY_SIZE, ToolbarCopySizeBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Copy size");
+                   FALSE, currentX, -1, NULL, "Copy size");
   currentX += width + dx + gap;
   toolbar->AddSeparator();
   toolbar->AddTool(TOOLBAR_TO_FRONT, ToolbarToFrontBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "To front");
+                   FALSE, currentX, -1, NULL, "To front");
   currentX += width + dx;
   toolbar->AddTool(TOOLBAR_TO_BACK, ToolbarToBackBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "To back");
+                   FALSE, currentX, -1, NULL, "To back");
   currentX += width + dx + gap;
 
   toolbar->AddSeparator();
   toolbar->AddTool(TOOLBAR_HELP, ToolbarHelpBitmap, wxNullBitmap,
-                   FALSE, (float)currentX, -1, NULL, "Help");
+                   FALSE, currentX, -1, NULL, "Help");
   currentX += width + dx;
   
   toolbar->Realize();
@@ -1318,7 +1317,22 @@ void wxResourceManager::AlignItems(int flag)
           break;
       }
 
+      wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
+      wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent());
+
       item->SetSize(newX, newY, w, h);
+
+         // 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 = item->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY));
+        newX = pt.x; newY = pt.y;
+        wxSize sz = item->GetParent()->ConvertPixelsToDialog(wxSize(w, h));
+        w = sz.x; h = sz.y;
+      }
+      resource->SetSize(newX, newY, w, h);
     }
   }
   win->Refresh();
@@ -1348,7 +1362,23 @@ void wxResourceManager::CopySize()
   {
     wxControl *item = (wxControl *)node->Data();
     if (item->GetParent() == win)
+       {
       item->SetSize(-1, -1, firstW, firstH);
+
+      wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
+      wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent());
+
+         // 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)
+      {
+        wxSize sz = item->GetParent()->ConvertPixelsToDialog(wxSize(firstW, firstH));
+        firstW = sz.x; firstH = sz.y;
+      }
+      resource->SetSize(resource->GetX(), resource->GetY(), firstW, firstH);
+
+       }
   }
   win->Refresh();
 }
@@ -1931,30 +1961,30 @@ wxWindowPropertyInfo *wxResourceManager::CreatePropertyInfoForWindow(wxWindow *w
         {
           info = new wxRadioButtonPropertyInfo(win);
         }
-  else if (win->IsKindOf(CLASSINFO(wxChoice)))
-        {
-          info = new wxChoicePropertyInfo(win);
-        }
   else if (win->IsKindOf(CLASSINFO(wxComboBox)))
         {
           info = new wxComboBoxPropertyInfo(win);
         }
-  else if (win->IsKindOf(CLASSINFO(wxButton)))
+  else if (win->IsKindOf(CLASSINFO(wxChoice)))
         {
-          info = new wxButtonPropertyInfo(win);
+          info = new wxChoicePropertyInfo(win);
         }
   else if (win->IsKindOf(CLASSINFO(wxBitmapButton)))
         {
           info = new wxBitmapButtonPropertyInfo(win);
         }
-  else if (win->IsKindOf(CLASSINFO(wxStaticText)))
+  else if (win->IsKindOf(CLASSINFO(wxButton)))
         {
-          info = new wxStaticTextPropertyInfo(win);
+          info = new wxButtonPropertyInfo(win);
         }
   else if (win->IsKindOf(CLASSINFO(wxStaticBitmap)))
         {
           info = new wxStaticBitmapPropertyInfo(win);
         }
+  else if (win->IsKindOf(CLASSINFO(wxStaticText)))
+        {
+          info = new wxStaticTextPropertyInfo(win);
+        }
   else if (win->IsKindOf(CLASSINFO(wxTextCtrl)))
         {
           info = new wxTextPropertyInfo(win);
@@ -2031,6 +2061,7 @@ BEGIN_EVENT_TABLE(wxResourceEditorFrame, wxFrame)
     EVT_MENU(RESED_DELETE, wxResourceEditorFrame::OnDeleteSelection)
     EVT_MENU(RESED_RECREATE, wxResourceEditorFrame::OnRecreateSelection)
     EVT_MENU(RESED_TEST, wxResourceEditorFrame::OnTest)
+    EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow)
 END_EVENT_TABLE()
 
 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title,
@@ -2076,8 +2107,8 @@ void wxResourceEditorFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event))
 
 void wxResourceEditorFrame::OnExit(wxCommandEvent& WXUNUSED(event))
 {
-         manager->Clear(TRUE, FALSE) ;
-      this->Close();
+      manager->Clear(TRUE, FALSE) ;
+      this->Destroy();
 }
 
 void wxResourceEditorFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
@@ -2112,12 +2143,15 @@ void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& WXUNUSED(event))
       manager->RecreateSelection();
 }
 
-bool wxResourceEditorFrame::OnClose()
+void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent& event)
 {
   if (manager->Modified())
   {
-  if (!manager->Clear(TRUE, FALSE))
-     return FALSE;
+     if (!manager->Clear(TRUE, FALSE))
+     {
+       event.Veto();
+       return;
+    }
   }
     
   if (!Iconized())
@@ -2136,7 +2170,7 @@ bool wxResourceEditorFrame::OnClose()
   manager->SetEditorFrame(NULL);
   manager->SetEditorToolBar(NULL);
 
-  return TRUE;
+  this->Destroy();
 }
 
 /*
@@ -2144,7 +2178,6 @@ bool wxResourceEditorFrame::OnClose()
  */
 
 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow, wxScrolledWindow)
-    EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll)
     EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint)
 END_EVENT_TABLE()
 
@@ -2155,21 +2188,12 @@ wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow *parent,
     m_marginX = 10;
     m_marginY = 40;
     m_childWindow = NULL;
-}
 
-wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
-{
+    SetBackgroundColour(* wxWHITE);
 }
 
-void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent& event)
+wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
 {
-    wxScrolledWindow::OnScroll(event);
-
-    int x, y;
-    ViewStart(& x, & y);
-
-    if (m_childWindow)
-        m_childWindow->Move(m_marginX + (- x * 10), m_marginY + (- y * 10));
 }
 
 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
@@ -2234,19 +2258,10 @@ void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event)
  *
  */
 
-#ifdef __WXGTK__   // I don't dare to delete it...
 BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar)
+//     EVT_PAINT(EditorToolBar::OnPaint)
 END_EVENT_TABLE()
 
-#else
-
-BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar)
-       EVT_PAINT(EditorToolBar::OnPaint)
-END_EVENT_TABLE()
-
-#endif
-
 EditorToolBar::EditorToolBar(wxFrame *frame, const wxPoint& pos, const wxSize& size,
             long style):
   wxToolBar(frame, -1, pos, size, style)