]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/src/stc/PlatWX.cpp
update watcom makefile
[wxWidgets.git] / contrib / src / stc / PlatWX.cpp
... / ...
CommitLineData
1// Scintilla source code edit control
2// PlatWX.cxx - implementation of platform facilities on wxWindows
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
12
13#include "Platform.h"
14#include "PlatWX.h"
15#include "wx/stc/stc.h"
16
17
18#ifdef __WXGTK__
19#include <gtk/gtk.h>
20#endif
21
22
23Point Point::FromLong(long lpoint) {
24 return Point(lpoint & 0xFFFF, lpoint >> 16);
25}
26
27wxRect wxRectFromPRectangle(PRectangle prc) {
28 wxRect rc(prc.left, prc.top,
29 prc.right-prc.left, prc.bottom-prc.top);
30 return rc;
31}
32
33PRectangle PRectangleFromwxRect(wxRect rc) {
34 return PRectangle(rc.GetLeft(), rc.GetTop(),
35 rc.GetRight()+1, rc.GetBottom()+1);
36}
37
38wxColour wxColourFromCA(const ColourAllocated& ca) {
39 ColourDesired cd(ca.AsLong());
40 return wxColour(cd.GetRed(), cd.GetGreen(), cd.GetBlue());
41}
42
43//----------------------------------------------------------------------
44
45Palette::Palette() {
46 used = 0;
47 allowRealization = false;
48}
49
50Palette::~Palette() {
51 Release();
52}
53
54void Palette::Release() {
55 used = 0;
56}
57
58// This method either adds a colour to the list of wanted colours (want==true)
59// or retrieves the allocated colour back to the ColourPair.
60// This is one method to make it easier to keep the code for wanting and retrieving in sync.
61void Palette::WantFind(ColourPair &cp, bool want) {
62 if (want) {
63 for (int i=0; i < used; i++) {
64 if (entries[i].desired == cp.desired)
65 return;
66 }
67
68 if (used < numEntries) {
69 entries[used].desired = cp.desired;
70 entries[used].allocated.Set(cp.desired.AsLong());
71 used++;
72 }
73 } else {
74 for (int i=0; i < used; i++) {
75 if (entries[i].desired == cp.desired) {
76 cp.allocated = entries[i].allocated;
77 return;
78 }
79 }
80 cp.allocated.Set(cp.desired.AsLong());
81 }
82}
83
84void Palette::Allocate(Window &) {
85 if (allowRealization) {
86 }
87}
88
89
90//----------------------------------------------------------------------
91
92Font::Font() {
93 id = 0;
94 ascent = 0;
95}
96
97Font::~Font() {
98}
99
100void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic) {
101 wxFontEncoding encoding;
102
103 Release();
104
105 switch (characterSet) {
106 default:
107 case wxSTC_CHARSET_ANSI:
108 case wxSTC_CHARSET_DEFAULT:
109 encoding = wxFONTENCODING_DEFAULT;
110 break;
111
112 case wxSTC_CHARSET_BALTIC:
113 encoding = wxFONTENCODING_ISO8859_13;
114 break;
115
116 case wxSTC_CHARSET_CHINESEBIG5:
117 encoding = wxFONTENCODING_CP950;
118 break;
119
120 case wxSTC_CHARSET_EASTEUROPE:
121 encoding = wxFONTENCODING_ISO8859_2;
122 break;
123
124 case wxSTC_CHARSET_GB2312:
125 encoding = wxFONTENCODING_CP936;
126 break;
127
128 case wxSTC_CHARSET_GREEK:
129 encoding = wxFONTENCODING_ISO8859_7;
130 break;
131
132 case wxSTC_CHARSET_HANGUL:
133 encoding = wxFONTENCODING_CP949;
134 break;
135
136 case wxSTC_CHARSET_MAC:
137 encoding = wxFONTENCODING_DEFAULT;
138 break;
139
140 case wxSTC_CHARSET_OEM:
141 encoding = wxFONTENCODING_DEFAULT;
142 break;
143
144 case wxSTC_CHARSET_RUSSIAN:
145 encoding = wxFONTENCODING_KOI8;
146 break;
147
148 case wxSTC_CHARSET_SHIFTJIS:
149 encoding = wxFONTENCODING_CP932;
150 break;
151
152 case wxSTC_CHARSET_SYMBOL:
153 encoding = wxFONTENCODING_DEFAULT;
154 break;
155
156 case wxSTC_CHARSET_TURKISH:
157 encoding = wxFONTENCODING_ISO8859_9;
158 break;
159
160 case wxSTC_CHARSET_JOHAB:
161 encoding = wxFONTENCODING_DEFAULT;
162 break;
163
164 case wxSTC_CHARSET_HEBREW:
165 encoding = wxFONTENCODING_ISO8859_8;
166 break;
167
168 case wxSTC_CHARSET_ARABIC:
169 encoding = wxFONTENCODING_ISO8859_6;
170 break;
171
172 case wxSTC_CHARSET_VIETNAMESE:
173 encoding = wxFONTENCODING_DEFAULT;
174 break;
175
176 case wxSTC_CHARSET_THAI:
177 encoding = wxFONTENCODING_ISO8859_11;
178 break;
179 }
180
181 wxFontEncodingArray ea = wxEncodingConverter::GetPlatformEquivalents(encoding);
182 if (ea.GetCount())
183 encoding = ea[0];
184
185 id = new wxFont(size,
186 wxDEFAULT,
187 italic ? wxITALIC : wxNORMAL,
188 bold ? wxBOLD : wxNORMAL,
189 false,
190 stc2wx(faceName),
191 encoding);
192#ifdef __WXMAC__
193 ((wxFont*)id)->SetNoAntiAliasing( true ) ;
194#endif
195}
196
197
198void Font::Release() {
199 if (id)
200 delete (wxFont*)id;
201 id = 0;
202}
203
204//----------------------------------------------------------------------
205
206class SurfaceImpl : public Surface {
207private:
208 wxDC* hdc;
209 bool hdcOwned;
210 wxBitmap* bitmap;
211 int x;
212 int y;
213 bool unicodeMode;
214
215public:
216 SurfaceImpl();
217 ~SurfaceImpl();
218
219 void Init();
220 void Init(SurfaceID sid);
221 void InitPixMap(int width, int height, Surface *surface_);
222
223 void Release();
224 bool Initialised();
225 void PenColour(ColourAllocated fore);
226 int LogPixelsY();
227 int DeviceHeightFont(int points);
228 void MoveTo(int x_, int y_);
229 void LineTo(int x_, int y_);
230 void Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back);
231 void RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back);
232 void FillRectangle(PRectangle rc, ColourAllocated back);
233 void FillRectangle(PRectangle rc, Surface &surfacePattern);
234 void RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back);
235 void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back);
236 void Copy(PRectangle rc, Point from, Surface &surfaceSource);
237
238 void DrawTextNoClip(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back);
239 void DrawTextClipped(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back);
240 void MeasureWidths(Font &font_, const char *s, int len, int *positions);
241 int WidthText(Font &font_, const char *s, int len);
242 int WidthChar(Font &font_, char ch);
243 int Ascent(Font &font_);
244 int Descent(Font &font_);
245 int InternalLeading(Font &font_);
246 int ExternalLeading(Font &font_);
247 int Height(Font &font_);
248 int AverageCharWidth(Font &font_);
249
250 int SetPalette(Palette *pal, bool inBackGround);
251 void SetClip(PRectangle rc);
252 void FlushCachedState();
253
254 void SetUnicodeMode(bool unicodeMode_);
255
256 void BrushColour(ColourAllocated back);
257 void SetFont(Font &font_);
258};
259
260
261
262SurfaceImpl::SurfaceImpl() :
263 hdc(0), hdcOwned(0), bitmap(0),
264 x(0), y(0), unicodeMode(0)
265{}
266
267SurfaceImpl::~SurfaceImpl() {
268 Release();
269}
270
271void SurfaceImpl::Release() {
272 if (bitmap) {
273 ((wxMemoryDC*)hdc)->SelectObject(wxNullBitmap);
274 delete bitmap;
275 bitmap = 0;
276 }
277 if (hdcOwned) {
278 delete hdc;
279 hdc = 0;
280 hdcOwned = false;
281 }
282}
283
284
285bool SurfaceImpl::Initialised() {
286 return hdc != 0;
287}
288
289void SurfaceImpl::Init() {
290#if 0
291 Release();
292 hdc = new wxMemoryDC();
293 hdcOwned = true;
294#else
295 // On Mac and GTK the DC is not really valid until it has a bitmap
296 // selected into it. So instead of just creating the DC with no bitmap,
297 // go ahead and give it one.
298 InitPixMap(1,1,NULL);
299#endif
300}
301
302void SurfaceImpl::Init(SurfaceID hdc_) {
303 Release();
304 hdc = (wxDC*)hdc_;
305}
306
307void SurfaceImpl::InitPixMap(int width, int height, Surface *surface_) {
308 Release();
309 hdc = new wxMemoryDC();
310 hdcOwned = true;
311 if (width < 1) width = 1;
312 if (height < 1) height = 1;
313 bitmap = new wxBitmap(width, height);
314 ((wxMemoryDC*)hdc)->SelectObject(*bitmap);
315}
316
317void SurfaceImpl::PenColour(ColourAllocated fore) {
318 hdc->SetPen(wxPen(wxColourFromCA(fore), 1, wxSOLID));
319}
320
321void SurfaceImpl::BrushColour(ColourAllocated back) {
322 hdc->SetBrush(wxBrush(wxColourFromCA(back), wxSOLID));
323}
324
325void SurfaceImpl::SetFont(Font &font_) {
326 if (font_.GetID()) {
327 hdc->SetFont(*((wxFont*)font_.GetID()));
328 }
329}
330
331int SurfaceImpl::LogPixelsY() {
332 return hdc->GetPPI().y;
333}
334
335int SurfaceImpl::DeviceHeightFont(int points) {
336 return points;
337}
338
339void SurfaceImpl::MoveTo(int x_, int y_) {
340 x = x_;
341 y = y_;
342}
343
344void SurfaceImpl::LineTo(int x_, int y_) {
345 hdc->DrawLine(x,y, x_,y_);
346 x = x_;
347 y = y_;
348}
349
350void SurfaceImpl::Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back) {
351 PenColour(fore);
352 BrushColour(back);
353 hdc->DrawPolygon(npts, (wxPoint*)pts);
354}
355
356void SurfaceImpl::RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back) {
357 PenColour(fore);
358 BrushColour(back);
359 hdc->DrawRectangle(wxRectFromPRectangle(rc));
360}
361
362void SurfaceImpl::FillRectangle(PRectangle rc, ColourAllocated back) {
363 BrushColour(back);
364 hdc->SetPen(*wxTRANSPARENT_PEN);
365 hdc->DrawRectangle(wxRectFromPRectangle(rc));
366}
367
368void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) {
369 wxBrush br;
370 if (((SurfaceImpl&)surfacePattern).bitmap)
371 br = wxBrush(*((SurfaceImpl&)surfacePattern).bitmap);
372 else // Something is wrong so display in red
373 br = wxBrush(*wxRED, wxSOLID);
374 hdc->SetPen(*wxTRANSPARENT_PEN);
375 hdc->SetBrush(br);
376 hdc->DrawRectangle(wxRectFromPRectangle(rc));
377}
378
379void SurfaceImpl::RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back) {
380 PenColour(fore);
381 BrushColour(back);
382 hdc->DrawRoundedRectangle(wxRectFromPRectangle(rc), 4);
383}
384
385void SurfaceImpl::Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back) {
386 PenColour(fore);
387 BrushColour(back);
388 hdc->DrawEllipse(wxRectFromPRectangle(rc));
389}
390
391void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) {
392 wxRect r = wxRectFromPRectangle(rc);
393 hdc->Blit(r.x, r.y, r.width, r.height,
394 ((SurfaceImpl&)surfaceSource).hdc,
395 from.x, from.y, wxCOPY);
396}
397
398void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, int ybase,
399 const char *s, int len,
400 ColourAllocated fore, ColourAllocated back) {
401 SetFont(font);
402 hdc->SetTextForeground(wxColourFromCA(fore));
403 hdc->SetTextBackground(wxColourFromCA(back));
404 FillRectangle(rc, back);
405
406 // ybase is where the baseline should be, but wxWin uses the upper left
407 // corner, so I need to calculate the real position for the text...
408 hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent);
409}
410
411void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase,
412 const char *s, int len,
413 ColourAllocated fore, ColourAllocated back) {
414 SetFont(font);
415 hdc->SetTextForeground(wxColourFromCA(fore));
416 hdc->SetTextBackground(wxColourFromCA(back));
417 FillRectangle(rc, back);
418 hdc->SetClippingRegion(wxRectFromPRectangle(rc));
419
420 // see comments above
421 hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent);
422 hdc->DestroyClippingRegion();
423}
424
425int SurfaceImpl::WidthText(Font &font, const char *s, int len) {
426 SetFont(font);
427 int w;
428 int h;
429
430 hdc->GetTextExtent(stc2wx(s, len), &w, &h);
431 return w;
432}
433
434
435void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) {
436 wxString str = stc2wx(s, len);
437 SetFont(font);
438
439 // Calculate the position of each character based on the widths of
440 // the previous characters
441 int* tpos = new int[len];
442 int totalWidth = 0;
443 size_t i;
444 for (i=0; i<str.Length(); i++) {
445 int w, h;
446 hdc->GetTextExtent(str[i], &w, &h);
447 totalWidth += w;
448 tpos[i] = totalWidth;
449 }
450
451#if wxUSE_UNICODE
452 // Map the widths for UCS-2 characters back to the UTF-8 input string
453 i = 0;
454 size_t ui = 0;
455 while (i < len) {
456 unsigned char uch = (unsigned char)s[i];
457 positions[i++] = tpos[ui];
458 if (uch >= 0x80) {
459 if (uch < (0x80 + 0x40 + 0x20)) {
460 positions[i++] = tpos[ui];
461 } else {
462 positions[i++] = tpos[ui];
463 positions[i++] = tpos[ui];
464 }
465 }
466 ui++;
467 }
468#else
469
470 // If not unicode then just use the widths we have
471 memcpy(positions, tpos, len * sizeof(*tpos));
472#endif
473
474 delete [] tpos;
475}
476
477
478int SurfaceImpl::WidthChar(Font &font, char ch) {
479 SetFont(font);
480 int w;
481 int h;
482 char s[2] = { ch, 0 };
483
484 hdc->GetTextExtent(stc2wx(s, 1), &w, &h);
485 return w;
486}
487
488#define EXTENT_TEST wxT(" `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
489
490int SurfaceImpl::Ascent(Font &font) {
491 SetFont(font);
492 int w, h, d, e;
493 hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
494 font.ascent = h - d;
495 return font.ascent;
496}
497
498int SurfaceImpl::Descent(Font &font) {
499 SetFont(font);
500 int w, h, d, e;
501 hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
502 return d;
503}
504
505int SurfaceImpl::InternalLeading(Font &font) {
506 return 0;
507}
508
509int SurfaceImpl::ExternalLeading(Font &font) {
510 SetFont(font);
511 int w, h, d, e;
512 hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
513 return e;
514}
515
516int SurfaceImpl::Height(Font &font) {
517 SetFont(font);
518 return hdc->GetCharHeight();
519}
520
521int SurfaceImpl::AverageCharWidth(Font &font) {
522 SetFont(font);
523 return hdc->GetCharWidth();
524}
525
526int SurfaceImpl::SetPalette(Palette *pal, bool inBackGround) {
527 return 0;
528}
529
530void SurfaceImpl::SetClip(PRectangle rc) {
531 hdc->SetClippingRegion(wxRectFromPRectangle(rc));
532}
533
534void SurfaceImpl::FlushCachedState() {
535}
536
537void SurfaceImpl::SetUnicodeMode(bool unicodeMode_) {
538 unicodeMode=unicodeMode_;
539#if wxUSE_UNICODE
540 wxASSERT_MSG(unicodeMode == wxUSE_UNICODE,
541 wxT("Only unicode may be used when wxUSE_UNICODE is on."));
542#else
543 wxASSERT_MSG(unicodeMode == wxUSE_UNICODE,
544 wxT("Only non-unicode may be used when wxUSE_UNICODE is off."));
545#endif
546}
547
548Surface *Surface::Allocate() {
549 return new SurfaceImpl;
550}
551
552
553//----------------------------------------------------------------------
554
555
556inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; }
557
558Window::~Window() {
559}
560
561void Window::Destroy() {
562 if (id)
563 GETWIN(id)->Destroy();
564 id = 0;
565}
566
567bool Window::HasFocus() {
568 return wxWindow::FindFocus() == GETWIN(id);
569}
570
571PRectangle Window::GetPosition() {
572 wxRect rc(GETWIN(id)->GetPosition(), GETWIN(id)->GetSize());
573 return PRectangleFromwxRect(rc);
574}
575
576void Window::SetPosition(PRectangle rc) {
577 wxRect r = wxRectFromPRectangle(rc);
578 GETWIN(id)->SetSize(r);
579}
580
581void Window::SetPositionRelative(PRectangle rc, Window) {
582 SetPosition(rc); // ????
583}
584
585PRectangle Window::GetClientPosition() {
586 wxSize sz = GETWIN(id)->GetClientSize();
587 return PRectangle(0, 0, sz.x, sz.y);
588}
589
590void Window::Show(bool show) {
591 GETWIN(id)->Show(show);
592}
593
594void Window::InvalidateAll() {
595 GETWIN(id)->Refresh(false);
596 wxWakeUpIdle();
597}
598
599void Window::InvalidateRectangle(PRectangle rc) {
600 wxRect r = wxRectFromPRectangle(rc);
601 GETWIN(id)->Refresh(false, &r);
602 wxWakeUpIdle();
603}
604
605void Window::SetFont(Font &font) {
606 GETWIN(id)->SetFont(*((wxFont*)font.GetID()));
607}
608
609void Window::SetCursor(Cursor curs) {
610 int cursorId;
611
612 switch (curs) {
613 case cursorText:
614 cursorId = wxCURSOR_IBEAM;
615 break;
616 case cursorArrow:
617 cursorId = wxCURSOR_ARROW;
618 break;
619 case cursorUp:
620 cursorId = wxCURSOR_ARROW; // ** no up arrow... wxCURSOR_UPARROW;
621 break;
622 case cursorWait:
623 cursorId = wxCURSOR_WAIT;
624 break;
625 case cursorHoriz:
626 cursorId = wxCURSOR_SIZEWE;
627 break;
628 case cursorVert:
629 cursorId = wxCURSOR_SIZENS;
630 break;
631 case cursorReverseArrow:
632 cursorId = wxCURSOR_RIGHT_ARROW;
633 break;
634 default:
635 cursorId = wxCURSOR_ARROW;
636 break;
637 }
638#ifdef __WXMOTIF__
639 wxCursor wc = wxStockCursor(cursorId) ;
640#else
641 wxCursor wc = wxCursor(cursorId) ;
642#endif
643 GETWIN(id)->SetCursor(wc);
644}
645
646
647void Window::SetTitle(const char *s) {
648 GETWIN(id)->SetTitle(stc2wx(s));
649}
650
651
652//----------------------------------------------------------------------
653// Helper classes for ListBox
654
655
656#if 1 // defined(__WXMAC__)
657class wxSTCListBoxWin : public wxListBox {
658public:
659 wxSTCListBoxWin(wxWindow* parent, wxWindowID id)
660 : wxListBox(parent, id, wxDefaultPosition, wxSize(0,0),
661 0, NULL, wxLB_SINGLE | wxSIMPLE_BORDER) {
662 SetCursor(wxCursor(wxCURSOR_ARROW));
663 Hide();
664 }
665
666 void OnFocus(wxFocusEvent& event) {
667 GetParent()->SetFocus();
668 event.Skip();
669 }
670
671 wxListBox* GetLB() { return this; }
672
673private:
674 DECLARE_EVENT_TABLE()
675};
676
677
678BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxListBox)
679 EVT_SET_FOCUS(wxSTCListBoxWin::OnFocus)
680END_EVENT_TABLE()
681
682
683
684#else
685
686
687class wxSTCListBox : public wxListBox {
688public:
689 wxSTCListBox(wxWindow* parent, wxWindowID id)
690 : wxListBox(parent, id, wxDefaultPosition, wxDefaultSize,
691 0, NULL, wxLB_SINGLE | wxSIMPLE_BORDER | wxWANTS_CHARS)
692 {}
693
694 void OnKeyDown(wxKeyEvent& event) {
695 // Give the key events to the STC. It will then update
696 // the listbox as needed.
697 GetGrandParent()->GetEventHandler()->ProcessEvent(event);
698 }
699
700private:
701 DECLARE_EVENT_TABLE()
702};
703
704BEGIN_EVENT_TABLE(wxSTCListBox, wxListBox)
705 EVT_KEY_DOWN(wxSTCListBox::OnKeyDown)
706 EVT_CHAR(wxSTCListBox::OnKeyDown)
707END_EVENT_TABLE()
708
709
710
711#undef wxSTC_USE_POPUP
712#define wxSTC_USE_POPUP 0 // wxPopupWindow just doesn't work well in this case...
713
714// A window to place the listbox upon. If wxPopupWindow is supported then
715// that will be used so the listbox can extend beyond the client area of the
716// wxSTC if needed.
717#if wxUSE_POPUPWIN && wxSTC_USE_POPUP
718#include <wx/popupwin.h>
719#define wxSTCListBoxWinBase wxPopupWindow
720#define param2 wxBORDER_NONE // popup's 2nd param is flags
721#else
722#define wxSTCListBoxWinBase wxWindow
723#define param2 -1 // wxWindow's 2nd param is ID
724#endif
725
726class wxSTCListBoxWin : public wxSTCListBoxWinBase {
727public:
728 wxSTCListBoxWin(wxWindow* parent, wxWindowID id)
729 : wxSTCListBoxWinBase(parent, param2) {
730 lb = new wxSTCListBox(this, id);
731 lb->SetCursor(wxCursor(wxCURSOR_ARROW));
732 lb->SetFocus();
733 }
734
735 void OnSize(wxSizeEvent& event) {
736 lb->SetSize(GetSize());
737 }
738
739 wxListBox* GetLB() { return lb; }
740
741#if wxUSE_POPUPWIN && wxSTC_USE_POPUP
742 virtual void DoSetSize(int x, int y,
743 int width, int height,
744 int sizeFlags = wxSIZE_AUTO) {
745 if (x != -1)
746 GetParent()->ClientToScreen(&x, NULL);
747 if (y != -1)
748 GetParent()->ClientToScreen(NULL, &y);
749 wxSTCListBoxWinBase::DoSetSize(x, y, width, height, sizeFlags);
750 }
751#endif
752
753private:
754 wxSTCListBox* lb;
755 DECLARE_EVENT_TABLE()
756};
757
758BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxSTCListBoxWinBase)
759 EVT_SIZE(wxSTCListBoxWin::OnSize)
760END_EVENT_TABLE()
761#endif
762
763inline wxListBox* GETLB(WindowID win) {
764 return (((wxSTCListBoxWin*)win)->GetLB());
765}
766
767//----------------------------------------------------------------------
768
769ListBox::ListBox() {
770}
771
772ListBox::~ListBox() {
773}
774
775void ListBox::Create(Window &parent, int ctrlID) {
776 id = new wxSTCListBoxWin(GETWIN(parent.GetID()), ctrlID);
777}
778
779void ListBox::SetVisibleRows(int rows) {
780 desiredVisibleRows = rows;
781}
782
783PRectangle ListBox::GetDesiredRect() {
784 wxSize sz = GETLB(id)->GetBestSize();
785 PRectangle rc;
786 rc.top = 0;
787 rc.left = 0;
788 if (sz.x > 400)
789 sz.x = 400;
790 if (sz.y > 140) // TODO: Use desiredVisibleRows??
791 sz.y = 140;
792 rc.right = sz.x;
793 rc.bottom = sz.y;
794 return rc;
795}
796
797void ListBox::SetAverageCharWidth(int width) {
798 aveCharWidth = width;
799}
800
801void ListBox::SetFont(Font &font) {
802 GETLB(id)->SetFont(*((wxFont*)font.GetID()));
803}
804
805void ListBox::Clear() {
806 GETLB(id)->Clear();
807}
808
809void ListBox::Append(char *s) {
810 GETLB(id)->Append(stc2wx(s));
811}
812
813int ListBox::Length() {
814 return GETLB(id)->GetCount();
815}
816
817void ListBox::Select(int n) {
818 bool select = TRUE;
819 if (n == -1) {
820 n = 0;
821 select = FALSE;
822 }
823 GETLB(id)->SetSelection(n, select);
824#ifdef __WXGTK__
825 if (n > 4)
826 n = n - 4;
827 else
828 n = 0;
829 GETLB(id)->SetFirstItem(n);
830#endif
831}
832
833int ListBox::GetSelection() {
834 return GETLB(id)->GetSelection();
835}
836
837int ListBox::Find(const char *prefix) {
838 // No longer used
839 return -1;
840}
841
842void ListBox::GetValue(int n, char *value, int len) {
843 wxString text = GETLB(id)->GetString(n);
844 strncpy(value, wx2stc(text), len);
845 value[len-1] = '\0';
846}
847
848void ListBox::Sort() {
849}
850
851//----------------------------------------------------------------------
852
853Menu::Menu() : id(0) {
854}
855
856void Menu::CreatePopUp() {
857 Destroy();
858 id = new wxMenu();
859}
860
861void Menu::Destroy() {
862 if (id)
863 delete (wxMenu*)id;
864 id = 0;
865}
866
867void Menu::Show(Point pt, Window &w) {
868 GETWIN(w.GetID())->PopupMenu((wxMenu*)id, pt.x - 4, pt.y);
869 Destroy();
870}
871
872//----------------------------------------------------------------------
873
874ColourDesired Platform::Chrome() {
875 wxColour c;
876 c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
877 return ColourDesired(c.Red(), c.Green(), c.Blue());
878}
879
880ColourDesired Platform::ChromeHighlight() {
881 wxColour c;
882 c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
883 return ColourDesired(c.Red(), c.Green(), c.Blue());
884}
885
886const char *Platform::DefaultFont() {
887 static char buf[128];
888 strcpy(buf, wxNORMAL_FONT->GetFaceName().mbc_str());
889 return buf;
890}
891
892int Platform::DefaultFontSize() {
893 return 8;
894}
895
896unsigned int Platform::DoubleClickTime() {
897 return 500; // **** ::GetDoubleClickTime();
898}
899
900void Platform::DebugDisplay(const char *s) {
901 wxLogDebug(stc2wx(s));
902}
903
904bool Platform::IsKeyDown(int key) {
905 return false; // I don't think we'll need this.
906}
907
908long Platform::SendScintilla(WindowID w,
909 unsigned int msg,
910 unsigned long wParam,
911 long lParam) {
912
913 wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w;
914 return stc->SendMsg(msg, wParam, lParam);
915}
916
917long Platform::SendScintillaPointer(WindowID w,
918 unsigned int msg,
919 unsigned long wParam,
920 void *lParam) {
921
922 wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w;
923 return stc->SendMsg(msg, wParam, (long)lParam);
924}
925
926
927// These are utility functions not really tied to a platform
928
929int Platform::Minimum(int a, int b) {
930 if (a < b)
931 return a;
932 else
933 return b;
934}
935
936int Platform::Maximum(int a, int b) {
937 if (a > b)
938 return a;
939 else
940 return b;
941}
942
943#define TRACE
944
945void Platform::DebugPrintf(const char *format, ...) {
946#ifdef TRACE
947 char buffer[2000];
948 va_list pArguments;
949 va_start(pArguments, format);
950 vsprintf(buffer,format,pArguments);
951 va_end(pArguments);
952 Platform::DebugDisplay(buffer);
953#endif
954}
955
956
957static bool assertionPopUps = true;
958
959bool Platform::ShowAssertionPopUps(bool assertionPopUps_) {
960 bool ret = assertionPopUps;
961 assertionPopUps = assertionPopUps_;
962 return ret;
963}
964
965void Platform::Assert(const char *c, const char *file, int line) {
966 char buffer[2000];
967 sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line);
968 if (assertionPopUps) {
969 /*int idButton = */
970 wxMessageBox(stc2wx(buffer),
971 wxT("Assertion failure"),
972 wxICON_HAND | wxOK);
973// if (idButton == IDRETRY) {
974// ::DebugBreak();
975// } else if (idButton == IDIGNORE) {
976// // all OK
977// } else {
978// abort();
979// }
980 } else {
981 strcat(buffer, "\r\n");
982 Platform::DebugDisplay(buffer);
983 abort();
984 }
985}
986
987
988int Platform::Clamp(int val, int minVal, int maxVal) {
989 if (val > maxVal)
990 val = maxVal;
991 if (val < minVal)
992 val = minVal;
993 return val;
994}
995
996
997bool Platform::IsDBCSLeadByte(int codePage, char ch) {
998 return false;
999}
1000
1001
1002
1003//----------------------------------------------------------------------
1004
1005ElapsedTime::ElapsedTime() {
1006 wxStartTimer();
1007}
1008
1009double ElapsedTime::Duration(bool reset) {
1010 double result = wxGetElapsedTime(reset);
1011 result /= 1000.0;
1012 return result;
1013}
1014
1015
1016//----------------------------------------------------------------------
1017
1018
1019
1020