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