Browse Source

SD2-611 - Auto-Complete tooltip does not word wrap when displayed on the left

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3515 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
72bc6eddad
  1. 22
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs
  2. 26
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/DeclarationViewWindow.cs
  3. 102
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/TipPainter.cs
  4. 179
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/TipPainterTools.cs

22
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs

@ -133,12 +133,24 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -133,12 +133,24 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
Point pos;
// The declaration view window has better line break when used on
// the right side, so prefer the right side to the left.
if (rightSpace * 2 > leftSpace)
if (rightSpace * 2 > leftSpace) {
declarationViewWindow.FixedWidth = false;
pos = new Point(Bounds.Right, Bounds.Top);
else
pos = new Point(Bounds.Left - declarationViewWindow.Width, Bounds.Top);
if (declarationViewWindow.Location != pos) {
declarationViewWindow.Location = pos;
if (declarationViewWindow.Location != pos) {
declarationViewWindow.Location = pos;
}
} else {
declarationViewWindow.Width = declarationViewWindow.GetRequiredLeftHandSideWidth(new Point(Bounds.Left, Bounds.Top));
declarationViewWindow.FixedWidth = true;
if (Bounds.Left < declarationViewWindow.Width) {
pos = new Point(0, Bounds.Top);
} else {
pos = new Point(Bounds.Left - declarationViewWindow.Width, Bounds.Top);
}
if (declarationViewWindow.Location != pos) {
declarationViewWindow.Location = pos;
}
declarationViewWindow.Refresh();
}
}

26
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/DeclarationViewWindow.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -26,6 +26,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
public class DeclarationViewWindow : Form, IDeclarationViewWindow
{
string description = String.Empty;
bool fixedWidth;
public string Description {
get {
@ -42,6 +43,25 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -42,6 +43,25 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
}
}
public bool FixedWidth {
get {
return fixedWidth;
}
set {
fixedWidth = value;
}
}
public int GetRequiredLeftHandSideWidth(Point p) {
if (description != null && description.Length > 0) {
using (Graphics g = CreateGraphics()) {
Size s = TipPainterTools.GetLeftHandSideDrawingSizeHelpTipFromCombinedDescription(this, g, Font, null, description, p);
return s.Width;
}
}
return 0;
}
public bool HideOnClick;
public DeclarationViewWindow(Form parent)
@ -89,7 +109,11 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -89,7 +109,11 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
protected override void OnPaint(PaintEventArgs pe)
{
if (description != null && description.Length > 0) {
TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, null, description);
if (fixedWidth) {
TipPainterTools.DrawFixedWidthHelpTipFromCombinedDescription(this, pe.Graphics, Font, null, description);
} else {
TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, null, description);
}
}
}

102
src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/TipPainter.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.TextEditor.Util @@ -45,7 +45,7 @@ namespace ICSharpCode.TextEditor.Util
if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
graphics.TextRenderingHint =
TextRenderingHint.AntiAliasGridFit;
TextRenderingHint.AntiAliasGridFit;
tipData.SetMaximumSize(maxLayoutSize);
tipSizeF = tipData.GetRequiredSize();
@ -63,6 +63,41 @@ namespace ICSharpCode.TextEditor.Util @@ -63,6 +63,41 @@ namespace ICSharpCode.TextEditor.Util
return tipSize;
}
public static Size GetLeftHandSideTipSize(Control control, Graphics graphics, TipSection tipData, Point p)
{
Size tipSize = Size.Empty;
SizeF tipSizeF = SizeF.Empty;
if (workingArea == RectangleF.Empty) {
Form ownerForm = control.FindForm();
if (ownerForm.Owner != null) {
ownerForm = ownerForm.Owner;
}
workingArea = Screen.GetWorkingArea(ownerForm);
}
PointF screenLocation = p;
SizeF maxLayoutSize = new SizeF(screenLocation.X - HorizontalBorder * 2,
workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);
if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
graphics.TextRenderingHint =
TextRenderingHint.AntiAliasGridFit;
tipData.SetMaximumSize(maxLayoutSize);
tipSizeF = tipData.GetRequiredSize();
tipData.SetAllocatedSize(tipSizeF);
tipSizeF += new SizeF(HorizontalBorder * 2,
VerticalBorder * 2);
tipSize = Size.Ceiling(tipSizeF);
}
return tipSize;
}
public static Size DrawTip(Control control, Graphics graphics, Font font, string description)
{
return DrawTip(control, graphics, new TipText (graphics, font, description));
@ -83,13 +118,13 @@ namespace ICSharpCode.TextEditor.Util @@ -83,13 +118,13 @@ namespace ICSharpCode.TextEditor.Util
workingArea = Screen.GetWorkingArea(ownerForm);
}
SizeF maxLayoutSize = new SizeF(workingArea.Right - screenLocation.X - HorizontalBorder * 2,
workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);
if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
graphics.TextRenderingHint =
TextRenderingHint.AntiAliasGridFit;
TextRenderingHint.AntiAliasGridFit;
tipData.SetMaximumSize(maxLayoutSize);
tipSizeF = tipData.GetRequiredSize();
@ -106,12 +141,65 @@ namespace ICSharpCode.TextEditor.Util @@ -106,12 +141,65 @@ namespace ICSharpCode.TextEditor.Util
if (tipSize != Size.Empty) {
Rectangle borderRectangle = new Rectangle
(Point.Empty, tipSize - new Size(1, 1));
(Point.Empty, tipSize - new Size(1, 1));
RectangleF displayRectangle = new RectangleF
(HorizontalBorder, VerticalBorder,
tipSizeF.Width - HorizontalBorder * 2,
tipSizeF.Height - VerticalBorder * 2);
// DrawRectangle draws from Left to Left + Width. A bug? :-/
graphics.DrawRectangle(SystemPens.WindowFrame,
borderRectangle);
tipData.Draw(new PointF(HorizontalBorder, VerticalBorder));
}
return tipSize;
}
public static Size DrawFixedWidthTip(Control control, Graphics graphics, TipSection tipData)
{
Size tipSize = Size.Empty;
SizeF tipSizeF = SizeF.Empty;
PointF screenLocation = control.PointToScreen(new Point(control.Width, 0));
if (workingArea == RectangleF.Empty) {
Form ownerForm = control.FindForm();
if (ownerForm.Owner != null) {
ownerForm = ownerForm.Owner;
}
workingArea = Screen.GetWorkingArea(ownerForm);
}
SizeF maxLayoutSize = new SizeF(screenLocation.X - HorizontalBorder * 2,
workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);
if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
graphics.TextRenderingHint =
TextRenderingHint.AntiAliasGridFit;
tipData.SetMaximumSize(maxLayoutSize);
tipSizeF = tipData.GetRequiredSize();
tipData.SetAllocatedSize(tipSizeF);
tipSizeF += new SizeF(HorizontalBorder * 2,
VerticalBorder * 2);
tipSize = Size.Ceiling(tipSizeF);
}
if (control.Height != tipSize.Height) {
control.Height = tipSize.Height;
}
if (tipSize != Size.Empty) {
Rectangle borderRectangle = new Rectangle
(Point.Empty, control.Size - new Size(1, 1));
RectangleF displayRectangle = new RectangleF
(HorizontalBorder, VerticalBorder,
tipSizeF.Width - HorizontalBorder * 2,
tipSizeF.Height - VerticalBorder * 2);
(HorizontalBorder, VerticalBorder,
tipSizeF.Width - HorizontalBorder * 2,
tipSizeF.Height - VerticalBorder * 2);
// DrawRectangle draws from Left to Left + Width. A bug? :-/
graphics.DrawRectangle(SystemPens.WindowFrame,

179
src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/TipPainterTools.cs

@ -11,26 +11,47 @@ using System.Windows.Forms; @@ -11,26 +11,47 @@ using System.Windows.Forms;
namespace ICSharpCode.TextEditor.Util
{
class TipPainterTools
static class TipPainterTools
{
const int SpacerSize = 4;
private TipPainterTools()
public static Size GetLeftHandSideDrawingSizeHelpTipFromCombinedDescription(Control control,
Graphics graphics,
Font font,
string countMessage,
string description,
Point p)
{
string basicDescription = null;
string documentation = null;
if (IsVisibleText(description)) {
string[] splitDescription = description.Split(new char[] { '\n' }, 2);
if (splitDescription.Length > 0) {
basicDescription = splitDescription[0];
if (splitDescription.Length > 1) {
documentation = splitDescription[1].Trim();
}
}
}
return GetLeftHandSideDrawingSizeDrawHelpTip(control, graphics, font, countMessage, basicDescription, documentation, p);
}
public static Size GetDrawingSizeHelpTipFromCombinedDescription(Control control,
Graphics graphics,
Font font,
string countMessage,
string description)
Graphics graphics,
Font font,
string countMessage,
string description)
{
string basicDescription = null;
string documentation = null;
if (IsVisibleText(description)) {
string[] splitDescription = description.Split(new char[] { '\n' }, 2);
string[] splitDescription = description.Split(new char[] { '\n' }, 2);
if (splitDescription.Length > 0) {
basicDescription = splitDescription[0];
@ -53,9 +74,9 @@ namespace ICSharpCode.TextEditor.Util @@ -53,9 +74,9 @@ namespace ICSharpCode.TextEditor.Util
string documentation = null;
if (IsVisibleText(description)) {
string[] splitDescription = description.Split
(new char[] { '\n' }, 2);
string[] splitDescription = description.Split
(new char[] { '\n' }, 2);
if (splitDescription.Length > 0) {
basicDescription = splitDescription[0];
@ -66,18 +87,44 @@ namespace ICSharpCode.TextEditor.Util @@ -66,18 +87,44 @@ namespace ICSharpCode.TextEditor.Util
}
return DrawHelpTip(control, graphics, font, countMessage,
basicDescription, documentation);
}
basicDescription, documentation);
}
public static Size DrawFixedWidthHelpTipFromCombinedDescription(Control control,
Graphics graphics,
Font font,
string countMessage,
string description)
{
string basicDescription = null;
string documentation = null;
if (IsVisibleText(description)) {
string[] splitDescription = description.Split
(new char[] { '\n' }, 2);
if (splitDescription.Length > 0) {
basicDescription = splitDescription[0];
if (splitDescription.Length > 1) {
documentation = splitDescription[1].Trim();
}
}
}
return DrawFixedWidthHelpTip(control, graphics, font, countMessage,
basicDescription, documentation);
}
// btw. I know it's ugly.
public static Rectangle DrawingRectangle1;
public static Rectangle DrawingRectangle2;
public static Size GetDrawingSizeDrawHelpTip(Control control,
Graphics graphics, Font font,
string countMessage,
string basicDescription,
string documentation)
Graphics graphics, Font font,
string countMessage,
string basicDescription,
string documentation)
{
if (IsVisibleText(countMessage) ||
IsVisibleText(basicDescription) ||
@ -97,7 +144,7 @@ namespace ICSharpCode.TextEditor.Util @@ -97,7 +144,7 @@ namespace ICSharpCode.TextEditor.Util
TipSplitter descSplitter = new TipSplitter(graphics, false,
descriptionTip,
docSpacer
);
);
TipSplitter mainSplitter = new TipSplitter(graphics, true,
countMessageTip,
@ -105,8 +152,8 @@ namespace ICSharpCode.TextEditor.Util @@ -105,8 +152,8 @@ namespace ICSharpCode.TextEditor.Util
descSplitter);
TipSplitter mainSplitter2 = new TipSplitter(graphics, false,
mainSplitter,
docTip);
mainSplitter,
docTip);
// Show it.
Size size = TipPainter.GetTipSize(control, graphics, mainSplitter2);
@ -116,6 +163,48 @@ namespace ICSharpCode.TextEditor.Util @@ -116,6 +163,48 @@ namespace ICSharpCode.TextEditor.Util
}
return Size.Empty;
}
public static Size GetLeftHandSideDrawingSizeDrawHelpTip(Control control,
Graphics graphics, Font font,
string countMessage,
string basicDescription,
string documentation,
Point p)
{
if (IsVisibleText(countMessage) ||
IsVisibleText(basicDescription) ||
IsVisibleText(documentation)) {
// Create all the TipSection objects.
CountTipText countMessageTip = new CountTipText(graphics, font, countMessage);
TipSpacer countSpacer = new TipSpacer(graphics, new SizeF(IsVisibleText(countMessage) ? 4 : 0, 0));
TipText descriptionTip = new TipText(graphics, font, basicDescription);
TipSpacer docSpacer = new TipSpacer(graphics, new SizeF(0, IsVisibleText(documentation) ? 4 : 0));
TipText docTip = new TipText(graphics, font, documentation);
// Now put them together.
TipSplitter descSplitter = new TipSplitter(graphics, false,
descriptionTip,
docSpacer
);
TipSplitter mainSplitter = new TipSplitter(graphics, true,
countMessageTip,
countSpacer,
descSplitter);
TipSplitter mainSplitter2 = new TipSplitter(graphics, false,
mainSplitter,
docTip);
// Show it.
Size size = TipPainter.GetLeftHandSideTipSize(control, graphics, mainSplitter2, p);
return size;
}
return Size.Empty;
}
public static Size DrawHelpTip(Control control,
Graphics graphics, Font font,
string countMessage,
@ -140,7 +229,7 @@ namespace ICSharpCode.TextEditor.Util @@ -140,7 +229,7 @@ namespace ICSharpCode.TextEditor.Util
TipSplitter descSplitter = new TipSplitter(graphics, false,
descriptionTip,
docSpacer
);
);
TipSplitter mainSplitter = new TipSplitter(graphics, true,
countMessageTip,
@ -148,8 +237,8 @@ namespace ICSharpCode.TextEditor.Util @@ -148,8 +237,8 @@ namespace ICSharpCode.TextEditor.Util
descSplitter);
TipSplitter mainSplitter2 = new TipSplitter(graphics, false,
mainSplitter,
docTip);
mainSplitter,
docTip);
// Show it.
Size size = TipPainter.DrawTip(control, graphics, mainSplitter2);
@ -160,6 +249,50 @@ namespace ICSharpCode.TextEditor.Util @@ -160,6 +249,50 @@ namespace ICSharpCode.TextEditor.Util
return Size.Empty;
}
public static Size DrawFixedWidthHelpTip(Control control,
Graphics graphics, Font font,
string countMessage,
string basicDescription,
string documentation)
{
if (IsVisibleText(countMessage) ||
IsVisibleText(basicDescription) ||
IsVisibleText(documentation)) {
// Create all the TipSection objects.
CountTipText countMessageTip = new CountTipText(graphics, font, countMessage);
TipSpacer countSpacer = new TipSpacer(graphics, new SizeF(IsVisibleText(countMessage) ? 4 : 0, 0));
TipText descriptionTip = new TipText(graphics, font, basicDescription);
TipSpacer docSpacer = new TipSpacer(graphics, new SizeF(0, IsVisibleText(documentation) ? 4 : 0));
TipText docTip = new TipText(graphics, font, documentation);
// Now put them together.
TipSplitter descSplitter = new TipSplitter(graphics, false,
descriptionTip,
docSpacer
);
TipSplitter mainSplitter = new TipSplitter(graphics, true,
countMessageTip,
countSpacer,
descSplitter);
TipSplitter mainSplitter2 = new TipSplitter(graphics, false,
mainSplitter,
docTip);
// Show it.
Size size = TipPainter.DrawFixedWidthTip(control, graphics, mainSplitter2);
DrawingRectangle1 = countMessageTip.DrawingRectangle1;
DrawingRectangle2 = countMessageTip.DrawingRectangle2;
return size;
}
return Size.Empty;
}
static bool IsVisibleText(string text)
{
return text != null && text.Length > 0;

Loading…
Cancel
Save