[Mono-winforms-list] swf patch
Aleksey Ryabchuk
ryabchuk@yahoo.com
Wed, 26 Mar 2003 09:30:59 -0800 (PST)
--0-292435941-1048699859=:86755
Content-Type: text/plain; charset=us-ascii
Content-Id:
Content-Disposition: inline
tooltip.cs,
win32Enums.cs,
win32functions.cs: implementation of ToolTip control
class.
Regards
Aleksey
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
--0-292435941-1048699859=:86755
Content-Type: text/plain; name=patch
Content-Description: patch
Content-Disposition: inline; filename=patch
Index: tooltip.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/tooltip.cs,v
retrieving revision 1.7
diff -u -r1.7 tooltip.cs
--- tooltip.cs 7 Dec 2002 03:15:13 -0000 1.7
+++ tooltip.cs 26 Mar 2003 17:26:46 -0000
@@ -4,119 +4,250 @@
// Author:
// stubbed out by Jackson Harper (jackson@latitudegeo.com)
// Dennis Hayes (dennish@raytek.com)
+// implemented by Aleksey Ryabchuk (ryabchuk@yahoo.com)
//
// (C) 2002 Ximian, Inc
//
using System.ComponentModel;
+using System.Runtime.InteropServices;
+using System.Collections;
+
namespace System.Windows.Forms {
// <summary>
- //
+ // Tooltip control
// </summary>
public sealed class ToolTip : Component, IExtenderProvider {
+ bool active = true;
+ int automaticDelay = 500;
+ int autoPopDelay = 5000;
+ int initialDelay = 500;
+ int reshowDelay = 100;
+ bool showAlways = false;
+ const int MAX_SHORT = 32767;
+
+ NativeWindow tooltipWnd = new NativeWindow ();
+ Hashtable tooltipTexts = new Hashtable();
- //
- // --- Public Constructors
- //
- [MonoTODO]
public ToolTip() {
-
+ createToolTipWindow ( );
}
- [MonoTODO]
public ToolTip(IContainer cont) {
-
+ createToolTipWindow ( );
+ cont.Add ( this );
}
- //
- // --- Public Properties
- //
- [MonoTODO]
+
public bool Active {
- get {
- throw new NotImplementedException ();
- }
+ get { return active; }
set {
- //FIXME:
+ if ( active != value ) {
+ active = value;
+ activateToolTip ( active );
+ }
}
}
- [MonoTODO]
public int AutomaticDelay {
- get {
- throw new NotImplementedException ();
- }
+ get { return automaticDelay; }
set {
- //FIXME:
+ if ( automaticDelay != value ) {
+ automaticDelay = value;
+ AutoPopDelay = 10*automaticDelay;
+ InitialDelay = automaticDelay;
+ ReshowDelay = automaticDelay / 5;
+ setToolTipDelay ( ToolTipControlDelayFlags.TTDT_AUTOMATIC, automaticDelay );
+ }
}
}
- [MonoTODO]
public int AutoPopDelay{
- get {
- throw new NotImplementedException ();
- }
+ get { return autoPopDelay; }
set {
- //FIXME:
+ autoPopDelay = value;
+ setToolTipDelay ( ToolTipControlDelayFlags.TTDT_AUTOPOP, autoPopDelay );
}
}
- [MonoTODO]
public int InitialDelay {
- get {
- throw new NotImplementedException ();
- }
+ get { return initialDelay; }
set {
- //FIXME:
+ initialDelay = value;
+ setToolTipDelay ( ToolTipControlDelayFlags.TTDT_INITIAL, initialDelay );
}
}
- [MonoTODO]
public int ReshowDelay {
- get {
- throw new NotImplementedException ();
- }
+ get { return reshowDelay; }
set {
- //FIXME:
+ reshowDelay = value;
+ setToolTipDelay ( ToolTipControlDelayFlags.TTDT_RESHOW, reshowDelay );
}
}
- [MonoTODO]
public bool ShowAlways {
- get {
- throw new NotImplementedException ();
- }
+ get { return showAlways ; }
set {
- //FIXME:
+ if ( showAlways != value ) {
+ bool OldStyle = showAlways;
+ showAlways = value;
+ if ( tooltipWnd.Handle != IntPtr.Zero )
+ Win32.UpdateWindowStyle ( tooltipWnd.Handle,
+ OldStyle ? (int)ToolTipControlStyles.TTS_ALWAYSTIP : 0,
+ value ? (int)ToolTipControlStyles.TTS_ALWAYSTIP : 0 );
+ }
}
}
- // --- Public Methods
-
- [MonoTODO]
public void RemoveAll() {
- //FIXME:
+ foreach (object o in tooltipTexts.Keys) {
+ Control target = o as Control;
+ if ( target != null ) {
+ removeToolTip ( target );
+ target.HandleCreated -= new System.EventHandler( control_HandleCreated );
+ target.HandleDestroyed -= new System.EventHandler ( control_HandleDestroyed );
+ }
+ }
+ tooltipTexts.Clear ( );
}
- [MonoTODO]
+
public void SetToolTip(Control control, string caption) {
- //FIXME:
+ if ( caption == null || caption.Length == 0 ) {
+ if ( tooltipTexts.Contains ( control ) ) {
+ removeToolTip ( control );
+ control.HandleCreated -= new System.EventHandler( control_HandleCreated );
+ control.HandleDestroyed -= new System.EventHandler ( control_HandleDestroyed );
+ tooltipTexts.Remove ( control );
+ return;
+ }
+ }
+ if ( !tooltipTexts.Contains ( control ) ) {
+ control.HandleCreated += new System.EventHandler( control_HandleCreated );
+ control.HandleDestroyed += new System.EventHandler ( control_HandleDestroyed );
+ if ( control.IsHandleCreated )
+ addTool ( control, caption );
+ }
+ else {
+ if ( control.IsHandleCreated )
+ updateTipText ( control, caption );
+ }
+ tooltipTexts[ control ] = caption;
+ }
+
+ public string GetToolTip( Control control ) {
+ string text = (string) tooltipTexts[control];
+ if ( text == null )
+ text = string.Empty;
+ return text;
}
- [MonoTODO]
+
public override string ToString() {
- //FIXME:
- return base.ToString();
+ return "[" + GetType().FullName.ToString() + "] InitialDelay: " + InitialDelay.ToString() +
+ ", ShowAlways: " + ShowAlways.ToString();
+ }
+
+ bool IExtenderProvider.CanExtend( object extendee ){
+ return ( extendee is Control ) && !( extendee is ToolTip );
+ }
+
+ private void createToolTipWindow ( ) {
+ if ( tooltipWnd.Handle == IntPtr.Zero ) {
+ initCommonControlsLibrary ( );
+
+ CreateParams pars = new CreateParams ( );
+
+ pars.ClassName = Win32.TOOLTIPS_CLASS;
+ pars.ExStyle = (int) WindowExStyles.WS_EX_TOPMOST;
+ pars.Style = (int) ToolTipControlStyles.TTS_NOPREFIX;
+
+ if ( ShowAlways )
+ pars.Style |= (int)ToolTipControlStyles.TTS_ALWAYSTIP;
+
+ tooltipWnd.CreateHandle ( pars );
+
+ Win32.SetWindowPos ( tooltipWnd.Handle,
+ SetWindowPosZOrder.HWND_TOPMOST,
+ 0, 0, 0, 0,
+ SetWindowPosFlags.SWP_NOMOVE |
+ SetWindowPosFlags.SWP_NOSIZE |
+ SetWindowPosFlags.SWP_NOACTIVATE );
+
+ Win32.SendMessage ( tooltipWnd.Handle,
+ (int)ToolTipControlMessages.TTM_SETMAXTIPWIDTH,
+ 0, MAX_SHORT );
+
+ activateToolTip ( Active );
+ }
+ }
+
+ private void initCommonControlsLibrary ( ) {
+ INITCOMMONCONTROLSEX initEx = new INITCOMMONCONTROLSEX();
+ initEx.dwICC = CommonControlInitFlags.ICC_BAR_CLASSES;
+ Win32.InitCommonControlsEx(initEx);
+ }
+
+ private void control_HandleCreated(object sender, System.EventArgs e) {
+ Control ctrl = sender as Control;
+ if ( ctrl != null && tooltipTexts.Contains ( ctrl ) )
+ addTool ( ctrl, GetToolTip ( ctrl ) );
+ }
+
+ private void control_HandleDestroyed(object sender, System.EventArgs e) {
+ Control ctrl = sender as Control;
+ if ( ctrl != null && tooltipTexts.Contains ( ctrl ) )
+ removeToolTip ( ctrl );
+ }
+
+ private void addTool ( Control target, string tiptext ) {
+ TOOLINFO ti = new TOOLINFO( );
+ ti.cbSize = (uint)Marshal.SizeOf( ti );
+ ti.hwnd = target.Handle;
+ ti.uId = (uint)target.Handle.ToInt32();
+ ti.lpszText = tiptext;
+ ti.uFlags = (int)(ToolTipFlags.TTF_SUBCLASS | ToolTipFlags.TTF_IDISHWND);
+ sendMessageHelper ( ToolTipControlMessages.TTM_ADDTOOL, ref ti);
+ }
+
+ private void updateTipText ( Control target, string tiptext ) {
+ TOOLINFO ti = new TOOLINFO( );
+ ti.cbSize = (uint)Marshal.SizeOf( ti );
+ ti.hwnd = target.Handle;
+ ti.uId = (uint)target.Handle.ToInt32();
+ ti.lpszText = tiptext;
+ sendMessageHelper ( ToolTipControlMessages.TTM_UPDATETIPTEXT, ref ti );
+ }
+
+ private void activateToolTip ( bool avtivate ) {
+ if ( tooltipWnd.Handle != IntPtr.Zero )
+ Win32.SendMessage ( tooltipWnd.Handle,
+ (int)ToolTipControlMessages.TTM_ACTIVATE, avtivate ? 1 : 0, 0 );
}
- //
- // --- Protected Methods
- //
-
- [MonoTODO]
- ~ToolTip() {
-
+
+ private void removeToolTip ( Control target ) {
+ if ( target.IsHandleCreated ) {
+ TOOLINFO ti = new TOOLINFO( );
+ ti.cbSize = (uint)Marshal.SizeOf( ti );
+ ti.hwnd = target.Handle;
+ ti.uId = (uint)target.Handle.ToInt32();
+ sendMessageHelper ( ToolTipControlMessages.TTM_DELTOOL, ref ti );
+ }
}
- bool IExtenderProvider.CanExtend(object extendee){
- throw new NotImplementedException ();
+
+ private void setToolTipDelay ( ToolTipControlDelayFlags flag, int DelayTime ) {
+ if ( tooltipWnd.Handle != IntPtr.Zero )
+ Win32.SendMessage ( tooltipWnd.Handle,
+ (int)ToolTipControlMessages.TTM_SETDELAYTIME,
+ (int)flag, Win32.MAKELONG( DelayTime, 0) );
}
+ private void sendMessageHelper ( ToolTipControlMessages mes, ref TOOLINFO ti ) {
+ if ( tooltipWnd.Handle != IntPtr.Zero ) {
+ IntPtr ptr = Marshal.AllocCoTaskMem ( Marshal.SizeOf ( ti ) );
+ Marshal.StructureToPtr( ti, ptr, false );
+ Win32.SendMessage ( tooltipWnd.Handle , (int)mes, 0, ptr.ToInt32() );
+ Marshal.FreeCoTaskMem( ptr );
+ }
+ }
}
}
Index: win32Enums.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/win32Enums.cs,v
retrieving revision 1.11
diff -u -r1.11 win32Enums.cs
--- win32Enums.cs 24 Mar 2003 23:28:11 -0000 1.11
+++ win32Enums.cs 26 Mar 2003 17:26:47 -0000
@@ -753,6 +753,7 @@
#region ToolTip Flags
public enum ToolTipFlags {
+ TTF_IDISHWND = 0x0001,
TTF_CENTERTIP = 0x0002,
TTF_RTLREADING = 0x0004,
TTF_SUBCLASS = 0x0010,
@@ -2485,6 +2486,36 @@
}
#endregion
+ #region ToolTipControl Messages
+ internal enum ToolTipControlMessages
+ {
+ TTM_ACTIVATE = (Msg.WM_USER + 1),
+ TTM_SETDELAYTIME = (Msg.WM_USER + 3),
+ TTM_SETMAXTIPWIDTH = (Msg.WM_USER + 24),
+ TTM_ADDTOOL = (Msg.WM_USER + 50),
+ TTM_DELTOOL = (Msg.WM_USER + 51),
+ TTM_UPDATETIPTEXT = (Msg.WM_USER +57)
+
+ }
+ #endregion
+
+ #region ToolTipControl Styles
+ internal enum ToolTipControlStyles
+ {
+ TTS_ALWAYSTIP = 0x01,
+ TTS_NOPREFIX = 0x02
+ }
+ #endregion
+
+ #region ToolTipControlDelay Flags
+ internal enum ToolTipControlDelayFlags {
+ TTDT_AUTOMATIC = 0,
+ TTDT_RESHOW = 1,
+ TTDT_AUTOPOP = 2,
+ TTDT_INITIAL = 3
+ }
+ #endregion
+
#region MonthCal Colors
internal enum MonthCalColors
{
Index: win32Structs.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/win32Structs.cs,v
retrieving revision 1.7
diff -u -r1.7 win32Structs.cs
--- win32Structs.cs 23 Mar 2003 20:46:53 -0000 1.7
+++ win32Structs.cs 26 Mar 2003 17:26:47 -0000
@@ -746,6 +746,17 @@
public IntPtr itemData;
}
+ [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
+ internal struct TOOLINFO {
+ internal uint cbSize;
+ internal uint uFlags;
+ internal IntPtr hwnd;
+ internal uint uId;
+ internal RECT rect;
+ internal IntPtr hinst;
+ internal string lpszText;
+ internal IntPtr lParam;
+ }
//
//
Index: win32functions.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/win32functions.cs,v
retrieving revision 1.15
diff -u -r1.15 win32functions.cs
--- win32functions.cs 20 Mar 2003 23:05:15 -0000 1.15
+++ win32functions.cs 26 Mar 2003 17:26:47 -0000
@@ -51,6 +51,8 @@
internal const string REBARCLASSNAME = "ReBarWindow32";
internal const string PROGRESSBARCLASSNAME = "msctls_progress32";
internal const string SCROLLBAR = "SCROLLBAR";
+ internal const string TOOLTIPS_CLASS = "tooltips_class32";
+
#endregion
#region CallBacks
@@ -689,6 +691,11 @@
{
return 0x0000FFFF & res;
}
+
+ internal static int MAKELONG(int lo, int hi)
+ {
+ return (hi << 16) | (lo & 0x0000ffff);
+ }
#endregion
#region Mono win32 Fuinctions
--0-292435941-1048699859=:86755--