1 /* Dia -- a 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 files handles which text elements are currently eligible to get
20 * the input focus, and moving back and forth between them. Objects can
21 * add their texts to the list with request_focus (more than one can be
22 * added), which doesn't give them focus outright, but makes them part of
23 * the focus chain. Actual handling of when focus goes where is handled
24 * in app/disp_callbacks.c
31 static Focus
*active_focus_ptr
= NULL
;
32 static GList
*text_foci
= NULL
;
34 /** Request that the give focus become active.
35 * Also adds the focus to the list of available foci.
36 * Eventually, this will only add the focus to the list. */
38 request_focus(Focus
*focus
)
40 /* Only add to focus list if not already there, and don't snatch focus. */
41 if (!g_list_find(text_foci
, focus
)) {
42 text_foci
= g_list_append(text_foci
, focus
);
45 if (active_focus_ptr
!= NULL
) {
46 active_focus_ptr
->has_focus
= FALSE
;
48 active_focus_ptr
= focus
;
49 active_focus_ptr
->has_focus
= TRUE
;
50 text_foci
= g_list_append(text_foci
, focus
);
53 /** Return the currently active focus */
57 return active_focus_ptr
;
61 give_focus(Focus
*focus
)
63 if (active_focus_ptr
!= NULL
) {
64 active_focus_ptr
->has_focus
= FALSE
;
66 active_focus_ptr
= focus
;
67 active_focus_ptr
->has_focus
= TRUE
;
70 /* Return the first focus on the given object
73 focus_get_first_on_object(DiaObject
*obj
)
75 GList
*tmplist
= text_foci
;
77 for (; tmplist
!= NULL
; tmplist
= g_list_next(tmplist
) ) {
78 Focus
*focus
= (Focus
*)tmplist
->data
;
79 if (focus_get_object(focus
) == obj
) {
86 /** Return the object that this focus belongs to. Note that each
87 * object may have more than one Text associated with it, the
88 * focus will be on one of those.
91 focus_get_object(Focus
*focus
)
96 /** Return the next available focus, if one is already active.
101 if (text_foci
!= NULL
&& active_focus_ptr
!= NULL
) {
102 GList
*listelem
= g_list_find(text_foci
, active_focus_ptr
);
103 listelem
= g_list_next(listelem
);
104 if (listelem
== NULL
) listelem
= text_foci
;
105 return ((Focus
*)listelem
->data
);
110 /** Return the previous available focus, if one is already active.
115 if (text_foci
!= NULL
&& active_focus_ptr
!= NULL
) {
116 GList
*listelem
= g_list_find(text_foci
, active_focus_ptr
);
117 listelem
= g_list_previous(listelem
);
118 if (listelem
== NULL
)
119 listelem
= g_list_last(text_foci
);
120 return (Focus
*)listelem
->data
;
125 /** Remove the current focus */
129 if (active_focus_ptr
!= NULL
) {
130 active_focus_ptr
->has_focus
= FALSE
;
132 active_focus_ptr
= NULL
;
135 /** Reset the list of currently available foci */
139 g_list_free(text_foci
);
143 /** Removes all foci owned by the object.
144 * Returns TRUE if the object had the active focus.
147 remove_focus_object(DiaObject
*obj
)
149 GList
*tmplist
= text_foci
;
150 gboolean active
= FALSE
;
152 for (; tmplist
!= NULL
; ) {
153 Focus
*focus
= (Focus
*)tmplist
->data
;
154 GList
*link
= tmplist
;
155 tmplist
= g_list_next(tmplist
);
156 if (focus_get_object(focus
) == obj
) {
157 text_foci
= g_list_delete_link(text_foci
, link
);
158 if (focus
== active_focus_ptr
) {