void cl_set_corner_sharpness (const gchar *detail, GtkWidget *widget, CLRectangle *r)
{
	if (widget->parent && GTK_IS_COMBO_BOX_ENTRY (widget->parent) || GTK_IS_COMBO (widget->parent))
	{
		gboolean rtl = get_direction (widget->parent) == GTK_TEXT_DIR_RTL;
		int cl = rtl ? CL_CORNER_ROUND : CL_CORNER_NONE;
		int cr = rtl ? CL_CORNER_NONE  : CL_CORNER_ROUND;
		
		cl_rectangle_set_corners (r, cl, cr, cl, cr);
	}
	else if (detail && !strcmp (detail, "spinbutton_up"))
	{
		gboolean rtl = get_direction (widget->parent) == GTK_TEXT_DIR_RTL;
		int tl = rtl ? CL_CORNER_ROUND : CL_CORNER_NONE;
		int tr = rtl ? CL_CORNER_NONE  : CL_CORNER_ROUND;

		cl_rectangle_set_corners (r, tl, tr,
		                          CL_CORNER_NONE, CL_CORNER_NONE);
	}
	else if (detail && !strcmp (detail, "spinbutton_down"))
	{
		gboolean rtl = get_direction (widget->parent) == GTK_TEXT_DIR_RTL;
		int bl = rtl ? CL_CORNER_ROUND : CL_CORNER_NONE;
		int br = rtl ? CL_CORNER_NONE  : CL_CORNER_ROUND;

		cl_rectangle_set_corners (r, CL_CORNER_NONE, CL_CORNER_NONE,
		                          bl, br);
	}
	else
	{
		cl_rectangle_set_corners (r, CL_CORNER_ROUND, CL_CORNER_ROUND,
		                          CL_CORNER_ROUND, CL_CORNER_ROUND);
	};
}
Exemple #2
0
static void
gail_combo_box_real_initialize (AtkObject *obj,
                                gpointer  data)
{
  GtkComboBox *combo_box;
  GailComboBox *gail_combo_box;
  AtkObject *popup;

  ATK_OBJECT_CLASS (gail_combo_box_parent_class)->initialize (obj, data);

  combo_box = GTK_COMBO_BOX (data);

  gail_combo_box = GAIL_COMBO_BOX (obj);

  g_signal_connect (combo_box,
                    "changed",
                    G_CALLBACK (gail_combo_box_changed_gtk),
                    NULL);
  gail_combo_box->old_selection = gtk_combo_box_get_active (combo_box);

  popup = gtk_combo_box_get_popup_accessible (combo_box);
  if (popup)
    {
      atk_object_set_parent (popup, obj);
      gail_combo_box->popup_set = TRUE;
    }
  if (GTK_IS_COMBO_BOX_ENTRY (combo_box))
    atk_object_set_parent (gtk_widget_get_accessible (gtk_bin_get_child (GTK_BIN (combo_box))), obj);

  obj->role = ATK_ROLE_COMBO_BOX;
}
Exemple #3
0
static void
widget_fixups (GtkWidget *widget)
{
  /* post-constructor for widgets that need additional settings to work correctly */
  if (GTK_IS_COMBO_BOX_ENTRY (widget))
    {
      GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
      g_object_set (widget, "model", store, "text-column", 0, NULL);
      g_object_unref (store);
      gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "test text");
    }
  else if (GTK_IS_COMBO_BOX (widget))
    {
      GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
      g_object_set (widget, "model", store, NULL);
      g_object_unref (store);
      gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "test text");
    }
}
Exemple #4
0
/*
 * The children of a GailComboBox are the list of items and the entry field
 * if it is editable.
 */
static gint
gail_combo_box_get_n_children (AtkObject* obj)
{
  gint n_children = 0;
  GtkWidget *widget;

  g_return_val_if_fail (GAIL_IS_COMBO_BOX (obj), 0);

  widget = GTK_ACCESSIBLE (obj)->widget;
  if (widget == NULL)
    /*
     * State is defunct
     */
    return 0;

  n_children++;
  if (GTK_IS_COMBO_BOX_ENTRY (widget))
    n_children ++;

  return n_children;
}
Exemple #5
0
static const char *getActiveValue( GtkComboBox *comboBox )
{
   const char *val = NULL;
   if( GTK_IS_COMBO_BOX_ENTRY( comboBox ) )
   {
      val = gtk_entry_get_text( getEntry( comboBox ) );
   }
   else
   {
      const int active  = gtk_combo_box_get_active( comboBox );
      if( active > -1 )
      {
         GtkTreePath  *path  = gtk_tree_path_new_from_indices( active, -1 );
         GtkTreeModel *model = gtk_combo_box_get_model( comboBox );
         GtkTreeIter  iter;
         gtk_tree_model_get_iter( model, &iter, path );
         gtk_tree_path_free( path );
         gtk_tree_model_get( model, &iter, VALUE_COLUMN, &val, -1 );
      }
   }
   return val;
}
Exemple #6
0
static AtkObject*
gail_combo_box_ref_child (AtkObject *obj,
                          gint      i)
{
  GtkWidget *widget;
  AtkObject *child;
  GailComboBox *box;

  g_return_val_if_fail (GAIL_IS_COMBO_BOX (obj), NULL);

  widget = GTK_ACCESSIBLE (obj)->widget;

  if (widget == NULL)
    /*
     * State is defunct
     */
    return NULL;

  if (i == 0)
    {
      child = gtk_combo_box_get_popup_accessible (GTK_COMBO_BOX (widget));
      box = GAIL_COMBO_BOX (obj);
      if (box->popup_set == FALSE)
        {
          atk_object_set_parent (child, obj);
          box->popup_set = TRUE;
        }
    }
  else if (i == 1 && GTK_IS_COMBO_BOX_ENTRY (widget))
    {
      child = gtk_widget_get_accessible (gtk_bin_get_child (GTK_BIN (widget)));
    }
  else
    {
      return NULL;
    }
  return g_object_ref (child);
}
Exemple #7
0
static int setState( ComboParams *para, const char *val )
{
   GObject *sigObj = getSigObj( para->comboBox );
   int n = 0;
   int blocked = g_signal_handlers_block_matched( 
         sigObj, G_SIGNAL_MATCH_FUNC,
         0, 0, NULL, (void *)changedFunc, NULL );

   if( GTK_IS_COMBO_BOX_ENTRY( para->comboBox ) )
      gtk_entry_set_text( getEntry( para->comboBox ), val );
   else
   {
      n = findItemFromValue( para->comboBox, val );
      if( n >= 0 )
         gtk_combo_box_set_active( para->comboBox, n );
   }

   if( blocked )
      g_signal_handlers_unblock_matched( 
            sigObj, G_SIGNAL_MATCH_FUNC, 
            0, 0, NULL, (void *)changedFunc, NULL );

   return n;
}
Exemple #8
0
static GObject *getSigObj( GtkComboBox *comboBox )
{
   return GTK_IS_COMBO_BOX_ENTRY( comboBox ) 
         ? G_OBJECT( getEntry( comboBox ) ) 
         : G_OBJECT( comboBox );
}
Exemple #9
0
/*!
  \brief sets up and populates the MS2-Extra combo for output choice
  \param widget is the pointer to the combo to initialize
  */
G_MODULE_EXPORT void ms2_output_combo_setup(GtkWidget *widget)
{
	guint i = 0;
	GtkWidget *parent = NULL;
	gchar * lower = NULL;
	gchar * upper = NULL;
	gfloat * multiplier = NULL;
	gfloat * adder = NULL;
	gfloat * testmult = NULL;
	gchar * range = NULL;
	gint bitval = 0;
	gint width = 0;
	DataSize size = MTX_U08;
	gint precision = 0;
	gconstpointer * object = NULL;
	gint raw_lower = 0;
	gint raw_upper = 0;
	gboolean freelower = FALSE;
	gboolean freeupper = FALSE;
	gchar *raw_lower_str = NULL;
	gchar *raw_upper_str = NULL;
	gfloat real_lower = 0.0;
	gfloat real_upper = 0.0;
	gfloat tmpf = 0.0;
	gchar * name = NULL;
	gchar *internal_names = NULL;
	GtkWidget *entry = NULL;
	GtkEntryCompletion *completion = NULL;
	GtkListStore *store = NULL;
	GtkTreeIter iter;

	ENTER();
	Rtv_Map *rtv_map = NULL;

	rtv_map = (Rtv_Map *)DATA_GET(global_data,"rtv_map");

	if (!rtv_map)
	{
		EXIT();
		return;
	}
	/* Create the store for the combo, with severla hidden values
	 */
	store = gtk_list_store_new(UO_COMBO_COLS,G_TYPE_STRING,G_TYPE_UCHAR,G_TYPE_POINTER,G_TYPE_POINTER,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UCHAR,G_TYPE_UCHAR);

	/* Iterate across valid variables */
	for (i=0;i<rtv_map->rtv_list->len;i++)
	{
		freelower = FALSE;
		freeupper = FALSE;
		object = NULL;
		name = NULL;
		object = (gconstpointer *)g_ptr_array_index(rtv_map->rtv_list,i);
		if (!object)
			continue;
		name = (gchar *) DATA_GET(object,"dlog_gui_name");
		if (!name)
			continue;
		if (DATA_GET(object,"fromecu_complex"))
			continue;
		if (DATA_GET(object,"special"))
			continue;
		internal_names = (gchar *) DATA_GET(object,"internal_names");
		if (!find_in_list(rtv_map->raw_list,internal_names))
			continue;

		size = (DataSize)(GINT)DATA_GET(object,"size");
		multiplier = (gfloat *)DATA_GET(object,"fromecu_mult");
		adder = (gfloat *)DATA_GET(object,"fromecu_add");
		precision = (GINT) DATA_GET(object,"precision");
		bitval = (GINT) DATA_GET(object,"offset");
		if (DATA_GET(object,"real_lower"))
		{
			lower = (gchar *)DATA_GET(object,"real_lower");
			real_lower = g_strtod(lower,NULL);
			raw_lower = calc_value_f(real_lower,multiplier,adder,TOECU);
		}
		else
		{
			raw_lower = get_extreme_from_size_f(size,LOWER);
			tmpf = calc_value_f(raw_lower,multiplier,adder,FROMECU);
			lower = g_strdup_printf("%i",(gint)tmpf);
			freelower = TRUE;
		}
		if (DATA_GET(object,"real_upper"))
		{
			upper = (gchar *)DATA_GET(object,"real_upper");
			real_upper = g_strtod(upper,NULL);
			raw_upper = calc_value_f(real_upper,multiplier,adder,TOECU);
		}
		else
		{
			raw_upper = get_extreme_from_size_f(size,UPPER);
			tmpf = calc_value_f(raw_upper,multiplier,adder,FROMECU);
			upper = g_strdup_printf("%i",(gint)tmpf);
			freeupper = TRUE;
		}
		range = g_strdup_printf("Valid Range: %s <-> %s",lower,upper);
		if (freelower)
			g_free(lower);
		if (freeupper)
			g_free(upper);
		if ((multiplier) && (adder))
		{
			raw_lower = (GINT)((real_lower - (*adder))/(*multiplier));
			raw_upper = (GINT)((real_upper - (*adder))/(*multiplier));
		}
		else if (multiplier)
		{
			raw_lower = (GINT)(real_lower/(*multiplier));
			raw_upper = (GINT)(real_upper/(*multiplier));
		}
		else
		{
			raw_lower = (GINT)real_lower;
			raw_upper = (GINT)real_upper;
		}
		raw_lower_str = g_strdup_printf("%i",raw_lower);
		raw_upper_str = g_strdup_printf("%i",raw_upper);

		gtk_list_store_append(store,&iter);
		gtk_list_store_set(store,&iter,
				UO_CHOICE_COL,name,
				UO_BITVAL_COL,bitval,
				UO_FROMECU_MULT_COL,multiplier,
				UO_FROMECU_ADD_COL,adder,
				UO_RAW_LOWER_COL,raw_lower_str,
				UO_RAW_UPPER_COL,raw_upper_str,
				UO_RANGE_COL,range,
				UO_SIZE_COL,size,
				UO_PRECISION_COL,precision,
				-1);
		g_free(raw_lower_str);
		g_free(raw_upper_str);
		g_free(range);
	}
/*#if GTK_MINOR_VERSION < 24 */
	if (GTK_IS_COMBO_BOX_ENTRY(widget))
	{
		gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(widget),UO_CHOICE_COL);
/*
#else
	if (GTK_IS_COMBO_BOX(widget))
	{
		gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(widget),UO_CHOICE_COL);
#endif
*/
		gtk_combo_box_set_model(GTK_COMBO_BOX(widget),GTK_TREE_MODEL(store));
		g_object_unref(store);
		entry = gtk_bin_get_child(GTK_BIN(widget));
		/* Nasty hack, but otherwise the entry is an obnoxious size.. */
		if ((width = (GINT)OBJ_GET((GtkWidget *)widget,"max_chars")) > 0)
			gtk_entry_set_width_chars(GTK_ENTRY(entry),width);
		else
			gtk_entry_set_width_chars(GTK_ENTRY(entry),12);

		gtk_widget_set_size_request(GTK_WIDGET(widget),-1,(3*(GINT)DATA_GET(global_data,"font_size")));

//		gtk_container_remove (GTK_CONTAINER (widget), gtk_bin_get_child(GTK_BIN(widget)));
//		gtk_container_add (GTK_CONTAINER (widget), entry);

		completion = gtk_entry_completion_new();
		gtk_entry_set_completion(GTK_ENTRY(entry),completion);
		g_object_unref(completion);
		gtk_entry_completion_set_model(completion,GTK_TREE_MODEL(store));
		gtk_entry_completion_set_text_column(completion,UO_CHOICE_COL);
		gtk_entry_completion_set_inline_completion(completion,TRUE);
		gtk_entry_completion_set_inline_selection(completion,TRUE);
		gtk_entry_completion_set_popup_single_match(completion,FALSE);
		OBJ_SET(widget,"arrow-size",GINT_TO_POINTER(1));
	}
	EXIT();
	return;
}
Exemple #10
0
/**
 * na_gtk_utils_set_editable:
 * @widget: the #GtkWdiget.
 * @editable: whether the @widget is editable or not.
 *
 * Try to set a visual indication of whether the @widget is editable or not.
 *
 * Having a GtkWidget should be enough, but we also deal with a GtkTreeViewColumn.
 * So the most-bottom common ancestor is just GObject (since GtkObject having been
 * deprecated in Gtk+-3.0)
 *
 * Note that using 'sensitivity' property is just a work-around because the
 * two things have distinct semantics:
 * - editable: whether we are allowed to modify the value (is not read-only)
 * - sensitive: whether the value is relevant (has a sense in this context)
 */
void
na_gtk_utils_set_editable( GObject *widget, gboolean editable )
{
	GList *renderers, *irender;

/* GtkComboBoxEntry is deprecated from Gtk+3
 * see. http://git.gnome.org/browse/gtk+/commit/?id=9612c648176378bf237ad0e1a8c6c995b0ca7c61
 * while 'has_entry' property exists since 2.24
 */
#if GTK_CHECK_VERSION( 2,24,0 )
	if( GTK_IS_COMBO_BOX( widget ) && gtk_combo_box_get_has_entry( GTK_COMBO_BOX( widget ))){
#else
	if( GTK_IS_COMBO_BOX_ENTRY( widget )){
#endif
		/* idem as GtkEntry */
		gtk_editable_set_editable( GTK_EDITABLE( gtk_bin_get_child( GTK_BIN( widget ))), editable );
		g_object_set( G_OBJECT( gtk_bin_get_child( GTK_BIN( widget ))), "can-focus", editable, NULL );
		/* disable the listbox button itself */
		gtk_combo_box_set_button_sensitivity( GTK_COMBO_BOX( widget ), editable ? GTK_SENSITIVITY_ON : GTK_SENSITIVITY_OFF );

	} else if( GTK_IS_COMBO_BOX( widget )){
		/* disable the listbox button itself */
		gtk_combo_box_set_button_sensitivity( GTK_COMBO_BOX( widget ), editable ? GTK_SENSITIVITY_ON : GTK_SENSITIVITY_OFF );

	} else if( GTK_IS_ENTRY( widget )){
		gtk_editable_set_editable( GTK_EDITABLE( widget ), editable );
		/* removing the frame leads to a disturbing modification of the
		 * height of the control */
		/*g_object_set( G_OBJECT( widget ), "has-frame", editable, NULL );*/
		/* this prevents the caret to be displayed when we click in the entry */
		g_object_set( G_OBJECT( widget ), "can-focus", editable, NULL );

	} else if( GTK_IS_TEXT_VIEW( widget )){
		g_object_set( G_OBJECT( widget ), "can-focus", editable, NULL );
		gtk_text_view_set_editable( GTK_TEXT_VIEW( widget ), editable );

	} else if( GTK_IS_TOGGLE_BUTTON( widget )){
		/* transforms to a quasi standard GtkButton */
		/*g_object_set( G_OBJECT( widget ), "draw-indicator", editable, NULL );*/
		/* this at least prevent the keyboard focus to go to the button
		 * (which is better than nothing) */
		g_object_set( G_OBJECT( widget ), "can-focus", editable, NULL );

	} else if( GTK_IS_TREE_VIEW_COLUMN( widget )){
		renderers = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( GTK_TREE_VIEW_COLUMN( widget )));
		for( irender = renderers ; irender ; irender = irender->next ){
			if( GTK_IS_CELL_RENDERER_TEXT( irender->data )){
				g_object_set( G_OBJECT( irender->data ), "editable", editable, "editable-set", TRUE, NULL );
			}
		}
		g_list_free( renderers );

	} else if( GTK_IS_BUTTON( widget )){
		gtk_widget_set_sensitive( GTK_WIDGET( widget ), editable );
	}
}

/**
 * na_gtk_utils_radio_set_initial_state:
 * @button: the #GtkRadioButton button which is initially active.
 * @handler: the corresponding "toggled" handler.
 * @user_data: the user data associated to the handler.
 * @editable: whether this radio button group is editable.
 * @sensitive: whether this radio button group is sensitive.
 *
 * This function should be called for the button which is initially active
 * inside of a radio button group when the radio group may happen to not be
 * editable.
 * This function should be called only once for the radio button group.
 *
 * It does the following operations:
 * - set the button as active
 * - set other buttons of the radio button group as icactive
 * - set all buttons of radio button group as @editable
 *
 * The initially active @button, along with its @handler, are recorded
 * as properties of the radio button group (actually as properties of each
 * radio button of the group), so that they can later be used to reset the
 * initial state.
 */
void
na_gtk_utils_radio_set_initial_state( GtkRadioButton *button,
		GCallback handler, void *user_data, gboolean editable, gboolean sensitive )
{
	GSList *group, *ig;
	GtkRadioButton *other;

	group = gtk_radio_button_get_group( button );

	for( ig = group ; ig ; ig = ig->next ){
		other = GTK_RADIO_BUTTON( ig->data );
		g_object_set_data( G_OBJECT( other ), NA_TOGGLE_DATA_BUTTON, button );
		g_object_set_data( G_OBJECT( other ), NA_TOGGLE_DATA_HANDLER, handler );
		g_object_set_data( G_OBJECT( other ), NA_TOGGLE_DATA_USER_DATA, user_data );
		g_object_set_data( G_OBJECT( other ), NA_TOGGLE_DATA_EDITABLE, GUINT_TO_POINTER( editable ));
		na_gtk_utils_set_editable( G_OBJECT( other ), editable );
		gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( other ), FALSE );
		gtk_widget_set_sensitive( GTK_WIDGET( other ), sensitive );
	}

	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
}
Exemple #11
0
/*!
  \brief sets up and populates the MS2-Extra combo for output choice
  \param widget is the pointer to the combo to initialize
  */
G_MODULE_EXPORT void ms2_output_combo_setup(GtkWidget *widget)
{
	guint i = 0;
	GtkWidget *parent = NULL;
	gchar * lower = NULL;
	gchar * upper = NULL;
	gfloat * multiplier = NULL;
	gfloat * adder = NULL;
	gfloat * testmult = NULL;
	gchar * range = NULL;
	gint bitval = 0;
	gint width = 0;
	DataSize size = MTX_U08;
	gint precision = 0;
	gconstpointer * object = NULL;
	gint raw_lower = 0;
	gint raw_upper = 0;
	gboolean temp_dep = FALSE;
	gchar *raw_lower_str = NULL;
	gchar *raw_upper_str = NULL;
	gchar *tempc_range = NULL;
	gchar *tempf_range = NULL;
	gchar *tempk_range = NULL;
	gfloat real_lower = 0.0;
	gfloat real_upper = 0.0;
	gfloat tmpf = 0.0;
	gchar * name = NULL;
	gchar *internal_names = NULL;
	GtkWidget *entry = NULL;
	GtkEntryCompletion *completion = NULL;
	GtkListStore *store = NULL;
	GtkTreeIter iter;

	ENTER();
	Rtv_Map *rtv_map = NULL;

	rtv_map = (Rtv_Map *)DATA_GET(global_data,"rtv_map");

	if (!rtv_map)
	{
		EXIT();
		return;
	}
	/* Create the store for the combo, with severla hidden values
	*/
	store = gtk_list_store_new(UO_COMBO_COLS,
			G_TYPE_STRING,	/* Choice */
			G_TYPE_UCHAR,	/* BITval */
			G_TYPE_POINTER,	/* FromECU Multiplier (gfloat *) */
			G_TYPE_POINTER,	/* FromECU Adder (gfloat *) */
			G_TYPE_STRING,	/* Raw Lower clamp limit */
			G_TYPE_STRING,	/* Raw Upper clamp limit */
			G_TYPE_STRING,	/* Range widget string (non temp ctrls) */
			G_TYPE_STRING,	/* Range widget string (Celsius) */
			G_TYPE_STRING,	/* Range widget string (Fahrenheit) */
			G_TYPE_STRING,	/* Range widget string (Kelvin) */
			G_TYPE_INT,		/* Size enumeration (_U08_, _U16_, etc.) */
			G_TYPE_UCHAR,	/* Precision (floating point precision) */
			G_TYPE_BOOLEAN);/* Temp dependent flag */

	/* Iterate across valid variables */
	for (i=0;i<rtv_map->rtv_list->len;i++)
	{
		object = NULL;
		name = NULL;
		object = (gconstpointer *)g_ptr_array_index(rtv_map->rtv_list,i);
		if (!object)
			continue;
		name = (gchar *) DATA_GET(object,"dlog_gui_name");
		if (!name)
			continue;
		if (DATA_GET(object,"fromecu_complex"))
			continue;
		if (DATA_GET(object,"special"))
			continue;
		internal_names = (gchar *) DATA_GET(object,"internal_names");
		if (!find_in_list(rtv_map->raw_list,internal_names))
			continue;

		temp_dep = (GBOOLEAN)DATA_GET(object,"temp_dep");
		size = (DataSize)(GINT)DATA_GET(object,"size");
		multiplier = (gfloat *)DATA_GET(object,"fromecu_mult");
		adder = (gfloat *)DATA_GET(object,"fromecu_add");
		precision = (GINT) DATA_GET(object,"precision");
		bitval = (GINT) DATA_GET(object,"offset");
		if (DATA_GET(object,"real_lower"))
		{
			lower = (gchar *)DATA_GET(object,"real_lower");
			real_lower = g_strtod(lower,NULL);
			raw_lower = calc_value_f(real_lower,multiplier,adder,TOECU);
		}
		else
			raw_lower = get_extreme_from_size_f(size,LOWER);
		if (DATA_GET(object,"real_upper"))
		{
			upper = (gchar *)DATA_GET(object,"real_upper");
			real_upper = g_strtod(upper,NULL);
			raw_upper = calc_value_f(real_upper,multiplier,adder,TOECU);
		}
		else
			raw_upper = get_extreme_from_size_f(size,UPPER);

		range = g_strdup_printf("Valid Range: %.1f <-> %.1f",real_lower,real_upper);
		if (temp_dep)
		{
			tempc_range = g_strdup_printf("Valid Range: %.1f\302\260C <-> %.1f\302\260C",f_to_c_f(real_lower),f_to_c_f(real_upper));
			tempf_range = g_strdup_printf("Valid Range: %.1f\302\260F <-> %.1f\302\260F",real_lower,real_upper);
			tempk_range = g_strdup_printf("Valid Range: %.1f\302\260K <-> %.1f\302\260K",f_to_k_f(real_lower),f_to_k_f(real_upper));
		}
		else
		{
			tempc_range = g_strdup(range);
			tempf_range = g_strdup(range);
			tempk_range = g_strdup(range);
		}
		raw_lower_str = g_strdup_printf("%i",raw_lower);
		raw_upper_str = g_strdup_printf("%i",raw_upper);

		gtk_list_store_append(store,&iter);
		gtk_list_store_set(store,&iter,
				UO_CHOICE_COL,name,
				UO_BITVAL_COL,bitval,
				UO_FROMECU_MULT_COL,multiplier,
				UO_FROMECU_ADD_COL,adder,
				UO_RAW_LOWER_COL,raw_lower_str,
				UO_RAW_UPPER_COL,raw_upper_str,
				UO_RANGE_COL,range,
				UO_RANGE_TEMPC_COL,tempc_range,
				UO_RANGE_TEMPF_COL,tempf_range,
				UO_RANGE_TEMPK_COL,tempk_range,
				UO_SIZE_COL,size,
				UO_PRECISION_COL,precision,
				UO_TEMP_DEP_COL,temp_dep,
				-1);
		g_free(raw_lower_str);
		g_free(raw_upper_str);
		g_free(range);
		g_free(tempc_range);
		g_free(tempf_range);
		g_free(tempk_range);
	}
	if (GTK_IS_COMBO_BOX_ENTRY(widget))
	{
		gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(widget),UO_CHOICE_COL);
		gtk_combo_box_set_model(GTK_COMBO_BOX(widget),GTK_TREE_MODEL(store));
		g_object_unref(store);
		entry = gtk_bin_get_child(GTK_BIN(widget));
		/* Nasty hack, but otherwise the entry is an obnoxious size.. */
		if ((width = (GINT)OBJ_GET((GtkWidget *)widget,"max_chars")) > 0)
			gtk_entry_set_width_chars(GTK_ENTRY(entry),width);
		else
			gtk_entry_set_width_chars(GTK_ENTRY(entry),12);

		gtk_widget_set_size_request(GTK_WIDGET(widget),-1,(3*(GINT)DATA_GET(global_data,"font_size")));

		//		gtk_container_remove (GTK_CONTAINER (widget), gtk_bin_get_child(GTK_BIN(widget)));
		//		gtk_container_add (GTK_CONTAINER (widget), entry);

		completion = gtk_entry_completion_new();
		gtk_entry_set_completion(GTK_ENTRY(entry),completion);
		g_object_unref(completion);
		gtk_entry_completion_set_model(completion,GTK_TREE_MODEL(store));
		gtk_entry_completion_set_text_column(completion,UO_CHOICE_COL);
		gtk_entry_completion_set_inline_completion(completion,TRUE);
		gtk_entry_completion_set_inline_selection(completion,TRUE);
		gtk_entry_completion_set_popup_single_match(completion,FALSE);
		OBJ_SET(widget,"arrow-size",GINT_TO_POINTER(1));
	}
	EXIT();
	return;
}
Exemple #12
0
/*!
  \brief Sets up a megatunix comboboxentry widget. Reads the data from the 
  passed ConfigFile *, and sets up the choices as well as the combo model
  and an entry completion/regex alloing textual based entry.
  \param object is the pointer to combo widget object
  \param cfgfile is the pointer to datamap file assocated with this widget
  \param section is the section within the cfgfile
  */
G_MODULE_EXPORT void combo_setup(GObject *object, ConfigFile *cfgfile, gchar * section)
{
	gchar *tmpbuf = NULL;
	gchar ** choices = NULL;
	gchar ** vector = NULL;
	gint num_choices = 0;
	gint num_bitvals = 0;
	gint i = 0;
	gchar *tmpstr = NULL;
	gchar *regex = NULL;
	const gchar *name = NULL;
	GtkListStore *store = NULL;
	GtkTreeIter iter;
	GtkEntryCompletion *completion = NULL;
	GtkWidget *entry = NULL;
	extern gconstpointer *global_data;

	cfg_read_string(cfgfile,section,"choices",&tmpbuf);

	choices = parse_keys(tmpbuf,&num_choices,",");
	tmpbuf = g_strdelimit(tmpbuf,",",'|');
	tmpstr = g_utf8_normalize(tmpbuf,-1,G_NORMALIZE_DEFAULT);
	regex = g_utf8_casefold(tmpbuf,-1);
	g_free(tmpbuf);
	g_free(tmpstr);

	if (!cfg_read_string(cfgfile,section,"bitvals",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("\"bitvals\" key is MISSING, critical fault, not setting up control \n"));
		return;
	}
	vector = parse_keys(tmpbuf,&num_bitvals,",");
	g_free(tmpbuf);
	if (num_bitvals != num_choices)
	{
		name = glade_get_widget_name(GTK_WIDGET(object));
		MTXDBG(CRITICAL,_("\"bitvals\" BIG PROBLEM, combobox %s choices %i and bits %i don't match up\n"),(name == NULL ? "undefined" : name),num_choices,num_bitvals);
		return;
	}


	store = gtk_list_store_new(COMBO_COLS,G_TYPE_STRING,G_TYPE_UCHAR);

	for (i=0;i<num_choices;i++)
	{
		gtk_list_store_append(store,&iter);
		assert(choices[i]);
		assert(vector[i]);
		gtk_list_store_set(store,&iter,CHOICE_COL,choices[i],BITVAL_COL,(guchar)g_ascii_strtoull(vector[i],NULL,10),-1);

	}
	OBJ_SET_FULL(object,"model",store,gtk_list_store_clear);
	g_strfreev(vector);
	g_strfreev(choices);

	gtk_combo_box_set_model(GTK_COMBO_BOX(object),GTK_TREE_MODEL(store));
	if (GTK_IS_COMBO_BOX_ENTRY(object))
	{
		gint width = 0;
		gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(object),CHOICE_COL);
		entry = mask_entry_new_with_mask(regex);
		/* Nasty hack, but otherwise the entry is an obnoxious size.. */
		if ((width = (GINT)OBJ_GET((GtkWidget *)object,"max_chars")) > 0)
			gtk_entry_set_width_chars(GTK_ENTRY(entry),width);
		else
			gtk_entry_set_width_chars(GTK_ENTRY(entry),12);

		gtk_widget_set_size_request(GTK_WIDGET(object),-1,(3*(GINT)DATA_GET(global_data,"font_size")));

		gtk_container_remove (GTK_CONTAINER (object), gtk_bin_get_child(GTK_BIN (object)));
		gtk_container_add (GTK_CONTAINER (object), entry);

		completion = gtk_entry_completion_new();
		OBJ_SET_FULL(object,"completion",completion,g_object_unref);
		gtk_entry_set_completion(GTK_ENTRY(entry),completion);
		gtk_entry_completion_set_model(completion,GTK_TREE_MODEL(store));
		gtk_entry_completion_set_text_column(completion,CHOICE_COL);
		gtk_entry_completion_set_inline_completion(completion,TRUE);
		gtk_entry_completion_set_inline_selection(completion,TRUE);
		gtk_entry_completion_set_popup_single_match(completion,FALSE);
		OBJ_SET(object,"arrow-size",GINT_TO_POINTER(1));
	}
	g_free(regex);

}
static void
moblin_netbook_draw_shadow (GtkStyle     *style,
                            GdkWindow    *window,
                            GtkStateType  state_type,
                            GtkShadowType shadow_type,
                            GdkRectangle *area,
                            GtkWidget    *widget,
                            const gchar  *detail,
                            gint          x,
                            gint          y,
                            gint          width,
                            gint          height)
{
  cairo_t *cr;
  MoblinNetbookStyle *mb_style = MOBLIN_NETBOOK_STYLE (style);
  gdouble radius = mb_style->radius;

  DEBUG;

  if (shadow_type == GTK_SHADOW_NONE)
    return;

  SANITIZE_SIZE;

  cr = moblin_netbook_cairo_create (window, area);

  /* initilise the background in the corners to the colour of the widget */
  if (widget)
    {
      cairo_rectangle (cr, x, y, width, height);
      if (mb_style->shadow)
        moblin_netbook_rounded_rectangle (cr, x, y, width - 1, height - 1,
                                          radius);
      else
        moblin_netbook_rounded_rectangle (cr, x, y, width, height, radius);

      gdk_cairo_set_source_color (cr, &widget->style->bg[state_type]);
      cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
      cairo_fill (cr);
    }

  /* FIXME: for RTL */
  if (widget && DETAIL ("entry")
      && (GTK_IS_SPIN_BUTTON (widget)
          || GTK_IS_COMBO_BOX_ENTRY (widget->parent)))
    width += 10;

  if (widget && DETAIL ("entry") && GTK_IS_COMBO_BOX_ENTRY (widget->parent))
    {
      GtkWidget *button;

      g_object_set_data (G_OBJECT (widget->parent),
                         "moblin-netbook-combo-entry", widget);

      button = g_object_get_data (G_OBJECT (widget->parent),
                                  "moblin-netbook-combo-button");


      if (button)
        {
          if (GTK_WIDGET_HAS_FOCUS (button))
            state_type = GTK_STATE_PRELIGHT;
          else
            /* try and keep the button and entry in the same state */
            gtk_widget_set_state (button, state_type);
        }


      width += 10;
    }

  cairo_translate (cr, 0.5, 0.5);
  width--;
  height--;

  cairo_set_line_width (cr, 1.0);
  if (mb_style->shadow != 0.0)
    {
      /* outer shadow */
      moblin_netbook_rounded_rectangle (cr, x, y, width, height,
                                        radius + 1.0);
      cairo_set_source_rgba (cr, 0, 0, 0, mb_style->shadow);
      cairo_stroke (cr);


      /* reduce size for outer shadow */
      height--;
      width--;
    }

  /* border */
  moblin_netbook_rounded_rectangle (cr, x, y, width, height, radius);
  moblin_netbook_set_border_color (cr, style, state_type);
  cairo_stroke (cr);

  cairo_destroy (cr);
}
static void
moblin_netbook_draw_box (GtkStyle     *style,
                         GdkWindow    *window,
                         GtkStateType  state_type,
                         GtkShadowType shadow_type,
                         GdkRectangle *area,
                         GtkWidget    *widget,
                         const gchar  *detail,
                         gint          x,
                         gint          y,
                         gint          width,
                         gint          height)
{
  cairo_t *cr;
  MoblinNetbookStyle *mb_style = MOBLIN_NETBOOK_STYLE (style);
  gint radius = mb_style->radius;

  DEBUG;

  if (DETAIL ("paned") || DETAIL ("buttondefault"))
    return;


  /* we want hover and focused widgets to look the same */
  if (widget && GTK_WIDGET_HAS_FOCUS (widget))
    state_type = GTK_STATE_PRELIGHT;


  /* scrollbar troughs are a plain rectangle */
  if (widget && GTK_IS_SCROLLBAR (widget) && DETAIL ("trough"))
    {
      cr = moblin_netbook_cairo_create (window, area);

      cairo_rectangle (cr, x, y, width, height);
      gdk_cairo_set_source_color (cr, &style->base[state_type]);
      cairo_fill (cr);

      cairo_destroy (cr);

      return;
    }

  SANITIZE_SIZE;

  /*** treeview headers ***/
  if (widget && GTK_IS_TREE_VIEW (widget->parent))
    {
      cr = moblin_netbook_cairo_create (window, area);

      cairo_rectangle (cr, x, y, width, height);
      gdk_cairo_set_source_color (cr, &style->bg[state_type]);
      cairo_fill (cr);
      cairo_destroy (cr);

      gtk_paint_vline (style, window, state_type, area, widget, detail,
                       y + 5, y + height - 5, x + width - 1);
      return;
    }

  /*** spin buttons ***/
  if (DETAIL ("spinbutton_down") || DETAIL ("spinbutton_up"))
    return;

  if (DETAIL ("spinbutton"))
    {
      /* FIXME: for RTL */
      width += 10;
      x -= 10;

      /* always draw button as shadow out to match the entry */
      shadow_type = GTK_SHADOW_OUT;

      /* draw the buttons with the same state type as the entry */
      state_type = widget->state;
    }

  /*** combo boxes ***/
  if (DETAIL ("button") && widget && GTK_IS_COMBO_BOX_ENTRY (widget->parent))
    {
      GtkWidget *entry;

      entry = g_object_get_data (G_OBJECT (widget->parent),
                                 "moblin-netbook-combo-entry");
      g_object_set_data (G_OBJECT (widget->parent),
                         "moblin-netbook-combo-button", widget);

      /* always draw combo box entry buttons as shadow out to match the entry */
      shadow_type = GTK_SHADOW_OUT;

      if (GTK_IS_ENTRY (entry))
        {
          gtk_widget_queue_draw (entry);
        }

      /* FIXME: RTL */
      width += 10;
      x -= 10;
    }

  if (widget
      && (DETAIL ("trough")
          || DETAIL ("trough-fill-level")
          || DETAIL ("trough-fill-level-full"))
      && GTK_IS_SCALE (widget))
    {
      if (mb_style->shadow)
        {
          width--;
          height--;
        }
      if (width > height)
        {
          y = y + (height / 2.0 - 2);
          height = 4;
        }
      else
        {
          x = x + (width / 2.0 - 2);
          width = 4;
        }
    }


  /* scrollbar buttons */
  if (DETAIL ("hscrollbar") || DETAIL ("vscrollbar"))
    {
      x += 2;
      y += 2;
      width -= 4;
      height -= 4;
    }

  /* scrollbar slider */
  if (DETAIL ("slider"))
    {
      if (widget && GTK_IS_HSCROLLBAR (widget))
        {
          y += 2;
          height -= 4;
        }
      else
        {
          x += 2;
          width -= 4;
        }
    }

  cr = moblin_netbook_cairo_create (window, area);

  cairo_set_line_width (cr, LINE_WIDTH);


  /* special "fill" indicator */
  if (DETAIL ("trough-fill-level-full")
      || DETAIL ("trough-fill-level"))
    {
      gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_SELECTED]);

      if (width > height)
        cairo_rectangle (cr, x, y + 1, width, height - 2);
      else
        cairo_rectangle (cr, x + 1, y, width - 2, height);

      cairo_fill (cr);
      cairo_destroy (cr);
      return;
    }

  if (mb_style->shadow)
    {
      if (shadow_type == GTK_SHADOW_OUT)
        {
          /* outer shadow */
          moblin_netbook_rounded_rectangle (cr, x, y, width, height,
                                            radius + 1);
          cairo_set_source_rgba (cr, 0, 0, 0, mb_style->shadow);
          cairo_fill (cr);

          /* reduce size for outer shadow */
          height--;
          width--;
        }
      else if (shadow_type == GTK_SHADOW_IN)
        {
          x++;
          y++;
          width--;
          height--;
        }
    }


  /* fill */
  moblin_netbook_rounded_rectangle (cr, x, y, width, height, radius);

  if (DETAIL ("light-switch-trough"))
    {
      cairo_pattern_t *crp;

      crp = cairo_pattern_create_linear (x, y, x, height);

      /* FIXME: these colours really should not be defined here */

      if (state_type == GTK_STATE_SELECTED)
        {
          cairo_pattern_add_color_stop_rgb (crp, 0, 0.365, 0.820, 0.953);
          cairo_pattern_add_color_stop_rgb (crp, 1, 0.627, 0.894, 0.973);
        }
      else
        {
          cairo_pattern_add_color_stop_rgb (crp, 0, 0.937, 0.941, 0.929);
          cairo_pattern_add_color_stop_rgb (crp, 1, 1.0, 1.0, 1.0);
        }

      cairo_set_source (cr, crp);
    }
  else
    gdk_cairo_set_source_color (cr, &style->bg[state_type]);

  cairo_fill (cr);

  /* extra hilight for "button" widgets, also used as focus rectangle since
   * state_type is set to prelight for focused widgets (see above) */
  if (state_type == GTK_STATE_PRELIGHT && DETAIL ("button")
      && !(widget && GTK_IS_COMBO_BOX_ENTRY (widget->parent)))
    {
      cairo_set_line_width (cr, 2.0);
      moblin_netbook_rounded_rectangle (cr, x + 2, y + 2, width - 4,
                                        height - 4, radius - 1);
      gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_SELECTED]);
      cairo_stroke (cr);
      cairo_set_line_width (cr, 1.0);
    }

  if (shadow_type != GTK_SHADOW_NONE)
    {
      /* border */
      moblin_netbook_rounded_rectangle (cr, x + 0.5, y + 0.5,
                                        width - 1, height - 1, radius);
      moblin_netbook_set_border_color (cr, style, state_type);
      cairo_stroke (cr);
    }

  /* add a grip to handles */
  if (DETAIL ("light-switch-handle") || DETAIL ("hscale"))
    {
      gdk_cairo_set_source_color (cr, &style->mid[state_type]);
      moblin_netbook_draw_grip (cr, FALSE, x, y, width, height);
    }
  else if (DETAIL ("vscale"))
    {
      gdk_cairo_set_source_color (cr, &style->mid[state_type]);
      moblin_netbook_draw_grip (cr, TRUE, x, y, width, height);
    }
  cairo_destroy (cr);

}