Bumped versions to 1.1.2/20070818/30:2:0 for the next development snapshot
[geda-gaf/whiteaudio.git] / gschem / src / o_find.c
blobe0e60e1f0db7b99588736c659deedd0460b89fc9
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
22 #include <math.h>
23 #include <stdio.h>
25 #include <libgeda/libgeda.h>
27 #include "../include/x_states.h"
28 #include "../include/prototype.h"
30 #ifdef HAVE_LIBDMALLOC
31 #include <dmalloc.h>
32 #endif
34 /*! \todo Finish function documentation!!!
35 * \brief
36 * \par Function Description
39 gboolean o_find_object(TOPLEVEL *w_current, int screen_x, int screen_y,
40 gboolean change_selection)
42 OBJECT *o_current=NULL;
43 gboolean object_found = FALSE;
44 int w_x, w_y, w_slack;
46 SCREENtoWORLD( w_current, screen_x, screen_y, &w_x, &w_y );
47 w_slack = WORLDabs( w_current, w_current->select_slack_pixels );
49 if (w_current->page_current->object_lastplace == NULL) {
50 o_current = w_current->page_current->object_head;
51 } else {
52 o_current = w_current->page_current->object_lastplace;
55 /* do first search */
56 while (o_current != NULL) {
57 if (inside_region(o_current->w_left - w_slack, o_current->w_top - w_slack,
58 o_current->w_right + w_slack, o_current->w_bottom + w_slack,
59 w_x, w_y)) {
60 if (o_current->sel_func != NULL &&
61 o_current->type != OBJ_HEAD &&
62 (o_current->visibility == VISIBLE ||
63 (o_current->visibility == INVISIBLE &&
64 w_current->show_hidden_text))) {
65 if (change_selection) {
66 (*o_current->sel_func)(
67 w_current, o_current,
68 SINGLE, 0); /* 0 is count */
70 object_found = TRUE;
71 w_current->page_current-> object_lastplace =
72 o_current->next;
73 i_update_menus(w_current);
74 return object_found;
77 o_current = o_current->next;
80 #if DEBUG
81 printf("SEARCHING AGAIN\n");
82 #endif
84 /* now search again since we didn't find anything starting at start
85 just in case we started last time at object_lastplace */
86 o_current = w_current->page_current->object_head;
87 while (o_current != NULL &&
88 o_current != w_current->page_current->object_lastplace) {
89 if (inside_region(o_current->w_left - w_slack, o_current->w_top - w_slack,
90 o_current->w_right + w_slack, o_current->w_bottom + w_slack,
91 w_x, w_y)) {
93 if (o_current->sel_func != NULL &&
94 o_current->type != OBJ_HEAD &&
95 (o_current->visibility == VISIBLE ||
96 (o_current->visibility == INVISIBLE &&
97 w_current->show_hidden_text))) {
98 if (change_selection) {
99 /* 0 is count */
100 (*o_current->sel_func)(w_current, o_current, SINGLE, 0);
102 w_current->page_current->object_lastplace = o_current;
103 object_found = TRUE;
105 i_update_menus(w_current);
106 return object_found;
109 o_current = o_current->next;
112 /* didn't find anything.... reset lastplace */
113 w_current->page_current->object_lastplace = NULL;
115 /* deselect everything only if shift key isn't pressed and
116 the caller allows it */
117 if (change_selection && (!w_current->SHIFTKEY)) {
118 o_select_run_hooks(w_current, NULL, 2);
119 o_selection_unselect_list (w_current, w_current->page_current->selection_list );
122 i_update_menus(w_current);
124 return (object_found);
127 /*! \todo Finish function documentation!!!
128 * \brief
129 * \par Function Description
132 gboolean o_find_selected_object(TOPLEVEL *w_current,
133 int screen_x, int screen_y)
135 OBJECT *o_current=NULL;
136 GList *s_current;
137 int w_x, w_y, w_slack;
139 SCREENtoWORLD( w_current, screen_x, screen_y, &w_x, &w_y );
140 w_slack = WORLDabs( w_current, w_current->select_slack_pixels );
142 s_current = geda_list_get_glist( w_current->page_current->selection_list );
143 /* do first search */
144 while (s_current != NULL) {
145 o_current = (OBJECT *) s_current->data;
146 if (inside_region(o_current->w_left - w_slack, o_current->w_top - w_slack,
147 o_current->w_right + w_slack, o_current->w_bottom + w_slack,
148 w_x, w_y)) {
150 #if DEBUG
151 printf("o_find_selected_object:\n");
152 printf("Object bounds:\n\tL: %i\tR: %i\n\tT: %i\tB: %i.\n",
153 o_current->w_left, o_current->w_right, o_current->w_top, o_current->w_bottom);
154 printf("Screen pointer at: (%i,%i)\n", screen_x, screen_y);
155 #endif
156 if (o_current->sel_func != NULL &&
157 o_current->type != OBJ_HEAD &&
158 (o_current->visibility == VISIBLE ||
159 (o_current->visibility == INVISIBLE &&
160 w_current->show_hidden_text))) {
161 return TRUE;
165 s_current = s_current->next;
168 return (FALSE);