]>
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 |
5cce237a RD |
38 | #if wxUSE_GRAPHICS_CONTEXT |
39 | #include "wx/dcgraph.h" | |
40 | #endif | |
1a2fb4cd | 41 | |
9ce192d4 | 42 | #include "Platform.h" |
1a2fb4cd | 43 | #include "PlatWX.h" |
9ce192d4 | 44 | #include "wx/stc/stc.h" |
ea88e9bc | 45 | #include "wx/stc/private.h" |
9ce192d4 | 46 | |
f97d84a6 | 47 | |
9ce192d4 | 48 | Point Point::FromLong(long lpoint) { |
f6bcfd97 | 49 | return Point(lpoint & 0xFFFF, lpoint >> 16); |
9ce192d4 RD |
50 | } |
51 | ||
52 | wxRect wxRectFromPRectangle(PRectangle prc) { | |
d13ea3aa RD |
53 | wxRect r(prc.left, prc.top, |
54 | prc.Width(), prc.Height()); | |
55 | return r; | |
9ce192d4 RD |
56 | } |
57 | ||
58 | PRectangle PRectangleFromwxRect(wxRect rc) { | |
bec17edf | 59 | return PRectangle(rc.GetLeft(), rc.GetTop(), |
04ebdf40 | 60 | rc.GetRight()+1, rc.GetBottom()+1); |
9ce192d4 RD |
61 | } |
62 | ||
9b01abb8 | 63 | wxColour wxColourFromCD(ColourDesired& cd) { |
c8b75e94 WS |
64 | return wxColour((unsigned char)cd.GetRed(), |
65 | (unsigned char)cd.GetGreen(), | |
66 | (unsigned char)cd.GetBlue()); | |
9ce192d4 RD |
67 | } |
68 | ||
9b01abb8 | 69 | wxColour wxColourFromCDandAlpha(ColourDesired& cd, int alpha) { |
5cce237a RD |
70 | return wxColour((unsigned char)cd.GetRed(), |
71 | (unsigned char)cd.GetGreen(), | |
72 | (unsigned char)cd.GetBlue(), | |
73 | (unsigned char)alpha); | |
74 | } | |
75 | ||
1a2fb4cd RD |
76 | //---------------------------------------------------------------------- |
77 | ||
9ce192d4 | 78 | Font::Font() { |
9e96e16f | 79 | fid = 0; |
9ce192d4 RD |
80 | ascent = 0; |
81 | } | |
82 | ||
83 | Font::~Font() { | |
84 | } | |
85 | ||
9b01abb8 | 86 | void Font::Create(const FontParameters &fp) { |
9ce192d4 | 87 | Release(); |
1a2fb4cd | 88 | |
9b01abb8 | 89 | // The minus one is done because since Scintilla uses SC_CHARSET_DEFAULT |
3727c043 RD |
90 | // internally and we need to have wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT |
91 | // so we adjust the encoding before passing it to Scintilla. See also | |
92 | // wxStyledTextCtrl::StyleSetCharacterSet | |
9b01abb8 | 93 | wxFontEncoding encoding = (wxFontEncoding)(fp.characterSet-1); |
d35ad26e | 94 | |
10ef30eb RD |
95 | wxFontEncodingArray ea = wxEncodingConverter::GetPlatformEquivalents(encoding); |
96 | if (ea.GetCount()) | |
97 | encoding = ea[0]; | |
1a2fb4cd | 98 | |
9b01abb8 RD |
99 | wxFontWeight weight; |
100 | if (fp.weight <= 300) | |
101 | weight = wxFONTWEIGHT_LIGHT; | |
102 | else if (fp.weight >= 700) | |
103 | weight = wxFONTWEIGHT_BOLD; | |
104 | else | |
105 | weight = wxFONTWEIGHT_NORMAL; | |
106 | ||
107 | wxFont* font = new wxFont(fp.size, | |
108 | wxFONTFAMILY_DEFAULT, | |
109 | fp.italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL, | |
110 | weight, | |
111 | false, | |
112 | stc2wx(fp.faceName), | |
113 | encoding); | |
9e96e16f | 114 | fid = font; |
9ce192d4 RD |
115 | } |
116 | ||
117 | ||
118 | void Font::Release() { | |
9e96e16f RD |
119 | if (fid) |
120 | delete (wxFont*)fid; | |
121 | fid = 0; | |
9ce192d4 RD |
122 | } |
123 | ||
1a2fb4cd RD |
124 | //---------------------------------------------------------------------- |
125 | ||
126 | class SurfaceImpl : public Surface { | |
127 | private: | |
128 | wxDC* hdc; | |
129 | bool hdcOwned; | |
130 | wxBitmap* bitmap; | |
131 | int x; | |
132 | int y; | |
133 | bool unicodeMode; | |
9ce192d4 | 134 | |
1a2fb4cd RD |
135 | public: |
136 | SurfaceImpl(); | |
137 | ~SurfaceImpl(); | |
138 | ||
9e730a78 RD |
139 | virtual void Init(WindowID wid); |
140 | virtual void Init(SurfaceID sid, WindowID wid); | |
141 | virtual void InitPixMap(int width, int height, Surface *surface_, WindowID wid); | |
142 | ||
143 | virtual void Release(); | |
144 | virtual bool Initialised(); | |
9b01abb8 | 145 | virtual void PenColour(ColourDesired fore); |
9e730a78 RD |
146 | virtual int LogPixelsY(); |
147 | virtual int DeviceHeightFont(int points); | |
148 | virtual void MoveTo(int x_, int y_); | |
149 | virtual void LineTo(int x_, int y_); | |
9b01abb8 RD |
150 | virtual void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back); |
151 | virtual void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back); | |
152 | virtual void FillRectangle(PRectangle rc, ColourDesired back); | |
9e730a78 | 153 | virtual void FillRectangle(PRectangle rc, Surface &surfacePattern); |
9b01abb8 RD |
154 | virtual void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back); |
155 | virtual void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, | |
156 | ColourDesired outline, int alphaOutline, int flags); | |
157 | virtual void DrawRGBAImage(PRectangle rc, int width, int height, | |
158 | const unsigned char *pixelsImage); | |
159 | virtual void Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back); | |
9e730a78 RD |
160 | virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource); |
161 | ||
9b01abb8 RD |
162 | virtual void DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back); |
163 | virtual void DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back); | |
164 | virtual void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore); | |
165 | virtual void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions); | |
166 | virtual XYPOSITION WidthText(Font &font_, const char *s, int len); | |
167 | virtual XYPOSITION WidthChar(Font &font_, char ch); | |
168 | virtual XYPOSITION Ascent(Font &font_); | |
169 | virtual XYPOSITION Descent(Font &font_); | |
170 | virtual XYPOSITION InternalLeading(Font &font_); | |
171 | virtual XYPOSITION ExternalLeading(Font &font_); | |
172 | virtual XYPOSITION Height(Font &font_); | |
173 | virtual XYPOSITION AverageCharWidth(Font &font_); | |
174 | ||
9e730a78 RD |
175 | virtual void SetClip(PRectangle rc); |
176 | virtual void FlushCachedState(); | |
177 | ||
178 | virtual void SetUnicodeMode(bool unicodeMode_); | |
179 | virtual void SetDBCSMode(int codePage); | |
1a2fb4cd | 180 | |
9b01abb8 | 181 | void BrushColour(ColourDesired back); |
1a2fb4cd RD |
182 | void SetFont(Font &font_); |
183 | }; | |
184 | ||
185 | ||
186 | ||
187 | SurfaceImpl::SurfaceImpl() : | |
9ce192d4 | 188 | hdc(0), hdcOwned(0), bitmap(0), |
1a2fb4cd RD |
189 | x(0), y(0), unicodeMode(0) |
190 | {} | |
9ce192d4 | 191 | |
1a2fb4cd | 192 | SurfaceImpl::~SurfaceImpl() { |
9ce192d4 RD |
193 | Release(); |
194 | } | |
195 | ||
9e730a78 | 196 | void SurfaceImpl::Init(WindowID wid) { |
81b32ce5 | 197 | #if 0 |
9ce192d4 RD |
198 | Release(); |
199 | hdc = new wxMemoryDC(); | |
200 | hdcOwned = true; | |
81b32ce5 | 201 | #else |
09bb2551 | 202 | // On Mac and GTK the DC is not really valid until it has a bitmap |
81b32ce5 RD |
203 | // selected into it. So instead of just creating the DC with no bitmap, |
204 | // go ahead and give it one. | |
9e730a78 | 205 | InitPixMap(1,1,NULL,wid); |
0f713d48 | 206 | #endif |
9ce192d4 RD |
207 | } |
208 | ||
9e730a78 | 209 | void SurfaceImpl::Init(SurfaceID hdc_, WindowID) { |
9ce192d4 | 210 | Release(); |
1a2fb4cd | 211 | hdc = (wxDC*)hdc_; |
9ce192d4 RD |
212 | } |
213 | ||
88a8b04e | 214 | void SurfaceImpl::InitPixMap(int width, int height, Surface *WXUNUSED(surface_), WindowID) { |
9ce192d4 | 215 | Release(); |
1a2fb4cd | 216 | hdc = new wxMemoryDC(); |
9ce192d4 | 217 | hdcOwned = true; |
2beb01db RD |
218 | if (width < 1) width = 1; |
219 | if (height < 1) height = 1; | |
21156596 | 220 | bitmap = new wxBitmap(width, height); |
9ce192d4 | 221 | ((wxMemoryDC*)hdc)->SelectObject(*bitmap); |
9ce192d4 RD |
222 | } |
223 | ||
9e730a78 RD |
224 | |
225 | void SurfaceImpl::Release() { | |
226 | if (bitmap) { | |
227 | ((wxMemoryDC*)hdc)->SelectObject(wxNullBitmap); | |
228 | delete bitmap; | |
229 | bitmap = 0; | |
230 | } | |
231 | if (hdcOwned) { | |
232 | delete hdc; | |
233 | hdc = 0; | |
234 | hdcOwned = false; | |
235 | } | |
236 | } | |
237 | ||
238 | ||
239 | bool SurfaceImpl::Initialised() { | |
240 | return hdc != 0; | |
241 | } | |
242 | ||
243 | ||
9b01abb8 RD |
244 | void SurfaceImpl::PenColour(ColourDesired fore) { |
245 | hdc->SetPen(wxPen(wxColourFromCD(fore))); | |
9ce192d4 RD |
246 | } |
247 | ||
9b01abb8 RD |
248 | void SurfaceImpl::BrushColour(ColourDesired back) { |
249 | hdc->SetBrush(wxBrush(wxColourFromCD(back))); | |
9ce192d4 RD |
250 | } |
251 | ||
1a2fb4cd | 252 | void SurfaceImpl::SetFont(Font &font_) { |
21156596 | 253 | if (font_.GetID()) { |
1a2fb4cd | 254 | hdc->SetFont(*((wxFont*)font_.GetID())); |
f6bcfd97 | 255 | } |
9ce192d4 RD |
256 | } |
257 | ||
1a2fb4cd | 258 | int SurfaceImpl::LogPixelsY() { |
9ce192d4 RD |
259 | return hdc->GetPPI().y; |
260 | } | |
261 | ||
1a2fb4cd | 262 | int SurfaceImpl::DeviceHeightFont(int points) { |
9968ba85 | 263 | return points; |
f6bcfd97 BP |
264 | } |
265 | ||
1a2fb4cd | 266 | void SurfaceImpl::MoveTo(int x_, int y_) { |
9ce192d4 RD |
267 | x = x_; |
268 | y = y_; | |
269 | } | |
270 | ||
1a2fb4cd | 271 | void SurfaceImpl::LineTo(int x_, int y_) { |
9ce192d4 RD |
272 | hdc->DrawLine(x,y, x_,y_); |
273 | x = x_; | |
274 | y = y_; | |
275 | } | |
276 | ||
9b01abb8 | 277 | void SurfaceImpl::Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back) { |
9ce192d4 | 278 | PenColour(fore); |
1a2fb4cd | 279 | BrushColour(back); |
9ce192d4 RD |
280 | hdc->DrawPolygon(npts, (wxPoint*)pts); |
281 | } | |
282 | ||
9b01abb8 | 283 | void SurfaceImpl::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) { |
9ce192d4 | 284 | PenColour(fore); |
1a2fb4cd | 285 | BrushColour(back); |
9ce192d4 RD |
286 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); |
287 | } | |
288 | ||
9b01abb8 | 289 | void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { |
1a2fb4cd | 290 | BrushColour(back); |
9ce192d4 RD |
291 | hdc->SetPen(*wxTRANSPARENT_PEN); |
292 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); | |
293 | } | |
294 | ||
1a2fb4cd | 295 | void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) { |
9ce192d4 | 296 | wxBrush br; |
1a2fb4cd RD |
297 | if (((SurfaceImpl&)surfacePattern).bitmap) |
298 | br = wxBrush(*((SurfaceImpl&)surfacePattern).bitmap); | |
9ce192d4 | 299 | else // Something is wrong so display in red |
cb129171 | 300 | br = wxBrush(*wxRED); |
9ce192d4 RD |
301 | hdc->SetPen(*wxTRANSPARENT_PEN); |
302 | hdc->SetBrush(br); | |
303 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); | |
304 | } | |
305 | ||
9b01abb8 | 306 | void SurfaceImpl::RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back) { |
9ce192d4 | 307 | PenColour(fore); |
1a2fb4cd | 308 | BrushColour(back); |
f6bcfd97 | 309 | hdc->DrawRoundedRectangle(wxRectFromPRectangle(rc), 4); |
9ce192d4 RD |
310 | } |
311 | ||
9b01abb8 | 312 | #if defined(__WXMSW__) || defined(__WXMAC__) |
6a93571d RD |
313 | #define wxPy_premultiply(p, a) ((p) * (a) / 0xff) |
314 | #else | |
315 | #define wxPy_premultiply(p, a) (p) | |
316 | #endif | |
317 | ||
b8193d80 | 318 | void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, |
9b01abb8 RD |
319 | ColourDesired fill, int alphaFill, |
320 | ColourDesired outline, int alphaOutline, | |
6a93571d | 321 | int /*flags*/) { |
5cce237a RD |
322 | #if wxUSE_GRAPHICS_CONTEXT |
323 | wxGCDC dc(*(wxMemoryDC*)hdc); | |
9b01abb8 RD |
324 | wxColour penColour(wxColourFromCDandAlpha(outline, alphaOutline)); |
325 | wxColour brushColour(wxColourFromCDandAlpha(fill, alphaFill)); | |
5cce237a RD |
326 | dc.SetPen(wxPen(penColour)); |
327 | dc.SetBrush(wxBrush(brushColour)); | |
328 | dc.DrawRoundedRectangle(wxRectFromPRectangle(rc), cornerSize); | |
329 | return; | |
330 | #else | |
ce00f59b | 331 | |
3fb1e059 | 332 | #ifdef wxHAS_RAW_BITMAP |
a3511a2e RD |
333 | |
334 | // TODO: do something with cornerSize | |
335 | wxUnusedVar(cornerSize); | |
038c0333 | 336 | |
6a93571d RD |
337 | int x, y; |
338 | wxRect r = wxRectFromPRectangle(rc); | |
339 | wxBitmap bmp(r.width, r.height, 32); | |
340 | wxAlphaPixelData pixData(bmp); | |
6a93571d RD |
341 | |
342 | // Set the fill pixels | |
343 | ColourDesired cdf(fill.AsLong()); | |
344 | int red = cdf.GetRed(); | |
345 | int green = cdf.GetGreen(); | |
346 | int blue = cdf.GetBlue(); | |
347 | ||
348 | wxAlphaPixelData::Iterator p(pixData); | |
349 | for (y=0; y<r.height; y++) { | |
350 | p.MoveTo(pixData, 0, y); | |
351 | for (x=0; x<r.width; x++) { | |
352 | p.Red() = wxPy_premultiply(red, alphaFill); | |
353 | p.Green() = wxPy_premultiply(green, alphaFill); | |
354 | p.Blue() = wxPy_premultiply(blue, alphaFill); | |
355 | p.Alpha() = alphaFill; | |
038c0333 | 356 | ++p; |
6a93571d RD |
357 | } |
358 | } | |
359 | ||
360 | // Set the outline pixels | |
361 | ColourDesired cdo(outline.AsLong()); | |
362 | red = cdo.GetRed(); | |
363 | green = cdo.GetGreen(); | |
364 | blue = cdo.GetBlue(); | |
365 | for (x=0; x<r.width; x++) { | |
366 | p.MoveTo(pixData, x, 0); | |
367 | p.Red() = wxPy_premultiply(red, alphaOutline); | |
368 | p.Green() = wxPy_premultiply(green, alphaOutline); | |
369 | p.Blue() = wxPy_premultiply(blue, alphaOutline); | |
038c0333 | 370 | p.Alpha() = alphaOutline; |
6a93571d RD |
371 | p.MoveTo(pixData, x, r.height-1); |
372 | p.Red() = wxPy_premultiply(red, alphaOutline); | |
373 | p.Green() = wxPy_premultiply(green, alphaOutline); | |
374 | p.Blue() = wxPy_premultiply(blue, alphaOutline); | |
038c0333 | 375 | p.Alpha() = alphaOutline; |
6a93571d | 376 | } |
b8193d80 | 377 | |
6a93571d RD |
378 | for (y=0; y<r.height; y++) { |
379 | p.MoveTo(pixData, 0, y); | |
380 | p.Red() = wxPy_premultiply(red, alphaOutline); | |
381 | p.Green() = wxPy_premultiply(green, alphaOutline); | |
382 | p.Blue() = wxPy_premultiply(blue, alphaOutline); | |
038c0333 | 383 | p.Alpha() = alphaOutline; |
6a93571d RD |
384 | p.MoveTo(pixData, r.width-1, y); |
385 | p.Red() = wxPy_premultiply(red, alphaOutline); | |
386 | p.Green() = wxPy_premultiply(green, alphaOutline); | |
387 | p.Blue() = wxPy_premultiply(blue, alphaOutline); | |
038c0333 | 388 | p.Alpha() = alphaOutline; |
6a93571d | 389 | } |
038c0333 | 390 | |
6a93571d RD |
391 | // Draw the bitmap |
392 | hdc->DrawBitmap(bmp, r.x, r.y, true); | |
8b6c20ce RD |
393 | |
394 | #else | |
395 | wxUnusedVar(cornerSize); | |
396 | wxUnusedVar(alphaFill); | |
397 | wxUnusedVar(alphaOutline); | |
398 | RectangleDraw(rc, outline, fill); | |
399 | #endif | |
5cce237a | 400 | #endif |
b8193d80 RD |
401 | } |
402 | ||
9b01abb8 RD |
403 | #ifdef wxHAS_RAW_BITMAP |
404 | wxBitmap BitmapFromRGBAImage(int width, int height, const unsigned char *pixelsImage) | |
405 | { | |
406 | int x, y; | |
407 | wxBitmap bmp(width, height, 32); | |
408 | wxAlphaPixelData pixData(bmp); | |
409 | ||
410 | wxAlphaPixelData::Iterator p(pixData); | |
411 | for (y=0; y<height; y++) { | |
412 | p.MoveTo(pixData, 0, y); | |
413 | for (x=0; x<width; x++) { | |
414 | unsigned char red = *pixelsImage++; | |
415 | unsigned char green = *pixelsImage++; | |
416 | unsigned char blue = *pixelsImage++; | |
417 | unsigned char alpha = *pixelsImage++; | |
418 | ||
419 | p.Red() = wxPy_premultiply(red, alpha); | |
420 | p.Green() = wxPy_premultiply(green, alpha); | |
421 | p.Blue() = wxPy_premultiply(blue, alpha); | |
422 | p.Alpha() = alpha; | |
423 | ++p; | |
424 | } | |
425 | } | |
426 | return bmp; | |
427 | } | |
428 | #endif | |
429 | ||
430 | ||
431 | void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, | |
432 | const unsigned char *pixelsImage) | |
433 | { | |
434 | #ifdef wxHAS_RAW_BITMAP | |
435 | wxRect r = wxRectFromPRectangle(rc); | |
436 | wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage); | |
437 | hdc->DrawBitmap(bmp, r.x, r.y, true); | |
438 | #endif | |
439 | } | |
440 | ||
441 | ||
442 | void SurfaceImpl::Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back) { | |
9ce192d4 | 443 | PenColour(fore); |
1a2fb4cd | 444 | BrushColour(back); |
9ce192d4 RD |
445 | hdc->DrawEllipse(wxRectFromPRectangle(rc)); |
446 | } | |
447 | ||
1a2fb4cd | 448 | void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) { |
f6bcfd97 BP |
449 | wxRect r = wxRectFromPRectangle(rc); |
450 | hdc->Blit(r.x, r.y, r.width, r.height, | |
1a2fb4cd RD |
451 | ((SurfaceImpl&)surfaceSource).hdc, |
452 | from.x, from.y, wxCOPY); | |
9ce192d4 RD |
453 | } |
454 | ||
9b01abb8 | 455 | void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, XYPOSITION ybase, |
1a2fb4cd | 456 | const char *s, int len, |
9b01abb8 | 457 | ColourDesired fore, ColourDesired back) { |
9ce192d4 | 458 | SetFont(font); |
9b01abb8 RD |
459 | hdc->SetTextForeground(wxColourFromCD(fore)); |
460 | hdc->SetTextBackground(wxColourFromCD(back)); | |
3d7a4fe8 | 461 | FillRectangle(rc, back); |
9ce192d4 RD |
462 | |
463 | // ybase is where the baseline should be, but wxWin uses the upper left | |
464 | // corner, so I need to calculate the real position for the text... | |
d13ea3aa | 465 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
9ce192d4 RD |
466 | } |
467 | ||
9b01abb8 | 468 | void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, XYPOSITION ybase, |
1a2fb4cd | 469 | const char *s, int len, |
9b01abb8 | 470 | ColourDesired fore, ColourDesired back) { |
9ce192d4 | 471 | SetFont(font); |
9b01abb8 RD |
472 | hdc->SetTextForeground(wxColourFromCD(fore)); |
473 | hdc->SetTextBackground(wxColourFromCD(back)); | |
3d7a4fe8 | 474 | FillRectangle(rc, back); |
9ce192d4 RD |
475 | hdc->SetClippingRegion(wxRectFromPRectangle(rc)); |
476 | ||
477 | // see comments above | |
d13ea3aa | 478 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
3d7a4fe8 | 479 | hdc->DestroyClippingRegion(); |
9ce192d4 RD |
480 | } |
481 | ||
9e730a78 | 482 | |
9b01abb8 | 483 | void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, XYPOSITION ybase, |
9e730a78 | 484 | const char *s, int len, |
9b01abb8 | 485 | ColourDesired fore) { |
9e730a78 | 486 | |
9ce192d4 | 487 | SetFont(font); |
9b01abb8 | 488 | hdc->SetTextForeground(wxColourFromCD(fore)); |
cb129171 | 489 | hdc->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); |
1a2fb4cd | 490 | |
9e730a78 RD |
491 | // ybase is where the baseline should be, but wxWin uses the upper left |
492 | // corner, so I need to calculate the real position for the text... | |
d13ea3aa | 493 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
9e730a78 | 494 | |
cb129171 | 495 | hdc->SetBackgroundMode(wxBRUSHSTYLE_SOLID); |
9ce192d4 RD |
496 | } |
497 | ||
1a2fb4cd | 498 | |
9b01abb8 | 499 | void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, XYPOSITION *positions) { |
9e730a78 | 500 | |
d1558f3d RD |
501 | wxString str = stc2wx(s, len); |
502 | wxArrayInt tpos; | |
10ef30eb | 503 | |
d1558f3d | 504 | SetFont(font); |
9e730a78 | 505 | |
d1558f3d | 506 | hdc->GetPartialTextExtents(str, tpos); |
10ef30eb RD |
507 | |
508 | #if wxUSE_UNICODE | |
509 | // Map the widths for UCS-2 characters back to the UTF-8 input string | |
9e730a78 RD |
510 | // NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2 |
511 | // so figure it out and fix it! | |
d1558f3d | 512 | size_t i = 0; |
10ef30eb | 513 | size_t ui = 0; |
d99859e4 | 514 | while ((int)i < len) { |
10ef30eb RD |
515 | unsigned char uch = (unsigned char)s[i]; |
516 | positions[i++] = tpos[ui]; | |
517 | if (uch >= 0x80) { | |
518 | if (uch < (0x80 + 0x40 + 0x20)) { | |
519 | positions[i++] = tpos[ui]; | |
520 | } else { | |
521 | positions[i++] = tpos[ui]; | |
522 | positions[i++] = tpos[ui]; | |
523 | } | |
524 | } | |
525 | ui++; | |
526 | } | |
527 | #else | |
528 | ||
529 | // If not unicode then just use the widths we have | |
01871bf6 | 530 | #if wxUSE_STD_CONTAINERS |
f3ee029e MB |
531 | std::copy(tpos.begin(), tpos.end(), positions); |
532 | #else | |
d1558f3d | 533 | memcpy(positions, tpos.begin(), len * sizeof(int)); |
10ef30eb | 534 | #endif |
f3ee029e | 535 | #endif |
9ce192d4 RD |
536 | } |
537 | ||
10ef30eb | 538 | |
9b01abb8 | 539 | XYPOSITION SurfaceImpl::WidthText(Font &font, const char *s, int len) { |
9e730a78 RD |
540 | SetFont(font); |
541 | int w; | |
542 | int h; | |
543 | ||
544 | hdc->GetTextExtent(stc2wx(s, len), &w, &h); | |
545 | return w; | |
546 | } | |
547 | ||
548 | ||
9b01abb8 | 549 | XYPOSITION SurfaceImpl::WidthChar(Font &font, char ch) { |
9ce192d4 RD |
550 | SetFont(font); |
551 | int w; | |
552 | int h; | |
10ef30eb RD |
553 | char s[2] = { ch, 0 }; |
554 | ||
0c5b83b0 | 555 | hdc->GetTextExtent(stc2wx(s, 1), &w, &h); |
9ce192d4 RD |
556 | return w; |
557 | } | |
558 | ||
1a2fb4cd | 559 | #define EXTENT_TEST wxT(" `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
9ce192d4 | 560 | |
9b01abb8 | 561 | XYPOSITION SurfaceImpl::Ascent(Font &font) { |
9ce192d4 RD |
562 | SetFont(font); |
563 | int w, h, d, e; | |
564 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
565 | font.ascent = h - d; | |
566 | return font.ascent; | |
567 | } | |
568 | ||
9b01abb8 | 569 | XYPOSITION SurfaceImpl::Descent(Font &font) { |
9ce192d4 RD |
570 | SetFont(font); |
571 | int w, h, d, e; | |
572 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
573 | return d; | |
574 | } | |
575 | ||
9b01abb8 | 576 | XYPOSITION SurfaceImpl::InternalLeading(Font &WXUNUSED(font)) { |
9ce192d4 RD |
577 | return 0; |
578 | } | |
579 | ||
9b01abb8 | 580 | XYPOSITION SurfaceImpl::ExternalLeading(Font &font) { |
9ce192d4 RD |
581 | SetFont(font); |
582 | int w, h, d, e; | |
583 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
584 | return e; | |
585 | } | |
586 | ||
9b01abb8 | 587 | XYPOSITION SurfaceImpl::Height(Font &font) { |
9ce192d4 | 588 | SetFont(font); |
d13ea3aa | 589 | return hdc->GetCharHeight() + 1; |
9ce192d4 RD |
590 | } |
591 | ||
9b01abb8 | 592 | XYPOSITION SurfaceImpl::AverageCharWidth(Font &font) { |
9ce192d4 RD |
593 | SetFont(font); |
594 | return hdc->GetCharWidth(); | |
595 | } | |
596 | ||
1a2fb4cd | 597 | void SurfaceImpl::SetClip(PRectangle rc) { |
9ce192d4 RD |
598 | hdc->SetClippingRegion(wxRectFromPRectangle(rc)); |
599 | } | |
600 | ||
1a2fb4cd | 601 | void SurfaceImpl::FlushCachedState() { |
f6bcfd97 | 602 | } |
9ce192d4 | 603 | |
1a2fb4cd | 604 | void SurfaceImpl::SetUnicodeMode(bool unicodeMode_) { |
1a2fb4cd RD |
605 | unicodeMode=unicodeMode_; |
606 | } | |
607 | ||
88a8b04e | 608 | void SurfaceImpl::SetDBCSMode(int WXUNUSED(codePage)) { |
9e730a78 RD |
609 | // dbcsMode = codePage == SC_CP_DBCS; |
610 | } | |
611 | ||
612 | ||
9b01abb8 | 613 | Surface *Surface::Allocate(int WXUNUSED(technology)) { |
1a2fb4cd RD |
614 | return new SurfaceImpl; |
615 | } | |
616 | ||
617 | ||
618 | //---------------------------------------------------------------------- | |
619 | ||
620 | ||
621 | inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; } | |
622 | ||
9ce192d4 RD |
623 | Window::~Window() { |
624 | } | |
625 | ||
626 | void Window::Destroy() { | |
9e96e16f | 627 | if (wid) { |
7e126a07 | 628 | Show(false); |
9e96e16f | 629 | GETWIN(wid)->Destroy(); |
9e730a78 | 630 | } |
9e96e16f | 631 | wid = 0; |
9ce192d4 RD |
632 | } |
633 | ||
634 | bool Window::HasFocus() { | |
9e96e16f | 635 | return wxWindow::FindFocus() == GETWIN(wid); |
9ce192d4 RD |
636 | } |
637 | ||
638 | PRectangle Window::GetPosition() { | |
9e96e16f RD |
639 | if (! wid) return PRectangle(); |
640 | wxRect rc(GETWIN(wid)->GetPosition(), GETWIN(wid)->GetSize()); | |
9ce192d4 RD |
641 | return PRectangleFromwxRect(rc); |
642 | } | |
643 | ||
644 | void Window::SetPosition(PRectangle rc) { | |
f6bcfd97 | 645 | wxRect r = wxRectFromPRectangle(rc); |
9e96e16f | 646 | GETWIN(wid)->SetSize(r); |
9ce192d4 RD |
647 | } |
648 | ||
649 | void Window::SetPositionRelative(PRectangle rc, Window) { | |
650 | SetPosition(rc); // ???? | |
651 | } | |
652 | ||
653 | PRectangle Window::GetClientPosition() { | |
9e96e16f RD |
654 | if (! wid) return PRectangle(); |
655 | wxSize sz = GETWIN(wid)->GetClientSize(); | |
21156596 | 656 | return PRectangle(0, 0, sz.x, sz.y); |
9ce192d4 RD |
657 | } |
658 | ||
659 | void Window::Show(bool show) { | |
9e96e16f | 660 | GETWIN(wid)->Show(show); |
9ce192d4 RD |
661 | } |
662 | ||
663 | void Window::InvalidateAll() { | |
9e96e16f | 664 | GETWIN(wid)->Refresh(false); |
9ce192d4 RD |
665 | } |
666 | ||
667 | void Window::InvalidateRectangle(PRectangle rc) { | |
f6bcfd97 | 668 | wxRect r = wxRectFromPRectangle(rc); |
9e96e16f | 669 | GETWIN(wid)->Refresh(false, &r); |
9ce192d4 RD |
670 | } |
671 | ||
672 | void Window::SetFont(Font &font) { | |
9e96e16f | 673 | GETWIN(wid)->SetFont(*((wxFont*)font.GetID())); |
9ce192d4 RD |
674 | } |
675 | ||
676 | void Window::SetCursor(Cursor curs) { | |
d4f392ea | 677 | wxStockCursor cursorId; |
9ce192d4 RD |
678 | |
679 | switch (curs) { | |
680 | case cursorText: | |
681 | cursorId = wxCURSOR_IBEAM; | |
682 | break; | |
683 | case cursorArrow: | |
684 | cursorId = wxCURSOR_ARROW; | |
685 | break; | |
686 | case cursorUp: | |
687 | cursorId = wxCURSOR_ARROW; // ** no up arrow... wxCURSOR_UPARROW; | |
688 | break; | |
689 | case cursorWait: | |
690 | cursorId = wxCURSOR_WAIT; | |
691 | break; | |
692 | case cursorHoriz: | |
693 | cursorId = wxCURSOR_SIZEWE; | |
694 | break; | |
695 | case cursorVert: | |
696 | cursorId = wxCURSOR_SIZENS; | |
697 | break; | |
698 | case cursorReverseArrow: | |
15dadf31 | 699 | cursorId = wxCURSOR_RIGHT_ARROW; |
9ce192d4 | 700 | break; |
9e730a78 RD |
701 | case cursorHand: |
702 | cursorId = wxCURSOR_HAND; | |
1e545382 | 703 | break; |
9ce192d4 RD |
704 | default: |
705 | cursorId = wxCURSOR_ARROW; | |
706 | break; | |
707 | } | |
d4f392ea FM |
708 | |
709 | wxCursor wc = wxCursor(cursorId); | |
710 | if(curs != cursorLast) | |
711 | { | |
9e96e16f | 712 | GETWIN(wid)->SetCursor(wc); |
d4f392ea FM |
713 | cursorLast = curs; |
714 | } | |
9ce192d4 RD |
715 | } |
716 | ||
717 | ||
718 | void Window::SetTitle(const char *s) { | |
9e96e16f | 719 | GETWIN(wid)->SetLabel(stc2wx(s)); |
9ce192d4 RD |
720 | } |
721 | ||
722 | ||
7e0c58e9 RD |
723 | // Returns rectangle of monitor pt is on |
724 | PRectangle Window::GetMonitorRect(Point pt) { | |
725 | wxRect rect; | |
9e96e16f | 726 | if (! wid) return PRectangle(); |
7e0c58e9 RD |
727 | #if wxUSE_DISPLAY |
728 | // Get the display the point is found on | |
729 | int n = wxDisplay::GetFromPoint(wxPoint(pt.x, pt.y)); | |
730 | wxDisplay dpy(n == wxNOT_FOUND ? 0 : n); | |
731 | rect = dpy.GetGeometry(); | |
c5147528 VZ |
732 | #else |
733 | wxUnusedVar(pt); | |
7e0c58e9 RD |
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 | 801 | |
d35ad26e | 802 | // A popup window to place the wxSTCListBox upon |
382fe640 RD |
803 | class wxSTCListBoxWin : public wxPopupWindow |
804 | { | |
805 | private: | |
806 | wxListView* lv; | |
807 | CallBackAction doubleClickAction; | |
808 | void* doubleClickActionData; | |
809 | public: | |
d35ad26e | 810 | wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point WXUNUSED(location)) : |
9e96e16f | 811 | wxPopupWindow(parent, wxBORDER_SIMPLE) |
382fe640 | 812 | { |
038c0333 | 813 | |
67879c5b | 814 | lv = new wxSTCListBox(parent, id, wxPoint(-50,-50), wxDefaultSize, |
382fe640 RD |
815 | wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxBORDER_NONE); |
816 | lv->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
817 | lv->InsertColumn(0, wxEmptyString); | |
818 | lv->InsertColumn(1, wxEmptyString); | |
819 | ||
820 | // NOTE: We need to fool the wxListView into thinking that it has the | |
821 | // focus so it will use the normal selection colour and will look | |
822 | // "right" to the user. But since the wxPopupWindow or its children | |
823 | // can't receive focus then we have to pull a fast one and temporarily | |
824 | // parent the listctrl on the STC window and then call SetFocus and | |
d35ad26e | 825 | // then reparent it back to the popup. |
382fe640 RD |
826 | lv->SetFocus(); |
827 | lv->Reparent(this); | |
828 | #ifdef __WXMSW__ | |
829 | lv->Show(); | |
56c1c299 RD |
830 | #endif |
831 | #ifdef __WXOSX_COCOA__ | |
832 | SetBackgroundColour(wxColour(0xC0, 0xC0, 0xC0)); | |
382fe640 RD |
833 | #endif |
834 | } | |
835 | ||
836 | ||
837 | // Set position in client coords | |
838 | virtual void DoSetSize(int x, int y, | |
839 | int width, int height, | |
840 | int sizeFlags = wxSIZE_AUTO) { | |
841 | if (x != wxDefaultCoord) { | |
842 | GetParent()->ClientToScreen(&x, NULL); | |
843 | } | |
844 | if (y != wxDefaultCoord) { | |
845 | GetParent()->ClientToScreen(NULL, &y); | |
846 | } | |
847 | wxPopupWindow::DoSetSize(x, y, width, height, sizeFlags); | |
848 | } | |
849 | ||
850 | // return position as if it were in client coords | |
851 | virtual void DoGetPosition( int *x, int *y ) const { | |
852 | int sx, sy; | |
853 | wxPopupWindow::DoGetPosition(&sx, &sy); | |
854 | GetParent()->ScreenToClient(&sx, &sy); | |
855 | if (x) *x = sx; | |
856 | if (y) *y = sy; | |
857 | } | |
858 | ||
859 | ||
860 | bool Destroy() { | |
861 | if ( !wxPendingDelete.Member(this) ) | |
862 | wxPendingDelete.Append(this); | |
863 | return true; | |
864 | } | |
865 | ||
866 | ||
867 | int IconWidth() { | |
868 | wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL); | |
869 | if (il != NULL) { | |
870 | int w, h; | |
871 | il->GetSize(0, w, h); | |
872 | return w; | |
873 | } | |
874 | return 0; | |
875 | } | |
876 | ||
877 | ||
878 | void SetDoubleClickAction(CallBackAction action, void *data) { | |
879 | doubleClickAction = action; | |
880 | doubleClickActionData = data; | |
881 | } | |
882 | ||
883 | ||
884 | void OnFocus(wxFocusEvent& event) { | |
885 | GetParent()->SetFocus(); | |
886 | event.Skip(); | |
887 | } | |
888 | ||
889 | void OnSize(wxSizeEvent& event) { | |
9e96e16f RD |
890 | // resize the child to fill the popup |
891 | wxSize sz = GetClientSize(); | |
56c1c299 RD |
892 | int x, y, w, h; |
893 | x = y = 0; | |
894 | w = sz.x; | |
895 | h = sz.y; | |
896 | #ifdef __WXOSX_COCOA__ | |
897 | // make room for the parent's bg color to show, to act as a border | |
898 | x = y = 1; | |
899 | w -= 2; | |
900 | h -= 2; | |
901 | #endif | |
902 | lv->SetSize(x, y, w, h); | |
382fe640 RD |
903 | // reset the column widths |
904 | lv->SetColumnWidth(0, IconWidth()+4); | |
56c1c299 | 905 | lv->SetColumnWidth(1, w - 2 - lv->GetColumnWidth(0) - |
382fe640 RD |
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(); | |
9b01abb8 | 1106 | static ListBox *Allocate(); |
9e730a78 RD |
1107 | |
1108 | virtual void SetFont(Font &font); | |
9b01abb8 | 1109 | virtual void Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_, int technology_); |
9e730a78 RD |
1110 | virtual void SetAverageCharWidth(int width); |
1111 | virtual void SetVisibleRows(int rows); | |
1e9bafca | 1112 | virtual int GetVisibleRows() const; |
9e730a78 RD |
1113 | virtual PRectangle GetDesiredRect(); |
1114 | virtual int CaretFromEdge(); | |
1115 | virtual void Clear(); | |
1116 | virtual void Append(char *s, int type = -1); | |
1e9bafca | 1117 | void Append(const wxString& text, int type); |
9e730a78 RD |
1118 | virtual int Length(); |
1119 | virtual void Select(int n); | |
1120 | virtual int GetSelection(); | |
1121 | virtual int Find(const char *prefix); | |
1122 | virtual void GetValue(int n, char *value, int len); | |
9e730a78 | 1123 | virtual void RegisterImage(int type, const char *xpm_data); |
9b01abb8 RD |
1124 | void RegisterImageHelper(int type, wxBitmap& bmp); |
1125 | virtual void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage); | |
9e730a78 RD |
1126 | virtual void ClearRegisteredImages(); |
1127 | virtual void SetDoubleClickAction(CallBackAction, void *); | |
1e9bafca | 1128 | virtual void SetList(const char* list, char separator, char typesep); |
9e730a78 RD |
1129 | }; |
1130 | ||
1131 | ||
1132 | ListBoxImpl::ListBoxImpl() | |
1133 | : lineHeight(10), unicodeMode(false), | |
1134 | desiredVisibleRows(5), aveCharWidth(8), maxStrWidth(0), | |
1135 | imgList(NULL), imgTypeMap(NULL) | |
1136 | { | |
9ce192d4 RD |
1137 | } |
1138 | ||
9e730a78 | 1139 | ListBoxImpl::~ListBoxImpl() { |
5276b0a5 VZ |
1140 | wxDELETE(imgList); |
1141 | wxDELETE(imgTypeMap); | |
9ce192d4 RD |
1142 | } |
1143 | ||
9e730a78 RD |
1144 | |
1145 | void ListBoxImpl::SetFont(Font &font) { | |
9e96e16f | 1146 | GETLB(wid)->SetFont(*((wxFont*)font.GetID())); |
9e730a78 RD |
1147 | } |
1148 | ||
1149 | ||
9b01abb8 | 1150 | void ListBoxImpl::Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_, int WXUNUSED(technology_)) { |
1e9bafca | 1151 | location = location_; |
9e730a78 RD |
1152 | lineHeight = lineHeight_; |
1153 | unicodeMode = unicodeMode_; | |
1154 | maxStrWidth = 0; | |
9e96e16f | 1155 | wid = new wxSTCListBoxWin(GETWIN(parent.GetID()), ctrlID, location); |
9e730a78 | 1156 | if (imgList != NULL) |
9e96e16f | 1157 | GETLB(wid)->SetImageList(imgList, wxIMAGE_LIST_SMALL); |
9ce192d4 RD |
1158 | } |
1159 | ||
9e730a78 RD |
1160 | |
1161 | void ListBoxImpl::SetAverageCharWidth(int width) { | |
1162 | aveCharWidth = width; | |
1163 | } | |
1164 | ||
1165 | ||
1166 | void ListBoxImpl::SetVisibleRows(int rows) { | |
769a9cb2 | 1167 | desiredVisibleRows = rows; |
f3c2c221 RD |
1168 | } |
1169 | ||
9e730a78 | 1170 | |
1e9bafca RD |
1171 | int ListBoxImpl::GetVisibleRows() const { |
1172 | return desiredVisibleRows; | |
1173 | } | |
1174 | ||
9e730a78 RD |
1175 | PRectangle ListBoxImpl::GetDesiredRect() { |
1176 | // wxListCtrl doesn't have a DoGetBestSize, so instead we kept track of | |
1177 | // the max size in Append and calculate it here... | |
1e9bafca | 1178 | int maxw = maxStrWidth * aveCharWidth; |
1e545382 | 1179 | int maxh ; |
9e730a78 RD |
1180 | |
1181 | // give it a default if there are no lines, and/or add a bit more | |
1182 | if (maxw == 0) maxw = 100; | |
1183 | maxw += aveCharWidth * 3 + | |
9e96e16f | 1184 | GETLBW(wid)->IconWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); |
9e730a78 RD |
1185 | if (maxw > 350) |
1186 | maxw = 350; | |
1187 | ||
1188 | // estimate a desired height | |
9e96e16f | 1189 | int count = GETLB(wid)->GetItemCount(); |
9e730a78 RD |
1190 | if (count) { |
1191 | wxRect rect; | |
9e96e16f | 1192 | GETLB(wid)->GetItemRect(0, rect); |
9e730a78 RD |
1193 | maxh = count * rect.GetHeight(); |
1194 | if (maxh > 140) // TODO: Use desiredVisibleRows?? | |
1195 | maxh = 140; | |
1196 | ||
1197 | // Try to make the size an exact multiple of some number of lines | |
1198 | int lines = maxh / rect.GetHeight(); | |
1199 | maxh = (lines + 1) * rect.GetHeight() + 2; | |
1200 | } | |
1201 | else | |
1202 | maxh = 100; | |
1203 | ||
d134f170 RD |
1204 | PRectangle rc; |
1205 | rc.top = 0; | |
1206 | rc.left = 0; | |
9e730a78 RD |
1207 | rc.right = maxw; |
1208 | rc.bottom = maxh; | |
d134f170 RD |
1209 | return rc; |
1210 | } | |
1211 | ||
d134f170 | 1212 | |
9e730a78 | 1213 | int ListBoxImpl::CaretFromEdge() { |
9e96e16f | 1214 | return 4 + GETLBW(wid)->IconWidth(); |
d134f170 RD |
1215 | } |
1216 | ||
9e730a78 RD |
1217 | |
1218 | void ListBoxImpl::Clear() { | |
9e96e16f | 1219 | GETLB(wid)->DeleteAllItems(); |
9ce192d4 RD |
1220 | } |
1221 | ||
9e730a78 RD |
1222 | |
1223 | void ListBoxImpl::Append(char *s, int type) { | |
1e9bafca RD |
1224 | Append(stc2wx(s), type); |
1225 | } | |
1226 | ||
1227 | void ListBoxImpl::Append(const wxString& text, int type) { | |
9e96e16f RD |
1228 | long count = GETLB(wid)->GetItemCount(); |
1229 | long itemID = GETLB(wid)->InsertItem(count, wxEmptyString); | |
038c0333 | 1230 | long idx = -1; |
9e96e16f | 1231 | GETLB(wid)->SetItem(itemID, 1, text); |
d35ad26e | 1232 | maxStrWidth = wxMax(maxStrWidth, text.length()); |
9e730a78 RD |
1233 | if (type != -1) { |
1234 | wxCHECK_RET(imgTypeMap, wxT("Unexpected NULL imgTypeMap")); | |
d67c3388 | 1235 | idx = imgTypeMap->Item(type); |
9e730a78 | 1236 | } |
9e96e16f | 1237 | GETLB(wid)->SetItemImage(itemID, idx, idx); |
9ce192d4 RD |
1238 | } |
1239 | ||
1e9bafca | 1240 | void ListBoxImpl::SetList(const char* list, char separator, char typesep) { |
9e96e16f | 1241 | GETLB(wid)->Freeze(); |
d35ad26e | 1242 | Clear(); |
1e9bafca RD |
1243 | wxStringTokenizer tkzr(stc2wx(list), (wxChar)separator); |
1244 | while ( tkzr.HasMoreTokens() ) { | |
1245 | wxString token = tkzr.GetNextToken(); | |
1246 | long type = -1; | |
1247 | int pos = token.Find(typesep); | |
1248 | if (pos != -1) { | |
1249 | token.Mid(pos+1).ToLong(&type); | |
1250 | token.Truncate(pos); | |
1251 | } | |
1252 | Append(token, (int)type); | |
1253 | } | |
9e96e16f | 1254 | GETLB(wid)->Thaw(); |
1e9bafca RD |
1255 | } |
1256 | ||
9e730a78 RD |
1257 | |
1258 | int ListBoxImpl::Length() { | |
9e96e16f | 1259 | return GETLB(wid)->GetItemCount(); |
9ce192d4 RD |
1260 | } |
1261 | ||
9e730a78 RD |
1262 | |
1263 | void ListBoxImpl::Select(int n) { | |
7e126a07 | 1264 | bool select = true; |
895066d8 RD |
1265 | if (n == -1) { |
1266 | n = 0; | |
7e126a07 | 1267 | select = false; |
895066d8 | 1268 | } |
9e96e16f RD |
1269 | GETLB(wid)->EnsureVisible(n); |
1270 | GETLB(wid)->Select(n, select); | |
9ce192d4 RD |
1271 | } |
1272 | ||
9e730a78 RD |
1273 | |
1274 | int ListBoxImpl::GetSelection() { | |
9e96e16f | 1275 | return GETLB(wid)->GetFirstSelected(); |
9ce192d4 RD |
1276 | } |
1277 | ||
9e730a78 | 1278 | |
88a8b04e | 1279 | int ListBoxImpl::Find(const char *WXUNUSED(prefix)) { |
b8b0e402 | 1280 | // No longer used |
7e126a07 | 1281 | return wxNOT_FOUND; |
9ce192d4 RD |
1282 | } |
1283 | ||
9e730a78 RD |
1284 | |
1285 | void ListBoxImpl::GetValue(int n, char *value, int len) { | |
1286 | wxListItem item; | |
1287 | item.SetId(n); | |
1288 | item.SetColumn(1); | |
1289 | item.SetMask(wxLIST_MASK_TEXT); | |
9e96e16f | 1290 | GETLB(wid)->GetItem(item); |
9e730a78 | 1291 | strncpy(value, wx2stc(item.GetText()), len); |
9ce192d4 RD |
1292 | value[len-1] = '\0'; |
1293 | } | |
1294 | ||
9b01abb8 RD |
1295 | void ListBoxImpl::RegisterImageHelper(int type, wxBitmap& bmp) |
1296 | { | |
9e730a78 RD |
1297 | if (! imgList) { |
1298 | // assumes all images are the same size | |
7e126a07 | 1299 | imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight(), true); |
9e730a78 RD |
1300 | imgTypeMap = new wxArrayInt; |
1301 | } | |
1302 | ||
1303 | int idx = imgList->Add(bmp); | |
1304 | ||
1305 | // do we need to extend the mapping array? | |
1306 | wxArrayInt& itm = *imgTypeMap; | |
9a8ffadd | 1307 | if ( itm.GetCount() < (size_t)type+1) |
9e730a78 RD |
1308 | itm.Add(-1, type - itm.GetCount() + 1); |
1309 | ||
1310 | // Add an item that maps type to the image index | |
1311 | itm[type] = idx; | |
1312 | } | |
1313 | ||
9b01abb8 RD |
1314 | void ListBoxImpl::RegisterImage(int type, const char *xpm_data) { |
1315 | wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1); | |
1316 | wxImage img(stream, wxBITMAP_TYPE_XPM); | |
1317 | wxBitmap bmp(img); | |
1318 | RegisterImageHelper(type, bmp); | |
1319 | } | |
1320 | ||
1321 | ||
1322 | void ListBoxImpl::RegisterRGBAImage(int type, int width, int height, | |
1323 | const unsigned char *pixelsImage) | |
1324 | { | |
1325 | wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage); | |
1326 | RegisterImageHelper(type, bmp); | |
1327 | } | |
1328 | ||
1329 | ||
9e730a78 | 1330 | void ListBoxImpl::ClearRegisteredImages() { |
5276b0a5 VZ |
1331 | wxDELETE(imgList); |
1332 | wxDELETE(imgTypeMap); | |
9e96e16f RD |
1333 | if (wid) |
1334 | GETLB(wid)->SetImageList(NULL, wxIMAGE_LIST_SMALL); | |
9e730a78 RD |
1335 | } |
1336 | ||
1337 | ||
1338 | void ListBoxImpl::SetDoubleClickAction(CallBackAction action, void *data) { | |
9e96e16f | 1339 | GETLBW(wid)->SetDoubleClickAction(action, data); |
9e730a78 RD |
1340 | } |
1341 | ||
1342 | ||
9e730a78 RD |
1343 | ListBox::ListBox() { |
1344 | } | |
1345 | ||
1346 | ListBox::~ListBox() { | |
1347 | } | |
1348 | ||
1349 | ListBox *ListBox::Allocate() { | |
1350 | return new ListBoxImpl(); | |
9ce192d4 RD |
1351 | } |
1352 | ||
1a2fb4cd | 1353 | //---------------------------------------------------------------------- |
9ce192d4 | 1354 | |
9e96e16f | 1355 | Menu::Menu() : mid(0) { |
9ce192d4 RD |
1356 | } |
1357 | ||
1358 | void Menu::CreatePopUp() { | |
1359 | Destroy(); | |
9e96e16f | 1360 | mid = new wxMenu(); |
9ce192d4 RD |
1361 | } |
1362 | ||
1363 | void Menu::Destroy() { | |
9e96e16f RD |
1364 | if (mid) |
1365 | delete (wxMenu*)mid; | |
1366 | mid = 0; | |
9ce192d4 RD |
1367 | } |
1368 | ||
1369 | void Menu::Show(Point pt, Window &w) { | |
9e96e16f | 1370 | GETWIN(w.GetID())->PopupMenu((wxMenu*)mid, pt.x - 4, pt.y); |
9ce192d4 RD |
1371 | Destroy(); |
1372 | } | |
1373 | ||
1a2fb4cd | 1374 | //---------------------------------------------------------------------- |
9ce192d4 | 1375 | |
88a8b04e | 1376 | DynamicLibrary *DynamicLibrary::Load(const char *WXUNUSED(modulePath)) { |
e14d10b0 RD |
1377 | wxFAIL_MSG(wxT("Dynamic lexer loading not implemented yet")); |
1378 | return NULL; | |
1379 | } | |
1380 | ||
1381 | //---------------------------------------------------------------------- | |
1382 | ||
1a2fb4cd | 1383 | ColourDesired Platform::Chrome() { |
9ce192d4 | 1384 | wxColour c; |
e1c6c6ae | 1385 | c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
1a2fb4cd | 1386 | return ColourDesired(c.Red(), c.Green(), c.Blue()); |
9ce192d4 RD |
1387 | } |
1388 | ||
1a2fb4cd | 1389 | ColourDesired Platform::ChromeHighlight() { |
9ce192d4 | 1390 | wxColour c; |
e1c6c6ae | 1391 | c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT); |
1a2fb4cd | 1392 | return ColourDesired(c.Red(), c.Green(), c.Blue()); |
9ce192d4 RD |
1393 | } |
1394 | ||
1395 | const char *Platform::DefaultFont() { | |
10ef30eb RD |
1396 | static char buf[128]; |
1397 | strcpy(buf, wxNORMAL_FONT->GetFaceName().mbc_str()); | |
1398 | return buf; | |
9ce192d4 RD |
1399 | } |
1400 | ||
1401 | int Platform::DefaultFontSize() { | |
9e730a78 | 1402 | return wxNORMAL_FONT->GetPointSize(); |
9ce192d4 RD |
1403 | } |
1404 | ||
1405 | unsigned int Platform::DoubleClickTime() { | |
1406 | return 500; // **** ::GetDoubleClickTime(); | |
1407 | } | |
1408 | ||
9e730a78 | 1409 | bool Platform::MouseButtonBounce() { |
7e126a07 | 1410 | return false; |
9e730a78 | 1411 | } |
9ce192d4 | 1412 | |
88a8b04e | 1413 | bool Platform::IsKeyDown(int WXUNUSED(key)) { |
9ce192d4 RD |
1414 | return false; // I don't think we'll need this. |
1415 | } | |
1416 | ||
1417 | long Platform::SendScintilla(WindowID w, | |
1418 | unsigned int msg, | |
1419 | unsigned long wParam, | |
1420 | long lParam) { | |
1421 | ||
1422 | wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w; | |
1423 | return stc->SendMsg(msg, wParam, lParam); | |
1424 | } | |
1425 | ||
a834585d RD |
1426 | long Platform::SendScintillaPointer(WindowID w, |
1427 | unsigned int msg, | |
1428 | unsigned long wParam, | |
1429 | void *lParam) { | |
1430 | ||
1431 | wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w; | |
b796ba39 | 1432 | return stc->SendMsg(msg, wParam, (wxIntPtr)lParam); |
a834585d RD |
1433 | } |
1434 | ||
9ce192d4 RD |
1435 | |
1436 | // These are utility functions not really tied to a platform | |
1437 | ||
1438 | int Platform::Minimum(int a, int b) { | |
1439 | if (a < b) | |
1440 | return a; | |
1441 | else | |
1442 | return b; | |
1443 | } | |
1444 | ||
1445 | int Platform::Maximum(int a, int b) { | |
1446 | if (a > b) | |
1447 | return a; | |
1448 | else | |
1449 | return b; | |
1450 | } | |
1451 | ||
74e1efdd VZ |
1452 | //#define TRACE |
1453 | ||
1454 | void Platform::DebugDisplay(const char *s) { | |
1455 | #ifdef TRACE | |
1456 | wxLogDebug(stc2wx(s)); | |
1457 | #else | |
1458 | wxUnusedVar(s); | |
1459 | #endif | |
1460 | } | |
9ce192d4 RD |
1461 | |
1462 | void Platform::DebugPrintf(const char *format, ...) { | |
1463 | #ifdef TRACE | |
1464 | char buffer[2000]; | |
1465 | va_list pArguments; | |
1466 | va_start(pArguments, format); | |
1467 | vsprintf(buffer,format,pArguments); | |
1468 | va_end(pArguments); | |
1469 | Platform::DebugDisplay(buffer); | |
8d3a5374 VZ |
1470 | #else |
1471 | wxUnusedVar(format); | |
9ce192d4 RD |
1472 | #endif |
1473 | } | |
1474 | ||
65ec6247 RD |
1475 | |
1476 | static bool assertionPopUps = true; | |
1477 | ||
1478 | bool Platform::ShowAssertionPopUps(bool assertionPopUps_) { | |
7e126a07 WS |
1479 | bool ret = assertionPopUps; |
1480 | assertionPopUps = assertionPopUps_; | |
1481 | return ret; | |
65ec6247 RD |
1482 | } |
1483 | ||
1484 | void Platform::Assert(const char *c, const char *file, int line) { | |
74e1efdd | 1485 | #ifdef TRACE |
7e126a07 WS |
1486 | char buffer[2000]; |
1487 | sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line); | |
1488 | if (assertionPopUps) { | |
1489 | /*int idButton = */ | |
1490 | wxMessageBox(stc2wx(buffer), | |
1491 | wxT("Assertion failure"), | |
1492 | wxICON_HAND | wxOK); | |
7e126a07 WS |
1493 | } else { |
1494 | strcat(buffer, "\r\n"); | |
1495 | Platform::DebugDisplay(buffer); | |
1496 | abort(); | |
1497 | } | |
74e1efdd VZ |
1498 | #else |
1499 | wxUnusedVar(c); | |
1500 | wxUnusedVar(file); | |
1501 | wxUnusedVar(line); | |
1502 | #endif | |
65ec6247 RD |
1503 | } |
1504 | ||
1505 | ||
9ce192d4 RD |
1506 | int Platform::Clamp(int val, int minVal, int maxVal) { |
1507 | if (val > maxVal) | |
1508 | val = maxVal; | |
1509 | if (val < minVal) | |
1510 | val = minVal; | |
1511 | return val; | |
1512 | } | |
1513 | ||
1514 | ||
88a8b04e | 1515 | bool Platform::IsDBCSLeadByte(int WXUNUSED(codePage), char WXUNUSED(ch)) { |
1a2fb4cd RD |
1516 | return false; |
1517 | } | |
1518 | ||
88a8b04e | 1519 | int Platform::DBCSCharLength(int WXUNUSED(codePage), const char *WXUNUSED(s)) { |
215ef7ae | 1520 | return 1; |
9e730a78 RD |
1521 | } |
1522 | ||
1523 | int Platform::DBCSCharMaxLength() { | |
215ef7ae | 1524 | return 1; |
9e730a78 | 1525 | } |
1a2fb4cd RD |
1526 | |
1527 | ||
1528 | //---------------------------------------------------------------------- | |
1529 | ||
1530 | ElapsedTime::ElapsedTime() { | |
1d94e268 WS |
1531 | wxLongLong localTime = wxGetLocalTimeMillis(); |
1532 | littleBit = localTime.GetLo(); | |
1533 | bigBit = localTime.GetHi(); | |
1a2fb4cd RD |
1534 | } |
1535 | ||
1536 | double ElapsedTime::Duration(bool reset) { | |
1d94e268 WS |
1537 | wxLongLong prevTime(bigBit, littleBit); |
1538 | wxLongLong localTime = wxGetLocalTimeMillis(); | |
1539 | if(reset) { | |
1540 | littleBit = localTime.GetLo(); | |
1541 | bigBit = localTime.GetHi(); | |
1542 | } | |
1543 | wxLongLong duration = localTime - prevTime; | |
1544 | double result = duration.ToDouble(); | |
1a2fb4cd RD |
1545 | result /= 1000.0; |
1546 | return result; | |
1547 | } | |
1548 | ||
1549 | ||
1550 | //---------------------------------------------------------------------- | |
9ce192d4 | 1551 | |
d99859e4 | 1552 | #if wxUSE_UNICODE |
6636ac1e RD |
1553 | |
1554 | #include "UniConversion.h" | |
1555 | ||
1556 | // Convert using Scintilla's functions instead of wx's, Scintilla's are more | |
1557 | // forgiving and won't assert... | |
c8b75e94 | 1558 | |
d99859e4 RD |
1559 | wxString stc2wx(const char* str, size_t len) |
1560 | { | |
81bfa5ae RD |
1561 | if (!len) |
1562 | return wxEmptyString; | |
8a07b43c | 1563 | |
7e0c58e9 | 1564 | size_t wclen = UTF16Length(str, len); |
6636ac1e RD |
1565 | wxWCharBuffer buffer(wclen+1); |
1566 | ||
7e0c58e9 | 1567 | size_t actualLen = UTF16FromUTF8(str, len, buffer.data(), wclen+1); |
6636ac1e RD |
1568 | return wxString(buffer.data(), actualLen); |
1569 | } | |
1570 | ||
d99859e4 | 1571 | |
d99859e4 | 1572 | |
6636ac1e RD |
1573 | wxString stc2wx(const char* str) |
1574 | { | |
1575 | return stc2wx(str, strlen(str)); | |
d99859e4 | 1576 | } |
6636ac1e RD |
1577 | |
1578 | ||
2ed48ef8 | 1579 | wxWX2MBbuf wx2stc(const wxString& str) |
6636ac1e RD |
1580 | { |
1581 | const wchar_t* wcstr = str.c_str(); | |
1582 | size_t wclen = str.length(); | |
1583 | size_t len = UTF8Length(wcstr, wclen); | |
1584 | ||
1585 | wxCharBuffer buffer(len+1); | |
7e0c58e9 | 1586 | UTF8FromUTF16(wcstr, wclen, buffer.data(), len); |
6636ac1e RD |
1587 | |
1588 | // TODO check NULL termination!! | |
1589 | ||
6636ac1e RD |
1590 | return buffer; |
1591 | } | |
1592 | ||
d99859e4 | 1593 | #endif |
29825f5f PC |
1594 | |
1595 | #endif // wxUSE_STC |