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