]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/CallTip.cxx
1 // Scintilla source code edit control
3 ** Code for displaying call tips.
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
13 #include "Scintilla.h"
18 inCallTipMode
= false;
27 colourBG
.desired
= ColourDesired(0xff, 0xff, 0xff);
28 colourUnSel
.desired
= ColourDesired(0x80, 0x80, 0x80);
29 colourSel
.desired
= ColourDesired(0, 0, 0x80);
30 colourShade
.desired
= ColourDesired(0, 0, 0);
31 colourLight
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
41 const int widthArrow
= 14;
43 void CallTip::RefreshColourPalette(Palette
&pal
, bool want
) {
44 pal
.WantFind(colourBG
, want
);
45 pal
.WantFind(colourUnSel
, want
);
46 pal
.WantFind(colourSel
, want
);
47 pal
.WantFind(colourShade
, want
);
48 pal
.WantFind(colourLight
, want
);
51 void CallTip::DrawChunk(Surface
*surface
, int &x
, const char *s
,
52 int posStart
, int posEnd
, int ytext
, PRectangle rcClient
,
53 bool highlight
, bool draw
) {
55 int len
= posEnd
- posStart
;
58 for (int i
=0;i
<len
;i
++) {
68 for (int seg
= 0; seg
<maxEnd
; seg
++) {
69 int endSeg
= ends
[seg
];
70 if (endSeg
> startSeg
) {
71 if (s
[startSeg
] <= '\002') {
72 xEnd
= x
+ widthArrow
;
75 const int halfWidth
= widthArrow
/ 2 - 3;
76 const int centreX
= x
+ widthArrow
/ 2 - 1;
77 const int centreY
= (rcClient
.top
+ rcClient
.bottom
) / 2;
79 rcClient
.right
= xEnd
;
80 surface
->FillRectangle(rcClient
, colourBG
.allocated
);
81 PRectangle
rcClientInner(rcClient
.left
+1, rcClient
.top
+1, rcClient
.right
-2, rcClient
.bottom
-1);
82 surface
->FillRectangle(rcClientInner
, colourUnSel
.allocated
);
84 if (s
[startSeg
] == '\001') {
87 Point(centreX
- halfWidth
, centreY
+ halfWidth
/ 2),
88 Point(centreX
+ halfWidth
, centreY
+ halfWidth
/ 2),
89 Point(centreX
, centreY
- halfWidth
+ halfWidth
/ 2),
91 surface
->Polygon(pts
, sizeof(pts
) / sizeof(pts
[0]),
92 colourBG
.allocated
, colourBG
.allocated
);
96 Point(centreX
- halfWidth
, centreY
- halfWidth
/ 2),
97 Point(centreX
+ halfWidth
, centreY
- halfWidth
/ 2),
98 Point(centreX
, centreY
+ halfWidth
- halfWidth
/ 2),
100 surface
->Polygon(pts
, sizeof(pts
) / sizeof(pts
[0]),
101 colourBG
.allocated
, colourBG
.allocated
);
104 if (s
[startSeg
] == '\001') {
111 xEnd
= x
+ surface
->WidthText(font
, s
+startSeg
, endSeg
- startSeg
);
114 rcClient
.right
= xEnd
;
115 surface
->DrawTextNoClip(rcClient
, font
, ytext
,
116 s
+startSeg
, endSeg
- startSeg
,
117 highlight
? colourSel
.allocated
: colourUnSel
.allocated
,
127 int CallTip::PaintContents(Surface
*surfaceWindow
, bool draw
) {
128 PRectangle rcClientPos
= wCallTip
.GetClientPosition();
129 PRectangle
rcClientSize(0, 0, rcClientPos
.right
- rcClientPos
.left
,
130 rcClientPos
.bottom
- rcClientPos
.top
);
131 PRectangle
rcClient(1, 1, rcClientSize
.right
- 1, rcClientSize
.bottom
- 1);
133 // To make a nice small call tip window, it is only sized to fit most normal characters without accents
134 int ascent
= surfaceWindow
->Ascent(font
) - surfaceWindow
->InternalLeading(font
);
137 // Draw the definition in three parts: before highlight, highlighted, after highlight
138 int ytext
= rcClient
.top
+ ascent
+ 1;
139 rcClient
.bottom
= ytext
+ surfaceWindow
->Descent(font
) + 1;
140 char *chunkVal
= val
;
141 bool moreChunks
= true;
144 char *chunkEnd
= strchr(chunkVal
, '\n');
145 if (chunkEnd
== NULL
) {
146 chunkEnd
= chunkVal
+ strlen(chunkVal
);
149 int chunkOffset
= chunkVal
- val
;
150 int chunkLength
= chunkEnd
- chunkVal
;
151 int chunkEndOffset
= chunkOffset
+ chunkLength
;
152 int thisStartHighlight
= Platform::Maximum(startHighlight
, chunkOffset
);
153 thisStartHighlight
= Platform::Minimum(thisStartHighlight
, chunkEndOffset
);
154 thisStartHighlight
-= chunkOffset
;
155 int thisEndHighlight
= Platform::Maximum(endHighlight
, chunkOffset
);
156 thisEndHighlight
= Platform::Minimum(thisEndHighlight
, chunkEndOffset
);
157 thisEndHighlight
-= chunkOffset
;
158 rcClient
.top
= ytext
- ascent
- 1;
162 DrawChunk(surfaceWindow
, x
, chunkVal
, 0, thisStartHighlight
,
163 ytext
, rcClient
, false, draw
);
164 DrawChunk(surfaceWindow
, x
, chunkVal
, thisStartHighlight
, thisEndHighlight
,
165 ytext
, rcClient
, true, draw
);
166 DrawChunk(surfaceWindow
, x
, chunkVal
, thisEndHighlight
, chunkLength
,
167 ytext
, rcClient
, false, draw
);
169 chunkVal
= chunkEnd
+ 1;
171 rcClient
.bottom
+= lineHeight
;
172 maxWidth
= Platform::Maximum(maxWidth
, x
);
177 void CallTip::PaintCT(Surface
*surfaceWindow
) {
180 PRectangle rcClientPos
= wCallTip
.GetClientPosition();
181 PRectangle
rcClientSize(0, 0, rcClientPos
.right
- rcClientPos
.left
,
182 rcClientPos
.bottom
- rcClientPos
.top
);
183 PRectangle
rcClient(1, 1, rcClientSize
.right
- 1, rcClientSize
.bottom
- 1);
185 surfaceWindow
->FillRectangle(rcClient
, colourBG
.allocated
);
188 PaintContents(surfaceWindow
, true);
190 // Draw a raised border around the edges of the window
191 surfaceWindow
->MoveTo(0, rcClientSize
.bottom
- 1);
192 surfaceWindow
->PenColour(colourShade
.allocated
);
193 surfaceWindow
->LineTo(rcClientSize
.right
- 1, rcClientSize
.bottom
- 1);
194 surfaceWindow
->LineTo(rcClientSize
.right
- 1, 0);
195 surfaceWindow
->PenColour(colourLight
.allocated
);
196 surfaceWindow
->LineTo(0, 0);
197 surfaceWindow
->LineTo(0, rcClientSize
.bottom
- 1);
200 void CallTip::MouseClick(Point pt
) {
202 if (pt
.y
< lineHeight
) {
203 if ((pt
.x
> xUp
) && (pt
.x
< xUp
+ widthArrow
- 2)) {
205 } else if ((pt
.x
> xDown
) && (pt
.x
< xDown
+ widthArrow
- 2)) {
211 PRectangle
CallTip::CallTipStart(int pos
, Point pt
, const char *defn
,
212 const char *faceName
, int size
,
213 int codePage_
, Window
&wParent
) {
217 val
= new char[strlen(defn
) + 1];
221 codePage
= codePage_
;
222 Surface
*surfaceMeasure
= Surface::Allocate();
225 surfaceMeasure
->Init(wParent
.GetID());
226 surfaceMeasure
->SetUnicodeMode(SC_CP_UTF8
== codePage
);
227 surfaceMeasure
->SetDBCSMode(codePage
);
230 inCallTipMode
= true;
231 posStartCallTip
= pos
;
232 int deviceHeight
= surfaceMeasure
->DeviceHeightFont(size
);
233 font
.Create(faceName
, SC_CHARSET_DEFAULT
, deviceHeight
, false, false);
234 // Look for multiple lines in the text
235 // Only support \n here - simply means container must avoid \r!
238 const char *look
= val
;
242 int width
= PaintContents(surfaceMeasure
, false) + 5;
243 while ((newline
= strchr(look
, '\n')) != NULL
) {
247 lineHeight
= surfaceMeasure
->Height(font
);
248 // Extra line for border and an empty line at top and bottom
249 int height
= lineHeight
* numLines
- surfaceMeasure
->InternalLeading(font
) + 2 + 2;
250 delete surfaceMeasure
;
251 return PRectangle(pt
.x
- offsetMain
, pt
.y
+ 1, pt
.x
+ width
- offsetMain
, pt
.y
+ 1 + height
);
254 void CallTip::CallTipCancel() {
255 inCallTipMode
= false;
256 if (wCallTip
.Created()) {
261 void CallTip::SetHighlight(int start
, int end
) {
262 // Avoid flashing by checking something has really changed
263 if ((start
!= startHighlight
) || (end
!= endHighlight
)) {
264 startHighlight
= start
;
266 if (wCallTip
.Created()) {
267 wCallTip
.InvalidateAll();