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/encconv.h>
11 #include <wx/listctrl.h>
12 #include <wx/mstream.h>
14 #include <wx/imaglist.h>
18 #include "wx/stc/stc.h"
26 Point
Point::FromLong(long lpoint
) {
27 return Point(lpoint
& 0xFFFF, lpoint
>> 16);
30 wxRect
wxRectFromPRectangle(PRectangle prc
) {
31 wxRect
rc(prc
.left
, prc
.top
,
32 prc
.right
-prc
.left
, prc
.bottom
-prc
.top
);
36 PRectangle
PRectangleFromwxRect(wxRect rc
) {
37 return PRectangle(rc
.GetLeft(), rc
.GetTop(),
38 rc
.GetRight()+1, rc
.GetBottom()+1);
41 wxColour
wxColourFromCA(const ColourAllocated
& ca
) {
42 ColourDesired
cd(ca
.AsLong());
43 return wxColour(cd
.GetRed(), cd
.GetGreen(), cd
.GetBlue());
46 //----------------------------------------------------------------------
50 allowRealization
= false;
57 void Palette::Release() {
61 // This method either adds a colour to the list of wanted colours (want==true)
62 // or retrieves the allocated colour back to the ColourPair.
63 // This is one method to make it easier to keep the code for wanting and retrieving in sync.
64 void Palette::WantFind(ColourPair
&cp
, bool want
) {
66 for (int i
=0; i
< used
; i
++) {
67 if (entries
[i
].desired
== cp
.desired
)
71 if (used
< numEntries
) {
72 entries
[used
].desired
= cp
.desired
;
73 entries
[used
].allocated
.Set(cp
.desired
.AsLong());
77 for (int i
=0; i
< used
; i
++) {
78 if (entries
[i
].desired
== cp
.desired
) {
79 cp
.allocated
= entries
[i
].allocated
;
83 cp
.allocated
.Set(cp
.desired
.AsLong());
87 void Palette::Allocate(Window
&) {
88 if (allowRealization
) {
93 //----------------------------------------------------------------------
103 void Font::Create(const char *faceName
, int characterSet
, int size
, bool bold
, bool italic
) {
104 wxFontEncoding encoding
;
108 switch (characterSet
) {
110 case wxSTC_CHARSET_ANSI
:
111 case wxSTC_CHARSET_DEFAULT
:
112 encoding
= wxFONTENCODING_DEFAULT
;
115 case wxSTC_CHARSET_BALTIC
:
116 encoding
= wxFONTENCODING_ISO8859_13
;
119 case wxSTC_CHARSET_CHINESEBIG5
:
120 encoding
= wxFONTENCODING_CP950
;
123 case wxSTC_CHARSET_EASTEUROPE
:
124 encoding
= wxFONTENCODING_ISO8859_2
;
127 case wxSTC_CHARSET_GB2312
:
128 encoding
= wxFONTENCODING_CP936
;
131 case wxSTC_CHARSET_GREEK
:
132 encoding
= wxFONTENCODING_ISO8859_7
;
135 case wxSTC_CHARSET_HANGUL
:
136 encoding
= wxFONTENCODING_CP949
;
139 case wxSTC_CHARSET_MAC
:
140 encoding
= wxFONTENCODING_DEFAULT
;
143 case wxSTC_CHARSET_OEM
:
144 encoding
= wxFONTENCODING_DEFAULT
;
147 case wxSTC_CHARSET_RUSSIAN
:
148 encoding
= wxFONTENCODING_KOI8
;
151 case wxSTC_CHARSET_SHIFTJIS
:
152 encoding
= wxFONTENCODING_CP932
;
155 case wxSTC_CHARSET_SYMBOL
:
156 encoding
= wxFONTENCODING_DEFAULT
;
159 case wxSTC_CHARSET_TURKISH
:
160 encoding
= wxFONTENCODING_ISO8859_9
;
163 case wxSTC_CHARSET_JOHAB
:
164 encoding
= wxFONTENCODING_DEFAULT
;
167 case wxSTC_CHARSET_HEBREW
:
168 encoding
= wxFONTENCODING_ISO8859_8
;
171 case wxSTC_CHARSET_ARABIC
:
172 encoding
= wxFONTENCODING_ISO8859_6
;
175 case wxSTC_CHARSET_VIETNAMESE
:
176 encoding
= wxFONTENCODING_DEFAULT
;
179 case wxSTC_CHARSET_THAI
:
180 encoding
= wxFONTENCODING_ISO8859_11
;
184 wxFontEncodingArray ea
= wxEncodingConverter::GetPlatformEquivalents(encoding
);
188 id
= new wxFont(size
,
190 italic
? wxITALIC
: wxNORMAL
,
191 bold
? wxBOLD
: wxNORMAL
,
198 void Font::Release() {
204 //----------------------------------------------------------------------
206 class SurfaceImpl
: public Surface
{
219 virtual void Init(WindowID wid
);
220 virtual void Init(SurfaceID sid
, WindowID wid
);
221 virtual void InitPixMap(int width
, int height
, Surface
*surface_
, WindowID wid
);
223 virtual void Release();
224 virtual bool Initialised();
225 virtual void PenColour(ColourAllocated fore
);
226 virtual int LogPixelsY();
227 virtual int DeviceHeightFont(int points
);
228 virtual void MoveTo(int x_
, int y_
);
229 virtual void LineTo(int x_
, int y_
);
230 virtual void Polygon(Point
*pts
, int npts
, ColourAllocated fore
, ColourAllocated back
);
231 virtual void RectangleDraw(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
);
232 virtual void FillRectangle(PRectangle rc
, ColourAllocated back
);
233 virtual void FillRectangle(PRectangle rc
, Surface
&surfacePattern
);
234 virtual void RoundedRectangle(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
);
235 virtual void Ellipse(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
);
236 virtual void Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
);
238 virtual void DrawTextNoClip(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, ColourAllocated fore
, ColourAllocated back
);
239 virtual void DrawTextClipped(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, ColourAllocated fore
, ColourAllocated back
);
240 virtual void DrawTextTransparent(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, ColourAllocated fore
);
241 virtual void MeasureWidths(Font
&font_
, const char *s
, int len
, int *positions
);
242 virtual int WidthText(Font
&font_
, const char *s
, int len
);
243 virtual int WidthChar(Font
&font_
, char ch
);
244 virtual int Ascent(Font
&font_
);
245 virtual int Descent(Font
&font_
);
246 virtual int InternalLeading(Font
&font_
);
247 virtual int ExternalLeading(Font
&font_
);
248 virtual int Height(Font
&font_
);
249 virtual int AverageCharWidth(Font
&font_
);
251 virtual int SetPalette(Palette
*pal
, bool inBackGround
);
252 virtual void SetClip(PRectangle rc
);
253 virtual void FlushCachedState();
255 virtual void SetUnicodeMode(bool unicodeMode_
);
256 virtual void SetDBCSMode(int codePage
);
258 void BrushColour(ColourAllocated back
);
259 void SetFont(Font
&font_
);
264 SurfaceImpl::SurfaceImpl() :
265 hdc(0), hdcOwned(0), bitmap(0),
266 x(0), y(0), unicodeMode(0)
269 SurfaceImpl::~SurfaceImpl() {
273 void SurfaceImpl::Init(WindowID wid
) {
276 hdc
= new wxMemoryDC();
279 // On Mac and GTK the DC is not really valid until it has a bitmap
280 // selected into it. So instead of just creating the DC with no bitmap,
281 // go ahead and give it one.
282 InitPixMap(1,1,NULL
,wid
);
286 void SurfaceImpl::Init(SurfaceID hdc_
, WindowID
) {
291 void SurfaceImpl::InitPixMap(int width
, int height
, Surface
*surface_
, WindowID
) {
293 hdc
= new wxMemoryDC();
295 if (width
< 1) width
= 1;
296 if (height
< 1) height
= 1;
297 bitmap
= new wxBitmap(width
, height
);
298 ((wxMemoryDC
*)hdc
)->SelectObject(*bitmap
);
302 void SurfaceImpl::Release() {
304 ((wxMemoryDC
*)hdc
)->SelectObject(wxNullBitmap
);
316 bool SurfaceImpl::Initialised() {
321 void SurfaceImpl::PenColour(ColourAllocated fore
) {
322 hdc
->SetPen(wxPen(wxColourFromCA(fore
), 1, wxSOLID
));
325 void SurfaceImpl::BrushColour(ColourAllocated back
) {
326 hdc
->SetBrush(wxBrush(wxColourFromCA(back
), wxSOLID
));
329 void SurfaceImpl::SetFont(Font
&font_
) {
331 hdc
->SetFont(*((wxFont
*)font_
.GetID()));
335 int SurfaceImpl::LogPixelsY() {
336 return hdc
->GetPPI().y
;
339 int SurfaceImpl::DeviceHeightFont(int points
) {
343 void SurfaceImpl::MoveTo(int x_
, int y_
) {
348 void SurfaceImpl::LineTo(int x_
, int y_
) {
349 hdc
->DrawLine(x
,y
, x_
,y_
);
354 void SurfaceImpl::Polygon(Point
*pts
, int npts
, ColourAllocated fore
, ColourAllocated back
) {
357 hdc
->DrawPolygon(npts
, (wxPoint
*)pts
);
360 void SurfaceImpl::RectangleDraw(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
) {
363 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
366 void SurfaceImpl::FillRectangle(PRectangle rc
, ColourAllocated back
) {
368 hdc
->SetPen(*wxTRANSPARENT_PEN
);
369 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
372 void SurfaceImpl::FillRectangle(PRectangle rc
, Surface
&surfacePattern
) {
374 if (((SurfaceImpl
&)surfacePattern
).bitmap
)
375 br
= wxBrush(*((SurfaceImpl
&)surfacePattern
).bitmap
);
376 else // Something is wrong so display in red
377 br
= wxBrush(*wxRED
, wxSOLID
);
378 hdc
->SetPen(*wxTRANSPARENT_PEN
);
380 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
383 void SurfaceImpl::RoundedRectangle(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
) {
386 hdc
->DrawRoundedRectangle(wxRectFromPRectangle(rc
), 4);
389 void SurfaceImpl::Ellipse(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
) {
392 hdc
->DrawEllipse(wxRectFromPRectangle(rc
));
395 void SurfaceImpl::Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
) {
396 wxRect r
= wxRectFromPRectangle(rc
);
397 hdc
->Blit(r
.x
, r
.y
, r
.width
, r
.height
,
398 ((SurfaceImpl
&)surfaceSource
).hdc
,
399 from
.x
, from
.y
, wxCOPY
);
402 void SurfaceImpl::DrawTextNoClip(PRectangle rc
, Font
&font
, int ybase
,
403 const char *s
, int len
,
404 ColourAllocated fore
, ColourAllocated back
) {
406 hdc
->SetTextForeground(wxColourFromCA(fore
));
407 hdc
->SetTextBackground(wxColourFromCA(back
));
408 //FillRectangle(rc, back);
410 // ybase is where the baseline should be, but wxWin uses the upper left
411 // corner, so I need to calculate the real position for the text...
412 hdc
->DrawText(stc2wx(s
, len
), rc
.left
, ybase
- font
.ascent
);
415 void SurfaceImpl::DrawTextClipped(PRectangle rc
, Font
&font
, int ybase
,
416 const char *s
, int len
,
417 ColourAllocated fore
, ColourAllocated back
) {
419 hdc
->SetTextForeground(wxColourFromCA(fore
));
420 hdc
->SetTextBackground(wxColourFromCA(back
));
421 //FillRectangle(rc, back);
422 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
424 // see comments above
425 hdc
->DrawText(stc2wx(s
, len
), rc
.left
, ybase
- font
.ascent
);
429 void SurfaceImpl::DrawTextTransparent(PRectangle rc
, Font
&font
, int ybase
,
430 const char *s
, int len
,
431 ColourAllocated fore
) {
434 hdc
->SetTextForeground(wxColourFromCA(fore
));
435 hdc
->SetBackgroundMode(wxTRANSPARENT
);
437 // ybase is where the baseline should be, but wxWin uses the upper left
438 // corner, so I need to calculate the real position for the text...
439 hdc
->DrawText(stc2wx(s
, len
), rc
.left
, ybase
- font
.ascent
);
441 hdc
->SetBackgroundMode(wxSOLID
);
445 void SurfaceImpl::MeasureWidths(Font
&font
, const char *s
, int len
, int *positions
) {
447 wxString str
= stc2wx(s
, len
);
451 // Calculate the position of each character based on the widths of
452 // the previous characters
453 int* tpos
= new int[len
];
456 for (i
=0; i
<str
.Length(); i
++) {
458 hdc
->GetTextExtent(str
[i
], &w
, &h
);
460 tpos
[i
] = totalWidth
;
463 // Instead of a running total, remeasure from the begining of the
464 // text for each character's position. This is because with AA fonts
465 // on OS X widths can be fractions of pixels wide when more than one
466 // are drawn together, so the sum of all character widths is not necessarily
467 // (and probably not) the same as the whole string width.
468 int* tpos
= new int[len
];
470 for (i
=0; i
<str
.Length(); i
++) {
472 hdc
->GetTextExtent(str
.Left(i
+1), &w
, &h
);
479 // Map the widths for UCS-2 characters back to the UTF-8 input string
480 // NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2
481 // so figure it out and fix it!
485 unsigned char uch
= (unsigned char)s
[i
];
486 positions
[i
++] = tpos
[ui
];
488 if (uch
< (0x80 + 0x40 + 0x20)) {
489 positions
[i
++] = tpos
[ui
];
491 positions
[i
++] = tpos
[ui
];
492 positions
[i
++] = tpos
[ui
];
499 // If not unicode then just use the widths we have
500 memcpy(positions
, tpos
, len
* sizeof(*tpos
));
507 int SurfaceImpl::WidthText(Font
&font
, const char *s
, int len
) {
512 hdc
->GetTextExtent(stc2wx(s
, len
), &w
, &h
);
517 int SurfaceImpl::WidthChar(Font
&font
, char ch
) {
521 char s
[2] = { ch
, 0 };
523 hdc
->GetTextExtent(stc2wx(s
, 1), &w
, &h
);
527 #define EXTENT_TEST wxT(" `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
529 int SurfaceImpl::Ascent(Font
&font
) {
532 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
537 int SurfaceImpl::Descent(Font
&font
) {
540 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
544 int SurfaceImpl::InternalLeading(Font
&font
) {
548 int SurfaceImpl::ExternalLeading(Font
&font
) {
551 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
555 int SurfaceImpl::Height(Font
&font
) {
557 return hdc
->GetCharHeight();
560 int SurfaceImpl::AverageCharWidth(Font
&font
) {
562 return hdc
->GetCharWidth();
565 int SurfaceImpl::SetPalette(Palette
*pal
, bool inBackGround
) {
569 void SurfaceImpl::SetClip(PRectangle rc
) {
570 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
573 void SurfaceImpl::FlushCachedState() {
576 void SurfaceImpl::SetUnicodeMode(bool unicodeMode_
) {
577 unicodeMode
=unicodeMode_
;
579 wxASSERT_MSG(unicodeMode
== wxUSE_UNICODE
,
580 wxT("Only unicode may be used when wxUSE_UNICODE is on."));
582 wxASSERT_MSG(unicodeMode
== wxUSE_UNICODE
,
583 wxT("Only non-unicode may be used when wxUSE_UNICODE is off."));
587 void SurfaceImpl::SetDBCSMode(int codePage
) {
588 // dbcsMode = codePage == SC_CP_DBCS;
592 Surface
*Surface::Allocate() {
593 return new SurfaceImpl
;
597 //----------------------------------------------------------------------
600 inline wxWindow
* GETWIN(WindowID id
) { return (wxWindow
*)id
; }
605 void Window::Destroy() {
608 GETWIN(id
)->Destroy();
613 bool Window::HasFocus() {
614 return wxWindow::FindFocus() == GETWIN(id
);
617 PRectangle
Window::GetPosition() {
618 if (! id
) return PRectangle();
619 wxRect
rc(GETWIN(id
)->GetPosition(), GETWIN(id
)->GetSize());
620 return PRectangleFromwxRect(rc
);
623 void Window::SetPosition(PRectangle rc
) {
624 wxRect r
= wxRectFromPRectangle(rc
);
625 GETWIN(id
)->SetSize(r
);
628 void Window::SetPositionRelative(PRectangle rc
, Window
) {
629 SetPosition(rc
); // ????
632 PRectangle
Window::GetClientPosition() {
633 if (! id
) return PRectangle();
634 wxSize sz
= GETWIN(id
)->GetClientSize();
635 return PRectangle(0, 0, sz
.x
, sz
.y
);
638 void Window::Show(bool show
) {
639 GETWIN(id
)->Show(show
);
642 void Window::InvalidateAll() {
643 GETWIN(id
)->Refresh(false);
647 void Window::InvalidateRectangle(PRectangle rc
) {
648 wxRect r
= wxRectFromPRectangle(rc
);
649 GETWIN(id
)->Refresh(false, &r
);
653 void Window::SetFont(Font
&font
) {
654 GETWIN(id
)->SetFont(*((wxFont
*)font
.GetID()));
657 void Window::SetCursor(Cursor curs
) {
662 cursorId
= wxCURSOR_IBEAM
;
665 cursorId
= wxCURSOR_ARROW
;
668 cursorId
= wxCURSOR_ARROW
; // ** no up arrow... wxCURSOR_UPARROW;
671 cursorId
= wxCURSOR_WAIT
;
674 cursorId
= wxCURSOR_SIZEWE
;
677 cursorId
= wxCURSOR_SIZENS
;
679 case cursorReverseArrow
:
680 cursorId
= wxCURSOR_RIGHT_ARROW
;
683 cursorId
= wxCURSOR_HAND
;
685 cursorId
= wxCURSOR_ARROW
;
689 wxCursor wc
= wxStockCursor(cursorId
) ;
691 wxCursor wc
= wxCursor(cursorId
) ;
693 GETWIN(id
)->SetCursor(wc
);
697 void Window::SetTitle(const char *s
) {
698 GETWIN(id
)->SetTitle(stc2wx(s
));
702 //----------------------------------------------------------------------
703 // Helper classes for ListBox
706 // This is a simple subclass of wxLIstView that just resets focus to the
707 // parent when it gets it.
708 class wxSTCListBox
: public wxListView
{
710 wxSTCListBox(wxWindow
* parent
, wxWindowID id
,
711 const wxPoint
& pos
, const wxSize
& size
,
713 : wxListView(parent
, id
, pos
, size
, style
)
716 void OnFocus(wxFocusEvent
& event
) {
717 GetParent()->SetFocus();
722 DECLARE_EVENT_TABLE()
725 BEGIN_EVENT_TABLE(wxSTCListBox
, wxListView
)
726 EVT_SET_FOCUS( wxSTCListBox::OnFocus
)
732 // A window to place the wxSTCListBox upon
733 class wxSTCListBoxWin
: public wxWindow
{
736 CallBackAction doubleClickAction
;
737 void* doubleClickActionData
;
739 wxSTCListBoxWin(wxWindow
* parent
, wxWindowID id
) :
740 wxWindow(parent
, id
, wxDefaultPosition
, wxSize(0,0), wxNO_BORDER
)
743 SetBackgroundColour(*wxBLACK
);
744 lv
= new wxSTCListBox(this, id
, wxDefaultPosition
, wxDefaultSize
,
745 wxLC_REPORT
| wxLC_SINGLE_SEL
| wxLC_NO_HEADER
| wxNO_BORDER
);
746 lv
->SetCursor(wxCursor(wxCURSOR_ARROW
));
747 lv
->InsertColumn(0, wxEmptyString
);
748 lv
->InsertColumn(1, wxEmptyString
);
753 wxImageList
* il
= lv
->GetImageList(wxIMAGE_LIST_SMALL
);
756 il
->GetSize(0, w
, h
);
763 void SetDoubleClickAction(CallBackAction action
, void *data
) {
764 doubleClickAction
= action
;
765 doubleClickActionData
= data
;
769 void OnFocus(wxFocusEvent
& event
) {
770 GetParent()->SetFocus();
774 void OnSize(wxSizeEvent
& event
) {
775 // resize the child, leaving a 1 pixel border
776 wxSize sz
= GetClientSize();
777 lv
->SetSize(1, 1, sz
.x
-2, sz
.y
-2);
778 // reset the column widths
779 lv
->SetColumnWidth(0, IconWidth()+4);
780 lv
->SetColumnWidth(1, sz
.x
- 2 - lv
->GetColumnWidth(0) -
781 wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
));
785 void OnActivate(wxListEvent
& event
) {
786 doubleClickAction(doubleClickActionData
);
789 wxListView
* GetLB() { return lv
; }
792 DECLARE_EVENT_TABLE()
796 BEGIN_EVENT_TABLE(wxSTCListBoxWin
, wxWindow
)
797 EVT_SET_FOCUS ( wxSTCListBoxWin::OnFocus
)
798 EVT_SIZE ( wxSTCListBoxWin::OnSize
)
799 EVT_LIST_ITEM_ACTIVATED(-1, wxSTCListBoxWin::OnActivate
)
804 inline wxSTCListBoxWin
* GETLBW(WindowID win
) {
805 return ((wxSTCListBoxWin
*)win
);
808 inline wxListView
* GETLB(WindowID win
) {
809 return GETLBW(win
)->GetLB();
812 //----------------------------------------------------------------------
814 class ListBoxImpl
: public ListBox
{
818 int desiredVisibleRows
;
821 wxImageList
* imgList
;
822 wxArrayInt
* imgTypeMap
;
828 virtual void SetFont(Font
&font
);
829 virtual void Create(Window
&parent
, int ctrlID
, int lineHeight_
, bool unicodeMode_
);
830 virtual void SetAverageCharWidth(int width
);
831 virtual void SetVisibleRows(int rows
);
832 virtual PRectangle
GetDesiredRect();
833 virtual int CaretFromEdge();
834 virtual void Clear();
835 virtual void Append(char *s
, int type
= -1);
836 virtual int Length();
837 virtual void Select(int n
);
838 virtual int GetSelection();
839 virtual int Find(const char *prefix
);
840 virtual void GetValue(int n
, char *value
, int len
);
842 virtual void RegisterImage(int type
, const char *xpm_data
);
843 virtual void ClearRegisteredImages();
844 virtual void SetDoubleClickAction(CallBackAction
, void *);
849 ListBoxImpl::ListBoxImpl()
850 : lineHeight(10), unicodeMode(false),
851 desiredVisibleRows(5), aveCharWidth(8), maxStrWidth(0),
852 imgList(NULL
), imgTypeMap(NULL
)
856 ListBoxImpl::~ListBoxImpl() {
868 void ListBoxImpl::SetFont(Font
&font
) {
869 GETLB(id
)->SetFont(*((wxFont
*)font
.GetID()));
873 void ListBoxImpl::Create(Window
&parent
, int ctrlID
, int lineHeight_
, bool unicodeMode_
) {
874 lineHeight
= lineHeight_
;
875 unicodeMode
= unicodeMode_
;
877 id
= new wxSTCListBoxWin(GETWIN(parent
.GetID()), ctrlID
);
879 GETLB(id
)->SetImageList(imgList
, wxIMAGE_LIST_SMALL
);
883 void ListBoxImpl::SetAverageCharWidth(int width
) {
884 aveCharWidth
= width
;
888 void ListBoxImpl::SetVisibleRows(int rows
) {
889 desiredVisibleRows
= rows
;
893 PRectangle
ListBoxImpl::GetDesiredRect() {
894 // wxListCtrl doesn't have a DoGetBestSize, so instead we kept track of
895 // the max size in Append and calculate it here...
896 int maxw
= maxStrWidth
;
899 // give it a default if there are no lines, and/or add a bit more
900 if (maxw
== 0) maxw
= 100;
901 maxw
+= aveCharWidth
* 3 +
902 GETLBW(id
)->IconWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
906 // estimate a desired height
907 int count
= GETLB(id
)->GetItemCount();
910 GETLB(id
)->GetItemRect(0, rect
);
911 maxh
= count
* rect
.GetHeight();
912 if (maxh
> 140) // TODO: Use desiredVisibleRows??
915 // Try to make the size an exact multiple of some number of lines
916 int lines
= maxh
/ rect
.GetHeight();
917 maxh
= (lines
+ 1) * rect
.GetHeight() + 2;
931 int ListBoxImpl::CaretFromEdge() {
932 return 4 + GETLBW(id
)->IconWidth();
936 void ListBoxImpl::Clear() {
937 GETLB(id
)->DeleteAllItems();
941 void ListBoxImpl::Append(char *s
, int type
) {
942 wxString text
= stc2wx(s
);
943 long count
= GETLB(id
)->GetItemCount();
944 long itemID
= GETLB(id
)->InsertItem(count
, wxEmptyString
);
945 GETLB(id
)->SetItem(itemID
, 1, text
);
947 GETLB(id
)->GetTextExtent(text
, &itemWidth
, NULL
);
948 maxStrWidth
= wxMax(maxStrWidth
, itemWidth
);
950 wxCHECK_RET(imgTypeMap
, wxT("Unexpected NULL imgTypeMap"));
951 long idx
= imgTypeMap
->Item(type
);
952 GETLB(id
)->SetItemImage(itemID
, idx
, idx
);
957 int ListBoxImpl::Length() {
958 return GETLB(id
)->GetItemCount();
962 void ListBoxImpl::Select(int n
) {
969 GETLB(id
)->Select(n
, select
);
973 int ListBoxImpl::GetSelection() {
974 return GETLB(id
)->GetFirstSelected();
978 int ListBoxImpl::Find(const char *prefix
) {
984 void ListBoxImpl::GetValue(int n
, char *value
, int len
) {
988 item
.SetMask(wxLIST_MASK_TEXT
);
989 GETLB(id
)->GetItem(item
);
990 strncpy(value
, wx2stc(item
.GetText()), len
);
994 void ListBoxImpl::Sort() {
998 void ListBoxImpl::RegisterImage(int type
, const char *xpm_data
) {
999 wxMemoryInputStream
stream(xpm_data
, strlen(xpm_data
)+1);
1000 wxBitmap
bmp(wxImage(stream
, wxBITMAP_TYPE_XPM
));
1003 // assumes all images are the same size
1004 imgList
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight(), TRUE
);
1005 imgTypeMap
= new wxArrayInt
;
1008 int idx
= imgList
->Add(bmp
);
1010 // do we need to extend the mapping array?
1011 wxArrayInt
& itm
= *imgTypeMap
;
1012 if ( itm
.GetCount() < (size_t)type
+1)
1013 itm
.Add(-1, type
- itm
.GetCount() + 1);
1015 // Add an item that maps type to the image index
1019 void ListBoxImpl::ClearRegisteredImages() {
1029 GETLB(id
)->SetImageList(NULL
, wxIMAGE_LIST_SMALL
);
1033 void ListBoxImpl::SetDoubleClickAction(CallBackAction action
, void *data
) {
1034 GETLBW(id
)->SetDoubleClickAction(action
, data
);
1039 ListBox::ListBox() {
1042 ListBox::~ListBox() {
1045 ListBox
*ListBox::Allocate() {
1046 return new ListBoxImpl();
1049 //----------------------------------------------------------------------
1051 Menu::Menu() : id(0) {
1054 void Menu::CreatePopUp() {
1059 void Menu::Destroy() {
1065 void Menu::Show(Point pt
, Window
&w
) {
1066 GETWIN(w
.GetID())->PopupMenu((wxMenu
*)id
, pt
.x
- 4, pt
.y
);
1070 //----------------------------------------------------------------------
1072 ColourDesired
Platform::Chrome() {
1074 c
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1075 return ColourDesired(c
.Red(), c
.Green(), c
.Blue());
1078 ColourDesired
Platform::ChromeHighlight() {
1080 c
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
);
1081 return ColourDesired(c
.Red(), c
.Green(), c
.Blue());
1084 const char *Platform::DefaultFont() {
1085 static char buf
[128];
1086 strcpy(buf
, wxNORMAL_FONT
->GetFaceName().mbc_str());
1090 int Platform::DefaultFontSize() {
1091 return wxNORMAL_FONT
->GetPointSize();
1094 unsigned int Platform::DoubleClickTime() {
1095 return 500; // **** ::GetDoubleClickTime();
1098 bool Platform::MouseButtonBounce() {
1101 void Platform::DebugDisplay(const char *s
) {
1102 wxLogDebug(stc2wx(s
));
1105 bool Platform::IsKeyDown(int key
) {
1106 return false; // I don't think we'll need this.
1109 long Platform::SendScintilla(WindowID w
,
1111 unsigned long wParam
,
1114 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
1115 return stc
->SendMsg(msg
, wParam
, lParam
);
1118 long Platform::SendScintillaPointer(WindowID w
,
1120 unsigned long wParam
,
1123 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
1124 return stc
->SendMsg(msg
, wParam
, (long)lParam
);
1128 // These are utility functions not really tied to a platform
1130 int Platform::Minimum(int a
, int b
) {
1137 int Platform::Maximum(int a
, int b
) {
1146 void Platform::DebugPrintf(const char *format
, ...) {
1150 va_start(pArguments
, format
);
1151 vsprintf(buffer
,format
,pArguments
);
1153 Platform::DebugDisplay(buffer
);
1158 static bool assertionPopUps
= true;
1160 bool Platform::ShowAssertionPopUps(bool assertionPopUps_
) {
1161 bool ret
= assertionPopUps
;
1162 assertionPopUps
= assertionPopUps_
;
1166 void Platform::Assert(const char *c
, const char *file
, int line
) {
1168 sprintf(buffer
, "Assertion [%s] failed at %s %d", c
, file
, line
);
1169 if (assertionPopUps
) {
1171 wxMessageBox(stc2wx(buffer
),
1172 wxT("Assertion failure"),
1173 wxICON_HAND
| wxOK
);
1174 // if (idButton == IDRETRY) {
1176 // } else if (idButton == IDIGNORE) {
1182 strcat(buffer
, "\r\n");
1183 Platform::DebugDisplay(buffer
);
1189 int Platform::Clamp(int val
, int minVal
, int maxVal
) {
1198 bool Platform::IsDBCSLeadByte(int codePage
, char ch
) {
1202 int Platform::DBCSCharLength(int codePage
, const char *s
) {
1206 int Platform::DBCSCharMaxLength() {
1211 //----------------------------------------------------------------------
1213 ElapsedTime::ElapsedTime() {
1217 double ElapsedTime::Duration(bool reset
) {
1218 double result
= wxGetElapsedTime(reset
);
1224 //----------------------------------------------------------------------