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