Skip to content

Commit a7b3dae

Browse files
committed
[[ Bug 14645 ]] Add tab alignments to MCFieldParagraphStyle struct
[[ Bug 14645 ]] Ensure tab alignments are copied appropriately on style import / export
1 parent d7aaf43 commit a7b3dae

3 files changed

Lines changed: 41 additions & 23 deletions

File tree

engine/src/field.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct MCFieldParagraphStyle
4444
bool has_space_above : 1;
4545
bool has_space_below : 1;
4646
bool has_tabs : 1;
47+
bool has_tab_alignments : 1;
4748
bool has_background_color : 1;
4849
bool has_border_width : 1;
4950
bool has_list_indent : 1;
@@ -74,6 +75,8 @@ struct MCFieldParagraphStyle
7475
int16_t space_below;
7576
uint16_t tab_count;
7677
uint16_t *tabs;
78+
uindex_t tab_alignment_count;
79+
intenum_t *tab_alignments;
7780
uint32_t background_color;
7881
uint32_t border_color;
7982
MCStringRef metadata;

engine/src/fieldh.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ bool MCField::doexport(MCFieldExportFlags p_flags, MCParagraph *p_paragraphs, in
167167
t_inherited_paragraph_style . first_indent = indent;
168168
t_inherited_paragraph_style . tab_count = ntabs;
169169
t_inherited_paragraph_style . tabs = tabs;
170+
t_inherited_paragraph_style . tab_alignment_count = nalignments;
171+
t_inherited_paragraph_style . tab_alignments = alignments;
170172
t_inherited_paragraph_style . border_color = getcoloraspixel(DI_BORDER);
171173
}
172174

engine/src/paragrafattr.cpp

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,6 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4242

4343
////////////////////////////////////////////////////////////////////////////////
4444

45-
static struct {const char *name; Properties prop; } kMCParagraphAttrsProps[] =
46-
{
47-
{"textAlign", P_TEXT_ALIGN},
48-
{"listStyle", P_LIST_STYLE},
49-
{"listDepth", P_LIST_DEPTH},
50-
{"listIndent", P_LIST_INDENT},
51-
{"firstIndent", P_FIRST_INDENT},
52-
{"leftIndent", P_LEFT_INDENT},
53-
{"rightIndent", P_RIGHT_INDENT},
54-
{"spaceAbove", P_SPACE_ABOVE},
55-
{"spaceBelow", P_SPACE_BELOW},
56-
{"tabStops", P_TAB_STOPS},
57-
{"backgroundColor", P_BACK_COLOR},
58-
{"borderWidth", P_BORDER_WIDTH},
59-
{"borderColor", P_BORDER_COLOR},
60-
{"hGrid", P_HGRID},
61-
{"vGrid", P_VGRID},
62-
{"dontWrap", P_DONT_WRAP},
63-
{"padding", P_PADDING},
64-
{"listIndex", P_LIST_INDEX},
65-
{nil, P_UNDEFINED},
66-
};
67-
6845
bool MCParagraph::hasattrs(void)
6946
{
7047
return attrs != nil;
@@ -138,6 +115,20 @@ void MCParagraph::fetchattrs(MCArrayRef src)
138115
MCValueRelease(t_stringref_value);
139116
}
140117

118+
if (ctxt . CopyElementAsString(src, MCNAME("tabAlign"), false, t_stringref_value))
119+
{
120+
MCInterfaceFieldTabAlignments t_alignments;
121+
MCMemoryClear(t_alignments);
122+
123+
if (MCField::parsetabalignments(t_stringref_value, t_alignments.m_alignments, t_alignments.m_count))
124+
{
125+
SetTabAlignments(ctxt, t_alignments);
126+
MCMemoryDeallocate(t_alignments.m_alignments);
127+
}
128+
129+
MCValueRelease(t_stringref_value);
130+
}
131+
141132
if (ctxt . CopyElementAsString(src, MCNAME("backgroundColor"), false, t_stringref_value))
142133
{
143134
MCInterfaceNamedColorParse(ctxt, t_stringref_value, t_color);
@@ -512,6 +503,12 @@ void MCParagraph::copyattrs(const MCParagraph& other)
512503
memcpy(attrs -> tabs, other . attrs -> tabs, sizeof(uint16_t) * other . attrs -> tab_count);
513504
}
514505

506+
// If the struct has tabalignments then copy them properly
507+
if ((other . attrs -> flags & PA_HAS_TAB_ALIGNMENTS) != 0)
508+
{
509+
/* UNCHECKED */ MCMemoryAllocateCopy(other . attrs -> alignments, sizeof(intenum_t) * other . attrs -> alignments_count, attrs -> alignments);
510+
}
511+
515512
// MW-2012-12-04: [[ Bug 10577 ]] If the struct has metadata, then copy it properly.
516513
if ((other . attrs -> flags & PA_HAS_METADATA) != 0)
517514
/* UNCHECKED */ MCStringCopy(other . attrs -> metadata, attrs -> metadata);
@@ -527,6 +524,10 @@ void MCParagraph::clearattrs(void)
527524
if ((attrs -> flags & PA_HAS_TABS) != 0)
528525
delete attrs -> tabs;
529526

527+
// If we have tab alignments then delete them.
528+
if ((attrs -> flags & PA_HAS_TAB_ALIGNMENTS) != 0)
529+
MCMemoryDeallocate(attrs -> alignments);
530+
530531
// MW-2012-11-13: [[ ParaMetadata ]] If we have metadata, delete it.
531532
if ((attrs -> flags & PA_HAS_METADATA) != 0)
532533
MCValueRelease(attrs -> metadata);
@@ -587,6 +588,12 @@ void MCParagraph::exportattrs(MCFieldParagraphStyle& x_style)
587588
x_style . tabs = attrs -> tabs;
588589
x_style . tab_count = attrs -> tab_count;
589590
}
591+
if ((attrs -> flags & PA_HAS_TAB_ALIGNMENTS) != 0)
592+
{
593+
x_style . has_tab_alignments = true;
594+
x_style . tab_alignments = attrs -> alignments;
595+
x_style . tab_alignment_count = attrs -> alignments_count;
596+
}
590597
if ((attrs -> flags & PA_HAS_BACKGROUND_COLOR) != 0)
591598
{
592599
x_style . has_background_color = true;
@@ -696,6 +703,12 @@ void MCParagraph::importattrs(const MCFieldParagraphStyle& p_style)
696703
attrs -> tabs = new uint16_t[p_style . tab_count];
697704
memcpy(attrs -> tabs, p_style . tabs, sizeof(uint16_t) * p_style . tab_count);
698705
}
706+
if (p_style . has_tab_alignments)
707+
{
708+
attrs -> flags |= PA_HAS_TAB_ALIGNMENTS;
709+
attrs -> alignments_count = p_style . tab_alignment_count;
710+
/* UNCHECKED */ MCMemoryAllocateCopy(p_style . tab_alignments, sizeof(intenum_t) * p_style . tab_alignment_count, attrs -> alignments);
711+
}
699712
if (p_style . has_background_color)
700713
{
701714
attrs -> flags |= PA_HAS_BACKGROUND_COLOR;

0 commit comments

Comments
 (0)