- move wine includes to precomp.h
[reactos.git] / reactos / dll / win32 / comdlg32 / filetitle.c
1 /*
2 * COMMDLG - File Dialogs
3 *
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <precomp.h>
23
24 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
25
26 /***********************************************************************
27 * GetFileTitleA (COMDLG32.@)
28 *
29 * See GetFileTitleW.
30 */
31 short WINAPI GetFileTitleA(LPCSTR lpFile, LPSTR lpTitle, WORD cbBuf)
32 {
33 int ret;
34 UNICODE_STRING strWFile;
35 LPWSTR lpWTitle;
36
37 RtlCreateUnicodeStringFromAsciiz(&strWFile, lpFile);
38 lpWTitle = HeapAlloc( GetProcessHeap(), 0, cbBuf*sizeof(WCHAR));
39 ret = GetFileTitleW(strWFile.Buffer, lpWTitle, cbBuf);
40 if (!ret) WideCharToMultiByte( CP_ACP, 0, lpWTitle, -1, lpTitle, cbBuf, NULL, NULL );
41 RtlFreeUnicodeString( &strWFile );
42 HeapFree( GetProcessHeap(), 0, lpWTitle );
43 return ret;
44 }
45
46
47 /***********************************************************************
48 * GetFileTitleW (COMDLG32.@)
49 *
50 * Get the name of a file.
51 *
52 * PARAMS
53 * lpFile [I] name and location of file
54 * lpTitle [O] returned file name
55 * cbBuf [I] buffer size of lpTitle
56 *
57 * RETURNS
58 * Success: zero
59 * Failure: negative number.
60 */
61 short WINAPI GetFileTitleW(LPCWSTR lpFile, LPWSTR lpTitle, WORD cbBuf)
62 {
63 int i, len;
64 static const WCHAR brkpoint[] = {'*','[',']',0};
65 TRACE("(%p %p %d);\n", lpFile, lpTitle, cbBuf);
66
67 if(lpFile == NULL || lpTitle == NULL)
68 return -1;
69
70 len = strlenW(lpFile);
71
72 if (len == 0)
73 return -1;
74
75 if(strpbrkW(lpFile, brkpoint))
76 return -1;
77
78 len--;
79
80 if(lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
81 return -1;
82
83 for(i = len; i >= 0; i--)
84 {
85 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
86 {
87 i++;
88 break;
89 }
90 }
91
92 if(i == -1)
93 i++;
94
95 TRACE("---> '%s'\n", debugstr_w(&lpFile[i]));
96
97 len = strlenW(lpFile+i)+1;
98 if(cbBuf < len)
99 return len;
100
101 strcpyW(lpTitle, &lpFile[i]);
102 return 0;
103 }
104
105
106 /***********************************************************************
107 * GetFileTitle (COMMDLG.27)
108 */
109 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
110 {
111 return GetFileTitleA(lpFile, lpTitle, cbBuf);
112 }