diff options
-rw-r--r-- | doc/ScintillaDoc.html | 61 | ||||
-rw-r--r-- | include/Scintilla.h | 2 | ||||
-rw-r--r-- | include/Scintilla.iface | 8 | ||||
-rw-r--r-- | src/CallTip.cxx | 92 | ||||
-rw-r--r-- | src/CallTip.h | 26 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 20 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 4 |
7 files changed, 164 insertions, 49 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index bc630f795..42314186a 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -38,7 +38,7 @@ <h1>Scintilla Documentation</h1> - <p>Last edited 2/November/2005 NH</p> + <p>Last edited 4/February/2006 NH</p> <p>There is <a class="jump" href="Design.html">an overview of the internal design of Scintilla</a>.<br /> @@ -1915,14 +1915,25 @@ struct TextToFind { </tr> <tr> + <th align="left"><code>STYLE_CALLTIP</code></th> + + <td>38</td> + + <td> Call tips normally use the font attributes defined by <code>STYLE_DEFAULT</code>. + Use of <a class="message" href="#SCI_CALLTIPUSESTYLE"><code>SCI_CALLTIPUSESTYLE</code></a> + causes call tips to use this style instead. Only the font face name, font size, + foreground and background colours and character set attributes are used.</td> + </tr> + + <tr> <th align="left"><code>STYLE_LASTPREDEFINED</code></th> <td>39</td> <td>To make it easier for client code to discover the range of styles that are predefined, this is set to the style number of the last predefined style. This is - currently set to 39 and the last style with an identifier is 37, which reserves space for - future predefined styles.</td> + currently set to 39 and the last style with an identifier is 38, which reserves space + for one future predefined style.</td> </tr> <tr> @@ -3159,9 +3170,16 @@ struct TextToFind { <h2 id="CallTips">Call tips</h2> <p>Call tips are small windows displaying the arguments to a function and are displayed after - the user has typed the name of the function. There is some interaction between call tips and - autocompletion lists in that showing a call tip cancels any active autocompletion list, and - vice versa.</p> + the user has typed the name of the function. They normally display characters using the font + facename, size and character set defined by + <code><a class="message" href="#StyleDefinition">STYLE_DEFAULT</a></code>. You can choose to + use <code><a class="message" href="#StyleDefinition">STYLE_CALLTIP</a></code> to define the + facename, size, foreground and background colours and character set with + <code><a class="message" href="#SCI_CALLTIPUSESTYLE">SCI_CALLTIPUSESTYLE</a></code>. + This also enables support for Tab characters. + + There is some interaction between call tips and autocompletion lists in that showing a + call tip cancels any active autocompletion list, and vice versa.</p> <p>Call tips can highlight part of the text within them. You could use this to highlight the current argument to a function by counting the number of commas (or whatever separator your @@ -3192,17 +3210,22 @@ struct TextToFind { <a class="message" href="#SCI_CALLTIPSETBACK">SCI_CALLTIPSETBACK(int colour)</a><br /> <a class="message" href="#SCI_CALLTIPSETFORE">SCI_CALLTIPSETFORE(int colour)</a><br /> <a class="message" href="#SCI_CALLTIPSETFOREHLT">SCI_CALLTIPSETFOREHLT(int colour)</a><br /> + <a class="message" href="#SCI_CALLTIPUSESTYLE">SCI_CALLTIPUSESTYLE(int tabsize)</a><br /> </code> - - <p><b id="SCI_CALLTIPSHOW">SCI_CALLTIPSHOW(int posStart, const char *definition)</b><br /> This message starts the process by displaying the call tip window. If a call tip is already active, this has no effect.<br /> <code>posStart</code> is the position in the document at which to align the call tip. The call - tip text is aligned to start 1 line below this character.<br /> + tip text is aligned to start 1 line below this character unless you have included up and/or + down arrows in the call tip text in which case the tip is aligned to the right-hand edge of + the rightmost arrow. The assumption is that you will start the text with something like + "\001 1 of 3 \002".<br /> <code>definition</code> is the call tip text. This can contain multiple lines separated by - '\n' (Line Feed, ASCII code 10) characters.</p> + '\n' (Line Feed, ASCII code 10) characters. Do not include '\r' (Carriage Return, ASCII + code 13), as this will most likely print as an empty box. '\t' (Tab, ASCII code 9) is + supported if you set a tabsize with + <code><a class="message" href="#SCI_CALLTIPUSESTYLE">SCI_CALLTIPUSESTYLE</a></code>.<br /></p> <p><b id="SCI_CALLTIPCANCEL">SCI_CALLTIPCANCEL</b><br /> This message cancels any displayed call tip. Scintilla will also cancel call tips for you if @@ -3233,14 +3256,24 @@ struct TextToFind { <p><b id="SCI_CALLTIPSETBACK">SCI_CALLTIPSETBACK(int colour)</b><br /> The background colour of call tips can be set with this message; the default colour is white. - It is not a good idea to set a dark colour as the background as the unselected text is drawn in - mid gray and the selected text in a dark blue.</p> + It is not a good idea to set a dark colour as the background as the default colour for normal + calltip text is mid gray and the defaultcolour for highlighted text is dark blue. This also + sets the background colour of <code>STYLE_CALLTIP</code>.</p> <p><b id="SCI_CALLTIPSETFORE">SCI_CALLTIPSETFORE(int colour)</b><br /> - The colour of call tip text can be set with this message; the default colour is mid gray.</p> + The colour of call tip text can be set with this message; the default colour is mid gray. + This also sets the foreground colour of <code>STYLE_CALLTIP</code>.</p> <p><b id="SCI_CALLTIPSETFOREHLT">SCI_CALLTIPSETFOREHLT(int colour)</b><br /> - The colour of highlighted call tip text can be set with this message; the default colour is dark blue.</p> + The colour of highlighted call tip text can be set with this message; the default colour + is dark blue.</p> + + <p><b id="SCI_CALLTIPUSESTYLE">SCI_CALLTIPUSESTYLE(int tabsize)</b><br /> + This message changes the style used for call tips from <code>STYLE_DEFAULT</code> to + <code>STYLE_CALLTIP</code> and sets a tab size in screen pixels. If <code>tabsize</code> is + less than 1, Tab characters are not treated specially. Once this call has been used, the + call tip foreground and background colours are also taken from the style.</p> + <h2 id="KeyboardCommands">Keyboard commands</h2> diff --git a/include/Scintilla.h b/include/Scintilla.h index b4ed329f7..29ffdb23d 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -154,6 +154,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define STYLE_BRACEBAD 35 #define STYLE_CONTROLCHAR 36 #define STYLE_INDENTGUIDE 37 +#define STYLE_CALLTIP 38 #define STYLE_LASTPREDEFINED 39 #define STYLE_MAX 127 #define SC_CHARSET_ANSI 0 @@ -358,6 +359,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_CALLTIPSETBACK 2205 #define SCI_CALLTIPSETFORE 2206 #define SCI_CALLTIPSETFOREHLT 2207 +#define SCI_CALLTIPUSESTYLE 2212 #define SCI_VISIBLEFROMDOCLINE 2220 #define SCI_DOCLINEFROMVISIBLE 2221 #define SCI_WRAPCOUNT 2235 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 9a3a94d77..ecb366530 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -344,8 +344,8 @@ set void SetMarginSensitiveN=2246(int margin, bool sensitive) # Retrieve the mouse click sensitivity of a margin. get bool GetMarginSensitiveN=2247(int margin,) -# Styles in range 32..37 are predefined for parts of the UI and are not used as normal styles. -# Styles 38 and 39 are for future use. +# Styles in range 32..38 are predefined for parts of the UI and are not used as normal styles. +# Style 39 is for future use. enu StylesCommon=STYLE_ val STYLE_DEFAULT=32 val STYLE_LINENUMBER=33 @@ -353,6 +353,7 @@ val STYLE_BRACELIGHT=34 val STYLE_BRACEBAD=35 val STYLE_CONTROLCHAR=36 val STYLE_INDENTGUIDE=37 +val STYLE_CALLTIP=38 val STYLE_LASTPREDEFINED=39 val STYLE_MAX=127 @@ -919,6 +920,9 @@ set void CallTipSetFore=2206(colour fore,) # Set the foreground colour for the highlighted part of the call tip. set void CallTipSetForeHlt=2207(colour fore,) +# Enable use of STYLE_CALLTIP and set call tip tab size in pixels. +set void CallTipUseStyle=2212(int tabSize,) + # Find the display line of a document line taking hidden lines into account. fun int VisibleFromDocLine=2220(int line,) diff --git a/src/CallTip.cxx b/src/CallTip.cxx index 80fd55d7b..f7a458313 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -13,6 +13,9 @@ #include "Scintilla.h" #include "CallTip.h" +static const int insetX = 5; // text inset in x from calltip border +const int widthArrow = 14; + CallTip::CallTip() { wCallTip = 0; inCallTipMode = false; @@ -23,6 +26,8 @@ CallTip::CallTip() { lineHeight = 1; startHighlight = 0; endHighlight = 0; + tabSize = 0; + useStyleCallTip = false; // for backwards compatibility colourBG.desired = ColourDesired(0xff, 0xff, 0xff); colourUnSel.desired = ColourDesired(0x80, 0x80, 0x80); @@ -38,8 +43,6 @@ CallTip::~CallTip() { val = 0; } -const int widthArrow = 14; - void CallTip::RefreshColourPalette(Palette &pal, bool want) { pal.WantFind(colourBG, want); pal.WantFind(colourUnSel, want); @@ -48,19 +51,42 @@ void CallTip::RefreshColourPalette(Palette &pal, bool want) { pal.WantFind(colourLight, want); } +// Although this test includes 0, we should never see a \0 character. static bool IsArrowCharacter(char ch) { return (ch == 0) || (ch == '\001') || (ch == '\002'); } +// We ignore tabs unless a tab width has been set. +bool CallTip::IsTabCharacter(char ch) { + return (tabSize > 0) && (ch == '\t'); +} + +int CallTip::NextTabPos(int x) { + if (tabSize > 0) { // paranoia... not called unless this is true + x -= insetX; // position relative to text + x = (x + tabSize) / tabSize; // tab "number" + return tabSize*x + insetX; // position of next tab + } else { + return x + 1; // arbitrary + } +} + +// Draw a section of the call tip that does not include \n in one colour. +// The text may include up to numEnds tabs or arrow characters. void CallTip::DrawChunk(Surface *surface, int &x, const char *s, int posStart, int posEnd, int ytext, PRectangle rcClient, bool highlight, bool draw) { s += posStart; int len = posEnd - posStart; + + // Divide the text into sections that are all text, or that are + // single arrows or single tab characters (if tabSize > 0). int maxEnd = 0; - int ends[10]; + const int numEnds = 10; + int ends[numEnds + 2]; for (int i=0;i<len;i++) { - if (IsArrowCharacter(s[i])) { + if ((maxEnd < numEnds) && + (IsArrowCharacter(s[i]) || IsTabCharacter(s[i])) ) { if (i > 0) ends[maxEnd++] = i; ends[maxEnd++] = i+1; @@ -73,20 +99,19 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, int endSeg = ends[seg]; if (endSeg > startSeg) { if (IsArrowCharacter(s[startSeg])) { - xEnd = x + widthArrow; - offsetMain = xEnd; + bool upArrow = s[startSeg] == '\001'; rcClient.left = x; - rcClient.right = xEnd; + rcClient.right = rcClient.left + widthArrow; if (draw) { const int halfWidth = widthArrow / 2 - 3; - const int centreX = x + widthArrow / 2 - 1; + const int centreX = rcClient.left + widthArrow / 2 - 1; const int centreY = (rcClient.top + rcClient.bottom) / 2; surface->FillRectangle(rcClient, colourBG.allocated); - PRectangle rcClientInner(rcClient.left+1, rcClient.top+1, rcClient.right-2, rcClient.bottom-1); + PRectangle rcClientInner(rcClient.left + 1, rcClient.top + 1, + rcClient.right - 2, rcClient.bottom - 1); surface->FillRectangle(rcClientInner, colourUnSel.allocated); - if (s[startSeg] == '\001') { - // Up arrow + if (upArrow) { // Up arrow Point pts[] = { Point(centreX - halfWidth, centreY + halfWidth / 2), Point(centreX + halfWidth, centreY + halfWidth / 2), @@ -94,8 +119,7 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, }; surface->Polygon(pts, sizeof(pts) / sizeof(pts[0]), colourBG.allocated, colourBG.allocated); - } else { - // Down arrow + } else { // Down arrow Point pts[] = { Point(centreX - halfWidth, centreY - halfWidth / 2), Point(centreX + halfWidth, centreY - halfWidth / 2), @@ -105,20 +129,23 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, colourBG.allocated, colourBG.allocated); } } - if (s[startSeg] == '\001') { + xEnd = rcClient.right; + offsetMain = xEnd; + if (upArrow) { rectUp = rcClient; - } else if (s[startSeg] == '\002') { + } else { rectDown = rcClient; } + } else if (IsTabCharacter(s[startSeg])) { + xEnd = NextTabPos(x); } else { - xEnd = x + surface->WidthText(font, s+startSeg, endSeg - startSeg); + xEnd = x + surface->WidthText(font, s + startSeg, endSeg - startSeg); if (draw) { rcClient.left = x; rcClient.right = xEnd; - surface->DrawTextNoClip(rcClient, font, ytext, + surface->DrawTextTransparent(rcClient, font, ytext, s+startSeg, endSeg - startSeg, - highlight ? colourSel.allocated : colourUnSel.allocated, - colourBG.allocated); + highlight ? colourSel.allocated : colourUnSel.allocated); } } x = xEnd; @@ -160,7 +187,7 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) { thisEndHighlight -= chunkOffset; rcClient.top = ytext - ascent - 1; - int x = 5; + int x = insetX; // start each line at this inset DrawChunk(surfaceWindow, x, chunkVal, 0, thisStartHighlight, ytext, rcClient, false, draw); @@ -187,7 +214,7 @@ void CallTip::PaintCT(Surface *surfaceWindow) { surfaceWindow->FillRectangle(rcClient, colourBG.allocated); - offsetMain = 5; + offsetMain = insetX; // initial alignment assuming no arrows PaintContents(surfaceWindow, true); // Draw a raised border around the edges of the window @@ -238,14 +265,17 @@ PRectangle CallTip::CallTipStart(int pos, Point pt, const char *defn, const char *look = val; rectUp = PRectangle(0,0,0,0); rectDown = PRectangle(0,0,0,0); - offsetMain = 5; - int width = PaintContents(surfaceMeasure, false) + 5; + offsetMain = insetX; // changed to right edge of any arrows + int width = PaintContents(surfaceMeasure, false) + insetX; while ((newline = strchr(look, '\n')) != NULL) { look = newline + 1; numLines++; } lineHeight = surfaceMeasure->Height(font); - // Extra line for border and an empty line at top and bottom + + // Extra line for border and an empty line at top and bottom. The returned + // rectangle is aligned to the right edge of the last arrow encountered in + // the tip text, else to the tip text left edge. int height = lineHeight * numLines - surfaceMeasure->InternalLeading(font) + 2 + 2; delete surfaceMeasure; return PRectangle(pt.x - offsetMain, pt.y + 1, pt.x + width - offsetMain, pt.y + 1 + height); @@ -268,3 +298,17 @@ void CallTip::SetHighlight(int start, int end) { } } } + +// Set the tab size (sizes > 0 enable the use of tabs). This also enables the +// use of the STYLE_CALLTIP. +void CallTip::SetTabSize(int tabSz) { + tabSize = tabSz; + useStyleCallTip = true; +} + +// It might be better to have two access functions for this and to use +// them for all settings of colours. +void CallTip::SetForeBack(const ColourPair &fore, const ColourPair &back) { + colourBG = back; + colourUnSel = fore; +} diff --git a/src/CallTip.h b/src/CallTip.h index 53eec832a..9848a10af 100644 --- a/src/CallTip.h +++ b/src/CallTip.h @@ -11,14 +11,17 @@ /** */ class CallTip { - int startHighlight; - int endHighlight; + int startHighlight; // character offset to start and... + int endHighlight; // ...end of highlighted text char *val; Font font; - PRectangle rectUp; - PRectangle rectDown; - int lineHeight; - int offsetMain; + PRectangle rectUp; // rectangle of last up angle in the tip + PRectangle rectDown; // rectangle of last down arrow in the tip + int lineHeight; // vertical line spacing + int offsetMain; // The alignment point of the call tip + int tabSize; // Tab size in pixels, <=0 no TAB expand + bool useStyleCallTip; // if true, STYLE_CALLTIP should be used + // Private so CallTip objects can not be copied CallTip(const CallTip &) {} CallTip &operator=(const CallTip &) { return *this; } @@ -26,6 +29,8 @@ class CallTip { int posStart, int posEnd, int ytext, PRectangle rcClient, bool highlight, bool draw); int PaintContents(Surface *surfaceWindow, bool draw); + bool IsTabCharacter(char c); + int NextTabPos(int x); public: Window wCallTip; @@ -60,6 +65,15 @@ public: /// Set a range of characters to be displayed in a highlight style. /// Commonly used to highlight the current parameter. void SetHighlight(int start, int end); + + /// Set the tab size in pixels for the call tip. 0 or -ve means no tab expand. + void SetTabSize(int tabSz); + + /// Used to determine which STYLE_xxxx to use for call tip information + bool UseStyleCallTip() const { return useStyleCallTip;} + + // Modify foreground and background colours + void SetForeBack(const ColourPair &fore, const ColourPair &back); }; #endif diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 6be8b74b5..0ca5002a7 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -368,12 +368,19 @@ int ScintillaBase::AutoCompleteGetCurrent() { void ScintillaBase::CallTipShow(Point pt, const char *defn) { AutoCompleteCancel(); pt.y += vs.lineHeight; + // If container knows about STYLE_CALLTIP then use it in place of the + // STYLE_DEFAULT for the face name, size and character set. Also use it + // for the foreground and background colour. + int ctStyle = ct.UseStyleCallTip() ? STYLE_CALLTIP : STYLE_DEFAULT; + if (ct.UseStyleCallTip()) { + ct.SetForeBack(vs.styles[STYLE_CALLTIP].fore, vs.styles[STYLE_CALLTIP].back); + } PRectangle rc = ct.CallTipStart(currentPos, pt, defn, - vs.styles[STYLE_DEFAULT].fontName, - vs.styles[STYLE_DEFAULT].sizeZoomed, + vs.styles[ctStyle].fontName, + vs.styles[ctStyle].sizeZoomed, CodePage(), - vs.styles[STYLE_DEFAULT].characterSet, + vs.styles[ctStyle].characterSet, wMain); // If the call-tip window would be out of the client // space, adjust so it displays above the text. @@ -624,11 +631,13 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara case SCI_CALLTIPSETBACK: ct.colourBG = ColourDesired(wParam); + vs.styles[STYLE_CALLTIP].fore = ct.colourBG; InvalidateStyleRedraw(); break; case SCI_CALLTIPSETFORE: ct.colourUnSel = ColourDesired(wParam); + vs.styles[STYLE_CALLTIP].fore = ct.colourUnSel; InvalidateStyleRedraw(); break; @@ -637,6 +646,11 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara InvalidateStyleRedraw(); break; + case SCI_CALLTIPUSESTYLE: + ct.SetTabSize((int)wParam); + InvalidateStyleRedraw(); + break; + case SCI_USEPOPUP: displayPopupMenu = wParam != 0; break; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index c52f1e472..fe519905b 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -278,6 +278,10 @@ void ViewStyle::ClearStyles() { } } styles[STYLE_LINENUMBER].back.desired = Platform::Chrome(); + + // Set call tip fore/back to match the values previously set for call tips + styles[STYLE_CALLTIP].back.desired = ColourDesired(0xff, 0xff, 0xff); + styles[STYLE_CALLTIP].fore.desired = ColourDesired(0x80, 0x80, 0x80); } void ViewStyle::SetStyleFontName(int styleIndex, const char *name) { |