File: setup_buttons.c

package info (click to toggle)
grpn 1.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 444 kB
  • ctags: 462
  • sloc: ansic: 5,766; sh: 155; makefile: 81
file content (119 lines) | stat: -rw-r--r-- 3,083 bytes parent folder | download | duplicates (5)
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
/*

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.

*/
/* setup_buttons.c  by Paul Wilkins */

#include <stdio.h>
#include <gtk/gtk.h>

#include "buttons.h"
#include "funcs.h"
#include "editor.h"



/* create the button widgets */
GtkWidget *createButton(
   GtkWidget *parent, 
   int leftPos, int rightPos,
   int topPos, int bottomPos,
   FuncInfo *fi)
{
   GtkWidget *btn, *label;
   void (*callBack)(GtkWidget *, gpointer);

   /*
   btn = gtk_button_new_with_label(fi->name);
   */

   btn = gtk_button_new();
   label = gtk_label_new(fi->name);
   gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
   gtk_misc_set_padding(GTK_MISC(label), 0, 0);
   gtk_container_add(GTK_CONTAINER(btn), label);
   gtk_widget_show(label);


   /* the space around the button 
   gtk_container_border_width(GTK_CONTAINER(btn), 10);
   */

   /* when the button is clicked, we call the "callback" function */
   callBack = fi->CB;
   gtk_signal_connect(GTK_OBJECT (btn), "clicked",
	   GTK_SIGNAL_FUNC(callBack), (gpointer)fi);

   gtk_table_attach_defaults(GTK_TABLE(parent), btn, leftPos, rightPos, topPos, bottomPos);

   gtk_widget_show(btn);

   GTK_WIDGET_UNSET_FLAGS(btn, GTK_CAN_FOCUS);

   return btn;
}


/* setup the buttons */
GtkWidget *setupButtons(GtkWidget *parent){
   int i, j;
   int good;
   int numRows, numCols;
   int tWidth;
   GtkWidget *table;

   /* get the number of rows and columns */
   numRows = NumButtonRows;
   numCols = 0;
   for(i=0; i<numRows; i++){
      if(rowinf[i].numBtns > numCols) numCols = rowinf[i].numBtns;
   }

   /* find the width of the table we need to fit out different sized buttons */
   for(tWidth=numCols; tWidth<100; tWidth++){
      good = 1;
      for(j=0; j<numRows; j++){
         if( (tWidth % rowinf[j].numBtns) != 0){
            good = 0;
            break;
         }
      }
      if(good == 1) break;
   }

   /* create the table that will hold our buttons */
   table = gtk_table_new(numRows, tWidth, TRUE);
   gtk_box_pack_end(GTK_BOX(parent), table, FALSE, FALSE, 0);
   gtk_widget_show(table);

   /* fill the form */
   for(i=0; i<numRows; i++){
      for(j=0; j<rowinf[i].numBtns; j++){
         if(rowinf[i].fi[j].name != NULL){
            createButton(table,
	       tWidth / rowinf[i].numBtns * j,
	       tWidth / rowinf[i].numBtns * (j + 1),
               i, i+1,
               &(rowinf[i].fi[j]) );
         }
      }
   }

   return table;

}