1 // Scintilla source code edit control
2 // PlatWX.cxx - implementation of platform facilities on wxWidgets
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
r(prc
.left
, prc
.top
,
32 prc
.Width(), prc
.Height());
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
, bool extraFontFlag
) {
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 wxFont
* font
= new wxFont(size
,
190 italic
? wxITALIC
: wxNORMAL
,
191 bold
? wxBOLD
: wxNORMAL
,
195 font
->SetNoAntiAliasing(!extraFontFlag
);
200 void Font::Release() {
206 //----------------------------------------------------------------------
208 class SurfaceImpl
: public Surface
{
221 virtual void Init(WindowID wid
);
222 virtual void Init(SurfaceID sid
, WindowID wid
);
223 virtual void InitPixMap(int width
, int height
, Surface
*surface_
, WindowID wid
);
225 virtual void Release();
226 virtual bool Initialised();
227 virtual void PenColour(ColourAllocated fore
);
228 virtual int LogPixelsY();
229 virtual int DeviceHeightFont(int points
);
230 virtual void MoveTo(int x_
, int y_
);
231 virtual void LineTo(int x_
, int y_
);
232 virtual void Polygon(Point
*pts
, int npts
, ColourAllocated fore
, ColourAllocated back
);
233 virtual void RectangleDraw(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
);
234 virtual void FillRectangle(PRectangle rc
, ColourAllocated back
);
235 virtual void FillRectangle(PRectangle rc
, Surface
&surfacePattern
);
236 virtual void RoundedRectangle(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
);
237 virtual void Ellipse(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
);
238 virtual void Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
);
240 virtual void DrawTextNoClip(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, ColourAllocated fore
, ColourAllocated back
);
241 virtual void DrawTextClipped(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, ColourAllocated fore
, ColourAllocated back
);
242 virtual void DrawTextTransparent(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, ColourAllocated fore
);
243 virtual void MeasureWidths(Font
&font_
, const char *s
, int len
, int *positions
);
244 virtual int WidthText(Font
&font_
, const char *s
, int len
);
245 virtual int WidthChar(Font
&font_
, char ch
);
246 virtual int Ascent(Font
&font_
);
247 virtual int Descent(Font
&font_
);
248 virtual int InternalLeading(Font
&font_
);
249 virtual int ExternalLeading(Font
&font_
);
250 virtual int Height(Font
&font_
);
251 virtual int AverageCharWidth(Font
&font_
);
253 virtual int SetPalette(Palette
*pal
, bool inBackGround
);
254 virtual void SetClip(PRectangle rc
);
255 virtual void FlushCachedState();
257 virtual void SetUnicodeMode(bool unicodeMode_
);
258 virtual void SetDBCSMode(int codePage
);
260 void BrushColour(ColourAllocated back
);
261 void SetFont(Font
&font_
);
266 SurfaceImpl::SurfaceImpl() :
267 hdc(0), hdcOwned(0), bitmap(0),
268 x(0), y(0), unicodeMode(0)
271 SurfaceImpl::~SurfaceImpl() {
275 void SurfaceImpl::Init(WindowID wid
) {
278 hdc
= new wxMemoryDC();
281 // On Mac and GTK the DC is not really valid until it has a bitmap
282 // selected into it. So instead of just creating the DC with no bitmap,
283 // go ahead and give it one.
284 InitPixMap(1,1,NULL
,wid
);
288 void SurfaceImpl::Init(SurfaceID hdc_
, WindowID
) {
293 void SurfaceImpl::InitPixMap(int width
, int height
, Surface
*WXUNUSED(surface_
), WindowID
) {
295 hdc
= new wxMemoryDC();
297 if (width
< 1) width
= 1;
298 if (height
< 1) height
= 1;
299 bitmap
= new wxBitmap(width
, height
);
300 ((wxMemoryDC
*)hdc
)->SelectObject(*bitmap
);
304 void SurfaceImpl::Release() {
306 ((wxMemoryDC
*)hdc
)->SelectObject(wxNullBitmap
);
318 bool SurfaceImpl::Initialised() {
323 void SurfaceImpl::PenColour(ColourAllocated fore
) {
324 hdc
->SetPen(wxPen(wxColourFromCA(fore
), 1, wxSOLID
));
327 void SurfaceImpl::BrushColour(ColourAllocated back
) {
328 hdc
->SetBrush(wxBrush(wxColourFromCA(back
), wxSOLID
));
331 void SurfaceImpl::SetFont(Font
&font_
) {
333 hdc
->SetFont(*((wxFont
*)font_
.GetID()));
337 int SurfaceImpl::LogPixelsY() {
338 return hdc
->GetPPI().y
;
341 int SurfaceImpl::DeviceHeightFont(int points
) {
345 void SurfaceImpl::MoveTo(int x_
, int y_
) {
350 void SurfaceImpl::LineTo(int x_
, int y_
) {
351 hdc
->DrawLine(x
,y
, x_
,y_
);
356 void SurfaceImpl::Polygon(Point
*pts
, int npts
, ColourAllocated fore
, ColourAllocated back
) {
359 hdc
->DrawPolygon(npts
, (wxPoint
*)pts
);
362 void SurfaceImpl::RectangleDraw(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
) {
365 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
368 void SurfaceImpl::FillRectangle(PRectangle rc
, ColourAllocated back
) {
370 hdc
->SetPen(*wxTRANSPARENT_PEN
);
371 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
374 void SurfaceImpl::FillRectangle(PRectangle rc
, Surface
&surfacePattern
) {
376 if (((SurfaceImpl
&)surfacePattern
).bitmap
)
377 br
= wxBrush(*((SurfaceImpl
&)surfacePattern
).bitmap
);
378 else // Something is wrong so display in red
379 br
= wxBrush(*wxRED
, wxSOLID
);
380 hdc
->SetPen(*wxTRANSPARENT_PEN
);
382 hdc
->DrawRectangle(wxRectFromPRectangle(rc
));
385 void SurfaceImpl::RoundedRectangle(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
) {
388 hdc
->DrawRoundedRectangle(wxRectFromPRectangle(rc
), 4);
391 void SurfaceImpl::Ellipse(PRectangle rc
, ColourAllocated fore
, ColourAllocated back
) {
394 hdc
->DrawEllipse(wxRectFromPRectangle(rc
));
397 void SurfaceImpl::Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
) {
398 wxRect r
= wxRectFromPRectangle(rc
);
399 hdc
->Blit(r
.x
, r
.y
, r
.width
, r
.height
,
400 ((SurfaceImpl
&)surfaceSource
).hdc
,
401 from
.x
, from
.y
, wxCOPY
);
404 void SurfaceImpl::DrawTextNoClip(PRectangle rc
, Font
&font
, int ybase
,
405 const char *s
, int len
,
406 ColourAllocated fore
, ColourAllocated back
) {
408 hdc
->SetTextForeground(wxColourFromCA(fore
));
409 hdc
->SetTextBackground(wxColourFromCA(back
));
410 FillRectangle(rc
, back
);
412 // ybase is where the baseline should be, but wxWin uses the upper left
413 // corner, so I need to calculate the real position for the text...
414 hdc
->DrawText(stc2wx(s
, len
), rc
.left
, ybase
- font
.ascent
);
417 void SurfaceImpl::DrawTextClipped(PRectangle rc
, Font
&font
, int ybase
,
418 const char *s
, int len
,
419 ColourAllocated fore
, ColourAllocated back
) {
421 hdc
->SetTextForeground(wxColourFromCA(fore
));
422 hdc
->SetTextBackground(wxColourFromCA(back
));
423 FillRectangle(rc
, back
);
424 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
426 // see comments above
427 hdc
->DrawText(stc2wx(s
, len
), rc
.left
, ybase
- font
.ascent
);
428 hdc
->DestroyClippingRegion();
432 void SurfaceImpl::DrawTextTransparent(PRectangle rc
, Font
&font
, int ybase
,
433 const char *s
, int len
,
434 ColourAllocated fore
) {
437 hdc
->SetTextForeground(wxColourFromCA(fore
));
438 hdc
->SetBackgroundMode(wxTRANSPARENT
);
440 // ybase is where the baseline should be, but wxWin uses the upper left
441 // corner, so I need to calculate the real position for the text...
442 hdc
->DrawText(stc2wx(s
, len
), rc
.left
, ybase
- font
.ascent
);
444 hdc
->SetBackgroundMode(wxSOLID
);
448 void SurfaceImpl::MeasureWidths(Font
&font
, const char *s
, int len
, int *positions
) {
450 wxString str
= stc2wx(s
, len
);
455 hdc
->GetPartialTextExtents(str
, tpos
);
458 // Map the widths for UCS-2 characters back to the UTF-8 input string
459 // NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2
460 // so figure it out and fix it!
463 while ((int)i
< len
) {
464 unsigned char uch
= (unsigned char)s
[i
];
465 positions
[i
++] = tpos
[ui
];
467 if (uch
< (0x80 + 0x40 + 0x20)) {
468 positions
[i
++] = tpos
[ui
];
470 positions
[i
++] = tpos
[ui
];
471 positions
[i
++] = tpos
[ui
];
478 // If not unicode then just use the widths we have
479 memcpy(positions
, tpos
.begin(), len
* sizeof(int));
484 int SurfaceImpl::WidthText(Font
&font
, const char *s
, int len
) {
489 hdc
->GetTextExtent(stc2wx(s
, len
), &w
, &h
);
494 int SurfaceImpl::WidthChar(Font
&font
, char ch
) {
498 char s
[2] = { ch
, 0 };
500 hdc
->GetTextExtent(stc2wx(s
, 1), &w
, &h
);
504 #define EXTENT_TEST wxT(" `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
506 int SurfaceImpl::Ascent(Font
&font
) {
509 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
514 int SurfaceImpl::Descent(Font
&font
) {
517 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
521 int SurfaceImpl::InternalLeading(Font
&WXUNUSED(font
)) {
525 int SurfaceImpl::ExternalLeading(Font
&font
) {
528 hdc
->GetTextExtent(EXTENT_TEST
, &w
, &h
, &d
, &e
);
532 int SurfaceImpl::Height(Font
&font
) {
534 return hdc
->GetCharHeight() + 1;
537 int SurfaceImpl::AverageCharWidth(Font
&font
) {
539 return hdc
->GetCharWidth();
542 int SurfaceImpl::SetPalette(Palette
*WXUNUSED(pal
), bool WXUNUSED(inBackGround
)) {
546 void SurfaceImpl::SetClip(PRectangle rc
) {
547 hdc
->SetClippingRegion(wxRectFromPRectangle(rc
));
550 void SurfaceImpl::FlushCachedState() {
553 void SurfaceImpl::SetUnicodeMode(bool unicodeMode_
) {
554 unicodeMode
=unicodeMode_
;
557 void SurfaceImpl::SetDBCSMode(int WXUNUSED(codePage
)) {
558 // dbcsMode = codePage == SC_CP_DBCS;
562 Surface
*Surface::Allocate() {
563 return new SurfaceImpl
;
567 //----------------------------------------------------------------------
570 inline wxWindow
* GETWIN(WindowID id
) { return (wxWindow
*)id
; }
575 void Window::Destroy() {
578 GETWIN(id
)->Destroy();
583 bool Window::HasFocus() {
584 return wxWindow::FindFocus() == GETWIN(id
);
587 PRectangle
Window::GetPosition() {
588 if (! id
) return PRectangle();
589 wxRect
rc(GETWIN(id
)->GetPosition(), GETWIN(id
)->GetSize());
590 return PRectangleFromwxRect(rc
);
593 void Window::SetPosition(PRectangle rc
) {
594 wxRect r
= wxRectFromPRectangle(rc
);
595 GETWIN(id
)->SetSize(r
);
598 void Window::SetPositionRelative(PRectangle rc
, Window
) {
599 SetPosition(rc
); // ????
602 PRectangle
Window::GetClientPosition() {
603 if (! id
) return PRectangle();
604 wxSize sz
= GETWIN(id
)->GetClientSize();
605 return PRectangle(0, 0, sz
.x
, sz
.y
);
608 void Window::Show(bool show
) {
609 GETWIN(id
)->Show(show
);
612 void Window::InvalidateAll() {
613 GETWIN(id
)->Refresh(false);
617 void Window::InvalidateRectangle(PRectangle rc
) {
618 wxRect r
= wxRectFromPRectangle(rc
);
619 GETWIN(id
)->Refresh(false, &r
);
623 void Window::SetFont(Font
&font
) {
624 GETWIN(id
)->SetFont(*((wxFont
*)font
.GetID()));
627 void Window::SetCursor(Cursor curs
) {
632 cursorId
= wxCURSOR_IBEAM
;
635 cursorId
= wxCURSOR_ARROW
;
638 cursorId
= wxCURSOR_ARROW
; // ** no up arrow... wxCURSOR_UPARROW;
641 cursorId
= wxCURSOR_WAIT
;
644 cursorId
= wxCURSOR_SIZEWE
;
647 cursorId
= wxCURSOR_SIZENS
;
649 case cursorReverseArrow
:
650 cursorId
= wxCURSOR_RIGHT_ARROW
;
653 cursorId
= wxCURSOR_HAND
;
656 cursorId
= wxCURSOR_ARROW
;
660 wxCursor wc
= wxStockCursor(cursorId
) ;
662 wxCursor wc
= wxCursor(cursorId
) ;
664 GETWIN(id
)->SetCursor(wc
);
668 void Window::SetTitle(const char *s
) {
669 GETWIN(id
)->SetTitle(stc2wx(s
));
673 //----------------------------------------------------------------------
674 // Helper classes for ListBox
677 // This is a simple subclass of wxListView that just resets focus to the
678 // parent when it gets it.
679 class wxSTCListBox
: public wxListView
{
681 wxSTCListBox(wxWindow
* parent
, wxWindowID id
,
682 const wxPoint
& pos
, const wxSize
& size
,
684 : wxListView(parent
, id
, pos
, size
, style
)
688 void OnFocus(wxFocusEvent
& event
) {
689 GetParent()->SetFocus();
693 void OnKillFocus(wxFocusEvent
& WXUNUSED(event
)) {
694 // Do nothing. Prevents base class from resetting the colors...
698 // For some reason I don't understand yet the focus doesn't really leave
699 // the listbox like it should, so if we get any events feed them back to
701 void OnKeyDown(wxKeyEvent
& event
) {
702 GetGrandParent()->GetEventHandler()->ProcessEvent(event
);
704 void OnChar(wxKeyEvent
& event
) {
705 GetGrandParent()->GetEventHandler()->ProcessEvent(event
);
708 // And we need to force the focus back when being destroyed
710 GetGrandParent()->SetFocus();
715 DECLARE_EVENT_TABLE()
718 BEGIN_EVENT_TABLE(wxSTCListBox
, wxListView
)
719 EVT_SET_FOCUS( wxSTCListBox::OnFocus
)
720 EVT_KILL_FOCUS(wxSTCListBox::OnKillFocus
)
722 EVT_KEY_DOWN( wxSTCListBox::OnKeyDown
)
723 EVT_CHAR( wxSTCListBox::OnChar
)
730 // A window to place the wxSTCListBox upon
731 class wxSTCListBoxWin
: public wxWindow
{
734 CallBackAction doubleClickAction
;
735 void* doubleClickActionData
;
737 wxSTCListBoxWin(wxWindow
* parent
, wxWindowID id
) :
738 wxWindow(parent
, id
, wxDefaultPosition
, wxSize(0,0), wxSIMPLE_BORDER
)
741 lv
= new wxSTCListBox(this, id
, wxDefaultPosition
, wxDefaultSize
,
742 wxLC_REPORT
| wxLC_SINGLE_SEL
| wxLC_NO_HEADER
| wxNO_BORDER
);
743 lv
->SetCursor(wxCursor(wxCURSOR_ARROW
));
744 lv
->InsertColumn(0, wxEmptyString
);
745 lv
->InsertColumn(1, wxEmptyString
);
747 // Eventhough we immediately reset the focus to the parent, this helps
748 // things to look right...
755 // On OSX and (possibly others) there can still be pending
756 // messages/events for the list control when Scintilla wants to
757 // close it, so do a pending delete of it instead of destroying
761 // The bottom edge of this window is not getting properly
762 // refreshed upon deletion, so help it out...
763 wxWindow
* p
= GetParent();
764 wxRect
r(GetPosition(), GetSize());
765 r
.SetHeight(r
.GetHeight()+1);
766 p
->Refresh(false, &r
);
768 if ( !wxPendingDelete
.Member(this) )
769 wxPendingDelete
.Append(this);
775 wxImageList
* il
= lv
->GetImageList(wxIMAGE_LIST_SMALL
);
778 il
->GetSize(0, w
, h
);
785 void SetDoubleClickAction(CallBackAction action
, void *data
) {
786 doubleClickAction
= action
;
787 doubleClickActionData
= data
;
791 void OnFocus(wxFocusEvent
& event
) {
792 GetParent()->SetFocus();
796 void OnSize(wxSizeEvent
& event
) {
798 wxSize sz
= GetClientSize();
800 // reset the column widths
801 lv
->SetColumnWidth(0, IconWidth()+4);
802 lv
->SetColumnWidth(1, sz
.x
- 2 - lv
->GetColumnWidth(0) -
803 wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
));
807 void OnActivate(wxListEvent
& WXUNUSED(event
)) {
808 doubleClickAction(doubleClickActionData
);
811 wxListView
* GetLB() { return lv
; }
814 DECLARE_EVENT_TABLE()
818 BEGIN_EVENT_TABLE(wxSTCListBoxWin
, wxWindow
)
819 EVT_SET_FOCUS ( wxSTCListBoxWin::OnFocus
)
820 EVT_SIZE ( wxSTCListBoxWin::OnSize
)
821 EVT_LIST_ITEM_ACTIVATED(wxID_ANY
, wxSTCListBoxWin::OnActivate
)
826 inline wxSTCListBoxWin
* GETLBW(WindowID win
) {
827 return ((wxSTCListBoxWin
*)win
);
830 inline wxListView
* GETLB(WindowID win
) {
831 return GETLBW(win
)->GetLB();
834 //----------------------------------------------------------------------
836 class ListBoxImpl
: public ListBox
{
840 int desiredVisibleRows
;
843 wxImageList
* imgList
;
844 wxArrayInt
* imgTypeMap
;
850 virtual void SetFont(Font
&font
);
851 virtual void Create(Window
&parent
, int ctrlID
, int lineHeight_
, bool unicodeMode_
);
852 virtual void SetAverageCharWidth(int width
);
853 virtual void SetVisibleRows(int rows
);
854 virtual PRectangle
GetDesiredRect();
855 virtual int CaretFromEdge();
856 virtual void Clear();
857 virtual void Append(char *s
, int type
= -1);
858 virtual int Length();
859 virtual void Select(int n
);
860 virtual int GetSelection();
861 virtual int Find(const char *prefix
);
862 virtual void GetValue(int n
, char *value
, int len
);
863 virtual void RegisterImage(int type
, const char *xpm_data
);
864 virtual void ClearRegisteredImages();
865 virtual void SetDoubleClickAction(CallBackAction
, void *);
870 ListBoxImpl::ListBoxImpl()
871 : lineHeight(10), unicodeMode(false),
872 desiredVisibleRows(5), aveCharWidth(8), maxStrWidth(0),
873 imgList(NULL
), imgTypeMap(NULL
)
877 ListBoxImpl::~ListBoxImpl() {
889 void ListBoxImpl::SetFont(Font
&font
) {
890 GETLB(id
)->SetFont(*((wxFont
*)font
.GetID()));
894 void ListBoxImpl::Create(Window
&parent
, int ctrlID
, int lineHeight_
, bool unicodeMode_
) {
895 lineHeight
= lineHeight_
;
896 unicodeMode
= unicodeMode_
;
898 id
= new wxSTCListBoxWin(GETWIN(parent
.GetID()), ctrlID
);
900 GETLB(id
)->SetImageList(imgList
, wxIMAGE_LIST_SMALL
);
904 void ListBoxImpl::SetAverageCharWidth(int width
) {
905 aveCharWidth
= width
;
909 void ListBoxImpl::SetVisibleRows(int rows
) {
910 desiredVisibleRows
= rows
;
914 PRectangle
ListBoxImpl::GetDesiredRect() {
915 // wxListCtrl doesn't have a DoGetBestSize, so instead we kept track of
916 // the max size in Append and calculate it here...
917 int maxw
= maxStrWidth
;
920 // give it a default if there are no lines, and/or add a bit more
921 if (maxw
== 0) maxw
= 100;
922 maxw
+= aveCharWidth
* 3 +
923 GETLBW(id
)->IconWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
927 // estimate a desired height
928 int count
= GETLB(id
)->GetItemCount();
931 GETLB(id
)->GetItemRect(0, rect
);
932 maxh
= count
* rect
.GetHeight();
933 if (maxh
> 140) // TODO: Use desiredVisibleRows??
936 // Try to make the size an exact multiple of some number of lines
937 int lines
= maxh
/ rect
.GetHeight();
938 maxh
= (lines
+ 1) * rect
.GetHeight() + 2;
952 int ListBoxImpl::CaretFromEdge() {
953 return 4 + GETLBW(id
)->IconWidth();
957 void ListBoxImpl::Clear() {
958 GETLB(id
)->DeleteAllItems();
962 void ListBoxImpl::Append(char *s
, int type
) {
963 wxString text
= stc2wx(s
);
964 long count
= GETLB(id
)->GetItemCount();
965 long itemID
= GETLB(id
)->InsertItem(count
, wxEmptyString
);
966 GETLB(id
)->SetItem(itemID
, 1, text
);
968 GETLB(id
)->GetTextExtent(text
, &itemWidth
, NULL
);
969 maxStrWidth
= wxMax(maxStrWidth
, itemWidth
);
971 wxCHECK_RET(imgTypeMap
, wxT("Unexpected NULL imgTypeMap"));
972 long idx
= imgTypeMap
->Item(type
);
973 GETLB(id
)->SetItemImage(itemID
, idx
, idx
);
978 int ListBoxImpl::Length() {
979 return GETLB(id
)->GetItemCount();
983 void ListBoxImpl::Select(int n
) {
990 GETLB(id
)->Select(n
, select
);
994 int ListBoxImpl::GetSelection() {
995 return GETLB(id
)->GetFirstSelected();
999 int ListBoxImpl::Find(const char *WXUNUSED(prefix
)) {
1005 void ListBoxImpl::GetValue(int n
, char *value
, int len
) {
1009 item
.SetMask(wxLIST_MASK_TEXT
);
1010 GETLB(id
)->GetItem(item
);
1011 strncpy(value
, wx2stc(item
.GetText()), len
);
1012 value
[len
-1] = '\0';
1016 void ListBoxImpl::RegisterImage(int type
, const char *xpm_data
) {
1017 wxMemoryInputStream
stream(xpm_data
, strlen(xpm_data
)+1);
1018 wxBitmap
bmp(wxImage(stream
, wxBITMAP_TYPE_XPM
));
1021 // assumes all images are the same size
1022 imgList
= new wxImageList(bmp
.GetWidth(), bmp
.GetHeight(), true);
1023 imgTypeMap
= new wxArrayInt
;
1026 int idx
= imgList
->Add(bmp
);
1028 // do we need to extend the mapping array?
1029 wxArrayInt
& itm
= *imgTypeMap
;
1030 if ( itm
.GetCount() < (size_t)type
+1)
1031 itm
.Add(-1, type
- itm
.GetCount() + 1);
1033 // Add an item that maps type to the image index
1037 void ListBoxImpl::ClearRegisteredImages() {
1047 GETLB(id
)->SetImageList(NULL
, wxIMAGE_LIST_SMALL
);
1051 void ListBoxImpl::SetDoubleClickAction(CallBackAction action
, void *data
) {
1052 GETLBW(id
)->SetDoubleClickAction(action
, data
);
1057 ListBox::ListBox() {
1060 ListBox::~ListBox() {
1063 ListBox
*ListBox::Allocate() {
1064 return new ListBoxImpl();
1067 //----------------------------------------------------------------------
1069 Menu::Menu() : id(0) {
1072 void Menu::CreatePopUp() {
1077 void Menu::Destroy() {
1083 void Menu::Show(Point pt
, Window
&w
) {
1084 GETWIN(w
.GetID())->PopupMenu((wxMenu
*)id
, pt
.x
- 4, pt
.y
);
1088 //----------------------------------------------------------------------
1090 DynamicLibrary
*DynamicLibrary::Load(const char *WXUNUSED(modulePath
)) {
1091 wxFAIL_MSG(wxT("Dynamic lexer loading not implemented yet"));
1095 //----------------------------------------------------------------------
1097 ColourDesired
Platform::Chrome() {
1099 c
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1100 return ColourDesired(c
.Red(), c
.Green(), c
.Blue());
1103 ColourDesired
Platform::ChromeHighlight() {
1105 c
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
);
1106 return ColourDesired(c
.Red(), c
.Green(), c
.Blue());
1109 const char *Platform::DefaultFont() {
1110 static char buf
[128];
1111 strcpy(buf
, wxNORMAL_FONT
->GetFaceName().mbc_str());
1115 int Platform::DefaultFontSize() {
1116 return wxNORMAL_FONT
->GetPointSize();
1119 unsigned int Platform::DoubleClickTime() {
1120 return 500; // **** ::GetDoubleClickTime();
1123 bool Platform::MouseButtonBounce() {
1126 void Platform::DebugDisplay(const char *s
) {
1127 wxLogDebug(stc2wx(s
));
1130 bool Platform::IsKeyDown(int WXUNUSED(key
)) {
1131 return false; // I don't think we'll need this.
1134 long Platform::SendScintilla(WindowID w
,
1136 unsigned long wParam
,
1139 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
1140 return stc
->SendMsg(msg
, wParam
, lParam
);
1143 long Platform::SendScintillaPointer(WindowID w
,
1145 unsigned long wParam
,
1148 wxStyledTextCtrl
* stc
= (wxStyledTextCtrl
*)w
;
1149 return stc
->SendMsg(msg
, wParam
, (long)lParam
);
1153 // These are utility functions not really tied to a platform
1155 int Platform::Minimum(int a
, int b
) {
1162 int Platform::Maximum(int a
, int b
) {
1171 void Platform::DebugPrintf(const char *format
, ...) {
1175 va_start(pArguments
, format
);
1176 vsprintf(buffer
,format
,pArguments
);
1178 Platform::DebugDisplay(buffer
);
1183 static bool assertionPopUps
= true;
1185 bool Platform::ShowAssertionPopUps(bool assertionPopUps_
) {
1186 bool ret
= assertionPopUps
;
1187 assertionPopUps
= assertionPopUps_
;
1191 void Platform::Assert(const char *c
, const char *file
, int line
) {
1193 sprintf(buffer
, "Assertion [%s] failed at %s %d", c
, file
, line
);
1194 if (assertionPopUps
) {
1196 wxMessageBox(stc2wx(buffer
),
1197 wxT("Assertion failure"),
1198 wxICON_HAND
| wxOK
);
1199 // if (idButton == IDRETRY) {
1201 // } else if (idButton == IDIGNORE) {
1207 strcat(buffer
, "\r\n");
1208 Platform::DebugDisplay(buffer
);
1214 int Platform::Clamp(int val
, int minVal
, int maxVal
) {
1223 bool Platform::IsDBCSLeadByte(int WXUNUSED(codePage
), char WXUNUSED(ch
)) {
1227 int Platform::DBCSCharLength(int WXUNUSED(codePage
), const char *WXUNUSED(s
)) {
1231 int Platform::DBCSCharMaxLength() {
1236 //----------------------------------------------------------------------
1238 ElapsedTime::ElapsedTime() {
1242 double ElapsedTime::Duration(bool reset
) {
1243 double result
= wxGetElapsedTime(reset
);
1249 //----------------------------------------------------------------------
1253 #include "UniConversion.h"
1255 // Convert using Scintilla's functions instead of wx's, Scintilla's are more
1256 // forgiving and won't assert...
1258 wxString
stc2wx(const char* str
, size_t len
)
1261 return wxEmptyString
;
1263 size_t wclen
= UCS2Length(str
, len
);
1264 wxWCharBuffer
buffer(wclen
+1);
1266 size_t actualLen
= UCS2FromUTF8(str
, len
, buffer
.data(), wclen
+1);
1267 return wxString(buffer
.data(), actualLen
);
1272 wxString
stc2wx(const char* str
)
1274 return stc2wx(str
, strlen(str
));
1278 const wxWX2MBbuf
wx2stc(const wxString
& str
)
1280 const wchar_t* wcstr
= str
.c_str();
1281 size_t wclen
= str
.length();
1282 size_t len
= UTF8Length(wcstr
, wclen
);
1284 wxCharBuffer
buffer(len
+1);
1285 UTF8FromUCS2(wcstr
, wclen
, buffer
.data(), len
);
1287 // TODO check NULL termination!!