ntdll: Validate blocks in the heap pending free request list.
[wine.git] / dlls / riched20 / row.c
blob715d2adbf62d658609bedd6ff64457a4bd2c235e
1 /*
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
5 * you get them back).
6 *
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
22 */
25 #include "editor.h"
27 ME_Row *row_next( ME_Row *row )
29 ME_DisplayItem *item;
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 )
38 ME_DisplayItem *item;
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 )
47 ME_DisplayItem *item;
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 )
56 ME_DisplayItem *item;
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 )
65 ME_DisplayItem *item;
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 )
76 ME_DisplayItem *item;
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 )
84 ME_DisplayItem *item;
86 item = ME_FindItemFwd( row_get_di( row ), diRun );
87 cursor->run = &item->member.run;
88 cursor->para = cursor->run->para;
89 cursor->nOffset = 0;
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 )
105 ME_Cursor cursor;
107 row_first_cursor( row, &cursor );
108 return cursor.para;
111 ME_Row *row_from_row_number( ME_TextEditor *editor, int row_num )
113 ME_Paragraph *para = editor_first_para( editor );
114 ME_Row *row;
115 int count = 0;
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 );
127 return row;
131 int row_number_from_char_ofs( ME_TextEditor *editor, int ofs )
133 ME_Paragraph *para = editor_first_para( editor );
134 ME_Row *row;
135 ME_Cursor cursor;
136 int row_num = 0;
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;
150 row_num++;
154 return row_num;