Ejemplo n.º 1
0
static void image_fullscreen_button ( GtkWidget *widget, AnypaperPreview *preview)
{
	GtkWidget *button, *image_button;

	button = widget;

	if (preview->priv->state == WINDOW_NORMAL_STATE)
	{
		gtk_button_set_label (GTK_BUTTON(button), GTK_STOCK_LEAVE_FULLSCREEN);
		image_button = gtk_button_get_image (GTK_BUTTON(button));
		gtk_image_set_from_stock (GTK_IMAGE(image_button), GTK_STOCK_LEAVE_FULLSCREEN, GTK_ICON_SIZE_BUTTON);
		gtk_widget_show(image_button);gtk_widget_hide(preview->priv->hbox);
		gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(preview->priv->window2), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
		preview->priv->state = WINDOW_FULLSCREEN_STATE;
	}
	else
	{
		gtk_button_set_label (GTK_BUTTON(button), GTK_STOCK_FULLSCREEN);
		image_button = gtk_button_get_image (GTK_BUTTON(button));
		gtk_image_set_from_stock (GTK_IMAGE(image_button), GTK_STOCK_FULLSCREEN, GTK_ICON_SIZE_BUTTON);
		gtk_widget_show(image_button);gtk_widget_show(preview->priv->hbox);
		gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(preview->priv->window2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
		preview->priv->state = WINDOW_NORMAL_STATE;
	}
}
Ejemplo n.º 2
0
static void
statusbar_features_toolbar_notify_toolbar_style_cb (GtkWidget*  toolbar,
                                                    GParamSpec* pspec,
                                                    GtkWidget*  button)
{
    GtkToolbarStyle style = katze_object_get_enum (toolbar, "toolbar-style");
    const gchar* text = g_object_get_data (G_OBJECT (button), "feature-label");
    switch (style)
    {
        case GTK_TOOLBAR_BOTH:
        case GTK_TOOLBAR_BOTH_HORIZ:
            gtk_button_set_label (GTK_BUTTON (button), text);
            gtk_widget_show (gtk_button_get_image (GTK_BUTTON (button)));
            break;
        case GTK_TOOLBAR_TEXT:
            gtk_button_set_label (GTK_BUTTON (button), text);
            gtk_widget_hide (gtk_button_get_image (GTK_BUTTON (button)));
            break;
        case GTK_TOOLBAR_ICONS:
            gtk_button_set_label (GTK_BUTTON (button), "");
            gtk_widget_show (gtk_button_get_image (GTK_BUTTON (button)));
            break;
        default:
            g_assert_not_reached ();
    }
}
Ejemplo n.º 3
0
/**
 * time_edit_click:
 */
static void time_edit_click ( GtkWidget* widget, GdkEventButton *event, VikWaypoint *wp )
{
  if ( event->button == 3 ) {
    // On right click and when a time is available, allow a method to copy the displayed time as text
    if ( !gtk_button_get_image ( GTK_BUTTON(widget) ) ) {
      vu_copy_label_menu ( widget, event->button );
    }
    return;
  }
  else if ( event->button == 2 ) {
    return;
  }

  GTimeZone *gtz = g_time_zone_new_local ();
  time_t mytime = vik_datetime_edit_dialog ( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
                                             _("Date/Time Edit"),
                                             wp->timestamp,
                                             gtz );
  g_time_zone_unref ( gtz );

  // Was the dialog cancelled?
  if ( mytime == 0 )
    return;

  // Otherwise use new value in the edit buffer
  edit_wp->timestamp = mytime;

  // Clear the previous 'Add' image as now a time is set
  if ( gtk_button_get_image ( GTK_BUTTON(widget) ) )
    gtk_button_set_image ( GTK_BUTTON(widget), NULL );

  update_time ( widget, edit_wp );
}
Ejemplo n.º 4
0
void wxAnyButton::GTKDoShowBitmap(const wxBitmap& bitmap)
{
    wxASSERT_MSG( bitmap.IsOk(), "invalid bitmap" );

    GtkWidget *image;
    if ( DontShowLabel() )
    {
        image = gtk_bin_get_child(GTK_BIN(m_widget));
    }
    else // have both label and bitmap
    {
#ifdef __WXGTK26__
        if ( !gtk_check_version(2,6,0) )
        {
            image = gtk_button_get_image(GTK_BUTTON(m_widget));
        }
        else
#endif // __WXGTK26__
        {
            // buttons with both label and bitmap are only supported with GTK+
            // 2.6 so far
            //
            // it shouldn't be difficult to implement them ourselves for the
            // previous GTK+ versions by stuffing a container with a label and
            // an image inside GtkButton but there doesn't seem to be much
            // point in doing this for ancient GTK+ versions
            return;
        }
    }

    wxCHECK_RET( image && GTK_IS_IMAGE(image), "must have image widget" );

    gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf());
}
Ejemplo n.º 5
0
static void on_play_button_clicked(GtkWidget* play_button, Data* data) {
	const char* full_filename = g_object_get_data(G_OBJECT(play_button), "full_filename");
	GtkWidget* play_image = gtk_button_get_image(GTK_BUTTON(play_button));
	puts(full_filename);
	if (data->recording_pid != 0) {
		// shouldn't even happen
		return;
	}
	if (data->playing_pid != 0) {
		if (strcmp(full_filename, data->currently_playing_song) != 0) {
			// something else is playing. Too lazy to handle right now.
			return;
		}
		// stop
		printf("playing pid: %d\n", data->playing_pid);
		kill(data->playing_pid, SIGTERM);
		gtk_image_set_from_icon_name(GTK_IMAGE(play_image), "media-playback-start", GTK_ICON_SIZE_BUTTON);
		data->playing_pid = 0;
		data->currently_playing_song = NULL;
	} else {
		// start
		data->playing_pid = fork();
		data->currently_playing_song = full_filename;
		if (data->playing_pid == 0) {
			//child
			execl("/usr/bin/ecasound", "/usr/bin/ecasound", "-i", full_filename, "-o", "alsa", (char*) 0);
		}
		gtk_image_set_from_icon_name(GTK_IMAGE(play_image), "media-playback-stop", GTK_ICON_SIZE_BUTTON);
	}
}
Ejemplo n.º 6
0
/**
 * tpwin_sync_time_to_tp:
 *
 */
static void tpwin_sync_time_to_tp ( GtkWidget* widget, GdkEventButton *event, VikTrwLayerTpwin *tpwin )
{
  if ( !tpwin->cur_tp || tpwin->sync_to_tp_block )
    return;

  if ( event->button == 3 ) {
    // On right click and when a time is available, allow a method to copy the displayed time as text
    if ( !gtk_button_get_image ( GTK_BUTTON(widget) ) ) {
       vu_copy_label_menu ( widget, event->button );
    }
    return;
  }
  else if ( event->button == 2 ) {
    return;
  }

  if ( !tpwin->cur_tp || tpwin->sync_to_tp_block )
    return;

  if ( tpwin->cur_tp->has_timestamp )
    last_edit_time = tpwin->cur_tp->timestamp;
  else if ( last_edit_time == 0 )
    time ( &last_edit_time );

  GTimeZone *gtz = g_time_zone_new_local ();
  time_t mytime = vik_datetime_edit_dialog ( GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(&tpwin->parent))),
                                             _("Date/Time Edit"),
                                             last_edit_time,
                                             gtz );
  g_time_zone_unref ( gtz );

  // Was the dialog cancelled?
  if ( mytime == 0 )
    return;

  // Otherwise use the new value
  tpwin->cur_tp->timestamp = mytime;
  tpwin->cur_tp->has_timestamp = TRUE;
  // TODO: consider warning about unsorted times?

  // Clear the previous 'Add' image as now a time is set
  if ( gtk_button_get_image ( GTK_BUTTON(tpwin->time) ) )
    gtk_button_set_image ( GTK_BUTTON(tpwin->time), NULL );

  tpwin_update_times ( tpwin, tpwin->cur_tp );
}
Ejemplo n.º 7
0
static void
garu_headerbar_set_button_image (GtkButton *button, const gchar *name)
{
  GtkWidget *image;
  image = gtk_button_get_image (button);
  gtk_image_set_from_icon_name (GTK_IMAGE (image), name,
                                GTK_ICON_SIZE_SMALL_TOOLBAR);
}
Ejemplo n.º 8
0
static int gtkToggleSetPaddingAttrib(Ihandle* ih, const char* value)
{
  iupStrToIntInt(value, &ih->data->horiz_padding, &ih->data->vert_padding, 'x');
  if (ih->handle && ih->data->type == IUP_TOGGLE_IMAGE)
  {
    GtkButton* button = (GtkButton*)ih->handle;
    GtkMisc* misc = (GtkMisc*)gtk_button_get_image(button);
    gtk_misc_set_padding(misc, ih->data->horiz_padding, ih->data->vert_padding);
  }
  return 0;
}
Ejemplo n.º 9
0
static GtkWidget *
get_image_from_button (GtkWidget *button)
{
  GtkWidget *image;

  image = gtk_button_get_image (GTK_BUTTON (button));
  if (GTK_IS_IMAGE (image))
    return image;

  return NULL;
}
Ejemplo n.º 10
0
/**
 * direction_edit_click:
 */
static void direction_add_click ( GtkWidget* widget, GdkEventButton *event, GtkWidget *direction )
{
  // Replace 'Add' with text and stop further callbacks
  if ( gtk_button_get_image ( GTK_BUTTON(widget) ) )
    gtk_button_set_image ( GTK_BUTTON(widget), NULL );
  gtk_button_set_label ( GTK_BUTTON(widget), _("True") );
  g_signal_handler_disconnect ( G_OBJECT(widget), direction_signal_id );

  // Enable direction value
  gtk_widget_set_sensitive ( direction, TRUE );
  gtk_spin_button_set_value ( GTK_SPIN_BUTTON(direction), 0.0 );
}
Ejemplo n.º 11
0
static int gtkToggleSetTitleAttrib(Ihandle* ih, const char* value)
{
  if (ih->data->type == IUP_TOGGLE_TEXT)
  {
    GtkButton* button = (GtkButton*)ih->handle;
    GtkLabel* label = (GtkLabel*)gtk_button_get_image(button);
    iupgtkSetMnemonicTitle(ih, label, value);
    return 1;
  }

  return 0;
}
Ejemplo n.º 12
0
static int gtkToggleSetStandardFontAttrib(Ihandle* ih, const char* value)
{
  iupdrvSetStandardFontAttrib(ih, value);

  if (ih->handle)
  {
    GtkWidget* label = gtk_button_get_image((GtkButton*)ih->handle);
    if (label)
      iupgtkUpdateWidgetFont(ih, label);
  }
  return 1;
}
Ejemplo n.º 13
0
Archivo: gui.c Proyecto: lukspdev/lppb
static void  
drag_data_received_handl(GtkWidget          *widget,
					     GdkDragContext     *context,
					     gint                x,
					     gint                y,
					     GtkSelectionData   *sel_data,
					     guint               info,
					     guint               time,
                         gpointer            data)
{
    gint i;
    guint candid = GPOINTER_TO_UINT(data);

    g_print("%s to dest %d\n",
            (gchar *)gtk_selection_data_get_data(sel_data), candid);
    i=g_strcmp0((gchar *)gtk_selection_data_get_data(sel_data), "Candidate 1");
    switch(i){
        case -1:
            merged[candid] = 0;
            break;
        case 0:
            merged[candid] = 1;
            break;
        case 1:
            merged[candid] = 2;
            break;
        default:
            break;
    }

    GtkWidget *source_widget;
    GdkPixbuf *source_buf;
    GtkWidget *parent;
    GdkPixbuf *buf;
    GtkWidget *new_widget;

    parent = gtk_widget_get_parent(GTK_WIDGET(widget));
    source_widget = gtk_drag_get_source_widget(context);
    source_widget = gtk_button_get_image(GTK_BUTTON(source_widget));
    source_buf = gtk_image_get_pixbuf(GTK_IMAGE(source_widget));
    buf = gdk_pixbuf_scale_simple(source_buf, hole_sizes_w[candid],
                                  hole_sizes_h[candid], GDK_INTERP_BILINEAR);
    new_widget = gtk_image_new_from_pixbuf(buf);
    g_object_unref(buf);

    gtk_fixed_put(GTK_FIXED(parent), new_widget, hole_x[candid],
                                                 hole_y[candid]);

    gtk_widget_show_all(new_widget);

    gtk_drag_finish (context, TRUE, FALSE, time);
}
Ejemplo n.º 14
0
static int gtkToggleSetPaddingAttrib(Ihandle* ih, const char* value)
{
  iupStrToIntInt(value, &ih->data->horiz_padding, &ih->data->vert_padding, 'x');
  if (ih->handle && ih->data->type == IUP_TOGGLE_IMAGE)
  {
    GtkButton* button = (GtkButton*)ih->handle;
    GtkMisc* misc = (GtkMisc*)gtk_button_get_image(button);
    gtk_misc_set_padding(misc, ih->data->horiz_padding, ih->data->vert_padding);
    return 0;
  }
  else
    return 1; /* store until not mapped, when mapped will be set again */
}
Ejemplo n.º 15
0
static int gtkToggleSetFgColorAttrib(Ihandle* ih, const char* value)
{
  unsigned char r, g, b;
  GtkWidget* label = (GtkWidget*)gtk_button_get_image((GtkButton*)ih->handle);
  if (!label) return 0;

  if (!iupStrToRGB(value, &r, &g, &b))
    return 0;

  iupgtkBaseSetFgColor(label, r, g, b);

  return 1;
}
Ejemplo n.º 16
0
static gboolean trigger_voice(GtkWidget *w, GdkEvent *e, GtkEntry *ent)
{
  voice = TRUE;
  GtkWidget *icon = gtk_button_get_image(GTK_BUTTON(v));
  gtk_image_set_from_icon_name(GTK_IMAGE(icon), "media-record", GTK_ICON_SIZE_BUTTON);
  gtk_widget_queue_draw (icon);
  while (gtk_events_pending ())
    gtk_main_iteration ();
  trigger(w, e, ent);
  gtk_image_set_from_icon_name(GTK_IMAGE(icon), "audio-input-microphone", GTK_ICON_SIZE_BUTTON);
  gtk_widget_queue_draw(icon);
  while (gtk_events_pending ())
    gtk_main_iteration ();
  return FALSE;
}
Ejemplo n.º 17
0
static int gtkToggleSetStandardFontAttrib(Ihandle* ih, const char* value)
{
  iupdrvSetStandardFontAttrib(ih, value);

  if (ih->handle)
  {
    GtkWidget* label = gtk_button_get_image((GtkButton*)ih->handle);
    if (!label) return 1;

    gtk_widget_modify_font(label, (PangoFontDescription*)iupgtkGetPangoFontDescAttrib(ih));

    if (ih->data->type == IUP_TOGGLE_TEXT)
      iupgtkFontUpdatePangoLayout(ih, gtk_label_get_layout((GtkLabel*)label));
  }
  return 1;
}
Ejemplo n.º 18
0
static int gtkButtonSetBgColorAttrib(Ihandle* ih, const char* value)
{
  if (ih->data->type == IUP_BUTTON_TEXT)
  {
    GtkWidget* frame = gtk_button_get_image(GTK_BUTTON(ih->handle));
    if (frame && GTK_IS_FRAME(frame))
    {
      unsigned char r, g, b;
      if (!iupStrToRGB(value, &r, &g, &b))
        return 0;

      iupgtkSetBgColor(gtk_bin_get_child(GTK_BIN(frame)), r, g, b);
      return 1;
    }
  }

  return iupdrvBaseSetBgColorAttrib(ih, value);
}
Ejemplo n.º 19
0
void wxAnyButton::GTKDoShowBitmap(const wxBitmap& bitmap)
{
    wxASSERT_MSG( bitmap.IsOk(), "invalid bitmap" );

    GtkWidget *image;
    if ( DontShowLabel() )
    {
        image = gtk_bin_get_child(GTK_BIN(m_widget));
    }
    else // have both label and bitmap
    {
        image = gtk_button_get_image(GTK_BUTTON(m_widget));
    }

    wxCHECK_RET( image && GTK_IS_IMAGE(image), "must have image widget" );

    gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf());
}
Ejemplo n.º 20
0
static void gtkToggleSetPixbuf(Ihandle* ih, const char* name, int make_inactive, const char* attrib_name)
{
  GtkButton* button = (GtkButton*)ih->handle;
  GtkImage* image = (GtkImage*)gtk_button_get_image(button);

  if (name)
  {
    GdkPixbuf* pixbuf = iupImageGetImage(name, ih, make_inactive, attrib_name);
    GdkPixbuf* old_pixbuf = gtk_image_get_pixbuf(image);
    if (pixbuf != old_pixbuf)
      gtk_image_set_from_pixbuf(image, pixbuf);
    return;
  }

  /* if not defined */
#if GTK_CHECK_VERSION(2, 8, 0)
  gtk_image_clear(image);
#endif
}
Ejemplo n.º 21
0
void
xmr_button_set_image_from_stock(XmrButton *button, const gchar *stock)
{
	GtkWidget *image;

	g_return_if_fail( button != NULL);

	if (stock == NULL)
		return ;

	image = gtk_button_get_image(GTK_BUTTON(button));
	if (image == NULL)
	{
		image = gtk_image_new_from_icon_name(stock, GTK_ICON_SIZE_BUTTON);

		gtk_button_set_image(GTK_BUTTON(button), image);
	}
	else
	{
		gtk_image_set_from_icon_name(GTK_IMAGE(image), stock, GTK_ICON_SIZE_BUTTON);
	}
}
Ejemplo n.º 22
0
static void gtkButtonSetPixbuf(Ihandle* ih, const char* name, int make_inactive)
{
  GtkImage* image;
  if (!iupAttribGet(ih, "_IUPGTK_EVENTBOX"))
    image = (GtkImage*)gtk_button_get_image((GtkButton*)ih->handle);
  else
    image = (GtkImage*)gtk_bin_get_child((GtkBin*)ih->handle);

  if (name && image)
  {
    GdkPixbuf* pixbuf = iupImageGetImage(name, ih, make_inactive);
    GdkPixbuf* old_pixbuf = gtk_image_get_pixbuf(image);
    if (pixbuf != old_pixbuf)
      gtk_image_set_from_pixbuf(image, pixbuf);
    return;
  }

  /* if not defined */
#if GTK_CHECK_VERSION(2, 8, 0)
  if (image)
    gtk_image_clear(image);
#endif
}
Ejemplo n.º 23
0
void
brasero_file_chooser_customize (GtkWidget *widget, gpointer null_data)
{
	/* we explore everything until we reach a treeview (there are two) */
	if (GTK_IS_TREE_VIEW (widget)) {
		GtkTargetList *list;
		GdkAtom target;
		gboolean found;
		guint num;

		list = gtk_drag_source_get_target_list (widget);
		target = gdk_atom_intern ("text/uri-list", TRUE);
		found = gtk_target_list_find (list, target, &num);
		/* FIXME: should we unref them ? apparently not according to 
		 * the warning messages we get if we do */

		if (found
		&&  gtk_tree_selection_get_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (widget))) == GTK_SELECTION_MULTIPLE) {
			GtkTreeModel *model;

			/* This is done because GtkFileChooser does not use a
			 * GtkListStore or GtkTreeStore any more. */
			egg_tree_multi_drag_add_drag_support (GTK_TREE_VIEW (widget));
			model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
			if (model) {
				GType type;

				type = G_OBJECT_TYPE (model);
				brasero_enable_multi_DND_for_model_type (type);
			}
			else
				g_signal_connect (widget,
				                  "notify::model",
				                  G_CALLBACK (brasero_file_chooser_notify_model),
				                  NULL);
		}
	}
	else if (GTK_IS_BUTTON (widget)) {
		GtkWidget *image;
		gchar *stock_id = NULL;

		image = gtk_button_get_image (GTK_BUTTON (widget));
		if (!GTK_IS_IMAGE (image))
			return;

		gtk_image_get_stock (GTK_IMAGE (image), &stock_id, NULL);
		if (stock_id
		&& (!strcmp (stock_id,GTK_STOCK_ADD)
		||  !strcmp (stock_id, GTK_STOCK_REMOVE))) {
			GtkRequisition request;
			gint width;
			GtkWidget *parent;

			/* This is to avoid having the left part too small */
			parent = gtk_widget_get_parent (widget);
			gtk_widget_get_requisition (parent, &request);
			width = request.width;
			gtk_widget_get_preferred_size (parent, &request, NULL);
			if (request.width >= width)
				gtk_widget_set_size_request (parent,
							     request.width,
							     request.height);
			
			gtk_widget_hide (widget);
		}
	}
	else if (GTK_IS_CONTAINER (widget)) {
		if (GTK_IS_PANED (widget)) {
			GtkWidget *left;

			/* This is to allow the left part to be shrunk as much 
			 * as the user want. */
			left = gtk_paned_get_child1 (GTK_PANED (widget));

			g_object_ref (left);
			gtk_container_remove (GTK_CONTAINER (widget), left);
			gtk_paned_pack1 (GTK_PANED (widget),
					 left,
					 TRUE,
					 TRUE);
			g_object_unref (left);

			g_signal_connect (widget,
			                  "size-allocate",
			                  G_CALLBACK (brasero_file_chooser_allocation_changed),
			                  NULL);
		}

		gtk_container_foreach (GTK_CONTAINER (widget),
				       brasero_file_chooser_customize,
				       NULL);
	}
}
Ejemplo n.º 24
0
void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
{
    switch ( which )
    {
        case State_Normal:
            if ( DontShowLabel() )
            {
                // we only have the bitmap in this button, never remove it but
                // do invalidate the best size when the bitmap (and presumably
                // its size) changes
                InvalidateBestSize();
            }
#ifdef __WXGTK26__
            // normal image is special: setting it enables images for the button and
            // resetting it to nothing disables all of them
            else if ( !gtk_check_version(2,6,0) )
            {
                GtkWidget *image = gtk_button_get_image(GTK_BUTTON(m_widget));
                if ( image && !bitmap.IsOk() )
                {
                    gtk_container_remove(GTK_CONTAINER(m_widget), image);
                }
                else if ( !image && bitmap.IsOk() )
                {
                    image = gtk_image_new();
                    gtk_button_set_image(GTK_BUTTON(m_widget), image);
                }
                else // image presence or absence didn't change
                {
                    // don't invalidate best size below
                    break;
                }

                InvalidateBestSize();
            }
#endif // GTK+ 2.6+
            break;

        case State_Pressed:
            if ( bitmap.IsOk() )
            {
                if ( !m_bitmaps[which].IsOk() )
                {
                    // we need to install the callbacks to be notified about
                    // the button pressed state change
                    g_signal_connect
                    (
                        m_widget,
                        "pressed",
                        G_CALLBACK(wxgtk_button_press_callback),
                        this
                    );

                    g_signal_connect
                    (
                        m_widget,
                        "released",
                        G_CALLBACK(wxgtk_button_released_callback),
                        this
                    );
                }
            }
            else // no valid bitmap
            {
                if ( m_bitmaps[which].IsOk() )
                {
                    // we don't need to be notified about the button pressed
                    // state changes any more
                    g_signal_handlers_disconnect_by_func
                    (
                        m_widget,
                        (gpointer)wxgtk_button_press_callback,
                        this
                    );

                    g_signal_handlers_disconnect_by_func
                    (
                        m_widget,
                        (gpointer)wxgtk_button_released_callback,
                        this
                    );

                    // also make sure we don't remain stuck in pressed state
                    if ( m_isPressed )
                    {
                        m_isPressed = false;
                        GTKUpdateBitmap();
                    }
                }
            }
            break;

        case State_Current:
            // the logic here is the same as above for State_Pressed: we need
            // to connect the handlers if we must be notified about the changes
            // in the button current state and we disconnect them when/if we
            // don't need them any more
            if ( bitmap.IsOk() )
            {
                if ( !m_bitmaps[which].IsOk() )
                {
                    g_signal_connect
                    (
                        m_widget,
                        "enter",
                        G_CALLBACK(wxgtk_button_enter_callback),
                        this
                    );

                    g_signal_connect
                    (
                        m_widget,
                        "leave",
                        G_CALLBACK(wxgtk_button_leave_callback),
                        this
                    );
                }
            }
            else // no valid bitmap
            {
                if ( m_bitmaps[which].IsOk() )
                {
                    g_signal_handlers_disconnect_by_func
                    (
                        m_widget,
                        (gpointer)wxgtk_button_enter_callback,
                        this
                    );

                    g_signal_handlers_disconnect_by_func
                    (
                        m_widget,
                        (gpointer)wxgtk_button_leave_callback,
                        this
                    );

                    if ( m_isCurrent )
                    {
                        m_isCurrent = false;
                        GTKUpdateBitmap();
                    }
                }
            }
            break;

        case State_Focused:
            if ( bitmap.IsOk() )
            {
                Connect(wxEVT_SET_FOCUS,
                        wxFocusEventHandler(wxAnyButton::GTKOnFocus));
                Connect(wxEVT_KILL_FOCUS,
                        wxFocusEventHandler(wxAnyButton::GTKOnFocus));
            }
            else // no valid focused bitmap
            {
                Disconnect(wxEVT_SET_FOCUS,
                           wxFocusEventHandler(wxAnyButton::GTKOnFocus));
                Disconnect(wxEVT_KILL_FOCUS,
                           wxFocusEventHandler(wxAnyButton::GTKOnFocus));
            }
            break;

        default:
            // no callbacks to connect/disconnect
            ;
    }

    m_bitmaps[which] = bitmap;

    // update the bitmap immediately if necessary, otherwise it will be done
    // when the bitmap for the corresponding state is needed the next time by
    // GTKUpdateBitmap()
    if ( bitmap.IsOk() && which == GTKGetCurrentState() )
    {
        GTKDoShowBitmap(bitmap);
    }
}
Ejemplo n.º 25
0
static gboolean _tristatebutton_expose(GtkWidget *widget, GdkEventExpose *event)
{
  g_return_val_if_fail(widget != NULL, FALSE);
  g_return_val_if_fail(DTGTK_IS_TRISTATEBUTTON(widget), FALSE);
  g_return_val_if_fail(event != NULL, FALSE);
  GtkStyle *style = gtk_widget_get_style(widget);
  int state = gtk_widget_get_state(widget);

  /* fix text style */
  for(int i = 0; i < 5; i++) style->text[i] = style->fg[i];

  /* fetch flags */
  int flags = DTGTK_TRISTATEBUTTON(widget)->icon_flags;

  /* set inner border */
  int border = DT_PIXEL_APPLY_DPI((flags & CPF_DO_NOT_USE_BORDER) ? 2 : 6);

  /* update active state paint flag */
  gboolean active = DTGTK_TRISTATEBUTTON(widget)->state > 0;
  if(active)
    flags |= CPF_ACTIVE;
  else
    flags &= ~(CPF_ACTIVE);


  /* begin cairo drawing */
  cairo_t *cr;
  cr = gdk_cairo_create(gtk_widget_get_window(widget));

  GtkAllocation allocation;
  gtk_widget_get_allocation(widget, &allocation);
  int x = allocation.x;
  int y = allocation.y;
  int width = allocation.width;
  int height = allocation.height;

  /* draw standard button background if not transparent nor flat styled */
  if((flags & CPF_STYLE_FLAT))
  {
    if(state != GTK_STATE_NORMAL)
    {
      cairo_rectangle(cr, x, y, width, height);
      cairo_set_source_rgba(cr, style->bg[state].red / 65535.0, style->bg[state].green / 65535.0,
                            style->bg[state].blue / 65535.0, 0.5);
      cairo_fill(cr);
    }
  }
  else if(!(flags & CPF_BG_TRANSPARENT))
  {
    cairo_rectangle(cr, x, y, width, height);
    float rs = 1.0, gs = 1.0, bs = 1.0;

    if(DTGTK_TRISTATEBUTTON(widget)->state == 1)
      rs = gs = bs = 3.0;
    else if(DTGTK_TRISTATEBUTTON(widget)->state == 2)
      rs = 3.0;

    cairo_set_source_rgba(cr, (style->bg[state].red / 65535.0) * rs, (style->bg[state].green / 65535.0) * gs,
                          (style->bg[state].blue / 65535.0) * bs, 0.5);
    cairo_fill(cr);
  }

  /* create pango text settings if label exists */
  PangoLayout *layout = NULL;
  int pw = 0, ph = 0;
  const gchar *text = gtk_button_get_label(GTK_BUTTON(widget));
  if(text)
  {
    layout = pango_cairo_create_layout(cr);
    pango_layout_set_font_description(layout, darktable.bauhaus->pango_font_desc);
    pango_cairo_context_set_resolution(pango_layout_get_context(layout), darktable.gui->dpi);
    pango_layout_set_text(layout, text, -1);
    pango_layout_get_pixel_size(layout, &pw, &ph);
  }

  cairo_set_source_rgb(cr, style->fg[state].red / 65535.0, style->fg[state].green / 65535.0,
                       style->fg[state].blue / 65535.0);

  /* draw button image if any */
  GtkWidget *image = gtk_button_get_image(GTK_BUTTON(widget));
  if(image)
  {
    GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));

    if(pixbuf)
    {
      /* Draw the pixbuf */
      gint pbw = gdk_pixbuf_get_width(pixbuf);
      gint pbh = gdk_pixbuf_get_height(pixbuf);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, allocation.x + ((allocation.width / 2) - (pbw / 2)),
                                  allocation.y + ((allocation.height / 2) - (pbh / 2)));
      cairo_paint(cr);
    }
  }


  /* draw icon */
  if(DTGTK_TRISTATEBUTTON(widget)->icon)
  {
    //     if (flags & CPF_IGNORE_FG_STATE)
    //       state = GTK_STATE_NORMAL;


    if(text)
      DTGTK_TRISTATEBUTTON(widget)
          ->icon(cr, x + border, y + border, height - (border * 2), height - (border * 2), flags);
    else
      DTGTK_TRISTATEBUTTON(widget)
          ->icon(cr, x + border, y + border, width - (border * 2), height - (border * 2), flags);
  }


  /* draw label */
  if(text)
  {
    int lx = x + DT_PIXEL_APPLY_DPI(2), ly = y + ((height / 2.0) - (ph / 2.0));
    cairo_translate(cr, lx, ly);
    pango_cairo_show_layout(cr, layout);
    g_object_unref(layout);
  }

  cairo_destroy(cr);

  return FALSE;
}
Ejemplo n.º 26
0
static void _set_playPauseImage (CustomData *data, const gchar *stockid) {
        gtk_image_set_from_stock(
                        GTK_IMAGE (gtk_button_get_image (GTK_BUTTON (data->playPauseButton))),
                        stockid, GTK_ICON_SIZE_BUTTON);
}