- changed STRRET definition
[wine] / dlls / commdlg / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <string.h>
23
24 #include "winbase.h"
25 #include "winnls.h"
26 #include "commdlg.h"
27 #include "wine/debug.h"
28
29 #include "heap.h"       /* Has to go */
30
31 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
32
33 #include "cdlg.h"
34
35 /***********************************************************************
36  *      GetFileTitleA           (COMDLG32.@)
37  *
38  */
39 short WINAPI GetFileTitleA(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
40 {
41         int i, len;
42
43         TRACE("(%p %p %d); \n", lpFile, lpTitle, cbBuf);
44
45         if(lpFile == NULL || lpTitle == NULL)
46                 return -1;
47
48         len = strlen(lpFile);
49
50         if (len == 0)
51                 return -1;
52
53         if(strpbrk(lpFile, "*[]"))
54                 return -1;
55
56         len--;
57
58         if(lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
59                 return -1;
60
61         for(i = len; i >= 0; i--)
62         {
63                 if (lpFile[i] == '/' ||  lpFile[i] == '\\' ||  lpFile[i] == ':')
64                 {
65                         i++;
66                         break;
67                 }
68         }
69
70         if(i == -1)
71                 i++;
72
73         TRACE("---> '%s' \n", &lpFile[i]);
74
75         len = strlen(lpFile+i)+1;
76         if(cbBuf < len)
77                 return len;
78
79         strncpy(lpTitle, &lpFile[i], len);
80         return 0;
81 }
82
83
84 /***********************************************************************
85  *      GetFileTitleW           (COMDLG32.@)
86  *
87  */
88 short WINAPI GetFileTitleW(LPCWSTR lpFile, LPWSTR lpTitle, UINT cbBuf)
89 {
90         LPSTR file = HEAP_strdupWtoA(GetProcessHeap(), 0, lpFile);      /* Has to go */
91         LPSTR title = HeapAlloc(GetProcessHeap(), 0, cbBuf);
92         short   ret;
93
94         ret = GetFileTitleA(file, title, cbBuf);
95
96         if (cbBuf > 0 && !MultiByteToWideChar( CP_ACP, 0, title, -1, lpTitle, cbBuf ))
97             lpTitle[cbBuf-1] = 0;
98         HeapFree(GetProcessHeap(), 0, file);
99         HeapFree(GetProcessHeap(), 0, title);
100         return ret;
101 }
102
103
104 /***********************************************************************
105  *      GetFileTitle            (COMMDLG.27)
106  */
107 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
108 {
109         return GetFileTitleA(lpFile, lpTitle, cbBuf);
110 }
111