1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 /** This file handles the display part of text edit stuff: Making text
20 * edit start and stop at the right time and highlighting the edits.
21 * lib/text.c and lib/focus.c handles internal things like who can have
22 * focus and how to enter text. app/disp_callbacks.c handles the actual
25 * There's an invariant that all objects in the focus list must be selected.
33 #include "highlight.h"
35 #include "object_ops.h"
38 /** Move the text edit focus either backwards or forwards. */
40 textedit_move_focus(DDisplay
*ddisp
, Focus
*focus
, gboolean forwards
)
43 /* Leak of focus highlight color here, but should it be handled
44 by highlight or by us?
46 highlight_object_off(focus
->obj
, ddisp
->diagram
);
47 object_add_updates(focus
->obj
, ddisp
->diagram
);
53 focus
= active_focus();
56 Color
*focus_col
= color_new_rgb(1.0, 1.0, 0.0);
57 highlight_object(focus
->obj
, focus_col
, ddisp
->diagram
);
58 object_add_updates(focus
->obj
, ddisp
->diagram
);
60 diagram_flush(ddisp
->diagram
);
64 /** Call when something recieves an actual focus (not to be confused
65 * with doing request_focus(), which merely puts one in the focus list).
68 textedit_activate_focus(DDisplay
*ddisp
, Focus
*focus
, Point
*clicked
)
71 Focus
*old_focus
= active_focus();
72 object_add_updates(old_focus
->obj
, ddisp
->diagram
);
73 highlight_object_off(old_focus
->obj
, ddisp
->diagram
);
75 highlight_object(focus
->obj
, color_new_rgb(1.0, 1.0, 0.0), ddisp
->diagram
);
77 text_set_cursor((Text
*)focus
->user_data
, clicked
, ddisp
->renderer
);
79 object_add_updates(focus
->obj
, ddisp
->diagram
);
81 diagram_flush(ddisp
->diagram
);
84 /** Call when an object is chosen for activation (e.g. due to creation).
87 textedit_activate_object(DDisplay
*ddisp
, DiaObject
*obj
, Point
*clicked
)
90 Focus
*focus
= active_focus();
91 highlight_object_off(focus
->obj
, ddisp
->diagram
);
92 object_add_updates(focus
->obj
, ddisp
->diagram
);
94 if (give_focus_to_object(obj
)) {
95 highlight_object(obj
, color_new_rgb(1.0, 1.0, 0.0), ddisp
->diagram
);
97 text_set_cursor((Text
*)active_focus()->user_data
, clicked
, ddisp
->renderer
);
99 object_add_updates(obj
, ddisp
->diagram
);
100 diagram_flush(ddisp
->diagram
);
104 /** Call when something causes the text focus to disappear.
105 * Does not remove objects from the focus list, but removes the
106 * focus highlight and stuff.
107 * Calling remove_focus on the active object or remove_focus_all
108 * implies deactivating the focus. */
110 textedit_deactivate_focus()
112 Focus
*focus
= active_focus();
114 highlight_object_off(focus
->obj
, ddisplay_active()->diagram
);
119 /** Call when something should be removed from the focus list */
121 textedit_remove_focus(DiaObject
*obj
, Diagram
*diagram
)
123 if (remove_focus_object(obj
)) {
124 highlight_object_off(obj
, ddisplay_active()->diagram
);
128 /** Call when the entire list of focusable texts gets reset. */
130 textedit_remove_focus_all(Diagram
*diagram
)
132 Focus
*focus
= active_focus();
134 highlight_object_off(focus
->obj
, diagram
);