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