]>
Commit | Line | Data |
---|---|---|
9ce192d4 | 1 | // Scintilla source code edit control |
be5a51fb | 2 | // PlatWX.cxx - implementation of platform facilities on wxWidgets |
9ce192d4 RD |
3 | // Copyright 1998-1999 by Neil Hodgson <neilh@scintilla.org> |
4 | // Robin Dunn <robin@aldunn.com> | |
5 | // The License.txt file describes the conditions under which this software may be distributed. | |
6 | ||
f6bcfd97 | 7 | #include <ctype.h> |
9ce192d4 | 8 | |
1a2fb4cd | 9 | #include <wx/wx.h> |
10ef30eb | 10 | #include <wx/encconv.h> |
9e730a78 RD |
11 | #include <wx/listctrl.h> |
12 | #include <wx/mstream.h> | |
13 | #include <wx/image.h> | |
14 | #include <wx/imaglist.h> | |
1a2fb4cd | 15 | |
9ce192d4 | 16 | #include "Platform.h" |
1a2fb4cd | 17 | #include "PlatWX.h" |
9ce192d4 RD |
18 | #include "wx/stc/stc.h" |
19 | ||
f97d84a6 | 20 | |
9ce192d4 | 21 | Point Point::FromLong(long lpoint) { |
f6bcfd97 | 22 | return Point(lpoint & 0xFFFF, lpoint >> 16); |
9ce192d4 RD |
23 | } |
24 | ||
25 | wxRect wxRectFromPRectangle(PRectangle prc) { | |
d13ea3aa RD |
26 | wxRect r(prc.left, prc.top, |
27 | prc.Width(), prc.Height()); | |
28 | return r; | |
9ce192d4 RD |
29 | } |
30 | ||
31 | PRectangle PRectangleFromwxRect(wxRect rc) { | |
bec17edf | 32 | return PRectangle(rc.GetLeft(), rc.GetTop(), |
04ebdf40 | 33 | rc.GetRight()+1, rc.GetBottom()+1); |
9ce192d4 RD |
34 | } |
35 | ||
1a2fb4cd RD |
36 | wxColour wxColourFromCA(const ColourAllocated& ca) { |
37 | ColourDesired cd(ca.AsLong()); | |
c8b75e94 WS |
38 | return wxColour((unsigned char)cd.GetRed(), |
39 | (unsigned char)cd.GetGreen(), | |
40 | (unsigned char)cd.GetBlue()); | |
9ce192d4 RD |
41 | } |
42 | ||
1a2fb4cd | 43 | //---------------------------------------------------------------------- |
9ce192d4 RD |
44 | |
45 | Palette::Palette() { | |
46 | used = 0; | |
47 | allowRealization = false; | |
48 | } | |
49 | ||
50 | Palette::~Palette() { | |
51 | Release(); | |
52 | } | |
53 | ||
54 | void 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. | |
61 | void 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 | ||
84 | void Palette::Allocate(Window &) { | |
85 | if (allowRealization) { | |
86 | } | |
87 | } | |
88 | ||
89 | ||
1a2fb4cd RD |
90 | //---------------------------------------------------------------------- |
91 | ||
9ce192d4 RD |
92 | Font::Font() { |
93 | id = 0; | |
94 | ascent = 0; | |
95 | } | |
96 | ||
97 | Font::~Font() { | |
98 | } | |
99 | ||
d1558f3d | 100 | void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic, bool extraFontFlag) { |
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 | |
d1558f3d | 185 | wxFont* font = new wxFont(size, |
9ce192d4 RD |
186 | wxDEFAULT, |
187 | italic ? wxITALIC : wxNORMAL, | |
188 | bold ? wxBOLD : wxNORMAL, | |
189 | false, | |
0c5b83b0 | 190 | stc2wx(faceName), |
1a2fb4cd | 191 | encoding); |
d1558f3d RD |
192 | font->SetNoAntiAliasing(!extraFontFlag); |
193 | id = font; | |
9ce192d4 RD |
194 | } |
195 | ||
196 | ||
197 | void Font::Release() { | |
198 | if (id) | |
1a2fb4cd | 199 | delete (wxFont*)id; |
9ce192d4 RD |
200 | id = 0; |
201 | } | |
202 | ||
1a2fb4cd RD |
203 | //---------------------------------------------------------------------- |
204 | ||
205 | class SurfaceImpl : public Surface { | |
206 | private: | |
207 | wxDC* hdc; | |
208 | bool hdcOwned; | |
209 | wxBitmap* bitmap; | |
210 | int x; | |
211 | int y; | |
212 | bool unicodeMode; | |
9ce192d4 | 213 | |
1a2fb4cd RD |
214 | public: |
215 | SurfaceImpl(); | |
216 | ~SurfaceImpl(); | |
217 | ||
9e730a78 RD |
218 | virtual void Init(WindowID wid); |
219 | virtual void Init(SurfaceID sid, WindowID wid); | |
220 | virtual void InitPixMap(int width, int height, Surface *surface_, WindowID wid); | |
221 | ||
222 | virtual void Release(); | |
223 | virtual bool Initialised(); | |
224 | virtual void PenColour(ColourAllocated fore); | |
225 | virtual int LogPixelsY(); | |
226 | virtual int DeviceHeightFont(int points); | |
227 | virtual void MoveTo(int x_, int y_); | |
228 | virtual void LineTo(int x_, int y_); | |
229 | virtual void Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back); | |
230 | virtual void RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back); | |
231 | virtual void FillRectangle(PRectangle rc, ColourAllocated back); | |
232 | virtual void FillRectangle(PRectangle rc, Surface &surfacePattern); | |
233 | virtual void RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back); | |
234 | virtual void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back); | |
235 | virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource); | |
236 | ||
237 | virtual void DrawTextNoClip(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back); | |
238 | virtual void DrawTextClipped(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back); | |
239 | virtual void DrawTextTransparent(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore); | |
240 | virtual void MeasureWidths(Font &font_, const char *s, int len, int *positions); | |
241 | virtual int WidthText(Font &font_, const char *s, int len); | |
242 | virtual int WidthChar(Font &font_, char ch); | |
243 | virtual int Ascent(Font &font_); | |
244 | virtual int Descent(Font &font_); | |
245 | virtual int InternalLeading(Font &font_); | |
246 | virtual int ExternalLeading(Font &font_); | |
247 | virtual int Height(Font &font_); | |
248 | virtual int AverageCharWidth(Font &font_); | |
249 | ||
250 | virtual int SetPalette(Palette *pal, bool inBackGround); | |
251 | virtual void SetClip(PRectangle rc); | |
252 | virtual void FlushCachedState(); | |
253 | ||
254 | virtual void SetUnicodeMode(bool unicodeMode_); | |
255 | virtual void SetDBCSMode(int codePage); | |
1a2fb4cd RD |
256 | |
257 | void BrushColour(ColourAllocated back); | |
258 | void SetFont(Font &font_); | |
259 | }; | |
260 | ||
261 | ||
262 | ||
263 | SurfaceImpl::SurfaceImpl() : | |
9ce192d4 | 264 | hdc(0), hdcOwned(0), bitmap(0), |
1a2fb4cd RD |
265 | x(0), y(0), unicodeMode(0) |
266 | {} | |
9ce192d4 | 267 | |
1a2fb4cd | 268 | SurfaceImpl::~SurfaceImpl() { |
9ce192d4 RD |
269 | Release(); |
270 | } | |
271 | ||
9e730a78 | 272 | void SurfaceImpl::Init(WindowID wid) { |
81b32ce5 | 273 | #if 0 |
9ce192d4 RD |
274 | Release(); |
275 | hdc = new wxMemoryDC(); | |
276 | hdcOwned = true; | |
81b32ce5 | 277 | #else |
09bb2551 | 278 | // On Mac and GTK the DC is not really valid until it has a bitmap |
81b32ce5 RD |
279 | // selected into it. So instead of just creating the DC with no bitmap, |
280 | // go ahead and give it one. | |
9e730a78 | 281 | InitPixMap(1,1,NULL,wid); |
0f713d48 | 282 | #endif |
9ce192d4 RD |
283 | } |
284 | ||
9e730a78 | 285 | void SurfaceImpl::Init(SurfaceID hdc_, WindowID) { |
9ce192d4 | 286 | Release(); |
1a2fb4cd | 287 | hdc = (wxDC*)hdc_; |
9ce192d4 RD |
288 | } |
289 | ||
88a8b04e | 290 | void SurfaceImpl::InitPixMap(int width, int height, Surface *WXUNUSED(surface_), WindowID) { |
9ce192d4 | 291 | Release(); |
1a2fb4cd | 292 | hdc = new wxMemoryDC(); |
9ce192d4 | 293 | hdcOwned = true; |
2beb01db RD |
294 | if (width < 1) width = 1; |
295 | if (height < 1) height = 1; | |
21156596 | 296 | bitmap = new wxBitmap(width, height); |
9ce192d4 | 297 | ((wxMemoryDC*)hdc)->SelectObject(*bitmap); |
9ce192d4 RD |
298 | } |
299 | ||
9e730a78 RD |
300 | |
301 | void SurfaceImpl::Release() { | |
302 | if (bitmap) { | |
303 | ((wxMemoryDC*)hdc)->SelectObject(wxNullBitmap); | |
304 | delete bitmap; | |
305 | bitmap = 0; | |
306 | } | |
307 | if (hdcOwned) { | |
308 | delete hdc; | |
309 | hdc = 0; | |
310 | hdcOwned = false; | |
311 | } | |
312 | } | |
313 | ||
314 | ||
315 | bool SurfaceImpl::Initialised() { | |
316 | return hdc != 0; | |
317 | } | |
318 | ||
319 | ||
1a2fb4cd RD |
320 | void SurfaceImpl::PenColour(ColourAllocated fore) { |
321 | hdc->SetPen(wxPen(wxColourFromCA(fore), 1, wxSOLID)); | |
9ce192d4 RD |
322 | } |
323 | ||
1a2fb4cd RD |
324 | void SurfaceImpl::BrushColour(ColourAllocated back) { |
325 | hdc->SetBrush(wxBrush(wxColourFromCA(back), wxSOLID)); | |
9ce192d4 RD |
326 | } |
327 | ||
1a2fb4cd | 328 | void SurfaceImpl::SetFont(Font &font_) { |
21156596 | 329 | if (font_.GetID()) { |
1a2fb4cd | 330 | hdc->SetFont(*((wxFont*)font_.GetID())); |
f6bcfd97 | 331 | } |
9ce192d4 RD |
332 | } |
333 | ||
1a2fb4cd | 334 | int SurfaceImpl::LogPixelsY() { |
9ce192d4 RD |
335 | return hdc->GetPPI().y; |
336 | } | |
337 | ||
1a2fb4cd | 338 | int SurfaceImpl::DeviceHeightFont(int points) { |
9968ba85 | 339 | return points; |
f6bcfd97 BP |
340 | } |
341 | ||
1a2fb4cd | 342 | void SurfaceImpl::MoveTo(int x_, int y_) { |
9ce192d4 RD |
343 | x = x_; |
344 | y = y_; | |
345 | } | |
346 | ||
1a2fb4cd | 347 | void SurfaceImpl::LineTo(int x_, int y_) { |
9ce192d4 RD |
348 | hdc->DrawLine(x,y, x_,y_); |
349 | x = x_; | |
350 | y = y_; | |
351 | } | |
352 | ||
1a2fb4cd | 353 | void SurfaceImpl::Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back) { |
9ce192d4 | 354 | PenColour(fore); |
1a2fb4cd | 355 | BrushColour(back); |
9ce192d4 RD |
356 | hdc->DrawPolygon(npts, (wxPoint*)pts); |
357 | } | |
358 | ||
1a2fb4cd | 359 | void SurfaceImpl::RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back) { |
9ce192d4 | 360 | PenColour(fore); |
1a2fb4cd | 361 | BrushColour(back); |
9ce192d4 RD |
362 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); |
363 | } | |
364 | ||
1a2fb4cd RD |
365 | void SurfaceImpl::FillRectangle(PRectangle rc, ColourAllocated back) { |
366 | BrushColour(back); | |
9ce192d4 RD |
367 | hdc->SetPen(*wxTRANSPARENT_PEN); |
368 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); | |
369 | } | |
370 | ||
1a2fb4cd | 371 | void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) { |
9ce192d4 | 372 | wxBrush br; |
1a2fb4cd RD |
373 | if (((SurfaceImpl&)surfacePattern).bitmap) |
374 | br = wxBrush(*((SurfaceImpl&)surfacePattern).bitmap); | |
9ce192d4 RD |
375 | else // Something is wrong so display in red |
376 | br = wxBrush(*wxRED, wxSOLID); | |
377 | hdc->SetPen(*wxTRANSPARENT_PEN); | |
378 | hdc->SetBrush(br); | |
379 | hdc->DrawRectangle(wxRectFromPRectangle(rc)); | |
380 | } | |
381 | ||
1a2fb4cd | 382 | void SurfaceImpl::RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back) { |
9ce192d4 | 383 | PenColour(fore); |
1a2fb4cd | 384 | BrushColour(back); |
f6bcfd97 | 385 | hdc->DrawRoundedRectangle(wxRectFromPRectangle(rc), 4); |
9ce192d4 RD |
386 | } |
387 | ||
1a2fb4cd | 388 | void SurfaceImpl::Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back) { |
9ce192d4 | 389 | PenColour(fore); |
1a2fb4cd | 390 | BrushColour(back); |
9ce192d4 RD |
391 | hdc->DrawEllipse(wxRectFromPRectangle(rc)); |
392 | } | |
393 | ||
1a2fb4cd | 394 | void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) { |
f6bcfd97 BP |
395 | wxRect r = wxRectFromPRectangle(rc); |
396 | hdc->Blit(r.x, r.y, r.width, r.height, | |
1a2fb4cd RD |
397 | ((SurfaceImpl&)surfaceSource).hdc, |
398 | from.x, from.y, wxCOPY); | |
9ce192d4 RD |
399 | } |
400 | ||
1a2fb4cd RD |
401 | void SurfaceImpl::DrawTextNoClip(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)); | |
3d7a4fe8 | 407 | FillRectangle(rc, back); |
9ce192d4 RD |
408 | |
409 | // ybase is where the baseline should be, but wxWin uses the upper left | |
410 | // corner, so I need to calculate the real position for the text... | |
d13ea3aa | 411 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
9ce192d4 RD |
412 | } |
413 | ||
1a2fb4cd RD |
414 | void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, |
415 | const char *s, int len, | |
416 | ColourAllocated fore, ColourAllocated back) { | |
9ce192d4 | 417 | SetFont(font); |
1a2fb4cd RD |
418 | hdc->SetTextForeground(wxColourFromCA(fore)); |
419 | hdc->SetTextBackground(wxColourFromCA(back)); | |
3d7a4fe8 | 420 | FillRectangle(rc, back); |
9ce192d4 RD |
421 | hdc->SetClippingRegion(wxRectFromPRectangle(rc)); |
422 | ||
423 | // see comments above | |
d13ea3aa | 424 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
3d7a4fe8 | 425 | hdc->DestroyClippingRegion(); |
9ce192d4 RD |
426 | } |
427 | ||
9e730a78 RD |
428 | |
429 | void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, int ybase, | |
430 | const char *s, int len, | |
431 | ColourAllocated fore) { | |
432 | ||
9ce192d4 | 433 | SetFont(font); |
9e730a78 RD |
434 | hdc->SetTextForeground(wxColourFromCA(fore)); |
435 | hdc->SetBackgroundMode(wxTRANSPARENT); | |
1a2fb4cd | 436 | |
9e730a78 RD |
437 | // ybase is where the baseline should be, but wxWin uses the upper left |
438 | // corner, so I need to calculate the real position for the text... | |
d13ea3aa | 439 | hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); |
9e730a78 RD |
440 | |
441 | hdc->SetBackgroundMode(wxSOLID); | |
9ce192d4 RD |
442 | } |
443 | ||
1a2fb4cd | 444 | |
10ef30eb | 445 | void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) { |
9e730a78 | 446 | |
d1558f3d RD |
447 | wxString str = stc2wx(s, len); |
448 | wxArrayInt tpos; | |
10ef30eb | 449 | |
d1558f3d | 450 | SetFont(font); |
9e730a78 | 451 | |
d1558f3d | 452 | hdc->GetPartialTextExtents(str, tpos); |
10ef30eb RD |
453 | |
454 | #if wxUSE_UNICODE | |
455 | // Map the widths for UCS-2 characters back to the UTF-8 input string | |
9e730a78 RD |
456 | // NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2 |
457 | // so figure it out and fix it! | |
d1558f3d | 458 | size_t i = 0; |
10ef30eb | 459 | size_t ui = 0; |
d99859e4 | 460 | while ((int)i < len) { |
10ef30eb RD |
461 | unsigned char uch = (unsigned char)s[i]; |
462 | positions[i++] = tpos[ui]; | |
463 | if (uch >= 0x80) { | |
464 | if (uch < (0x80 + 0x40 + 0x20)) { | |
465 | positions[i++] = tpos[ui]; | |
466 | } else { | |
467 | positions[i++] = tpos[ui]; | |
468 | positions[i++] = tpos[ui]; | |
469 | } | |
470 | } | |
471 | ui++; | |
472 | } | |
473 | #else | |
474 | ||
475 | // If not unicode then just use the widths we have | |
d1558f3d | 476 | memcpy(positions, tpos.begin(), len * sizeof(int)); |
10ef30eb | 477 | #endif |
9ce192d4 RD |
478 | } |
479 | ||
10ef30eb | 480 | |
9e730a78 RD |
481 | int SurfaceImpl::WidthText(Font &font, const char *s, int len) { |
482 | SetFont(font); | |
483 | int w; | |
484 | int h; | |
485 | ||
486 | hdc->GetTextExtent(stc2wx(s, len), &w, &h); | |
487 | return w; | |
488 | } | |
489 | ||
490 | ||
1a2fb4cd | 491 | int SurfaceImpl::WidthChar(Font &font, char ch) { |
9ce192d4 RD |
492 | SetFont(font); |
493 | int w; | |
494 | int h; | |
10ef30eb RD |
495 | char s[2] = { ch, 0 }; |
496 | ||
0c5b83b0 | 497 | hdc->GetTextExtent(stc2wx(s, 1), &w, &h); |
9ce192d4 RD |
498 | return w; |
499 | } | |
500 | ||
1a2fb4cd | 501 | #define EXTENT_TEST wxT(" `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
9ce192d4 | 502 | |
1a2fb4cd | 503 | int SurfaceImpl::Ascent(Font &font) { |
9ce192d4 RD |
504 | SetFont(font); |
505 | int w, h, d, e; | |
506 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
507 | font.ascent = h - d; | |
508 | return font.ascent; | |
509 | } | |
510 | ||
1a2fb4cd | 511 | int SurfaceImpl::Descent(Font &font) { |
9ce192d4 RD |
512 | SetFont(font); |
513 | int w, h, d, e; | |
514 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
515 | return d; | |
516 | } | |
517 | ||
88a8b04e | 518 | int SurfaceImpl::InternalLeading(Font &WXUNUSED(font)) { |
9ce192d4 RD |
519 | return 0; |
520 | } | |
521 | ||
1a2fb4cd | 522 | int SurfaceImpl::ExternalLeading(Font &font) { |
9ce192d4 RD |
523 | SetFont(font); |
524 | int w, h, d, e; | |
525 | hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); | |
526 | return e; | |
527 | } | |
528 | ||
1a2fb4cd | 529 | int SurfaceImpl::Height(Font &font) { |
9ce192d4 | 530 | SetFont(font); |
d13ea3aa | 531 | return hdc->GetCharHeight() + 1; |
9ce192d4 RD |
532 | } |
533 | ||
1a2fb4cd | 534 | int SurfaceImpl::AverageCharWidth(Font &font) { |
9ce192d4 RD |
535 | SetFont(font); |
536 | return hdc->GetCharWidth(); | |
537 | } | |
538 | ||
88a8b04e | 539 | int SurfaceImpl::SetPalette(Palette *WXUNUSED(pal), bool WXUNUSED(inBackGround)) { |
65ec6247 | 540 | return 0; |
9ce192d4 RD |
541 | } |
542 | ||
1a2fb4cd | 543 | void SurfaceImpl::SetClip(PRectangle rc) { |
9ce192d4 RD |
544 | hdc->SetClippingRegion(wxRectFromPRectangle(rc)); |
545 | } | |
546 | ||
1a2fb4cd | 547 | void SurfaceImpl::FlushCachedState() { |
f6bcfd97 | 548 | } |
9ce192d4 | 549 | |
1a2fb4cd | 550 | void SurfaceImpl::SetUnicodeMode(bool unicodeMode_) { |
1a2fb4cd RD |
551 | unicodeMode=unicodeMode_; |
552 | } | |
553 | ||
88a8b04e | 554 | void SurfaceImpl::SetDBCSMode(int WXUNUSED(codePage)) { |
9e730a78 RD |
555 | // dbcsMode = codePage == SC_CP_DBCS; |
556 | } | |
557 | ||
558 | ||
1a2fb4cd RD |
559 | Surface *Surface::Allocate() { |
560 | return new SurfaceImpl; | |
561 | } | |
562 | ||
563 | ||
564 | //---------------------------------------------------------------------- | |
565 | ||
566 | ||
567 | inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; } | |
568 | ||
9ce192d4 RD |
569 | Window::~Window() { |
570 | } | |
571 | ||
572 | void Window::Destroy() { | |
9e730a78 | 573 | if (id) { |
7e126a07 | 574 | Show(false); |
1a2fb4cd | 575 | GETWIN(id)->Destroy(); |
9e730a78 | 576 | } |
9ce192d4 RD |
577 | id = 0; |
578 | } | |
579 | ||
580 | bool Window::HasFocus() { | |
1a2fb4cd | 581 | return wxWindow::FindFocus() == GETWIN(id); |
9ce192d4 RD |
582 | } |
583 | ||
584 | PRectangle Window::GetPosition() { | |
9e730a78 | 585 | if (! id) return PRectangle(); |
1a2fb4cd | 586 | wxRect rc(GETWIN(id)->GetPosition(), GETWIN(id)->GetSize()); |
9ce192d4 RD |
587 | return PRectangleFromwxRect(rc); |
588 | } | |
589 | ||
590 | void Window::SetPosition(PRectangle rc) { | |
f6bcfd97 | 591 | wxRect r = wxRectFromPRectangle(rc); |
1a2fb4cd | 592 | GETWIN(id)->SetSize(r); |
9ce192d4 RD |
593 | } |
594 | ||
595 | void Window::SetPositionRelative(PRectangle rc, Window) { | |
596 | SetPosition(rc); // ???? | |
597 | } | |
598 | ||
599 | PRectangle Window::GetClientPosition() { | |
9e730a78 | 600 | if (! id) return PRectangle(); |
1a2fb4cd | 601 | wxSize sz = GETWIN(id)->GetClientSize(); |
21156596 | 602 | return PRectangle(0, 0, sz.x, sz.y); |
9ce192d4 RD |
603 | } |
604 | ||
605 | void Window::Show(bool show) { | |
1a2fb4cd | 606 | GETWIN(id)->Show(show); |
9ce192d4 RD |
607 | } |
608 | ||
609 | void Window::InvalidateAll() { | |
1a2fb4cd | 610 | GETWIN(id)->Refresh(false); |
26f4607d | 611 | wxWakeUpIdle(); |
9ce192d4 RD |
612 | } |
613 | ||
614 | void Window::InvalidateRectangle(PRectangle rc) { | |
f6bcfd97 | 615 | wxRect r = wxRectFromPRectangle(rc); |
1a2fb4cd | 616 | GETWIN(id)->Refresh(false, &r); |
26f4607d | 617 | wxWakeUpIdle(); |
9ce192d4 RD |
618 | } |
619 | ||
620 | void Window::SetFont(Font &font) { | |
1a2fb4cd | 621 | GETWIN(id)->SetFont(*((wxFont*)font.GetID())); |
9ce192d4 RD |
622 | } |
623 | ||
624 | void Window::SetCursor(Cursor curs) { | |
625 | int cursorId; | |
626 | ||
627 | switch (curs) { | |
628 | case cursorText: | |
629 | cursorId = wxCURSOR_IBEAM; | |
630 | break; | |
631 | case cursorArrow: | |
632 | cursorId = wxCURSOR_ARROW; | |
633 | break; | |
634 | case cursorUp: | |
635 | cursorId = wxCURSOR_ARROW; // ** no up arrow... wxCURSOR_UPARROW; | |
636 | break; | |
637 | case cursorWait: | |
638 | cursorId = wxCURSOR_WAIT; | |
639 | break; | |
640 | case cursorHoriz: | |
641 | cursorId = wxCURSOR_SIZEWE; | |
642 | break; | |
643 | case cursorVert: | |
644 | cursorId = wxCURSOR_SIZENS; | |
645 | break; | |
646 | case cursorReverseArrow: | |
15dadf31 | 647 | cursorId = wxCURSOR_RIGHT_ARROW; |
9ce192d4 | 648 | break; |
9e730a78 RD |
649 | case cursorHand: |
650 | cursorId = wxCURSOR_HAND; | |
1e545382 | 651 | break; |
9ce192d4 RD |
652 | default: |
653 | cursorId = wxCURSOR_ARROW; | |
654 | break; | |
655 | } | |
9f79d14b CE |
656 | #ifdef __WXMOTIF__ |
657 | wxCursor wc = wxStockCursor(cursorId) ; | |
658 | #else | |
659 | wxCursor wc = wxCursor(cursorId) ; | |
660 | #endif | |
cb1871ca | 661 | GETWIN(id)->SetCursor(wc); |
9ce192d4 RD |
662 | } |
663 | ||
664 | ||
665 | void Window::SetTitle(const char *s) { | |
0c5b83b0 | 666 | GETWIN(id)->SetTitle(stc2wx(s)); |
9ce192d4 RD |
667 | } |
668 | ||
669 | ||
769a9cb2 RD |
670 | //---------------------------------------------------------------------- |
671 | // Helper classes for ListBox | |
672 | ||
267484bc | 673 | |
b0d0494f | 674 | // This is a simple subclass of wxListView that just resets focus to the |
9e730a78 RD |
675 | // parent when it gets it. |
676 | class wxSTCListBox : public wxListView { | |
451c5cc7 | 677 | public: |
9e730a78 RD |
678 | wxSTCListBox(wxWindow* parent, wxWindowID id, |
679 | const wxPoint& pos, const wxSize& size, | |
680 | long style) | |
681 | : wxListView(parent, id, pos, size, style) | |
682 | {} | |
451c5cc7 | 683 | |
7e126a07 | 684 | |
451c5cc7 RD |
685 | void OnFocus(wxFocusEvent& event) { |
686 | GetParent()->SetFocus(); | |
687 | event.Skip(); | |
688 | } | |
689 | ||
5f9eb69c | 690 | void OnKillFocus(wxFocusEvent& WXUNUSED(event)) { |
b0d0494f RD |
691 | // Do nothing. Prevents base class from resetting the colors... |
692 | } | |
7e126a07 | 693 | |
719ee9c3 RD |
694 | #ifdef __WXMAC__ |
695 | // For some reason I don't understand yet the focus doesn't really leave | |
696 | // the listbox like it should, so if we get any events feed them back to | |
697 | // the wxSTC | |
698 | void OnKeyDown(wxKeyEvent& event) { | |
699 | GetGrandParent()->GetEventHandler()->ProcessEvent(event); | |
700 | } | |
701 | void OnChar(wxKeyEvent& event) { | |
702 | GetGrandParent()->GetEventHandler()->ProcessEvent(event); | |
703 | } | |
b0d0494f | 704 | |
719ee9c3 RD |
705 | // And we need to force the focus back when being destroyed |
706 | ~wxSTCListBox() { | |
707 | GetGrandParent()->SetFocus(); | |
7e126a07 WS |
708 | } |
709 | #endif | |
710 | ||
451c5cc7 RD |
711 | private: |
712 | DECLARE_EVENT_TABLE() | |
713 | }; | |
714 | ||
9e730a78 RD |
715 | BEGIN_EVENT_TABLE(wxSTCListBox, wxListView) |
716 | EVT_SET_FOCUS( wxSTCListBox::OnFocus) | |
b0d0494f | 717 | EVT_KILL_FOCUS(wxSTCListBox::OnKillFocus) |
719ee9c3 RD |
718 | #ifdef __WXMAC__ |
719 | EVT_KEY_DOWN( wxSTCListBox::OnKeyDown) | |
720 | EVT_CHAR( wxSTCListBox::OnChar) | |
721 | #endif | |
451c5cc7 RD |
722 | END_EVENT_TABLE() |
723 | ||
724 | ||
725 | ||
267484bc | 726 | |
9e730a78 RD |
727 | // A window to place the wxSTCListBox upon |
728 | class wxSTCListBoxWin : public wxWindow { | |
729 | private: | |
730 | wxListView* lv; | |
731 | CallBackAction doubleClickAction; | |
732 | void* doubleClickActionData; | |
f97d84a6 | 733 | public: |
9e730a78 | 734 | wxSTCListBoxWin(wxWindow* parent, wxWindowID id) : |
d13ea3aa | 735 | wxWindow(parent, id, wxDefaultPosition, wxSize(0,0), wxSIMPLE_BORDER ) |
9e730a78 RD |
736 | { |
737 | ||
9e730a78 RD |
738 | lv = new wxSTCListBox(this, id, wxDefaultPosition, wxDefaultSize, |
739 | wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxNO_BORDER); | |
740 | lv->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
741 | lv->InsertColumn(0, wxEmptyString); | |
742 | lv->InsertColumn(1, wxEmptyString); | |
b0d0494f RD |
743 | |
744 | // Eventhough we immediately reset the focus to the parent, this helps | |
745 | // things to look right... | |
746 | lv->SetFocus(); | |
747 | ||
6612393c RD |
748 | Hide(); |
749 | } | |
750 | ||
7e126a07 | 751 | |
a4f3565e RD |
752 | // On OSX and (possibly others) there can still be pending |
753 | // messages/events for the list control when Scintilla wants to | |
754 | // close it, so do a pending delete of it instead of destroying | |
755 | // immediately. | |
756 | bool Destroy() { | |
d13ea3aa | 757 | #ifdef __WXMAC__ |
719ee9c3 | 758 | // The bottom edge of this window is not getting properly |
d13ea3aa RD |
759 | // refreshed upon deletion, so help it out... |
760 | wxWindow* p = GetParent(); | |
761 | wxRect r(GetPosition(), GetSize()); | |
762 | r.SetHeight(r.GetHeight()+1); | |
763 | p->Refresh(false, &r); | |
764 | #endif | |
a4f3565e RD |
765 | if ( !wxPendingDelete.Member(this) ) |
766 | wxPendingDelete.Append(this); | |
7e126a07 | 767 | return true; |
f97d84a6 RD |
768 | } |
769 | ||
7e126a07 | 770 | |
9e730a78 RD |
771 | int IconWidth() { |
772 | wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL); | |
773 | if (il != NULL) { | |
774 | int w, h; | |
775 | il->GetSize(0, w, h); | |
776 | return w; | |
777 | } | |
778 | return 0; | |
779 | } | |
f97d84a6 | 780 | |
769a9cb2 | 781 | |
9e730a78 RD |
782 | void SetDoubleClickAction(CallBackAction action, void *data) { |
783 | doubleClickAction = action; | |
784 | doubleClickActionData = data; | |
785 | } | |
451c5cc7 | 786 | |
769a9cb2 | 787 | |
9e730a78 RD |
788 | void OnFocus(wxFocusEvent& event) { |
789 | GetParent()->SetFocus(); | |
790 | event.Skip(); | |
791 | } | |
769a9cb2 RD |
792 | |
793 | void OnSize(wxSizeEvent& event) { | |
d13ea3aa | 794 | // resize the child |
9e730a78 | 795 | wxSize sz = GetClientSize(); |
d13ea3aa | 796 | lv->SetSize(sz); |
9e730a78 RD |
797 | // reset the column widths |
798 | lv->SetColumnWidth(0, IconWidth()+4); | |
799 | lv->SetColumnWidth(1, sz.x - 2 - lv->GetColumnWidth(0) - | |
800 | wxSystemSettings::GetMetric(wxSYS_VSCROLL_X)); | |
801 | event.Skip(); | |
769a9cb2 | 802 | } |
769a9cb2 | 803 | |
719493e1 RD |
804 | #ifdef __WXMAC__ |
805 | virtual bool Show(bool show = true) { | |
806 | bool rv = wxWindow::Show(show); | |
807 | GetParent()->Refresh(false); | |
808 | return rv; | |
809 | } | |
810 | #endif | |
811 | ||
5f9eb69c | 812 | void OnActivate(wxListEvent& WXUNUSED(event)) { |
9e730a78 | 813 | doubleClickAction(doubleClickActionData); |
769a9cb2 | 814 | } |
9e730a78 RD |
815 | |
816 | wxListView* GetLB() { return lv; } | |
769a9cb2 RD |
817 | |
818 | private: | |
769a9cb2 RD |
819 | DECLARE_EVENT_TABLE() |
820 | }; | |
821 | ||
9e730a78 RD |
822 | |
823 | BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxWindow) | |
7e126a07 WS |
824 | EVT_SET_FOCUS ( wxSTCListBoxWin::OnFocus) |
825 | EVT_SIZE ( wxSTCListBoxWin::OnSize) | |
826 | EVT_LIST_ITEM_ACTIVATED(wxID_ANY, wxSTCListBoxWin::OnActivate) | |
769a9cb2 | 827 | END_EVENT_TABLE() |
769a9cb2 | 828 | |
9e730a78 RD |
829 | |
830 | ||
831 | inline wxSTCListBoxWin* GETLBW(WindowID win) { | |
832 | return ((wxSTCListBoxWin*)win); | |
833 | } | |
834 | ||
835 | inline wxListView* GETLB(WindowID win) { | |
836 | return GETLBW(win)->GetLB(); | |
1a2fb4cd | 837 | } |
769a9cb2 RD |
838 | |
839 | //---------------------------------------------------------------------- | |
840 | ||
9e730a78 RD |
841 | class ListBoxImpl : public ListBox { |
842 | private: | |
843 | int lineHeight; | |
844 | bool unicodeMode; | |
845 | int desiredVisibleRows; | |
846 | int aveCharWidth; | |
847 | int maxStrWidth; | |
848 | wxImageList* imgList; | |
849 | wxArrayInt* imgTypeMap; | |
850 | ||
851 | public: | |
852 | ListBoxImpl(); | |
853 | ~ListBoxImpl(); | |
854 | ||
855 | virtual void SetFont(Font &font); | |
856 | virtual void Create(Window &parent, int ctrlID, int lineHeight_, bool unicodeMode_); | |
857 | virtual void SetAverageCharWidth(int width); | |
858 | virtual void SetVisibleRows(int rows); | |
859 | virtual PRectangle GetDesiredRect(); | |
860 | virtual int CaretFromEdge(); | |
861 | virtual void Clear(); | |
862 | virtual void Append(char *s, int type = -1); | |
863 | virtual int Length(); | |
864 | virtual void Select(int n); | |
865 | virtual int GetSelection(); | |
866 | virtual int Find(const char *prefix); | |
867 | virtual void GetValue(int n, char *value, int len); | |
9e730a78 RD |
868 | virtual void RegisterImage(int type, const char *xpm_data); |
869 | virtual void ClearRegisteredImages(); | |
870 | virtual void SetDoubleClickAction(CallBackAction, void *); | |
871 | ||
872 | }; | |
873 | ||
874 | ||
875 | ListBoxImpl::ListBoxImpl() | |
876 | : lineHeight(10), unicodeMode(false), | |
877 | desiredVisibleRows(5), aveCharWidth(8), maxStrWidth(0), | |
878 | imgList(NULL), imgTypeMap(NULL) | |
879 | { | |
9ce192d4 RD |
880 | } |
881 | ||
9e730a78 RD |
882 | ListBoxImpl::~ListBoxImpl() { |
883 | if (imgList) { | |
884 | delete imgList; | |
885 | imgList = NULL; | |
886 | } | |
887 | if (imgTypeMap) { | |
888 | delete imgTypeMap; | |
889 | imgTypeMap = NULL; | |
890 | } | |
9ce192d4 RD |
891 | } |
892 | ||
9e730a78 RD |
893 | |
894 | void ListBoxImpl::SetFont(Font &font) { | |
895 | GETLB(id)->SetFont(*((wxFont*)font.GetID())); | |
896 | } | |
897 | ||
898 | ||
899 | void ListBoxImpl::Create(Window &parent, int ctrlID, int lineHeight_, bool unicodeMode_) { | |
900 | lineHeight = lineHeight_; | |
901 | unicodeMode = unicodeMode_; | |
902 | maxStrWidth = 0; | |
1a2fb4cd | 903 | id = new wxSTCListBoxWin(GETWIN(parent.GetID()), ctrlID); |
9e730a78 RD |
904 | if (imgList != NULL) |
905 | GETLB(id)->SetImageList(imgList, wxIMAGE_LIST_SMALL); | |
9ce192d4 RD |
906 | } |
907 | ||
9e730a78 RD |
908 | |
909 | void ListBoxImpl::SetAverageCharWidth(int width) { | |
910 | aveCharWidth = width; | |
911 | } | |
912 | ||
913 | ||
914 | void ListBoxImpl::SetVisibleRows(int rows) { | |
769a9cb2 | 915 | desiredVisibleRows = rows; |
f3c2c221 RD |
916 | } |
917 | ||
9e730a78 RD |
918 | |
919 | PRectangle ListBoxImpl::GetDesiredRect() { | |
920 | // wxListCtrl doesn't have a DoGetBestSize, so instead we kept track of | |
921 | // the max size in Append and calculate it here... | |
922 | int maxw = maxStrWidth; | |
1e545382 | 923 | int maxh ; |
9e730a78 RD |
924 | |
925 | // give it a default if there are no lines, and/or add a bit more | |
926 | if (maxw == 0) maxw = 100; | |
927 | maxw += aveCharWidth * 3 + | |
928 | GETLBW(id)->IconWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); | |
929 | if (maxw > 350) | |
930 | maxw = 350; | |
931 | ||
932 | // estimate a desired height | |
933 | int count = GETLB(id)->GetItemCount(); | |
934 | if (count) { | |
935 | wxRect rect; | |
936 | GETLB(id)->GetItemRect(0, rect); | |
937 | maxh = count * rect.GetHeight(); | |
938 | if (maxh > 140) // TODO: Use desiredVisibleRows?? | |
939 | maxh = 140; | |
940 | ||
941 | // Try to make the size an exact multiple of some number of lines | |
942 | int lines = maxh / rect.GetHeight(); | |
943 | maxh = (lines + 1) * rect.GetHeight() + 2; | |
944 | } | |
945 | else | |
946 | maxh = 100; | |
947 | ||
d134f170 RD |
948 | PRectangle rc; |
949 | rc.top = 0; | |
950 | rc.left = 0; | |
9e730a78 RD |
951 | rc.right = maxw; |
952 | rc.bottom = maxh; | |
d134f170 RD |
953 | return rc; |
954 | } | |
955 | ||
d134f170 | 956 | |
9e730a78 RD |
957 | int ListBoxImpl::CaretFromEdge() { |
958 | return 4 + GETLBW(id)->IconWidth(); | |
d134f170 RD |
959 | } |
960 | ||
9e730a78 RD |
961 | |
962 | void ListBoxImpl::Clear() { | |
963 | GETLB(id)->DeleteAllItems(); | |
9ce192d4 RD |
964 | } |
965 | ||
9e730a78 RD |
966 | |
967 | void ListBoxImpl::Append(char *s, int type) { | |
968 | wxString text = stc2wx(s); | |
969 | long count = GETLB(id)->GetItemCount(); | |
970 | long itemID = GETLB(id)->InsertItem(count, wxEmptyString); | |
971 | GETLB(id)->SetItem(itemID, 1, text); | |
972 | int itemWidth = 0; | |
973 | GETLB(id)->GetTextExtent(text, &itemWidth, NULL); | |
974 | maxStrWidth = wxMax(maxStrWidth, itemWidth); | |
975 | if (type != -1) { | |
976 | wxCHECK_RET(imgTypeMap, wxT("Unexpected NULL imgTypeMap")); | |
977 | long idx = imgTypeMap->Item(type); | |
978 | GETLB(id)->SetItemImage(itemID, idx, idx); | |
979 | } | |
9ce192d4 RD |
980 | } |
981 | ||
9e730a78 RD |
982 | |
983 | int ListBoxImpl::Length() { | |
984 | return GETLB(id)->GetItemCount(); | |
9ce192d4 RD |
985 | } |
986 | ||
9e730a78 RD |
987 | |
988 | void ListBoxImpl::Select(int n) { | |
7e126a07 | 989 | bool select = true; |
895066d8 RD |
990 | if (n == -1) { |
991 | n = 0; | |
7e126a07 | 992 | select = false; |
895066d8 | 993 | } |
9e730a78 RD |
994 | GETLB(id)->Focus(n); |
995 | GETLB(id)->Select(n, select); | |
9ce192d4 RD |
996 | } |
997 | ||
9e730a78 RD |
998 | |
999 | int ListBoxImpl::GetSelection() { | |
1000 | return GETLB(id)->GetFirstSelected(); | |
9ce192d4 RD |
1001 | } |
1002 | ||
9e730a78 | 1003 | |
88a8b04e | 1004 | int ListBoxImpl::Find(const char *WXUNUSED(prefix)) { |
b8b0e402 | 1005 | // No longer used |
7e126a07 | 1006 | return wxNOT_FOUND; |
9ce192d4 RD |
1007 | } |
1008 | ||
9e730a78 RD |
1009 | |
1010 | void ListBoxImpl::GetValue(int n, char *value, int len) { | |
1011 | wxListItem item; | |
1012 | item.SetId(n); | |
1013 | item.SetColumn(1); | |
1014 | item.SetMask(wxLIST_MASK_TEXT); | |
1015 | GETLB(id)->GetItem(item); | |
1016 | strncpy(value, wx2stc(item.GetText()), len); | |
9ce192d4 RD |
1017 | value[len-1] = '\0'; |
1018 | } | |
1019 | ||
9e730a78 RD |
1020 | |
1021 | void ListBoxImpl::RegisterImage(int type, const char *xpm_data) { | |
1022 | wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1); | |
c8b75e94 WS |
1023 | wxImage img(stream, wxBITMAP_TYPE_XPM); |
1024 | wxBitmap bmp(img); | |
9e730a78 RD |
1025 | |
1026 | if (! imgList) { | |
1027 | // assumes all images are the same size | |
7e126a07 | 1028 | imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight(), true); |
9e730a78 RD |
1029 | imgTypeMap = new wxArrayInt; |
1030 | } | |
1031 | ||
1032 | int idx = imgList->Add(bmp); | |
1033 | ||
1034 | // do we need to extend the mapping array? | |
1035 | wxArrayInt& itm = *imgTypeMap; | |
9a8ffadd | 1036 | if ( itm.GetCount() < (size_t)type+1) |
9e730a78 RD |
1037 | itm.Add(-1, type - itm.GetCount() + 1); |
1038 | ||
1039 | // Add an item that maps type to the image index | |
1040 | itm[type] = idx; | |
1041 | } | |
1042 | ||
1043 | void ListBoxImpl::ClearRegisteredImages() { | |
1044 | if (imgList) { | |
1045 | delete imgList; | |
1046 | imgList = NULL; | |
1047 | } | |
1048 | if (imgTypeMap) { | |
1049 | delete imgTypeMap; | |
1050 | imgTypeMap = NULL; | |
1051 | } | |
1052 | if (id) | |
1053 | GETLB(id)->SetImageList(NULL, wxIMAGE_LIST_SMALL); | |
1054 | } | |
1055 | ||
1056 | ||
1057 | void ListBoxImpl::SetDoubleClickAction(CallBackAction action, void *data) { | |
1058 | GETLBW(id)->SetDoubleClickAction(action, data); | |
1059 | } | |
1060 | ||
1061 | ||
1062 | ||
1063 | ListBox::ListBox() { | |
1064 | } | |
1065 | ||
1066 | ListBox::~ListBox() { | |
1067 | } | |
1068 | ||
1069 | ListBox *ListBox::Allocate() { | |
1070 | return new ListBoxImpl(); | |
9ce192d4 RD |
1071 | } |
1072 | ||
1a2fb4cd | 1073 | //---------------------------------------------------------------------- |
9ce192d4 RD |
1074 | |
1075 | Menu::Menu() : id(0) { | |
1076 | } | |
1077 | ||
1078 | void Menu::CreatePopUp() { | |
1079 | Destroy(); | |
1080 | id = new wxMenu(); | |
1081 | } | |
1082 | ||
1083 | void Menu::Destroy() { | |
1084 | if (id) | |
1a2fb4cd | 1085 | delete (wxMenu*)id; |
9ce192d4 RD |
1086 | id = 0; |
1087 | } | |
1088 | ||
1089 | void Menu::Show(Point pt, Window &w) { | |
1a2fb4cd | 1090 | GETWIN(w.GetID())->PopupMenu((wxMenu*)id, pt.x - 4, pt.y); |
9ce192d4 RD |
1091 | Destroy(); |
1092 | } | |
1093 | ||
1a2fb4cd | 1094 | //---------------------------------------------------------------------- |
9ce192d4 | 1095 | |
88a8b04e | 1096 | DynamicLibrary *DynamicLibrary::Load(const char *WXUNUSED(modulePath)) { |
e14d10b0 RD |
1097 | wxFAIL_MSG(wxT("Dynamic lexer loading not implemented yet")); |
1098 | return NULL; | |
1099 | } | |
1100 | ||
1101 | //---------------------------------------------------------------------- | |
1102 | ||
1a2fb4cd | 1103 | ColourDesired Platform::Chrome() { |
9ce192d4 | 1104 | wxColour c; |
e1c6c6ae | 1105 | c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
1a2fb4cd | 1106 | return ColourDesired(c.Red(), c.Green(), c.Blue()); |
9ce192d4 RD |
1107 | } |
1108 | ||
1a2fb4cd | 1109 | ColourDesired Platform::ChromeHighlight() { |
9ce192d4 | 1110 | wxColour c; |
e1c6c6ae | 1111 | c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT); |
1a2fb4cd | 1112 | return ColourDesired(c.Red(), c.Green(), c.Blue()); |
9ce192d4 RD |
1113 | } |
1114 | ||
1115 | const char *Platform::DefaultFont() { | |
10ef30eb RD |
1116 | static char buf[128]; |
1117 | strcpy(buf, wxNORMAL_FONT->GetFaceName().mbc_str()); | |
1118 | return buf; | |
9ce192d4 RD |
1119 | } |
1120 | ||
1121 | int Platform::DefaultFontSize() { | |
9e730a78 | 1122 | return wxNORMAL_FONT->GetPointSize(); |
9ce192d4 RD |
1123 | } |
1124 | ||
1125 | unsigned int Platform::DoubleClickTime() { | |
1126 | return 500; // **** ::GetDoubleClickTime(); | |
1127 | } | |
1128 | ||
9e730a78 | 1129 | bool Platform::MouseButtonBounce() { |
7e126a07 | 1130 | return false; |
9e730a78 | 1131 | } |
9ce192d4 | 1132 | void Platform::DebugDisplay(const char *s) { |
0c5b83b0 | 1133 | wxLogDebug(stc2wx(s)); |
9ce192d4 RD |
1134 | } |
1135 | ||
88a8b04e | 1136 | bool Platform::IsKeyDown(int WXUNUSED(key)) { |
9ce192d4 RD |
1137 | return false; // I don't think we'll need this. |
1138 | } | |
1139 | ||
1140 | long Platform::SendScintilla(WindowID w, | |
1141 | unsigned int msg, | |
1142 | unsigned long wParam, | |
1143 | long lParam) { | |
1144 | ||
1145 | wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w; | |
1146 | return stc->SendMsg(msg, wParam, lParam); | |
1147 | } | |
1148 | ||
a834585d RD |
1149 | long Platform::SendScintillaPointer(WindowID w, |
1150 | unsigned int msg, | |
1151 | unsigned long wParam, | |
1152 | void *lParam) { | |
1153 | ||
1154 | wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w; | |
1155 | return stc->SendMsg(msg, wParam, (long)lParam); | |
1156 | } | |
1157 | ||
9ce192d4 RD |
1158 | |
1159 | // These are utility functions not really tied to a platform | |
1160 | ||
1161 | int Platform::Minimum(int a, int b) { | |
1162 | if (a < b) | |
1163 | return a; | |
1164 | else | |
1165 | return b; | |
1166 | } | |
1167 | ||
1168 | int Platform::Maximum(int a, int b) { | |
1169 | if (a > b) | |
1170 | return a; | |
1171 | else | |
1172 | return b; | |
1173 | } | |
1174 | ||
1175 | #define TRACE | |
1176 | ||
1177 | void Platform::DebugPrintf(const char *format, ...) { | |
1178 | #ifdef TRACE | |
1179 | char buffer[2000]; | |
1180 | va_list pArguments; | |
1181 | va_start(pArguments, format); | |
1182 | vsprintf(buffer,format,pArguments); | |
1183 | va_end(pArguments); | |
1184 | Platform::DebugDisplay(buffer); | |
1185 | #endif | |
1186 | } | |
1187 | ||
65ec6247 RD |
1188 | |
1189 | static bool assertionPopUps = true; | |
1190 | ||
1191 | bool Platform::ShowAssertionPopUps(bool assertionPopUps_) { | |
7e126a07 WS |
1192 | bool ret = assertionPopUps; |
1193 | assertionPopUps = assertionPopUps_; | |
1194 | return ret; | |
65ec6247 RD |
1195 | } |
1196 | ||
1197 | void Platform::Assert(const char *c, const char *file, int line) { | |
7e126a07 WS |
1198 | char buffer[2000]; |
1199 | sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line); | |
1200 | if (assertionPopUps) { | |
1201 | /*int idButton = */ | |
1202 | wxMessageBox(stc2wx(buffer), | |
1203 | wxT("Assertion failure"), | |
1204 | wxICON_HAND | wxOK); | |
1205 | // if (idButton == IDRETRY) { | |
1206 | // ::DebugBreak(); | |
1207 | // } else if (idButton == IDIGNORE) { | |
1208 | // // all OK | |
1209 | // } else { | |
1210 | // abort(); | |
1211 | // } | |
1212 | } else { | |
1213 | strcat(buffer, "\r\n"); | |
1214 | Platform::DebugDisplay(buffer); | |
1215 | abort(); | |
1216 | } | |
65ec6247 RD |
1217 | } |
1218 | ||
1219 | ||
9ce192d4 RD |
1220 | int Platform::Clamp(int val, int minVal, int maxVal) { |
1221 | if (val > maxVal) | |
1222 | val = maxVal; | |
1223 | if (val < minVal) | |
1224 | val = minVal; | |
1225 | return val; | |
1226 | } | |
1227 | ||
1228 | ||
88a8b04e | 1229 | bool Platform::IsDBCSLeadByte(int WXUNUSED(codePage), char WXUNUSED(ch)) { |
1a2fb4cd RD |
1230 | return false; |
1231 | } | |
1232 | ||
88a8b04e | 1233 | int Platform::DBCSCharLength(int WXUNUSED(codePage), const char *WXUNUSED(s)) { |
215ef7ae | 1234 | return 1; |
9e730a78 RD |
1235 | } |
1236 | ||
1237 | int Platform::DBCSCharMaxLength() { | |
215ef7ae | 1238 | return 1; |
9e730a78 | 1239 | } |
1a2fb4cd RD |
1240 | |
1241 | ||
1242 | //---------------------------------------------------------------------- | |
1243 | ||
1244 | ElapsedTime::ElapsedTime() { | |
1245 | wxStartTimer(); | |
1246 | } | |
1247 | ||
1248 | double ElapsedTime::Duration(bool reset) { | |
1249 | double result = wxGetElapsedTime(reset); | |
1250 | result /= 1000.0; | |
1251 | return result; | |
1252 | } | |
1253 | ||
1254 | ||
1255 | //---------------------------------------------------------------------- | |
9ce192d4 | 1256 | |
d99859e4 | 1257 | #if wxUSE_UNICODE |
6636ac1e RD |
1258 | |
1259 | #include "UniConversion.h" | |
1260 | ||
1261 | // Convert using Scintilla's functions instead of wx's, Scintilla's are more | |
1262 | // forgiving and won't assert... | |
c8b75e94 | 1263 | |
d99859e4 RD |
1264 | wxString stc2wx(const char* str, size_t len) |
1265 | { | |
81bfa5ae RD |
1266 | if (!len) |
1267 | return wxEmptyString; | |
8a07b43c | 1268 | |
6636ac1e RD |
1269 | size_t wclen = UCS2Length(str, len); |
1270 | wxWCharBuffer buffer(wclen+1); | |
1271 | ||
1272 | size_t actualLen = UCS2FromUTF8(str, len, buffer.data(), wclen+1); | |
1273 | return wxString(buffer.data(), actualLen); | |
1274 | } | |
1275 | ||
d99859e4 | 1276 | |
d99859e4 | 1277 | |
6636ac1e RD |
1278 | wxString stc2wx(const char* str) |
1279 | { | |
1280 | return stc2wx(str, strlen(str)); | |
d99859e4 | 1281 | } |
6636ac1e RD |
1282 | |
1283 | ||
1284 | const wxWX2MBbuf wx2stc(const wxString& str) | |
1285 | { | |
1286 | const wchar_t* wcstr = str.c_str(); | |
1287 | size_t wclen = str.length(); | |
1288 | size_t len = UTF8Length(wcstr, wclen); | |
1289 | ||
1290 | wxCharBuffer buffer(len+1); | |
1291 | UTF8FromUCS2(wcstr, wclen, buffer.data(), len); | |
1292 | ||
1293 | // TODO check NULL termination!! | |
1294 | ||
6636ac1e RD |
1295 | return buffer; |
1296 | } | |
1297 | ||
d99859e4 RD |
1298 | #endif |
1299 | ||
1300 | ||
1301 | ||
9ce192d4 RD |
1302 | |
1303 | ||
1304 |