294 missing WINAPI added.
[wine] / misc / commdlg.c
index 03e57f9..5c82b6b 100644 (file)
@@ -5,6 +5,7 @@
  * Copyright 1996 Albrecht Kleine
  */
 
+#include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 #include "win.h"
@@ -33,7 +34,7 @@ static const char defaultfilter[]=" \0\0";
 /***********************************************************************
  *                             FileDlg_Init                    [internal]
  */
-static BOOL32 FileDlg_Init()
+static BOOL32 FileDlg_Init(void)
 {
     static BOOL32 initialized = 0;
     
@@ -73,7 +74,7 @@ BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
     if (lpofn->Flags & OFN_WINE32) {
            if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
            {
-               if (!(template = LockResource32( lpofn->hInstance )))
+               if (!(template = LockResource32( MapHModuleSL(lpofn->hInstance ))))
                {
                    CommDlgLastError = CDERR_LOADRESFAILURE;
                    return FALSE;
@@ -81,13 +82,14 @@ BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
            }
            else if (lpofn->Flags & OFN_ENABLETEMPLATE)
            {
-               if (!(hResInfo = FindResource32A(lpofn->hInstance,
+               if (!(hResInfo = FindResource32A(MapHModuleSL(lpofn->hInstance),
                                                PTR_SEG_TO_LIN(lpofn->lpTemplateName), RT_DIALOG32A)))
                {
                    CommDlgLastError = CDERR_FINDRESFAILURE;
                    return FALSE;
                }
-               if (!(hDlgTmpl = LoadResource32( lpofn->hInstance, hResInfo )) ||
+               if (!(hDlgTmpl = LoadResource32( MapHModuleSL(lpofn->hInstance),
+                                                hResInfo )) ||
                    !(template = LockResource32( hDlgTmpl )))
                {
                    CommDlgLastError = CDERR_LOADRESFAILURE;
@@ -198,7 +200,7 @@ BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
     if (lpofn->Flags & OFN_WINE32) {
            if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
            {
-               if (!(template = LockResource32( lpofn->hInstance )))
+               if (!(template = LockResource32( MapHModuleSL(lpofn->hInstance ))))
                {
                    CommDlgLastError = CDERR_LOADRESFAILURE;
                    return FALSE;
@@ -207,14 +209,15 @@ BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
            else if (lpofn->Flags & OFN_ENABLETEMPLATE)
            {
                HANDLE32 hResInfo;
-               if (!(hResInfo = FindResource32A(lpofn->hInstance,
+               if (!(hResInfo = FindResource32A(MapHModuleSL(lpofn->hInstance),
                                                 PTR_SEG_TO_LIN(lpofn->lpTemplateName),
                                                  RT_DIALOG32A)))
                {
                    CommDlgLastError = CDERR_FINDRESFAILURE;
                    return FALSE;
                }
-               if (!(hDlgTmpl = LoadResource32(lpofn->hInstance,hResInfo)) ||
+               if (!(hDlgTmpl = LoadResource32(MapHModuleSL(lpofn->hInstance),
+                                               hResInfo)) ||
                    !(template = LockResource32(hDlgTmpl)))
                {
                    CommDlgLastError = CDERR_LOADRESFAILURE;
@@ -331,15 +334,46 @@ static void FILEDLG_StripEditControl(HWND16 hwnd)
  */
 static BOOL32 FILEDLG_ScanDir(HWND16 hWnd, LPSTR newPath)
 {
-    int len;
-    char str[512];
+    char               buffer[512];
+        char*                  str = buffer;
+    int                        drive;
+    HWND32             hlb;
 
-    lstrcpyn32A( str, newPath, 512 );
-    len = strlen(str);
-    GetDlgItemText32A( hWnd, edt1, str + len, sizeof(str) - len );
-    if (!DlgDirList32A( hWnd, str, lst1, 0, 0x0000 )) return FALSE;
-    strcpy( str, "*.*" );
-    return DlgDirList32A( hWnd, str, lst2, stc1, 0x8010 );
+    lstrcpyn32A(buffer, newPath, sizeof(buffer));
+
+    if (str[0] && (str[1] == ':')) {
+        drive = toupper(str[0]) - 'A';
+        str += 2;
+        if (!DRIVE_SetCurrentDrive(drive)) 
+                         return FALSE;
+    } else {
+                drive = DRIVE_GetCurrentDrive();
+        }
+
+    if (str[0] && !DRIVE_Chdir(drive, str)) {
+                return FALSE;
+    }
+
+    GetDlgItemText32A(hWnd, edt1, buffer, sizeof(buffer));
+    if ((hlb = GetDlgItem32(hWnd, lst1)) != 0) {
+                char*  scptr; /* ptr on semi-colon */
+                char*  filter = buffer;
+
+                TRACE(commdlg, "Using filter %s\n", filter);
+                SendMessage32A(hlb, LB_RESETCONTENT32, 0, 0);
+                while (filter) {
+                        scptr = strchr(filter, ';');
+                        if (scptr)     *scptr = 0;
+                        TRACE(commdlg, "Using file spec %s\n", filter);
+                        if (SendMessage32A(hlb, LB_DIR32, 0, (LPARAM)filter) == LB_ERR)
+                                return FALSE;
+                        if (scptr) *scptr = ';';
+                        filter = (scptr) ? (scptr + 1) : 0;
+                }
+        }
+
+    strcpy(buffer, "*.*");
+    return DlgDirList32A(hWnd, buffer, lst2, stc1, 0x8010);
 }
 
 /***********************************************************************
@@ -391,11 +425,13 @@ static LONG FILEDLG_WMDrawItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam,int s
                       (LPARAM)SEGPTR_GET(str));
 
        if (savedlg)       /* use _gray_ text in FileSaveDlg */
+        {
          if (!lpdis->itemState)
            SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_GRAYTEXT) );
          else  
            SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_WINDOWTEXT) );
            /* inversion of gray would be bad readable */                 
+        }
 
        TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
                   str, strlen(str));
@@ -791,7 +827,7 @@ static LRESULT FILEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
       lpofn->nFileExtension = 0;
       while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
         lpofn->nFileExtension++;
-      if (lpofn->nFileExtension == '\0')
+      if (tmpstr2[lpofn->nFileExtension] == '\0')
        lpofn->nFileExtension = 0;
       else
        lpofn->nFileExtension++;
@@ -1446,8 +1482,14 @@ BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
  */
 BOOL32 WINAPI PrintDlg32A( LPPRINTDLG32A printdlg )
 {
-    FIXME(commdlg, "empty stub\n" );
-    return FALSE;
+    FIXME(commdlg, "(%p): stub\n",printdlg);
+    /* Altough returning FALSE is theoricaly the right thing
+     * most programs check for a printer at startup, and if
+     * none is found popup PrintDlg32A(), if it fails the program
+     * terminates; by returning TRUE the programs can still run
+     * as long as no printer related stuff is used
+     */ 
+    return TRUE;
 }
 
 
@@ -1547,6 +1589,8 @@ short WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
        i++;
        break;
     }
+    if (i == -1)
+      i++;
     TRACE(commdlg,"---> '%s' \n", &lpFile[i]);
     
     len = strlen(lpFile+i)+1;
@@ -2244,7 +2288,7 @@ static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
  EnableWindow32(GetDlgItem32(hDlg,0x2c8),TRUE);
 
  if (lprect)
-  SetWindowPos32(hDlg,NULL,0,0,lprect->right-lprect->left,
+  SetWindowPos32(hDlg,0,0,0,lprect->right-lprect->left,
    lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
 
  ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_SHOW);
@@ -2405,7 +2449,7 @@ static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
       ScreenToClient16(hDlg,&point);
       GetClientRect16(hDlg,&rect);
       point.x+=GetSystemMetrics32(SM_CXDLGFRAME);
-      SetWindowPos32(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
+      SetWindowPos32(hDlg,0,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
 
       ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_HIDE);
       ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_HIDE);
@@ -3523,7 +3567,7 @@ LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
                         FIXME(commdlg, "current logfont back to caller\n");
                         break;
     }
-  WINPROC_UnmapMsg16To32A(uMsg32, wParam32, lParam, res);    
+  WINPROC_UnmapMsg16To32A(hDlg,uMsg32, wParam32, lParam, res);    
   return res;
 }
 
@@ -3631,7 +3675,7 @@ LRESULT WINAPI FormatCharDlgProc32W(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
 }
 
 
-static BOOL32 Commdlg_GetFileName32A( BOOL16 (*dofunction)(),
+static BOOL32 Commdlg_GetFileName32A( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
                                       LPOPENFILENAME32A ofn )
 {
        BOOL16 ret;
@@ -3640,8 +3684,7 @@ static BOOL32 Commdlg_GetFileName32A( BOOL16 (*dofunction)(),
        memset(ofn16,'\0',sizeof(*ofn16));
        ofn16->lStructSize = sizeof(*ofn16);
        ofn16->hwndOwner = ofn->hwndOwner;
-       /* FIXME: OPENFILENAME16 got only 16 bit for HINSTANCE... */
-       ofn16->hInstance = 0;
+       ofn16->hInstance = MapHModuleLS(ofn->hInstance);
        if (ofn->lpstrFilter) {
                LPSTR   s,x;
 
@@ -3661,8 +3704,8 @@ static BOOL32 Commdlg_GetFileName32A( BOOL16 (*dofunction)(),
                s = (LPSTR)ofn->lpstrCustomFilter;
                while (*s)
                        s = s+strlen(s)+1;
-               x = SEGPTR_ALLOC(s-ofn->lpstrCustomFilter);
                s++;
+               x = SEGPTR_ALLOC(s-ofn->lpstrCustomFilter);
                memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);
                ofn16->lpstrCustomFilter = SEGPTR_GET(x);
        }
@@ -3721,7 +3764,7 @@ static BOOL32 Commdlg_GetFileName32A( BOOL16 (*dofunction)(),
        return ret;
 }
 
-static BOOL32 Commdlg_GetFileName32W( BOOL16 (*dofunction)(), 
+static BOOL32 Commdlg_GetFileName32W( BOOL16 (CALLBACK *dofunction)(SEGPTR x), 
                                       LPOPENFILENAME32W ofn )
 {
        BOOL16 ret;
@@ -3730,8 +3773,7 @@ static BOOL32 Commdlg_GetFileName32W( BOOL16 (*dofunction)(),
        memset(ofn16,'\0',sizeof(*ofn16));
        ofn16->lStructSize = sizeof(*ofn16);
        ofn16->hwndOwner = ofn->hwndOwner;
-       /* FIXME: OPENFILENAME16 got only 16 bit for HINSTANCE... */
-       ofn16->hInstance = 0;
+       ofn16->hInstance = MapHModuleLS(ofn->hInstance);
        if (ofn->lpstrFilter) {
                LPWSTR  s;
                LPSTR   x,y;
@@ -3830,7 +3872,7 @@ static BOOL32 Commdlg_GetFileName32W( BOOL16 (*dofunction)(),
  */
 BOOL32 WINAPI GetOpenFileName32A( LPOPENFILENAME32A ofn )
 {
-   BOOL16 (WINAPI * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
+   BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
    return Commdlg_GetFileName32A(dofunction,ofn);
 }
 
@@ -3839,7 +3881,7 @@ BOOL32 WINAPI GetOpenFileName32A( LPOPENFILENAME32A ofn )
  */
 BOOL32 WINAPI GetOpenFileName32W( LPOPENFILENAME32W ofn )
 {
-   BOOL16 (WINAPI * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
+   BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
    return Commdlg_GetFileName32W(dofunction,ofn);
 }
 
@@ -3848,7 +3890,7 @@ BOOL32 WINAPI GetOpenFileName32W( LPOPENFILENAME32W ofn )
  */
 BOOL32 WINAPI GetSaveFileName32A( LPOPENFILENAME32A ofn )
 {
-   BOOL16 (WINAPI * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
+   BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
    return Commdlg_GetFileName32A(dofunction,ofn);
 }
 
@@ -3857,7 +3899,7 @@ BOOL32 WINAPI GetSaveFileName32A( LPOPENFILENAME32A ofn )
  */
 BOOL32 WINAPI GetSaveFileName32W( LPOPENFILENAME32W ofn )
 {
-   BOOL16 (WINAPI * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
+   BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
    return Commdlg_GetFileName32W(dofunction,ofn);
 }
 
@@ -3875,7 +3917,7 @@ BOOL32 WINAPI ChooseColor32A(LPCHOOSECOLOR32A lpChCol )
   memset(lpcc16,'\0',sizeof(*lpcc16));
   lpcc16->lStructSize=sizeof(*lpcc16);
   lpcc16->hwndOwner=lpChCol->hwndOwner;
-  lpcc16->hInstance=0; /* FIXME:MODULE_HANDLEtoHMODULE16(lpChCol->hInstance)*/
+  lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
   lpcc16->rgbResult=lpChCol->rgbResult;
   memcpy(ccref,lpChCol->lpCustColors,64);
   lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
@@ -3909,7 +3951,7 @@ BOOL32 WINAPI ChooseColor32W(LPCHOOSECOLOR32W lpChCol )
   memset(lpcc16,'\0',sizeof(*lpcc16));
   lpcc16->lStructSize=sizeof(*lpcc16);
   lpcc16->hwndOwner=lpChCol->hwndOwner;
-  lpcc16->hInstance=0; /*FIXME:MODULE_HANDLEtoHMODULE16(lpChCol->hInstance)*/
+  lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
   lpcc16->rgbResult=lpChCol->rgbResult;
   memcpy(ccref,lpChCol->lpCustColors,64);
   lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);