gschem

x_basic.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <math.h>
00024 
00025 #include "gschem.h"
00026 
00027 #ifdef HAVE_LIBDMALLOC
00028 #include <dmalloc.h>
00029 #endif
00030 
00036 void x_repaint_background_region (GSCHEM_TOPLEVEL *w_current,
00037                                   int x, int y, int width, int height)
00038 {
00039   TOPLEVEL *toplevel = w_current->toplevel;
00040 
00041   gdk_gc_set_foreground (w_current->gc,
00042                          x_get_color (toplevel->background_color));
00043 
00044   gdk_draw_rectangle (w_current->drawable,
00045                       w_current->gc, TRUE, x, y, width, height);
00046 
00047   x_grid_draw_region (w_current, x, y, width, height);
00048 }
00049 
00055 void x_hscrollbar_set_ranges(GSCHEM_TOPLEVEL *w_current)
00056 {
00057   TOPLEVEL *toplevel = w_current->toplevel;
00058         GtkAdjustment        *hadjustment;
00059 
00060     if (w_current->scrollbars_flag == FALSE) {
00061         return;
00062     }
00063 
00064     hadjustment =
00065         gtk_range_get_adjustment(GTK_RANGE(w_current->h_scrollbar));
00066 
00067     hadjustment->lower = toplevel->init_left;
00068     hadjustment->upper = toplevel->init_right;
00069 
00070 }
00071 
00077 void x_hscrollbar_update(GSCHEM_TOPLEVEL *w_current)
00078 {
00079   TOPLEVEL *toplevel = w_current->toplevel;
00080   GtkAdjustment *hadjustment;
00081 
00082   if (w_current->scrollbars_flag == FALSE) {
00083     return;
00084   }
00085 
00086   if (w_current->h_scrollbar == NULL) {
00087     return;
00088   }
00089 
00090   hadjustment = gtk_range_get_adjustment (GTK_RANGE (
00091                                                      w_current->h_scrollbar));
00092 
00093   hadjustment->value = toplevel->page_current->left;
00094 
00095   hadjustment->page_size = fabs(toplevel->page_current->right -
00096                                 toplevel->page_current->left);
00097 
00098   hadjustment->page_increment = hadjustment->page_size - 100.0;
00099 
00100 #if DEBUG
00101   printf("H %f %f\n", hadjustment->lower, hadjustment->upper);
00102   printf("Hp %f\n", hadjustment->page_size);
00103 #endif
00104 
00105   gtk_signal_emit_by_name(GTK_OBJECT(hadjustment), "changed");
00106   gtk_signal_emit_by_name(GTK_OBJECT(hadjustment), "value_changed");
00107 }
00108 
00114 void x_vscrollbar_set_ranges(GSCHEM_TOPLEVEL *w_current)
00115 {
00116   TOPLEVEL *toplevel = w_current->toplevel;
00117   GtkAdjustment *vadjustment;
00118 
00119   if (w_current->scrollbars_flag == FALSE) {
00120     return;
00121   }
00122 
00123   vadjustment =
00124   gtk_range_get_adjustment(GTK_RANGE(w_current->v_scrollbar));
00125 
00126   vadjustment->lower = toplevel->init_top;
00127   vadjustment->upper = toplevel->init_bottom;
00128 }
00129 
00135 void x_vscrollbar_update(GSCHEM_TOPLEVEL *w_current)
00136 {
00137   TOPLEVEL *toplevel = w_current->toplevel;
00138   GtkAdjustment *vadjustment;
00139 
00140   if (w_current->scrollbars_flag == FALSE) {
00141     return;
00142   }
00143 
00144   if (w_current->v_scrollbar == NULL) {
00145     return;
00146   }
00147 
00148   vadjustment =
00149   gtk_range_get_adjustment(GTK_RANGE(w_current->v_scrollbar));
00150 
00151   vadjustment->page_size = fabs(toplevel->page_current->bottom -
00152                                 toplevel->page_current->top);
00153 
00154   vadjustment->page_increment = vadjustment->page_size - 100.0;
00155 
00156   vadjustment->value =
00157   toplevel->init_bottom - toplevel->page_current->bottom;
00158 
00159 #if DEBUG
00160   printf("V %f %f\n", vadjustment->lower, vadjustment->upper);
00161   printf("Vp %f\n", vadjustment->page_size);
00162 #endif
00163 
00164   gtk_signal_emit_by_name(GTK_OBJECT(vadjustment), "changed");
00165   gtk_signal_emit_by_name(GTK_OBJECT(vadjustment), "value_changed");
00166 }
00167 
00173 void x_scrollbars_update(GSCHEM_TOPLEVEL *w_current)
00174 {
00175   if (w_current->scrollbars_flag == FALSE) {
00176     return;
00177   }
00178 
00179   x_hscrollbar_update(w_current);
00180   x_vscrollbar_update(w_current);
00181 }
00182 
00183 
00189 void x_basic_warp_cursor (GtkWidget* widget, gint x, gint y)
00190 {
00191   GdkScreen *screen;
00192   GdkDisplay *display;
00193   int window_x, window_y;
00194 
00195   gdk_window_get_origin (widget->window, &window_x, &window_y);
00196 
00197   screen = gtk_widget_get_screen (widget);
00198   display = gdk_screen_get_display (screen);
00199 
00200   gdk_display_warp_pointer (display, screen, window_x + x, window_y + y);
00201 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines