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