Esempio n. 1
0
static void
na_tray_child_realize (GtkWidget *widget)
{
  NaTrayChild *child = NA_TRAY_CHILD (widget);
  GdkVisual *visual = gtk_widget_get_visual (widget);
  GdkWindow *window;

  GTK_WIDGET_CLASS (na_tray_child_parent_class)->realize (widget);

  window = gtk_widget_get_window (widget);

  if (child->has_alpha)
    {
      /* We have real transparency with an ARGB visual and the Composite
       * extension. */

      /* Set a transparent background */
      GdkColor transparent = { 0, 0, 0, 0 }; /* only pixel=0 matters */
      gdk_window_set_background (window, &transparent);
      gdk_window_set_composited (window, TRUE);

      child->parent_relative_bg = FALSE;
	}
	#if GTK_CHECK_VERSION(3, 0, 0)
		else if (visual == gdk_window_get_visual(gdk_window_get_parent(window)))
	#else
		else if (visual == gdk_drawable_get_visual(GDK_DRAWABLE(gdk_window_get_parent(window))))
	#endif
	{
      /* Otherwise, if the visual matches the visual of the parent window, we
       * can use a parent-relative background and fake transparency. */
      gdk_window_set_back_pixmap (window, NULL, TRUE);

      child->parent_relative_bg = TRUE;
    }
  else
    {
      /* Nothing to do; the icon will sit on top of an ugly gray box */
      child->parent_relative_bg = FALSE;
    }

  gdk_window_set_composited (window, child->composited);

  gtk_widget_set_app_paintable (GTK_WIDGET (child),
                                child->parent_relative_bg || child->has_alpha);

  /* Double-buffering will interfere with the parent-relative-background fake
   * transparency, since the double-buffer code doesn't know how to fill in the
   * background of the double-buffer correctly.
   */
  gtk_widget_set_double_buffered (GTK_WIDGET (child),
                                  child->parent_relative_bg);
}
Esempio n. 2
0
JNIEXPORT jlong JNICALL
Java_org_gnome_gdk_GdkWindow_gdk_1window_1get_1parent
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	GdkWindow* result;
	jlong _result;
	GdkWindow* self;

	// convert parameter self
	self = (GdkWindow*) _self;

	// call function
	result = gdk_window_get_parent(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jlong) result;

	// cleanup return value
	if (result != NULL) {
		bindings_java_memory_cleanup((GObject*)result, FALSE);
	}

	// and finally
	return _result;
}
Esempio n. 3
0
void WinDraw_InitWindowSize(WORD width, WORD height)
{
	static BOOL inited = FALSE;

	if (!inited) {
		GdkWindow *t, *root = window->window;

		while ((t = gdk_window_get_parent(root)) != 0)
			root = t;
		gdk_window_get_size(root, &root_width, &root_height);
		inited = TRUE;
	}

	gdk_window_get_position(window->window, &winx, &winy);

	winw = width;
	winh = height;

	if (root_width < winw)
		winx = (root_width - winw) / 2;
	else if (winx < 0)
		winx = 0;
	else if ((winx + winw) > root_width)
		winx = root_width - winw;
	if (root_height < winh)
		winy = (root_height - winh) / 2;
	else if (winy < 0)
		winy = 0;
	else if ((winy + winh) > root_height)
		winy = root_height - winh;
}
/**
 * anjuta_tabber_get_widget_coordinates:
 * @widget: widget for the coordinates
 * @event: event to get coordinates from
 * @x: return location for x coordinate
 * @y: return location for y coordinate
 *
 * Returns: %TRUE if coordinates were set, %FALSE otherwise
 */
static gboolean
anjuta_tabber_get_widget_coordinates (GtkWidget *widget,
			GdkEvent  *event,
			gint      *x,
			gint      *y)
{
  GdkWindow *window = ((GdkEventAny *)event)->window;
  gdouble tx, ty;

  if (!gdk_event_get_coords (event, &tx, &ty))
    return FALSE;

  while (window && window != gtk_widget_get_window (widget))
    {
      gint window_x, window_y;

      gdk_window_get_position (window, &window_x, &window_y);
      tx += window_x;
      ty += window_y;

      window = gdk_window_get_parent (window);
    }

  if (window)
    {
      *x = tx;
      *y = ty;

      return TRUE;
    }
  else
    return FALSE;
}
Esempio n. 5
0
static void
na_tray_child_size_allocate (GtkWidget      *widget,
                             GtkAllocation  *allocation)
{
  NaTrayChild *child = NA_TRAY_CHILD (widget);
  GtkAllocation widget_allocation;
  gboolean moved, resized;

  gtk_widget_get_allocation (widget, &widget_allocation);

  moved = (allocation->x != widget_allocation.x ||
	   allocation->y != widget_allocation.y);
  resized = (allocation->width != widget_allocation.width ||
	     allocation->height != widget_allocation.height);

  /* When we are allocating the widget while mapped we need special handling
   * for both real and fake transparency.
   *
   * Real transparency: we need to invalidate and trigger a redraw of the old
   *   and new areas. (GDK really should handle this for us, but doesn't as of
   *   GTK+-2.14)
   *
   * Fake transparency: if the widget moved, we need to force the contents to
   *   be redrawn with the new offset for the parent-relative background.
   */
  if ((moved || resized) && gtk_widget_get_mapped (widget))
    {
      if (na_tray_child_has_alpha (child))
        gdk_window_invalidate_rect (gdk_window_get_parent (gtk_widget_get_window (widget)),
                                    &widget_allocation, FALSE);
    }

  GTK_WIDGET_CLASS (na_tray_child_parent_class)->size_allocate (widget,
                                                                allocation);

  if ((moved || resized) && gtk_widget_get_mapped (widget))
    {
      if (na_tray_child_has_alpha (NA_TRAY_CHILD (widget)))
        gdk_window_invalidate_rect (gdk_window_get_parent (gtk_widget_get_window (widget)),
                                    &widget_allocation, FALSE);
      else if (moved && child->parent_relative_bg)
        na_tray_child_force_redraw (child);
    }
}
Esempio n. 6
0
static void
na_tray_child_realize (GtkWidget *widget)
{
  NaTrayChild *child = NA_TRAY_CHILD (widget);
  GdkVisual *visual = gtk_widget_get_visual (widget);
  GdkWindow *window;

  GTK_WIDGET_CLASS (na_tray_child_parent_class)->realize (widget);

  window = gtk_widget_get_window (widget);

  if (child->has_alpha)
    {
      /* We have real transparency with an ARGB visual and the Composite
       * extension. */

      /* Set a transparent background */
      cairo_pattern_t *transparent = cairo_pattern_create_rgba (0, 0, 0, 0);
      gdk_window_set_background_pattern (window, transparent);
      gdk_window_set_composited (window, TRUE);
      cairo_pattern_destroy (transparent);

      child->parent_relative_bg = FALSE;
    }
  else if (visual == gdk_window_get_visual (gdk_window_get_parent (window)))
    {
      /* Otherwise, if the visual matches the visual of the parent window, we
       * can use a parent-relative background and fake transparency. */
      gdk_window_set_background_pattern (window, NULL);

      child->parent_relative_bg = TRUE;
    }
  else
    {
      /* Nothing to do; the icon will sit on top of an ugly gray box */
      child->parent_relative_bg = FALSE;
    }

  gdk_window_set_composited (window, child->composited);

  gtk_widget_set_app_paintable (GTK_WIDGET (child),
                                child->parent_relative_bg || child->has_alpha);

  /* Double-buffering will interfere with the parent-relative-background fake
   * transparency, since the double-buffer code doesn't know how to fill in the
   * background of the double-buffer correctly.
   */
  gtk_widget_set_double_buffered (GTK_WIDGET (child),
                                  child->parent_relative_bg);
}
Esempio n. 7
0
PRIVATE GdkFilterReturn
monitor_icon_event(GdkXEvent* xevent, GdkEvent* event, GdkWindow* wrapper)
{
    XEvent* xev = xevent;
    if (xev->type == DestroyNotify) {
        if (_deepin_tray == wrapper ) {
            destroy_wrapper(_deepin_tray);
            _deepin_tray = NULL;
            _deepin_tray_width = 0;
            _update_fcitx_try_position();
        } else if (_fcitx_tray == wrapper) {
            destroy_wrapper(_fcitx_tray);
            _fcitx_tray = NULL;
            _fcitx_tray_width = 0;
            _update_notify_area_width();
        } else {
            g_hash_table_remove(_icons, wrapper);
            destroy_wrapper(wrapper);
            _update_notify_area_width();
        }
        return GDK_FILTER_CONTINUE;
    } else if (xev->type == ConfigureNotify) {
        XConfigureEvent* xev = (XConfigureEvent*)xevent;
        int new_width = ((XConfigureEvent*)xev)->width;
        if (wrapper == _deepin_tray) {
            _deepin_tray_width = CLAMP_WIDTH(new_width);
            _update_deepin_try_position();
        } else if (wrapper == _fcitx_tray) {
            _fcitx_tray_width = CLAMP_WIDTH(new_width);
            _update_fcitx_try_position();
        } else if (wrapper != _deepin_tray && wrapper != _fcitx_tray) {
            int new_height = ((XConfigureEvent*)xev)->height;
            g_hash_table_insert(_icons, wrapper, GINT_TO_POINTER(CLAMP_WIDTH((new_width * 1.0 / new_height * DEFAULT_HEIGHT))));
            _update_notify_area_width();
        }
        return GDK_FILTER_REMOVE;
    } else if (xev->type == GenericEvent) {
        GdkWindow* parent = gdk_window_get_parent(wrapper);
        XGenericEvent* ge = xevent;
        if (ge->evtype == EnterNotify) {
            g_object_set_data(G_OBJECT(wrapper), "is_mouse_in", GINT_TO_POINTER(TRUE));
            gdk_window_invalidate_rect(parent, NULL, TRUE);
        } else if (ge->evtype == LeaveNotify) {
            g_object_set_data(G_OBJECT(wrapper), "is_mouse_in", GINT_TO_POINTER(FALSE));
            gdk_window_invalidate_rect(parent, NULL, TRUE);
        }
        return GDK_FILTER_REMOVE;
    }
    return GDK_FILTER_CONTINUE;
}
Esempio n. 8
0
static void realize(GtkWidget* widget)
{
    parent_class->realize(widget);

    wxPizza* pizza = WX_PIZZA(widget);
    if (pizza->m_border_style || pizza->m_is_scrollable)
    {
        int border_x, border_y;
        pizza->get_border_widths(border_x, border_y);
        int x = widget->allocation.x + border_x;
        int y = widget->allocation.y + border_y;
        int w = widget->allocation.width  - 2 * border_x;
        int h = widget->allocation.height - 2 * border_y;
        if (w < 0) w = 0;
        if (h < 0) h = 0;
        if (pizza->m_is_scrollable)
        {
            // second window is created if wxWindow is scrollable
            GdkWindowAttr attr;
            attr.event_mask = 0;
            attr.x = x;
            attr.y = y;
            attr.width  = w;
            attr.height = h;
            attr.wclass = GDK_INPUT_OUTPUT;
            attr.visual = gtk_widget_get_visual(widget);
            attr.colormap = gtk_widget_get_colormap(widget);
            attr.window_type = GDK_WINDOW_CHILD;

            pizza->m_backing_window = gdk_window_new(
                gdk_window_get_parent(widget->window),
                &attr,
                GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP);

            gdk_window_set_user_data(pizza->m_backing_window, widget);
            gdk_window_reparent(widget->window, pizza->m_backing_window, 0, 0);
            gdk_window_resize(widget->window, w, h);

            // Parts of m_backing_window may be exposed temporarily while
            // resizing. Setting the backing pixmap to None prevents those
            // areas from being briefly painted black.
            gdk_window_set_back_pixmap(pizza->m_backing_window, NULL, false);
        }
        else
            gdk_window_move_resize(widget->window, x, y, w, h);
    }
}
Esempio n. 9
0
static gboolean
is_parent_of (GdkWindow *parent,
              GdkWindow *child)
{
  GdkWindow *w;

  w = child;
  while (w != NULL)
    {
      if (w == parent)
        return TRUE;

      w = gdk_window_get_parent (w);
    }

  return FALSE;
}
Esempio n. 10
0
GdkWindow * gdk_xynth_other_event_window (GdkWindow *window, GdkEventType type)
{
	GdkWindow *w;
	guint32 evmask;
	ENTER();
	w = window;
	while (w != _gdk_parent_root) {
		if ((w != window) && (GDK_WINDOW_OBJECT(w)->window_type != GDK_WINDOW_CHILD) && (g_object_get_data(G_OBJECT(w), "gdk-window-child-handler"))) {
			break;
		}
		evmask = GDK_WINDOW_OBJECT(w)->event_mask;
		if (evmask & type_masks[type]) {
			LEAVE();
			return w;
		}
		w = gdk_window_get_parent(w);
	}
	LEAVE();
	return NULL;
}
Esempio n. 11
0
GtkWidget*
remmina_widget_pool_find_by_window(GType type, GdkWindow *window)
{
	GtkWidget *widget;
	gint i;
	GdkWindow *parent;

	if (window == NULL || remmina_widget_pool == NULL)
		return NULL;

	for (i = 0; i < remmina_widget_pool->len; i++)
	{
		widget = GTK_WIDGET(g_ptr_array_index(remmina_widget_pool, i));
		if (!G_TYPE_CHECK_INSTANCE_TYPE(widget, type))
			continue;
		/* gdk_window_get_toplevel won't work here, if the window is an embedded client. So we iterate the window tree */
		for (parent = window; parent && parent != GDK_WINDOW_ROOT; parent = gdk_window_get_parent(parent))
		{
			if (gtk_widget_get_window(widget) == parent)
				return widget;
		}
	}
	return NULL;
}
Esempio n. 12
0
static PyObject *
PyGdkWindow_GetAttr(PyGdkWindow_Object *self, char *key)
{
    GdkWindow *win = PyGdkWindow_Get(self);
    gint x, y;
    GdkModifierType p_mask;

    if (!strcmp(key, "__members__"))
	return Py_BuildValue("[sssssssssssss]", "children", "colormap", "depth",
			     "height", "parent", "pointer", "pointer_state",
			     "toplevel", "type", "width", "x", "xid", "y");
    if (!strcmp(key, "width")) {
	gdk_drawable_get_size(win, &x, NULL);
	return PyInt_FromLong(x);
    }
    if (!strcmp(key, "height")) {
	gdk_drawable_get_size(win, NULL, &y);
	return PyInt_FromLong(y);
    }
    if (!strcmp(key, "x")) {
	gdk_window_get_position(win, &x, NULL);
	return PyInt_FromLong(x);
    }
    if (!strcmp(key, "y")) {
	gdk_window_get_position(win, NULL, &y);
	return PyInt_FromLong(y);
    }
    if (!strcmp(key, "colormap"))
	return PyGdkColormap_New(gdk_drawable_get_colormap(win));
    if (!strcmp(key, "pointer")) {
	gdk_window_get_pointer(win, &x, &y, NULL);
	return Py_BuildValue("(ii)", x, y);
    }
    if (!strcmp(key, "pointer_state")) {
	gdk_window_get_pointer(win, NULL, NULL, &p_mask);
	return PyInt_FromLong(p_mask);
    }
    if (!strcmp(key, "parent")) {
	GdkWindow *par = gdk_window_get_parent(win);
	if (par)
	    return PyGdkWindow_New(par);
	Py_INCREF(Py_None);
	return Py_None;
    }
    if (!strcmp(key, "toplevel"))
	return PyGdkWindow_New(gdk_window_get_toplevel(win));
    if (!strcmp(key, "children")) {
	GList *children, *tmp;
	PyObject *ret;
	children = gdk_window_get_children(win);
	if ((ret = PyList_New(0)) == NULL)
	    return NULL;
	for (tmp = children; tmp != NULL; tmp = tmp->next) {
	    PyObject *win = PyGdkWindow_New(tmp->data);
	    if (win == NULL) {
		Py_DECREF(ret);
		return NULL;
	    }
	    PyList_Append(ret, win);
	    Py_DECREF(win);
	}
	g_list_free(children);
	return ret;
    }
    if (!strcmp(key, "type"))
	return PyInt_FromLong(gdk_drawable_get_type(win));
    if (!strcmp(key, "depth")) {
	gdk_window_get_geometry(win, NULL, NULL, NULL, NULL, &x);
	return PyInt_FromLong(x);
    }
#ifdef WITH_XSTUFF
    if (!strcmp(key, "xid"))
	return PyInt_FromLong(GDK_WINDOW_XWINDOW(win));
#endif

    return Py_FindMethod(PyGdkWindow_methods, (PyObject *)self, key);
}
Esempio n. 13
0
nsresult
EmbedPrivate::Realize(PRBool *aAlreadyRealized)
{

  *aAlreadyRealized = PR_FALSE;

  // create the offscreen window if we have to
  EnsureOffscreenWindow();

  // Have we ever been initialized before?  If so then just reparent
  // from the offscreen window.
  if (mMozWindowWidget) {
    gtk_widget_reparent(mMozWindowWidget, GTK_WIDGET(mOwningWidget));
    *aAlreadyRealized = PR_TRUE;
    return NS_OK;
  }

  // Get the nsIWebBrowser object for our embedded window.
  nsCOMPtr<nsIWebBrowser> webBrowser;
  mWindow->GetWebBrowser(getter_AddRefs(webBrowser));

  // get a handle on the navigation object
  mNavigation = do_QueryInterface(webBrowser);

  // Create our session history object and tell the navigation object
  // to use it.  We need to do this before we create the web browser
  // window.
  mSessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID);
  mNavigation->SetSessionHistory(mSessionHistory);

  // create the window
  mWindow->CreateWindow();

  // bind the progress listener to the browser object
  nsCOMPtr<nsISupportsWeakReference> supportsWeak;
  supportsWeak = do_QueryInterface(mProgressGuard);
  nsCOMPtr<nsIWeakReference> weakRef;
  supportsWeak->GetWeakReference(getter_AddRefs(weakRef));
  webBrowser->AddWebBrowserListener(weakRef,
				    NS_GET_IID(nsIWebProgressListener));

  // set ourselves as the parent uri content listener
  nsCOMPtr<nsIURIContentListener> uriListener;
  uriListener = do_QueryInterface(mContentListenerGuard);
  webBrowser->SetParentURIContentListener(uriListener);

  // save the window id of the newly created window
  nsCOMPtr<nsIWidget> mozWidget;
  mWindow->mBaseWindow->GetMainWidget(getter_AddRefs(mozWidget));
  // get the native drawing area
  GdkWindow *tmp_window =
    static_cast<GdkWindow *>(
		   mozWidget->GetNativeData(NS_NATIVE_WINDOW));
  // and, thanks to superwin we actually need the parent of that.
  tmp_window = gdk_window_get_parent(tmp_window);
  // save the widget ID - it should be the mozarea of the window.
  gpointer data = nsnull;
  gdk_window_get_user_data(tmp_window, &data);
  mMozWindowWidget = static_cast<GtkWidget *>(data);

  // Apply the current chrome mask
  ApplyChromeMask();

  return NS_OK;
}
Esempio n. 14
0
static GtkWidget *
find_widget_under_pointer (GdkWindow *window,
                           gint      *x,
                           gint      *y)
{
  GtkWidget *event_widget;
  struct ChildLocation child_loc = { NULL, NULL, 0, 0 };

  gdk_window_get_user_data (window, (void **)&event_widget);

  if (! event_widget)
    return NULL;

#ifdef DEBUG_TOOLTIP
  g_print ("event window %p (belonging to %p (%s))  (%d, %d)\n",
           window, event_widget, gtk_widget_get_name (event_widget),
           *x, *y);
#endif

  /* Coordinates are relative to event window */
  child_loc.x = *x;
  child_loc.y = *y;

  /* We go down the window hierarchy to the widget->window,
   * coordinates stay relative to the current window.
   * We end up with window == widget->window, coordinates relative to that.
   */
  while (window && window != gtk_widget_get_window (event_widget))
    {
      gint px, py;

      gdk_window_get_position (window, &px, &py);
      child_loc.x += px;
      child_loc.y += py;

      window = gdk_window_get_parent (window);
    }

  /* Failing to find widget->window can happen for e.g. a detached handle box;
   * chaining ::query-tooltip up to its parent probably makes little sense,
   * and users better implement tooltips on handle_box->child.
   * so we simply ignore the event for tooltips here.
   */
  if (!window)
    return NULL;

  /* Convert the window relative coordinates to allocation
   * relative coordinates.
   */
  window_to_alloc (event_widget,
                   child_loc.x, child_loc.y,
                   &child_loc.x, &child_loc.y);

  if (GTK_IS_CONTAINER (event_widget))
    {
      GtkWidget *container = event_widget;

      child_loc.container = event_widget;
      child_loc.child = NULL;

      gtk_container_forall (GTK_CONTAINER (event_widget),
                            child_location_foreach, &child_loc);

      /* Here we have a widget, with coordinates relative to
       * child_loc.container's allocation.
       */

      if (child_loc.child)
        event_widget = child_loc.child;
      else if (child_loc.container)
        event_widget = child_loc.container;

      /* Translate to event_widget's allocation */
      gtk_widget_translate_coordinates (container, event_widget,
                                        child_loc.x, child_loc.y,
                                        &child_loc.x, &child_loc.y);

    }

  /* We return (x, y) relative to the allocation of event_widget. */
  if (x)
    *x = child_loc.x;
  if (y)
    *y = child_loc.y;

  return event_widget;
}
Esempio n. 15
0
static VALUE
gdkwin_get_parent(VALUE self)
{
    return GOBJ2RVAL(gdk_window_get_parent(_SELF(self)));
}
Esempio n. 16
0
GdkWindow * gdk_xynth_pointer_event_window (GdkWindow *window, GdkEventType type)
{
	guint evmask;
	GdkWindow *w;
	GdkModifierType mask;
	
	ENTER();
	
	gdk_xynth_mouse_get_info(NULL, NULL, &mask);
	
	if (_gdk_xynth_pointer_grab_window && !_gdk_xynth_pointer_grab_owner_events) {
		evmask = _gdk_xynth_pointer_grab_events;
		if (evmask & (GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK)) {
			if (((mask & GDK_BUTTON1_MASK) && (evmask & GDK_BUTTON1_MOTION_MASK)) ||
			    ((mask & GDK_BUTTON2_MASK) && (evmask & GDK_BUTTON2_MOTION_MASK)) ||
                            ((mask & GDK_BUTTON3_MASK) && (evmask & GDK_BUTTON3_MOTION_MASK))) {
				evmask |= GDK_POINTER_MOTION_MASK;
			}
		}
		if (evmask & type_masks[type]) {
			if (_gdk_xynth_pointer_grab_owner_events) {
				LEAVE();
				return _gdk_xynth_pointer_grab_window;
			} else {
				GdkWindowObject *obj= GDK_WINDOW_OBJECT(window);
				while (obj != NULL && 
				       obj != GDK_WINDOW_OBJECT(_gdk_xynth_pointer_grab_window)) {
					obj = (GdkWindowObject *) obj->parent;
				}
				if (obj == GDK_WINDOW_OBJECT(_gdk_xynth_pointer_grab_window)) {
					LEAVE();
					return  window;
				} else {
					LEAVE();
					return _gdk_xynth_pointer_grab_window;
				}
			}
		}
	}
	w = window;
	while (w != _gdk_parent_root) {
		/* Huge hack, so that we don't propagate events to GtkWindow->frame */
		if ((w != window) &&
		    (GDK_WINDOW_OBJECT(w)->window_type != GDK_WINDOW_CHILD) &&
		    (g_object_get_data(G_OBJECT(w), "gdk-window-child-handler"))) {
			break;
		}
		evmask = GDK_WINDOW_OBJECT(w)->event_mask;
		if (evmask & (GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK)) {
			if (((mask & GDK_BUTTON1_MASK) && (evmask & GDK_BUTTON1_MOTION_MASK)) ||
			    ((mask & GDK_BUTTON2_MASK) && (evmask & GDK_BUTTON2_MOTION_MASK)) ||
			    ((mask & GDK_BUTTON3_MASK) && (evmask & GDK_BUTTON3_MOTION_MASK))) {
				evmask |= GDK_POINTER_MOTION_MASK;
			}
		}
		if (evmask & type_masks[type]) {
			LEAVE();
			return w;
		}
		w = gdk_window_get_parent(w);
	}
	LEAVE();
	return NULL;
}
Esempio n. 17
0
File: dnd.c Progetto: ayyi/samplecat
gint
drag_received (GtkWidget* widget, GdkDragContext* drag_context, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer user_data)
{
	// this receives drops for the whole window.

	if(!data || data->length < 0){ perr("no data!\n"); return -1; }

	dbg(1, "%s", data->data);

	if(g_str_has_prefix((char*)data->data, "colour:")){

		char* colour_string = (char*)data->data + 7;
		unsigned colour_index = atoi(colour_string) ? atoi(colour_string) - 1 : 0;

		// which row are we on?
		GtkTreePath* path;
		GtkTreeIter iter;
		gint tx, treeview_top;
		gdk_window_get_position(app->libraryview->widget->window, &tx, &treeview_top);
		dbg(2, "treeview_top=%i", y);

#ifdef HAVE_GTK_2_12
		gint bx, by;
		gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(app->libraryview->widget), x, y - treeview_top, &bx, &by);
		dbg(2, "coords: %dx%d => %dx%d", x, y, bx, by);

#else
		gint by = y - treeview_top - 20;
#endif

#ifdef USE_GDL
		GdkWindow* top_window = gdk_window_get_toplevel(gtk_widget_get_toplevel(app->libraryview->widget)->window);
		GdkWindow* window = app->libraryview->widget->window;
		while((window = gdk_window_get_parent(window)) != top_window){
			gint x0, y0;
			gdk_window_get_position(window, &x0, &y0);
			by -= y0;
		}
#endif

    if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(app->libraryview->widget), x, by, &path, NULL, NULL, NULL)){

      gtk_tree_model_get_iter(GTK_TREE_MODEL(samplecat.store), &iter, path);
      gchar* path_str = gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(samplecat.store), &iter);
      dbg(2, "path=%s y=%i final_y=%i", path_str, y, y - treeview_top);

      listview_item_set_colour(path, colour_index);

      gtk_tree_path_free(path);
    }
    else dbg(0, "path not found.");

    return FALSE;
  }

  if(info == GPOINTER_TO_INT(GDK_SELECTION_TYPE_STRING)) printf(" type=string.\n");

  if(info == GPOINTER_TO_INT(TARGET_URI_LIST)){
    dbg(1, "type=uri_list. len=%i", data->length);
    GList* list = uri_list_to_glist((char*)data->data);
    if(g_list_length(list) < 1) pwarn("drag drop: uri list parsing found no uri's.\n");
    int i = 0;
    ScanResults result = {0,};
    GList* l = list;
#ifdef __APPLE__
    gdk_threads_enter();
#endif
    for(;l;l=l->next){
      char* u = l->data;

      gchar* method_string;
      vfs_get_method_string(u, &method_string);
      dbg(2, "%i: %s method=%s", i, u, method_string);

      if(!strcmp(method_string, "file")){
        //we could probably better use g_filename_from_uri() here
        //http://10.0.0.151/man/glib-2.0/glib-Character-Set-Conversion.html#g-filename-from-uri
        //-or perhaps get_local_path() from rox/src/support.c

        char* uri_unescaped = vfs_unescape_string(u + strlen(method_string) + 1, NULL);

        char* uri = (strstr(uri_unescaped, "///") == uri_unescaped) ? uri_unescaped + 2 : uri_unescaped;

        if(do_progress(0,0)) break;
        if(is_dir(uri)) application_add_dir(uri, &result);
        else application_add_file(uri, &result);

        g_free(uri_unescaped);
      }
      else pwarn("drag drop: unknown format: '%s'. Ignoring.\n", u);
      i++;
    }
    hide_progress();
#ifdef __APPLE__
    gdk_threads_leave();
#endif

    statusbar_print(1, "import complete. %i files added", result.n_added);

    uri_list_free(list);
  }

  return FALSE;
}
Esempio n. 18
0
static void
find_widget (GtkWidget      *widget,
             FindWidgetData *data)
{
  GtkAllocation new_allocation;
  gint x_offset = 0;
  gint y_offset = 0;

  gtk_widget_get_allocation (widget, &new_allocation);

  if (data->found || !gtk_widget_get_mapped (widget))
    return;

  /* Note that in the following code, we only count the
   * position as being inside a WINDOW widget if it is inside
   * widget->window; points that are outside of widget->window
   * but within the allocation are not counted. This is consistent
   * with the way we highlight drag targets.
   */
  if (gtk_widget_get_has_window (widget))
    {
      new_allocation.x = 0;
      new_allocation.y = 0;
    }

  if (gtk_widget_get_parent (widget) && !data->first)
    {
      GdkWindow *window;

      window = gtk_widget_get_window (widget);
      while (window != gtk_widget_get_window (gtk_widget_get_parent (widget)))
        {
          gint tx, ty, twidth, theight;

          if (window == NULL)
            return;

          twidth = gdk_window_get_width (window);
          theight = gdk_window_get_height (window);

          if (new_allocation.x < 0)
            {
              new_allocation.width += new_allocation.x;
              new_allocation.x = 0;
            }
          if (new_allocation.y < 0)
            {
              new_allocation.height += new_allocation.y;
              new_allocation.y = 0;
            }
          if (new_allocation.x + new_allocation.width > twidth)
            new_allocation.width = twidth - new_allocation.x;
          if (new_allocation.y + new_allocation.height > theight)
            new_allocation.height = theight - new_allocation.y;

          gdk_window_get_position (window, &tx, &ty);
          new_allocation.x += tx;
          x_offset += tx;
          new_allocation.y += ty;
          y_offset += ty;

          window = gdk_window_get_parent (window);
        }
    }

  if ((data->x >= new_allocation.x) && (data->y >= new_allocation.y) &&
      (data->x < new_allocation.x + new_allocation.width) &&
      (data->y < new_allocation.y + new_allocation.height))
    {
      /* First, check if the drag is in a valid drop site in
       * one of our children 
       */
      if (GTK_IS_CONTAINER (widget))
        {
          FindWidgetData new_data = *data;

          new_data.x -= x_offset;
          new_data.y -= y_offset;
          new_data.found = FALSE;
          new_data.first = FALSE;

          gtk_container_forall (GTK_CONTAINER (widget),
                                (GtkCallback)find_widget,
                                &new_data);

          data->found = new_data.found;
          if (data->found)
            data->res_widget = new_data.res_widget;
        }

      /* If not, and this widget is registered as a drop site, check to
       * emit "drag_motion" to check if we are actually in
       * a drop site.
       */
      if (!data->found)
        {
          data->found = TRUE;
          data->res_widget = widget;
        }
    }
}