]>
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(),
29 rc
.GetRight()+1, rc
.GetBottom()+1);
32 Colour::Colour(long lcol
) {
33 co
.Set(lcol
& 0xff, (lcol
>> 8) & 0xff, (lcol
>> 16) & 0xff);
36 Colour::Colour(unsigned int red
, unsigned int green
, unsigned int blue
) {
37 co
.Set(red
, green
, blue
);
40 bool Colour::operator==(const Colour
&other
) const {
41 return co
== other
.co
;
44 long Colour::AsLong() const {
45 return (((long)co
.Blue() << 16) |
46 ((long)co
.Green() << 8) |
50 unsigned int Colour::GetRed() {
54 unsigned int Colour::GetGreen() {
58 unsigned int Colour::GetBlue() {
64 allowRealization
= false;
71 void Palette::Release() {
75 // This method either adds a colour to the list of wanted colours (want==true)
76 // or retrieves the allocated colour back to the ColourPair.
77 // This is one method to make it easier to keep the code for wanting and retrieving in sync.
78 void Palette::WantFind(ColourPair
&cp
, bool want
) {
80 for (int i
=0; i
< used
; i
++) {
81 if (entries
[i
].desired
== cp
.desired
)
85 if (used
< numEntries
) {
86 entries
[used
].desired
= cp
.desired
;
87 entries
[used
].allocated
= cp
.desired
;
91 for (int i
=0; i
< used
; i
++) {
92 if (entries
[i
].desired
== cp
.desired
) {
93 cp
.allocated
= entries
[i
].allocated
;
97 cp
.allocated
= cp
.desired
;
101 void Palette::Allocate(Window
&) {
102 if (allowRealization
) {
115 void Font::Create(const char *faceName
, int characterSet
, int size
, bool bold
, bool italic
) {
116 // TODO: what to do about the characterSet?
119 id
= new wxFont(size
,
121 italic
? wxITALIC
: wxNORMAL
,
122 bold
? wxBOLD
: wxNORMAL
,
125 wxFONTENCODING_DEFAULT
);
129 void Font::Release() {
137 hdc(0), hdcOwned(0), bitmap(0),
141 Surface::~Surface() {
145 void Surface::Release() {
147 ((wxMemoryDC
*)hdc
)->SelectObject(wxNullBitmap
);
159 bool Surface::Initialised() {
163 void Surface::Init() {
165 hdc
= new wxMemoryDC();
169 void Surface::Init(SurfaceID hdc_
) {
174 void Surface::InitPixMap(int width
, int height
, Surface
*surface_
) {
176 hdc
= new wxMemoryDC(surface_
->hdc
);
178 if (width
< 1) width
= 1;
179 if (height
< 1) height
= 1;
180 bitmap
= new wxBitmap(width
, height
);
181 ((wxMemoryDC
*)hdc
)->SelectObject(*bitmap
);
184 void Surface::PenColour(Colour fore
) {
185 hdc
->SetPen(wxPen(fore
.co
, 1, wxSOLID
));
188 void Surface::BrushColor(Colour back
) {
189 hdc
->SetBrush(wxBrush(back
.co
, wxSOLID
));
192 void Surface::SetFont(Font
&font_
) {
194 hdc
->SetFont(*font_
.GetID());
198 int Surface::LogPixelsY() {
199 return hdc
->GetPPI().y
;
203 int Surface::DeviceHeightFont(int points
) {
208 void Surface::MoveTo(int x_
, int y_
) {
213 void Surface::LineTo(int x_
, int y_
) {
214 hdc
->DrawLine(x
,y
, x_
,y_
);
219 void Surface::Polygon(Point
*pts
, int npts
, Colour fore
,
223 hdc
->DrawPolygon(npts
, (wxPoint
*)pts
);
226 void Surface::RectangleDraw(PRectangle rc
, Colour fore
, Colour back
) {
229 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
232 void Surface::FillRectangle(PRectangle rc
, Colour back
) {
234 hdc
->SetPen(*wxTRANSPARENT_PEN
);
235 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
238 void Surface::FillRectangle(PRectangle rc
, Surface
&surfacePattern
) {
240 if (surfacePattern
.bitmap
)
241 br
= wxBrush(*surfacePattern
.bitmap
);
242 else // Something is wrong so display in red
243 br
= wxBrush(*wxRED
, wxSOLID
);
244 hdc
->SetPen(*wxTRANSPARENT_PEN
);
246 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
249 void Surface::RoundedRectangle(PRectangle rc
, Colour fore
, Colour back
) {
252 hdc
->DrawRoundedRectangle(wxRectFromPRectangle(rc
), 4);
255 void Surface::Ellipse(PRectangle rc
, Colour fore
, Colour back
) {
258 hdc
->DrawEllipse(wxRectFromPRectangle(rc
));
261 void Surface::Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
) {
262 wxRect r
= wxRectFromPRectangle(rc
);
263 hdc
->Blit(r
.x
, r
.y
, r
.width
, r
.height
,
264 surfaceSource
.hdc
, from
.x
, from
.y
, wxCOPY
);
267 void Surface::DrawText(PRectangle rc
, Font
&font
, int ybase
,
268 const char *s
, int len
, Colour fore
, Colour back
) {
270 hdc
->SetTextForeground(fore
.co
);
271 hdc
->SetTextBackground(back
.co
);
272 FillRectangle(rc
, back
);
274 // ybase is where the baseline should be, but wxWin uses the upper left
275 // corner, so I need to calculate the real position for the text...
276 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
279 void Surface::DrawTextClipped(PRectangle rc
, Font
&font
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
) {
281 hdc
->SetTextForeground(fore
.co
);
282 hdc
->SetTextBackground(back
.co
);
283 FillRectangle(rc
, back
);
284 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
286 // see comments above
287 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
288 hdc
->DestroyClippingRegion();
291 int Surface::WidthText(Font
&font
, const char *s
, int len
) {
295 hdc
->GetTextExtent(wxString(s
, len
), &w
, &h
);
299 void Surface::MeasureWidths(Font
&font
, const char *s
, int len
, int *positions
) {
302 for (int i
=0; i
<len
; i
++) {
305 hdc
->GetTextExtent(s
[i
], &w
, &h
);
307 positions
[i
] = totalWidth
;
311 int Surface::WidthChar(Font
&font
, char ch
) {
315 hdc
->GetTextExtent(ch
, &w
, &h
);
319 #define EXTENT_TEST " `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
321 int Surface::Ascent(Font
&font
) {
324 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
329 int Surface::Descent(Font
&font
) {
332 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
336 int Surface::InternalLeading(Font
&font
) {
340 int Surface::ExternalLeading(Font
&font
) {
343 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
347 int Surface::Height(Font
&font
) {
349 return hdc
->GetCharHeight();
352 int Surface::AverageCharWidth(Font
&font
) {
354 return hdc
->GetCharWidth();
357 int Surface::SetPalette(Palette
*pal
, bool inBackGround
) {
361 void Surface::SetClip(PRectangle rc
) {
362 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
365 void Surface::FlushCachedState() {
371 void Window::Destroy() {
377 bool Window::HasFocus() {
378 return wxWindow::FindFocus() == id
;
381 PRectangle
Window::GetPosition() {
382 wxRect
rc(id
->GetPosition(), id
->GetSize());
383 return PRectangleFromwxRect(rc
);
386 void Window::SetPosition(PRectangle rc
) {
387 wxRect r
= wxRectFromPRectangle(rc
);
391 void Window::SetPositionRelative(PRectangle rc
, Window
) {
392 SetPosition(rc
); // ????
395 PRectangle
Window::GetClientPosition() {
396 wxSize sz
= id
->GetClientSize();
397 return PRectangle(0, 0, sz
.x
, sz
.y
);
400 void Window::Show(bool show
) {
404 void Window::InvalidateAll() {
408 void Window::InvalidateRectangle(PRectangle rc
) {
409 wxRect r
= wxRectFromPRectangle(rc
);
410 id
->Refresh(false, &r
);
413 void Window::SetFont(Font
&font
) {
414 id
->SetFont(*font
.GetID());
417 void Window::SetCursor(Cursor curs
) {
422 cursorId
= wxCURSOR_IBEAM
;
425 cursorId
= wxCURSOR_ARROW
;
428 cursorId
= wxCURSOR_ARROW
; // ** no up arrow... wxCURSOR_UPARROW;
431 cursorId
= wxCURSOR_WAIT
;
434 cursorId
= wxCURSOR_SIZEWE
;
437 cursorId
= wxCURSOR_SIZENS
;
439 case cursorReverseArrow
:
440 cursorId
= wxCURSOR_POINT_RIGHT
;
443 cursorId
= wxCURSOR_ARROW
;
447 id
->SetCursor(wxCursor(cursorId
));
451 void Window::SetTitle(const char *s
) {
456 class wxSTCListBox
: public wxListBox
{
458 wxSTCListBox(wxWindow
* parent
, wxWindowID id
)
459 : wxListBox(parent
, id
, wxDefaultPosition
, wxDefaultSize
,
460 0, NULL
, wxLB_SINGLE
| wxSIMPLE_BORDER
) // | wxLB_SORT )
463 void OnFocus(wxFocusEvent
& event
) {
464 GetParent()->SetFocus();
469 DECLARE_EVENT_TABLE()
472 BEGIN_EVENT_TABLE(wxSTCListBox
, wxListBox
)
473 EVT_SET_FOCUS(wxSTCListBox::OnFocus
)
480 ListBox::~ListBox() {
483 void ListBox::Create(Window
&parent
, int ctrlID
) {
484 id
= new wxSTCListBox(parent
.id
, ctrlID
);
487 void ListBox::SetVisibleRows(int rows
) {
488 desiredVisibleRows
= rows
;
491 PRectangle
ListBox::GetDesiredRect() {
492 wxSize sz
= ((wxListBox
*)id
)->GetBestSize();
498 if (sz
.y
> 160) // TODO: Use desiredVisibleRows??
505 void ListBox::SetAverageCharWidth(int width
) {
506 aveCharWidth
= width
;
509 void ListBox::SetFont(Font
&font
) {
510 Window::SetFont(font
);
513 void ListBox::Clear() {
514 ((wxListBox
*)id
)->Clear();
517 void ListBox::Append(char *s
) {
518 ((wxListBox
*)id
)->Append(s
);
521 int ListBox::Length() {
522 return ((wxListBox
*)id
)->GetCount();
525 void ListBox::Select(int n
) {
526 ((wxListBox
*)id
)->SetSelection(n
);
532 ((wxListBox
*)id
)->SetFirstItem(n
);
536 int ListBox::GetSelection() {
537 return ((wxListBox
*)id
)->GetSelection();
540 int ListBox::Find(const char *prefix
) {
545 void ListBox::GetValue(int n
, char *value
, int len
) {
546 wxString text
= ((wxListBox
*)id
)->GetString(n
);
547 strncpy(value
, text
.c_str(), len
);
551 void ListBox::Sort() {
552 // wxWindows keeps sorted so no need to sort
556 Menu::Menu() : id(0) {
559 void Menu::CreatePopUp() {
564 void Menu::Destroy() {
570 void Menu::Show(Point pt
, Window
&w
) {
571 w
.GetID()->PopupMenu(id
, pt
.x
- 4, pt
.y
);
576 Colour
Platform::Chrome() {
578 c
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
579 return Colour(c
.Red(), c
.Green(), c
.Blue());
582 Colour
Platform::ChromeHighlight() {
584 c
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
);
585 return Colour(c
.Red(), c
.Green(), c
.Blue());
588 const char *Platform::DefaultFont() {
589 return wxNORMAL_FONT
->GetFaceName();
592 int Platform::DefaultFontSize() {
596 unsigned int Platform::DoubleClickTime() {
597 return 500; // **** ::GetDoubleClickTime();
600 void Platform::DebugDisplay(const char *s
) {
604 bool Platform::IsKeyDown(int key
) {
605 return false; // I don't think we'll need this.
608 long Platform::SendScintilla(WindowID w
,
610 unsigned long wParam
,
613 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
614 return stc
->SendMsg(msg
, wParam
, lParam
);
618 // These are utility functions not really tied to a platform
620 int Platform::Minimum(int a
, int b
) {
627 int Platform::Maximum(int a
, int b
) {
636 void Platform::DebugPrintf(const char *format
, ...) {
640 va_start(pArguments
, format
);
641 vsprintf(buffer
,format
,pArguments
);
643 Platform::DebugDisplay(buffer
);
648 static bool assertionPopUps
= true;
650 bool Platform::ShowAssertionPopUps(bool assertionPopUps_
) {
651 bool ret
= assertionPopUps
;
652 assertionPopUps
= assertionPopUps_
;
656 void Platform::Assert(const char *c
, const char *file
, int line
) {
658 sprintf(buffer
, "Assertion [%s] failed at %s %d", c
, file
, line
);
659 if (assertionPopUps
) {
660 int idButton
= wxMessageBox(buffer
, "Assertion failure",
662 // if (idButton == IDRETRY) {
664 // } else if (idButton == IDIGNORE) {
670 strcat(buffer
, "\r\n");
671 Platform::DebugDisplay(buffer
);
677 int Platform::Clamp(int val
, int minVal
, int maxVal
) {