~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
// Author:      Robin Dunn
10
10
//
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
/////////////////////////////////////////////////////////////////////////////
16
16
 
 
17
// For compilers that support precompilation, includes "wx.h".
 
18
#include <wx/wxprec.h>
 
19
 
 
20
#ifndef WX_PRECOMP
 
21
    #include <wx/scrolbar.h>
 
22
    #include <wx/menu.h>
 
23
    #include <wx/timer.h>
 
24
#endif // WX_PRECOMP
 
25
 
 
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"
 
32
 
22
33
#ifdef __WXMSW__
23
 
#include <wx/msw/private.h> // GetHwndOf()
 
34
    // GetHwndOf()
 
35
    #include <wx/msw/private.h>
24
36
#endif
25
37
 
26
38
//----------------------------------------------------------------------
29
41
class wxSCITimer : public wxTimer {
30
42
public:
31
43
    wxSCITimer(ScintillaWX* swx) {
32
 
        this->swx = swx;
 
44
        m_swx = swx;
33
45
    }
34
46
 
35
47
    void Notify() {
36
 
        swx->DoTick();
 
48
        m_swx->DoTick();
37
49
    }
38
50
 
39
51
private:
40
 
    ScintillaWX* swx;
 
52
    ScintillaWX* m_swx;
41
53
};
42
54
 
43
55
 
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);
47
59
}
48
60
 
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);
51
63
}
52
64
 
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);
55
67
}
56
68
 
57
69
void  wxSCIDropTarget::OnLeave() {
58
 
    swx->DoDragLeave();
 
70
    m_swx->DoDragLeave();
59
71
}
60
 
#endif
61
 
 
62
 
 
63
 
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP
 
72
#endif // wxUSE_DRAG_AND_DROP
 
73
 
 
74
//--------------------------------------------------------------------------
 
75
 
 
76
#if wxUSE_POPUPWIN
64
77
#include <wx/popupwin.h>
65
78
#define wxSCICallTipBase wxPopupWindow
66
 
#define param2  wxBORDER_NONE  // popup's 2nd param is flags
67
79
#else
68
 
#define wxSCICallTipBase wxWindow
69
 
#define param2 -1 // wxWindow's 2nd param is ID
 
80
#include <wx/frame.h>
 
81
#define wxSCICallTipBase wxFrame
70
82
#endif
71
83
 
 
84
#include "wx/panel.h"
72
85
#include <wx/dcbuffer.h>
73
86
 
74
 
class wxSCICallTip : public wxSCICallTipBase {
 
87
 
 
88
class wxSCICallTipContent : public wxPanel {
75
89
public:
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)
79
 
        {
80
 
        }
81
 
 
82
 
    ~wxSCICallTip() {
83
 
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP && defined(__WXGTK__)
84
 
        wxRect rect = GetRect();
85
 
        rect.x = m_cx;
86
 
        rect.y = m_cy;
87
 
        GetParent()->Refresh(false, &rect);
88
 
#endif
 
90
    wxSCICallTipContent(wxWindow* parent, CallTip* ct, ScintillaWX* swx)
 
91
        : wxPanel(parent, -1),
 
92
          m_ct(ct), m_swx(swx)
 
93
    {
 
94
        SetBackgroundStyle(wxBG_STYLE_CUSTOM);
89
95
    }
90
96
 
91
97
    bool AcceptsFocus() const { return false; }
92
98
 
93
 
    void OnPaint(wxPaintEvent& WXUNUSED(evt)) {
94
 
        wxBufferedPaintDC dc(this);
 
99
    void OnPaint(wxPaintEvent& WXUNUSED(evt))
 
100
    {
 
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;
100
107
    }
101
108
 
102
 
    void OnFocus(wxFocusEvent& event) {
103
 
        GetParent()->SetFocus();
 
109
    void OnFocus(wxFocusEvent& event)
 
110
    {
 
111
        GetGrandParent()->SetFocus();
104
112
        event.Skip();
105
113
    }
106
114
 
107
 
    void OnLeftDown(wxMouseEvent& event) {
 
115
    void OnLeftDown(wxMouseEvent& event)
 
116
    {
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();
112
121
    }
113
122
 
114
 
#if wxUSE_POPUPWIN && wxSCI_USE_POPUP
 
123
private:
 
124
    CallTip*      m_ct;
 
125
    ScintillaWX*  m_swx;
 
126
    DECLARE_EVENT_TABLE()
 
127
};
 
128
 
 
129
 
 
130
BEGIN_EVENT_TABLE(wxSCICallTipContent, wxPanel)
 
131
    EVT_PAINT(wxSCICallTipContent::OnPaint)
 
132
    EVT_SET_FOCUS(wxSCICallTipContent::OnFocus)
 
133
    EVT_LEFT_DOWN(wxSCICallTipContent::OnLeftDown)
 
134
END_EVENT_TABLE()
 
135
 
 
136
 
 
137
 
 
138
class wxSCICallTip : public wxSCICallTipBase {
 
139
public:
 
140
    wxSCICallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx) :
 
141
#if wxUSE_POPUPWIN
 
142
        wxSCICallTipBase(parent, wxBORDER_NONE),
 
143
#else
 
144
        wxSCICallTipBase(parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
 
145
                         wxFRAME_NO_TASKBAR
 
146
                         | wxFRAME_FLOAT_ON_PARENT
 
147
                         | wxBORDER_NONE
 
148
#ifdef __WXMAC__
 
149
                         | wxPOPUP_WINDOW
 
150
#endif
 
151
            ),
 
152
#endif
 
153
        m_cx(wxDefaultCoord), m_cy(wxDefaultCoord)
 
154
        {
 
155
            m_content = new wxSCICallTipContent(this, ct, swx);
 
156
        }
 
157
 
 
158
    ~wxSCICallTip() {
 
159
#if wxUSE_POPUPWIN && defined(__WXGTK__)
 
160
        wxRect rect = GetRect();
 
161
        rect.x = m_cx;
 
162
        rect.y = m_cy;
 
163
        GetParent()->Refresh(false, &rect);
 
164
#endif
 
165
    }
 
166
 
 
167
    bool AcceptsFocus() const { return false; }
 
168
 
115
169
    virtual void DoSetSize(int x, int y,
116
170
                           int width, int height,
117
 
                           int sizeFlags = wxSIZE_AUTO) {
118
 
        if (x != -1) {
 
171
                           int sizeFlags = wxSIZE_AUTO)
 
172
    {
 
173
        // convert coords to screen coords since we're a top-level window
 
174
        if (x != wxDefaultCoord) {
119
175
            m_cx = x;
120
176
            GetParent()->ClientToScreen(&x, NULL);
121
177
        }
122
 
        if (y != -1) {
 
178
        if (y != wxDefaultCoord) {
123
179
            m_cy = y;
124
180
            GetParent()->ClientToScreen(NULL, &y);
125
181
        }
126
182
        wxSCICallTipBase::DoSetSize(x, y, width, height, sizeFlags);
 
183
 
 
184
        m_content->SetSize(0, 0, width, height, sizeFlags);
 
185
    }
 
186
 
 
187
#if wxUSE_POPUPWIN
 
188
#else
 
189
    virtual bool Show( bool show = true )
 
190
    {
 
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);
 
194
        if (rv && show)
 
195
        {
 
196
            wxTopLevelWindow *frame = wxDynamicCast(
 
197
                wxGetTopLevelParent(GetParent()), wxTopLevelWindow);
 
198
            if (frame)
 
199
                frame->Raise();
 
200
        }
 
201
        return rv;
127
202
    }
128
203
#endif
129
204
 
130
 
    wxPoint GetMyPosition() {
 
205
    wxPoint GetMyPosition()
 
206
    {
131
207
        return wxPoint(m_cx, m_cy);
132
208
    }
133
209
 
134
210
private:
135
 
    CallTip*      m_ct;
136
 
    ScintillaWX*  m_swx;
137
211
    int           m_cx, m_cy;
138
 
    DECLARE_EVENT_TABLE()
 
212
    wxSCICallTipContent* m_content;
139
213
};
140
214
 
141
 
BEGIN_EVENT_TABLE(wxSCICallTip, wxSCICallTipBase)
142
 
    EVT_PAINT(wxSCICallTip::OnPaint)
143
 
    EVT_SET_FOCUS(wxSCICallTip::OnFocus)
144
 
    EVT_LEFT_DOWN(wxSCICallTip::OnLeftDown)
145
 
END_EVENT_TABLE()
146
215
 
147
216
 
148
217
//----------------------------------------------------------------------
173
242
}
174
243
#endif // wxUSE_DATAOBJ
175
244
 
 
245
 
 
246
static int wxCountLines(const char* text, int scintillaMode)
 
247
{
 
248
    char eolchar;
 
249
 
 
250
    switch (scintillaMode) {
 
251
        case wxSCI_EOL_CRLF:
 
252
        case wxSCI_EOL_LF:
 
253
            eolchar = '\n';
 
254
            break;
 
255
        case wxSCI_EOL_CR:
 
256
            eolchar = '\r';
 
257
            break;
 
258
        default:
 
259
            return 0;
 
260
    }
 
261
 
 
262
    int count = 0;
 
263
    int i     = 0;
 
264
    while (text[i] != 0) {
 
265
        if (text[i] == eolchar) {
 
266
            count++;
 
267
        }
 
268
        i++;
 
269
    }
 
270
 
 
271
    return count;
 
272
}
 
273
 
176
274
//----------------------------------------------------------------------
177
275
// Constructor/Destructor
178
276
 
185
283
    wheelRotation = 0;
186
284
    Initialise();
187
285
#ifdef __WXMSW__
188
 
#if wxCHECK_VERSION(2, 5, 0)
189
286
    sysCaretBitmap = 0;
190
287
    sysCaretWidth = 0;
191
288
    sysCaretHeight = 0;
192
289
#endif
193
 
#endif
194
290
}
195
291
 
196
292
 
198
294
    Finalise();
199
295
}
200
296
 
 
297
 
201
298
//----------------------------------------------------------------------
202
299
// base class virtuals
203
300
 
208
305
    dropTarget = new wxSCIDropTarget;
209
306
    dropTarget->SetScintilla(this);
210
307
    sci->SetDropTarget(dropTarget);
211
 
#endif
212
 
#ifdef __WXMAC__
213
 
    vs.extraFontFlag = false;  // UseAntiAliasing
214
 
#else
215
 
    vs.extraFontFlag = true;   // UseAntiAliasing
216
 
#endif
 
308
    dragRectangle = false;
 
309
#endif // wxUSE_DRAG_AND_DROP
217
310
}
218
311
 
219
312
 
227
320
 
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);
231
324
 
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);
 
329
/* C::B begin */
 
330
    evt.SetDragAllowMove(wxDrag_DefaultMove);
 
331
/* C::B end */
 
332
    evt.SetPosition (wxMin(sci->GetSelectionStart(),
 
333
                               sci->GetSelectionEnd()));
 
334
    sci->GetEventHandler()->ProcessEvent (evt);
 
335
    UndoGroup ug(pdoc);
 
336
 
240
337
    dragText = evt.GetDragText();
241
 
 
 
338
    dragRectangle = drag.rectangular;
242
339
    if (dragText.Length()) {
243
340
        wxDropSource        source(sci);
244
341
        wxTextDataObject    data(dragText);
246
343
 
247
344
        source.SetData(data);
248
345
        dropWentOutside = true;
 
346
        inDragDrop = ddDragging;
249
347
        result = source.DoDragDrop(evt.GetDragAllowMove());
250
348
        if (result == wxDragMove && dropWentOutside)
251
349
            ClearSelection();
252
 
        inDragDrop = false;
253
 
        SetDragPosition(invalidPosition);
 
350
        inDragDrop = ddNone;
 
351
        SetDragPosition (SelectionPosition(invalidPosition));
254
352
    }
255
 
#endif
 
353
#endif // wxUSE_DRAG_AND_DROP
256
354
}
257
355
 
258
356
 
260
358
    if (idler.state != on) {
261
359
        // connect or disconnect the EVT_IDLE handler
262
360
        if (on)
263
 
            sci->Connect(wxID_ANY, wxEVT_IDLE,
264
 
                         (wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxScintilla::OnIdle);
 
361
            sci->Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(wxScintilla::OnIdle));
265
362
        else
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;
269
365
    }
270
366
    return idler.state;
399
495
}
400
496
 
401
497
 
 
498
void ScintillaWX::NotifyFocus(bool focus) {
 
499
    sci->NotifyFocus(focus);
 
500
}
 
501
 
 
502
 
402
503
void ScintillaWX::NotifyChange() {
403
504
    sci->NotifyChange();
404
505
}
423
524
 
424
525
 
425
526
void ScintillaWX::Copy() {
426
 
    if (currentPos != anchor) {
 
527
    if (!SelectionEmpty()) {
427
528
        SelectionText st;
428
529
        CopySelectionRange(&st);
429
 
        CopyToClipboard(st);
 
530
#ifdef __WXGTK__
 
531
                for(int i=0; i<5; i++) {
 
532
                        //wxPrintf(wxT("Copying to clipboard %ld\n"), i);
 
533
                CopyToClipboard(st);
 
534
                }
 
535
#else
 
536
        CopyToClipboard(st);
 
537
#endif
430
538
    }
431
539
}
432
540
 
433
541
 
434
542
void ScintillaWX::Paste() {
435
 
    pdoc->BeginUndoAction();
 
543
    UndoGroup ug(pdoc);
 
544
        // Selection::First
 
545
    SelectionPosition firstPosition = SelectionStart();
 
546
    if(sel.IsRectangular() && !sel.Empty()) {
 
547
        for (size_t i=0; i<sel.Count()-1; i++) {
 
548
            sel.RotateMain();
 
549
            if(firstPosition > SelectionStart())
 
550
                firstPosition = SelectionStart();
 
551
        }
 
552
    }
436
553
    ClearSelection();
437
554
 
438
555
#if wxUSE_DATAOBJ
439
556
    wxTextDataObject data;
440
 
    bool gotData = false;
 
557
    wxString textString;
 
558
 
 
559
    wxWX2MBbuf buf;
 
560
    int   len  = 0;
 
561
    bool  rectangular = false;
441
562
 
442
563
    if (wxTheClipboard->Open()) {
443
564
        wxTheClipboard->UsePrimarySelection(false);
444
 
        gotData = wxTheClipboard->GetData(data);
 
565
/* C::B begin */
 
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);
 
569
/* C::B end */
 
570
        bool gotRectData = wxTheClipboard->GetData(selData);
 
571
 
 
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);
 
579
            delete [] buffer;
 
580
        } else {
 
581
            bool gotData = wxTheClipboard->GetData(data);
 
582
            if (gotData) {
 
583
                textString = wxTextBuffer::Translate (data.GetText(),
 
584
                                                      wxConvertEOLMode(pdoc->eolMode));
 
585
            }
 
586
        }
 
587
        data.SetText(wxEmptyString); // free the data object content
445
588
        wxTheClipboard->Close();
446
589
    }
447
 
    if (gotData) {
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);
 
590
 
 
591
    buf = (wxWX2MBbuf)wx2sci(textString);
 
592
    len  = strlen(buf);
 
593
    int newPos = 0;
 
594
    int caretMain = CurrentPosition();
 
595
    if (rectangular) {
 
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);
 
601
    } else {
 
602
        pdoc->InsertString (caretMain, buf, len);
 
603
        newPos = caretMain + len;
454
604
    }
 
605
    SetEmptySelection (newPos);
455
606
#endif // wxUSE_DATAOBJ
456
607
 
457
 
    pdoc->EndUndoAction();
458
608
    NotifyChange();
459
609
    Redraw();
460
610
}
461
611
 
462
612
 
463
 
void ScintillaWX::CopyToClipboard(const SelectionText& st) {
 
613
void ScintillaWX::CopyToClipboard (const SelectionText& st) {
464
614
#if wxUSE_CLIPBOARD
 
615
    if ( !st.len )
 
616
        return;
 
617
 
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));
 
621
 
 
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
 
624
        // rectangular).
 
625
        wxDataObjectComposite* obj = new wxDataObjectComposite();
 
626
        wxCustomDataObject* rectData = new wxCustomDataObject (wxDataFormat(wxString(wxT("application/x-cbrectdata"))));
 
627
 
 
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);
 
632
        delete [] buffer;
 
633
 
 
634
        obj->Add (rectData, true);
 
635
        obj->Add (new wxTextDataObject (text));
 
636
        wxTheClipboard->SetData (obj);
469
637
        wxTheClipboard->Close();
470
638
    }
471
639
#else
548
716
            DestroySystemCaret();
549
717
            CreateSystemCaret();
550
718
        }
551
 
        Point pos = LocationFromPosition(currentPos);
552
 
#if wxCHECK_VERSION(2, 5, 0)
 
719
        Point pos = LocationFromPosition(CurrentPosition());
553
720
        ::SetCaretPos(pos.x, pos.y);
554
 
#endif
555
721
    }
556
722
#endif
557
723
}
559
725
 
560
726
bool ScintillaWX::HasCaretSizeChanged() {
561
727
#ifdef __WXMSW__
562
 
#if !wxCHECK_VERSION(2, 5, 0)
563
 
    return false;
564
 
#else
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) ) ) {
567
730
        return true;
568
731
    }
569
732
#endif
570
 
#endif
571
733
    return false;
572
734
}
573
735
 
574
736
bool ScintillaWX::CreateSystemCaret() {
575
737
#ifdef __WXMSW__
576
 
#if !wxCHECK_VERSION(2, 5, 0)
577
 
    return false;
578
 
#else
579
738
    sysCaretWidth = vs.caretWidth;
580
739
    if (0 == sysCaretWidth) {
581
740
        sysCaretWidth = 1;
591
750
                                sysCaretWidth, sysCaretHeight);
592
751
    ::ShowCaret(GetHwndOf(sci));
593
752
    return retval != 0;
594
 
#endif
595
753
#else
596
754
    return false;
597
755
#endif
599
757
 
600
758
bool ScintillaWX::DestroySystemCaret() {
601
759
#ifdef __WXMSW__
602
 
#if !wxCHECK_VERSION(2, 5, 0)
603
 
    return false;
604
 
#else
605
760
    ::HideCaret(GetHwndOf(sci));
606
761
    BOOL retval = ::DestroyCaret();
607
762
    if (sysCaretBitmap) {
609
764
        sysCaretBitmap = 0;
610
765
    }
611
766
    return retval != 0;
612
 
#endif
613
767
#else
614
768
    return false;
615
769
#endif
618
772
 
619
773
//----------------------------------------------------------------------
620
774
 
621
 
long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
 
775
sptr_t ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t /*wParam*/, sptr_t /*lParam*/) {
622
776
    return 0;
623
777
}
624
778
 
625
 
long ScintillaWX::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) {
 
779
sptr_t ScintillaWX::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
626
780
      switch (iMessage) {
627
781
      case SCI_CALLTIPSHOW: {
628
782
          // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
633
787
          char* defn = reinterpret_cast<char *>(lParam);
634
788
          AutoCompleteCancel();
635
789
          pt.y += vs.lineHeight;
636
 
          PRectangle rc = ct.CallTipStart(currentPos, pt,
 
790
/* C::B begin */
 
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,
637
796
                                          defn,
638
 
                                          vs.styles[STYLE_DEFAULT].fontName,
639
 
                                          vs.styles[STYLE_DEFAULT].sizeZoomed,
 
797
                                          vs.styles[ctStyle].fontName,
 
798
                                          vs.styles[ctStyle].sizeZoomed,
640
799
                                          CodePage(),
641
 
                                          vs.styles[STYLE_DEFAULT].characterSet,
 
800
                                          vs.styles[ctStyle].characterSet,
642
801
                                          wMain);
 
802
/* C::B end */
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();
659
819
          break;
660
820
      }
661
 
/*? TODO
 
821
 
 
822
      case SCI_GETDIRECTFUNCTION:
 
823
            return reinterpret_cast<sptr_t>(DirectFunction);
 
824
 
 
825
      case SCI_GETDIRECTPOINTER:
 
826
            return reinterpret_cast<sptr_t>(this);
 
827
 
 
828
      case SCI_GRABFOCUS:
 
829
            sci->SetFocus();
 
830
            break;
 
831
 
662
832
#ifdef SCI_LEXER
663
833
      case SCI_LOADLEXERLIBRARY:
664
834
            LexerManager::GetInstance()->Load((const char*)lParam);
665
835
            break;
666
 
#endif ?*/
 
836
#endif
 
837
 
667
838
      default:
668
839
          return ScintillaBase::WndProc(iMessage, wParam, lParam);
669
840
      }
670
841
      return 0;
671
842
}
672
843
 
 
844
sptr_t ScintillaWX::DirectFunction(ScintillaWX *wxsci, unsigned int iMessage, uptr_t wParam, sptr_t lParam)
 
845
{
 
846
        return wxsci->WndProc(iMessage, wParam, lParam);
 
847
}
673
848
 
674
849
 
675
850
//----------------------------------------------------------------------
684
859
    PRectangle rcClient = GetClientRectangle();
685
860
    paintingAllText = rcPaint.Contains(rcClient);
686
861
 
687
 
//    dc->BeginDrawing(); // Deprecated - it's an empty function anyway
688
862
    ClipChildren(*dc, rcPaint);
689
863
    Paint(surfaceWindow, rcPaint);
690
864
 
695
869
        FullPaint();
696
870
    }
697
871
    paintState = notPainting;
698
 
//    dc->EndDrawing(); // Deprecated - it's an empty function anyway
699
872
}
700
873
 
701
874
 
785
958
    focusEvent = true;
786
959
    SetFocusState(false);
787
960
    focusEvent = false;
 
961
    SetMouseCapture(false);
788
962
    DestroySystemCaret();
789
963
}
790
964
 
817
991
    // Set the current position to the mouse click point and
818
992
    // then paste in the PRIMARY selection, if any.  wxGTK only.
819
993
    int newPos = PositionFromLocation(pt);
820
 
    MovePositionTo(newPos, noSel, true);
 
994
    MovePositionTo(newPos, Selection::noSel, true);
821
995
 
822
 
    pdoc->BeginUndoAction();
 
996
    UndoGroup ug(pdoc);
823
997
    wxTextDataObject data;
824
998
    bool gotData = false;
825
999
    if (wxTheClipboard->Open()) {
829
1003
        wxTheClipboard->Close();
830
1004
    }
831
1005
    if (gotData) {
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);
838
1013
    }
839
 
    pdoc->EndUndoAction();
840
1014
    NotifyChange();
841
1015
    Redraw();
842
1016
 
873
1047
        key += 'A' - 1;
874
1048
 
875
1049
    switch (key) {
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
891
1065
#endif
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
897
1071
#endif
898
1072
    case WXK_PAGEDOWN:          // fall through
904
1078
    case WXK_ESCAPE:            key = SCK_ESCAPE;   break;
905
1079
    case WXK_BACK:              key = SCK_BACK;     break;
906
1080
    case WXK_TAB:               key = SCK_TAB;      break;
907
 
    case WXK_NUMPAD_ENTER:      // fall through
908
 
    case WXK_RETURN:            key = SCK_RETURN;   break;
 
1081
    case WXK_RETURN:            // fall through
 
1082
    case WXK_NUMPAD_ENTER:      key = SCK_RETURN;   break;
909
1083
    case WXK_ADD:               // fall through
910
1084
    case WXK_NUMPAD_ADD:        key = SCK_ADD;      break;
911
1085
    case WXK_SUBTRACT:          // fall through
970
1144
 
971
1145
#if wxUSE_DRAG_AND_DROP
972
1146
bool ScintillaWX::DoDropText(long x, long y, const wxString& data) {
973
 
    SetDragPosition(invalidPosition);
 
1147
    SetDragPosition(SelectionPosition(invalidPosition));
974
1148
 
975
 
    wxString text = wxTextBuffer::Translate(data,
976
 
                                            wxConvertEOLMode(pdoc->eolMode));
 
1149
    wxString text = wxTextBuffer::Translate (data, wxConvertEOLMode(pdoc->eolMode));
977
1150
 
978
1151
    // Send an event to allow the drag details to be changed
979
1152
    wxScintillaEvent evt(wxEVT_SCI_DO_DROP, sci->GetId());
987
1160
 
988
1161
    dragResult = evt.GetDragResult();
989
1162
    if (dragResult == wxDragMove || dragResult == wxDragCopy) {
990
 
        DropAt(evt.GetPosition(),
 
1163
        DropAt(SelectionPosition(evt.GetPosition()),
991
1164
               wx2sci(evt.GetDragText()),
992
1165
               dragResult == wxDragMove,
993
 
               false); // TODO: rectangular?
 
1166
               dragRectangle);
994
1167
        return true;
995
1168
    }
996
1169
    return false;
1004
1177
 
1005
1178
 
1006
1179
wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
1007
 
    SetDragPosition(PositionFromLocation(Point(x, y)));
 
1180
    SetDragPosition(SelectionPosition(PositionFromLocation(Point(x, y))));
1008
1181
 
1009
1182
    // Send an event to allow the drag result to be changed
1010
1183
    wxScintillaEvent evt(wxEVT_SCI_DRAG_OVER, sci->GetId());
1021
1194
 
1022
1195
 
1023
1196
void ScintillaWX::DoDragLeave() {
1024
 
    SetDragPosition(invalidPosition);
 
1197
    SetDragPosition(SelectionPosition(invalidPosition));
1025
1198
}
1026
 
#endif
 
1199
#endif // wxUSE_DRAG_AND_DROP
1027
1200
//----------------------------------------------------------------------
1028
1201
 
1029
1202
// Force the whole window to be repainted
1044
1217
    HorizontalScrollTo(column * vs.spaceWidth);
1045
1218
}
1046
1219
 
1047
 
#ifdef __WXGTK__
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));
1052
 
    if (ac.Active()) {
1053
 
        wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1054
 
        rgn.Subtract(childRect);
1055
 
    }
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());
1061
 
#endif
1062
 
        rgn.Subtract(childRect);
1063
 
    }
1064
 
 
1065
 
    dc.SetClippingRegion(rgn);
1066
 
#endif
1067
 
}
1068
 
#else
1069
 
void ScintillaWX::ClipChildren(wxDC& WXUNUSED(dc), PRectangle WXUNUSED(rect)) {
1070
 
}
1071
 
#endif
1072
 
 
1073
 
 
1074
 
void ScintillaWX::SetUseAntiAliasing(bool useAA) {
1075
 
    vs.extraFontFlag = useAA;
1076
 
    InvalidateStyleRedraw();
1077
 
}
1078
 
 
1079
 
bool ScintillaWX::GetUseAntiAliasing() {
1080
 
    return vs.extraFontFlag;
1081
 
}
 
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))
 
1223
{
 
1224
//     wxRegion rgn(wxRectFromPRectangle(rect));
 
1225
//     if (ac.Active()) {
 
1226
//         wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
 
1227
//         rgn.Subtract(childRect);
 
1228
//     }
 
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());
 
1234
// #endif
 
1235
//         rgn.Subtract(childRect);
 
1236
//     }
 
1237
//     dc.SetClippingRegion(rgn);
 
1238
}
 
1239
 
1082
1240
 
1083
1241
//----------------------------------------------------------------------
1084
1242
//----------------------------------------------------------------------