Update of /cvsroot/morphix/mcp/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7307/src Modified Files: Makefile Makefile.am Makefile.in callbacks.c callbacks.h dirtree.c iconviewer.c iconviewer.h main.c Log Message: added iconviewer-widget (sortof), resizing still doesn't work (disabled). added directory of .desktop files for MCP, .directory support not yet included into widget. Nope Tiago doesn't kill me for this... Index: Makefile =================================================================== RCS file: /cvsroot/morphix/mcp/src/Makefile,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile 5 Sep 2003 12:16:16 -0000 1.3 --- Makefile 2 Mar 2004 17:09:11 -0000 1.4 *************** *** 91,95 **** bin_PROGRAMS = mcp ! mcp_SOURCES = main.c support.c support.h callbacks.c callbacks.h desktop_file.c desktop_file.h dirtree.c dirtree.h iconviewer.c iconviewer.h --- 91,95 ---- bin_PROGRAMS = mcp ! mcp_SOURCES = main.c support.c support.h callbacks.c callbacks.h desktop_file.c desktop_file.h dirtree.c dirtree.h iconviewer.c iconviewer.h interface.c interface.h *************** *** 106,110 **** LIBS = mcp_OBJECTS = main.o support.o callbacks.o desktop_file.o dirtree.o \ ! iconviewer.o mcp_DEPENDENCIES = mcp_LDFLAGS = --- 106,110 ---- LIBS = mcp_OBJECTS = main.o support.o callbacks.o desktop_file.o dirtree.o \ ! iconviewer.o interface.o mcp_DEPENDENCIES = mcp_LDFLAGS = *************** *** 121,125 **** GZIP_ENV = --best DEP_FILES = .deps/callbacks.P .deps/desktop_file.P .deps/dirtree.P \ ! .deps/iconviewer.P .deps/main.P .deps/support.P SOURCES = $(mcp_SOURCES) OBJECTS = $(mcp_OBJECTS) --- 121,125 ---- GZIP_ENV = --best DEP_FILES = .deps/callbacks.P .deps/desktop_file.P .deps/dirtree.P \ ! .deps/iconviewer.P .deps/interface.P .deps/main.P .deps/support.P SOURCES = $(mcp_SOURCES) OBJECTS = $(mcp_OBJECTS) Index: Makefile.am =================================================================== RCS file: /cvsroot/morphix/mcp/src/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 5 Sep 2003 12:16:16 -0000 1.3 --- Makefile.am 2 Mar 2004 17:09:11 -0000 1.4 *************** *** 14,18 **** desktop_file.c desktop_file.h \ dirtree.c dirtree.h \ ! iconviewer.c iconviewer.h mcp_LDADD = @PACKAGE_LIBS@ $(INTLLIBS) -L/usr/lib -lz -lpthread -lm --- 14,19 ---- desktop_file.c desktop_file.h \ dirtree.c dirtree.h \ ! iconviewer.c iconviewer.h \ ! interface.c interface.h mcp_LDADD = @PACKAGE_LIBS@ $(INTLLIBS) -L/usr/lib -lz -lpthread -lm Index: Makefile.in =================================================================== RCS file: /cvsroot/morphix/mcp/src/Makefile.in,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.in 5 Sep 2003 12:16:16 -0000 1.3 --- Makefile.in 2 Mar 2004 17:09:11 -0000 1.4 *************** *** 91,95 **** bin_PROGRAMS = mcp ! mcp_SOURCES = main.c support.c support.h callbacks.c callbacks.h desktop_file.c desktop_file.h dirtree.c dirtree.h iconviewer.c iconviewer.h --- 91,95 ---- bin_PROGRAMS = mcp ! mcp_SOURCES = main.c support.c support.h callbacks.c callbacks.h desktop_file.c desktop_file.h dirtree.c dirtree.h iconviewer.c iconviewer.h interface.c interface.h *************** *** 106,110 **** LIBS = @LIBS@ mcp_OBJECTS = main.o support.o callbacks.o desktop_file.o dirtree.o \ ! iconviewer.o mcp_DEPENDENCIES = mcp_LDFLAGS = --- 106,110 ---- LIBS = @LIBS@ mcp_OBJECTS = main.o support.o callbacks.o desktop_file.o dirtree.o \ ! iconviewer.o interface.o mcp_DEPENDENCIES = mcp_LDFLAGS = *************** *** 121,125 **** GZIP_ENV = --best DEP_FILES = .deps/callbacks.P .deps/desktop_file.P .deps/dirtree.P \ ! .deps/iconviewer.P .deps/main.P .deps/support.P SOURCES = $(mcp_SOURCES) OBJECTS = $(mcp_OBJECTS) --- 121,125 ---- GZIP_ENV = --best DEP_FILES = .deps/callbacks.P .deps/desktop_file.P .deps/dirtree.P \ ! .deps/iconviewer.P .deps/interface.P .deps/main.P .deps/support.P SOURCES = $(mcp_SOURCES) OBJECTS = $(mcp_OBJECTS) Index: callbacks.c =================================================================== RCS file: /cvsroot/morphix/mcp/src/callbacks.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** callbacks.c 27 Sep 2003 21:31:44 -0000 1.13 --- callbacks.c 2 Mar 2004 17:09:11 -0000 1.14 *************** *** 13,18 **** #include "iconviewer.h" gint debug_switch = 1; ! GtkWidget *iv; int debug(const char *fmt, ...) { --- 13,20 ---- #include "iconviewer.h" + extern GtkWidget *MainWindow; + gint debug_switch = 1; ! gchar *base_path; int debug(const char *fmt, ...) { *************** *** 41,89 **** filename = tmp; printf("You've selected %s\n", filename); ! iconviewer_refresh(iv, filename); g_free(filename); } } ! GtkWidget* control_panel_new(gchar* base) ! { ! GtkWidget *wndMain, *tblMain, *vbRoot, *tree, *paneRoot, *scroll; ! GtkTreeSelection *select; ! // Setup the window ! wndMain = gtk_window_new(GTK_WINDOW_TOPLEVEL); ! gtk_widget_set_size_request(wndMain, 450, 450); ! ! g_signal_connect ((gpointer) wndMain, "destroy", ! G_CALLBACK (gtk_main_quit), ! NULL); ! gtk_window_set_title(GTK_WINDOW(wndMain), "Morphix Configuration Panel"); ! paneRoot = gtk_hpaned_new(); ! gtk_container_add (GTK_CONTAINER (wndMain), paneRoot); ! ! // Setup the tree panel ! tree = dirtree_new(base, FALSE, FALSE, gdk_pixbuf_new_from_file(find_icon("../test/Harddisk.png"), NULL)); ! scroll = gtk_scrolled_window_new(NULL, NULL); ! gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); ! gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tree); ! ! select = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree)); ! gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE); ! g_signal_connect (G_OBJECT (select), "changed", ! G_CALLBACK (changed_dir), ! NULL); ! gtk_paned_add1(GTK_PANED(paneRoot), scroll); ! gtk_widget_set_size_request(scroll, 220, -1); ! // Setup the icon panel ! tblMain = iconviewer_new(); ! scroll = gtk_scrolled_window_new(NULL, NULL); ! gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); ! gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tblMain); ! iv = tblMain; ! gtk_widget_show_all(tblMain); ! gtk_paned_add2(GTK_PANED(paneRoot), scroll); ! gtk_widget_set_size_request(tree, 220, -1); ! return wndMain; } --- 43,67 ---- filename = tmp; printf("You've selected %s\n", filename); ! // iconviewer_refresh(iv, filename); g_free(filename); } } ! void set_panel_path(gchar *base) { ! base_path = g_strdup(base); ! } ! gchar *get_panel_path() { ! return base_path; ! } ! void free_panel_path() { ! g_free(base_path); ! } ! ! void control_panel_new(gchar* base) ! { ! set_panel_path(base); ! gtk_widget_show(MainWindow); } *************** *** 97,102 **** dir = g_strdup(dir_str); ! gtk_widget_show_all(control_panel_new(dir_str)); } --- 75,147 ---- dir = g_strdup(dir_str); ! control_panel_new(dir_str); } + + void + on_MainWindow_show (GtkWidget *widget, + gpointer user_data) + { + GtkWidget *da = lookup_widget(MainWindow,"MainDrawingArea"); + iv_add(get_panel_path(),da); + } + + + gboolean + on_MainDrawingArea_button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) + { + iv_button_press_callback(widget,event,user_data); + iv_redraw(widget); + return FALSE; + } + + + gboolean + on_MainDrawingArea_expose_event (GtkWidget *widget, + GdkEventExpose *event, + gpointer user_data) + { + guchar *pixels; + int rowstride; + int width, height; + gtk_window_get_size(GTK_WINDOW(MainWindow),&width,&height); + GdkPixbuf *image = iv_get_image(); + if (image == NULL) + return FALSE; + + rowstride = gdk_pixbuf_get_rowstride(image); + pixels = gdk_pixbuf_get_pixels (image) + rowstride * event->area.y + + event->area.x * 3; + gdk_draw_rgb_image_dithalign (widget->window, + widget->style->black_gc, + event->area.x, event->area.y, + event->area.width, event->area.height, + GDK_RGB_DITHER_NORMAL,pixels,rowstride,0,0); + + return FALSE; + } + + gboolean + on_MainDrawingArea_key_press_event (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data) {} + + + gboolean + on_MainWindow_configure_event (GtkWidget *widget, + GdkEventConfigure *event, + gpointer user_data) + { + /* printf("Configure event! old_width: %d old_height: %d new_width: %d new height: %d\n", + iv_get_width(),iv_get_height(),event->width,event->height); */ + if (event->width != iv_get_width() || event->height != iv_get_height()) { + GtkWidget *da = lookup_widget(MainWindow,"MainDrawingArea"); + /* printf("Redrawing iconviewer after configure event\n"); */ + iv_redraw(da); + } + return FALSE; + } + Index: callbacks.h =================================================================== RCS file: /cvsroot/morphix/mcp/src/callbacks.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** callbacks.h 5 Sep 2003 12:16:16 -0000 1.3 --- callbacks.h 2 Mar 2004 17:09:11 -0000 1.4 *************** *** 1,5 **** #include <gtk/gtk.h> ! GtkWidget* control_panel_new(gchar* base_dir); void --- 1,5 ---- #include <gtk/gtk.h> ! void control_panel_new(gchar* base_dir); void *************** *** 12,63 **** gpointer user_data); - void - on_drawingarea1_drag_begin (GtkWidget *widget, - GdkDragContext *drag_context, - gpointer user_data); - - void - on_drawingarea1_drag_end (GtkWidget *widget, - GdkDragContext *drag_context, - gpointer user_data); - gboolean ! on_drawingarea1_drag_drop (GtkWidget *widget, ! GdkDragContext *drag_context, ! gint x, ! gint y, ! guint time, gpointer user_data); gboolean ! on_drawingarea1_drag_motion (GtkWidget *widget, ! GdkDragContext *drag_context, ! gint x, ! gint y, ! guint time, gpointer user_data); void ! on_drawingarea1_drag_leave (GtkWidget *widget, ! GdkDragContext *drag_context, ! guint time, gpointer user_data); gboolean ! on_drawingarea1_key_press_event (GtkWidget *widget, ! GdkEventKey *event, gpointer user_data); ! void ! on_drawingarea1_show (GtkWidget *widget, gpointer user_data); gboolean ! on_drawingarea1_button_release_event (GtkWidget *widget, ! GdkEventButton *event, gpointer user_data); - gboolean ! on_MainDrawingArea_expose_event (GtkWidget *widget, ! GdkEventExpose *event, gpointer user_data); --- 12,45 ---- gpointer user_data); gboolean ! on_drawingarea1_key_press_event (GtkWidget *widget, ! GdkEventKey *event, gpointer user_data); gboolean ! on_MainDrawingArea_expose_event (GtkWidget *widget, ! GdkEventExpose *event, gpointer user_data); void ! on_MainWindow_show (GtkWidget *widget, gpointer user_data); gboolean ! on_MainDrawingArea_button_press_event (GtkWidget *widget, ! GdkEventButton *event, gpointer user_data); ! gboolean ! on_MainDrawingArea_expose_event (GtkWidget *widget, ! GdkEventExpose *event, gpointer user_data); gboolean ! on_MainDrawingArea_key_press_event (GtkWidget *widget, ! GdkEventKey *event, gpointer user_data); gboolean ! on_MainWindow_configure_event (GtkWidget *widget, ! GdkEventConfigure *event, gpointer user_data); Index: dirtree.c =================================================================== RCS file: /cvsroot/morphix/mcp/src/dirtree.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dirtree.c 7 Sep 2003 13:27:24 -0000 1.6 --- dirtree.c 2 Mar 2004 17:09:11 -0000 1.7 *************** *** 118,122 **** } else { //TODO: error details ! tmp = find_icon(icon); g_free(icon); icon = tmp; --- 118,122 ---- } else { //TODO: error details ! tmp = iv_find_icon(icon); g_free(icon); icon = tmp; Index: iconviewer.c =================================================================== RCS file: /cvsroot/morphix/mcp/src/iconviewer.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** iconviewer.c 7 Sep 2003 13:27:24 -0000 1.4 --- iconviewer.c 2 Mar 2004 17:09:11 -0000 1.5 *************** *** 9,40 **** #include <string.h> #include <stdlib.h> typedef struct { ! // GdkPixbuf *pixbuf; ! // gint boxx; ! // gint boxy; ! // gint boxwidth; ! // gint boxheight; gchar *command; gchar *name; - // gint namex; - // gint namey; - // gint namexmax; gchar *tip; gchar *iconpath; - // gint iconx; - // gint icony; - // gint iconwidth; - // gint iconheight; } item_struct; ! void icon_item_free(item_struct *item) ! { ! if(item) { ! if(item->name) g_free(item->name); ! if(item->tip) g_free(item->tip); ! if(item->command) g_free(item->command); ! if(item->iconpath) g_free(item->iconpath); ! g_free(item); ! } } --- 9,46 ---- #include <string.h> #include <stdlib.h> + typedef struct { ! GdkPixbuf *pixbuf; ! gboolean selected; gchar *command; gchar *name; gchar *tip; gchar *iconpath; } item_struct; ! extern GtkWidget *MainWindow; ! ! /* globals */ ! GList *items; ! int iconviewer_height; ! int iconviewer_width; ! ! #define MAX_ICON_WIDTH 32 ! #define MAX_ICON_HEIGHT 32 ! ! GdkPixbuf *image; ! ! /* GDK_WINDOW coord helpers */ ! int top_border = 5; ! int side_border = 5; ! int box_width = 120; ! int box_height = 84; ! int icon_width = MAX_ICON_WIDTH; ! int icon_height = MAX_ICON_HEIGHT; ! int icon_from_top = 0; ! int text_from_top = 20; ! ! GdkPixbuf *iv_get_image() { ! return image; } *************** *** 48,51 **** --- 54,67 ---- } + void icon_item_free(item_struct *item) + { + if(item) { + if(item->name) g_free(item->name); + if(item->tip) g_free(item->tip); + if(item->command) g_free(item->command); + if(item->iconpath) g_free(item->iconpath); + g_free(item); + } + } void on_icon_click(GtkButton *button, gpointer user_data) *************** *** 60,86 **** } ! ! GtkWidget* icon_new(item_struct *item) { ! GtkWidget *eb, *vb, *lbl, *img; ! GtkTooltips *tooltips = gtk_tooltips_new (); ! GnomeDesktopFile *icon; ! gchar *file; ! ! eb = gtk_button_new(); ! gtk_tooltips_set_tip (tooltips, eb, item->tip, NULL); ! ! vb = gtk_vbox_new(FALSE, 2); ! lbl = gtk_label_new(item->name); ! img = gtk_image_new_from_file(item->iconpath); ! ! gtk_box_pack_start_defaults(GTK_BOX(vb), img); ! gtk_box_pack_start_defaults(GTK_BOX(vb), lbl); ! ! g_signal_connect((gpointer) eb, "clicked", G_CALLBACK(on_icon_click), NULL); ! g_object_set_data(G_OBJECT(eb), "command", g_strdup(item->command)); ! gtk_container_add(GTK_CONTAINER(eb), vb); ! gtk_button_set_relief(GTK_BUTTON(eb), GTK_RELIEF_NONE); ! ! return eb; } --- 76,92 ---- } ! item_struct* icon_copy(item_struct *item) { ! item_struct *newitem; ! newitem = g_malloc0(sizeof(item_struct)); ! newitem->name = g_strdup(item->name); ! newitem->tip = g_strup(item->tip); ! newitem->iconpath = g_strdup(item->iconpath); ! newitem->command = g_strdup(item->command); ! if (item->selected == TRUE) ! newitem->selected = TRUE; ! //if (item->pixbuf != NULL) ! // hmm ! //newitem->pixbuf = g_object_copy(item->pixbuf); ! return newitem; } *************** *** 90,94 **** * @post: ret != NULL */ ! gchar *find_icon(gchar *iconpath) { FILE *f; --- 96,100 ---- * @post: ret != NULL */ ! gchar *iv_find_icon(gchar *iconpath) { FILE *f; *************** *** 102,105 **** --- 108,112 ---- // but it's the way it works with gnome (and in kde too, i guess) list = g_list_append(NULL, g_strdup("/usr/share/icons/Default/48x48/apps/")); + list = g_list_append(list, g_strdup("/usr/share/icons/")); list = g_list_append(list, g_strdup("/usr/share/icons/hicolor/48x48/apps/")); list = g_list_append(list, g_strdup("/usr/share/pixmaps/")); *************** *** 131,134 **** --- 138,144 ---- } + /* + read files in the path, return as a list of items + */ GList* get_items(gchar *dir_str) *************** *** 137,141 **** char *file, *val = NULL, *tmp = NULL; - GList *list = NULL; item_struct *item; --- 147,150 ---- *************** *** 150,154 **** df = gnome_desktop_file_load(file, NULL); if (df != NULL) { ! item = (item_struct *) g_malloc(sizeof(item_struct)); gnome_desktop_file_get_string(df, "Desktop Entry", "Name", &val); item->name = val; --- 159,163 ---- df = gnome_desktop_file_load(file, NULL); if (df != NULL) { ! item = (item_struct *) g_malloc0(sizeof(item_struct)); gnome_desktop_file_get_string(df, "Desktop Entry", "Name", &val); item->name = val; *************** *** 158,162 **** item->command = val; if(gnome_desktop_file_get_string(df, "Desktop Entry", "Icon", &val)) { ! tmp = find_icon(val); g_free(val); item->iconpath = tmp; --- 167,171 ---- item->command = val; if(gnome_desktop_file_get_string(df, "Desktop Entry", "Icon", &val)) { ! tmp = iv_find_icon(val); g_free(val); item->iconpath = tmp; *************** *** 171,175 **** } else { // add new item to the list ! list = g_list_append(list, icon_new(item)); } icon_item_free(item); --- 180,184 ---- } else { // add new item to the list ! list = g_list_append(list, icon_copy(item)); } icon_item_free(item); *************** *** 184,242 **** } ! void iconviewer_clear(GtkWidget *iconviewer) { ! GList *entry = gtk_container_get_children(GTK_CONTAINER(iconviewer)); ! GtkWidget *widget; ! while( entry != NULL) { ! widget = GTK_WIDGET(entry->data); ! // remove and free the resources ! gtk_container_remove(GTK_CONTAINER(iconviewer), widget); ! // remove allocated command string ! g_free(g_object_get_data(G_OBJECT(widget), "command")); ! gtk_widget_destroy(widget); ! ! entry = entry->next; ! } ! g_list_free(entry); } ! void iconviewer_refresh(GtkWidget *iconviewer, gchar* newbase) ! { ! GList *entry; ! GtkWidget *widget; ! int icon_count, max_row, x, y; ! iconviewer_clear(iconviewer); ! // get the list of icons ! entry = get_items(newbase); ! icon_count = g_list_length(entry); ! max_row = (int) sqrt(icon_count); ! if(icon_count - max_row * max_row) ! max_row++; ! ! if(max_row) { ! gtk_table_resize (GTK_TABLE(iconviewer), max_row , max_row); ! for(x = 0; x < max_row; x++) { ! for(y = 0; y < max_row; y++) { ! widget = GTK_WIDGET(entry->data); ! gtk_table_attach_defaults (GTK_TABLE (iconviewer), widget, y, y + 1, x, x + 1); ! entry = entry->next; ! if(entry == NULL) break; ! } ! if(entry == NULL) break; } ! gtk_widget_show_all(iconviewer); } ! } ! GtkWidget* iconviewer_new(void) ! { ! GtkWidget *tblMain; ! tblMain = gtk_table_new (1 , 1, FALSE); ! gtk_container_set_border_width (GTK_CONTAINER (tblMain), 20); ! // iconviewer_refresh(tblMain, base); ! return tblMain; } --- 193,416 ---- } ! gint minimum_width() { ! return 300; // lame } ! /* ! redraw the icons on the drawingarea ! this could use a diagram to clear it up :) ! */ ! void iv_redraw(GtkWidget *da) { ! ! int nr_x = 0; ! int nr_y = 0; ! int i, width, height; ! ! PangoContext *context; ! PangoLayout *layout; ! PangoFontDescription *fontd; ! PangoAttrList *attrlist; ! ! GdkColor colorfg, colorbg; ! GdkPixmap *pixmap; ! colorfg.red = 0; ! colorfg.green = 0; ! colorfg.blue = 0; ! colorbg.red = 65535; ! colorbg.green = 65535; ! colorbg.blue = 65535; ! ! attrlist = pango_attr_list_new(); ! /* Thanks to chen shengqi for noting this in gtk-app-devel */ ! context = gtk_widget_get_pango_context(da); ! fontd = pango_font_description_from_string("8"); ! gtk_window_get_size(GTK_WINDOW(MainWindow),&width,&height); ! iv_set_width(width); ! iv_set_height(height); ! // gdk_window_get_geometry(da,NULL,NULL,&width,&height,NULL); ! ! pixmap = gdk_pixmap_new(da->window,width,height,-1); ! ! gtk_widget_modify_fg(da,GTK_STATE_NORMAL,&colorfg); ! gtk_widget_modify_bg(da,GTK_STATE_NORMAL,&colorbg); ! ! gdk_draw_rectangle(pixmap,da->style->bg_gc[GTK_WIDGET_STATE(da)],TRUE,0,0,width,height); ! GList *ptr = items; ! while (ptr != NULL) { ! item_struct *item = (item_struct *)ptr->data; ! int x_coord = side_border + (nr_x * box_width + nr_x * side_border); ! int y_coord = top_border + (nr_y * box_height + nr_y * top_border); ! gchar buf[128]; ! if (x_coord + side_border * 2 + box_width > width) { ! nr_x = 0; ! nr_y++; ! } ! x_coord = side_border + (nr_x * box_width + nr_x * side_border); ! y_coord = top_border + (nr_y * box_height + nr_y * top_border); ! ! layout = pango_layout_new(context); ! sprintf(buf,"<span foreground=\"black\">%127s</span>",item->name); ! pango_layout_set_markup(layout,buf,-1); ! pango_layout_set_font_description(layout,fontd); ! pango_layout_set_alignment(layout,PANGO_ALIGN_CENTER); ! pango_layout_set_wrap(layout,PANGO_WRAP_WORD); ! pango_layout_set_width(layout,box_width); ! pango_layout_set_justify(layout,TRUE); ! //pango_layout_set_spacing(layout,0); ! if (item->selected == TRUE) { ! GdkColor color; ! color.red = 16896; ! color.blue = 44288; ! color.green = 25856; ! int circle_width = 30; ! gtk_widget_modify_fg(da,GTK_STATE_NORMAL,&color); ! /* top right */ ! gdk_draw_arc(pixmap,da->style->fg_gc[GTK_WIDGET_STATE (da)],TRUE,x_coord + box_width - circle_width,y_coord + text_from_top + circle_width / 2,circle_width,circle_width,64 * 0,64 * 90); ! /* bottom left */ ! gdk_draw_arc(pixmap,da->style->fg_gc[GTK_WIDGET_STATE (da)],TRUE,x_coord,y_coord + box_height - circle_width,circle_width,circle_width,64 * 180,64 * 90); ! /* bottom right */ ! gdk_draw_arc(pixmap,da->style->fg_gc[GTK_WIDGET_STATE (da)],TRUE,x_coord + box_width - circle_width,y_coord + box_height - circle_width,circle_width,circle_width,64 * 270,64 * 90); ! /* top left */ ! gdk_draw_arc(pixmap,da->style->fg_gc[GTK_WIDGET_STATE (da)],TRUE,x_coord,y_coord + text_from_top + circle_width / 2,circle_width,circle_width,64 * 90,64 * 90); ! /* center */ ! gdk_draw_rectangle(pixmap,da->style->fg_gc[GTK_WIDGET_STATE (da)],TRUE,x_coord,y_coord + text_from_top + circle_width,box_width,box_height - text_from_top - circle_width - circle_width / 2); ! /* top */ ! gdk_draw_rectangle(pixmap,da->style->fg_gc[GTK_WIDGET_STATE (da)],TRUE,x_coord + circle_width / 2,y_coord + text_from_top + circle_width / 2,box_width - circle_width,circle_width / 2); ! /* bottom */ ! gdk_draw_rectangle(pixmap,da->style->fg_gc[GTK_WIDGET_STATE (da)],TRUE,x_coord + circle_width / 2,y_coord + box_height - circle_width / 2,box_width - circle_width, circle_width / 2); } + else { + gtk_widget_modify_fg(da,GTK_STATE_NORMAL,&colorfg); + } + + printf("layout width: %d\n",pango_layout_get_width(layout)); + gdk_draw_pixbuf(pixmap,NULL,item->pixbuf,0,0,x_coord + (box_width - icon_width) / 2,y_coord + icon_from_top,-1,-1,GDK_RGB_DITHER_NORMAL,0,0); ! gdk_draw_layout(pixmap,da->style->fg_gc[GTK_WIDGET_STATE (da)],x_coord+box_width / 2,y_coord+text_from_top,layout); ! ! nr_x++; ! ptr = ptr->next; ! /* Looks scary, but it seems to work... */ } ! image = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0,0,0,0,width,height); ! gdk_draw_drawable(da->window,gdk_gc_new(pixmap),pixmap,0,0,0,0,width,height); } ! /* ! returns or sets the allocatable size of the widget ! */ ! ! int iv_get_width() { return iconviewer_width; } ! int iv_get_height() { return iconviewer_height; } ! void iv_set_width(int width) { iconviewer_width = width; } ! void iv_set_height(int height) { iconviewer_height = height; } ! ! /* ! open the directory, and draw the icons in the drawingarea ! */ ! ! void iv_add(gchar *pathname, GtkWidget *drawingarea) { ! gint i; ! GList *item_list = NULL; ! item_struct *item = NULL; ! GError *error = NULL; ! item_list = get_items(pathname); ! if (item_list == NULL) ! return; ! GList *ptr = item_list; ! while (ptr != NULL) { ! item = (item_struct *)ptr->data; ! if (item->iconpath == NULL) { ! fprintf(stderr,"Pixbuf path not set!\n"); ! return; ! } ! GdkPixbuf *pix = gdk_pixbuf_new_from_file (item->iconpath,&error); ! if (pix == NULL) { ! fprintf(stderr,"Couldn't find icon %s\n",item->iconpath); ! } ! else { ! if (gdk_pixbuf_get_width(pix) > MAX_ICON_WIDTH || gdk_pixbuf_get_height(pix) > MAX_ICON_HEIGHT) { ! pix = gdk_pixbuf_scale_simple(pix,MAX_ICON_WIDTH,MAX_ICON_HEIGHT,GDK_INTERP_BILINEAR); ! } ! } ! item->pixbuf = pix; ! ptr = ptr->next; ! } ! items = item_list; ! ! gtk_widget_realize(drawingarea); ! iv_redraw(drawingarea); ! gtk_widget_add_events(drawingarea,GDK_BUTTON_PRESS_MASK); ! return; } + /* + set the message of the statusbar + */ + + void set_statusbar(gchar *str) { + GtkWidget *status = lookup_widget(MainWindow,"statusbar1"); + if (status) { + gtk_statusbar_pop(GTK_STATUSBAR(status),0); + gtk_statusbar_push(GTK_STATUSBAR(status),gtk_statusbar_get_context_id(GTK_STATUSBAR(status),str),str); + } + } + void iv_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer data) { + if (event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS) { + GtkWidget *drawingarea = lookup_widget(MainWindow,"MainDrawingArea"); + + gint width, height; + gdk_window_get_geometry(drawingarea->window,NULL,NULL,&width,&height,NULL); + + gint i; + int nr_x = 0; + int nr_y = 0; + + GList *ptr = items; + while (ptr != NULL) { + item_struct *item = (item_struct *)ptr->data; + item->selected = FALSE; + ptr = ptr->next; + } + ptr = items; + while (ptr != NULL) { + item_struct *item = (item_struct *)ptr->data; + int x_coord = side_border + (nr_x * box_width + nr_x * side_border); + int y_coord = top_border + (nr_y * box_height + nr_y * top_border); + + if (x_coord + side_border * 2 + box_width > width) { + nr_x = 0; + nr_y++; + } + x_coord = side_border + (nr_x * box_width + nr_x * side_border); + y_coord = top_border + (nr_y * box_height + nr_y * top_border); + + if (event->x > x_coord && + event->x < x_coord + box_width && + event->y > y_coord && + event->y < y_coord + box_height) { + if (event->type == GDK_2BUTTON_PRESS) { + + gchar *string = g_strdup_printf("Starting: %s",item->command); + set_statusbar(string); + g_free(string); + + if (!ExecuteAsyncCommand(item->command)) { + string = g_strdup_printf("%s could not be executed"); + set_statusbar(string); + g_free(string); + } + } + else { + item->selected = TRUE; + } + break; + } + + nr_x++; + ptr = ptr->next; + } + } + } Index: iconviewer.h =================================================================== RCS file: /cvsroot/morphix/mcp/src/iconviewer.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** iconviewer.h 7 Sep 2003 13:27:24 -0000 1.3 --- iconviewer.h 2 Mar 2004 17:09:11 -0000 1.4 *************** *** 1,4 **** #include <gtk/gtk.h> ! void iconviewer_refresh(GtkWidget *iconviewer, gchar* newbase); ! GtkWidget* iconviewer_new(void); ! gchar *find_icon(gchar *iconpath); --- 1,15 ---- + #ifndef ICONVIEWER_H + #define ICONVIEWER_H #include <gtk/gtk.h> ! GdkPixbuf *iv_get_image(); ! void iv_redraw(GtkWidget *da); ! void iv_add(gchar *pathname, GtkWidget *da); ! gchar *iv_find_icon(gchar *iconpath); ! ! int iv_get_width(); ! int iv_get_height(); ! void iv_set_width(int width); ! void iv_set_height(int height); ! ! void iv_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer data); ! #endif // ICONVIEWER_H Index: main.c =================================================================== RCS file: /cvsroot/morphix/mcp/src/main.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** main.c 3 Sep 2003 00:52:24 -0000 1.4 --- main.c 2 Mar 2004 17:09:11 -0000 1.5 *************** *** 1,7 **** - /* - * Initial main.c file generated by Glade. Edit as required. - * Glade will not overwrite this file. - */ - #ifdef HAVE_CONFIG_H # include <config.h> --- 1,2 ---- *************** *** 9,13 **** #include <gtk/gtk.h> ! #include "callbacks.h" #include "support.h" --- 4,8 ---- #include <gtk/gtk.h> ! #include "interface.h" #include "callbacks.h" #include "support.h" *************** *** 29,37 **** add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); ! /* ! * The following code was added by Glade to create one of each component ! * (except popup menus), just so that you see something after building ! * the project. Delete any components that you don't want shown initially. ! */ if (argc == 2) { load_control_panel(argv[1]); --- 24,28 ---- add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); ! MainWindow = create_MainWindow(); if (argc == 2) { load_control_panel(argv[1]); *************** *** 40,43 **** --- 31,35 ---- load_control_panel("./"); } + gtk_widget_show(MainWindow); gtk_main (); return 0; |