adding alignment, indent, and tab support (only 1 distance)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@49604 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1835,61 +1835,121 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo
|
|||||||
{
|
{
|
||||||
TXNTypeAttributes typeAttr[4] ;
|
TXNTypeAttributes typeAttr[4] ;
|
||||||
RGBColor color ;
|
RGBColor color ;
|
||||||
int attrCount = 0 ;
|
size_t typeAttrCount = 0 ;
|
||||||
|
|
||||||
|
TXNMargins margins;
|
||||||
|
TXNControlTag controlTags[4];
|
||||||
|
TXNControlData controlData[4];
|
||||||
|
size_t controlAttrCount = 0;
|
||||||
|
|
||||||
|
TXNTab* tabs = NULL;
|
||||||
|
|
||||||
|
bool relayout = false;
|
||||||
|
|
||||||
if ( style.HasFont() )
|
if ( style.HasFont() )
|
||||||
{
|
{
|
||||||
|
wxASSERT( typeAttrCount < WXSIZEOF(typeAttr) );
|
||||||
const wxFont &font = style.GetFont() ;
|
const wxFont &font = style.GetFont() ;
|
||||||
|
typeAttr[typeAttrCount].tag = kTXNATSUIStyle ;
|
||||||
#if 0 // old version
|
typeAttr[typeAttrCount].size = kTXNATSUIStyleSize ;
|
||||||
Str255 fontName = "\pMonaco" ;
|
typeAttr[typeAttrCount].data.dataPtr = font.MacGetATSUStyle() ;
|
||||||
SInt16 fontSize = 12 ;
|
typeAttrCount++ ;
|
||||||
Style fontStyle = normal ;
|
|
||||||
wxMacStringToPascal( font.GetFaceName() , fontName ) ;
|
|
||||||
fontSize = font.GetPointSize() ;
|
|
||||||
if ( font.GetUnderlined() )
|
|
||||||
fontStyle |= underline ;
|
|
||||||
if ( font.GetWeight() == wxBOLD )
|
|
||||||
fontStyle |= bold ;
|
|
||||||
if ( font.GetStyle() == wxITALIC )
|
|
||||||
fontStyle |= italic ;
|
|
||||||
|
|
||||||
typeAttr[attrCount].tag = kTXNQDFontNameAttribute ;
|
|
||||||
typeAttr[attrCount].size = kTXNQDFontNameAttributeSize ;
|
|
||||||
typeAttr[attrCount].data.dataPtr = (void*)fontName ;
|
|
||||||
attrCount++ ;
|
|
||||||
|
|
||||||
typeAttr[attrCount].tag = kTXNQDFontSizeAttribute ;
|
|
||||||
typeAttr[attrCount].size = kTXNFontSizeAttributeSize ;
|
|
||||||
typeAttr[attrCount].data.dataValue = (fontSize << 16) ;
|
|
||||||
attrCount++ ;
|
|
||||||
|
|
||||||
typeAttr[attrCount].tag = kTXNQDFontStyleAttribute ;
|
|
||||||
typeAttr[attrCount].size = kTXNQDFontStyleAttributeSize ;
|
|
||||||
typeAttr[attrCount].data.dataValue = fontStyle ;
|
|
||||||
attrCount++ ;
|
|
||||||
#else
|
|
||||||
typeAttr[attrCount].tag = kTXNATSUIStyle ;
|
|
||||||
typeAttr[attrCount].size = kTXNATSUIStyleSize ;
|
|
||||||
typeAttr[attrCount].data.dataPtr = font.MacGetATSUStyle() ;
|
|
||||||
attrCount++ ;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( style.HasTextColour() )
|
if ( style.HasTextColour() )
|
||||||
{
|
{
|
||||||
|
wxASSERT( typeAttrCount < WXSIZEOF(typeAttr) );
|
||||||
color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ;
|
color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ;
|
||||||
|
|
||||||
typeAttr[attrCount].tag = kTXNQDFontColorAttribute ;
|
typeAttr[typeAttrCount].tag = kTXNQDFontColorAttribute ;
|
||||||
typeAttr[attrCount].size = kTXNQDFontColorAttributeSize ;
|
typeAttr[typeAttrCount].size = kTXNQDFontColorAttributeSize ;
|
||||||
typeAttr[attrCount].data.dataPtr = (void*) &color ;
|
typeAttr[typeAttrCount].data.dataPtr = (void*) &color ;
|
||||||
attrCount++ ;
|
typeAttrCount++ ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( style.HasAlignment() )
|
||||||
|
{
|
||||||
|
wxASSERT( controlAttrCount < WXSIZEOF(controlTags) );
|
||||||
|
SInt32 align;
|
||||||
|
|
||||||
|
switch ( style.GetAlignment() )
|
||||||
|
{
|
||||||
|
case wxTEXT_ALIGNMENT_LEFT:
|
||||||
|
align = kTXNFlushLeft;
|
||||||
|
break;
|
||||||
|
case wxTEXT_ALIGNMENT_CENTRE:
|
||||||
|
align = kTXNCenter;
|
||||||
|
break;
|
||||||
|
case wxTEXT_ALIGNMENT_RIGHT:
|
||||||
|
align = kTXNFlushRight;
|
||||||
|
break;
|
||||||
|
case wxTEXT_ALIGNMENT_JUSTIFIED:
|
||||||
|
align = kTXNFullJust;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
case wxTEXT_ALIGNMENT_DEFAULT:
|
||||||
|
align = kTXNFlushDefault;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
controlTags[controlAttrCount] = kTXNJustificationTag ;
|
||||||
|
controlData[controlAttrCount].sValue = align ;
|
||||||
|
controlAttrCount++ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( attrCount > 0 )
|
if ( style.HasLeftIndent() || style.HasRightIndent() )
|
||||||
|
{
|
||||||
|
wxASSERT( controlAttrCount < WXSIZEOF(controlTags) );
|
||||||
|
controlTags[controlAttrCount] = kTXNMarginsTag;
|
||||||
|
controlData[controlAttrCount].marginsPtr = &margins;
|
||||||
|
verify_noerr( TXNGetTXNObjectControls (m_txn, 1 ,
|
||||||
|
&controlTags[controlAttrCount], &controlData[controlAttrCount]) );
|
||||||
|
if ( style.HasLeftIndent() )
|
||||||
|
{
|
||||||
|
margins.leftMargin = style.GetLeftIndent() / 254.0 * 72 + 0.5;
|
||||||
|
}
|
||||||
|
if ( style.HasRightIndent() )
|
||||||
|
{
|
||||||
|
margins.rightMargin = style.GetRightIndent() / 254.0 * 72 + 0.5;
|
||||||
|
}
|
||||||
|
controlAttrCount++ ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( style.HasTabs() )
|
||||||
|
{
|
||||||
|
const wxArrayInt& tabarray = style.GetTabs();
|
||||||
|
// unfortunately Mac only applies a tab distance, not individually different tabs
|
||||||
|
controlTags[controlAttrCount] = kTXNTabSettingsTag;
|
||||||
|
if ( tabarray.size() > 0 )
|
||||||
|
controlData[controlAttrCount].tabValue.value = tabarray[0] / 254.0 * 72 + 0.5;
|
||||||
|
else
|
||||||
|
controlData[controlAttrCount].tabValue.value = 72 ;
|
||||||
|
|
||||||
|
controlData[controlAttrCount].tabValue.tabType = kTXNLeftTab;
|
||||||
|
controlAttrCount++ ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// unfortunately the relayout is not automatic
|
||||||
|
if ( controlAttrCount > 0 )
|
||||||
|
{
|
||||||
|
verify_noerr( TXNSetTXNObjectControls (m_txn, false /* don't clear all */, controlAttrCount,
|
||||||
|
controlTags, controlData) );
|
||||||
|
relayout = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( typeAttrCount > 0 )
|
||||||
|
{
|
||||||
|
verify_noerr( TXNSetTypeAttributes( m_txn , typeAttrCount, typeAttr, from , to ) );
|
||||||
|
relayout = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( tabs != NULL )
|
||||||
|
{
|
||||||
|
delete[] tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( relayout )
|
||||||
{
|
{
|
||||||
verify_noerr( TXNSetTypeAttributes( m_txn , attrCount , typeAttr, from , to ) );
|
|
||||||
// unfortunately the relayout is not automatic
|
|
||||||
TXNRecalcTextLayout( m_txn );
|
TXNRecalcTextLayout( m_txn );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user