comparison dwtest.c @ 254:42332e598d55

Add third notebook page - for tree example. Just starting. Add gap window on second page. Fix bug with resizing render box on second page Added key_press callbacks for render boxes, but no keypresses are available.
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 20 Feb 2003 11:21:47 +0000
parents e041ce42659a
children 9ea4ac9a097f
comparison
equal deleted inserted replaced
253:e041ce42659a 254:42332e598d55
23 cancelbutton, 23 cancelbutton,
24 lbbox, 24 lbbox,
25 notebookbox, 25 notebookbox,
26 notebookbox1, 26 notebookbox1,
27 notebookbox2, 27 notebookbox2,
28 notebookbox3,
28 notebook, 29 notebook,
29 vscrollbar, 30 vscrollbar,
30 hscrollbar, 31 hscrollbar,
31 status, 32 status,
32 stext, 33 stext,
34 tree,
33 pagebox, 35 pagebox,
34 textbox1, textbox2, textboxA, 36 treebox,
37 textbox1, textbox2, textboxA, textbox3,
38 gap_box,
35 buttonbox; 39 buttonbox;
36 40
37 HPIXMAP text1pm,text2pm; 41 HPIXMAP text1pm,text2pm,text3pm;
38 42
39 int font_width = 8; 43 int font_width = 8;
40 int font_height=12; 44 int font_height=12;
41 int font_gap = 2; 45 int font_gap = 2;
42 int rows=100,width1=6,cols=80; 46 int rows=100,width1=6,cols=80;
50 char **lp; 54 char **lp;
51 55
52 /* This gets called when a part of the graph needs to be repainted. */ 56 /* This gets called when a part of the graph needs to be repainted. */
53 int DWSIGNAL text_expose(HWND hwnd, DWExpose *exp, void *data) 57 int DWSIGNAL text_expose(HWND hwnd, DWExpose *exp, void *data)
54 { 58 {
55 HPIXMAP hpm = (hwnd == textbox1 ? text1pm : text2pm); 59 HPIXMAP hpm;
56 int width = DW_PIXMAP_WIDTH(hpm); 60 int width,height;
57 int height = DW_PIXMAP_HEIGHT(hpm); 61
62 if ( hwnd == textbox1 )
63 hpm = text1pm;
64 else if ( hwnd == textbox2 )
65 hpm = text2pm;
66 else if ( hwnd == textbox3 )
67 hpm = text3pm;
68
69 width = DW_PIXMAP_WIDTH(hpm);
70 height = DW_PIXMAP_HEIGHT(hpm);
58 71
59 dw_pixmap_bitblt(hwnd, NULL, 0, 0, width, height, NULL, hpm, 0, 0 ); 72 dw_pixmap_bitblt(hwnd, NULL, 0, 0, width, height, NULL, hpm, 0, 0 );
60 dw_flush(); 73 dw_flush();
61 return TRUE; 74 return TRUE;
62 } 75 }
105 sprintf( buf, "%6.6d", i+row ); 118 sprintf( buf, "%6.6d", i+row );
106 dw_draw_text( NULL, text1pm, 0, y, buf); 119 dw_draw_text( NULL, text1pm, 0, y, buf);
107 pLine = lp[i+row]; 120 pLine = lp[i+row];
108 dw_draw_text( NULL, text2pm, 0, y, pLine+col ); 121 dw_draw_text( NULL, text2pm, 0, y, pLine+col );
109 } 122 }
110 text_expose( textbox1, NULL, text1pm); 123 dw_color_foreground_set(DW_CLR_DEFAULT);
111 text_expose( textbox2, NULL, text2pm); 124 dw_draw_rect(0, text3pm, TRUE, 0, 0, DW_PIXMAP_WIDTH(text3pm), DW_PIXMAP_HEIGHT(text3pm));
125 text_expose( textbox1, NULL, NULL);
126 text_expose( textbox2, NULL, NULL);
127 text_expose( textbox3, NULL, NULL);
112 } 128 }
113 } 129 }
114 130
115 int DWSIGNAL beep_callback(HWND window, void *data) 131 int DWSIGNAL beep_callback(HWND window, void *data)
116 { 132 {
117 dw_timer_disconnect( timerid ); 133 dw_timer_disconnect( timerid );
118 return TRUE; 134 return TRUE;
135 }
136
137 int DWSIGNAL keypress_callback(HWND window, void *data)
138 {
139 fprintf(stderr,"got keypress\n");
140 return 0;
119 } 141 }
120 142
121 int DWSIGNAL exit_callback(HWND window, void *data) 143 int DWSIGNAL exit_callback(HWND window, void *data)
122 { 144 {
123 dw_window_destroy((HWND)data); 145 dw_window_destroy((HWND)data);
174 } 196 }
175 197
176 /* Handle size change of the main render window */ 198 /* Handle size change of the main render window */
177 int DWSIGNAL configure_event(HWND hwnd, int width, int height, void *data) 199 int DWSIGNAL configure_event(HWND hwnd, int width, int height, void *data)
178 { 200 {
179 HPIXMAP old1 = text1pm, old2 = text2pm; 201 HPIXMAP old1 = text1pm, old2 = text2pm, old3 = text3pm;
180 unsigned long height1; 202 unsigned long height1;
181 int depth = dw_color_depth(); 203 int depth = dw_color_depth();
182 204
183 rows = height / (font_height+font_gap); 205 rows = height / (font_height+font_gap);
184 cols = width / font_width; 206 cols = width / font_width;
185 207
186 dw_window_get_pos_size(textbox1, NULL, NULL, NULL, &height1); 208 dw_window_get_pos_size(textbox1, NULL, NULL, NULL, &height1);
187 209
188 /* Create new pixmaps with the current sizes */ 210 /* Create new pixmaps with the current sizes */
189 text1pm = dw_pixmap_new(textbox1, (font_width*width1)+2, height1, depth); 211 text1pm = dw_pixmap_new(textbox1, (font_width*width1)+2, height, depth); /* was height1 */
190 text2pm = dw_pixmap_new(textbox2, width, height, depth); 212 text2pm = dw_pixmap_new(textbox2, width, height, depth);
213 text3pm = dw_pixmap_new(textbox3, width, height, depth);
191 214
192 /* Destroy the old pixmaps */ 215 /* Destroy the old pixmaps */
193 dw_pixmap_destroy(old1); 216 dw_pixmap_destroy(old1);
194 dw_pixmap_destroy(old2); 217 dw_pixmap_destroy(old2);
218 dw_pixmap_destroy(old3);
195 219
196 /* Update scrollbar ranges with new values */ 220 /* Update scrollbar ranges with new values */
197 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); 221 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols);
198 dw_scrollbar_set_range(vscrollbar, num_lines, rows); 222 dw_scrollbar_set_range(vscrollbar, num_lines, rows);
199 223
270 294
271 /* create render box for number pixmap */ 295 /* create render box for number pixmap */
272 textbox1 = dw_render_new( 100 ); 296 textbox1 = dw_render_new( 100 );
273 dw_window_set_font(textbox1, FIXEDFONT); 297 dw_window_set_font(textbox1, FIXEDFONT);
274 dw_font_text_extents(textbox1, NULL, "O", &font_width, &font_height); 298 dw_font_text_extents(textbox1, NULL, "O", &font_width, &font_height);
275 dw_box_pack_start(pagebox, textbox1, (font_width*width1)+2, font_height*rows, FALSE, TRUE, 0); 299 dw_box_pack_start(pagebox, textbox1, (font_width*width1), font_height*rows, FALSE, TRUE, 0);
300
301 /* create render box for gap pixmap */
302 textbox3 = dw_render_new( 102 );
303 dw_window_set_font(textbox3, FIXEDFONT);
304 dw_font_text_extents(textbox3, NULL, "O", &font_width, &font_height);
305 dw_box_pack_start(pagebox, textbox3, (font_width), font_height*rows, FALSE, TRUE, 0);
276 306
277 /* create box for filecontents and horz scrollbar */ 307 /* create box for filecontents and horz scrollbar */
278 textboxA = dw_box_new( BOXVERT,0 ); 308 textboxA = dw_box_new( BOXVERT,0 );
279 dw_box_pack_start( pagebox, textboxA, 0, 0, TRUE, TRUE, 0); 309 dw_box_pack_start( pagebox, textboxA, 0, 0, TRUE, TRUE, 0);
280 310
294 dw_box_pack_start(vscrollbox, 0, 14, 14, FALSE, FALSE, 0); 324 dw_box_pack_start(vscrollbox, 0, 14, 14, FALSE, FALSE, 0);
295 dw_box_pack_start(pagebox, vscrollbox, 0, 0, FALSE, TRUE, 0); 325 dw_box_pack_start(pagebox, vscrollbox, 0, 0, FALSE, TRUE, 0);
296 326
297 text1pm = dw_pixmap_new( textbox1, (font_width*width1)+2, font_height*rows, depth ); 327 text1pm = dw_pixmap_new( textbox1, (font_width*width1)+2, font_height*rows, depth );
298 text2pm = dw_pixmap_new( textbox2, font_width*cols, font_height*rows, depth ); 328 text2pm = dw_pixmap_new( textbox2, font_width*cols, font_height*rows, depth );
329 text3pm = dw_pixmap_new( textbox3, font_width, font_height*rows, depth );
299 330
300 dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height); 331 dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height);
301 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows); 332 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows);
302 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*cols, font_height*rows); 333 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*cols, font_height*rows);
303 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL); 334 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL);
304 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL); 335 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL);
336 dw_signal_connect(textbox3, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL);
305 dw_signal_connect(textbox2, "configure_event", DW_SIGNAL_FUNC(configure_event), text2pm); 337 dw_signal_connect(textbox2, "configure_event", DW_SIGNAL_FUNC(configure_event), text2pm);
306 dw_signal_connect(hscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); 338 dw_signal_connect(hscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status);
307 dw_signal_connect(vscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); 339 dw_signal_connect(vscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status);
340 dw_signal_connect(textbox1, "key_press_event", DW_SIGNAL_FUNC(keypress_callback), text1pm);
341 dw_signal_connect(textbox2, "key_press_event", DW_SIGNAL_FUNC(keypress_callback), text2pm);
342 }
343
344 void tree_add(void)
345 {
346 HWND t1,t2,t3;
347 int depth = dw_color_depth();
348
349 /* create a box to pack into the notebook page */
350 treebox = dw_box_new(BOXHORZ, 2);
351 dw_box_pack_start( notebookbox3, treebox, 500, 200, TRUE, TRUE, 0);
352
353 /* now a tree area under this box */
354 tree = dw_tree_new(0);
355 dw_box_pack_start( notebookbox3, tree, 500, 200, TRUE, FALSE, 1);
356
357 t1 = dw_tree_insert(tree, "tree item 1", NULL, NULL, NULL );
358 t2 = dw_tree_insert(tree, "tree item 2", NULL, NULL, NULL );
359 t3 = dw_tree_insert(tree, "tree item 3", NULL, t2, NULL );
360
361 /*
362 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL);
363 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL);
364 dw_signal_connect(textbox2, "configure_event", DW_SIGNAL_FUNC(configure_event), text2pm);
365 dw_signal_connect(hscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status);
366 dw_signal_connect(vscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status);
367 dw_signal_connect(textbox1, "key_press_event", DW_SIGNAL_FUNC(keypress_callback), text1pm);
368 dw_signal_connect(textbox2, "key_press_event", DW_SIGNAL_FUNC(keypress_callback), text2pm);
369 */
308 } 370 }
309 371
310 /* Beep every second */ 372 /* Beep every second */
311 int DWSIGNAL timer_callback(void *data) 373 int DWSIGNAL timer_callback(void *data)
312 { 374 {
321 */ 383 */
322 int main(int argc, char *argv[]) 384 int main(int argc, char *argv[])
323 { 385 {
324 ULONG notebookpage1; 386 ULONG notebookpage1;
325 ULONG notebookpage2; 387 ULONG notebookpage2;
388 ULONG notebookpage3;
326 389
327 dw_init(TRUE, argc, argv); 390 dw_init(TRUE, argc, argv);
328 391
329 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX ); 392 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX );
330 393
344 notebookpage2 = dw_notebook_page_new( notebook, 1, FALSE ); 407 notebookpage2 = dw_notebook_page_new( notebook, 1, FALSE );
345 dw_notebook_pack( notebook, notebookpage2, notebookbox2 ); 408 dw_notebook_pack( notebook, notebookpage2, notebookbox2 );
346 dw_notebook_page_set_text( notebook, notebookpage2, "second page"); 409 dw_notebook_page_set_text( notebook, notebookpage2, "second page");
347 text_add(); 410 text_add();
348 411
412 notebookbox3 = dw_box_new( BOXVERT, 5 );
413 notebookpage3 = dw_notebook_page_new( notebook, 1, FALSE );
414 dw_notebook_pack( notebook, notebookpage3, notebookbox3 );
415 dw_notebook_page_set_text( notebook, notebookpage3, "third page");
416 tree_add();
417
349 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(exit_callback), (void *)mainwindow); 418 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(exit_callback), (void *)mainwindow);
350 timerid = dw_timer_connect(1000, DW_SIGNAL_FUNC(timer_callback), 0); 419 timerid = dw_timer_connect(1000, DW_SIGNAL_FUNC(timer_callback), 0);
351 dw_window_set_usize(mainwindow, 640, 480); 420 dw_window_set_usize(mainwindow, 640, 480);
352 dw_window_show(mainwindow); 421 dw_window_show(mainwindow);
353 422