Пример #1
0
static void
on_page_switched (GtkNotebook * notebook, GParamSpec * arg, gpointer user_data)
{
  BtMainPages *self = BT_MAIN_PAGES (user_data);
  BtSong *song;
  GHashTable *properties;
  GtkWidget *page;
  gchar *prop;
  guint page_num;

  // get objects
  g_object_get (self->priv->app, "song", &song, NULL);
  if (!song) {
    return;
  }

  g_object_get (notebook, "page", &page_num, NULL);
  GST_INFO ("page has switched : self=%p, page=%d", self, page_num);

  // ensure the new page gets focused, this sounds like a hack though
  page = gtk_notebook_get_nth_page (notebook, page_num);
  GTK_WIDGET_GET_CLASS (page)->focus (page, GTK_DIR_TAB_FORWARD);

  // remember page
  bt_child_proxy_get (song, "setup::properties", &properties, NULL);
  prop = g_strdup_printf ("%u", page_num);
  g_hash_table_insert (properties, g_strdup ("active-page"), prop);

  // release the reference
  g_object_unref (song);
  GST_INFO ("page-switched done");
}
Пример #2
0
/**
 * gtk_widget_get_request_mode:
 * @widget: a #GtkWidget instance
 *
 * Gets whether the widget prefers a height-for-width layout
 * or a width-for-height layout.
 *
 * <note><para>#GtkBin widgets generally propagate the preference of
 * their child, container widgets need to request something either in
 * context of their children or in context of their allocation
 * capabilities.</para></note>
 *
 * Returns: The #GtkSizeRequestMode preferred by @widget.
 *
 * Since: 3.0
 */
GtkSizeRequestMode
gtk_widget_get_request_mode (GtkWidget *widget)
{
  g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_SIZE_REQUEST_CONSTANT_SIZE);

  return GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget);
}
Пример #3
0
wxSize wxControl::DoGetBestSize() const
{
    // Do not return any arbitrary default value...
    wxASSERT_MSG( m_widget, wxT("DoGetBestSize called before creation") );

    wxSize best;
    if (m_wxwindow)
    {
        // this is not a native control, size_request is likely to be (0,0)
        best = wxControlBase::DoGetBestSize();
    }
    else
    {
        GtkRequisition req;
#ifdef __WXGTK3__
        if (gtk_widget_get_request_mode(m_widget) != GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
        {
            gtk_widget_get_preferred_height(m_widget, NULL, &req.height);
            gtk_widget_get_preferred_width_for_height(m_widget, req.height, NULL, &req.width);
        }
        else
        {
            gtk_widget_get_preferred_width(m_widget, NULL, &req.width);
            gtk_widget_get_preferred_height_for_width(m_widget, req.width, NULL, &req.height);
        }
#else
        GTK_WIDGET_GET_CLASS(m_widget)->size_request(m_widget, &req);
#endif
        best.Set(req.width, req.height);
    }
    CacheBestSize(best);
    return best;
}
Пример #4
0
static GtkWidget *
find_mnemonic_widget (GtkWidget *widget,
                      gint       level)
{
    gboolean can_focus;

    g_object_get (widget, "can-focus", &can_focus, NULL);

    if (GTK_WIDGET_GET_CLASS (widget)->activate_signal ||
            can_focus                                      ||
            GTK_WIDGET_GET_CLASS (widget)->mnemonic_activate !=
            GTK_WIDGET_CLASS (g_type_class_peek (GTK_TYPE_WIDGET))->mnemonic_activate)
    {
        return widget;
    }

    if (GIMP_IS_SIZE_ENTRY (widget))
    {
        GimpSizeEntry *entry = GIMP_SIZE_ENTRY (widget);

        return gimp_size_entry_get_help_widget (entry,
                                                entry->number_of_fields - 1);
    }
    else if (GTK_IS_CONTAINER (widget))
    {
        GtkWidget *mnemonic_widget = NULL;
        GList     *children;
        GList     *list;

        children = gtk_container_get_children (GTK_CONTAINER (widget));

        for (list = children; list; list = g_list_next (list))
        {
            mnemonic_widget = find_mnemonic_widget (list->data, level + 1);

            if (mnemonic_widget)
                break;
        }

        g_list_free (children);

        return mnemonic_widget;
    }

    return NULL;
}
Пример #5
0
static gboolean key_press_event_cb(WebKitWebView* webView, GdkEvent* event, gpointer data)
{
    KeyEventFixture* fixture = (KeyEventFixture*)data;
    gboolean handled = GTK_WIDGET_GET_CLASS(fixture->webView)->key_press_event(GTK_WIDGET(fixture->webView), &event->key);
    g_assert_cmpint(handled, ==, fixture->info->shouldBeHandled);

    return FALSE;
}
Пример #6
0
void activate_cell_renderer_toggle_tree_mode(void)
{
	GtkCellRendererClass *cell_class;
	GtkCellRendererToggle *toggle_renderer;

	toggle_renderer = GTK_CELL_RENDERER_TOGGLE(gtk_cell_renderer_toggle_new());
	cell_class = GTK_CELL_RENDERER_CLASS(GTK_WIDGET_GET_CLASS(toggle_renderer));
	cell_class->activate = gtk_cell_renderer_toggle_activate;
	gtk_object_destroy(GTK_OBJECT(toggle_renderer));
}
Пример #7
0
static void
gimp_message_box_get_preferred_height_for_width (GtkWidget *widget,
                                                 gint       width,
                                                 gint      *minimum_height,
                                                 gint      *natural_height)
{
  GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget,
                                                       minimum_height,
                                                       natural_height);
}
Пример #8
0
static gboolean
treeview_clicked_cb(cam* cam, GdkEventButton* ev, GtkTreeView* treeview) {
	gboolean retval = GTK_WIDGET_GET_CLASS(treeview)->button_press_event(GTK_WIDGET(treeview), ev);

	if(ev->button == 3) {
		show_popup(cam, treeview, NULL);
		retval = TRUE;
	}

	return retval;
}
Пример #9
0
// This is not the same as GetBestSize() because that size may have
// been recalculated and cached by us. We want GTK+ information.
wxSize wxControl::GTKGetPreferredSize(GtkWidget* widget) const
{
    GtkRequisition req;
#ifdef __WXGTK3__
    gtk_widget_get_preferred_size(widget, NULL, &req);
#else
    GTK_WIDGET_GET_CLASS(widget)->size_request(widget, &req);
#endif

    return wxSize(req.width, req.height);
}
Пример #10
0
static gboolean key_release_event_cb(WebKitWebView* webView, GdkEvent* event, gpointer data)
{
    // WebCore never seems to mark keyup events as handled.
    KeyEventFixture* fixture = (KeyEventFixture*)data;
    gboolean handled = GTK_WIDGET_GET_CLASS(fixture->webView)->key_press_event(GTK_WIDGET(fixture->webView), &event->key);
    g_assert(!handled);

    g_main_loop_quit(fixture->loop);

    return FALSE;
}
Пример #11
0
static gboolean
toplevel_key_press_event_after (EggSearchBar *self,
                                GdkEventKey  *event,
                                GtkWindow    *toplevel)
{
  EggSearchBarPrivate *priv = egg_search_bar_get_instance_private (self);
  GtkWidget *entry;

  g_assert (EGG_IS_SEARCH_BAR (self));
  g_assert (event != NULL);
  g_assert (GTK_IS_WINDOW (toplevel));

  entry = GTK_WIDGET (priv->entry);

  switch (event->keyval)
    {
    case GDK_KEY_Escape:
    case GDK_KEY_Up:
    case GDK_KEY_KP_Up:
    case GDK_KEY_Down:
    case GDK_KEY_KP_Down:
    case GDK_KEY_Left:
    case GDK_KEY_KP_Left:
    case GDK_KEY_Right:
    case GDK_KEY_KP_Right:
    case GDK_KEY_Home:
    case GDK_KEY_KP_Home:
    case GDK_KEY_End:
    case GDK_KEY_KP_End:
    case GDK_KEY_Page_Up:
    case GDK_KEY_KP_Page_Up:
    case GDK_KEY_Page_Down:
    case GDK_KEY_KP_Page_Down:
    case GDK_KEY_KP_Tab:
    case GDK_KEY_Tab:
      /* ignore keynav */
      break;

    default:
      if (((event->state & GDK_MOD1_MASK) != 0) ||
          ((event->state & GDK_CONTROL_MASK) != 0) ||
          priv->search_mode_enabled ||
          is_modifier_key (event))
        break;

      egg_search_bar_set_search_mode_enabled (self, TRUE);

      return GTK_WIDGET_GET_CLASS (entry)->key_press_event (entry, event);
    }

  return GDK_EVENT_PROPAGATE;
}
Пример #12
0
__attribute__((noreturn)) static void
end (GtkWidget   *win,
     const gchar *msg)
{
    GTK_WIDGET_GET_CLASS (win)->key_press_event = NULL;
    GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (win),
                                                GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                GTK_MESSAGE_INFO,
                                                GTK_BUTTONS_OK,
                                                "%s", msg);
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
    exit (EXIT_SUCCESS);
}
Пример #13
0
wxSize wxCollapsiblePane::DoGetBestSize() const
{
    wxASSERT_MSG( m_widget, wxT("DoGetBestSize called before creation") );

    GtkRequisition req;
#ifdef __WXGTK3__
    gtk_widget_get_preferred_size(m_widget, NULL, &req);
#else
    GTK_WIDGET_GET_CLASS(m_widget)->size_request(m_widget, &req);
#endif

    // notice that we do not cache our best size here as it changes
    // all times the user expands/hide our pane
    return wxSize(req.width, req.height);
}
Пример #14
0
/**
 * gtk_widget_get_preferred_width_for_height:
 * @widget: a #GtkWidget instance
 * @height: the height which is available for allocation
 * @minimum_width: (out) (allow-none): location for storing the minimum width, or %NULL
 * @natural_width: (out) (allow-none): location for storing the natural width, or %NULL
 *
 * Retrieves a widget's minimum and natural width if it would be given
 * the specified @height.
 *
 * The returned request will be modified by the
 * GtkWidgetClass::adjust_size_request virtual method and by any
 * #GtkSizeGroup<!-- -->s that have been applied. That is, the returned request
 * is the one that should be used for layout, not necessarily the one
 * returned by the widget itself.
 *
 * Since: 3.0
 */
void
gtk_widget_get_preferred_width_for_height (GtkWidget *widget,
                                           gint       height,
                                           gint      *minimum_width,
                                           gint      *natural_width)
{
  g_return_if_fail (GTK_IS_WIDGET (widget));
  g_return_if_fail (minimum_width != NULL || natural_width != NULL);
  g_return_if_fail (height >= 0);

  if (GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
    compute_size_for_orientation (widget, GTK_SIZE_GROUP_HORIZONTAL,
				  -1, minimum_width, natural_width);
  else
    compute_size_for_orientation (widget, GTK_SIZE_GROUP_HORIZONTAL,
				  height, minimum_width, natural_width);
}
Пример #15
0
/**
 * gtk_widget_get_preferred_height_for_width:
 * @widget: a #GtkWidget instance
 * @width: the width which is available for allocation
 * @minimum_height: (out) (allow-none): location for storing the minimum height, or %NULL
 * @natural_height: (out) (allow-none): location for storing the natural height, or %NULL
 *
 * Retrieves a widget's minimum and natural height if it would be given
 * the specified @width.
 *
 * The returned request will be modified by the
 * GtkWidgetClass::adjust_size_request virtual method and by any
 * #GtkSizeGroup<!-- -->s that have been applied. That is, the returned request
 * is the one that should be used for layout, not necessarily the one
 * returned by the widget itself.
 *
 * Since: 3.0
 */
void
gtk_widget_get_preferred_height_for_width (GtkWidget *widget,
                                           gint       width,
                                           gint      *minimum_height,
                                           gint      *natural_height)
{
  g_return_if_fail (GTK_IS_WIDGET (widget));
  g_return_if_fail (minimum_height != NULL || natural_height != NULL);
  g_return_if_fail (width >= 0);

  if (GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
    compute_size_for_orientation (widget, GTK_SIZE_GROUP_VERTICAL,
				  -1, minimum_height, natural_height);
  else
    compute_size_for_orientation (widget, GTK_SIZE_GROUP_VERTICAL,
				  width, minimum_height, natural_height);
}
Пример #16
0
/**
 * gtk_widget_get_request_mode:
 * @widget: a #GtkWidget instance
 *
 * Gets whether the widget prefers a height-for-width layout
 * or a width-for-height layout.
 *
 * <note><para>#GtkBin widgets generally propagate the preference of
 * their child, container widgets need to request something either in
 * context of their children or in context of their allocation
 * capabilities.</para></note>
 *
 * Returns: The #GtkSizeRequestMode preferred by @widget.
 *
 * Since: 3.0
 */
GtkSizeRequestMode
gtk_widget_get_request_mode (GtkWidget *widget)
{
  SizeRequestCache *cache;

  g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_SIZE_REQUEST_CONSTANT_SIZE);

  cache = _gtk_widget_peek_request_cache (widget);

  if (!cache->request_mode_valid)
    {
      cache->request_mode = GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget);
      cache->request_mode_valid = TRUE;
    }

  return cache->request_mode;
}
Пример #17
0
CAMLprim value ml_gtk_widget_style_get_property (value w, value n)
{
    CAMLparam2 (w, n);
    CAMLlocal1 (ret);
    GtkWidget *widget = GtkWidget_val (w);
    gchar *name = String_val (n);
    GParamSpec * pspec;
    pspec = gtk_widget_class_find_style_property
               (GTK_WIDGET_GET_CLASS (widget), name);
    if (pspec) {
        value ret = ml_g_value_new ();
        GValue *gv = GValueptr_val (ret);
        g_value_init (gv, G_PARAM_SPEC_VALUE_TYPE (pspec));
        gtk_widget_style_get_property (widget, name, gv);
    } else {
        invalid_argument("Gobject.Widget.style_get_property");
    }
    CAMLreturn (ret);
}
Пример #18
0
void ucview_info_box_add_action_widget( UCViewInfoBox  *box, GtkWidget *widget, gint response_id )
{
   ResponseData *rd;
   guint signal_id;

   g_return_if_fail( IS_UCVIEW_INFO_BOX( box ) );
   g_return_if_fail( GTK_IS_WIDGET( widget ) );

   rd = get_response_data( widget, TRUE );
   rd->response_id = response_id;
   
   if( GTK_IS_BUTTON( widget ) )
   {
      signal_id = g_signal_lookup( "clicked", GTK_TYPE_BUTTON );
   }
   else
   {
      signal_id = GTK_WIDGET_GET_CLASS( widget )->activate_signal;
   }
   
   if( signal_id )
   {
      GClosure *closure;
      
      closure = g_cclosure_new_object( G_CALLBACK( action_widget_activated ), G_OBJECT( box ) );
      
      g_signal_connect_closure_by_id( widget, signal_id, 0, closure, FALSE );
   }
   else
   {
      g_warning( "UCViewInfoBox: add_action_widget: Item not activatable" );
   }
   
   if( response_id != GTK_RESPONSE_HELP )
   {
      gtk_box_pack_start( GTK_BOX( box->priv->action_box ), widget, FALSE, FALSE, 12 );
   }
   else
   {
      gtk_box_pack_end( GTK_BOX( box->priv->action_box ), widget, FALSE, FALSE, 12 );
   }   
}
Пример #19
0
void wxFrame::UpdateMenuBarSize()
{
    m_menuBarHeight = 2;

    // this is called after Remove with a NULL m_frameMenuBar
    if ( m_frameMenuBar )
    {
        GtkRequisition req;
        gtk_widget_ensure_style(m_frameMenuBar->m_widget);
        // have to call class method directly because
        // "size_request" signal is overridden by wx
        GTK_WIDGET_GET_CLASS(m_frameMenuBar->m_widget)->size_request(
            m_frameMenuBar->m_widget, &req);

        m_menuBarHeight = req.height;
    }

    // resize window in OnInternalIdle
    GtkUpdateSize();
}
Пример #20
0
wxSize wxControl::DoGetBestSize() const
{
    // Do not return any arbitrary default value...
    wxASSERT_MSG( m_widget, wxT("DoGetBestSize called before creation") );

    wxSize best;
    if (m_wxwindow)
    {
        // this is not a native control, size_request is likely to be (0,0)
        best = wxControlBase::DoGetBestSize();
    }
    else
    {
        GtkRequisition req;
        GTK_WIDGET_GET_CLASS(m_widget)->size_request(m_widget, &req);
        best.Set(req.width, req.height);
    }
    CacheBestSize(best);
    return best;
}
Пример #21
0
static void
draw_expander (GtkStyle      *style,
	       cairo_t       *cr,
	       GtkStateType   state,
	       GtkWidget     *widget,
	       const gchar   *detail,
	       gint           x,
	       gint           y,
	       GtkExpanderStyle expander_style)
{
#define DEFAULT_EXPANDER_SIZE 12

  ThemeMatchData match_data;
  gint expander_size;
  gint radius;
  
  if (widget &&
      gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
                                            "expander-size"))
    {
      gtk_widget_style_get (widget,
			    "expander-size", &expander_size,
			    NULL);
    }
  else
    expander_size = DEFAULT_EXPANDER_SIZE;

  radius = expander_size/2;

  match_data.function = TOKEN_D_EXPANDER;
  match_data.detail = (gchar *)detail;
  match_data.flags = (THEME_MATCH_STATE | 
		      THEME_MATCH_EXPANDER_STYLE);
  match_data.state = state;
  match_data.expander_style = expander_style;

  if (!draw_simple_image (style, cr, widget, &match_data, TRUE, TRUE,
			  x - radius, y - radius, expander_size, expander_size))
    parent_class->draw_expander (style, cr, state, widget, detail,
				 x, y, expander_style);
}
Пример #22
0
static gint set_key_press(GtkWidget* wid, GdkEventKey *event, gpointer data)
{
	if((event->keyval == GDK_Control_L || event->keyval == GDK_Control_R) ) 
		g_object_set_data(G_OBJECT (wid), "ControlKeyPressed", GINT_TO_POINTER(1));
	if((event->keyval == GDK_Alt_L || event->keyval == GDK_Alt_R) ) 
		g_object_set_data(G_OBJECT (wid), "ControlKeyPressed", GINT_TO_POINTER(1));

	if((event->keyval == GDK_c || event->keyval == GDK_C) )
	{
		gint ControlKeyPressed = GPOINTER_TO_INT(g_object_get_data(G_OBJECT (wid), "ControlKeyPressed"));
		if(ControlKeyPressed) 
		{
			/* printf("Copy to clipboard\n");*/
			copy_to_clipboard();
		}

	}
	GTK_WIDGET_GET_CLASS(wid)->key_press_event(wid, event);
	return TRUE;

}
Пример #23
0
/* This tries to find a parent widget of a label that would be used for
   mnemonic activation, e.g. a button or a menuitem. If it finds one, it
   returns TRUE. */
static gboolean
gb_label_find_mnemonic_widget (GtkWidget *widget)
{
  GtkWidget *parent;

  parent = widget->parent;

  while (parent)
    {
      if (GTK_WIDGET_GET_CLASS (parent)->activate_signal)
	{
	  return TRUE;
	}
      if (GTK_IS_MENU_ITEM (parent))
	{
	  return TRUE;
	}

      parent = parent->parent;
    }

  return FALSE;
}
Пример #24
0
    static gboolean
    wxgtk_tlw_key_press_event(GtkWidget *widget, GdkEventKey *event)
    {
        GtkWindow* const window = GTK_WINDOW(widget);

        // By default GTK+ checks for the menu accelerators in this (top level)
        // window first and then propagates the event to the currently focused
        // child from where it bubbles up the window parent chain. In wxWidgets,
        // however, we want the child window to have the event first but still
        // handle it as an accelerator if it's not processed there, so we need to
        // customize this by reversing the order of the steps done in the standard
        // GTK+ gtk_window_key_press_event() handler.

        if ( gtk_window_propagate_key_event(window, event) )
            return TRUE;

        if ( gtk_window_activate_key(window, event) )
            return TRUE;

        if (GTK_WIDGET_GET_CLASS(widget)->key_press_event(widget, event))
            return TRUE;

        return FALSE;
    }
Пример #25
0
static void
gtk_widget_query_size_for_orientation (GtkWidget        *widget,
                                       GtkOrientation    orientation,
                                       gint              for_size,
                                       gint             *minimum_size,
                                       gint             *natural_size)
{
  SizeRequestCache *cache;
  gint min_size = 0;
  gint nat_size = 0;
  gboolean found_in_cache;

  if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
    for_size = -1;

  cache = _gtk_widget_peek_request_cache (widget);
  found_in_cache = _gtk_size_request_cache_lookup (cache,
                                                   orientation,
                                                   for_size,
                                                   &min_size,
                                                   &nat_size);
  
  if (!found_in_cache)
    {
      gint adjusted_min, adjusted_natural, adjusted_for_size = for_size;

      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
      gtk_widget_ensure_style (widget);
      G_GNUC_END_IGNORE_DEPRECATIONS;

      if (orientation == GTK_ORIENTATION_HORIZONTAL)
        {
          if (for_size < 0)
            {
	      push_recursion_check (widget, orientation, for_size);
              GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_size, &nat_size);
	      pop_recursion_check (widget, orientation);
            }
          else
            {
              gint ignored_position = 0;
              gint minimum_height;
              gint natural_height;

	      /* Pull the base natural height from the cache as it's needed to adjust
	       * the proposed 'for_size' */
	      gtk_widget_get_preferred_height (widget, &minimum_height, &natural_height);

              /* convert for_size to unadjusted height (for_size is a proposed allocation) */
              GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
                                                                     GTK_ORIENTATION_VERTICAL,
                                                                     &minimum_height,
								     &natural_height,
                                                                     &ignored_position,
                                                                     &adjusted_for_size);

	      push_recursion_check (widget, orientation, for_size);
              GTK_WIDGET_GET_CLASS (widget)->get_preferred_width_for_height (widget, 
									     MAX (adjusted_for_size, minimum_height),
									     &min_size, &nat_size);
	      pop_recursion_check (widget, orientation);
            }
        }
      else
        {
          if (for_size < 0)
            {
	      push_recursion_check (widget, orientation, for_size);
              GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, &min_size, &nat_size);
	      pop_recursion_check (widget, orientation);
            }
          else
            {
              gint ignored_position = 0;
              gint minimum_width;
              gint natural_width;

	      /* Pull the base natural width from the cache as it's needed to adjust
	       * the proposed 'for_size' */
	      gtk_widget_get_preferred_width (widget, &minimum_width, &natural_width);

              /* convert for_size to unadjusted width (for_size is a proposed allocation) */
              GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
                                                                     GTK_ORIENTATION_HORIZONTAL,
								     &minimum_width,
                                                                     &natural_width,
                                                                     &ignored_position,
                                                                     &adjusted_for_size);

	      push_recursion_check (widget, orientation, for_size);
              GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, 
									     MAX (adjusted_for_size, minimum_width),
									     &min_size, &nat_size);
	      pop_recursion_check (widget, orientation);
            }
        }

      if (min_size > nat_size)
        {
          g_warning ("%s %p reported min size %d and natural size %d in %s(); natural size must be >= min size",
                     G_OBJECT_TYPE_NAME (widget), widget, min_size, nat_size, get_vfunc_name (orientation, for_size));
        }

      adjusted_min     = min_size;
      adjusted_natural = nat_size;
      GTK_WIDGET_GET_CLASS (widget)->adjust_size_request (widget,
                                                          orientation,
                                                          &adjusted_min,
                                                          &adjusted_natural);

      if (adjusted_min < min_size ||
          adjusted_natural < nat_size)
        {
          g_warning ("%s %p adjusted size %s min %d natural %d must not decrease below min %d natural %d",
                     G_OBJECT_TYPE_NAME (widget), widget,
                     orientation == GTK_ORIENTATION_VERTICAL ? "vertical" : "horizontal",
                     adjusted_min, adjusted_natural,
                     min_size, nat_size);
          /* don't use the adjustment */
        }
      else if (adjusted_min > adjusted_natural)
        {
          g_warning ("%s %p adjusted size %s min %d natural %d original min %d natural %d has min greater than natural",
                     G_OBJECT_TYPE_NAME (widget), widget,
                     orientation == GTK_ORIENTATION_VERTICAL ? "vertical" : "horizontal",
                     adjusted_min, adjusted_natural,
                     min_size, nat_size);
          /* don't use the adjustment */
        }
      else
        {
          /* adjustment looks good */
          min_size = adjusted_min;
          nat_size = adjusted_natural;
        }

      _gtk_size_request_cache_commit (cache,
                                      orientation,
                                      for_size,
                                      min_size,
                                      nat_size);
    }

  if (minimum_size)
    *minimum_size = min_size;

  if (natural_size)
    *natural_size = nat_size;

  g_assert (min_size <= nat_size);

  GTK_NOTE (SIZE_REQUEST,
            g_print ("[%p] %s\t%s: %d is minimum %d and natural: %d (hit cache: %s)\n",
                     widget, G_OBJECT_TYPE_NAME (widget),
                     orientation == GTK_ORIENTATION_HORIZONTAL ?
                     "width for height" : "height for width" ,
                     for_size, min_size, nat_size,
                     found_in_cache ? "yes" : "no"));
}
Пример #26
0
static void
on_page_mapped (GtkWidget * widget, gpointer user_data)
{
  GTK_WIDGET_GET_CLASS (widget)->focus (widget, GTK_DIR_TAB_FORWARD);
}
Пример #27
0
Preview_t *
make_preview (GimpDrawable *drawable)
{
   Preview_t *data = g_new(Preview_t, 1);
   GtkAdjustment *hadj;
   GtkAdjustment *vadj;
   GtkWidget *preview;
   GtkWidget *window;
   GtkWidget *button, *arrow;
   GtkWidget *ruler;
   GtkWidget *table;
   GtkWidget *scrollbar;
   gint width, height;

   data->drawable = drawable;
   data->preview = preview = gimp_preview_area_new ();

   g_object_set_data (G_OBJECT (preview), "preview", data);
   gtk_widget_set_events(GTK_WIDGET(preview), PREVIEW_MASK);
   g_signal_connect_after(preview, "expose-event",
                          G_CALLBACK(preview_expose), data);
   g_signal_connect (preview, "size-allocate",
                     G_CALLBACK (preview_size_allocate), (gpointer)data);

   /* Handle drop of links in preview widget */
   gtk_drag_dest_set(preview, GTK_DEST_DEFAULT_ALL, target_table,
                     2, GDK_ACTION_COPY);
   g_signal_connect(preview, "drag-data-received",
                    G_CALLBACK(handle_drop), NULL);

   data->widget_width = data->width =
       gimp_drawable_width(drawable->drawable_id);
   data->widget_height = data->height =
       gimp_drawable_height(drawable->drawable_id);
   gtk_widget_set_size_request (preview, data->widget_width,
                                data->widget_height);

   /* The main table */
   data->window = table = gtk_table_new(3, 3, FALSE);
   gtk_table_set_col_spacings (GTK_TABLE (table), 1);
   gtk_table_set_row_spacings (GTK_TABLE (table), 1);

   /* Create button with arrow */
   button = gtk_button_new();
   gtk_widget_set_can_focus (button, FALSE);
   gtk_table_attach(GTK_TABLE(table), button, 0, 1, 0, 1, GTK_FILL, GTK_FILL,
                    0, 0);
   gtk_widget_set_events(button,
                         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
   g_signal_connect(button, "button-press-event",
                    G_CALLBACK(arrow_cb), NULL);
   gtk_widget_show(button);

   arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
   gtk_container_add(GTK_CONTAINER(button), arrow);
   gtk_widget_show(arrow);

   /* Create horizontal ruler */
   data->hruler = ruler = gimp_ruler_new (GTK_ORIENTATION_HORIZONTAL);
   g_signal_connect_swapped(preview, "motion-notify-event",
                            G_CALLBACK(GTK_WIDGET_GET_CLASS(ruler)->motion_notify_event),
                            ruler);

   gtk_table_attach(GTK_TABLE(table), ruler, 1, 2, 0, 1,
                    GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
   gtk_widget_show(ruler);

   /* Create vertical ruler */
   data->vruler = ruler = gimp_ruler_new (GTK_ORIENTATION_VERTICAL);
   g_signal_connect_swapped(preview, "motion-notify-event",
                            G_CALLBACK(GTK_WIDGET_GET_CLASS(ruler)->motion_notify_event),
                            ruler);
   gtk_table_attach(GTK_TABLE(table), ruler, 0, 1, 1, 2,
                    GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
   gtk_widget_show(ruler);

   window = gtk_scrolled_window_new (NULL, NULL);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window),
                                  GTK_POLICY_NEVER, GTK_POLICY_NEVER);
   width = (data->width > 600) ? 600 : data->width;
   height = (data->height > 400) ? 400 : data->height;
   gtk_widget_set_size_request(window, width, height);
   gtk_table_attach(GTK_TABLE(table), window, 1, 2, 1, 2, GTK_FILL, GTK_FILL,
                    0, 0);
   gtk_widget_show(window);

   hadj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (window));

   g_signal_connect (hadj, "changed",
                     G_CALLBACK (scroll_adj_changed),
                     data->hruler);
   g_signal_connect (hadj, "value-changed",
                     G_CALLBACK (scroll_adj_changed),
                     data->hruler);

   vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (window));

   g_signal_connect (vadj, "changed",
                     G_CALLBACK (scroll_adj_changed),
                     data->vruler);
   g_signal_connect (vadj, "value-changed",
                     G_CALLBACK (scroll_adj_changed),
                     data->vruler);

   gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(window), preview);

   scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadj);
   gtk_table_attach(GTK_TABLE(table), scrollbar, 1, 2, 2, 3,
                    GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 0, 0);
   gtk_widget_show (scrollbar);

   scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, vadj);
   gtk_table_attach(GTK_TABLE(table), scrollbar,  2, 3, 1, 2,
                    GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 0, 0);
   gtk_widget_show (scrollbar);

   gtk_widget_show (preview);

   gimp_pixel_rgn_init(&data->src_rgn, drawable, 0, 0, data->width,
                       data->height, FALSE, FALSE);
   render_preview(data, &data->src_rgn);

   gtk_widget_show(table);

   return data;
}
Пример #28
0
static void
gstyle_slidein_get_preferred_height (GtkWidget *widget,
                                     gint      *min_height,
                                     gint      *nat_height)
{
  GstyleSlidein *self = (GstyleSlidein *)widget;
  GtkWidget *child;
  gint min_height_slide_based;
  gint nat_height_slide_based;

  g_assert (GSTYLE_IS_SLIDEIN (self));

  *min_height = *nat_height = 1;

  child = gtk_bin_get_child (GTK_BIN (self));
  if (child != NULL)
    gtk_widget_get_preferred_width (child, min_height, nat_height);

  if (self->interpolate_size ||
      (self->overlay_child != NULL && gtk_widget_get_visible (self->overlay_child)))
    {
      if (gtk_widget_get_request_mode (self->overlay_child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
        {
          gint min_width;
          gint nat_width;

          gtk_widget_get_preferred_width (self->overlay_child, &min_width, &nat_width);
          GTK_WIDGET_GET_CLASS(self->overlay_child)->get_preferred_height_for_width (self->overlay_child,
                                                                                     min_width,
                                                                                     &min_height_slide_based,
                                                                                     &nat_height_slide_based);
        }
      else
        gtk_widget_get_preferred_height (self->overlay_child, &min_height_slide_based, &nat_height_slide_based);

      if (get_orientation (self) == GTK_ORIENTATION_VERTICAL)
        {
          if (!self->interpolate_size)
            {
              min_height_slide_based *= self->offset;
              nat_height_slide_based *= self->offset;
            }

          if (self->slide_fraction > 0)
            {
              min_height_slide_based /= self->slide_fraction;
              nat_height_slide_based /= self->slide_fraction;
            }

          min_height_slide_based += self->slide_margin;
          nat_height_slide_based += self->slide_margin;
        }

      /* TODO: add dynamic grow/shrink mode */
      *min_height = MAX (*min_height, min_height_slide_based);
      *nat_height = MAX (*nat_height, nat_height_slide_based);
    }
  else
    {
      *min_height = MAX (*min_height, self->slide_margin);
      *nat_height = MAX (*nat_height, self->slide_margin);
    }
}
Пример #29
0
gint
main (gint argc, gchar *argv[])
{
    gtk_init (&argc, &argv);
    g_object_set (gtk_settings_get_default (), "gtk-application-prefer-dark-theme", TRUE, NULL);

    gsize size = DEFAULT_SIZE;
    guint32 target = DEFAULT_TARGET;
    const gchar *theme = DEFAULT_THEME;

    GOptionEntry options[] = {
        { "size",   's',  0, G_OPTION_ARG_INT,    &size,   "The size of the grid", "4"           },
        { "target", '\0', 0, G_OPTION_ARG_INT,    &target, "The tile to reach",    "2048"        },
        { "theme",  't',  0, G_OPTION_ARG_STRING, &theme,  "The theme to use",     DEFAULT_THEME },
        { NULL,     '\0', 0, G_OPTION_ARG_NONE,   NULL,    NULL,                   NULL          }
    };
    G_2048_CLEANUP_OPTIONS_FREE GOptionContext *ctx = g_option_context_new ("foobar");
    g_option_context_add_main_entries (ctx, options, NULL);
    g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
    g_option_context_parse (ctx, &argc, &argv, NULL);

    GtkApplication *app = gtk_application_new ("org.gnome.g2048", G_APPLICATION_FLAGS_NONE);
    GApplication *gapp = G_APPLICATION (app);
    G_2048_CLEANUP_ERROR_FREE GError *error = NULL;
    G_APPLICATION_GET_CLASS (gapp)->activate = show_win;

    g_application_register (gapp, NULL, &error);
    if (error)
    {
        fprintf (stderr, "Failed to register the gtk application: %s\n", error->message);
        return EXIT_FAILURE;
    }
    if (g_application_get_is_remote (gapp))
    {
        g_application_activate (gapp);
        return EXIT_SUCCESS;
    }

    G_2048_CLEANUP_FREE gchar *theme_path = get_theme_path (theme);
    if (!theme_path)
        theme_path = get_theme_path (DEFAULT_THEME);
    if (!theme_path)
    {
        g_critical ("No theme found");
        exit (EXIT_FAILURE);
    }

    GtkWidget *score_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
    GtkBox *hbox = GTK_BOX (score_box);
    gtk_box_pack_start (hbox, gtk_label_new ("Score:"), TRUE, TRUE, 0);

    GtkWidget *score_label = gtk_label_new ("0");
    GtkLabel *label = GTK_LABEL (score_label);
    GdkRGBA color;
    gdk_rgba_parse (&color, "white");
    gtk_widget_override_background_color (score_label, GTK_STATE_FLAG_NORMAL, &color);
    gdk_rgba_parse (&color, "black");
    gtk_widget_override_color (score_label, GTK_STATE_FLAG_NORMAL, &color);
    gtk_label_set_width_chars (GTK_LABEL (score_label), 8);
    gtk_box_pack_end (hbox, score_label, TRUE, FALSE, 0);

    GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
    GtkBox *vbox = GTK_BOX (box);
    gtk_box_pack_start (vbox, g_2048_grid_new (size, target, theme_path, label), TRUE, TRUE, 0);
    gtk_box_pack_end (vbox, score_box, TRUE, TRUE, 20);

    GtkWidget *win = gtk_widget_new (GTK_TYPE_APPLICATION_WINDOW,
                                     "application",     app,
                                     "type",            GTK_WINDOW_TOPLEVEL,
                                     "window-position", GTK_WIN_POS_CENTER,
                                     "resizable",       FALSE,
                                     NULL);
    gtk_container_add (GTK_CONTAINER (win), box);
    gtk_widget_show_all (win);
    gtk_widget_override_font (win, pango_font_description_from_string("Monospace 18"));
    GTK_WIDGET_GET_CLASS (win)->key_press_event = on_key;

    return g_application_run (gapp, argc, argv);
}
Пример #30
0
static gboolean
egg_tree_multi_drag_button_press_event (GtkWidget      *widget,
					GdkEventButton *event,
					gpointer        data)
{
  GtkTreeView         *tree_view;
  GtkTreePath         *path = NULL;
  GtkTreeViewColumn   *column = NULL;
  gint                 cell_x, cell_y;
  GtkTreeSelection    *selection;
  EggTreeMultiDndData *priv_data;

  if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)))
    return FALSE;

  if (event->button == 3)
    return FALSE;

  tree_view = GTK_TREE_VIEW (widget);
  priv_data = g_object_get_data (G_OBJECT (tree_view), EGG_TREE_MULTI_DND_STRING);
  if (priv_data == NULL)
    {
      priv_data = g_new0 (EggTreeMultiDndData, 1);
      priv_data->pending_event = FALSE;
      g_object_set_data (G_OBJECT (tree_view),
			 EGG_TREE_MULTI_DND_STRING,
			 priv_data);
    }

  if (g_slist_find (priv_data->event_list, event))
    return FALSE;

  if (priv_data->pending_event)
    {
      /* save the event to be propagated in order */
      priv_data->event_list = g_slist_append (priv_data->event_list,
					      gdk_event_copy ((GdkEvent*)event));
      return TRUE;
    }

  if (event->type == GDK_2BUTTON_PRESS)
    return FALSE;

  gtk_tree_view_get_path_at_pos (tree_view,
				 event->x, event->y,
				 &path, &column,
				 &cell_x, &cell_y);

  selection = gtk_tree_view_get_selection (tree_view);

  if (path)
    {
      gboolean call_parent = (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) ||
			      !gtk_tree_selection_path_is_selected (selection, path) ||
			      event->button != 1);

      if (call_parent)
	(GTK_WIDGET_GET_CLASS (tree_view))->button_press_event (widget, event);

      if (gtk_tree_selection_path_is_selected (selection, path))
    {
      priv_data->pressed_button = event->button;
      priv_data->x = event->x;
      priv_data->y = event->y;

      priv_data->pending_event = TRUE;
      if (!call_parent)
	priv_data->event_list = g_slist_append (priv_data->event_list,
						gdk_event_copy ((GdkEvent*)event));

      if (priv_data->motion_notify_handler == 0)
        {
          priv_data->motion_notify_handler =
	    g_signal_connect (G_OBJECT (tree_view),
	  		      "motion_notify_event",
			      G_CALLBACK (egg_tree_multi_drag_motion_event),
			      NULL);
        }

      if (priv_data->button_release_handler == 0)
        {
          priv_data->button_release_handler =
	    g_signal_connect (G_OBJECT (tree_view),
	 		      "button_release_event",
			      G_CALLBACK (egg_tree_multi_drag_button_release_event),
			      NULL);
        }

      if (priv_data->drag_data_get_handler == 0)
	{
	  priv_data->drag_data_get_handler =
	    g_signal_connect (G_OBJECT (tree_view),
			      "drag_data_get",
			      G_CALLBACK (egg_tree_multi_drag_drag_data_get),
			      NULL);
	}
    }

      gtk_tree_path_free (path);
      /* We called the default handler so we don't let the default handler run */
      return TRUE;
    }

  return FALSE;
}