wine/misc/commdlg.c
Alexandre Julliard 2787be8766 Release 950522
Sun May 21 12:30:30 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)

	* [debugger/hash.c] [debugger/info.c]
	Added support for symbolic segmented addresses. Add symbols for all
	built-in API entry points.

	* [if1632/relay.c] [include/dlls.h]
	Removed dll_table structure, as we now use the built-in module
	structures.

	* [if1632/relay.c] [loader/main.c]
	Removed winestat option, as it was no longer very meaningful.

	* [include/stackframe.h]
	New macro MAKE_SEGPTR that creates a segmented pointer to a local
	variable on the 32-bit stack.

	* [loader/module.c]
	Added support for multiple instances of an application.
	Implemented LoadModule() and FreeModule().

	* [loader/ne_image.c] [loader/task.c]
	Moved initialisation of built-in DLLs to InitTask().

	* [memory/global.c]
	Implemented discardable blocks.

	* [misc/file.c]
	Search path of current executable in OpenFile().
	Fixed bug with searching in Windows path.

	* [misc/lstr.c]
	Hard-coded translation tables for Ansi<->Oem.

	* [misc/user.c]
	Moved some global initializations to InitApp(), because they need
	a task context to be performed.

	* [objects/dc.c]
	Handle R2_BLACK and R2_WHITE specially so that they work correctly
	with palette displays.

	* [tools/build.c]
	Suppressed generation of the C file for DLL specs, because it's no
	longer needed. Output all the assembly code directly to stdout.
	Some changes to integrate Win32 support from Martin von	Loewis. 

	* [windows/msgbox.c]
	Moved message box code from misc/ to windows/.

Mon May 15 23:40:04 1995  Martin Ayotte (wine@trgcorp.mksinfo.qc.ca)

	* [misc/audio.c] [misc/mcicda.c] [misc/mcianim.c] [misc/midi.c]
	  [misc/mmaux.c] [misc/mmsystem.c]
	Modify code & use pointers conversion macros.
	Make cdaudio & wave devices work again (only using some applets).

	* [misc/profile.c]
	Change getc() to fgetc() where needed.

Mon May 15 22:10:56 1995  Martin von Loewis  <loewis@informatik.hu-berlin.de>

	* [if1632/Imakefile]
	added entries for the new files gdi32.spec, kernel32.spec,
	user32.spec, shell32.spec and winprocs32.spec.

	* [if1632/commdlg.spec][if1632/kernel.spec][if1632/shell.spec]
	  [if1632/storage.spec][if1632/system.spec][if1632/user.spec]
	ChooseFont, RESERVED5, InternalExtractIcon: Marked as stubs
	ExtractAssociatedIcon, DoEnvironmentSubst, DumpIcon:
		stub implementations provided 
	marked storage.dll,storege.sys functions as stubs

	* [include/pe_image.h]
	Added structures WIN32_builtin and  WIN32_function

	* [include/peexe.h]
	PE_Import_Directory: renamed reserved fields to 
		TimeDate, Forwarder, Thunk_List

	* [include/winerror.h]
	New file.

	* [loader/main.c]
	called RELAY32_Init

	* [loader/pe_image.c]
	xmmap: map BSS anonymous
	dump_imports: renamed to fixup_imports, do the fixup of imported
	              symbols
	PE_LoadImage: pass raw data size to xmmap

	* [loader/resource.c]
	DumpIcon: new function

	* [misc/kernel32.c]
	New file.

	* [misc/main.c]
	make stdout and stderr unbuffered

	* [misc/shell.c]
	DoEnvironmentSubst: new function

	* [objects/font.c]
	FONT_MatchFont: try oblique if there is no italic

	* [rc/Imakefile][rc/parser.l]
	yywrap: new function
	Don't link with libfl.a on Linux

	* [tools/build.c]
	Added keywords stdcall, subsystem, base
	GenerateForWin32: new function
	BuildSpecFiles: call GenerateForWin32 if subsystem is win32

Mon May 15 10:38:14 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>
        
        * [controls/listbox.c] [controls/combo.c] [windows/defwnd.c]
	Minor fixes.
	
	* [misc/message.c] [misc/main.c] [rc/sysres*.rc] [include/texts.h]
	Rewrote message box handling.
	
	* [windows/dialog.c]
	Dialogs should be invisible until after WM_INITDIALOG is seent.
	Don't switch to invisible dialog items on a TAB keypress.
	
	* [windows/mdi.c]
	Send WM_NCPAINT message in MDIRestoreChild().
	
	* [windows/painting.c]
	Fixed typo (&& -> &).
	
	* [windows/message.c] [if1632/user.spec]
	Implemented PostAppMessage().
	
	* [windows/event.c]
	SetCapture(0) should act like ReleaseCapture().

Tue May  9 11:55:52 1995     Eddie C. Dost             (ecd@dressler.de)

	* [Imakefile]
	Changed CDEBUGFLAGS for systems running __ELF__ (temporarily)
	Added ASFLAGS to exported variables.

	* [debugger/readline/Imakefile]
	Moved defines for libreadline from DEFINES to EXTRA_DEFINES

	* [memory/local.c] [miscemu/int21.c]
	Added some more debugging outputs.

Mon May  8 00:55:27 MET DST 1995	  Dag Asheim (dash@ifi.uio.no)

	* [misc/message.c]
	Fixed a "FIXME" concerning norwegian translation.

Sun May  7 23:25:23 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>
        
	* [*/*]
        Removed warnings in a couple of files and deleted some obsolete code.

        * [controls/listbox.c]
        Cleanup, speed improvements & lots of bug fixes.

        * [controls/combo.c]
	Mostly rewritten. This is still very buggy, but not quite as bad as 
	before.

        * [include/commdlg.h] [misc/commdlg.c]
        Removed the need for sysres.dll. Small bug fixes.
	
        * [objects/oembitmap.c] [include/bitmaps/<many>] [include/windows.h]
          [loader/library.c] [loader/main.c] [rc/sysres*.rc]
        Removed sysres.dll and replaced the remaining bitmaps/icons with
        XPM equivalents.

        * [misc/message.c] [windows/nonclient.c] [misc/main.c]
          [if1632/winprocs.spec]
        "About Wine..." now brings up a standard ShellAbout() window with
        the Wine icon and the list of contributors.
	
	* [misc/shell.c]
	Fixed ShellAbout()/AboutDialogProc() to show the right icon.

	* [windows/event.c]
	Small hack for non-alphanumeric keys: Dont't send the ascii value in
	the WM_KEYDOWN message, but some unused code instead. Should be done
	properly by sending different codes for each key. The edit control
	used to get a VK_DELETE message each time the user typed '.'.

	* [windows/class.c]
	Removed a check for CS_GLOBALCLASS in CLASS_FindClassByName().
	This used to be no problem, but breaks Resource Workshop in 950403.
	
	* [objects/dib.c]
	New diagnostic for a bug I've been encountering. If it shows up,
	please report it.

Sun May  7 23:11:18 EDT 1995  William Magro (wmagro@tc.cornell.edu)

	* [objects/color.c]
	Handle situation when 'dc' exists, but palette mapping
	does not.  (Fixes kidpix2 demo.)

Sun May  7 03:32:00 1995  Charles M. Hannum  (mycroft@mit.edu)

	* [loader/ldt.c]
	LDT_Print: Only show the number of entries that the kernel
	returned. Make this work for NetBSD.

Fri May  5 02:53:26 1995  Charles M. Hannum  (mycroft@mit.edu)

	* [debugger/dbg.y] [include/wine.h] [loader/signal.c]
	Modify cs and ds selector values for NetBSD-current.

	* [debugger/debug.l]
	$sp, $esp: Use RN_ESP_AT_SIGNAL rather than RN_ESP.

	* [debugger/regpos.h]
	Modify sigcontext format for NetBSD-current.
	SC_ESP: Use RN_ESP_AT_SIGNAL rather than RN_ESP.

	* [include/ldt.h]
	SELECTOR_TO_ENTRY: Explicitly clear the top half of the selector
	value, since only 16 bits of it may have been saved.

	* [misc/winsocket.c]
	Set structure packing with `#pragma pack' to accomodate
	other/older compilers.

Tue May  2 18:15:01 1995 Paal Beyer (beyer@idt.unit.no)
	
	* [misc/commdlg.c]
	Fixed path-names so when changing directory the listboxes
	changes too.
	
	* [debugger/dbg.y debugger/debug.l wine.ini]
	Added SymbolTableFile to wine.ini so symbols can be read
	without standing in the directory containing wine.sym.
	Added the possibility to specify full name of wine.sym from
	the debugger prompt.
1995-05-22 18:23:01 +00:00

1019 lines
29 KiB
C

/*
* COMMDLG functions
*
* Copyright 1994 Martin Ayotte
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dialog.h"
#include "win.h"
#include "user.h"
#include "message.h"
#include "commdlg.h"
#include "dlgs.h"
#include "selectors.h"
#include "../rc/sysres.h"
#define OPENFILEDLG2 11
#define SAVEFILEDLG2 12
static DWORD CommDlgLastError = 0;
static HBITMAP hFolder = 0;
static HBITMAP hFolder2 = 0;
static HBITMAP hFloppy = 0;
static HBITMAP hHDisk = 0;
static HBITMAP hCDRom = 0;
int DOS_GetDefaultDrive(void);
void DOS_SetDefaultDrive(int drive);
char *DOS_GetCurrentDir(int drive);
int DOS_ChangeDir(int drive, char *dirname);
BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
/***********************************************************************
* COMMDLG_IsPathName [internal]
*/
static BOOL COMMDLG_IsPathName(LPSTR str)
{
if (str[strlen(str)-1] == ':' && strlen(str) == 2) return TRUE;
if (str[strlen(str)-1] == '\\') return TRUE;
if (strchr(str,'*') != NULL) return TRUE;
return FALSE;
}
/***********************************************************************
* FileDlg_Init [internal]
*/
static BOOL FileDlg_Init()
{
if (!hFolder) hFolder = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER));
if (!hFolder2) hFolder2 = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2));
if (!hFloppy) hFloppy = LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY));
if (!hHDisk) hHDisk = LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK));
if (!hCDRom) hCDRom = LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM));
if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
hHDisk == 0 || hCDRom == 0)
fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
return TRUE;
}
/***********************************************************************
* OpenDlg_FixDirName [internal]
*/
void OpenDlg_FixDirName(LPSTR dirname)
{
char temp[512];
char* strp1;
char* strp2;
strp1=dirname;
if( dirname[1] != ':'){
temp[0]=(char)((char)DOS_GetDefaultDrive()+'A');
temp[1]=':';
temp[2]='\\';
temp[3]= '\0';
strcat(temp, DOS_GetCurrentDir(DOS_GetDefaultDrive()));
if(dirname[0]=='.' && dirname[1]=='.') {
strp2 = strrchr(temp, '\\');
if (strp2 != NULL){
*strp2='\0';
strp1+=2;
}
}
strcat(temp, "\\");
strcat(temp, strp1);
strcpy(dirname, temp);
}
}
/***********************************************************************
* OpenDlg_ScanDir [internal]
*/
static BOOL OpenDlg_ScanDir(HWND hWnd, LPSTR newPath)
{
static HANDLE hStr = 0;
static LPSTR str = NULL;
static SEGPTR str16 = 0;
LPSTR strp;
OpenDlg_FixDirName(newPath);
if (str == NULL) {
hStr = GlobalAlloc(0,512);
str = GlobalLock(hStr);
str16 = WIN16_GlobalLock(hStr);
}
strcpy(str,newPath);
DlgDirList(hWnd, str, lst1, 0, 0x0000);
strp = strrchr(str,'\\');
if (strp == NULL) {
if (str[1] == ':') {
strp = str+2;
} else {
strp = str;
}
} else strp++;
strcpy(str,strp);
SendDlgItemMessage(hWnd,edt1,WM_SETTEXT, 0, str16);
strcpy(str,"*.*");
DlgDirList(hWnd, str, lst2, stc1, 0x8010);
return TRUE;
}
/***********************************************************************
* OpenDlg_GetFileType [internal]
*/
static LPSTR OpenDlg_GetFileType(LPCSTR types, WORD index)
{
int n;
int i = 1;
LPSTR ptr = (LPSTR) types;
if (ptr == NULL) return NULL;
while((n = strlen(ptr)) != 0) {
ptr += ++n;
if (i++ == index) return ptr;
n = strlen(ptr);
ptr += ++n;
}
return NULL;
}
/***********************************************************************
* GetOpenFileName [COMMDLG.1]
*/
BOOL GetOpenFileName(LPOPENFILENAME lpofn)
{
HANDLE hDlgTmpl;
HANDLE hResInfo;
HINSTANCE hInst;
BOOL bRet;
LPCSTR dlgTemplate;
if (lpofn == NULL) return FALSE;
if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
dlgTemplate = GlobalLock(lpofn->hInstance);
if (!dlgTemplate) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
} else {
if (lpofn->Flags & OFN_ENABLETEMPLATE) {
hInst = lpofn->hInstance;
hResInfo = FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG);
if (hResInfo == 0) {
CommDlgLastError = CDERR_FINDRESFAILURE;
return FALSE;
}
hDlgTmpl = LoadResource(hInst, hResInfo);
if (hDlgTmpl == 0) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
dlgTemplate = GlobalLock(hDlgTmpl);
} else {
dlgTemplate = sysres_DIALOG_3;
}
}
hInst = GetWindowWord(lpofn->hwndOwner, GWW_HINSTANCE);
bRet = DialogBoxIndirectParamPtr(hInst, dlgTemplate, lpofn->hwndOwner,
GetWndProcEntry16("FileOpenDlgProc"),
(DWORD)lpofn);
printf("GetOpenFileName // return lpstrFile='%s' !\n",
(LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
return bRet;
}
/***********************************************************************
* GetSaveFileName [COMMDLG.2]
*/
BOOL GetSaveFileName(LPOPENFILENAME lpofn)
{
HANDLE hDlgTmpl;
HANDLE hResInfo;
HINSTANCE hInst;
BOOL bRet;
LPCSTR dlgTemplate;
if (lpofn == NULL) return FALSE;
if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
dlgTemplate = GlobalLock(lpofn->hInstance);
if (!dlgTemplate) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
} else {
if (lpofn->Flags & OFN_ENABLETEMPLATE) {
hInst = lpofn->hInstance;
hResInfo = FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG);
if (hResInfo == 0) {
CommDlgLastError = CDERR_FINDRESFAILURE;
return FALSE;
}
hDlgTmpl = LoadResource(hInst, hResInfo);
if (hDlgTmpl == 0) {
CommDlgLastError = CDERR_LOADRESFAILURE;
return FALSE;
}
dlgTemplate = GlobalLock(hDlgTmpl);
} else {
dlgTemplate = sysres_DIALOG_4; /* SAVEFILEDIALOG */
}
}
hInst = GetWindowWord(lpofn->hwndOwner, GWW_HINSTANCE);
bRet = DialogBoxIndirectParamPtr(hInst, dlgTemplate, lpofn->hwndOwner,
GetWndProcEntry16("FileSaveDlgProc"),
(DWORD)lpofn);
printf("GetSaveFileName // return lpstrFile='%s' !\n",
(LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
return bRet;
}
/***********************************************************************
* ChooseColor [COMMDLG.5]
*/
BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
{
WND *wndPtr;
BOOL bRet;
wndPtr = WIN_FindWndPtr(lpChCol->hwndOwner);
bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, sysres_DIALOG_8,
lpChCol->hwndOwner, GetWndProcEntry16("ColorDlgProc"),
(DWORD)lpChCol);
return bRet;
}
/***********************************************************************
* FileOpenDlgProc [COMMDLG.6]
*/
BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
int n;
LPSTR ptr;
LPSTR fspec;
WORD wRet;
LONG lRet;
HBRUSH hBrush;
HDC hMemDC;
HBITMAP hBitmap;
BITMAP bm;
LPMEASUREITEMSTRUCT lpmeasure;
LPDRAWITEMSTRUCT lpdis;
int nDrive;
static LPOPENFILENAME lpofn;/* FIXME - this won't multitask */
SEGPTR tempsegp;
static HANDLE hStr = 0;
static LPSTR str = NULL;
static SEGPTR str16 = 0;
if (str == NULL) {
hStr = GlobalAlloc(0,512);
str = GlobalLock(hStr);
str16 = WIN16_GlobalLock(hStr);
}
switch (wMsg) {
case WM_INITDIALOG:
printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
if (!FileDlg_Init()) return TRUE;
SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0);
lpofn = (LPOPENFILENAME)lParam;
ptr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
tempsegp = lpofn->lpstrFilter;
while(*ptr) {
n = strlen(ptr);
SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, tempsegp);
ptr += n + 1; tempsegp += n + 1;
n = strlen(ptr);
ptr += n + 1; tempsegp += n + 1;
}
/* set default filter */
SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
lpofn->nFilterIndex - 1, 0L);
/* get drive information into combo 2 */
strcpy(str,"");
DlgDirListComboBox(hWnd, str16, cmb2, 0, 0xC000);
if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL) {
strcpy(str, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir));
if (str[strlen(str)-1] != '\\' && str[strlen(str)-1] != ':') {
strcat(str,"\\");
}
} else {
strcpy(str,"");
}
lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
if (lRet == LB_ERR) return FALSE;
fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
strcat(str,fspec);
if (!OpenDlg_ScanDir(hWnd, str)) {
printf("OpenDlg_ScanDir // ChangeDir Error !\n");
}
/* select current drive in combo */
nDrive = DOS_GetDefaultDrive();
SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
ShowWindow(hWnd, SW_SHOWNORMAL);
return TRUE;
case WM_SHOWWINDOW:
if (wParam == 0) break;
if (!(lpofn->Flags & OFN_SHOWHELP)) {
ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
}
if (lpofn->Flags & OFN_HIDEREADONLY) {
ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
}
return TRUE;
case WM_MEASUREITEM:
GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
lpmeasure->itemHeight = bm.bmHeight;
return TRUE;
case WM_DRAWITEM:
if (lParam == 0L) break;
lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
if (ptr == NULL) break;
TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
ptr, strlen(ptr));
if (lpdis->itemState != 0) {
InvertRect(lpdis->hDC, &lpdis->rcItem);
}
return TRUE;
}
if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
if (ptr == NULL) break;
hBitmap = hFolder;
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
lpdis->rcItem.top, ptr, strlen(ptr));
hMemDC = CreateCompatibleDC(lpdis->hDC);
SelectObject(hMemDC, hBitmap);
BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
if (lpdis->itemState != 0) {
InvertRect(lpdis->hDC, &lpdis->rcItem);
}
return TRUE;
}
if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
if (ptr == NULL) break;
switch(ptr[2]) {
case 'a': case 'b':
hBitmap = hFloppy;
break;
default:
hBitmap = hHDisk;
break;
}
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
lpdis->rcItem.top, ptr, strlen(ptr));
hMemDC = CreateCompatibleDC(lpdis->hDC);
SelectObject(hMemDC, hBitmap);
BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
if (lpdis->itemState != 0) {
InvertRect(lpdis->hDC, &lpdis->rcItem);
}
return TRUE;
}
break;
case WM_COMMAND:
switch (wParam) {
case lst1:
if (HIWORD(lParam) == LBN_DBLCLK) {
lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR) return 0;
SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, str16);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
}
break;
case lst2:
if (HIWORD(lParam) == LBN_DBLCLK) {
lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR) return 0;
SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet, str16);
if (str[0] == '[') {
str[strlen(str) - 1] = 0;
strcpy(str,str+1);
}
strcat(str,"\\");
lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
if (lRet == LB_ERR) return FALSE;
fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
strcat(str,"\\"); strcat(str,fspec);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
}
break;
case cmb1:
if (HIWORD(lParam) == CBN_SELCHANGE) {
lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR) return FALSE;
fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
strcpy(str,fspec);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
}
break;
case cmb2:
wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, str16);
str[0] = str[2]; str[1] = ':'; str[2] = 0;
lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR) return FALSE;
fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
strcat(str,fspec);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
break;
case chx1:
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // read-only toggled !\n");
#endif
break;
case pshHelp:
#ifdef DEBUG_OPENDLG
printf("FileOpenDlgProc // pshHelp pressed !\n");
#endif
break;
case IDOK:
SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, str16);
if (COMMDLG_IsPathName(str)) {
OpenDlg_ScanDir(hWnd, str);
} else {
ShowWindow(hWnd, SW_HIDE);
strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), str);
lpofn->nFileOffset = 0;
lpofn->nFileExtension = strlen(PTR_SEG_TO_LIN(lpofn->lpstrFile)) - 3;
if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) {
wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, str16);
strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), str);
}
EndDialog(hWnd, TRUE);
}
return TRUE;
case IDCANCEL:
EndDialog(hWnd, FALSE);
return TRUE;
}
/* return FALSE;*/
}
/*
case WM_CTLCOLOR:
SetBkColor((HDC)wParam, 0x00C0C0C0);
switch (HIWORD(lParam))
{
case CTLCOLOR_BTN:
SetTextColor((HDC)wParam, 0x00000000);
return hGRAYBrush;
case CTLCOLOR_STATIC:
SetTextColor((HDC)wParam, 0x00000000);
return hGRAYBrush;
}
return FALSE;
*/
return FALSE;
}
/***********************************************************************
* FileSaveDlgProc [COMMDLG.7]
*/
BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
int n;
LPSTR ptr;
LPSTR fspec;
WORD wRet;
LONG lRet;
HBRUSH hBrush;
HDC hMemDC;
HBITMAP hBitmap;
BITMAP bm;
LPMEASUREITEMSTRUCT lpmeasure;
LPDRAWITEMSTRUCT lpdis;
int nDrive;
static LPOPENFILENAME lpofn;/* FIXME - this won't multitask */
SEGPTR tempsegp;
static HANDLE hStr = 0;
static LPSTR str = NULL;
static SEGPTR str16 = 0;
if (str == NULL) {
hStr = GlobalAlloc(0,512);
str = GlobalLock(hStr);
str16 = WIN16_GlobalLock(hStr);
}
switch (wMsg) {
case WM_INITDIALOG:
printf("FileSaveDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
if (!FileDlg_Init()) return TRUE;
SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0);
lpofn = (LPOPENFILENAME)lParam;
ptr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
tempsegp = lpofn->lpstrFilter;
while(*ptr) {
n = strlen(ptr);
SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, tempsegp);
ptr += n + 1; tempsegp += n + 1;
n = strlen(ptr);
ptr += n + 1; tempsegp += n + 1;
}
/* set default filter */
SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
lpofn->nFilterIndex - 1, 0L);
/* get drive information into combo 2 */
strcpy(str,"");
DlgDirListComboBox(hWnd, str16, cmb2, 0, 0xC000);
if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL) {
strcpy(str, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir));
if (str[strlen(str)-1] != '\\' && str[strlen(str)-1] != ':') {
strcat(str,"\\");
}
} else {
strcpy(str,"");
}
lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
if (lRet == LB_ERR) return FALSE;
fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
strcat(str,fspec);
if (!OpenDlg_ScanDir(hWnd, str)) {
printf("SaveDlg_ScanDir // ChangeDir Error !\n");
}
/* select current drive in combo */
nDrive = DOS_GetDefaultDrive();
SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
ShowWindow(hWnd, SW_SHOWNORMAL);
return TRUE;
case WM_SHOWWINDOW:
if (wParam == 0) break;
if (!(lpofn->Flags & OFN_SHOWHELP)) {
ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
}
if (lpofn->Flags & OFN_HIDEREADONLY) {
ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
}
return TRUE;
case WM_MEASUREITEM:
GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
lpmeasure->itemHeight = bm.bmHeight;
return TRUE;
case WM_DRAWITEM:
if (lParam == 0L) break;
lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
if (ptr == NULL) break;
TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
ptr, strlen(ptr));
if (lpdis->itemState != 0) {
InvertRect(lpdis->hDC, &lpdis->rcItem);
}
return TRUE;
}
if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
if (ptr == NULL) break;
hBitmap = hFolder;
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
lpdis->rcItem.top, ptr, strlen(ptr));
hMemDC = CreateCompatibleDC(lpdis->hDC);
SelectObject(hMemDC, hBitmap);
BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
if (lpdis->itemState != 0) {
InvertRect(lpdis->hDC, &lpdis->rcItem);
}
return TRUE;
}
if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdis->hDC, hBrush);
FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
ptr = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
if (ptr == NULL) break;
switch(ptr[2]) {
case 'a': case 'b':
hBitmap = hFloppy;
break;
default:
hBitmap = hHDisk;
break;
}
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
lpdis->rcItem.top, ptr, strlen(ptr));
hMemDC = CreateCompatibleDC(lpdis->hDC);
SelectObject(hMemDC, hBitmap);
BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
if (lpdis->itemState != 0) {
InvertRect(lpdis->hDC, &lpdis->rcItem);
}
return TRUE;
}
break;
case WM_COMMAND:
switch (wParam) {
case lst1:
if (HIWORD(lParam) == LBN_DBLCLK) {
lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR) return 0;
SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, str16);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
}
break;
case lst2:
if (HIWORD(lParam) == LBN_DBLCLK) {
lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR) return 0;
SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet, str16);
if (str[0] == '[') {
str[strlen(str) - 1] = 0;
strcpy(str,str+1);
}
strcat(str,"\\");
lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
if (lRet == LB_ERR) return FALSE;
fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
strcat(str,"\\"); strcat(str,fspec);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
}
break;
case cmb1:
if (HIWORD(lParam) == CBN_SELCHANGE) {
lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR) return FALSE;
fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
strcpy(str,fspec);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
}
break;
case cmb2:
wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
if (wRet == (WORD)LB_ERR) return 0;
SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, str16);
str[0] = str[2]; str[1] = ':'; str[2] = 0;
lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR) return FALSE;
fspec = OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), lRet + 1);
strcat(str,fspec);
SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, str16);
return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
break;
case chx1:
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // read-only toggled !\n");
#endif
break;
case pshHelp:
#ifdef DEBUG_OPENDLG
printf("FileSaveDlgProc // pshHelp pressed !\n");
#endif
break;
case IDOK:
SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, str16);
if (COMMDLG_IsPathName(str)) {
OpenDlg_ScanDir(hWnd, str);
} else {
ShowWindow(hWnd, SW_HIDE);
strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), str);
lpofn->nFileOffset = 0;
lpofn->nFileExtension = strlen(PTR_SEG_TO_LIN(lpofn->lpstrFile)) - 3;
if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) {
wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, str16);
strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), str);
}
EndDialog(hWnd, TRUE);
}
return TRUE;
case IDCANCEL:
EndDialog(hWnd, FALSE);
return TRUE;
}
/* return FALSE;*/
}
/*
case WM_CTLCOLOR:
SetBkColor((HDC)wParam, 0x00C0C0C0);
switch (HIWORD(lParam))
{
case CTLCOLOR_BTN:
SetTextColor((HDC)wParam, 0x00000000);
return hGRAYBrush;
case CTLCOLOR_STATIC:
SetTextColor((HDC)wParam, 0x00000000);
return hGRAYBrush;
}
return FALSE;
*/
return FALSE;
}
/***********************************************************************
* ColorDlgProc [COMMDLG.8]
*/
BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* FindTextDlg [COMMDLG.11]
*/
BOOL FindText(LPFINDREPLACE lpFind)
{
WND *wndPtr;
BOOL bRet;
LPCSTR lpTemplate;
lpTemplate = sysres_DIALOG_9;
wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
lpFind->hwndOwner, GetWndProcEntry16("FindTextDlgProc"),
(DWORD)lpFind);
return bRet;
}
/***********************************************************************
* ReplaceTextDlg [COMMDLG.12]
*/
BOOL ReplaceText(LPFINDREPLACE lpFind)
{
WND *wndPtr;
BOOL bRet;
LPCSTR lpTemplate;
lpTemplate = sysres_DIALOG_10;
wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
lpFind->hwndOwner, GetWndProcEntry16("ReplaceTextDlgProc"),
(DWORD)lpFind);
return bRet;
}
/***********************************************************************
* FindTextDlgProc [COMMDLG.13]
*/
BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* ReplaceTextDlgProc [COMMDLG.14]
*/
BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* PrintDlg [COMMDLG.20]
*/
BOOL PrintDlg(LPPRINTDLG lpPrint)
{
WND *wndPtr;
BOOL bRet;
LPCSTR lpTemplate;
printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags);
if (lpPrint->Flags & PD_PRINTSETUP) {
lpTemplate = sysres_DIALOG_6;
} else {
lpTemplate = sysres_DIALOG_5;
}
wndPtr = WIN_FindWndPtr(lpPrint->hwndOwner);
if (lpPrint->Flags & PD_PRINTSETUP)
bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
lpPrint->hwndOwner, GetWndProcEntry16("PrintSetupDlgProc"),
(DWORD)lpPrint);
else
bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
lpPrint->hwndOwner, GetWndProcEntry16("PrintDlgProc"),
(DWORD)lpPrint);
return bRet;
}
/***********************************************************************
* PrintDlgProc [COMMDLG.21]
*/
BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* PrintSetupDlgProc [COMMDLG.22]
*/
BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
ShowWindow(hWnd, SW_SHOWNORMAL);
return (TRUE);
case WM_COMMAND:
switch (wParam) {
case IDOK:
EndDialog(hWnd, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hWnd, FALSE);
return(TRUE);
}
return(FALSE);
}
return FALSE;
}
/***********************************************************************
* CommDlgExtendError [COMMDLG.26]
*/
DWORD CommDlgExtendError(void)
{
return CommDlgLastError;
}
/***********************************************************************
* GetFileTitle [COMMDLG.27]
*/
int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
{
int i, len;
printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
if (lpFile == NULL || lpTitle == NULL) return -1;
len = strlen(lpFile);
if (len == 0) return -1;
if (strchr(lpFile, '*') != NULL) return -1;
if (strchr(lpFile, '[') != NULL) return -1;
if (strchr(lpFile, ']') != NULL) return -1;
len--;
if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') return -1;
for (i = len; i >= 0; i--) {
if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':') {
i++;
break;
}
}
printf("\n---> '%s' ", &lpFile[i]);
len = min(cbBuf, strlen(&lpFile[i]) + 1);
strncpy(lpTitle, &lpFile[i], len + 1);
if (len != cbBuf)
return len;
else
return 0;
}