Document wxMetafileDataObject This will allow language binding, including wxPython, to provide wrappers for it. Closes #25861.
Fix wxTextCtrl::SetFont() with wxTE_RICH when in dark mode Explicitly set the correct (for dark mode) colours when setting the new style, otherwise the control would use black text on almost black background. See #25856.
Fix nested markup conversion to NSAttributedString wxMarkupToAttrStringBase implementation of markup parsing failed to correctly apply nested attributes: in e.g. <i><b>foo</b></i>, only the outer attribute was in effect. This was due to applying - and overwriting - attributes to a span in OnAttrEnd(), which is called first for the inner span, and then for the outer one, overwriting all inner changes. Instead, apply the currently effective attributes to text in OnText(), similarly to how wxMarkupParserRenderOutput does it. As a side effect, this also eliminates the need to apply default font to the entire range first. Closes #25864.
... | ... | @@ -37,12 +37,6 @@ protected: |
37 | 37 | |
38 | 38 | [m_attrString beginEditing];
|
39 | 39 | |
40 | - // First thing we do is change the default string font: as mentioned in
|
|
41 | - // Apple documentation, attributed strings use "Helvetica 12" font by
|
|
42 | - // default which is different from the system "Lucida Grande" font. So
|
|
43 | - // we need to explicitly change the font for the entire string.
|
|
44 | - ApplyFont(font, NSMakeRange(0, [m_attrString length]));
|
|
45 | - |
|
46 | 40 | // Now translate the markup tags to corresponding attributes.
|
47 | 41 | wxMarkupParser parser(*this);
|
48 | 42 | parser.Parse(markup);
|
... | ... | @@ -56,27 +50,6 @@ protected: |
56 | 50 | [m_attrString release];
|
57 | 51 | }
|
58 | 52 | |
59 | - void ApplyFont(const wxFont& font, const NSRange& range)
|
|
60 | - {
|
|
61 | - [m_attrString addAttribute:NSFontAttributeName
|
|
62 | - value:font.OSXGetNSFont()
|
|
63 | - range:range];
|
|
64 | - |
|
65 | - if ( font.GetStrikethrough() )
|
|
66 | - {
|
|
67 | - [m_attrString addAttribute:NSStrikethroughStyleAttributeName
|
|
68 | - value:@(NSUnderlineStyleSingle)
|
|
69 | - range:range];
|
|
70 | - }
|
|
71 | - |
|
72 | - if ( font.GetUnderlined() )
|
|
73 | - {
|
|
74 | - [m_attrString addAttribute:NSUnderlineStyleAttributeName
|
|
75 | - value:@(NSUnderlineStyleSingle)
|
|
76 | - range:range];
|
|
77 | - }
|
|
78 | - }
|
|
79 | - |
|
80 | 53 | // prepare text chunk for display, e.g. strip mnemonics from it
|
81 | 54 | virtual wxString PrepareText(const wxString& text) = 0;
|
82 | 55 | |
... | ... | @@ -89,53 +62,42 @@ public: |
89 | 62 | return m_attrString;
|
90 | 63 | }
|
91 | 64 | |
92 | - |
|
93 | 65 | // Implement base class pure virtual methods to process markup tags.
|
94 | 66 | virtual void OnText(const wxString& text) override
|
95 | 67 | {
|
96 | - m_pos += PrepareText(text).length();
|
|
97 | - }
|
|
68 | + const Attr& attr = GetAttr();
|
|
98 | 69 | |
99 | - virtual void OnAttrStart(const Attr& WXUNUSED(attr)) override
|
|
100 | - {
|
|
101 | - // Just remember the starting position of the range, we can't really
|
|
102 | - // set the attribute until we find the end of it.
|
|
103 | - m_rangeStarts.push(m_pos);
|
|
104 | - }
|
|
70 | + NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
|
105 | 71 | |
106 | - virtual void OnAttrEnd(const Attr& attr) override
|
|
107 | - {
|
|
108 | - unsigned start = m_rangeStarts.top();
|
|
109 | - m_rangeStarts.pop();
|
|
110 | - |
|
111 | - const NSRange range = NSMakeRange(start, m_pos - start);
|
|
112 | - |
|
113 | - ApplyFont(attr.font, range);
|
|
114 | - |
|
115 | - if ( attr.foreground.IsOk() )
|
|
116 | - {
|
|
117 | - [m_attrString addAttribute:NSForegroundColorAttributeName
|
|
118 | - value:attr.foreground.OSXGetWXColor()
|
|
119 | - range:range];
|
|
120 | - }
|
|
121 | - |
|
122 | - if ( attr.background.IsOk() )
|
|
123 | - {
|
|
124 | - [m_attrString addAttribute:NSBackgroundColorAttributeName
|
|
125 | - value:attr.background.OSXGetWXColor()
|
|
126 | - range:range];
|
|
127 | - }
|
|
72 | + dict[NSFontAttributeName] = attr.effectiveFont.OSXGetNSFont();
|
|
73 | + if ( attr.effectiveFont.GetStrikethrough() )
|
|
74 | + dict[NSStrikethroughStyleAttributeName] = @(NSUnderlineStyleSingle);
|
|
75 | + if ( attr.effectiveFont.GetUnderlined() )
|
|
76 | + dict[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle);
|
|
77 | + |
|
78 | + if ( attr.effectiveForeground.IsOk() )
|
|
79 | + dict[NSForegroundColorAttributeName] = attr.effectiveForeground.OSXGetWXColor();
|
|
80 | + |
|
81 | + if ( attr.effectiveBackground.IsOk() )
|
|
82 | + dict[NSBackgroundColorAttributeName] = attr.effectiveBackground.OSXGetWXColor();
|
|
83 | + |
|
84 | + const unsigned len = PrepareText(text).length();
|
|
85 | + |
|
86 | + [m_attrString addAttributes:dict range:NSMakeRange(m_pos, len)];
|
|
87 | + |
|
88 | + m_pos += len;
|
|
128 | 89 | }
|
129 | 90 | |
91 | + virtual void OnAttrStart(const Attr& WXUNUSED(attr)) override {}
|
|
92 | + |
|
93 | + virtual void OnAttrEnd(const Attr& WXUNUSED(attr)) override {}
|
|
94 | + |
|
130 | 95 | private:
|
131 | 96 | // The attributed string we're building.
|
132 | 97 | NSMutableAttributedString *m_attrString;
|
133 | 98 | |
134 | 99 | // The current position in the output string.
|
135 | 100 | unsigned m_pos;
|
136 | - |
|
137 | - // The positions of starting ranges.
|
|
138 | - wxStack<unsigned> m_rangeStarts;
|
|
139 | 101 | };
|
140 | 102 | |
141 | 103 |
... | ... | @@ -128,6 +128,54 @@ public: |
128 | 128 | bool SetClipboard(int width = 0, int height = 0);
|
129 | 129 | };
|
130 | 130 | |
131 | +/**
|
|
132 | + @class wxMetafileDataObject
|
|
133 | + |
|
134 | + This wxDataObject implementation provides support for exchanging metafiles
|
|
135 | + with the other applications through the clipboard or drag and drop.
|
|
136 | + |
|
137 | + @onlyfor{wxmsw}
|
|
138 | + |
|
139 | + @library{wxcore}
|
|
140 | + |
|
141 | + @see wxMetafile, wxDataObject
|
|
142 | +*/
|
|
143 | +class wxMetafileDataObject : public wxDataObjectSimple
|
|
144 | +{
|
|
145 | +public:
|
|
146 | + /**
|
|
147 | + Default constructor.
|
|
148 | + |
|
149 | + The object is initially empty, use SetMetafile() to set the data.
|
|
150 | + */
|
|
151 | + wxMetafileDataObject();
|
|
152 | + |
|
153 | + /**
|
|
154 | + Constructor taking a metafile.
|
|
155 | + |
|
156 | + The object is initialized with a copy of the given metafile.
|
|
157 | + */
|
|
158 | + wxMetafileDataObject(const wxMetafile& metafile);
|
|
159 | + |
|
160 | + /**
|
|
161 | + Set the metafile associated with this object.
|
|
162 | + |
|
163 | + This is useful when using the object as source of a drag and drop
|
|
164 | + operation or when putting data to the clipboard.
|
|
165 | + */
|
|
166 | + virtual void SetMetafile(const wxMetafile& metafile);
|
|
167 | + |
|
168 | + /**
|
|
169 | + Get the metafile associated with this object.
|
|
170 | + |
|
171 | + This is useful when using the object as target of a drag and drop
|
|
172 | + operation or when getting data from the clipboard.
|
|
173 | + */
|
|
174 | + virtual wxMetafile GetMetafile() const;
|
|
175 | + |
|
176 | +protected:
|
|
177 | + wxMetafile m_metafile;
|
|
178 | +};
|
|
131 | 179 | |
132 | 180 | |
133 | 181 | // ============================================================================
|
... | ... | @@ -3131,6 +3131,15 @@ bool wxTextCtrl::SetFont(const wxFont& font) |
3131 | 3131 | // the default font for it.
|
3132 | 3132 | wxTextAttr attr;
|
3133 | 3133 | attr.SetFont(font);
|
3134 | + |
|
3135 | + // In dark mode we also need to set the colours explicitly, just as we
|
|
3136 | + // do for the colours of the control itself in Create().
|
|
3137 | + if ( wxMSWDarkMode::IsActive() )
|
|
3138 | + {
|
|
3139 | + attr.SetTextColour(GetForegroundColour());
|
|
3140 | + attr.SetBackgroundColour(GetBackgroundColour());
|
|
3141 | + }
|
|
3142 | + |
|
3134 | 3143 | SetStyle(-1, -1, attr);
|
3135 | 3144 | }
|
3136 | 3145 |
—
View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help