]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/PlatWX.cpp
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.
10 #include "wx/stc/stc.h"
12 Point
Point::FromLong(long lpoint
) {
13 return Point(lpoint
& 0xFFFF, lpoint
>> 16);
16 wxRect
wxRectFromPRectangle(PRectangle prc
) {
17 wxRect
rc(prc
.left
, prc
.top
,
18 prc
.right
-prc
.left
, prc
.bottom
-prc
.top
);
22 PRectangle
PRectangleFromwxRect(wxRect rc
) {
23 return PRectangle(rc
.GetLeft(), rc
.GetTop(), rc
.GetRight(), rc
.GetBottom());
26 Colour::Colour(long lcol
) {
27 co
.Set(lcol
& 0xff, (lcol
>> 8) & 0xff, (lcol
>> 16) & 0xff);
30 Colour::Colour(unsigned int red
, unsigned int green
, unsigned int blue
) {
31 co
.Set(red
, green
, blue
);
34 bool Colour::operator==(const Colour
&other
) const {
35 return co
== other
.co
;
38 long Colour::AsLong() const {
39 return (((long)co
.Blue() << 16) |
40 ((long)co
.Green() << 8) |
44 unsigned int Colour::GetRed() {
48 unsigned int Colour::GetGreen() {
52 unsigned int Colour::GetBlue() {
58 allowRealization
= false;
65 void Palette::Release() {
69 // This method either adds a colour to the list of wanted colours (want==true)
70 // or retrieves the allocated colour back to the ColourPair.
71 // This is one method to make it easier to keep the code for wanting and retrieving in sync.
72 void Palette::WantFind(ColourPair
&cp
, bool want
) {
74 for (int i
=0; i
< used
; i
++) {
75 if (entries
[i
].desired
== cp
.desired
)
79 if (used
< numEntries
) {
80 entries
[used
].desired
= cp
.desired
;
81 entries
[used
].allocated
= cp
.desired
;
85 for (int i
=0; i
< used
; i
++) {
86 if (entries
[i
].desired
== cp
.desired
) {
87 cp
.allocated
= entries
[i
].allocated
;
91 cp
.allocated
= cp
.desired
;
95 void Palette::Allocate(Window
&) {
96 if (allowRealization
) {
109 void Font::Create(const char *faceName
, int characterSet
, int size
, bool bold
, bool italic
) {
111 id
= new wxFont(size
,
113 italic
? wxITALIC
: wxNORMAL
,
114 bold
? wxBOLD
: wxNORMAL
,
117 wxFONTENCODING_DEFAULT
);
121 void Font::Release() {
129 hdc(0), hdcOwned(0), bitmap(0),
133 Surface::~Surface() {
137 void Surface::Release() {
139 ((wxMemoryDC
*)hdc
)->SelectObject(wxNullBitmap
);
151 bool Surface::Initialised() {
155 void Surface::Init() {
157 hdc
= new wxMemoryDC();
159 // **** ::SetTextAlign(hdc, TA_BASELINE);
162 void Surface::Init(SurfaceID hdc_
) {
165 // **** ::SetTextAlign(hdc, TA_BASELINE);
168 void Surface::InitPixMap(int width
, int height
, Surface
*surface_
) {
170 hdc
= new wxMemoryDC(surface_
->hdc
);
172 bitmap
= new wxBitmap(width
, height
);
173 ((wxMemoryDC
*)hdc
)->SelectObject(*bitmap
);
174 // **** ::SetTextAlign(hdc, TA_BASELINE);
177 void Surface::PenColour(Colour fore
) {
178 hdc
->SetPen(wxPen(fore
.co
, 1, wxSOLID
));
181 void Surface::BrushColor(Colour back
) {
182 hdc
->SetBrush(wxBrush(back
.co
, wxSOLID
));
185 void Surface::SetFont(Font
&font_
) {
187 hdc
->SetFont(*font_
.GetID());
191 int Surface::LogPixelsY() {
192 return hdc
->GetPPI().y
;
196 int Surface::DeviceHeightFont(int points
) {
197 return points
* LogPixelsY() / 72;
201 void Surface::MoveTo(int x_
, int y_
) {
206 void Surface::LineTo(int x_
, int y_
) {
207 hdc
->DrawLine(x
,y
, x_
,y_
);
212 void Surface::Polygon(Point
*pts
, int npts
, Colour fore
,
216 hdc
->DrawPolygon(npts
, (wxPoint
*)pts
);
219 void Surface::RectangleDraw(PRectangle rc
, Colour fore
, Colour back
) {
222 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
225 void Surface::FillRectangle(PRectangle rc
, Colour back
) {
227 hdc
->SetPen(*wxTRANSPARENT_PEN
);
228 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
231 void Surface::FillRectangle(PRectangle rc
, Surface
&surfacePattern
) {
233 if (surfacePattern
.bitmap
)
234 br
= wxBrush(*surfacePattern
.bitmap
);
235 else // Something is wrong so display in red
236 br
= wxBrush(*wxRED
, wxSOLID
);
237 hdc
->SetPen(*wxTRANSPARENT_PEN
);
239 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
242 void Surface::RoundedRectangle(PRectangle rc
, Colour fore
, Colour back
) {
245 hdc
->DrawRoundedRectangle(wxRectFromPRectangle(rc
), 4);
248 void Surface::Ellipse(PRectangle rc
, Colour fore
, Colour back
) {
251 hdc
->DrawEllipse(wxRectFromPRectangle(rc
));
254 void Surface::Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
) {
255 wxRect r
= wxRectFromPRectangle(rc
);
256 hdc
->Blit(r
.x
, r
.y
, r
.width
, r
.height
,
257 surfaceSource
.hdc
, from
.x
, from
.y
, wxCOPY
);
260 void Surface::DrawText(PRectangle rc
, Font
&font
, int ybase
,
261 const char *s
, int len
, Colour fore
, Colour back
) {
263 hdc
->SetTextForeground(fore
.co
);
264 hdc
->SetTextBackground(back
.co
);
265 FillRectangle(rc
, back
);
267 // ybase is where the baseline should be, but wxWin uses the upper left
268 // corner, so I need to calculate the real position for the text...
269 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
272 void Surface::DrawTextClipped(PRectangle rc
, Font
&font
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
) {
274 hdc
->SetTextForeground(fore
.co
);
275 hdc
->SetTextBackground(back
.co
);
276 FillRectangle(rc
, back
);
277 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
279 // see comments above
280 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
281 hdc
->DestroyClippingRegion();
284 int Surface::WidthText(Font
&font
, const char *s
, int len
) {
288 hdc
->GetTextExtent(wxString(s
, len
), &w
, &h
);
292 void Surface::MeasureWidths(Font
&font
, const char *s
, int len
, int *positions
) {
295 for (int i
=0; i
<len
; i
++) {
298 hdc
->GetTextExtent(s
[i
], &w
, &h
);
300 positions
[i
] = totalWidth
;
304 int Surface::WidthChar(Font
&font
, char ch
) {
308 hdc
->GetTextExtent(ch
, &w
, &h
);
312 #define EXTENT_TEST " `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
314 int Surface::Ascent(Font
&font
) {
317 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
322 int Surface::Descent(Font
&font
) {
325 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
329 int Surface::InternalLeading(Font
&font
) {
333 int Surface::ExternalLeading(Font
&font
) {
336 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
340 int Surface::Height(Font
&font
) {
342 return hdc
->GetCharHeight();
345 int Surface::AverageCharWidth(Font
&font
) {
347 return hdc
->GetCharWidth();
350 int Surface::SetPalette(Palette
*pal
, bool inBackGround
) {
351 return 0; // **** figure out what to do with palettes...
354 void Surface::SetClip(PRectangle rc
) {
355 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
358 void Surface::FlushCachedState() {
364 void Window::Destroy() {
370 bool Window::HasFocus() {
371 return wxWindow::FindFocus() == id
;
374 PRectangle
Window::GetPosition() {
375 wxRect
rc(id
->GetPosition(), id
->GetSize());
376 return PRectangleFromwxRect(rc
);
379 void Window::SetPosition(PRectangle rc
) {
380 wxRect r
= wxRectFromPRectangle(rc
);
384 void Window::SetPositionRelative(PRectangle rc
, Window
) {
385 SetPosition(rc
); // ????
388 PRectangle
Window::GetClientPosition() {
389 wxSize sz
= id
->GetClientSize();
390 return PRectangle(0, 0, sz
.x
, sz
.y
);
393 void Window::Show(bool show
) {
397 void Window::InvalidateAll() {
401 void Window::InvalidateRectangle(PRectangle rc
) {
402 wxRect r
= wxRectFromPRectangle(rc
);
403 id
->Refresh(false, &r
);
406 void Window::SetFont(Font
&font
) {
407 id
->SetFont(*font
.GetID());
410 void Window::SetCursor(Cursor curs
) {
415 cursorId
= wxCURSOR_IBEAM
;
418 cursorId
= wxCURSOR_ARROW
;
421 cursorId
= wxCURSOR_ARROW
; // ** no up arrow... wxCURSOR_UPARROW;
424 cursorId
= wxCURSOR_WAIT
;
427 cursorId
= wxCURSOR_SIZEWE
;
430 cursorId
= wxCURSOR_SIZENS
;
432 case cursorReverseArrow
:
433 cursorId
= wxCURSOR_POINT_RIGHT
;
436 cursorId
= wxCURSOR_ARROW
;
440 id
->SetCursor(wxCursor(cursorId
));
444 void Window::SetTitle(const char *s
) {
453 ListBox::~ListBox() {
456 void ListBox::Create(Window
&parent
, int ctrlID
) {
457 id
= new wxListBox(parent
.id
, ctrlID
, wxDefaultPosition
, wxDefaultSize
,
458 0, NULL
, wxLB_SINGLE
| wxLB_SORT
);
461 PRectangle
ListBox::GetDesiredRect() {
462 wxSize sz
= ((wxListBox
*)id
)->GetBestSize();
472 void ListBox::SetAverageCharWidth(int width
) {
473 aveCharWidth
= width
;
476 void ListBox::SetFont(Font
&font
) {
477 Window::SetFont(font
);
480 void ListBox::Clear() {
481 ((wxListBox
*)id
)->Clear();
484 void ListBox::Append(char *s
) {
485 ((wxListBox
*)id
)->Append(s
);
488 int ListBox::Length() {
489 return ((wxListBox
*)id
)->Number();
492 void ListBox::Select(int n
) {
493 ((wxListBox
*)id
)->SetSelection(n
);
496 int ListBox::GetSelection() {
497 return ((wxListBox
*)id
)->GetSelection();
500 int ListBox::Find(const char *prefix
) {
502 for (int x
=0; x
< ((wxListBox
*)id
)->Number(); x
++) {
503 wxString text
= ((wxListBox
*)id
)->GetString(x
);
504 if (text
.StartsWith(prefix
))
511 void ListBox::GetValue(int n
, char *value
, int len
) {
512 wxString text
= ((wxListBox
*)id
)->GetString(n
);
513 strncpy(value
, text
.c_str(), len
);
517 void ListBox::Sort() {
518 // wxWindows keeps sorted so no need to sort
522 Menu::Menu() : id(0) {
525 void Menu::CreatePopUp() {
530 void Menu::Destroy() {
536 void Menu::Show(Point pt
, Window
&w
) {
537 w
.GetID()->PopupMenu(id
, pt
.x
- 4, pt
.y
);
542 Colour
Platform::Chrome() {
544 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
545 return Colour(c
.Red(), c
.Green(), c
.Blue());
548 Colour
Platform::ChromeHighlight() {
550 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT
);
551 return Colour(c
.Red(), c
.Green(), c
.Blue());
554 const char *Platform::DefaultFont() {
555 return wxNORMAL_FONT
->GetFaceName();
558 int Platform::DefaultFontSize() {
562 unsigned int Platform::DoubleClickTime() {
563 return 500; // **** ::GetDoubleClickTime();
566 void Platform::DebugDisplay(const char *s
) {
570 bool Platform::IsKeyDown(int key
) {
571 return false; // I don't think we'll need this.
574 long Platform::SendScintilla(WindowID w
,
576 unsigned long wParam
,
579 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
580 return stc
->SendMsg(msg
, wParam
, lParam
);
584 // These are utility functions not really tied to a platform
586 int Platform::Minimum(int a
, int b
) {
593 int Platform::Maximum(int a
, int b
) {
602 void Platform::DebugPrintf(const char *format
, ...) {
606 va_start(pArguments
, format
);
607 vsprintf(buffer
,format
,pArguments
);
609 Platform::DebugDisplay(buffer
);
613 int Platform::Clamp(int val
, int minVal
, int maxVal
) {