~haaaad/geany/master

« back to all changes in this revision

Viewing changes to scintilla/src/ViewStyle.cxx

  • Committer: elextr
  • Author(s): Colomban Wendling
  • Date: 2017-07-24 23:24:05 UTC
  • Revision ID: git-v1:18360460abb4f4bec23dff127031ecf4e9120f7f
Update Scintilla to version 3.7.5 (#1503)

* Update Scintilla to version 3.7.5

This now requires a C++11-capable compiler.

Closes #1308.

* Test using newer dist on Travis

Since Scintilla needs C++11

* Add debugging code for when configure fails

* Workaround a pkg-config-corsswrapper bug on Ubuntu 14.04

See https://bugs.launchpad.net/ubuntu/+source/mingw-w64/+bug/1327242

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
6
6
// The License.txt file describes the conditions under which this software may be distributed.
7
7
 
8
 
#include <string.h>
9
 
#include <assert.h>
 
8
#include <cstddef>
 
9
#include <cassert>
 
10
#include <cstring>
10
11
 
11
12
#include <stdexcept>
12
13
#include <vector>
13
14
#include <map>
 
15
#include <algorithm>
 
16
#include <memory>
14
17
 
15
18
#include "Platform.h"
16
19
 
17
20
#include "Scintilla.h"
18
21
#include "Position.h"
19
 
#include "SplitVector.h"
20
 
#include "Partitioning.h"
21
 
#include "RunStyles.h"
 
22
#include "UniqueString.h"
22
23
#include "Indicator.h"
23
24
#include "XPM.h"
24
25
#include "LineMarker.h"
29
30
using namespace Scintilla;
30
31
#endif
31
32
 
32
 
MarginStyle::MarginStyle() :
33
 
        style(SC_MARGIN_SYMBOL), width(0), mask(0), sensitive(false), cursor(SC_CURSORREVERSEARROW) {
 
33
MarginStyle::MarginStyle(int style_, int width_, int mask_) :
 
34
        style(style_), width(width_), mask(mask_), sensitive(false), cursor(SC_CURSORREVERSEARROW) {
34
35
}
35
36
 
36
37
// A list of the fontnames - avoids wasting space in each style
42
43
}
43
44
 
44
45
void FontNames::Clear() {
45
 
        for (std::vector<char *>::const_iterator it=names.begin(); it != names.end(); ++it) {
46
 
                delete []*it;
47
 
        }
48
46
        names.clear();
49
47
}
50
48
 
51
49
const char *FontNames::Save(const char *name) {
52
50
        if (!name)
53
 
                return 0;
 
51
                return nullptr;
54
52
 
55
 
        for (std::vector<char *>::const_iterator it=names.begin(); it != names.end(); ++it) {
56
 
                if (strcmp(*it, name) == 0) {
57
 
                        return *it;
 
53
        for (const UniqueString &nm : names) {
 
54
                if (strcmp(nm.get(), name) == 0) {
 
55
                        return nm.get();
58
56
                }
59
57
        }
60
 
        const size_t lenName = strlen(name) + 1;
61
 
        char *nameSave = new char[lenName];
62
 
        memcpy(nameSave, name, lenName);
63
 
        names.push_back(nameSave);
64
 
        return nameSave;
 
58
 
 
59
        names.push_back(UniqueStringCopy(name));
 
60
        return names.back().get();
65
61
}
66
62
 
67
63
FontRealised::FontRealised() {
83
79
 
84
80
        ascent = static_cast<unsigned int>(surface.Ascent(font));
85
81
        descent = static_cast<unsigned int>(surface.Descent(font));
 
82
        capitalHeight = surface.Ascent(font) - surface.InternalLeading(font);
86
83
        aveCharWidth = surface.AverageCharWidth(font);
87
84
        spaceWidth = surface.WidthChar(font, ' ');
88
85
}
89
86
 
90
 
ViewStyle::ViewStyle() {
 
87
ViewStyle::ViewStyle() : markers(MARKER_MAX + 1), indicators(INDIC_MAX + 1) {
91
88
        Init();
92
89
}
93
90
 
94
 
ViewStyle::ViewStyle(const ViewStyle &source) {
 
91
// Copy constructor only called when printing copies the screen ViewStyle so it can be
 
92
// modified for printing styles.
 
93
ViewStyle::ViewStyle(const ViewStyle &source) : markers(MARKER_MAX + 1), indicators(INDIC_MAX + 1) {
95
94
        Init(source.styles.size());
96
 
        for (unsigned int sty=0; sty<source.styles.size(); sty++) {
97
 
                styles[sty] = source.styles[sty];
98
 
                // Can't just copy fontname as its lifetime is relative to its owning ViewStyle
 
95
        styles = source.styles;
 
96
        for (size_t sty=0; sty<source.styles.size(); sty++) {
 
97
                // Can't just copy fontName as its lifetime is relative to its owning ViewStyle
99
98
                styles[sty].fontName = fontNames.Save(source.styles[sty].fontName);
100
99
        }
101
100
        nextExtendedStyle = source.nextExtendedStyle;
102
 
        for (int mrk=0; mrk<=MARKER_MAX; mrk++) {
103
 
                markers[mrk] = source.markers[mrk];
104
 
        }
 
101
        markers = source.markers;
105
102
        CalcLargestMarkerHeight();
106
 
        indicatorsDynamic = 0;
107
 
        indicatorsSetFore = 0;
108
 
        for (int ind=0; ind<=INDIC_MAX; ind++) {
109
 
                indicators[ind] = source.indicators[ind];
110
 
                if (indicators[ind].IsDynamic())
111
 
                        indicatorsDynamic++;
112
 
                if (indicators[ind].OverridesTextFore())
113
 
                        indicatorsSetFore++;
114
 
        }
 
103
 
 
104
        indicators = source.indicators;
 
105
 
 
106
        indicatorsDynamic = source.indicatorsDynamic;
 
107
        indicatorsSetFore = source.indicatorsSetFore;
115
108
 
116
109
        selColours = source.selColours;
117
110
        selAdditionalForeground = source.selAdditionalForeground;
135
128
        selbarlight = source.selbarlight;
136
129
        caretcolour = source.caretcolour;
137
130
        additionalCaretColour = source.additionalCaretColour;
 
131
        caretLineFrame = source.caretLineFrame;
138
132
        showCaretLineBackground = source.showCaretLineBackground;
139
133
        alwaysShowCaretLineBackground = source.alwaysShowCaretLineBackground;
140
134
        caretLineBackground = source.caretLineBackground;
185
179
 
186
180
ViewStyle::~ViewStyle() {
187
181
        styles.clear();
188
 
        for (FontMap::iterator it = fonts.begin(); it != fonts.end(); ++it) {
189
 
                delete it->second;
190
 
        }
191
182
        fonts.clear();
192
183
}
193
184
 
195
186
        fixedColumnWidth = marginInside ? leftMarginWidth : 0;
196
187
        maskInLine = 0xffffffff;
197
188
        int maskDefinedMarkers = 0;
198
 
        for (size_t margin = 0; margin < ms.size(); margin++) {
199
 
                fixedColumnWidth += ms[margin].width;
200
 
                if (ms[margin].width > 0)
201
 
                        maskInLine &= ~ms[margin].mask;
202
 
                maskDefinedMarkers |= ms[margin].mask;
 
189
        for (const MarginStyle &m : ms) {
 
190
                fixedColumnWidth += m.width;
 
191
                if (m.width > 0)
 
192
                        maskInLine &= ~m.mask;
 
193
                maskDefinedMarkers |= m.mask;
203
194
        }
204
195
        maskDrawInText = 0;
205
196
        for (int markBit = 0; markBit < 32; markBit++) {
231
222
        indicators[2] = Indicator(INDIC_PLAIN, ColourDesired(0xff, 0, 0));
232
223
 
233
224
        technology = SC_TECHNOLOGY_DEFAULT;
234
 
        indicatorsDynamic = 0;
235
 
        indicatorsSetFore = 0;
 
225
        indicatorsDynamic = false;
 
226
        indicatorsSetFore = false;
236
227
        lineHeight = 1;
237
228
        lineOverlap = 0;
238
229
        maxAscent = 1;
263
254
        styles[STYLE_LINENUMBER].back = Platform::Chrome();
264
255
        caretcolour = ColourDesired(0, 0, 0);
265
256
        additionalCaretColour = ColourDesired(0x7f, 0x7f, 0x7f);
 
257
        caretLineFrame = 0;
266
258
        showCaretLineBackground = false;
267
259
        alwaysShowCaretLineBackground = false;
268
260
        caretLineBackground = ColourDesired(0xff, 0xff, 0);
280
272
        leftMarginWidth = 1;
281
273
        rightMarginWidth = 1;
282
274
        ms.resize(SC_MAX_MARGIN + 1);
283
 
        ms[0].style = SC_MARGIN_NUMBER;
284
 
        ms[0].width = 0;
285
 
        ms[0].mask = 0;
286
 
        ms[1].style = SC_MARGIN_SYMBOL;
287
 
        ms[1].width = 16;
288
 
        ms[1].mask = ~SC_MASK_FOLDERS;
289
 
        ms[2].style = SC_MARGIN_SYMBOL;
290
 
        ms[2].width = 0;
291
 
        ms[2].mask = 0;
 
275
        ms[0] = MarginStyle(SC_MARGIN_NUMBER);
 
276
        ms[1] = MarginStyle(SC_MARGIN_SYMBOL, 16, ~SC_MASK_FOLDERS);
 
277
        ms[2] = MarginStyle(SC_MARGIN_SYMBOL);
292
278
        marginInside = true;
293
279
        CalculateMarginWidthAndMask();
294
280
        textStart = marginInside ? fixedColumnWidth : leftMarginWidth;
324
310
}
325
311
 
326
312
void ViewStyle::Refresh(Surface &surface, int tabInChars) {
327
 
        for (FontMap::iterator it = fonts.begin(); it != fonts.end(); ++it) {
328
 
                delete it->second;
329
 
        }
330
313
        fonts.clear();
331
314
 
332
315
        selbar = Platform::Chrome();
333
316
        selbarlight = Platform::ChromeHighlight();
334
317
 
335
 
        for (unsigned int i=0; i<styles.size(); i++) {
336
 
                styles[i].extraFontFlag = extraFontFlag;
 
318
        // Apply the extra font flag which controls text drawing quality to each style.
 
319
        for (Style &style : styles) {
 
320
                style.extraFontFlag = extraFontFlag;
337
321
        }
338
 
 
 
322
        
 
323
        // Create a FontRealised object for each unique font in the styles.
339
324
        CreateAndAddFont(styles[STYLE_DEFAULT]);
340
 
        for (unsigned int j=0; j<styles.size(); j++) {
341
 
                CreateAndAddFont(styles[j]);
342
 
        }
343
 
 
344
 
        for (FontMap::iterator it = fonts.begin(); it != fonts.end(); ++it) {
345
 
                it->second->Realise(surface, zoomLevel, technology, it->first);
346
 
        }
347
 
 
348
 
        for (unsigned int k=0; k<styles.size(); k++) {
349
 
                FontRealised *fr = Find(styles[k]);
350
 
                styles[k].Copy(fr->font, *fr);
351
 
        }
352
 
        indicatorsDynamic = 0;
353
 
        indicatorsSetFore = 0;
354
 
        for (int ind = 0; ind <= INDIC_MAX; ind++) {
355
 
                if (indicators[ind].IsDynamic())
356
 
                        indicatorsDynamic++;
357
 
                if (indicators[ind].OverridesTextFore())
358
 
                        indicatorsSetFore++;
359
 
        }
 
325
        for (const Style &style : styles) {
 
326
                CreateAndAddFont(style);
 
327
        }
 
328
 
 
329
        // Ask platform to allocate each unique font.
 
330
        for (std::pair<const FontSpecification, std::unique_ptr<FontRealised>> &font : fonts) {
 
331
                font.second->Realise(surface, zoomLevel, technology, font.first);
 
332
        }
 
333
 
 
334
        // Set the platform font handle and measurements for each style.
 
335
        for (Style &style : styles) {
 
336
                FontRealised *fr = Find(style);
 
337
                style.Copy(fr->font, *fr);
 
338
        }
 
339
 
 
340
        indicatorsDynamic = std::any_of(indicators.cbegin(), indicators.cend(),
 
341
                [](const Indicator &indicator) { return indicator.IsDynamic(); });
 
342
 
 
343
        indicatorsSetFore = std::any_of(indicators.cbegin(), indicators.cend(),
 
344
                [](const Indicator &indicator) { return indicator.OverridesTextFore(); });
 
345
 
360
346
        maxAscent = 1;
361
347
        maxDescent = 1;
362
348
        FindMaxAscentDescent();
369
355
        if (lineOverlap > lineHeight)
370
356
                lineOverlap = lineHeight;
371
357
 
372
 
        someStylesProtected = false;
373
 
        someStylesForceCase = false;
374
 
        for (unsigned int l=0; l<styles.size(); l++) {
375
 
                if (styles[l].IsProtected()) {
376
 
                        someStylesProtected = true;
377
 
                }
378
 
                if (styles[l].caseForce != Style::caseMixed) {
379
 
                        someStylesForceCase = true;
380
 
                }
381
 
        }
 
358
        someStylesProtected = std::any_of(styles.cbegin(), styles.cend(),
 
359
                [](const Style &style) { return style.IsProtected(); });
 
360
 
 
361
        someStylesForceCase = std::any_of(styles.cbegin(), styles.cend(),
 
362
                [](const Style &style) { return style.caseForce != Style::caseMixed; });
382
363
 
383
364
        aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
384
365
        spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
464
445
 
465
446
void ViewStyle::CalcLargestMarkerHeight() {
466
447
        largestMarkerHeight = 0;
467
 
        for (int m = 0; m <= MARKER_MAX; ++m) {
468
 
                switch (markers[m].markType) {
 
448
        for (const LineMarker &marker : markers) {
 
449
                switch (marker.markType) {
469
450
                case SC_MARK_PIXMAP:
470
 
                        if (markers[m].pxpm && markers[m].pxpm->GetHeight() > largestMarkerHeight)
471
 
                                largestMarkerHeight = markers[m].pxpm->GetHeight();
 
451
                        if (marker.pxpm && marker.pxpm->GetHeight() > largestMarkerHeight)
 
452
                                largestMarkerHeight = marker.pxpm->GetHeight();
472
453
                        break;
473
454
                case SC_MARK_RGBAIMAGE:
474
 
                        if (markers[m].image && markers[m].image->GetHeight() > largestMarkerHeight)
475
 
                                largestMarkerHeight = markers[m].image->GetHeight();
 
455
                        if (marker.image && marker.image->GetHeight() > largestMarkerHeight)
 
456
                                largestMarkerHeight = marker.image->GetHeight();
476
457
                        break;
477
458
                }
478
459
        }
479
460
}
480
461
 
 
462
int ViewStyle::GetFrameWidth() const {
 
463
        return Platform::Clamp(caretLineFrame, 1, lineHeight / 3);
 
464
}
 
465
 
 
466
bool ViewStyle::IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const {
 
467
        return caretLineFrame && (caretActive || alwaysShowCaretLineBackground) && showCaretLineBackground &&
 
468
                (caretLineAlpha == SC_ALPHA_NOALPHA) && lineContainsCaret;
 
469
}
 
470
 
481
471
// See if something overrides the line background color:  Either if caret is on the line
482
472
// and background color is set for that, or if a marker is defined that forces its background
483
473
// color onto the line, or if a marker is defined but has no selection margin in which to
486
476
// the color for the highest numbered one is used.
487
477
ColourOptional ViewStyle::Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const {
488
478
        ColourOptional background;
489
 
        if ((caretActive || alwaysShowCaretLineBackground) && showCaretLineBackground && (caretLineAlpha == SC_ALPHA_NOALPHA) && lineContainsCaret) {
 
479
        if (!caretLineFrame && (caretActive || alwaysShowCaretLineBackground) && showCaretLineBackground &&
 
480
                (caretLineAlpha == SC_ALPHA_NOALPHA) && lineContainsCaret) {
490
481
                background = ColourOptional(caretLineBackground, true);
491
482
        }
492
483
        if (!background.isSet && marksOfLine) {
552
543
                wrapStateWanted = eWrapNone;
553
544
                break;
554
545
        }
555
 
        bool changed = wrapState != wrapStateWanted;
 
546
        const bool changed = wrapState != wrapStateWanted;
556
547
        wrapState = wrapStateWanted;
557
548
        return changed;
558
549
}
559
550
 
560
551
bool ViewStyle::SetWrapVisualFlags(int wrapVisualFlags_) {
561
 
        bool changed = wrapVisualFlags != wrapVisualFlags_;
 
552
        const bool changed = wrapVisualFlags != wrapVisualFlags_;
562
553
        wrapVisualFlags = wrapVisualFlags_;
563
554
        return changed;
564
555
}
565
556
 
566
557
bool ViewStyle::SetWrapVisualFlagsLocation(int wrapVisualFlagsLocation_) {
567
 
        bool changed = wrapVisualFlagsLocation != wrapVisualFlagsLocation_;
 
558
        const bool changed = wrapVisualFlagsLocation != wrapVisualFlagsLocation_;
568
559
        wrapVisualFlagsLocation = wrapVisualFlagsLocation_;
569
560
        return changed;
570
561
}
571
562
 
572
563
bool ViewStyle::SetWrapVisualStartIndent(int wrapVisualStartIndent_) {
573
 
        bool changed = wrapVisualStartIndent != wrapVisualStartIndent_;
 
564
        const bool changed = wrapVisualStartIndent != wrapVisualStartIndent_;
574
565
        wrapVisualStartIndent = wrapVisualStartIndent_;
575
566
        return changed;
576
567
}
577
568
 
578
569
bool ViewStyle::SetWrapIndentMode(int wrapIndentMode_) {
579
 
        bool changed = wrapIndentMode != wrapIndentMode_;
 
570
        const bool changed = wrapIndentMode != wrapIndentMode_;
580
571
        wrapIndentMode = wrapIndentMode_;
581
572
        return changed;
582
573
}
597
588
        if (fs.fontName) {
598
589
                FontMap::iterator it = fonts.find(fs);
599
590
                if (it == fonts.end()) {
600
 
                        fonts[fs] = new FontRealised();
 
591
                        fonts[fs] = std::unique_ptr<FontRealised>(new FontRealised());
601
592
                }
602
593
        }
603
594
}
604
595
 
605
596
FontRealised *ViewStyle::Find(const FontSpecification &fs) {
606
597
        if (!fs.fontName)       // Invalid specification so return arbitrary object
607
 
                return fonts.begin()->second;
 
598
                return fonts.begin()->second.get();
608
599
        FontMap::iterator it = fonts.find(fs);
609
600
        if (it != fonts.end()) {
610
601
                // Should always reach here since map was just set for all styles
611
 
                return it->second;
 
602
                return it->second.get();
612
603
        }
613
604
        return 0;
614
605
}
615
606
 
616
607
void ViewStyle::FindMaxAscentDescent() {
617
 
        for (FontMap::const_iterator it = fonts.begin(); it != fonts.end(); ++it) {
 
608
        for (FontMap::const_iterator it = fonts.cbegin(); it != fonts.cend(); ++it) {
618
609
                if (maxAscent < it->second->ascent)
619
610
                        maxAscent = it->second->ascent;
620
611
                if (maxDescent < it->second->descent)