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