]>
git.saurik.com Git - wxWidgets.git/blob - contrib/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"
17 Point
Point::FromLong(long lpoint
) {
18 return Point(lpoint
& 0xFFFF, lpoint
>> 16);
21 wxRect
wxRectFromPRectangle(PRectangle prc
) {
22 wxRect
rc(prc
.left
, prc
.top
,
23 prc
.right
-prc
.left
, prc
.bottom
-prc
.top
);
27 PRectangle
PRectangleFromwxRect(wxRect rc
) {
28 return PRectangle(rc
.GetLeft(), rc
.GetTop(), rc
.GetRight(), rc
.GetBottom());
31 Colour::Colour(long lcol
) {
32 co
.Set(lcol
& 0xff, (lcol
>> 8) & 0xff, (lcol
>> 16) & 0xff);
35 Colour::Colour(unsigned int red
, unsigned int green
, unsigned int blue
) {
36 co
.Set(red
, green
, blue
);
39 bool Colour::operator==(const Colour
&other
) const {
40 return co
== other
.co
;
43 long Colour::AsLong() const {
44 return (((long)co
.Blue() << 16) |
45 ((long)co
.Green() << 8) |
49 unsigned int Colour::GetRed() {
53 unsigned int Colour::GetGreen() {
57 unsigned int Colour::GetBlue() {
63 allowRealization
= false;
70 void Palette::Release() {
74 // This method either adds a colour to the list of wanted colours (want==true)
75 // or retrieves the allocated colour back to the ColourPair.
76 // This is one method to make it easier to keep the code for wanting and retrieving in sync.
77 void Palette::WantFind(ColourPair
&cp
, bool want
) {
79 for (int i
=0; i
< used
; i
++) {
80 if (entries
[i
].desired
== cp
.desired
)
84 if (used
< numEntries
) {
85 entries
[used
].desired
= cp
.desired
;
86 entries
[used
].allocated
= cp
.desired
;
90 for (int i
=0; i
< used
; i
++) {
91 if (entries
[i
].desired
== cp
.desired
) {
92 cp
.allocated
= entries
[i
].allocated
;
96 cp
.allocated
= cp
.desired
;
100 void Palette::Allocate(Window
&) {
101 if (allowRealization
) {
114 void Font::Create(const char *faceName
, int characterSet
, int size
, bool bold
, bool italic
) {
115 // TODO: what to do about the characterSet?
118 id
= new wxFont(size
,
120 italic
? wxITALIC
: wxNORMAL
,
121 bold
? wxBOLD
: wxNORMAL
,
124 wxFONTENCODING_DEFAULT
);
128 void Font::Release() {
136 hdc(0), hdcOwned(0), bitmap(0),
140 Surface::~Surface() {
144 void Surface::Release() {
146 ((wxMemoryDC
*)hdc
)->SelectObject(wxNullBitmap
);
158 bool Surface::Initialised() {
162 void Surface::Init() {
164 hdc
= new wxMemoryDC();
168 void Surface::Init(SurfaceID hdc_
) {
173 void Surface::InitPixMap(int width
, int height
, Surface
*surface_
) {
175 hdc
= new wxMemoryDC(surface_
->hdc
);
177 if (width
< 1) width
= 1;
178 if (height
< 1) height
= 1;
179 bitmap
= new wxBitmap(width
, height
);
180 ((wxMemoryDC
*)hdc
)->SelectObject(*bitmap
);
183 void Surface::PenColour(Colour fore
) {
184 hdc
->SetPen(wxPen(fore
.co
, 1, wxSOLID
));
187 void Surface::BrushColor(Colour back
) {
188 hdc
->SetBrush(wxBrush(back
.co
, wxSOLID
));
191 void Surface::SetFont(Font
&font_
) {
193 hdc
->SetFont(*font_
.GetID());
197 int Surface::LogPixelsY() {
198 return hdc
->GetPPI().y
;
202 int Surface::DeviceHeightFont(int points
) {
207 void Surface::MoveTo(int x_
, int y_
) {
212 void Surface::LineTo(int x_
, int y_
) {
213 hdc
->DrawLine(x
,y
, x_
,y_
);
218 void Surface::Polygon(Point
*pts
, int npts
, Colour fore
,
222 hdc
->DrawPolygon(npts
, (wxPoint
*)pts
);
225 void Surface::RectangleDraw(PRectangle rc
, Colour fore
, Colour back
) {
228 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
231 void Surface::FillRectangle(PRectangle rc
, Colour back
) {
233 hdc
->SetPen(*wxTRANSPARENT_PEN
);
234 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
237 void Surface::FillRectangle(PRectangle rc
, Surface
&surfacePattern
) {
239 if (surfacePattern
.bitmap
)
240 br
= wxBrush(*surfacePattern
.bitmap
);
241 else // Something is wrong so display in red
242 br
= wxBrush(*wxRED
, wxSOLID
);
243 hdc
->SetPen(*wxTRANSPARENT_PEN
);
245 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
248 void Surface::RoundedRectangle(PRectangle rc
, Colour fore
, Colour back
) {
251 hdc
->DrawRoundedRectangle(wxRectFromPRectangle(rc
), 4);
254 void Surface::Ellipse(PRectangle rc
, Colour fore
, Colour back
) {
257 hdc
->DrawEllipse(wxRectFromPRectangle(rc
));
260 void Surface::Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
) {
261 wxRect r
= wxRectFromPRectangle(rc
);
262 hdc
->Blit(r
.x
, r
.y
, r
.width
, r
.height
,
263 surfaceSource
.hdc
, from
.x
, from
.y
, wxCOPY
);
266 void Surface::DrawText(PRectangle rc
, Font
&font
, int ybase
,
267 const char *s
, int len
, Colour fore
, Colour back
) {
269 hdc
->SetTextForeground(fore
.co
);
270 hdc
->SetTextBackground(back
.co
);
271 FillRectangle(rc
, back
);
273 // ybase is where the baseline should be, but wxWin uses the upper left
274 // corner, so I need to calculate the real position for the text...
275 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
278 void Surface::DrawTextClipped(PRectangle rc
, Font
&font
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
) {
280 hdc
->SetTextForeground(fore
.co
);
281 hdc
->SetTextBackground(back
.co
);
282 FillRectangle(rc
, back
);
283 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
285 // see comments above
286 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
287 hdc
->DestroyClippingRegion();
290 int Surface::WidthText(Font
&font
, const char *s
, int len
) {
294 hdc
->GetTextExtent(wxString(s
, len
), &w
, &h
);
298 void Surface::MeasureWidths(Font
&font
, const char *s
, int len
, int *positions
) {
301 for (int i
=0; i
<len
; i
++) {
304 hdc
->GetTextExtent(s
[i
], &w
, &h
);
306 positions
[i
] = totalWidth
;
310 int Surface::WidthChar(Font
&font
, char ch
) {
314 hdc
->GetTextExtent(ch
, &w
, &h
);
318 #define EXTENT_TEST " `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
320 int Surface::Ascent(Font
&font
) {
323 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
328 int Surface::Descent(Font
&font
) {
331 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
335 int Surface::InternalLeading(Font
&font
) {
339 int Surface::ExternalLeading(Font
&font
) {
342 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
346 int Surface::Height(Font
&font
) {
348 return hdc
->GetCharHeight();
351 int Surface::AverageCharWidth(Font
&font
) {
353 return hdc
->GetCharWidth();
356 int Surface::SetPalette(Palette
*pal
, bool inBackGround
) {
360 void Surface::SetClip(PRectangle rc
) {
361 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
364 void Surface::FlushCachedState() {
370 void Window::Destroy() {
376 bool Window::HasFocus() {
377 return wxWindow::FindFocus() == id
;
380 PRectangle
Window::GetPosition() {
381 wxRect
rc(id
->GetPosition(), id
->GetSize());
382 return PRectangleFromwxRect(rc
);
385 void Window::SetPosition(PRectangle rc
) {
386 wxRect r
= wxRectFromPRectangle(rc
);
390 void Window::SetPositionRelative(PRectangle rc
, Window
) {
391 SetPosition(rc
); // ????
394 PRectangle
Window::GetClientPosition() {
395 wxSize sz
= id
->GetClientSize();
396 return PRectangle(0, 0, sz
.x
, sz
.y
);
399 void Window::Show(bool show
) {
403 void Window::InvalidateAll() {
407 void Window::InvalidateRectangle(PRectangle rc
) {
408 wxRect r
= wxRectFromPRectangle(rc
);
409 id
->Refresh(false, &r
);
412 void Window::SetFont(Font
&font
) {
413 id
->SetFont(*font
.GetID());
416 void Window::SetCursor(Cursor curs
) {
421 cursorId
= wxCURSOR_IBEAM
;
424 cursorId
= wxCURSOR_ARROW
;
427 cursorId
= wxCURSOR_ARROW
; // ** no up arrow... wxCURSOR_UPARROW;
430 cursorId
= wxCURSOR_WAIT
;
433 cursorId
= wxCURSOR_SIZEWE
;
436 cursorId
= wxCURSOR_SIZENS
;
438 case cursorReverseArrow
:
439 cursorId
= wxCURSOR_POINT_RIGHT
;
442 cursorId
= wxCURSOR_ARROW
;
446 id
->SetCursor(wxCursor(cursorId
));
450 void Window::SetTitle(const char *s
) {
455 class wxSTCListBox
: public wxListBox
{
457 wxSTCListBox(wxWindow
* parent
, wxWindowID id
)
458 : wxListBox(parent
, id
, wxDefaultPosition
, wxDefaultSize
,
459 0, NULL
, wxLB_SINGLE
| wxSIMPLE_BORDER
) // | wxLB_SORT )
462 void OnFocus(wxFocusEvent
& event
) {
463 GetParent()->SetFocus();
468 DECLARE_EVENT_TABLE()
471 BEGIN_EVENT_TABLE(wxSTCListBox
, wxListBox
)
472 EVT_SET_FOCUS(wxSTCListBox::OnFocus
)
479 ListBox::~ListBox() {
482 void ListBox::Create(Window
&parent
, int ctrlID
) {
483 id
= new wxSTCListBox(parent
.id
, ctrlID
);
486 void ListBox::SetVisibleRows(int rows
) {
487 desiredVisibleRows
= rows
;
490 PRectangle
ListBox::GetDesiredRect() {
491 wxSize sz
= ((wxListBox
*)id
)->GetBestSize();
497 // if (sz.y > 150) // TODO: Use desiredVisibleRows??
498 // sz.y = 150; // For now just use the default from GetBestSize
504 void ListBox::SetAverageCharWidth(int width
) {
505 aveCharWidth
= width
;
508 void ListBox::SetFont(Font
&font
) {
509 Window::SetFont(font
);
512 void ListBox::Clear() {
513 ((wxListBox
*)id
)->Clear();
516 void ListBox::Append(char *s
) {
517 ((wxListBox
*)id
)->Append(s
);
520 int ListBox::Length() {
521 return ((wxListBox
*)id
)->GetCount();
524 void ListBox::Select(int n
) {
525 ((wxListBox
*)id
)->SetSelection(n
);
531 ((wxListBox
*)id
)->SetFirstItem(n
);
535 int ListBox::GetSelection() {
536 return ((wxListBox
*)id
)->GetSelection();
539 int ListBox::Find(const char *prefix
) {
544 void ListBox::GetValue(int n
, char *value
, int len
) {
545 wxString text
= ((wxListBox
*)id
)->GetString(n
);
546 strncpy(value
, text
.c_str(), len
);
550 void ListBox::Sort() {
551 // wxWindows keeps sorted so no need to sort
555 Menu::Menu() : id(0) {
558 void Menu::CreatePopUp() {
563 void Menu::Destroy() {
569 void Menu::Show(Point pt
, Window
&w
) {
570 w
.GetID()->PopupMenu(id
, pt
.x
- 4, pt
.y
);
575 Colour
Platform::Chrome() {
577 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
578 return Colour(c
.Red(), c
.Green(), c
.Blue());
581 Colour
Platform::ChromeHighlight() {
583 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT
);
584 return Colour(c
.Red(), c
.Green(), c
.Blue());
587 const char *Platform::DefaultFont() {
588 return wxNORMAL_FONT
->GetFaceName();
591 int Platform::DefaultFontSize() {
595 unsigned int Platform::DoubleClickTime() {
596 return 500; // **** ::GetDoubleClickTime();
599 void Platform::DebugDisplay(const char *s
) {
603 bool Platform::IsKeyDown(int key
) {
604 return false; // I don't think we'll need this.
607 long Platform::SendScintilla(WindowID w
,
609 unsigned long wParam
,
612 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
613 return stc
->SendMsg(msg
, wParam
, lParam
);
617 // These are utility functions not really tied to a platform
619 int Platform::Minimum(int a
, int b
) {
626 int Platform::Maximum(int a
, int b
) {
635 void Platform::DebugPrintf(const char *format
, ...) {
639 va_start(pArguments
, format
);
640 vsprintf(buffer
,format
,pArguments
);
642 Platform::DebugDisplay(buffer
);
647 static bool assertionPopUps
= true;
649 bool Platform::ShowAssertionPopUps(bool assertionPopUps_
) {
650 bool ret
= assertionPopUps
;
651 assertionPopUps
= assertionPopUps_
;
655 void Platform::Assert(const char *c
, const char *file
, int line
) {
657 sprintf(buffer
, "Assertion [%s] failed at %s %d", c
, file
, line
);
658 if (assertionPopUps
) {
659 int idButton
= wxMessageBox(buffer
, "Assertion failure",
661 // if (idButton == IDRETRY) {
663 // } else if (idButton == IDIGNORE) {
669 strcat(buffer
, "\r\n");
670 Platform::DebugDisplay(buffer
);
676 int Platform::Clamp(int val
, int minVal
, int maxVal
) {