source: trunk/third/gtkhtml/src/htmlengine-edit-selection-updater.c @ 16767

Revision 16767, 4.3 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16766, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*  This file is part of the GtkHTML library.
3
4    Copyright (C) 2000 Helix Code, Inc.
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public License
17    along with this library; see the file COPYING.LIB.  If not, write to
18    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.
20*/
21
22/* WARNING / FIXME : All of this code assumes that the only kind of
23   selectable object that does not accept the cursor is
24   `HTMLClueFlow'.  */
25
26
27#include <config.h>
28#include <gtk/gtkmain.h>
29#include "htmlengine-edit-selection-updater.h"
30#include "htmlinterval.h"
31#include "htmlselection.h"
32
33struct _HTMLEngineEditSelectionUpdater {
34        HTMLEngine *engine;
35        gint idle_id;
36};
37
38
39/**
40 * html_engine_edit_selection_updater_new:
41 * @engine: A GtkHTML engine object.
42 *
43 * Create a new updater associated with @engine.
44 *
45 * Return value: A pointer to the new updater object.
46 **/
47HTMLEngineEditSelectionUpdater *
48html_engine_edit_selection_updater_new (HTMLEngine *engine)
49{
50        HTMLEngineEditSelectionUpdater *new;
51
52        g_return_val_if_fail (engine != NULL, NULL);
53        g_return_val_if_fail (HTML_IS_ENGINE (engine), NULL);
54
55        new = g_new (HTMLEngineEditSelectionUpdater, 1);
56
57        new->engine  = engine;
58        new->idle_id = 0;
59
60        return new;
61}
62
63/**
64 * html_engine_edit_selection_updater_destroy:
65 * @updater: An HTMLEngineEditSelectionUpdater object.
66 *
67 * Destroy @updater.
68 **/
69void
70html_engine_edit_selection_updater_destroy (HTMLEngineEditSelectionUpdater *updater)
71{
72        g_return_if_fail (updater != NULL);
73
74        if (updater->idle_id != 0)
75                gtk_idle_remove (updater->idle_id);
76
77        g_free (updater);
78}
79
80
81static gint
82updater_idle_callback (gpointer data)
83{
84        HTMLEngineEditSelectionUpdater *updater;
85        HTMLEngine *engine;
86
87        updater = (HTMLEngineEditSelectionUpdater *) data;
88        engine = updater->engine;
89
90        if (engine->mark && html_cursor_get_position (engine->mark) != html_cursor_get_position (engine->cursor))
91                html_engine_select_interval (engine, html_interval_new_from_cursor (engine->mark, engine->cursor));
92        else {
93                gboolean selection_mode = engine->selection_mode;
94
95                html_engine_disable_selection (engine);
96                engine->selection_mode = selection_mode;
97        }
98
99        updater->idle_id = 0;
100        return FALSE;
101}
102
103/**
104 * html_engine_edit_selection_updater_schedule:
105 * @updater: An HTMLEngineEditSelectionUpdater object.
106 *
107 * Schedule an update for the keyboard-selected region on @updater.
108 **/
109void
110html_engine_edit_selection_updater_schedule (HTMLEngineEditSelectionUpdater *updater)
111{
112        g_return_if_fail (updater != NULL);
113
114        if (updater->idle_id != 0)
115                return;
116
117        updater->idle_id = gtk_idle_add (updater_idle_callback, updater);
118}
119
120/**
121 * html_engine_edit_selection_updater_reset:
122 * @updater: An HTMLEngineEditSelectionUpdater object.
123 *
124 * Reset @updater so after no selection is active anymore.
125 **/
126void
127html_engine_edit_selection_updater_reset (HTMLEngineEditSelectionUpdater *updater)
128{
129        g_return_if_fail (updater != NULL);
130
131        if (updater->idle_id != 0) {
132                gtk_idle_remove (updater->idle_id);
133                updater->idle_id = 0;
134        }
135}
136
137/**
138 * html_engine_edit_selection_updater_update_now:
139 * @updater: An HTMLEngineEditSelectionUpdater object.
140 *
141 * Remove @updater idle callback and run's update callback immediately.
142 **/
143void
144html_engine_edit_selection_updater_update_now (HTMLEngineEditSelectionUpdater *updater)
145{
146        /* remove scheduled idle cb */
147        if (updater->idle_id != 0) {
148                gtk_idle_remove (updater->idle_id);
149                updater->idle_id = 0;
150        }
151
152        /* run it now */
153        updater_idle_callback (updater);
154}
155
156void
157html_engine_edit_selection_updater_do_idle (HTMLEngineEditSelectionUpdater *updater)
158{
159        /* remove scheduled idle cb */
160        if (updater->idle_id != 0) {
161                gtk_idle_remove (updater->idle_id);
162                updater->idle_id = 0;
163
164                /* run it now */
165                updater_idle_callback (updater);
166        }
167}
Note: See TracBrowser for help on using the repository browser.