Mercurial > dwindows
comparison dwtest.c @ 218:fe0ab0040ba2
Not quite right yet but... handle resize and pixmap resizing.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 04 Feb 2003 23:37:30 +0000 |
parents | 7112c817573d |
children | 79968cf0f3b3 |
comparison
equal
deleted
inserted
replaced
217:7112c817573d | 218:fe0ab0040ba2 |
---|---|
30 HPIXMAP text1pm,text2pm; | 30 HPIXMAP text1pm,text2pm; |
31 | 31 |
32 int font_width = 8; | 32 int font_width = 8; |
33 int font_height=12; | 33 int font_height=12; |
34 int font_gap = 2; | 34 int font_gap = 2; |
35 int rows=100,width1=6,width2=80; | 35 int rows=100,width1=6,cols=80; |
36 char *current_file = NULL; | 36 char *current_file = NULL; |
37 int timerid; | 37 int timerid; |
38 int num_lines=0; | 38 int num_lines=0; |
39 int max_linewidth=0; | 39 int max_linewidth=0; |
40 int current_row=0,current_col=0; | 40 int current_row=0,current_col=0; |
41 | 41 |
42 FILE *fp=NULL; | 42 FILE *fp=NULL; |
43 char **lp; | 43 char **lp; |
44 | 44 |
45 /* This gets called when a part of the graph needs to be repainted. */ | 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) | 46 int DWSIGNAL text_expose(HWND hwnd, DWExpose *exp, void *data) |
47 { | 47 { |
48 HPIXMAP hpm = (HPIXMAP)data; | 48 HPIXMAP hpm = (HPIXMAP)data; |
49 | 49 int width = DW_PIXMAP_WIDTH(hpm); |
50 dw_pixmap_bitblt(hwnd, NULL, 0, 0, font_width*width1, font_height*rows, NULL, hpm, 0, 0 ); | 50 int height = DW_PIXMAP_HEIGHT(hpm); |
51 dw_flush(); | 51 |
52 return TRUE; | 52 dw_pixmap_bitblt(hwnd, NULL, 0, 0, width, height, NULL, hpm, 0, 0 ); |
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(); | 53 dw_flush(); |
61 return TRUE; | 54 return TRUE; |
62 } | 55 } |
63 | 56 |
64 void read_file( void ) | 57 void read_file( void ) |
66 char line[1024]; | 59 char line[1024]; |
67 char buf[10]; | 60 char buf[10]; |
68 int i,y,len; | 61 int i,y,len; |
69 fp = fopen( current_file, "r" ); | 62 fp = fopen( current_file, "r" ); |
70 lp = (char **)calloc( 1000,sizeof(char *)); | 63 lp = (char **)calloc( 1000,sizeof(char *)); |
71 /* should test for out of memory */ | 64 /* should test for out of memory */ |
72 max_linewidth=0; | 65 max_linewidth=0; |
73 for ( i = 0; i < 1000; i++ ) | 66 for ( i = 0; i < 1000; i++ ) |
74 { | 67 { |
75 lp[i] = (char *)malloc( 1025 ); | 68 lp[i] = (char *)malloc( 1025 ); |
76 if ( fgets( lp[i], 1024, fp ) == NULL ) | 69 if ( fgets( lp[i], 1024, fp ) == NULL ) |
81 if ( lp[i][len - 1] == '\n' ) | 74 if ( lp[i][len - 1] == '\n' ) |
82 lp[i][len - 1] = '\0'; | 75 lp[i][len - 1] = '\0'; |
83 } | 76 } |
84 num_lines = i; | 77 num_lines = i; |
85 fclose( fp ); | 78 fclose( fp ); |
86 dw_scrollbar_set_range(hscrollbar, max_linewidth, width2); | 79 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); |
87 dw_scrollbar_set_pos(hscrollbar, 0); | 80 dw_scrollbar_set_pos(hscrollbar, 0); |
88 dw_scrollbar_set_range(vscrollbar, num_lines, rows); | 81 dw_scrollbar_set_range(vscrollbar, num_lines, rows); |
89 dw_scrollbar_set_pos(vscrollbar, 0); | 82 dw_scrollbar_set_pos(vscrollbar, 0); |
90 } | 83 } |
91 | 84 |
96 char *pLine; | 89 char *pLine; |
97 fprintf(stderr,"in draw_file: %d %d\n",row,col); | 90 fprintf(stderr,"in draw_file: %d %d\n",row,col); |
98 if ( current_file ) | 91 if ( current_file ) |
99 { | 92 { |
100 dw_color_foreground_set(DW_CLR_WHITE); | 93 dw_color_foreground_set(DW_CLR_WHITE); |
101 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows); | 94 dw_draw_rect(0, text1pm, TRUE, 0, 0, DW_PIXMAP_WIDTH(text1pm), DW_PIXMAP_HEIGHT(text1pm)); |
102 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*width2, font_height*rows); | 95 dw_draw_rect(0, text2pm, TRUE, 0, 0, DW_PIXMAP_WIDTH(text2pm), DW_PIXMAP_HEIGHT(text2pm)); |
103 for ( i = 0;(i < rows) & (i+row < rows); i++) | 96 for ( i = 0;(i < rows) & (i+row < rows); i++) |
104 { | 97 { |
105 y = i*(font_height+font_gap); | 98 y = i*(font_height+font_gap); |
106 dw_color_foreground_set( i ); | 99 dw_color_foreground_set( i ); |
107 sprintf( buf, "%6.6d", i+row ); | 100 sprintf( buf, "%6.6d", i+row ); |
108 dw_draw_text( NULL, text1pm, 0, y, buf); | 101 dw_draw_text( NULL, text1pm, 0, y, buf); |
109 pLine = lp[i+row]; | 102 pLine = lp[i+row]; |
110 dw_draw_text( NULL, text2pm, 0, y, pLine+col ); | 103 dw_draw_text( NULL, text2pm, 0, y, pLine+col ); |
111 } | 104 } |
112 text_expose1( textbox1, NULL, text1pm); | 105 text_expose( textbox1, NULL, text1pm); |
113 text_expose1( textbox2, NULL, text2pm); | 106 text_expose( textbox2, NULL, text2pm); |
114 } | 107 } |
115 } | 108 } |
116 | 109 |
117 int DWSIGNAL beep_callback(HWND window, void *data) | 110 int DWSIGNAL beep_callback(HWND window, void *data) |
118 { | 111 { |
119 dw_timer_disconnect( timerid ); | 112 dw_timer_disconnect( timerid ); |
113 return TRUE; | |
120 } | 114 } |
121 | 115 |
122 int DWSIGNAL exit_callback(HWND window, void *data) | 116 int DWSIGNAL exit_callback(HWND window, void *data) |
123 { | 117 { |
124 dw_window_destroy((HWND)data); | 118 dw_window_destroy((HWND)data); |
173 dw_window_set_text(stext, tmpbuf); | 167 dw_window_set_text(stext, tmpbuf); |
174 draw_file( current_row, current_col); | 168 draw_file( current_row, current_col); |
175 } | 169 } |
176 } | 170 } |
177 | 171 |
172 /* Handle size change of the main render window */ | |
173 int DWSIGNAL configure_event(HWND hwnd, int width, int height, void *data) | |
174 { | |
175 HPIXMAP old1 = text1pm, old2 = text2pm; | |
176 rows = height / font_height; | |
177 cols = width / font_width; | |
178 | |
179 /* Create new pixmaps with the current sizes */ | |
180 text1pm = dw_pixmap_new( textbox2, font_width*width1, height, dw_color_depth()); | |
181 text2pm = dw_pixmap_new( textbox2, width, height, dw_color_depth()); | |
182 | |
183 /* Destroy the old pixmaps */ | |
184 dw_pixmap_destroy(old1); | |
185 dw_pixmap_destroy(old2); | |
186 | |
187 /* Update scrollbar ranges with new values */ | |
188 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); | |
189 dw_scrollbar_set_range(vscrollbar, num_lines, rows); | |
190 | |
191 /* Redraw the window */ | |
192 draw_file( current_row, current_col); | |
193 return TRUE; | |
194 } | |
195 | |
178 void archive_add(void) | 196 void archive_add(void) |
179 { | 197 { |
180 HWND browsebutton, browsebox; | 198 HWND browsebutton, browsebox; |
181 | 199 |
182 lbbox = dw_box_new(BOXVERT, 10); | 200 lbbox = dw_box_new(BOXVERT, 10); |
245 status = dw_status_text_new("", 0); | 263 status = dw_status_text_new("", 0); |
246 dw_box_pack_start( notebookbox2, status, 100, 20, TRUE, FALSE, 1); | 264 dw_box_pack_start( notebookbox2, status, 100, 20, TRUE, FALSE, 1); |
247 | 265 |
248 /* create render box for number pixmap */ | 266 /* create render box for number pixmap */ |
249 textbox1 = dw_render_new( 100 ); | 267 textbox1 = dw_render_new( 100 ); |
250 dw_box_pack_start( pagebox, textbox1, font_width*width1, font_height*rows, FALSE, TRUE, 0); | |
251 dw_window_set_font(textbox1, "9.WarpSans"); | 268 dw_window_set_font(textbox1, "9.WarpSans"); |
269 dw_font_text_extents( NULL, text1pm, "O", &font_width, &font_height ); | |
270 dw_box_pack_start(pagebox, textbox1, font_width*width1, font_height*rows, FALSE, TRUE, 0); | |
252 | 271 |
253 /* create box for filecontents and horz scrollbar */ | 272 /* create box for filecontents and horz scrollbar */ |
254 textboxA = dw_box_new( BOXVERT,0 ); | 273 textboxA = dw_box_new( BOXVERT,0 ); |
255 dw_box_pack_start( pagebox, textboxA, 0, 0, TRUE, TRUE, 0); | 274 dw_box_pack_start( pagebox, textboxA, 0, 0, TRUE, TRUE, 0); |
256 | 275 |
257 /* create render box for filecontents pixmap */ | 276 /* create render box for filecontents pixmap */ |
258 textbox2 = dw_render_new( 101 ); | 277 textbox2 = dw_render_new( 101 ); |
259 dw_box_pack_start( textboxA, textbox2, font_width*width2, font_height*rows, TRUE, TRUE, 0); | 278 dw_box_pack_start( textboxA, textbox2, 10, 10, TRUE, TRUE, 0); |
260 dw_window_set_font(textbox2, "9.WarpSans"); | 279 dw_window_set_font(textbox2, "9.WarpSans"); |
261 /* create horizonal scrollbar */ | 280 /* create horizonal scrollbar */ |
262 hscrollbar = dw_scrollbar_new(FALSE, 100, 50); | 281 hscrollbar = dw_scrollbar_new(FALSE, 100, 50); |
263 dw_box_pack_start( textboxA, hscrollbar, 100, 20, TRUE, FALSE, 0); | 282 dw_box_pack_start( textboxA, hscrollbar, 100, 20, TRUE, FALSE, 0); |
264 | 283 |
265 /* create vertical scrollbar */ | 284 /* create vertical scrollbar */ |
266 vscrollbar = dw_scrollbar_new(TRUE, 100, 50); | 285 vscrollbar = dw_scrollbar_new(TRUE, 100, 50); |
267 dw_box_pack_start(pagebox, vscrollbar, 20, 100, FALSE, TRUE, 0); | 286 dw_box_pack_start(pagebox, vscrollbar, 20, 100, FALSE, TRUE, 0); |
268 | 287 |
269 text1pm = dw_pixmap_new( textbox1, font_width*width1, font_height*rows, depth ); | 288 text1pm = dw_pixmap_new( textbox1, font_width*width1, font_height*rows, depth ); |
270 text2pm = dw_pixmap_new( textbox2, font_width*width2, font_height*rows, depth ); | 289 text2pm = dw_pixmap_new( textbox2, font_width*cols, font_height*rows, depth ); |
271 | 290 |
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); | 291 dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height); |
274 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows); | 292 dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows); |
275 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*width2, font_height*rows); | 293 dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*cols, font_height*rows); |
276 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose1), text1pm); | 294 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), text1pm); |
277 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose2), text2pm); | 295 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), text2pm); |
296 dw_signal_connect(textbox2, "configure_event", DW_SIGNAL_FUNC(configure_event), text2pm); | |
278 dw_signal_connect(hscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); | 297 dw_signal_connect(hscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); |
279 dw_signal_connect(vscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); | 298 dw_signal_connect(vscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); |
280 } | 299 } |
281 | 300 |
282 /* Beep every second */ | 301 /* Beep every second */ |