📄 dw_ext_iterator.c
字号:
/* No more data in the top-most widget. */ if (eit->stack_top > 0) { /* Pop iterator from stack, and move to next item in the old one. */ a_Dw_iterator_free (it); eit->stack_top--; return a_Dw_ext_iterator_next (eit); } else { /* Stack is empty. */ eit->content.type = DW_CONTENT_END; return FALSE; } }}/* * Move iterator backward and store content in it. Returns TRUE on * success. */gboolean a_Dw_ext_iterator_prev (DwExtIterator *eit){ DwIterator *it = eit->stack[eit->stack_top]; if (a_Dw_iterator_prev(it)) { if (it->content.type == DW_CONTENT_WIDGET) { /* Widget: new iterator on stack, to search in this widget. */ eit->stack_top++; a_List_add (eit->stack, eit->stack_top, eit->stack_max); eit->stack[eit->stack_top] = a_Dw_widget_iterator (it->content.data.widget, it->mask, TRUE); return a_Dw_ext_iterator_prev (eit); } else { /* Simply return the content of the iterartor. */ eit->content = it->content; return TRUE; } } else { /* No more data in the top-most widget. */ if (eit->stack_top > 0) { /* Pop iterator from stack, and move to previous item in the old one. */ a_Dw_iterator_free (it); eit->stack_top--; return a_Dw_ext_iterator_prev (eit); } else { /* Stack is empty. */ eit->content.type = DW_CONTENT_START; return FALSE; } }}/* * Create an exact copy of the iterator, which then can be used * independantly of the original one. */DwExtIterator* a_Dw_ext_iterator_clone (DwExtIterator *eit){ int i; DwExtIterator *eit2 = g_new (DwExtIterator, 1); *eit2 = *eit; eit2->stack = g_new (DwIterator*, eit2->stack_max); for (i = 0; i <= eit2->stack_top; i++) eit2->stack[i] = a_Dw_iterator_clone (eit->stack[i]); return eit2;}/* * Return a value < 0, if first iterator is smaller, > 0, if it is * greater, or 0 for equal iterators. It is assumed, that both terators * belong to the same widget tree (i.e. they have the same top-level * widget). */gint a_Dw_ext_iterator_compare (DwExtIterator *eit1, DwExtIterator *eit2){ int nea = 0; while (eit1->stack[nea]->widget == eit2->stack[nea]->widget) { if (nea == eit1->stack_top || nea == eit2->stack_top) break; nea++; } if (eit1->stack[nea]->widget != eit2->stack[nea]->widget) nea--; return a_Dw_iterator_compare (eit1->stack[nea], eit2->stack[nea]);}/* * Free memory of iterator. */void a_Dw_ext_iterator_free (DwExtIterator *eit){ int i; for (i = 0; i <= eit->stack_top; i++) a_Dw_iterator_free (eit->stack[i]); g_free (eit->stack); g_free (eit);}/* * Create a new word iterator. <widget> is the top of the widget * tree over which is iterated. */DwWordIterator* a_Dw_word_iterator_new (DwWidget *widget){ DwWordIterator *it; DwIterator *it0; it = g_new (DwWordIterator, 1); it->word = NULL; it0 = a_Dw_widget_iterator (widget, DW_CONTENT_TEXT | DW_CONTENT_WIDGET, FALSE); it->iterator = a_Dw_ext_iterator_new (it0); it->word_splitpos = NULL; it->content_hl_start = -1; it->content_hl_end = -1; return it;}/* * Move iterator forward and store word in it. Returns TRUE on * success. */gboolean a_Dw_word_iterator_next (DwWordIterator *it){ if (it->word) { g_free (it->word); it->word = NULL; } while (it->word_splitpos == NULL || it->word_splitpos[2 * (it->word_pos + 1)] == -1) { if (it->word_splitpos) { g_free (it->word_splitpos); it->word_splitpos = NULL; it->content_hl_start = -1; it->content_hl_end = -1; } if (!a_Dw_ext_iterator_next (it->iterator)) return FALSE; it->word_splitpos = a_Misc_strsplitpos (it->iterator->content.data.text, " \t\n"); it->word_pos = -1; } it->word_pos++; it->word = a_Misc_strpdup (it->iterator->content.data.text, it->word_splitpos[2 * it->word_pos], it->word_splitpos[2 * it->word_pos + 1]); return TRUE;}/* * Move iterator backward and store word in it. Returns TRUE on * success. */gboolean a_Dw_word_iterator_prev (DwWordIterator *it){ if (it->word) { g_free (it->word); it->word = NULL; } while (it->word_splitpos == NULL || it->word_pos == 0) { if (it->word_splitpos) { g_free (it->word_splitpos); it->word_splitpos = NULL; it->content_hl_start = -1; it->content_hl_end = -1; } if (!a_Dw_ext_iterator_prev (it->iterator)) return FALSE; it->word_splitpos = a_Misc_strsplitpos(it->iterator->content.data.text, " \t\n"); it->word_pos = 0; while (it->word_splitpos[2 * it->word_pos] != -1) it->word_pos++; } it->word_pos--; it->word = a_Misc_strpdup (it->iterator->content.data.text, it->word_splitpos[2 * it->word_pos], it->word_splitpos[2 * it->word_pos + 1]); return TRUE;}/* * Highlight a part of the current word. Unhighlight the current word * by passing -1 as start. */void a_Dw_word_iterator_highlight (DwWordIterator *it, gint start, gint end, DwHighlightLayer layer){ gint new_start, new_end; if (start == -1) { /* Unhighlight the whole content word. * todo: This works incorrect, by unhighlighting the whole * current content of the DwExtIterator. Anyway, a correct * behavior is not needed. */ it->content_hl_start = -1; it->content_hl_end = -1; a_Dw_ext_iterator_unhighlight (it->iterator, layer); } else { new_start = it->word_splitpos[2 * it->word_pos] + start; new_end = it->word_splitpos[2 * it->word_pos] + end; if (it->content_hl_start == -1) { /* nothing selected yet */ it->content_hl_start = new_start; it->content_hl_end = new_end; } else { it->content_hl_start = MIN (it->content_hl_start, new_start); it->content_hl_end = MAX (it->content_hl_end, new_end); } a_Dw_ext_iterator_highlight (it->iterator, it->content_hl_start, it->content_hl_end, layer); }}void a_Dw_word_iterator_get_allocation (DwWordIterator *it, gint start, gint end, DwAllocation *allocation){ /* todo: Implement this. (Although it is not used yet.) */ g_assert_not_reached ();}void a_Dw_word_iterator_scroll_to (DwWordIterator *it1, DwWordIterator *it2, gint start, gint end, DwHPosition hpos, DwVPosition vpos){ gint real_start, real_end; real_start = it1->word_splitpos[2 * it1->word_pos] + start; real_end = it2->word_splitpos[2 * it2->word_pos] + end; a_Dw_ext_iterator_scroll_to (it1->iterator, it2->iterator, real_start, real_end, hpos, vpos);}DwWordIterator* a_Dw_word_iterator_clone (DwWordIterator *it){ DwWordIterator *it2; it2 = g_new (DwWordIterator, 1); *it2 = *it; it2->iterator = a_Dw_ext_iterator_clone (it->iterator); it2->word = it->word ? g_strdup (it->word) : NULL; it2->word_splitpos = it->word_splitpos ? a_Misc_strsplitposdup (it->word_splitpos) : NULL; return it2;}void a_Dw_word_iterator_free (DwWordIterator *it){ a_Dw_ext_iterator_free (it->iterator); g_free (it->word); g_free (it->word_splitpos); g_free (it);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -