changeset 1394:a151d45a7041

Added generic tooltip support on OS/2. Will be modifying the behavior shortly to delay tooltip display... and after a time remove the tooltip... so it acts like the other platforms.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 27 Nov 2011 09:03:26 +0000
parents eb83c9830dfa
children e0a66f06501c
files os2/dw.c readme
diffstat 2 files changed, 203 insertions(+), 161 deletions(-) [+]
line wrap: on
line diff
--- a/os2/dw.c	Sat Nov 26 22:55:33 2011 +0000
+++ b/os2/dw.c	Sun Nov 27 09:03:26 2011 +0000
@@ -1614,6 +1614,157 @@
 }
 
 
+/* Function: BubbleProc
+ * Abstract: Subclass procedure for bubble help
+ */
+MRESULT EXPENTRY _BubbleProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+{
+   MRESULT res;
+   PFNWP proc = (PFNWP)WinQueryWindowPtr(hwnd, QWL_USER);
+
+   if(proc)
+      res = proc(hwnd, msg, mp1, mp2);
+   else
+      res = WinDefWindowProc(hwnd, msg, mp1, mp2);
+
+   if(msg == WM_PAINT)
+   {
+      POINTL ptl;
+      HPS hpsTemp;
+      RECTL rcl;
+      int height, width;
+
+      WinQueryWindowRect(hwnd, &rcl);
+      height = rcl.yTop - rcl.yBottom - 1;
+      width = rcl.xRight - rcl.xLeft - 1;
+
+      /* Draw a border around the bubble help */
+      hpsTemp = WinGetPS(hwnd);
+      GpiSetColor(hpsTemp, CLR_BLACK);
+      ptl.x = ptl.y = 0;
+      GpiMove(hpsTemp, &ptl);
+      ptl.x = 0;
+      ptl.y = height;
+      GpiLine(hpsTemp, &ptl);
+      ptl.x = ptl.y = 0;
+      GpiMove(hpsTemp, &ptl);
+      ptl.y = 0;
+      ptl.x = width;
+      GpiLine(hpsTemp, &ptl);
+      ptl.x = width;
+      ptl.y = height;
+      GpiMove(hpsTemp, &ptl);
+      ptl.x = 0;
+      ptl.y = height;
+      GpiLine(hpsTemp, &ptl);
+      ptl.x = width;
+      ptl.y = height;
+      GpiMove(hpsTemp, &ptl);
+      ptl.y = 0;
+      ptl.x = width;
+      GpiLine(hpsTemp, &ptl);
+      WinReleasePS(hpsTemp);
+   }
+   return res;
+}
+
+/* Function to handle tooltip messages from a variety of procedures */
+MRESULT EXPENTRY _TooltipProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, WindowData *blah)
+{
+   switch(msg)
+   {
+   case 0x041f:
+      if (hwndBubble)
+      {
+         WinDestroyWindow(hwndBubble);
+         hwndBubble = 0;
+      }
+      break;
+
+   case 0x041e:
+
+      if(!*blah->bubbletext)
+         break;
+
+      if(hwndBubble)
+      {
+         WinDestroyWindow(hwndBubble);
+         hwndBubble = 0;
+      }
+
+      if(!hwndBubble)
+      {
+         HPS   hpsTemp = 0;
+         LONG  lHight;
+         LONG  lWidth;
+         POINTL txtPointl[TXTBOX_COUNT];
+         POINTL ptlWork = {0,0};
+         ULONG ulColor = CLR_YELLOW;
+         void *bubbleproc;
+
+         hwndBubbleLast   = hwnd;
+         hwndBubble = WinCreateWindow(HWND_DESKTOP,
+                               WC_STATIC,
+                               NULL,
+                               SS_TEXT |
+                               DT_CENTER |
+                               DT_VCENTER,
+                                         0,0,0,0,
+                               HWND_DESKTOP,
+                               HWND_TOP,
+                               0,
+                               NULL,
+                               NULL);
+
+         WinSetPresParam(hwndBubble,
+                     PP_FONTNAMESIZE,
+                     strlen(DefaultFont)+1,
+                     DefaultFont);
+
+
+         WinSetPresParam(hwndBubble,
+                     PP_BACKGROUNDCOLORINDEX,
+                     sizeof(ulColor),
+                     &ulColor);
+
+         WinSetWindowText(hwndBubble,
+                      (PSZ)blah->bubbletext);
+
+         WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptlWork, 1);
+
+         hpsTemp = WinGetPS(hwndBubble);
+         GpiQueryTextBox(hpsTemp,
+                     strlen(blah->bubbletext),
+                     (PCH)blah->bubbletext,
+                     TXTBOX_COUNT,
+                     txtPointl);
+         WinReleasePS(hpsTemp);
+
+         lWidth = txtPointl[TXTBOX_TOPRIGHT].x -
+            txtPointl[TXTBOX_TOPLEFT ].x + 8;
+
+         lHight = txtPointl[TXTBOX_TOPLEFT].y -
+            txtPointl[TXTBOX_BOTTOMLEFT].y + 8;
+
+         ptlWork.y -= lHight;
+
+         bubbleproc = (void *)WinSubclassWindow(hwndBubble, _BubbleProc);
+
+         if(bubbleproc)
+            WinSetWindowPtr(hwndBubble, QWP_USER, bubbleproc);
+
+         WinSetWindowPos(hwndBubble,
+                     HWND_TOP,
+                     ptlWork.x,
+                     ptlWork.y,
+                     lWidth,
+                     lHight,
+                     SWP_SIZE | SWP_MOVE | SWP_SHOW);
+      }
+      break;
+   }
+}
+
 #define CALENDAR_BORDER 3
 #define CALENDAR_ARROW 8
 
@@ -1653,6 +1804,9 @@
    {
       oldproc = blah->oldproc;
 
+      if(blah->bubbletext[0])
+          _TooltipProc(hWnd, msg, mp1, mp2, blah);
+
       switch(msg)
       {
       case WM_BUTTON1DOWN:
@@ -1888,14 +2042,21 @@
 /* This procedure handles drawing of a status border */
 MRESULT EXPENTRY _statusproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
-   PFNWP *blah = WinQueryWindowPtr(hWnd, QWP_USER);
+   WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER);
+   PFNWP oldproc = 0;
 
    if(msg == WM_MOUSEMOVE && _wndproc(hWnd, msg, mp1, mp2))
       return MPFROMSHORT(FALSE);
 
-   if(blah && *blah)
-   {
-      PFNWP myfunc = *blah;
+   if(blah)
+   {
+      oldproc = blah->oldproc;
+
+      if(blah->bubbletext[0])
+          _TooltipProc(hWnd, msg, mp1, mp2, blah);
+
+      if(blah->bubbletext[0])
+          _TooltipProc(hWnd, msg, mp1, mp2, blah);
 
       switch(msg)
       {
@@ -1930,7 +2091,8 @@
             return (MRESULT)TRUE;
          }
       }
-      return myfunc(hWnd, msg, mp1, mp2);
+      if(oldproc)
+          return oldproc(hWnd, msg, mp1, mp2);
    }
 
    return WinDefWindowProc(hWnd, msg, mp1, mp2);
@@ -2095,6 +2257,9 @@
 
    WinQueryClassName(hWnd, 99, (PCH)tmpbuf);
 
+   if(blah && blah->bubbletext[0])
+       _TooltipProc(hWnd, msg, mp1, mp2, blah);
+
    /* These are the window classes which should get a menu */
    if(strncmp(tmpbuf, "#2", 3)==0 ||  /* Combobox */
       strncmp(tmpbuf, "#6", 3)==0 ||  /* Entryfield */
@@ -2251,6 +2416,9 @@
 {
    WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER);
 
+   if(blah && blah->bubbletext[0])
+       _TooltipProc(hWnd, msg, mp1, mp2, blah);
+
    switch(msg)
    {
    case WM_MOUSEMOVE:
@@ -2304,6 +2472,9 @@
    if(blah)
       oldproc = blah->oldproc;
 
+   if(blah && blah->bubbletext[0])
+       _TooltipProc(hWnd, msg, mp1, mp2, blah);
+
    switch(msg)
    {
    case WM_MOUSEMOVE:
@@ -2353,6 +2524,9 @@
    if(blah)
       oldproc = blah->oldproc;
 
+   if(blah && blah->bubbletext[0])
+       _TooltipProc(hWnd, msg, mp1, mp2, blah);
+
    switch(msg)
    {
    case WM_MOUSEMOVE:
@@ -2384,6 +2558,9 @@
    if(blah)
       oldproc = blah->oldproc;
 
+   if(blah && blah->bubbletext[0])
+       _TooltipProc(hWnd, msg, mp1, mp2, blah);
+
    switch(msg)
    {
    case WM_MOUSEMOVE:
@@ -3538,60 +3715,6 @@
    return WinDefWindowProc(hwnd, msg, mp1, mp2);
 }
 
-/* Function: BubbleProc
- * Abstract: Subclass procedure for bubble help
- */
-MRESULT EXPENTRY _BubbleProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
-{
-   MRESULT res;
-   PFNWP proc = (PFNWP)WinQueryWindowPtr(hwnd, QWL_USER);
-
-   if(proc)
-      res = proc(hwnd, msg, mp1, mp2);
-   else
-      res = WinDefWindowProc(hwnd, msg, mp1, mp2);
-
-   if(msg == WM_PAINT)
-   {
-      POINTL ptl;
-      HPS hpsTemp;
-      RECTL rcl;
-      int height, width;
-
-      WinQueryWindowRect(hwnd, &rcl);
-      height = rcl.yTop - rcl.yBottom - 1;
-      width = rcl.xRight - rcl.xLeft - 1;
-
-      /* Draw a border around the bubble help */
-      hpsTemp = WinGetPS(hwnd);
-      GpiSetColor(hpsTemp, CLR_BLACK);
-      ptl.x = ptl.y = 0;
-      GpiMove(hpsTemp, &ptl);
-      ptl.x = 0;
-      ptl.y = height;
-      GpiLine(hpsTemp, &ptl);
-      ptl.x = ptl.y = 0;
-      GpiMove(hpsTemp, &ptl);
-      ptl.y = 0;
-      ptl.x = width;
-      GpiLine(hpsTemp, &ptl);
-      ptl.x = width;
-      ptl.y = height;
-      GpiMove(hpsTemp, &ptl);
-      ptl.x = 0;
-      ptl.y = height;
-      GpiLine(hpsTemp, &ptl);
-      ptl.x = width;
-      ptl.y = height;
-      GpiMove(hpsTemp, &ptl);
-      ptl.y = 0;
-      ptl.x = width;
-      GpiLine(hpsTemp, &ptl);
-      WinReleasePS(hpsTemp);
-   }
-   return res;
-}
-
 MRESULT EXPENTRY _button_draw(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, PFNWP oldproc, int indent)
 {
    HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap");
@@ -3677,6 +3800,9 @@
 
    oldproc = blah->oldproc;
 
+   if(blah->bubbletext[0])
+       _TooltipProc(hwnd, msg, mp1, mp2, blah);
+
    switch(msg)
    {
    case WM_MOUSEMOVE:
@@ -3801,97 +3927,7 @@
          }
       }
       break;
-   case 0x041f:
-      if (hwndBubble)
-      {
-         WinDestroyWindow(hwndBubble);
-         hwndBubble = 0;
-      }
-      break;
-
-   case 0x041e:
-
-      if(!*blah->bubbletext)
-         break;
-
-      if(hwndBubble)
-      {
-         WinDestroyWindow(hwndBubble);
-         hwndBubble = 0;
-      }
-
-      if(!hwndBubble)
-      {
-         HPS   hpsTemp = 0;
-         LONG  lHight;
-         LONG  lWidth;
-         POINTL txtPointl[TXTBOX_COUNT];
-         POINTL ptlWork = {0,0};
-         ULONG ulColor = CLR_YELLOW;
-         void *bubbleproc;
-
-         hwndBubbleLast   = hwnd;
-         hwndBubble = WinCreateWindow(HWND_DESKTOP,
-                               WC_STATIC,
-                               NULL,
-                               SS_TEXT |
-                               DT_CENTER |
-                               DT_VCENTER,
-                                         0,0,0,0,
-                               HWND_DESKTOP,
-                               HWND_TOP,
-                               0,
-                               NULL,
-                               NULL);
-
-         WinSetPresParam(hwndBubble,
-                     PP_FONTNAMESIZE,
-                     strlen(DefaultFont)+1,
-                     DefaultFont);
-
-
-         WinSetPresParam(hwndBubble,
-                     PP_BACKGROUNDCOLORINDEX,
-                     sizeof(ulColor),
-                     &ulColor);
-
-         WinSetWindowText(hwndBubble,
-                      (PSZ)blah->bubbletext);
-
-         WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptlWork, 1);
-
-         hpsTemp = WinGetPS(hwndBubble);
-         GpiQueryTextBox(hpsTemp,
-                     strlen(blah->bubbletext),
-                     (PCH)blah->bubbletext,
-                     TXTBOX_COUNT,
-                     txtPointl);
-         WinReleasePS(hpsTemp);
-
-         lWidth = txtPointl[TXTBOX_TOPRIGHT].x -
-            txtPointl[TXTBOX_TOPLEFT ].x + 8;
-
-         lHight = txtPointl[TXTBOX_TOPLEFT].y -
-            txtPointl[TXTBOX_BOTTOMLEFT].y + 8;
-
-         ptlWork.y -= lHight;
-
-         bubbleproc = (void *)WinSubclassWindow(hwndBubble, _BubbleProc);
-
-         if(bubbleproc)
-            WinSetWindowPtr(hwndBubble, QWP_USER, bubbleproc);
-
-         WinSetWindowPos(hwndBubble,
-                     HWND_TOP,
-                     ptlWork.x,
-                     ptlWork.y,
-                     lWidth,
-                     lHight,
-                     SWP_SIZE | SWP_MOVE | SWP_SHOW);
-      }
-      break;
-   }
-
+   }
    if(!oldproc)
       return WinDefWindowProc(hwnd, msg, mp1, mp2);
    return oldproc(hwnd, msg, mp1, mp2);
@@ -3899,8 +3935,12 @@
 
 MRESULT EXPENTRY _RendProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
-   int res = 0;
-   res = (int)_run_event(hwnd, msg, mp1, mp2);
+   WindowData *blah = (WindowData *)WinQueryWindowPtr(hwnd, QWP_USER);
+   int res = (int)_run_event(hwnd, msg, mp1, mp2);
+
+   if(blah && blah->bubbletext[0])
+       _TooltipProc(hwnd, msg, mp1, mp2, blah);
+
    switch(msg)
    {
    case WM_MOUSEMOVE:
@@ -3926,6 +3966,9 @@
    if(blah)
       oldproc = blah->oldproc;
 
+   if(blah && blah->bubbletext[0])
+       _TooltipProc(hwnd, msg, mp1, mp2, blah);
+
    switch(msg)
    {
    case WM_MOUSEMOVE:
@@ -5638,7 +5681,6 @@
                     NULL);
 
    strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
-   blah->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
    blah->oldproc = WinSubclassWindow(tmp, _BtProc);
 
    WinSetWindowPtr(tmp, QWP_USER, blah);
@@ -5736,7 +5778,6 @@
    }
 
    strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
-   blah->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
    blah->oldproc = WinSubclassWindow(tmp, _BtProc);
 
    WinSetWindowPtr(tmp, QWP_USER, blah);
@@ -5835,7 +5876,6 @@
    }
 
    strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1);
-   blah->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
    blah->oldproc = WinSubclassWindow(tmp, _BtProc);
 
    WinSetWindowPtr(tmp, QWP_USER, blah);
@@ -5926,7 +5966,7 @@
    HWND tmp;
 
    sldcData.cbSize = sizeof(SLDCDATA);
-    sldcData.usScale1Increments = increments;
+   sldcData.usScale1Increments = increments;
 
    tmp = WinCreateWindow(HWND_OBJECT,
                     WC_SLIDER,
@@ -6011,7 +6051,6 @@
                         id,
                         NULL,
                         NULL);
-   blah->bubbletext[0] = '\0';
    blah->oldproc = WinSubclassWindow(tmp, _BtProc);
    WinSetWindowPtr(tmp, QWP_USER, blah);
    dw_window_set_font(tmp, DefaultFont);
@@ -6315,9 +6354,13 @@
  */
 void API dw_window_set_tooltip(HWND handle, char *bubbletext)
 {
-    /* TODO: Fill this in with generic bubble help code...
-     * like we do for the bitmap buttons.
-     */
+   WindowData *blah = (WindowData *)WinQueryWindowPtr(handle, QWP_USER);
+   HWND buddy = (HWND)dw_window_get_data(handle, "_dw_buddy");
+
+   if(blah)
+       strncpy(blah->bubbletext, bubbletext, BUBBLE_HELP_MAX - 1);
+   if(buddy && (blah = (WindowData *)WinQueryWindowPtr(buddy, QWP_USER)))
+       strncpy(blah->bubbletext, bubbletext, BUBBLE_HELP_MAX - 1);
 }
 
 /*
--- a/readme	Sat Nov 26 22:55:33 2011 +0000
+++ b/readme	Sun Nov 27 09:03:26 2011 +0000
@@ -37,7 +37,6 @@
 Added dw_app_dir() which attempts to locate private application data
     for the current platform.  
 Added dw_window_set_tooltip() for adding tooltips to most widgets.
-    All platforms supported except OS/2 which will be coming soon.
 Fixed bubble help not being displayed on Windows.
 Fixed menu bar items remaining highlighted on Mac.