]>
Commit | Line | Data |
---|---|---|
9ce192d4 | 1 | // Scintilla source code edit control |
be5a51fb | 2 | // PlatWX.cxx - implementation of platform facilities on wxWidgets |
9ce192d4 RD |
3 | // Copyright 1998-1999 by Neil Hodgson <neilh@scintilla.org> |
4 | // Robin Dunn <robin@aldunn.com> | |
5 | // The License.txt file describes the conditions under which this software may be distributed. | |
6 | ||
54429bb3 RD |
7 | // For compilers that support precompilation, includes "wx.h". |
8 | #include "wx/wxprec.h" | |
9 | ||
10 | #ifdef __BORLANDC__ | |
11 | #pragma hdrstop | |
12 | #endif | |
13 | ||
29825f5f | 14 | #if wxUSE_STC |
54429bb3 RD |
15 | |
16 | #ifndef WX_PRECOMP | |
29825f5f PC |
17 | #include "wx/menu.h" |
18 | #include "wx/dcmemory.h" | |
19 | #include "wx/settings.h" | |
54429bb3 RD |
20 | #endif // WX_PRECOMP |
21 | ||
f6bcfd97 | 22 | #include <ctype.h> |
9ce192d4 | 23 | |
7e0c58e9 RD |
24 | #if wxUSE_DISPLAY |
25 | #include "wx/display.h" | |
26 | #endif | |
27 | ||
d6655166 WS |
28 | #include "wx/encconv.h" |
29 | #include "wx/listctrl.h" | |
30 | #include "wx/mstream.h" | |
31 | #include "wx/image.h" | |
32 | #include "wx/imaglist.h" | |
1e9bafca | 33 | #include "wx/tokenzr.h" |
8b3d52fc | 34 | |
3fb1e059 | 35 | #ifdef wxHAS_RAW_BITMAP |
6a93571d | 36 | #include "wx/rawbmp.h" |
8b6c20ce | 37 | #endif |
1a2fb4cd | 38 | |
9ce192d4 | 39 | #include "Platform.h" |
1a2fb4cd | 40 | #include "PlatWX.h" |
9ce192d4 | 41 | #include "wx/stc/stc.h" |
ea88e9bc | 42 | #include "wx/stc/private.h" |
9ce192d4 | 43 | |
f97d84a6 | 44 | |
f9ee2e27 | 45 | |
9ce192d4 | 46 | Point Point::FromLong(long lpoint) { |
f6bcfd97 | 47 | return Point(lpoint & 0xFFFF, lpoint >> 16); |
9ce192d4 RD |
48 | } |
49 | ||
50 | wxRect wxRectFromPRectangle(PRectangle prc) { | |
d13ea3aa RD |
51 | wxRect r(prc.left, prc.top, |
52 | prc.Width(), prc.Height()); | |
53 | return r; | |
9ce192d4 RD |
54 | } |
55 | ||
56 | PRectangle PRectangleFromwxRect(wxRect rc) { | |
bec17edf | 57 | return PRectangle(rc.GetLeft(), rc.GetTop(), |
04ebdf40 | 58 | rc.GetRight()+1, rc.GetBottom()+1); |
9ce192d4 RD |
59 | } |
60 | ||
1a2fb4cd RD |
61 | wxColour wxColourFromCA(const ColourAllocated& ca) { |
62 | ColourDesired cd(ca.AsLong()); | |
c8b75e94 WS |
63 | return wxColour((unsigned char)cd.GetRed(), |
64 | (unsigned char)cd.GetGreen(), | |
65 | (unsigned char)cd.GetBlue()); | |
9ce192d4 RD |
66 | } |
67 | ||
1a2fb4cd | 68 | //---------------------------------------------------------------------- |
9ce192d4 RD |
69 | |
70 | Palette::Palette() { | |
71 | used = 0; | |
72 | allowRealization = false; | |
b8193d80 RD |
73 | size = 100; |
74 | entries = new ColourPair[size]; | |
9ce192d4 RD |
75 | } |
76 | ||
77 | Palette::~Palette() { | |
78 | Release(); | |
b8193d80 RD |
79 | delete [] entries; |
80 | entries = 0; | |
9ce192d4 RD |
81 | } |
82 | ||
83 | void Palette::Release() { | |
84 | used = 0; | |
b8193d80 RD |
85 | delete [] entries; |
86 | size = 100; | |
87 | entries = new ColourPair[size]; | |
9ce192d4 RD |
88 | } |
89 | ||
90 | // This method either adds a colour to the list of wanted colours (want==true) | |
91 | // or retrieves the allocated colour back to the ColourPair. | |
92 | // This is one method to make it easier to keep the code for wanting and retrieving in sync. | |
93 | void Palette::WantFind(ColourPair &cp, bool want) { | |
94 | if (want) { | |
95 | for (int i=0; i < used; i++) { | |
96 | if (entries[i].desired == cp.desired) | |
97 | return; | |
98 | } | |
99 | ||
b8193d80 RD |
100 | if (used >= size) { |
101 | int sizeNew = size * 2; | |
102 | ColourPair *entriesNew = new ColourPair[sizeNew]; | |
103 | for (int j=0; j<size; j++) { | |
104 | entriesNew[j] = entries[j]; | |
105 | } | |
106 | delete []entries; | |
107 | entries = entriesNew; | |
108 | size = sizeNew; | |
9ce192d4 | 109 | } |
b8193d80 RD |
110 | |
111 | entries[used].desired = cp.desired; | |
112 | entries[used].allocated.Set(cp.desired.AsLong()); | |
113 | used++; | |
9ce192d4 RD |
114 | } else { |
115 | for (int i=0; i < used; i++) { | |
116 | if (entries[i].desired == cp.desired) { | |
117 | cp.allocated = entries[i].allocated; | |
118 | return; | |
119 | } | |
120 | } | |
1a2fb4cd | 121 | cp.allocated.Set(cp.desired.AsLong()); |
9ce192d4 RD |
122 | } |
123 | } | |
124 | ||
125 | void Palette::Allocate(Window &) { | |
126 | if (allowRealization) { | |
127 | } | |
128 | } | |
129 | ||
130 | ||
1a2fb4cd RD |
131 | //---------------------------------------------------------------------- |
132 | ||
9ce192d4 RD |
133 | Font::Font() { |
134 | id = 0; | |
135 | ascent = 0; | |
136 | } | |
137 | ||
138 | Font::~Font() { | |
139 | } | |
140 | ||
3f0640b0 VZ |
141 | void Font::Create(const char *faceName, int characterSet, |
142 | int size, bool bold, bool italic, | |
8462a84b | 143 | bool WXUNUSED(extraFontFlag)) { |
9ce192d4 | 144 | Release(); |
1a2fb4cd | 145 | |
3727c043 RD |
146 | // The minus one is done because since Scintilla uses SC_SHARSET_DEFAULT |
147 | // internally and we need to have wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT | |
148 | // so we adjust the encoding before passing it to Scintilla. See also | |
149 | // wxStyledTextCtrl::StyleSetCharacterSet | |
150 | wxFontEncoding encoding = (wxFontEncoding)(characterSet-1); | |
d35ad26e | 151 | |
10ef30eb RD |
152 | wxFontEncodingArray ea = wxEncodingConverter::GetPlatformEquivalents(encoding); |
153 | if (ea.GetCount()) | |
154 | encoding = ea[0]; | |
1a2fb4cd | 155 | |
d1558f3d | 156 | wxFont* font = new wxFont(size, |
9ce192d4 RD |
157 | wxDEFAULT, |
158 | italic ? wxITALIC : wxNORMAL, | |
159 | bold ? wxBOLD : wxNORMAL, | |
160 | false, | |
0c5b83b0 | 161 | stc2wx(faceName), |
1a2fb4cd | 162 | encoding); |
d1558f3d | 163 | id = font; |
9ce192d4 RD |
164 | } |
165 | ||
166 | ||
167 | void Font::Release() { | |
168 | if (id) | |
1a2fb4cd | 169 | delete (wxFont*)id; |
9ce192d4 RD |
170 | id = 0; |
171 | } | |
172 | ||
1a2fb4cd RD |
173 | //---------------------------------------------------------------------- |
174 | ||
175 | class SurfaceImpl : public Surface { | |
176 | private: | |
177 | wxDC* hdc; | |
178 | bool hdcOwned; | |
179 | wxBitmap* bitmap; | |
180 | int x; | |
181 | int y; | |
182 | bool unicodeMode; | |
9ce192d4 | 183 | |
1a2fb4cd RD |
184 | public: |
185 | SurfaceImpl(); | |
186 | ~SurfaceImpl(); | |
187 | ||
9e730a78 RD |
188 | virtual void Init(WindowID wid); |
189 | virtual void Init(SurfaceID sid, WindowID wid); | |
190 | virtual void InitPixMap(int width, int height, Surface *surface_, WindowID wid); | |
191 | ||
192 | virtual void Release(); | |
193 | virtual bool Initialised(); | |
194 | virtual void PenColour(ColourAllocated fore); | |
195 | virtual int LogPixelsY(); | |
196 | virtual int DeviceHeightFont(int points); | |
197 | virtual void MoveTo(int x_, int y_); | |
198 | virtual void LineTo(int x_, int y_); | |
199 | virtual void Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back); | |
200 | virtual void RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back); | |
201 | virtual void FillRectangle(PRectangle rc, ColourAllocated back); | |
202 | virtual void FillRectangle(PRectangle rc, Surface &surfacePattern); | |
203 | virtual void RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back); | |
b8193d80 RD |
204 | virtual void AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill, |
205 | ColourAllocated outline, int alphaOutline, int flags); | |
9e730a78 RD |
206 | virtual void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back); |
207 | virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource); | |
208 | ||
209 | virtual void DrawTextNoClip(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back); | |
210 | virtual void DrawTextClipped(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back); | |
211 | virtual void DrawTextTransparent(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore); | |
212 | virtual void MeasureWidths(Font &font_, const char *s, int len, int *positions); | |
213 | virtual int WidthText(Font &font_, const char *s, int len); | |
214 | virtual int WidthChar(Font &font_, char ch); | |
215 | virtual int Ascent(Font &font_); | |
216 | virtual int Descent(Font &font_); | |
217 | virtual int InternalLeading(Font &font_); | |
218 | virtual int ExternalLeading(Font &font_); | |
219 | virtual int Height(Font &font_); | |
220 | virtual int AverageCharWidth(Font &font_); | |
221 | ||
222 | virtual int SetPalette(Palette *pal, bool inBackGround); | |
223 | virtual void SetClip(PRectangle rc); | |
224 | virtual void FlushCachedState(); | |
225 | ||
226 | virtual void SetUnicodeMode(bool unicodeMode_); | |
227 | virtual void SetDBCSMode(int codePage); | |
1a2fb4cd RD |
228 | |
229 | void BrushColour(ColourAllocated back); | |
230 | void SetFont(Font &font_); | |
231 | }; | |
232 | ||
233 | ||
234 | ||
235 | SurfaceImpl::SurfaceImpl() : | |
9ce192d4 | 236 | hdc(0), hdcOwned(0), bitmap(0), |
1a2fb4cd RD |
237 | x(0), y(0), unicodeMode(0) |
238 | {} | |
9ce192d4 | 239 | |
1a2fb4cd | 240 | SurfaceImpl::~SurfaceImpl() { |
9ce192d4 RD |
241 | Release(); |
242 | } | |
243 | ||
9e730a78 | 244 | void SurfaceImpl::Init(WindowID wid) { |
81b32ce5 | 245 | #if 0 |
9ce192d4 RD |
246 | Release(); |
247 | hdc = new wxMemoryDC(); | |
248 | hdcOwned = true; | |
81b32ce5 | 249 | #else |
09bb2551 | 250 | // On Mac and GTK the DC is not really valid until it has a bitmap |
81b32ce5 RD |
251 | // selected into it. So instead of just creating the DC with no bitmap, |
252 | // go ahead and give it one. | |
9e730a78 | 253 | InitPixMap(1,1,NULL,wid); |
0f713d48 | 254 | #endif |
9ce192d4 RD |
255 | } |
256 | ||
9e730a78 | 257 | void SurfaceImpl::Init(SurfaceID hdc_, WindowID) { |
9ce192d4 | 258 | Release(); |
1a2fb4cd | 259 | hdc = (wxDC*)hdc_; |
9ce192d4 RD |
260 | } |
261 | ||
88a8b04e | 262 | void SurfaceImpl::InitPixMap(int width, int height, Surface *WXUNUSED(surface_), WindowID) { |
9ce192d4 | 263 | Release(); |
1a2fb4cd | 264 | hdc = new wxMemoryDC(); |
9ce192d4 | 265 | hdcOwned = true; |
2beb01db RD |
266 | if (width < 1) width = 1; |
267 | if (height < 1) height = 1; | |
21156596 | 268 | bitmap = new wxBitmap(width, height); |
9ce192d4 | 269 | ((wxMemoryDC*)hdc)->SelectObject(*bitmap); |
9ce192d4 RD |
270 | } |
271 | ||
9e730a78 RD |
272 | |
273 | void SurfaceImpl::Release() { | |
274 | if (bitmap) { | |
275 | ((wxMemoryDC*)hdc)->SelectObject(wxNullBitmap); | |
276 | delete bitmap; | |
277 | bitmap = 0; | |
278 | } | |
279 | if (hdcOwned) { | |
280 | delete hdc; | |
281 | hdc = 0; | |
282 | hdcOwned = false; | |
283 | } | |
284 | } | |
285 | ||
286 | ||
287 | bool SurfaceImpl::Initialised() { | |
288 | return hdc != 0; | |
289 | } | |
290 | ||
291 | ||
1a2fb4cd | 292 | void SurfaceImpl::PenColour(ColourAllocated fore) { |
cb129171 | 293 | hdc->SetPen(wxPen(wxColourFromCA(fore))); |
9ce192d4 RD |
294 | } |
295 | ||
1a2fb4cd | 296 | void SurfaceImpl::BrushColour(ColourAllocated back) { |
cb129171 | 297 | hdc->SetBrush(wxBrush(wxColourFromCA(back))); |
9ce192d4 RD |
298 | } |
299 | ||
1a2fb4cd | 300 | void SurfaceImpl::SetFont(Font &font_) { |
21156596 | 301 | if (font_.GetID()) { |
1a2fb4cd | 302 | hdc->SetFont(*((wxFont*)font_.GetID())); |
f6bcfd97 | 303 | } |
9ce192d4 RD |
304 | } |
305 | ||
1a2fb4cd | 306 | int SurfaceImpl::LogPixelsY() { |
9ce192d4 RD |
307 | return hdc->GetPPI().y; |
308 | } | |
309 | ||
1a2fb4cd | 310 | int SurfaceImpl::DeviceHeightFont(int points) { |
9968ba85 | 311 | return points; |
f6bcfd97 BP |
312 | } |
313 | ||
1a2fb4cd | 314 | void SurfaceImpl::MoveTo(int x_, int y_) { |
9ce192d4 RD |
315 | x = x_; |
316 | y = y_; | |
317 | } | |
318 | ||
1a2fb4cd | 319 | void SurfaceImpl::LineTo(int x_, int y_) { |
9ce192d4 RD |
320 | hdc->DrawLine(x,y, x_,y_); |
321 | x = x_; | |
322 | y = y_; | |
323 | } | |
324 | ||
1a2fb4cd | 325 | void SurfaceImpl::Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back) { |
9ce192d4 | 326 | PenColour(fore); |
1a2fb4cd | 327 | BrushColour(back); |
9ce192d4 RD |
328 | hdc->DrawPolygon(npts, (wxPoint*)pts); |
329 | } | |
330 | ||
1a2fb4cd | 331 | void SurfaceImpl::RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back) { |
9ce192d4 | 332 | PenColour(fore); |
1a2fb4cd | 333 | BrushColour(back); |
9ce192d4 RD |
334 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); |
335 | } | |
336 | ||
1a2fb4cd RD |
337 | void SurfaceImpl::FillRectangle(PRectangle rc, ColourAllocated back) { |
338 | BrushColour(back); | |
9ce192d4 RD |
339 | hdc->SetPen(*wxTRANSPARENT_PEN); |
340 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); | |
341 | } | |
342 | ||
1a2fb4cd | 343 | void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) { |
9ce192d4 | 344 | wxBrush br; |
1a2fb4cd RD |
345 | if (((SurfaceImpl&)surfacePattern).bitmap) |
346 | br = wxBrush(*((SurfaceImpl&)surfacePattern).bitmap); | |
9ce192d4 | 347 | else // Something is wrong so display in red |
cb129171 | 348 | br = wxBrush(*wxRED); |
9ce192d4 RD |
349 | hdc->SetPen(*wxTRANSPARENT_PEN); |
350 | hdc->SetBrush(br); | |
351 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); | |
352 | } | |
353 | ||
1a2fb4cd | 354 | void SurfaceImpl::RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back) { |
9ce192d4 | 355 | PenColour(fore); |
1a2fb4cd | 356 | BrushColour(back); |
f6bcfd97 | 357 | hdc->DrawRoundedRectangle(wxRectFromPRectangle(rc), 4); |
9ce192d4 RD |
358 | } |
359 | ||
6a93571d RD |
360 | #ifdef __WXMSW__ |
361 | #define wxPy_premultiply(p, a) ((p) * (a) / 0xff) | |
362 | #else | |
363 | #define wxPy_premultiply(p, a) (p) | |
364 | #endif | |
365 | ||
b8193d80 RD |
366 | void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, |
367 | ColourAllocated fill, int alphaFill, | |
6a93571d RD |
368 | ColourAllocated outline, int alphaOutline, |
369 | int /*flags*/) { | |
3fb1e059 | 370 | #ifdef wxHAS_RAW_BITMAP |
a3511a2e RD |
371 | |
372 | // TODO: do something with cornerSize | |
373 | wxUnusedVar(cornerSize); | |
038c0333 | 374 | |
6a93571d RD |
375 | int x, y; |
376 | wxRect r = wxRectFromPRectangle(rc); | |
377 | wxBitmap bmp(r.width, r.height, 32); | |
378 | wxAlphaPixelData pixData(bmp); | |
6a93571d RD |
379 | |
380 | // Set the fill pixels | |
381 | ColourDesired cdf(fill.AsLong()); | |
382 | int red = cdf.GetRed(); | |
383 | int green = cdf.GetGreen(); | |
384 | int blue = cdf.GetBlue(); | |
385 | ||
386 | wxAlphaPixelData::Iterator p(pixData); | |
387 | for (y=0; y<r.height; y++) { | |
388 | p.MoveTo(pixData, 0, y); | |
389 | for (x=0; x<r.width; x++) { | |
390 | p.Red() = wxPy_premultiply(red, alphaFill); | |
391 | p.Green() = wxPy_premultiply(green, alphaFill); | |
392 | p.Blue() = wxPy_premultiply(blue, alphaFill); | |
393 | p.Alpha() = alphaFill; | |
038c0333 | 394 | ++p; |
6a93571d RD |
395 | } |
396 | } | |
397 | ||
398 | // Set the outline pixels | |
399 | ColourDesired cdo(outline.AsLong()); | |
400 | red = cdo.GetRed(); | |
401 | green = cdo.GetGreen(); | |
402 | blue = cdo.GetBlue(); | |
403 | for (x=0; x<r.width; x++) { | |
404 | p.MoveTo(pixData, x, 0); | |
405 | p.Red() = wxPy_premultiply(red, alphaOutline); | |
406 | p.Green() = wxPy_premultiply(green, alphaOutline); | |
407 | p.Blue() = wxPy_premultiply(blue, alphaOutline); | |
038c0333 | 408 | p.Alpha() = alphaOutline; |
6a93571d RD |
409 | p.MoveTo(pixData, x, r.height-1); |
410 | p.Red() = wxPy_premultiply(red, alphaOutline); | |
411 | p.Green() = wxPy_premultiply(green, alphaOutline); | |
412 | p.Blue() = wxPy_premultiply(blue, alphaOutline); | |
038c0333 | 413 | p.Alpha() = alphaOutline; |
6a93571d | 414 | } |
b8193d80 | 415 | |
6a93571d RD |
416 | for (y=0; y<r.height; y++) { |
417 | p.MoveTo(pixData, 0, y); | |
418 | p.Red() = wxPy_premultiply(red, alphaOutline); | |
419 | p.Green() = wxPy_premultiply(green, alphaOutline); | |
420 | p.Blue() = wxPy_premultiply(blue, alphaOutline); | |
038c0333 | 421 | p.Alpha() = alphaOutline; |
6a93571d RD |
422 | p.MoveTo(pixData, r.width-1, y); |
423 | p.Red() = wxPy_premultiply(red, alphaOutline); | |
424 | p.Green() = wxPy_premultiply(green, alphaOutline); | |
425 | p.Blue() = wxPy_premultiply(blue, alphaOutline); | |
038c0333 | 426 | p.Alpha() = alphaOutline; |
6a93571d | 427 | } |
038c0333 | 428 | |
6a93571d RD |
429 | // Draw the bitmap |
430 | hdc->DrawBitmap(bmp, r.x, r.y, true); | |
8b6c20ce RD |
431 | |
432 | #else | |
433 | wxUnusedVar(cornerSize); | |
434 | wxUnusedVar(alphaFill); | |
435 | wxUnusedVar(alphaOutline); | |
436 | RectangleDraw(rc, outline, fill); | |
437 | #endif | |
b8193d80 RD |
438 | } |
439 | ||
1a2fb4cd | 440 | void SurfaceImpl::Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back) { |
9ce192d4 | 441 | PenColour(fore); |
1a2fb4cd | 442 | BrushColour(back); |
9ce192d4 RD |
443 | hdc->DrawEllipse(wxRectFromPRectangle(rc)); |
444 | } | |
445 | ||
1a2fb4cd | 446 | void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) { |
f6bcfd97 BP |
447 | wxRect r = wxRectFromPRectangle(rc); |
448 | hdc->Blit(r.x, r.y, r.width, r.height, | |
1a2fb4cd RD |
449 | ((SurfaceImpl&)surfaceSource).hdc, |
450 | from.x, from.y, wxCOPY); | |
9ce192d4 RD |
451 | } |
452 | ||
1a2fb4cd RD |
453 | void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, int ybase, |
454 | const char *s, int len, | |
455 | ColourAllocated fore, ColourAllocated back) { | |
9ce192d4 | 456 | SetFont(font); |
1a2fb4cd RD |
457 | hdc->SetTextForeground(wxColourFromCA(fore)); |
458 | hdc->SetTextBackground(wxColourFromCA(back)); | |
3d7a4fe8 | 459 | FillRectangle(rc, back); |
9ce192d4 RD |
460 | |
461 | // ybase is where the baseline should be, but wxWin uses the upper left | |
462 | // corner, so I need to calculate the real position for the text... | |
d13ea3aa | 463 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
9ce192d4 RD |
464 | } |
465 | ||
1a2fb4cd RD |
466 | void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, |
467 | const char *s, int len, | |
468 | ColourAllocated fore, ColourAllocated back) { | |
9ce192d4 | 469 | SetFont(font); |
1a2fb4cd RD |
470 | hdc->SetTextForeground(wxColourFromCA(fore)); |
471 | hdc->SetTextBackground(wxColourFromCA(back)); | |
3d7a4fe8 | 472 | FillRectangle(rc, back); |
9ce192d4 RD |
473 | hdc->SetClippingRegion(wxRectFromPRectangle(rc)); |
474 | ||
475 | // see comments above | |
d13ea3aa | 476 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
3d7a4fe8 | 477 | hdc->DestroyClippingRegion(); |
9ce192d4 RD |
478 | } |
479 | ||
9e730a78 RD |
480 | |
481 | void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, int ybase, | |
482 | const char *s, int len, | |
483 | ColourAllocated fore) { | |
484 | ||
9ce192d4 | 485 | SetFont(font); |
9e730a78 | 486 | hdc->SetTextForeground(wxColourFromCA(fore)); |
cb129171 | 487 | hdc->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); |
1a2fb4cd | 488 | |
9e730a78 RD |
489 | // ybase is where the baseline should be, but wxWin uses the upper left |
490 | // corner, so I need to calculate the real position for the text... | |
d13ea3aa | 491 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
9e730a78 | 492 | |
cb129171 | 493 | hdc->SetBackgroundMode(wxBRUSHSTYLE_SOLID); |
9ce192d4 RD |
494 | } |
495 | ||
1a2fb4cd | 496 | |
10ef30eb | 497 | void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) { |
9e730a78 | 498 | |
d1558f3d RD |
499 | wxString str = stc2wx(s, len); |
500 | wxArrayInt tpos; | |
10ef30eb | 501 | |
d1558f3d | 502 | SetFont(font); |
9e730a78 | 503 | |
d1558f3d | 504 | hdc->GetPartialTextExtents(str, tpos); |
10ef30eb RD |
505 | |
506 | #if wxUSE_UNICODE | |
507 | // Map the widths for UCS-2 characters back to the UTF-8 input string | |
9e730a78 RD |
508 | // NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2 |
509 | // so figure it out and fix it! | |
d1558f3d | 510 | size_t i = 0; |
10ef30eb | 511 | size_t ui = 0; |
d99859e4 | 512 | while ((int)i < len) { |
10ef30eb RD |
513 | unsigned char uch = (unsigned char)s[i]; |
514 | positions[i++] = tpos[ui]; | |
515 | if (uch >= 0x80) { | |
516 | if (uch < (0x80 + 0x40 + 0x20)) { | |
517 | positions[i++] = tpos[ui]; | |
518 | } else { | |
519 | positions[i++] = tpos[ui]; | |
520 | positions[i++] = tpos[ui]; | |
521 | } | |
522 | } | |
523 | ui++; | |
524 | } | |
525 | #else | |
526 | ||
527 | // If not unicode then just use the widths we have | |
f3ee029e MB |
528 | #if wxUSE_STL |
529 | std::copy(tpos.begin(), tpos.end(), positions); | |
530 | #else | |
d1558f3d | 531 | memcpy(positions, tpos.begin(), len * sizeof(int)); |
10ef30eb | 532 | #endif |
f3ee029e | 533 | #endif |
9ce192d4 RD |
534 | } |
535 | ||
10ef30eb | 536 | |
9e730a78 RD |
537 | int SurfaceImpl::WidthText(Font &font, const char *s, int len) { |
538 | SetFont(font); | |
539 | int w; | |
540 | int h; | |
541 | ||
542 | hdc->GetTextExtent(stc2wx(s, len), &w, &h); | |
543 | return w; | |
544 | } | |
545 | ||
546 | ||
1a2fb4cd | 547 | int SurfaceImpl::WidthChar(Font &font, char ch) { |
9ce192d4 RD |
548 | SetFont(font); |
549 | int w; | |
550 | int h; | |
10ef30eb RD |
551 | char s[2] = { ch, 0 }; |
552 | ||
0c5b83b0 | 553 | hdc->GetTextExtent(stc2wx(s, 1), &w, &h); |
9ce192d4 RD |
554 | return w; |
555 | } | |
556 | ||
1a2fb4cd | 557 | #define EXTENT_TEST wxT(" `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
9ce192d4 | 558 | |
1a2fb4cd | 559 | int SurfaceImpl::Ascent(Font &font) { |
9ce192d4 RD |
560 | SetFont(font); |
561 | int w, h, d, e; | |
562 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
563 | font.ascent = h - d; | |
564 | return font.ascent; | |
565 | } | |
566 | ||
1a2fb4cd | 567 | int SurfaceImpl::Descent(Font &font) { |
9ce192d4 RD |
568 | SetFont(font); |
569 | int w, h, d, e; | |
570 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
571 | return d; | |
572 | } | |
573 | ||
88a8b04e | 574 | int SurfaceImpl::InternalLeading(Font &WXUNUSED(font)) { |
9ce192d4 RD |
575 | return 0; |
576 | } | |
577 | ||
1a2fb4cd | 578 | int SurfaceImpl::ExternalLeading(Font &font) { |
9ce192d4 RD |
579 | SetFont(font); |
580 | int w, h, d, e; | |
581 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
582 | return e; | |
583 | } | |
584 | ||
1a2fb4cd | 585 | int SurfaceImpl::Height(Font &font) { |
9ce192d4 | 586 | SetFont(font); |
d13ea3aa | 587 | return hdc->GetCharHeight() + 1; |
9ce192d4 RD |
588 | } |
589 | ||
1a2fb4cd | 590 | int SurfaceImpl::AverageCharWidth(Font &font) { |
9ce192d4 RD |
591 | SetFont(font); |
592 | return hdc->GetCharWidth(); | |
593 | } | |
594 | ||
88a8b04e | 595 | int SurfaceImpl::SetPalette(Palette *WXUNUSED(pal), bool WXUNUSED(inBackGround)) { |
65ec6247 | 596 | return 0; |
9ce192d4 RD |
597 | } |
598 | ||
1a2fb4cd | 599 | void SurfaceImpl::SetClip(PRectangle rc) { |
9ce192d4 RD |
600 | hdc->SetClippingRegion(wxRectFromPRectangle(rc)); |
601 | } | |
602 | ||
1a2fb4cd | 603 | void SurfaceImpl::FlushCachedState() { |
f6bcfd97 | 604 | } |
9ce192d4 | 605 | |
1a2fb4cd | 606 | void SurfaceImpl::SetUnicodeMode(bool unicodeMode_) { |
1a2fb4cd RD |
607 | unicodeMode=unicodeMode_; |
608 | } | |
609 | ||
88a8b04e | 610 | void SurfaceImpl::SetDBCSMode(int WXUNUSED(codePage)) { |
9e730a78 RD |
611 | // dbcsMode = codePage == SC_CP_DBCS; |
612 | } | |
613 | ||
614 | ||
1a2fb4cd RD |
615 | Surface *Surface::Allocate() { |
616 | return new SurfaceImpl; | |
617 | } | |
618 | ||
619 | ||
620 | //---------------------------------------------------------------------- | |
621 | ||
622 | ||
623 | inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; } | |
624 | ||
9ce192d4 RD |
625 | Window::~Window() { |
626 | } | |
627 | ||
628 | void Window::Destroy() { | |
9e730a78 | 629 | if (id) { |
7e126a07 | 630 | Show(false); |
1a2fb4cd | 631 | GETWIN(id)->Destroy(); |
9e730a78 | 632 | } |
9ce192d4 RD |
633 | id = 0; |
634 | } | |
635 | ||
636 | bool Window::HasFocus() { | |
1a2fb4cd | 637 | return wxWindow::FindFocus() == GETWIN(id); |
9ce192d4 RD |
638 | } |
639 | ||
640 | PRectangle Window::GetPosition() { | |
9e730a78 | 641 | if (! id) return PRectangle(); |
1a2fb4cd | 642 | wxRect rc(GETWIN(id)->GetPosition(), GETWIN(id)->GetSize()); |
9ce192d4 RD |
643 | return PRectangleFromwxRect(rc); |
644 | } | |
645 | ||
646 | void Window::SetPosition(PRectangle rc) { | |
f6bcfd97 | 647 | wxRect r = wxRectFromPRectangle(rc); |
1a2fb4cd | 648 | GETWIN(id)->SetSize(r); |
9ce192d4 RD |
649 | } |
650 | ||
651 | void Window::SetPositionRelative(PRectangle rc, Window) { | |
652 | SetPosition(rc); // ???? | |
653 | } | |
654 | ||
655 | PRectangle Window::GetClientPosition() { | |
9e730a78 | 656 | if (! id) return PRectangle(); |
1a2fb4cd | 657 | wxSize sz = GETWIN(id)->GetClientSize(); |
21156596 | 658 | return PRectangle(0, 0, sz.x, sz.y); |
9ce192d4 RD |
659 | } |
660 | ||
661 | void Window::Show(bool show) { | |
1a2fb4cd | 662 | GETWIN(id)->Show(show); |
9ce192d4 RD |
663 | } |
664 | ||
665 | void Window::InvalidateAll() { | |
1a2fb4cd | 666 | GETWIN(id)->Refresh(false); |
9ce192d4 RD |
667 | } |
668 | ||
669 | void Window::InvalidateRectangle(PRectangle rc) { | |
f6bcfd97 | 670 | wxRect r = wxRectFromPRectangle(rc); |
1a2fb4cd | 671 | GETWIN(id)->Refresh(false, &r); |
9ce192d4 RD |
672 | } |
673 | ||
674 | void Window::SetFont(Font &font) { | |
1a2fb4cd | 675 | GETWIN(id)->SetFont(*((wxFont*)font.GetID())); |
9ce192d4 RD |
676 | } |
677 | ||
678 | void Window::SetCursor(Cursor curs) { | |
d4f392ea | 679 | wxStockCursor cursorId; |
9ce192d4 RD |
680 | |
681 | switch (curs) { | |
682 | case cursorText: | |
683 | cursorId = wxCURSOR_IBEAM; | |
684 | break; | |
685 | case cursorArrow: | |
686 | cursorId = wxCURSOR_ARROW; | |
687 | break; | |
688 | case cursorUp: | |
689 | cursorId = wxCURSOR_ARROW; // ** no up arrow... wxCURSOR_UPARROW; | |
690 | break; | |
691 | case cursorWait: | |
692 | cursorId = wxCURSOR_WAIT; | |
693 | break; | |
694 | case cursorHoriz: | |
695 | cursorId = wxCURSOR_SIZEWE; | |
696 | break; | |
697 | case cursorVert: | |
698 | cursorId = wxCURSOR_SIZENS; | |
699 | break; | |
700 | case cursorReverseArrow: | |
15dadf31 | 701 | cursorId = wxCURSOR_RIGHT_ARROW; |
9ce192d4 | 702 | break; |
9e730a78 RD |
703 | case cursorHand: |
704 | cursorId = wxCURSOR_HAND; | |
1e545382 | 705 | break; |
9ce192d4 RD |
706 | default: |
707 | cursorId = wxCURSOR_ARROW; | |
708 | break; | |
709 | } | |
d4f392ea FM |
710 | |
711 | wxCursor wc = wxCursor(cursorId); | |
712 | if(curs != cursorLast) | |
713 | { | |
714 | GETWIN(id)->SetCursor(wc); | |
715 | cursorLast = curs; | |
716 | } | |
9ce192d4 RD |
717 | } |
718 | ||
719 | ||
720 | void Window::SetTitle(const char *s) { | |
fd39aa23 | 721 | GETWIN(id)->SetLabel(stc2wx(s)); |
9ce192d4 RD |
722 | } |
723 | ||
724 | ||
7e0c58e9 RD |
725 | // Returns rectangle of monitor pt is on |
726 | PRectangle Window::GetMonitorRect(Point pt) { | |
727 | wxRect rect; | |
728 | if (! id) return PRectangle(); | |
729 | #if wxUSE_DISPLAY | |
730 | // Get the display the point is found on | |
731 | int n = wxDisplay::GetFromPoint(wxPoint(pt.x, pt.y)); | |
732 | wxDisplay dpy(n == wxNOT_FOUND ? 0 : n); | |
733 | rect = dpy.GetGeometry(); | |
734 | #endif | |
735 | return PRectangleFromwxRect(rect); | |
736 | } | |
737 | ||
769a9cb2 RD |
738 | //---------------------------------------------------------------------- |
739 | // Helper classes for ListBox | |
740 | ||
267484bc | 741 | |
b0d0494f | 742 | // This is a simple subclass of wxListView that just resets focus to the |
9e730a78 RD |
743 | // parent when it gets it. |
744 | class wxSTCListBox : public wxListView { | |
451c5cc7 | 745 | public: |
9e730a78 RD |
746 | wxSTCListBox(wxWindow* parent, wxWindowID id, |
747 | const wxPoint& pos, const wxSize& size, | |
748 | long style) | |
382fe640 RD |
749 | : wxListView() |
750 | { | |
751 | #ifdef __WXMSW__ | |
752 | Hide(); // don't flicker as we move it around... | |
753 | #endif | |
754 | Create(parent, id, pos, size, style); | |
755 | } | |
451c5cc7 | 756 | |
7e126a07 | 757 | |
451c5cc7 RD |
758 | void OnFocus(wxFocusEvent& event) { |
759 | GetParent()->SetFocus(); | |
760 | event.Skip(); | |
761 | } | |
762 | ||
5f9eb69c | 763 | void OnKillFocus(wxFocusEvent& WXUNUSED(event)) { |
b0d0494f RD |
764 | // Do nothing. Prevents base class from resetting the colors... |
765 | } | |
7e126a07 | 766 | |
719ee9c3 RD |
767 | #ifdef __WXMAC__ |
768 | // For some reason I don't understand yet the focus doesn't really leave | |
769 | // the listbox like it should, so if we get any events feed them back to | |
770 | // the wxSTC | |
771 | void OnKeyDown(wxKeyEvent& event) { | |
772 | GetGrandParent()->GetEventHandler()->ProcessEvent(event); | |
773 | } | |
774 | void OnChar(wxKeyEvent& event) { | |
775 | GetGrandParent()->GetEventHandler()->ProcessEvent(event); | |
776 | } | |
b0d0494f | 777 | |
719ee9c3 RD |
778 | // And we need to force the focus back when being destroyed |
779 | ~wxSTCListBox() { | |
780 | GetGrandParent()->SetFocus(); | |
7e126a07 WS |
781 | } |
782 | #endif | |
783 | ||
451c5cc7 RD |
784 | private: |
785 | DECLARE_EVENT_TABLE() | |
786 | }; | |
787 | ||
9e730a78 RD |
788 | BEGIN_EVENT_TABLE(wxSTCListBox, wxListView) |
789 | EVT_SET_FOCUS( wxSTCListBox::OnFocus) | |
b0d0494f | 790 | EVT_KILL_FOCUS(wxSTCListBox::OnKillFocus) |
719ee9c3 RD |
791 | #ifdef __WXMAC__ |
792 | EVT_KEY_DOWN( wxSTCListBox::OnKeyDown) | |
793 | EVT_CHAR( wxSTCListBox::OnChar) | |
794 | #endif | |
451c5cc7 RD |
795 | END_EVENT_TABLE() |
796 | ||
797 | ||
798 | ||
d35ad26e | 799 | #if wxUSE_POPUPWIN //----------------------------------- |
819850ff | 800 | #include "wx/popupwin.h" |
382fe640 RD |
801 | |
802 | ||
803 | // | |
804 | // TODO: Refactor these two classes to have a common base (or a mix-in) to get | |
805 | // rid of the code duplication. (Either that or convince somebody to | |
806 | // implement wxPopupWindow for the Mac!!) | |
807 | // | |
808 | // In the meantime, be careful to duplicate any changes as needed... | |
d35ad26e WS |
809 | // |
810 | ||
811 | // A popup window to place the wxSTCListBox upon | |
382fe640 RD |
812 | class wxSTCListBoxWin : public wxPopupWindow |
813 | { | |
814 | private: | |
815 | wxListView* lv; | |
816 | CallBackAction doubleClickAction; | |
817 | void* doubleClickActionData; | |
818 | public: | |
d35ad26e | 819 | wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point WXUNUSED(location)) : |
382fe640 RD |
820 | wxPopupWindow(parent, wxBORDER_NONE) |
821 | { | |
038c0333 | 822 | |
382fe640 RD |
823 | SetBackgroundColour(*wxBLACK); // for our simple border |
824 | ||
67879c5b | 825 | lv = new wxSTCListBox(parent, id, wxPoint(-50,-50), wxDefaultSize, |
382fe640 RD |
826 | wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxBORDER_NONE); |
827 | lv->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
828 | lv->InsertColumn(0, wxEmptyString); | |
829 | lv->InsertColumn(1, wxEmptyString); | |
830 | ||
831 | // NOTE: We need to fool the wxListView into thinking that it has the | |
832 | // focus so it will use the normal selection colour and will look | |
833 | // "right" to the user. But since the wxPopupWindow or its children | |
834 | // can't receive focus then we have to pull a fast one and temporarily | |
835 | // parent the listctrl on the STC window and then call SetFocus and | |
d35ad26e | 836 | // then reparent it back to the popup. |
382fe640 RD |
837 | lv->SetFocus(); |
838 | lv->Reparent(this); | |
839 | #ifdef __WXMSW__ | |
840 | lv->Show(); | |
841 | #endif | |
842 | } | |
843 | ||
844 | ||
845 | // Set position in client coords | |
846 | virtual void DoSetSize(int x, int y, | |
847 | int width, int height, | |
848 | int sizeFlags = wxSIZE_AUTO) { | |
849 | if (x != wxDefaultCoord) { | |
850 | GetParent()->ClientToScreen(&x, NULL); | |
851 | } | |
852 | if (y != wxDefaultCoord) { | |
853 | GetParent()->ClientToScreen(NULL, &y); | |
854 | } | |
855 | wxPopupWindow::DoSetSize(x, y, width, height, sizeFlags); | |
856 | } | |
857 | ||
858 | // return position as if it were in client coords | |
859 | virtual void DoGetPosition( int *x, int *y ) const { | |
860 | int sx, sy; | |
861 | wxPopupWindow::DoGetPosition(&sx, &sy); | |
862 | GetParent()->ScreenToClient(&sx, &sy); | |
863 | if (x) *x = sx; | |
864 | if (y) *y = sy; | |
865 | } | |
866 | ||
867 | ||
868 | bool Destroy() { | |
869 | if ( !wxPendingDelete.Member(this) ) | |
870 | wxPendingDelete.Append(this); | |
871 | return true; | |
872 | } | |
873 | ||
874 | ||
875 | int IconWidth() { | |
876 | wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL); | |
877 | if (il != NULL) { | |
878 | int w, h; | |
879 | il->GetSize(0, w, h); | |
880 | return w; | |
881 | } | |
882 | return 0; | |
883 | } | |
884 | ||
885 | ||
886 | void SetDoubleClickAction(CallBackAction action, void *data) { | |
887 | doubleClickAction = action; | |
888 | doubleClickActionData = data; | |
889 | } | |
890 | ||
891 | ||
892 | void OnFocus(wxFocusEvent& event) { | |
893 | GetParent()->SetFocus(); | |
894 | event.Skip(); | |
895 | } | |
896 | ||
897 | void OnSize(wxSizeEvent& event) { | |
898 | // resize the child | |
899 | wxSize sz = GetSize(); | |
900 | sz.x -= 2; | |
901 | sz.y -= 2; | |
902 | lv->SetSize(1, 1, sz.x, sz.y); | |
903 | // reset the column widths | |
904 | lv->SetColumnWidth(0, IconWidth()+4); | |
905 | lv->SetColumnWidth(1, sz.x - 2 - lv->GetColumnWidth(0) - | |
906 | wxSystemSettings::GetMetric(wxSYS_VSCROLL_X)); | |
907 | event.Skip(); | |
908 | } | |
909 | ||
910 | void OnActivate(wxListEvent& WXUNUSED(event)) { | |
911 | doubleClickAction(doubleClickActionData); | |
912 | } | |
913 | ||
914 | wxListView* GetLB() { return lv; } | |
915 | ||
916 | private: | |
917 | DECLARE_EVENT_TABLE() | |
918 | ||
919 | }; | |
920 | ||
921 | BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxPopupWindow) | |
922 | EVT_SET_FOCUS ( wxSTCListBoxWin::OnFocus) | |
923 | EVT_SIZE ( wxSTCListBoxWin::OnSize) | |
924 | EVT_LIST_ITEM_ACTIVATED(wxID_ANY, wxSTCListBoxWin::OnActivate) | |
925 | END_EVENT_TABLE() | |
926 | ||
d35ad26e | 927 | |
382fe640 | 928 | |
67879c5b | 929 | #else // !wxUSE_POPUPWIN ----------------------------------- |
819850ff | 930 | #include "wx/frame.h" |
267484bc | 931 | |
67879c5b RD |
932 | // A normal window to place the wxSTCListBox upon, but make it behave as much |
933 | // like a wxPopupWindow as possible | |
934 | class wxSTCListBoxWin : public wxFrame { | |
9e730a78 RD |
935 | private: |
936 | wxListView* lv; | |
937 | CallBackAction doubleClickAction; | |
938 | void* doubleClickActionData; | |
f97d84a6 | 939 | public: |
1e9bafca | 940 | wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point location) : |
67879c5b RD |
941 | wxFrame(parent, id, wxEmptyString, wxPoint(location.x, location.y), wxSize(0,0), |
942 | wxFRAME_NO_TASKBAR | |
943 | | wxFRAME_FLOAT_ON_PARENT | |
944 | #ifdef __WXMAC__ | |
038c0333 | 945 | | wxPOPUP_WINDOW |
67879c5b RD |
946 | | wxNO_BORDER |
947 | #else | |
948 | | wxSIMPLE_BORDER | |
949 | #endif | |
950 | ) | |
9e730a78 RD |
951 | { |
952 | ||
9e730a78 RD |
953 | lv = new wxSTCListBox(this, id, wxDefaultPosition, wxDefaultSize, |
954 | wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxNO_BORDER); | |
955 | lv->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
956 | lv->InsertColumn(0, wxEmptyString); | |
957 | lv->InsertColumn(1, wxEmptyString); | |
b0d0494f RD |
958 | |
959 | // Eventhough we immediately reset the focus to the parent, this helps | |
960 | // things to look right... | |
961 | lv->SetFocus(); | |
962 | ||
6612393c | 963 | Hide(); |
038c0333 | 964 | } |
6612393c | 965 | |
7e126a07 | 966 | |
a4f3565e RD |
967 | // On OSX and (possibly others) there can still be pending |
968 | // messages/events for the list control when Scintilla wants to | |
969 | // close it, so do a pending delete of it instead of destroying | |
970 | // immediately. | |
67879c5b RD |
971 | bool Destroy() |
972 | { | |
d13ea3aa | 973 | #ifdef __WXMAC__ |
719ee9c3 | 974 | // The bottom edge of this window is not getting properly |
d13ea3aa RD |
975 | // refreshed upon deletion, so help it out... |
976 | wxWindow* p = GetParent(); | |
977 | wxRect r(GetPosition(), GetSize()); | |
978 | r.SetHeight(r.GetHeight()+1); | |
979 | p->Refresh(false, &r); | |
980 | #endif | |
a4f3565e RD |
981 | if ( !wxPendingDelete.Member(this) ) |
982 | wxPendingDelete.Append(this); | |
7e126a07 | 983 | return true; |
f97d84a6 RD |
984 | } |
985 | ||
7e126a07 | 986 | |
67879c5b RD |
987 | int IconWidth() |
988 | { | |
9e730a78 RD |
989 | wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL); |
990 | if (il != NULL) { | |
991 | int w, h; | |
992 | il->GetSize(0, w, h); | |
993 | return w; | |
994 | } | |
995 | return 0; | |
996 | } | |
f97d84a6 | 997 | |
769a9cb2 | 998 | |
67879c5b RD |
999 | void SetDoubleClickAction(CallBackAction action, void *data) |
1000 | { | |
9e730a78 RD |
1001 | doubleClickAction = action; |
1002 | doubleClickActionData = data; | |
1003 | } | |
451c5cc7 | 1004 | |
769a9cb2 | 1005 | |
67879c5b RD |
1006 | void OnFocus(wxFocusEvent& event) |
1007 | { | |
1008 | ActivateParent(); | |
9e730a78 RD |
1009 | GetParent()->SetFocus(); |
1010 | event.Skip(); | |
1011 | } | |
769a9cb2 | 1012 | |
67879c5b RD |
1013 | void OnSize(wxSizeEvent& event) |
1014 | { | |
d13ea3aa | 1015 | // resize the child |
9e730a78 | 1016 | wxSize sz = GetClientSize(); |
d13ea3aa | 1017 | lv->SetSize(sz); |
9e730a78 RD |
1018 | // reset the column widths |
1019 | lv->SetColumnWidth(0, IconWidth()+4); | |
1020 | lv->SetColumnWidth(1, sz.x - 2 - lv->GetColumnWidth(0) - | |
1021 | wxSystemSettings::GetMetric(wxSYS_VSCROLL_X)); | |
1022 | event.Skip(); | |
769a9cb2 | 1023 | } |
769a9cb2 | 1024 | |
67879c5b RD |
1025 | void ActivateParent() |
1026 | { | |
1027 | // Although we're a frame, we always want the parent to be active, so | |
1028 | // raise it whenever we get shown, focused, etc. | |
1029 | wxTopLevelWindow *frame = wxDynamicCast( | |
1030 | wxGetTopLevelParent(GetParent()), wxTopLevelWindow); | |
1031 | if (frame) | |
1032 | frame->Raise(); | |
1033 | } | |
038c0333 | 1034 | |
67879c5b RD |
1035 | |
1036 | virtual void DoSetSize(int x, int y, | |
1037 | int width, int height, | |
1038 | int sizeFlags = wxSIZE_AUTO) | |
1039 | { | |
1040 | // convert coords to screen coords since we're a top-level window | |
1041 | if (x != wxDefaultCoord) { | |
1042 | GetParent()->ClientToScreen(&x, NULL); | |
1043 | } | |
1044 | if (y != wxDefaultCoord) { | |
1045 | GetParent()->ClientToScreen(NULL, &y); | |
1046 | } | |
1047 | wxFrame::DoSetSize(x, y, width, height, sizeFlags); | |
1048 | } | |
1049 | ||
1050 | virtual bool Show(bool show = true) | |
1051 | { | |
1052 | bool rv = wxFrame::Show(show); | |
1053 | if (rv && show) | |
1054 | ActivateParent(); | |
719493e1 | 1055 | #ifdef __WXMAC__ |
719493e1 | 1056 | GetParent()->Refresh(false); |
67879c5b | 1057 | #endif |
719493e1 RD |
1058 | return rv; |
1059 | } | |
d35ad26e | 1060 | |
67879c5b RD |
1061 | void OnActivate(wxListEvent& WXUNUSED(event)) |
1062 | { | |
9e730a78 | 1063 | doubleClickAction(doubleClickActionData); |
769a9cb2 | 1064 | } |
9e730a78 RD |
1065 | |
1066 | wxListView* GetLB() { return lv; } | |
769a9cb2 RD |
1067 | |
1068 | private: | |
769a9cb2 RD |
1069 | DECLARE_EVENT_TABLE() |
1070 | }; | |
1071 | ||
9e730a78 RD |
1072 | |
1073 | BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxWindow) | |
7e126a07 WS |
1074 | EVT_SET_FOCUS ( wxSTCListBoxWin::OnFocus) |
1075 | EVT_SIZE ( wxSTCListBoxWin::OnSize) | |
1076 | EVT_LIST_ITEM_ACTIVATED(wxID_ANY, wxSTCListBoxWin::OnActivate) | |
769a9cb2 | 1077 | END_EVENT_TABLE() |
769a9cb2 | 1078 | |
382fe640 | 1079 | #endif // wxUSE_POPUPWIN ----------------------------------- |
9e730a78 RD |
1080 | |
1081 | ||
1082 | inline wxSTCListBoxWin* GETLBW(WindowID win) { | |
1083 | return ((wxSTCListBoxWin*)win); | |
1084 | } | |
1085 | ||
1086 | inline wxListView* GETLB(WindowID win) { | |
1087 | return GETLBW(win)->GetLB(); | |
1a2fb4cd | 1088 | } |
769a9cb2 RD |
1089 | |
1090 | //---------------------------------------------------------------------- | |
1091 | ||
9e730a78 RD |
1092 | class ListBoxImpl : public ListBox { |
1093 | private: | |
1094 | int lineHeight; | |
1095 | bool unicodeMode; | |
1096 | int desiredVisibleRows; | |
1097 | int aveCharWidth; | |
80cac95e | 1098 | size_t maxStrWidth; |
1e9bafca | 1099 | Point location; // Caret location at which the list is opened |
9e730a78 RD |
1100 | wxImageList* imgList; |
1101 | wxArrayInt* imgTypeMap; | |
1102 | ||
1103 | public: | |
1104 | ListBoxImpl(); | |
1105 | ~ListBoxImpl(); | |
1106 | ||
1107 | virtual void SetFont(Font &font); | |
1e9bafca | 1108 | virtual void Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_); |
9e730a78 RD |
1109 | virtual void SetAverageCharWidth(int width); |
1110 | virtual void SetVisibleRows(int rows); | |
1e9bafca | 1111 | virtual int GetVisibleRows() const; |
9e730a78 RD |
1112 | virtual PRectangle GetDesiredRect(); |
1113 | virtual int CaretFromEdge(); | |
1114 | virtual void Clear(); | |
1115 | virtual void Append(char *s, int type = -1); | |
1e9bafca | 1116 | void Append(const wxString& text, int type); |
9e730a78 RD |
1117 | virtual int Length(); |
1118 | virtual void Select(int n); | |
1119 | virtual int GetSelection(); | |
1120 | virtual int Find(const char *prefix); | |
1121 | virtual void GetValue(int n, char *value, int len); | |
9e730a78 RD |
1122 | virtual void RegisterImage(int type, const char *xpm_data); |
1123 | virtual void ClearRegisteredImages(); | |
1124 | virtual void SetDoubleClickAction(CallBackAction, void *); | |
1e9bafca | 1125 | virtual void SetList(const char* list, char separator, char typesep); |
9e730a78 RD |
1126 | }; |
1127 | ||
1128 | ||
1129 | ListBoxImpl::ListBoxImpl() | |
1130 | : lineHeight(10), unicodeMode(false), | |
1131 | desiredVisibleRows(5), aveCharWidth(8), maxStrWidth(0), | |
1132 | imgList(NULL), imgTypeMap(NULL) | |
1133 | { | |
9ce192d4 RD |
1134 | } |
1135 | ||
9e730a78 RD |
1136 | ListBoxImpl::~ListBoxImpl() { |
1137 | if (imgList) { | |
1138 | delete imgList; | |
1139 | imgList = NULL; | |
1140 | } | |
1141 | if (imgTypeMap) { | |
1142 | delete imgTypeMap; | |
1143 | imgTypeMap = NULL; | |
1144 | } | |
9ce192d4 RD |
1145 | } |
1146 | ||
9e730a78 RD |
1147 | |
1148 | void ListBoxImpl::SetFont(Font &font) { | |
1149 | GETLB(id)->SetFont(*((wxFont*)font.GetID())); | |
1150 | } | |
1151 | ||
1152 | ||
1e9bafca RD |
1153 | void ListBoxImpl::Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_) { |
1154 | location = location_; | |
9e730a78 RD |
1155 | lineHeight = lineHeight_; |
1156 | unicodeMode = unicodeMode_; | |
1157 | maxStrWidth = 0; | |
1e9bafca | 1158 | id = new wxSTCListBoxWin(GETWIN(parent.GetID()), ctrlID, location); |
9e730a78 RD |
1159 | if (imgList != NULL) |
1160 | GETLB(id)->SetImageList(imgList, wxIMAGE_LIST_SMALL); | |
9ce192d4 RD |
1161 | } |
1162 | ||
9e730a78 RD |
1163 | |
1164 | void ListBoxImpl::SetAverageCharWidth(int width) { | |
1165 | aveCharWidth = width; | |
1166 | } | |
1167 | ||
1168 | ||
1169 | void ListBoxImpl::SetVisibleRows(int rows) { | |
769a9cb2 | 1170 | desiredVisibleRows = rows; |
f3c2c221 RD |
1171 | } |
1172 | ||
9e730a78 | 1173 | |
1e9bafca RD |
1174 | int ListBoxImpl::GetVisibleRows() const { |
1175 | return desiredVisibleRows; | |
1176 | } | |
1177 | ||
9e730a78 RD |
1178 | PRectangle ListBoxImpl::GetDesiredRect() { |
1179 | // wxListCtrl doesn't have a DoGetBestSize, so instead we kept track of | |
1180 | // the max size in Append and calculate it here... | |
1e9bafca | 1181 | int maxw = maxStrWidth * aveCharWidth; |
1e545382 | 1182 | int maxh ; |
9e730a78 RD |
1183 | |
1184 | // give it a default if there are no lines, and/or add a bit more | |
1185 | if (maxw == 0) maxw = 100; | |
1186 | maxw += aveCharWidth * 3 + | |
1187 | GETLBW(id)->IconWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); | |
1188 | if (maxw > 350) | |
1189 | maxw = 350; | |
1190 | ||
1191 | // estimate a desired height | |
1192 | int count = GETLB(id)->GetItemCount(); | |
1193 | if (count) { | |
1194 | wxRect rect; | |
1195 | GETLB(id)->GetItemRect(0, rect); | |
1196 | maxh = count * rect.GetHeight(); | |
1197 | if (maxh > 140) // TODO: Use desiredVisibleRows?? | |
1198 | maxh = 140; | |
1199 | ||
1200 | // Try to make the size an exact multiple of some number of lines | |
1201 | int lines = maxh / rect.GetHeight(); | |
1202 | maxh = (lines + 1) * rect.GetHeight() + 2; | |
1203 | } | |
1204 | else | |
1205 | maxh = 100; | |
1206 | ||
d134f170 RD |
1207 | PRectangle rc; |
1208 | rc.top = 0; | |
1209 | rc.left = 0; | |
9e730a78 RD |
1210 | rc.right = maxw; |
1211 | rc.bottom = maxh; | |
d134f170 RD |
1212 | return rc; |
1213 | } | |
1214 | ||
d134f170 | 1215 | |
9e730a78 RD |
1216 | int ListBoxImpl::CaretFromEdge() { |
1217 | return 4 + GETLBW(id)->IconWidth(); | |
d134f170 RD |
1218 | } |
1219 | ||
9e730a78 RD |
1220 | |
1221 | void ListBoxImpl::Clear() { | |
1222 | GETLB(id)->DeleteAllItems(); | |
9ce192d4 RD |
1223 | } |
1224 | ||
9e730a78 RD |
1225 | |
1226 | void ListBoxImpl::Append(char *s, int type) { | |
1e9bafca RD |
1227 | Append(stc2wx(s), type); |
1228 | } | |
1229 | ||
1230 | void ListBoxImpl::Append(const wxString& text, int type) { | |
9e730a78 RD |
1231 | long count = GETLB(id)->GetItemCount(); |
1232 | long itemID = GETLB(id)->InsertItem(count, wxEmptyString); | |
038c0333 | 1233 | long idx = -1; |
9e730a78 | 1234 | GETLB(id)->SetItem(itemID, 1, text); |
d35ad26e | 1235 | maxStrWidth = wxMax(maxStrWidth, text.length()); |
9e730a78 RD |
1236 | if (type != -1) { |
1237 | wxCHECK_RET(imgTypeMap, wxT("Unexpected NULL imgTypeMap")); | |
d67c3388 | 1238 | idx = imgTypeMap->Item(type); |
9e730a78 | 1239 | } |
d67c3388 | 1240 | GETLB(id)->SetItemImage(itemID, idx, idx); |
9ce192d4 RD |
1241 | } |
1242 | ||
1e9bafca RD |
1243 | void ListBoxImpl::SetList(const char* list, char separator, char typesep) { |
1244 | GETLB(id)->Freeze(); | |
d35ad26e | 1245 | Clear(); |
1e9bafca RD |
1246 | wxStringTokenizer tkzr(stc2wx(list), (wxChar)separator); |
1247 | while ( tkzr.HasMoreTokens() ) { | |
1248 | wxString token = tkzr.GetNextToken(); | |
1249 | long type = -1; | |
1250 | int pos = token.Find(typesep); | |
1251 | if (pos != -1) { | |
1252 | token.Mid(pos+1).ToLong(&type); | |
1253 | token.Truncate(pos); | |
1254 | } | |
1255 | Append(token, (int)type); | |
1256 | } | |
1257 | GETLB(id)->Thaw(); | |
1258 | } | |
1259 | ||
9e730a78 RD |
1260 | |
1261 | int ListBoxImpl::Length() { | |
1262 | return GETLB(id)->GetItemCount(); | |
9ce192d4 RD |
1263 | } |
1264 | ||
9e730a78 RD |
1265 | |
1266 | void ListBoxImpl::Select(int n) { | |
7e126a07 | 1267 | bool select = true; |
895066d8 RD |
1268 | if (n == -1) { |
1269 | n = 0; | |
7e126a07 | 1270 | select = false; |
895066d8 | 1271 | } |
67879c5b | 1272 | GETLB(id)->EnsureVisible(n); |
9e730a78 | 1273 | GETLB(id)->Select(n, select); |
9ce192d4 RD |
1274 | } |
1275 | ||
9e730a78 RD |
1276 | |
1277 | int ListBoxImpl::GetSelection() { | |
1278 | return GETLB(id)->GetFirstSelected(); | |
9ce192d4 RD |
1279 | } |
1280 | ||
9e730a78 | 1281 | |
88a8b04e | 1282 | int ListBoxImpl::Find(const char *WXUNUSED(prefix)) { |
b8b0e402 | 1283 | // No longer used |
7e126a07 | 1284 | return wxNOT_FOUND; |
9ce192d4 RD |
1285 | } |
1286 | ||
9e730a78 RD |
1287 | |
1288 | void ListBoxImpl::GetValue(int n, char *value, int len) { | |
1289 | wxListItem item; | |
1290 | item.SetId(n); | |
1291 | item.SetColumn(1); | |
1292 | item.SetMask(wxLIST_MASK_TEXT); | |
1293 | GETLB(id)->GetItem(item); | |
1294 | strncpy(value, wx2stc(item.GetText()), len); | |
9ce192d4 RD |
1295 | value[len-1] = '\0'; |
1296 | } | |
1297 | ||
9e730a78 RD |
1298 | |
1299 | void ListBoxImpl::RegisterImage(int type, const char *xpm_data) { | |
1300 | wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1); | |
c8b75e94 WS |
1301 | wxImage img(stream, wxBITMAP_TYPE_XPM); |
1302 | wxBitmap bmp(img); | |
9e730a78 RD |
1303 | |
1304 | if (! imgList) { | |
1305 | // assumes all images are the same size | |
7e126a07 | 1306 | imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight(), true); |
9e730a78 RD |
1307 | imgTypeMap = new wxArrayInt; |
1308 | } | |
1309 | ||
1310 | int idx = imgList->Add(bmp); | |
1311 | ||
1312 | // do we need to extend the mapping array? | |
1313 | wxArrayInt& itm = *imgTypeMap; | |
9a8ffadd | 1314 | if ( itm.GetCount() < (size_t)type+1) |
9e730a78 RD |
1315 | itm.Add(-1, type - itm.GetCount() + 1); |
1316 | ||
1317 | // Add an item that maps type to the image index | |
1318 | itm[type] = idx; | |
1319 | } | |
1320 | ||
1321 | void ListBoxImpl::ClearRegisteredImages() { | |
1322 | if (imgList) { | |
1323 | delete imgList; | |
1324 | imgList = NULL; | |
1325 | } | |
1326 | if (imgTypeMap) { | |
1327 | delete imgTypeMap; | |
1328 | imgTypeMap = NULL; | |
1329 | } | |
1330 | if (id) | |
1331 | GETLB(id)->SetImageList(NULL, wxIMAGE_LIST_SMALL); | |
1332 | } | |
1333 | ||
1334 | ||
1335 | void ListBoxImpl::SetDoubleClickAction(CallBackAction action, void *data) { | |
1336 | GETLBW(id)->SetDoubleClickAction(action, data); | |
1337 | } | |
1338 | ||
1339 | ||
9e730a78 RD |
1340 | ListBox::ListBox() { |
1341 | } | |
1342 | ||
1343 | ListBox::~ListBox() { | |
1344 | } | |
1345 | ||
1346 | ListBox *ListBox::Allocate() { | |
1347 | return new ListBoxImpl(); | |
9ce192d4 RD |
1348 | } |
1349 | ||
1a2fb4cd | 1350 | //---------------------------------------------------------------------- |
9ce192d4 RD |
1351 | |
1352 | Menu::Menu() : id(0) { | |
1353 | } | |
1354 | ||
1355 | void Menu::CreatePopUp() { | |
1356 | Destroy(); | |
1357 | id = new wxMenu(); | |
1358 | } | |
1359 | ||
1360 | void Menu::Destroy() { | |
1361 | if (id) | |
1a2fb4cd | 1362 | delete (wxMenu*)id; |
9ce192d4 RD |
1363 | id = 0; |
1364 | } | |
1365 | ||
1366 | void Menu::Show(Point pt, Window &w) { | |
1a2fb4cd | 1367 | GETWIN(w.GetID())->PopupMenu((wxMenu*)id, pt.x - 4, pt.y); |
9ce192d4 RD |
1368 | Destroy(); |
1369 | } | |
1370 | ||
1a2fb4cd | 1371 | //---------------------------------------------------------------------- |
9ce192d4 | 1372 | |
88a8b04e | 1373 | DynamicLibrary *DynamicLibrary::Load(const char *WXUNUSED(modulePath)) { |
e14d10b0 RD |
1374 | wxFAIL_MSG(wxT("Dynamic lexer loading not implemented yet")); |
1375 | return NULL; | |
1376 | } | |
1377 | ||
1378 | //---------------------------------------------------------------------- | |
1379 | ||
1a2fb4cd | 1380 | ColourDesired Platform::Chrome() { |
9ce192d4 | 1381 | wxColour c; |
e1c6c6ae | 1382 | c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
1a2fb4cd | 1383 | return ColourDesired(c.Red(), c.Green(), c.Blue()); |
9ce192d4 RD |
1384 | } |
1385 | ||
1a2fb4cd | 1386 | ColourDesired Platform::ChromeHighlight() { |
9ce192d4 | 1387 | wxColour c; |
e1c6c6ae | 1388 | c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT); |
1a2fb4cd | 1389 | return ColourDesired(c.Red(), c.Green(), c.Blue()); |
9ce192d4 RD |
1390 | } |
1391 | ||
1392 | const char *Platform::DefaultFont() { | |
10ef30eb RD |
1393 | static char buf[128]; |
1394 | strcpy(buf, wxNORMAL_FONT->GetFaceName().mbc_str()); | |
1395 | return buf; | |
9ce192d4 RD |
1396 | } |
1397 | ||
1398 | int Platform::DefaultFontSize() { | |
9e730a78 | 1399 | return wxNORMAL_FONT->GetPointSize(); |
9ce192d4 RD |
1400 | } |
1401 | ||
1402 | unsigned int Platform::DoubleClickTime() { | |
1403 | return 500; // **** ::GetDoubleClickTime(); | |
1404 | } | |
1405 | ||
9e730a78 | 1406 | bool Platform::MouseButtonBounce() { |
7e126a07 | 1407 | return false; |
9e730a78 | 1408 | } |
9ce192d4 | 1409 | |
88a8b04e | 1410 | bool Platform::IsKeyDown(int WXUNUSED(key)) { |
9ce192d4 RD |
1411 | return false; // I don't think we'll need this. |
1412 | } | |
1413 | ||
1414 | long Platform::SendScintilla(WindowID w, | |
1415 | unsigned int msg, | |
1416 | unsigned long wParam, | |
1417 | long lParam) { | |
1418 | ||
1419 | wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w; | |
1420 | return stc->SendMsg(msg, wParam, lParam); | |
1421 | } | |
1422 | ||
a834585d RD |
1423 | long Platform::SendScintillaPointer(WindowID w, |
1424 | unsigned int msg, | |
1425 | unsigned long wParam, | |
1426 | void *lParam) { | |
1427 | ||
1428 | wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w; | |
b796ba39 | 1429 | return stc->SendMsg(msg, wParam, (wxIntPtr)lParam); |
a834585d RD |
1430 | } |
1431 | ||
9ce192d4 RD |
1432 | |
1433 | // These are utility functions not really tied to a platform | |
1434 | ||
1435 | int Platform::Minimum(int a, int b) { | |
1436 | if (a < b) | |
1437 | return a; | |
1438 | else | |
1439 | return b; | |
1440 | } | |
1441 | ||
1442 | int Platform::Maximum(int a, int b) { | |
1443 | if (a > b) | |
1444 | return a; | |
1445 | else | |
1446 | return b; | |
1447 | } | |
1448 | ||
74e1efdd VZ |
1449 | //#define TRACE |
1450 | ||
1451 | void Platform::DebugDisplay(const char *s) { | |
1452 | #ifdef TRACE | |
1453 | wxLogDebug(stc2wx(s)); | |
1454 | #else | |
1455 | wxUnusedVar(s); | |
1456 | #endif | |
1457 | } | |
9ce192d4 RD |
1458 | |
1459 | void Platform::DebugPrintf(const char *format, ...) { | |
1460 | #ifdef TRACE | |
1461 | char buffer[2000]; | |
1462 | va_list pArguments; | |
1463 | va_start(pArguments, format); | |
1464 | vsprintf(buffer,format,pArguments); | |
1465 | va_end(pArguments); | |
1466 | Platform::DebugDisplay(buffer); | |
8d3a5374 VZ |
1467 | #else |
1468 | wxUnusedVar(format); | |
9ce192d4 RD |
1469 | #endif |
1470 | } | |
1471 | ||
65ec6247 RD |
1472 | |
1473 | static bool assertionPopUps = true; | |
1474 | ||
1475 | bool Platform::ShowAssertionPopUps(bool assertionPopUps_) { | |
7e126a07 WS |
1476 | bool ret = assertionPopUps; |
1477 | assertionPopUps = assertionPopUps_; | |
1478 | return ret; | |
65ec6247 RD |
1479 | } |
1480 | ||
1481 | void Platform::Assert(const char *c, const char *file, int line) { | |
74e1efdd | 1482 | #ifdef TRACE |
7e126a07 WS |
1483 | char buffer[2000]; |
1484 | sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line); | |
1485 | if (assertionPopUps) { | |
1486 | /*int idButton = */ | |
1487 | wxMessageBox(stc2wx(buffer), | |
1488 | wxT("Assertion failure"), | |
1489 | wxICON_HAND | wxOK); | |
7e126a07 WS |
1490 | } else { |
1491 | strcat(buffer, "\r\n"); | |
1492 | Platform::DebugDisplay(buffer); | |
1493 | abort(); | |
1494 | } | |
74e1efdd VZ |
1495 | #else |
1496 | wxUnusedVar(c); | |
1497 | wxUnusedVar(file); | |
1498 | wxUnusedVar(line); | |
1499 | #endif | |
65ec6247 RD |
1500 | } |
1501 | ||
1502 | ||
9ce192d4 RD |
1503 | int Platform::Clamp(int val, int minVal, int maxVal) { |
1504 | if (val > maxVal) | |
1505 | val = maxVal; | |
1506 | if (val < minVal) | |
1507 | val = minVal; | |
1508 | return val; | |
1509 | } | |
1510 | ||
1511 | ||
88a8b04e | 1512 | bool Platform::IsDBCSLeadByte(int WXUNUSED(codePage), char WXUNUSED(ch)) { |
1a2fb4cd RD |
1513 | return false; |
1514 | } | |
1515 | ||
88a8b04e | 1516 | int Platform::DBCSCharLength(int WXUNUSED(codePage), const char *WXUNUSED(s)) { |
215ef7ae | 1517 | return 1; |
9e730a78 RD |
1518 | } |
1519 | ||
1520 | int Platform::DBCSCharMaxLength() { | |
215ef7ae | 1521 | return 1; |
9e730a78 | 1522 | } |
1a2fb4cd RD |
1523 | |
1524 | ||
1525 | //---------------------------------------------------------------------- | |
1526 | ||
1527 | ElapsedTime::ElapsedTime() { | |
1d94e268 WS |
1528 | wxLongLong localTime = wxGetLocalTimeMillis(); |
1529 | littleBit = localTime.GetLo(); | |
1530 | bigBit = localTime.GetHi(); | |
1a2fb4cd RD |
1531 | } |
1532 | ||
1533 | double ElapsedTime::Duration(bool reset) { | |
1d94e268 WS |
1534 | wxLongLong prevTime(bigBit, littleBit); |
1535 | wxLongLong localTime = wxGetLocalTimeMillis(); | |
1536 | if(reset) { | |
1537 | littleBit = localTime.GetLo(); | |
1538 | bigBit = localTime.GetHi(); | |
1539 | } | |
1540 | wxLongLong duration = localTime - prevTime; | |
1541 | double result = duration.ToDouble(); | |
1a2fb4cd RD |
1542 | result /= 1000.0; |
1543 | return result; | |
1544 | } | |
1545 | ||
1546 | ||
1547 | //---------------------------------------------------------------------- | |
9ce192d4 | 1548 | |
d99859e4 | 1549 | #if wxUSE_UNICODE |
6636ac1e RD |
1550 | |
1551 | #include "UniConversion.h" | |
1552 | ||
1553 | // Convert using Scintilla's functions instead of wx's, Scintilla's are more | |
1554 | // forgiving and won't assert... | |
c8b75e94 | 1555 | |
d99859e4 RD |
1556 | wxString stc2wx(const char* str, size_t len) |
1557 | { | |
81bfa5ae RD |
1558 | if (!len) |
1559 | return wxEmptyString; | |
8a07b43c | 1560 | |
7e0c58e9 | 1561 | size_t wclen = UTF16Length(str, len); |
6636ac1e RD |
1562 | wxWCharBuffer buffer(wclen+1); |
1563 | ||
7e0c58e9 | 1564 | size_t actualLen = UTF16FromUTF8(str, len, buffer.data(), wclen+1); |
6636ac1e RD |
1565 | return wxString(buffer.data(), actualLen); |
1566 | } | |
1567 | ||
d99859e4 | 1568 | |
d99859e4 | 1569 | |
6636ac1e RD |
1570 | wxString stc2wx(const char* str) |
1571 | { | |
1572 | return stc2wx(str, strlen(str)); | |
d99859e4 | 1573 | } |
6636ac1e RD |
1574 | |
1575 | ||
1576 | const wxWX2MBbuf wx2stc(const wxString& str) | |
1577 | { | |
1578 | const wchar_t* wcstr = str.c_str(); | |
1579 | size_t wclen = str.length(); | |
1580 | size_t len = UTF8Length(wcstr, wclen); | |
1581 | ||
1582 | wxCharBuffer buffer(len+1); | |
7e0c58e9 | 1583 | UTF8FromUTF16(wcstr, wclen, buffer.data(), len); |
6636ac1e RD |
1584 | |
1585 | // TODO check NULL termination!! | |
1586 | ||
6636ac1e RD |
1587 | return buffer; |
1588 | } | |
1589 | ||
d99859e4 | 1590 | #endif |
29825f5f PC |
1591 | |
1592 | #endif // wxUSE_STC |