1 /*
2 * Calcoo: b_main.c
3 *
4 * Copyright (C) 2001-2005 Alexei Kaminski
5 *
6 */
7
8 #include <stdlib.h>
9 #include <gtk/gtk.h>
10
11 #include "codes.h"
12 #include "body.h"
13 #include "defaults.h"
14 #include "b_headers.h"
15 #include "gtkaux_headers.h"
16 #include "io_headers.h"
17 #include "aux_headers.h"
18 #include "b_accel_headers.h"
19
20 #include "pixmaps/main.xpm"
21
22 t_calcoo_body *body;
23
24
create_body(void)25 void create_body(void)
26 {
27 malloc_body();
28 malloc_displays(); /* these displays are not widgets, but structures to
29 * store information what to display in the
30 * corresponding widgets */
31 create_widgets();
32 }
33
malloc_body(void)34 void malloc_body(void)
35 {
36 body = (t_calcoo_body*) malloc(sizeof(t_calcoo_body));
37 }
38
39
create_main_window(int w,int h)40 void create_main_window(int w, int h)
41 {
42 //GdkPixmap *main_pixmap;
43 //GdkBitmap *main_mask;
44 int i;
45
46 /* Main widget */
47 body->main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
48 gtk_window_set_title (GTK_WINDOW (body->main_window), "Calcoo");
49 gtk_container_set_border_width (GTK_CONTAINER (body->main_window), 0);
50 gtk_widget_set_size_request(body->main_window, w, h);
51 gtk_window_set_resizable (GTK_WINDOW (body->main_window),
52 FALSE);
53
54 g_signal_connect (G_OBJECT (body->main_window),
55 "delete_event",
56 GTK_SIGNAL_FUNC (gtk_main_quit),
57 NULL);
58 g_signal_connect (G_OBJECT (body->main_window),
59 "destroy",
60 GTK_SIGNAL_FUNC (gtk_main_quit),
61 NULL);
62 g_signal_connect (G_OBJECT (body->main_window),
63 "key_press_event",
64 GTK_SIGNAL_FUNC (key_press_handler),
65 NULL);
66 g_signal_connect (G_OBJECT (body->main_window),
67 "button_press_event",
68 GTK_SIGNAL_FUNC (button_press_handler),
69 NULL);
70 gtk_widget_set_events (body->main_window,
71 GDK_BUTTON_PRESS_MASK );
72
73 gtk_widget_show (body->main_window);
74
75 body->style = gtk_style_copy (
76 gtk_widget_get_style (body->main_window)
77 );
78
79 /* Main window icon */
80 /*
81 main_pixmap = gdk_pixmap_create_from_xpm_d (
82 (body->main_window)->window,
83 &main_mask,
84 &(body->style)->bg[GTK_STATE_NORMAL],
85 (gchar **) main_xpm
86 );
87
88 gdk_window_set_icon (body->main_window->window, NULL,
89 main_pixmap, main_mask);
90 */
91 gtk_window_set_icon (GTK_WINDOW(body->main_window),
92 gdk_pixbuf_new_from_xpm_data((const char **)main_xpm));
93
94 /* Fixer to fix the button positions and sizes */
95 body->fixer = gtk_fixed_new();
96 gtk_container_add (GTK_CONTAINER(body->main_window), body->fixer);
97 gtk_widget_show (body->fixer);
98
99 /* Button tooltips */
100 body->button_tooltips = gtk_tooltips_new();
101 //gtk_tooltips_set_delay(body->button_tooltips, DEFAULT_TOOLTIP_DELAY);
102
103 /* Setting all button pointers to NULL in order to be able to tell
104 * existing from non-existing buttons when making all the buttons
105 * active/non-active, like after an error */
106 for (i = 0; i < MAX_BUTTON_NUMBER; i++)
107 body->button[i] = NULL;
108
109 gtk_widget_show (body->main_window);
110
111 }
112
set_rpn_mode(int a)113 void set_rpn_mode(int a)
114 {
115 if (a) {
116 show_button(CODE_ENTER);
117 show_button(CODE_STACK_DOWN);
118 show_button(CODE_STACK_UP);
119 hide_button(CODE_EQ);
120 hide_button(CODE_RIGHT_PAREN);
121 hide_button(CODE_LEFT_PAREN);
122 } else {
123 show_button(CODE_EQ);
124 show_button(CODE_RIGHT_PAREN);
125 show_button(CODE_LEFT_PAREN);
126 hide_button(CODE_ENTER);
127 hide_button(CODE_STACK_DOWN);
128 hide_button(CODE_STACK_UP);
129 }
130 clicked_set_rpn_mode(a);
131 }
132
133 /* One may wonder why we introduce all these get_ and set_ functions below,
134 * which do not do anything but passing the requests further. The answer is
135 * that they pass it directly to the cpu, and we may still need to do something
136 * in the body. It is the case for set_rpn_mode(). It is not the case for the
137 * other functions, but since it may be the case in the future and also for
138 * uniformity, we decided to have these functions. */
139
get_rpn_mode(void)140 int get_rpn_mode(void)
141 {
142 return requested_rpn_mode();
143 }
144
set_enter_mode(int a)145 void set_enter_mode(int a)
146 {
147 clicked_set_enter_mode(a);
148 }
149
get_rounding_mode(void)150 int get_rounding_mode(void)
151 {
152 return requested_rounding_mode();
153 }
154
set_rounding_mode(int a)155 void set_rounding_mode(int a)
156 {
157 clicked_set_rounding_mode(a);
158 }
159
get_trunc_zeros_mode(void)160 int get_trunc_zeros_mode(void)
161 {
162 return requested_trunc_zeros_mode();
163 }
164
set_trunc_zeros_mode(int a)165 void set_trunc_zeros_mode(int a)
166 {
167 clicked_set_trunc_zeros_mode(a);
168 }
169
get_enter_mode(void)170 int get_enter_mode(void)
171 {
172 return requested_enter_mode();
173 }
174
set_stack_mode(int a)175 void set_stack_mode(int a)
176 {
177 clicked_set_stack_mode(a);
178 }
179
get_stack_mode(void)180 int get_stack_mode(void)
181 {
182 return requested_stack_mode();
183 }
184
get_angle_units(void)185 int get_angle_units(void)
186 {
187 return requested_angle_units();
188 }
189
set_angle_units(int a)190 void set_angle_units(int a)
191 {
192 clicked_set_angle_units(a);
193 }
194
call_exit(void)195 void call_exit(void)
196 {
197 gtk_main_quit();
198 }
199
200