Пример #1
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;
}
Пример #2
0
 virtual bool get_valign(GtkAlign& align) {
     widget_attached_t detached = 0;
     if ((detached = this->attached_to())) {
         align = gtk_widget_get_valign(detached);
         return true;
     }
     return false;
 }
Пример #3
0
/* TODO - Optimize this a bit */
static void 
calculate_pupil_xy (EyesApplet *eyes_applet,
		    gint x, gint y,
		    gint *pupil_x, gint *pupil_y, GtkWidget* widget)
{
        GtkAllocation allocation;
        double sina;
        double cosa;
        double h;
        double temp;
 	 double nx, ny;

	 gfloat xalign, yalign;
	 gint width, height;

	 gtk_widget_get_allocation (GTK_WIDGET(widget), &allocation);
	 width = allocation.width;
	 height = allocation.height;

	xalign = gtk_align_to_gfloat (gtk_widget_get_halign (widget));
	yalign = gtk_align_to_gfloat (gtk_widget_get_valign (widget));

	 nx = x - MAX(width - eyes_applet->eye_width, 0) * xalign - eyes_applet->eye_width / 2;
	 ny = y - MAX(height- eyes_applet->eye_height, 0) * yalign - eyes_applet->eye_height / 2;
  
	 h = hypot (nx, ny);
        if (h < 0.5 || abs (h) 
            < (abs (hypot (eyes_applet->eye_height / 2, eyes_applet->eye_width / 2)) - eyes_applet->wall_thickness - eyes_applet->pupil_height)) {
                *pupil_x = nx + eyes_applet->eye_width / 2;
                *pupil_y = ny + eyes_applet->eye_height / 2;
                return;
        }
        
	 sina = nx / h; 
	 cosa = ny / h;
	
        temp = hypot ((eyes_applet->eye_width / 2) * sina, (eyes_applet->eye_height / 2) * cosa);
        temp -= hypot ((eyes_applet->pupil_width / 2) * sina, (eyes_applet->pupil_height / 2) * cosa);
        temp -= hypot ((eyes_applet->wall_thickness / 2) * sina, (eyes_applet->wall_thickness / 2) * cosa);

        *pupil_x = temp * sina + (eyes_applet->eye_width / 2);
        *pupil_y = temp * cosa + (eyes_applet->eye_height / 2);
}
Пример #4
0
/** This function moves a GtkWidget from one GtkGrid to another,
 *  preserving its attachment data, etc.  It is called when adding one
 *  partial preference page to another.
 *
 *  @internal
 *
 *  @param widget A pointer to the widget to move.
 *
 *  @param data A pointer to a data structure passed in by the caller.
 *  This data structure contains pointers to the old and new grids
 *  plus the row offset into the new grid.
 */
static void
gnc_prefs_move_grid_entry (GtkWidget *child,
                            gpointer data)
{
    struct copy_data *copydata = data;
    gint top, left, height, width;
    gboolean hexpand, vexpand;
    GtkAlign halign, valign;
    gint topm, bottomm, leftm, rightm;

    ENTER("child %p, copy data %p", child, data);
    gtk_container_child_get(GTK_CONTAINER(copydata->grid_from), child,
                            "left-attach", &left,
                            "top-attach", &top,
                            "height", &height,
                            "width", &width,
                            NULL);
    hexpand = gtk_widget_get_hexpand (child);
    vexpand = gtk_widget_get_vexpand (child);
    halign = gtk_widget_get_halign (child);
    valign = gtk_widget_get_valign (child);

    g_object_get (child, "margin-top", &topm, "margin-bottom", &bottomm, NULL);
    g_object_get (child, "margin-left", &leftm, "margin-right", &rightm, NULL);

    g_object_ref(child);
    gtk_container_remove(GTK_CONTAINER(copydata->grid_from), child);

    gtk_grid_attach(copydata->grid_to, child, left, copydata->rows + top , width, height);

    gtk_widget_set_hexpand (child, hexpand);
    gtk_widget_set_vexpand (child, vexpand);
    gtk_widget_set_halign (child, halign);
    gtk_widget_set_valign (child, valign);

    g_object_set (child, "margin-left", leftm, "margin-right", rightm, NULL);
    g_object_set (child, "margin-top", topm, "margin-bottom", bottomm, NULL);

    g_object_unref(child);
    LEAVE(" ");
}
Пример #5
0
uiprivChild *uiprivNewChild(uiControl *child, uiControl *parent, GtkContainer *parentContainer)
{
	uiprivChild *c;

	if (child == NULL)
		return NULL;

	c = uiprivNew(uiprivChild);
	c->c = child;
	c->widget = GTK_WIDGET(uiControlHandle(c->c));

	c->oldhexpand = gtk_widget_get_hexpand(c->widget);
	c->oldhalign = gtk_widget_get_halign(c->widget);
	c->oldvexpand = gtk_widget_get_vexpand(c->widget);
	c->oldvalign = gtk_widget_get_valign(c->widget);

	uiControlSetParent(c->c, parent);
	uiUnixControlSetContainer(uiUnixControl(c->c), parentContainer, FALSE);
	c->parent = parentContainer;

	return c;
}
Пример #6
0
static void
menu_position_side_func (GtkMenu       *menu,
                         gint          *x,
                         gint          *y,
                         gboolean      *push_in,
                         GtkMenuButton *menu_button)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;
  GtkAllocation allocation;
  GtkAllocation menu_allocation;
  GtkWidget *widget = GTK_WIDGET (menu_button);
  GdkRectangle monitor;
  gint monitor_num;
  GdkScreen *screen;
  GdkWindow *window;
  GtkAlign align;
  GtkTextDirection direction;

  window = gtk_widget_get_window (widget);

  direction = gtk_widget_get_direction (widget);
  align = gtk_widget_get_valign (GTK_WIDGET (menu));
  screen = gtk_widget_get_screen (GTK_WIDGET (menu));
  monitor_num = gdk_screen_get_monitor_at_window (screen, window);
  if (monitor_num < 0)
    monitor_num = 0;
  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);

  gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (menu_button)), x, y);

  gtk_widget_get_allocation (widget, &allocation);
  gtk_widget_get_allocation (priv->menu, &menu_allocation);

  if ((priv->arrow_type == GTK_ARROW_RIGHT && direction == GTK_TEXT_DIR_LTR) ||
      (priv->arrow_type == GTK_ARROW_LEFT && direction == GTK_TEXT_DIR_RTL))

    {
      if (*x + allocation.width + menu_allocation.width <= monitor.x + monitor.width)
        *x += allocation.width;
      else
        *x -= menu_allocation.width;
    }
  else
    {
      if (*x - menu_allocation.width >= monitor.x)
        *x -= menu_allocation.width;
      else
        *x += allocation.width;
    }

  /* treat the default align value like START */
  if (align == GTK_ALIGN_FILL)
    align = GTK_ALIGN_START;

  if (align == GTK_ALIGN_CENTER)
    *y -= (menu_allocation.height - allocation.height) / 2;
  else if (align == GTK_ALIGN_END)
    *y -= menu_allocation.height - allocation.height;

  *push_in = FALSE;
}
Пример #7
0
/*
 * Class:     org_java_gtk_gtk_Widget
 * Method:    gtk_widget_get_valign
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_org_java_1gtk_gtk_Widget_gtk_1widget_1get_1valign
  (JNIEnv *env, jclass cls, jlong widget)
{
	return (jint)gtk_widget_get_valign((GtkWidget*)widget);
}
Пример #8
0
static void
popup_menu (GtkMenuButton *menu_button,
            GdkEvent      *event)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;
  GdkGravity widget_anchor = GDK_GRAVITY_SOUTH_WEST;
  GdkGravity menu_anchor = GDK_GRAVITY_NORTH_WEST;

  if (priv->func)
    priv->func (priv->user_data);

  if (!priv->menu)
    return;

  switch (priv->arrow_type)
    {
    case GTK_ARROW_UP:
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_Y |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    NULL);

      switch (gtk_widget_get_halign (priv->menu))
        {
        case GTK_ALIGN_FILL:
        case GTK_ALIGN_START:
        case GTK_ALIGN_BASELINE:
          widget_anchor = GDK_GRAVITY_NORTH_WEST;
          menu_anchor = GDK_GRAVITY_SOUTH_WEST;
          break;

        case GTK_ALIGN_END:
          widget_anchor = GDK_GRAVITY_NORTH_EAST;
          menu_anchor = GDK_GRAVITY_SOUTH_EAST;
          break;

        case GTK_ALIGN_CENTER:
          widget_anchor = GDK_GRAVITY_NORTH;
          menu_anchor = GDK_GRAVITY_SOUTH;
          break;
        }

      break;

    case GTK_ARROW_DOWN:
      /* In the common case the menu button is showing a dropdown menu, set the
       * corresponding type hint on the toplevel, so the WM can omit the top side
       * of the shadows.
       */
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_Y |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    "menu-type-hint", GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU,
                    NULL);

      switch (gtk_widget_get_halign (priv->menu))
        {
        case GTK_ALIGN_FILL:
        case GTK_ALIGN_START:
        case GTK_ALIGN_BASELINE:
          widget_anchor = GDK_GRAVITY_SOUTH_WEST;
          menu_anchor = GDK_GRAVITY_NORTH_WEST;
          break;

        case GTK_ALIGN_END:
          widget_anchor = GDK_GRAVITY_SOUTH_EAST;
          menu_anchor = GDK_GRAVITY_NORTH_EAST;
          break;

        case GTK_ALIGN_CENTER:
          widget_anchor = GDK_GRAVITY_SOUTH;
          menu_anchor = GDK_GRAVITY_NORTH;
          break;
        }

      break;

    case GTK_ARROW_LEFT:
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_X |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    NULL);

      switch (gtk_widget_get_valign (priv->menu))
        {
        case GTK_ALIGN_FILL:
        case GTK_ALIGN_START:
        case GTK_ALIGN_BASELINE:
          widget_anchor = GDK_GRAVITY_NORTH_WEST;
          menu_anchor = GDK_GRAVITY_NORTH_EAST;
          break;

        case GTK_ALIGN_END:
          widget_anchor = GDK_GRAVITY_SOUTH_WEST;
          menu_anchor = GDK_GRAVITY_SOUTH_EAST;
          break;

        case GTK_ALIGN_CENTER:
          widget_anchor = GDK_GRAVITY_WEST;
          menu_anchor = GDK_GRAVITY_EAST;
          break;
        }

      break;

    case GTK_ARROW_RIGHT:
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_X |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    NULL);

      switch (gtk_widget_get_valign (priv->menu))
        {
        case GTK_ALIGN_FILL:
        case GTK_ALIGN_START:
        case GTK_ALIGN_BASELINE:
          widget_anchor = GDK_GRAVITY_NORTH_EAST;
          menu_anchor = GDK_GRAVITY_NORTH_WEST;
          break;

        case GTK_ALIGN_END:
          widget_anchor = GDK_GRAVITY_SOUTH_EAST;
          menu_anchor = GDK_GRAVITY_SOUTH_WEST;
          break;

        case GTK_ALIGN_CENTER:
          widget_anchor = GDK_GRAVITY_EAST;
          menu_anchor = GDK_GRAVITY_WEST;
          break;
        }

      break;

    case GTK_ARROW_NONE:
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_Y |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    NULL);

      break;
    }

  gtk_menu_popup_at_widget (GTK_MENU (priv->menu),
                            GTK_WIDGET (menu_button),
                            widget_anchor,
                            menu_anchor,
                            event);
}