Release 950522
[wine.git] / misc / commdlg.c
blobd9a0f31fe2a031f842cc40bf10f03e87a35fc585
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "dialog.h"
11 #include "win.h"
12 #include "user.h"
13 #include "message.h"
14 #include "commdlg.h"
15 #include "dlgs.h"
16 #include "selectors.h"
17 #include "../rc/sysres.h"
19 #define OPENFILEDLG2 11
20 #define SAVEFILEDLG2 12
22 static DWORD CommDlgLastError = 0;
24 static HBITMAP hFolder = 0;
25 static HBITMAP hFolder2 = 0;
26 static HBITMAP hFloppy = 0;
27 static HBITMAP hHDisk = 0;
28 static HBITMAP hCDRom = 0;
30 int DOS_GetDefaultDrive(void);
31 void DOS_SetDefaultDrive(int drive);
32 char *DOS_GetCurrentDir(int drive);
33 int DOS_ChangeDir(int drive, char *dirname);
35 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
36 BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
37 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
38 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
39 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
40 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
41 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
43 /***********************************************************************
44 * COMMDLG_IsPathName [internal]
47 static BOOL COMMDLG_IsPathName(LPSTR str)
49 if (str[strlen(str)-1] == ':' && strlen(str) == 2) return TRUE;
50 if (str[strlen(str)-1] == '\\') return TRUE;
51 if (strchr(str,'*') != NULL) return TRUE;
52 return FALSE;
55 /***********************************************************************
56 * FileDlg_Init [internal]
58 static BOOL FileDlg_Init()
60 if (!hFolder) hFolder = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER));
61 if (!hFolder2) hFolder2 = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2));
62 if (!hFloppy) hFloppy = LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY));
63 if (!hHDisk) hHDisk = LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK));
64 if (!hCDRom) hCDRom = LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM));
65 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
66 hHDisk == 0 || hCDRom == 0)
67 fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
68 return TRUE;
71 /***********************************************************************
72 * OpenDlg_FixDirName [internal]
74 void OpenDlg_FixDirName(LPSTR dirname)
76 char temp[512];
77 char* strp1;
78 char* strp2;
80 strp1=dirname;
81 if( dirname[1] != ':'){
82 temp[0]=(char)((char)DOS_GetDefaultDrive()+'A');
83 temp[1]=':';
84 temp[2]='\\';
85 temp[3]= '\0';
86 strcat(temp, DOS_GetCurrentDir(DOS_GetDefaultDrive()));
87 if(dirname[0]=='.' && dirname[1]=='.') {
88 strp2 = strrchr(temp, '\\');
89 if (strp2 != NULL){
90 *strp2='\0';
91 strp1+=2;
94 strcat(temp, "\\");
95 strcat(temp, strp1);
96 strcpy(dirname, temp);
101 /***********************************************************************
102 * OpenDlg_ScanDir [internal]
104 static BOOL OpenDlg_ScanDir(HWND hWnd, LPSTR newPath)
106 static HANDLE hStr = 0;
107 static LPSTR str = NULL;
108 static SEGPTR str16 = 0;
109 LPSTR strp;
111 OpenDlg_FixDirName(newPath);
112 if (str == NULL) {
113 hStr = GlobalAlloc(0,512);
114 str = GlobalLock(hStr);
115 str16 = WIN16_GlobalLock(hStr);
118 strcpy(str,newPath);
119 DlgDirList(hWnd, str, lst1, 0, 0x0000);
120 strp = strrchr(str,'\\');
121 if (strp == NULL) {
122 if (str[1] == ':') {
123 strp = str+2;
124 } else {
125 strp = str;
127 } else strp++;
128 strcpy(str,strp);
129 SendDlgItemMessage(hWnd,edt1,WM_SETTEXT, 0, str16);
130 strcpy(str,"*.*");
131 DlgDirList(hWnd, str, lst2, stc1, 0x8010);
133 return TRUE;
136 /***********************************************************************
137 * OpenDlg_GetFileType [internal]
139 static LPSTR OpenDlg_GetFileType(LPCSTR types, WORD index)
141 int n;
142 int i = 1;
143 LPSTR ptr = (LPSTR) types;
144 if (ptr == NULL) return NULL;
145 while((n = strlen(ptr)) != 0) {
146 ptr += ++n;
147 if (i++ == index) return ptr;
148 n = strlen(ptr);
149 ptr += ++n;
151 return NULL;
154 /***********************************************************************
155 * GetOpenFileName [COMMDLG.1]
157 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
159 HANDLE hDlgTmpl;
160 HANDLE hResInfo;
161 HINSTANCE hInst;
162 BOOL bRet;
163 LPCSTR dlgTemplate;
165 if (lpofn == NULL) return FALSE;
166 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
167 dlgTemplate = GlobalLock(lpofn->hInstance);
168 if (!dlgTemplate) {
169 CommDlgLastError = CDERR_LOADRESFAILURE;
170 return FALSE;
172 } else {
173 if (lpofn->Flags & OFN_ENABLETEMPLATE) {
174 hInst = lpofn->hInstance;
175 hResInfo = FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG);
176 if (hResInfo == 0) {
177 CommDlgLastError = CDERR_FINDRESFAILURE;
178 return FALSE;
180 hDlgTmpl = LoadResource(hInst, hResInfo);
181 if (hDlgTmpl == 0) {
182 CommDlgLastError = CDERR_LOADRESFAILURE;
183 return FALSE;
185 dlgTemplate = GlobalLock(hDlgTmpl);
186 } else {
187 dlgTemplate = sysres_DIALOG_3;
190 hInst = GetWindowWord(lpofn->hwndOwner, GWW_HINSTANCE);
191 bRet = DialogBoxIndirectParamPtr(hInst, dlgTemplate, lpofn->hwndOwner,
192 GetWndProcEntry16("FileOpenDlgProc"),
193 (DWORD)lpofn);
195 printf("GetOpenFileName // return lpstrFile='%s' !\n",
196 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
197 return bRet;
201 /***********************************************************************
202 * GetSaveFileName [COMMDLG.2]
204 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
206 HANDLE hDlgTmpl;
207 HANDLE hResInfo;
208 HINSTANCE hInst;
209 BOOL bRet;
210 LPCSTR dlgTemplate;
212 if (lpofn == NULL) return FALSE;
213 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
214 dlgTemplate = GlobalLock(lpofn->hInstance);
215 if (!dlgTemplate) {
216 CommDlgLastError = CDERR_LOADRESFAILURE;
217 return FALSE;
219 } else {
220 if (lpofn->Flags & OFN_ENABLETEMPLATE) {
221 hInst = lpofn->hInstance;
222 hResInfo = FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG);
223 if (hResInfo == 0) {
224 CommDlgLastError = CDERR_FINDRESFAILURE;
225 return FALSE;
227 hDlgTmpl = LoadResource(hInst, hResInfo);
228 if (hDlgTmpl == 0) {
229 CommDlgLastError = CDERR_LOADRESFAILURE;
230 return FALSE;
232 dlgTemplate = GlobalLock(hDlgTmpl);
233 } else {
234 dlgTemplate = sysres_DIALOG_4; /* SAVEFILEDIALOG */
237 hInst = GetWindowWord(lpofn->hwndOwner, GWW_HINSTANCE);
238 bRet = DialogBoxIndirectParamPtr(hInst, dlgTemplate, lpofn->hwndOwner,
239 GetWndProcEntry16("FileSaveDlgProc"),
240 (DWORD)lpofn);
241 printf("GetSaveFileName // return lpstrFile='%s' !\n",
242 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
243 return bRet;
247 /***********************************************************************
248 * ChooseColor [COMMDLG.5]
250 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
252 WND *wndPtr;
253 BOOL bRet;
254 wndPtr = WIN_FindWndPtr(lpChCol->hwndOwner);
255 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, sysres_DIALOG_8,
256 lpChCol->hwndOwner, GetWndProcEntry16("ColorDlgProc"),
257 (DWORD)lpChCol);
258 return bRet;
262 /***********************************************************************
263 * FileOpenDlgProc [COMMDLG.6]
265 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
267 int n;
268 LPSTR ptr;
269 LPSTR fspec;
270 WORD wRet;
271 LONG lRet;
272 HBRUSH hBrush;
273 HDC hMemDC;
274 HBITMAP hBitmap;
275 BITMAP bm;
276 LPMEASUREITEMSTRUCT lpmeasure;
277 LPDRAWITEMSTRUCT lpdis;
278 int nDrive;
279 static LPOPENFILENAME lpofn;/* FIXME - this won't multitask */
281 SEGPTR tempsegp;
283 static HANDLE hStr = 0;
284 static LPSTR str = NULL;
285 static SEGPTR str16 = 0;
287 if (str == NULL) {
288 hStr = GlobalAlloc(0,512);
289 str = GlobalLock(hStr);
290 str16 = WIN16_GlobalLock(hStr);
293 switch (wMsg) {
294 case WM_INITDIALOG:
295 printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
296 if (!FileDlg_Init()) return TRUE;
297 SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0);
298 lpofn = (LPOPENFILENAME)lParam;
299 ptr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
300 tempsegp = lpofn->lpstrFilter;
301 while(*ptr) {
302 n = strlen(ptr);
303 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, tempsegp);
304 ptr += n + 1; tempsegp += n + 1;
305 n = strlen(ptr);
306 ptr += n + 1; tempsegp += n + 1;
308 /* set default filter */
309 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
310 lpofn->nFilterIndex - 1, 0L);
311 /* get drive information into combo 2 */
312 strcpy(str,"");
313 DlgDirListComboBox(hWnd, str16, cmb2, 0, 0xC000);
315 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL) {
316 strcpy(str, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir));
317 if (str[strlen(str)-1] != '\\' && str[strlen(str)-1] != ':') {
318 strcat(str,"\\");
320 } else {
321 strcpy(str,"");
323 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
324 if (lRet == LB_ERR) return FALSE;
325 fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
326 strcat(str,fspec);
328 if (!OpenDlg_ScanDir(hWnd, str)) {
329 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
331 /* select current drive in combo */
332 nDrive = DOS_GetDefaultDrive();
333 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
335 ShowWindow(hWnd, SW_SHOWNORMAL);
336 return TRUE;
338 case WM_SHOWWINDOW:
339 if (wParam == 0) break;
340 if (!(lpofn->Flags & OFN_SHOWHELP)) {
341 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
343 if (lpofn->Flags & OFN_HIDEREADONLY) {
344 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
346 return TRUE;
348 case WM_MEASUREITEM:
349 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
350 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
351 lpmeasure->itemHeight = bm.bmHeight;
352 return TRUE;
354 case WM_DRAWITEM:
355 if (lParam == 0L) break;
356 lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
357 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
358 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
359 SelectObject(lpdis->hDC, hBrush);
360 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
361 ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
362 if (ptr == NULL) break;
363 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
364 ptr, strlen(ptr));
365 if (lpdis->itemState != 0) {
366 InvertRect(lpdis->hDC, &lpdis->rcItem);
368 return TRUE;
370 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
371 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
372 SelectObject(lpdis->hDC, hBrush);
373 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
374 ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
375 if (ptr == NULL) break;
376 hBitmap = hFolder;
377 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
378 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
379 lpdis->rcItem.top, ptr, strlen(ptr));
380 hMemDC = CreateCompatibleDC(lpdis->hDC);
381 SelectObject(hMemDC, hBitmap);
382 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
383 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
384 DeleteDC(hMemDC);
385 if (lpdis->itemState != 0) {
386 InvertRect(lpdis->hDC, &lpdis->rcItem);
388 return TRUE;
390 if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
391 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
392 SelectObject(lpdis->hDC, hBrush);
393 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
394 ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
395 if (ptr == NULL) break;
396 switch(ptr[2]) {
397 case 'a': case 'b':
398 hBitmap = hFloppy;
399 break;
400 default:
401 hBitmap = hHDisk;
402 break;
404 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
405 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
406 lpdis->rcItem.top, ptr, strlen(ptr));
407 hMemDC = CreateCompatibleDC(lpdis->hDC);
408 SelectObject(hMemDC, hBitmap);
409 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
410 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
411 DeleteDC(hMemDC);
412 if (lpdis->itemState != 0) {
413 InvertRect(lpdis->hDC, &lpdis->rcItem);
415 return TRUE;
417 break;
419 case WM_COMMAND:
420 switch (wParam) {
421 case lst1:
422 if (HIWORD(lParam) == LBN_DBLCLK) {
423 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
424 if (lRet == LB_ERR) return 0;
425 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, str16);
426 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
427 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
429 break;
430 case lst2:
431 if (HIWORD(lParam) == LBN_DBLCLK) {
432 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
433 if (lRet == LB_ERR) return 0;
434 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet, str16);
436 if (str[0] == '[') {
437 str[strlen(str) - 1] = 0;
438 strcpy(str,str+1);
440 strcat(str,"\\");
441 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
442 if (lRet == LB_ERR) return FALSE;
443 fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
444 strcat(str,"\\"); strcat(str,fspec);
445 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
446 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
448 break;
449 case cmb1:
450 if (HIWORD(lParam) == CBN_SELCHANGE) {
451 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
452 if (lRet == LB_ERR) return FALSE;
453 fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
454 strcpy(str,fspec);
455 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
456 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
458 break;
459 case cmb2:
460 wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
461 if (wRet == (WORD)LB_ERR) return 0;
462 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, str16);
463 str[0] = str[2]; str[1] = ':'; str[2] = 0;
464 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
465 if (lRet == LB_ERR) return FALSE;
466 fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
467 strcat(str,fspec);
468 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
469 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
470 break;
471 case chx1:
472 #ifdef DEBUG_OPENDLG
473 printf("FileOpenDlgProc // read-only toggled !\n");
474 #endif
475 break;
476 case pshHelp:
477 #ifdef DEBUG_OPENDLG
478 printf("FileOpenDlgProc // pshHelp pressed !\n");
479 #endif
480 break;
481 case IDOK:
482 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, str16);
483 if (COMMDLG_IsPathName(str)) {
484 OpenDlg_ScanDir(hWnd, str);
485 } else {
486 ShowWindow(hWnd, SW_HIDE);
487 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), str);
488 lpofn->nFileOffset = 0;
489 lpofn->nFileExtension = strlen(PTR_SEG_TO_LIN(lpofn->lpstrFile)) - 3;
490 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) {
491 wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
492 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, str16);
493 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), str);
495 EndDialog(hWnd, TRUE);
497 return TRUE;
498 case IDCANCEL:
499 EndDialog(hWnd, FALSE);
500 return TRUE;
502 /* return FALSE;*/
506 case WM_CTLCOLOR:
507 SetBkColor((HDC)wParam, 0x00C0C0C0);
508 switch (HIWORD(lParam))
510 case CTLCOLOR_BTN:
511 SetTextColor((HDC)wParam, 0x00000000);
512 return hGRAYBrush;
513 case CTLCOLOR_STATIC:
514 SetTextColor((HDC)wParam, 0x00000000);
515 return hGRAYBrush;
517 return FALSE;
520 return FALSE;
524 /***********************************************************************
525 * FileSaveDlgProc [COMMDLG.7]
527 BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
529 int n;
530 LPSTR ptr;
531 LPSTR fspec;
532 WORD wRet;
533 LONG lRet;
534 HBRUSH hBrush;
535 HDC hMemDC;
536 HBITMAP hBitmap;
537 BITMAP bm;
538 LPMEASUREITEMSTRUCT lpmeasure;
539 LPDRAWITEMSTRUCT lpdis;
540 int nDrive;
541 static LPOPENFILENAME lpofn;/* FIXME - this won't multitask */
543 SEGPTR tempsegp;
545 static HANDLE hStr = 0;
546 static LPSTR str = NULL;
547 static SEGPTR str16 = 0;
549 if (str == NULL) {
550 hStr = GlobalAlloc(0,512);
551 str = GlobalLock(hStr);
552 str16 = WIN16_GlobalLock(hStr);
555 switch (wMsg) {
556 case WM_INITDIALOG:
557 printf("FileSaveDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
558 if (!FileDlg_Init()) return TRUE;
559 SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0);
560 lpofn = (LPOPENFILENAME)lParam;
561 ptr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
562 tempsegp = lpofn->lpstrFilter;
563 while(*ptr) {
564 n = strlen(ptr);
565 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, tempsegp);
566 ptr += n + 1; tempsegp += n + 1;
567 n = strlen(ptr);
568 ptr += n + 1; tempsegp += n + 1;
570 /* set default filter */
571 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
572 lpofn->nFilterIndex - 1, 0L);
573 /* get drive information into combo 2 */
574 strcpy(str,"");
575 DlgDirListComboBox(hWnd, str16, cmb2, 0, 0xC000);
577 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL) {
578 strcpy(str, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir));
579 if (str[strlen(str)-1] != '\\' && str[strlen(str)-1] != ':') {
580 strcat(str,"\\");
582 } else {
583 strcpy(str,"");
585 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
586 if (lRet == LB_ERR) return FALSE;
587 fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
588 strcat(str,fspec);
590 if (!OpenDlg_ScanDir(hWnd, str)) {
591 printf("SaveDlg_ScanDir // ChangeDir Error !\n");
593 /* select current drive in combo */
594 nDrive = DOS_GetDefaultDrive();
595 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
597 ShowWindow(hWnd, SW_SHOWNORMAL);
598 return TRUE;
600 case WM_SHOWWINDOW:
601 if (wParam == 0) break;
602 if (!(lpofn->Flags & OFN_SHOWHELP)) {
603 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
605 if (lpofn->Flags & OFN_HIDEREADONLY) {
606 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
608 return TRUE;
610 case WM_MEASUREITEM:
611 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
612 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
613 lpmeasure->itemHeight = bm.bmHeight;
614 return TRUE;
616 case WM_DRAWITEM:
617 if (lParam == 0L) break;
618 lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
619 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
620 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
621 SelectObject(lpdis->hDC, hBrush);
622 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
623 ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
624 if (ptr == NULL) break;
625 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
626 ptr, strlen(ptr));
627 if (lpdis->itemState != 0) {
628 InvertRect(lpdis->hDC, &lpdis->rcItem);
630 return TRUE;
632 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
633 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
634 SelectObject(lpdis->hDC, hBrush);
635 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
636 ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
637 if (ptr == NULL) break;
638 hBitmap = hFolder;
639 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
640 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
641 lpdis->rcItem.top, ptr, strlen(ptr));
642 hMemDC = CreateCompatibleDC(lpdis->hDC);
643 SelectObject(hMemDC, hBitmap);
644 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
645 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
646 DeleteDC(hMemDC);
647 if (lpdis->itemState != 0) {
648 InvertRect(lpdis->hDC, &lpdis->rcItem);
650 return TRUE;
652 if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
653 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
654 SelectObject(lpdis->hDC, hBrush);
655 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
656 ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
657 if (ptr == NULL) break;
658 switch(ptr[2]) {
659 case 'a': case 'b':
660 hBitmap = hFloppy;
661 break;
662 default:
663 hBitmap = hHDisk;
664 break;
666 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
667 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
668 lpdis->rcItem.top, ptr, strlen(ptr));
669 hMemDC = CreateCompatibleDC(lpdis->hDC);
670 SelectObject(hMemDC, hBitmap);
671 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
672 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
673 DeleteDC(hMemDC);
674 if (lpdis->itemState != 0) {
675 InvertRect(lpdis->hDC, &lpdis->rcItem);
677 return TRUE;
679 break;
681 case WM_COMMAND:
682 switch (wParam) {
683 case lst1:
684 if (HIWORD(lParam) == LBN_DBLCLK) {
685 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
686 if (lRet == LB_ERR) return 0;
687 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, str16);
688 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
689 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
691 break;
692 case lst2:
693 if (HIWORD(lParam) == LBN_DBLCLK) {
694 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
695 if (lRet == LB_ERR) return 0;
696 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet, str16);
698 if (str[0] == '[') {
699 str[strlen(str) - 1] = 0;
700 strcpy(str,str+1);
702 strcat(str,"\\");
703 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
704 if (lRet == LB_ERR) return FALSE;
705 fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
706 strcat(str,"\\"); strcat(str,fspec);
707 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
708 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
710 break;
711 case cmb1:
712 if (HIWORD(lParam) == CBN_SELCHANGE) {
713 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
714 if (lRet == LB_ERR) return FALSE;
715 fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
716 strcpy(str,fspec);
717 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
718 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
720 break;
721 case cmb2:
722 wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
723 if (wRet == (WORD)LB_ERR) return 0;
724 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, str16);
725 str[0] = str[2]; str[1] = ':'; str[2] = 0;
726 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
727 if (lRet == LB_ERR) return FALSE;
728 fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
729 strcat(str,fspec);
730 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
731 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
732 break;
733 case chx1:
734 #ifdef DEBUG_OPENDLG
735 printf("FileSaveDlgProc // read-only toggled !\n");
736 #endif
737 break;
738 case pshHelp:
739 #ifdef DEBUG_OPENDLG
740 printf("FileSaveDlgProc // pshHelp pressed !\n");
741 #endif
742 break;
743 case IDOK:
744 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, str16);
745 if (COMMDLG_IsPathName(str)) {
746 OpenDlg_ScanDir(hWnd, str);
747 } else {
748 ShowWindow(hWnd, SW_HIDE);
749 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), str);
750 lpofn->nFileOffset = 0;
751 lpofn->nFileExtension = strlen(PTR_SEG_TO_LIN(lpofn->lpstrFile)) - 3;
752 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) {
753 wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
754 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, str16);
755 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), str);
757 EndDialog(hWnd, TRUE);
759 return TRUE;
760 case IDCANCEL:
761 EndDialog(hWnd, FALSE);
762 return TRUE;
764 /* return FALSE;*/
769 case WM_CTLCOLOR:
770 SetBkColor((HDC)wParam, 0x00C0C0C0);
771 switch (HIWORD(lParam))
773 case CTLCOLOR_BTN:
774 SetTextColor((HDC)wParam, 0x00000000);
775 return hGRAYBrush;
776 case CTLCOLOR_STATIC:
777 SetTextColor((HDC)wParam, 0x00000000);
778 return hGRAYBrush;
780 return FALSE;
783 return FALSE;
787 /***********************************************************************
788 * ColorDlgProc [COMMDLG.8]
790 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
792 switch (wMsg) {
793 case WM_INITDIALOG:
794 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
795 ShowWindow(hWnd, SW_SHOWNORMAL);
796 return (TRUE);
798 case WM_COMMAND:
799 switch (wParam) {
800 case IDOK:
801 EndDialog(hWnd, TRUE);
802 return(TRUE);
803 case IDCANCEL:
804 EndDialog(hWnd, FALSE);
805 return(TRUE);
807 return(FALSE);
809 return FALSE;
813 /***********************************************************************
814 * FindTextDlg [COMMDLG.11]
816 BOOL FindText(LPFINDREPLACE lpFind)
818 WND *wndPtr;
819 BOOL bRet;
820 LPCSTR lpTemplate;
822 lpTemplate = sysres_DIALOG_9;
823 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
824 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
825 lpFind->hwndOwner, GetWndProcEntry16("FindTextDlgProc"),
826 (DWORD)lpFind);
827 return bRet;
831 /***********************************************************************
832 * ReplaceTextDlg [COMMDLG.12]
834 BOOL ReplaceText(LPFINDREPLACE lpFind)
836 WND *wndPtr;
837 BOOL bRet;
838 LPCSTR lpTemplate;
840 lpTemplate = sysres_DIALOG_10;
841 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
842 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
843 lpFind->hwndOwner, GetWndProcEntry16("ReplaceTextDlgProc"),
844 (DWORD)lpFind);
845 return bRet;
849 /***********************************************************************
850 * FindTextDlgProc [COMMDLG.13]
852 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
854 switch (wMsg) {
855 case WM_INITDIALOG:
856 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
857 ShowWindow(hWnd, SW_SHOWNORMAL);
858 return (TRUE);
860 case WM_COMMAND:
861 switch (wParam) {
862 case IDOK:
863 EndDialog(hWnd, TRUE);
864 return(TRUE);
865 case IDCANCEL:
866 EndDialog(hWnd, FALSE);
867 return(TRUE);
869 return(FALSE);
871 return FALSE;
875 /***********************************************************************
876 * ReplaceTextDlgProc [COMMDLG.14]
878 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
880 switch (wMsg) {
881 case WM_INITDIALOG:
882 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
883 ShowWindow(hWnd, SW_SHOWNORMAL);
884 return (TRUE);
886 case WM_COMMAND:
887 switch (wParam) {
888 case IDOK:
889 EndDialog(hWnd, TRUE);
890 return(TRUE);
891 case IDCANCEL:
892 EndDialog(hWnd, FALSE);
893 return(TRUE);
895 return(FALSE);
897 return FALSE;
901 /***********************************************************************
902 * PrintDlg [COMMDLG.20]
904 BOOL PrintDlg(LPPRINTDLG lpPrint)
906 WND *wndPtr;
907 BOOL bRet;
908 LPCSTR lpTemplate;
910 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags);
911 if (lpPrint->Flags & PD_PRINTSETUP) {
912 lpTemplate = sysres_DIALOG_6;
913 } else {
914 lpTemplate = sysres_DIALOG_5;
916 wndPtr = WIN_FindWndPtr(lpPrint->hwndOwner);
917 if (lpPrint->Flags & PD_PRINTSETUP)
918 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
919 lpPrint->hwndOwner, GetWndProcEntry16("PrintSetupDlgProc"),
920 (DWORD)lpPrint);
921 else
922 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
923 lpPrint->hwndOwner, GetWndProcEntry16("PrintDlgProc"),
924 (DWORD)lpPrint);
925 return bRet;
929 /***********************************************************************
930 * PrintDlgProc [COMMDLG.21]
932 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
934 switch (wMsg) {
935 case WM_INITDIALOG:
936 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
937 ShowWindow(hWnd, SW_SHOWNORMAL);
938 return (TRUE);
940 case WM_COMMAND:
941 switch (wParam) {
942 case IDOK:
943 EndDialog(hWnd, TRUE);
944 return(TRUE);
945 case IDCANCEL:
946 EndDialog(hWnd, FALSE);
947 return(TRUE);
949 return(FALSE);
951 return FALSE;
955 /***********************************************************************
956 * PrintSetupDlgProc [COMMDLG.22]
958 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
960 switch (wMsg) {
961 case WM_INITDIALOG:
962 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
963 ShowWindow(hWnd, SW_SHOWNORMAL);
964 return (TRUE);
966 case WM_COMMAND:
967 switch (wParam) {
968 case IDOK:
969 EndDialog(hWnd, TRUE);
970 return(TRUE);
971 case IDCANCEL:
972 EndDialog(hWnd, FALSE);
973 return(TRUE);
975 return(FALSE);
977 return FALSE;
981 /***********************************************************************
982 * CommDlgExtendError [COMMDLG.26]
984 DWORD CommDlgExtendError(void)
986 return CommDlgLastError;
990 /***********************************************************************
991 * GetFileTitle [COMMDLG.27]
993 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
995 int i, len;
996 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
997 if (lpFile == NULL || lpTitle == NULL) return -1;
998 len = strlen(lpFile);
999 if (len == 0) return -1;
1000 if (strchr(lpFile, '*') != NULL) return -1;
1001 if (strchr(lpFile, '[') != NULL) return -1;
1002 if (strchr(lpFile, ']') != NULL) return -1;
1003 len--;
1004 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') return -1;
1005 for (i = len; i >= 0; i--) {
1006 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':') {
1007 i++;
1008 break;
1011 printf("\n---> '%s' ", &lpFile[i]);
1012 len = min(cbBuf, strlen(&lpFile[i]) + 1);
1013 strncpy(lpTitle, &lpFile[i], len + 1);
1014 if (len != cbBuf)
1015 return len;
1016 else
1017 return 0;