Changed CBGetDroppedControlRect to be compliant with Windows API.
[wine/testsucceed.git] / dlls / commdlg / filetitle.c
blob4f93534b1b313a19a5ebfc3f1aa65365d9f1c891
1 /*
2 * COMMDLG - File Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
8 #include <string.h>
10 #include "winbase.h"
11 #include "commdlg.h"
12 #include "debug.h"
14 #include "heap.h" /* Has to go */
16 DEFAULT_DEBUG_CHANNEL(commdlg)
18 #include "cdlg.h"
20 /***********************************************************************
21 * GetFileTitleA (COMDLG32.8)
24 short WINAPI GetFileTitleA(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
26 int i, len;
28 TRACE(commdlg,"(%p %p %d); \n", lpFile, lpTitle, cbBuf);
30 if(lpFile == NULL || lpTitle == NULL)
31 return -1;
33 len = strlen(lpFile);
35 if (len == 0)
36 return -1;
38 if(strpbrk(lpFile, "*[]"))
39 return -1;
41 len--;
43 if(lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
44 return -1;
46 for(i = len; i >= 0; i--)
48 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
50 i++;
51 break;
55 if(i == -1)
56 i++;
58 TRACE(commdlg,"---> '%s' \n", &lpFile[i]);
60 len = strlen(lpFile+i)+1;
61 if(cbBuf < len)
62 return len;
64 strncpy(lpTitle, &lpFile[i], len);
65 return 0;
69 /***********************************************************************
70 * GetFileTitleW (COMDLG32.9)
73 short WINAPI GetFileTitleW(LPCWSTR lpFile, LPWSTR lpTitle, UINT cbBuf)
75 LPSTR file = HEAP_strdupWtoA(GetProcessHeap(), 0, lpFile); /* Has to go */
76 LPSTR title = HeapAlloc(GetProcessHeap(), 0, cbBuf);
77 short ret;
79 ret = GetFileTitleA(file, title, cbBuf);
81 lstrcpynAtoW(lpTitle, title, cbBuf);
82 HeapFree(GetProcessHeap(), 0, file);
83 HeapFree(GetProcessHeap(), 0, title);
84 return ret;
88 /***********************************************************************
89 * GetFileTitle16 (COMMDLG.27)
91 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
93 return GetFileTitleA(lpFile, lpTitle, cbBuf);