Ejemplo n.º 1
0
static void
move_to_left (GtkTreeModel *src,
	      GtkTreeIter  *src_iter,
	      GtkTreeIter  *dest_iter)
{
  GtkTreeIter iter;
  GtkTreeViewColumn *column;
  GtkTreeSelection *selection;
  gchar *label;

  gtk_tree_model_get (src, src_iter, 0, &label, 1, &column, -1);

  if (src == top_right_tree_model)
    gtk_tree_view_remove_column (GTK_TREE_VIEW (sample_tree_view_top), column);
  else
    gtk_tree_view_remove_column (GTK_TREE_VIEW (sample_tree_view_bottom), column);

  /*  gtk_list_store_remove (GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (data))), &iter);*/

  /* Put it back on the left */
  if (dest_iter)
    gtk_list_store_insert_before (GTK_LIST_STORE (left_tree_model),
				  &iter, dest_iter);
  else
    gtk_list_store_append (GTK_LIST_STORE (left_tree_model), &iter);
  
  gtk_list_store_set (GTK_LIST_STORE (left_tree_model), &iter, 0, label, 1, column, -1);
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (left_tree_view));
  gtk_tree_selection_select_iter (selection, &iter);

  g_free (label);
}
Ejemplo n.º 2
0
static void
move_up_or_down (GtkTreeModel *src,
		 GtkTreeIter  *src_iter,
		 GtkTreeModel *dest,
		 GtkTreeIter  *dest_iter)
{
  GtkTreeViewColumn *column;
  gchar *label;
  gint before = -1;
  
  gtk_tree_model_get (src, src_iter, 0, &label, 1, &column, -1);

  if (dest_iter)
    {
      GtkTreePath *path = gtk_tree_model_get_path (dest, dest_iter);
      before = (gtk_tree_path_get_indices (path))[0];
      gtk_tree_path_free (path);
    }
  
  if (src == top_right_tree_model)
    gtk_tree_view_remove_column (GTK_TREE_VIEW (sample_tree_view_top), column);
  else
    gtk_tree_view_remove_column (GTK_TREE_VIEW (sample_tree_view_bottom), column);

  if (dest == top_right_tree_model)
    gtk_tree_view_insert_column (GTK_TREE_VIEW (sample_tree_view_top), column, before);
  else
    gtk_tree_view_insert_column (GTK_TREE_VIEW (sample_tree_view_bottom), column, before);

  g_free (label);
}
Ejemplo n.º 3
0
/*
 * cancel-button of if_window
 */
void on_button_if_cancel_clicked(GtkWidget * gw, GtkTreeView * view)
{
	GtkTreeViewColumn *col;
	col = gtk_tree_view_get_column(view, 0);
	gtk_tree_view_remove_column(view, col);
	// 删除完第1列后,原来的第
	// 2列也成了第一列,所以两个都是删除 0 列
	col = gtk_tree_view_get_column(view, 0);
	gtk_tree_view_remove_column(view, col);

}
Ejemplo n.º 4
0
void tag_apply_open(GSList *msglist)
{
	if (!applywindow.window)
		apply_window_create();

	manage_window_set_transient(GTK_WINDOW(applywindow.window));
	gtk_widget_grab_focus(applywindow.close_btn);
	
	applywindow.msglist = msglist;
	apply_window_load_tags();

	if (msglist && !applywindow.has_tag_col) {
		apply_window_insert_check_column(applywindow.taglist);
		applywindow.has_tag_col = TRUE;
	}
	if (!msglist && applywindow.has_tag_col) {
		gtk_tree_view_remove_column(GTK_TREE_VIEW(applywindow.taglist),
			gtk_tree_view_get_column(GTK_TREE_VIEW(applywindow.taglist), 0));
		applywindow.has_tag_col = FALSE;
	} 

	gtk_widget_show(applywindow.window);
	gtk_widget_grab_focus(applywindow.taglist);
	gtk_window_set_modal(GTK_WINDOW(applywindow.window), TRUE);
}
Ejemplo n.º 5
0
static VALUE
rg_remove_column(VALUE self, VALUE column)
{
    G_CHILD_REMOVE(self, column);
    return INT2NUM(gtk_tree_view_remove_column(_SELF(self), 
                                               TREEVIEW_COL(column)));
}  
Ejemplo n.º 6
0
/*
 * 点击if_window窗口左上角的关闭时
 */
void on_if_window_delete_event(GtkWidget * gw, gpointer data)
{

	GtkTreeView *if_view;
	if_view =
	    GTK_TREE_VIEW(gtk_builder_get_object
			  (builder, "treeview_interface"));

	GtkTreeViewColumn *col;
	col = gtk_tree_view_get_column(if_view, 0);
	gtk_tree_view_remove_column(if_view, col);
	col = gtk_tree_view_get_column(if_view, 0);
	gtk_tree_view_remove_column(if_view, col);

	gtk_widget_hide(gw);
}
Ejemplo n.º 7
0
void
glade_gtk_treeview_replace_child (GladeWidgetAdaptor * adaptor,
                                  GObject * container,
                                  GObject * current, GObject * new_column)
{
  GtkTreeView *view = GTK_TREE_VIEW (container);
  GList *columns;
  GtkTreeViewColumn *column;
  GladeWidget *gcolumn;
  gint index;

  if (!GTK_IS_TREE_VIEW_COLUMN (current))
    return;

  column = GTK_TREE_VIEW_COLUMN (current);

  columns = gtk_tree_view_get_columns (view);
  index = g_list_index (columns, column);
  g_list_free (columns);

  gtk_tree_view_remove_column (view, column);
  column = GTK_TREE_VIEW_COLUMN (new_column);

  gtk_tree_view_insert_column (view, column, index);

  if (gtk_tree_view_get_fixed_height_mode (view))
    {
      gcolumn = glade_widget_get_from_gobject (column);
      glade_widget_property_set (gcolumn, "sizing", GTK_TREE_VIEW_COLUMN_FIXED);
      glade_widget_property_set_sensitive (gcolumn, "sizing", FALSE,
                                           INSENSITIVE_COLUMN_SIZING_MSG);
    }

  glade_gtk_cell_layout_sync_attributes (G_OBJECT (column));
}
Ejemplo n.º 8
0
static void
trg_tree_view_hide_column(GtkWidget * w, GtkTreeViewColumn * col)
{
    trg_column_description *desc = g_object_get_data(G_OBJECT(col),
                                                     GDATA_KEY_COLUMN_DESC);
    GtkWidget *tv = gtk_tree_view_column_get_tree_view(col);
    desc->flags &= ~TRG_COLUMN_SHOWING;
    gtk_tree_view_remove_column(GTK_TREE_VIEW(tv), col);
}
Ejemplo n.º 9
0
void trg_tree_view_remove_all_columns(TrgTreeView * tv)
{
    GtkTreeView *gtv = GTK_TREE_VIEW(tv);
    GList *cols = gtk_tree_view_get_columns(gtv);
    GList *li;
    for (li = cols; li; li = g_list_next(li)) {
        gtk_tree_view_remove_column(gtv, GTK_TREE_VIEW_COLUMN(li->data));
    }
    g_list_free(cols);
}
Ejemplo n.º 10
0
void
glade_gtk_treeview_remove_child (GladeWidgetAdaptor * adaptor,
                                 GObject * container, GObject * child)
{
  GtkTreeView *view = GTK_TREE_VIEW (container);
  GtkTreeViewColumn *column;

  if (!GTK_IS_TREE_VIEW_COLUMN (child))
    return;

  column = GTK_TREE_VIEW_COLUMN (child);
  gtk_tree_view_remove_column (view, column);
}
Ejemplo n.º 11
0
static void
clear_view (GladeEditorProperty * eprop)
{
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GtkTreeViewColumn *column;

  /* Clear columns ... */
  while ((column = gtk_tree_view_get_column (eprop_data->view, 0)) != NULL)
    gtk_tree_view_remove_column (eprop_data->view, column);

  /* Clear store ... (this will unref the old store) */
  gtk_tree_view_set_model (eprop_data->view, NULL);

}
Ejemplo n.º 12
0
Archivo: gui.c Proyecto: hrl/AVL
void _gui_clean_column() {
    /*
     * clean all columns in screen
     *
     * */
    int columns;
    GtkTreeViewColumn *column;
    columns = gtk_tree_view_get_n_columns(treeview);

    while(columns) {
        column = gtk_tree_view_get_column(treeview, 0);
        gtk_tree_view_remove_column(treeview, column);
        columns--;
    }
}
Ejemplo n.º 13
0
static void set_columns(struct search_param *param, int mode)
{
	GList *columns_list,*columns;
	char **column_text=columns_text[mode];
	int i=0;

	columns_list=gtk_tree_view_get_columns(GTK_TREE_VIEW(param->treeview));
	columns=columns_list;
	while (columns) {
		gtk_tree_view_remove_column(GTK_TREE_VIEW(param->treeview), columns->data);
		columns=g_list_next(columns);
	}
	g_list_free(columns_list);
	while (*column_text) {
		GtkCellRenderer *cell=gtk_cell_renderer_text_new();
		gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (param->treeview),-1, gettext(*column_text), cell, "text", i, NULL);
		i++;
		column_text++;
	}

}
Ejemplo n.º 14
0
void
glade_gtk_treeview_set_child_property (GladeWidgetAdaptor * adaptor,
                                       GObject * container,
                                       GObject * child,
                                       const gchar * property_name,
                                       const GValue * value)
{
  if (strcmp (property_name, "position") == 0)
    {

      gtk_tree_view_remove_column (GTK_TREE_VIEW (container),
                                   GTK_TREE_VIEW_COLUMN (child));
      gtk_tree_view_insert_column (GTK_TREE_VIEW (container),
                                   GTK_TREE_VIEW_COLUMN (child),
                                   g_value_get_int (value));
    }
  else
    /* Chain Up */
    GWA_GET_CLASS
        (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
                                                  container, child,
                                                  property_name, value);
}
Ejemplo n.º 15
0
static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_data)
{
  dt_lib_module_t *self = (dt_lib_module_t *)user_data;
  if(!self || !(self->data)) return;

  GtkListStore  *store;
  GtkTreeIter    iter;
  GtkWidget     *view=GTK_WIDGET(((dt_lib_modulelist_t*)self->data)->tree);
  GtkCellRenderer     *pix_renderer,*fav_renderer,*text_renderer;
  GtkStyle *style=gtk_widget_get_style(view);

  store = gtk_list_store_new (NUM_COLS, GDK_TYPE_PIXBUF,  G_TYPE_POINTER);
  gtk_tree_view_set_model (GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
  g_object_unref (store);

  gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_MODULE, _lib_modulelist_gui_sort, NULL, NULL);
  gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_MODULE, GTK_SORT_ASCENDING);

  pix_renderer = gtk_cell_renderer_pixbuf_new ();
  g_object_set(pix_renderer,"cell-background-gdk",&style->bg[GTK_STATE_ACTIVE],NULL);

  fav_renderer = gtk_cell_renderer_pixbuf_new ();
  cairo_surface_t *fav_cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ICON_SIZE, ICON_SIZE);
  cairo_t *fav_cr = cairo_create(fav_cst);
  cairo_set_source_rgb(fav_cr, 0.7,0.7,0.7);
  dtgtk_cairo_paint_modulegroup_favorites(fav_cr, 0, 0, ICON_SIZE, ICON_SIZE, 0);
  guchar* data = cairo_image_surface_get_data(fav_cst);
  dt_draw_cairo_to_gdk_pixbuf(data, ICON_SIZE, ICON_SIZE);
  ((dt_lib_modulelist_t*)self->data)->fav_pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, ICON_SIZE,
    ICON_SIZE, cairo_image_surface_get_stride(fav_cst), NULL, NULL);
  g_object_set(fav_renderer,"cell-background-gdk",&style->bg[GTK_STATE_ACTIVE],NULL);
  g_object_set(fav_renderer,"width",gdk_pixbuf_get_width(((dt_lib_modulelist_t*)self->data)->fav_pixbuf),NULL);

  text_renderer = gtk_cell_renderer_text_new ();
  g_object_set(text_renderer,"cell-background-gdk",&style->bg[GTK_STATE_ACTIVE],NULL);

  gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view),FALSE);
  gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(view),FALSE);
  gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view),FALSE);
  GtkTreeSelection  *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
  gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE);

  GtkTreeViewColumn *col;
  col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 0);
  if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
  gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (view),
                                               0,
                                               "favorite",
                                               fav_renderer,
                                               favorite_renderer_function,
                                               NULL,NULL);
  col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 1);
  if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
  gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (view),
                                               1,
                                               "image",
                                               pix_renderer,
                                               image_renderer_function,
                                               NULL,NULL);
  col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 2);
  if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
  gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (view),
                                               2,
                                               "name",
                                               text_renderer,
                                               text_renderer_function,
                                               NULL,NULL);

  /* go thru list of iop modules and add them to the list */
  GList *modules = g_list_last(darktable.develop->iop);

  while(modules)
  {
    dt_iop_module_t *module = (dt_iop_module_t *)(modules->data);
    if(!dt_iop_is_hidden(module) && !(module->flags() & IOP_FLAGS_DEPRECATED) && module->multi_priority==0)
    {
      char filename[DT_MAX_PATH_LEN], datadir[DT_MAX_PATH_LEN];
      dt_loc_get_datadir(datadir, DT_MAX_PATH_LEN);
      snprintf(filename, DT_MAX_PATH_LEN, "%s/pixmaps/plugins/darkroom/%s.png", datadir, module->op);
      if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
        snprintf(filename, DT_MAX_PATH_LEN, "%s/pixmaps/plugins/darkroom/template.png", datadir);


      GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename,NULL);
      gtk_list_store_append (store, &iter);
      gtk_list_store_set (store, &iter,
          COL_IMAGE, pixbuf,
          COL_MODULE,module,
          -1);
      g_object_unref (pixbuf);
    }

    modules = g_list_previous(modules);
  }

}
Ejemplo n.º 16
0
//-----------------------------------------------------------------------------
void rebuild_sensors_tree(gboolean force_rebuild) 
{
		if (force_rebuild ||
				(GTK_WIDGET_VISIBLE((GtkWidget*)settings_dialog) &&
				 gtk_notebook_get_current_page(settings_notebook) == 1)) 		// FIXME: uwazac na numerki
		{
				//printf("Przebudowa wyswietlacza listy czujnikow\n") ;
				// usun istniejace kolumny
						GList *columns = gtk_tree_view_get_columns(sensors_manage_display_tree) ;
				GList *col = g_list_last(columns) ;
				while (col != NULL) {
						gtk_tree_view_remove_column(sensors_manage_display_tree, col->data) ;
						col = g_list_previous(col) ;
				} ;
				g_list_free(columns) ;
				gtk_tree_view_set_model(sensors_manage_display_tree, NULL) ;		// chyba nadmiar
						
						// utworz model
						GtkListStore *store ;
				store = t_sensor_list_new_store(sensors) ;
				
				gtk_tree_view_set_model(sensors_manage_display_tree, GTK_TREE_MODEL(store)) ;
				
				///////////////////////////////////
						GtkCellRenderer *renderer ;
				GtkTreeViewColumn *column ;
				
				renderer = gtk_cell_renderer_text_new ();
				column = gtk_tree_view_column_new_with_attributes ("Identyfikator",
																													 renderer,
																													 "text", ID,
																													 NULL);
				gtk_tree_view_append_column (GTK_TREE_VIEW (sensors_manage_display_tree), column);
				
				renderer = gtk_cell_renderer_text_new ();
				column = gtk_tree_view_column_new_with_attributes ("Nazwa",
																													 renderer,
																													 "text", NAME,
																													 NULL);
				gtk_tree_view_append_column (GTK_TREE_VIEW (sensors_manage_display_tree), column);
				
				renderer = gtk_cell_renderer_text_new ();
				column = gtk_tree_view_column_new_with_attributes ("Rozdzielczość",
																													 renderer,
																													 "text", RESOLUTION,
																													 NULL);
				gtk_tree_view_append_column (GTK_TREE_VIEW (sensors_manage_display_tree), column);
				
				renderer = gtk_cell_renderer_text_new ();
				column = gtk_tree_view_column_new_with_attributes ("Odświeżanie",
																													 renderer,
																													 "text", REFRESH_TIME,
																													 NULL);
				gtk_tree_view_append_column (GTK_TREE_VIEW (sensors_manage_display_tree), column);
				
				renderer = gtk_cell_renderer_toggle_new ();
				column = gtk_tree_view_column_new_with_attributes ("Buforowany",
																													 renderer,
																													 "active", CACHED,
																													 NULL);
				gtk_tree_view_append_column (GTK_TREE_VIEW (sensors_manage_display_tree), column);
				
				renderer = gtk_cell_renderer_text_new ();
				column = gtk_tree_view_column_new_with_attributes ("Liczba punktów",
																													 renderer,
																													 "text", N_POINTS_BUFFERED,
																													 NULL);
				gtk_tree_view_append_column (GTK_TREE_VIEW (sensors_manage_display_tree), column);
				
				renderer = gtk_cell_renderer_toggle_new ();
				column = gtk_tree_view_column_new_with_attributes ("Dostępny",
																													 renderer,
																													 "active", SENSOR_PRESENT,
																													 NULL);
				gtk_tree_view_append_column (GTK_TREE_VIEW (sensors_manage_display_tree), column);
				
				// usuniecie selekcji
						GtkTreeSelection *selection;		
				selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sensors_manage_display_tree));
				
				gtk_tree_selection_unselect_all (selection) ;
				gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE) ;
				
				//g_object_unref(renderer) ;		// chyba nie mozna, doczytac !!!
						g_object_unref(store) ;	
		} ;
} ;
Ejemplo n.º 17
0
/*
 * 在 treeview_single中显示数据包的详细  封装信息
 */
void
show_single_packet(int pktno, struct pcap_pkthdr *pkthdr, const u_char * packet)
{
	GtkTreeStore *store;
	GtkTreeIter iter, child, grandchild;
	store = gtk_tree_store_new(1, G_TYPE_STRING);

	int i;
	int j;
/***-----------------------------------------***/
	// frame
	gtk_tree_store_append(store, &iter, NULL);
	u_char show_str[100];
	sprintf(show_str, "Frame %d, capture length %d bytes", pktno,
		pkthdr->caplen);
	gtk_tree_store_set(store, &iter, 0, show_str, -1);
	for (i = 0; i < 3; i++) {
		gtk_tree_store_append(store, &child, &iter);
		switch (i) {
		case 0:
			sprintf(show_str, "Frame: %d", pktno);
			break;
		case 1:
			sprintf(show_str, "Packet Length: %u", pkthdr->caplen);
			break;
		case 2:
			sprintf(show_str, "Capture Time: %s [%uus]",
				asctime(localtime(&pkthdr->ts.tv_sec)),
				pkthdr->ts.tv_usec);
			break;
		}
		gtk_tree_store_set(store, &child, 0, show_str, -1);
	}
/***-----------------------------------------***/
	// ethernet
	u_char ptype[5];
	u_short eth_type;
	struct ether_header *hdr;

	hdr = (struct ether_header *)packet;
	eth_type = ntohs(hdr->ether_type);
	printf("%04x\n", eth_type);
	switch (eth_type) {
	case 0x0800:
		sprintf(ptype, "IP");
		break;
	case 0x0806:
		sprintf(ptype, "ARP");
		break;
	case 0x8035:
		sprintf(ptype, "RARP");
		break;
	case 0x86dd:
		sprintf(ptype, "IPv6");
		break;
	default:
		sprintf(ptype, "%04x", eth_type);
		break;
	}
	u_char src_mac[25];
	u_char dst_mac[25];
	sprintf(src_mac, "%02x:%02x:%02x:%02x:%02x:%02x", hdr->src_mac[0],
		hdr->src_mac[1], hdr->src_mac[2], hdr->src_mac[3],
		hdr->src_mac[4], hdr->src_mac[5]);
	sprintf(dst_mac, "%02x:%02x:%02x:%02x:%02x:%02x", hdr->dst_mac[0],
		hdr->dst_mac[1], hdr->dst_mac[2], hdr->dst_mac[3],
		hdr->dst_mac[4], hdr->dst_mac[5]);

	gtk_tree_store_append(store, &iter, NULL);
	gtk_tree_store_set(store, &iter, 0, "Ethernet Layer", -1);
	for (i = 0; i < 3; i++) {
		gtk_tree_store_append(store, &child, &iter);
		switch (i) {
		case 0:
			sprintf(show_str, "Source MAC: %s", src_mac);
			break;
		case 1:
			sprintf(show_str, "Destination MAC: %s", dst_mac);
			break;
		case 2:
			sprintf(show_str, "Protocol type: %s", ptype);
			break;
		}
		gtk_tree_store_set(store, &child, 0, show_str, -1);
	}

/***-----------------------------------------***/
	// arp
	u_char src_ip[20];
	u_char dst_ip[20];
	if (0x0806 == eth_type) {
		struct arp_header *hdr;

		u_short oper;
		u_char operation[20];

		hdr = (struct arp_header *)(packet + 14);
		oper = ntohs(hdr->oper);
		switch (oper) {
		case 1:
			sprintf(operation, "ARP Request");
			break;
		case 2:
			sprintf(operation, "ARP Reply");
			break;
		case 3:
			sprintf(operation, "RARP Request");
			break;
		case 4:
			sprintf(operation, "RARP Reply");
			break;
		default:
			break;
		}

		sprintf(src_mac, "%02x:%02x:%02x:%02x:%02x:%02x", hdr->sha[0],
			hdr->sha[1], hdr->sha[2], hdr->sha[3], hdr->sha[4],
			hdr->sha[5]);
		sprintf(dst_mac, "%02x:%02x:%02x:%02x:%02x:%02x", hdr->tha[0],
			hdr->tha[1], hdr->tha[2], hdr->tha[3], hdr->tha[4],
			hdr->tha[5]);

		sprintf(src_ip, "%d.%d.%d.%d", hdr->spa[0], hdr->spa[1],
			hdr->spa[2], hdr->spa[3]);
		sprintf(dst_ip, "%d.%d.%d.%d", hdr->tpa[0], hdr->tpa[1],
			hdr->tpa[2], hdr->tpa[3]);

		// store
		gtk_tree_store_append(store, &iter, NULL);
		gtk_tree_store_set(store, &iter, 0, "ARP", -1);
		for (i = 0; i < 9; i++) {
			gtk_tree_store_append(store, &child, &iter);
			switch (i) {
			case 0:
				sprintf(show_str, "Hardware Type: %d",
					ntohs(hdr->htype));
				break;
			case 1:
				sprintf(show_str, "Protocol Type: %d",
					ntohs(hdr->ptype));
				break;
			case 2:
				sprintf(show_str, "Hardware Length: %d",
					hdr->hlen);
				break;
			case 3:
				sprintf(show_str, "Protocol Length: %d",
					hdr->plen);
				break;
			case 4:
				sprintf(show_str, "Operation: %s", operation);
				break;
			case 5:
				sprintf(show_str, "Sender MAC Address: %s",
					src_mac);
				break;
			case 6:
				sprintf(show_str, "Sender IP Address: %s",
					src_ip);
				break;
			case 7:
				sprintf(show_str, "Target MAC Address: %s",
					dst_mac);
				break;
			case 8:
				sprintf(show_str, "Target IP Address: %s",
					dst_ip);
				break;
			}
			gtk_tree_store_set(store, &child, 0, show_str, -1);
		}
	}
/***-----------------------------------------***/
	// IP 
	u_int8_t tprotocol = 0;	// transmission protocol , tcp or udp
	if (0x0800 == eth_type) {
		struct ip_header *hdr;
		u_int hlen;
		u_int offset;
		u_char tos;
		u_int16_t chksum;
		hdr = (struct ip_header *)(packet + 14);

		chksum = ntohs(hdr->checksum);
		hlen = hdr->ip_hdr_len << 2;
		tos = hdr->tos;
		offset = ntohs(hdr->frag_off);

		tprotocol = hdr->protocol;
		u_char protocol_str[5];
		switch (hdr->protocol) {
		case 6:
			sprintf(protocol_str, "TCP");
			break;
		case 17:
			sprintf(protocol_str, "UDP");
			break;
		case 1:
			sprintf(protocol_str, "ICMP");
			break;
		default:
			sprintf(protocol_str, "");
			break;
		}
		// store
		gtk_tree_store_append(store, &iter, NULL);
		gtk_tree_store_set(store, &iter, 0,
				   "Internet Protocol Version 4(IPv4)", -1);
		for (i = 0; i < 12; i++) {
			gtk_tree_store_append(store, &child, &iter);
			switch (i) {
			case 0:
				sprintf(show_str, "Version: %d",
					hdr->ip_version);
				break;
			case 1:
				sprintf(show_str, "Header Length: %d", hlen);
				break;
			case 2:
				sprintf(show_str, "TOS: %d", tos);
				break;
			case 3:
				sprintf(show_str, "Total Length: %d",
					ntohs(hdr->tot_len));
				break;
			case 4:
				sprintf(show_str, "Identification: %d",
					ntohs(hdr->id));
				break;
			case 5:
				sprintf(show_str, "Flags: 0x%02X",
					offset & 0xe000);
				gtk_tree_store_set(store, &child, 0, show_str,
						   -1);
				for (j = 0; j < 3; j++) {
					gtk_tree_store_append(store,
							      &grandchild,
							      &child);
					switch (j) {
					case 0:
						sprintf(show_str,
							"%d... .... = Reserved bit",
							(offset & 0x8000) >>
							15);
						break;
					case 1:
						sprintf(show_str,
							".%d.. .... = Don't Fragment",
							(offset & 0x4000) >>
							14);
						break;
					case 2:
						sprintf(show_str,
							"..%d. .... = More Fragments",
							(offset & 0x2000) >>
							13);
						break;
					}
					gtk_tree_store_set(store, &grandchild,
							   0, show_str, -1);
				}
				break;
			case 6:
				sprintf(show_str, "Fragment offset: %d",
					offset & 0x1fff);
				break;
			case 7:
				sprintf(show_str, "Time to live(TTL): %d",
					hdr->ttl);
				break;
			case 8:
				sprintf(show_str,
					"Transimission Protocol: %s(%d)",
					protocol_str, hdr->protocol);
				break;
			case 9:
				sprintf(show_str, "Header Checksum: 0x%x",
					chksum);
				break;
			case 10:
				sprintf(show_str, "Source IP Address: %s",
					inet_ntoa(hdr->src_addr));
				break;
			case 11:
				sprintf(show_str, "Desitination IP Address: %s",
					inet_ntoa(hdr->dst_addr));
				break;
			}
			if (i != 5)
				gtk_tree_store_set(store, &child, 0, show_str,
						   -1);
		}

	}
/***-----------------------------------------***/
	// IPv6
	if (0x86dd == eth_type) {
		struct ipv6_header *hdr;
		hdr = (struct ipv6_header *)(packet + 14);

		u_char src[50], dst[50], stemp[5], dtemp[5];
		strcpy(src, "");
		strcpy(dst, "");
		for (i = 1; i <= 16; i++) {
			if (i % 2 == 0 && i < 16) {
				sprintf(stemp, "%02x:", hdr->src_ipv6[i - 1]);
				sprintf(dtemp, "%02x:", hdr->dst_ipv6[i - 1]);
			} else {
				sprintf(stemp, "%02x", hdr->src_ipv6[i - 1]);
				sprintf(dtemp, "%02x", hdr->dst_ipv6[i - 1]);
			}
			strcat(src, stemp);
			strcat(dst, dtemp);
		}

		// store
		gtk_tree_store_append(store, &iter, NULL);
		gtk_tree_store_set(store, &iter, 0,
				   "Internet Protocol Version 6(IPv6)", -1);
		for (i = 0; i < 8; i++) {
			gtk_tree_store_append(store, &child, &iter);
			switch (i) {
			case 0:
				sprintf(show_str, "Version: %d",
					hdr->ip_version);
				break;
			case 1:
				sprintf(show_str, "Traffic Class: %d",
					(hdr->
					 traffic_class_1 << 4) |
					hdr->traffic_class_2);
				break;
			case 2:
				sprintf(show_str, "Flow Label: %d",
					(hdr->
					 flow_label_1 << 16) |
					ntohs(hdr->flow_label_2));
				break;
			case 3:
				sprintf(show_str, "Payload Length: %d",
					ntohs(hdr->payload_length));
				break;
			case 4:
				sprintf(show_str, "Next Header: %d",
					hdr->next_header);
				break;
			case 5:
				sprintf(show_str, "Hop Limit: %d",
					hdr->hop_limit);
				gtk_tree_store_set(store, &child, 0, show_str,
						   -1);
				break;
			case 6:
				sprintf(show_str, "Source IPv6 Address: %s",
					src);
				break;
			case 7:
				sprintf(show_str,
					"Desitination IPv6 Address: %s", dst);
				break;
			}
			gtk_tree_store_set(store, &child, 0, show_str, -1);
		}
	}
/***-----------------------------------------***/
	int http_flag = 0;
	// TCP
	if (6 == tprotocol) {
		struct tcp_header *hdr;
		u_char flags;
		u_int hlen;
		u_short dst_port;
		u_short src_port;
		u_char protocol_str[10];	// 应用层协议
		hdr = (struct tcp_header *)(packet + 14 + 20);
		dst_port = ntohs(hdr->dst_port);
		src_port = ntohs(hdr->src_port);
		if (dst_port == 80 || src_port == 80)
			http_flag = 1;
		hlen = hdr->tcp_off << 2;
		flags = hdr->th_flags;

		switch (dst_port) {
		case 80:
			sprintf(protocol_str, "HTTP");
			break;
		case 21:
			sprintf(protocol_str, "FTP");
			break;
		case 23:
			sprintf(protocol_str, "TELNET");
			break;
		case 25:
			sprintf(protocol_str, "SMTP");
			break;
		case 110:
			sprintf(protocol_str, "POP3");
			break;
		default:
			sprintf(protocol_str, "");
			break;
		}
		// store
		gtk_tree_store_append(store, &iter, NULL);
		gtk_tree_store_set(store, &iter, 0,
				   "Transimission Control Protocol(TCP)", -1);
		for (i = 0; i < 9; i++) {
			gtk_tree_store_append(store, &child, &iter);
			switch (i) {
			case 0:
				sprintf(show_str, "Source Port: %d",
					ntohs(hdr->src_port));
				break;
			case 1:
				sprintf(show_str, "Desitination Port: %s(%d)",
					protocol_str, ntohs(hdr->dst_port));
				break;
			case 2:
				sprintf(show_str, "Sequence Number: %u",
					ntohl(hdr->tcp_seq));
				break;
			case 3:
				sprintf(show_str, "Acknowledgement Number: %u",
					ntohl(hdr->tcp_ack));
				break;
			case 4:
				sprintf(show_str, "Header Length: %d bytes",
					hlen);
				break;
			case 5:
				sprintf(show_str, "Flags: 0x%x", flags);
				gtk_tree_store_set(store, &child, 0, show_str,
						   -1);
				for (j = 0; j < 6; j++) {
					gtk_tree_store_append(store,
							      &grandchild,
							      &child);
					switch (j) {
					case 0:
						sprintf(show_str,
							"..%d. .... = URG",
							(0x20 & flags) >> 5);
						break;
					case 1:
						sprintf(show_str,
							"...%d .... = ACK",
							(0x10 & flags) >> 4);
						break;
					case 2:
						sprintf(show_str,
							".... %d... = PSH",
							(0x08 & flags) >> 3);
						break;
					case 3:
						sprintf(show_str,
							".... .%d.. = RST",
							(0x04 & flags) >> 2);
						break;
					case 4:
						sprintf(show_str,
							".... ..%d. = SYN",
							(0x02 & flags) >> 1);
						break;
					case 5:
						sprintf(show_str,
							".... ...%d = FIN",
							0x01 & flags);
						break;
					}
					gtk_tree_store_set(store, &grandchild,
							   0, show_str, -1);
				}
				break;
			case 6:
				sprintf(show_str, "Window size: %d",
					ntohs(hdr->th_win));
				break;
			case 7:
				sprintf(show_str, "Checksum: 0x%x",
					ntohs(hdr->th_sum));
				break;
			case 8:
				sprintf(show_str, "Urgent Pointer: 0x%x",
					ntohs(hdr->th_urp));
				break;

			}
			if (i != 5)
				gtk_tree_store_set(store, &child, 0, show_str,
						   -1);
		}
		if (hlen > 20) {	// 报头有选项数据
			gtk_tree_store_append(store, &child, &iter);
			gtk_tree_store_set(store, &child, 0, "Options", -1);
			u_char *p = (packet + 14 + 20 + 20);
			u_int mss;
			mss = ntohl((u_int) * p);
			for (j = 0; j < 3; j++) {
				gtk_tree_store_append(store, &grandchild,
						      &child);
				switch (j) {
				case 0:
					sprintf(show_str,
						"Maximum segment: %u bytes",
						mss);
					break;
				case 1:
					sprintf(show_str,
						"TCP SACK Permitted Option:..");
					break;
				case 2:
					sprintf(show_str, "Timestamp:..");
					break;
				}
				gtk_tree_store_set(store, &grandchild, 0,
						   show_str, -1);
			}
		}
		if (pkthdr->caplen > 14 + 20 + hlen && !http_flag) {
			// has data
			gtk_tree_store_append(store, &iter, NULL);
			gtk_tree_store_set(store, &iter, 0, "Data", -1);
		}
	}
/***-----------------------------------------***/
	//http
	if (http_flag) {
		gtk_tree_store_append(store, &iter, NULL);
		gtk_tree_store_set(store, &iter, 0,
				   "Hypertext Transfer Protocol(HTTP)", -1);
		u_char *p;
		u_char http_header[1500];

		memcpy(http_header, (packet + 14 + 20 + 20),
		       pkthdr->caplen - 54);
		p = http_header;
		/*for (i = 0; i < 3; i++) {
		   gtk_tree_store_append(store, &child, &iter);
		   j=0;
		   while(*p!='\r'&&*(p+1)!='\n')
		   {
		   show_str[j] =(char)*p;
		   j++;
		   p++;
		   }
		   gtk_tree_store_set(store, &child, 0,
		   show_str, -1);
		   p +=2;  

		   } */

	}
/***-----------------------------------------***/
	// UDP
	if (17 == tprotocol) {
		struct udp_header *hdr;
		u_short src_port;
		u_short dst_port;
		u_short len;
		u_short chksum;
		hdr = (struct udp_header *)(packet + 14 + 20);

		src_port = ntohs(hdr->src_port);
		dst_port = ntohs(hdr->dst_port);
		len = ntohs(hdr->len);
		chksum = ntohs(hdr->checksum);

		u_char protocol_str[20];
		switch (dst_port) {
		case 138:
			sprintf(protocol_str, "NETBIOS Datagram Service");
			break;
		case 137:
			sprintf(protocol_str, "NETBIOS Name Service");
			break;
		case 139:
			sprintf(protocol_str, "NETBIOS session service");
			break;
		case 53:
			sprintf(protocol_str, "Domain Name Service");
			break;
		default:
			break;
		}

		// printf("Length:%d\n", len);
		// printf("Checksum:%d\n", chksum);

		// store
		gtk_tree_store_append(store, &iter, NULL);
		gtk_tree_store_set(store, &iter, 0,
				   "User Datagram Protocol(UDP)", -1);
		for (i = 0; i < 4; i++) {
			gtk_tree_store_append(store, &child, &iter);
			switch (i) {
			case 0:
				sprintf(show_str, "Source Port: %d", src_port);
				break;
			case 1:
				sprintf(show_str, "Destination Port: %s(%d)",
					protocol_str, dst_port);
				break;
			case 2:
				sprintf(show_str, "Length: %d", len);
				break;
			case 3:
				sprintf(show_str, "Checksum: 0x%x", chksum);
				break;

			}
			gtk_tree_store_set(store, &child, 0, show_str, -1);
		}

		gtk_tree_store_append(store, &iter, NULL);
		sprintf(show_str, "Data (%u bytes)", len);
		gtk_tree_store_set(store, &iter, 0, show_str, -1);
	}
/***-----------------------------------------***/
	// icmp
	if (1 == tprotocol) {
		struct icmp_header *hdr;
		hdr = (struct icmp_header *)(packet + 14 + 20);
		u_char icmp_type_str[50];
		switch (hdr->icmp_type) {
		case 0:
			sprintf(icmp_type_str, "ICMP Echo Reply Protocol");
			break;
		case 8:
			sprintf(icmp_type_str, "ICMP Echo Request Protocol");
			break;
		case 3:
			sprintf(icmp_type_str, "ICMP Unreachable");
			break;
		case 4:
			sprintf(icmp_type_str, "Source quench 源抑制");
			break;
		case 5:
			sprintf(icmp_type_str, "ICMP Redirect 重定向");
			break;
		case 9:
			sprintf(icmp_type_str, "Router Advertisement");
			break;
		case 10:
			sprintf(icmp_type_str, "Router Solicitation");
			break;
		case 11:
			sprintf(icmp_type_str, "Time Exceeded");
			break;
		case 13:
			sprintf(icmp_type_str, "ICMP Timestamp Request");
			break;
		case 14:
			sprintf(icmp_type_str, "ICMP Timestamp Reply");
			break;
		case 17:
			sprintf(icmp_type_str, "Address Mask Request");
			break;
		case 18:
			sprintf(icmp_type_str, "Address Mask Reply");
			break;
		default:
			break;
		}

		// store
		gtk_tree_store_append(store, &iter, NULL);
		gtk_tree_store_set(store, &iter, 0,
				   "Internet Control Message Protocol(ICMP)",
				   -1);
		for (i = 0; i < 5; i++) {
			gtk_tree_store_append(store, &child, &iter);
			switch (i) {
			case 0:
				sprintf(show_str, "ICMP Type: %s(%d)",
					icmp_type_str, hdr->icmp_type);
				break;
			case 1:
				sprintf(show_str, "ICMP Code: %d",
					hdr->icmp_code);
				break;
			case 2:
				sprintf(show_str, "Checksum: 0x%x",
					ntohs(hdr->icmp_chksum));
				break;
			case 3:
				sprintf(show_str, "Identifier: %d",
					hdr->icmp_id);
				break;
			case 4:
				sprintf(show_str, "Sequence Number: %d",
					hdr->icmp_seq);
				break;
			}
			gtk_tree_store_set(store, &child, 0, show_str, -1);
		}
	}

/************************************/
	// 连接 model and view
	GtkTreeViewColumn *col;
	GtkCellRenderer *renderer;
	GtkTreeModel *model;
	GtkWidget *view;

	view = GTK_TREE_VIEW(gtk_builder_get_object(builder,
						    "treeview_single"));
	// 删除原来的
	col = gtk_tree_view_get_column(view, 0);
	if (col)
		gtk_tree_view_remove_column(view, col);

	model = GTK_TREE_MODEL(store);

	renderer = gtk_cell_renderer_text_new();
	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
						    -1, NULL, renderer, "text",
						    0, NULL);

	gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);

	g_object_unref(model);	// destroy model automatically with view 

}
void VectorTableToDialog (vector_table_options_D *dialog, BUS_LAYOUT *bus_layout, int *sim_type, VectorTable *pvt)
  {
  GList *llCols = NULL, *llItr = NULL ;
  int Nix ;
  GtkTreeModel *model = NULL ;
  GtkWidget *tbtn = NULL ;
  GtkTreeViewColumn *col = NULL ;

  if (NULL == dialog || NULL == sim_type || NULL == pvt) return ;

  g_object_set_data (G_OBJECT (dialog->dialog), "user_sim_type", sim_type) ;
  g_object_set_data (G_OBJECT (dialog->dialog), "user_pvt", pvt) ;
  g_object_set_data (G_OBJECT (dialog->dialog), "user_bus_layout", bus_layout) ;
  g_object_set_data (G_OBJECT (dialog->dialog), "idxVector", (gpointer)-1) ;

  if (0 == bus_layout->inputs->icUsed)
    (*sim_type) = EXHAUSTIVE_VERIFICATION ;

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tbtn = (VECTOR_TABLE == (*sim_type) ? dialog->tbtnVT : dialog->tbtnExhaustive)), TRUE) ;

  g_object_set_data (G_OBJECT (dialog->crActive), "pvt", pvt) ;

  if (NULL != (model = GTK_TREE_MODEL (design_bus_layout_tree_store_new (bus_layout, ROW_TYPE_INPUT, 1, G_TYPE_BOOLEAN))))
    {
    gboolean bActive = FALSE ;
    GtkTreeIter itr, itrChild ;
    int row_type = -1, idx = -1 ;
    QCADCell *cell = NULL ;
    gboolean bBusActive = FALSE ;

    // First reflect the active_flag of current cell inputs
    if (gtk_tree_model_get_iter_first (model, &itr))
      while (TRUE)
        {
        gtk_tree_model_get (model, &itr, 
          BUS_LAYOUT_MODEL_COLUMN_TYPE, &row_type,
          BUS_LAYOUT_MODEL_COLUMN_CELL, &cell, -1) ;
        if (ROW_TYPE_CELL_INPUT == row_type && NULL != cell)
          if (-1 != (idx = VectorTable_find_input_idx (pvt, cell)))
            gtk_tree_store_set (GTK_TREE_STORE (model), &itr, 
              VECTOR_TABLE_MODEL_COLUMN_ACTIVE, exp_array_index_1d (pvt->inputs, VT_INPUT, idx).active_flag, -1) ;
        if (!gtk_tree_model_iter_next_dfs (model, &itr)) break ;
        }

    // For any given bus, if any of its cells are active, then the bus is active. Reflect this.
    if (gtk_tree_model_get_iter_first (model, &itr))
      while (TRUE)
        {
        bBusActive = FALSE ;
        if (gtk_tree_model_iter_children (model, &itrChild, &itr))
          {
          while (TRUE)
            {
            gtk_tree_model_get (model, &itrChild, VECTOR_TABLE_MODEL_COLUMN_ACTIVE, &bActive, -1) ;
            if ((bBusActive = bActive)) break ;
            if (!gtk_tree_model_iter_next (model, &itrChild)) break ;
            }
          gtk_tree_store_set (GTK_TREE_STORE (model), &itr, VECTOR_TABLE_MODEL_COLUMN_ACTIVE, bBusActive, -1) ;
          }
        if (!gtk_tree_model_iter_next (model, &itr)) break ;
        }

    llCols = gtk_tree_view_get_columns (GTK_TREE_VIEW (dialog->tv)) ;
    for (Nix = 0, llItr = llCols ; Nix < 2 && NULL != llItr ; Nix++, llItr = llItr->next) ;
    for (; llItr != NULL ; llItr = llItr->next)
      gtk_tree_view_remove_column (GTK_TREE_VIEW (dialog->tv), GTK_TREE_VIEW_COLUMN (llItr->data)) ;
    g_list_free (llCols) ;

    gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->tv), model) ;
    }

  gtk_tree_view_expand_all (GTK_TREE_VIEW (dialog->tv)) ;

  for (Nix = 0 ; Nix < pvt->vectors->icUsed ; Nix++)
    {
    if (NULL == col)
      col = add_vector_to_dialog (dialog, pvt, Nix) ;
    else
      add_vector_to_dialog (dialog, pvt, Nix) ;
    // Give the dialog a chance to update itself
    if (0 == Nix % 10)
      while (gtk_events_pending ())
        gtk_main_iteration () ;
    }

  if (NULL != col)
    gtk_tree_view_column_clicked (col) ;

  if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tbtn)))
    vector_table_options_dialog_btnSimType_clicked (tbtn, dialog) ;

  vector_table_options_dialog_reflect_state (dialog) ;
  }
Ejemplo n.º 19
0
bool change_function(int vars)
{
    /* Clear model */
    clear_liststore(function_view);

    /* Create the dynamic types array */
    GType* types = (GType*) malloc(3 * vars * sizeof(GType));
    if(types == NULL) {
        return false;
    }

    /* Set type in the dynamic types array */
    for(int i = 0; i < vars; i++) {
        types[i] = G_TYPE_INT;               /* Coeffs */
        types[vars + i] = G_TYPE_STRING;     /* Text   */
        types[2 * vars + i] = G_TYPE_STRING; /* Signs  */
    }

    /* Create and fill the new model */
    GtkListStore* function = gtk_list_store_newv(3 * vars, types);
    GtkTreeIter iter;

    GValue initi = G_VALUE_INIT;
    g_value_init(&initi, G_TYPE_INT);

    GValue inits = G_VALUE_INIT;
    g_value_init(&inits, G_TYPE_STRING);

    gtk_list_store_append(function, &iter);
    for(int i = 0; i < vars; i++) {

        g_value_set_int(&initi, 1);
        gtk_list_store_set_value(function, &iter, i, &initi);

        char* text = var_name(1, i, false);
        g_value_set_string(&inits, text);
        gtk_list_store_set_value(function, &iter, vars + i, &inits);
        free(text);

        g_value_set_string(&inits, PLUS);
        gtk_list_store_set_value(function, &iter, 2 * vars + i, &inits);
    }

    /* Clear the previous columns */
    for(int i = gtk_tree_view_get_n_columns(function_view) - 1; i >= 0; i--) {
        gtk_tree_view_remove_column(
                                function_view,
                                gtk_tree_view_get_column(function_view, i)
                            );
    }

    /* Create the new columns */
    for(int i = 0; i < vars; i++) {

        /* Create sign column */
        if(i > 0) {
            GtkCellRenderer* sign = gtk_cell_renderer_text_new();
            GtkTreeViewColumn* sign_c =
                gtk_tree_view_column_new_with_attributes(
                                            "", sign,  /* Title, renderer */
                                            "markup", 2 * vars + i,
                                            NULL);
            gtk_tree_view_append_column(function_view, sign_c);
        }

        /* Create text column */
        /* Create and configure cell */
        GtkCellRenderer* cell = gtk_cell_renderer_spin_new();

        gtk_cell_renderer_set_alignment(cell, 1.0, 0.5);
        g_object_set(cell, "editable", true, NULL);

        /* Configure callbacks */
        g_signal_connect(G_OBJECT(cell),
                    "editing-started", G_CALLBACK(function_edit_started_cb),
                    GINT_TO_POINTER(i));
        function_edit_started_cb(cell, NULL, NULL, GINT_TO_POINTER(i));

        g_signal_connect(G_OBJECT(cell),
                         "edited", G_CALLBACK(function_edited_cb),
                         GINT_TO_POINTER(i));

        /* Configure column */
        GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(
                                        "", cell,  /* Title, renderer */
                                        "markup", vars + i,
                                        NULL);
        gtk_tree_view_column_set_min_width(column, 100);
        gtk_tree_view_append_column(function_view, column);
    }
    gtk_tree_view_append_column(function_view, gtk_tree_view_column_new());

    /* Set the new model */
    gtk_tree_view_set_model(function_view, GTK_TREE_MODEL(function));

    /* Free resources */
    g_object_unref(G_OBJECT(function));
    free(types);

    return true;
}
Ejemplo n.º 20
0
/**
 * Create the model containing CSV file preview.
 *
 * \param tree_preview		GtkTreeView to associate model to.
 * \param contents		Contents to place into model
 *
 *
 */
GtkTreeModel * csv_import_create_model ( GtkTreeView * tree_preview, gchar * contents,
                        gchar * separator )
{
    GtkWidget * assistant;
    GtkTreeStore *model;
    GtkTreeViewColumn * col;
    GtkCellRenderer * cell;
    GType *types;
    gint size, i;
    GList *list;

    size = csv_import_count_columns ( contents, separator );
    if ( ! size || ! contents)
	    return NULL;

    csv_fields_config = csv_import_update_fields_config ( contents, size, separator );

    assistant = g_object_get_data ( G_OBJECT(tree_preview), "assistant" );

    /* Remove previous columns if any. */
    list = gtk_tree_view_get_columns ( GTK_TREE_VIEW ( tree_preview ) );

    while ( list )
    {
        gtk_tree_view_remove_column ( tree_preview, list -> data );
        list = list -> next;
    }

    types = (GType *) g_malloc0 ( ( size + 2 ) * sizeof ( GType * ) );

    types[0] = G_TYPE_BOOLEAN;
    cell = gtk_cell_renderer_toggle_new ();
    col = gtk_tree_view_column_new_with_attributes ( _("Skip"),
					    cell,
                        "active", 0,
					    NULL);
    gtk_tree_view_append_column ( tree_preview, col );
    g_object_set_data ( G_OBJECT ( col ), "assistant", assistant );
    g_signal_connect ( cell,
                        "toggled",
                        G_CALLBACK ( skip_line_toggled ),
                        tree_preview );

    for ( i = 0 ; i < size ; i ++ )
    {
        GtkWidget *label;
        gchar *name;

        types[i+1] = G_TYPE_STRING;

        cell = gtk_cell_renderer_text_new ();
        col = gtk_tree_view_column_new_with_attributes (
                        NULL,
                        cell,
                        "text", i + 1,
                        "strikethrough", 0,
                        NULL);

        if ( csv_fields_config[i] > 0 )
        {
            name = g_strconcat ( "<b><u>", _( csv_fields [ csv_fields_config[i] ] . name ),
                     "</u></b>", NULL );
        }
        else
        {
            name = my_strdup (_( csv_fields [ csv_fields_config[i] ] . name ));
        }

        label = gtk_label_new ( NULL );
        gtk_label_set_markup ( GTK_LABEL(label), name );
        gtk_widget_show ( label );
        g_free ( name );

        gtk_tree_view_column_set_widget ( col, label );
        gtk_tree_view_append_column ( tree_preview, col );
        gtk_tree_view_column_set_clickable ( col, TRUE );
        g_object_set_data ( G_OBJECT ( col ), "column", col );
        g_object_set_data ( G_OBJECT ( col ), "assistant", assistant );
        g_signal_connect ( G_OBJECT ( col ),
                   "clicked",
                   G_CALLBACK ( csv_import_header_on_click ),
                   GINT_TO_POINTER ( i + 1 ) );
    }

    model =  gtk_tree_store_newv ( size + 1, types );

    return (GtkTreeModel *) model;
}
Ejemplo n.º 21
0
bool change_restrictions(int vars)
{
    /* Clear model */
    clear_liststore(restrictions_view);

    /* Create the dynamic types array */
    int size = vars + 2;
    GType* types = (GType*) malloc(3 * size * sizeof(GType));
    if(types == NULL) {
        return false;
    }

    /* Set type in the dynamic types array */
    for(int i = 0; i < size; i++) {
        types[i] = G_TYPE_INT;               /* Coeffs */
        types[size + i] = G_TYPE_STRING;     /* Text   */
        types[2 * size + i] = G_TYPE_STRING; /* Signs  */
    }

    /* Create the new model */
    GtkListStore* restrictions = gtk_list_store_newv(3 * size, types);

    /* Clear the previous columns */
    for(int i = gtk_tree_view_get_n_columns(restrictions_view) - 1; i >= 0; i--) {
        gtk_tree_view_remove_column(
                                restrictions_view,
                                gtk_tree_view_get_column(restrictions_view, i)
                            );
    }

    /* Create the new columns */
    for(int i = 0; i < size; i++) {

        /* Especial column for type */
        if(i == (size - 2)) {
            GtkCellRenderer* type = gtk_cell_renderer_text_new();
            GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(
                                        "", type,  /* Title, renderer */
                                        "markup", size + i,
                                        NULL);
            gtk_tree_view_append_column(restrictions_view, column);
            continue;
        }

        /* Create sign column */
        if((i != 0) && (i != size - 1)) {
            GtkCellRenderer* sign = gtk_cell_renderer_text_new();
            GtkTreeViewColumn* sign_c =
                gtk_tree_view_column_new_with_attributes(
                                            "", sign,  /* Title, renderer */
                                            "markup", 2 * size + i,
                                            NULL);
            gtk_tree_view_append_column(restrictions_view, sign_c);
        }

        /* Create text column */
        /* Create and configure cell */
        GtkCellRenderer* cell = gtk_cell_renderer_spin_new();

        gtk_cell_renderer_set_alignment(cell, 1.0, 0.5);
        g_object_set(cell, "editable", true, NULL);

        /* Configure callbacks */
        g_signal_connect(G_OBJECT(cell),
                    "editing-started", G_CALLBACK(restrictions_edit_started_cb),
                    GINT_TO_POINTER(i));
        restrictions_edit_started_cb(cell, NULL, NULL, GINT_TO_POINTER(i));

        if(i < size - 2) {
            g_signal_connect(G_OBJECT(cell),
                         "edited", G_CALLBACK(restrictions_edited_cb),
                         GINT_TO_POINTER(i));
        } else {
            g_signal_connect(G_OBJECT(cell),
                         "edited", G_CALLBACK(num_edited_cb),
                         GINT_TO_POINTER(i));
        }

        /* Configure column */
        GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(
                                        "", cell,  /* Title, renderer */
                                        "markup", size + i,
                                        NULL);
        gtk_tree_view_column_set_min_width(column, 100);
        gtk_tree_view_append_column(restrictions_view, column);
    }
    gtk_tree_view_append_column(restrictions_view, gtk_tree_view_column_new());

    /* Set the new model */
    gtk_tree_view_set_model(restrictions_view, GTK_TREE_MODEL(restrictions));

    /* Free resources */
    g_object_unref(G_OBJECT(restrictions));
    free(types);

    return true;
}
Ejemplo n.º 22
0
void setup_tree_view(struct _properties *properties)
{
  GtkCellRenderer *renderer;
  GtkTreeViewColumn *column;

  char strike[200] = { 0 };
  char call[200] = { 0 };
  char put[200] = { 0 };

  // delete previous column names if any...
  GtkTreeViewColumn *col;
  while((col = gtk_tree_view_get_column(GTK_TREE_VIEW(properties->GtkInfo.treeview),0)) != NULL)
  {
    gtk_tree_view_remove_column(GTK_TREE_VIEW(properties->GtkInfo.treeview),col);
  }

  if( option_algorithms[properties->modeltype].assetClass == FUTURES_CLASS )
  {
    //g_print("tree Future detected\n");

    if(properties->decimalorcalendar == CALENDAR )
    {
      //g_print("tree CALENDAR future detect\n");

      if( properties->spreads == 0 )
      {
        properties->GtkInfo.liststore1 = gtk_list_store_new (5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
      } else if( properties->spreads == 1 )
      {
        properties->GtkInfo.liststore1 = gtk_list_store_new (12, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
      }

      gtk_tree_view_set_model (GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1));
      g_object_unref (properties->GtkInfo.liststore1);
  
      renderer = gtk_cell_renderer_text_new();
      column = gtk_tree_view_column_new_with_attributes
                           ("Expiration", renderer, "text", X1 , NULL);
      gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

      renderer = gtk_cell_renderer_text_new();
      column = gtk_tree_view_column_new_with_attributes
                          ("Price", renderer, "text", X2, NULL);
                          //(option_algorithms[properties->modeltype].price, renderer, "text", X2, NULL);
      gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

      renderer = gtk_cell_renderer_text_new();
      column = gtk_tree_view_column_new_with_attributes
                           ("Days to Expr", renderer, "text", X3, NULL);
      gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

      renderer = gtk_cell_renderer_text_new();
      column = gtk_tree_view_column_new_with_attributes
        //                 ("Decimal Time", renderer, "text", X4, NULL);
                           ("Years to Expr", renderer, "text", X4, NULL);
      gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

      renderer = gtk_cell_renderer_text_new();
      column = gtk_tree_view_column_new_with_attributes
                           ("Ticker", renderer, "text", X5, NULL);
      gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

      if( properties->spreads == 1 )
      {
        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
                           ("Expiration", renderer, "text", X6 , NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
                           ("Price", renderer, "text", X7, NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
                           ("Days to Expr", renderer, "text", X8, NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
                           ("Years to Expr", renderer, "text", X9, NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
                           ("Ticker", renderer, "text", X10, NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
                           ("Spread", renderer, "text", X11, NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes
                           ("Spread Ticker", renderer, "text", X12, NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);
      }

      return;
    }

    if(properties->decimalorcalendar == DECIMALS )
    {
      //g_print("DECIMALS future detect\n");

      properties->GtkInfo.liststore1 = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING );

      gtk_tree_view_set_model (GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1));
      g_object_unref (properties->GtkInfo.liststore1);
  
      renderer = gtk_cell_renderer_text_new();
      column = gtk_tree_view_column_new_with_attributes
                           ("Description", renderer, "text", X1 , NULL);
      gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

      renderer = gtk_cell_renderer_text_new();
      column = gtk_tree_view_column_new_with_attributes
                           ("Value", renderer, "text", X2, NULL);
      gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);
      return;
    }
  }

  if( option_algorithms[properties->modeltype].assetClass == BOND_CLASS )
  {
    g_print("Bonds detected\n");

    properties->GtkInfo.liststore1 = gtk_list_store_new (8, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );

    gtk_tree_view_set_model (GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1));
    g_object_unref (properties->GtkInfo.liststore1);
    
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Description", renderer, "text", X1 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Value", renderer, "text", X2 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Date", renderer, "text", X3 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Time", renderer, "text", X4 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    return;
  }

  if( option_algorithms[properties->modeltype].assetClass == TERMSTRUCTURE_CLASS )  {
    g_print("Termstructure detected\n");

    properties->GtkInfo.liststore1 = gtk_list_store_new (8, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );

    gtk_tree_view_set_model (GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1));
    g_object_unref (properties->GtkInfo.liststore1);
    
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Description", renderer, "text", X1 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Value", renderer, "text", X2 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Date", renderer, "text", X3 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Time", renderer, "text", X4 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    return;

  }

  if( properties->decimalorcalendar == DECIMALS )
  {
    properties->GtkInfo.liststore1 = gtk_list_store_new (12, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );

    gtk_tree_view_set_model (GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1));
    g_object_unref (properties->GtkInfo.liststore1);
  
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (option_algorithms[properties->modeltype].price, renderer, "text", X1 , NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    if( option_algorithms[properties->modeltype].supportStrikes )
    {
      sprintf(strike,"%s",option_algorithms[properties->modeltype].strike);
    } else
    {
      strike[0] = 0;
    }
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (strike, renderer, "text", X2, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(call,"%s",option_algorithms[properties->modeltype].call);
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (call, renderer, "text", X3, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(put,"%s",option_algorithms[properties->modeltype].put);
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (put, renderer, "text", X4, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Call Delta", renderer, "text", X5, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Put Delta", renderer, "text", X6, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Gamma", renderer, "text", X7, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Vega", renderer, "text", X8, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Call Theta", renderer, "text", X9, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Put Theta", renderer, "text", X10, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Call Rho", renderer, "text", X11, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Put Rho", renderer, "text", X12, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);
  } 
  else if(properties->decimalorcalendar == CALENDAR && properties->format == CALENDAR_OPTIONS6 )
  {
    properties->GtkInfo.liststore1 = gtk_list_store_new (8, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);

    gtk_tree_view_set_model (GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1));
    g_object_unref (properties->GtkInfo.liststore1);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (option_algorithms[properties->modeltype].price, renderer, "text", X1, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);
  
    if( option_algorithms[properties->modeltype].supportStrikes )
    {
      sprintf(strike,"%s",option_algorithms[properties->modeltype].strike);
    } else
    {
      strike[0] = 0;
    }
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (strike, renderer, "text", X2, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    char textDate[500] = { 0 };

    sprintf(textDate,"%s %s%2d %04.0f",option_algorithms[properties->modeltype].call,mon[*properties->expiration_month],*properties->days_to_expiration,(double)*properties->expiration_year + 2000);
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X3, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s %s%2d %04.0f",option_algorithms[properties->modeltype].call,mon[*(properties->expiration_month+1)],*(properties->days_to_expiration+1),(double)*(properties->expiration_year+1) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X4, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s %s%2d %04.0f",option_algorithms[properties->modeltype].call,mon[*(properties->expiration_month+2)],*(properties->days_to_expiration+2),(double)*(properties->expiration_year+2) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X5, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s %s%2d %04.0f",option_algorithms[properties->modeltype].put,mon[*properties->expiration_month],*properties->days_to_expiration,(double)*properties->expiration_year + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X6, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s %s%2d %04.0f",option_algorithms[properties->modeltype].put,mon[*(properties->expiration_month+1)],*(properties->days_to_expiration+1),(double)*(properties->expiration_year+1) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X7, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s %s%2d %04.0f",option_algorithms[properties->modeltype].put,mon[*(properties->expiration_month+2)],*(properties->days_to_expiration+2),(double)*(properties->expiration_year+2) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X8, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

  } else if( properties->decimalorcalendar == CALENDAR && properties->format == CALENDAR_OPTIONS5 )
  {
    properties->GtkInfo.liststore1 = gtk_list_store_new( 10, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );

    gtk_tree_view_set_model( GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1) );
    g_object_unref( properties->GtkInfo.liststore1 );

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (option_algorithms[properties->modeltype].price, renderer, "text", X1, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);
  
    if( option_algorithms[properties->modeltype].supportStrikes )
    {
      sprintf(strike,"%s",option_algorithms[properties->modeltype].strike);
    } else
    {
      strike[0] = 0;
    }
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (strike, renderer, "text", X2, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    char textDate[400] = { 0 };

    sprintf(textDate,"%s%2d %04.0f",mon[*properties->expiration_month],*properties->days_to_expiration,(double)*properties->expiration_year + 2000);
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X3, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s%2d %04.0f",mon[*(properties->expiration_month+1)],*(properties->days_to_expiration+1),(double)*(properties->expiration_year+1) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X4, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s%2d %04.0f",mon[*(properties->expiration_month+2)],*(properties->days_to_expiration+2),(double)*(properties->expiration_year+2) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X5, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s%2d %04.0f",mon[*(properties->expiration_month+3)],*(properties->days_to_expiration+3),(double)*(properties->expiration_year+3) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X6, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s%2d %04.0f",mon[*(properties->expiration_month+4)],*(properties->days_to_expiration+4),(double)*(properties->expiration_year+4) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X7, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s%2d %04.0f",mon[*(properties->expiration_month+5)],*(properties->days_to_expiration+5),(double)*(properties->expiration_year+5) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X8, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s%2d %04.0f",mon[*(properties->expiration_month+6)],*(properties->days_to_expiration+6),(double)*(properties->expiration_year+6) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X9, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(textDate,"%s%2d %04.0f",mon[*(properties->expiration_month+7)],*(properties->days_to_expiration+7),(double)*(properties->expiration_year+7) + 2000 );
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (textDate, renderer, "text", X10, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

  } else if( properties->decimalorcalendar == CALENDAR && properties->spreads == 0 && ( properties->format == CALENDAR_OPTIONS4 || properties->format == CALENDAR_OPTIONS3 || properties->format == CALENDAR_CUSTOM ))
  {
    properties->GtkInfo.liststore1 = gtk_list_store_new( 17, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING , G_TYPE_STRING , G_TYPE_STRING , G_TYPE_STRING , G_TYPE_STRING );
    
    gtk_tree_view_set_model( GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1) );
    g_object_unref(properties->GtkInfo.liststore1 );

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (option_algorithms[properties->modeltype].price, renderer, "text", X1, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Expr Date", renderer, "text", X2, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);
  
    if( option_algorithms[properties->modeltype].supportStrikes )
    {
      sprintf(strike,"%s",option_algorithms[properties->modeltype].strike);
    } else
    {
      strike[0] = 0;
    }
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (strike, renderer, "text", X3, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(call,"%s",option_algorithms[properties->modeltype].call);
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (call, renderer, "text", X4, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    if(option_algorithms[properties->modeltype].supportPuts)
      sprintf(put,"%s",option_algorithms[properties->modeltype].put);
    else
      put[0] = 0;

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (put, renderer, "text", X5, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Days to Expr", renderer, "text", X6, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
      //                   ("Decimal Time", renderer, "text", X7, NULL);
                           ("Years to Expr", renderer, "text", X7, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Call Delta", renderer, "text", X8, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Put Delta", renderer, "text", X9, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Gamma", renderer, "text", X10, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Vega", renderer, "text", X11, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Call Theta", renderer, "text", X12, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Put Theta", renderer, "text", X13, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Call Rho", renderer, "text", X14, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Put Rho", renderer, "text", X15, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Legacy C", renderer, "text", X16, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Legacy P", renderer, "text", X17, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

  } else if( properties->decimalorcalendar == CALENDAR && properties->spreads == 1 && ( properties->format == CALENDAR_OPTIONS4 || properties->format == CALENDAR_OPTIONS3 || properties->format == CALENDAR_CUSTOM ))
  {
    g_print("Spreads for Options\n");

    properties->GtkInfo.liststore1 = gtk_list_store_new( 13, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );

    gtk_tree_view_set_model( GTK_TREE_VIEW (properties->GtkInfo.treeview), GTK_TREE_MODEL (properties->GtkInfo.liststore1) );
    g_object_unref(properties->GtkInfo.liststore1 );

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (option_algorithms[properties->modeltype].price, renderer, "text", X1, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Expr Date", renderer, "text", X2, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    if( option_algorithms[properties->modeltype].supportStrikes )
    {
      sprintf(strike,"%s",option_algorithms[properties->modeltype].strike);
    } else
    {
      strike[0] = 0;
    }
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (strike, renderer, "text", X3, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(call,"%s",option_algorithms[properties->modeltype].call);
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (call, renderer, "text", X4, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    if(option_algorithms[properties->modeltype].supportPuts)
      sprintf(put,"%s",option_algorithms[properties->modeltype].put);
    else
      put[0] = 0;

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (put, renderer, "text", X5, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Expr Date", renderer, "text", X6, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);
  
    if( option_algorithms[properties->modeltype].supportStrikes )
    {
      sprintf(strike,"%s",option_algorithms[properties->modeltype].strike);
    } else
    {
      strike[0] = 0;
    }
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (strike, renderer, "text", X7, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    sprintf(call,"%s",option_algorithms[properties->modeltype].call);
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (call, renderer, "text", X8, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    if(option_algorithms[properties->modeltype].supportPuts)
      sprintf(put,"%s",option_algorithms[properties->modeltype].put);
    else
      put[0] = 0;

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           (put, renderer, "text", X9, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Spread C-C", renderer, "text", X10, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Spread P-P", renderer, "text", X11, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Spread C-P", renderer, "text", X12, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes
                           ("Spread P-C", renderer, "text", X13, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW (properties->GtkInfo.treeview), column);

  }
}
Ejemplo n.º 23
0
static void
gmdb_sql_execute_cb(GtkWidget *w, GladeXML *xml)
{

	guint len;
	gchar *buf;
	gchar *bound_data[256];
	int i;
	MdbSQLColumn *sqlcol;
	GtkTextBuffer *txtbuffer;
	GtkTextIter start, end;
	GtkWidget *textview, *combobox, *treeview;
	GtkTreeModel *store;
	/*GtkWidget *window;*/
	GType *gtypes;
	GtkTreeIter iter;
	GtkTreeViewColumn *column;
	long row, maxrow;
	/* GdkCursor *watch, *pointer; */

	/*  need to figure out how to clock during the treeview recalc/redraw
	window = glade_xml_get_widget(xml, "sql_window");
	watch = gdk_cursor_new(GDK_WATCH);
	gdk_window_set_cursor(GTK_WIDGET(window)->window, watch);
	gdk_cursor_unref(watch);
	*/

	/* stuff this query on the history */
	textview = glade_xml_get_widget(xml, "sql_textview");
	combobox = glade_xml_get_widget(xml, "sql_combo");
	txtbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
	len = gtk_text_buffer_get_char_count(txtbuffer);
	gtk_text_buffer_get_iter_at_offset (txtbuffer, &start, 0);
	gtk_text_buffer_get_iter_at_offset (txtbuffer, &end, len);
	buf = gtk_text_buffer_get_text(txtbuffer, &start, &end, FALSE);

	/* add to the history */
	gtk_combo_box_prepend_text(GTK_COMBO_BOX(combobox), buf);
	gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);

	/* ok now execute it */
	mdb_sql_run_query(sql, buf);
	if (mdb_sql_has_error(sql)) {
		GtkWidget* dlg = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (w)),
		    GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
		    "%s", mdb_sql_last_error(sql));
		gtk_dialog_run (GTK_DIALOG (dlg));
		gtk_widget_destroy (dlg);
		mdb_sql_reset(sql);
		return;
	}

	treeview = glade_xml_get_widget(xml, "sql_results");

	gtypes = g_malloc(sizeof(GType) * sql->num_columns);
	for (i=0;i<sql->num_columns;i++) 
		gtypes[i]=G_TYPE_STRING;

	store = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
	if (store) {
		while ((column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0))) {
			gtk_tree_view_remove_column(GTK_TREE_VIEW(treeview), column);
		}
		g_object_unref(store);
	}
	store = (GtkTreeModel*)gtk_list_store_newv(sql->num_columns, gtypes);
	g_free(gtypes);

	gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), store);
	
	GtkCellRenderer *renderer;
	renderer = gtk_cell_renderer_text_new(); 

	for (i=0;i<sql->num_columns;i++) { 
		bound_data[i] = (char *) g_malloc0(MDB_BIND_SIZE); 
        	mdb_sql_bind_column(sql, i+1, bound_data[i], NULL);
		sqlcol = g_ptr_array_index(sql->columns,i);
		column = gtk_tree_view_column_new_with_attributes(sqlcol->name, renderer, "text", i, NULL); 
		gtk_tree_view_append_column(GTK_TREE_VIEW (treeview), column); 
	}

	maxrow = gmdb_prefs_get_maxrows();

	row = 0;
	while(mdb_fetch_row(sql->cur_table) &&
			(!maxrow || (row < maxrow))) {
		row++;
		gtk_list_store_append(GTK_LIST_STORE(store), &iter);
		for (i=0;i<sql->num_columns;i++) { 
			gtk_list_store_set(GTK_LIST_STORE(store), 
				&iter, i, (gchar *) bound_data[i], -1);
		}
	}


	/* free the memory used to bind */
	for (i=0;i<sql->num_columns;i++) {
		g_free(bound_data[i]);
	}

	mdb_sql_reset(sql);
	g_free(buf);

	/*
	pointer = gdk_cursor_new(GDK_LEFT_PTR);
	gdk_window_set_cursor(GTK_WIDGET(window)->window, pointer);
	gdk_cursor_unref(pointer);
	*/
	
}
void
stf_preview_set_lines (RenderData_t *renderdata,
		       GStringChunk *lines_chunk,
		       GPtrArray *lines)
{
	unsigned int i;
	int colcount = 1;
	GnumericLazyList *ll;
	gboolean hidden;

	g_return_if_fail (renderdata != NULL);

	/* Empty the table.  */
	gtk_tree_view_set_model (renderdata->tree_view, NULL);

	if (renderdata->lines != lines) {
		if (renderdata->lines)
			stf_parse_general_free (renderdata->lines);
		renderdata->lines = lines;
	}

	if (renderdata->lines_chunk != lines_chunk) {
		if (renderdata->lines_chunk)
			g_string_chunk_free (renderdata->lines_chunk);
		renderdata->lines_chunk = lines_chunk;
	}

	if (lines == NULL)
		return;

	for (i = 0; i < lines->len; i++) {
		GPtrArray *line = g_ptr_array_index (lines, i);
		colcount = MAX (colcount, (int)line->len);
	}

	/*
	 * If we are making large changes we need to hide the treeview
	 * because performance otherwise suffers a lot.
	 */
	hidden = gtk_widget_get_visible (GTK_WIDGET (renderdata->tree_view)) &&
		(colcount < renderdata->colcount - 1 ||
		 colcount > renderdata->colcount + 10);
	if (hidden)
		gtk_widget_hide (GTK_WIDGET (renderdata->tree_view));

	while (renderdata->colcount > colcount)
               gtk_tree_view_remove_column
                       (renderdata->tree_view,
                        gtk_tree_view_get_column (renderdata->tree_view,
                                                  --(renderdata->colcount)));

	while (renderdata->colcount < colcount) {
		char *text = g_strdup_printf (_(COLUMN_CAPTION),
					      renderdata->colcount + 1);
		GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
		GtkTreeViewColumn *column =
			gtk_tree_view_column_new_with_attributes
			(text, cell,
			 "text", renderdata->colcount,
			 NULL);
		g_object_set (cell,
			      "single_paragraph_mode", TRUE,
			      NULL);
		gtk_tree_view_append_column (renderdata->tree_view, column);
		g_free (text);
		renderdata->colcount++;
	}

	ll = gnumeric_lazy_list_new (render_get_value, renderdata,
				     MIN (lines->len, LINE_DISPLAY_LIMIT),
				     0);
	gnumeric_lazy_list_add_column (ll, colcount, G_TYPE_STRING);
	gtk_tree_view_set_model (renderdata->tree_view, GTK_TREE_MODEL (ll));
	g_object_unref (ll);

	if (hidden)
		gtk_widget_show (GTK_WIDGET (renderdata->tree_view));
}
Ejemplo n.º 25
0
static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_data)
{
    dt_lib_module_t *self = (dt_lib_module_t *)user_data;
    if(!self || !(self->data)) return;

    GtkListStore *store;
    GtkTreeIter iter;
    GtkWidget *view = GTK_WIDGET(((dt_lib_modulelist_t *)self->data)->tree);
    GtkCellRenderer *pix_renderer, *fav_renderer, *text_renderer;
    GdkRGBA color;
    GtkStyleContext *context = gtk_widget_get_style_context(view);
    gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color);
    if(!color_found)
    {
        color.red = 1.0;
        color.green = 0.0;
        color.blue = 0.0;
        color.alpha = 1.0;
    }

    store = gtk_list_store_new(NUM_COLS, GDK_TYPE_PIXBUF, G_TYPE_POINTER);
    gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
    g_object_unref(store);

    gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_MODULE, _lib_modulelist_gui_sort, NULL, NULL);
    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_MODULE, GTK_SORT_ASCENDING);

    pix_renderer = gtk_cell_renderer_pixbuf_new();
    g_object_set(pix_renderer, "cell-background-rgba", &color, NULL);

    fav_renderer = gtk_cell_renderer_pixbuf_new();
    cairo_surface_t *fav_cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ICON_SIZE, ICON_SIZE);
    cairo_t *fav_cr = cairo_create(fav_cst);
    cairo_set_source_rgb(fav_cr, 0.7, 0.7, 0.7);
    dtgtk_cairo_paint_modulegroup_favorites(fav_cr, 0, 0, ICON_SIZE, ICON_SIZE, 0);
    guchar *data = cairo_image_surface_get_data(fav_cst);
    dt_draw_cairo_to_gdk_pixbuf(data, ICON_SIZE, ICON_SIZE);
    ((dt_lib_modulelist_t *)self->data)->fav_pixbuf
        = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, ICON_SIZE, ICON_SIZE,
                                   cairo_image_surface_get_stride(fav_cst), NULL, NULL);
    g_object_set(fav_renderer, "cell-background-rgba", &color, NULL);
    g_object_set(fav_renderer, "width", gdk_pixbuf_get_width(((dt_lib_modulelist_t *)self->data)->fav_pixbuf),
                 NULL);

    text_renderer = gtk_cell_renderer_text_new();
    g_object_set(text_renderer, "cell-background-rgba", &color, NULL);

    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
    gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(view), FALSE);
    GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
    gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE);

    GtkTreeViewColumn *col;
    col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 0);
    if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
    gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 0, "favorite", fav_renderer,
            favorite_renderer_function, NULL, NULL);
    col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 1);
    if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
    gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 1, "image", pix_renderer,
            image_renderer_function, NULL, NULL);
    col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 2);
    if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
    gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 2, "name", text_renderer,
            text_renderer_function, NULL, NULL);

    /* go thru list of iop modules and add them to the list */
    GList *modules = g_list_last(darktable.develop->iop);

    char datadir[PATH_MAX] = { 0 };
    dt_loc_get_datadir(datadir, sizeof(datadir));

    while(modules)
    {
        dt_iop_module_t *module = (dt_iop_module_t *)(modules->data);
        if(!dt_iop_is_hidden(module) && !(module->flags() & IOP_FLAGS_DEPRECATED) && module->multi_priority == 0)
        {
            GdkPixbuf *pixbuf;
            char filename[PATH_MAX] = { 0 };

            snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.svg", datadir, module->op);
            pixbuf = load_image(filename);
            if(pixbuf) goto end;

            snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.png", datadir, module->op);
            pixbuf = load_image(filename);
            if(pixbuf) goto end;

            snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.svg", datadir);
            pixbuf = load_image(filename);
            if(pixbuf) goto end;

            snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.png", datadir);
            pixbuf = load_image(filename);
            if(pixbuf) goto end;

            // wow, we could neither load the SVG nor the PNG files. something is f****d up.
            pixbuf = gdk_pixbuf_new_from_data(fallback_pixel, GDK_COLORSPACE_RGB, TRUE, 8, 1, 1, 4, NULL, NULL);

end:
            gtk_list_store_append(store, &iter);
            gtk_list_store_set(store, &iter, COL_IMAGE, pixbuf, COL_MODULE, module, -1);
            g_object_unref(pixbuf);
        }

        modules = g_list_previous(modules);
    }
}
Ejemplo n.º 26
0
static void
recode_dialog (PsppireDataWindow *de, gboolean diff)
{
  gint response;

  struct recode_dialog rd;

  GtkBuilder *builder = builder_new ("recode.ui");

  GtkWidget *selector = get_widget_assert (builder, "psppire-selector1");

  GtkWidget *oldandnew = get_widget_assert (builder, "button1");


  GtkWidget *output_variable_box = get_widget_assert (builder,"frame4");

  PsppireVarStore *vs = NULL;
  g_object_get (de->data_editor, "var-store", &vs, NULL);

  rd.change_button = get_widget_assert (builder, "change-button");
  rd.varmap = NULL;
  rd.dialog = get_widget_assert   (builder, "recode-dialog");
  rd.dict_treeview = get_widget_assert (builder, "treeview1");
  rd.variable_treeview =   get_widget_assert (builder, "treeview2");
  rd.new_name_entry = get_widget_assert (builder, "dest-name-entry");
  rd.new_label_entry = get_widget_assert (builder, "dest-label-entry");

  g_object_get (vs, "dictionary", &rd.dict, NULL);

  rd.value_map = gtk_list_store_new (2,
				     old_value_get_type (),
				     new_value_get_type ()
				     );

  g_object_set (output_variable_box, "visible", diff, NULL);

  if ( diff )
    gtk_window_set_title (GTK_WINDOW (rd.dialog),
			  _("Recode into Different Variables"));
  else
    gtk_window_set_title (GTK_WINDOW (rd.dialog),
			  _("Recode into Same Variables"));

  rd.different = diff;

  gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), GTK_WINDOW (de));

  g_object_set (rd.dict_treeview, "model", rd.dict, NULL);

  if (rd.different)
    {
      GtkTreeSelection *sel;

      GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();

      GtkTreeViewColumn *col = gtk_tree_view_column_new_with_attributes (_("New"),
									 renderer,
									 "text", NULL,
									 NULL);

      gtk_tree_view_column_set_cell_data_func (col, renderer,
					       render_new_var_name,
					       &rd, NULL);


      gtk_tree_view_append_column (GTK_TREE_VIEW (rd.variable_treeview), col);


      col = gtk_tree_view_get_column (GTK_TREE_VIEW (rd.variable_treeview), 0);

      g_object_set (col, "title", _("Old"), NULL);

      g_object_set (rd.variable_treeview, "headers-visible", TRUE, NULL);

      rd.varmap = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, nlp_destroy);

      sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (rd.variable_treeview));

      g_signal_connect (sel, "changed",
			G_CALLBACK (on_selection_change), &rd);

      g_signal_connect (rd.change_button, "clicked",
			G_CALLBACK (on_change_clicked),  &rd);

    }

  psppire_selector_set_allow (PSPPIRE_SELECTOR (selector), homogeneous_types);

  /* Set up the Old & New Values subdialog */
  {
    rd.string_button = get_widget_assert (builder, "checkbutton1");
    rd.width_entry   = get_widget_assert (builder, "spinbutton1");

    rd.convert_button           = get_widget_assert (builder, "checkbutton2");

    rd.old_value_chooser = get_widget_assert (builder, "val-chooser");

    rd.new_value_entry = get_widget_assert (builder, "entry1");


    rd.toggle[BUTTON_NEW_VALUE]  = get_widget_assert (builder, "radiobutton1");
    rd.toggle[BUTTON_NEW_SYSMIS] = get_widget_assert (builder, "radiobutton2");
    rd.toggle[BUTTON_NEW_COPY]   = get_widget_assert (builder, "radiobutton3");

    rd.new_copy_label = get_widget_assert (builder, "label3");
    rd.strings_box    = get_widget_assert (builder, "table3");

    rd.old_and_new_dialog =
      PSPPIRE_DIALOG (get_widget_assert (builder, "old-new-values-dialog"));

    gtk_window_set_transient_for (GTK_WINDOW (rd.old_and_new_dialog),
				  GTK_WINDOW (de));

    rd.acr = PSPPIRE_ACR (get_widget_assert (builder, "psppire-acr1"));

    g_signal_connect_swapped (rd.toggle[BUTTON_NEW_VALUE], "toggled",
		      G_CALLBACK (set_acr), &rd);

    g_signal_connect_swapped (rd.new_value_entry, "changed",
		      G_CALLBACK (set_acr), &rd);

    {
      GtkTreeSelection *sel;
      /* Remove the ACR's default column.  We don't like it */
      GtkTreeViewColumn *column = gtk_tree_view_get_column (rd.acr->tv, 0);
      gtk_tree_view_remove_column (rd.acr->tv, column);


      column =
	gtk_tree_view_column_new_with_attributes (_("Old"),
						  gtk_cell_renderer_text_new (),
						  "text", 0,
						  NULL);

      gtk_tree_view_append_column (rd.acr->tv, column);

      column =
	gtk_tree_view_column_new_with_attributes (_("New"),
						  gtk_cell_renderer_text_new (),
						  "text", 1,
						  NULL);

      gtk_tree_view_append_column (rd.acr->tv, column);
      g_object_set (rd.acr->tv, "headers-visible", TRUE, NULL);


      sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (rd.acr->tv));
      g_signal_connect (sel, "changed",
			G_CALLBACK (on_acr_selection_change), &rd);
    }


    g_signal_connect_swapped (oldandnew, "clicked",
			      G_CALLBACK (run_old_and_new_dialog), &rd);


    g_signal_connect (rd.toggle[BUTTON_NEW_VALUE], "toggled",
		      G_CALLBACK (toggle_sensitivity), rd.new_value_entry);

    g_signal_connect (rd.string_button, "toggled",
		      G_CALLBACK (toggle_sensitivity), rd.width_entry);

    g_signal_connect (rd.string_button, "toggled",
		      G_CALLBACK (on_string_toggled), &rd);

    g_signal_connect (rd.convert_button, "toggled",
		      G_CALLBACK (on_convert_toggled), &rd);

    g_signal_connect_swapped (rd.old_and_new_dialog, "show",
			      G_CALLBACK (on_old_new_show), &rd);
  }

  g_signal_connect (rd.dialog, "refresh", G_CALLBACK (refresh),  &rd);


  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (rd.dialog),
				      dialog_state_valid, &rd);

  response = psppire_dialog_run (PSPPIRE_DIALOG (rd.dialog));

  switch (response)
    {
    case GTK_RESPONSE_OK:
      g_free (execute_syntax_string (de, generate_syntax (&rd)));
      break;
    case PSPPIRE_RESPONSE_PASTE:
      g_free (paste_syntax_to_window (generate_syntax (&rd)));
      break;
    default:
      break;
    }

  if (rd.varmap)
    g_hash_table_destroy (rd.varmap);

  gtk_list_store_clear (GTK_LIST_STORE (rd.value_map));
  g_object_unref (rd.value_map);

  g_object_unref (builder);
}
Ejemplo n.º 27
0
static void
set_columns_type (GtkTreeView *tree_view, ColumnsType type)
{
  GtkTreeViewColumn *col;
  GtkCellRenderer *rend;
  GdkPixbuf *pixbuf;
  GtkWidget *image;
  GtkAdjustment *adjustment;

  current_column_type = type;
  
  col = gtk_tree_view_get_column (tree_view, 0);
  while (col)
    {
      gtk_tree_view_remove_column (tree_view, col);

      col = gtk_tree_view_get_column (tree_view, 0);
    }

  gtk_tree_view_set_rules_hint (tree_view, FALSE);
  
  switch (type)
    {
    case COLUMNS_NONE:
      break;

    case COLUMNS_LOTS:
      /* with lots of columns we need to turn on rules */
      gtk_tree_view_set_rules_hint (tree_view, TRUE);
      
      rend = gtk_cell_renderer_text_new ();

      col = gtk_tree_view_column_new_with_attributes ("Column 1",
                                                      rend,
                                                      "text", 1,
                                                      NULL);
      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
      
      col = gtk_tree_view_column_new();
      gtk_tree_view_column_set_title (col, "Column 2");
      
      rend = gtk_cell_renderer_pixbuf_new ();
      gtk_tree_view_column_pack_start (col, rend, FALSE);
      gtk_tree_view_column_add_attribute (col, rend, "pixbuf", 2);
      rend = gtk_cell_renderer_text_new ();
      gtk_tree_view_column_pack_start (col, rend, TRUE);
      gtk_tree_view_column_add_attribute (col, rend, "text", 0);

      setup_column (col);
      
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
      gtk_tree_view_set_expander_column (tree_view, col);
      
      rend = gtk_cell_renderer_toggle_new ();

      g_signal_connect (rend, "toggled",
			G_CALLBACK (toggled_callback), tree_view);
      
      col = gtk_tree_view_column_new_with_attributes ("Column 3",
                                                      rend,
                                                      "active", BOOL_COLUMN,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);

      pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **)book_closed_xpm);

      image = gtk_image_new_from_pixbuf (pixbuf);

      g_object_unref (pixbuf);
      
      gtk_widget_show (image);
      
      gtk_tree_view_column_set_widget (col, image);
      
      rend = gtk_cell_renderer_toggle_new ();

      /* you could also set this per-row by tying it to a column
       * in the model of course.
       */
      g_object_set (rend, "radio", TRUE, NULL);
      
      g_signal_connect (rend, "toggled",
			G_CALLBACK (toggled_callback), tree_view);
      
      col = gtk_tree_view_column_new_with_attributes ("Column 4",
                                                      rend,
                                                      "active", BOOL_COLUMN,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);

      rend = gtk_cell_renderer_spin_new ();

      adjustment = gtk_adjustment_new (0, 0, 10000, 100, 100, 100);
      g_object_set (rend, "editable", TRUE, NULL);
      g_object_set (rend, "adjustment", adjustment, NULL);

      g_signal_connect (rend, "edited",
			G_CALLBACK (edited_callback), tree_view);

      col = gtk_tree_view_column_new_with_attributes ("Column 5",
                                                      rend,
                                                      "text", 4,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
#if 0
      
      rend = gtk_cell_renderer_text_new ();
      
      col = gtk_tree_view_column_new_with_attributes ("Column 6",
                                                      rend,
                                                      "text", 4,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
      
      rend = gtk_cell_renderer_text_new ();
      
      col = gtk_tree_view_column_new_with_attributes ("Column 7",
                                                      rend,
                                                      "text", 5,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
      
      rend = gtk_cell_renderer_text_new ();
      
      col = gtk_tree_view_column_new_with_attributes ("Column 8",
                                                      rend,
                                                      "text", 6,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
      
      rend = gtk_cell_renderer_text_new ();
      
      col = gtk_tree_view_column_new_with_attributes ("Column 9",
                                                      rend,
                                                      "text", 7,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
      
      rend = gtk_cell_renderer_text_new ();
      
      col = gtk_tree_view_column_new_with_attributes ("Column 10",
                                                      rend,
                                                      "text", 8,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
      
#endif
      
      /* FALL THRU */
      
    case COLUMNS_ONE:
      rend = gtk_cell_renderer_text_new ();
      
      col = gtk_tree_view_column_new_with_attributes ("Column 0",
                                                      rend,
                                                      "text", 0,
                                                      NULL);

      setup_column (col);
      
      gtk_tree_view_insert_column (GTK_TREE_VIEW (tree_view), col, 0);
    default:
      break;
    }
}
Ejemplo n.º 28
0
static void
gwy_graph_data_update_ncurves(GwyGraphData *graph_data)
{
    GwyGraphDataCurve *curve;
    GtkTreeView *treeview;
    GtkTreeViewColumn *column;
    GtkWidget *table, *label;
    guint i, ncolumns, ncurves = 0;

    ncolumns = graph_data->curves->len;
    gwy_debug("old ncurves: %d", ncolumns);

    /* Reconnect all signals just to be sure.
     * GraphModel is a bit cagey when changes in its curves are regarded */
    for (i = 0; i < graph_data->curves->len; i++) {
        curve = &g_array_index(graph_data->curves, GwyGraphDataCurve, i);
        gwy_signal_handler_disconnect(curve->gcmodel, curve->changed_id);
        gwy_object_unref(curve->gcmodel);
    }
    g_array_set_size(graph_data->curves, 0);

    if (graph_data->graph_model) {
        GwyGraphDataCurve newcurve;

        ncurves = gwy_graph_model_get_n_curves(graph_data->graph_model);
        for (i = 0; i < ncurves; i++) {
            newcurve.gcmodel
                = gwy_graph_model_get_curve(graph_data->graph_model, i);
            g_object_ref(newcurve.gcmodel);
            newcurve.changed_id = g_signal_connect_swapped
                                      (newcurve.gcmodel, "data-changed",
                                       G_CALLBACK(gwy_graph_data_update_nrows),
                                       graph_data);
            g_array_append_val(graph_data->curves, newcurve);
        }
    }
    gwy_debug("ncurves: %d", ncurves);

    /* Update the number of columns. */
    treeview = GTK_TREE_VIEW(graph_data);

    while (ncolumns > ncurves) {
        ncolumns--;
        gwy_debug("removing column %d", ncolumns);
        column = gtk_tree_view_get_column(treeview, ncolumns);
        gtk_tree_view_remove_column(treeview, column);
    }

    while (ncolumns < ncurves) {
        GtkRequisition req;
        GtkWidget *align;

        gwy_debug("adding column %d", ncolumns);
        column = gtk_tree_view_column_new();
        g_object_set_qdata(G_OBJECT(column), quark_id,
                           GINT_TO_POINTER(ncolumns));

        gwy_graph_data_pack_renderer(graph_data, column, 0);
        gwy_graph_data_pack_renderer(graph_data, column, 1);

        table = gtk_table_new(2, 2, TRUE);
        label = gtk_label_new(NULL);
        gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 0, 1);
        label = gtk_label_new(NULL);
        gtk_label_set_width_chars(GTK_LABEL(label), COL_WIDTH);
        gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
        label = gtk_label_new(NULL);
        gtk_label_set_width_chars(GTK_LABEL(label), COL_WIDTH);
        gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 1, 2);
        gtk_widget_show_all(table);
        gtk_tree_view_column_set_widget(column, table);

        gtk_widget_size_request(table, &req);

        g_object_set(column,
                     "sizing", GTK_TREE_VIEW_COLUMN_FIXED,
                     "fixed-width", req.width,
                     NULL);
        gtk_tree_view_append_column(treeview, column);

        align = gtk_widget_get_parent(table);
        /* XXX: The alignment is Gtk+'s private widget. */
        if (align && GTK_IS_ALIGNMENT(align)) {
            g_signal_connect(align, "notify::xscale",
                             G_CALLBACK(fix_xscale), NULL);
            fix_xscale(align);
        }

        ncolumns++;
    }

    if (graph_data->graph_model)
        gwy_graph_data_update_headers(graph_data);

    if (graph_data->store)
        gwy_graph_data_update_nrows(graph_data);
}