mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 17:19:44 -06:00
Import r67258 of the wxWidgets trunk, which I expect will before
long become wxWidgets 2.9.2, which in turn is expected to be the last 2.9 release before the 3.0 stable release. Since the full wxWidgets distribution is rather large, I have imported only the parts that we use, on a subdirectory basis: art include/wx/*.* include/wx/aui include/wx/cocoa include/wx/generic include/wx/gtk include/wx/meta include/wx/msw include/wx/osx include/wx/persist include/wx/private include/wx/protocol include/wx/unix src/aui src/common src/generic src/gtk src/msw src/osx src/unix git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7380 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
120
Externals/wxWidgets3/include/wx/osx/cocoa/private/markuptoattr.h
vendored
Normal file
120
Externals/wxWidgets3/include/wx/osx/cocoa/private/markuptoattr.h
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/osx/cocoa/private/markuptoattr.h
|
||||
// Purpose: Class to convert markup to Cocoa attributed strings.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-02-22
|
||||
// RCS-ID: $Id: markuptoattr.h 67069 2011-02-27 12:48:46Z VZ $
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_OSX_COCOA_PRIVATE_MARKUPTOATTR_H_
|
||||
#define _WX_OSX_COCOA_PRIVATE_MARKUPTOATTR_H_
|
||||
|
||||
#include "wx/private/markupparserattr.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMarkupToAttrString: create NSAttributedString from markup.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxMarkupToAttrString : public wxMarkupParserAttrOutput
|
||||
{
|
||||
public:
|
||||
// We don't care about the original colours because we never use them but
|
||||
// we do need the correct initial font as we apply modifiers (e.g. create a
|
||||
// font larger than it) to it and so it must be valid.
|
||||
wxMarkupToAttrString(wxWindow *win, const wxString& markup)
|
||||
: wxMarkupParserAttrOutput(win->GetFont(), wxColour(), wxColour())
|
||||
{
|
||||
const wxCFStringRef
|
||||
label(wxControl::RemoveMnemonics(wxMarkupParser::Strip(markup)));
|
||||
m_attrString = [[NSMutableAttributedString alloc]
|
||||
initWithString: label.AsNSString()];
|
||||
|
||||
m_pos = 0;
|
||||
|
||||
[m_attrString beginEditing];
|
||||
|
||||
// First thing we do is change the default string font: as mentioned in
|
||||
// Apple documentation, attributed strings use "Helvetica 12" font by
|
||||
// default which is different from the system "Lucida Grande" font. So
|
||||
// we need to explicitly change the font for the entire string.
|
||||
[m_attrString addAttribute:NSFontAttributeName
|
||||
value:win->GetFont().OSXGetNSFont()
|
||||
range:NSMakeRange(0, [m_attrString length])];
|
||||
|
||||
// Now translate the markup tags to corresponding attributes.
|
||||
wxMarkupParser parser(*this);
|
||||
parser.Parse(markup);
|
||||
|
||||
[m_attrString endEditing];
|
||||
}
|
||||
|
||||
~wxMarkupToAttrString()
|
||||
{
|
||||
[m_attrString release];
|
||||
}
|
||||
|
||||
// Accessor for the users of this class.
|
||||
//
|
||||
// We keep ownership of the returned string.
|
||||
NSMutableAttributedString *GetNSAttributedString() const
|
||||
{
|
||||
return m_attrString;
|
||||
}
|
||||
|
||||
|
||||
// Implement base class pure virtual methods to process markup tags.
|
||||
virtual void OnText(const wxString& text)
|
||||
{
|
||||
m_pos += wxControl::RemoveMnemonics(text).length();
|
||||
}
|
||||
|
||||
virtual void OnAttrStart(const Attr& WXUNUSED(attr))
|
||||
{
|
||||
// Just remember the starting position of the range, we can't really
|
||||
// set the attribute until we find the end of it.
|
||||
m_rangeStarts.push(m_pos);
|
||||
}
|
||||
|
||||
virtual void OnAttrEnd(const Attr& attr)
|
||||
{
|
||||
unsigned start = m_rangeStarts.top();
|
||||
m_rangeStarts.pop();
|
||||
|
||||
const NSRange range = NSMakeRange(start, m_pos - start);
|
||||
|
||||
[m_attrString addAttribute:NSFontAttributeName
|
||||
value:attr.font.OSXGetNSFont()
|
||||
range:range];
|
||||
|
||||
if ( attr.foreground.IsOk() )
|
||||
{
|
||||
[m_attrString addAttribute:NSForegroundColorAttributeName
|
||||
value:attr.foreground.OSXGetNSColor()
|
||||
range:range];
|
||||
}
|
||||
|
||||
if ( attr.background.IsOk() )
|
||||
{
|
||||
[m_attrString addAttribute:NSBackgroundColorAttributeName
|
||||
value:attr.background.OSXGetNSColor()
|
||||
range:range];
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// The attributed string we're building.
|
||||
NSMutableAttributedString *m_attrString;
|
||||
|
||||
// The current position in the output string.
|
||||
unsigned m_pos;
|
||||
|
||||
// The positions of starting ranges.
|
||||
wxStack<unsigned> m_rangeStarts;
|
||||
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxMarkupToAttrString);
|
||||
};
|
||||
|
||||
#endif // _WX_OSX_COCOA_PRIVATE_MARKUPTOATTR_H_
|
Reference in New Issue
Block a user