@@ -115,6 +115,7 @@ MCParagraph::MCParagraph()
115115 opened = 0 ;
116116 startindex = endindex = originalindex = MAXUINT2;
117117 state = 0 ;
118+ needs_layout = true ;
118119
119120 // MW-2012-01-25: [[ ParaStyles ]] All attributes are unset to begin with.
120121 attrs = nil;
@@ -155,6 +156,7 @@ MCParagraph::MCParagraph(const MCParagraph &pref) : MCDLlist(pref)
155156 startindex = endindex = originalindex = MAXUINT2;
156157 opened = 0 ;
157158 state = 0 ;
159+ needs_layout = true ; // is this needed?
158160}
159161
160162MCParagraph::~MCParagraph ()
@@ -273,6 +275,8 @@ IO_stat MCParagraph::load(IO_handle stream, const char *version, bool is_ext)
273275 }
274276 }
275277
278+ needs_layout = true ;
279+
276280 return IO_NORMAL;
277281}
278282
@@ -415,6 +419,8 @@ bool MCParagraph::recomputefonts(MCFontRef p_parent_font)
415419 }
416420 while (t_block != blocks);
417421
422+ if (t_changed)
423+ needs_layout = true ;
418424 return t_changed;
419425}
420426
@@ -461,6 +467,8 @@ void MCParagraph::deletelines()
461467 MCLine *lptr = lines->remove (lines);
462468 delete lptr;
463469 }
470+
471+ needs_layout = true ;
464472}
465473
466474// **** mutate blocks
@@ -473,6 +481,7 @@ void MCParagraph::deleteblocks()
473481 }
474482
475483 state |= PS_LINES_NOT_SYNCHED;
484+ needs_layout = true ;
476485}
477486
478487// clear blocks with the same attributes
@@ -513,17 +522,23 @@ void MCParagraph::defrag()
513522 if (t_blocks_changed)
514523 {
515524 state |= PS_LINES_NOT_SYNCHED;
525+ needs_layout = true ;
516526 }
517527}
518528
519529// MW-2012-01-25: [[ ParaStyles ]] This method causes a reflow of the paragraph depending
520530// on the setting of 'dontWrap'.
521531void MCParagraph::layout ()
522532{
533+ if (!needs_layout)
534+ return ;
535+
523536 if (getdontwrap ())
524537 noflow ();
525538 else
526539 flow ();
540+
541+ needs_layout = False;
527542}
528543
529544// reflow paragraph with wrapping
@@ -601,13 +616,6 @@ void MCParagraph::noflow(void)
601616 MCLine *lptr = lines->remove (lines);
602617 delete lptr;
603618 }
604- MCBlock *bptr = blocks;
605- do
606- {
607- bptr->reset ();
608- bptr = bptr->next ();
609- }
610- while (bptr != blocks);
611619 lines->appendall (blocks);
612620
613621 // MW-2012-02-10: [[ FixedTable ]] If there is a non-zero table width then
@@ -1255,6 +1263,8 @@ void MCParagraph::setatts(uint2 si, uint2 ei, Properties p, void *value, bool p_
12551263{
12561264 bool t_blocks_changed;
12571265 t_blocks_changed = false ;
1266+ bool t_needs_layout;
1267+ t_needs_layout = false ;
12581268
12591269 defrag ();
12601270 MCBlock *bptr = indextoblock (si, False);
@@ -1296,10 +1306,12 @@ void MCParagraph::setatts(uint2 si, uint2 ei, Properties p, void *value, bool p_
12961306 break ;
12971307 case P_TEXT_SHIFT:
12981308 bptr->setshift ((uint4)(intptr_t )value);
1309+ t_needs_layout = true ;
12991310 break ;
13001311 case P_IMAGE_SOURCE:
13011312 {
13021313 bptr->setatts (p, value);
1314+ t_needs_layout = true ;
13031315
13041316 // MW-2008-04-03: [[ Bug ]] Only add an extra block if this is coming from
13051317 // html parsing.
@@ -1319,6 +1331,7 @@ void MCParagraph::setatts(uint2 si, uint2 ei, Properties p, void *value, bool p_
13191331 break ;
13201332 default :
13211333 bptr->setatts (p, value);
1334+ t_needs_layout = true ;
13221335 break ;
13231336 }
13241337 // MW-2012-02-14: [[ FontRefs ]] If the block is open, pass in the parent's
@@ -1333,6 +1346,10 @@ void MCParagraph::setatts(uint2 si, uint2 ei, Properties p, void *value, bool p_
13331346 {
13341347 state |= PS_LINES_NOT_SYNCHED;
13351348 }
1349+ if (t_needs_layout || t_blocks_changed)
1350+ {
1351+ needs_layout = true ;
1352+ }
13361353}
13371354
13381355// MW-2008-03-27: [[ Bug 5093 ]] Rewritten to more correctly insert blocks around
@@ -1518,6 +1535,7 @@ void MCParagraph::join()
15181535 delete pgptr;
15191536 clearzeros ();
15201537 deletelines ();
1538+ needs_layout = true ;
15211539}
15221540
15231541void MCParagraph::split () // split paragraphs on return
@@ -1571,6 +1589,7 @@ void MCParagraph::split() //split paragraphs on return
15711589 pgptr->open (parent -> getfontref ());
15721590 append (pgptr);
15731591 deletelines ();
1592+ needs_layout = true ;
15741593}
15751594
15761595void MCParagraph::deletestring (uint2 si, uint2 ei)
@@ -1634,6 +1653,7 @@ void MCParagraph::deletestring(uint2 si, uint2 ei)
16341653 clearzeros ();
16351654
16361655 state |= PS_LINES_NOT_SYNCHED;
1656+ needs_layout = true ;
16371657}
16381658
16391659MCParagraph *MCParagraph::copystring (uint2 si, uint2 ei)
@@ -1795,6 +1815,7 @@ void MCParagraph::finsertnobreak(const MCString& p_text, bool p_is_unicode)
17951815 }
17961816
17971817 delete t_native_text;
1818+ needs_layout = true ;
17981819}
17991820
18001821// MW-2012-02-13: [[ Block Unicode ]] New implementation of finsert which understands unicodeness.
0 commit comments