]> git.saurik.com Git - wxWidgets.git/blame - src/stc/PlatWX.cpp
1. status bar can now be positioned on top (and anywhere, in fact)
[wxWidgets.git] / src / stc / PlatWX.cpp
CommitLineData
9ce192d4
RD
1// Scintilla source code edit control
2// PlatWX.cxx - implementation of platform facilities on wxWindows
3// Copyright 1998-1999 by Neil Hodgson <neilh@scintilla.org>
4// Robin Dunn <robin@aldunn.com>
5// The License.txt file describes the conditions under which this software may be distributed.
6
7
8#include "Platform.h"
9#include "wx/stc/stc.h"
10
11Point Point::FromLong(long lpoint) {
12 return Point(lpoint & 0xFFFF, lpoint >> 32);
13}
14
15wxRect wxRectFromPRectangle(PRectangle prc) {
16 wxRect rc(prc.left, prc.top,
17 prc.right-prc.left+1, prc.bottom-prc.top+1);
18 return rc;
19}
20
21PRectangle PRectangleFromwxRect(wxRect rc) {
22 return PRectangle(rc.GetLeft(), rc.GetTop(), rc.GetRight(), rc.GetBottom());
23}
24
25Colour::Colour(long lcol) {
26 co.Set(lcol & 0xff, (lcol >> 8) & 0xff, (lcol >> 16) & 0xff);
27}
28
29Colour::Colour(unsigned int red, unsigned int green, unsigned int blue) {
30 co.Set(red, green, blue);
31}
32
33bool Colour::operator==(const Colour &other) const {
34 return co == other.co;
35}
36
37long Colour::AsLong() const {
38 return (((long)co.Blue() << 16) |
39 ((long)co.Green() << 8) |
40 ((long)co.Red()));
41}
42
43unsigned int Colour::GetRed() {
44 return co.Red();
45}
46
47unsigned int Colour::GetGreen() {
48 return co.Green();
49}
50
51unsigned int Colour::GetBlue() {
52 return co.Blue();
53}
54
55Palette::Palette() {
56 used = 0;
57 allowRealization = false;
58}
59
60Palette::~Palette() {
61 Release();
62}
63
64void Palette::Release() {
65 used = 0;
66}
67
68// This method either adds a colour to the list of wanted colours (want==true)
69// or retrieves the allocated colour back to the ColourPair.
70// This is one method to make it easier to keep the code for wanting and retrieving in sync.
71void Palette::WantFind(ColourPair &cp, bool want) {
72 if (want) {
73 for (int i=0; i < used; i++) {
74 if (entries[i].desired == cp.desired)
75 return;
76 }
77
78 if (used < numEntries) {
79 entries[used].desired = cp.desired;
80 entries[used].allocated = cp.desired;
81 used++;
82 }
83 } else {
84 for (int i=0; i < used; i++) {
85 if (entries[i].desired == cp.desired) {
86 cp.allocated = entries[i].allocated;
87 return;
88 }
89 }
90 cp.allocated = cp.desired;
91 }
92}
93
94void Palette::Allocate(Window &) {
95 if (allowRealization) {
96 }
97}
98
99
100Font::Font() {
101 id = 0;
102 ascent = 0;
103}
104
105Font::~Font() {
106}
107
108void Font::Create(const char *faceName, int size, bool bold, bool italic) {
109 Release();
110 id = new wxFont(size,
111 wxDEFAULT,
112 italic ? wxITALIC : wxNORMAL,
113 bold ? wxBOLD : wxNORMAL,
114 false,
115 faceName);
116}
117
118
119void Font::Release() {
120 if (id)
121 delete id;
122 id = 0;
123}
124
125
126Surface::Surface() :
127 hdc(0), hdcOwned(0), bitmap(0),
128 x(0), y(0) {
129}
130
131Surface::~Surface() {
132 Release();
133}
134
135void Surface::Release() {
136 if (bitmap) {
137 ((wxMemoryDC*)hdc)->SelectObject(wxNullBitmap);
138 delete bitmap;
139 bitmap = 0;
140 }
141 if (hdcOwned) {
142 delete hdc;
143 hdc = 0;
144 hdcOwned = false;
145 }
146}
147
148
149bool Surface::Initialised() {
150 return hdc != 0;
151}
152
153void Surface::Init() {
154 Release();
155 hdc = new wxMemoryDC();
156 hdcOwned = true;
157 // **** ::SetTextAlign(hdc, TA_BASELINE);
158}
159
160void Surface::Init(SurfaceID hdc_) {
161 Release();
162 hdc = hdc_;
163 // **** ::SetTextAlign(hdc, TA_BASELINE);
164}
165
166void Surface::InitPixMap(int width, int height, Surface *surface_) {
167 Release();
168 hdc = new wxMemoryDC(surface_->hdc);
169 hdcOwned = true;
170 bitmap = new wxBitmap(width, height);
171 ((wxMemoryDC*)hdc)->SelectObject(*bitmap);
172 // **** ::SetTextAlign(hdc, TA_BASELINE);
173}
174
175void Surface::PenColour(Colour fore) {
176 hdc->SetPen(wxPen(fore.co, 1, wxSOLID));
177}
178
179void Surface::BrushColor(Colour back) {
180 hdc->SetBrush(wxBrush(back.co, wxSOLID));
181}
182
183void Surface::SetFont(Font &font_) {
184 hdc->SetFont(*font_.GetID());
185}
186
187int Surface::LogPixelsY() {
188 return hdc->GetPPI().y;
189}
190
191void Surface::MoveTo(int x_, int y_) {
192 x = x_;
193 y = y_;
194}
195
196void Surface::LineTo(int x_, int y_) {
197 hdc->DrawLine(x,y, x_,y_);
198 x = x_;
199 y = y_;
200}
201
202void Surface::Polygon(Point *pts, int npts, Colour fore,
203 Colour back) {
204 PenColour(fore);
205 BrushColor(back);
206 hdc->DrawPolygon(npts, (wxPoint*)pts);
207}
208
209void Surface::RectangleDraw(PRectangle rc, Colour fore, Colour back) {
210 PenColour(fore);
211 BrushColor(back);
212 hdc->DrawRectangle(wxRectFromPRectangle(rc));
213}
214
215void Surface::FillRectangle(PRectangle rc, Colour back) {
216 BrushColor(back);
217 hdc->SetPen(*wxTRANSPARENT_PEN);
218 hdc->DrawRectangle(wxRectFromPRectangle(rc));
219}
220
221void Surface::FillRectangle(PRectangle rc, Surface &surfacePattern) {
222 wxBrush br;
223 if (surfacePattern.bitmap)
224 br = wxBrush(*surfacePattern.bitmap);
225 else // Something is wrong so display in red
226 br = wxBrush(*wxRED, wxSOLID);
227 hdc->SetPen(*wxTRANSPARENT_PEN);
228 hdc->SetBrush(br);
229 hdc->DrawRectangle(wxRectFromPRectangle(rc));
230}
231
232void Surface::RoundedRectangle(PRectangle rc, Colour fore, Colour back) {
233 PenColour(fore);
234 BrushColor(back);
235 hdc->DrawRoundedRectangle(wxRectFromPRectangle(rc), 8);
236}
237
238void Surface::Ellipse(PRectangle rc, Colour fore, Colour back) {
239 PenColour(fore);
240 BrushColor(back);
241 hdc->DrawEllipse(wxRectFromPRectangle(rc));
242}
243
244void Surface::Copy(PRectangle rc, Point from, Surface &surfaceSource) {
245 hdc->Blit(rc.left, rc.top, rc.Width(), rc.Height(),
246 surfaceSource.hdc, from.x, from.y, wxCOPY);
247}
248
249void Surface::DrawText(PRectangle rc, Font &font, int ybase,
250 const char *s, int len, Colour fore, Colour back) {
251 SetFont(font);
252 hdc->SetTextForeground(fore.co);
253 hdc->SetTextBackground(back.co);
254 FillRectangle(rc, back);
255
256 // ybase is where the baseline should be, but wxWin uses the upper left
257 // corner, so I need to calculate the real position for the text...
258 hdc->DrawText(wxString(s, len), rc.left, ybase - font.ascent);
259}
260
261void Surface::DrawTextClipped(PRectangle rc, Font &font, int ybase, const char *s, int len, Colour fore, Colour back) {
262 SetFont(font);
263 hdc->SetTextForeground(fore.co);
264 hdc->SetTextBackground(back.co);
265 FillRectangle(rc, back);
266 hdc->SetClippingRegion(wxRectFromPRectangle(rc));
267
268 // see comments above
269 hdc->DrawText(wxString(s, len), rc.left, ybase - font.ascent);
270 hdc->DestroyClippingRegion();
271}
272
273int Surface::WidthText(Font &font, const char *s, int len) {
274 SetFont(font);
275 int w;
276 int h;
277 hdc->GetTextExtent(wxString(s, len), &w, &h);
278 return w;
279}
280
281void Surface::MeasureWidths(Font &font, const char *s, int len, int *positions) {
282 SetFont(font);
283 int totalWidth = 0;
284 for (int i=0; i<len; i++) {
285 int w;
286 int h;
287 hdc->GetTextExtent(s[i], &w, &h);
288 totalWidth += w;
289 positions[i] = totalWidth;
290 }
291}
292
293int Surface::WidthChar(Font &font, char ch) {
294 SetFont(font);
295 int w;
296 int h;
297 hdc->GetTextExtent(ch, &w, &h);
298 return w;
299}
300
301#define EXTENT_TEST " `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
302
303int Surface::Ascent(Font &font) {
304 SetFont(font);
305 int w, h, d, e;
306 hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
307 font.ascent = h - d;
308 return font.ascent;
309}
310
311int Surface::Descent(Font &font) {
312 SetFont(font);
313 int w, h, d, e;
314 hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
315 return d;
316}
317
318int Surface::InternalLeading(Font &font) {
319 return 0;
320}
321
322int Surface::ExternalLeading(Font &font) {
323 SetFont(font);
324 int w, h, d, e;
325 hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
326 return e;
327}
328
329int Surface::Height(Font &font) {
330 SetFont(font);
331 return hdc->GetCharHeight();
332}
333
334int Surface::AverageCharWidth(Font &font) {
335 SetFont(font);
336 return hdc->GetCharWidth();
337}
338
339int Surface::SetPalette(Palette *pal, bool inBackGround) {
340 return 0; // **** figure out what to do with palettes...
341}
342
343void Surface::SetClip(PRectangle rc) {
344 hdc->SetClippingRegion(wxRectFromPRectangle(rc));
345}
346
347
348
349Window::~Window() {
350}
351
352void Window::Destroy() {
353 if (id)
354 id->Destroy();
355 id = 0;
356}
357
358bool Window::HasFocus() {
359 return wxWindow::FindFocus() == id;
360}
361
362PRectangle Window::GetPosition() {
363 wxRect rc(id->GetPosition(), id->GetSize());
364 return PRectangleFromwxRect(rc);
365}
366
367void Window::SetPosition(PRectangle rc) {
368 id->SetSize(rc.left, rc.top, rc.Width(), rc.Height());
369}
370
371void Window::SetPositionRelative(PRectangle rc, Window) {
372 SetPosition(rc); // ????
373}
374
375PRectangle Window::GetClientPosition() {
376 wxSize sz = id->GetClientSize();
377 return PRectangle(0, 0, sz.x - 1, sz.y - 1);
378}
379
380void Window::Show(bool show) {
381 id->Show(show);
382}
383
384void Window::InvalidateAll() {
385 id->Refresh(false);
386}
387
388void Window::InvalidateRectangle(PRectangle rc) {
389 id->Refresh(false, &wxRectFromPRectangle(rc));
390}
391
392void Window::SetFont(Font &font) {
393 id->SetFont(*font.GetID());
394}
395
396void Window::SetCursor(Cursor curs) {
397 int cursorId;
398
399 switch (curs) {
400 case cursorText:
401 cursorId = wxCURSOR_IBEAM;
402 break;
403 case cursorArrow:
404 cursorId = wxCURSOR_ARROW;
405 break;
406 case cursorUp:
407 cursorId = wxCURSOR_ARROW; // ** no up arrow... wxCURSOR_UPARROW;
408 break;
409 case cursorWait:
410 cursorId = wxCURSOR_WAIT;
411 break;
412 case cursorHoriz:
413 cursorId = wxCURSOR_SIZEWE;
414 break;
415 case cursorVert:
416 cursorId = wxCURSOR_SIZENS;
417 break;
418 case cursorReverseArrow:
419 cursorId = wxCURSOR_POINT_RIGHT;
420 break;
421 default:
422 cursorId = wxCURSOR_ARROW;
423 break;
424 }
425
426 id->SetCursor(wxCursor(cursorId));
427}
428
429
430void Window::SetTitle(const char *s) {
431 id->SetTitle(s);
432}
433
434
435
436ListBox::ListBox() {
437}
438
439ListBox::~ListBox() {
440}
441
442void ListBox::Create(Window &parent, int ctrlID) {
443 id = new wxListBox(parent.id, ctrlID, wxDefaultPosition, wxDefaultSize,
444 0, NULL, wxLB_SINGLE | wxLB_SORT);
445}
446
447void ListBox::Clear() {
448 ((wxListBox*)id)->Clear();
449}
450
451void ListBox::Append(char *s) {
452 ((wxListBox*)id)->Append(s);
453}
454
455int ListBox::Length() {
456 return ((wxListBox*)id)->Number();
457}
458
459void ListBox::Select(int n) {
460 ((wxListBox*)id)->SetSelection(n);
461}
462
463int ListBox::GetSelection() {
464 return ((wxListBox*)id)->GetSelection();
465}
466
467int ListBox::Find(const char *prefix) {
468 return ((wxListBox*)id)->FindString(prefix);
469}
470
471void ListBox::GetValue(int n, char *value, int len) {
472 wxString text = ((wxListBox*)id)->GetString(n);
473 strncpy(value, text.c_str(), len);
474 value[len-1] = '\0';
475}
476
477void ListBox::Sort() {
478 // wxWindows keeps sorted so no need to sort
479}
480
481
482Menu::Menu() : id(0) {
483}
484
485void Menu::CreatePopUp() {
486 Destroy();
487 id = new wxMenu();
488}
489
490void Menu::Destroy() {
491 if (id)
492 delete id;
493 id = 0;
494}
495
496void Menu::Show(Point pt, Window &w) {
497 w.GetID()->PopupMenu(id, pt.x - 4, pt.y);
498 Destroy();
499}
500
501
502Colour Platform::Chrome() {
503 wxColour c;
504 c = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
505 return Colour(c.Red(), c.Green(), c.Blue());
506}
507
508Colour Platform::ChromeHighlight() {
509 wxColour c;
510 c = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT);
511 return Colour(c.Red(), c.Green(), c.Blue());
512}
513
514const char *Platform::DefaultFont() {
515 return wxNORMAL_FONT->GetFaceName();
516}
517
518int Platform::DefaultFontSize() {
519 return 8;
520}
521
522unsigned int Platform::DoubleClickTime() {
523 return 500; // **** ::GetDoubleClickTime();
524}
525
526void Platform::DebugDisplay(const char *s) {
527 wxLogDebug(s);
528}
529
530bool Platform::IsKeyDown(int key) {
531 return false; // I don't think we'll need this.
532}
533
534long Platform::SendScintilla(WindowID w,
535 unsigned int msg,
536 unsigned long wParam,
537 long lParam) {
538
539 wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w;
540 return stc->SendMsg(msg, wParam, lParam);
541}
542
543
544// These are utility functions not really tied to a platform
545
546int Platform::Minimum(int a, int b) {
547 if (a < b)
548 return a;
549 else
550 return b;
551}
552
553int Platform::Maximum(int a, int b) {
554 if (a > b)
555 return a;
556 else
557 return b;
558}
559
560#define TRACE
561
562void Platform::DebugPrintf(const char *format, ...) {
563#ifdef TRACE
564 char buffer[2000];
565 va_list pArguments;
566 va_start(pArguments, format);
567 vsprintf(buffer,format,pArguments);
568 va_end(pArguments);
569 Platform::DebugDisplay(buffer);
570#endif
571}
572
573int Platform::Clamp(int val, int minVal, int maxVal) {
574 if (val > maxVal)
575 val = maxVal;
576 if (val < minVal)
577 val = minVal;
578 return val;
579}
580
581
582
583
584
585