# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1045772349 0 # Node ID 9ea4ac9a097f7ed7348de399f7faa12569603c05 # Parent 63d68387d9240adf94382c6b44b512556485ef1d Added dw_icon_load_from_file() on OS/2 and Windows. Added a stub on Unix to be filled in shortly. diff -r 63d68387d924 -r 9ea4ac9a097f dw.def --- a/dw.def Thu Feb 20 17:55:56 2003 +0000 +++ b/dw.def Thu Feb 20 20:19:09 2003 +0000 @@ -118,6 +118,7 @@ dw_icon_load @210 dw_icon_free @211 + dw_icon_load_from_file @212 dw_container_new @220 dw_container_setup @221 diff -r 63d68387d924 -r 9ea4ac9a097f dw.h --- a/dw.h Thu Feb 20 17:55:56 2003 +0000 +++ b/dw.h Thu Feb 20 20:19:09 2003 +0000 @@ -697,6 +697,7 @@ void API dw_tree_set_data(HWND handle, HWND item, void *itemdata); int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator); unsigned long API dw_icon_load(unsigned long module, unsigned long id); +unsigned long API dw_icon_load_from_file(char *filename); void API dw_icon_free(unsigned long handle); void * API dw_container_alloc(HWND handle, int rowcount); void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data); diff -r 63d68387d924 -r 9ea4ac9a097f dwtest.c --- a/dwtest.c Thu Feb 20 17:55:56 2003 +0000 +++ b/dwtest.c Thu Feb 20 20:19:09 2003 +0000 @@ -14,6 +14,8 @@ #define FIXEDFONT "fixed" #endif +#define SCROLLBARWIDTH 14 + unsigned long flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_TASKLIST | DW_FCF_DLGBORDER; @@ -34,11 +36,11 @@ tree, pagebox, treebox, - textbox1, textbox2, textboxA, textbox3, + textbox1, textbox2, textboxA, gap_box, buttonbox; -HPIXMAP text1pm,text2pm,text3pm; +HPIXMAP text1pm,text2pm; int font_width = 8; int font_height=12; @@ -63,8 +65,6 @@ hpm = text1pm; else if ( hwnd == textbox2 ) hpm = text2pm; - else if ( hwnd == textbox3 ) - hpm = text3pm; width = DW_PIXMAP_WIDTH(hpm); height = DW_PIXMAP_HEIGHT(hpm); @@ -120,11 +120,8 @@ pLine = lp[i+row]; dw_draw_text( NULL, text2pm, 0, y, pLine+col ); } - dw_color_foreground_set(DW_CLR_DEFAULT); - dw_draw_rect(0, text3pm, TRUE, 0, 0, DW_PIXMAP_WIDTH(text3pm), DW_PIXMAP_HEIGHT(text3pm)); text_expose( textbox1, NULL, NULL); text_expose( textbox2, NULL, NULL); - text_expose( textbox3, NULL, NULL); } } @@ -198,24 +195,19 @@ /* Handle size change of the main render window */ int DWSIGNAL configure_event(HWND hwnd, int width, int height, void *data) { - HPIXMAP old1 = text1pm, old2 = text2pm, old3 = text3pm; - unsigned long height1; + HPIXMAP old1 = text1pm, old2 = text2pm; int depth = dw_color_depth(); rows = height / (font_height+font_gap); cols = width / font_width; - dw_window_get_pos_size(textbox1, NULL, NULL, NULL, &height1); - /* Create new pixmaps with the current sizes */ - text1pm = dw_pixmap_new(textbox1, (font_width*width1)+2, height, depth); /* was height1 */ + text1pm = dw_pixmap_new(textbox1, (font_width*(width1+1)), height+1, depth); text2pm = dw_pixmap_new(textbox2, width, height, depth); - text3pm = dw_pixmap_new(textbox3, width, height, depth); /* Destroy the old pixmaps */ dw_pixmap_destroy(old1); dw_pixmap_destroy(old2); - dw_pixmap_destroy(old3); /* Update scrollbar ranges with new values */ dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); @@ -296,14 +288,12 @@ textbox1 = dw_render_new( 100 ); dw_window_set_font(textbox1, FIXEDFONT); dw_font_text_extents(textbox1, NULL, "O", &font_width, &font_height); - dw_box_pack_start(pagebox, textbox1, (font_width*width1), font_height*rows, FALSE, TRUE, 0); + vscrollbox = dw_box_new(BOXVERT, 0); + dw_box_pack_start(vscrollbox, textbox1, (font_width*(width1+1)), font_height*rows, FALSE, TRUE, 0); + dw_box_pack_start(vscrollbox, 0, (font_width*(width1+1)), SCROLLBARWIDTH, FALSE, FALSE, 0); + dw_box_pack_start(pagebox, vscrollbox, 0, 0, FALSE, TRUE, 0); /* create render box for gap pixmap */ - textbox3 = dw_render_new( 102 ); - dw_window_set_font(textbox3, FIXEDFONT); - dw_font_text_extents(textbox3, NULL, "O", &font_width, &font_height); - dw_box_pack_start(pagebox, textbox3, (font_width), font_height*rows, FALSE, TRUE, 0); - /* create box for filecontents and horz scrollbar */ textboxA = dw_box_new( BOXVERT,0 ); dw_box_pack_start( pagebox, textboxA, 0, 0, TRUE, TRUE, 0); @@ -314,26 +304,24 @@ dw_window_set_font(textbox2, FIXEDFONT); /* create horizonal scrollbar */ hscrollbar = dw_scrollbar_new(FALSE, 100, 50); - dw_box_pack_start( textboxA, hscrollbar, 100, 14, TRUE, FALSE, 0); + dw_box_pack_start( textboxA, hscrollbar, 100, SCROLLBARWIDTH, TRUE, FALSE, 0); /* create vertical scrollbar */ vscrollbox = dw_box_new(BOXVERT, 0); vscrollbar = dw_scrollbar_new(TRUE, 100, 50); - dw_box_pack_start(vscrollbox, vscrollbar, 14, 100, FALSE, TRUE, 0); + dw_box_pack_start(vscrollbox, vscrollbar, SCROLLBARWIDTH, 100, FALSE, TRUE, 0); /* Pack an area of empty space 14x14 pixels */ - dw_box_pack_start(vscrollbox, 0, 14, 14, FALSE, FALSE, 0); + dw_box_pack_start(vscrollbox, 0, SCROLLBARWIDTH, SCROLLBARWIDTH, FALSE, FALSE, 0); dw_box_pack_start(pagebox, vscrollbox, 0, 0, FALSE, TRUE, 0); - text1pm = dw_pixmap_new( textbox1, (font_width*width1)+2, font_height*rows, depth ); + text1pm = dw_pixmap_new( textbox1, (font_width*(width1+1)), font_height*rows, depth ); text2pm = dw_pixmap_new( textbox2, font_width*cols, font_height*rows, depth ); - text3pm = dw_pixmap_new( textbox3, font_width, font_height*rows, depth ); dw_messagebox("DWTest", "Width: %d Height: %d\n", font_width, font_height); dw_draw_rect(0, text1pm, TRUE, 0, 0, font_width*width1, font_height*rows); dw_draw_rect(0, text2pm, TRUE, 0, 0, font_width*cols, font_height*rows); dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL); dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL); - dw_signal_connect(textbox3, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL); dw_signal_connect(textbox2, "configure_event", DW_SIGNAL_FUNC(configure_event), text2pm); dw_signal_connect(hscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); dw_signal_connect(vscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); diff -r 63d68387d924 -r 9ea4ac9a097f dww.def --- a/dww.def Thu Feb 20 17:55:56 2003 +0000 +++ b/dww.def Thu Feb 20 20:19:09 2003 +0000 @@ -115,6 +115,7 @@ dw_icon_load @210 dw_icon_free @211 + dw_icon_load_from_file @212 dw_container_new @220 dw_container_setup @221 diff -r 63d68387d924 -r 9ea4ac9a097f gtk/dw.c --- a/gtk/dw.c Thu Feb 20 17:55:56 2003 +0000 +++ b/gtk/dw.c Thu Feb 20 20:19:09 2003 +0000 @@ -4127,6 +4127,34 @@ } /* + * Obtains an icon from a file. + * Parameters: + * filename: Name of the file, omit extention to have + * DW pick the appropriate file extension. + * (ICO on OS/2 or Windows, XPM on Unix) + */ +unsigned long API dw_icon_load_from_file(char *filename) +{ + char *file = alloca(strlen(filename) + 5); + + if(!file) + return 0; + + strcpy(file, filename); + + /* check if we can read from this file (it exists and read permission) */ + if(access(file, 04) != 0) + { + /* Try with .bmp extention */ + strcat(file, ".xpm"); + if(access(file, 04) != 0) + return 0; + } + /* Need to add code to add to the internal pixmap lists */ + return 0; +} + +/* * Frees a loaded resource in OS/2 and Windows. * Parameters: * handle: Handle to icon returned by dw_icon_load(). diff -r 63d68387d924 -r 9ea4ac9a097f os2/dw.c --- a/os2/dw.c Thu Feb 20 17:55:56 2003 +0000 +++ b/os2/dw.c Thu Feb 20 20:19:09 2003 +0000 @@ -5813,6 +5813,33 @@ } /* + * Obtains an icon from a file. + * Parameters: + * filename: Name of the file, omit extention to have + * DW pick the appropriate file extension. + * (ICO on OS/2 or Windows, XPM on Unix) + */ +unsigned long API dw_icon_load_from_file(char *filename) +{ + char *file = alloca(strlen(filename) + 5); + + if(!file) + return 0; + + strcpy(file, filename); + + /* check if we can read from this file (it exists and read permission) */ + if(access(file, 04) != 0) + { + /* Try with .bmp extention */ + strcat(file, ".ico"); + if(access(file, 04) != 0) + return 0; + } + return WinLoadFileIcon(file, FALSE); +} + +/* * Frees a loaded resource in OS/2 and Windows. * Parameters: * handle: Handle to icon returned by dw_icon_load(). diff -r 63d68387d924 -r 9ea4ac9a097f win/dw.c --- a/win/dw.c Thu Feb 20 17:55:56 2003 +0000 +++ b/win/dw.c Thu Feb 20 20:19:09 2003 +0000 @@ -5855,6 +5855,39 @@ } /* + * Obtains an icon from a file. + * Parameters: + * filename: Name of the file, omit extention to have + * DW pick the appropriate file extension. + * (ICO on OS/2 or Windows, XPM on Unix) + */ +unsigned long API dw_icon_load_from_file(char *filename) +{ + char *file = malloc(strlen(filename) + 5); + HANDLE icon; + + if(!file) + return 0; + + strcpy(file, filename); + + /* check if we can read from this file (it exists and read permission) */ + if(access(file, 04) != 0) + { + /* Try with .bmp extention */ + strcat(file, ".ico"); + if(access(file, 04) != 0) + { + free(file); + return 0; + } + } + icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); + free(file); + return (unsigned long)icon; +} + +/* * Frees a loaded resource in OS/2 and Windows. * Parameters: * handle: Handle to icon returned by dw_icon_load().