2004-11-21 Hans Breuer <hans@breuer.org>
[dia.git] / app / textedit.c
blobcb25680c55da7376246e48f864ef9ce766ff7327
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
23 * keystrokes.
25 * There's an invariant that all objects in the focus list must be selected.
28 #include <config.h>
30 #include "object.h"
31 #include "focus.h"
32 #include "display.h"
33 #include "highlight.h"
34 #include "textedit.h"
35 #include "object_ops.h"
36 #include "text.h"
38 /** Move the text edit focus either backwards or forwards. */
39 Focus *
40 textedit_move_focus(DDisplay *ddisp, Focus *focus, gboolean forwards)
42 if (focus != NULL) {
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);
49 if (forwards)
50 focus_next();
51 else
52 focus_previous();
53 focus = active_focus();
55 if (focus != NULL) {
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);
61 return focus;
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).
67 void
68 textedit_activate_focus(DDisplay *ddisp, Focus *focus, Point *clicked)
70 if (active_focus()) {
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);
76 if (clicked) {
77 text_set_cursor((Text*)focus->user_data, clicked, ddisp->renderer);
79 object_add_updates(focus->obj, ddisp->diagram);
80 give_focus(focus);
81 diagram_flush(ddisp->diagram);
84 /** Call when an object is chosen for activation (e.g. due to creation).
86 void
87 textedit_activate_object(DDisplay *ddisp, DiaObject *obj, Point *clicked)
89 if (active_focus()) {
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);
96 if (clicked) {
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. */
109 void
110 textedit_deactivate_focus()
112 Focus *focus = active_focus();
113 if (focus != NULL) {
114 highlight_object_off(focus->obj, ddisplay_active()->diagram);
115 remove_focus();
119 /** Call when something should be removed from the focus list */
120 void
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. */
129 void
130 textedit_remove_focus_all(Diagram *diagram)
132 Focus *focus = active_focus();
133 if (focus != NULL) {
134 highlight_object_off(focus->obj, diagram);
136 reset_foci();