9
9
// Author: Robin Dunn
11
11
// Created: 13-Jan-2000
12
// RCS-ID: $Id: ScintillaWX.cpp 4043 2007-06-02 06:03:13Z rickg22 $
12
// RCS-ID: $Id: ScintillaWX.cpp 6163 2010-02-15 11:15:27Z mortenmacfly $
13
13
// Copyright: (c) 2000 by Total Control Software
14
14
// Licence: wxWindows license
15
15
/////////////////////////////////////////////////////////////////////////////
17
// For compilers that support precompilation, includes "wx.h".
18
#include <wx/wxprec.h>
21
#include <wx/scrolbar.h>
26
#include <wx/clipbrd.h>
27
#include <wx/textbuf.h>
17
28
#include "ScintillaWX.h"
18
//?#include "ExternalLexer.h"
29
#include "wx/wxscintilla.h"
19
30
#include "PlatWX.h"
20
#include "wx/wxscintilla.h"
21
#include <wx/textbuf.h>
31
#include "ExternalLexer.h"
23
#include <wx/msw/private.h> // GetHwndOf()
35
#include <wx/msw/private.h>
26
38
//----------------------------------------------------------------------
29
41
class wxSCITimer : public wxTimer {
31
43
wxSCITimer(ScintillaWX* swx) {
44
56
#if wxUSE_DRAG_AND_DROP
45
57
bool wxSCIDropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data) {
46
return swx->DoDropText(x, y, data);
58
return m_swx->DoDropText(x, y, data);
49
61
wxDragResult wxSCIDropTarget::OnEnter(wxCoord x, wxCoord y, wxDragResult def) {
50
return swx->DoDragEnter(x, y, def);
62
return m_swx->DoDragEnter(x, y, def);
53
65
wxDragResult wxSCIDropTarget::OnDragOver(wxCoord x, wxCoord y, wxDragResult def) {
54
return swx->DoDragOver(x, y, def);
66
return m_swx->DoDragOver(x, y, def);
57
69
void wxSCIDropTarget::OnLeave() {
63
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP
72
#endif // wxUSE_DRAG_AND_DROP
74
//--------------------------------------------------------------------------
64
77
#include <wx/popupwin.h>
65
78
#define wxSCICallTipBase wxPopupWindow
66
#define param2 wxBORDER_NONE // popup's 2nd param is flags
68
#define wxSCICallTipBase wxWindow
69
#define param2 -1 // wxWindow's 2nd param is ID
81
#define wxSCICallTipBase wxFrame
72
85
#include <wx/dcbuffer.h>
74
class wxSCICallTip : public wxSCICallTipBase {
88
class wxSCICallTipContent : public wxPanel {
76
wxSCICallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx)
77
: wxSCICallTipBase(parent, param2),
78
m_ct(ct), m_swx(swx), m_cx(-1), m_cy(-1)
83
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP && defined(__WXGTK__)
84
wxRect rect = GetRect();
87
GetParent()->Refresh(false, &rect);
90
wxSCICallTipContent(wxWindow* parent, CallTip* ct, ScintillaWX* swx)
91
: wxPanel(parent, -1),
94
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
91
97
bool AcceptsFocus() const { return false; }
93
void OnPaint(wxPaintEvent& WXUNUSED(evt)) {
94
wxBufferedPaintDC dc(this);
99
void OnPaint(wxPaintEvent& WXUNUSED(evt))
101
wxAutoBufferedPaintDC dc(this);
95
102
Surface* surfaceWindow = Surface::Allocate();
96
103
surfaceWindow->Init(&dc, m_ct->wDraw.GetID());
97
104
m_ct->PaintCT(surfaceWindow);
99
106
delete surfaceWindow;
102
void OnFocus(wxFocusEvent& event) {
103
GetParent()->SetFocus();
109
void OnFocus(wxFocusEvent& event)
111
GetGrandParent()->SetFocus();
107
void OnLeftDown(wxMouseEvent& event) {
115
void OnLeftDown(wxMouseEvent& event)
108
117
wxPoint pt = event.GetPosition();
109
118
Point p(pt.x, pt.y);
110
119
m_ct->MouseClick(p);
111
120
m_swx->CallTipClick();
114
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP
126
DECLARE_EVENT_TABLE()
130
BEGIN_EVENT_TABLE(wxSCICallTipContent, wxPanel)
131
EVT_PAINT(wxSCICallTipContent::OnPaint)
132
EVT_SET_FOCUS(wxSCICallTipContent::OnFocus)
133
EVT_LEFT_DOWN(wxSCICallTipContent::OnLeftDown)
138
class wxSCICallTip : public wxSCICallTipBase {
140
wxSCICallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx) :
142
wxSCICallTipBase(parent, wxBORDER_NONE),
144
wxSCICallTipBase(parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
146
| wxFRAME_FLOAT_ON_PARENT
153
m_cx(wxDefaultCoord), m_cy(wxDefaultCoord)
155
m_content = new wxSCICallTipContent(this, ct, swx);
159
#if wxUSE_POPUPWIN && defined(__WXGTK__)
160
wxRect rect = GetRect();
163
GetParent()->Refresh(false, &rect);
167
bool AcceptsFocus() const { return false; }
115
169
virtual void DoSetSize(int x, int y,
116
170
int width, int height,
117
int sizeFlags = wxSIZE_AUTO) {
171
int sizeFlags = wxSIZE_AUTO)
173
// convert coords to screen coords since we're a top-level window
174
if (x != wxDefaultCoord) {
120
176
GetParent()->ClientToScreen(&x, NULL);
178
if (y != wxDefaultCoord) {
124
180
GetParent()->ClientToScreen(NULL, &y);
126
182
wxSCICallTipBase::DoSetSize(x, y, width, height, sizeFlags);
184
m_content->SetSize(0, 0, width, height, sizeFlags);
189
virtual bool Show( bool show = true )
191
// Although we're a frame, we always want the parent to be active, so
192
// raise it whenever we get shown.
193
bool rv = wxSCICallTipBase::Show(show);
196
wxTopLevelWindow *frame = wxDynamicCast(
197
wxGetTopLevelParent(GetParent()), wxTopLevelWindow);
130
wxPoint GetMyPosition() {
205
wxPoint GetMyPosition()
131
207
return wxPoint(m_cx, m_cy);
138
DECLARE_EVENT_TABLE()
212
wxSCICallTipContent* m_content;
141
BEGIN_EVENT_TABLE(wxSCICallTip, wxSCICallTipBase)
142
EVT_PAINT(wxSCICallTip::OnPaint)
143
EVT_SET_FOCUS(wxSCICallTip::OnFocus)
144
EVT_LEFT_DOWN(wxSCICallTip::OnLeftDown)
148
217
//----------------------------------------------------------------------
228
321
void ScintillaWX::StartDrag() {
229
322
#if wxUSE_DRAG_AND_DROP
230
wxString dragText = sci2wx(drag.s, drag.len);
323
wxString dragText = sci2wx (drag.s, drag.len);
232
325
// Send an event to allow the drag text to be changed
233
326
wxScintillaEvent evt(wxEVT_SCI_START_DRAG, sci->GetId());
234
evt.SetEventObject(sci);
327
evt.SetEventObject (sci);
235
328
evt.SetDragText(dragText);
236
evt.SetDragAllowMove(true);
237
evt.SetPosition(wxMin(sci->GetSelectionStart(),
238
sci->GetSelectionEnd()));
239
sci->GetEventHandler()->ProcessEvent(evt);
330
evt.SetDragAllowMove(wxDrag_DefaultMove);
332
evt.SetPosition (wxMin(sci->GetSelectionStart(),
333
sci->GetSelectionEnd()));
334
sci->GetEventHandler()->ProcessEvent (evt);
240
337
dragText = evt.GetDragText();
338
dragRectangle = drag.rectangular;
242
339
if (dragText.Length()) {
243
340
wxDropSource source(sci);
244
341
wxTextDataObject data(dragText);
260
358
if (idler.state != on) {
261
359
// connect or disconnect the EVT_IDLE handler
263
sci->Connect(wxID_ANY, wxEVT_IDLE,
264
(wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxScintilla::OnIdle);
361
sci->Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(wxScintilla::OnIdle));
266
sci->Disconnect(wxID_ANY, wxEVT_IDLE,
267
(wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxScintilla::OnIdle);
363
sci->Disconnect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(wxScintilla::OnIdle));
268
364
idler.state = on;
270
366
return idler.state;
425
526
void ScintillaWX::Copy() {
426
if (currentPos != anchor) {
527
if (!SelectionEmpty()) {
427
528
SelectionText st;
428
529
CopySelectionRange(&st);
531
for(int i=0; i<5; i++) {
532
//wxPrintf(wxT("Copying to clipboard %ld\n"), i);
434
542
void ScintillaWX::Paste() {
435
pdoc->BeginUndoAction();
545
SelectionPosition firstPosition = SelectionStart();
546
if(sel.IsRectangular() && !sel.Empty()) {
547
for (size_t i=0; i<sel.Count()-1; i++) {
549
if(firstPosition > SelectionStart())
550
firstPosition = SelectionStart();
436
553
ClearSelection();
438
555
#if wxUSE_DATAOBJ
439
556
wxTextDataObject data;
440
bool gotData = false;
561
bool rectangular = false;
442
563
if (wxTheClipboard->Open()) {
443
564
wxTheClipboard->UsePrimarySelection(false);
444
gotData = wxTheClipboard->GetData(data);
566
// Leave the followig lines that way to enable compilation with GCC 3.3.3
567
wxDataFormat dataFormat(wxString(wxT("application/x-cbrectdata")));
568
wxCustomDataObject selData(dataFormat);
570
bool gotRectData = wxTheClipboard->GetData(selData);
572
if (gotRectData && selData.GetSize()>1) {
573
const char* rectBuf = (const char*)selData.GetData();
574
rectangular = rectBuf[0] == (char)1;
575
len = selData.GetDataSize()-1;
576
char* buffer = new char[len];
577
memcpy (buffer, rectBuf+1, len);
578
textString = sci2wx(buffer, len);
581
bool gotData = wxTheClipboard->GetData(data);
583
textString = wxTextBuffer::Translate (data.GetText(),
584
wxConvertEOLMode(pdoc->eolMode));
587
data.SetText(wxEmptyString); // free the data object content
445
588
wxTheClipboard->Close();
448
wxString text = wxTextBuffer::Translate(data.GetText(),
449
wxConvertEOLMode(pdoc->eolMode));
450
wxWX2MBbuf buf = (wxWX2MBbuf)wx2sci(text);
451
int len = strlen(buf);
452
pdoc->InsertString(currentPos, buf, len);
453
SetEmptySelection(currentPos + len);
591
buf = (wxWX2MBbuf)wx2sci(textString);
594
int caretMain = CurrentPosition();
596
SelectionPosition selStart = sel.Range(sel.Main()).Start();
597
int newLine = pdoc->LineFromPosition (caretMain) + wxCountLines (buf, pdoc->eolMode);
598
int newCol = pdoc->GetColumn(caretMain);
599
PasteRectangular (selStart, buf, len);
600
newPos = pdoc->FindColumn (newLine, newCol);
602
pdoc->InsertString (caretMain, buf, len);
603
newPos = caretMain + len;
605
SetEmptySelection (newPos);
455
606
#endif // wxUSE_DATAOBJ
457
pdoc->EndUndoAction();
463
void ScintillaWX::CopyToClipboard(const SelectionText& st) {
613
void ScintillaWX::CopyToClipboard (const SelectionText& st) {
464
614
#if wxUSE_CLIPBOARD
465
618
if (wxTheClipboard->Open()) {
466
wxTheClipboard->UsePrimarySelection(false);
467
wxString text = wxTextBuffer::Translate(sci2wx(st.s, st.len-1));
468
wxTheClipboard->SetData(new wxTextDataObject(text));
619
wxTheClipboard->UsePrimarySelection (false);
620
wxString text = wxTextBuffer::Translate (sci2wx(st.s, st.len-1));
622
// composite object will hold "plain text" for pasting in other programs and a custom
623
// object for local use that remembers what kind of selection was made (stream or
625
wxDataObjectComposite* obj = new wxDataObjectComposite();
626
wxCustomDataObject* rectData = new wxCustomDataObject (wxDataFormat(wxString(wxT("application/x-cbrectdata"))));
628
char* buffer = new char[st.len+1];
629
buffer[0] = (st.rectangular)? (char)1 : (char)0;
630
memcpy (buffer+1, st.s, st.len);
631
rectData->SetData (st.len+1, buffer);
634
obj->Add (rectData, true);
635
obj->Add (new wxTextDataObject (text));
636
wxTheClipboard->SetData (obj);
469
637
wxTheClipboard->Close();
560
726
bool ScintillaWX::HasCaretSizeChanged() {
562
#if !wxCHECK_VERSION(2, 5, 0)
565
if (( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) )
566
|| (0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight)) {
728
if ( ( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) )
729
|| ( (0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight) ) ) {
574
736
bool ScintillaWX::CreateSystemCaret() {
576
#if !wxCHECK_VERSION(2, 5, 0)
579
738
sysCaretWidth = vs.caretWidth;
580
739
if (0 == sysCaretWidth) {
581
740
sysCaretWidth = 1;
633
787
char* defn = reinterpret_cast<char *>(lParam);
634
788
AutoCompleteCancel();
635
789
pt.y += vs.lineHeight;
636
PRectangle rc = ct.CallTipStart(currentPos, pt,
791
/* This fix will allow you to actually modify the calltip font (it
792
* was hardcoded to STYLE_DEFAULT instead of allowing user to
793
* override it when STYLE_CALLTIP is set). */
794
int ctStyle = ct.UseStyleCallTip() ? STYLE_CALLTIP : STYLE_DEFAULT;
795
PRectangle rc = ct.CallTipStart(sel.MainCaret(), pt,
638
vs.styles[STYLE_DEFAULT].fontName,
639
vs.styles[STYLE_DEFAULT].sizeZoomed,
797
vs.styles[ctStyle].fontName,
798
vs.styles[ctStyle].sizeZoomed,
641
vs.styles[STYLE_DEFAULT].characterSet,
800
vs.styles[ctStyle].characterSet,
643
803
// If the call-tip window would be out of the client
644
804
// space, adjust so it displays above the text.
645
805
PRectangle rcClient = GetClientRectangle();
658
818
ct.wCallTip.Show();
822
case SCI_GETDIRECTFUNCTION:
823
return reinterpret_cast<sptr_t>(DirectFunction);
825
case SCI_GETDIRECTPOINTER:
826
return reinterpret_cast<sptr_t>(this);
663
833
case SCI_LOADLEXERLIBRARY:
664
834
LexerManager::GetInstance()->Load((const char*)lParam);
668
839
return ScintillaBase::WndProc(iMessage, wParam, lParam);
844
sptr_t ScintillaWX::DirectFunction(ScintillaWX *wxsci, unsigned int iMessage, uptr_t wParam, sptr_t lParam)
846
return wxsci->WndProc(iMessage, wParam, lParam);
675
850
//----------------------------------------------------------------------
829
1003
wxTheClipboard->Close();
832
wxString text = wxTextBuffer::Translate(data.GetText(),
833
wxConvertEOLMode(pdoc->eolMode));
1006
wxString text = wxTextBuffer::Translate (data.GetText(),
1007
wxConvertEOLMode(pdoc->eolMode));
1008
data.SetText(wxEmptyString); // free the data object content
834
1009
wxWX2MBbuf buf = (wxWX2MBbuf)wx2sci(text);
835
1010
int len = strlen(buf);
836
pdoc->InsertString(currentPos, buf, len);
837
SetEmptySelection(currentPos + len);
1011
pdoc->InsertString(CurrentPosition(), buf, len);
1012
SetEmptySelection(CurrentPosition() + len);
839
pdoc->EndUndoAction();
876
case WXK_NUMPAD_DOWN: // fall through
877
case WXK_DOWN: key = SCK_DOWN; break;
878
case WXK_NUMPAD_UP: // fall through
879
case WXK_UP: key = SCK_UP; break;
880
case WXK_NUMPAD_LEFT: // fall through
881
case WXK_LEFT: key = SCK_LEFT; break;
882
case WXK_NUMPAD_RIGHT: // fall through
883
case WXK_RIGHT: key = SCK_RIGHT; break;
884
case WXK_NUMPAD_HOME: // fall through
885
case WXK_HOME: key = SCK_HOME; break;
886
case WXK_NUMPAD_END: // fall through
887
case WXK_END: key = SCK_END; break;
1050
case WXK_DOWN: // fall through
1051
case WXK_NUMPAD_DOWN: key = SCK_DOWN; break;
1052
case WXK_UP: // fall through
1053
case WXK_NUMPAD_UP: key = SCK_UP; break;
1054
case WXK_LEFT: // fall through
1055
case WXK_NUMPAD_LEFT: key = SCK_LEFT; break;
1056
case WXK_RIGHT: // fall through
1057
case WXK_NUMPAD_RIGHT: key = SCK_RIGHT; break;
1058
case WXK_HOME: // fall through
1059
case WXK_NUMPAD_HOME: key = SCK_HOME; break;
1060
case WXK_END: // fall through
1061
case WXK_NUMPAD_END: key = SCK_END; break;
888
1062
#if !wxCHECK_VERSION(2, 8, 0)
889
case WXK_PRIOR: // fall through
1063
case WXK_PRIOR: // fall through
890
1064
case WXK_NUMPAD_PRIOR: // fall through
892
1066
case WXK_PAGEUP: // fall through
893
1067
case WXK_NUMPAD_PAGEUP: key = SCK_PRIOR; break;
894
1068
#if !wxCHECK_VERSION(2, 8, 0)
895
case WXK_NEXT: // fall through
1069
case WXK_NEXT: // fall through
896
1070
case WXK_NUMPAD_NEXT: // fall through
898
1072
case WXK_PAGEDOWN: // fall through
1044
1217
HorizontalScrollTo(column * vs.spaceWidth);
1048
void ScintillaWX::ClipChildren(wxDC& dc, PRectangle rect) {
1049
// wxGTK > 2.5 doesn't appear to need this explicit clipping code any longer
1050
#if !wxCHECK_VERSION(2, 5, 0)
1051
wxRegion rgn(wxRectFromPRectangle(rect));
1053
wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1054
rgn.Subtract(childRect);
1056
if (ct.inCallTipMode) {
1057
wxSCICallTip* tip = (wxSCICallTip*)ct.wCallTip.GetID();
1058
wxRect childRect = tip->GetRect();
1059
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP
1060
childRect.SetPosition(tip->GetMyPosition());
1062
rgn.Subtract(childRect);
1065
dc.SetClippingRegion(rgn);
1069
void ScintillaWX::ClipChildren(wxDC& WXUNUSED(dc), PRectangle WXUNUSED(rect)) {
1074
void ScintillaWX::SetUseAntiAliasing(bool useAA) {
1075
vs.extraFontFlag = useAA;
1076
InvalidateStyleRedraw();
1079
bool ScintillaWX::GetUseAntiAliasing() {
1080
return vs.extraFontFlag;
1220
// wxGTK doesn't appear to need this explicit clipping code any longer, but I
1221
// will leave it here commented out for a while just in case...
1222
void ScintillaWX::ClipChildren(wxDC& WXUNUSED(dc), PRectangle WXUNUSED(rect))
1224
// wxRegion rgn(wxRectFromPRectangle(rect));
1225
// if (ac.Active()) {
1226
// wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1227
// rgn.Subtract(childRect);
1229
// if (ct.inCallTipMode) {
1230
// wxSCICallTip* tip = (wxSCICallTip*)ct.wCallTip.GetID();
1231
// wxRect childRect = tip->GetRect();
1232
// #if wxUSE_POPUPWIN
1233
// childRect.SetPosition(tip->GetMyPosition());
1235
// rgn.Subtract(childRect);
1237
// dc.SetClippingRegion(rgn);
1083
1241
//----------------------------------------------------------------------
1084
1242
//----------------------------------------------------------------------