예제 #1
0
파일: gtktestutils.c 프로젝트: jdapena/gtk
static int
widget_geo_dist (GtkWidget *a,
                 GtkWidget *b,
                 GtkWidget *base)
{
    GtkAllocation allocation;
    int ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, xdist = 0, ydist = 0;

    gtk_widget_get_allocation (a, &allocation);
    if (!gtk_widget_translate_coordinates (a, base, 0, 0, &ax0, &ay0) ||
            !gtk_widget_translate_coordinates (a, base, allocation.width, allocation.height, &ax1, &ay1))
        return -G_MAXINT;

    gtk_widget_get_allocation (b, &allocation);
    if (!gtk_widget_translate_coordinates (b, base, 0, 0, &bx0, &by0) ||
            !gtk_widget_translate_coordinates (b, base, allocation.width, allocation.height, &bx1, &by1))
        return +G_MAXINT;

    if (bx0 >= ax1)
        xdist = bx0 - ax1;
    else if (ax0 >= bx1)
        xdist = ax0 - bx1;
    if (by0 >= ay1)
        ydist = by0 - ay1;
    else if (ay0 >= by1)
        ydist = ay0 - by1;

    return xdist + ydist;
}
예제 #2
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;
}
예제 #3
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;
}
예제 #4
0
static gboolean
gimp_ruler_track_widget_motion_notify (GtkWidget      *widget,
                                       GdkEventMotion *mevent,
                                       GimpRuler      *ruler)
{
  gint widget_x;
  gint widget_y;
  gint ruler_x;
  gint ruler_y;

  widget = gtk_get_event_widget ((GdkEvent *) mevent);

  gimp_ruler_event_to_widget_coords (widget, mevent->window,
                                     mevent->x, mevent->y,
                                     &widget_x, &widget_y);

  if (gtk_widget_translate_coordinates (widget, GTK_WIDGET (ruler),
                                        widget_x, widget_y,
                                        &ruler_x, &ruler_y))
    {
      gimp_ruler_update_position (ruler, ruler_x, ruler_y);
    }

  return FALSE;
}
예제 #5
0
static void
sn_item_get_action_coordinates (SnItem *item,
                                gint   *x,
                                gint   *y)
{
    GtkWidget *widget;
    SnItemPrivate *priv;
    GdkWindow *window;
    GtkWidget *toplevel;
    gint width;
    gint height;

    priv = sn_item_get_instance_private (item);
    widget = GTK_WIDGET (item);
    window = gtk_widget_get_window (widget);
    toplevel = gtk_widget_get_toplevel (widget);

    gdk_window_get_geometry (window, x, y, &width, &height);
    gtk_widget_translate_coordinates (widget, toplevel, *x, *y, x, y);

    if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        *y += height;
    else
        *x += width;
}
예제 #6
0
static gboolean
wrap_table_child_focus_in (GtkWidget *widget,
                           GdkEventFocus *event,
                           gpointer data)
{
    gint x, y;
    GtkWidget *container, *viewport = NULL;

    container = gtk_widget_get_parent (widget);
    if (container)
    {
        viewport = gtk_widget_get_parent (container);
    }
    g_assert (container && viewport);
    g_assert (GTK_IS_VIEWPORT (viewport));
    g_return_val_if_fail (gtk_widget_get_realized (viewport), FALSE);

    if (!wrap_table_child_visible_in (widget, viewport))
    {
        GtkAdjustment *hadj, *vadj;

        hadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (viewport));
        vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (viewport));

        gtk_widget_translate_coordinates (widget, container, 0, 0, &x, &y);

        gtk_adjustment_set_value (hadj, MIN (x, gtk_adjustment_get_upper(hadj) - gtk_adjustment_get_page_size(hadj)));
        gtk_adjustment_set_value (vadj, MIN (y, gtk_adjustment_get_upper(vadj) - gtk_adjustment_get_page_size(vadj)));
    }

    return FALSE;
}
예제 #7
0
파일: gtktexthandle.c 프로젝트: GYGit/gtk
static void
_handle_update_child_visible (GtkTextHandle         *handle,
                              GtkTextHandlePosition  pos)
{
  HandleWindow *handle_window;
  GtkTextHandlePrivate *priv;
  cairo_rectangle_int_t rect;
  GtkAllocation allocation;
  GtkWidget *parent;

  priv = handle->priv;
  handle_window = &priv->windows[pos];

  if (!priv->parent_scrollable)
    {
      gtk_widget_set_child_visible (handle_window->widget, TRUE);
      return;
    }

  parent = gtk_widget_get_parent (GTK_WIDGET (priv->parent_scrollable));
  rect = handle_window->pointing_to;

  gtk_widget_translate_coordinates (priv->parent, parent,
                                    rect.x, rect.y, &rect.x, &rect.y);

  gtk_widget_get_allocation (GTK_WIDGET (parent), &allocation);

  if (rect.x < 0 || rect.x + rect.width > allocation.width ||
      rect.y < 0 || rect.y + rect.height > allocation.height)
    gtk_widget_set_child_visible (handle_window->widget, FALSE);
  else
    gtk_widget_set_child_visible (handle_window->widget, TRUE);
}
예제 #8
0
static gboolean
event_window_button_press_event_cb (GstyleSlidein *self,
                                    GdkEvent      *event,
                                    GstyleSlidein *unused)
{
  GdkEventButton *button_event = (GdkEventButton *)event;
  GtkAllocation child_alloc;
  gboolean is_in_slide;
  GtkWidget *src_widget;
  gint dest_x, dest_y;

  g_assert (GSTYLE_IS_SLIDEIN (self));

  src_widget = gtk_get_event_widget (event);
  gtk_widget_translate_coordinates (src_widget, GTK_WIDGET (self->overlay_child),
                                    button_event->x, button_event->y,
                                    &dest_x, &dest_y);

  gtk_widget_get_allocated_size (self->overlay_child, &child_alloc, NULL);
  is_in_slide = (0 <= dest_x && dest_x <= child_alloc.width && 0 <= dest_y && dest_y <= child_alloc.height);
  if (!is_in_slide)
    {
      gtk_grab_remove (GTK_WIDGET (self));
      gstyle_slidein_reveal_slide (self, FALSE);

      return GDK_EVENT_PROPAGATE;
    }
  else
    return GDK_EVENT_STOP;
}
예제 #9
0
파일: testoverlay.c 프로젝트: 3v1n0/gtk
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;
}
예제 #10
0
파일: spellcheck.c 프로젝트: zakkudo/gwaei
void
gw_spellcheck_record_mouse_cordinates (GwSpellcheck *spellcheck, 
                                       GdkEvent     *event)
{
    GwSpellcheckPrivate *priv;
    GtkWidget *toplevel;
    gint toplevel_x, toplevel_y;

    priv = spellcheck->priv;
    toplevel = GTK_WIDGET (gtk_widget_get_ancestor (GTK_WIDGET (priv->entry), GTK_TYPE_WINDOW));

    gdk_window_get_device_position (
      gtk_widget_get_window (GTK_WIDGET (priv->entry)),
      gdk_event_get_device (event),
      &toplevel_x, 
      &toplevel_y, 
      NULL
    );

    gtk_widget_translate_coordinates (
      toplevel, 
      GTK_WIDGET (priv->entry), 
      toplevel_x, 
      toplevel_y, 
      &priv->x, 
      &priv->y
    );
}
예제 #11
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);
}
예제 #12
0
/* methods to receive URLs which were dropped anywhere in the main window */
static void
liferea_shell_URL_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time_received)
{
	gchar		*tmp1, *tmp2, *freeme;
	GtkWidget	*mainwindow;
	GtkAllocation	alloc;
	GtkTreeView	*treeview;
	GtkTreeModel	*model;
	GtkTreePath	*path;
	GtkTreeIter	iter;
	nodePtr		node;
	gint		tx, ty;
	
	g_return_if_fail (gtk_selection_data_get_data (data) != NULL);
		
	mainwindow = GTK_WIDGET (shell->priv->window);
	treeview = GTK_TREE_VIEW (shell->priv->feedlistView);
	model = gtk_tree_view_get_model (treeview);

	/* x and y are relative to the main window, make them relative to the treeview */
	gtk_widget_translate_coordinates (mainwindow, GTK_WIDGET (treeview), x, y, &tx, &ty);

	/* Allow link drops only over feed list widget. This is to avoid
	   the frequent accidental text drops in the HTML view. */

	gtk_widget_get_allocation(GTK_WIDGET(treeview), &alloc);

	if((x > alloc.x+alloc.width) || (x < alloc.x) ||
	   (y > alloc.y+alloc.height) || (y < alloc.y)) {
		gtk_drag_finish (context, FALSE, FALSE, time_received);
		return;
	}		

	if ((gtk_selection_data_get_length (data) >= 0) && (gtk_selection_data_get_format (data) == 8)) {
		/* extra handling to accept multiple drops */
		freeme = tmp1 = g_strdup (gtk_selection_data_get_data (data));
		while ((tmp2 = strsep (&tmp1, "\n\r"))) {
			if (strlen (tmp2)) {
				/* if the drop is over a node, select it so that feedlist_add_subscription()
				 * adds it in the correct folder */
				if (gtk_tree_view_get_dest_row_at_pos (treeview, tx, ty, &path, NULL)) {
					if (gtk_tree_model_get_iter (model, &iter, path)) {
						gtk_tree_model_get (model, &iter, FS_PTR, &node, -1);
						/* if node is NULL, feed_list_view_select() will unselect the tv */
						feed_list_view_select (node);
					}
					gtk_tree_path_free (path);
				}
				feedlist_add_subscription (g_strdup (tmp2), NULL, NULL,
				                           FEED_REQ_PRIORITY_HIGH);
			}
		}
		g_free (freeme);
		gtk_drag_finish (context, TRUE, FALSE, time_received);
	} else {
		gtk_drag_finish (context, FALSE, FALSE, time_received);
	}
}
static void
carrick_list_drag_motion (GtkWidget      *widget,
                          GdkDragContext *context,
                          gint            x,
                          gint            y,
                          guint           time,
                          CarrickList    *list)
{
  CarrickListPrivate *priv = list->priv;
  int                 list_x, list_y;
  int                 new_speed;

  gtk_widget_translate_coordinates (widget, GTK_WIDGET (list),
                                    x, y,
                                    &list_x, &list_y);
  if (gtk_adjustment_get_value (priv->adjustment) >
      gtk_adjustment_get_lower (priv->adjustment) &&
      list_y < FAST_SCROLL_BUFFER)
    {
      new_speed = -12;
    }
  else if (gtk_adjustment_get_value (priv->adjustment) >
           gtk_adjustment_get_lower (priv->adjustment) &&
           list_y < SCROLL_BUFFER)
    {
      new_speed = -5;
    }
  else if (gtk_adjustment_get_value (priv->adjustment) <
           gtk_adjustment_get_upper (priv->adjustment) &&
           GTK_WIDGET (list)->allocation.height - list_y < FAST_SCROLL_BUFFER)
    {
      new_speed = 12;
    }
  else if (gtk_adjustment_get_value (priv->adjustment) <
           gtk_adjustment_get_upper (priv->adjustment) &&
           GTK_WIDGET (list)->allocation.height - list_y < SCROLL_BUFFER)
    {
      new_speed = 5;
    }
  else
    {
      new_speed = 0;
    }

  if (new_speed != priv->scroll_speed)
    {
      priv->scroll_speed = new_speed;
      if (priv->scroll_speed != 0)
        {
          if (priv->scroll_timeout_id > 0)
            {
              g_source_remove (priv->scroll_timeout_id);
            }
          priv->scroll_timeout_id = g_timeout_add
                    (40, (GSourceFunc) carrick_list_scroll, list);
        }
    }
}
예제 #14
0
void
cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpointer data)
{
  zathura_t* zathura = data;
  if (zathura == NULL || zathura->document == NULL || zathura->ui.page_widget == NULL) {
    return;
  }

  GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
  GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));

  GdkRectangle view_rect;
  /* get current adjustment values */
  view_rect.y      = 0;
  view_rect.height = gtk_adjustment_get_page_size(view_vadjustment);
  view_rect.x      = 0;
  view_rect.width  = gtk_adjustment_get_page_size(view_hadjustment);

  int page_padding = 1;
  girara_setting_get(zathura->ui.session, "page-padding", &page_padding);

  GdkRectangle center;
  center.x = (view_rect.width + 1) / 2;
  center.y = (view_rect.height + 1) / 2;
  center.height = center.width = (2 * page_padding) + 1;

  unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
  double scale = zathura_document_get_scale(zathura->document);

  bool updated = false;
  /* find page that fits */
  for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
    zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);

    GdkRectangle page_rect;
    GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
    gtk_widget_translate_coordinates(page_widget,
        zathura->ui.session->gtk.view, 0, 0, &page_rect.x, &page_rect.y);
    page_rect.width  = zathura_page_get_width(page)  * scale;
    page_rect.height = zathura_page_get_height(page) * scale;

    if (gdk_rectangle_intersect(&view_rect, &page_rect, NULL) == TRUE) {
      zathura_page_set_visibility(page, true);
      if (zathura->global.update_page_number == true && updated == false
          && gdk_rectangle_intersect(&center, &page_rect, NULL) == TRUE) {
        zathura_document_set_current_page_number(zathura->document, page_id);
        updated = true;
      }
    } else {
      zathura_page_set_visibility(page, false);
    }
    zathura_page_widget_update_view_time(ZATHURA_PAGE(page_widget));
  }

  statusbar_page_number_update(zathura);
}
예제 #15
0
/* Takes a point (x or y depending on 'row') relative to
* grid, and returns the row or column in which the point
* was found.
*/
static gint
glade_gtk_grid_get_row_col_from_point (GtkGrid *grid, gboolean row, gint point)
{
  GladeGridAttachments attach;
  GtkAllocation allocation;
  GList *list, *children;
  gint span, trans_point, size, base, end;

  children = gtk_container_get_children (GTK_CONTAINER (grid));

  for (list = children; list; list = list->next)
    {
      GtkWidget *widget = list->data;

      glade_gtk_grid_get_child_attachments (GTK_WIDGET (grid), widget, &attach);

      if (row)
        gtk_widget_translate_coordinates (GTK_WIDGET (grid), widget, 0, point, NULL, &trans_point);
      else
        gtk_widget_translate_coordinates (GTK_WIDGET (grid), widget, point, 0, &trans_point, NULL);

      gtk_widget_get_allocation (widget, &allocation);

      /* Find any widget in our row/column
       */
      end = row ? allocation.height : allocation.width;

      if (trans_point >= 0 &&
          /* should be trans_point < end ... test FIXME ! */
          trans_point < end)
        {
          base = row ? attach.top_attach : attach.left_attach;
          size = row ? allocation.height : allocation.width;
          span = row ? attach.height     : attach.width;

          return base + (trans_point * span / size);
        }
    }

  g_list_free (children);

  return -1;
}
예제 #16
0
파일: utils.c 프로젝트: aroig/zathura
void
page_calculate_offset(zathura_t* zathura, zathura_page_t* page, page_offset_t* offset)
{
  g_return_if_fail(page != NULL);
  g_return_if_fail(offset != NULL);
  GtkWidget* widget = zathura_page_get_widget(zathura, page);

  g_return_if_fail(gtk_widget_translate_coordinates(widget,
                   zathura->ui.page_widget, 0, 0, &(offset->x), &(offset->y)) == true);
}
예제 #17
0
static void menu_position_cb (GtkMenu * menu, int * x, int * y, int * push, void * button)
{
    int xorig, yorig, xwin, ywin;

    gdk_window_get_origin (gtk_widget_get_window (window), & xorig, & yorig);
    gtk_widget_translate_coordinates (button, window, 0, 0, & xwin, & ywin);

    * x = xorig + xwin;
    * y = yorig + ywin + gtk_widget_get_allocated_height (button);
    * push = TRUE;
}
예제 #18
0
static gint
ev_page_accessible_get_offset_at_point (AtkText      *text,
					gint         x,
					gint         y,
					AtkCoordType coords)
{
	EvPageAccessible *self = EV_PAGE_ACCESSIBLE (text);
	EvView *view = ev_page_accessible_get_view (self);
	GtkWidget *toplevel;
	EvRectangle *areas = NULL;
	EvRectangle *rect = NULL;
	guint n_areas = 0;
	guint i;
	gint x_widget, y_widget;
	gint offset=-1;
	GdkPoint view_point;
	gdouble doc_x, doc_y;
	GtkBorder border;
	GdkRectangle page_area;

	if (!view->page_cache)
		return -1;

	ev_page_cache_get_text_layout (view->page_cache, self->priv->page, &areas, &n_areas);
	if (!areas)
		return -1;

	view_point.x = x;
	view_point.y = y;
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
	gtk_widget_translate_coordinates (GTK_WIDGET (self), toplevel, 0, 0, &x_widget, &y_widget);
	view_point.x -= x_widget;
	view_point.y -= y_widget;

	if (coords == ATK_XY_SCREEN) {
		gint x_window, y_window;

		gdk_window_get_origin (gtk_widget_get_window (toplevel), &x_window, &y_window);
		view_point.x -= x_window;
		view_point.y -= y_window;
	}

	ev_view_get_page_extents (view, self->priv->page, &page_area, &border);
	_ev_view_transform_view_point_to_doc_point (view, &view_point, &page_area, &border, &doc_x, &doc_y);

	for (i = 0; i < n_areas; i++) {
		rect = areas + i;
		if (doc_x >= rect->x1 && doc_x <= rect->x2 &&
		    doc_y >= rect->y1 && doc_y <= rect->y2)
			offset = i;
	}

	return offset;
}
예제 #19
0
static void getRootCoords(GtkWidget* view, int* rootX, int* rootY)
{
    GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view));
    int tmpX, tmpY;

    gtk_widget_translate_coordinates(view, window, lastMousePositionX, lastMousePositionY, &tmpX, &tmpY);

    gdk_window_get_origin(window->window, rootX, rootY);

    *rootX += tmpX;
    *rootY += tmpY;
}
예제 #20
0
static void chose_face(GtkWidget *widget, gpointer data) {

	chatbox_t *dlg = (chatbox_t*)data;
	int x , y , ex , ey , root_x , root_y;

	gtk_widget_translate_coordinates(widget , dlg->window , 0 , 0 , &ex , &ey );
	gtk_window_get_position(GTK_WINDOW(dlg->window) , &root_x , &root_y);

	x = root_x + ex + 3;
	y = root_y + ey + 46;

	emotion_chose_dialg_init(dlg, x, y);
}
예제 #21
0
static gboolean
motion_notify_event (GtkWidget * widget,
                     GdkEventMotion * event, App * app)
{

    gint x, y;
    gboolean ret;
    GtkAdjustment *hadjustment, *vadjustment;
    gfloat hval, vval;

    GET_UI_ELEMENT (GtkWidget, scrolledwindow2);
    GET_UI_ELEMENT (GtkWidget, layout1);

    gtk_widget_translate_coordinates (widget, layout1,
                                      event->x, event->y, &x,
                                      &y);

    x -= offsetx;
    y -= offsety;

    // make sure the potential coordinates x,y:
    //   1) will not push any part of the widget outside of its parent container
    //   2) is a multiple of Sensitivity

    x = RoundToNearestMultiple (Max (Min (x, maxx), 0),
                                Sensitivity);
    y = RoundToNearestMultiple (Max (Min (y, maxy), 0),
                                Sensitivity);

    if (x != px || y != py) {
        g_object_get (scrolledwindow2, "hadjustment",
                      &hadjustment, "vadjustment",
                      &vadjustment, NULL);

        hval = gtk_adjustment_get_value (hadjustment);
        vval = gtk_adjustment_get_value (vadjustment);

        x += hval;
        y += vval;

        px = x;
        py = y;

        gtk_layout_move (GTK_LAYOUT (layout1), widget, x, y);
    }

    gtk_widget_queue_draw (layout1);

    return TRUE;
}
예제 #22
0
// FIXME: this does not take into account the WM decorations
static IntPoint widgetScreenPosition(GtkWidget* widget)
{
    GtkWidget* window = gtk_widget_get_toplevel(widget);
    int widgetX = 0, widgetY = 0;

    gtk_widget_translate_coordinates(widget, window, 0, 0, &widgetX, &widgetY);

    IntPoint result(widgetX, widgetY);
    int originX, originY;
    gdk_window_get_origin(window->window, &originX, &originY);
    result.move(originX, originY);

    return result;
}
예제 #23
0
/**
 * wrap_table_child_visible_in
 *
 * Get child position relative to parent, then determine whether
 * the whole child rectangle is visible in the scrolled window
 **/
static gboolean
wrap_table_child_visible_in (GtkWidget *child, GtkWidget *scrolled)
{
    gint x, y;
    GtkAllocation child_alloc, scroll_alloc;

    gtk_widget_translate_coordinates (child, scrolled, 0, 0, &x, &y);
    gtk_widget_get_allocation(child, &child_alloc);
    gtk_widget_get_allocation(scrolled, &scroll_alloc);

    return (x >= 0 && y >= 0)
        && x + child_alloc.width <= scroll_alloc.width
        && y + child_alloc.height <= scroll_alloc.height;
}
예제 #24
0
static VALUE
rg_translate_coordinates(VALUE self, VALUE dest_widget, VALUE src_x, VALUE src_y)
{
    gint dest_x, dest_y;
    gboolean ret;
    VALUE result = Qnil;
    ret = gtk_widget_translate_coordinates(_SELF(self), _SELF(dest_widget),
                                           NUM2INT(src_x), NUM2INT(src_y),
                                           &dest_x, &dest_y);
    if (ret)
        result = rb_ary_new3(2, INT2FIX(dest_x), INT2FIX(dest_y));

    return result;
}
예제 #25
0
static void bar_pane_exif_dnd_receive(GtkWidget *pane, GdkDragContext *context,
					  gint x, gint y,
					  GtkSelectionData *selection_data, guint info,
					  guint time, gpointer data)
{
	PaneExifData *ped;
	GList *work, *list;
	gint pos;
	GtkWidget *new_entry = NULL;

	ped = g_object_get_data(G_OBJECT(pane), "pane_data");
	if (!ped) return;

	switch (info)
		{
		case TARGET_APP_EXIF_ENTRY:
			new_entry = *(gpointer *)gtk_selection_data_get_data(selection_data);

			if (gtk_widget_get_parent(new_entry) && gtk_widget_get_parent(new_entry) != ped->vbox) bar_pane_exif_reparent_entry(new_entry, pane);

			break;
		default:
			/* FIXME: this needs a check for valid exif keys */
			new_entry = bar_pane_exif_add_entry(ped, (gchar *)gtk_selection_data_get_data(selection_data), NULL, TRUE, FALSE);
			break;
		}

	list = gtk_container_get_children(GTK_CONTAINER(ped->vbox));
	work = list;
	pos = 0;
	while (work)
		{
		gint nx, ny;
		GtkWidget *entry = work->data;
		GtkAllocation allocation;
		work = work->next;

		if (entry == new_entry) continue;

		gtk_widget_get_allocation(entry, &allocation);

		if (gtk_widget_is_drawable(entry) &&
		    gtk_widget_translate_coordinates(pane, entry, x, y, &nx, &ny) &&
		    ny < allocation.height / 2) break;
		pos++;
		}
	g_list_free(list);

	gtk_box_reorder_child(GTK_BOX(ped->vbox), new_entry, pos);
}
예제 #26
0
파일: events.c 프로젝트: K6BSD/SBBSUnstable
int get_date(GtkWidget *t, isoDate_t *date)
{
	GtkWidget	*w;
	GtkWindow	*win;
	GtkWidget	*thiswin;
	gint		x,x_off;
	gint		y,y_off;
	guint		year;
	guint		month;
	guint		day;
	isoDate_t	odate=*date;

	got_date=0;
	win=GTK_WINDOW(gtk_builder_get_object (builder, "CalendarWindow"));
	if(win==NULL) {
		fprintf(stderr,"Could not locate Calendar window\n");
		return(-1);
	}

	thiswin = gtk_widget_get_toplevel(t);
	if(thiswin==NULL) {
		fprintf(stderr,"Could not locate main window\n");
		return(-1);
	}
	if(!(gtk_widget_translate_coordinates(GTK_WIDGET(t)
			,GTK_WIDGET(thiswin), 0, 0, &x_off, &y_off))) {
		fprintf(stderr,"Could not get position of button in window");
	}
	gtk_window_get_position(GTK_WINDOW(thiswin), &x, &y);

	gtk_window_move(GTK_WINDOW(win), x+x_off, y+y_off);

	w=GTK_WIDGET(gtk_builder_get_object (builder, "Calendar"));
	if(w==NULL) {
		fprintf(stderr,"Could not locate Calendar widget\n");
		return(-1);
	}
	gtk_calendar_select_month(GTK_CALENDAR(w), isoDate_month(*date)-1, isoDate_year(*date));
	gtk_calendar_select_day(GTK_CALENDAR(w), isoDate_day(*date));
	gtk_window_present(GTK_WINDOW(win));
	/* Wait for window to close... */
	gtk_main();
	w=GTK_WIDGET(gtk_builder_get_object (builder, "Calendar"));
	if(w==NULL)
		return(-1);
	gtk_calendar_get_date(GTK_CALENDAR(w), &year, &month, &day);
	gtk_widget_hide_on_delete(GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(w))));
	*date=isoDate_create(year, month+1, day);
	return(odate!=*date);
}
예제 #27
0
void dr_canvas_refresh(GtkWidget *widget)
{
	// Redraw the canvas from the widget
	GtkAllocation allc;
	int x, y;
	int newx, newy;

	gtk_widget_get_allocation(widget, &allc);
	x = allc.x;
	y = allc.y;
	gtk_widget_translate_coordinates(widget, window, x, y, &newx, &newy);
	gtk_widget_queue_draw_area(window, newx, newy, allc.width, allc.height);

	return;
}
예제 #28
0
static void
ev_page_accessible_get_character_extents (AtkText      *text,
					  gint         offset,
					  gint         *x,
					  gint         *y,
					  gint         *width,
					  gint         *height,
					  AtkCoordType coords)
{
	EvPageAccessible *self = EV_PAGE_ACCESSIBLE (text);
	EvView *view = ev_page_accessible_get_view (self);
	GtkWidget *toplevel;
	EvRectangle *areas = NULL;
	EvRectangle *doc_rect;
	guint n_areas = 0;
	gint x_widget, y_widget;
	GdkRectangle view_rect;

	if (!view->page_cache)
		return;

	ev_page_cache_get_text_layout (view->page_cache, self->priv->page, &areas, &n_areas);
	if (!areas || offset >= n_areas)
		return;

	doc_rect = areas + offset;
	_ev_view_transform_doc_rect_to_view_rect (view, self->priv->page, doc_rect, &view_rect);
	view_rect.x -= view->scroll_x;
	view_rect.y -= view->scroll_y;

	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
	gtk_widget_translate_coordinates (GTK_WIDGET (view), toplevel, 0, 0, &x_widget, &y_widget);
	view_rect.x += x_widget;
	view_rect.y += y_widget;

	if (coords == ATK_XY_SCREEN) {
		gint x_window, y_window;

		gdk_window_get_origin (gtk_widget_get_window (toplevel), &x_window, &y_window);
		view_rect.x += x_window;
		view_rect.y += y_window;
	}

	*x = view_rect.x;
	*y = view_rect.y;
	*width = view_rect.width;
	*height = view_rect.height;
}
예제 #29
0
파일: gtktooltip.c 프로젝트: aswinas/gtk-
static gboolean
gtk_tooltip_run_requery (GtkWidget  **widget,
			 GtkTooltip  *tooltip,
			 gint        *x,
			 gint        *y)
{
  gboolean has_tooltip = FALSE;
  gboolean return_value = FALSE;

  gtk_tooltip_reset (tooltip);

  do
    {
      g_object_get (*widget,
		    "has-tooltip", &has_tooltip,
		    NULL);

      if (has_tooltip)
	g_signal_emit_by_name (*widget,
			       "query-tooltip",
			       *x, *y,
			       tooltip->keyboard_mode_enabled,
			       tooltip,
			       &return_value);

      if (!return_value)
        {
	  GtkWidget *parent = gtk_widget_get_parent (*widget);

	  if (parent)
	    gtk_widget_translate_coordinates (*widget, parent, *x, *y, x, y);

	  *widget = parent;
	}
      else
	break;
    }
  while (*widget);

  /* If the custom widget was not reset in the query-tooltip
   * callback, we clear it here.
   */
  if (!tooltip->custom_was_reset)
    gtk_tooltip_set_custom (tooltip, NULL);

  return return_value;
}
예제 #30
0
파일: chatwidget.c 프로젝트: 4179e1/gtkqq
//
// Face tool button clicked handler
//
static void face_tool_button_clicked(GtkToolButton *btn, gpointer data)
{
    QQChatWidgetPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE(data
                                        , qq_chatwidget_get_type()
                                        , QQChatWidgetPriv);
    int x , y , ex , ey , root_x , root_y;

    // Get the top level window
    GtkWidget *parent = GTK_WIDGET(btn), *tmp;
    while((tmp = gtk_widget_get_parent(parent)) != NULL){
        parent = tmp;
    }

    gtk_widget_translate_coordinates(GTK_WIDGET(btn), parent, 0, 0, &ex, &ey);
    gtk_window_get_position(GTK_WINDOW(parent), &root_x, &root_y);
    x = root_x + ex + 2;
    y = root_y + ey + 45;
    qq_face_popup_window_popup(priv -> facepopupwindow, x, y);
}