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