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