| 1 | /* $Id: filetitle.c,v 1.3 2000-08-02 15:11:59 bird Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * COMMDLG - File Dialogs
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1994 Martin Ayotte
|
|---|
| 6 | * Copyright 1996 Albrecht Kleine
|
|---|
| 7 | *
|
|---|
| 8 | * Corel WINE 20000324 level
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | #include <string.h>
|
|---|
| 12 |
|
|---|
| 13 | #include "wine/winestring.h"
|
|---|
| 14 | #include "winbase.h"
|
|---|
| 15 | #include "commdlg.h"
|
|---|
| 16 | #include "debugtools.h"
|
|---|
| 17 |
|
|---|
| 18 | #include "heap.h" /* Has to go */
|
|---|
| 19 |
|
|---|
| 20 | DEFAULT_DEBUG_CHANNEL(commdlg)
|
|---|
| 21 |
|
|---|
| 22 | #include "cdlg.h"
|
|---|
| 23 |
|
|---|
| 24 | #ifdef __WIN32OS2__
|
|---|
| 25 | #include <misc.h>
|
|---|
| 26 | #endif
|
|---|
| 27 |
|
|---|
| 28 | /***********************************************************************
|
|---|
| 29 | * GetFileTitleA (COMDLG32.8)
|
|---|
| 30 | *
|
|---|
| 31 | */
|
|---|
| 32 | short WINAPI GetFileTitleA(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
|
|---|
| 33 | {
|
|---|
| 34 | int i, len;
|
|---|
| 35 |
|
|---|
| 36 | TRACE("(%p %p %d); \n", lpFile, lpTitle, cbBuf);
|
|---|
| 37 |
|
|---|
| 38 | if(lpFile == NULL || (lpTitle == NULL))
|
|---|
| 39 | return -1;
|
|---|
| 40 |
|
|---|
| 41 | len = strlen(lpFile);
|
|---|
| 42 |
|
|---|
| 43 | if (len == 0)
|
|---|
| 44 | return -1;
|
|---|
| 45 |
|
|---|
| 46 | if(strpbrk(lpFile, "*[]"))
|
|---|
| 47 | return -1;
|
|---|
| 48 |
|
|---|
| 49 | len--;
|
|---|
| 50 |
|
|---|
| 51 | if(lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
|
|---|
| 52 | return -1;
|
|---|
| 53 |
|
|---|
| 54 | for(i = len; i >= 0; i--)
|
|---|
| 55 | {
|
|---|
| 56 | if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
|
|---|
| 57 | {
|
|---|
| 58 | i++;
|
|---|
| 59 | break;
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | if(i == -1)
|
|---|
| 64 | i++;
|
|---|
| 65 |
|
|---|
| 66 | TRACE("---> '%s' \n", &lpFile[i]);
|
|---|
| 67 |
|
|---|
| 68 | len = strlen(lpFile+i)+1;
|
|---|
| 69 | if(cbBuf < len)
|
|---|
| 70 | return len;
|
|---|
| 71 |
|
|---|
| 72 | strncpy(lpTitle,&lpFile[i],len);
|
|---|
| 73 | return 0;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | /***********************************************************************
|
|---|
| 78 | * GetFileTitleW (COMDLG32.9)
|
|---|
| 79 | *
|
|---|
| 80 | */
|
|---|
| 81 | short WINAPI GetFileTitleW(LPCWSTR lpFile, LPWSTR lpTitle, UINT cbBuf)
|
|---|
| 82 | {
|
|---|
| 83 | LPSTR file = HEAP_strdupWtoA(GetProcessHeap(), 0, lpFile); /* Has to go */
|
|---|
| 84 | LPSTR title = HeapAlloc(GetProcessHeap(), 0, cbBuf);
|
|---|
| 85 | short ret;
|
|---|
| 86 |
|
|---|
| 87 | ret = GetFileTitleA(file, title, cbBuf);
|
|---|
| 88 |
|
|---|
| 89 | lstrcpynAtoW(lpTitle, title, cbBuf);
|
|---|
| 90 | HeapFree(GetProcessHeap(), 0, file);
|
|---|
| 91 | HeapFree(GetProcessHeap(), 0, title);
|
|---|
| 92 | return ret;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | /***********************************************************************
|
|---|
| 97 | * GetFileTitle16 (COMMDLG.27)
|
|---|
| 98 | */
|
|---|
| 99 | short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
|
|---|
| 100 | {
|
|---|
| 101 | return GetFileTitleA(lpFile, lpTitle, cbBuf);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|