[gcalctool] Merged dsfuns.c into gtk.c
- From: Robert Ancell <rancell src gnome org>
- To: svn-commits-list gnome org
- Subject: [gcalctool] Merged dsfuns.c into gtk.c
- Date: Sun, 10 May 2009 21:58:05 -0400 (EDT)
commit ecf9219f173691d213182698d23ad2ac190a0ed7
Author: Robert Ancell <robert ancell gmail com>
Date: Mon May 11 11:57:32 2009 +1000
Merged dsfuns.c into gtk.c
---
src/Makefile.am | 2 -
src/dsdefs.h | 48 ----------------
src/dsfuns.c | 163 -------------------------------------------------------
src/gtk.c | 97 +++++++++++++++++++++++++++++++--
4 files changed, 93 insertions(+), 217 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index ef757fa..f9a13f2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,8 +18,6 @@ gcalctool_SOURCES = \
calctool.h \
display.c \
display.h \
- dsfuns.c \
- dsdefs.h \
get.c \
get.h \
functions.c \
diff --git a/src/dsdefs.h b/src/dsdefs.h
deleted file mode 100644
index d6b3621..0000000
--- a/src/dsdefs.h
+++ /dev/null
@@ -1,48 +0,0 @@
-
-/* $Header$
- *
- * External definitions needed by calctool from the libdeskset, libguide
- * and libguidexv include files.
- *
- * Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef __DSDEFS_H__
-#define __DSDEFS_H__
-
-#include <stdio.h>
-#include <gtk/gtk.h>
-
-/* Definitions taken from .../libdeskset/<various>.h */
-
-/* Location ops for ds_position_popup(). */
-
-enum ds_location_op {
- DS_POPUP_RIGHT, /* Place popup to right of baseframe */
- DS_POPUP_LEFT, /* Place popup to left of baseframe */
- DS_POPUP_ABOVE, /* Place popup above baseframe */
- DS_POPUP_BELOW, /* Place popup below baseframe */
- DS_POPUP_LOR, /* Place popup to right or left of baseframe */
- DS_POPUP_AOB, /* Place popup above or below baseframe */
- DS_POPUP_CENTERED /* Center popup within baseframe */
-};
-
-int ds_position_popup(GtkWidget *base, GtkWidget *popup,
- enum ds_location_op location_op);
-
-#endif /* __DSDEFS_H__ */
diff --git a/src/dsfuns.c b/src/dsfuns.c
deleted file mode 100644
index 1c4b615..0000000
--- a/src/dsfuns.c
+++ /dev/null
@@ -1,163 +0,0 @@
-
-/* $Header$
- *
- * External functions needed by calctool from the libdeskset, libguide
- * and libguidexv libraries.
- *
- * Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include <stdlib.h>
-#include "calctool.h"
-#include "dsdefs.h"
-
-#define WM_WIDTH_FACTOR 10
-#define WM_HEIGHT_FACTOR 30
-
-static int ds_position_popup_rect(int, int, int, int, GtkWidget *,
- enum ds_location_op);
-static int ds_force_popup_on_screen(int *, int *, int, int, GtkWidget *);
-static int ds_get_screen_size(int *, int *);
-
-
-int
-ds_position_popup(GtkWidget *base, GtkWidget *popup,
- enum ds_location_op location_op)
-{
- int x, y, width, height;
-
- gtk_window_get_position(GTK_WINDOW(base), &x, &y);
- gtk_window_get_size(GTK_WINDOW(base), &width, &height);
-
- return(ds_position_popup_rect(x, y, width, height, popup, location_op));
-}
-
-
-static int
-ds_position_popup_rect(int base_x, int base_y, int base_width, int base_height,
- GtkWidget *popup, enum ds_location_op location_op)
-{
- int popup_x, popup_y, popup_width, popup_height;
- int screen_width, screen_height;
-
- gtk_window_get_position(GTK_WINDOW(popup), &popup_x, &popup_y);
- gtk_window_get_size(GTK_WINDOW(popup), &popup_width, &popup_height);
-
- ds_get_screen_size(&screen_width, &screen_height);
-
- if (location_op == DS_POPUP_LOR) {
- if (base_x >= screen_width - base_width - base_x) {
- location_op = DS_POPUP_LEFT;
- } else {
- location_op = DS_POPUP_RIGHT;
- }
- } else if (location_op == DS_POPUP_AOB) {
- if (base_y > screen_height - base_height - base_y) {
- location_op = DS_POPUP_ABOVE;
- } else {
- location_op = DS_POPUP_BELOW;
- }
- }
-
- switch (location_op) {
- case DS_POPUP_RIGHT:
- popup_x = base_x + base_width + WM_WIDTH_FACTOR;
- popup_y = base_y;
- break;
-
- case DS_POPUP_LEFT:
- popup_x = base_x - popup_width - WM_WIDTH_FACTOR;
- popup_y = base_y;
- break;
-
- case DS_POPUP_ABOVE:
- popup_x = base_x;
- popup_y = base_y - popup_height - WM_HEIGHT_FACTOR;
- break;
-
- case DS_POPUP_BELOW:
- popup_x = base_x;
- popup_y = base_y + base_height + WM_HEIGHT_FACTOR;
- break;
-
- case DS_POPUP_CENTERED:
- default:
- popup_x = base_x + (base_width - popup_width) / 2;
- popup_y = base_y + (base_height - popup_height) / 2;
- break;
- }
-
- ds_force_popup_on_screen(&popup_x, &popup_y,
- popup_width, popup_height, popup);
-
- return(1);
-}
-
-
-/*ARGSUSED*/
-static int
-ds_force_popup_on_screen(int *popup_x_p, int *popup_y_p,
- int popup_width, int popup_height,
- GtkWidget *popup)
-{
- int popup_x, popup_y, screen_width, screen_height, n, rcode;
-
- popup_x = *popup_x_p;
- popup_y = *popup_y_p;
-
- /* Get the screen size */
- ds_get_screen_size(&screen_width, &screen_height);
-
- /* Make sure frame doesn't go off side of screen */
- n = popup_x + popup_width;
- if (n > screen_width) {
- popup_x -= (n - screen_width);
- } else if (popup_x < 0) {
- popup_x = 0;
- }
-
- /* Make sure frame doesn't go off top or bottom */
- n = popup_y + popup_height;
- if (n > screen_height) {
- popup_y -= n - screen_height;
- } else if (popup_y < 0) {
- popup_y = 0;
- }
-
- gtk_window_move(GTK_WINDOW(popup), popup_x, popup_y);
-
- if (popup_x != *popup_x_p || popup_y != *popup_y_p) {
- rcode = TRUE;
- } else {
- rcode = FALSE;
- }
- *popup_x_p = popup_x;
- *popup_y_p = popup_y;
-
- return(rcode);
-}
-
-
-static int
-ds_get_screen_size(int *width_p, int *height_p)
-{
- *width_p = gdk_screen_width();
- *height_p = gdk_screen_height();
-
- return(1);
-}
diff --git a/src/gtk.c b/src/gtk.c
index ffe4cb5..bc9cc3d 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -35,7 +35,6 @@
#include "ui.h"
#include "config.h"
-#include "dsdefs.h"
#include "functions.h"
#include "financial.h"
#include "mp-equation.h"
@@ -533,6 +532,96 @@ enum {
static void setup_finc_dialogs ();
+#define WM_WIDTH_FACTOR 10
+#define WM_HEIGHT_FACTOR 30
+
+typedef enum {
+ POPUP_RIGHT, /* Place popup to right of baseframe */
+ POPUP_LEFT, /* Place popup to left of baseframe */
+ POPUP_ABOVE, /* Place popup above baseframe */
+ POPUP_BELOW, /* Place popup below baseframe */
+ POPUP_LOR, /* Place popup to right or left of baseframe */
+ POPUP_AOB, /* Place popup above or below baseframe */
+ POPUP_CENTERED /* Center popup within baseframe */
+} PopupLocation;
+
+static void
+position_popup(GtkWidget *base, GtkWidget *popup,
+ PopupLocation location_op)
+{
+ int base_x, base_y, base_width, base_height;
+ int popup_x, popup_y, popup_width, popup_height;
+ int screen_width, screen_height;
+ int n;
+
+ gtk_window_get_position(GTK_WINDOW(base), &base_x, &base_y);
+ gtk_window_get_size(GTK_WINDOW(base), &base_width, &base_height);
+ gtk_window_get_position(GTK_WINDOW(popup), &popup_x, &popup_y);
+ gtk_window_get_size(GTK_WINDOW(popup), &popup_width, &popup_height);
+ screen_width = gdk_screen_width();
+ screen_height = gdk_screen_height();
+
+ if (location_op == POPUP_LOR) {
+ if (base_x >= screen_width - base_width - base_x) {
+ location_op = POPUP_LEFT;
+ } else {
+ location_op = POPUP_RIGHT;
+ }
+ } else if (location_op == POPUP_AOB) {
+ if (base_y > screen_height - base_height - base_y) {
+ location_op = POPUP_ABOVE;
+ } else {
+ location_op = POPUP_BELOW;
+ }
+ }
+
+ switch (location_op) {
+ case POPUP_RIGHT:
+ popup_x = base_x + base_width + WM_WIDTH_FACTOR;
+ popup_y = base_y;
+ break;
+
+ case POPUP_LEFT:
+ popup_x = base_x - popup_width - WM_WIDTH_FACTOR;
+ popup_y = base_y;
+ break;
+
+ case POPUP_ABOVE:
+ popup_x = base_x;
+ popup_y = base_y - popup_height - WM_HEIGHT_FACTOR;
+ break;
+
+ case POPUP_BELOW:
+ popup_x = base_x;
+ popup_y = base_y + base_height + WM_HEIGHT_FACTOR;
+ break;
+
+ case POPUP_CENTERED:
+ default:
+ popup_x = base_x + (base_width - popup_width) / 2;
+ popup_y = base_y + (base_height - popup_height) / 2;
+ break;
+ }
+
+ /* Make sure frame doesn't go off side of screen */
+ n = popup_x + popup_width;
+ if (n > screen_width) {
+ popup_x -= (n - screen_width);
+ } else if (popup_x < 0) {
+ popup_x = 0;
+ }
+
+ /* Make sure frame doesn't go off top or bottom */
+ n = popup_y + popup_height;
+ if (n > screen_height) {
+ popup_y -= n - screen_height;
+ } else if (popup_y < 0) {
+ popup_y = 0;
+ }
+
+ gtk_window_move(GTK_WINDOW(popup), popup_x, popup_y);
+}
+
void
ui_set_accuracy(int accuracy)
{
@@ -1193,7 +1282,7 @@ ui_set_registers_visible(gboolean visible)
gdk_window_raise(X.rframe->window);
return;
}
- ds_position_popup(X.kframe, X.rframe, DS_POPUP_ABOVE);
+ position_popup(X.kframe, X.rframe, POPUP_ABOVE);
gtk_widget_show(X.rframe);
} else {
gtk_widget_hide(X.rframe);
@@ -2219,7 +2308,7 @@ void
insert_ascii_cb(GtkWidget *widget)
{
if (!GTK_WIDGET_VISIBLE(X.aframe)) {
- ds_position_popup(X.kframe, X.aframe, DS_POPUP_LEFT);
+ position_popup(X.kframe, X.aframe, POPUP_LEFT);
}
gtk_widget_grab_focus(GTK_WIDGET(X.aframe_ch));
gtk_widget_show(X.aframe);
@@ -2278,7 +2367,7 @@ void
accuracy_other_cb(GtkWidget *widget)
{
if (!GTK_WIDGET_VISIBLE(X.spframe)) {
- ds_position_popup(X.kframe, X.spframe, DS_POPUP_LEFT);
+ position_popup(X.kframe, X.spframe, POPUP_LEFT);
}
gtk_widget_grab_focus(GTK_WIDGET(X.precision_spin));
gtk_widget_show(X.spframe);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]