1
0
Fork 0
mirror of synced 2025-03-07 03:53:26 +01:00
wine/dlls/comctl32/updown.c
Alexandre Julliard d30dfd24d6 Release 980927
Sun Sep 27 14:25:38 1998  Petter Reinholdtsen <pere@td.org.uit.no>

	* [files/drive.c]
	Make sure GetDriveType32A() handles param NULL.  Added some
	doc on function.

Sun Sep 27 14:07:26 1998  Huw D M Davies <daviesh@abacus.physics.ox.ac.uk>

	* [controls/edit.c] [windows/win.c]
	Don't call SetWindowLong() in EDIT_WM_NCREATE.
	Fix SetWindowLong(GWL_[EX]STYLE) to work for 16bit windows. Remove
	UpdateWindow() call. 

Sun Sep 27 13:41:22 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [scheduler/*.c] [server/event.c] [server/mutex.c]
	  [server/semaphore.c]
	Implemented server-side synchronisation objects.

Sun Sep 27 01:13:35 1998  Alex Priem <alexp@sci.kun.nl>

	* [dlls/comctl32/treeview.c] [include/treeview.h] [include/comctl.h]
	Treeview implementation.

	* [dlls/comctl32/trackbar.c] [include/trackbar.h] 
	Trackbar implementation.

Sat Sep 26 20:49:13 1998  Ulrich Weigand <weigand@informatik.uni-erlangen.de>

	* [if1632/thunk.c] [tools/build.c] [win32/kernel32.c]
	Bugfix: several problems with flat thunks fixed.

	* [memory/selector.c]
	Bugfix: IsBad...Ptr16 didn't work for limit_in_pages segments.

	* [scheduler/thread.c]
	Bugfix: CreateThread: Allow id parameter == NULL.

	* [objects/gdiobj.c]
	Bugfix: IsGDIObject: Return correct object type for stock objects.

	* [msdos/dpmi.c]
	Bugfix: fixed typo in INT_DoRealModeInt.

	* [msdos/int21.c]
	Bugfix: int21 READ *must* use WIN16_hread, not _hread16.

	* [if1632/kernel.spec] [if1632/dummy.c] [if1632/thunk.c]
	  [loader/ne/module.c] [scheduler/event.c] [scheduler/synchro.c]
	  [scheduler/thread.c] [win32/kernel32.c] [win32/ordinals.c]
	Added names/stubs for all undocumented KERNEL routines (Win95).
	Added the following undoc. 16-bit equivalents to Win32 routines:
	KERNEL.441-443,449-453,456-462,471-476,479-486,488.
	Added stubs for some other KERNEL routines.

	* [memory/heap.c] [memory/global.c] [include/global.h]
	Implemented Local32... 32-bit local heap routines (KERNEL.208-215, 229).

	* [miscemu/instr.c] [loader/module.c] [include/module.h]
	Implemented __GP fault handling and HasGPHandler (KERNEL.338).

	* [misc/error.c]
	Implemented LogParamErrorRegs (KERNEL.327).

	* [loader/task.c] [include/windows.h]
	Implemented GetCodeInfo (KERNEL.104).

	* [loader/task.c] [scheduler/thread.c] [include/thread.h]
	Implemented [GS]etThreadQueue and [GS]etFastQueue (KERNEL.463/4, 624/5).

	* [if1632/gdi.spec] [objects/dc.c] [objects/dib.c]
	  [objects/bitmap.c] [include/windows.h]
	Bugfix: fixed wrong parameter for CreateDIBSection16.
	Added [GS]etDIBColorTable16, stub for GetBoundsRect16.
	Partially implemented BITMAP_GetObject16 for DIBs.

	* [if1632/gdi.spec] [relay32/gdi32.spec] [objects/palette.c]
	Added some GDI stubs.

	* [if1632/Makefile.in] [if1632/display.spec] [if1632/mouse.spec]
	  [if1632/keyboard.spec] [if1632/builtin.c] [windows/keyboard.c]
	Added some stubs for Win16 drivers: KEYBOARD, MOUSE, DISPLAY.

	* [if1632/wprocs.spec] [msdos/vxd.c]
	Added some stubs for VxDs: VMM, ConfigMG, TimerAPI.

	* [msdos/int2f.c]
	Added some stubs for real-mode network drivers.

Sat Sep 26 18:18:18 1998  Marcus Meissner <marcus@jet.franken.de>

	* [configure.in]
	Merged in some more of the FreeBSD ports/emulators/wine patches. 
	(Maintainer(s) of this port: You can just submit these
	patches to Alexandre directly.)

	 * [loader/pe_image.c]
	Check filesize of image against size derived from header
	to spot truncated executeables without crashing.

	* [files/directory.c]
	Set envvar "COMSPEC". One win32(!!) program crashes without it.

	* [multimedia/mmio.c]
	Added mmioSetInfo32.

	* [include/file.h]
	Return STD_ERROR_HANDLE for AUX and PRT dos handles.

	* [loader/module.c]
	Handle executeables with spaces in their names a bit better in
	CreateProcess.

	* [relay32/msvfw32.spec][if1632/msvideo.spec][multimedia/msvideo.c][include/vfw.h]
	Started on MS Video support (can load Win32 ICMs).

	* [tools/testrun]
	A bit smarter use of ps.

	* [memory/virtual.c]
	Report PAGE_GUARDed pages as PAGE_PROTECTED (AutoCAD LT R17 fails
	without that check (since Win95 doesn't know about PAGE_GUARD)).

Sat Sep 26 15:04:05 1998  Ove Kaaven <ovek@arcticnet.no>

	* [include/miscemu.h] [if1632/builtin.c] [loader/task.c]
	  [miscemu/instr.c] [msdos/dpmi.c] [msdos/int21.c]
	  [msdos/interrupts.c] [windows/user.c]
	INT_[S|G]etHandler was renamed to INT_[S|G]etPMHandler.
	Added handlers to deal with real-mode interrupts; DOS
	programs are now able to hook real-mode interrupts.

	* [loader/dos/module.c] [msdos/dosmem.c] [msdos/int21.c]
	Moved real-mode interrupt table initialization to
	msdos/dosmem.c, and made new V86 tasks get a full copy
	of the existing "system memory" instead of almost empty
	space. Misc fixes.

	* [include/dosexe.h] [loader/dos/module.c] [msdos/dpmi.c]
	  [msdos/int2f.c]
	First shot at letting DOS programs start up DPMI (but DPMI
	is still disabled for DOS programs, for pkunzip's sake).

	* [include/debugger.h] [debugger/break.c] [debugger/dbg.y]
	  [debugger/registers.c] [debugger/memory.c] [debugger/info.c]
	  [loader/dos/dosvm.c]
	First shot at making Wine's debugger work for DOS programs.
	The -debug flag works, as do "nexti" and "stepi".

Sat Sep 26 13:13:13 1998  Juergen Schmied <juergen.schmied@metronet.de>

	* [dlls/shell32/dataobject.c]
	New classes IEnumFORMATETC implemented, IDataObject stubs.
	
	* [dlls/shell32/*.*][relay32/shell32.spec]
	Bugfixes.
	New: ICM_InsertItem(), ILCreateFromPath().
	Implemented: ILCloneFirst().
	Stubs: ILIsEqual(), ILFindChild(), SHLogILFromFSIL(),
	  PathMatchSpec(), PathIsExe().
	Changed: ILGetSize(), _ILIsDesktop(), PathCombine().

	* [include/shlobj.h]
	New SHLGUID's
	New structures: DVTARGETDEVICE32, STGMEDIUM32, FORMATETC32,
	CLIPFORMAT32.
	New interfaces: IEnumFORMATETC, IDataObject, ICommDlgBrowser
	IDockingWindowFrame, IServiceProvider.

	* [dlls/shell32/folders.c]
	Stubs for IShellLink.

	* [loader/resource.c]
	Small fixes.

	* [misc/crtdll.c][relay32/crtdll.spec]
	New __dllonexit().

	* [windows/message.c]
	SendNotifyMessageA, SendMessageCallBack32A half implemented.

	* [controls/edit.c]
	EDIT_WM_SetText set EF_UPDATE flag not for ES_MULTILINE.

	* [files/file.c]
	Handling of fileposition fixed.

Fri Sep 25 18:13:30 1998  Patrik Stridvall <ps@leissner.se>

	* [include/windows.h] [include/wintypes.h]
	  [ole/ole2nls.h] [relay32/kernel32.spec]
	Implemented EnumDateFormats and EnumTimeFormats.
	Only adds US English support.

	* [Makefile.in] [configure.in] 
	  [dlls/Makefile.in] [dlls/psapi/Makefile.in] 
	  [dlls/psapi/psapi_main.c] 
	New files to implement stubs for PSAPI.DLL (NT only).

	* [relay32/Makefile.in] [relay32/builtin32.c] 
	  [relay32/psapi.spec]
	New spec file for PSAPI.DLL (NT only).

	* [scheduler/handle.c]
	HANDLE_GetObjPtr should only interpret the pseudo handles as the
	current thread or the current process if a thread or a process is
	requested.

	* [include/winversion.h] [misc/version.c]
	Adds the global function VERSION_GetVersion() so functions can
	have different behavior depending on the -winver flag.

	* [include/oledlg.h] [ole/oledlg.c]
	Minor fixes. 

	* [windows/winproc.c]
	Minor changes.

	* [include/imm.h] [misc/imm.c]
	Now returns correct values under both Windows 95 and NT 4.0.

Thu Sep 24 22:11:44 1998  Kristian Nielsen  <kristian.nielsen@risoe.dk>

	* [configure.in] [include/acconfig.h] [include/thread.h]
	  [scheduler/sysdeps.c]
	Autoconfig test for non-reentrant libc.

Wed Sep 23 19:52:12 1998  Matthew Becker <mbecker@glasscity.net>

	* [*/*.c]
	Miscellaneous documentation updates and debugging output 
	standardizations.

	* [objects/clipping.c]
	Added ExtSelectClipRgn.

Wed Sep 23 00:03:28 EDT 1998  Pete Ratzlaff <pratzlaff@cfa.harvard.edu>

	* [include/windows.h] [if1632/user.spec] [relay32/user32.spec]
	  [windows/keyboard.c]
	Added, marginally implemented, GetKeyboardLayoutName().
	Only returns US English keyboard name.

Tue Sep 22 16:32:41 1998  Marcel Baur <mbaur@iiic.ethz.ch>

	* [programs/control/*]
	New Winelib application.

Mon Sep 21 00:29:18 1998  Peter Hunnisett <hunnise@nortel.ca>

	* [include/dplay.h][multimedia/dplay.c][ole/compobj.c]
	Added all DirectPlayLobby interfaces and enhanced DirectPlay
	and DirectPlayLobby support. Still not all that much. Useful
	enough if you just need to start a program, don't try any
	real dplay/lobby stuff.

	* [documentation/status/directplay]
	Added a very little bit.

	* [graphics/ddraw.c]
	- Call to SetWindowLong32A wasn't working because there was no
	  memory set aside when the window class was registered.
	- Fixed some xlib reference counting and change the behaviour
	  of DirectDrawSurface3_SetPalette to mimic observed behaviour
	  (palette is associated will all backbuffers)
	- Also stored all palette colour fields and spit back our saved
	  colour fields rather than query X for them.
	- Added plenty of AddRef and Release traces.
	- Added Xlib support for using -desktop option.
	- Fixed Xlib message handling. Messages weren't being passed to
	  the application. Fixes mouse movements in some xlib DDraw games.
	- Added a few stubs.

	* [windows/win.c][include/winerror.h]
	Fixed up some error handling in WIN_SetWindowLong. SetLastError
	wasn't being used. Could cause problems with 0 return codes.
	Added new error in winerror (1400).

	* [AUTHORS] [include/authors.h]
	Added myself as a Wine author.

Sun Sep 20 21:22:44 1998  Alexander Larsson  <alla@lysator.liu.se>

	* [loader/module.c]
	Changed GetModuleFileName32A so that is returns the
	long version of the filename. Note that just the name
	is long, not the directories.

Sat Sep 19 20:05:30 1998 Per Ångström <pang@mind.nu> 

	* [controls/menu.c]
	Made a couple of fixes to make life easier for applications that alter
	their menus at runtime.

	* [windows/defdlg.c]
	Removed the cast of the return value from dialog procedures to a 16-bit
	bool. The return value needs to retain all its 32 bits, since it is not 
	always a bool, such as when responding to the WM_NCHITTEST message.

Fri Sep 18 11:30:38 1998  Sergey Turchanov <turchanov@usa.net>

	* [loader/resource.c]
	Fixed very funny bug (though gravely affecting further excecution)
	with FindResource[Ex]32 functions.

	* [include/multimon.h] [windows/multimon.c] [relay32/user32.spec]
	  [include/windows.h] [windows/sysmetrics.c]
	Default implementation for Multimonitor API.

	* [include/windows.h] [windows/winpos.c]
	Fixed incorrect declaration (and behaviour) of GetWindowRect32.

Wed Sep 16 10:21:15 1998  Gerard Patel <G.Patel@Wanadoo.fr>

	* [controls/edit.c]
	Fixed EDIT_EM_GetLine to use correctly length of lines.

Tue Sep 15 20:40:16 1998  Eric Kohl <ekohl@abo.rhein-zeitung.de>

	* [misc/tweak.c][include/tweak.h][controls/menu.c]
	Replaced the tweak graphic routines by calls to DrawEdge32().

	* [misc/tweak.c][include/tweak.h][documentation/win95look]
	  [wine.ini][*/*]
	Changed "look and feel" selection. Allows Win3.1, Win95 and
	Win98 (no GUI code implemented) look and feel.

	* [dlls/comctl32/header.c][include/header.h][include/commctrl.h]
	Started callback item support and did some minor improvements.

	* [dlls/comctl32/imagelist.c]
	Fixed bug in transparent image display.
	ImageList_GetIcon is still buggy :-(

	* [dlls/comctl32/toolbar.c]
	Fixed button drawing (partial hack).

	* [dlls/comctl32/commctrl.c]
	Fixed MenuHelp().

	* [controls/button.c]
	Added 3d effect for groupbox.

	* [windows/msgbox.c]
	Added font support for message boxes.

	* [windows/nonclient.c]
	Fixed window moving bug.

	* [dlls/comctl32/*.c]
	Various improvements.

	* [dlls/comctl32/listview.c][dlls/comctl32/rebar.c]
	  [include/commctrl.h]
	More messages.

	* [windows/syscolor.c][include/windows.h]
	Introduced new Win98 system colors.

Tue Sep 15 18:29:45 1998 Wesley Filardo <eightknots@aol.com>

	* [files/profile.c]
	Added support in PROFILE_LoadWineIni for -config option

	* [misc/main.c] [include/options.h]
	Added -config option.

Tue Sep 15 18:22:26 1998  Petter Reinholdtsen <pere@td.org.uit.no>

	* [documentation/Makefile.in]
	Make sure directory exists before installing into it.

Tue Sep 15 01:47:33 1998  Pablo Saratxaga <pablo.sarachaga@ping.be>

	* [ole/nls/*] [ole/ole2nls.c] [include/winnls.h]
	Fixed a few errors and completed some NLS files.

Mon Sep 14 01:23:45 1998  Joseph Pranevich <knight@baltimore.wwaves.com>

	* [include/miscemu.h] [msdos/interrupts.c]
	Removed a compilation warning, added INT 25 to the list of interrupts
	callable from DOS applications, added a debug message when unsupported
	interrupts are used.

Sun Sep 13 19:55:22 1998  Lawson Whitney <lawson_whitney@juno.com>

	* [if1632/relay.c]
	CallProcEx32W should not reverse arguments.

Sun Aug 17 21:18:12 1998  Eric Pouech  <eric.pouech@lemel.fr>

	* [multimedia/midi.c] [multimedia/init.c] [multimedia/mmsys.c] 
	  [include/multimedia.h] [include/mmsystem.h] 
	  [multimedia/Makefile.in] [multimedia/midipatch.c]
	  [if1632/multimedia.spec]
	Made MIDI input and output functional on OSS capable systems.

	* [multimedia/timer.c]
	Changes to trigger callbacks at the accurate pace even when
	fake timers are used.
1998-09-27 18:28:36 +00:00

845 lines
25 KiB
C

/*
* Updown control
*
* Copyright 1997 Dimitrie O. Paun
*
* TODO:
* - subclass the buddy window (in UPDOWN_SetBuddy) to process the
* arrow keys
* - I am not sure about the default values for the Min, Max, Pos
* (in the UPDOWN_INFO the fields: MinVal, MaxVal, CurVal)
* - I think I do not handle correctly the WS_BORDER style.
* (Should be fixed. <ekohl@abo.rhein-zeitung.de>)
*
* Testing:
* Not much. The following have not been tested at all:
* - horizontal arrows
* - listbox as buddy window
* - acceleration
* - base 16
* - UDS_ALIGNLEFT, ~UDS_WRAP
* - integers with thousand separators.
* Even though the above list seems rather large, the control seems to
* behave very well so I am confident it does work in most (all) of the
* untested cases.
* Problems:
* I do not like the arrows yet, I'll work more on them later on.
*/
#include <stdlib.h>
#include "windows.h"
#include "commctrl.h"
#include "winnls.h"
#include "sysmetrics.h"
#include "updown.h"
#include "graphics.h"
#include "win.h"
#include "debug.h"
/* Control configuration constants */
#define INITIAL_DELAY 500 /* initial timer until auto-increment kicks in */
#define REPEAT_DELAY 50 /* delay between auto-increments */
#define DEFAULT_WIDTH 14 /* default width of the ctrl */
#define DEFAULT_XSEP 0 /* default separation between buddy and crtl */
#define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */
#define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */
/* Work constants */
#define FLAG_INCR 0x01
#define FLAG_DECR 0x02
#define FLAG_MOUSEIN 0x04
#define FLAG_CLICKED (FLAG_INCR | FLAG_DECR)
#define TIMERID1 1
#define TIMERID2 2
static int accelIndex = -1;
#define UNKNOWN_PARAM(msg, wParam, lParam) WARN(updown, \
"UpDown Ctrl: Unknown parameter(s) for message " #msg \
"(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
#define UPDOWN_GetInfoPtr(wndPtr) ((UPDOWN_INFO *)wndPtr->wExtra[0])
/***********************************************************************
* UPDOWN_InBounds
* Tests if a given value 'val' is between the Min&Max limits
*/
static BOOL32 UPDOWN_InBounds(WND *wndPtr, int val)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
if(infoPtr->MaxVal > infoPtr->MinVal)
return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
else
return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
}
/***********************************************************************
* UPDOWN_OffsetVal
* Tests if we can change the current value by delta. If so, it changes
* it and returns TRUE. Else, it leaves it unchanged and returns FALSE.
*/
static BOOL32 UPDOWN_OffsetVal(WND *wndPtr, int delta)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
/* check if we can do the modification first */
if(!UPDOWN_InBounds(wndPtr, infoPtr->CurVal+delta)){
if(wndPtr->dwStyle & UDS_WRAP)
delta += (delta < 0 ? -1 : 1) *
(infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
(infoPtr->MinVal - infoPtr->MaxVal) +
(delta < 0 ? 1 : -1);
else
return FALSE;
}
infoPtr->CurVal += delta;
return TRUE;
}
/***********************************************************************
* UPDOWN_GetArrowRect
* wndPtr - pointer to the up-down wnd
* rect - will hold the rectangle
* incr - TRUE get the "increment" rect (up or right)
* FALSE get the "decrement" rect (down or left)
*
*/
static void UPDOWN_GetArrowRect(WND *wndPtr, RECT32 *rect, BOOL32 incr)
{
int len; /* will hold the width or height */
GetClientRect32(wndPtr->hwndSelf, rect);
if (wndPtr->dwStyle & UDS_HORZ) {
len = rect->right - rect->left; /* compute the width */
if (incr)
rect->left = len/2+1;
else
rect->right = len/2;
}
else {
len = rect->bottom - rect->top; /* compute the height */
if (incr)
rect->bottom = len/2;
else
rect->top = len/2+1;
}
}
/***********************************************************************
* UPDOWN_GetArrowFromPoint
* Returns the rectagle (for the up or down arrow) that contains pt.
* If it returns the up rect, it returns TRUE.
* If it returns the down rect, it returns FALSE.
*/
static int UPDOWN_GetArrowFromPoint(WND *wndPtr, RECT32 *rect, POINT32 pt)
{
UPDOWN_GetArrowRect(wndPtr, rect, TRUE);
if(PtInRect32(rect, pt))
return TRUE;
UPDOWN_GetArrowRect(wndPtr, rect, FALSE);
return FALSE;
}
/***********************************************************************
* UPDOWN_GetThousandSep
* Returns the thousand sep. If an error occurs, it returns ','.
*/
static char UPDOWN_GetThousandSep()
{
char sep[2];
if(GetLocaleInfo32A(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
sep, sizeof(sep)) != 1)
return ',';
return sep[0];
}
/***********************************************************************
* UPDOWN_GetBuddyInt
* Tries to read the pos from the buddy window and if it succeeds,
* it stores it in the control's CurVal
* returns:
* TRUE - if it read the integer from the buddy successfully
* FALSE - if an error occured
*/
static BOOL32 UPDOWN_GetBuddyInt(WND *wndPtr)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
char txt[20], sep, *src, *dst;
int newVal;
if (!IsWindow32(infoPtr->Buddy))
return FALSE;
/*if the buddy is a list window, we must set curr index */
if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_LISTBOX)){
newVal = SendMessage32A(infoPtr->Buddy, LB_GETCARETINDEX32, 0, 0);
if(newVal < 0)
return FALSE;
}
else{
/* we have a regular window, so will get the text */
if (!GetWindowText32A(infoPtr->Buddy, txt, sizeof(txt)))
return FALSE;
sep = UPDOWN_GetThousandSep();
/* now get rid of the separators */
for(src = dst = txt; *src; src++)
if(*src != sep)
*dst++ = *src;
*dst = 0;
/* try to convert the number and validate it */
newVal = strtol(txt, &src, infoPtr->Base);
if(*src || !UPDOWN_InBounds(wndPtr, newVal))
return FALSE;
TRACE(updown, "new value(%d) read from buddy (old=%d)\n",
newVal, infoPtr->CurVal);
}
infoPtr->CurVal = newVal;
return TRUE;
}
/***********************************************************************
* UPDOWN_SetBuddyInt
* Tries to set the pos to the buddy window based on current pos
* returns:
* TRUE - if it set the caption of the buddy successfully
* FALSE - if an error occured
*/
static BOOL32 UPDOWN_SetBuddyInt(WND *wndPtr)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
char txt1[20], sep;
int len;
if (!IsWindow32(infoPtr->Buddy))
return FALSE;
TRACE(updown, "set new value(%d) to buddy.\n",
infoPtr->CurVal);
/*if the buddy is a list window, we must set curr index */
if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_LISTBOX)){
SendMessage32A(infoPtr->Buddy, LB_SETCURSEL32, infoPtr->CurVal, 0);
}
else{ /* Regular window, so set caption to the number */
len = sprintf(txt1, (infoPtr->Base==16) ? "%X" : "%d", infoPtr->CurVal);
sep = UPDOWN_GetThousandSep();
if (!(wndPtr->dwStyle & UDS_NOTHOUSANDS)) {
char txt2[20], *src = txt1, *dst = txt2;
if(len%3 > 0){
lstrcpyn32A (dst, src, len%3);
dst += len%3;
src += len%3;
}
for(len=0; *src; len++,src++){
if(len%3==0)
*dst++ = sep;
*dst++ = *src++;
}
*dst = 0; /* null terminate it */
strcpy(txt1, txt2); /* move it to the proper place */
}
SetWindowText32A(infoPtr->Buddy, txt1);
}
return TRUE;
}
/***********************************************************************
* UPDOWN_Draw [Internal]
*
* Draw the arrows. The background need not be erased.
*/
static void UPDOWN_Draw (WND *wndPtr, HDC32 hdc)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
BOOL32 prssed;
RECT32 rect;
/* Draw the incr button */
UPDOWN_GetArrowRect(wndPtr, &rect, TRUE);
prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
DrawFrameControl32(hdc, &rect, DFC_SCROLL,
(wndPtr->dwStyle & UDS_HORZ ? DFCS_SCROLLLEFT : DFCS_SCROLLUP) |
(prssed ? DFCS_PUSHED : 0) |
(wndPtr->dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
/* Draw the space between the buttons */
rect.top = rect.bottom; rect.bottom++;
DrawEdge32(hdc, &rect, 0, BF_MIDDLE);
/* Draw the decr button */
UPDOWN_GetArrowRect(wndPtr, &rect, FALSE);
prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
DrawFrameControl32(hdc, &rect, DFC_SCROLL,
(wndPtr->dwStyle & UDS_HORZ ? DFCS_SCROLLRIGHT : DFCS_SCROLLDOWN) |
(prssed ? DFCS_PUSHED : 0) |
(wndPtr->dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
}
/***********************************************************************
* UPDOWN_Refresh [Internal]
*
* Synchronous drawing (must NOT be used in WM_PAINT).
* Calls UPDOWN_Draw.
*/
static void UPDOWN_Refresh (WND *wndPtr)
{
HDC32 hdc;
hdc = GetDC32 (wndPtr->hwndSelf);
UPDOWN_Draw (wndPtr, hdc);
ReleaseDC32 (wndPtr->hwndSelf, hdc);
}
/***********************************************************************
* UPDOWN_Paint [Internal]
*
* Asynchronous drawing (must ONLY be used in WM_PAINT).
* Calls UPDOWN_Draw.
*/
static void UPDOWN_Paint (WND *wndPtr)
{
PAINTSTRUCT32 ps;
HDC32 hdc;
hdc = BeginPaint32 (wndPtr->hwndSelf, &ps);
UPDOWN_Draw (wndPtr, hdc);
EndPaint32 (wndPtr->hwndSelf, &ps);
}
/***********************************************************************
* UPDOWN_SetBuddy
* Tests if 'hwndBud' is a valid window handle. If not, returns FALSE.
* Else, sets it as a new Buddy.
* Then, it should subclass the buddy
* If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
* process the UP/DOWN arrow keys.
* If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
* the size/pos of the buddy and the control are adjusted accordingly.
*/
static BOOL32 UPDOWN_SetBuddy(WND *wndPtr, HWND32 hwndBud)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
RECT32 budRect; /* new coord for the buddy */
int x; /* new x position and width for the up-down */
/* Is is a valid bud? */
if(!IsWindow32(hwndBud))
return FALSE;
if(wndPtr->dwStyle & UDS_ARROWKEYS){
FIXME(updown, "we need to subclass the buddy to process the arrow keys.\n");
}
/* do we need to do any adjustments? */
if(!(wndPtr->dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)))
return TRUE;
/* Get the rect of the buddy relative to its parent */
GetWindowRect32(infoPtr->Buddy, &budRect);
MapWindowPoints32(HWND_DESKTOP, GetParent32(infoPtr->Buddy),
(POINT32 *)(&budRect.left), 2);
/* now do the positioning */
if(wndPtr->dwStyle & UDS_ALIGNRIGHT){
budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
x = budRect.right+DEFAULT_XSEP;
}
else{ /* UDS_ALIGNLEFT */
x = budRect.left;
budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
}
/* first adjust the buddy to accomodate the up/down */
SetWindowPos32(infoPtr->Buddy, 0, budRect.left, budRect.top,
budRect.right - budRect.left, budRect.bottom - budRect.top,
SWP_NOACTIVATE|SWP_NOZORDER);
/* now position the up/down */
/* Since the UDS_ALIGN* flags were used, */
/* we will pick the position and size of the window. */
SetWindowPos32(wndPtr->hwndSelf,0,x,budRect.top-DEFAULT_ADDTOP,DEFAULT_WIDTH,
(budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
SWP_NOACTIVATE|SWP_NOZORDER);
return TRUE;
}
/***********************************************************************
* UPDOWN_DoAction
*
* This function increments/decrements the CurVal by the
* 'delta' amount according to the 'incr' flag
* It notifies the parent as required.
* It handles wraping and non-wraping correctly.
* It is assumed that delta>0
*/
static void UPDOWN_DoAction(WND *wndPtr, int delta, BOOL32 incr)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
int old_val = infoPtr->CurVal;
NM_UPDOWN ni;
TRACE(updown, "%s by %d\n", incr ? "inc" : "dec", delta);
/* check if we can do the modification first */
delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
if(!UPDOWN_OffsetVal(wndPtr, delta))
return;
/* so, if we can do the change, recompute delta and restore old value */
delta = infoPtr->CurVal - old_val;
infoPtr->CurVal = old_val;
/* We must notify parent now to obtain permission */
ni.iPos = infoPtr->CurVal;
ni.iDelta = delta;
ni.hdr.hwndFrom = wndPtr->hwndSelf;
ni.hdr.idFrom = wndPtr->wIDmenu;
ni.hdr.code = UDN_DELTAPOS;
if(SendMessage32A(wndPtr->parent->hwndSelf,
WM_NOTIFY, wndPtr->wIDmenu, (LPARAM)&ni))
return; /* we are not allowed to change */
/* Now adjust value with (maybe new) delta */
if(!UPDOWN_OffsetVal(wndPtr, ni.iDelta))
return;
/* Now take care about our buddy */
if(!IsWindow32(infoPtr->Buddy))
return; /* Nothing else to do */
if(wndPtr->dwStyle & UDS_SETBUDDYINT)
UPDOWN_SetBuddyInt(wndPtr);
/* Also, notify it */
/* FIXME: do we need to send the notification only if
we do not have the UDS_SETBUDDYINT style set? */
SendMessage32A(GetParent32 (wndPtr->hwndSelf),
wndPtr->dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
MAKELONG(incr ? SB_LINEUP : SB_LINEDOWN, infoPtr->CurVal),
wndPtr->hwndSelf);
}
/***********************************************************************
* UPDOWN_IsEnabled
*
* Returns TRUE if it is enabled as well as its buddy (if any)
* FALSE otherwise
*/
static BOOL32 UPDOWN_IsEnabled(WND *wndPtr)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
if(wndPtr->dwStyle & WS_DISABLED)
return FALSE;
return IsWindowEnabled32(infoPtr->Buddy);
}
/***********************************************************************
* UPDOWN_CancelMode
*
* Deletes any timers, releases the mouse and does redraw if necessary.
* If the control is not in "capture" mode, it does nothing.
* If the control was not in cancel mode, it returns FALSE.
* If the control was in cancel mode, it returns TRUE.
*/
static BOOL32 UPDOWN_CancelMode(WND *wndPtr)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
/* if not in 'capture' mode, do nothing */
if(!(infoPtr->Flags & FLAG_CLICKED))
return FALSE;
KillTimer32(wndPtr->hwndSelf, TIMERID1); /* kill all possible timers */
KillTimer32(wndPtr->hwndSelf, TIMERID2);
if(GetCapture32() == wndPtr->hwndSelf) /* let the mouse go */
ReleaseCapture(); /* if we still have it */
infoPtr->Flags = 0; /* get rid of any flags */
UPDOWN_Refresh (wndPtr); /* redraw the control just in case */
return TRUE;
}
/***********************************************************************
* UPDOWN_HandleMouseEvent
*
* Handle a mouse event for the updown.
* 'pt' is the location of the mouse event in client or
* windows coordinates.
*/
static void UPDOWN_HandleMouseEvent(WND *wndPtr, UINT32 msg, POINT32 pt)
{
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
RECT32 rect;
int temp;
switch(msg)
{
case WM_LBUTTONDOWN: /* Initialise mouse tracking */
/* If we are already in the 'clicked' mode, then nothing to do */
if(infoPtr->Flags & FLAG_CLICKED)
return;
/* If the buddy is an edit, will set focus to it */
if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_EDIT))
SetFocus32(infoPtr->Buddy);
/* Now see which one is the 'active' arrow */
temp = UPDOWN_GetArrowFromPoint(wndPtr, &rect, pt);
/* Update the CurVal if necessary */
if(wndPtr->dwStyle & UDS_SETBUDDYINT)
UPDOWN_GetBuddyInt(wndPtr);
/* Before we proceed, see if we can spin... */
if(!(wndPtr->dwStyle & UDS_WRAP))
if(( temp && infoPtr->CurVal==infoPtr->MaxVal) ||
(!temp && infoPtr->CurVal==infoPtr->MinVal))
return;
/* Set up the correct flags */
infoPtr->Flags = 0;
infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
infoPtr->Flags |= FLAG_MOUSEIN;
/* repaint the control */
UPDOWN_Refresh (wndPtr);
/* process the click */
UPDOWN_DoAction(wndPtr, 1, infoPtr->Flags & FLAG_INCR);
/* now capture all mouse messages */
SetCapture32(wndPtr->hwndSelf);
/* and startup the first timer */
SetTimer32(wndPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0);
break;
case WM_MOUSEMOVE:
/* If we are not in the 'clicked' mode, then nothing to do */
if(!(infoPtr->Flags & FLAG_CLICKED))
return;
/* save the flags to see if any got modified */
temp = infoPtr->Flags;
/* Now get the 'active' arrow rectangle */
if (infoPtr->Flags & FLAG_INCR)
UPDOWN_GetArrowRect(wndPtr, &rect, TRUE);
else
UPDOWN_GetArrowRect(wndPtr, &rect, FALSE);
/* Update the flags if we are in/out */
if(PtInRect32(&rect, pt))
infoPtr->Flags |= FLAG_MOUSEIN;
else{
infoPtr->Flags &= ~FLAG_MOUSEIN;
if(accelIndex != -1) /* if we have accel info */
accelIndex = 0; /* reset it */
}
/* If state changed, redraw the control */
if(temp != infoPtr->Flags)
UPDOWN_Refresh (wndPtr);
break;
default:
ERR(updown, "Impossible case!\n");
}
}
/***********************************************************************
* UpDownWndProc
*/
LRESULT WINAPI UpDownWindowProc(HWND32 hwnd, UINT32 message, WPARAM32 wParam,
LPARAM lParam)
{
WND *wndPtr = WIN_FindWndPtr(hwnd);
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
int temp;
switch(message)
{
case WM_NCCREATE:
/* get rid of border, if any */
wndPtr->dwStyle &= ~WS_BORDER;
return TRUE;
case WM_CREATE:
infoPtr = (UPDOWN_INFO*)COMCTL32_Alloc (sizeof(UPDOWN_INFO));
wndPtr->wExtra[0] = (DWORD)infoPtr;
/* initialize the info struct */
infoPtr->AccelCount=0; infoPtr->AccelVect=0;
infoPtr->CurVal=0; infoPtr->MinVal=0; infoPtr->MaxVal=100; /*FIXME*/
infoPtr->Base = 10; /* Default to base 10 */
infoPtr->Buddy = 0; /* No buddy window yet */
infoPtr->Flags = 0; /* And no flags */
/* Do we pick the buddy win ourselves? */
if(wndPtr->dwStyle & UDS_AUTOBUDDY)
UPDOWN_SetBuddy(wndPtr, GetWindow32(wndPtr->hwndSelf, GW_HWNDPREV));
TRACE(updown, "UpDown Ctrl creation, hwnd=%04x\n", hwnd);
break;
case WM_DESTROY:
if(infoPtr->AccelVect)
COMCTL32_Free (infoPtr->AccelVect);
COMCTL32_Free (infoPtr);
wndPtr->wExtra[0] = 0;
TRACE(updown, "UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
break;
case WM_ENABLE:
if(wndPtr->dwStyle & WS_DISABLED)
UPDOWN_CancelMode(wndPtr);
UPDOWN_Paint(wndPtr);
break;
case WM_TIMER:
/* if initial timer, kill it and start the repeat timer */
if(wParam == TIMERID1){
KillTimer32(hwnd, TIMERID1);
/* if no accel info given, used default timer */
if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0){
accelIndex = -1;
temp = REPEAT_DELAY;
}
else{
accelIndex = 0; /* otherwise, use it */
temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
}
SetTimer32(hwnd, TIMERID2, temp, 0);
}
/* now, if the mouse is above us, do the thing...*/
if(infoPtr->Flags & FLAG_MOUSEIN){
temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc;
UPDOWN_DoAction(wndPtr, temp, infoPtr->Flags & FLAG_INCR);
if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1){
KillTimer32(hwnd, TIMERID2);
accelIndex++; /* move to the next accel info */
temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
/* make sure we have at least 1ms intervals */
SetTimer32(hwnd, TIMERID2, temp, 0);
}
}
break;
case WM_CANCELMODE:
UPDOWN_CancelMode(wndPtr);
break;
case WM_LBUTTONUP:
if(!UPDOWN_CancelMode(wndPtr))
break;
/*If we released the mouse and our buddy is an edit */
/* we must select all text in it. */
if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_EDIT))
SendMessage32A(infoPtr->Buddy, EM_SETSEL32, 0, MAKELONG(0, -1));
break;
case WM_LBUTTONDOWN:
case WM_MOUSEMOVE:
if(UPDOWN_IsEnabled(wndPtr)){
POINT32 pt;
CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
UPDOWN_HandleMouseEvent( wndPtr, message, pt );
}
break;
case WM_KEYDOWN:
if((wndPtr->dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(wndPtr)){
switch(wParam){
case VK_UP:
case VK_DOWN:
UPDOWN_GetBuddyInt(wndPtr);
UPDOWN_DoAction(wndPtr, 1, wParam==VK_UP);
break;
}
}
break;
case WM_PAINT:
UPDOWN_Paint(wndPtr);
break;
case UDM_GETACCEL:
if (wParam==0 && lParam==0) /*if both zero, */
return infoPtr->AccelCount; /*just return the accel count*/
if (wParam || lParam){
UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
return 0;
}
temp = MIN(infoPtr->AccelCount, wParam);
memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
return temp;
case UDM_SETACCEL:
TRACE(updown, "UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
if(infoPtr->AccelVect){
COMCTL32_Free (infoPtr->AccelVect);
infoPtr->AccelCount = 0;
infoPtr->AccelVect = 0;
}
if(wParam==0)
return TRUE;
infoPtr->AccelVect = COMCTL32_Alloc (wParam*sizeof(UDACCEL));
if(infoPtr->AccelVect==0)
return FALSE;
memcpy(infoPtr->AccelVect, (void*)lParam, wParam*sizeof(UDACCEL));
return TRUE;
case UDM_GETBASE:
if (wParam || lParam)
UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam);
return infoPtr->Base;
case UDM_SETBASE:
TRACE(updown, "UpDown Ctrl new base(%d), hwnd=%04x\n",
wParam, hwnd);
if ( !(wParam==10 || wParam==16) || lParam)
UNKNOWN_PARAM(UDM_SETBASE, wParam, lParam);
if (wParam==10 || wParam==16){
temp = infoPtr->Base;
infoPtr->Base = wParam;
return temp; /* return the prev base */
}
break;
case UDM_GETBUDDY:
if (wParam || lParam)
UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam);
return infoPtr->Buddy;
case UDM_SETBUDDY:
if (lParam)
UNKNOWN_PARAM(UDM_SETBUDDY, wParam, lParam);
temp = infoPtr->Buddy;
infoPtr->Buddy = wParam;
UPDOWN_SetBuddy(wndPtr, wParam);
TRACE(updown, "UpDown Ctrl new buddy(%04x), hwnd=%04x\n",
infoPtr->Buddy, hwnd);
return temp;
case UDM_GETPOS:
if (wParam || lParam)
UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
temp = UPDOWN_GetBuddyInt(wndPtr);
return MAKELONG(infoPtr->CurVal, temp ? 0 : 1);
case UDM_SETPOS:
if (wParam || HIWORD(lParam))
UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
temp = SLOWORD(lParam);
TRACE(updown, "UpDown Ctrl new value(%d), hwnd=%04x\n",
temp, hwnd);
if(!UPDOWN_InBounds(wndPtr, temp)){
if(temp < infoPtr->MinVal)
temp = infoPtr->MinVal;
if(temp > infoPtr->MaxVal)
temp = infoPtr->MaxVal;
}
wParam = infoPtr->CurVal; /* save prev value */
infoPtr->CurVal = temp; /* set the new value */
if(wndPtr->dwStyle & UDS_SETBUDDYINT)
UPDOWN_SetBuddyInt(wndPtr);
return wParam; /* return prev value */
case UDM_GETRANGE:
if (wParam || lParam)
UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal);
case UDM_SETRANGE:
if (wParam)
UNKNOWN_PARAM(UDM_SETRANGE, wParam, lParam); /* we must have: */
infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
/* |Max-Min| <= UD_MAXVAL */
TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
infoPtr->MinVal, infoPtr->MaxVal, hwnd);
break;
case UDM_GETRANGE32:
if (wParam)
*(LPINT32)wParam = infoPtr->MinVal;
if (lParam)
*(LPINT32)lParam = infoPtr->MaxVal;
break;
case UDM_SETRANGE32:
infoPtr->MinVal = (INT32)wParam;
infoPtr->MaxVal = (INT32)lParam;
if (infoPtr->MaxVal <= infoPtr->MinVal)
infoPtr->MaxVal = infoPtr->MinVal + 1;
TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
infoPtr->MinVal, infoPtr->MaxVal, hwnd);
break;
default:
if (message >= WM_USER)
ERR (updown, "unknown msg %04x wp=%04x lp=%08lx\n",
message, wParam, lParam);
return DefWindowProc32A (hwnd, message, wParam, lParam);
}
return 0;
}
/***********************************************************************
* UPDOWN_Register [Internal]
*
* Registers the updown window class.
*/
void UPDOWN_Register(void)
{
WNDCLASS32A wndClass;
if( GlobalFindAtom32A( UPDOWN_CLASS32A ) ) return;
ZeroMemory( &wndClass, sizeof( WNDCLASS32A ) );
wndClass.style = CS_GLOBALCLASS | CS_VREDRAW;
wndClass.lpfnWndProc = (WNDPROC32)UpDownWindowProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = sizeof(UPDOWN_INFO*);
wndClass.hCursor = LoadCursor32A( 0, IDC_ARROW32A );
wndClass.hbrBackground = (HBRUSH32)(COLOR_3DFACE + 1);
wndClass.lpszClassName = UPDOWN_CLASS32A;
RegisterClass32A( &wndClass );
}