Mercurial > dwindows
comparison dwtest.c @ 1230:75a773cdb626
Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
Also added multi-page printing code to the test program to make sure that works properly on all platforms.
It will print the selected file on page 2, or a centered error message if none is selected.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 16 Oct 2011 19:12:53 +0000 |
parents | b54d37938d61 |
children | 8e37ebb3fab7 |
comparison
equal
deleted
inserted
replaced
1229:437b045a3b07 | 1230:75a773cdb626 |
---|---|
305 dw_scrollbar_set_range(vscrollbar, num_lines, rows); | 305 dw_scrollbar_set_range(vscrollbar, num_lines, rows); |
306 dw_scrollbar_set_pos(vscrollbar, 0); | 306 dw_scrollbar_set_pos(vscrollbar, 0); |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 void draw_file( int row, int col ) | 310 /* When hpma is not NULL we are printing.. so handle things differently */ |
311 { | 311 void draw_file( int row, int col, int nrows, int fheight, HPIXMAP hpma ) |
312 { | |
313 HPIXMAP hpm = hpma ? hpma : text2pm; | |
312 char buf[10]; | 314 char buf[10]; |
313 int i,y,fileline; | 315 int i,y,fileline; |
314 char *pLine; | 316 char *pLine; |
315 | 317 |
316 if ( current_file ) | 318 if ( current_file ) |
317 { | 319 { |
318 dw_color_foreground_set(DW_CLR_WHITE); | 320 dw_color_foreground_set(DW_CLR_WHITE); |
319 dw_draw_rect(0, text1pm, TRUE, 0, 0, (int)DW_PIXMAP_WIDTH(text1pm), (int)DW_PIXMAP_HEIGHT(text1pm)); | 321 if(!hpma) |
320 dw_draw_rect(0, text2pm, TRUE, 0, 0, (int)DW_PIXMAP_WIDTH(text2pm), (int)DW_PIXMAP_HEIGHT(text2pm)); | 322 dw_draw_rect(0, text1pm, TRUE, 0, 0, (int)DW_PIXMAP_WIDTH(text1pm), (int)DW_PIXMAP_HEIGHT(text1pm)); |
321 | 323 dw_draw_rect(0, hpm, TRUE, 0, 0, (int)DW_PIXMAP_WIDTH(hpm), (int)DW_PIXMAP_HEIGHT(hpm)); |
322 for ( i = 0;(i < rows) && (i+row < num_lines); i++) | 324 |
325 for ( i = 0;(i < nrows) && (i+row < num_lines); i++) | |
323 { | 326 { |
324 fileline = i + row - 1; | 327 fileline = i + row - 1; |
325 y = i*font_height; | 328 y = i*fheight; |
326 dw_color_background_set( 1 + (fileline % 15) ); | 329 dw_color_background_set( 1 + (fileline % 15) ); |
327 dw_color_foreground_set( fileline < 0 ? DW_CLR_WHITE : fileline % 16 ); | 330 dw_color_foreground_set( fileline < 0 ? DW_CLR_WHITE : fileline % 16 ); |
328 sprintf( buf, "%6.6d", i+row ); | 331 if(!hpma) |
329 dw_draw_text( 0, text1pm, 0, y, buf); | 332 { |
333 sprintf( buf, "%6.6d", i+row ); | |
334 dw_draw_text( 0, text1pm, 0, y, buf); | |
335 } | |
330 pLine = lp[i+row]; | 336 pLine = lp[i+row]; |
331 dw_draw_text( 0, text2pm, 0, y, pLine+col ); | 337 dw_draw_text( 0, hpm, 0, y, pLine+col ); |
332 } | 338 } |
333 text_expose( textbox1, NULL, NULL); | 339 if(!hpma) |
334 text_expose( textbox2, NULL, NULL); | 340 { |
335 } | 341 text_expose( textbox1, NULL, NULL); |
336 } | 342 text_expose( textbox2, NULL, NULL); |
337 | 343 } |
344 } | |
345 } | |
346 | |
347 /* When hpma is not NULL we are printing.. so handle things differently */ | |
338 void draw_shapes(int direct, HPIXMAP hpma) | 348 void draw_shapes(int direct, HPIXMAP hpma) |
339 { | 349 { |
340 HPIXMAP hpm = hpma ? hpma : text2pm; | 350 HPIXMAP hpm = hpma ? hpma : text2pm; |
341 int width = (int)DW_PIXMAP_WIDTH(hpm), height = (int)DW_PIXMAP_HEIGHT(hpm); | 351 int width = (int)DW_PIXMAP_WIDTH(hpm), height = (int)DW_PIXMAP_HEIGHT(hpm); |
342 HPIXMAP pixmap = direct ? NULL : hpm; | 352 HPIXMAP pixmap = direct ? NULL : hpm; |
373 break; | 383 break; |
374 case 1: | 384 case 1: |
375 draw_shapes(TRUE, NULL); | 385 draw_shapes(TRUE, NULL); |
376 break; | 386 break; |
377 case 2: | 387 case 2: |
378 draw_file(current_row, current_col); | 388 draw_file(current_row, current_col, rows, font_height, NULL); |
379 break; | 389 break; |
380 } | 390 } |
381 } | 391 } |
382 | 392 |
383 int DWSIGNAL draw_page(HPRINT print, HPIXMAP pixmap, int page_num, void *data) | 393 int DWSIGNAL draw_page(HPRINT print, HPIXMAP pixmap, int page_num, void *data) |
384 { | 394 { |
385 dw_pixmap_set_font(pixmap, FIXEDFONT); | 395 dw_pixmap_set_font(pixmap, FIXEDFONT); |
386 draw_shapes(FALSE, pixmap); | 396 if(page_num == 0) |
397 { | |
398 draw_shapes(FALSE, pixmap); | |
399 } | |
400 else if(page_num == 1) | |
401 { | |
402 /* Get the font size for this printer context... */ | |
403 int fheight, fwidth; | |
404 | |
405 /* If we have a file to display... */ | |
406 if(current_file) | |
407 { | |
408 int nrows; | |
409 | |
410 /* Calculate new dimensions */ | |
411 dw_font_text_extents_get(NULL, pixmap, "(g", NULL, &fheight); | |
412 nrows = (int)(DW_PIXMAP_HEIGHT(pixmap) / fheight); | |
413 | |
414 /* Do the actual drawing */ | |
415 draw_file(0, 0, nrows, fheight, pixmap); | |
416 } | |
417 else | |
418 { | |
419 /* We don't have a file so center an error message on the page */ | |
420 char *text = "No file currently selected!"; | |
421 int posx, posy; | |
422 | |
423 dw_font_text_extents_get(NULL, pixmap, text, &fwidth, &fheight); | |
424 | |
425 posx = (int)(DW_PIXMAP_WIDTH(pixmap) - fwidth)/2; | |
426 posy = (int)(DW_PIXMAP_HEIGHT(pixmap) - fheight)/2; | |
427 | |
428 dw_color_foreground_set(DW_CLR_BLACK); | |
429 dw_color_background_set(DW_CLR_WHITE); | |
430 dw_draw_text(NULL, pixmap, posx, posy, text); | |
431 } | |
432 } | |
387 return TRUE; | 433 return TRUE; |
388 } | 434 } |
389 | 435 |
390 int DWSIGNAL print_callback(HWND window, void *data) | 436 int DWSIGNAL print_callback(HWND window, void *data) |
391 { | 437 { |
392 HPRINT print = dw_print_new("DWTest Job", 0, 1, DW_SIGNAL_FUNC(draw_page), NULL); | 438 HPRINT print = dw_print_new("DWTest Job", 0, 2, DW_SIGNAL_FUNC(draw_page), NULL); |
393 dw_print_run(print, 0); | 439 dw_print_run(print, 0); |
394 return FALSE; | 440 return FALSE; |
395 } | 441 } |
396 | 442 |
397 int DWSIGNAL refresh_callback(HWND window, void *data) | 443 int DWSIGNAL refresh_callback(HWND window, void *data) |