File: help.c

package info (click to toggle)
grpn 1.4.1-1.1
  • links: PTS
  • area: main
  • in suites: bookworm, sid
  • size: 2,020 kB
  • sloc: ansic: 6,616; makefile: 74
file content (278 lines) | stat: -rw-r--r-- 8,017 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*

Copyright (C) 2002  Paul Wilkins

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
of the License, 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>

#include "help.h"
#include "funcs.h"
#include "buttons.h"
#include "license.h"
#include "version.h"


#define ABOUT_TXT \
"GRPN is a graphical reverse polish notation (RPN) calculator.\n\
\n\
By: Paul Wilkins\n\
    paul.wilkins at analog com\n\
    Fix_locale.dpatch by Wartan Hachaturow <wart at debian.org>\n\
    Add_includes.dpatch by Michael Bienia <geser at ubuntu.com>\n\
    gtk2.dpatch by Barry deFreese <bdefreese at debian.org>\n\
    Support for Pango-fonts by Jean-Pierre Demailly.\n\
    Shift operators by Nathaniel Clark.\n\
    Changes since version 1.1.2-3: Jens Getreu <getreu at web.de>\n\
\n\
"

#define HELP_TXT \
"\
GRPN is a graphical reverse polish notation (RPN) calculator.\n\
\n\
GRPN works with real numbers, complex numbers, matrices, and\n\
complex matrices.  Numbers can be displayed in 4 different\n\
radix modes, and complex numbers can be displayed in either\n\
Cartesian or polar form.\n\
\n\
GRPN uses a stack and reverse polish notation to evaluate\n\
expressions.  The stack in GRPN is infinite and limited only\n\
by available memory.\n\
\n\
Expressions are evaluated in reverse polish notation.  Unlike\n\
conventional (prefix) notation, RPN requires that all arguments\n\
to a command are entered prior to execution of the command.  For\n\
example to add 6.7 to 3.2 you would push both numbers onto the\n\
stack, then press the add (+) button:\n\
\n\
3.2<enter>\n\
6.7<enter>\n\
+\n\
\n\
The result is left on the stack.\n\
\n\
Cntr-c copies the result to the clipboard for use in \n\
other applications. \n\
\n\
Note that GRPN uses a shorthand for all commands that causes\n\
an automatic <enter> before executing a command.  The previous\n\
example could then be done as:\n\
\n\
3.2<enter>\n\
6.7+\n\
\n\
Input is accepted from both the keyboard and the mouse.  When\n\
entering a command from the keyboard, the command may be\n\
abbreviated to the shortest set of letters which uniquely\n\
identifies the command.\n\
\n\
Input may be forced to be interpreted as a command by prefixing\n\
the command with double or single quotes.  This is useful, for\n\
example when in Hexadecimal mode and you would like to switch to\n\
decimal mode by typing:\n\
dec\n\
\n\
Mouse input simply requires pressing the button with the desired\n\
command.\n\
\n\
To enter a matrix first push its data on the stack as you would\n\
lines, f. ex.:\n\
1<enter> 2<enter> 3<enter> 4<enter> 5<enter> 6<enter>\n\
\n\
Then you can enter the dimension of the matrix f. ex.:\n\
3<enter> 2<enter> matrix<enter>\n\
\n\
As you can see in the following output, the command 'matrix'\n\
creates (or decomposes) the matrix:\n\
1:  [1 2 3 \n\
     4 5 6]\n\
\n\
Complex numbers are entered in a similar way:\n\
3<enter> 7<enter> complex<enter>\n\
1:  (3,7)\n\
\n\
Note that the complex-command also decomposes\n\
complex numbers:\n\
complex<enter>\n\
2:  3\n\
1:  7\n\
\n\
The 'undo' command allows you to undo up to the last 10\n\
operations.\n\
\n\
Available commands:\n\
\n\
+           Add.\n\
-           Subtract.\n\
*           Multiply.\n\
/           Divide.\n\
^           Power.\n\
<enter>     Push a number onto the top of the stack.\n\
<space>     Push a number onto the top of the stack.\n\
"

void popup_window(GtkWidget **dialog, char *txt, char *title){


   GtkWidget *vbox;
   GtkWidget *scrolled_win;
   GtkWidget *label;
   GtkWidget *button;
 
   if (!*dialog) {

      *dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_window_set_title(GTK_WINDOW(*dialog), title);

      gtk_signal_connect(GTK_OBJECT(*dialog), "destroy",
                        GTK_SIGNAL_FUNC(gtk_widget_destroyed),
                        dialog);
#ifdef GTK_VER_1_1
      gtk_container_set_border_width(GTK_CONTAINER(*dialog), 5); 
#else
      gtk_container_border_width(GTK_CONTAINER(*dialog), 5); 
#endif

      gtk_window_set_title(GTK_WINDOW(*dialog), title);
      gtk_widget_set_usize(*dialog, 470, 470);

      vbox = gtk_vbox_new(FALSE, 0);
      gtk_container_add(GTK_CONTAINER(*dialog), vbox);
      gtk_widget_show(vbox);

      scrolled_win = gtk_scrolled_window_new (NULL, NULL);
#ifdef GTK_VER_1_1
      gtk_container_set_border_width(GTK_CONTAINER(scrolled_win), 5); 
#else
      gtk_container_border_width(GTK_CONTAINER(scrolled_win), 5); 
#endif
      gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_win),
                                     GTK_POLICY_AUTOMATIC,
                                     GTK_POLICY_AUTOMATIC);
      gtk_box_pack_start(GTK_BOX(vbox), scrolled_win, TRUE, TRUE, 0);
      gtk_widget_show(scrolled_win);

      label = gtk_label_new(txt);
      gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
#ifdef GTK_VER_1_1
      gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_win), label);
#else
      gtk_container_add(GTK_CONTAINER(scrolled_win), label);
#endif
      gtk_widget_show(label);

      button = gtk_button_new_with_label("Dismiss");
      gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
                                 GTK_SIGNAL_FUNC(gtk_widget_destroy),
                                 GTK_OBJECT(*dialog));
      gtk_box_pack_end(GTK_BOX(vbox), button, FALSE, FALSE, 0);
      GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
      /* gtk_widget_grab_default(button);  This puts an ugly box around the botton */
      gtk_widget_show(button);
 
   }

   if (!GTK_WIDGET_VISIBLE(*dialog))
      gtk_widget_show(*dialog);
   else
      gtk_widget_destroy(*dialog);

}
 

void license_popup(){
   int i;
   char *htxt;
   static GtkWidget *licenseDialog = NULL;
 
   if(NULL == (htxt = (char*)malloc((10000)*sizeof(char)))){
      perror("license_popup: malloc");
      return;
   } else {
      strcpy(htxt, LICENSE_TXT);
      //popup_window wants a long text to scroll
      for(i=0; i<60; i++){
	       strcat(htxt, "\n");
      }
   }
   popup_window(&licenseDialog, htxt, "License");
   free(htxt);
}
 
 

void help_popup(){
   int i, j, k;
   int cmds;
   int len;
   char *htxt;
   char *cmd;
   static GtkWidget *helpDialog = NULL;

   cmds = 0;
   for(i=0; i<NumFunctionRows; i++){
      cmds += rowinf[i].numBtns;
   }
   if(NULL == (htxt = (char*)malloc((10000+cmds*60)*sizeof(char)))){
      perror("help_popup: malloc");
      return;
   } else {
      strcpy(htxt, HELP_TXT);
      // append the list of commands to the help text 
      for(i=0; i<NumFunctionRows; i++){
	 for(j=0; j<rowinf[i].numBtns; j++){
	    cmd = rowinf[i].fi[j].cmd;
	    if(cmd != NULL){
	       strcat(htxt, cmd);
	       len = 12 - strlen(cmd);
	       for(k=0; k<len; k++) strcat(htxt, " ");
	       strcat(htxt, rowinf[i].fi[j].help);
	       strcat(htxt, "\n");
	    }
	 }
      }
   }

   popup_window(&helpDialog, htxt, "Help");

   free(htxt);

}

void about_popup(){
   int i;
   char *htxt;
   static GtkWidget *aboutDialog = NULL;
 
   if(NULL == (htxt = (char*)malloc((10000)*sizeof(char)))){
      perror("about_popup: malloc");
      return;
   } else {
      strcpy(htxt, GRPN_VERSION);
      strcat(htxt, ABOUT_TXT);
      //popup_window wants a long text to scroll
      for(i=0; i<60; i++){
	       strcat(htxt, "\n");
      }
   }
   popup_window(&aboutDialog, htxt, "About");
   free(htxt);
}