Пример #1
0
static void
popup_container_position_func (PopupContainer *cont, gint *out_x, gint *out_y)
{
	GtkWidget *console, *top;
	gint x, y;
        GtkRequisition req;

	console = g_object_get_data (G_OBJECT (cont), "console");
	top = gtk_widget_get_toplevel (console);	
	gtk_widget_get_preferred_size ((GtkWidget*) cont, NULL, &req);

	GtkAllocation alloc;
        gdk_window_get_origin (gtk_widget_get_window (top), &x, &y);
	gtk_widget_get_allocation (top, &alloc);
	x += (alloc.width - req.width) / 2;
	y += (alloc.height - req.height) / 2;

        if (x < 0)
                x = 0;

        if (y < 0)
                y = 0;

	*out_x = x;
	*out_y = y;
}
Пример #2
0
static void
egg_cell_renderer_keys_get_size (GtkCellRenderer       *cell,
				 GtkWidget             *widget,
				 const GdkRectangle    *cell_area,
				 gint                  *x_offset,
				 gint                  *y_offset,
				 gint                  *width,
				 gint                  *height)

{
  EggCellRendererKeys *keys = (EggCellRendererKeys *) cell;
  GtkRequisition requisition;

  if (keys->sizing_label == NULL)
    keys->sizing_label = gtk_label_new (TOOLTIP_TEXT);

#if GTK_CHECK_VERSION (3,0,0)
  gtk_widget_get_preferred_size (keys->sizing_label, NULL, &requisition);
#else
  gtk_widget_size_request (keys->sizing_label, &requisition);
#endif
  (* GTK_CELL_RENDERER_CLASS (parent_class)->get_size) (cell, widget, cell_area, x_offset, y_offset, width, height);
  /* FIXME: need to take the cell_area et al. into account */
  if (width)
    *width = MAX (*width, requisition.width);
  if (height)
    *height = MAX (*height, requisition.height);
}
Пример #3
0
/**
 * seahorse_util_determine_popup_menu_position:
 * @menu: The menu to place
 * @x: (out) x pos of the menu
 * @y: (out) y pos of the menu
 * @push_in: (out) will be set to TRUE
 * @gdata: GTK_WIDGET for which the menu is
 *
 *
 * Callback to determine where a popup menu should be placed
 *
 */
void
seahorse_util_determine_popup_menu_position (GtkMenu *menu, int *x, int *y,
                                             gboolean *push_in, gpointer  gdata)
{
        GtkWidget      *widget;
        GtkRequisition  requisition;
        GtkAllocation   allocation;
        gint            menu_xpos;
        gint            menu_ypos;

        widget = GTK_WIDGET (gdata);

        gtk_widget_get_preferred_size (GTK_WIDGET (menu), &requisition, NULL);

        gdk_window_get_origin (gtk_widget_get_window (widget), &menu_xpos, &menu_ypos);

        gtk_widget_get_allocation (widget, &allocation);
        menu_xpos += allocation.x;
        menu_ypos += allocation.y;


        if (menu_ypos > gdk_screen_get_height (gtk_widget_get_screen (widget)) / 2)
                menu_ypos -= requisition.height;
        else
                menu_ypos += allocation.height;

        *x = menu_xpos;
        *y = menu_ypos;
        *push_in = TRUE;
}
Пример #4
0
static void
position_popup (GNCDateEdit *gde)
{
    gint x, y;
    gint bwidth, bheight;
    GtkRequisition req;
    GtkAllocation alloc;

    gtk_widget_get_preferred_size (gde->cal_popup, &req, NULL);

    gdk_window_get_origin (gtk_widget_get_window (gde->date_button), &x, &y);

    gtk_widget_get_allocation (gde->date_button, &alloc);
    x += alloc.x;
    y += alloc.y;
    bwidth = alloc.width;
    bheight = alloc.height;

    x += bwidth - req.width;
    y += bheight;

    if (x < 0)
        x = 0;

    if (y < 0)
        y = 0;

    gtk_window_move (GTK_WINDOW (gde->cal_popup), x, y);
}
Пример #5
0
static gboolean
get_child_position (GtkOverlay    *overlay,
                    GtkWidget     *widget,
                    GtkAllocation *alloc,
                    GtkWidget     *relative)
{
  GtkRequisition req;
  GtkWidget *child;
  GtkAllocation main_alloc;
  gint x, y;

  child = gtk_bin_get_child (GTK_BIN (overlay));

  gtk_widget_translate_coordinates (relative, child, 0, 0, &x, &y);
  main_alloc.x = x;
  main_alloc.y = y;
  main_alloc.width = gtk_widget_get_allocated_width (relative);
  main_alloc.height = gtk_widget_get_allocated_height (relative);

  gtk_widget_get_preferred_size (widget, NULL, &req);

  alloc->x = main_alloc.x;
  alloc->width = MIN (main_alloc.width, req.width);
  if (gtk_widget_get_halign (widget) == GTK_ALIGN_END)
    alloc->x += main_alloc.width - req.width;

  alloc->y = main_alloc.y;
  alloc->height = MIN (main_alloc.height, req.height);
  if (gtk_widget_get_valign (widget) == GTK_ALIGN_END)
    alloc->y += main_alloc.height - req.height;

  return TRUE;
}
Пример #6
0
/* static */
wxSize wxButtonBase::GetDefaultSize()
{
    static wxSize size = wxDefaultSize;
    if (size == wxDefaultSize)
    {
        // NB: Default size of buttons should be same as size of stock
        //     buttons as used in most GTK+ apps. Unfortunately it's a little
        //     tricky to obtain this size: stock button's size may be smaller
        //     than size of button in GtkButtonBox and vice versa,
        //     GtkButtonBox's minimal button size may be smaller than stock
        //     button's size. We have to retrieve both values and combine them.

        GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        GtkWidget *box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
        GtkWidget *btn = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
        gtk_container_add(GTK_CONTAINER(box), btn);
        gtk_container_add(GTK_CONTAINER(wnd), box);
        GtkRequisition req;
        gtk_widget_get_preferred_size(btn, NULL, &req);

        gint minwidth, minheight;
        gtk_widget_style_get(box,
                             "child-min-width", &minwidth,
                             "child-min-height", &minheight,
                             NULL);

        size.x = wxMax(minwidth, req.width);
        size.y = wxMax(minheight, req.height);

        gtk_widget_destroy(wnd);
    }
    return size;
}
Пример #7
0
static void
popup_position (PopupContainer *container, gint *out_x, gint *out_y)
{
	GtkWidget *poswidget;
	poswidget = g_object_get_data (G_OBJECT (container), "__poswidget");

	gint x, y;
        GtkRequisition req;

	gtk_widget_get_preferred_size (poswidget, NULL, &req);

	GtkAllocation alloc;
        gdk_window_get_origin (gtk_widget_get_window (poswidget), &x, &y);
	gtk_widget_get_allocation (poswidget, &alloc);
        x += alloc.x;
        y += alloc.y;
        y += alloc.height;

        if (x < 0)
                x = 0;

        if (y < 0)
                y = 0;

	*out_x = x;
	*out_y = y;
}
gint
gnc_popup_get_button_width (void)
{
    GtkWidget *window, *button, *arrow;
    gint       width;

    GtkRequisition req;

    window = gtk_window_new (GTK_WINDOW_POPUP);

    button = gtk_button_new ();
    gtk_widget_show (button);
    gtk_container_add (GTK_CONTAINER (window), button);

    arrow = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (arrow);

    gtk_container_add (GTK_CONTAINER (button), arrow);

    gtk_window_move (GTK_WINDOW (window), -500, -500);
    gtk_widget_show (window);

    gtk_widget_get_preferred_size (window, &req, NULL);

    width = req.width;

    gtk_widget_destroy (window);

    return width;
}
Пример #9
0
wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
{
    // Compute the max size of the tab labels.
    wxSize sizeTabMax;
    const size_t pageCount = GetPageCount();
    for ( size_t n = 0; n < pageCount; n++ )
    {
        GtkRequisition req;
        gtk_widget_get_preferred_size(GetNotebookPage(n)->m_box, NULL, &req);
        sizeTabMax.IncTo(wxSize(req.width, req.height));
    }

    // Unfortunately this doesn't account for the real tab size and I don't
    // know how to find it, e.g. where do the margins below come from.
    const int PAGE_MARGIN = 3;
    const int TAB_MARGIN = 4;

    sizeTabMax.IncBy(3*TAB_MARGIN);

    wxSize sizeFull(sizePage);
    if ( IsVertical() )
        sizeFull.y += sizeTabMax.y;
    else
        sizeFull.x += sizeTabMax.x;

    sizeFull.IncBy(2*PAGE_MARGIN);

    return sizeFull;
}
Пример #10
0
void
gedit_utils_menu_position_under_widget (GtkMenu  *menu,
					gint     *x,
					gint     *y,
					gboolean *push_in,
					gpointer  user_data)
{
	GtkWidget *widget;
	GtkRequisition requisition;
	GtkAllocation allocation;

	widget = GTK_WIDGET (user_data);
	widget_get_origin (widget, x, y);

	gtk_widget_get_preferred_size (GTK_WIDGET (menu), &requisition,
	                               NULL);

	gtk_widget_get_allocation (widget, &allocation);

	if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
	{
		*x += allocation.x + allocation.width - requisition.width;
	}
	else
	{
		*x += allocation.x;
	}

	*y += allocation.y + allocation.height;

	*push_in = TRUE;
}
Пример #11
0
static void ygtk_adj_size_get_preferred_size (
	GtkWidget *widget, GtkRequisition *requisition)
{
	GtkWidget *child = gtk_bin_get_child(GTK_BIN (widget));

	requisition->width = requisition->height = 0;
	if (child && gtk_widget_get_visible((child))) {
		gtk_widget_get_preferred_size(child, NULL, requisition);

		guint border = gtk_container_get_border_width(GTK_CONTAINER (widget));
		requisition->width += border * 2;
		requisition->height += border * 2;

		YGtkAdjSize *adj_size = YGTK_ADJ_SIZE (widget);
		if (adj_size->min_size_cb) {
			guint min_width, min_height;
			adj_size->min_size_cb (&min_width, &min_height, adj_size->min_size_data);
			requisition->width = MAX (requisition->width, min_width);
			requisition->height = MAX (requisition->height, min_height);
		}
		requisition->width = MAX (requisition->width, adj_size->min_width);
		requisition->height = MAX (requisition->height, adj_size->min_height);

		if (adj_size->max_width)
			requisition->width = MIN (requisition->width, adj_size->max_width);
		if (adj_size->max_height)
			requisition->height = MIN (requisition->height, adj_size->max_height);

		if (adj_size->only_expand) {
			adj_size->min_width = requisition->width;
			adj_size->min_height = requisition->height;
		}
	}
}
Пример #12
0
/* We put size_request and _allocate in the same functions for both
   orientations because it's just easier to maintain having the
   logic in the same place. */
static void ygtk_ratio_box_get_preferred_size (GtkWidget      *widget,
                                               GtkRequisition *requisition,
                                               GtkOrientation  orientation)
{
	requisition->width = requisition->height = 0;

	YGtkRatioBox* box = YGTK_RATIO_BOX (widget);
	gint children_nb = 0;
	GList *i;
	for (i = box->children; i; i = i->next) {
		YGtkRatioBoxChild* child = i->data;
		if (!gtk_widget_get_visible (child->widget))
			continue;

		GtkRequisition min_child_req;
                GtkRequisition nat_child_req;
		gtk_widget_get_preferred_size (child->widget, &min_child_req, &nat_child_req);
		if (orientation == GTK_ORIENTATION_HORIZONTAL)
			requisition->height = MAX (requisition->height, min_child_req.height);
		else
			requisition->width = MAX (requisition->width, min_child_req.width);
		children_nb++;
	}
	gint spacing = children_nb ? box->spacing*(children_nb-1) : 0;
	if (orientation == GTK_ORIENTATION_HORIZONTAL)
		requisition->width += spacing;
	else
		requisition->height += spacing;

	int border = gtk_container_get_border_width(GTK_CONTAINER (box));
	requisition->width += border*2;
	requisition->height += border*2;
}
Пример #13
0
static gint
cpufreq_applet_get_widget_size (CPUFreqApplet *applet,
                                GtkWidget     *widget)
{
        GtkRequisition  req;
        gint            size;

        if (!gtk_widget_get_visible (widget))
                return 0;

#if GTK_CHECK_VERSION (3, 0, 0)
        gtk_widget_get_preferred_size (widget, &req, NULL);
#else
        gtk_widget_size_request (widget, &req);
#endif

        switch (applet->orient) {
        case MATE_PANEL_APPLET_ORIENT_LEFT:
        case MATE_PANEL_APPLET_ORIENT_RIGHT:
                size = req.width;
                break;
        case MATE_PANEL_APPLET_ORIENT_UP:
        case MATE_PANEL_APPLET_ORIENT_DOWN:
                size = req.height;
                break;
        default:
                g_assert_not_reached ();
        }

        return size;
}
Пример #14
0
static void
gtk_image_menu_item_get_preferred_height (GtkWidget        *widget,
                                          gint             *minimum,
                                          gint             *natural)
{
  GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
  GtkImageMenuItemPrivate *priv = image_menu_item->priv;
  gint child_height = 0;
  GtkPackDirection pack_dir;
  GtkWidget *parent;

  parent = gtk_widget_get_parent (widget);

  if (GTK_IS_MENU_BAR (parent))
    pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
  else
    pack_dir = GTK_PACK_DIRECTION_LTR;

  if (priv->image && gtk_widget_get_visible (priv->image))
    {
      GtkRequisition child_requisition;

      gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);

      child_height = child_requisition.height;
    }

  GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->get_preferred_height (widget, minimum, natural);

  if (pack_dir == GTK_PACK_DIRECTION_RTL || pack_dir == GTK_PACK_DIRECTION_LTR)
    {
      *minimum = MAX (*minimum, child_height);
      *natural = MAX (*natural, child_height);
    }
}
Пример #15
0
static void popup_position_func(GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer user_data)
{
	GtkRequisition req;
	GdkPoint* pos;

	pos = user_data;

#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
#else
	gtk_widget_size_request(GTK_WIDGET(menu), &req);
#endif

	*x = pos->x;
	*y = pos->y;

	if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
	{
		*x = MAX (0, *x - req.width);
	}

	/* Ensure onscreen */
	*x = CLAMP (*x, 0, MAX(0, gdk_screen_width() - req.width));
	*y = CLAMP (*y, 0, MAX(0, gdk_screen_height() - req.height));
}
Пример #16
0
/* If the menu is popped up in response to a keystroke, center it
 * immediately below the toolbar.
 */
static void
tm_popup_position_func(GtkMenu * menu, gint * x, gint * y,
                       gboolean * push_in, gpointer user_data)
{
    GtkWidget *toolbar = GTK_WIDGET(user_data);
    GdkScreen *screen = gtk_widget_get_screen(toolbar);
    GtkRequisition req;
    gint monitor_num;
    GdkRectangle monitor;
    GtkAllocation allocation;

    g_return_if_fail(gtk_widget_get_window(toolbar));

    gdk_window_get_origin(gtk_widget_get_window(toolbar), x, y);

    gtk_widget_get_preferred_size(GTK_WIDGET(menu), NULL, &req);

    gtk_widget_get_allocation(toolbar, &allocation);
    *x += (allocation.width - req.width) / 2;
    *y += allocation.height;

    monitor_num = gdk_screen_get_monitor_at_point(screen, *x, *y);
    gtk_menu_set_monitor(menu, monitor_num);
    gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor);

    *x = CLAMP(*x, monitor.x,
               monitor.x + MAX(0, monitor.width - req.width));
    *y = CLAMP(*y, monitor.y,
               monitor.y + MAX(0, monitor.height - req.height));

    *push_in = FALSE;
}
Пример #17
0
static void
ephy_fullscreen_popup_update_position (EphyFullscreenPopup *popup)
{
	GtkWidget *widget = GTK_WIDGET (popup);
	GtkRequisition requisition;
	GdkScreen *screen;
	GdkRectangle screen_rect;
	int popup_width;

	gtk_widget_get_preferred_size (widget, &requisition, NULL);
	popup_width = requisition.width;

	screen = gtk_widget_get_screen (widget);
	gdk_screen_get_monitor_geometry
		(screen,
		 gdk_screen_get_monitor_at_window (screen,
						   gtk_widget_get_window (widget)),
		 &screen_rect);

	if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
	{
		gtk_window_move (GTK_WINDOW (widget),
				 screen_rect.x, screen_rect.y);
	}
	else
	{
		gtk_window_move (GTK_WINDOW (widget),
				 screen_rect.x + screen_rect.width - popup_width,
				 screen_rect.y);
	}
}
Пример #18
0
int get_widget_xy(GtkWidget *win, GtkWidget *widget, int *rx, int *ry)
{
    if (!win && !widget)
        p_err("get_widget_xy err");

//  gdk_flush();

    GtkRequisition sz;
    gtk_widget_get_preferred_size(widget, NULL, &sz);
    int wx, wy;

    wx=wy=0;

    gtk_widget_translate_coordinates(widget, win,
                                     0, sz.height, &wx, &wy);

    gtk_widget_translate_coordinates(widget, win,
                                     0, sz.height, &wx, &wy);

//  dbg("%d wx:%d\n", index,  wx);

    int win_x, win_y;

    gtk_window_get_position(GTK_WINDOW(win), &win_x, &win_y);
    int win_xl, win_yl;
    get_win_size(win, &win_xl, &win_yl);

    if (wx > win_xl)
        wx = win_xl;

    *rx = win_x + wx;
    *ry = win_y + wy;
    return wx;
}
Пример #19
0
static void
menu_position_func (GtkMenu           *menu,
                    int               *x,
                    int               *y,
                    gboolean          *push_in,
                    GtkButton         *button)
{
  GtkAllocation allocation;
  GtkWidget *widget = GTK_WIDGET (button);
  GtkRequisition menu_req;
  GtkTextDirection direction;
  GdkWindow *window;
  GtkWidget *toplevel;

  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
  gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);

  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
                                 &menu_req, NULL);

  direction = gtk_widget_get_direction (widget);
  window = gtk_widget_get_window (widget);

  gtk_widget_get_allocation (widget, &allocation);

  gdk_window_get_origin (window, x, y);
  *x += allocation.x;
  *y += allocation.y + allocation.height;

  if (direction == GTK_TEXT_DIR_LTR)
      *x += allocation.width - menu_req.width;

  *push_in = FALSE;
}
Пример #20
0
wxSize wxChoice::DoGetSizeFromTextSize(int xlen, int ylen) const
{
    wxASSERT_MSG( m_widget, wxS("GetSizeFromTextSize called before creation") );

    // a GtkEntry for wxComboBox and a GtkCellView for wxChoice
    GtkWidget* childPart = gtk_bin_get_child(GTK_BIN(m_widget));

    // Set a as small as possible size for the control, so preferred sizes
    // return "natural" sizes, not taking into account the previous ones (which
    // seems to be GTK+3 behaviour)
    gtk_widget_set_size_request(m_widget, 0, 0);

    // We are interested in the difference of sizes between the whole contol
    // and its child part. I.e. arrow, separators, etc.
    GtkRequisition req;
    gtk_widget_get_preferred_size(childPart, NULL, &req);
    wxSize totalS = GTKGetPreferredSize(m_widget);

    wxSize tsize(xlen + totalS.x - req.width, totalS.y);

    // For a wxChoice, not for wxComboBox, add some margins
    if ( !GTK_IS_ENTRY(childPart) )
        tsize.IncBy(5, 0);

    // Perhaps the user wants something different from CharHeight
    if ( ylen > 0 )
        tsize.IncBy(0, ylen - GetCharHeight());

    return tsize;
}
Пример #21
0
wxSize wxChoice::DoGetSizeFromTextSize(int xlen, int ylen) const
{
    wxASSERT_MSG( m_widget, wxS("GetSizeFromTextSize called before creation") );

    // a GtkEntry for wxComboBox and a GtkCellView for wxChoice
    GtkWidget* childPart = gtk_bin_get_child(GTK_BIN(m_widget));

    // We are interested in the difference of sizes between the whole contol
    // and its child part. I.e. arrow, separators, etc.
    GtkRequisition req;
    gtk_widget_get_preferred_size(childPart, NULL, &req);
    wxSize totalS = GTKGetPreferredSize(m_widget);

    wxSize tsize(xlen + totalS.x - req.width, totalS.y);

    // For a wxChoice, not for wxComboBox, add some margins
    if ( !GTK_IS_ENTRY(childPart) )
        tsize.IncBy(5, 0);

    // Perhaps the user wants something different from CharHeight
    if ( ylen > 0 )
        tsize.IncBy(0, ylen - GetCharHeight());

    return tsize;
}
Пример #22
0
static gboolean
gdict_sidebar_select_button_press_cb (GtkWidget      *widget,
				      GdkEventButton *event,
				      gpointer        user_data)
{
  GdictSidebar *sidebar = GDICT_SIDEBAR (user_data);
  GtkAllocation allocation;

  if (event->button == 1)
    {
      GtkRequisition req;
      gint width;

      gtk_widget_get_allocation (widget, &allocation);
      width = allocation.width;
      gtk_widget_set_size_request (sidebar->priv->menu, -1, -1);
      gtk_widget_get_preferred_size (sidebar->priv->menu, NULL, &req);
      gtk_widget_set_size_request (sidebar->priv->menu,
		      		   MAX (width, req.width), -1);
      gtk_widget_grab_focus (widget);

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
      gtk_menu_popup (GTK_MENU (sidebar->priv->menu),
		      NULL, NULL,
		      gdict_sidebar_menu_position_function, widget,
		      event->button, event->time);

      return TRUE;
    }

  return FALSE;
}
Пример #23
0
static void
get_menu_pos (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
{
	charpick_data *curr_data = data;
	GtkRequisition  reqmenu;
	gint tempx, tempy, width, height;
	gint screen_width, screen_height;

	gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &reqmenu);
	gdk_window_get_origin (GDK_WINDOW (gtk_widget_get_window(curr_data->applet)), &tempx, &tempy);
	gdk_window_get_geometry (GDK_WINDOW (gtk_widget_get_window(curr_data->applet)), NULL, NULL,
				 &width, &height
				 );
     			      
	switch (mate_panel_applet_get_orient (MATE_PANEL_APPLET (curr_data->applet))) {
	case MATE_PANEL_APPLET_ORIENT_DOWN:
		tempy += height;
		break;
	case MATE_PANEL_APPLET_ORIENT_UP:
		tempy -= reqmenu.height;
		break;
	case MATE_PANEL_APPLET_ORIENT_LEFT:
		tempx -= reqmenu.width;
		break;
	case MATE_PANEL_APPLET_ORIENT_RIGHT:
		tempx += width;
		break;
	}

	gdk_window_get_geometry (gdk_screen_get_root_window (gdk_screen_get_default()),
				 NULL, NULL, &screen_width, &screen_height);

	*x = CLAMP (tempx, 0, MAX (0, screen_width - reqmenu.width));
	*y = CLAMP (tempy, 0, MAX (0, screen_height - reqmenu.height));
}
Пример #24
0
static gboolean
get_child_position (GtkOverlay     *overlay,
                    GtkWidget      *widget,
                    GtkAllocation  *allocation,
                    GtkColorEditor *editor)
{
  GtkRequisition req;
  GtkAllocation alloc;
  gint s, e;

  gtk_widget_get_preferred_size (widget, &req, NULL);

  allocation->x = 0;
  allocation->y = 0;
  allocation->width = req.width;
  allocation->height = req.height;

  if (widget == editor->priv->sv_popup)
    {
      if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL)
        allocation->x = 0;
      else
        allocation->x = gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width;
      allocation->y = req.height / 3;
    }
  else if (widget == editor->priv->h_popup)
    {
      gtk_widget_get_allocation (editor->priv->h_slider, &alloc);
      gtk_range_get_slider_range (GTK_RANGE (editor->priv->h_slider), &s, &e);

      if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL)
        gtk_widget_translate_coordinates (editor->priv->h_slider,
                                          gtk_widget_get_parent (editor->priv->grid),
                                          - req.width, (s + e - req.height) / 2,
                                          &allocation->x, &allocation->y);
      else
        gtk_widget_translate_coordinates (editor->priv->h_slider,
                                          gtk_widget_get_parent (editor->priv->grid),
                                          alloc.width, (s + e - req.height) / 2,
                                          &allocation->x, &allocation->y);
    }
  else if (widget == editor->priv->a_popup)
    {
      gtk_widget_get_allocation (editor->priv->a_slider, &alloc);
      gtk_range_get_slider_range (GTK_RANGE (editor->priv->a_slider), &s, &e);

      gtk_widget_translate_coordinates (editor->priv->a_slider,
                                        gtk_widget_get_parent (editor->priv->grid),
                                        (s + e - req.width) / 2, - req.height,
                                        &allocation->x, &allocation->y);
    }
  else
    return FALSE;

  allocation->x = CLAMP (allocation->x, 0, gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width);
  allocation->y = CLAMP (allocation->y, 0, gtk_widget_get_allocated_height (GTK_WIDGET (overlay)) - req.height);

  return TRUE;
}
Пример #25
0
/**
 * Constructor
 */ 
AboutBox::AboutBox() : Gtk::Dialog(_("About Inkscape")) {

    // call this first
    initStrings();

    Gtk::Notebook *tabs=new Gtk::Notebook();

    tabs->set_scrollable();

    Gtk::Widget *splash=build_splash_widget();
    if (splash) {
        tabs->append_page(*manage(splash), _("_Splash"), true);
    }

    tabs->append_page(*manage(
        make_scrolled_text(authors_text)), _("_Authors"), true);
    tabs->append_page(*manage(
        make_scrolled_text(translators_text)), _("_Translators"), true);
    tabs->append_page(*manage(
        make_scrolled_text(license_text)), _("_License"), true);

#if WITH_GTKMM_3_0
    get_content_area()->pack_end(*manage(tabs), true, true);
#else
    get_vbox()->pack_end(*manage(tabs), true, true);
#endif

    tabs->show_all();

    add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
    set_default_response(Gtk::RESPONSE_CLOSE);

    Gtk::Label *label=new Gtk::Label();
    gchar *label_text = 
        g_strdup_printf("<small>Inkscape %s</small>",
              Inkscape::version_string);
    label->set_markup(label_text);
    label->set_alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
    label->set_padding(5,0);
    g_free(label_text);
    label->set_selectable(true);
    label->show();

#if WITH_GTKMM_3_0
    get_content_area()->pack_start(*manage(label), false, false);
#else
    get_vbox()->pack_start(*manage(label), false, false);
#endif

    Gtk::Requisition requisition;
#if GTK_CHECK_VERSION(3,0,0)
    gtk_widget_get_preferred_size(reinterpret_cast<GtkWidget*>(gobj()), &requisition, NULL);
#else
    gtk_widget_size_request (reinterpret_cast<GtkWidget*>(gobj()), &requisition);
#endif
    // allow window to shrink
    set_size_request(0, 0);
    set_default_size(requisition.width, requisition.height);
}
Пример #26
0
void
uim_cand_win_gtk_layout(UIMCandWinGtk *cwin,
                        gint topwin_x, gint topwin_y,
                        gint topwin_width, gint topwin_height)
{
    GtkRequisition req;
    int  x, y;
    int  cursor_x, cursor_y;
    int  sc_he, cw_he; /*screen height, candidate window height*/
    int  sc_wi, cw_wi;

    g_return_if_fail(UIM_IS_CAND_WIN_GTK(cwin));

#if GTK_CHECK_VERSION(3, 0, 0)
    gtk_widget_get_preferred_size(GTK_WIDGET(cwin), &req, NULL);
#else
    gtk_widget_size_request(GTK_WIDGET(cwin), &req);
#endif
    cw_wi = req.width;
    cw_he = req.height;

    sc_he = gdk_screen_get_height(gdk_screen_get_default ());
    sc_wi = gdk_screen_get_width (gdk_screen_get_default ());

    /* FIXME */
    switch (cwin->position) {
    case UIM_CAND_WIN_POS_LEFT:
        cursor_x = 0;
        break;
    case UIM_CAND_WIN_POS_RIGHT:
        cursor_x = topwin_width - cw_wi;
        break;
    default:
        cursor_x = cwin->cursor.x;
        break;
    }
    cursor_y = cwin->cursor.y;

    if (sc_wi <  topwin_x + cursor_x + cw_wi) {
        /* x = topwin_x + cursor_x - cw_wi; */
        x = sc_wi - cw_wi;
    } else {
        x = topwin_x + cursor_x;
    }

    if (sc_he <  topwin_y + cursor_y +  cwin->cursor.height + cw_he) {
        y = topwin_y + cursor_y - cw_he;
    } else {
        y = topwin_y + cursor_y +  cwin->cursor.height;
    }

    gtk_window_move(GTK_WINDOW(cwin), x, y);
#if GTK_CHECK_VERSION(3, 7, 8)
    if (gtk_widget_get_mapped(cwin->view) && GTK_IS_TREE_VIEW(cwin->view))
        gtk_widget_queue_resize_no_redraw(cwin->view);
#endif

    uim_cand_win_gtk_layout_sub_window(cwin);
}
Пример #27
0
void get_win_size(GtkWidget *win, int *width, int *height)
{
  GtkRequisition sz;
  sz.width = sz.height = 0;
  gtk_widget_get_preferred_size(GTK_WIDGET(win), NULL, &sz);
  *width = sz.width;
  *height = sz.height;
}
static void
hd_status_area_box_size_allocate (GtkWidget     *widget,
                                  GtkAllocation *allocation)
{
  HDStatusAreaBoxPrivate *priv;
  guint border_width;
  GtkAllocation child_allocation = {0, 0, 0, 0};
  guint visible_children = 0;
  GList *c;

  priv = HD_STATUS_AREA_BOX (widget)->priv;

  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));

  /* chain up */
  GTK_WIDGET_CLASS (hd_status_area_box_parent_class)->size_allocate (widget,
                                                                     allocation);

  child_allocation.height = ITEM_HEIGHT;

  /* Place the first eight visible children */
  for (c = priv->children; c && visible_children < priv->max_visible_children; c = c->next)
    {
      HDStatusAreaBoxChild *info = c->data;
      GtkRequisition child_requisition;

      /* ignore hidden widgets */
      if (!gtk_widget_is_visible (info->widget))
        continue;

      /* there are some widgets which need a size request */
      gtk_widget_get_preferred_size (info->widget, &child_requisition, NULL);

      child_allocation.x = allocation->x +
                           border_width +
                           PADDING_LEFT +
                           (visible_children / 2) * (ITEM_WIDTH + SPACING);
      child_allocation.y = allocation->y +
                           border_width +
                           (visible_children % 2 * (ITEM_HEIGHT + SPACING));

      child_allocation.width = ITEM_WIDTH;
      child_allocation.height = ITEM_HEIGHT;

      gtk_widget_size_allocate (info->widget, &child_allocation);
      gtk_widget_set_child_visible (info->widget, TRUE);

      visible_children++;
    }

  /* Hide the other children */
  for (; c; c = c->next)
    {
      HDStatusAreaBoxChild *info = c->data;

      gtk_widget_set_child_visible (info->widget, FALSE);
    }
}
Пример #29
0
static void
overlay_draw (GtkDrawingArea *da,
              cairo_t        *cr,
              int             width,
              int             height,
              gpointer        data)
{
  GtkWidget *widget = GTK_WIDGET (da);
  PangoLayout *layout;
  const double dashes[] = { 6, 18 };
  GtkAllocation label_allocation;
  GtkRequisition minimum_size, natural_size;
  GtkWidget *label = data;
  gint x, y;

  cairo_translate (cr, -0.5, -0.5);
  cairo_set_line_width (cr, 1);

  cairo_set_source_rgb (cr, 1, 1, 1);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_fill (cr);

  gtk_widget_translate_coordinates (label, widget, 0, 0, &x, &y);
  layout = gtk_widget_create_pango_layout (widget, "");

  gtk_widget_get_preferred_size (label, &minimum_size, &natural_size); 

  pango_layout_set_markup (layout,
    "<span color='#c33'>\342\227\217 requisition</span>\n"
    "<span color='#3c3'>\342\227\217 natural size</span>\n"
    "<span color='#33c'>\342\227\217 allocation</span>", -1);

  pango_cairo_show_layout (cr, layout);
  g_object_unref (layout);

  gtk_widget_get_allocation (label, &label_allocation);

  cairo_rectangle (cr,
                   x + 0.5 * (label_allocation.width - minimum_size.width),
                   y + 0.5 * (label_allocation.height - minimum_size.height),
                   minimum_size.width, minimum_size.height);
  cairo_set_source_rgb (cr, 0.8, 0.2, 0.2);
  cairo_set_dash (cr, NULL, 0, 0);
  cairo_stroke (cr);

  cairo_rectangle (cr, x, y, label_allocation.width, label_allocation.height);
  cairo_set_source_rgb (cr, 0.2, 0.2, 0.8);
  cairo_set_dash (cr, dashes, 2, 0.5);
  cairo_stroke (cr);

  cairo_rectangle (cr,
                   x + 0.5 * (label_allocation.width - natural_size.width),
                   y + 0.5 * (label_allocation.height - natural_size.height),
                   natural_size.width, natural_size.height);
  cairo_set_source_rgb (cr, 0.2, 0.8, 0.2);
  cairo_set_dash (cr, dashes, 2, 12.5);
  cairo_stroke (cr);
}
Пример #30
0
static void
brasero_file_chooser_find_pane (GtkWidget *child,
				gpointer footer)
{
	if (GTK_IS_PANED (child)) {
		GList *children_vbox;
		GList *iter_vbox;
		GtkWidget *vbox;

		vbox = gtk_paned_get_child2 (GTK_PANED (child));
		children_vbox = gtk_container_get_children (GTK_CONTAINER (vbox));
		for (iter_vbox = children_vbox; iter_vbox; iter_vbox = iter_vbox->next) {
			if (GTK_IS_BOX (iter_vbox->data) &&
                            gtk_orientable_get_orientation (GTK_ORIENTABLE (iter_vbox->data)) == GTK_ORIENTATION_HORIZONTAL) {
				GtkPackType packing;

				gtk_box_query_child_packing (GTK_BOX (vbox),
							     GTK_WIDGET (iter_vbox->data),
							     NULL,
							     NULL,
							     NULL,
							     &packing);

				if (packing == GTK_PACK_START) {
					GtkRequisition total_request, footer_request;

					gtk_widget_get_preferred_size (GTK_WIDGET (vbox),
								 &total_request, NULL);
					gtk_widget_get_preferred_size (GTK_WIDGET (iter_vbox->data),
								 &footer_request, NULL);
					*((gint *) footer) = total_request.height - footer_request.height;
					break;
				}
			}
		}
		g_list_free (children_vbox);
	}
	else if (GTK_IS_CONTAINER (child)) {
		gtk_container_foreach (GTK_CONTAINER (child),
				       brasero_file_chooser_find_pane,
				       footer);
	}
}