head	1.23;
access;
symbols
	core-8-5-9:1.15.2.1
	core-8-5-8:1.15.2.1
	macosx-cocoa-merge:1.17
	macosx-cocoa-premerge:1.17
	macosx-carbon-freeze:1.17
	core-8-5-7:1.15.2.1
	core-8-5-6:1.15.2.1
	core-8-6-b1:1.17
	core-8-6-a3:1.16
	core-8-5-5:1.15.2.1
	core-8-6-a2:1.15
	core-8-5-4:1.15
	core-8-5-3:1.15
	core-8-6-a1:1.15
	core-8-4-19:1.9
	core-8-5-branch:1.15.0.2
	core-8-5-2:1.15
	core-8-4-18:1.9
	core-8-5-1:1.15
	core-8-4-17:1.9
	core-8-5-0:1.15
	core-8-5-b3:1.12
	core-8-5-b2:1.12
	core-8-4-16:1.9
	core-8-5-b1:1.12
	core-stablilizer-merge:1.12
	core-stabilizer-branch:1.12.0.2
	core-stabilizer-merge:1.15
	core-8-4-15:1.9
	core-8-5-a6:1.12
	core-8-5-a5:1.12
	core-8-4-14:1.9
	core-8-5-a4:1.12
	core-8-4-13:1.9
	core-8-4-12:1.9
	core-8-4-11:1.9
	core-8-5-a3:1.10
	core-8-4-10:1.9
	core-8-4-9-branch:1.9.0.6
	core-8-5-a2:1.10
	core-8-4-9:1.9
	core-8-4-8:1.9
	core-8-4-7:1.9
	core-8-5-a1:1.10
	core-8-4-6:1.9
	core-8-4-5:1.9
	mistachkin-dev-branch:1.9.0.4
	core-8-4-4:1.9
	core-8-4-3:1.9
	core-8-4-branch:1.9.0.2
	core-8-4-2:1.9
	core-8-4-1:1.8
	core-8-3-5:1.5.2.1
	core-8-4-0:1.8
	macosx-8-4-merge-2002-08-31-trunk:1.8
	macosx-8-4-premerge-2002-08-31-branch:1.7.4.1
	macosx-8-4-premerge-2002-08-31-trunk:1.8
	macosx-8-4-merge-2002-08-30-branch:1.7.4.1
	macosx-8-4-merge-2002-08-30-trunk:1.8
	macosx-8-4-merge-2002-08-20-branch:1.7.4.1
	macosx-8-4-merge-2002-08-20-trunk:1.8
	core-8-4-b2:1.8
	core-8-4-b1:1.8
	macosx-premerge-6-9-02:1.7
	core-8-4-a4:1.7
	core-8-3-4:1.5.2.1
	macosx-8-4-branch:1.7.0.4
	macosx-8-4-branchpoint:1.7
	core-8-4-a3:1.7
	core-8-3-3:1.5.2.1
	dgp-privates-into-namespace:1.7.0.2
	tclpro-1-5-0:1.5
	core-8-4-win-speedup:1.6.0.2
	core-8-4-a2:1.6
	tclpro-1-4-1:1.5
	tclpro-1-4-0:1.5
	core-8-3-2:1.5
	ajuba-ajuba2-2-1-base:1.5
	ajuba-ajuba2-2-0:1.5
	core-8-4-a1:1.5
	core-8-3-1-branch:1.5.0.2
	core-8-3-1:1.5
	scriptics-sc-2-0-b5:1.4
	scriptics-sc-2-0-fixed:1.4
	scriptics-sc-2-0-b2:1.4
	scriptics-sc-2-0-b1:1.4
	core-8-3-0:1.4
	core-8-3-b2:1.4
	core-8-3-b1:1.3
	scriptics-sc-1-1:1.3
	scriptics-sc-1-1-b1:1.3
	core-8-2-3:1.3
	scriptics-sc-1-1-branch:1.3.0.10
	scriptics-sc-1-1-base:1.3
	scriptics-sc-1-0:1.3
	scriptics-sc-1-0-branch:1.3.0.8
	scriptics-sc-1-0-base:1.3
	core-8-2-2:1.3
	core-8-2-1:1.3
	scriptics-bc-1-0-b1:1.3
	core-8-2-1-branch:1.3.0.6
	scriptics-tclpro-1-3-0:1.3
	core-8-2-0:1.3
	core-8-2-b3-branch:1.3.0.4
	core-8-2-b3-base:1.3
	scriptics-tclpro-1-3-b4:1.3
	core-8-2-b2:1.3
	scriptics-tclpro-1-3-b3:1.3
	core-8-2-b1:1.3
	scriptics-tclpro-1-3-b2:1.3
	merge-to-mainline-5/21/99:1.3
	scriptics-tclpro-1-3-b2-branch:1.3.0.2
	core-8-1-1:1.3
	scriptics-tclpro-1-3-b1:1.3
	core-8-1-1-base:1.3
	core-8-1-0:1.3
	merge-to-mainline-4-29-99:1.3
	merge-to-mainline-4-23-99:1.3
	core-8-1-branch-old:1.1.0.4
	core-8-0-6-branch:1.2.0.6
	core-8-0-6-base:1.2
	core-8-0-5:1.2
	core-8-1-b3:1.1.4.3
	core-8-1-b2:1.1.4.3
	dev-8-1-stubs-branch:1.1.4.3.0.2
	dev-stubs-branch:1.2.0.4
	scriptics-tclpro-1-2:1.2
	scriptics-tclpro-1-2-b2:1.2
	core-8-1-merge-2/10/99:1.2
	core-8-0-5-branch:1.2.0.2
	core-8-0-5-base:1.2
	scriptics-tclpro-1-2-b1:1.2
	scriptics-tclpro-1-2-a1:1.2
	core-8-1-b1:1.1.4.2
	core-8-0-4:1.2
	core-8-1-a2:1.1.4.1
	core-8-0-2:1.1
	core-8-0-3:1.2;
locks; strict;
comment	@ * @;


1.23
date	2010.11.29.09.07.13;	author nijtmans;	state Exp;
branches;
next	1.22;

1.22
date	2010.06.19.16.18.41;	author jenglish;	state Exp;
branches;
next	1.21;

1.21
date	2010.04.29.15.28.04;	author nijtmans;	state Exp;
branches;
next	1.20;

1.20
date	2010.02.17.19.21.17;	author nijtmans;	state Exp;
branches;
next	1.19;

1.19
date	2010.02.16.21.12.56;	author nijtmans;	state Exp;
branches;
next	1.18;

1.18
date	2010.01.13.23.08.11;	author nijtmans;	state Exp;
branches;
next	1.17;

1.17
date	2008.12.09.21.22.56;	author dgp;	state Exp;
branches;
next	1.16;

1.16
date	2008.10.03.13.13.31;	author dkf;	state Exp;
branches;
next	1.15;

1.15
date	2007.12.14.15.56.09;	author patthoyts;	state Exp;
branches
	1.15.2.1;
next	1.14;

1.14
date	2007.12.13.15.28.56;	author dgp;	state Exp;
branches;
next	1.13;

1.13
date	2007.12.05.19.08.00;	author hobbs;	state Exp;
branches;
next	1.12;

1.12
date	2005.12.02.13.42.29;	author dkf;	state Exp;
branches
	1.12.2.1;
next	1.11;

1.11
date	2005.12.02.00.19.04;	author dkf;	state Exp;
branches;
next	1.10;

1.10
date	2004.01.13.02.06.02;	author davygrvy;	state Exp;
branches;
next	1.9;

1.9
date	2003.02.21.02.07.50;	author hobbs;	state Exp;
branches;
next	1.8;

1.8
date	2002.06.14.22.25.12;	author jenglish;	state Exp;
branches;
next	1.7;

1.7
date	2000.11.22.01.49.38;	author ericm;	state Exp;
branches
	1.7.4.1;
next	1.6;

1.6
date	2000.11.03.01.22.17;	author hobbs;	state Exp;
branches
	1.6.2.1;
next	1.5;

1.5
date	2000.03.31.09.24.27;	author hobbs;	state Exp;
branches
	1.5.2.1;
next	1.4;

1.4
date	2000.01.13.02.07.27;	author hobbs;	state Exp;
branches;
next	1.3;

1.3
date	99.04.16.01.51.53;	author stanton;	state Exp;
branches;
next	1.2;

1.2
date	98.09.14.18.24.01;	author stanton;	state Exp;
branches;
next	1.1;

1.1
date	98.04.01.10.00.32;	author rjohnson;	state Exp;
branches
	1.1.4.1;
next	;

1.1.4.1
date	98.09.29.00.26.09;	author stanton;	state Exp;
branches;
next	1.1.4.2;

1.1.4.2
date	98.09.30.02.19.37;	author stanton;	state Exp;
branches;
next	1.1.4.3;

1.1.4.3
date	98.12.13.08.16.19;	author lfb;	state Exp;
branches;
next	;

1.5.2.1
date	2001.04.04.07.57.18;	author hobbs;	state Exp;
branches;
next	;

1.6.2.1
date	2002.04.02.21.17.05;	author hobbs;	state Exp;
branches;
next	;

1.7.4.1
date	2002.08.20.20.27.19;	author das;	state Exp;
branches;
next	;

1.12.2.1
date	2007.12.05.20.26.47;	author dgp;	state Exp;
branches;
next	1.12.2.2;

1.12.2.2
date	2008.01.23.16.39.14;	author dgp;	state Exp;
branches;
next	;

1.15.2.1
date	2008.10.05.11.34.46;	author dkf;	state Exp;
branches;
next	;


desc
@@


1.23
log
@Fix various 64-bit gcc(-4.5.2) warnings: cast from pointer to integer of different size
@
text
@/*
 * tkWinScrollbar.c --
 *
 *	This file implements the Windows specific portion of the scrollbar
 *	widget.
 *
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.22 2010/06/19 16:18:41 jenglish Exp $
 */

#include "tkWinInt.h"
#include "tkScrollbar.h"

/*
 * The following constant is used to specify the maximum scroll position. This
 * value is limited by the Win32 API to either 16-bits or 32-bits, depending
 * on the context. For now we'll just use a value small enough to fit in
 * 16-bits, but which gives us 4-digits of precision.
 */

#define MAX_SCROLL 10000

/*
 * Declaration of Windows specific scrollbar structure.
 */

typedef struct WinScrollbar {
    TkScrollbar info;		/* Generic scrollbar info. */
    WNDPROC oldProc;		/* Old window procedure. */
    int lastVertical;		/* 1 if was vertical at last refresh. */
    HWND hwnd;			/* Current window handle. */
    int winFlags;		/* Various flags; see below. */
} WinScrollbar;

/*
 * Flag bits for native scrollbars:
 *
 * IN_MODAL_LOOP:		Non-zero means this scrollbar is in the middle
 *				of a modal loop.
 * ALREADY_DEAD:		Non-zero means this scrollbar has been
 *				destroyed, but has not been cleaned up.
 */

#define IN_MODAL_LOOP	1
#define ALREADY_DEAD	2

/*
 * Cached system metrics used to determine scrollbar geometry.
 */

static int initialized = 0;
static int hArrowWidth, hThumb; /* Horizontal control metrics. */
static int vArrowHeight, vThumb; /* Vertical control metrics. */

TCL_DECLARE_MUTEX(winScrlbrMutex)

/*
 * Declarations for functions defined in this file.
 */

static Window		CreateProc(Tk_Window tkwin, Window parent,
			    ClientData instanceData);
static void		ModalLoop(WinScrollbar *, XEvent *eventPtr);
static LRESULT CALLBACK	ScrollbarProc(HWND hwnd, UINT message, WPARAM wParam,
			    LPARAM lParam);
static void		UpdateScrollbar(WinScrollbar *scrollPtr);
static void		UpdateScrollbarMetrics(void);

/*
 * The class procedure table for the scrollbar widget.
 */

const Tk_ClassProcs tkpScrollbarProcs = {
    sizeof(Tk_ClassProcs),	/* size */
    NULL,			/* worldChangedProc */
    CreateProc,			/* createProc */
    NULL 			/* modalProc */
};

static void
WinScrollbarEventProc(ClientData clientData, XEvent *eventPtr)
{
    WinScrollbar *scrollPtr = clientData;

    if (eventPtr->type == ButtonPress) {
	ModalLoop(scrollPtr, eventPtr);
    } else {
	TkScrollbarEventProc(clientData, eventPtr);
    }
}


/*
 *----------------------------------------------------------------------
 *
 * TkpCreateScrollbar --
 *
 *	Allocate a new TkScrollbar structure.
 *
 * Results:
 *	Returns a newly allocated TkScrollbar structure.
 *
 * Side effects:
 *	Registers an event handler for the widget.
 *
 *----------------------------------------------------------------------
 */

TkScrollbar *
TkpCreateScrollbar(
    Tk_Window tkwin)
{
    WinScrollbar *scrollPtr;

    if (!initialized) {
	Tcl_MutexLock(&winScrlbrMutex);
	UpdateScrollbarMetrics();
	initialized = 1;
	Tcl_MutexUnlock(&winScrlbrMutex);
    }

    scrollPtr = (WinScrollbar *) ckalloc(sizeof(WinScrollbar));
    scrollPtr->winFlags = 0;
    scrollPtr->hwnd = NULL;

    Tk_CreateEventHandler(tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask|ButtonPressMask,
	    WinScrollbarEventProc, scrollPtr);

    return (TkScrollbar *) scrollPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateScrollbar --
 *
 *	This function updates the position and size of the scrollbar thumb
 *	based on the current settings.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Moves the thumb.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateScrollbar(
    WinScrollbar *scrollPtr)
{
    SCROLLINFO scrollInfo;
    double thumbSize;

    /*
     * Update the current scrollbar position and shape.
     */

    scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
    scrollInfo.cbSize = sizeof(scrollInfo);
    scrollInfo.nMin = 0;
    scrollInfo.nMax = MAX_SCROLL;
    thumbSize = (scrollPtr->info.lastFraction - scrollPtr->info.firstFraction);
    scrollInfo.nPage = ((UINT) (thumbSize * (double) MAX_SCROLL)) + 1;
    if (thumbSize < 1.0) {
	scrollInfo.nPos = (int)
		((scrollPtr->info.firstFraction / (1.0-thumbSize))
		* (MAX_SCROLL - (scrollInfo.nPage - 1)));
    } else {
	scrollInfo.nPos = 0;

	/*
	 * Disable the scrollbar when there is nothing to scroll. This is
	 * standard Windows style (see eg Notepad). Also prevents possible
	 * crash on XP+ systems [Bug #624116].
	 */

	scrollInfo.fMask |= SIF_DISABLENOSCROLL;
    }
    SetScrollInfo(scrollPtr->hwnd, SB_CTL, &scrollInfo, TRUE);
}

/*
 *----------------------------------------------------------------------
 *
 * CreateProc --
 *
 *	This function creates a new Scrollbar control, subclasses the
 *	instance, and generates a new Window object.
 *
 * Results:
 *	Returns the newly allocated Window object, or None on failure.
 *
 * Side effects:
 *	Causes a new Scrollbar control to come into existence.
 *
 *----------------------------------------------------------------------
 */

static Window
CreateProc(
    Tk_Window tkwin,		/* Token for window. */
    Window parentWin,		/* Parent of new window. */
    ClientData instanceData)	/* Scrollbar instance data. */
{
    DWORD style;
    Window window;
    HWND parent;
    TkWindow *winPtr;
    WinScrollbar *scrollPtr = (WinScrollbar *)instanceData;

    parent = Tk_GetHWND(parentWin);

    if (scrollPtr->info.vertical) {
	style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS
		| SBS_VERT | SBS_RIGHTALIGN;
    } else {
	style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS
		| SBS_HORZ | SBS_BOTTOMALIGN;
    }

    scrollPtr->hwnd = CreateWindow(TEXT("SCROLLBAR"), NULL, style,
	    Tk_X(tkwin), Tk_Y(tkwin), Tk_Width(tkwin), Tk_Height(tkwin),
	    parent, NULL, Tk_GetHINSTANCE(), NULL);

    /*
     * Ensure new window is inserted into the stacking order at the correct
     * place.
     */

    SetWindowPos(scrollPtr->hwnd, HWND_TOP, 0, 0, 0, 0,
		    SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

    for (winPtr = ((TkWindow*)tkwin)->nextPtr; winPtr != NULL;
	    winPtr = winPtr->nextPtr) {
	if ((winPtr->window != None) && !(winPtr->flags & TK_TOP_HIERARCHY)) {
	    TkWinSetWindowPos(scrollPtr->hwnd, Tk_GetHWND(winPtr->window),
		    Below);
	    break;
	}
    }

    scrollPtr->lastVertical = scrollPtr->info.vertical;
    scrollPtr->oldProc = (WNDPROC)SetWindowLongPtr(scrollPtr->hwnd,
	    GWLP_WNDPROC, (LONG_PTR) ScrollbarProc);
    window = Tk_AttachHWND(tkwin, scrollPtr->hwnd);

    UpdateScrollbar(scrollPtr);
    return window;
}

/*
 *--------------------------------------------------------------
 *
 * TkpDisplayScrollbar --
 *
 *	This procedure redraws the contents of a scrollbar window. It is
 *	invoked as a do-when-idle handler, so it only runs when there's
 *	nothing else for the application to do.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

void
TkpDisplayScrollbar(
    ClientData clientData)	/* Information about window. */
{
    WinScrollbar *scrollPtr = (WinScrollbar *) clientData;
    Tk_Window tkwin = scrollPtr->info.tkwin;

    scrollPtr->info.flags &= ~REDRAW_PENDING;
    if ((tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }

    /*
     * Destroy and recreate the scrollbar control if the orientation has
     * changed.
     */

    if (scrollPtr->lastVertical != scrollPtr->info.vertical) {
	HWND hwnd = Tk_GetHWND(Tk_WindowId(tkwin));

	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) scrollPtr->oldProc);
	DestroyWindow(hwnd);

	CreateProc(tkwin, Tk_WindowId(Tk_Parent(tkwin)),
		(ClientData) scrollPtr);
    } else {
	UpdateScrollbar(scrollPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDestroyScrollbar --
 *
 *	Free data structures associated with the scrollbar control.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Restores the default control state.
 *
 *----------------------------------------------------------------------
 */

void
TkpDestroyScrollbar(
    TkScrollbar *scrollPtr)
{
    WinScrollbar *winScrollPtr = (WinScrollbar *)scrollPtr;
    HWND hwnd = winScrollPtr->hwnd;

    if (hwnd) {
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (INT_PTR) winScrollPtr->oldProc);
	if (winScrollPtr->winFlags & IN_MODAL_LOOP) {
	    ((TkWindow *)scrollPtr->tkwin)->flags |= TK_DONT_DESTROY_WINDOW;
	    SetParent(hwnd, NULL);
	}
    }
    winScrollPtr->winFlags |= ALREADY_DEAD;
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateScrollbarMetrics --
 *
 *	This function retrieves the current system metrics for a scrollbar.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Updates the geometry cache info for all scrollbars.
 *
 *----------------------------------------------------------------------
 */

void
UpdateScrollbarMetrics(void)
{
    int arrowWidth = GetSystemMetrics(SM_CXVSCROLL);

    hArrowWidth = GetSystemMetrics(SM_CXHSCROLL);
    hThumb = GetSystemMetrics(SM_CXHTHUMB);
    vArrowHeight = GetSystemMetrics(SM_CYVSCROLL);
    vThumb = GetSystemMetrics(SM_CYVTHUMB);

    sprintf(tkDefScrollbarWidth, "%d", arrowWidth);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpComputeScrollbarGeometry --
 *
 *	After changes in a scrollbar's size or configuration, this procedure
 *	recomputes various geometry information used in displaying the
 *	scrollbar.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The scrollbar will be displayed differently.
 *
 *----------------------------------------------------------------------
 */

void
TkpComputeScrollbarGeometry(
    register TkScrollbar *scrollPtr)
				/* Scrollbar whose geometry may have
				 * changed. */
{
    int fieldLength, minThumbSize;

    /*
     * Windows doesn't use focus rings on scrollbars, but we still perform
     * basic sanity checks to appease backwards compatibility.
     */

    if (scrollPtr->highlightWidth < 0) {
	scrollPtr->highlightWidth = 0;
    }

    if (scrollPtr->vertical) {
	scrollPtr->arrowLength = vArrowHeight;
	fieldLength = Tk_Height(scrollPtr->tkwin);
	minThumbSize = vThumb;
    } else {
	scrollPtr->arrowLength = hArrowWidth;
	fieldLength = Tk_Width(scrollPtr->tkwin);
	minThumbSize = hThumb;
    }
    fieldLength -= 2*scrollPtr->arrowLength;
    if (fieldLength < 0) {
	fieldLength = 0;
    }
    scrollPtr->sliderFirst = (int) ((double)fieldLength
	    * scrollPtr->firstFraction);
    scrollPtr->sliderLast = (int) ((double)fieldLength
	    * scrollPtr->lastFraction);

    /*
     * Adjust the slider so that some piece of it is always displayed in the
     * scrollbar and so that it has at least a minimal width (so it can be
     * grabbed with the mouse).
     */

    if (scrollPtr->sliderFirst > fieldLength) {
	scrollPtr->sliderFirst = fieldLength;
    }
    if (scrollPtr->sliderFirst < 0) {
	scrollPtr->sliderFirst = 0;
    }
    if (scrollPtr->sliderLast < (scrollPtr->sliderFirst
	    + minThumbSize)) {
	scrollPtr->sliderLast = scrollPtr->sliderFirst + minThumbSize;
    }
    if (scrollPtr->sliderLast > fieldLength) {
	scrollPtr->sliderLast = fieldLength;
    }
    scrollPtr->sliderFirst += scrollPtr->arrowLength;
    scrollPtr->sliderLast += scrollPtr->arrowLength;

    /*
     * Register the desired geometry for the window (leave enough space for
     * the two arrows plus a minimum-size slider, plus border around the whole
     * window, if any). Then arrange for the window to be redisplayed.
     */

    if (scrollPtr->vertical) {
	Tk_GeometryRequest(scrollPtr->tkwin,
		scrollPtr->width, 2*scrollPtr->arrowLength + minThumbSize);
    } else {
	Tk_GeometryRequest(scrollPtr->tkwin,
		2*scrollPtr->arrowLength + minThumbSize, scrollPtr->width);
    }
    Tk_SetInternalBorder(scrollPtr->tkwin, 0);
}

/*
 *----------------------------------------------------------------------
 *
 * ScrollbarProc --
 *
 *	This function is call by Windows whenever an event occurs on a
 *	scrollbar control created by Tk.
 *
 * Results:
 *	Standard Windows return value.
 *
 * Side effects:
 *	May generate events.
 *
 *----------------------------------------------------------------------
 */

static LRESULT CALLBACK
ScrollbarProc(
    HWND hwnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
{
    LRESULT result;
    POINT point;
    WinScrollbar *scrollPtr;
    Tk_Window tkwin = Tk_HWNDToWindow(hwnd);

    if (tkwin == NULL) {
	Tcl_Panic("ScrollbarProc called on an invalid HWND");
    }
    scrollPtr = (WinScrollbar *)((TkWindow*)tkwin)->instanceData;

    switch(message) {
    case WM_HSCROLL:
    case WM_VSCROLL: {
	Tcl_Interp *interp;
	Tcl_DString cmdString;
	int command = LOWORD(wParam);
	int code;

	GetCursorPos(&point);
	Tk_TranslateWinEvent(NULL, WM_MOUSEMOVE, 0,
		MAKELPARAM(point.x, point.y), &result);

	if (command == SB_ENDSCROLL) {
	    return 0;
	}

	/*
	 * Bail out immediately if there isn't a command to invoke.
	 */

	if (scrollPtr->info.commandSize == 0) {
	    Tcl_ServiceAll();
	    return 0;
	}

	Tcl_DStringInit(&cmdString);
	Tcl_DStringAppend(&cmdString, scrollPtr->info.command,
		scrollPtr->info.commandSize);

	if (command == SB_LINELEFT || command == SB_LINERIGHT) {
	    Tcl_DStringAppendElement(&cmdString, "scroll");
	    Tcl_DStringAppendElement(&cmdString,
		    (command == SB_LINELEFT ) ? "-1" : "1");
	    Tcl_DStringAppendElement(&cmdString, "units");
	} else if (command == SB_PAGELEFT || command == SB_PAGERIGHT) {
	    Tcl_DStringAppendElement(&cmdString, "scroll");
	    Tcl_DStringAppendElement(&cmdString,
		    (command == SB_PAGELEFT ) ? "-1" : "1");
	    Tcl_DStringAppendElement(&cmdString, "pages");
	} else {
	    char valueString[TCL_DOUBLE_SPACE];
	    double pos = 0.0;

	    switch (command) {
	    case SB_THUMBPOSITION:
		pos = ((double)HIWORD(wParam)) / MAX_SCROLL;
		break;
	    case SB_THUMBTRACK:
		pos = ((double)HIWORD(wParam)) / MAX_SCROLL;
		break;
	    case SB_TOP:
		pos = 0.0;
		break;
	    case SB_BOTTOM:
		pos = 1.0;
		break;
	    }

	    Tcl_PrintDouble(NULL, pos, valueString);
	    Tcl_DStringAppendElement(&cmdString, "moveto");
	    Tcl_DStringAppendElement(&cmdString, valueString);
	}

	interp = scrollPtr->info.interp;
	code = Tcl_GlobalEval(interp, cmdString.string);
	if (code != TCL_OK && code != TCL_CONTINUE && code != TCL_BREAK) {
	    Tcl_AddErrorInfo(interp, "\n    (scrollbar command)");
	    Tcl_BackgroundException(interp, code);
	}
	Tcl_DStringFree(&cmdString);

	Tcl_ServiceAll();
	return 0;
    }

    default:
	if (Tk_TranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
	    return result;
	}
    }
    return CallWindowProc(scrollPtr->oldProc, hwnd, message, wParam, lParam);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpConfigureScrollbar --
 *
 *	This procedure is called after the generic code has finished
 *	processing configuration options, in order to configure platform
 *	specific options.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkpConfigureScrollbar(
    register TkScrollbar *scrollPtr)
				/* Information about widget; may or may not
				 * already have values for some fields. */
{
}

/*
 *----------------------------------------------------------------------
 *
 * ModalLoop --
 *
 *	This function is invoked in response to a ButtonPress event.
 *	It resends the event to the Scrollbar window procedure,
 * 	which in turn enters a modal loop.
 *
 *----------------------------------------------------------------------
 */

static void
ModalLoop(
    WinScrollbar *scrollPtr,
    XEvent *eventPtr)
{
    int oldMode;

    if (scrollPtr->hwnd) {
	Tcl_Preserve((ClientData)scrollPtr);
	scrollPtr->winFlags |= IN_MODAL_LOOP;
	oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
	TkWinResendEvent(scrollPtr->oldProc, scrollPtr->hwnd, eventPtr);
	(void) Tcl_SetServiceMode(oldMode);
	scrollPtr->winFlags &= ~IN_MODAL_LOOP;
	if (scrollPtr->hwnd && scrollPtr->winFlags & ALREADY_DEAD) {
	    DestroyWindow(scrollPtr->hwnd);
	}
	Tcl_Release((ClientData)scrollPtr);
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkpScrollbarPosition --
 *
 *	Determine the scrollbar element corresponding to a given position.
 *
 * Results:
 *	One of TOP_ARROW, TOP_GAP, etc., indicating which element of the
 *	scrollbar covers the position given by (x, y). If (x,y) is outside the
 *	scrollbar entirely, then OUTSIDE is returned.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkpScrollbarPosition(
    register TkScrollbar *scrollPtr,
				/* Scrollbar widget record. */
    int x, int y)		/* Coordinates within scrollPtr's window. */
{
    int length, width, tmp;

    if (scrollPtr->vertical) {
	length = Tk_Height(scrollPtr->tkwin);
	width = Tk_Width(scrollPtr->tkwin);
    } else {
	tmp = x;
	x = y;
	y = tmp;
	length = Tk_Width(scrollPtr->tkwin);
	width = Tk_Height(scrollPtr->tkwin);
    }

    if ((x < scrollPtr->inset) || (x >= (width - scrollPtr->inset))
	    || (y < scrollPtr->inset) || (y >= (length - scrollPtr->inset))) {
	return OUTSIDE;
    }

    /*
     * All of the calculations in this procedure mirror those in
     * TkpDisplayScrollbar. Be sure to keep the two consistent.
     */

    if (y < (scrollPtr->inset + scrollPtr->arrowLength)) {
	return TOP_ARROW;
    }
    if (y < scrollPtr->sliderFirst) {
	return TOP_GAP;
    }
    if (y < scrollPtr->sliderLast) {
	return SLIDER;
    }
    if (y >= (length - (scrollPtr->arrowLength + scrollPtr->inset))) {
	return BOTTOM_ARROW;
    }
    return BOTTOM_GAP;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
@


1.22
log
@[Patch 3009998]: Replace binding procedures with ordinary event handlers
in win/tkWinScrlbr.c and carbon/tkMacOSXScrlbr.c.

Simplifications enabled by previous change:

    * TkCreateBindingProcedure() and associated machinery no longer needed.
    * TkBindDeadWindow() no longer needed.
    * TK_DEFER_MODAL_LOOP and associated machinery no longer needed.
    * Tests related to C binding procedures no longer needed.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.21 2010/04/29 15:28:04 nijtmans Exp $
d251 1
a251 1
	    GWLP_WNDPROC, (INT_PTR) ScrollbarProc);
d296 1
a296 1
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (INT_PTR) scrollPtr->oldProc);
@


1.21
log
@Unnessarary TCL_STORAGE_CLASS re-definitions
Make various functions MODULE_SCOPE
TCHAR-related fixes, making al those
files compile fine when TCHAR != char.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.20 2010/02/17 19:21:17 nijtmans Exp $
d67 1
a67 4
static void		ModalLoopProc(Tk_Window tkwin, XEvent *eventPtr);
static int		ScrollbarBindProc(ClientData clientData,
			    Tcl_Interp *interp, XEvent *eventPtr,
			    Tk_Window tkwin, KeySym keySym);
d81 1
a81 1
    ModalLoopProc		/* modalProc */
d84 12
a117 1
    TkWindow *winPtr = (TkWindow *)tkwin;
d131 2
a132 11
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    TkScrollbarEventProc, (ClientData) scrollPtr);

    if (!Tcl_GetAssocData(winPtr->mainPtr->interp, "TkScrollbar", NULL)) {
	Tcl_SetAssocData(winPtr->mainPtr->interp, "TkScrollbar", NULL,
		(ClientData)1);
	TkCreateBindingProcedure(winPtr->mainPtr->interp,
		winPtr->mainPtr->bindingTable,
		(ClientData)Tk_GetUid("Scrollbar"), "<ButtonPress>",
		ScrollbarBindProc, NULL, NULL);
    }
a602 33
 *--------------------------------------------------------------
 *
 * ScrollbarBindProc --
 *
 *	This procedure is invoked when the default <ButtonPress> binding on
 *	the Scrollbar bind tag fires.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The event enters a modal loop.
 *
 *--------------------------------------------------------------
 */

static int
ScrollbarBindProc(
    ClientData clientData,
    Tcl_Interp *interp,
    XEvent *eventPtr,
    Tk_Window tkwin,
    KeySym keySym)
{
    TkWindow *winPtr = (TkWindow *) tkwin;

    if (eventPtr->type == ButtonPress) {
	winPtr->flags |= TK_DEFER_MODAL;
    }
    return TCL_OK;
}

/*
d605 1
a605 4
 * ModalLoopProc --
 *
 *	This function is invoked at the end of the event processing whenever
 *	the ScrollbarBindProc has been invoked for a ButtonPress event.
d607 3
a609 5
 * Results:
 *	None.
 *
 * Side effects:
 *	Enters a modal loop.
d615 2
a616 2
ModalLoopProc(
    Tk_Window tkwin,
a618 2
    TkWindow *winPtr = (TkWindow*)tkwin;
    WinScrollbar *scrollPtr = (WinScrollbar *) winPtr->instanceData;
@


1.20
log
@CONSTify everything related to Tk_ConfigSpec
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.19 2010/02/16 21:12:56 nijtmans Exp $
d229 1
a229 1
    scrollPtr->hwnd = CreateWindow("SCROLLBAR", NULL, style,
@


1.19
log
@tkWindow.c/tkStubInit.c adapted from stub changes in Tcl
tkArgv.c      make defaultTable const
tkScrollbar.c Store default for "-with" in static non-const memory
tkWinInt.h        make tkWinProcs const, and 5
tkWinX.c          procs MODULE_SCOPE
tkWinColor.c      make sysColors const
tkWinKey.c        make keymap const
tkWinScrlbr.c     Simplify copying of "-with" default value.
tkUnixWm.c       make TkSetTransientFor static
tests/textImage.test  textImage-1.13 depends on hash-order
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.18 2010/01/13 23:08:11 nijtmans Exp $
a359 1
    const Tk_ConfigSpec *specPtr;
d366 1
a366 10
    for (specPtr = tkpScrollbarConfigSpecs; specPtr->type != TK_CONFIG_END;
	    specPtr++) {
	/* Make sure that the default value belonging to the "-width"
	 * option of TkScrollbar points to static non-const space,
	 * otherwise the following sprintf results in a crash!
	 */
	if (specPtr->offset == Tk_Offset(TkScrollbar, width)) {
	    sprintf((char *)specPtr->defValue, "%d", arrowWidth);
	}
    }
@


1.18
log
@Eliminate tkpMenubuttonClass
make tkpButtonProcs CONST
fix gcc warnings: missing initializer
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.17 2008/12/09 21:22:56 dgp Exp $
d57 1
a57 1
static int vArrowWidth, vArrowHeight, vThumb; /* Vertical control metrics. */
a61 7
 * This variable holds the default width for a scrollbar in string form for
 * use in a Tk_ConfigSpec.
 */

static char defWidth[TCL_INTEGER_SPACE];

/*
d359 2
a360 1
    Tk_ConfigSpec *specPtr;
a363 1
    vArrowWidth = GetSystemMetrics(SM_CXVSCROLL);
a366 1
    sprintf(defWidth, "%d", vArrowWidth);
d369 4
d374 1
a374 1
	    specPtr->defValue = defWidth;
@


1.17
log
@        TIP 337

        * generic/tkBind.c:     Updated callers of Tcl_BackgroundError()
        * generic/tkCanvas.c:   to use the new routine
        * generic/tkEntry.c:    Tcl_BackgroundException() as appropriate.
        * generic/tkImgBmap.c:
        * generic/tkListbox.c:
        * generic/tkSelect.c:
        * generic/tkTextDisp.c:
        * generic/tkTextWind.c:
        * macosx/tkMacOSXHLEvents.c:
        * macosx/tkMacOSXMenu.c:
        * macosx/tkMacOSXMenus.c:
        * macosx/tkMacOSXScale.c:
        * macosx/tkMacOSXWindowEvent.c:
        * unix/tkUnixScale.c:
        * unix/tkUnixWm.c:
        * win/tkWinButton.c:
        * win/tkWinMenu.c:
        * win/tkWinScrlbr.c:
        * win/tkWinWm.c:
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.16 2008/10/03 13:13:31 dkf Exp $
d87 1
a87 1
Tk_ClassProcs tkpScrollbarProcs = {
d91 1
a91 1
    ModalLoopProc,		/* modalProc */
@


1.16
log
@Convert %g to Tcl_PrintDouble to avoid locale trouble. [Bug 2112563]
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.15 2007/12/14 15:56:09 patthoyts Exp $
d575 1
a575 1
	    Tcl_BackgroundError(interp);
@


1.15
log
@Add in missing function definitions to support plain MSVC6 and use
INT_PTR rather than LONG_PTR which isn'tr defined in the msvc6
headers.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.14 2007/12/13 15:28:56 dgp Exp $
d566 1
a566 1
	    sprintf(valueString, "%g", pos);
@


1.15.2.1
log
@Backport of fix for [Bug 2112563]
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.15 2007/12/14 15:56:09 patthoyts Exp $
d566 1
a566 1
	    Tcl_PrintDouble(NULL, pos, valueString);
d672 1
a672 1
    TkWindow *winPtr = (TkWindow *) tkwin;
d677 1
a677 1
	Tcl_Preserve(scrollPtr);
d686 1
a686 1
	Tcl_Release(scrollPtr);
@


1.14
log
@merge stable branch onto HEAD
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.12.2.1 2007/12/05 20:26:47 dgp Exp $
d259 1
a259 1
	    GWLP_WNDPROC, (LONG_PTR) ScrollbarProc);
d304 1
a304 1
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) scrollPtr->oldProc);
d338 1
a338 1
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) winScrollPtr->oldProc);
@


1.13
log
@	* win/tkWinButton.c, win/tkWinDialog.c: use SetWindowLongPtr and
	* win/tkWinScrlbr.c, win/tkWinWm.c:     GetWindowLongPtr only.
	* win/ttkWinMonitor.c:
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.12 2005/12/02 13:42:29 dkf Exp $
@


1.12
log
@More fixes (mostly getting rid of excess spaces)
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.11 2005/12/02 00:19:04 dkf Exp $
a257 1
#ifdef _WIN64
a259 4
#else
    scrollPtr->oldProc = (WNDPROC)SetWindowLong(scrollPtr->hwnd, GWL_WNDPROC,
	    (DWORD) ScrollbarProc);
#endif
a303 1
#ifdef _WIN64
a304 3
#else
	SetWindowLong(hwnd, GWL_WNDPROC, (DWORD) scrollPtr->oldProc);
#endif
a337 1
#ifdef _WIN64
a338 3
#else
	SetWindowLong(hwnd, GWL_WNDPROC, (DWORD) winScrollPtr->oldProc);
#endif
@


1.12.2.1
log
@merge updates from HEAD
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.12 2005/12/02 13:42:29 dkf Exp $
d258 1
d261 4
d309 1
d311 3
d347 1
d349 3
@


1.12.2.2
log
@merge updates from HEAD
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.14 2007/12/13 15:28:56 dgp Exp $
d259 1
a259 1
	    GWLP_WNDPROC, (INT_PTR) ScrollbarProc);
d304 1
a304 1
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (INT_PTR) scrollPtr->oldProc);
d338 1
a338 1
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (INT_PTR) winScrollPtr->oldProc);
@


1.11
log
@ANSIfication
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.10 2004/01/13 02:06:02 davygrvy Exp $
d119 1
a119 1
        Tcl_MutexLock(&winScrlbrMutex);
@


1.10
log
@	* generic/tk3d.c:	All uses of 'panic' (the macro) changed
	* generic/tkBind.c:	to 'Tcl_Panic' (the function).  The #define
	* generic/tkBitmap.c:	of panic in tcl.h clearly states it is
	* generic/tkCanvArc.c:	deprecated in the comments.
	* generic/tkCanvBmap.c: [Tcl Patch 865264]
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvText.c:
	* generic/tkCanvWind.c:
	* generic/tkColor.c:
	* generic/tkConfig.c:
	* generic/tkCursor.c:
	* generic/tkError.c:
	* generic/tkEvent.c:
	* generic/tkFocus.c:
	* generic/tkFont.c:
	* generic/tkFrame.c:
	* generic/tkGC.c:
	* generic/tkGrid.c:
	* generic/tkImgBmap.c:
	* generic/tkImgPhoto.c:
	* generic/tkImgUtil.c:
	* generic/tkMenu.c:
	* generic/tkObj.c:
	* generic/tkPack.c:
	* generic/tkPlace.c:
	* generic/tkRectOval.c:
	* generic/tkSelect.c:
	* generic/tkText.c:
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextImage.c:
	* generic/tkTextIndex.c:
	* generic/tkTextMark.c:
	* generic/tkTextWind.c:
	* generic/tkVisual.c:
	* generic/tkWindow.c:
	* mac/tkMacAppInit.c:
	* mac/tkMacAppearanceStubs.c:
	* mac/tkMacButton.c:
	* mac/tkMacDraw.c:
	* mac/tkMacEmbed.c:
	* mac/tkMacFont.c:
	* mac/tkMacInit.c:
	* mac/tkMacMenus.c:
	* mac/tkMacPort.h:
	* mac/tkMacSubwindows.c:
	* mac/tkMacWm.c:
	* mac/tkMacXStubs.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXPort.h:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* unix/tkUnix3d.c:
	* unix/tkUnixColor.c:
	* unix/tkUnixEmbed.c:
	* unix/tkUnixEvent.c:
	* unix/tkUnixFocus.c:
	* unix/tkUnixFont.c:
	* unix/tkUnixSelect.c:
	* unix/tkUnixSend.c:
	* unix/tkUnixWm.c:
	* win/tkWin3d.c:
	* win/tkWinButton.c:
	* win/tkWinColor.c:
	* win/tkWinDialog.c:
	* win/tkWinDraw.c:
	* win/tkWinEmbed.c:
	* win/tkWinFont.c:
	* win/tkWinPixmap.c:
	* win/tkWinPointer.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWm.c:
	* win/tkWinX.c:
@
text
@d1 1
a1 1
/* 
d9 2
a10 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.9 2003/02/21 02:07:50 hobbs Exp $
a17 1

d19 4
a22 4
 * The following constant is used to specify the maximum scroll position.
 * This value is limited by the Win32 API to either 16-bits or 32-bits,
 * depending on the context.  For now we'll just use a value small
 * enough to fit in 16-bits, but which gives us 4-digits of precision.
d41 1
a41 1
 * 
d62 2
a63 2
 * This variable holds the default width for a scrollbar in string
 * form for use in a Tk_ConfigSpec.
d72 4
a75 5
static Window		CreateProc _ANSI_ARGS_((Tk_Window tkwin,
			    Window parent, ClientData instanceData));
static void		ModalLoopProc _ANSI_ARGS_((Tk_Window tkwin,
			    XEvent *eventPtr));
static int		ScrollbarBindProc _ANSI_ARGS_((ClientData clientData,
d77 5
a81 6
			    Tk_Window tkwin, KeySym keySym));
static LRESULT CALLBACK	ScrollbarProc _ANSI_ARGS_((HWND hwnd, UINT message,
			    WPARAM wParam, LPARAM lParam));
static void		UpdateScrollbar _ANSI_ARGS_((
    			    WinScrollbar *scrollPtr));
static void		UpdateScrollbarMetrics _ANSI_ARGS_((void));
d112 2
a113 2
TkpCreateScrollbar(tkwin)
    Tk_Window tkwin;
d117 1
a117 1
    
d142 1
a142 1
    return (TkScrollbar*) scrollPtr;
d150 2
a151 2
 *	This function updates the position and size of the scrollbar
 *	thumb based on the current settings.
d163 2
a164 2
UpdateScrollbar(scrollPtr)
    WinScrollbar *scrollPtr;
d181 2
a182 2
	    ((scrollPtr->info.firstFraction / (1.0-thumbSize))
		    * (MAX_SCROLL - (scrollInfo.nPage - 1)));
d185 1
d187 3
a189 3
	 * Disable the scrollbar when there is nothing to scroll.
	 * This is standard Windows style (see eg Notepad).
	 * Also prevents possible crash on XP+ systems [Bug #624116].
d191 1
d202 2
a203 2
 *	This function creates a new Scrollbar control, subclasses
 *	the instance, and generates a new Window object.
d215 4
a218 4
CreateProc(tkwin, parentWin, instanceData)
    Tk_Window tkwin;		/* Token for window. */
    Window parentWin;		/* Parent of new window. */
    ClientData instanceData;	/* Scrollbar instance data. */
d230 1
a230 1
	    | SBS_VERT | SBS_RIGHTALIGN;
d233 1
a233 1
	    | SBS_HORZ | SBS_BOTTOMALIGN;
d242 1
a242 1
     * place. 
d249 1
a249 1
	 winPtr = winPtr->nextPtr) {
d276 3
a278 3
 *	This procedure redraws the contents of a scrollbar window.
 *	It is invoked as a do-when-idle handler, so it only runs
 *	when there's nothing else for the application to do.
d290 2
a291 2
TkpDisplayScrollbar(clientData)
    ClientData clientData;	/* Information about window. */
d302 2
a303 2
     * Destroy and recreate the scrollbar control if the orientation
     * has changed.
d340 2
a341 2
TkpDestroyScrollbar(scrollPtr)
    TkScrollbar *scrollPtr;
d345 1
d365 1
a365 2
 *	This function retrieves the current system metrics for a
 *	scrollbar.
d377 1
a377 1
UpdateScrollbarMetrics()
d401 3
a403 3
 *	After changes in a scrollbar's size or configuration, this
 *	procedure recomputes various geometry information used in
 *	displaying the scrollbar.
d415 4
a418 3
TkpComputeScrollbarGeometry(scrollPtr)
    register TkScrollbar *scrollPtr;	/* Scrollbar whose geometry may
					 * have changed. */
d423 2
a424 2
     * Windows doesn't use focus rings on scrollbars, but we still
     * perform basic sanity checks to appease backwards compatibility.
d450 3
a452 3
     * Adjust the slider so that some piece of it is always
     * displayed in the scrollbar and so that it has at least
     * a minimal width (so it can be grabbed with the mouse).
d472 3
a474 4
     * Register the desired geometry for the window (leave enough space
     * for the two arrows plus a minimum-size slider, plus border around
     * the whole window, if any).  Then arrange for the window to be
     * redisplayed.
d492 2
a493 2
 *	This function is call by Windows whenever an event occurs on
 *	a scrollbar control created by Tk.
d505 5
a509 5
ScrollbarProc(hwnd, message, wParam, lParam)
    HWND hwnd;
    UINT message;
    WPARAM wParam;
    LPARAM lParam;
d522 10
a531 10
	case WM_HSCROLL:
	case WM_VSCROLL: {
	    Tcl_Interp *interp;
	    Tcl_DString cmdString;
	    int command = LOWORD(wParam);
	    int code;

	    GetCursorPos(&point);
	    Tk_TranslateWinEvent(NULL, WM_MOUSEMOVE, 0,
		    MAKELPARAM(point.x, point.y), &result);
d533 3
a535 3
	    if (command == SB_ENDSCROLL) {
		return 0;
	    }
d537 3
a539 55
	    /*
	     * Bail out immediately if there isn't a command to invoke.
	     */

	    if (scrollPtr->info.commandSize == 0) {
		Tcl_ServiceAll();
		return 0;
	    }
		
	    Tcl_DStringInit(&cmdString);
	    Tcl_DStringAppend(&cmdString, scrollPtr->info.command,
		    scrollPtr->info.commandSize);
		
	    if (command == SB_LINELEFT || command == SB_LINERIGHT) {
		Tcl_DStringAppendElement(&cmdString, "scroll");
		Tcl_DStringAppendElement(&cmdString,
			(command == SB_LINELEFT ) ? "-1" : "1");
		Tcl_DStringAppendElement(&cmdString, "units");
	    } else if (command == SB_PAGELEFT || command == SB_PAGERIGHT) {
		Tcl_DStringAppendElement(&cmdString, "scroll");
		Tcl_DStringAppendElement(&cmdString,
			(command == SB_PAGELEFT ) ? "-1" : "1");
		Tcl_DStringAppendElement(&cmdString, "pages");
	    } else {
		char valueString[TCL_DOUBLE_SPACE];
		double pos = 0.0;
		switch (command) {
		    case SB_THUMBPOSITION:
			pos = ((double)HIWORD(wParam)) / MAX_SCROLL;
			break;

		    case SB_THUMBTRACK:
			pos = ((double)HIWORD(wParam)) / MAX_SCROLL;
			break;

		    case SB_TOP:
			pos = 0.0;
			break;

		    case SB_BOTTOM:
			pos = 1.0;
			break;
		}
		sprintf(valueString, "%g", pos);
		Tcl_DStringAppendElement(&cmdString, "moveto");
		Tcl_DStringAppendElement(&cmdString, valueString);
	    }

	    interp = scrollPtr->info.interp;
	    code = Tcl_GlobalEval(interp, cmdString.string);
	    if (code != TCL_OK && code != TCL_CONTINUE && code != TCL_BREAK) {
		Tcl_AddErrorInfo(interp, "\n    (scrollbar command)");
		Tcl_BackgroundError(interp);
	    }		
	    Tcl_DStringFree(&cmdString);		
d541 1
d546 31
a576 3
	default:
	    if (Tk_TranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
		return result;
d578 22
d610 2
a611 2
 *	processing configuration options, in order to configure
 *	platform specific options.
d623 4
a626 4
TkpConfigureScrollbar(scrollPtr)
    register TkScrollbar *scrollPtr;	/* Information about widget;  may or
					 * may not already have values for
					 * some fields. */
d635 2
a636 2
 *	This procedure is invoked when the default <ButtonPress>
 *	binding on the Scrollbar bind tag fires.
d648 6
a653 6
ScrollbarBindProc(clientData, interp, eventPtr, tkwin, keySym)
    ClientData clientData;
    Tcl_Interp *interp;
    XEvent *eventPtr;
    Tk_Window tkwin;
    KeySym keySym;
d655 2
a656 1
    TkWindow *winPtr = (TkWindow*)tkwin;
d668 2
a669 3
 *	This function is invoked at the end of the event processing
 *	whenever the ScrollbarBindProc has been invoked for a ButtonPress
 *	event. 
d681 3
a683 3
ModalLoopProc(tkwin, eventPtr)
    Tk_Window tkwin;
    XEvent *eventPtr;
d708 1
a708 2
 *	Determine the scrollbar element corresponding to a
 *	given position.
d711 3
a713 4
 *	One of TOP_ARROW, TOP_GAP, etc., indicating which element
 *	of the scrollbar covers the position given by (x, y).  If
 *	(x,y) is outside the scrollbar entirely, then OUTSIDE is
 *	returned.
d722 4
a725 4
TkpScrollbarPosition(scrollPtr, x, y)
    register TkScrollbar *scrollPtr;	/* Scrollbar widget record. */
    int x, y;				/* Coordinates within scrollPtr's
					 * window. */
d747 1
a747 1
     * TkpDisplayScrollbar.  Be sure to keep the two consistent.
d764 8
@


1.9
log
@	* win/tkWinScrlbr.c (UpdateScrollbar): use SIF_DISABLENOSCROLL to
	"disable" scrollbar when on Windows when there is nothing to
	scroll.  This is Windows style, and fixes [Bug #624116].
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.8 2002/06/14 22:25:12 jenglish Exp $
d518 1
a518 1
	panic("ScrollbarProc called on an invalid HWND");
@


1.8
log
@TIP #47 "Modifying Tk to Allow Writing X Window managers"
(patch from Neil McKay).
* Add CirculateRequest, Create, MapRequest, ResizeRequest,
  and ConfigureRequest event types;
* Split TK_TOPLEVEL flag into TK_TOPLEVEL, TK_HAS_WRAPPER,
  TK_WIN_MANAGED, and TK_TOP_HIERARCHY.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.7 2000/11/22 01:49:38 ericm Exp $
d188 6
@


1.7
log
@	Overall change:  Implemented TIP 5, which exports
	TkClassProcs/TkSetClassProcs as Tk_ClassProcs/Tk_SetClassProcs,
	adding a size field to Tk_ClassProcs to allow for future
	expansion, and renaming the geometryProc to worldChangedProc,
	which is more in keeping with the actual use of the callback.

	See ChangeLog for details.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.6 2000/11/03 01:22:17 hobbs Exp $
d245 1
a245 1
	if ((winPtr->window != None) && !(winPtr->flags & TK_TOP_LEVEL)) {
@


1.7.4.1
log
@merged with trunk at tag macosx-8-4-merge-2002-08-20-trunk
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d245 1
a245 1
	if ((winPtr->window != None) && !(winPtr->flags & TK_TOP_HIERARCHY)) {
@


1.6
log
@	* win/tkWinButton.c:
	* win/tkWinDialog.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWm.c: fixed up code for Win64 support.  This mostly
	remains in _WIN64 #ifdef's, until updated compilers are standard.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.5 2000/03/31 09:24:27 hobbs Exp $
d90 3
a92 1
TkClassProcs tkpScrollbarProcs = {
a93 1
    NULL,			/* geometryProc */
@


1.6.2.1
log
@sync with head
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.7 2000/11/22 01:49:38 ericm Exp $
d90 1
a90 3
Tk_ClassProcs tkpScrollbarProcs = {
    sizeof(Tk_ClassProcs),	/* size */
    NULL,			/* worldChangedProc */
d92 1
@


1.5
log
@	* win/tkWinDialog.c: added unicode-aware open/save file dialogs

	* win/tkWinFont.c (TkpFontPkgInit): move private ref to platformId
	to TkWinGetPlatformId

	* win/tkWinMenu.c (SetDefaults): moved private use of versionInfo
	to TkWinGetPlatformId and removed all code for
	(versionInfo.dwMajorVersion < 4) (== Win32s)

	* win/tkWinX.c:
	* win/tkWin32Dll.c: moved TkWinGetPlatformId to tkWinX.c
	* win/tkWinInit.c: added TkWinXInit to TkpInit to ensure that its
	called for static Windows shells. [Bug: 3647]

	* win/tkWinInt.h:
	* win/tkWinX.c:
	* win/tkWinDraw.c (SetUpGraphicsPort):
	* win/tkWinScrlbr.c (UpdateScrollbar): removed use of tkpIsWin32s

	* win/tkWinInt.h (TkWinDCState struct): added bkmode value
	* win/tkWinDraw.c (TkWinGetDrawableDC, et al): added support for
	properly transparent dashed lines on Windows. [Bug: 4617]
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.4 2000/01/13 02:07:27 hobbs Exp $
d252 4
d258 1
d303 3
d307 1
d340 3
d344 1
@


1.5.2.1
log
@see ChangeLog for specific file details
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.5 2000/03/31 09:24:27 hobbs Exp $
a251 4
#ifdef _WIN64
    scrollPtr->oldProc = (WNDPROC)SetWindowLongPtr(scrollPtr->hwnd,
	    GWLP_WNDPROC, (LONG_PTR) ScrollbarProc);
#else
a253 1
#endif
a297 3
#ifdef _WIN64
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) scrollPtr->oldProc);
#else
a298 1
#endif
a330 3
#ifdef _WIN64
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) winScrollPtr->oldProc);
#else
a331 1
#endif
@


1.4
log
@	* win/tkWinScrlbr.c: added check for valid hwnd in ModalLoopProc
	to avoid crash when building statically
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.3 1999/04/16 01:51:53 stanton Exp $
d180 1
a180 5
    if (tkpIsWin32s) {
	scrollInfo.nPage = 0;
    } else {
	scrollInfo.nPage = ((UINT) (thumbSize * (double) MAX_SCROLL)) + 1;
    } 
@


1.3
log
@* Merged 8.1 branch into the main trunk
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d675 11
a685 8
    Tcl_Preserve((ClientData)scrollPtr);
    scrollPtr->winFlags |= IN_MODAL_LOOP;
    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
    TkWinResendEvent(scrollPtr->oldProc, scrollPtr->hwnd, eventPtr);
    (void) Tcl_SetServiceMode(oldMode);
    scrollPtr->winFlags &= ~IN_MODAL_LOOP;
    if (scrollPtr->hwnd && scrollPtr->winFlags & ALREADY_DEAD) {
	DestroyWindow(scrollPtr->hwnd);
a686 1
    Tcl_Release((ClientData)scrollPtr);
@


1.2
log
@Replaced SCCS strings, fixed binary files
@
text
@d60 2
d67 1
a67 1
static char defWidth[8];
d121 1
d124 1
@


1.1
log
@Initial revision
@
text
@d12 1
a12 1
 * SCCS: @@(#) tkWinScrlbr.c 1.19 97/08/13 17:37:49
@


1.1.4.1
log
@initial tk8.1a2 version
@
text
@d12 1
a12 1
 * SCCS: @@(#) tkWinScrlbr.c 1.20 97/11/07 21:25:53
d65 1
a65 1
static char defWidth[TCL_INTEGER_SPACE];
@


1.1.4.2
log
@Merged 8.0.3 changes into 8.1
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.2 1998/09/14 18:24:01 stanton Exp $
@


1.1.4.3
log
@
Tk 8.1 Muti-threading changes.

Moved static and global data elements into thread-local storage,
or introduced locks where not possible, as first stage of adding
thread safety to Tk.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinScrlbr.c,v 1.1.4.2 1998/09/30 02:19:37 stanton Exp $
a59 2
TCL_DECLARE_MUTEX(winScrlbrMutex)

a118 1
        Tcl_MutexLock(&winScrlbrMutex);
a120 1
	Tcl_MutexUnlock(&winScrlbrMutex);
@


