wine/controls/combo.c
Alexandre Julliard 988ca977ab Release 940620
Mon Jun 20 14:26:41 1994  Bob Amstadt  (bob@pooh)

	* [objects/bitmap.c]
	Allow negative bitmap sizes.

Sun Jun 19 12:00:04 1994  David Metcalfe <david@prism.demon.co.uk>

        * [controls/edit.c]
        Improved selection display.  Added processing for WM_SETFONT,
        EM_REPLACESEL, EM_LINELENGTH, EM_UNDO, EM_EMPTYUNDOBUFFER,
        EM_GETHANDLE, EM_SETHANDLE messages.  Text buffer now stored on 
        application's local heap.

        * [windows/graphics.c]
        Corrected bug in Rectangle().  XFillRectangle has the same
        width as Rectangle, but XDrawRectangle is one pixel wider
        for the same co-ordinates.

        * [memory/heap.c] [include/heap.h]
        Added HEAP_LocalSize function.

        * [windows/event.c] [windows/keyboard.c]
        Improvements to KeyStateTable and addition of AsyncKeyStateTable.
        Added supporting code to GetKeyState and GetAsyncKeyState and
        merged mouse button states into GetKeyboardState.

        * [loader/resource.c] [include/accel.h]
        Added recognition of SHIFT, CONTROL and ALT keys to
        TranslateAccelerator.

        * [objects/metafile.c] [objects/font.c] [objects/bitblt.c]
        A bit more metafile support.

Sun Jun 19 17:29:00 MET DST 1994  Erik Bos (erik@hacktic.nl)

        * [loader/resource.c]
        SizeofResource() and AllocResource() added, AccessResource() updated.

        * [if1632/kernel.spec]
        FreeLibrary() used for FreeModule().

        * [windows/graphics.c]
        Rectangle(): swap left & right corners when right < left,
        swap top & bottom when botton < top.

Jun 19, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [controls/combo.c]
	Fix bug in window style of the associated listbox.

	* [controls/menu.c]
	Skip separators in keyboard navigation by using new internal 
		functions SelectPrevItem() & SelectNextItem(),

	* [misc/profile.c]
	Bug fix in GetPrivateProfileInt(), was limited to 4 digit,
		IntBuf must be alloc to (5+1)=6. char instead of 5.

	* [misc/main.c]
	Put code in functions SetEnvironment() & GetEnvironment().

	* [misc/shell.c]
	Start putting some code in ExtractIcon() function.

	* [misc/mmsystem.c]
	Some code for MMTimer functions & timers list.

	* [miscemu/int31.c]
	Few stubs for DPMI interrupt calls. Nothing work yet.

Mon Jun 20 07:37:43 EDT 1994	John Richardson (jrichard@cs.uml.edu)

	* include/win.h (tagWND):
	Added icon fields icon, hIcon and rectClientSave to 
	the tagWND struct.

	* windows/Imakefile
	Added icon.c to the list of files to compile

	* windows/dce.c (GetDCEx):
	Added some checks for iconic mode and pass icon window as drawable,
	not the real window.

	* windows/defwnd.c (DefWindowProc)
	Added PAINTICON default windows procedure.

	* windows/event.c (EVENT_Expose)
	Added check for iconic window expose. If iconic window is exposed
	send a WM_PAINTICON message

	* windows/icon.c 
	New file.  ICON_Iconify, ICON_findIconFromPoint, ICON_Deiconify.

	* windows/mdi.c (DefMDIChildProc)
	Test for IsIconic during a SC_RESTORE, this doesn't work yet.

	* windows/message.c (hardware_event)
	Looks for icon as well as window now.

	* windows/nonclient.c (NC_HandleSysCommand, NC_DoNCPaintIcon)
	Added iconify/deiconify in NC_HandleSysCommand, new function
	NC_DoNCPaintIcon which paints an icon.

	* windows/painting.c (BeginPaint)
	Made a BeginPaint select the STOCK_BLACK_PEN, STOCK_WHITE_BRUSH,
	and STOCK_SYSTEM_FONT objects since this is (hopefully) default
	windows behavior.

	* windows/win.h (CreateWindowEx)
	Set the default background color of a window to be white.
	Create icon window, turn off MINIMIZE if it is on, since
	I don't know what to do with it as of yet... register
	the icon with the hwnd of its window so we can identify where
	icon messages are coming from.

Mon Jun 20 10:15:59 1994  Miguel de Icaza  (miguel@sphinx)

	* windows/event.c: Added a hack to define XPointer when using
	X11R4. 

	* toolkit/hello.c: Test application for WineLib. To compile you'll
	need: gcc -Iinclude -DWINELIB -g hello.c -c, and to link you'll
	need: gcc hello.o libwine.a -lX11 -L/usr/openwin/lib -lm 

	* toolkit/heap.c: Extended the size of the block size per chunk.

	* misc/stress.c (GetFreeFileHandles): Fixed typo.

	* misc/main.c (main): Changes to allow compilation under SunOS. 

	* loader/library.c: Changed some ifdefs to compile WineLib.
1994-06-21 16:15:21 +00:00

441 lines
13 KiB
C

/*
* Interface code to COMBOBOX widget
*
* Copyright Martin Ayotte, 1993
*
*/
#define DEBUG_COMBO
/*
#define DEBUG_COMBO
*/
static char Copyright[] = "Copyright Martin Ayotte, 1993";
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "windows.h"
#include "combo.h"
#include "heap.h"
#include "win.h"
#include "prototypes.h"
HBITMAP hComboBit = 0;
LPHEADCOMBO ComboGetStorageHeader(HWND hwnd);
int CreateComboStruct(HWND hwnd);
/***********************************************************************
* ComboWndProc
*/
LONG ComboBoxWndProc( HWND hwnd, WORD message, WORD wParam, LONG lParam )
{
WORD wRet;
RECT rect;
int y, count;
int width, height;
int AltState;
WND *wndPtr;
LPHEADCOMBO lphc;
HDC hDC, hMemDC;
BITMAP bm;
char str[128];
PAINTSTRUCT paintstruct;
static RECT rectsel;
switch(message)
{
case WM_CREATE:
wndPtr = WIN_FindWndPtr(hwnd);
if (wndPtr == NULL) return 0;
#ifdef DEBUG_COMBO
printf("Combo WM_CREATE %lX !\n", lphc);
#endif
if (hComboBit == (HBITMAP)NULL)
hComboBit = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_COMBO));
GetObject(hComboBit, sizeof(BITMAP), (LPSTR)&bm);
wndPtr->dwStyle &= 0xFFFFFFFFL ^ (WS_VSCROLL | WS_HSCROLL);
GetWindowRect(hwnd, &rect);
width = rect.right - rect.left;
height = rect.bottom - rect.top;
SetWindowPos(hwnd, 0, 0, 0, width + bm.bmHeight, bm.bmHeight,
SWP_NOMOVE | SWP_NOZORDER);
CreateComboStruct(hwnd);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
if (wndPtr->dwStyle & CBS_SIMPLE)
/* lphc->hWndEdit = CreateWindow("EDIT", "", */
lphc->hWndEdit = CreateWindow("STATIC", "",
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | SS_LEFT,
0, 0, width - bm.bmHeight, bm.bmHeight,
hwnd, 1, wndPtr->hInstance, 0L);
else
lphc->hWndEdit = CreateWindow("STATIC", "",
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | SS_LEFT,
0, 0, width - bm.bmHeight, bm.bmHeight,
hwnd, 1, wndPtr->hInstance, 0L);
lphc->hWndLBox = CreateWindow("LISTBOX", "",
WS_POPUP | WS_BORDER | WS_VSCROLL | LBS_NOTIFY,
rect.left, rect.top + bm.bmHeight,
width, height, wndPtr->hwndParent, 0,
wndPtr->hInstance, (LPSTR)MAKELONG(0, hwnd));
ShowWindow(lphc->hWndLBox, SW_HIDE);
#ifdef DEBUG_COMBO
printf("Combo Creation LBox=%X!\n", lphc->hWndLBox);
#endif
return 0;
case WM_DESTROY:
lphc = ComboGetStorageHeader(hwnd);
if (lphc == 0) return 0;
/*
DestroyWindow(lphc->hWndEdit);
*/
DestroyWindow(lphc->hWndLBox);
free(lphc);
/*
*((LPHEADCOMBO *)&wndPtr->wExtra[1]) = 0;
printf("Combo WM_DESTROY after clearing wExtra !\n");
*/
#ifdef DEBUG_COMBO
printf("Combo WM_DESTROY %lX !\n", lphc);
#endif
return DefWindowProc( hwnd, message, wParam, lParam );
case WM_SHOWWINDOW:
#ifdef DEBUG_COMBO
printf("ComboBox WM_SHOWWINDOW hWnd=%04X !\n", hwnd);
#endif
if (!(wParam == 0 && lParam == 0L)) {
InvalidateRect(hwnd, NULL, TRUE);
}
break;
case WM_COMMAND:
wndPtr = WIN_FindWndPtr(hwnd);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
if (LOWORD(lParam) == lphc->hWndLBox) {
switch(HIWORD(lParam)) {
case LBN_SELCHANGE:
lphc->dwState = lphc->dwState & (CB_SHOWDROPDOWN ^ 0xFFFFFFFFL);
ShowWindow(lphc->hWndLBox, SW_HIDE);
y = SendMessage(lphc->hWndLBox, LB_GETCURSEL, 0, 0L);
if (y != LB_ERR) {
SendMessage(lphc->hWndLBox, LB_GETTEXT, (WORD)y, (LPARAM)str);
SendMessage(lphc->hWndEdit, WM_SETTEXT, (WORD)y, (LPARAM)str);
}
SendMessage(GetParent(hwnd), WM_COMMAND, wndPtr->wIDmenu,
MAKELONG(hwnd, CBN_SELCHANGE));
break;
case LBN_DBLCLK:
SendMessage(GetParent(hwnd), WM_COMMAND, wndPtr->wIDmenu,
MAKELONG(hwnd, CBN_DBLCLK));
break;
}
}
break;
case WM_LBUTTONDOWN:
printf("Combo WM_LBUTTONDOWN wParam=%x lParam=%lX !\n", wParam, lParam);
GetClientRect(hwnd, &rect);
rect.left = rect.right - (rect.bottom - rect.top);
hDC = GetDC(hwnd);
InflateRect(&rect, -1, -1);
DrawReliefRect(hDC, rect, 1, 1);
ReleaseDC(hwnd, hDC);
wndPtr = WIN_FindWndPtr(hwnd);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
lphc->dwState = lphc->dwState ^ CB_SHOWDROPDOWN;
if ((lphc->dwState & CB_SHOWDROPDOWN) == CB_SHOWDROPDOWN) {
ShowWindow(lphc->hWndLBox, SW_SHOW);
SetFocus(lphc->hWndLBox);
}
else {
printf("before Combo Restore Focus !\n");
SetFocus(lphc->hWndEdit);
printf("before Combo List Hide !\n");
ShowWindow(lphc->hWndLBox, SW_HIDE);
printf("before Combo List GetCurSel !\n");
y = SendMessage(lphc->hWndLBox, LB_GETCURSEL, 0, 0L);
if (y != LB_ERR) {
printf("before Combo List GetText !\n");
SendMessage(lphc->hWndLBox, LB_GETTEXT, (WORD)y, (LPARAM)str);
SendMessage(lphc->hWndEdit, WM_SETTEXT, (WORD)y, (LPARAM)str);
}
printf("End of Combo List Hide !\n");
}
break;
case WM_LBUTTONUP:
printf("Combo WM_LBUTTONUP wParam=%x lParam=%lX !\n", wParam, lParam);
GetClientRect(hwnd, &rect);
rect.left = rect.right - (rect.bottom - rect.top);
hDC = GetDC(hwnd);
InflateRect(&rect, -1, -1);
DrawReliefRect(hDC, rect, 1, 0);
ReleaseDC(hwnd, hDC);
break;
case WM_KEYDOWN:
wndPtr = WIN_FindWndPtr(hwnd);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
y = SendMessage(lphc->hWndLBox, LB_GETCURSEL, 0, 0L);
count = SendMessage(lphc->hWndLBox, LB_GETCOUNT, 0, 0L);
printf("COMBOBOX // GetKeyState(VK_MENU)=%d\n", GetKeyState(VK_MENU));
if (GetKeyState(VK_MENU) < 0) {
lphc->dwState = lphc->dwState ^ CB_SHOWDROPDOWN;
if ((lphc->dwState & CB_SHOWDROPDOWN) == CB_SHOWDROPDOWN) {
ShowWindow(lphc->hWndLBox, SW_SHOW);
SetFocus(lphc->hWndLBox);
}
else {
ShowWindow(lphc->hWndLBox, SW_HIDE);
y = SendMessage(lphc->hWndLBox, LB_GETCURSEL, 0, 0L);
if (y != LB_ERR) {
SendMessage(lphc->hWndLBox, LB_GETTEXT, (WORD)y, (LPARAM)str);
SendMessage(lphc->hWndEdit, WM_SETTEXT, (WORD)y, (LPARAM)str);
}
}
}
else {
switch(wParam) {
case VK_HOME:
y = 0;
break;
case VK_END:
y = count - 1;
break;
case VK_UP:
y--;
break;
case VK_DOWN:
y++;
break;
}
if (y < 0) y = 0;
if (y >= count) y = count - 1;
SendMessage(lphc->hWndLBox, LB_SETCURSEL, y, 0L);
SendMessage(lphc->hWndLBox, LB_GETTEXT, (WORD)y, (LPARAM)str);
SendMessage(lphc->hWndEdit, WM_SETTEXT, (WORD)y, (LPARAM)str);
SendMessage(GetParent(hwnd), WM_COMMAND, wndPtr->wIDmenu,
MAKELONG(hwnd, CBN_SELCHANGE));
}
break;
case WM_MEASUREITEM:
printf("ComboBoxWndProc WM_MEASUREITEM !\n");
return(SendMessage(GetParent(hwnd), WM_MEASUREITEM, wParam, lParam));
case WM_CTLCOLOR:
return(SendMessage(GetParent(hwnd), WM_CTLCOLOR, wParam, lParam));
case WM_PAINT:
GetClientRect(hwnd, &rect);
hDC = BeginPaint(hwnd, &paintstruct);
hMemDC = CreateCompatibleDC(hDC);
if (hMemDC != 0 && hComboBit != 0) {
GetObject(hComboBit, sizeof(BITMAP), (LPSTR)&bm);
SelectObject(hMemDC, hComboBit);
BitBlt(hDC, rect.right - bm.bmWidth, 0,
bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
}
DeleteDC(hMemDC);
EndPaint(hwnd, &paintstruct);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
InvalidateRect(lphc->hWndEdit, NULL, TRUE);
UpdateWindow(lphc->hWndEdit);
if ((lphc->dwState & CB_SHOWDROPDOWN) == CB_SHOWDROPDOWN) {
InvalidateRect(lphc->hWndLBox, NULL, TRUE);
UpdateWindow(lphc->hWndLBox);
}
break;
case WM_SETFOCUS:
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
SetFocus(lphc->hWndEdit);
break;
case WM_KILLFOCUS:
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
ShowWindow(lphc->hWndLBox, SW_HIDE);
y = SendMessage(lphc->hWndLBox, LB_GETCURSEL, 0, 0L);
if (y != LB_ERR) {
SendMessage(lphc->hWndLBox, LB_GETTEXT, (WORD)y, (LPARAM)str);
SendMessage(lphc->hWndEdit, WM_SETTEXT, (WORD)y, (LPARAM)str);
}
break;
case CB_ADDSTRING:
#ifdef DEBUG_COMBO
printf("CB_ADDSTRING '%s' !\n", (LPSTR)lParam);
#endif
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_ADDSTRING, wParam, lParam));
case CB_GETLBTEXT:
#ifdef DEBUG_COMBO
printf("CB_GETLBTEXT #%u !\n", wParam);
#endif
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_GETTEXT, wParam, lParam));
case CB_GETLBTEXTLEN:
printf("CB_GETLBTEXTLEN !\n");
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_GETTEXTLEN, wParam, lParam));
case CB_INSERTSTRING:
printf("CB_INSERTSTRING '%s' !\n", (LPSTR)lParam);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam));
case CB_DELETESTRING:
printf("CB_DELETESTRING #%u !\n", wParam);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_DELETESTRING, wParam, 0L));
case CB_RESETCONTENT:
printf("CB_RESETCONTENT !\n");
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_RESETCONTENT, 0, 0L));
case CB_DIR:
printf("ComboBox CB_DIR !\n");
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_DIR, wParam, lParam));
case CB_FINDSTRING:
lphc = ComboGetStorageHeader(hwnd);
return(SendMessage(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam));
case CB_GETCOUNT:
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_GETCOUNT, 0, 0L));
case CB_GETCURSEL:
printf("ComboBox CB_GETCURSEL !\n");
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_GETCURSEL, 0, 0L));
case CB_SETCURSEL:
printf("ComboBox CB_SETCURSEL wParam=%X !\n", wParam);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_SETCURSEL, wParam, 0L));
case CB_GETEDITSEL:
printf("ComboBox CB_GETEDITSEL !\n");
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
/* return(SendMessage(lphc->hWndEdit, EM_GETSEL, 0, 0L)); */
break;
case CB_SETEDITSEL:
printf("ComboBox CB_SETEDITSEL lParam=%lX !\n", lParam);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
/* return(SendMessage(lphc->hWndEdit, EM_SETSEL, 0, lParam)); */
break;
case CB_SELECTSTRING:
printf("ComboBox CB_SELECTSTRING !\n");
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
break;
case CB_SHOWDROPDOWN:
printf("ComboBox CB_SHOWDROPDOWN !\n");
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
lphc->dwState = lphc->dwState | CB_SHOWDROPDOWN;
if (wParam != 0) {
ShowWindow(lphc->hWndLBox, SW_SHOW);
}
else {
lphc->dwState = lphc->dwState ^ CB_SHOWDROPDOWN;
ShowWindow(lphc->hWndLBox, SW_HIDE);
SendMessage(GetParent(hwnd), WM_COMMAND, wndPtr->wIDmenu,
MAKELONG(hwnd, CBN_DROPDOWN));
}
break;
case CB_GETITEMDATA:
printf("ComboBox CB_GETITEMDATA wParam=%X !\n", wParam);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0L));
break;
case CB_SETITEMDATA:
printf("ComboBox CB_SETITEMDATA wParam=%X lParam=%lX !\n", wParam, lParam);
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
return(SendMessage(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam));
break;
case CB_LIMITTEXT:
printf("ComboBox CB_LIMITTEXT !\n");
lphc = ComboGetStorageHeader(hwnd);
if (lphc == NULL) return 0;
/* return(SendMessage(lphc->hWndEdit, EM_LIMITTEXT, wParam, 0L)); */
break;
default:
return DefWindowProc( hwnd, message, wParam, lParam );
}
return 0;
}
LPHEADCOMBO ComboGetStorageHeader(HWND hwnd)
{
WND *wndPtr;
LPHEADCOMBO lphc;
wndPtr = WIN_FindWndPtr(hwnd);
if (wndPtr == 0) {
printf("Bad Window handle on ComboBox !\n");
return 0;
}
lphc = *((LPHEADCOMBO *)&wndPtr->wExtra[1]);
return lphc;
}
int CreateComboStruct(HWND hwnd)
{
WND *wndPtr;
LPHEADCOMBO lphc;
wndPtr = WIN_FindWndPtr(hwnd);
if (wndPtr == 0) {
printf("Bad Window handle on ComboBox !\n");
return 0;
}
lphc = (LPHEADCOMBO)malloc(sizeof(HEADCOMBO));
*((LPHEADCOMBO *)&wndPtr->wExtra[1]) = lphc;
lphc->dwState = 0;
return TRUE;
}
/************************************************************************
* DlgDirSelectComboBox [USER.194]
*/
BOOL DlgDirSelectComboBox(HWND hDlg, LPSTR lpStr, int nIDLBox)
{
printf("DlgDirSelectComboBox(%04X, '%s', %d) \n", hDlg, lpStr, nIDLBox);
}
/************************************************************************
* DlgDirListComboBox [USER.195]
*/
int DlgDirListComboBox(HWND hDlg, LPSTR lpPathSpec,
int nIDLBox, int nIDStat, WORD wType)
{
HWND hWnd;
LPHEADCOMBO lphc;
printf("DlgDirListComboBox(%04X, '%s', %d, %d, %04X) \n",
hDlg, lpPathSpec, nIDLBox, nIDStat, wType);
hWnd = GetDlgItem(hDlg, nIDLBox);
lphc = ComboGetStorageHeader(hWnd);
if (lphc == NULL) return 0;
SendMessage(lphc->hWndLBox, LB_RESETCONTENT, 0, 0L);
return SendMessage(lphc->hWndLBox, LB_DIR, wType, (DWORD)lpPathSpec);
}