]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/PlatWX.cpp
0fc480d8064420ece1e02da0d9dc1a6ddf00c284
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
>> 32);
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 size
, bool bold
, bool italic
) {
111 id
= new wxFont(size
,
113 italic
? wxITALIC
: wxNORMAL
,
114 bold
? wxBOLD
: wxNORMAL
,
120 void Font::Release() {
128 hdc(0), hdcOwned(0), bitmap(0),
132 Surface::~Surface() {
136 void Surface::Release() {
138 ((wxMemoryDC
*)hdc
)->SelectObject(wxNullBitmap
);
150 bool Surface::Initialised() {
154 void Surface::Init() {
156 hdc
= new wxMemoryDC();
158 // **** ::SetTextAlign(hdc, TA_BASELINE);
161 void Surface::Init(SurfaceID hdc_
) {
164 // **** ::SetTextAlign(hdc, TA_BASELINE);
167 void Surface::InitPixMap(int width
, int height
, Surface
*surface_
) {
169 hdc
= new wxMemoryDC(surface_
->hdc
);
171 bitmap
= new wxBitmap(width
, height
);
172 ((wxMemoryDC
*)hdc
)->SelectObject(*bitmap
);
173 // **** ::SetTextAlign(hdc, TA_BASELINE);
176 void Surface::PenColour(Colour fore
) {
177 hdc
->SetPen(wxPen(fore
.co
, 1, wxSOLID
));
180 void Surface::BrushColor(Colour back
) {
181 hdc
->SetBrush(wxBrush(back
.co
, wxSOLID
));
184 void Surface::SetFont(Font
&font_
) {
186 // I think the following check is valid.
187 // It eliminates a crash for me. -- eric@sourcegear.com
191 hdc
->SetFont(*font_
.GetID());
195 int Surface::LogPixelsY() {
196 return hdc
->GetPPI().y
;
199 void Surface::MoveTo(int x_
, int y_
) {
204 void Surface::LineTo(int x_
, int y_
) {
205 hdc
->DrawLine(x
,y
, x_
,y_
);
210 void Surface::Polygon(Point
*pts
, int npts
, Colour fore
,
214 hdc
->DrawPolygon(npts
, (wxPoint
*)pts
);
217 void Surface::RectangleDraw(PRectangle rc
, Colour fore
, Colour back
) {
220 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
223 void Surface::FillRectangle(PRectangle rc
, Colour back
) {
225 hdc
->SetPen(*wxTRANSPARENT_PEN
);
226 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
229 void Surface::FillRectangle(PRectangle rc
, Surface
&surfacePattern
) {
231 if (surfacePattern
.bitmap
)
232 br
= wxBrush(*surfacePattern
.bitmap
);
233 else // Something is wrong so display in red
234 br
= wxBrush(*wxRED
, wxSOLID
);
235 hdc
->SetPen(*wxTRANSPARENT_PEN
);
237 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
240 void Surface::RoundedRectangle(PRectangle rc
, Colour fore
, Colour back
) {
243 hdc
->DrawRoundedRectangle(wxRectFromPRectangle(rc
), 8);
246 void Surface::Ellipse(PRectangle rc
, Colour fore
, Colour back
) {
249 hdc
->DrawEllipse(wxRectFromPRectangle(rc
));
252 void Surface::Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
) {
253 hdc
->Blit(rc
.left
, rc
.top
, rc
.Width(), rc
.Height(),
254 surfaceSource
.hdc
, from
.x
, from
.y
, wxCOPY
);
257 void Surface::DrawText(PRectangle rc
, Font
&font
, int ybase
,
258 const char *s
, int len
, Colour fore
, Colour back
) {
260 hdc
->SetTextForeground(fore
.co
);
261 hdc
->SetTextBackground(back
.co
);
262 FillRectangle(rc
, back
);
264 // ybase is where the baseline should be, but wxWin uses the upper left
265 // corner, so I need to calculate the real position for the text...
266 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
269 void Surface::DrawTextClipped(PRectangle rc
, Font
&font
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
) {
271 hdc
->SetTextForeground(fore
.co
);
272 hdc
->SetTextBackground(back
.co
);
273 FillRectangle(rc
, back
);
274 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
276 // see comments above
277 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
278 hdc
->DestroyClippingRegion();
281 int Surface::WidthText(Font
&font
, const char *s
, int len
) {
285 hdc
->GetTextExtent(wxString(s
, len
), &w
, &h
);
289 void Surface::MeasureWidths(Font
&font
, const char *s
, int len
, int *positions
) {
292 for (int i
=0; i
<len
; i
++) {
295 hdc
->GetTextExtent(s
[i
], &w
, &h
);
297 positions
[i
] = totalWidth
;
301 int Surface::WidthChar(Font
&font
, char ch
) {
305 hdc
->GetTextExtent(ch
, &w
, &h
);
309 #define EXTENT_TEST " `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
311 int Surface::Ascent(Font
&font
) {
314 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
319 int Surface::Descent(Font
&font
) {
322 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
326 int Surface::InternalLeading(Font
&font
) {
330 int Surface::ExternalLeading(Font
&font
) {
333 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
337 int Surface::Height(Font
&font
) {
339 return hdc
->GetCharHeight();
342 int Surface::AverageCharWidth(Font
&font
) {
344 return hdc
->GetCharWidth();
347 int Surface::SetPalette(Palette
*pal
, bool inBackGround
) {
348 return 0; // **** figure out what to do with palettes...
351 void Surface::SetClip(PRectangle rc
) {
352 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
355 void Surface::FlushCachedState() {
356 // TODO Is there anything we need to do here? eric@sourcegear.com
357 // TODO I had to add this method when I merged new Scintilla code
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 id
->SetSize(rc
.left
, rc
.top
, rc
.Width(), rc
.Height());
383 void Window::SetPositionRelative(PRectangle rc
, Window
) {
384 SetPosition(rc
); // ????
387 PRectangle
Window::GetClientPosition() {
388 wxSize sz
= id
->GetClientSize();
389 return PRectangle(0, 0, sz
.x
- 1, sz
.y
- 1);
392 void Window::Show(bool show
) {
396 void Window::InvalidateAll() {
400 void Window::InvalidateRectangle(PRectangle rc
) {
401 id
->Refresh(false, &wxRectFromPRectangle(rc
));
404 void Window::SetFont(Font
&font
) {
405 id
->SetFont(*font
.GetID());
408 void Window::SetCursor(Cursor curs
) {
413 cursorId
= wxCURSOR_IBEAM
;
416 cursorId
= wxCURSOR_ARROW
;
419 cursorId
= wxCURSOR_ARROW
; // ** no up arrow... wxCURSOR_UPARROW;
422 cursorId
= wxCURSOR_WAIT
;
425 cursorId
= wxCURSOR_SIZEWE
;
428 cursorId
= wxCURSOR_SIZENS
;
430 case cursorReverseArrow
:
431 cursorId
= wxCURSOR_POINT_RIGHT
;
434 cursorId
= wxCURSOR_ARROW
;
438 id
->SetCursor(wxCursor(cursorId
));
442 void Window::SetTitle(const char *s
) {
451 ListBox::~ListBox() {
454 void ListBox::Create(Window
&parent
, int ctrlID
) {
455 id
= new wxListBox(parent
.id
, ctrlID
, wxDefaultPosition
, wxDefaultSize
,
456 0, NULL
, wxLB_SINGLE
| wxLB_SORT
);
459 void ListBox::Clear() {
460 ((wxListBox
*)id
)->Clear();
463 void ListBox::Append(char *s
) {
464 ((wxListBox
*)id
)->Append(s
);
467 int ListBox::Length() {
468 return ((wxListBox
*)id
)->Number();
471 void ListBox::Select(int n
) {
472 ((wxListBox
*)id
)->SetSelection(n
);
475 int ListBox::GetSelection() {
476 return ((wxListBox
*)id
)->GetSelection();
479 int ListBox::Find(const char *prefix
) {
480 return ((wxListBox
*)id
)->FindString(prefix
);
483 void ListBox::GetValue(int n
, char *value
, int len
) {
484 wxString text
= ((wxListBox
*)id
)->GetString(n
);
485 strncpy(value
, text
.c_str(), len
);
489 void ListBox::Sort() {
490 // wxWindows keeps sorted so no need to sort
494 Menu::Menu() : id(0) {
497 void Menu::CreatePopUp() {
502 void Menu::Destroy() {
508 void Menu::Show(Point pt
, Window
&w
) {
509 w
.GetID()->PopupMenu(id
, pt
.x
- 4, pt
.y
);
514 Colour
Platform::Chrome() {
516 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
517 return Colour(c
.Red(), c
.Green(), c
.Blue());
520 Colour
Platform::ChromeHighlight() {
522 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT
);
523 return Colour(c
.Red(), c
.Green(), c
.Blue());
526 const char *Platform::DefaultFont() {
527 return wxNORMAL_FONT
->GetFaceName();
530 int Platform::DefaultFontSize() {
534 unsigned int Platform::DoubleClickTime() {
535 return 500; // **** ::GetDoubleClickTime();
538 void Platform::DebugDisplay(const char *s
) {
542 bool Platform::IsKeyDown(int key
) {
543 return false; // I don't think we'll need this.
546 long Platform::SendScintilla(WindowID w
,
548 unsigned long wParam
,
551 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
552 return stc
->SendMsg(msg
, wParam
, lParam
);
556 // These are utility functions not really tied to a platform
558 int Platform::Minimum(int a
, int b
) {
565 int Platform::Maximum(int a
, int b
) {
574 void Platform::DebugPrintf(const char *format
, ...) {
578 va_start(pArguments
, format
);
579 vsprintf(buffer
,format
,pArguments
);
581 Platform::DebugDisplay(buffer
);
585 int Platform::Clamp(int val
, int minVal
, int maxVal
) {