comparison dwtest.c @ 195:b023d363fc09

Added scrollbar and timer support on OS/2 and GTK.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 20 Jan 2003 08:49:11 +0000
parents efd4703450fa
children f3718165f0b2
comparison
equal deleted inserted replaced
194:37bee5b50bcb 195:b023d363fc09
6 #include <stdio.h> 6 #include <stdio.h>
7 #include "dw.h" 7 #include "dw.h"
8 8
9 9
10 unsigned long flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR | 10 unsigned long flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
11 DW_FCF_SHELLPOSITION | DW_FCF_TASKLIST | DW_FCF_DLGBORDER; 11 DW_FCF_SHELLPOSITION | DW_FCF_TASKLIST | DW_FCF_DLGBORDER;
12 12
13 HWND mainwindow, 13 HWND mainwindow,
14 entryfield, 14 entryfield,
15 okbutton, 15 okbutton,
16 cancelbutton, 16 cancelbutton,
17 lbbox, 17 lbbox,
18 notebookbox, 18 notebookbox,
19 notebookbox1, 19 notebookbox1,
20 notebookbox2, 20 notebookbox2,
21 notebook, 21 notebook,
22 stext, 22 stext,
23 pagebox, 23 pagebox,
24 textbox1, textbox2, 24 textbox1, textbox2,
25 buttonbox; 25 buttonbox;
26 26
27 int DWSIGNAL exit_callback(HWND window, void *data) 27 int DWSIGNAL exit_callback(HWND window, void *data)
28 { 28 {
29 dw_window_destroy((HWND)data); 29 dw_window_destroy((HWND)data);
30 exit(0); 30 exit(0);
31 return -1; 31 return -1;
32 } 32 }
33 33
34 int DWSIGNAL test_callback(HWND window, void *data) 34 int DWSIGNAL test_callback(HWND window, void *data)
35 { 35 {
36 dw_window_destroy((HWND)data); 36 dw_window_destroy((HWND)data);
37 exit(0); 37 exit(0);
38 return -1; 38 return -1;
39 } 39 }
40 40
41 int DWSIGNAL browse_callback(HWND window, void *data) 41 int DWSIGNAL browse_callback(HWND window, void *data)
42 { 42 {
43 dw_file_browse("test string", NULL, "c", DW_FILE_OPEN ); 43 dw_file_browse("test string", NULL, "c", DW_FILE_OPEN );
44 return 0; 44 return 0;
45 } 45 }
46 46
47 void archive_add(void) 47 void archive_add(void)
48 { 48 {
49 HWND browsebutton, browsebox; 49 HWND browsebutton, browsebox;
50 50
51 lbbox = dw_box_new(BOXVERT, 10); 51 lbbox = dw_box_new(BOXVERT, 10);
52 52
53 dw_box_pack_start(notebookbox1, lbbox, 150, 70, TRUE, TRUE, 0); 53 dw_box_pack_start(notebookbox1, lbbox, 150, 70, TRUE, TRUE, 0);
54 54
55 /* Archive Name */ 55 /* Archive Name */
56 stext = dw_text_new("Archive Name", 0); 56 stext = dw_text_new("Archive Name", 0);
57 57
58 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); 58 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER);
59 59
60 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 2); 60 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 2);
61 61
62 browsebox = dw_box_new(BOXHORZ, 0); 62 browsebox = dw_box_new(BOXHORZ, 0);
63 63
64 dw_box_pack_start(lbbox, browsebox, 0, 0, TRUE, TRUE, 0); 64 dw_box_pack_start(lbbox, browsebox, 0, 0, TRUE, TRUE, 0);
65 65
66 entryfield = dw_entryfield_new("", 100L); 66 entryfield = dw_entryfield_new("", 100L);
67 67
68 dw_box_pack_start(browsebox, entryfield, 100, 15, TRUE, TRUE, 4); 68 dw_box_pack_start(browsebox, entryfield, 100, 15, TRUE, TRUE, 4);
69 69
70 browsebutton = dw_button_new("Browse", 1001L); 70 browsebutton = dw_button_new("Browse", 1001L);
71 71
72 dw_box_pack_start(browsebox, browsebutton, 30, 15, TRUE, TRUE, 0); 72 dw_box_pack_start(browsebox, browsebutton, 30, 15, TRUE, TRUE, 0);
73 73
74 dw_window_set_color(browsebox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); 74 dw_window_set_color(browsebox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY);
75 dw_window_set_font(browsebutton, "9.WarpSans"); 75 dw_window_set_font(browsebutton, "9.WarpSans");
76 dw_window_set_font(stext, "9.WarpSans"); 76 dw_window_set_font(stext, "9.WarpSans");
77 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); 77 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY);
78 dw_window_set_font(entryfield, "9.WarpSans"); 78 dw_window_set_font(entryfield, "9.WarpSans");
79 79
80 /* Archive Description */ 80 /* Archive Description */
81 stext = dw_text_new("Archive Description", 0); 81 stext = dw_text_new("Archive Description", 0);
82 82
83 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); 83 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER);
84 84
85 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 4); 85 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 4);
86 86
87 entryfield = dw_entryfield_new("", 100L); 87 entryfield = dw_entryfield_new("", 100L);
88 88
89 dw_box_pack_start(lbbox, entryfield, 130, 15, TRUE, TRUE, 4); 89 dw_box_pack_start(lbbox, entryfield, 130, 15, TRUE, TRUE, 4);
90 90
91 dw_window_set_font(stext, "9.WarpSans"); 91 dw_window_set_font(stext, "9.WarpSans");
92 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); 92 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY);
93 dw_window_set_font(entryfield, "9.WarpSans"); 93 dw_window_set_font(entryfield, "9.WarpSans");
94 94
95 /* Comments */ 95 /* Comments */
96 stext = dw_text_new("Comments", 0); 96 stext = dw_text_new("Comments", 0);
97 97
98 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); 98 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER);
99 99
100 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 4); 100 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 4);
101 101
102 entryfield = dw_entryfield_new("", 100L); 102 entryfield = dw_entryfield_new("", 100L);
103 103
104 dw_box_pack_start(lbbox, entryfield, 130, 15, TRUE, TRUE, 4); 104 dw_box_pack_start(lbbox, entryfield, 130, 15, TRUE, TRUE, 4);
105 105
106 dw_window_set_font(stext, "9.WarpSans"); 106 dw_window_set_font(stext, "9.WarpSans");
107 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); 107 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY);
108 dw_window_set_font(entryfield, "9.WarpSans"); 108 dw_window_set_font(entryfield, "9.WarpSans");
109 109
110 /* Buttons */ 110 /* Buttons */
111 buttonbox = dw_box_new(BOXHORZ, 10); 111 buttonbox = dw_box_new(BOXHORZ, 10);
112 112
113 dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0); 113 dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0);
114 114
115 okbutton = dw_button_new("Ok", 1001L); 115 okbutton = dw_button_new("Ok", 1001L);
116 116
117 dw_box_pack_start(buttonbox, okbutton, 130, 30, TRUE, TRUE, 2); 117 dw_box_pack_start(buttonbox, okbutton, 130, 30, TRUE, TRUE, 2);
118 118
119 cancelbutton = dw_button_new("Cancel", 1002L); 119 cancelbutton = dw_button_new("Cancel", 1002L);
120 120
121 dw_box_pack_start(buttonbox, cancelbutton, 130, 30, TRUE, TRUE, 2); 121 dw_box_pack_start(buttonbox, cancelbutton, 130, 30, TRUE, TRUE, 2);
122 122
123 /* Set some nice fonts and colors */ 123 /* Set some nice fonts and colors */
124 dw_window_set_color(lbbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY); 124 dw_window_set_color(lbbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY);
125 dw_window_set_color(buttonbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY); 125 dw_window_set_color(buttonbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY);
126 dw_window_set_color(okbutton, DW_CLR_PALEGRAY, DW_CLR_DARKCYAN); 126 dw_window_set_color(okbutton, DW_CLR_PALEGRAY, DW_CLR_DARKCYAN);
127 dw_window_set_font(okbutton, "9.WarpSans"); 127 dw_window_set_font(okbutton, "9.WarpSans");
128 dw_window_set_font(cancelbutton, "9.WarpSans"); 128 dw_window_set_font(cancelbutton, "9.WarpSans");
129 129
130 dw_signal_connect(browsebutton, "clicked", DW_SIGNAL_FUNC(browse_callback), (void *)notebookbox1); 130 dw_signal_connect(browsebutton, "clicked", DW_SIGNAL_FUNC(browse_callback), (void *)notebookbox1);
131 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)notebookbox1); 131 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)notebookbox1);
132 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)notebookbox1); 132 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)notebookbox1);
133 } 133 }
134 134
135 135
136 int font_width = 9; 136 int font_width = 9;
137 int font_height=6; 137 int font_height=6;
138 int rows=100,width1=6,width2=50; 138 int rows=100,width1=6,width2=50;
139 139
140 /* This gets called when a part of the graph needs to be repainted. */ 140 /* This gets called when a part of the graph needs to be repainted. */
141 int DWSIGNAL text_expose(HWND hwnd, DWExpose *exp, void *data) 141 int DWSIGNAL text_expose(HWND hwnd, DWExpose *exp, void *data)
142 { 142 {
143 HPIXMAP hpm = (HPIXMAP)data; 143 HPIXMAP hpm = (HPIXMAP)data;
144 144
145 dw_pixmap_bitblt(hwnd, NULL, 0, 0, font_width*width1, font_height*rows, NULL, hpm, 0, 0 ); 145 dw_pixmap_bitblt(hwnd, NULL, 0, 0, font_width*width1, font_height*rows, NULL, hpm, 0, 0 );
146 dw_flush(); 146 dw_flush();
147 return TRUE; 147 return TRUE;
148 } 148 }
149 149
150 void text_add(void) 150 void text_add(void)
151 { 151 {
152 int i,y,depth = dw_color_depth(); 152 int i,y,depth = dw_color_depth();
153 char buf[10]; 153 char buf[10];
154 HPIXMAP text1pm,text2pm; 154 HPIXMAP text1pm,text2pm;
155 155
156 pagebox = dw_box_new(BOXVERT, 5); 156 pagebox = dw_box_new(BOXVERT, 5);
157 dw_box_pack_start( notebookbox2, pagebox, 1, 1, TRUE, TRUE, 0); 157 dw_box_pack_start( notebookbox2, pagebox, 1, 1, TRUE, TRUE, 0);
158 158
159 textbox1 = dw_render_new( 100 ); 159 textbox1 = dw_render_new( 100 );
160 dw_box_pack_start( pagebox, textbox1, font_width*width1, font_height*rows, TRUE, TRUE, 4); 160 dw_box_pack_start( pagebox, textbox1, font_width*width1, font_height*rows, TRUE, TRUE, 4);
161 dw_window_set_font(textbox1, "9.WarpSans"); 161 dw_window_set_font(textbox1, "9.WarpSans");
162 162
163 textbox2 = dw_render_new( 101 ); 163 textbox2 = dw_render_new( 101 );
164 dw_box_pack_start( pagebox, textbox2, font_width*width2, font_height*rows, TRUE, TRUE, 4); 164 dw_box_pack_start( pagebox, textbox2, font_width*width2, font_height*rows, TRUE, TRUE, 4);
165 dw_window_set_font(textbox2, "9.WarpSans"); 165 dw_window_set_font(textbox2, "9.WarpSans");
166 166
167 text1pm = dw_pixmap_new( textbox1, font_width*width1, font_height*rows, depth ); 167 text1pm = dw_pixmap_new( textbox1, font_width*width1, font_height*rows, depth );
168 text2pm = dw_pixmap_new( textbox2, font_width*width2, font_height*rows, depth ); 168 text2pm = dw_pixmap_new( textbox2, font_width*width2, font_height*rows, depth );
169 169
170 dw_color_foreground_set(DW_CLR_WHITE); 170 dw_color_foreground_set(DW_CLR_WHITE);
171 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows); 171 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows);
172 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*width2, font_height*rows); 172 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*width2, font_height*rows);
173 173
174 dw_font_text_extents( NULL, text1pm, "O", &font_width, &font_height ); 174 dw_font_text_extents( NULL, text1pm, "O", &font_width, &font_height );
175 dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height); 175 dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height);
176 176
177 dw_color_background_set( DW_CLR_WHITE ); 177 dw_color_background_set( DW_CLR_WHITE );
178 for ( i = 0;i < 100; i++) 178 for ( i = 0;i < 100; i++)
179 { 179 {
180 y = i*font_height; 180 y = i*font_height;
181 181
182 dw_color_foreground_set( DW_CLR_BLACK ); 182 dw_color_foreground_set( DW_CLR_BLACK );
183 sprintf( buf, "%6.6d", i ); 183 sprintf( buf, "%6.6d", i );
184 dw_draw_text( NULL, text1pm, 0, y, buf); 184 dw_draw_text( NULL, text1pm, 0, y, buf);
185 dw_draw_text( NULL, text2pm, 0, y, buf); 185 dw_draw_text( NULL, text2pm, 0, y, buf);
186 } 186 }
187 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), text1pm); 187 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), text1pm);
188 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), text2pm); 188 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), text2pm);
189 }
190
191 /* Beep every second */
192 int DWSIGNAL timer_callback(void *data)
193 {
194 dw_beep(200, 200);
195
196 /* Return TRUE so we get called again */
197 return TRUE;
189 } 198 }
190 199
191 /* 200 /*
192 * Let's demonstrate the functionality of this library. :) 201 * Let's demonstrate the functionality of this library. :)
193 */ 202 */
194 int main(int argc, char *argv[]) 203 int main(int argc, char *argv[])
195 { 204 {
196 ULONG notebookpage1; 205 ULONG notebookpage1;
197 ULONG notebookpage2; 206 ULONG notebookpage2;
198 207 int timerid;
199 dw_init(TRUE, argc, argv); 208
200 209 dw_init(TRUE, argc, argv);
201 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX ); 210
202 211 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX );
203 notebookbox = dw_box_new( BOXVERT, 5 ); 212
204 dw_box_pack_start( mainwindow, notebookbox, 1, 1, TRUE, TRUE, 0); 213 notebookbox = dw_box_new( BOXVERT, 5 );
205 214 dw_box_pack_start( mainwindow, notebookbox, 1, 1, TRUE, TRUE, 0);
206 notebook = dw_notebook_new( 1, TRUE ); 215
207 dw_box_pack_start( notebookbox, notebook, 100, 100, TRUE, TRUE, 0); 216 notebook = dw_notebook_new( 1, TRUE );
208 dw_window_set_font( notebook, "8.WarpSans"); 217 dw_box_pack_start( notebookbox, notebook, 100, 100, TRUE, TRUE, 0);
209 218 dw_window_set_font( notebook, "8.WarpSans");
210 notebookbox1 = dw_box_new( BOXVERT, 5 ); 219
211 notebookpage1 = dw_notebook_page_new( notebook, 0, TRUE ); 220 notebookbox1 = dw_box_new( BOXVERT, 5 );
212 dw_notebook_pack( notebook, notebookpage1, notebookbox1 ); 221 notebookpage1 = dw_notebook_page_new( notebook, 0, TRUE );
213 fprintf( stderr, "page1: %ld\n", notebookpage1 ); 222 dw_notebook_pack( notebook, notebookpage1, notebookbox1 );
214 dw_notebook_page_set_text( notebook, notebookpage1, "first page"); 223 dw_notebook_page_set_text( notebook, notebookpage1, "first page");
215 archive_add(); 224 archive_add();
216 225
217 notebookbox2 = dw_box_new( BOXVERT, 5 ); 226 notebookbox2 = dw_box_new( BOXVERT, 5 );
218 notebookpage2 = dw_notebook_page_new( notebook, 1, FALSE ); 227 notebookpage2 = dw_notebook_page_new( notebook, 1, FALSE );
219 dw_notebook_pack( notebook, notebookpage2, notebookbox2 ); 228 dw_notebook_pack( notebook, notebookpage2, notebookbox2 );
220 fprintf( stderr, "page2: %ld\n",notebookpage2); 229 dw_notebook_page_set_text( notebook, notebookpage2, "second page");
221 dw_notebook_page_set_text( notebook, notebookpage2, "second page"); 230 text_add();
222 text_add(); 231
223 232 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(exit_callback), (void *)mainwindow);
224 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(exit_callback), (void *)mainwindow); 233 timerid = dw_timer_connect(mainwindow, 1000, DW_SIGNAL_FUNC(timer_callback), 0);
225 dw_window_set_usize(mainwindow, 640, 480); 234 dw_window_set_usize(mainwindow, 640, 480);
226 dw_window_show(mainwindow); 235 dw_window_show(mainwindow);
227 236
228 dw_main(); 237 dw_main();
229 238
230 return 0; 239 return 0;
231 } 240 }