changeset 70:eabb41384d60

ToolTip
author Frank Benoit <benoit@tionex.de>
date Mon, 04 Feb 2008 21:48:28 +0100
parents 3b93cc2ffe96
children effe4929903f
files dwt/internal/win32/OS.d dwt/widgets/ToolTip.d dwt/widgets/TrayItem.d
diffstat 3 files changed, 81 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/internal/win32/OS.d	Mon Feb 04 21:28:40 2008 +0100
+++ b/dwt/internal/win32/OS.d	Mon Feb 04 21:48:28 2008 +0100
@@ -4954,6 +4954,7 @@
     alias StrToWCHARz       StrToTCHARz;
     alias WCHARzToStr       TCHARzToStr;
     alias WCHARsToStr       TCHARsToStr;
+    alias _tcslen           TCHARzLen;
 }
 
 
--- a/dwt/widgets/ToolTip.d	Mon Feb 04 21:28:40 2008 +0100
+++ b/dwt/widgets/ToolTip.d	Mon Feb 04 21:48:28 2008 +0100
@@ -10,20 +10,6 @@
  *******************************************************************************/
 module dwt.widgets.ToolTip;
 
-import dwt.widgets.Widget;
-import dwt.internal.win32.OS;
-class ToolTip : Widget {
-    //Shell parent;
-    //TrayItem item;
-    char[] text = "", message = "";
-    int id, x, y;
-    bool autoHide = true, hasLocation, visible;
-    static const int TIMER_ID = 100;
-    this( Widget, int );
-HWND hwndToolTip () ;
-public void setVisible (bool visible) ;
-}
-/++
 
 import dwt.DWT;
 import dwt.DWTException;
@@ -32,6 +18,14 @@
 import dwt.graphics.Point;
 import dwt.internal.win32.OS;
 
+import dwt.widgets.Widget;
+import dwt.widgets.Shell;
+import dwt.widgets.TrayItem;
+import dwt.widgets.Display;
+import dwt.widgets.TypedListener;
+
+import dwt.dwthelper.utils;
+
 /**
  * Instances of this class represent popup windows that are used
  * to inform or warn the user.
@@ -53,13 +47,13 @@
  * @since 3.2
  */
 
-public class ToolTip extends Widget {
+public class ToolTip : Widget {
     Shell parent;
     TrayItem item;
-    String text = "", message = "";
+    char[] text = "", message = "";
     int id, x, y;
     bool autoHide = true, hasLocation, visible;
-    static final int TIMER_ID = 100;
+    static const int TIMER_ID = 100;
 
 /**
  * Constructs a new instance of this class given its parent
@@ -91,7 +85,7 @@
  * @see Widget#checkSubclass
  * @see Widget#getStyle
  */
-public ToolTip (Shell parent, int style) {
+public this (Shell parent, int style) {
     super (parent, checkStyle (style));
     this.parent = parent;
     checkOrientation (parent);
@@ -169,7 +163,7 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public String getMessage () {
+public char[] getMessage () {
     checkWidget();
     return message;
 }
@@ -200,7 +194,7 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public String getText () {
+public char[] getText () {
     checkWidget();
     return text;
 }
@@ -226,18 +220,18 @@
     checkWidget();
     if (OS.IsWinCE) return false;
     if (item !is null) return visible;
-    int hwndToolTip = hwndToolTip ();
-    if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, 0) !is 0) {
-        TOOLINFO lpti = new TOOLINFO ();
+    auto hwndToolTip_ = hwndToolTip ();
+    if (OS.SendMessage (hwndToolTip_, OS.TTM_GETCURRENTTOOL, 0, 0) !is 0) {
+        TOOLINFO lpti;
         lpti.cbSize = TOOLINFO.sizeof;
-        if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) !is 0) {
+        if (OS.SendMessage (hwndToolTip_, OS.TTM_GETCURRENTTOOL, 0, &lpti) !is 0) {
             return (lpti.uFlags & OS.TTF_IDISHWND) is 0 && lpti.uId is id;
         }
     }
     return false;
 }
 
-int hwndToolTip () {
+HWND hwndToolTip () {
     return (style & DWT.BALLOON) !is 0 ? parent.balloonTipHandle () : parent.toolTipHandle ();
 }
 
@@ -272,16 +266,16 @@
     super.releaseWidget ();
     if (item is null) {
         if (autoHide) {
-            int hwndToolTip = hwndToolTip ();
-            if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, 0) !is 0) {
-                TOOLINFO lpti = new TOOLINFO ();
+            auto hwndToolTip_ = hwndToolTip ();
+            if (OS.SendMessage (hwndToolTip_, OS.TTM_GETCURRENTTOOL, 0, 0) !is 0) {
+                TOOLINFO lpti;
                 lpti.cbSize = TOOLINFO.sizeof;
-                if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) !is 0) {
+                if (OS.SendMessage (hwndToolTip_, OS.TTM_GETCURRENTTOOL, 0, &lpti) !is 0) {
                     if ((lpti.uFlags & OS.TTF_IDISHWND) is 0) {
                         if (lpti.uId is id) {
-                            OS.SendMessage (hwndToolTip, OS.TTM_TRACKACTIVATE, 0, lpti);
-                            OS.SendMessage (hwndToolTip, OS.TTM_POP, 0, 0);
-                            OS.KillTimer (hwndToolTip, TIMER_ID);
+                            OS.SendMessage (hwndToolTip_, OS.TTM_TRACKACTIVATE, 0, &lpti);
+                            OS.SendMessage (hwndToolTip_, OS.TTM_POP, 0, 0);
+                            OS.KillTimer (hwndToolTip_, TIMER_ID);
                         }
                     }
                 }
@@ -406,7 +400,7 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public void setMessage (String string) {
+public void setMessage (char[] string) {
     checkWidget ();
     if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
     message = string;
@@ -426,7 +420,7 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public void setText (String string) {
+public void setText (char[] string) {
     checkWidget ();
     if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
     text = string;
@@ -454,46 +448,46 @@
     if (OS.IsWinCE) return;
     if (visible is getVisible ()) return;
     if (item is null) {
-        int hwnd = parent.handle;
-        TOOLINFO lpti = new TOOLINFO ();
+        auto hwnd = parent.handle;
+        TOOLINFO lpti;
         lpti.cbSize = TOOLINFO.sizeof;
         lpti.uId = id;
         lpti.hwnd = hwnd;
-        int hwndToolTip = hwndToolTip ();
+        auto hwndToolTip_ = hwndToolTip ();
         Shell shell = parent.getShell ();
-        if (text.length () !is 0) {
+        if (text.length !is 0) {
             int icon = OS.TTI_NONE;
             if ((style & DWT.ICON_INFORMATION) !is 0) icon = OS.TTI_INFO;
             if ((style & DWT.ICON_WARNING) !is 0) icon = OS.TTI_WARNING;
             if ((style & DWT.ICON_ERROR) !is 0) icon = OS.TTI_ERROR;
-            shell.setToolTipTitle (hwndToolTip, text, icon);
+            shell.setToolTipTitle (hwndToolTip_, text, cast(HICON) icon);
         } else {
-            shell.setToolTipTitle (hwndToolTip, null, 0);
+            shell.setToolTipTitle (hwndToolTip_, null, null);
         }
         int maxWidth = 0;
         if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
-            RECT rect = new RECT ();
-            OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, rect, 0);
+            RECT rect;
+            OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, &rect, 0);
             maxWidth = (rect.right - rect.left) / 4;
         } else {
-            int hmonitor = OS.MonitorFromWindow (hwnd, OS.MONITOR_DEFAULTTONEAREST);
-            MONITORINFO lpmi = new MONITORINFO ();
+            auto hmonitor = OS.MonitorFromWindow (hwnd, OS.MONITOR_DEFAULTTONEAREST);
+            MONITORINFO lpmi;
             lpmi.cbSize = MONITORINFO.sizeof;
-            OS.GetMonitorInfo (hmonitor, lpmi);
-            maxWidth = (lpmi.rcWork_right - lpmi.rcWork_left) / 4;
+            OS.GetMonitorInfo (hmonitor, &lpmi);
+            maxWidth = (lpmi.rcWork.right - lpmi.rcWork.left) / 4;
         }
-        OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, maxWidth);
+        OS.SendMessage (hwndToolTip_, OS.TTM_SETMAXTIPWIDTH, 0, maxWidth);
         if (visible) {
             int nX = x, nY = y;
             if (!hasLocation) {
-                POINT pt = new POINT ();
-                if (OS.GetCursorPos (pt)) {
+                POINT pt;
+                if (OS.GetCursorPos (&pt)) {
                     nX = pt.x;
                     nY = pt.y;
                 }
             }
             int lParam = (nX & 0xFFFF) | ((nY << 16) & 0xFFFF0000);
-            OS.SendMessage (hwndToolTip, OS.TTM_TRACKPOSITION, 0, lParam);
+            OS.SendMessage (hwndToolTip_, OS.TTM_TRACKPOSITION, 0, lParam);
 
             /*
             * Feature in Windows.  Windows will not show a tool tip
@@ -502,50 +496,50 @@
             * move the cursor into the tool window, show the tool tip,
             * and then restore the cursor.
             */
-            POINT pt = new POINT ();
-            OS.GetCursorPos (pt);
-            RECT rect = new RECT ();
-            OS.GetClientRect (hwnd, rect);
-            OS.MapWindowPoints (hwnd, 0, rect, 2);
-            if (!OS.PtInRect (rect, pt)) {
-                int hCursor = OS.GetCursor ();
-                OS.SetCursor (0);
+            POINT pt;
+            OS.GetCursorPos (&pt);
+            RECT rect;
+            OS.GetClientRect (hwnd, &rect);
+            OS.MapWindowPoints (hwnd, null, cast(POINT*) &rect, 2);
+            if (!OS.PtInRect (&rect, pt)) {
+                HCURSOR hCursor = OS.GetCursor ();
+                OS.SetCursor (null);
                 OS.SetCursorPos (rect.left, rect.top);
-                OS.SendMessage (hwndToolTip, OS.TTM_TRACKACTIVATE, 1, lpti);
+                OS.SendMessage (hwndToolTip_, OS.TTM_TRACKACTIVATE, 1, &lpti);
                 OS.SetCursorPos (pt.x, pt.y);
                 OS.SetCursor (hCursor);
             } else {
-                OS.SendMessage (hwndToolTip, OS.TTM_TRACKACTIVATE, 1, lpti);
+                OS.SendMessage (hwndToolTip_, OS.TTM_TRACKACTIVATE, 1, &lpti);
             }
 
-            int time = OS.SendMessage (hwndToolTip, OS.TTM_GETDELAYTIME, OS.TTDT_AUTOPOP, 0);
-            OS.SetTimer (hwndToolTip, TIMER_ID, time, 0);
+            int time = OS.SendMessage (hwndToolTip_, OS.TTM_GETDELAYTIME, OS.TTDT_AUTOPOP, 0);
+            OS.SetTimer (hwndToolTip_, TIMER_ID, time, null);
         } else {
-            OS.SendMessage (hwndToolTip, OS.TTM_TRACKACTIVATE, 0, lpti);
-            OS.SendMessage (hwndToolTip, OS.TTM_POP, 0, 0);
-            OS.KillTimer (hwndToolTip, TIMER_ID);
+            OS.SendMessage (hwndToolTip_, OS.TTM_TRACKACTIVATE, 0, &lpti);
+            OS.SendMessage (hwndToolTip_, OS.TTM_POP, 0, 0);
+            OS.KillTimer (hwndToolTip_, TIMER_ID);
         }
         return;
     }
     if (item !is null && OS.SHELL32_MAJOR >= 5) {
         if (visible) {
-            NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
-            TCHAR buffer1 = new TCHAR (0, text, true);
-            TCHAR buffer2 = new TCHAR (0, message, true);
-            if (OS.IsUnicode) {
-                char [] szInfoTitle = ((NOTIFYICONDATAW) iconData).szInfoTitle;
-                int length1 = Math.min (szInfoTitle.length - 1, buffer1.length ());
-                System.arraycopy (buffer1.chars, 0, szInfoTitle, 0, length1);
-                char [] szInfo = ((NOTIFYICONDATAW) iconData).szInfo;
-                int length2 = Math.min (szInfo.length - 1, buffer2.length ());
-                System.arraycopy (buffer2.chars, 0, szInfo, 0, length2);
+            NOTIFYICONDATA iconData;
+            TCHAR[] buffer1 = StrToTCHARs (0, text, true);
+            TCHAR[] buffer2 = StrToTCHARs (0, message, true);
+            static if (OS.IsUnicode) {
+                TCHAR [] szInfoTitle = iconData.szInfoTitle;
+                int length1 = Math.min (szInfoTitle.length - 1, buffer1.length);
+                System.arraycopy (buffer1, 0, szInfoTitle, 0, length1);
+                TCHAR [] szInfo = iconData.szInfo;
+                int length2 = Math.min (szInfo.length - 1, buffer2.length );
+                System.arraycopy (buffer2, 0, szInfo, 0, length2);
             } else {
-                byte [] szInfoTitle = ((NOTIFYICONDATAA) iconData).szInfoTitle;
-                int length = Math.min (szInfoTitle.length - 1, buffer1.length ());
-                System.arraycopy (buffer1.bytes, 0, szInfoTitle, 0, length);
-                byte [] szInfo = ((NOTIFYICONDATAA) iconData).szInfo;
-                int length2 = Math.min (szInfo.length - 1, buffer2.length ());
-                System.arraycopy (buffer2.bytes, 0, szInfo, 0, length2);
+                byte [] szInfoTitle = iconData.szInfoTitle;
+                int length = Math.min (szInfoTitle.length - 1, buffer1.length );
+                System.arraycopy (buffer1, 0, szInfoTitle, 0, length);
+                byte [] szInfo = iconData.szInfo;
+                int length2 = Math.min (szInfo.length - 1, buffer2.length );
+                System.arraycopy (buffer2, 0, szInfo, 0, length2);
             }
             Display display = item.getDisplay ();
             iconData.cbSize = NOTIFYICONDATA.sizeof;
@@ -556,11 +550,11 @@
             if ((style & DWT.ICON_WARNING) !is 0) iconData.dwInfoFlags = OS.NIIF_WARNING;
             if ((style & DWT.ICON_ERROR) !is 0) iconData.dwInfoFlags = OS.NIIF_ERROR;
             sendEvent (DWT.Show);
-            this.visible = OS.Shell_NotifyIcon (OS.NIM_MODIFY, iconData);
+            this.visible = cast(bool) OS.Shell_NotifyIcon (OS.NIM_MODIFY, &iconData);
         } else {
             //TODO - hide the tray item
         }
     }
 }
 }
-++/
+
--- a/dwt/widgets/TrayItem.d	Mon Feb 04 21:28:40 2008 +0100
+++ b/dwt/widgets/TrayItem.d	Mon Feb 04 21:48:28 2008 +0100
@@ -12,6 +12,7 @@
 
 import dwt.widgets.Item;
 import dwt.widgets.Widget;
+import dwt.widgets.ToolTip;
 import dwt.internal.win32.OS;
 
 class TrayItem : Item {
@@ -21,6 +22,8 @@
     }
 int messageProc (HWND hwnd, int msg, int wParam, int lParam) ;
 void recreate () ;
+public bool getVisible () ;
+    ToolTip toolTip;
 }
 /++