Tk Source Code

Artifact [274a9c7d]
Login

Artifact 274a9c7d334a157962e9165263350e4042fb649e:

Attachment "0002-ak-Enable-the-context-help-pointer-on-Windows.patch" to ticket [2838812f] added by patthoyts 2010-01-02 23:44:20.
From 6b071ffcd42fde1bb3809805f1326fd794085965 Mon Sep 17 00:00:00 2001
From: Pat Thoyts <[email protected]>
Date: Sat, 2 Jan 2010 14:02:24 +0000
Subject: [PATCH 2/3] ak: Enable the context help pointer on Windows

This patch from Anton Kovalenko adds a -contexthelp option to the wm
attributes command which enables the help button on the window frame.
This affects the cursor which then shows a help cursor and clicking on
a control should then show context help about that control.

Signed-off-by: Pat Thoyts <[email protected]>
---
 win/tkWinCursor.c |   11 +++++++++
 win/tkWinWm.c     |    8 ++++++
 win/tkWinX.c      |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/win/tkWinCursor.c b/win/tkWinCursor.c
index 28aab72..908d445 100644
--- a/win/tkWinCursor.c
+++ b/win/tkWinCursor.c
@@ -250,6 +250,11 @@ void
 TkpSetCursor(
     TkpCursor cursor)
 {
+   /* the hcursor_idc_help test is necessary for the CONTEXT HELP to work
+    * using wm attributes $window -contexthelp
+    */
+ 
+    static HCURSOR hcursor_idc_help = NULL;
     HCURSOR hcursor;
     TkWinCursor *winCursor = (TkWinCursor *) cursor;
 
@@ -259,6 +264,12 @@ TkpSetCursor(
 	hcursor = winCursor->winCursor;
     }
 
+    if (hcursor_idc_help == NULL) {
+	hcursor_idc_help = LoadCursor(NULL,IDC_HELP);
+    }
+    if (GetCursor() == hcursor_idc_help) {
+	return;
+    }
     if (hcursor != NULL) {
 	SetCursor(hcursor);
     }
diff --git a/win/tkWinWm.c b/win/tkWinWm.c
index c9d9205..b0276ea 100644
--- a/win/tkWinWm.c
+++ b/win/tkWinWm.c
@@ -3090,6 +3090,7 @@ WmAttributesCmd(
 	Tcl_WrongNumArgs(interp, 2, objv,
 		"window"
 		" ?-alpha ?double??"
+ 		" ?-contexthelp ?bool??"
 		" ?-transparentcolor ?color??"
 		" ?-disabled ?bool??"
 		" ?-fullscreen ?bool??"
@@ -3124,6 +3125,10 @@ WmAttributesCmd(
 		Tcl_NewStringObj("-topmost", -1));
 	Tcl_ListObjAppendElement(NULL, objPtr,
 		Tcl_NewBooleanObj((exStyle & WS_EX_TOPMOST)));
+	Tcl_ListObjAppendElement(NULL, objPtr,
+		Tcl_NewStringObj("-contexthelp", -1));
+	Tcl_ListObjAppendElement(NULL, objPtr,
+		Tcl_NewBooleanObj((style & WS_EX_CONTEXTHELP)));
 	Tcl_SetObjResult(interp, objPtr);
 	return TCL_OK;
     }
@@ -3143,6 +3148,9 @@ WmAttributesCmd(
 	} else if (strncmp(string, "-fullscreen", (unsigned) length) == 0) {
 	    config_fullscreen = 1;
 	    styleBit = 0;
+	} else if (strncmp(string,"-contexthelp", length) == 0) {
+	    stylePtr=&exStyle;
+	    styleBit=WS_EX_CONTEXTHELP;
 	} else if ((length > 3)
 		&& (strncmp(string, "-toolwindow", (unsigned) length) == 0)) {
 	    stylePtr = &exStyle;
diff --git a/win/tkWinX.c b/win/tkWinX.c
index ee7a9fc..40a4488 100644
--- a/win/tkWinX.c
+++ b/win/tkWinX.c
@@ -786,6 +786,61 @@ XBell(
 /*
  *----------------------------------------------------------------------
  *
+ * HelpEvent --
+ *
+ *	Generates a "Help" virtual event. This can be used to do
+ *	context-sensitive help.
+ *
+ * Results:
+ *	None.
+ *
+ * Side effects:
+ *	Places a virtual event on the event queue.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+HelpEvent (hwnd, message, wParam, lParam)
+    HWND hwnd;
+    UINT message;
+    WPARAM wParam;
+    LPARAM lParam;
+{
+    TkWindow *winPtr = (TkWindow *)Tk_HWNDToWindow(hwnd);
+    XVirtualEvent event;
+    POINTS rootPoint;
+    POINT clientPoint;
+    DWORD msgPos;
+
+    event.type = VirtualEvent;
+    event.serial = winPtr->display->request;
+    event.send_event = 0;
+    event.display = winPtr->display;
+    event.event = Tk_WindowId(winPtr);
+    event.root = XRootWindow(winPtr->display, 0);
+    event.subwindow = None;
+    event.time = TkpGetMS();
+
+    msgPos = GetMessagePos();
+    rootPoint = MAKEPOINTS(msgPos);
+    clientPoint.x = rootPoint.x;
+    clientPoint.y = rootPoint.y;
+    ScreenToClient(hwnd, &clientPoint);
+    event.x = clientPoint.x;
+    event.y = clientPoint.y;
+    event.x_root = rootPoint.x;
+    event.y_root = rootPoint.y;
+    event.state = TkWinGetModifierState();
+    event.same_screen = 1;
+    event.name = Tk_GetUid("Help");
+    event.user_data = NULL;
+    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
  * TkWinChildProc --
  *
  *	Callback from Windows whenever an event occurs on a child window.
@@ -809,6 +864,14 @@ TkWinChildProc(
     LRESULT result;
 
     switch (message) {
+
+    case WM_HELP:
+	Tk_UpdatePointer(NULL, 0, 0, TkWinGetModifierState() | 
+			NOBUTTONEVENTS_MASK);
+	HelpEvent(hwnd, message, wParam, lParam);
+	result = DefWindowProc(hwnd, message, wParam, lParam);
+	break;
+
     case WM_INPUTLANGCHANGE:
 	UpdateInputLanguage((int) wParam);
 	result = 1;
-- 
1.6.6