Пример #1
0
/* This replaces the file list widget with another one made specifically
 * to monitor the progress of an impending scan */
void
filelist_scan_monitor_init( void )
{
	char *col_titles[3];
	char *empty_row[3] = { NULL, NULL, NULL };
	GtkWidget *parent_w;
	Icon *icon;
	int i;

	col_titles[0] = _("Type");
	col_titles[1] = _("Found");
	col_titles[2] = _("Bytes");

	/* Replace current clist widget with a 3-column one */
	parent_w = file_clist_w->parent->parent;
	gtk_widget_destroy( file_clist_w->parent );
	file_clist_w = gui_clist_add( parent_w, 3, col_titles );

	/* Place icons and static text */
	for (i = 1; i <= NUM_NODE_TYPES; i++) {
		gtk_clist_append( GTK_CLIST(file_clist_w), empty_row );
		if (i < NUM_NODE_TYPES) {
			icon = &node_type_mini_icons[i];
			gtk_clist_set_pixtext( GTK_CLIST(file_clist_w), i - 1, 0, _(node_type_plural_names[i]), 2, icon->pixmap, icon->mask );
		}
		else
                        gtk_clist_set_text( GTK_CLIST(file_clist_w), i - 1, 0, _("TOTAL") );
		gtk_clist_set_selectable( GTK_CLIST(file_clist_w), i - 1, FALSE );
	}
}
Пример #2
0
static GtkWidget* generate_credit_list(const char *text[], gboolean sec_space)
{
	GtkWidget *clist, *scrollwin;
	int i = 0;

	clist = gtk_clist_new(2);

	while (text[i])
	{
		gchar *temp[2];
		guint row;
		
		temp[0] = gettext(text[i++]);
		temp[1] = gettext(text[i++]);
		row = gtk_clist_append(GTK_CLIST(clist), temp);
		gtk_clist_set_selectable(GTK_CLIST(clist), row, FALSE);
		temp[0] = "";
		while (text[i])
		{
			temp[1] = gettext(text[i++]);
			row = gtk_clist_append(GTK_CLIST(clist), temp);
			gtk_clist_set_selectable(GTK_CLIST(clist), row, FALSE);
		}
		i++;
		if (text[i] && sec_space)
		{
			temp[1] = "";
			row = gtk_clist_append(GTK_CLIST(clist), temp);
			gtk_clist_set_selectable(GTK_CLIST(clist), row, FALSE);
		}
	}
	gtk_clist_columns_autosize(GTK_CLIST(clist));
	gtk_clist_set_column_justification(GTK_CLIST(clist), 0, GTK_JUSTIFY_RIGHT);
	
	scrollwin = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
				       GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
	gtk_container_add(GTK_CONTAINER(scrollwin), clist);
	gtk_container_set_border_width(GTK_CONTAINER(scrollwin), 10);
	gtk_widget_set_usize(scrollwin, -1, 120);

	return scrollwin;
}
Пример #3
0
void
hcache_gui_init(void)
{
    GtkCList *clist;
    const gchar *titles[5];
    guint i;

    for (i = 0; i < G_N_ELEMENTS(titles); i++) {
        titles[i] = "-";
	}
    clist = GTK_CLIST(gui_main_window_lookup("clist_hcache"));

    /*
     * Stats can't be sorted: make column headers insensitive.
     */
	gtk_clist_column_titles_passive(clist);

    /*
     * Initialize stats tables.
     */
    for (i = 0; i < HCACHE_MAX; i++) {
        gint row;

		if (i == HCACHE_NONE)
			continue;

        titles[0] = get_hcache_name(i);

	/* Override const */
        row = gtk_clist_append(clist, (gchar **) titles);
        gtk_clist_set_selectable(clist, row, FALSE);
    }

    for (i = 1; i < 4; i++) {
        gtk_clist_set_column_justification(clist, i, GTK_JUSTIFY_RIGHT);
    }
	clist_restore_widths(clist, PROP_HCACHE_COL_WIDTHS);
	main_gui_add_timer(hcache_gui_timer);
}
Пример #4
0
static GtkWidget*
make_contents(history_calendar_dlg *hcdlg) {
	GtkWidget *vbox, *button, *scrollwin;
	gchar *titles[] = { "Time", "Event" };

	button = gtk_button_new();
	hcdlg->daylabel = gtk_label_new("");
	g_signal_connect(G_OBJECT(button), "clicked",
			G_CALLBACK(popup_calendar), hcdlg);
	gtk_container_add(GTK_CONTAINER(button), hcdlg->daylabel);

	scrollwin = gtk_scrolled_window_new (NULL, NULL); 
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
		(scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	hcdlg->evlist = gtk_clist_new_with_titles(2, titles);
	gtk_clist_set_selection_mode(GTK_CLIST(hcdlg->evlist),
			GTK_SELECTION_BROWSE);
	g_signal_connect(G_OBJECT(hcdlg->evlist), "select-row", 
			G_CALLBACK(hc_row_selected), hcdlg);
	g_signal_connect(G_OBJECT(hcdlg->evlist), "unselect-row", 
			G_CALLBACK(hc_row_selected), hcdlg);
	g_signal_connect(G_OBJECT(hcdlg->evlist), "button_press_event",
			G_CALLBACK(hc_list_click_cb), hcdlg);
	gtk_clist_column_titles_passive(GTK_CLIST(hcdlg->evlist));
	/* fixme gtk2 gtk_clist_set_column_width(GTK_CLIST(hcdlg->evlist), 0, 
			gdk_string_width(hcdlg->evlist->style->font, "00:00a"));*/
	titles[0] = NULL;
	titles[1] = "[select a day]";
	gtk_clist_append(GTK_CLIST(hcdlg->evlist), titles);
	gtk_clist_set_selectable(GTK_CLIST(hcdlg->evlist), 0, FALSE);
	gtk_container_add(GTK_CONTAINER(scrollwin), hcdlg->evlist);

	vbox = gtk_vbox_new(FALSE, 5); 
	gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), scrollwin, TRUE, TRUE, 0);
	return vbox;
}
Пример #5
0
static void
change_day(history_calendar_dlg *hcdlg) {
	int count, i, itemid;
	char key[50];
	char *str, *event;
	int hour, minute;
	gint row;
	char *append[2];

	NetRequest *request;
	NetResult  *result;
	
	if (hcdlg->firstyear == 0) return; /* this can happen if they cancelled the getdaycounts */

	request = XXX("getevents");

	net_request_seti(request,  "truncate",      50);
	net_request_seti(request,  "prefersubject", 1);
	net_request_seti(request,  "noprops",       1);
	net_request_copys(request, "selecttype",    "day");
	net_request_copys(request, "lineendings",   "dots");

	net_request_seti(request, "year", hcdlg->year);
	net_request_seti(request, "month", hcdlg->mon);
	net_request_seti(request, "day", hcdlg->day);

	result = net_request_run(hcdlg->win, "Loading day calendar...", request);
	net_request_free(request);

	if (!net_result_succeeded(result)) {
		net_result_free(result);
		return;
	}

	/* it would have been better if net_result_geti used a GError */
	str = net_result_get(result, "events_count");
	if (str == NULL) return;
	count = atoi(str);

	if (count == 0) {
		/* FIXME? no events this day; whoops.  can happen if they delete. */
		MARKMONTH_CUR(hcdlg) &= ~(1L << hcdlg->day);
		gtk_clist_clear(GTK_CLIST(hcdlg->evlist));
		append[0] = "";
		append[1] = "[no events]";
		gtk_clist_append(GTK_CLIST(hcdlg->evlist), append);
		gtk_clist_set_selectable(GTK_CLIST(hcdlg->evlist), 0, FALSE);
		net_result_free(result);
		return;
	}

	gtk_clist_freeze(GTK_CLIST(hcdlg->evlist));
	gtk_clist_clear(GTK_CLIST(hcdlg->evlist));

	for (i = 1; i < count+1; i++) {
		sprintf(key, "events_%d_event", i);
		event = net_result_get(result, key);

		sprintf(key, "events_%d_eventtime", i);
		str = net_result_get(result, key);
		sscanf(str+11, "%2d:%2d", &hour, &minute);

		sprintf(key, "events_%d_itemid", i);
		str = net_result_get(result, key);
		if (str == NULL) continue;
		itemid = atoi(str);

		sprintf(key, "%02d:%02d", hour, minute);
		append[0] = key;
		append[1] = event;
		row = gtk_clist_append(GTK_CLIST(hcdlg->evlist), append);
		gtk_clist_set_row_data(GTK_CLIST(hcdlg->evlist), row, GINT_TO_POINTER(itemid));
	}
	gtk_clist_thaw(GTK_CLIST(hcdlg->evlist));
	gtk_clist_set_column_width(GTK_CLIST(hcdlg->evlist), 0, 
			gtk_clist_optimal_column_width(GTK_CLIST(hcdlg->evlist), 0));

	net_result_free(result);
}
Пример #6
0
void 
ghack_menu_window_add_menu( GtkWidget *menuWin, gpointer menu_item,
			    gpointer data)
{
    GHackMenuItem*  item;
    GtkWidget	    *clist;
    gchar buf[BUFSZ]="", accelBuf[BUFSZ]="";
    gchar *pbuf;
    char *text[4] = { buf, NULL, NULL, NULL };
    gint nCurrentRow = -1, numItems = -1;
    MenuWinType isMenu;
    GtkStyle *bigStyle = NULL;
    gboolean item_selectable;
    GdkImlibImage* image;
    static gboolean special;

    g_assert (menu_item != NULL);
    item = (GHackMenuItem*) menu_item;
    item_selectable = ( item->identifier->a_int == 0)? FALSE : TRUE;
    isMenu = (MenuWinType) GPOINTER_TO_INT
    	(gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu"));

    clist = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (menuWin), "clist"));
    g_assert (clist != NULL);
    /* This is a special kludge to make the special hidden help menu item work as designed */ 
    if ( special==TRUE ) {
	special=FALSE;
	item_selectable=TRUE;
    }
    if ( ! strcmp( item->str, "The NetHack license.")) {
	special=TRUE;
    }
    
    if (item->str) {

	/* First, make a new blank entry in the clist */
	nCurrentRow = gtk_clist_append (GTK_CLIST (clist), text);

	if (item->glyph != NO_GLYPH) {
	    image = ghack_image_from_glyph( item->glyph, FALSE);
	    if (image==NULL || image->pixmap==NULL) {
		g_warning("Bummer -- having to force rendering for glyph %d!", item->glyph);
		/* wierd -- pixmap is NULL so retry rendering it */
		image = ghack_image_from_glyph( item->glyph, TRUE);
	    }
	    if (image==NULL || image->pixmap==NULL) {
		    g_error("Aiiee! glyph is still NULL for item\n\"%s\"", 
			    item->str);
	    }
	    else 
		gtk_clist_set_pixmap (GTK_CLIST (clist), 
			nCurrentRow, 1, 
			gdk_imlib_move_image( image), 
			gdk_imlib_move_mask( image));
	}
	if (item->accelerator) {
	    /* FIXME: handle accelerator, */
	    g_snprintf(accelBuf, sizeof(accelBuf), "%c ", item->accelerator);
	    gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 0, accelBuf);
	    g_snprintf(buf, sizeof(buf), "%s", item->str);
	    gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf);
	} else {
	    if (item->group_accel) {
		/* FIXME: maybe some day I should try to handle 
		 * group accelerators... */
	    }
	    if (( (item->attr == 0) && (item->identifier->a_int != 0)) || (special ==TRUE) ) {
		numItems = GPOINTER_TO_INT( gtk_object_get_data(
			    GTK_OBJECT(clist), "numItems") )+1;

		/* Ok, now invent a unique accelerator */
		if (  ('a'+numItems) <= 'z' ) {
		    g_snprintf(accelBuf, sizeof(accelBuf), "%c ", 'a'+numItems);
		    gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf);
		}
		else if ( ('A'+numItems-26)<='Z') {
		    g_snprintf(accelBuf, sizeof(accelBuf), "%c ", 'A'+numItems-26); 
		    gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf);
		} else {
		    accelBuf[0] = buf[0] = 0;
		}
		g_snprintf(buf, sizeof(buf), "%s", item->str);
		gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf);
		gtk_object_set_data (GTK_OBJECT (clist), "numItems",
					GINT_TO_POINTER (numItems));

		/* This junk is to specially handle the options menu */
		pbuf = strstr( buf, " [");
		if (pbuf == NULL) {
		    pbuf = strstr( buf, "\t[");
		}
		if (pbuf != NULL) {
		    *pbuf=0;
		    pbuf++;
		    gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 3, pbuf);
		}
	    }
	    /* FIXME: handle more than 26*2 accelerators (but how?
	     * since I only have so many keys to work with???)
	    else
	    {
		foo();
	    }
	    */
	    else {
		g_snprintf(buf, sizeof(buf), "%s", item->str);
		pbuf = strstr( buf, " [");
		if (pbuf == NULL) {
		    pbuf = strstr( buf, "\t[");
		}
		if (pbuf != NULL) {
		    *pbuf=0;
		    pbuf++;
		    gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 3, pbuf);
		}
		gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf);
		
	    }
	}

	if (item->attr) {
	    switch(item->attr) {
		case ATR_ULINE:
		case ATR_BOLD:
		case ATR_BLINK:
		case ATR_INVERSE:
		    bigStyle = gtk_style_copy (GTK_WIDGET (clist)->style);
		    g_assert (bigStyle != NULL);
		    gdk_font_unref (bigStyle->font);
		    bigStyle->font = gdk_font_load (
				"-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*");
		    bigStyle->fg[GTK_STATE_NORMAL] = color_blue;
		    gtk_clist_set_cell_style (GTK_CLIST (clist), 
			    nCurrentRow, 2, bigStyle);
		    item_selectable = FALSE;
	    }
	}


	g_assert (nCurrentRow >= 0);
	gtk_clist_set_selectable (GTK_CLIST (clist), nCurrentRow,
			      item_selectable);

	if ( item_selectable==TRUE && item->presel== TRUE) {
	    /* pre-select this item */
	    gtk_clist_select_row( GTK_CLIST (clist), nCurrentRow, 0);
	}
	
	gtk_object_set_data (GTK_OBJECT (clist), "numRows",
		                GINT_TO_POINTER (nCurrentRow));
        
	/* We have to allocate memory here, since the menu_item currently
	 * lives on the stack, and will otherwise go to the great bit bucket 
	 * in the sky as soon as this function exits, which would leave a 
	 * pointer to crap in the row_data.  Use g_memdup to make a private, 
	 * persistant copy of the item identifier.
	 *
	 * We need to arrange to blow away this memory somewhere (like 
	 * ghack_menu_destroy and ghack_menu_window_clear for example).
	 *
	 *  -Erik
	 */
	{
	    menuItem newItem;
	    menuItem *pNewItem;
	    
	    newItem.identifier = *item->identifier;
	    newItem.itemNumber=nCurrentRow;
	    newItem.selected=FALSE;
	    newItem.accelerator[0]=0;
	    /* only copy 1 char, since accel keys are by definition 1 char */
	    if (accelBuf[0]) {
		strncpy(newItem.accelerator, accelBuf, 1);
	    }
	    newItem.accelerator[1]=0;

	    pNewItem = g_memdup(&newItem, sizeof( menuItem));
	    gtk_clist_set_row_data (GTK_CLIST (clist), nCurrentRow,
				    (gpointer) pNewItem);
	}
    }
    /* Now adjust the column widths to match the contents */
    gtk_clist_columns_autosize (GTK_CLIST (clist));
}