]> git.saurik.com Git - wxWidgets.git/blame - src/stc/scintilla/src/Style.cxx
attempts at making modal dialogs without parent work - failed
[wxWidgets.git] / src / stc / scintilla / src / Style.cxx
CommitLineData
9ce192d4
RD
1// Scintilla source code edit control
2// Style.cxx - defines the font and colour style for a class of text
3// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4// The License.txt file describes the conditions under which this software may be distributed.
5
6#include <string.h>
7
8#include "Platform.h"
9
f6bcfd97 10#include "Scintilla.h"
9ce192d4
RD
11#include "Style.h"
12
13Style::Style() {
f6bcfd97
BP
14 aliasOfDefaultFont = true;
15 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
16 Platform::DefaultFontSize(), 0, SC_CHARSET_DEFAULT,
d134f170 17 false, false, false, false, true);
f6bcfd97
BP
18}
19
20Style::Style(const Style &source) {
21 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
22 0, 0, 0,
d134f170 23 false, false, false, false, true);
f6bcfd97
BP
24 fore.desired = source.fore.desired;
25 back.desired = source.back.desired;
26 characterSet = source.characterSet;
27 bold = source.bold;
28 italic = source.italic;
29 size = source.size;
30 eolFilled = source.eolFilled;
31 underline = source.underline;
d134f170 32 visible = source.visible;
9ce192d4 33}
88b780d9 34
9ce192d4 35Style::~Style() {
f6bcfd97
BP
36 if (aliasOfDefaultFont)
37 font.SetID(0);
38 else
39 font.Release();
40 aliasOfDefaultFont = false;
9ce192d4
RD
41}
42
43Style &Style::operator=(const Style &source) {
44 if (this == &source)
45 return *this;
f6bcfd97
BP
46 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
47 0, 0, SC_CHARSET_DEFAULT,
d134f170 48 false, false, false, false, true);
9ce192d4
RD
49 fore.desired = source.fore.desired;
50 back.desired = source.back.desired;
f6bcfd97 51 characterSet = source.characterSet;
9ce192d4
RD
52 bold = source.bold;
53 italic = source.italic;
54 size = source.size;
9ce192d4 55 eolFilled = source.eolFilled;
f6bcfd97 56 underline = source.underline;
d134f170 57 visible = source.visible;
9ce192d4
RD
58 return *this;
59}
60
f6bcfd97
BP
61void Style::Clear(Colour fore_, Colour back_, int size_,
62 const char *fontName_, int characterSet_,
d134f170 63 bool bold_, bool italic_, bool eolFilled_, bool underline_, bool visible_) {
9ce192d4
RD
64 fore.desired = fore_;
65 back.desired = back_;
f6bcfd97 66 characterSet = characterSet_;
9ce192d4
RD
67 bold = bold_;
68 italic = italic_;
69 size = size_;
f6bcfd97 70 fontName = fontName_;
9ce192d4 71 eolFilled = eolFilled_;
f6bcfd97 72 underline = underline_;
d134f170 73 visible = visible_;
f6bcfd97
BP
74 if (aliasOfDefaultFont)
75 font.SetID(0);
76 else
77 font.Release();
78 aliasOfDefaultFont = false;
9ce192d4
RD
79}
80
f6bcfd97
BP
81bool Style::EquivalentFontTo(const Style *other) const {
82 if (bold != other->bold ||
83 italic != other->italic ||
84 size != other->size ||
85 characterSet != other->characterSet)
86 return false;
87 if (fontName == other->fontName)
88 return true;
89 if (!fontName)
90 return false;
91 if (!other->fontName)
92 return false;
93 return strcmp(fontName, other->fontName) == 0;
94}
95
96void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle) {
9ce192d4
RD
97 int sizeZoomed = size + zoomLevel;
98 if (sizeZoomed <= 2) // Hangs if sizeZoomed <= 1
99 sizeZoomed = 2;
f6bcfd97
BP
100
101 if (aliasOfDefaultFont)
102 font.SetID(0);
103 else
104 font.Release();
105 int deviceHeight = surface.DeviceHeightFont(sizeZoomed);
106 aliasOfDefaultFont = defaultStyle &&
107 (EquivalentFontTo(defaultStyle) || !fontName);
108 if (aliasOfDefaultFont) {
109 font.SetID(defaultStyle->font.GetID());
110 } else if (fontName) {
111 font.Create(fontName, characterSet, deviceHeight, bold, italic);
112 } else {
113 font.SetID(0);
114 }
9ce192d4
RD
115
116 ascent = surface.Ascent(font);
117 descent = surface.Descent(font);
118 // Probably more typographically correct to include leading
119 // but that means more complex drawing as leading must be erased
120 //lineHeight = surface.ExternalLeading() + surface.Height();
121 externalLeading = surface.ExternalLeading(font);
122 lineHeight = surface.Height(font);
123 aveCharWidth = surface.AverageCharWidth(font);
124 spaceWidth = surface.WidthChar(font, ' ');
125}