Files
mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/HelpProvider.cs
T
Peter Dennis Bartok 915b0c9619 2005-09-21 Peter Dennis Bartok <[email protected]>
* OpenFileDialog.cs, ContentsResizedEventArgs.cs, LibSupport.cs, GridItem.cs,
	  CursorConverter.cs, SplitterEventHandler.cs, PropertyGridTextBox.cs,
	  GridTablesFactory.cs, MethodInvoker.cs, AccessibleEvents.cs,
	  SplitterEventArgs.cs, XplatUI.cs, Mime.cs, PropertySort.cs,
	  TreeViewCancelEventHandler.cs, Form.cs, PropertyGridCommands.cs,
	  IDataGridEditingService.cs, DateBoldEventHandler.cs, Label.cs,
	  KeyboardLayouts.cs, TextControl.cs, ProgressBar.cs, ToolTip.cs,
	  RadioButton.cs, OSFeature.cs, LinkLabel.cs, ColorDialog.cs,
	  ThemeNice.cs, ErrorIconAlignment.cs, TreeNode.cs, MimeGenerated.cs,
	  ComboBox.cs, DataGridTextBoxColumn.cs, ArrangeStartingPosition.cs,
	  GridColumnStylesCollection.cs, 
	  IDataGridColumnStyleEditingNotificationService.cs,
	  PropertyGrid.cs, IFeatureSupport.cs, ICommandExecutor.cs,
	  MdiLayout.cs, GridEntry.cs, ControlBindingsCollection.cs,
	  GridTableStylesCollection.cs, TreeViewCancelEventArgs.cs, 
	  TreeNodeCollection.cs, AmbientProperties.cs, 
	  RichTextBoxSelectionAttribute.cs, RichTextBoxSelectionTypes.cs,
	  DataObject.cs, ErrorProvider.cs, Splitter.cs,
	  DataGridLineStyle.cs, Shortcut.cs, Control.cs,
	  FontDialog.cs, SecurityIDType.cs, GridItemType.cs,
	  BindingMemberInfo.cs, DataGridCell.cs, MdiChildContext.cs,
	  IRootGridEntry.cs, PropertyGridView.cs, DataGridParentRowsLabelStyle.cs,
	  FolderBrowserDialog.cs, OpacityConverter.cs, HelpProvider.cs,
	  IComponentEditorPageSite.cs, DataGridTableStyle.cs, NavigateEventArgs.cs,
	  NotifyIcon.cs, ContentsResizedEventHandler.cs, MenuItem.cs,
	  PropertyTabChangedEventHandler.cs, TextBoxBase.cs, OpenTreeNodeEnumerator.cs,
	  SelectionMode.cs, TextBox.cs, ListBindingConverter.cs,
	  FileDialog.cs, KeysConverter.cs, DomainUpDown.cs,
	  DataFormats.cs, SaveFileDialog.cs, GridItemCollection.cs,
	  ArrangeDirection.cs, FeatureSupport.cs, SelectionRangeConverter.cs,
	  RichTextBoxScrollBars.cs, NodeLabelEditEventHandler.cs, TreeNodeConverter.cs,
	  MimeIcon.cs, X11Structs.cs, PropertyGridEntry.cs,
	  ImageList.cs, ThemeWin32Classic.cs, X11Keyboard.cs,
	  CheckedListBox.cs, HelpNavigator.cs, DateTimePickerFormat.cs,
	  MdiClient.cs, DataGridDrawingLogic.cs, DataGridBoolColumn.cs,
	  NodeLabelEditEventArgs.cs, Screen.cs, PropertyManager.cs,
	  ComponentModel.cs, PropertiesTab.cs, CurrencyManager.cs,
	  SizeGrip.cs, DateBoldEventArgs.cs, X11Dnd.cs, Panel.cs,
	  Hwnd.cs, OSXStructs.cs, DrawMode.cs, XplatUIDriver.cs,
	  RichTextBox.cs, PropertyTabChangedEventArgs.cs, CommonDialog.cs,
	  DataGrid.cs, XplatUIX11.cs, RichTextBoxStreamType.cs, Win32DnD.cs,
	  ErrorBlinkStyle.cs, TreeViewEventHandler.cs,
	  PropertyValueChangedEventHandler.cs, IFileReaderService.cs,
	  DataGridTextBox.cs, SelectedGridItemChangedEventArgs.cs, ScrollBar.cs,
	  ListBox.cs, TreeViewAction.cs, Help.cs, TrackBar.cs,
	  AxHost.cs, PropertyValueChangedEventArgs.cs, XplatUIOSX.cs,
	  RichTextBoxFinds.cs, UpDownEventArgs.cs, Cursors.cs,
	  CategoryGridEntry.cs, RichTextBoxWordPunctuations.cs, DataGridColumnStyle.cs,
	  SelectedGridItemChangedEventHandler.cs, DateTimePicker.cs, NavigateEventHandler.cs,
	  Clipboard.cs, UpDownEventHandler.cs, MonthCalendar.cs,
	  SendKeys.cs, DataGridPreferredColumnWidthTypeConverter.cs, TreeView.cs,
	  ThreadExceptionDialog.cs, ImageListConverter.cs, XplatUIWin32.cs,
	  TreeViewEventArgs.cs: Fixed whitespace and set eol-style:native attribute


svn path=/trunk/mcs/; revision=50399
2005-09-21 18:35:43 +00:00

280 lines
7.5 KiB
C#

// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Peter Bartok ([email protected])
//
//
// NOT COMPLETE
// Still missing: Tie-in to HTML help when the user presses F1 on the control
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
namespace System.Windows.Forms {
[ToolboxItemFilter("System.Windows.Forms")]
[ProvideProperty("ShowHelp", "System.Windows.Forms.Control, " + Consts.AssemblySystem_Windows_Forms)]
[ProvideProperty("HelpNavigator", "System.Windows.Forms.Control, " + Consts.AssemblySystem_Windows_Forms)]
[ProvideProperty("HelpKeyword", "System.Windows.Forms.Control, " + Consts.AssemblySystem_Windows_Forms)]
[ProvideProperty("HelpString", "System.Windows.Forms.Control, " + Consts.AssemblySystem_Windows_Forms)]
public class HelpProvider : Component, IExtenderProvider {
#region HelpProperty Class
private class HelpProperty {
internal string keyword;
internal HelpNavigator navigator;
internal string text;
internal bool show;
internal Control control;
internal HelpProvider hp;
public HelpProperty(HelpProvider hp, Control control) {
this.control = control;
this.hp = hp;
keyword = null;
navigator = HelpNavigator.AssociateIndex;
text = null;
show = false;
control.HelpRequested += hp.HelpRequestHandler;
}
public string Keyword {
get { return keyword; }
set { keyword = value; }
}
public HelpNavigator Navigator {
get { return navigator; }
set { navigator = value; }
}
public string Text {
get { return text; }
set { text = value; }
}
public bool Show {
get { return show; }
set { show = value; }
}
}
#endregion // HelpProperty Class
#region Local Variables
private string helpnamespace;
private Hashtable controls;
private ToolTip.ToolTipWindow tooltip;
private EventHandler HideToolTipHandler;
private KeyPressEventHandler HideToolTipKeyHandler;
private MouseEventHandler HideToolTipMouseHandler;
private HelpEventHandler HelpRequestHandler;
#endregion // Local Variables
#region Public Constructors
public HelpProvider() {
controls = new Hashtable();
tooltip = new ToolTip.ToolTipWindow(null);
HideToolTipHandler = new EventHandler(HideToolTip);
HideToolTipKeyHandler = new KeyPressEventHandler(HideToolTipKey);
HideToolTipMouseHandler = new MouseEventHandler(HideToolTipMouse);
HelpRequestHandler = new HelpEventHandler(HelpRequested);
}
#endregion // Public Constructors
#region Public Instance Properties
[DefaultValue(null)]
[Editor ("System.Windows.Forms.Design.HelpNamespaceEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
[Localizable(true)]
public string HelpNamespace {
get {
return helpnamespace;
}
set {
helpnamespace = value;
}
}
#endregion // Public Instance Properties
#region Public Instance Methods
public bool CanExtend(object extendee) {
if (!(extendee is Control)) {
return false;
}
if ((extendee is Form) || (extendee is ToolBar)) {
return false;
}
return true;
}
[DefaultValue(null)]
[Localizable(true)]
public virtual string GetHelpKeyword(Control ctl) {
return GetHelpProperty(ctl).Keyword;
}
[DefaultValue(HelpNavigator.AssociateIndex)]
[Localizable(true)]
public virtual HelpNavigator GetHelpNavigator(Control ctl) {
return GetHelpProperty(ctl).Navigator;
}
[DefaultValue(null)]
[Localizable(true)]
public virtual string GetHelpString(Control ctl) {
return GetHelpProperty(ctl).Text;
}
[Localizable(true)]
public virtual bool GetShowHelp(Control ctl) {
return GetHelpProperty(ctl).Show;
}
public virtual void ResetShowHelp(Control ctl) {
HelpProperty hp;
hp = GetHelpProperty(ctl);
if ((hp.Keyword != null) || (hp.Text != null)) {
hp.Show = true;
} else {
hp.Show = false;
}
}
public virtual void SetHelpKeyword(Control ctl, string keyword) {
GetHelpProperty(ctl).Keyword = keyword;
}
public virtual void SetHelpNavigator(Control ctl, HelpNavigator navigator) {
GetHelpProperty(ctl).Navigator = navigator;
}
public virtual void SetHelpString(Control ctl, string helpString) {
GetHelpProperty(ctl).Text = helpString;
}
public virtual void SetShowHelp(Control ctl, bool value) {
GetHelpProperty(ctl).Show = value;
}
public override string ToString() {
return base.ToString() + ", HelpNameSpace: " + helpnamespace;
}
#endregion // Public Instance Methods
#region Private Methods
private HelpProperty GetHelpProperty(Control control) {
HelpProperty hp;
hp = (HelpProperty)controls[control];
if (hp == null) {
hp = new HelpProperty(this, control);
controls[control] = hp;
}
return hp;
}
private void HideToolTip(object Sender, EventArgs e) {
Control control;
control = (Control)Sender;
control.LostFocus -= HideToolTipHandler;
this.tooltip.Visible = false;
}
private void HideToolTipKey(object Sender, KeyPressEventArgs e) {
Control control;
control = (Control)Sender;
control.KeyPress -= HideToolTipKeyHandler;
this.tooltip.Visible = false;
}
private void HideToolTipMouse(object Sender, MouseEventArgs e) {
Control control;
control = (Control)Sender;
control.MouseDown -= HideToolTipMouseHandler;
this.tooltip.Visible = false;
}
// This is called when the user does a "what's this" style lookup. It uses the 'text' property
private void HelpRequested(object sender, HelpEventArgs e) {
Size size;
Point pt;
Control control;
control = (Control)sender;
if (GetHelpProperty(control).Text == null) {
return;
}
pt = e.MousePos;
// Display Tip
tooltip.Text = GetHelpProperty(control).Text;
size = ThemeEngine.Current.ToolTipSize(tooltip, tooltip.Text);
tooltip.Width = size.Width;
tooltip.Height = size.Height;
pt.X -= size.Width / 2;
if (pt.X < 0) {
pt.X += size.Width / 2;
}
if ((pt.X + size.Width) < SystemInformation.WorkingArea.Width) {
tooltip.Left = pt.X;
} else {
tooltip.Left = pt.X - size.Width;
}
if ((pt.Y + size.Height) < (SystemInformation.WorkingArea.Height - 16)) {
tooltip.Top = pt.Y;
} else {
tooltip.Top = pt.Y - size.Height;
}
tooltip.Visible = true;
control.KeyPress += HideToolTipKeyHandler;
control.MouseDown += HideToolTipMouseHandler;
control.LostFocus += HideToolTipHandler;
e.Handled = true;
}
#endregion // Private Methods
}
}