~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

Viewing changes to sdk/wxscintilla/src/ScintillaWX.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-07-29 19:42:47 UTC
  • mfrom: (1.1.9 upstream) (18.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100729194247-cuibfk03wog33nxq
Tags: 2.6.0.4189~dfsg-1
* New upstream release.
* Bump Standards.
* Refresh patches.
* Add license information about files under ./Debugger/

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
class wxSCITimer : public wxTimer {
34
34
public:
35
 
    wxSCITimer(ScintillaWX* swx) {
36
 
        this->swx = swx;
37
 
    }
 
35
        wxSCITimer(ScintillaWX* swx) {
 
36
                this->swx = swx;
 
37
        }
38
38
 
39
 
    void Notify() {
40
 
        swx->DoTick();
41
 
    }
 
39
        void Notify() {
 
40
                swx->DoTick();
 
41
        }
42
42
 
43
43
private:
44
 
    ScintillaWX* swx;
 
44
        ScintillaWX* swx;
45
45
};
46
46
 
47
47
 
48
48
#if wxUSE_DRAG_AND_DROP
49
49
class wxStartDragTimer : public wxTimer {
50
50
public:
51
 
    wxStartDragTimer(ScintillaWX* swx) {
52
 
        this->swx = swx;
53
 
    }
 
51
        wxStartDragTimer(ScintillaWX* swx) {
 
52
                this->swx = swx;
 
53
        }
54
54
 
55
 
    void Notify() {
56
 
        swx->DoStartDrag();
57
 
    }
 
55
        void Notify() {
 
56
                swx->DoStartDrag();
 
57
        }
58
58
 
59
59
private:
60
 
    ScintillaWX* swx;
 
60
        ScintillaWX* swx;
61
61
};
62
62
 
63
63
bool wxSCIDropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data) {
64
 
    return swx->DoDropText(x, y, data);
 
64
        return swx->DoDropText(x, y, data);
65
65
}
66
66
 
67
67
wxDragResult  wxSCIDropTarget::OnEnter(wxCoord x, wxCoord y, wxDragResult def) {
68
 
    return swx->DoDragEnter(x, y, def);
 
68
        return swx->DoDragEnter(x, y, def);
69
69
}
70
70
 
71
71
wxDragResult  wxSCIDropTarget::OnDragOver(wxCoord x, wxCoord y, wxDragResult def) {
72
 
    return swx->DoDragOver(x, y, def);
 
72
        return swx->DoDragOver(x, y, def);
73
73
}
74
74
 
75
75
void  wxSCIDropTarget::OnLeave() {
76
 
    swx->DoDragLeave();
 
76
        swx->DoDragLeave();
77
77
}
78
78
#endif
79
79
 
91
91
 
92
92
class wxSCICallTip : public wxSCICallTipBase {
93
93
public:
94
 
    wxSCICallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx)
95
 
        : wxSCICallTipBase(parent, param2),
96
 
          m_ct(ct), m_swx(swx), m_cx(-1), m_cy(-1)
97
 
        {
98
 
        }
 
94
        wxSCICallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx)
 
95
                : wxSCICallTipBase(parent, param2),
 
96
                  m_ct(ct), m_swx(swx), m_cx(-1), m_cy(-1) {
 
97
        }
99
98
 
100
 
    ~wxSCICallTip() {
 
99
        ~wxSCICallTip() {
101
100
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP && defined(__WXGTK__)
102
 
        wxRect rect = GetRect();
103
 
        rect.x = m_cx;
104
 
        rect.y = m_cy;
105
 
        GetParent()->Refresh(false, &rect);
 
101
                wxRect rect = GetRect();
 
102
                rect.x = m_cx;
 
103
                rect.y = m_cy;
 
104
                GetParent()->Refresh(false, &rect);
106
105
#endif
107
 
    }
108
 
 
109
 
    bool AcceptsFocus() const { return false; }
110
 
 
111
 
    void OnPaint(wxPaintEvent& WXUNUSED(evt)) {
112
 
        wxBufferedPaintDC dc(this);
113
 
        Surface* surfaceWindow = Surface::Allocate();
114
 
        surfaceWindow->Init(&dc, m_ct->wDraw.GetID());
115
 
        m_ct->PaintCT(surfaceWindow);
116
 
        surfaceWindow->Release();
117
 
        delete surfaceWindow;
118
 
    }
119
 
 
120
 
    void OnFocus(wxFocusEvent& event) {
121
 
        GetParent()->SetFocus();
122
 
        event.Skip();
123
 
    }
124
 
 
125
 
    void OnLeftDown(wxMouseEvent& event) {
126
 
        wxPoint pt = event.GetPosition();
127
 
        Point p(pt.x, pt.y);
128
 
        m_ct->MouseClick(p);
129
 
        m_swx->CallTipClick();
130
 
    }
 
106
        }
 
107
 
 
108
        bool AcceptsFocus() const {
 
109
                return false;
 
110
        }
 
111
 
 
112
        void OnPaint(wxPaintEvent& WXUNUSED(evt)) {
 
113
                wxBufferedPaintDC dc(this);
 
114
                Surface* surfaceWindow = Surface::Allocate();
 
115
                surfaceWindow->Init(&dc, m_ct->wDraw.GetID());
 
116
                m_ct->PaintCT(surfaceWindow);
 
117
                surfaceWindow->Release();
 
118
                delete surfaceWindow;
 
119
        }
 
120
 
 
121
        void OnFocus(wxFocusEvent& event) {
 
122
                GetParent()->SetFocus();
 
123
                event.Skip();
 
124
        }
 
125
 
 
126
        void OnLeftDown(wxMouseEvent& event) {
 
127
                wxPoint pt = event.GetPosition();
 
128
                Point p(pt.x, pt.y);
 
129
                m_ct->MouseClick(p);
 
130
                m_swx->CallTipClick();
 
131
        }
131
132
 
132
133
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP
133
 
    virtual void DoSetSize(int x, int y,
134
 
                           int width, int height,
135
 
                           int sizeFlags = wxSIZE_AUTO) {
136
 
        if (x != -1) {
137
 
            m_cx = x;
138
 
            GetParent()->ClientToScreen(&x, NULL);
139
 
        }
140
 
        if (y != -1) {
141
 
            m_cy = y;
142
 
            GetParent()->ClientToScreen(NULL, &y);
143
 
        }
144
 
        wxSCICallTipBase::DoSetSize(x, y, width, height, sizeFlags);
145
 
    }
 
134
        virtual void DoSetSize(int x, int y,
 
135
                               int width, int height,
 
136
                               int sizeFlags = wxSIZE_AUTO) {
 
137
                if (x != -1) {
 
138
                        m_cx = x;
 
139
                        GetParent()->ClientToScreen(&x, NULL);
 
140
                }
 
141
                if (y != -1) {
 
142
                        m_cy = y;
 
143
                        GetParent()->ClientToScreen(NULL, &y);
 
144
                }
 
145
                wxSCICallTipBase::DoSetSize(x, y, width, height, sizeFlags);
 
146
        }
146
147
#endif
147
148
 
148
 
    wxPoint GetMyPosition() {
149
 
        return wxPoint(m_cx, m_cy);
150
 
    }
 
149
        wxPoint GetMyPosition() {
 
150
                return wxPoint(m_cx, m_cy);
 
151
        }
151
152
 
152
153
private:
153
 
    CallTip*      m_ct;
154
 
    ScintillaWX*  m_swx;
155
 
    int           m_cx, m_cy;
156
 
    DECLARE_EVENT_TABLE()
 
154
        CallTip*      m_ct;
 
155
        ScintillaWX*  m_swx;
 
156
        int           m_cx, m_cy;
 
157
        DECLARE_EVENT_TABLE()
157
158
};
158
159
 
159
160
BEGIN_EVENT_TABLE(wxSCICallTip, wxSCICallTipBase)
160
 
    EVT_PAINT(wxSCICallTip::OnPaint)
161
 
    EVT_SET_FOCUS(wxSCICallTip::OnFocus)
162
 
    EVT_LEFT_DOWN(wxSCICallTip::OnLeftDown)
 
161
        EVT_PAINT(wxSCICallTip::OnPaint)
 
162
        EVT_SET_FOCUS(wxSCICallTip::OnFocus)
 
163
        EVT_LEFT_DOWN(wxSCICallTip::OnLeftDown)
163
164
END_EVENT_TABLE()
164
165
 
165
166
 
166
167
//----------------------------------------------------------------------
167
168
 
168
169
#if wxUSE_DATAOBJ
169
 
static wxTextFileType wxConvertEOLMode(int scintillaMode)
170
 
{
171
 
    wxTextFileType type;
172
 
 
173
 
    switch (scintillaMode) {
174
 
        case wxSCI_EOL_CRLF:
175
 
            type = wxTextFileType_Dos;
176
 
            break;
177
 
 
178
 
        case wxSCI_EOL_CR:
179
 
            type = wxTextFileType_Mac;
180
 
            break;
181
 
 
182
 
        case wxSCI_EOL_LF:
183
 
            type = wxTextFileType_Unix;
184
 
            break;
185
 
 
186
 
        default:
187
 
            type = wxTextBuffer::typeDefault;
188
 
            break;
189
 
    }
190
 
    return type;
 
170
static wxTextFileType wxConvertEOLMode(int scintillaMode) {
 
171
        wxTextFileType type;
 
172
 
 
173
        switch (scintillaMode) {
 
174
        case wxSCI_EOL_CRLF:
 
175
                type = wxTextFileType_Dos;
 
176
                break;
 
177
 
 
178
        case wxSCI_EOL_CR:
 
179
                type = wxTextFileType_Mac;
 
180
                break;
 
181
 
 
182
        case wxSCI_EOL_LF:
 
183
                type = wxTextFileType_Unix;
 
184
                break;
 
185
 
 
186
        default:
 
187
                type = wxTextBuffer::typeDefault;
 
188
                break;
 
189
        }
 
190
        return type;
191
191
}
192
192
#endif // wxUSE_DATAOBJ
193
193
 
194
194
 
195
 
static int wxCountLines(const char* text, int scintillaMode)
196
 
{
197
 
    char eolchar;
198
 
 
199
 
    switch (scintillaMode) {
200
 
        case wxSCI_EOL_CRLF:
201
 
        case wxSCI_EOL_LF:
202
 
            eolchar = '\n';
203
 
            break;
204
 
        case wxSCI_EOL_CR:
205
 
            eolchar = '\r';
206
 
            break;
207
 
        default:
208
 
            return 0;
209
 
    }
210
 
 
211
 
    int count = 0;
212
 
    int i     = 0;
213
 
    while (text[i] != 0) {
214
 
        if (text[i] == eolchar) {
215
 
            count++;
216
 
        }
217
 
        i++;
218
 
    }
219
 
 
220
 
    return count;
 
195
static int wxCountLines(const char* text, int scintillaMode) {
 
196
        char eolchar;
 
197
 
 
198
        switch (scintillaMode) {
 
199
        case wxSCI_EOL_CRLF:
 
200
        case wxSCI_EOL_LF:
 
201
                eolchar = '\n';
 
202
                break;
 
203
        case wxSCI_EOL_CR:
 
204
                eolchar = '\r';
 
205
                break;
 
206
        default:
 
207
                return 0;
 
208
        }
 
209
 
 
210
        int count = 0;
 
211
        int i     = 0;
 
212
        while (text[i] != 0) {
 
213
                if (text[i] == eolchar) {
 
214
                        count++;
 
215
                }
 
216
                i++;
 
217
        }
 
218
 
 
219
        return count;
221
220
}
222
221
 
223
222
//----------------------------------------------------------------------
225
224
 
226
225
 
227
226
ScintillaWX::ScintillaWX(wxScintilla* win) {
228
 
    capturedMouse = false;
229
 
    focusEvent = false;
230
 
    wMain = win;
231
 
    sci   = win;
232
 
    wheelRotation = 0;
233
 
    Initialise();
 
227
        capturedMouse = false;
 
228
        focusEvent = false;
 
229
        wMain = win;
 
230
        sci   = win;
 
231
        wheelRotation = 0;
 
232
        Initialise();
234
233
#ifdef __WXMSW__
235
234
#if wxCHECK_VERSION(2, 5, 0)
236
 
    sysCaretBitmap = 0;
237
 
    sysCaretWidth = 0;
238
 
    sysCaretHeight = 0;
 
235
        sysCaretBitmap = 0;
 
236
        sysCaretWidth = 0;
 
237
        sysCaretHeight = 0;
239
238
#endif
240
239
#endif
241
240
#if wxUSE_DRAG_AND_DROP
242
 
    startDragTimer = new wxStartDragTimer(this);
 
241
        startDragTimer = new wxStartDragTimer(this);
243
242
#endif
244
243
}
245
244
 
246
245
 
247
246
ScintillaWX::~ScintillaWX() {
248
247
#if wxUSE_DRAG_AND_DROP
249
 
    delete startDragTimer;
 
248
        delete startDragTimer;
250
249
#endif
251
 
    Finalise();
 
250
        Finalise();
252
251
}
253
252
 
254
253
//----------------------------------------------------------------------
256
255
 
257
256
 
258
257
void ScintillaWX::Initialise() {
259
 
    //ScintillaBase::Initialise();
 
258
        //ScintillaBase::Initialise();
260
259
#if wxUSE_DRAG_AND_DROP
261
 
    dropTarget = new wxSCIDropTarget;
262
 
    dropTarget->SetScintilla(this);
263
 
    sci->SetDropTarget(dropTarget);
264
 
    dragRectangle = false;
 
260
        dropTarget = new wxSCIDropTarget;
 
261
        dropTarget->SetScintilla(this);
 
262
        sci->SetDropTarget(dropTarget);
 
263
        dragRectangle = false;
265
264
#endif
266
265
#ifdef __WXMAC__
267
 
    vs.extraFontFlag = false;  // UseAntiAliasing
 
266
        vs.extraFontFlag = false;  // UseAntiAliasing
268
267
#else
269
 
    vs.extraFontFlag = true;   // UseAntiAliasing
 
268
        vs.extraFontFlag = true;   // UseAntiAliasing
270
269
#endif
271
270
}
272
271
 
273
272
 
274
273
void ScintillaWX::Finalise() {
275
 
    ScintillaBase::Finalise();
276
 
    SetTicking(false);
277
 
    SetIdle(false);
278
 
    DestroySystemCaret();
 
274
        ScintillaBase::Finalise();
 
275
        SetTicking(false);
 
276
        SetIdle(false);
 
277
        DestroySystemCaret();
279
278
}
280
279
 
281
280
 
285
284
        // For recent wxGTKs, DnD won't work if we delay with the timer, so go there direct
286
285
        DoStartDrag();
287
286
#else
288
 
     startDragTimer->Start (200, true);
 
287
        startDragTimer->Start (200, true);
289
288
#endif // wxVERSION_NUMBER >= 2701 && defined(__WXGTK20__)
290
289
#endif
291
290
}
292
291
 
293
292
void ScintillaWX::DoStartDrag() {
294
293
#if wxUSE_DRAG_AND_DROP
295
 
    wxString dragText = sci2wx (drag.s, drag.len);
 
294
        wxString dragText = sci2wx (drag.s, drag.len);
296
295
 
297
 
    // Send an event to allow the drag text to be changed
298
 
    wxScintillaEvent evt(wxEVT_SCI_START_DRAG, sci->GetId());
299
 
    evt.SetEventObject (sci);
300
 
    evt.SetDragText (dragText);
301
 
    evt.SetDragAllowMove (true);
302
 
    evt.SetPosition (wxMin(sci->GetSelectionStart(), sci->GetSelectionEnd()));
303
 
    sci->GetEventHandler()->ProcessEvent (evt);
 
296
        // Send an event to allow the drag text to be changed
 
297
        wxScintillaEvent evt(wxEVT_SCI_START_DRAG, sci->GetId());
 
298
        evt.SetEventObject (sci);
 
299
        evt.SetDragText (dragText);
 
300
        evt.SetDragAllowMove (true);
 
301
        evt.SetPosition (wxMin(sci->GetSelectionStart(), sci->GetSelectionEnd()));
 
302
        sci->GetEventHandler()->ProcessEvent (evt);
304
303
 
305
304
        pdoc->BeginUndoAction();
306
 
    dragText = evt.GetDragText();
307
 
    dragRectangle = drag.rectangular;
308
 
    if (dragText.Length()) {
309
 
        wxDropSource source(sci);
310
 
        wxTextDataObject data(dragText);
311
 
        source.SetData(data);
 
305
        dragText = evt.GetDragText();
 
306
        dragRectangle = drag.rectangular;
 
307
        if (dragText.Length()) {
 
308
                wxDropSource source(sci);
 
309
                wxTextDataObject data(dragText);
 
310
                source.SetData(data);
312
311
 
313
 
        inDragDrop = ddDragging;
314
 
        source.DoDragDrop(wxDrag_DefaultMove);
315
 
        inDragDrop = ddNone;
316
 
        SetDragPosition (SelectionPosition(invalidPosition));
317
 
    }
 
312
                inDragDrop = ddDragging;
 
313
                source.DoDragDrop(wxDrag_DefaultMove);
 
314
                inDragDrop = ddNone;
 
315
                SetDragPosition (SelectionPosition(invalidPosition));
 
316
        }
318
317
        pdoc->EndUndoAction();
319
318
#endif
320
319
}
321
320
 
322
321
 
323
322
bool ScintillaWX::SetIdle(bool on) {
324
 
    if (idler.state != on) {
325
 
        // connect or disconnect the EVT_IDLE handler
326
 
        if (on)
327
 
            sci->Connect(wxID_ANY, wxEVT_IDLE,
328
 
                         (wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxScintilla::OnIdle);
329
 
        else
330
 
            sci->Disconnect(wxID_ANY, wxEVT_IDLE,
331
 
                            (wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxScintilla::OnIdle);
332
 
        idler.state = on;
333
 
    }
334
 
    return idler.state;
 
323
        if (idler.state != on) {
 
324
                // connect or disconnect the EVT_IDLE handler
 
325
                if (on)
 
326
                        sci->Connect(wxID_ANY, wxEVT_IDLE,
 
327
                                     (wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxScintilla::OnIdle);
 
328
                else
 
329
                        sci->Disconnect(wxID_ANY, wxEVT_IDLE,
 
330
                                        (wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxScintilla::OnIdle);
 
331
                idler.state = on;
 
332
        }
 
333
        return idler.state;
335
334
}
336
335
 
337
336
 
338
337
void ScintillaWX::SetTicking(bool on) {
339
 
    wxSCITimer* stiTimer;
340
 
    if (timer.ticking != on) {
341
 
        timer.ticking = on;
342
 
        if (timer.ticking) {
343
 
            stiTimer = new wxSCITimer(this);
344
 
            stiTimer->Start(timer.tickSize);
345
 
            timer.tickerID = stiTimer;
346
 
        } else {
347
 
            stiTimer = (wxSCITimer*)timer.tickerID;
348
 
            stiTimer->Stop();
349
 
            delete stiTimer;
350
 
            timer.tickerID = 0;
351
 
        }
352
 
    }
353
 
    timer.ticksToWait = caret.period;
 
338
        wxSCITimer* stiTimer;
 
339
        if (timer.ticking != on) {
 
340
                timer.ticking = on;
 
341
                if (timer.ticking) {
 
342
                        stiTimer = new wxSCITimer(this);
 
343
                        stiTimer->Start(timer.tickSize);
 
344
                        timer.tickerID = stiTimer;
 
345
                } else {
 
346
                        stiTimer = (wxSCITimer*)timer.tickerID;
 
347
                        stiTimer->Stop();
 
348
                        delete stiTimer;
 
349
                        timer.tickerID = 0;
 
350
                }
 
351
        }
 
352
        timer.ticksToWait = caret.period;
354
353
}
355
354
 
356
355
 
357
356
void ScintillaWX::SetMouseCapture(bool on) {
358
 
    if (mouseDownCaptures) {
359
 
        if (on && !capturedMouse)
360
 
            sci->CaptureMouse();
361
 
        else if (!on && capturedMouse && sci->HasCapture())
362
 
            sci->ReleaseMouse();
363
 
        capturedMouse = on;
364
 
    }
 
357
        if (mouseDownCaptures) {
 
358
                if (on && !capturedMouse)
 
359
                        sci->CaptureMouse();
 
360
                else if (!on && capturedMouse && sci->HasCapture())
 
361
                        sci->ReleaseMouse();
 
362
                capturedMouse = on;
 
363
        }
365
364
}
366
365
 
367
366
 
368
367
bool ScintillaWX::HaveMouseCapture() {
369
 
    return capturedMouse;
 
368
        return capturedMouse;
370
369
}
371
370
 
372
371
 
373
372
void ScintillaWX::ScrollText(int linesToMove) {
374
 
    int dy = vs.lineHeight * (linesToMove);
375
 
    sci->ScrollWindow(0, dy);
376
 
    sci->Update();
 
373
        int dy = vs.lineHeight * (linesToMove);
 
374
        sci->ScrollWindow(0, dy);
 
375
        sci->Update();
377
376
}
378
377
 
379
378
void ScintillaWX::SetVerticalScrollPos() {
380
 
    if (sci->m_vScrollBar == NULL) {  // Use built-in scrollbar
381
 
        sci->SetScrollPos(wxVERTICAL, topLine);
382
 
    }
383
 
    else { // otherwise use the one that's been given to us
384
 
        sci->m_vScrollBar->SetThumbPosition(topLine);
385
 
    }
 
379
        if (sci->m_vScrollBar == NULL) {  // Use built-in scrollbar
 
380
                sci->SetScrollPos(wxVERTICAL, topLine);
 
381
        } else { // otherwise use the one that's been given to us
 
382
                sci->m_vScrollBar->SetThumbPosition(topLine);
 
383
        }
386
384
}
387
385
 
388
386
void ScintillaWX::SetHorizontalScrollPos() {
389
 
    if (sci->m_hScrollBar == NULL) {  // Use built-in scrollbar
390
 
        sci->SetScrollPos(wxHORIZONTAL, xOffset);
391
 
    }
392
 
    else { // otherwise use the one that's been given to us
393
 
        sci->m_hScrollBar->SetThumbPosition(xOffset);
394
 
    }
 
387
        if (sci->m_hScrollBar == NULL) {  // Use built-in scrollbar
 
388
                sci->SetScrollPos(wxHORIZONTAL, xOffset);
 
389
        } else { // otherwise use the one that's been given to us
 
390
                sci->m_hScrollBar->SetThumbPosition(xOffset);
 
391
        }
395
392
}
396
393
 
397
394
 
398
395
const int H_SCROLL_STEP = 20;
399
396
 
400
397
bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) {
401
 
    bool modified = false;
402
 
 
403
 
    int vertEnd = nMax;
404
 
    if (!verticalScrollBarVisible)
405
 
        vertEnd = 0;
406
 
 
407
 
    // Check the vertical scrollbar
408
 
    if (sci->m_vScrollBar == NULL) {  // Use built-in scrollbar
409
 
        int  sbMax    = sci->GetScrollRange(wxVERTICAL);
410
 
        int  sbThumb  = sci->GetScrollThumb(wxVERTICAL);
411
 
        int  sbPos    = sci->GetScrollPos(wxVERTICAL);
412
 
        if (sbMax != vertEnd || sbThumb != nPage) {
413
 
            sci->SetScrollbar(wxVERTICAL, sbPos, nPage, vertEnd+1);
414
 
            modified = true;
415
 
        }
416
 
    }
417
 
    else { // otherwise use the one that's been given to us
418
 
        int  sbMax    = sci->m_vScrollBar->GetRange();
419
 
        int  sbPage   = sci->m_vScrollBar->GetPageSize();
420
 
        int  sbPos    = sci->m_vScrollBar->GetThumbPosition();
421
 
        if (sbMax != vertEnd || sbPage != nPage) {
422
 
            sci->m_vScrollBar->SetScrollbar(sbPos, nPage, vertEnd+1, nPage);
423
 
            modified = true;
424
 
        }
425
 
    }
426
 
 
427
 
 
428
 
    // Check the horizontal scrollbar
429
 
    PRectangle rcText = GetTextRectangle();
430
 
    int horizEnd = scrollWidth;
431
 
    if (horizEnd < 0)
432
 
        horizEnd = 0;
433
 
    if (!horizontalScrollBarVisible || (wrapState != eWrapNone))
434
 
        horizEnd = 0;
435
 
    int pageWidth = rcText.Width();
436
 
 
437
 
    if (sci->m_hScrollBar == NULL) {  // Use built-in scrollbar
438
 
        int sbMax    = sci->GetScrollRange(wxHORIZONTAL);
439
 
        int sbThumb  = sci->GetScrollThumb(wxHORIZONTAL);
440
 
        int sbPos    = sci->GetScrollPos(wxHORIZONTAL);
441
 
        if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
442
 
            sci->SetScrollbar(wxHORIZONTAL, sbPos, pageWidth, horizEnd);
443
 
            modified = true;
444
 
            if (scrollWidth < pageWidth) {
445
 
                HorizontalScrollTo(0);
446
 
            }
447
 
        }
448
 
    }
449
 
    else { // otherwise use the one that's been given to us
450
 
        int sbMax    = sci->m_hScrollBar->GetRange();
451
 
        int sbThumb  = sci->m_hScrollBar->GetPageSize();
452
 
        int sbPos    = sci->m_hScrollBar->GetThumbPosition();
453
 
        if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
454
 
            sci->m_hScrollBar->SetScrollbar(sbPos, pageWidth, horizEnd, pageWidth);
455
 
            modified = true;
456
 
            if (scrollWidth < pageWidth) {
457
 
                HorizontalScrollTo(0);
458
 
            }
459
 
        }
460
 
    }
461
 
 
462
 
    return modified;
 
398
        bool modified = false;
 
399
 
 
400
        int vertEnd = nMax;
 
401
        if (!verticalScrollBarVisible)
 
402
                vertEnd = 0;
 
403
 
 
404
        // Check the vertical scrollbar
 
405
        if (sci->m_vScrollBar == NULL) {  // Use built-in scrollbar
 
406
                int  sbMax    = sci->GetScrollRange(wxVERTICAL);
 
407
                int  sbThumb  = sci->GetScrollThumb(wxVERTICAL);
 
408
                int  sbPos    = sci->GetScrollPos(wxVERTICAL);
 
409
                if (sbMax != vertEnd || sbThumb != nPage) {
 
410
                        sci->SetScrollbar(wxVERTICAL, sbPos, nPage, vertEnd+1);
 
411
                        modified = true;
 
412
                }
 
413
        } else { // otherwise use the one that's been given to us
 
414
                int  sbMax    = sci->m_vScrollBar->GetRange();
 
415
                int  sbPage   = sci->m_vScrollBar->GetPageSize();
 
416
                int  sbPos    = sci->m_vScrollBar->GetThumbPosition();
 
417
                if (sbMax != vertEnd || sbPage != nPage) {
 
418
                        sci->m_vScrollBar->SetScrollbar(sbPos, nPage, vertEnd+1, nPage);
 
419
                        modified = true;
 
420
                }
 
421
        }
 
422
 
 
423
 
 
424
        // Check the horizontal scrollbar
 
425
        PRectangle rcText = GetTextRectangle();
 
426
        int horizEnd = scrollWidth;
 
427
        if (horizEnd < 0)
 
428
                horizEnd = 0;
 
429
        if (!horizontalScrollBarVisible || (wrapState != eWrapNone))
 
430
                horizEnd = 0;
 
431
        int pageWidth = rcText.Width();
 
432
 
 
433
        if (sci->m_hScrollBar == NULL) {  // Use built-in scrollbar
 
434
                int sbMax    = sci->GetScrollRange(wxHORIZONTAL);
 
435
                int sbThumb  = sci->GetScrollThumb(wxHORIZONTAL);
 
436
                int sbPos    = sci->GetScrollPos(wxHORIZONTAL);
 
437
                if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
 
438
                        sci->SetScrollbar(wxHORIZONTAL, sbPos, pageWidth, horizEnd);
 
439
                        modified = true;
 
440
                        if (scrollWidth < pageWidth) {
 
441
                                HorizontalScrollTo(0);
 
442
                        }
 
443
                }
 
444
        } else { // otherwise use the one that's been given to us
 
445
                int sbMax    = sci->m_hScrollBar->GetRange();
 
446
                int sbThumb  = sci->m_hScrollBar->GetPageSize();
 
447
                int sbPos    = sci->m_hScrollBar->GetThumbPosition();
 
448
                if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
 
449
                        sci->m_hScrollBar->SetScrollbar(sbPos, pageWidth, horizEnd, pageWidth);
 
450
                        modified = true;
 
451
                        if (scrollWidth < pageWidth) {
 
452
                                HorizontalScrollTo(0);
 
453
                        }
 
454
                }
 
455
        }
 
456
 
 
457
        return modified;
463
458
}
464
459
 
465
460
 
466
461
void ScintillaWX::NotifyChange() {
467
 
    sci->NotifyChange();
 
462
        sci->NotifyChange();
468
463
}
469
464
 
470
465
 
471
466
void ScintillaWX::NotifyParent(SCNotification scn) {
472
 
    sci->NotifyParent(&scn);
 
467
        sci->NotifyParent(&scn);
473
468
}
474
469
 
475
470
 
478
473
// a side effect that the AutoComp will also not be destroyed when switching
479
474
// to another window, but I think that is okay.
480
475
void ScintillaWX::CancelModes() {
481
 
    if (! focusEvent)
482
 
        AutoCompleteCancel();
483
 
    ct.CallTipCancel();
484
 
    Editor::CancelModes();
 
476
        if (! focusEvent)
 
477
                AutoCompleteCancel();
 
478
        ct.CallTipCancel();
 
479
        Editor::CancelModes();
485
480
}
486
481
 
487
482
 
488
483
void ScintillaWX::Copy() {
489
 
    if ( !sel.Empty() ) {
490
 
        SelectionText st;
491
 
        CopySelectionRange(&st);
 
484
        if ( !sel.Empty() ) {
 
485
                SelectionText st;
 
486
                CopySelectionRange(&st);
492
487
#ifdef __WXGTK__
493
488
                for(int i=0; i<5; i++) {
494
489
                        //wxPrintf(wxT("Copying to clipboard %ld\n"), i);
495
 
                CopyToClipboard(st);
 
490
                        CopyToClipboard(st);
496
491
                }
497
492
#else
498
 
        CopyToClipboard(st);
 
493
                CopyToClipboard(st);
499
494
#endif
500
 
    }
 
495
        }
501
496
}
502
497
 
503
498
 
504
499
void ScintillaWX::Paste() {
505
 
    pdoc->BeginUndoAction();
506
 
    ClearSelection();
 
500
        pdoc->BeginUndoAction();
 
501
        ClearSelection();
507
502
 
508
503
#if wxUSE_DATAOBJ
509
 
    wxTextDataObject data;
510
 
    wxString textString;
511
 
 
512
 
    wxWX2MBbuf buf;
513
 
    int   len  = 0;
514
 
    bool  rectangular = false;
515
 
 
516
 
        wxTheClipboard->UsePrimarySelection(false);
517
 
    if (wxTheClipboard->Open()) {
518
 
        wxCustomDataObject selData(wxDataFormat(wxString(wxT("application/x-cbrectdata"))));
519
 
        bool gotRectData = wxTheClipboard->GetData(selData);
520
 
 
521
 
        if (gotRectData && selData.GetSize()>1) {
522
 
            const char* rectBuf = (const char*)selData.GetData();
523
 
            rectangular = rectBuf[0] == (char)1;
524
 
            len = selData.GetDataSize()-1;
525
 
            char* buffer = new char[len];
526
 
            memcpy (buffer, rectBuf+1, len);
527
 
            textString = sci2wx(buffer, len);
528
 
            delete [] buffer;
529
 
        } else {
530
 
            bool gotData = wxTheClipboard->GetData(data);
531
 
            if (gotData) {
532
 
                textString = wxTextBuffer::Translate (data.GetText(),
533
 
                                                      wxConvertEOLMode(pdoc->eolMode));
534
 
            }
535
 
        }
536
 
        data.SetText(wxEmptyString); // free the data object content
537
 
        wxTheClipboard->Close();
538
 
    }
539
 
 
540
 
    buf = (wxWX2MBbuf)wx2sci(textString);
541
 
    len  = strlen(buf);
542
 
    int newPos = 0;
543
 
    int caretMain = sel.MainCaret();
544
 
    if (rectangular) {
545
 
        SelectionPosition selStart = sel.Range(sel.Main()).Start();
546
 
        int newLine = pdoc->LineFromPosition (caretMain) + wxCountLines (buf, pdoc->eolMode);
547
 
        int newCol = pdoc->GetColumn(caretMain);
548
 
        PasteRectangular (selStart, buf, len);
549
 
        newPos = pdoc->FindColumn (newLine, newCol);
550
 
    } else {
551
 
        pdoc->InsertString (caretMain, buf, len);
552
 
        newPos = caretMain + len;
553
 
    }
554
 
    SetEmptySelection (newPos);
 
504
        wxTextDataObject data;
 
505
        wxString textString;
 
506
 
 
507
        wxWX2MBbuf buf;
 
508
        int   len  = 0;
 
509
        bool  rectangular = false;
 
510
 
 
511
        wxTheClipboard->UsePrimarySelection(false);
 
512
        if (wxTheClipboard->Open()) {
 
513
                wxCustomDataObject selData(wxDataFormat(wxString(wxT("application/x-cbrectdata"))));
 
514
                bool gotRectData = wxTheClipboard->GetData(selData);
 
515
 
 
516
                if (gotRectData && selData.GetSize()>1) {
 
517
                        const char* rectBuf = (const char*)selData.GetData();
 
518
                        rectangular = rectBuf[0] == (char)1;
 
519
                        len = selData.GetDataSize()-1;
 
520
                        char* buffer = new char[len];
 
521
                        memcpy (buffer, rectBuf+1, len);
 
522
                        textString = sci2wx(buffer, len);
 
523
                        delete [] buffer;
 
524
                } else {
 
525
                        bool gotData = wxTheClipboard->GetData(data);
 
526
                        if (gotData) {
 
527
                                textString = wxTextBuffer::Translate (data.GetText(),
 
528
                                                                      wxConvertEOLMode(pdoc->eolMode));
 
529
                        }
 
530
                }
 
531
                data.SetText(wxEmptyString); // free the data object content
 
532
                wxTheClipboard->Close();
 
533
        }
 
534
 
 
535
        // Check to see if the Copy() command inserted a '\r\n' at the begining of the textString
 
536
        bool allowCopyLines(false);
 
537
 
 
538
        buf = (wxWX2MBbuf)wx2sci(textString);
 
539
        len  = strlen(buf);
 
540
 
 
541
        // Eran: Allow copy-line to be inserted at the begining of the next line instead
 
542
        // of at the current caret position
 
543
        if(len > 0 && buf.data()[len-1] == '\n') {
 
544
                allowCopyLines = true;
 
545
        }
 
546
 
 
547
        int newPos = 0;
 
548
        int caretMain = sel.MainCaret();
 
549
        if (rectangular) {
 
550
                SelectionPosition selStart = sel.Range(sel.Main()).Start();
 
551
                int newLine = pdoc->LineFromPosition (caretMain) + wxCountLines (buf, pdoc->eolMode);
 
552
                int newCol = pdoc->GetColumn(caretMain);
 
553
                PasteRectangular (selStart, buf, len);
 
554
                newPos = pdoc->FindColumn (newLine, newCol);
 
555
        } else {
 
556
                bool allowCopyLineSuccess(false);
 
557
                if(allowCopyLines) {
 
558
                        // copied text ends with \r\n OR \n
 
559
                        int lineNum = pdoc->LineFromPosition(caretMain);
 
560
                        if(lineNum != wxNOT_FOUND) {
 
561
                                int where = pdoc->LineStart(lineNum);
 
562
                                if(where != wxNOT_FOUND) {
 
563
                                        pdoc->InsertString(where, buf, len);
 
564
                                        newPos = where + len;
 
565
 
 
566
                                        allowCopyLineSuccess = true;
 
567
                                }
 
568
                        }
 
569
                }
 
570
 
 
571
                if(!allowCopyLineSuccess) {
 
572
                        // Simple copy paste block
 
573
                        pdoc->InsertString (caretMain, buf, len);
 
574
                        newPos = caretMain + len;
 
575
                }
 
576
        }
 
577
        SetEmptySelection (newPos);
555
578
#endif // wxUSE_DATAOBJ
556
579
 
557
 
    pdoc->EndUndoAction();
558
 
    NotifyChange();
559
 
    Redraw();
 
580
        pdoc->EndUndoAction();
 
581
        NotifyChange();
 
582
        Redraw();
560
583
}
561
584
 
562
585
 
563
586
void ScintillaWX::CopyToClipboard (const SelectionText& st) {
564
587
#if wxUSE_CLIPBOARD
565
 
        wxTheClipboard->UsePrimarySelection(false);
 
588
        wxTheClipboard->UsePrimarySelection(false);
566
589
        if (wxTheClipboard->Open()) {
567
 
        wxString text = wxTextBuffer::Translate (sci2wx(st.s, st.len-1));
568
 
 
569
 
        // composite object will hold "plain text" for pasting in other programs and a custom
570
 
        // object for local use that remembers what kind of selection was made (stream or
571
 
        // rectangular).
572
 
        wxDataObjectComposite* obj = new wxDataObjectComposite();
573
 
        wxCustomDataObject* rectData = new wxCustomDataObject (wxDataFormat(wxString(wxT("application/x-cbrectdata"))));
574
 
 
575
 
        char* buffer = new char[st.len+1];
576
 
        buffer[0] = (st.rectangular)? (char)1 : (char)0;
577
 
        memcpy (buffer+1, st.s, st.len);
578
 
        rectData->SetData (st.len+1, buffer);
579
 
        delete [] buffer;
580
 
 
581
 
        obj->Add (rectData, true);
582
 
        obj->Add (new wxTextDataObject (text));
583
 
        wxTheClipboard->SetData (obj);
584
 
        wxTheClipboard->Close();
 
590
                wxString text = wxTextBuffer::Translate (sci2wx(st.s, st.len-1));
 
591
 
 
592
                // composite object will hold "plain text" for pasting in other programs and a custom
 
593
                // object for local use that remembers what kind of selection was made (stream or
 
594
                // rectangular).
 
595
                wxDataObjectComposite* obj = new wxDataObjectComposite();
 
596
                wxCustomDataObject* rectData = new wxCustomDataObject (wxDataFormat(wxString(wxT("application/x-cbrectdata"))));
 
597
 
 
598
                char* buffer = new char[st.len+1];
 
599
                buffer[0] = (st.rectangular)? (char)1 : (char)0;
 
600
                memcpy (buffer+1, st.s, st.len);
 
601
                rectData->SetData (st.len+1, buffer);
 
602
                delete [] buffer;
 
603
 
 
604
                obj->Add (rectData, true);
 
605
                obj->Add (new wxTextDataObject (text));
 
606
                wxTheClipboard->SetData (obj);
 
607
                wxTheClipboard->Close();
585
608
        }
586
609
#else
587
 
    wxUnusedVar(st);
 
610
        wxUnusedVar(st);
588
611
#endif // wxUSE_CLIPBOARD
589
612
}
590
613
 
591
614
 
592
615
bool ScintillaWX::CanPaste() {
593
 
wxTheClipboard->UsePrimarySelection(false);
 
616
        wxTheClipboard->UsePrimarySelection(false);
594
617
#if wxUSE_CLIPBOARD
595
 
    bool canPaste = false;
596
 
    bool didOpen;
597
 
 
598
 
    if (Editor::CanPaste()) {
599
 
        didOpen = !wxTheClipboard->IsOpened();
600
 
        if ( didOpen )
601
 
            wxTheClipboard->Open();
602
 
 
603
 
        if (wxTheClipboard->IsOpened()) {
604
 
            canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);
605
 
            if (didOpen)
606
 
                wxTheClipboard->Close();
607
 
        }
608
 
    }
609
 
    return canPaste;
 
618
        bool canPaste = false;
 
619
        bool didOpen;
 
620
 
 
621
        if (Editor::CanPaste()) {
 
622
                didOpen = !wxTheClipboard->IsOpened();
 
623
                if ( didOpen )
 
624
                        wxTheClipboard->Open();
 
625
 
 
626
                if (wxTheClipboard->IsOpened()) {
 
627
                        canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);
 
628
                        if (didOpen)
 
629
                                wxTheClipboard->Close();
 
630
                }
 
631
        }
 
632
        return canPaste;
610
633
#else
611
 
    return false;
 
634
        return false;
612
635
#endif // wxUSE_CLIPBOARD
613
636
}
614
637
 
615
638
void ScintillaWX::CreateCallTipWindow(PRectangle) {
616
 
    if (! ct.wCallTip.Created() ) {
617
 
        ct.wCallTip = new wxSCICallTip(sci, &ct, this);
618
 
        ct.wDraw = ct.wCallTip;
619
 
    }
 
639
        if (! ct.wCallTip.Created() ) {
 
640
                ct.wCallTip = new wxSCICallTip(sci, &ct, this);
 
641
                ct.wDraw = ct.wCallTip;
 
642
        }
620
643
}
621
644
 
622
645
 
623
646
void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) {
624
 
    if (!label[0])
625
 
        ((wxMenu*)popup.GetID())->AppendSeparator();
626
 
    else
627
 
        ((wxMenu*)popup.GetID())->Append(cmd, wxGetTranslation(sci2wx(label)));
 
647
        if (!label[0])
 
648
                ((wxMenu*)popup.GetID())->AppendSeparator();
 
649
        else
 
650
                ((wxMenu*)popup.GetID())->Append(cmd, wxGetTranslation(sci2wx(label)));
628
651
 
629
 
    if (!enabled)
630
 
        ((wxMenu*)popup.GetID())->Enable(cmd, enabled);
 
652
        if (!enabled)
 
653
                ((wxMenu*)popup.GetID())->Enable(cmd, enabled);
631
654
}
632
655
 
633
656
// [CHANGED]
637
660
void ScintillaWX::ClaimSelection() {
638
661
 
639
662
#if defined(__WXGTK__) && wxCHECK_VERSION(2,9,0)
640
 
    // Put the selected text in the PRIMARY selection
641
 
    if (!sel.Empty()) {
642
 
        SelectionText st;
643
 
        CopySelectionRange(&st);
644
 
            wxTheClipboard->UsePrimarySelection(true);
645
 
        if (wxTheClipboard->Open()) {
646
 
            wxString text = sci2wx(st.s, st.len);
647
 
            wxTheClipboard->SetData(new wxTextDataObject(text));
648
 
            wxTheClipboard->Close();
649
 
        }
650
 
        wxTheClipboard->UsePrimarySelection(false);
651
 
    }
 
663
        // Put the selected text in the PRIMARY selection
 
664
        if (!sel.Empty()) {
 
665
                SelectionText st;
 
666
                CopySelectionRange(&st);
 
667
                wxTheClipboard->UsePrimarySelection(true);
 
668
                if (wxTheClipboard->Open()) {
 
669
                        wxString text = sci2wx(st.s, st.len);
 
670
                        wxTheClipboard->SetData(new wxTextDataObject(text));
 
671
                        wxTheClipboard->Close();
 
672
                }
 
673
                wxTheClipboard->UsePrimarySelection(false);
 
674
        }
652
675
#endif
653
676
}
654
677
 
655
678
 
656
679
void ScintillaWX::UpdateSystemCaret() {
657
680
#ifdef __WXMSW__
658
 
    if (hasFocus) {
659
 
        if (HasCaretSizeChanged()) {
660
 
            DestroySystemCaret();
661
 
            CreateSystemCaret();
662
 
        }
663
 
        Point pos = LocationFromPosition(sel.MainCaret());
 
681
        if (hasFocus) {
 
682
                if (HasCaretSizeChanged()) {
 
683
                        DestroySystemCaret();
 
684
                        CreateSystemCaret();
 
685
                }
 
686
                Point pos = LocationFromPosition(sel.MainCaret());
664
687
#if wxCHECK_VERSION(2, 5, 0)
665
 
        ::SetCaretPos(pos.x, pos.y);
 
688
                ::SetCaretPos(pos.x, pos.y);
666
689
#endif
667
 
    }
 
690
        }
668
691
#endif
669
692
}
670
693
 
672
695
bool ScintillaWX::HasCaretSizeChanged() {
673
696
#ifdef __WXMSW__
674
697
#if !wxCHECK_VERSION(2, 5, 0)
675
 
    return false;
 
698
        return false;
676
699
#else
677
 
    if (( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) )
678
 
        || (0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight)) {
679
 
        return true;
680
 
    }
681
 
#endif
682
 
#endif
683
 
    return false;
 
700
        if (( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) )
 
701
                || (0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight)) {
 
702
                return true;
 
703
        }
 
704
#endif
 
705
#endif
 
706
        return false;
684
707
}
685
708
 
686
709
bool ScintillaWX::CreateSystemCaret() {
687
710
#ifdef __WXMSW__
688
711
#if !wxCHECK_VERSION(2, 5, 0)
689
 
    return false;
 
712
        return false;
690
713
#else
691
 
    sysCaretWidth = vs.caretWidth;
692
 
    if (0 == sysCaretWidth) {
693
 
        sysCaretWidth = 1;
694
 
    }
695
 
    sysCaretHeight = vs.lineHeight;
696
 
    int bitmapSize = (((sysCaretWidth + 15) & ~15) >> 3) * sysCaretHeight;
697
 
    char *bits = new char[bitmapSize];
698
 
    memset(bits, 0, bitmapSize);
699
 
    sysCaretBitmap = ::CreateBitmap(sysCaretWidth, sysCaretHeight, 1,
700
 
                                    1, reinterpret_cast<BYTE *>(bits));
701
 
    delete [] bits;
702
 
    BOOL retval = ::CreateCaret(GetHwndOf(sci), sysCaretBitmap,
703
 
                                sysCaretWidth, sysCaretHeight);
704
 
    ::ShowCaret(GetHwndOf(sci));
705
 
    return retval != 0;
 
714
        sysCaretWidth = vs.caretWidth;
 
715
        if (0 == sysCaretWidth) {
 
716
                sysCaretWidth = 1;
 
717
        }
 
718
        sysCaretHeight = vs.lineHeight;
 
719
        int bitmapSize = (((sysCaretWidth + 15) & ~15) >> 3) * sysCaretHeight;
 
720
        char *bits = new char[bitmapSize];
 
721
        memset(bits, 0, bitmapSize);
 
722
        sysCaretBitmap = ::CreateBitmap(sysCaretWidth, sysCaretHeight, 1,
 
723
                                        1, reinterpret_cast<BYTE *>(bits));
 
724
        delete [] bits;
 
725
        BOOL retval = ::CreateCaret(GetHwndOf(sci), sysCaretBitmap,
 
726
                                    sysCaretWidth, sysCaretHeight);
 
727
        ::ShowCaret(GetHwndOf(sci));
 
728
        return retval != 0;
706
729
#endif
707
730
#else
708
 
    return false;
 
731
        return false;
709
732
#endif
710
733
}
711
734
 
712
735
bool ScintillaWX::DestroySystemCaret() {
713
736
#ifdef __WXMSW__
714
737
#if !wxCHECK_VERSION(2, 5, 0)
715
 
    return false;
 
738
        return false;
716
739
#else
717
 
    ::HideCaret(GetHwndOf(sci));
718
 
    BOOL retval = ::DestroyCaret();
719
 
    if (sysCaretBitmap) {
720
 
        ::DeleteObject(sysCaretBitmap);
721
 
        sysCaretBitmap = 0;
722
 
    }
723
 
    return retval != 0;
 
740
        ::HideCaret(GetHwndOf(sci));
 
741
        BOOL retval = ::DestroyCaret();
 
742
        if (sysCaretBitmap) {
 
743
                ::DeleteObject(sysCaretBitmap);
 
744
                sysCaretBitmap = 0;
 
745
        }
 
746
        return retval != 0;
724
747
#endif
725
748
#else
726
 
    return false;
 
749
        return false;
727
750
#endif
728
751
}
729
752
 
731
754
//----------------------------------------------------------------------
732
755
 
733
756
long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
734
 
    return 0;
 
757
        return 0;
735
758
}
736
759
 
737
760
long ScintillaWX::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) {
738
 
      switch (iMessage) {
739
 
      case SCI_CALLTIPSHOW: {
740
 
          // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
741
 
          // because of the little tweak that needs done below for wxGTK.
742
 
          // When updating new versions double check that this is still
743
 
          // needed, and that any new code there is copied here too.
744
 
          Point pt = LocationFromPosition(wParam);
745
 
          char* defn = reinterpret_cast<char *>(lParam);
746
 
          AutoCompleteCancel();
747
 
          pt.y += vs.lineHeight;
748
 
 
749
 
                  int ctStyle = ct.UseStyleCallTip() ? STYLE_CALLTIP : STYLE_DEFAULT;
750
 
          PRectangle rc = ct.CallTipStart(sel.MainCaret(), pt,
751
 
                                          defn,
752
 
                                          vs.styles[ctStyle].fontName,
753
 
                                          vs.styles[ctStyle].sizeZoomed,
754
 
                                          CodePage(),
755
 
                                          vs.styles[ctStyle].characterSet,
756
 
                                          wMain);
757
 
          // If the call-tip window would be out of the client
758
 
          // space, adjust so it displays above the text.
759
 
          PRectangle rcClient = GetClientRectangle();
760
 
          if (rc.bottom > rcClient.bottom) {
 
761
        switch (iMessage) {
 
762
        case SCI_CALLTIPSHOWEXT: {
 
763
                Point pt = LocationFromPosition(wParam);
 
764
                char* defn = reinterpret_cast<char *>(lParam);
 
765
                AutoCompleteCancel();
 
766
 
 
767
                // If container knows about STYLE_CALLTIP then use it in place of the
 
768
                // STYLE_DEFAULT for the face name, size and character set. Also use it
 
769
                // for the foreground and background colour.
 
770
                int ctStyle = ct.UseStyleCallTip() ? STYLE_CALLTIP : STYLE_DEFAULT;
 
771
 
 
772
                PRectangle rc = ct.CallTipStart(sel.MainCaret(), pt,
 
773
                                                defn,
 
774
                                                vs.styles[ctStyle].fontName,
 
775
                                                vs.styles[ctStyle].sizeZoomed,
 
776
                                                CodePage(),
 
777
                                                vs.styles[ctStyle].characterSet,
 
778
                                                wMain);
 
779
                int tipHeight = rc.Height();
 
780
                int tipWidth  = rc.Width();
 
781
 
 
782
                // handle the Y axis
 
783
                int h = rc.Height();
 
784
                rc.top    = sci->m_ccPoint.y;
 
785
                rc.bottom = rc.top + h;
 
786
 
 
787
                // Adjust the X coordinates of the tip
 
788
                rc.left   = sci->m_ccPoint.x + 250;
 
789
                rc.right  = rc.left + tipWidth;
 
790
                rc.top    = sci->m_ccPoint.y;
 
791
                rc.bottom = rc.top + tipHeight;
 
792
 
 
793
                // If the call-tip window would be out of the client
 
794
                // space, adjust so it displays above the text.
 
795
 
 
796
                // Convert the cilent position to screen position
 
797
                // and perform all calculations based on screen size
 
798
                // once done, convert the result back to client coords
 
799
                static int ww(-1);
 
800
                static int hh(-1);
 
801
                if(hh == -1 || ww == -1)
 
802
                        ::wxDisplaySize(&ww, &hh);
 
803
 
 
804
                wxRect rr = wxRectFromPRectangle(rc);
 
805
                wxPoint parentPt      = sci->ClientToScreen(rr.GetLeftTop());
 
806
                wxPoint parentCCBoxPt = sci->ClientToScreen(sci->m_ccPoint);
 
807
 
 
808
                rr.SetTopLeft( parentPt );
 
809
 
 
810
                /////////////////////////////////////////////////////////
 
811
                // Adjust the Y axis
 
812
                /////////////////////////////////////////////////////////
 
813
 
 
814
                if (rr.GetBottom() > hh) {
 
815
                        int offset = (rr.GetBottom()- hh);
 
816
                        rr.y -= offset;
 
817
 
 
818
                        if(rr.y < 0) {
 
819
                                rr.y     = 0;
 
820
                        }
 
821
                }
 
822
 
 
823
                if(rr.GetRight() > ww) {
 
824
                        int fallbackX = rr.x;
 
825
                        rr.x  = parentCCBoxPt.x;
 
826
                        rr.x  -= tipWidth;
 
827
 
 
828
                        if(rr.x < 0) {
 
829
                                // moving the tip to the left is not good also
 
830
                                // fallback
 
831
                                rr.x = fallbackX;
 
832
                        }
 
833
                }
 
834
 
 
835
                // Convert the 'rr' into Client Coords
 
836
                wxPoint clientPt = sci->ScreenToClient(rr.GetTopLeft());
 
837
                rr.SetTopLeft( clientPt );
 
838
                rc = PRectangle(rr.GetLeft(), rr.GetTop(), rr.GetRight()+1, rr.GetBottom()+1);
 
839
                
 
840
                if(sci->m_isTipBgDark) {
 
841
                        ct.colourDoxyHighlight = ColourAllocated( ColourDesired(0, 255, 0).AsLong() );
 
842
                        ct.colourDivider       = ColourAllocated( ColourDesired(255, 255, 255).AsLong() );
 
843
                }
 
844
                
 
845
                // Now display the window.
 
846
                CreateCallTipWindow(rc);
 
847
                ct.wCallTip.SetPositionRelative(rc, wMain);
 
848
                ct.wCallTip.Show();
 
849
                break;
 
850
        }
 
851
        case SCI_CALLTIPSHOW: {
 
852
                // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
 
853
                // because of the little tweak that needs done below for wxGTK.
 
854
                // When updating new versions double check that this is still
 
855
                // needed, and that any new code there is copied here too.
 
856
                Point pt = LocationFromPosition(wParam);
 
857
                char* defn = reinterpret_cast<char *>(lParam);
 
858
                AutoCompleteCancel();
 
859
                pt.y += vs.lineHeight;
 
860
 
 
861
                int ctStyle = ct.UseStyleCallTip() ? STYLE_CALLTIP : STYLE_DEFAULT;
 
862
                PRectangle rc = ct.CallTipStart(sel.MainCaret(), pt,
 
863
                                                defn,
 
864
                                                vs.styles[ctStyle].fontName,
 
865
                                                vs.styles[ctStyle].sizeZoomed,
 
866
                                                CodePage(),
 
867
                                                vs.styles[ctStyle].characterSet,
 
868
                                                wMain);
 
869
                // If the call-tip window would be out of the client
 
870
                // space, adjust so it displays above the text.
 
871
                PRectangle rcClient = GetClientRectangle();
 
872
                if (rc.bottom > rcClient.bottom) {
761
873
#ifdef __WXGTK__
762
 
              int offset = int(vs.lineHeight * 1.25)  + rc.Height();
 
874
                        int offset = int(vs.lineHeight * 1.25)  + rc.Height();
763
875
#else
764
 
              int offset = vs.lineHeight + rc.Height();
 
876
                        int offset = vs.lineHeight + rc.Height();
765
877
#endif
766
 
              rc.top -= offset;
767
 
              rc.bottom -= offset;
768
 
          }
769
 
          // Now display the window.
770
 
          CreateCallTipWindow(rc);
771
 
          ct.wCallTip.SetPositionRelative(rc, wMain);
772
 
          ct.wCallTip.Show();
773
 
          break;
774
 
      }
775
 
/*? TODO
776
 
#ifdef SCI_LEXER
777
 
      case SCI_LOADLEXERLIBRARY:
778
 
            LexerManager::GetInstance()->Load((const char*)lParam);
779
 
            break;
780
 
#endif ?*/
781
 
      default:
782
 
          return ScintillaBase::WndProc(iMessage, wParam, lParam);
783
 
      }
784
 
      return 0;
 
878
                        rc.top -= offset;
 
879
                        rc.bottom -= offset;
 
880
                }
 
881
                // Now display the window.
 
882
                CreateCallTipWindow(rc);
 
883
                ct.wCallTip.SetPositionRelative(rc, wMain);
 
884
                ct.wCallTip.Show();
 
885
                break;
 
886
        }
 
887
        /*? TODO
 
888
        #ifdef SCI_LEXER
 
889
              case SCI_LOADLEXERLIBRARY:
 
890
                    LexerManager::GetInstance()->Load((const char*)lParam);
 
891
                    break;
 
892
        #endif ?*/
 
893
        default:
 
894
                return ScintillaBase::WndProc(iMessage, wParam, lParam);
 
895
        }
 
896
        return 0;
785
897
}
786
898
 
787
899
 
791
903
 
792
904
void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) {
793
905
 
794
 
    paintState = painting;
795
 
    Surface* surfaceWindow = Surface::Allocate();
796
 
    surfaceWindow->Init(dc, wMain.GetID());
797
 
    rcPaint = PRectangleFromwxRect(rect);
798
 
    PRectangle rcClient = GetClientRectangle();
799
 
    paintingAllText = rcPaint.Contains(rcClient);
800
 
 
801
 
    ClipChildren(*dc, rcPaint);
802
 
    Paint(surfaceWindow, rcPaint);
803
 
 
804
 
    delete surfaceWindow;
805
 
    if (paintState == paintAbandoned) {
806
 
        // Painting area was insufficient to cover new styling or brace
807
 
        // highlight positions
808
 
        FullPaint();
809
 
    }
810
 
    paintState = notPainting;
 
906
        paintState = painting;
 
907
        Surface* surfaceWindow = Surface::Allocate();
 
908
        surfaceWindow->Init(dc, wMain.GetID());
 
909
        rcPaint = PRectangleFromwxRect(rect);
 
910
        PRectangle rcClient = GetClientRectangle();
 
911
        paintingAllText = rcPaint.Contains(rcClient);
 
912
 
 
913
        ClipChildren(*dc, rcPaint);
 
914
        Paint(surfaceWindow, rcPaint);
 
915
 
 
916
        delete surfaceWindow;
 
917
        if (paintState == paintAbandoned) {
 
918
                // Painting area was insufficient to cover new styling or brace
 
919
                // highlight positions
 
920
                FullPaint();
 
921
        }
 
922
        paintState = notPainting;
811
923
}
812
924
 
813
925
 
814
926
void ScintillaWX::DoHScroll(int type, int pos) {
815
 
    int xPos = xOffset;
816
 
    PRectangle rcText = GetTextRectangle();
817
 
    int pageWidth = rcText.Width() * 2 / 3;
818
 
    if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
819
 
        xPos -= H_SCROLL_STEP;
820
 
    else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
821
 
        xPos += H_SCROLL_STEP;
822
 
    else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
823
 
        xPos -= pageWidth;
824
 
    else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) {
825
 
        xPos += pageWidth;
826
 
        if (xPos > scrollWidth - rcText.Width()) {
827
 
            xPos = scrollWidth - rcText.Width();
828
 
        }
829
 
    }
830
 
    else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
831
 
        xPos = 0;
832
 
    else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
833
 
        xPos = scrollWidth;
834
 
    else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
835
 
        xPos = pos;
 
927
        int xPos = xOffset;
 
928
        PRectangle rcText = GetTextRectangle();
 
929
        int pageWidth = rcText.Width() * 2 / 3;
 
930
        if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
 
931
                xPos -= H_SCROLL_STEP;
 
932
        else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
 
933
                xPos += H_SCROLL_STEP;
 
934
        else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
 
935
                xPos -= pageWidth;
 
936
        else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) {
 
937
                xPos += pageWidth;
 
938
                if (xPos > scrollWidth - rcText.Width()) {
 
939
                        xPos = scrollWidth - rcText.Width();
 
940
                }
 
941
        } else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
 
942
                xPos = 0;
 
943
        else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
 
944
                xPos = scrollWidth;
 
945
        else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
 
946
                xPos = pos;
836
947
 
837
 
    HorizontalScrollTo(xPos);
 
948
        HorizontalScrollTo(xPos);
838
949
}
839
950
 
840
951
void ScintillaWX::DoVScroll(int type, int pos) {
841
 
    int topLineNew = topLine;
842
 
    if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
843
 
        topLineNew -= 1;
844
 
    else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
845
 
        topLineNew += 1;
846
 
    else if (type ==  wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
847
 
        topLineNew -= LinesToScroll();
848
 
    else if (type ==  wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN)
849
 
        topLineNew += LinesToScroll();
850
 
    else if (type ==  wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
851
 
        topLineNew = 0;
852
 
    else if (type ==  wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
853
 
        topLineNew = MaxScrollPos();
854
 
    else if (type ==   wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
855
 
        topLineNew = pos;
 
952
        int topLineNew = topLine;
 
953
        if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
 
954
                topLineNew -= 1;
 
955
        else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
 
956
                topLineNew += 1;
 
957
        else if (type ==  wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
 
958
                topLineNew -= LinesToScroll();
 
959
        else if (type ==  wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN)
 
960
                topLineNew += LinesToScroll();
 
961
        else if (type ==  wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
 
962
                topLineNew = 0;
 
963
        else if (type ==  wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
 
964
                topLineNew = MaxScrollPos();
 
965
        else if (type ==   wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
 
966
                topLineNew = pos;
856
967
 
857
 
    ScrollTo(topLineNew);
 
968
        ScrollTo(topLineNew);
858
969
}
859
970
 
860
971
void ScintillaWX::DoMouseWheel(int rotation, int delta,
861
972
                               int linesPerAction, int ctrlDown,
862
973
                               bool isPageScroll ) {
863
 
    int topLineNew = topLine;
864
 
    int lines;
 
974
        int topLineNew = topLine;
 
975
        int lines;
865
976
 
866
 
    if (ctrlDown) {  // Zoom the fonts if Ctrl key down
867
 
        if (rotation < 0) {
868
 
            KeyCommand(SCI_ZOOMIN);
869
 
        }
870
 
        else {
871
 
            KeyCommand(SCI_ZOOMOUT);
872
 
        }
873
 
    }
874
 
    else { // otherwise just scroll the window
875
 
        if ( !delta )
876
 
            delta = 120;
877
 
        wheelRotation += rotation;
878
 
        lines = wheelRotation / delta;
879
 
        wheelRotation -= lines * delta;
880
 
        if (lines != 0) {
881
 
            if (isPageScroll)
882
 
                lines = lines * LinesOnScreen();  // lines is either +1 or -1
883
 
            else
884
 
                lines *= linesPerAction;
885
 
            topLineNew -= lines;
886
 
            ScrollTo(topLineNew);
887
 
        }
888
 
    }
 
977
        if (ctrlDown) {  // Zoom the fonts if Ctrl key down
 
978
                if (rotation < 0) {
 
979
                        KeyCommand(SCI_ZOOMIN);
 
980
                } else {
 
981
                        KeyCommand(SCI_ZOOMOUT);
 
982
                }
 
983
        } else { // otherwise just scroll the window
 
984
                if ( !delta )
 
985
                        delta = 120;
 
986
                wheelRotation += rotation;
 
987
                lines = wheelRotation / delta;
 
988
                wheelRotation -= lines * delta;
 
989
                if (lines != 0) {
 
990
                        if (isPageScroll)
 
991
                                lines = lines * LinesOnScreen();  // lines is either +1 or -1
 
992
                        else
 
993
                                lines *= linesPerAction;
 
994
                        topLineNew -= lines;
 
995
                        ScrollTo(topLineNew);
 
996
                }
 
997
        }
889
998
}
890
999
 
891
1000
 
892
1001
void ScintillaWX::DoSize(int WXUNUSED(width), int WXUNUSED(height)) {
893
 
    ChangeSize();
894
 
}
895
 
 
896
 
void ScintillaWX::DoLoseFocus(){
897
 
    focusEvent = true;
898
 
    SetFocusState(false);
899
 
    focusEvent = false;
900
 
    DestroySystemCaret();
901
 
}
902
 
 
903
 
void ScintillaWX::DoGainFocus(){
904
 
    focusEvent = true;
905
 
    SetFocusState(true);
906
 
    focusEvent = false;
907
 
    DestroySystemCaret();
908
 
    CreateSystemCaret();
 
1002
        ChangeSize();
 
1003
}
 
1004
 
 
1005
void ScintillaWX::DoLoseFocus() {
 
1006
        focusEvent = true;
 
1007
        SetFocusState(false);
 
1008
        focusEvent = false;
 
1009
        DestroySystemCaret();
 
1010
}
 
1011
 
 
1012
void ScintillaWX::DoGainFocus() {
 
1013
        focusEvent = true;
 
1014
        SetFocusState(true);
 
1015
        focusEvent = false;
 
1016
        DestroySystemCaret();
 
1017
        CreateSystemCaret();
909
1018
}
910
1019
 
911
1020
void ScintillaWX::DoSysColourChange() {
912
 
    InvalidateStyleData();
 
1021
        InvalidateStyleData();
913
1022
}
914
1023
 
915
1024
void ScintillaWX::DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
916
 
    ButtonDown(pt, curTime, shift, ctrl, alt);
 
1025
        ButtonDown(pt, curTime, shift, ctrl, alt);
917
1026
}
918
1027
 
919
1028
void ScintillaWX::DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl) {
920
 
    ButtonUp(pt, curTime, ctrl);
 
1029
        ButtonUp(pt, curTime, ctrl);
921
1030
#if wxUSE_DRAG_AND_DROP
922
 
    if (startDragTimer->IsRunning()) {
923
 
        startDragTimer->Stop();
924
 
        SetDragPosition(SelectionPosition(invalidPosition));
925
 
        SetEmptySelection(PositionFromLocation(pt));
926
 
        ShowCaretAtCurrentPosition();
927
 
    }
 
1031
        if (startDragTimer->IsRunning()) {
 
1032
                startDragTimer->Stop();
 
1033
                SetDragPosition(SelectionPosition(invalidPosition));
 
1034
                SetEmptySelection(PositionFromLocation(pt));
 
1035
                ShowCaretAtCurrentPosition();
 
1036
        }
928
1037
#endif
929
1038
}
930
1039
 
931
1040
void ScintillaWX::DoLeftButtonMove(Point pt) {
932
 
    ButtonMove(pt);
 
1041
        ButtonMove(pt);
933
1042
}
934
1043
 
935
1044
#ifdef __WXGTK__
936
1045
void ScintillaWX::DoMiddleButtonUp(Point pt) {
937
 
    // Set the current position to the mouse click point and
938
 
    // then paste in the PRIMARY selection, if any.  wxGTK only.
939
 
    int newPos = PositionFromLocation(pt);
940
 
    MovePositionTo(newPos, Selection::noSel, true);
941
 
 
942
 
    pdoc->BeginUndoAction();
943
 
    wxTextDataObject data;
944
 
    bool gotData = false;
945
 
        wxTheClipboard->UsePrimarySelection(true);
946
 
    if (wxTheClipboard->Open()) {
947
 
        gotData = wxTheClipboard->GetData(data);
948
 
        wxTheClipboard->Close();
949
 
    }
950
 
    wxTheClipboard->UsePrimarySelection(false);
951
 
    if (gotData) {
952
 
        wxString text = wxTextBuffer::Translate (data.GetText(),
953
 
                                                 wxConvertEOLMode(pdoc->eolMode));
954
 
        data.SetText(wxEmptyString); // free the data object content
955
 
        wxWX2MBbuf buf = (wxWX2MBbuf)wx2sci(text);
956
 
        int        len = strlen(buf);
957
 
        pdoc->InsertString(sel.MainCaret(), buf, len);
958
 
        SetEmptySelection(sel.MainCaret() + len);
959
 
    }
960
 
    pdoc->EndUndoAction();
961
 
    NotifyChange();
962
 
    Redraw();
963
 
 
964
 
    ShowCaretAtCurrentPosition();
965
 
    EnsureCaretVisible();
 
1046
        // Set the current position to the mouse click point and
 
1047
        // then paste in the PRIMARY selection, if any.  wxGTK only.
 
1048
        int newPos = PositionFromLocation(pt);
 
1049
        MovePositionTo(newPos, Selection::noSel, true);
 
1050
 
 
1051
        pdoc->BeginUndoAction();
 
1052
        wxTextDataObject data;
 
1053
        bool gotData = false;
 
1054
        wxTheClipboard->UsePrimarySelection(true);
 
1055
        if (wxTheClipboard->Open()) {
 
1056
                gotData = wxTheClipboard->GetData(data);
 
1057
                wxTheClipboard->Close();
 
1058
        }
 
1059
        wxTheClipboard->UsePrimarySelection(false);
 
1060
        if (gotData) {
 
1061
                wxString text = wxTextBuffer::Translate (data.GetText(),
 
1062
                                wxConvertEOLMode(pdoc->eolMode));
 
1063
                data.SetText(wxEmptyString); // free the data object content
 
1064
                wxWX2MBbuf buf = (wxWX2MBbuf)wx2sci(text);
 
1065
                int        len = strlen(buf);
 
1066
                pdoc->InsertString(sel.MainCaret(), buf, len);
 
1067
                SetEmptySelection(sel.MainCaret() + len);
 
1068
        }
 
1069
        pdoc->EndUndoAction();
 
1070
        NotifyChange();
 
1071
        Redraw();
 
1072
 
 
1073
        ShowCaretAtCurrentPosition();
 
1074
        EnsureCaretVisible();
966
1075
}
967
1076
#else
968
1077
void ScintillaWX::DoMiddleButtonUp(Point WXUNUSED(pt)) {
972
1081
 
973
1082
void ScintillaWX::DoAddChar(int key) {
974
1083
#if wxUSE_UNICODE
975
 
    wxChar wszChars[2];
976
 
    wszChars[0] = (wxChar)key;
977
 
    wszChars[1] = 0;
978
 
    wxWX2MBbuf buf = (wxWX2MBbuf)wx2sci(wszChars);
979
 
    AddCharUTF((char*)buf.data(), strlen(buf));
 
1084
        wxChar wszChars[2];
 
1085
        wszChars[0] = (wxChar)key;
 
1086
        wszChars[1] = 0;
 
1087
        wxWX2MBbuf buf = (wxWX2MBbuf)wx2sci(wszChars);
 
1088
        AddCharUTF((char*)buf.data(), strlen(buf));
980
1089
#else
981
 
    AddChar((char)key);
 
1090
        AddChar((char)key);
982
1091
#endif
983
1092
}
984
1093
 
985
1094
 
986
 
int  ScintillaWX::DoKeyDown(const wxKeyEvent& evt, bool* consumed)
987
 
{
988
 
    int key = evt.GetKeyCode();
989
 
    bool shift = evt.ShiftDown(),
990
 
         ctrl  = evt.ControlDown(),
991
 
         alt   = evt.AltDown();
992
 
 
993
 
    if (ctrl && key >= 1 && key <= 26 && key != WXK_BACK)
994
 
        key += 'A' - 1;
995
 
 
996
 
    switch (key) {
997
 
    case WXK_DOWN:              // fall through
998
 
    case WXK_NUMPAD_DOWN:       key = SCK_DOWN;     break;
999
 
    case WXK_UP:                // fall through
1000
 
    case WXK_NUMPAD_UP:         key = SCK_UP;       break;
1001
 
    case WXK_LEFT:              // fall through
1002
 
    case WXK_NUMPAD_LEFT:       key = SCK_LEFT;     break;
1003
 
    case WXK_RIGHT:             // fall through
1004
 
    case WXK_NUMPAD_RIGHT:      key = SCK_RIGHT;    break;
1005
 
    case WXK_HOME:              // fall through
1006
 
    case WXK_NUMPAD_HOME:       key = SCK_HOME;     break;
1007
 
    case WXK_END:               // fall through
1008
 
    case WXK_NUMPAD_END:        key = SCK_END;      break;
1009
 
#if !wxCHECK_VERSION(2, 7, 0)
1010
 
    case WXK_PRIOR:             // fall through
1011
 
    case WXK_NUMPAD_PRIOR:      // fall through
1012
 
#endif
1013
 
    case WXK_PAGEUP:            // fall through
1014
 
    case WXK_NUMPAD_PAGEUP:     key = SCK_PRIOR;    break;
1015
 
#if !wxCHECK_VERSION(2, 7, 0)
1016
 
    case WXK_NEXT:              // fall through
1017
 
    case WXK_NUMPAD_NEXT:       // fall through
1018
 
#endif
1019
 
    case WXK_PAGEDOWN:          // fall through
1020
 
    case WXK_NUMPAD_PAGEDOWN:   key = SCK_NEXT;     break;
1021
 
        //Eran - BEGIN
 
1095
int  ScintillaWX::DoKeyDown(const wxKeyEvent& evt, bool* consumed) {
 
1096
        int key = evt.GetKeyCode();
 
1097
        bool shift = evt.ShiftDown(),
 
1098
             ctrl  = evt.ControlDown(),
 
1099
             alt   = evt.AltDown();
 
1100
 
 
1101
        if (ctrl && key >= 1 && key <= 26 && key != WXK_BACK)
 
1102
                key += 'A' - 1;
 
1103
 
 
1104
        switch (key) {
 
1105
        case WXK_DOWN:              // fall through
 
1106
        case WXK_NUMPAD_DOWN:
 
1107
                key = SCK_DOWN;
 
1108
                break;
 
1109
        case WXK_UP:                // fall through
 
1110
        case WXK_NUMPAD_UP:
 
1111
                key = SCK_UP;
 
1112
                break;
 
1113
        case WXK_LEFT:              // fall through
 
1114
        case WXK_NUMPAD_LEFT:
 
1115
                key = SCK_LEFT;
 
1116
                break;
 
1117
        case WXK_RIGHT:             // fall through
 
1118
        case WXK_NUMPAD_RIGHT:
 
1119
                key = SCK_RIGHT;
 
1120
                break;
 
1121
        case WXK_HOME:              // fall through
 
1122
        case WXK_NUMPAD_HOME:
 
1123
                key = SCK_HOME;
 
1124
                break;
 
1125
        case WXK_END:               // fall through
 
1126
        case WXK_NUMPAD_END:
 
1127
                key = SCK_END;
 
1128
                break;
 
1129
#if !wxCHECK_VERSION(2, 7, 0)
 
1130
        case WXK_PRIOR:             // fall through
 
1131
        case WXK_NUMPAD_PRIOR:      // fall through
 
1132
#endif
 
1133
        case WXK_PAGEUP:            // fall through
 
1134
        case WXK_NUMPAD_PAGEUP:
 
1135
                key = SCK_PRIOR;
 
1136
                break;
 
1137
#if !wxCHECK_VERSION(2, 7, 0)
 
1138
        case WXK_NEXT:              // fall through
 
1139
        case WXK_NUMPAD_NEXT:       // fall through
 
1140
#endif
 
1141
        case WXK_PAGEDOWN:          // fall through
 
1142
        case WXK_NUMPAD_PAGEDOWN:
 
1143
                key = SCK_NEXT;
 
1144
                break;
 
1145
                //Eran - BEGIN
1022
1146
        case WXK_NUMPAD_DELETE: //fall through
1023
 
        //Eran - END
1024
 
    case WXK_DELETE:            key = SCK_DELETE;   break;
 
1147
                //Eran - END
 
1148
        case WXK_DELETE:
 
1149
                key = SCK_DELETE;
 
1150
                break;
1025
1151
 
1026
 
        //Eran - BEGIN
 
1152
                //Eran - BEGIN
1027
1153
        case WXK_NUMPAD_INSERT://fall through
1028
 
        //Eran - END
1029
 
    case WXK_INSERT:            key = SCK_INSERT;   break;
1030
 
    case WXK_ESCAPE:            key = SCK_ESCAPE;   break;
1031
 
    case WXK_BACK:              key = SCK_BACK;     break;
1032
 
    case WXK_TAB:               key = SCK_TAB;      break;
1033
 
    case WXK_RETURN:            // fall through
1034
 
    case WXK_NUMPAD_ENTER:      key = SCK_RETURN;   break;
1035
 
    case WXK_ADD:               // fall through
1036
 
    case WXK_NUMPAD_ADD:        key = SCK_ADD;      break;
1037
 
    case WXK_SUBTRACT:          // fall through
1038
 
    case WXK_NUMPAD_SUBTRACT:   key = SCK_SUBTRACT; break;
1039
 
    case WXK_DIVIDE:            // fall through
1040
 
    case WXK_NUMPAD_DIVIDE:     key = SCK_DIVIDE;   break;
1041
 
    case WXK_CONTROL:           key = 0; break;
1042
 
    case WXK_ALT:               key = 0; break;
1043
 
    case WXK_SHIFT:             key = 0; break;
1044
 
    case WXK_MENU:              key = 0; break;
1045
 
    }
 
1154
                //Eran - END
 
1155
        case WXK_INSERT:
 
1156
                key = SCK_INSERT;
 
1157
                break;
 
1158
        case WXK_ESCAPE:
 
1159
                key = SCK_ESCAPE;
 
1160
                break;
 
1161
        case WXK_BACK:
 
1162
                key = SCK_BACK;
 
1163
                break;
 
1164
        case WXK_TAB:
 
1165
                key = SCK_TAB;
 
1166
                break;
 
1167
        case WXK_RETURN:            // fall through
 
1168
        case WXK_NUMPAD_ENTER:
 
1169
                key = SCK_RETURN;
 
1170
                break;
 
1171
        case WXK_ADD:               // fall through
 
1172
        case WXK_NUMPAD_ADD:
 
1173
                key = SCK_ADD;
 
1174
                break;
 
1175
        case WXK_SUBTRACT:          // fall through
 
1176
        case WXK_NUMPAD_SUBTRACT:
 
1177
                key = SCK_SUBTRACT;
 
1178
                break;
 
1179
        case WXK_DIVIDE:            // fall through
 
1180
        case WXK_NUMPAD_DIVIDE:
 
1181
                key = SCK_DIVIDE;
 
1182
                break;
 
1183
        case WXK_CONTROL:
 
1184
                key = 0;
 
1185
                break;
 
1186
        case WXK_ALT:
 
1187
                key = 0;
 
1188
                break;
 
1189
        case WXK_SHIFT:
 
1190
                key = 0;
 
1191
                break;
 
1192
        case WXK_MENU:
 
1193
                key = 0;
 
1194
                break;
 
1195
        }
1046
1196
 
1047
1197
#ifdef __WXMAC__
1048
 
    if ( evt.MetaDown() ) {
1049
 
        // check for a few common Mac Meta-key combos and remap them to Ctrl
1050
 
        // for Scintilla
1051
 
        switch ( key ) {
1052
 
        case 'Z':       // Undo
1053
 
        case 'X':       // Cut
1054
 
        case 'C':       // Copy
1055
 
        case 'V':       // Paste
1056
 
        case 'A':       // Select All
1057
 
            ctrl = true;
1058
 
            break;
1059
 
        }
1060
 
    }
 
1198
        if ( evt.MetaDown() ) {
 
1199
                // check for a few common Mac Meta-key combos and remap them to Ctrl
 
1200
                // for Scintilla
 
1201
                switch ( key ) {
 
1202
                case 'Z':       // Undo
 
1203
                case 'X':       // Cut
 
1204
                case 'C':       // Copy
 
1205
                case 'V':       // Paste
 
1206
                case 'A':       // Select All
 
1207
                        ctrl = true;
 
1208
                        break;
 
1209
                }
 
1210
        }
1061
1211
#endif
1062
1212
 
1063
 
    int rv = KeyDown(key, shift, ctrl, alt, consumed);
 
1213
        int rv = KeyDown(key, shift, ctrl, alt, consumed);
1064
1214
 
1065
 
    if (key)
1066
 
        return rv;
1067
 
    else
1068
 
        return 1;
 
1215
        if (key)
 
1216
                return rv;
 
1217
        else
 
1218
                return 1;
1069
1219
}
1070
1220
 
1071
1221
 
1072
1222
void ScintillaWX::DoCommand(int ID) {
1073
 
    Command(ID);
 
1223
        Command(ID);
1074
1224
}
1075
1225
 
1076
1226
 
1077
1227
void ScintillaWX::DoContextMenu(Point pt) {
1078
 
    if (displayPopupMenu)
1079
 
        ContextMenu(pt);
 
1228
        if (displayPopupMenu)
 
1229
                ContextMenu(pt);
1080
1230
}
1081
1231
 
1082
1232
void ScintillaWX::DoOnListBox() {
1083
 
    AutoCompleteCompleted();
 
1233
        AutoCompleteCompleted();
1084
1234
}
1085
1235
 
1086
1236
 
1087
1237
void ScintillaWX::DoOnIdle(wxIdleEvent& evt) {
1088
1238
 
1089
 
    if ( Idle() )
1090
 
        evt.RequestMore();
1091
 
    else
1092
 
        SetIdle(false);
 
1239
        if ( Idle() )
 
1240
                evt.RequestMore();
 
1241
        else
 
1242
                SetIdle(false);
1093
1243
}
1094
1244
 
1095
1245
//----------------------------------------------------------------------
1096
1246
 
1097
1247
#if wxUSE_DRAG_AND_DROP
1098
1248
bool ScintillaWX::DoDropText(long x, long y, const wxString& data) {
1099
 
    SetDragPosition(SelectionPosition(invalidPosition));
1100
 
 
1101
 
    wxString text = wxTextBuffer::Translate (data, wxConvertEOLMode(pdoc->eolMode));
1102
 
 
1103
 
    // Send an event to allow the drag details to be changed
1104
 
    wxScintillaEvent evt(wxEVT_SCI_DO_DROP, sci->GetId());
1105
 
    evt.SetEventObject(sci);
1106
 
    evt.SetDragResult(dragResult);
1107
 
    evt.SetX(x);
1108
 
    evt.SetY(y);
1109
 
    evt.SetPosition(PositionFromLocation(Point(x,y)));
1110
 
    evt.SetDragText(text);
1111
 
    sci->GetEventHandler()->ProcessEvent(evt);
1112
 
 
1113
 
    dragResult = evt.GetDragResult();
1114
 
    if (dragResult == wxDragMove || dragResult == wxDragCopy) {
1115
 
        DropAt( SelectionPosition(evt.GetPosition()),
1116
 
               wx2sci(evt.GetDragText()),
1117
 
               dragResult == wxDragMove,
1118
 
               dragRectangle);
1119
 
        return true;
1120
 
    }
1121
 
    return false;
 
1249
        SetDragPosition(SelectionPosition(invalidPosition));
 
1250
 
 
1251
        wxString text = wxTextBuffer::Translate (data, wxConvertEOLMode(pdoc->eolMode));
 
1252
 
 
1253
        // Send an event to allow the drag details to be changed
 
1254
        wxScintillaEvent evt(wxEVT_SCI_DO_DROP, sci->GetId());
 
1255
        evt.SetEventObject(sci);
 
1256
        evt.SetDragResult(dragResult);
 
1257
        evt.SetX(x);
 
1258
        evt.SetY(y);
 
1259
        evt.SetPosition(PositionFromLocation(Point(x,y)));
 
1260
        evt.SetDragText(text);
 
1261
        sci->GetEventHandler()->ProcessEvent(evt);
 
1262
 
 
1263
        dragResult = evt.GetDragResult();
 
1264
        if (dragResult == wxDragMove || dragResult == wxDragCopy) {
 
1265
                DropAt( SelectionPosition(evt.GetPosition()),
 
1266
                        wx2sci(evt.GetDragText()),
 
1267
                        dragResult == wxDragMove,
 
1268
                        dragRectangle);
 
1269
                return true;
 
1270
        }
 
1271
        return false;
1122
1272
}
1123
1273
 
1124
1274
 
1125
1275
wxDragResult ScintillaWX::DoDragEnter(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult def) {
1126
 
    dragResult = def;
1127
 
    return dragResult;
 
1276
        dragResult = def;
 
1277
        return dragResult;
1128
1278
}
1129
1279
 
1130
1280
 
1131
1281
wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
1132
 
    SetDragPosition(SelectionPosition( PositionFromLocation(Point(x, y)) ) );
1133
 
 
1134
 
    // Send an event to allow the drag result to be changed
1135
 
    wxScintillaEvent evt(wxEVT_SCI_DRAG_OVER, sci->GetId());
1136
 
    evt.SetEventObject(sci);
1137
 
    evt.SetDragResult(def);
1138
 
    evt.SetX(x);
1139
 
    evt.SetY(y);
1140
 
    evt.SetPosition(PositionFromLocation(Point(x,y)));
1141
 
    sci->GetEventHandler()->ProcessEvent(evt);
1142
 
 
1143
 
    dragResult = evt.GetDragResult();
1144
 
    return dragResult;
 
1282
        SetDragPosition(SelectionPosition( PositionFromLocation(Point(x, y)) ) );
 
1283
 
 
1284
        // Send an event to allow the drag result to be changed
 
1285
        wxScintillaEvent evt(wxEVT_SCI_DRAG_OVER, sci->GetId());
 
1286
        evt.SetEventObject(sci);
 
1287
        evt.SetDragResult(def);
 
1288
        evt.SetX(x);
 
1289
        evt.SetY(y);
 
1290
        evt.SetPosition(PositionFromLocation(Point(x,y)));
 
1291
        sci->GetEventHandler()->ProcessEvent(evt);
 
1292
 
 
1293
        dragResult = evt.GetDragResult();
 
1294
        return dragResult;
1145
1295
}
1146
1296
 
1147
1297
 
1148
1298
void ScintillaWX::DoDragLeave() {
1149
 
    SetDragPosition(SelectionPosition(invalidPosition));
 
1299
        SetDragPosition(SelectionPosition(invalidPosition));
1150
1300
}
1151
1301
#endif
1152
1302
//----------------------------------------------------------------------
1154
1304
// Force the whole window to be repainted
1155
1305
void ScintillaWX::FullPaint() {
1156
1306
#ifndef __WXMAC__
1157
 
    sci->Refresh(false);
 
1307
        sci->Refresh(false);
1158
1308
#endif
1159
 
    sci->Update();
 
1309
        sci->Update();
1160
1310
}
1161
1311
 
1162
1312
 
1163
1313
void ScintillaWX::DoScrollToLine(int line) {
1164
 
    ScrollTo(line);
 
1314
        ScrollTo(line);
1165
1315
}
1166
1316
 
1167
1317
 
1168
1318
void ScintillaWX::DoScrollToColumn(int column) {
1169
 
    HorizontalScrollTo(column * vs.spaceWidth);
 
1319
        HorizontalScrollTo(column * vs.spaceWidth);
1170
1320
}
1171
1321
 
1172
1322
#ifdef __WXGTK__
1173
1323
void ScintillaWX::ClipChildren(wxDC& dc, PRectangle rect) {
1174
1324
// wxGTK > 2.5 doesn't appear to need this explicit clipping code any longer
1175
1325
#if !wxCHECK_VERSION(2, 5, 0)
1176
 
    wxRegion rgn(wxRectFromPRectangle(rect));
1177
 
    if (ac.Active()) {
1178
 
        wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1179
 
        rgn.Subtract(childRect);
1180
 
    }
1181
 
    if (ct.inCallTipMode) {
1182
 
        wxSCICallTip* tip = (wxSCICallTip*)ct.wCallTip.GetID();
1183
 
        wxRect childRect = tip->GetRect();
 
1326
        wxRegion rgn(wxRectFromPRectangle(rect));
 
1327
        if (ac.Active()) {
 
1328
                wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
 
1329
                rgn.Subtract(childRect);
 
1330
        }
 
1331
        if (ct.inCallTipMode) {
 
1332
                wxSCICallTip* tip = (wxSCICallTip*)ct.wCallTip.GetID();
 
1333
                wxRect childRect = tip->GetRect();
1184
1334
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP
1185
 
        childRect.SetPosition(tip->GetMyPosition());
 
1335
                childRect.SetPosition(tip->GetMyPosition());
1186
1336
#endif
1187
 
        rgn.Subtract(childRect);
1188
 
    }
 
1337
                rgn.Subtract(childRect);
 
1338
        }
1189
1339
 
1190
 
    dc.SetClippingRegion(rgn);
 
1340
        dc.SetClippingRegion(rgn);
1191
1341
#endif
1192
1342
}
1193
1343
#else
1197
1347
 
1198
1348
 
1199
1349
void ScintillaWX::SetUseAntiAliasing(bool useAA) {
1200
 
    vs.extraFontFlag = useAA;
1201
 
    InvalidateStyleRedraw();
 
1350
        vs.extraFontFlag = useAA;
 
1351
        InvalidateStyleRedraw();
1202
1352
}
1203
1353
 
1204
1354
bool ScintillaWX::GetUseAntiAliasing() {
1205
 
    return vs.extraFontFlag;
 
1355
        return vs.extraFontFlag;
1206
1356
}
1207
1357
 
1208
1358
//----------------------------------------------------------------------