2 * RichEdit - Operations on rows of text (rows are recreated during
3 * wrapping and are used for displaying the document, they don't keep any
4 * true document content; delete all rows, rewrap all paragraphs and
7 * Copyright 2004 by Krzysztof Foltman
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 ME_Row
*row_next( ME_Row
*row
)
31 item
= ME_FindItemFwd( row_get_di( row
), diStartRowOrParagraphOrEnd
);
32 if (!item
|| item
->type
!= diStartRow
) return NULL
;
33 return &item
->member
.row
;
36 ME_Row
*row_next_all_paras( ME_Row
*row
)
40 item
= ME_FindItemFwd( row_get_di( row
), diStartRow
);
41 if (!item
) return NULL
;
42 return &item
->member
.row
;
45 ME_Row
*row_prev_all_paras( ME_Row
*row
)
49 item
= ME_FindItemBack( row_get_di( row
), diStartRow
);
50 if (!item
) return NULL
;
51 return &item
->member
.row
;
54 ME_Run
*row_first_run( ME_Row
*row
)
58 item
= ME_FindItemFwd( row_get_di( row
), diRunOrStartRow
);
59 assert( item
->type
== diRun
);
60 return &item
->member
.run
;
63 ME_Run
*row_next_run( ME_Row
*row
, ME_Run
*run
)
67 assert( row
== &ME_FindItemBack( run_get_di( run
), diStartRow
)->member
.row
);
69 item
= ME_FindItemFwd( run_get_di( run
), diRunOrStartRow
);
70 if (!item
|| item
->type
== diStartRow
) return NULL
;
71 return &item
->member
.run
;
74 ME_Row
*row_from_cursor( ME_Cursor
*cursor
)
78 item
= ME_FindItemBack( run_get_di( cursor
->run
), diStartRow
);
79 return &item
->member
.row
;
82 void row_first_cursor( ME_Row
*row
, ME_Cursor
*cursor
)
86 item
= ME_FindItemFwd( row_get_di( row
), diRun
);
87 cursor
->run
= &item
->member
.run
;
88 cursor
->para
= cursor
->run
->para
;
92 void row_end_cursor( ME_Row
*row
, ME_Cursor
*cursor
, BOOL include_eop
)
94 ME_DisplayItem
*item
, *run
;
96 item
= ME_FindItemFwd( row_get_di( row
), diStartRowOrParagraphOrEnd
);
97 run
= ME_FindItemBack( item
, diRun
);
98 cursor
->run
= &run
->member
.run
;
99 cursor
->para
= cursor
->run
->para
;
100 cursor
->nOffset
= (item
->type
== diStartRow
|| include_eop
) ? cursor
->run
->len
: 0;
103 ME_Paragraph
*row_para( ME_Row
*row
)
107 row_first_cursor( row
, &cursor
);
111 ME_Row
*row_from_row_number( ME_TextEditor
*editor
, int row_num
)
113 ME_Paragraph
*para
= editor_first_para( editor
);
117 while (para_next( para
) && count
+ para
->nRows
<= row_num
)
119 count
+= para
->nRows
;
120 para
= para_next( para
);
122 if (!para_next( para
)) return NULL
;
124 for (row
= para_first_row( para
); row
&& count
< row_num
; count
++)
125 row
= row_next( row
);
131 int row_number_from_char_ofs( ME_TextEditor
*editor
, int ofs
)
133 ME_Paragraph
*para
= editor_first_para( editor
);
138 while (para_next( para
) && para_next( para
)->nCharOfs
<= ofs
)
140 row_num
+= para
->nRows
;
141 para
= para_next( para
);
144 if (para_next( para
))
146 for (row
= para_first_row( para
); row
; row
= row_next( row
))
148 row_end_cursor( row
, &cursor
, TRUE
);
149 if (ME_GetCursorOfs( &cursor
) > ofs
) break;