7 /* location of UI XML file relative to path in which program is running */
8 #define BUILDER_XML_FILE "kal.glade"
10 #define MAX_VALUE 9999
13 // struktura s ukazateli na jednotlive widgety v aplikaci
40 //deklarace globalnich promenych pro vysledky kalkulacky
45 int operace
=0; //udaj o tom, co se ma delat
46 int desetina
=0; //pri hodnote 1 se už tvori desetina cisla
48 int omezeni
=8; //omezeni kolik maximalne muze uzivatel zadat cislic na jedno cislo
50 * 0 - nic, nebylo zadano
60 // handler, ktery je v glade prirazen stisknuti tlacitka
61 void on_button0_clicked (GtkObject
*object
, App
*app
)
63 if ((operace
==0)||(operace
==8)){ //zatim je jen jedno cislo
68 else{ //uz bylo vybrano a tak se to pouzije...
69 //zde by mela byt moznost scitani
72 x = atoi(gtk_entry_get_text(app->entry));
78 snprintf(str,10,"%d",x);
79 gtk_entry_set_text(app->entry,str);*/
80 //app->label1->set_label("tlacitko 1");
81 //app->label1 = gtk_label_new("Cold was my");
82 //gtk_label_set_text(app->label1,"pokus");
85 void on_button1_clicked (GtkObject
*object
, App
*app
)
87 if ((operace
==0)||(operace
==8)){ //zatim je jen jedno cislo
92 else{ //uz bylo vybrano a tak se to pouzije...
93 //zde by mela byt moznost scitani
96 void on_button2_clicked (GtkObject
*object
, App
*app
)
98 if ((operace
==0)||(operace
==8)){ //zatim je jen jedno cislo
103 else{ //uz bylo vybrano a tak se to pouzije...
104 //zde by mela byt moznost scitani
107 void on_button3_clicked (GtkObject
*object
, App
*app
)
109 if ((operace
==0)||(operace
==8)){ //zatim je jen jedno cislo
114 else{ //uz bylo vybrano a tak se to pouzije...
115 //zde by mela byt moznost scitani
118 void on_button4_clicked (GtkObject
*object
, App
*app
)
120 if ((operace
==0)||(operace
==8)){ //zatim je jen jedno cislo
125 else{ //uz bylo vybrano a tak se to pouzije...
126 //zde by mela byt moznost scitani
129 void on_button5_clicked (GtkObject
*object
, App
*app
)
131 hodnota1
=logaritmus(hodnota1
.result
);
132 char* x
= malloc(sizeof(char)*15);
133 sprintf(x
,"%.5f",hodnota1
.result
);
134 gtk_label_set_text(app
->label1
,x
);
136 operace
=0; //uz nebude mozne zadavat hodnotu 1
140 void on_button6_clicked (GtkObject
*object
, App
*app
)
142 hodnota1
=faktorial(hodnota1
.result
);
143 char* x
= malloc(sizeof(char)*15);
144 sprintf(x
,"%.5f",hodnota1
.result
);
145 gtk_label_set_text(app
->label1
,x
);
147 operace
=0; //uz nebude mozne zadavat hodnotu 1
151 void on_button7_clicked (GtkObject
*object
, App
*app
)
160 gtk_label_set_text(app
->label1
,"Kalkulacka BETON");
162 void on_button8_clicked (GtkObject
*object
, App
*app
)
166 char* x
= malloc(sizeof(char)*15);
169 hodnota1
.result
=hodnota1
.result
* 10 + 1;
172 hodnota1
.result
=hodnota1
.result
+ (1.0/pow(10,desetina
));
175 sprintf(x
,"%.5f",hodnota1
.result
);
176 gtk_label_set_text(app
->label1
,x
);
180 hodnota2
.result
=hodnota2
.result
* 10 + 1;
183 hodnota2
.result
=hodnota2
.result
+ (1.0/pow(10,desetina
));
186 sprintf(x
,"%.5f",hodnota2
.result
);
187 gtk_label_set_text(app
->label1
,x
);
192 void on_button9_clicked (GtkObject
*object
, App
*app
)
196 char* x
= malloc(sizeof(char)*15);
199 hodnota1
.result
=hodnota1
.result
* 10 + 2;
202 hodnota1
.result
=hodnota1
.result
+ (2.0/pow(10,desetina
));
205 sprintf(x
,"%.5f",hodnota1
.result
);
206 gtk_label_set_text(app
->label1
,x
);
210 hodnota2
.result
=hodnota2
.result
* 10 + 2;
213 hodnota2
.result
=hodnota2
.result
+ (2.0/pow(10,desetina
));
216 sprintf(x
,"%.5f",hodnota2
.result
);
217 gtk_label_set_text(app
->label1
,x
);
222 void on_button10_clicked (GtkObject
*object
, App
*app
)
226 char* x
= malloc(sizeof(char)*15);
229 hodnota1
.result
=hodnota1
.result
* 10 + 3;
232 hodnota1
.result
=hodnota1
.result
+ (3.0/pow(10,desetina
));
235 sprintf(x
,"%.5f",hodnota1
.result
);
236 gtk_label_set_text(app
->label1
,x
);
240 hodnota2
.result
=hodnota2
.result
* 10 + 3;
243 hodnota2
.result
=hodnota2
.result
+ (3.0/pow(10,desetina
));
246 sprintf(x
,"%.5f",hodnota2
.result
);
247 gtk_label_set_text(app
->label1
,x
);
252 void on_button11_clicked (GtkObject
*object
, App
*app
)
256 char* x
= malloc(sizeof(char)*15);
259 hodnota1
.result
=hodnota1
.result
* 10 + 4;
262 hodnota1
.result
=hodnota1
.result
+ (4.0/pow(10,desetina
));
265 sprintf(x
,"%.5f",hodnota1
.result
);
266 gtk_label_set_text(app
->label1
,x
);
270 hodnota2
.result
=hodnota2
.result
* 10 + 4;
273 hodnota2
.result
=hodnota2
.result
+ (4.0/pow(10,desetina
));
276 sprintf(x
,"%.5f",hodnota2
.result
);
277 gtk_label_set_text(app
->label1
,x
);
282 void on_button12_clicked (GtkObject
*object
, App
*app
)
286 char* x
= malloc(sizeof(char)*15);
289 hodnota1
.result
=hodnota1
.result
* 10 + 5;
292 hodnota1
.result
=hodnota1
.result
+ (5.0/pow(10,desetina
));
295 sprintf(x
,"%.5f",hodnota1
.result
);
296 gtk_label_set_text(app
->label1
,x
);
300 hodnota2
.result
=hodnota2
.result
* 10 + 5;
303 hodnota2
.result
=hodnota2
.result
+ (5.0/pow(10,desetina
));
306 sprintf(x
,"%.5f",hodnota2
.result
);
307 gtk_label_set_text(app
->label1
,x
);
312 void on_button13_clicked (GtkObject
*object
, App
*app
)
316 char* x
= malloc(sizeof(char)*15);
319 hodnota1
.result
=hodnota1
.result
* 10 + 6;
322 hodnota1
.result
=hodnota1
.result
+ (6.0/pow(10,desetina
));
325 sprintf(x
,"%.5f",hodnota1
.result
);
326 gtk_label_set_text(app
->label1
,x
);
330 hodnota2
.result
=hodnota2
.result
* 10 + 6;
333 hodnota2
.result
=hodnota2
.result
+ (6.0/pow(10,desetina
));
336 sprintf(x
,"%.5f",hodnota2
.result
);
337 gtk_label_set_text(app
->label1
,x
);
342 void on_button14_clicked (GtkObject
*object
, App
*app
)
346 char* x
= malloc(sizeof(char)*15);
349 hodnota1
.result
=hodnota1
.result
* 10 + 7;
352 hodnota1
.result
=hodnota1
.result
+ (7.0/pow(10,desetina
));
355 sprintf(x
,"%.5f",hodnota1
.result
);
356 gtk_label_set_text(app
->label1
,x
);
360 hodnota2
.result
=hodnota2
.result
* 10 + 7;
363 hodnota2
.result
=hodnota2
.result
+ (7.0/pow(10,desetina
));
366 sprintf(x
,"%.5f",hodnota2
.result
);
367 gtk_label_set_text(app
->label1
,x
);
372 void on_button15_clicked (GtkObject
*object
, App
*app
)
376 char* x
= malloc(sizeof(char)*15);
379 hodnota1
.result
=hodnota1
.result
* 10 + 8;
382 hodnota1
.result
=hodnota1
.result
+ (8.0/pow(10,desetina
));
385 sprintf(x
,"%.5f",hodnota1
.result
);
386 gtk_label_set_text(app
->label1
,x
);
390 hodnota2
.result
=hodnota2
.result
* 10 + 8;
393 hodnota2
.result
=hodnota2
.result
+ (8.0/pow(10,desetina
));
396 sprintf(x
,"%.5f",hodnota2
.result
);
397 gtk_label_set_text(app
->label1
,x
);
402 void on_button16_clicked (GtkObject
*object
, App
*app
)
406 char* x
= malloc(sizeof(char)*15);
409 hodnota1
.result
=hodnota1
.result
* 10 + 0;
412 hodnota1
.result
=hodnota1
.result
+ (0.0/pow(10,desetina
));
415 sprintf(x
,"%.5f",hodnota1
.result
);
416 gtk_label_set_text(app
->label1
,x
);
420 hodnota2
.result
=hodnota2
.result
* 10 + 0;
423 hodnota2
.result
=hodnota2
.result
+ (0.0/pow(10,desetina
));
426 sprintf(x
,"%.5f",hodnota2
.result
);
427 gtk_label_set_text(app
->label1
,x
);
432 void on_button17_clicked (GtkObject
*object
, App
*app
)
438 else{ //vypsani chyby pokud se vickrat klikne na desetinu
442 void on_button18_clicked (GtkObject
*object
, App
*app
)
446 char* x
= malloc(sizeof(char)*15);
449 hodnota1
.result
=hodnota1
.result
* 10 + 9;
452 hodnota1
.result
=hodnota1
.result
+ (9.0/pow(10,desetina
));
455 sprintf(x
,"%.5f",hodnota1
.result
);
456 gtk_label_set_text(app
->label1
,x
);
460 hodnota2
.result
=hodnota2
.result
* 10 + 9;
463 hodnota2
.result
=hodnota2
.result
+ (9.0/pow(10,desetina
));
466 sprintf(x
,"%.5f",hodnota2
.result
);
467 gtk_label_set_text(app
->label1
,x
);
472 void on_button19_clicked (GtkObject
*object
, App
*app
)
474 /* * 0 - nic, nebylo zadano
482 * 8 - rovnase - hodnota pro zmenu
484 char* x
= malloc(sizeof(char)*15);
487 hodnota1
=scitani(hodnota1
.result
, hodnota2
.result
);
488 sprintf(x
,"%.5f",hodnota1
.result
);
489 gtk_label_set_text(app
->label1
,x
);
494 hodnota1
=odcitani(hodnota1
.result
, hodnota2
.result
);
495 sprintf(x
,"%.5f",hodnota1
.result
);
496 gtk_label_set_text(app
->label1
,x
);
501 hodnota1
=nasobeni(hodnota1
.result
, hodnota2
.result
);
502 sprintf(x
,"%.5f",hodnota1
.result
);
503 gtk_label_set_text(app
->label1
,x
);
508 hodnota1
=deleni(hodnota1
.result
, hodnota2
.result
);
509 if (hodnota1
.error
!=0){
510 gtk_label_set_text(app
->label1
,"EROR");
518 sprintf(x
,"%.5f",hodnota1
.result
);
519 gtk_label_set_text(app
->label1
,x
);
525 hodnota1
=umocneni(hodnota1
.result
, hodnota2
.result
);
526 sprintf(x
,"%.5f",hodnota1
.result
);
527 gtk_label_set_text(app
->label1
,x
);
537 // ukonci hlavni smycku gtk pri zavreni okna
538 void on_window_destroy (GtkObject
*object
, gpointer user_data
)
544 int main (int argc
, char *argv
[])
553 // alokuje pamet pro app
554 app
= g_slice_new(App
);
556 gtk_init (&argc
, &argv
);
559 builder
= gtk_builder_new ();
560 gtk_builder_add_from_file (builder
, BUILDER_XML_FILE
, NULL
);
562 // priradi do struktury jednotlive widgety
563 app
->window
= GTK_WIDGET (gtk_builder_get_object (builder
, "window1"));
564 app
->button0
= GTK_WIDGET (gtk_builder_get_object (builder
, "button0"));
565 app
->button1
= GTK_WIDGET (gtk_builder_get_object (builder
, "button1"));
566 app
->button2
= GTK_WIDGET (gtk_builder_get_object (builder
, "button2"));
567 app
->button3
= GTK_WIDGET (gtk_builder_get_object (builder
, "button3"));
568 app
->button4
= GTK_WIDGET (gtk_builder_get_object (builder
, "button4"));
569 app
->button5
= GTK_WIDGET (gtk_builder_get_object (builder
, "button5"));
570 app
->button6
= GTK_WIDGET (gtk_builder_get_object (builder
, "button6"));
571 app
->button7
= GTK_WIDGET (gtk_builder_get_object (builder
, "button7"));
572 app
->button8
= GTK_WIDGET (gtk_builder_get_object (builder
, "button8"));
573 app
->button9
= GTK_WIDGET (gtk_builder_get_object (builder
, "button9"));
574 app
->button10
= GTK_WIDGET (gtk_builder_get_object (builder
, "button10"));
575 app
->button11
= GTK_WIDGET (gtk_builder_get_object (builder
, "button11"));
576 app
->button12
= GTK_WIDGET (gtk_builder_get_object (builder
, "button12"));
577 app
->button13
= GTK_WIDGET (gtk_builder_get_object (builder
, "button13"));
578 app
->button14
= GTK_WIDGET (gtk_builder_get_object (builder
, "button14"));
579 app
->button15
= GTK_WIDGET (gtk_builder_get_object (builder
, "button15"));
580 app
->button16
= GTK_WIDGET (gtk_builder_get_object (builder
, "button16"));
581 app
->button17
= GTK_WIDGET (gtk_builder_get_object (builder
, "button17"));
582 app
->button18
= GTK_WIDGET (gtk_builder_get_object (builder
, "button18"));
583 app
->button19
= GTK_WIDGET (gtk_builder_get_object (builder
, "button19"));
584 app
->label1
= GTK_LABEL (gtk_builder_get_object (builder
, "label1"));
586 gtk_builder_connect_signals (builder
, app
);
588 g_object_unref (G_OBJECT (builder
));
590 gtk_widget_show (app
->window
);