comparison dwtest.c @ 217:7112c817573d

Added test code from mark hessling.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 04 Feb 2003 22:38:53 +0000
parents f8b50901ac45
children fe0ab0040ba2
comparison
equal deleted inserted replaced
216:bd06f8d123f0 217:7112c817573d
17 lbbox, 17 lbbox,
18 notebookbox, 18 notebookbox,
19 notebookbox1, 19 notebookbox1,
20 notebookbox2, 20 notebookbox2,
21 notebook, 21 notebook,
22 scrollbar, 22 vscrollbar,
23 scrollbar2, 23 hscrollbar,
24 status, 24 status,
25 stext, 25 stext,
26 pagebox, 26 pagebox,
27 textbox1, textbox2, 27 textbox1, textbox2, textboxA,
28 buttonbox; 28 buttonbox;
29
30 HPIXMAP text1pm,text2pm;
31
32 int font_width = 8;
33 int font_height=12;
34 int font_gap = 2;
35 int rows=100,width1=6,width2=80;
36 char *current_file = NULL;
37 int timerid;
38 int num_lines=0;
39 int max_linewidth=0;
40 int current_row=0,current_col=0;
41
42 FILE *fp=NULL;
43 char **lp;
44
45 /* This gets called when a part of the graph needs to be repainted. */
46 int DWSIGNAL text_expose1(HWND hwnd, DWExpose *exp, void *data)
47 {
48 HPIXMAP hpm = (HPIXMAP)data;
49
50 dw_pixmap_bitblt(hwnd, NULL, 0, 0, font_width*width1, font_height*rows, NULL, hpm, 0, 0 );
51 dw_flush();
52 return TRUE;
53 }
54
55 int DWSIGNAL text_expose2(HWND hwnd, DWExpose *exp, void *data)
56 {
57 HPIXMAP hpm = (HPIXMAP)data;
58
59 dw_pixmap_bitblt(hwnd, NULL, 0, 0, font_width*width2, font_height*rows, NULL, hpm, 0, 0 );
60 dw_flush();
61 return TRUE;
62 }
63
64 void read_file( void )
65 {
66 char line[1024];
67 char buf[10];
68 int i,y,len;
69 fp = fopen( current_file, "r" );
70 lp = (char **)calloc( 1000,sizeof(char *));
71 /* should test for out of memory */
72 max_linewidth=0;
73 for ( i = 0; i < 1000; i++ )
74 {
75 lp[i] = (char *)malloc( 1025 );
76 if ( fgets( lp[i], 1024, fp ) == NULL )
77 break;
78 len = strlen( lp[i] );
79 if ( len > max_linewidth )
80 max_linewidth = len;
81 if ( lp[i][len - 1] == '\n' )
82 lp[i][len - 1] = '\0';
83 }
84 num_lines = i;
85 fclose( fp );
86 dw_scrollbar_set_range(hscrollbar, max_linewidth, width2);
87 dw_scrollbar_set_pos(hscrollbar, 0);
88 dw_scrollbar_set_range(vscrollbar, num_lines, rows);
89 dw_scrollbar_set_pos(vscrollbar, 0);
90 }
91
92 void draw_file( int row, int col )
93 {
94 char buf[10];
95 int i,y;
96 char *pLine;
97 fprintf(stderr,"in draw_file: %d %d\n",row,col);
98 if ( current_file )
99 {
100 dw_color_foreground_set(DW_CLR_WHITE);
101 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows);
102 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*width2, font_height*rows);
103 for ( i = 0;(i < rows) & (i+row < rows); i++)
104 {
105 y = i*(font_height+font_gap);
106 dw_color_foreground_set( i );
107 sprintf( buf, "%6.6d", i+row );
108 dw_draw_text( NULL, text1pm, 0, y, buf);
109 pLine = lp[i+row];
110 dw_draw_text( NULL, text2pm, 0, y, pLine+col );
111 }
112 text_expose1( textbox1, NULL, text1pm);
113 text_expose1( textbox2, NULL, text2pm);
114 }
115 }
116
117 int DWSIGNAL beep_callback(HWND window, void *data)
118 {
119 dw_timer_disconnect( timerid );
120 }
29 121
30 int DWSIGNAL exit_callback(HWND window, void *data) 122 int DWSIGNAL exit_callback(HWND window, void *data)
31 { 123 {
32 dw_window_destroy((HWND)data); 124 dw_window_destroy((HWND)data);
33 exit(0); 125 exit(0);
35 } 127 }
36 128
37 int DWSIGNAL test_callback(HWND window, void *data) 129 int DWSIGNAL test_callback(HWND window, void *data)
38 { 130 {
39 dw_window_destroy((HWND)data); 131 dw_window_destroy((HWND)data);
132 if ( current_file )
133 dw_free( current_file );
40 exit(0); 134 exit(0);
41 return -1; 135 return -1;
42 } 136 }
43 137
44 int DWSIGNAL browse_callback(HWND window, void *data) 138 int DWSIGNAL browse_callback(HWND window, void *data)
45 { 139 {
46 dw_file_browse("test string", NULL, "c", DW_FILE_OPEN ); 140 char *tmp;
141 if ( current_file )
142 {
143 dw_free( current_file );
144 }
145 tmp = dw_file_browse("test string", NULL, "c", DW_FILE_OPEN );
146 if ( tmp )
147 {
148 current_file = tmp;
149 dw_window_set_text( entryfield, current_file );
150 read_file();
151 draw_file(0,0);
152 }
47 return 0; 153 return 0;
48 } 154 }
49 155
156 /* Callback to handle user selection of the scrollbar position */
157 void DWSIGNAL scrollbar_valuechanged(HWND hwnd, int value, void *data)
158 {
159 fprintf(stderr,"scrollbar_valuechanged: value %d data %d, %s\n",value,data,(hwnd == vscrollbar) ? "vert" : "horz");
160 if(data)
161 {
162 HWND stext = (HWND)data;
163 char tmpbuf[100];
164 if ( hwnd == vscrollbar )
165 {
166 current_row = value;
167 }
168 else
169 {
170 current_col = value;
171 }
172 sprintf(tmpbuf, "Row:%d Col:%d Lines:%d Cols:%d", current_row,current_col,num_lines,max_linewidth);
173 dw_window_set_text(stext, tmpbuf);
174 draw_file( current_row, current_col);
175 }
176 }
177
50 void archive_add(void) 178 void archive_add(void)
51 { 179 {
52 HWND browsebutton, browsebox; 180 HWND browsebutton, browsebox;
53 181
54 lbbox = dw_box_new(BOXVERT, 10); 182 lbbox = dw_box_new(BOXVERT, 10);
55 183
56 dw_box_pack_start(notebookbox1, lbbox, 150, 70, TRUE, TRUE, 0); 184 dw_box_pack_start(notebookbox1, lbbox, 150, 70, TRUE, TRUE, 0);
57 185
58 /* Archive Name */ 186 /* Archive Name */
59 stext = dw_text_new("Archive Name", 0); 187 stext = dw_text_new("File to browse", 0);
60 188
61 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); 189 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER);
62 190
63 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 2); 191 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 2);
64 192
78 dw_window_set_font(browsebutton, "9.WarpSans"); 206 dw_window_set_font(browsebutton, "9.WarpSans");
79 dw_window_set_font(stext, "9.WarpSans"); 207 dw_window_set_font(stext, "9.WarpSans");
80 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); 208 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY);
81 dw_window_set_font(entryfield, "9.WarpSans"); 209 dw_window_set_font(entryfield, "9.WarpSans");
82 210
83 /* Archive Description */
84 stext = dw_text_new("Archive Description", 0);
85
86 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER);
87
88 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 4);
89
90 entryfield = dw_entryfield_new("", 100L);
91
92 dw_box_pack_start(lbbox, entryfield, 130, 15, TRUE, TRUE, 4);
93
94 dw_window_set_font(stext, "9.WarpSans");
95 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY);
96 dw_window_set_font(entryfield, "9.WarpSans");
97
98 /* Comments */
99 stext = dw_text_new("Comments", 0);
100
101 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER);
102
103 dw_box_pack_start(lbbox, stext, 130, 15, TRUE, TRUE, 4);
104
105 entryfield = dw_entryfield_new("", 100L);
106
107 dw_box_pack_start(lbbox, entryfield, 130, 15, TRUE, TRUE, 4);
108
109 dw_window_set_font(stext, "9.WarpSans");
110 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY);
111 dw_window_set_font(entryfield, "9.WarpSans");
112
113 /* Buttons */ 211 /* Buttons */
114 buttonbox = dw_box_new(BOXHORZ, 10); 212 buttonbox = dw_box_new(BOXHORZ, 10);
115 213
116 dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0); 214 dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0);
117 215
118 okbutton = dw_button_new("Ok", 1001L); 216 okbutton = dw_button_new("Turn Off Annoying Beep!", 1001L);
119 217
120 dw_box_pack_start(buttonbox, okbutton, 130, 30, TRUE, TRUE, 2); 218 dw_box_pack_start(buttonbox, okbutton, 130, 30, TRUE, TRUE, 2);
121 219
122 cancelbutton = dw_button_new("Cancel", 1002L); 220 cancelbutton = dw_button_new("Exit", 1002L);
123 221
124 dw_box_pack_start(buttonbox, cancelbutton, 130, 30, TRUE, TRUE, 2); 222 dw_box_pack_start(buttonbox, cancelbutton, 130, 30, TRUE, TRUE, 2);
125 223
126 /* Set some nice fonts and colors */ 224 /* Set some nice fonts and colors */
127 dw_window_set_color(lbbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY); 225 dw_window_set_color(lbbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY);
129 dw_window_set_color(okbutton, DW_CLR_PALEGRAY, DW_CLR_DARKCYAN); 227 dw_window_set_color(okbutton, DW_CLR_PALEGRAY, DW_CLR_DARKCYAN);
130 dw_window_set_font(okbutton, "9.WarpSans"); 228 dw_window_set_font(okbutton, "9.WarpSans");
131 dw_window_set_font(cancelbutton, "9.WarpSans"); 229 dw_window_set_font(cancelbutton, "9.WarpSans");
132 230
133 dw_signal_connect(browsebutton, "clicked", DW_SIGNAL_FUNC(browse_callback), (void *)notebookbox1); 231 dw_signal_connect(browsebutton, "clicked", DW_SIGNAL_FUNC(browse_callback), (void *)notebookbox1);
134 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)notebookbox1); 232 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(beep_callback), (void *)notebookbox1);
135 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)notebookbox1); 233 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(exit_callback), (void *)mainwindow);
136 } 234 }
137 235
138 236
139 int font_width = 9;
140 int font_height=6;
141 int rows=100,width1=6,width2=50;
142
143 /* This gets called when a part of the graph needs to be repainted. */
144 int DWSIGNAL text_expose(HWND hwnd, DWExpose *exp, void *data)
145 {
146 HPIXMAP hpm = (HPIXMAP)data;
147
148 dw_pixmap_bitblt(hwnd, NULL, 0, 0, font_width*width1, font_height*rows, NULL, hpm, 0, 0 );
149 dw_flush();
150 return TRUE;
151 }
152
153 /* Callback to handle user selection of the scrollbar position */
154 void DWSIGNAL scrollbar_valuechanged(HWND hwnd, int value, void *data)
155 {
156 if(data)
157 {
158 HWND stext = (HWND)data;
159 char tmpbuf[100];
160
161 sprintf(tmpbuf, "%d", value);
162 dw_window_set_text(stext, tmpbuf);
163 }
164 }
165 void text_add(void) 237 void text_add(void)
166 { 238 {
167 int i,y,depth = dw_color_depth(); 239 int depth = dw_color_depth();
168 char buf[10]; 240
169 HPIXMAP text1pm,text2pm; 241 /* create a box to pack into the notebook page */
170 HWND hbox; 242 pagebox = dw_box_new(BOXHORZ, 2);
171 243 dw_box_pack_start( notebookbox2, pagebox, 0, 0, TRUE, TRUE, 0);
172 pagebox = dw_box_new(BOXVERT, 5); 244 /* now a status area under this box */
173 dw_box_pack_start(notebookbox2, pagebox, 0, 0, TRUE, TRUE, 0); 245 status = dw_status_text_new("", 0);
174 246 dw_box_pack_start( notebookbox2, status, 100, 20, TRUE, FALSE, 1);
175 hbox = dw_box_new(BOXHORZ, 0); 247
176 dw_box_pack_start(pagebox, hbox, 0, 0, TRUE, TRUE, 0); 248 /* create render box for number pixmap */
177
178 pagebox = dw_box_new(BOXVERT, 0);
179 dw_box_pack_start(hbox, pagebox, 0, 0, TRUE, TRUE, 0);
180
181 scrollbar2 = dw_scrollbar_new(TRUE, 100, 50);
182 dw_box_pack_start(hbox, scrollbar2, 20, 100, FALSE, TRUE, 0);
183 dw_scrollbar_set_range(scrollbar2, 100, 50);
184 dw_scrollbar_set_pos(scrollbar2, 10);
185
186 textbox1 = dw_render_new( 100 ); 249 textbox1 = dw_render_new( 100 );
187 dw_box_pack_start( pagebox, textbox1, font_width*width1, font_height*rows, TRUE, TRUE, 4); 250 dw_box_pack_start( pagebox, textbox1, font_width*width1, font_height*rows, FALSE, TRUE, 0);
188 dw_window_set_font(textbox1, "9.WarpSans"); 251 dw_window_set_font(textbox1, "9.WarpSans");
189 252
253 /* create box for filecontents and horz scrollbar */
254 textboxA = dw_box_new( BOXVERT,0 );
255 dw_box_pack_start( pagebox, textboxA, 0, 0, TRUE, TRUE, 0);
256
257 /* create render box for filecontents pixmap */
190 textbox2 = dw_render_new( 101 ); 258 textbox2 = dw_render_new( 101 );
191 dw_box_pack_start( pagebox, textbox2, font_width*width2, font_height*rows, TRUE, TRUE, 4); 259 dw_box_pack_start( textboxA, textbox2, font_width*width2, font_height*rows, TRUE, TRUE, 0);
192 dw_window_set_font(textbox2, "9.WarpSans"); 260 dw_window_set_font(textbox2, "9.WarpSans");
193 261 /* create horizonal scrollbar */
194 scrollbar = dw_scrollbar_new(FALSE, 100, 50); 262 hscrollbar = dw_scrollbar_new(FALSE, 100, 50);
195 dw_box_pack_start( pagebox, scrollbar, 100, 20, TRUE, FALSE, 0); 263 dw_box_pack_start( textboxA, hscrollbar, 100, 20, TRUE, FALSE, 0);
196 dw_scrollbar_set_range(scrollbar, 100, 50); 264
197 dw_scrollbar_set_pos(scrollbar, 10); 265 /* create vertical scrollbar */
198 266 vscrollbar = dw_scrollbar_new(TRUE, 100, 50);
199 status = dw_status_text_new("", 0); 267 dw_box_pack_start(pagebox, vscrollbar, 20, 100, FALSE, TRUE, 0);
200 dw_box_pack_start( pagebox, status, 100, 20, TRUE, FALSE, 1);
201 268
202 text1pm = dw_pixmap_new( textbox1, font_width*width1, font_height*rows, depth ); 269 text1pm = dw_pixmap_new( textbox1, font_width*width1, font_height*rows, depth );
203 text2pm = dw_pixmap_new( textbox2, font_width*width2, font_height*rows, depth ); 270 text2pm = dw_pixmap_new( textbox2, font_width*width2, font_height*rows, depth );
204 271
205 dw_color_foreground_set(DW_CLR_WHITE); 272 dw_font_text_extents( NULL, text1pm, "O", &font_width, &font_height );
273 dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height);
206 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows); 274 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows);
207 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*width2, font_height*rows); 275 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*width2, font_height*rows);
208 276 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose1), text1pm);
209 dw_font_text_extents( NULL, text1pm, "O", &font_width, &font_height ); 277 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose2), text2pm);
210 dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height); 278 dw_signal_connect(hscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status);
211 279 dw_signal_connect(vscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status);
212 dw_color_background_set( DW_CLR_WHITE );
213 for ( i = 0;i < 100; i++)
214 {
215 y = i*font_height;
216
217 dw_color_foreground_set( DW_CLR_BLACK );
218 sprintf( buf, "%6.6d", i );
219 dw_draw_text( NULL, text1pm, 0, y, buf);
220 dw_draw_text( NULL, text2pm, 0, y, buf);
221 }
222 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), text1pm);
223 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), text2pm);
224 dw_signal_connect(scrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status);
225 dw_signal_connect(scrollbar2, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status);
226 } 280 }
227 281
228 /* Beep every second */ 282 /* Beep every second */
229 int DWSIGNAL timer_callback(void *data) 283 int DWSIGNAL timer_callback(void *data)
230 { 284 {
239 */ 293 */
240 int main(int argc, char *argv[]) 294 int main(int argc, char *argv[])
241 { 295 {
242 ULONG notebookpage1; 296 ULONG notebookpage1;
243 ULONG notebookpage2; 297 ULONG notebookpage2;
244 int timerid;
245 298
246 dw_init(TRUE, argc, argv); 299 dw_init(TRUE, argc, argv);
247 300
248 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX ); 301 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX );
249 302
250 notebookbox = dw_box_new( BOXVERT, 5 ); 303 notebookbox = dw_box_new( BOXVERT, 5 );
251 dw_box_pack_start( mainwindow, notebookbox, 1, 1, TRUE, TRUE, 0); 304 dw_box_pack_start( mainwindow, notebookbox, 0, 0, TRUE, TRUE, 0);
252 305
253 notebook = dw_notebook_new( 1, TRUE ); 306 notebook = dw_notebook_new( 1, TRUE );
254 dw_box_pack_start( notebookbox, notebook, 100, 100, TRUE, TRUE, 0); 307 dw_box_pack_start( notebookbox, notebook, 100, 100, TRUE, TRUE, 0);
255 dw_window_set_font( notebook, "8.WarpSans"); 308 dw_window_set_font( notebook, "9.WarpSans");
256 309
257 notebookbox1 = dw_box_new( BOXVERT, 5 ); 310 notebookbox1 = dw_box_new( BOXVERT, 5 );
258 notebookpage1 = dw_notebook_page_new( notebook, 0, TRUE ); 311 notebookpage1 = dw_notebook_page_new( notebook, 0, TRUE );
259 dw_notebook_pack( notebook, notebookpage1, notebookbox1 ); 312 dw_notebook_pack( notebook, notebookpage1, notebookbox1 );
260 dw_notebook_page_set_text( notebook, notebookpage1, "first page"); 313 dw_notebook_page_set_text( notebook, notebookpage1, "first page");