]>
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
+1, prc
.bottom
-prc
.top
+1);
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
+1);
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 // I think the following check is valid.
188 // It eliminates a crash for me. -- eric@sourcegear.com
192 hdc
->SetFont(*font_
.GetID());
196 int Surface::LogPixelsY() {
197 return hdc
->GetPPI().y
;
201 int Surface::DeviceHeightFont(int points
) {
202 return points
* LogPixelsY() / 72;
206 void Surface::MoveTo(int x_
, int y_
) {
211 void Surface::LineTo(int x_
, int y_
) {
212 hdc
->DrawLine(x
,y
, x_
,y_
);
217 void Surface::Polygon(Point
*pts
, int npts
, Colour fore
,
221 hdc
->DrawPolygon(npts
, (wxPoint
*)pts
);
224 void Surface::RectangleDraw(PRectangle rc
, Colour fore
, Colour back
) {
227 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
230 void Surface::FillRectangle(PRectangle rc
, Colour back
) {
232 hdc
->SetPen(*wxTRANSPARENT_PEN
);
233 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
236 void Surface::FillRectangle(PRectangle rc
, Surface
&surfacePattern
) {
238 if (surfacePattern
.bitmap
)
239 br
= wxBrush(*surfacePattern
.bitmap
);
240 else // Something is wrong so display in red
241 br
= wxBrush(*wxRED
, wxSOLID
);
242 hdc
->SetPen(*wxTRANSPARENT_PEN
);
244 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
247 void Surface::RoundedRectangle(PRectangle rc
, Colour fore
, Colour back
) {
250 hdc
->DrawRoundedRectangle(wxRectFromPRectangle(rc
), 4);
253 void Surface::Ellipse(PRectangle rc
, Colour fore
, Colour back
) {
256 hdc
->DrawEllipse(wxRectFromPRectangle(rc
));
259 void Surface::Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
) {
260 wxRect r
= wxRectFromPRectangle(rc
);
261 hdc
->Blit(r
.x
, r
.y
, r
.width
, r
.height
,
262 surfaceSource
.hdc
, from
.x
, from
.y
, wxCOPY
);
265 void Surface::DrawText(PRectangle rc
, Font
&font
, int ybase
,
266 const char *s
, int len
, Colour fore
, Colour back
) {
268 hdc
->SetTextForeground(fore
.co
);
269 hdc
->SetTextBackground(back
.co
);
270 FillRectangle(rc
, back
);
272 // ybase is where the baseline should be, but wxWin uses the upper left
273 // corner, so I need to calculate the real position for the text...
274 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
277 void Surface::DrawTextClipped(PRectangle rc
, Font
&font
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
) {
279 hdc
->SetTextForeground(fore
.co
);
280 hdc
->SetTextBackground(back
.co
);
281 FillRectangle(rc
, back
);
282 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
284 // see comments above
285 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
286 hdc
->DestroyClippingRegion();
289 int Surface::WidthText(Font
&font
, const char *s
, int len
) {
293 hdc
->GetTextExtent(wxString(s
, len
), &w
, &h
);
297 void Surface::MeasureWidths(Font
&font
, const char *s
, int len
, int *positions
) {
300 for (int i
=0; i
<len
; i
++) {
303 hdc
->GetTextExtent(s
[i
], &w
, &h
);
305 positions
[i
] = totalWidth
;
309 int Surface::WidthChar(Font
&font
, char ch
) {
313 hdc
->GetTextExtent(ch
, &w
, &h
);
317 #define EXTENT_TEST " `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
319 int Surface::Ascent(Font
&font
) {
322 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
327 int Surface::Descent(Font
&font
) {
330 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
334 int Surface::InternalLeading(Font
&font
) {
338 int Surface::ExternalLeading(Font
&font
) {
341 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
345 int Surface::Height(Font
&font
) {
347 return hdc
->GetCharHeight();
350 int Surface::AverageCharWidth(Font
&font
) {
352 return hdc
->GetCharWidth();
355 int Surface::SetPalette(Palette
*pal
, bool inBackGround
) {
356 return 0; // **** figure out what to do with palettes...
359 void Surface::SetClip(PRectangle rc
) {
360 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
363 void Surface::FlushCachedState() {
364 // TODO Is there anything we need to do here? eric@sourcegear.com
365 // TODO I had to add this method when I merged new Scintilla code
372 void Window::Destroy() {
378 bool Window::HasFocus() {
379 return wxWindow::FindFocus() == id
;
382 PRectangle
Window::GetPosition() {
383 wxRect
rc(id
->GetPosition(), id
->GetSize());
384 return PRectangleFromwxRect(rc
);
387 void Window::SetPosition(PRectangle rc
) {
388 wxRect r
= wxRectFromPRectangle(rc
);
392 void Window::SetPositionRelative(PRectangle rc
, Window
) {
393 SetPosition(rc
); // ????
396 PRectangle
Window::GetClientPosition() {
397 wxSize sz
= id
->GetClientSize();
398 return PRectangle(0, 0, sz
.x
- 1, sz
.y
- 1);
401 void Window::Show(bool show
) {
405 void Window::InvalidateAll() {
409 void Window::InvalidateRectangle(PRectangle rc
) {
410 wxRect r
= wxRectFromPRectangle(rc
);
411 id
->Refresh(false, &r
);
414 void Window::SetFont(Font
&font
) {
415 id
->SetFont(*font
.GetID());
418 void Window::SetCursor(Cursor curs
) {
423 cursorId
= wxCURSOR_IBEAM
;
426 cursorId
= wxCURSOR_ARROW
;
429 cursorId
= wxCURSOR_ARROW
; // ** no up arrow... wxCURSOR_UPARROW;
432 cursorId
= wxCURSOR_WAIT
;
435 cursorId
= wxCURSOR_SIZEWE
;
438 cursorId
= wxCURSOR_SIZENS
;
440 case cursorReverseArrow
:
441 cursorId
= wxCURSOR_POINT_RIGHT
;
444 cursorId
= wxCURSOR_ARROW
;
448 id
->SetCursor(wxCursor(cursorId
));
452 void Window::SetTitle(const char *s
) {
461 ListBox::~ListBox() {
464 void ListBox::Create(Window
&parent
, int ctrlID
) {
465 id
= new wxListBox(parent
.id
, ctrlID
, wxDefaultPosition
, wxDefaultSize
,
466 0, NULL
, wxLB_SINGLE
| wxLB_SORT
);
469 void ListBox::Clear() {
470 ((wxListBox
*)id
)->Clear();
473 void ListBox::Append(char *s
) {
474 ((wxListBox
*)id
)->Append(s
);
477 int ListBox::Length() {
478 return ((wxListBox
*)id
)->Number();
481 void ListBox::Select(int n
) {
482 ((wxListBox
*)id
)->SetSelection(n
);
485 int ListBox::GetSelection() {
486 return ((wxListBox
*)id
)->GetSelection();
489 int ListBox::Find(const char *prefix
) {
490 for (int x
=0; x
< ((wxListBox
*)id
)->Number(); x
++) {
491 wxString text
= ((wxListBox
*)id
)->GetString(x
);
492 if (text
.StartsWith(prefix
))
498 void ListBox::GetValue(int n
, char *value
, int len
) {
499 wxString text
= ((wxListBox
*)id
)->GetString(n
);
500 strncpy(value
, text
.c_str(), len
);
504 void ListBox::Sort() {
505 // wxWindows keeps sorted so no need to sort
509 Menu::Menu() : id(0) {
512 void Menu::CreatePopUp() {
517 void Menu::Destroy() {
523 void Menu::Show(Point pt
, Window
&w
) {
524 w
.GetID()->PopupMenu(id
, pt
.x
- 4, pt
.y
);
529 Colour
Platform::Chrome() {
531 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
532 return Colour(c
.Red(), c
.Green(), c
.Blue());
535 Colour
Platform::ChromeHighlight() {
537 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT
);
538 return Colour(c
.Red(), c
.Green(), c
.Blue());
541 const char *Platform::DefaultFont() {
542 return wxNORMAL_FONT
->GetFaceName();
545 int Platform::DefaultFontSize() {
549 unsigned int Platform::DoubleClickTime() {
550 return 500; // **** ::GetDoubleClickTime();
553 void Platform::DebugDisplay(const char *s
) {
557 bool Platform::IsKeyDown(int key
) {
558 return false; // I don't think we'll need this.
561 long Platform::SendScintilla(WindowID w
,
563 unsigned long wParam
,
566 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
567 return stc
->SendMsg(msg
, wParam
, lParam
);
571 // These are utility functions not really tied to a platform
573 int Platform::Minimum(int a
, int b
) {
580 int Platform::Maximum(int a
, int b
) {
589 void Platform::DebugPrintf(const char *format
, ...) {
593 va_start(pArguments
, format
);
594 vsprintf(buffer
,format
,pArguments
);
596 Platform::DebugDisplay(buffer
);
600 int Platform::Clamp(int val
, int minVal
, int maxVal
) {