]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Save the alpha values if the image has an alpha channel
[wxWidgets.git] / src / common / docview.cpp
index 65e74723ad97b12bcc4d11c8db09d6aa280ecf74..38dd2f9363df35587b92005b94f1b8d980f60289 100644 (file)
@@ -80,7 +80,7 @@
 #endif
 
 // ----------------------------------------------------------------------------
-// wxWindows macros
+// wxWidgets macros
 // ----------------------------------------------------------------------------
 
 IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler)
@@ -253,11 +253,42 @@ bool wxDocument::SaveAs()
     if (!docTemplate)
         return FALSE;
 
+#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
+    wxString filter = docTemplate->GetDescription() + wxT(" (") + docTemplate->GetFileFilter() + wxT(")|") + docTemplate->GetFileFilter();
+
+    // Now see if there are some other template with identical view and document
+    // classes, whose filters may also be used.
+
+    if (docTemplate->GetViewClassInfo() && docTemplate->GetDocClassInfo())
+    {
+        wxList::compatibility_iterator node = wxDocManager::GetDocumentManager()->GetTemplates().GetFirst();
+        while (node)
+        {
+            wxDocTemplate *t = (wxDocTemplate*) node->GetData();
+            
+            if (t->IsVisible() && t != docTemplate &&
+                t->GetViewClassInfo() == docTemplate->GetViewClassInfo() &&
+                t->GetDocClassInfo() == docTemplate->GetDocClassInfo())
+            {
+                // add a '|' to separate this filter from the previous one
+                if ( !filter.IsEmpty() )
+                    filter << wxT('|');
+                
+                filter << t->GetDescription() << wxT(" (") << t->GetFileFilter() << wxT(") |")
+                       << t->GetFileFilter();
+            }
+
+            node = node->GetNext();
+        }
+    }
+#else
+    wxString filter = docTemplate->GetFileFilter() ;
+#endif
     wxString tmp = wxFileSelector(_("Save as"),
             docTemplate->GetDirectory(),
             wxFileNameFromPath(GetFilename()),
             docTemplate->GetDefaultExtension(),
-            docTemplate->GetFileFilter(),
+            filter,
             wxSAVE | wxOVERWRITE_PROMPT,
             GetDocumentWindow());
 
@@ -691,18 +722,31 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
     if (!m_docClassInfo)
         return (wxDocument *) NULL;
     wxDocument *doc = (wxDocument *)m_docClassInfo->CreateObject();
+    
+    if (InitDocument(doc, path, flags))
+    {
+        return doc;
+    }
+    else
+    {
+        return (wxDocument *) NULL;
+    }
+}
+
+bool wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags)
+{
     doc->SetFilename(path);
     doc->SetDocumentTemplate(this);
     GetDocumentManager()->AddDocument(doc);
     doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
 
     if (doc->OnCreate(path, flags))
-        return doc;
+        return true;
     else
     {
         if (GetDocumentManager()->GetDocuments().Member(doc))
             doc->DeleteAllViews();
-        return (wxDocument *) NULL;
+        return false;
     }
 }