]>
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.
9 #include "wx/stc/stc.h"
11 Point
Point::FromLong(long lpoint
) {
12 return Point(lpoint
& 0xFFFF, lpoint
>> 32);
15 wxRect
wxRectFromPRectangle(PRectangle prc
) {
16 wxRect
rc(prc
.left
, prc
.top
,
17 prc
.right
-prc
.left
+1, prc
.bottom
-prc
.top
+1);
21 PRectangle
PRectangleFromwxRect(wxRect rc
) {
22 return PRectangle(rc
.GetLeft(), rc
.GetTop(), rc
.GetRight(), rc
.GetBottom());
25 Colour::Colour(long lcol
) {
26 co
.Set(lcol
& 0xff, (lcol
>> 8) & 0xff, (lcol
>> 16) & 0xff);
29 Colour::Colour(unsigned int red
, unsigned int green
, unsigned int blue
) {
30 co
.Set(red
, green
, blue
);
33 bool Colour::operator==(const Colour
&other
) const {
34 return co
== other
.co
;
37 long Colour::AsLong() const {
38 return (((long)co
.Blue() << 16) |
39 ((long)co
.Green() << 8) |
43 unsigned int Colour::GetRed() {
47 unsigned int Colour::GetGreen() {
51 unsigned int Colour::GetBlue() {
57 allowRealization
= false;
64 void Palette::Release() {
68 // This method either adds a colour to the list of wanted colours (want==true)
69 // or retrieves the allocated colour back to the ColourPair.
70 // This is one method to make it easier to keep the code for wanting and retrieving in sync.
71 void Palette::WantFind(ColourPair
&cp
, bool want
) {
73 for (int i
=0; i
< used
; i
++) {
74 if (entries
[i
].desired
== cp
.desired
)
78 if (used
< numEntries
) {
79 entries
[used
].desired
= cp
.desired
;
80 entries
[used
].allocated
= cp
.desired
;
84 for (int i
=0; i
< used
; i
++) {
85 if (entries
[i
].desired
== cp
.desired
) {
86 cp
.allocated
= entries
[i
].allocated
;
90 cp
.allocated
= cp
.desired
;
94 void Palette::Allocate(Window
&) {
95 if (allowRealization
) {
108 void Font::Create(const char *faceName
, int size
, bool bold
, bool italic
) {
110 id
= new wxFont(size
,
112 italic
? wxITALIC
: wxNORMAL
,
113 bold
? wxBOLD
: wxNORMAL
,
119 void Font::Release() {
127 hdc(0), hdcOwned(0), bitmap(0),
131 Surface::~Surface() {
135 void Surface::Release() {
137 ((wxMemoryDC
*)hdc
)->SelectObject(wxNullBitmap
);
149 bool Surface::Initialised() {
153 void Surface::Init() {
155 hdc
= new wxMemoryDC();
157 // **** ::SetTextAlign(hdc, TA_BASELINE);
160 void Surface::Init(SurfaceID hdc_
) {
163 // **** ::SetTextAlign(hdc, TA_BASELINE);
166 void Surface::InitPixMap(int width
, int height
, Surface
*surface_
) {
168 hdc
= new wxMemoryDC(surface_
->hdc
);
170 bitmap
= new wxBitmap(width
, height
);
171 ((wxMemoryDC
*)hdc
)->SelectObject(*bitmap
);
172 // **** ::SetTextAlign(hdc, TA_BASELINE);
175 void Surface::PenColour(Colour fore
) {
176 hdc
->SetPen(wxPen(fore
.co
, 1, wxSOLID
));
179 void Surface::BrushColor(Colour back
) {
180 hdc
->SetBrush(wxBrush(back
.co
, wxSOLID
));
183 void Surface::SetFont(Font
&font_
) {
184 hdc
->SetFont(*font_
.GetID());
187 int Surface::LogPixelsY() {
188 return hdc
->GetPPI().y
;
191 void Surface::MoveTo(int x_
, int y_
) {
196 void Surface::LineTo(int x_
, int y_
) {
197 hdc
->DrawLine(x
,y
, x_
,y_
);
202 void Surface::Polygon(Point
*pts
, int npts
, Colour fore
,
206 hdc
->DrawPolygon(npts
, (wxPoint
*)pts
);
209 void Surface::RectangleDraw(PRectangle rc
, Colour fore
, Colour back
) {
212 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
215 void Surface::FillRectangle(PRectangle rc
, Colour back
) {
217 hdc
->SetPen(*wxTRANSPARENT_PEN
);
218 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
221 void Surface::FillRectangle(PRectangle rc
, Surface
&surfacePattern
) {
223 if (surfacePattern
.bitmap
)
224 br
= wxBrush(*surfacePattern
.bitmap
);
225 else // Something is wrong so display in red
226 br
= wxBrush(*wxRED
, wxSOLID
);
227 hdc
->SetPen(*wxTRANSPARENT_PEN
);
229 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
232 void Surface::RoundedRectangle(PRectangle rc
, Colour fore
, Colour back
) {
235 hdc
->DrawRoundedRectangle(wxRectFromPRectangle(rc
), 8);
238 void Surface::Ellipse(PRectangle rc
, Colour fore
, Colour back
) {
241 hdc
->DrawEllipse(wxRectFromPRectangle(rc
));
244 void Surface::Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
) {
245 hdc
->Blit(rc
.left
, rc
.top
, rc
.Width(), rc
.Height(),
246 surfaceSource
.hdc
, from
.x
, from
.y
, wxCOPY
);
249 void Surface::DrawText(PRectangle rc
, Font
&font
, int ybase
,
250 const char *s
, int len
, Colour fore
, Colour back
) {
252 hdc
->SetTextForeground(fore
.co
);
253 hdc
->SetTextBackground(back
.co
);
254 FillRectangle(rc
, back
);
256 // ybase is where the baseline should be, but wxWin uses the upper left
257 // corner, so I need to calculate the real position for the text...
258 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
261 void Surface::DrawTextClipped(PRectangle rc
, Font
&font
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
) {
263 hdc
->SetTextForeground(fore
.co
);
264 hdc
->SetTextBackground(back
.co
);
265 FillRectangle(rc
, back
);
266 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
268 // see comments above
269 hdc
->DrawText(wxString(s
, len
), rc
.left
, ybase
- font
.ascent
);
270 hdc
->DestroyClippingRegion();
273 int Surface::WidthText(Font
&font
, const char *s
, int len
) {
277 hdc
->GetTextExtent(wxString(s
, len
), &w
, &h
);
281 void Surface::MeasureWidths(Font
&font
, const char *s
, int len
, int *positions
) {
284 for (int i
=0; i
<len
; i
++) {
287 hdc
->GetTextExtent(s
[i
], &w
, &h
);
289 positions
[i
] = totalWidth
;
293 int Surface::WidthChar(Font
&font
, char ch
) {
297 hdc
->GetTextExtent(ch
, &w
, &h
);
301 #define EXTENT_TEST " `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
303 int Surface::Ascent(Font
&font
) {
306 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
311 int Surface::Descent(Font
&font
) {
314 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
318 int Surface::InternalLeading(Font
&font
) {
322 int Surface::ExternalLeading(Font
&font
) {
325 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
329 int Surface::Height(Font
&font
) {
331 return hdc
->GetCharHeight();
334 int Surface::AverageCharWidth(Font
&font
) {
336 return hdc
->GetCharWidth();
339 int Surface::SetPalette(Palette
*pal
, bool inBackGround
) {
340 return 0; // **** figure out what to do with palettes...
343 void Surface::SetClip(PRectangle rc
) {
344 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
352 void Window::Destroy() {
358 bool Window::HasFocus() {
359 return wxWindow::FindFocus() == id
;
362 PRectangle
Window::GetPosition() {
363 wxRect
rc(id
->GetPosition(), id
->GetSize());
364 return PRectangleFromwxRect(rc
);
367 void Window::SetPosition(PRectangle rc
) {
368 id
->SetSize(rc
.left
, rc
.top
, rc
.Width(), rc
.Height());
371 void Window::SetPositionRelative(PRectangle rc
, Window
) {
372 SetPosition(rc
); // ????
375 PRectangle
Window::GetClientPosition() {
376 wxSize sz
= id
->GetClientSize();
377 return PRectangle(0, 0, sz
.x
- 1, sz
.y
- 1);
380 void Window::Show(bool show
) {
384 void Window::InvalidateAll() {
388 void Window::InvalidateRectangle(PRectangle rc
) {
389 id
->Refresh(false, &wxRectFromPRectangle(rc
));
392 void Window::SetFont(Font
&font
) {
393 id
->SetFont(*font
.GetID());
396 void Window::SetCursor(Cursor curs
) {
401 cursorId
= wxCURSOR_IBEAM
;
404 cursorId
= wxCURSOR_ARROW
;
407 cursorId
= wxCURSOR_ARROW
; // ** no up arrow... wxCURSOR_UPARROW;
410 cursorId
= wxCURSOR_WAIT
;
413 cursorId
= wxCURSOR_SIZEWE
;
416 cursorId
= wxCURSOR_SIZENS
;
418 case cursorReverseArrow
:
419 cursorId
= wxCURSOR_POINT_RIGHT
;
422 cursorId
= wxCURSOR_ARROW
;
426 id
->SetCursor(wxCursor(cursorId
));
430 void Window::SetTitle(const char *s
) {
439 ListBox::~ListBox() {
442 void ListBox::Create(Window
&parent
, int ctrlID
) {
443 id
= new wxListBox(parent
.id
, ctrlID
, wxDefaultPosition
, wxDefaultSize
,
444 0, NULL
, wxLB_SINGLE
| wxLB_SORT
);
447 void ListBox::Clear() {
448 ((wxListBox
*)id
)->Clear();
451 void ListBox::Append(char *s
) {
452 ((wxListBox
*)id
)->Append(s
);
455 int ListBox::Length() {
456 return ((wxListBox
*)id
)->Number();
459 void ListBox::Select(int n
) {
460 ((wxListBox
*)id
)->SetSelection(n
);
463 int ListBox::GetSelection() {
464 return ((wxListBox
*)id
)->GetSelection();
467 int ListBox::Find(const char *prefix
) {
468 return ((wxListBox
*)id
)->FindString(prefix
);
471 void ListBox::GetValue(int n
, char *value
, int len
) {
472 wxString text
= ((wxListBox
*)id
)->GetString(n
);
473 strncpy(value
, text
.c_str(), len
);
477 void ListBox::Sort() {
478 // wxWindows keeps sorted so no need to sort
482 Menu::Menu() : id(0) {
485 void Menu::CreatePopUp() {
490 void Menu::Destroy() {
496 void Menu::Show(Point pt
, Window
&w
) {
497 w
.GetID()->PopupMenu(id
, pt
.x
- 4, pt
.y
);
502 Colour
Platform::Chrome() {
504 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
505 return Colour(c
.Red(), c
.Green(), c
.Blue());
508 Colour
Platform::ChromeHighlight() {
510 c
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT
);
511 return Colour(c
.Red(), c
.Green(), c
.Blue());
514 const char *Platform::DefaultFont() {
515 return wxNORMAL_FONT
->GetFaceName();
518 int Platform::DefaultFontSize() {
522 unsigned int Platform::DoubleClickTime() {
523 return 500; // **** ::GetDoubleClickTime();
526 void Platform::DebugDisplay(const char *s
) {
530 bool Platform::IsKeyDown(int key
) {
531 return false; // I don't think we'll need this.
534 long Platform::SendScintilla(WindowID w
,
536 unsigned long wParam
,
539 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
540 return stc
->SendMsg(msg
, wParam
, lParam
);
544 // These are utility functions not really tied to a platform
546 int Platform::Minimum(int a
, int b
) {
553 int Platform::Maximum(int a
, int b
) {
562 void Platform::DebugPrintf(const char *format
, ...) {
566 va_start(pArguments
, format
);
567 vsprintf(buffer
,format
,pArguments
);
569 Platform::DebugDisplay(buffer
);
573 int Platform::Clamp(int val
, int minVal
, int maxVal
) {