-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication1.c
155 lines (120 loc) · 5.58 KB
/
application1.c
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
/****************************************************************/
/* Application1.c - An example application for Otk library. */
/* Shows how to make: toggle and radio buttons, pull-down */
/* menu, and selection lists. */
/* */
/* Compile:
cc -L/usr/X11R6/lib application1.c -lGLU -lGL -lXmu -lXext -lX11 -lm -o app1.exe
*/
/* Dec 15, 2004. */
/****************************************************************/
#include "otk_lib.c"
OtkWidget tbutton1, tbutton2;
void toggled( int state, void *x )
{
if (state==1) printf("Toggle button %d toggled ON.\n", (int)x);
else printf("Toggle button %d toggled OFF.\n", (int)x);
printf(" (Toggle button states: %d %d\n",Otk_Get_Button_State(tbutton1),Otk_Get_Button_State(tbutton2));
}
char directory[500]=".", wildcards[500]="", filename[500]="";
void my_file_answer( char *filename )
{ printf("To open file %s\n", filename); }
void fileopener()
{ Otk_Browse_Files( "File to Open:", 500, directory, wildcards, filename, my_file_answer ); }
void saveas_answer( char *filename )
{ printf("To saveas file %s\n", filename); }
void filesaver()
{ Otk_Browse_Files( "File to Save:", 500, directory, wildcards, filename, saveas_answer ); }
void radiocallback( void *x )
{
printf("Radio button %d selected.\n", (int)x );
}
void selectlistcallback( void *x )
{
printf("Item %d selected.\n", (int)x );
}
void testbutton()
{ printf("Test button pressed.\n"); }
void quit( void *x )
{ printf("Exiting\n"); exit(0); }
/* ===================== MAIN ======================== */
main( int argc, char **argv )
{
OtkWidget menubar, pdmenu1, pdmenu2, pdmenu3, pdmenu4, pdmenu5, sbmenu;
OtkWidget rbutton1, slist;
float x=3.0, y=5.0, dx, dy, hsz, vsz;
int nrows, ncols;
OtkInitWindow( 400, 450, argc, argv );
/******************************/
/* Make some Pull-down Menus. */
/******************************/
menubar = OtkMakePanel( OtkOuterWindow, Otk_Flat, OtkSetColor(0.7,0.7,0.7), 0, 0, 100, 5 );
pdmenu1 = Otk_Make_Menu( menubar, 0, 0, 15, 100, " File " );
Otk_Add_Menu_Item( pdmenu1, "Open", fileopener, 0 );
Otk_Add_Menu_Item( pdmenu1, "Save", 0, 0 );
Otk_Add_Menu_Item( pdmenu1, "Save As", filesaver, 0 );
Otk_Add_Menu_Item( pdmenu1, "Print", 0, 0 );
Otk_Add_Menu_Item( pdmenu1, "Exit", quit, 0 );
pdmenu2 = Otk_Make_Menu( menubar, 15, 0, 15, 100, " Edit " );
Otk_Add_Menu_Item( pdmenu2, "Cut", 0, 0 );
Otk_Add_Menu_Item( pdmenu2, "Copy", 0, 0 );
Otk_Add_Menu_Item( pdmenu2, "Paste", 0, 0 );
pdmenu3 = Otk_Make_Menu( menubar, 30, 0, 15, 100, " View " );
Otk_Add_Menu_Item( pdmenu3, "Normal", 0, 0 );
sbmenu = Otk_Add_SubMenu( pdmenu3, "Zoom" ); /* Add a Sub-Menu. */
Otk_Add_Menu_Item( sbmenu, "Zoom-In", 0, 0 );
Otk_Add_Menu_Item( sbmenu, "Zoom-Out", 0, 0 );
pdmenu4 = Otk_Make_Menu( menubar, 45, 0, 15, 100, " Tools " );
Otk_Add_Menu_Item( pdmenu4, "Search", 0, 0 );
pdmenu5 = Otk_Make_Menu( menubar, 60, 0, 15, 100, " Help " );
Otk_Add_Menu_Item( pdmenu5, "About", 0, 0 );
/******************************/
/* Make some toggle buttons. */
/******************************/
x = 3.0; y = 12.0; /* x = horizontal position, y = vertical. */
hsz = 8.0; vsz=2.0;
OtkMakeTextLabel( OtkOuterWindow, "Toggle Buttons:", Otk_Black, 2.0, 1.0, x, y );
tbutton1 = OtkMakeToggleButton( OtkOuterWindow, x+50, y, hsz, vsz, toggled, (void *)1 );
OtkMakeTextLabel( OtkOuterWindow, "T1", Otk_Black, 2.0, 1.0, x+59, y+0.4 );
tbutton2 = OtkMakeToggleButton( OtkOuterWindow, x+70, y, hsz, vsz, toggled, (void *)2 );
OtkMakeTextLabel( OtkOuterWindow, "T2", Otk_Black, 2.0, 1.0, x+79, y+0.4 );
/******************************/
/* Make some Radio Buttons. */
/******************************/
x = 3.0; y = 30.0;
hsz = 8.0; vsz=2.0; dx = 20.0;
OtkMakeTextLabel( OtkOuterWindow, "Radio Buttons:", Otk_Black, 2.0, 1.0, x, y );
x = 10.0; y = y + 5.0;
rbutton1 = OtkMakeRadioButton( OtkOuterWindow, x, y, hsz, vsz, radiocallback, (void *)1 );
OtkMakeTextLabel( OtkOuterWindow, "R1", Otk_Black, 2.0, 1.0, x+9.0, y );
x = x + dx;
OtkMakeRadioButton( rbutton1, x, y, hsz, vsz, radiocallback, (void *)2 );
OtkMakeTextLabel( OtkOuterWindow, "R2", Otk_Black, 2.0, 1.0, x+9.0, y );
x = x + dx;
OtkMakeRadioButton( rbutton1, x, y, hsz, vsz, radiocallback, (void *)3 );
OtkMakeTextLabel( OtkOuterWindow, "R3", Otk_Black, 2.0, 1.0, x+9.0, y );
x = x + dx;
OtkMakeRadioButton( rbutton1, x, y, hsz, vsz, radiocallback, (void *)4 );
OtkMakeTextLabel( OtkOuterWindow, "R4", Otk_Black, 2.0, 1.0, x+9.0, y );
/******************************/
/* Make a selection-list. */
/******************************/
x = 3.0; y = 50.0;
OtkMakeTextLabel( OtkOuterWindow, "Selection List:", Otk_Black, 2.0, 1.0, x, y );
hsz = 70.0; vsz=20.0;
x = 10.0; y = y + 5.0;
nrows = 5; ncols = 25;
slist = Otk_Make_Selection_List( OtkOuterWindow, nrows, ncols, x, y, hsz, vsz );
Otk_Add_Selection_Item( slist, "Grapes", selectlistcallback, (void *)1 );
Otk_Add_Selection_Item( slist, "Olives", selectlistcallback, (void *)2 );
Otk_Add_Selection_Item( slist, "Bananas", selectlistcallback, (void *)3 );
Otk_Add_Selection_Item( slist, "Cherries", selectlistcallback, (void *)4 );
Otk_Add_Selection_Item( slist, "Apples", selectlistcallback, (void *)5 );
Otk_Add_Selection_Item( slist, "Cigars", selectlistcallback, (void *)6 );
Otk_Add_Selection_Item( slist, "Lemons", selectlistcallback, (void *)7 );
Otk_Add_Selection_Item( slist, "Tangerines", selectlistcallback, (void *)8 );
Otk_Frame_Selection_List( slist );
OtkMakeButton( OtkOuterWindow, 45.0, 89.0, 10.0, 4.0, "Test", testbutton, 0 );
OtkMakeButton( OtkOuterWindow, 45.0, 95.0, 10.0, 4.0, "Exit", quit, 0 );
OtkMainLoop();
}