]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/filedlg.cpp
add accessors for sockaddr to wxSockAddress (closes #10511)
[wxWidgets.git] / src / msw / filedlg.cpp
index b788f8a7cf3a393eaea48b82de1d00a2f7c58848..ae89ed5c05eb056991ca228c97e798a7132e10d4 100644 (file)
@@ -86,12 +86,22 @@ wxFileDialogHookFunction(HWND      hDlg,
 {
     switch ( iMsg )
     {
+#ifndef __WXWINCE__
+        case WM_INITDIALOG:
+            {
+                OPENFILENAME* ofn = reinterpret_cast<OPENFILENAME *>(lParam);
+                reinterpret_cast<wxFileDialog *>(ofn->lCustData)
+                    ->MSWOnInitDialogHook((WXHWND)hDlg);
+            }
+            break;
+#endif // __WXWINCE__
+
         case WM_NOTIFY:
             {
-                OFNOTIFY *pNotifyCode = wx_reinterpret_cast(OFNOTIFY *, lParam);
+                OFNOTIFY *pNotifyCode = reinterpret_cast<OFNOTIFY *>(lParam);
                 if ( pNotifyCode->hdr.code == CDN_INITDONE )
                 {
-                    wx_reinterpret_cast(wxFileDialog *,
+                    reinterpret_cast<wxFileDialog *>(
                                         pNotifyCode->lpOFN->lCustData)
                         ->MSWOnInitDone((WXHWND)hDlg);
                  }
@@ -167,7 +177,7 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const
 void wxFileDialog::SetPath(const wxString& path)
 {
     wxString ext;
-    wxSplitPath(path, &m_dir, &m_fileName, &ext);
+    wxFileName::SplitPath(path, &m_dir, &m_fileName, &ext);
     if ( !ext.empty() )
         m_fileName << _T('.') << ext;
 }
@@ -360,6 +370,17 @@ static bool ShowCommFileDialog(OPENFILENAME *of, long style)
     return true;
 }
 
+#ifndef __WXWINCE__
+void wxFileDialog::MSWOnInitDialogHook(WXHWND hwnd)
+{
+   SetHWND(hwnd);
+
+   CreateExtraControl();
+
+   SetHWND(NULL);
+}
+#endif // __WXWINCE__
+
 int wxFileDialog::ShowModal()
 {
     HWND hWnd = 0;
@@ -385,7 +406,7 @@ int wxFileDialog::ShowModal()
         in the upper left of the frame, it does not center
         automatically.
     */
-    if (m_bMovedWindow) // we need these flags.
+    if (m_bMovedWindow || HasExtraControlCreator()) // we need these flags.
     {
         msw_flags |= OFN_EXPLORER|OFN_ENABLEHOOK;
 #ifndef __WXWINCE__
@@ -421,6 +442,37 @@ int wxFileDialog::ShowModal()
     of.lpstrFileTitle    = titleBuffer;
     of.nMaxFileTitle     = wxMAXFILE + 1 + wxMAXEXT;
 
+#ifndef __WXWINCE__
+    GlobalPtr hgbl;
+    if ( HasExtraControlCreator() )
+    {
+        msw_flags |= OFN_ENABLETEMPLATEHANDLE;
+
+        hgbl.Init(256, GMEM_ZEROINIT);
+        GlobalPtrLock hgblLock(hgbl);
+        LPDLGTEMPLATE lpdt = static_cast<LPDLGTEMPLATE>(hgblLock.Get());
+
+        // Define a dialog box.
+
+        lpdt->style = DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS;
+        lpdt->cdit = 0;         // Number of controls
+        lpdt->x = 0;
+        lpdt->y = 0;
+
+        wxSize extra_size = GetExtraControlSize();
+        // setting cx doesn't change the width of the dialog
+        lpdt->cx = extra_size.GetWidth();
+        // Dividing by 2 gives expected height on WinXP and Wine.
+        // I don't know why (MW).
+        lpdt->cy = extra_size.GetHeight() / 2;
+
+        // after the DLGTEMPLATE there are 3 additional WORDs for dialog menu,
+        // class and title, all three set to zeros.
+
+        of.hInstance = (HINSTANCE)lpdt;
+    }
+#endif // __WXWINCE__
+
     // Convert forward slashes to backslashes (file selector doesn't like
     // forward slashes) and also squeeze multiple consecutive slashes into one
     // as it doesn't like two backslashes in a row neither
@@ -494,8 +546,7 @@ int wxFileDialog::ShowModal()
 
     //=== Setting defaultFileName >>=========================================
 
-    wxStrncpy(fileNameBuffer, m_fileName, wxMAXPATH-1);
-    fileNameBuffer[ wxMAXPATH-1 ] = wxT('\0');
+    wxStrlcpy(fileNameBuffer, m_fileName.c_str(), WXSIZEOF(fileNameBuffer));
 
     of.lpstrFile = fileNameBuffer;  // holds returned filename
     of.nMaxFile  = wxMAXPATH;
@@ -596,8 +647,7 @@ int wxFileDialog::ShowModal()
                 extension = extension + wxStrlen( extension ) + 1;
 
             m_fileName = AppendExtension(fileNameBuffer, extension);
-            wxStrncpy(fileNameBuffer, m_fileName.c_str(), wxMin(m_fileName.length(), wxMAXPATH-1));
-            fileNameBuffer[wxMin(m_fileName.length(), wxMAXPATH-1)] = wxT('\0');
+            wxStrlcpy(fileNameBuffer, m_fileName.c_str(), WXSIZEOF(fileNameBuffer));
         }
 
         m_path = fileNameBuffer;