static void
carrick_list_drag_begin (GtkWidget      *widget,
                         GdkDragContext *context,
                         CarrickList    *list)
{
  CarrickListPrivate *priv = list->priv;
  gint                x, y;

  carrick_service_item_set_active (CARRICK_SERVICE_ITEM (widget), FALSE);

  /* save old place in list for drag-failures */
  gtk_container_child_get (GTK_CONTAINER (priv->box),
                           widget,
                           "position", &priv->drag_position,
                           NULL);
  priv->drop_position = priv->drag_position;

  /* remove widget from list and setup dnd popup window */
  priv->drag_window = gtk_window_new (GTK_WINDOW_POPUP);
  gtk_widget_set_size_request (priv->drag_window,
                               widget->allocation.width,
                               widget->allocation.height);
  gtk_widget_get_pointer (widget, &x, &y);
  gtk_widget_reparent (widget, priv->drag_window);
  gtk_drag_set_icon_widget (context,
                            priv->drag_window,
                            x, y);
}
Ejemplo n.º 2
0
static gboolean
lyric_show_viewport_button_press(GtkWidget    *widget,GdkEventButton *event)
{
    LyricShowViewport *lsv;
    lsv = LYRIC_SHOW_VIEWPORT(widget);
    gint x = 0;
    gint y = 0;

    if(!gtk_widget_get_visible(lsv->priv->lyricbox))
    {
        goto ext;
    }

    if(event->button != 1)
        goto ext;

#if GTK_CHECK_VERSION(3,2,0)
    gtk_widget_get_mouse_position(widget,(GdkEvent*) event,&x,&y);
#else
    gtk_widget_get_pointer(widget,&x,&y);
#endif

    lsv->priv->is_pressed = TRUE;
    lsv->priv->pressed_y = y;

ext:
    lyric_show_viewport_update_cursor(lsv);
    gtk_widget_queue_resize(widget);
///    GTK_WIDGET_CLASS(lyric_show_viewport_parent_class)->button_press_event(widget,event);
    return FALSE;
}
Ejemplo n.º 3
0
static gboolean on_mouse_leave (GtkWidget *event_box, GdkEventButton *event, gpointer data)
{
	int orientation;
	pqi const inst = (pqi)data;
	gtk_widget_queue_draw(event_box);
	inst->glowing = FALSE; /* No more glow */
	/* Show the menu if it was gestured in the correct direction */
	if (inst->clicked) {
		GtkAllocation alloc;
		int x = event->x, y = event->y;
		gtk_widget_get_allocation(inst->box, &alloc); /* Get the dimensions of our widget */
		gtk_widget_get_pointer(inst->box, &x, &y); /* Get the location of our mouse */
		
		/* Check if the mouse is dragging away from the panel */
		orientation = mate_panel_applet_get_orient(inst->applet);
		if ((orientation == MATE_PANEL_APPLET_ORIENT_UP    && x > -alloc.width /2 && x < 3*alloc.width /2 && y <= 0)
		||  (orientation == MATE_PANEL_APPLET_ORIENT_RIGHT && y > -alloc.height/2 && y < 3*alloc.height/2 && x >= alloc.width)
		||  (orientation == MATE_PANEL_APPLET_ORIENT_DOWN  && x > -alloc.width /2 && x < 3*alloc.width /2 && y >= alloc.height)
		||  (orientation == MATE_PANEL_APPLET_ORIENT_LEFT  && y > -alloc.height/2 && y < 3*alloc.height/2 && x <= 0))
		{
			/* Dragging out menu */
			show_menu(inst);
		}
		else return TRUE;
	}
	return TRUE;
}
Ejemplo n.º 4
0
void widget_set_sensitive(GtkWidget * widget, gboolean sensitive)
{
	GtkWidget *button;

	gtk_widget_set_sensitive(widget, sensitive);

	/** @bug Gtk bug 56070. If the mouse is over a toolbar button that
	 *  becomes sensitive, one can't click it without moving the mouse out
	 *  and in again. This bug is registered in Bugzilla as a Gtk bug. The
	 *  workaround tests if the mouse is inside the currently sensitivized
	 *  button, and if yes call button_enter()
	 */
	if (!GTK_IS_BIN(widget))
		return;

	button = gtk_bin_get_child(GTK_BIN(widget));
	if (sensitive && GTK_IS_BUTTON(button)) {
		gint x, y, state;
		gtk_widget_get_pointer(button, &x, &y);
		state = GTK_WIDGET_STATE(button);
		if ((state == GTK_STATE_NORMAL
		     || state == GTK_STATE_PRELIGHT) && x >= 0 && y >= 0
		    && x < button->allocation.width
		    && y < button->allocation.height) {
			gtk_button_enter(GTK_BUTTON(button));
			GTK_BUTTON(button)->in_button = TRUE;
			gtk_widget_set_state(widget, GTK_STATE_PRELIGHT);
		}
	}
}
Ejemplo n.º 5
0
static VALUE
rg_pointer(VALUE self)
{
    int x, y;

    gtk_widget_get_pointer(_SELF(self), &x, &y);
    return rb_assoc_new(INT2FIX(x), INT2FIX(y));
}
Ejemplo n.º 6
0
repv
sys_get_mouse_pos(Lisp_Window *w)
{
    int x, y;
    /* XXX track mouse pointer position in gtk_jade.c.. */
    gtk_widget_get_pointer (GTK_WIDGET (w->w_Window), &x, &y);
    return make_pos((x - w->pixel_left) / w->font_width,
		    (y - w->pixel_top) / w->font_height);
}
Ejemplo n.º 7
0
Error GTKWindow::GetMousePos(Pos &oPos)
{
    if (initialized) {
        gdk_threads_enter();
        gtk_widget_get_pointer(mainWindow, &oPos.x, &oPos.y);
        gdk_threads_leave();
    }
    return kError_NoErr;
}
Ejemplo n.º 8
0
Archivo: ml_gtk.c Proyecto: CRogers/obc
CAMLprim value ml_gtk_widget_get_pointer (value w)
{
    int x,y;
    value ret;
    gtk_widget_get_pointer (GtkWidget_val(w), &x, &y);
    ret = alloc_small (2,0);
    Field(ret,0) = Val_int(x);
    Field(ret,1) = Val_int(y);
    return ret;
}
static gboolean
gossip_cell_renderer_expander_activate (GtkCellRenderer      *cell,
					GdkEvent             *event,
					GtkWidget            *widget,
					const gchar          *path_string,
					const GdkRectangle   *background_area,
					const GdkRectangle   *cell_area,
					GtkCellRendererState  flags)
{
	GossipCellRendererExpanderPriv *priv;
	GtkTreePath                    *path;
	gboolean                        in_cell;
	int                             mouse_x;
	int                             mouse_y;

	priv = GET_PRIV (cell);

	if (!GTK_IS_TREE_VIEW (widget) || !priv->activatable)
		return FALSE;

	path = gtk_tree_path_new_from_string (path_string);

	gtk_widget_get_pointer (widget, &mouse_x, &mouse_y);
	gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW (widget),
							   mouse_x, mouse_y,
							   &mouse_x, &mouse_y);

	/* check if click is within the cell */
	if (mouse_x - cell_area->x >= 0
	    && mouse_x - cell_area->x <= cell_area->width) {
		in_cell = TRUE;
	} else {
		in_cell = FALSE;
	}

	if (! in_cell) {
		gtk_tree_path_free (path);
		return FALSE;
	}

	if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
		gtk_tree_view_collapse_row (GTK_TREE_VIEW (widget), path);
		priv->style_flags &= ~(GTK_STATE_FLAG_ACTIVE);
	} else {
		gtk_tree_view_expand_row (GTK_TREE_VIEW (widget), path, FALSE);
		priv->style_flags |= ~(GTK_STATE_FLAG_ACTIVE);
	}

	gtk_tree_path_free (path);

	return TRUE;
}
Ejemplo n.º 10
0
static gint
area_event (GtkWidget *widget, GdkEvent *event, void *d)
{
	switch (event->type){
	case GDK_EXPOSE: {
		GdkEventExpose *e = (GdkEventExpose *) event;
		paint (&e->area);
		return TRUE;
	}
	
	case GDK_BUTTON_PRESS: {
		int x, y;
		gtk_widget_get_pointer (widget, &x, &y);
		kill_balls (x / STONE_SIZE, y / STONE_SIZE);
		old_x = -1;
		old_y = -1;
	}

	case GDK_ENTER_NOTIFY:
	case GDK_MOTION_NOTIFY: {
		int x, y;
		
		gtk_widget_get_pointer (widget, &x, &y);
		mark_balls (x / STONE_SIZE, y / STONE_SIZE);
		return TRUE;
	}
	
	case GDK_LEAVE_NOTIFY:
		old_x = -1;
		old_y = -1;
		disable_timeout ();
		untag_all ();
		return TRUE;

	default:
		return FALSE;
	}
}
Ejemplo n.º 11
0
static gint key_press_map_cb(GtkWidget * area, GdkEventKey * event,
			     gpointer user_data)
{
	static gint last_x, last_y;
	static gchar *last_key;
	GuiMap *gmap = user_data;
	gint x, y;
	gboolean plus10;

	if (area->window == NULL || gmap->map == NULL)
		return FALSE;

	gtk_widget_get_pointer(area, &x, &y);

	current_hex = guimap_find_hex(gmap, x, y);
	if (current_hex == NULL || !terrain_has_chit(current_hex->terrain))
		return TRUE;

	if (last_x == x && last_y == y && strcmp(last_key, "1") == 0)
		plus10 = TRUE;
	else
		plus10 = FALSE;

	if (!plus10 && strcmp(event->string, "2") == 0)
		current_hex->roll = 2;
	else if (strcmp(event->string, "3") == 0)
		current_hex->roll = 3;
	else if (strcmp(event->string, "4") == 0)
		current_hex->roll = 4;
	else if (strcmp(event->string, "5") == 0)
		current_hex->roll = 5;
	else if (strcmp(event->string, "6") == 0)
		current_hex->roll = 6;
	else if (strcmp(event->string, "8") == 0)
		current_hex->roll = 8;
	else if (strcmp(event->string, "9") == 0)
		current_hex->roll = 9;
	else if (plus10 && strcmp(event->string, "0") == 0)
		current_hex->roll = 10;
	else if (plus10 && strcmp(event->string, "1") == 0)
		current_hex->roll = 11;
	else if (plus10 && strcmp(event->string, "2") == 0)
		current_hex->roll = 12;
	guimap_draw_hex(gmap, current_hex);
	last_x = x;
	last_y = y;
	g_free(last_key);
	last_key = g_strdup(event->string);
	return TRUE;
}
Ejemplo n.º 12
0
static void
record_stroke_segment (GtkWidget *widget)
{
  gint x, y;
  struct gstroke_metrics *metrics;

  g_return_if_fail( widget != NULL );

  gtk_widget_get_pointer (widget, &x, &y);

  if (last_mouse_position.invalid)
    last_mouse_position.invalid = FALSE;
  else if (gstroke_draw_strokes())
    {
#if 1
      XDrawLine (gstroke_disp, gstroke_window, gstroke_gc,
                 last_mouse_position.last_point.x,
                 last_mouse_position.last_point.y,
                 x, y);
      /* XFlush (gstroke_disp); */
#else
      /* FIXME: this does not work. It will only work if we create a
         corresponding GDK window for stroke_window and draw on
         that... */
      gdk_draw_line (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
                     last_mouse_position.last_point.x,
                     last_mouse_position.last_point.y,
                     x,
                     y);
#endif
    }

  if (last_mouse_position.last_point.x != x
      || last_mouse_position.last_point.y != y)
    {
      last_mouse_position.last_point.x = x;
      last_mouse_position.last_point.y = y;
      metrics = (struct gstroke_metrics *)g_object_get_data(G_OBJECT(widget),
															GSTROKE_METRICS);
      _gstroke_record (x, y, metrics);
    }
}
Ejemplo n.º 13
0
/*! \brief Emits a faked motion event to update objects being drawn or placed
 *  \par Function Description
 *  This function emits an additional "motion-notify-event" to
 *  update objects being drawn or placed while zooming, scrolling, or
 *  panning.
 *
 *  If its event parameter is not NULL, the current state of Shift
 *  and Control is preserved to correctly deal with special cases.
 *
 *  \param [in] view      The GschemPageView object which received the signal.
 *  \param [in] event     The event structure of the signal or NULL.
 *  \returns FALSE to propagate the event further.
 */
gboolean
x_event_faked_motion (GschemPageView *view, GdkEventKey *event) {
  gint x, y;
  gboolean ret;
  GdkEventMotion *newevent;

  gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
  newevent = (GdkEventMotion*)gdk_event_new(GDK_MOTION_NOTIFY);
  newevent->x = x;
  newevent->y = y;

  if (event != NULL ) {
    switch (event->keyval) {
      case GDK_Control_L:
      case GDK_Control_R:
        if (event->type == GDK_KEY_PRESS) {
          newevent->state |= GDK_CONTROL_MASK;
        } else {
          newevent->state &= ~GDK_CONTROL_MASK;
        }
        break;

      case GDK_Shift_L:
      case GDK_Shift_R:
        if (event->type == GDK_KEY_PRESS) {
          newevent->state |= GDK_SHIFT_MASK;
        } else {
          newevent->state &= ~GDK_SHIFT_MASK;
        }
        break;
    }
  }

  g_signal_emit_by_name (view, "motion-notify-event", newevent, &ret);

  gdk_event_free((GdkEvent*)newevent);

  return FALSE;
}
Ejemplo n.º 14
0
static gboolean
lyric_show_viewport_button_release(GtkWidget    *widget,GdkEventButton *event)
{
    LyricShowViewport *lsv;
    lsv = LYRIC_SHOW_VIEWPORT(widget);

    gint64 t=0;
    gint x = 0;
    gint y = 0;
    gboolean is_pressed = lsv->priv->is_pressed;

#if GTK_CHECK_VERSION(3,2,0)
    gtk_widget_get_mouse_position(widget,(GdkEvent*)event,&x,&y);
#else
    gtk_widget_get_pointer(widget,&x,&y);
#endif

    lsv->priv->is_pressed = FALSE;

    if(is_pressed && lsv->priv->time_requestable)
    {
        t = lyric_show_viewport_get_requested_time(lsv);
///        lsv->priv->pos += lsv->priv->pressed_pos ;
        lsv->priv->pressed_pos = 0;

        lyric_show_viewport_update_cursor(lsv);
        lyric_show_time_request(LYRIC_SHOW(lsv),t);
    }else
        lyric_show_viewport_update_current_widget(lsv);
    if(event->button == 3)
    {
        GtkWidget *menu = lyric_show_menu_get_for(LYRIC_SHOW(widget));
        gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,event->button,event->time);
    }
    gtk_widget_queue_resize(widget);
///    GTK_WIDGET_CLASS(lyric_show_viewport_parent_class)->button_release_event(widget,event);
    return FALSE;
}
Ejemplo n.º 15
0
static gint 
timer_cb (EyesApplet *eyes_applet)
{
        gint x, y;
        gint pupil_x, pupil_y;
        gint i;

        for (i = 0; i < eyes_applet->num_eyes; i++) {
		if (gtk_widget_get_realized (eyes_applet->eyes[i])) {
			gtk_widget_get_pointer (eyes_applet->eyes[i], 
						&x, &y);
			if ((x != eyes_applet->pointer_last_x[i]) || (y != eyes_applet->pointer_last_y[i])) { 

				calculate_pupil_xy (eyes_applet, x, y, &pupil_x, &pupil_y, eyes_applet->eyes[i]);
				draw_eye (eyes_applet, i, pupil_x, pupil_y);
	    	        
			        eyes_applet->pointer_last_x[i] = x;
			        eyes_applet->pointer_last_y[i] = y;
			}
		}
        }
        return TRUE;
}
Ejemplo n.º 16
0
/*! \brief get the pointer position of a given GschemToplevel
 *  \par Function Description
 *  This function gets the pointer position of the drawing area of the
 *  current workspace <b>GschemToplevel</b>. The flag <b>snapped</b> specifies
 *  whether the pointer position should be snapped to the current grid.
 *
 *  \param [in] w_current  The GschemToplevel object.
 *  \param [in] snapped    An option flag to specify the wished coords
 *  \param [out] wx        snapped/unsnapped world x coordinate
 *  \param [out] wy        snapped/unsnapped world y coordinate
 *
 *  \return Returns TRUE if the pointer position is inside the drawing area.
 *
 */
gboolean
x_event_get_pointer_position (GschemToplevel *w_current, gboolean snapped, gint *wx, gint *wy)
{
  int width;
  int height;
  int sx;
  int sy;
  int x;
  int y;

  GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current);
  g_return_val_if_fail (page_view != NULL, FALSE);

  g_return_val_if_fail (GTK_WIDGET (page_view)->window != NULL, FALSE);

  /* \todo The following line is depricated in GDK 2.24 */
  gdk_drawable_get_size (GTK_WIDGET (page_view)->window, &width, &height);

  gtk_widget_get_pointer(GTK_WIDGET (page_view), &sx, &sy);

  /* check if we are inside the drawing area */
  if ((sx < 0) || (sx >= width) || (sy < 0) || (sy >= height)) {
    return FALSE;
  }

  gschem_page_view_SCREENtoWORLD (page_view, sx, sy, &x, &y);

  if (snapped) {
    x = snap_grid (w_current, x);
    y = snap_grid (w_current, y);
  }

  *wx = x;
  *wy = y;

  return TRUE;
}
Ejemplo n.º 17
0
static gboolean
lyric_show_viewport_motion_notify(GtkWidget *widget,GdkEventMotion *event)
{
    LyricShowViewport *lsv;
    lsv = LYRIC_SHOW_VIEWPORT(widget);
    gint x = 0;
    gint y = 0;
    gint tmp_pos = 0;
    GtkAllocation alc = {0};

    if(lsv->priv->time_requestable)
    {

#if GTK_CHECK_VERSION(3,2,0)
        gtk_widget_get_mouse_position(widget,(GdkEvent*)event,&x,&y);
#else
        gtk_widget_get_pointer(widget,&x,&y);
#endif

        tmp_pos = lsv->priv->pressed_y - y;
        gtk_widget_get_allocation(lsv->priv->lyricbox,&alc);
        if(tmp_pos + lsv->priv->pos > 0)
        {
            if(tmp_pos + lsv->priv->pos >= alc.height)
                tmp_pos = alc.height-lsv->priv->pos-1;
        }else{
            tmp_pos = -lsv->priv->pos;
        }
        lsv->priv->pressed_pos = tmp_pos;
        gtk_widget_queue_resize(widget);
    }
    if(GTK_WIDGET_CLASS(lyric_show_viewport_parent_class)->motion_notify_event)
    {
        GTK_WIDGET_CLASS(lyric_show_viewport_parent_class)->motion_notify_event(widget,event);
    }
    return FALSE;
}
Ejemplo n.º 18
0
gboolean onMouseMove(GtkWidget * widget, GdkEventMotion * event, gpointer user_data) {
  udata *dat=(udata *)user_data;
  gint x, y, x0=0, y0=0;
  UNUSED(widget);
  UNUSED(event);

  x0 = (dat->imgWG->allocation.width - dat->nx*dat->zoom)/2;
  if (x0 < 0) x0 = 0;
  y0 = (dat->imgWG->allocation.height - dat->ny*dat->zoom)/2;
  if (y0 < 0) y0 = 0;

  gtk_widget_get_pointer(dat->imgWG, &x, &y);
  dat->x = (x-x0) / dat->zoom + 1;
  dat->y = (y-y0) / dat->zoom + 1;

  if (dat->x<1) dat->x = 1;
  if (dat->y<1) dat->y = 1;
  if (dat->x>dat->nx) dat->x = dat->nx;
  if (dat->y>dat->ny) dat->y = dat->ny;
  
  updateStatusBar(user_data);
  gdk_flush();
  return TRUE;
}
Ejemplo n.º 19
0
/* GTk utility function */
void gtk_button_set_sensitive(GtkWidget *button, gboolean sensitive)
{
    gtk_widget_set_sensitive(button, sensitive);

    /* Simulate a mouse crossing event, to enable button */
    if ( sensitive ) {
        int x, y;
        gboolean retval;
        GdkEventCrossing crossing;

        gtk_widget_get_pointer(button, &x, &y);
        if ( (x >= 0) && (y >= 0) &&
             (x <= button->allocation.width) &&
             (y <= button->allocation.height) ) {
                memset(&crossing, 0, sizeof(crossing));
                crossing.type = GDK_ENTER_NOTIFY;
                crossing.window = button->window;
                crossing.detail = GDK_NOTIFY_VIRTUAL;
                gtk_signal_emit_by_name(GTK_OBJECT(button),
                                        "enter_notify_event",
                                        &crossing, &retval);
        }
    }
}
Ejemplo n.º 20
0
static void
chat_text_view_populate_popup (EmpathyChatTextView *view,
			  GtkMenu        *menu,
			  gpointer        user_data)
{
	EmpathyChatTextViewPriv *priv;
	GtkTextTagTable    *table;
	GtkTextTag         *tag;
	gint                x, y;
	GtkTextIter         iter, start, end;
	GtkWidget          *item;
	gchar              *str = NULL;
	
	priv = GET_PRIV (view);
	
	/* Clear menu item */
	if (gtk_text_buffer_get_char_count (priv->buffer) > 0) {
		item = gtk_menu_item_new ();
		gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
		gtk_widget_show (item);
		
		item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
		gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
		gtk_widget_show (item);
		
		g_signal_connect (item,
				  "activate",
				  G_CALLBACK (chat_text_view_clear_view_cb),
				  view);
	}
	
	/* Link context menu items */
	table = gtk_text_buffer_get_tag_table (priv->buffer);
	tag = gtk_text_tag_table_lookup (table, EMPATHY_CHAT_TEXT_VIEW_TAG_LINK);
	
	gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
	
	gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
					       GTK_TEXT_WINDOW_WIDGET,
					       x, y,
					       &x, &y);
	
	gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
	
	start = end = iter;
	
	if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
	    gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
		    str = gtk_text_buffer_get_text (priv->buffer,
						    &start, &end, FALSE);
	    }
	
	if (EMP_STR_EMPTY (str)) {
		g_free (str);
		return;
	}
	
	/* NOTE: Set data just to get the string freed when not needed. */
	g_object_set_data_full (G_OBJECT (menu),
				"url", str,
				(GDestroyNotify) g_free);
	
	item = gtk_menu_item_new ();
	gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
	gtk_widget_show (item);
	
	item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Address"));
	g_signal_connect (item,
			  "activate",
			  G_CALLBACK (chat_text_view_copy_address_cb),
			  str);
	gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
	gtk_widget_show (item);
	
	item = gtk_menu_item_new_with_mnemonic (_("_Open Link"));
	g_signal_connect (item,
			  "activate",
			  G_CALLBACK (chat_text_view_open_address_cb),
			  str);
	gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
	gtk_widget_show (item);
}
Ejemplo n.º 21
0
static void
ViewAutoDrawerUpdate(ViewAutoDrawer *that, // IN
                     gboolean immediate)   // IN
{
   ViewAutoDrawerPrivate *priv = that->priv;
   GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(that));
   GtkWindow *window;
   GtkAllocation allocation;

   if (!toplevel || !gtk_widget_is_toplevel(toplevel)) {
      // The autoDrawer cannot function properly without a toplevel.
      return;
   }
   window = GTK_WINDOW(toplevel);

   /*
    * We decide to open the drawer by OR'ing several conditions. Evaluating a
    * condition can have the side-effect of setting 'immediate' to TRUE, so we
    * cannot stop evaluating the conditions after we have found one to be TRUE.
    */

   priv->opened = FALSE;

   /* Is the AutoDrawer pinned? */

   if (priv->pinned) {
      immediate = TRUE;

      priv->opened = TRUE;
   }

   /* Is the mouse cursor inside the event box? */

   {
      int x;
      int y;

      gtk_widget_get_pointer(priv->evBox, &x, &y);
      gtk_widget_get_allocation(priv->evBox, &allocation);
      g_assert(gtk_container_get_border_width(   GTK_CONTAINER(priv->evBox))
                                              == 0);
      if (   (guint)x < (guint)allocation.width
          && (guint)y < (guint)allocation.height) {
         priv->opened = TRUE;
      }
   }

   /* If there is a focused widget, is it inside the event box? */

   {
      GtkWidget *focus;

      focus = gtk_window_get_focus(window);
      if (focus && gtk_widget_is_ancestor(focus, priv->evBox)) {
         /*
          * Override the default 'immediate' to make sure the 'over' widget
          * immediately appears along with the widget the focused widget.
          */
         immediate = TRUE;

         priv->opened = TRUE;
      }
   }

   /* If input is grabbed, is it on behalf of a widget inside the event box? */

   if (!priv->inputUngrabbed) {
      GtkWidget *grabbed = NULL;

      if (gtk_window_has_group (window)) {
        GtkWindowGroup *group = gtk_window_get_group (window);
        grabbed = gtk_window_group_get_current_grab (group);
      }
      if (!grabbed) {
         grabbed = gtk_grab_get_current();
      }

      if (grabbed && GTK_IS_MENU(grabbed)) {
         /*
          * With cascading menus, the deepest menu owns the grab. Traverse the
          * menu hierarchy up until we reach the attach widget for the whole
          * hierarchy.
          */

         for (;;) {
            GtkWidget *menuAttach;
            GtkWidget *menuItemParent;

            menuAttach = gtk_menu_get_attach_widget(GTK_MENU(grabbed));
            if (!menuAttach) {
               /*
                * It is unfortunately not mandatory for a menu to have a proper
                * attach widget set.
                */
               break;
            }

            grabbed = menuAttach;
            if (!GTK_IS_MENU_ITEM(grabbed)) {
               break;
            }

            menuItemParent = gtk_widget_get_parent(grabbed);
            g_return_if_fail(menuItemParent);
            if (!GTK_IS_MENU(menuItemParent)) {
               break;
            }

            grabbed = menuItemParent;
         }
      }

      if (grabbed && gtk_widget_is_ancestor(grabbed, priv->evBox)) {
         /*
          * Override the default 'immediate' to make sure the 'over' widget
          * immediately appears along with the widget the grab happens on
          * behalf of.
          */
         immediate = TRUE;

         priv->opened = TRUE;
      }
   }

   if (priv->delayConnection) {
      g_source_remove(priv->delayConnection);
   }

   if (priv->forceClosing) {
      ViewAutoDrawerEnforce(that, TRUE);
   } else if (immediate) {
      ViewAutoDrawerEnforce(that, FALSE);
   } else {
      priv->delayConnection = g_timeout_add(priv->delayValue,
         (GSourceFunc)ViewAutoDrawerOnEnforceDelay, that);
   }
}
Ejemplo n.º 22
0
gboolean gtk_xournal_button_press_event(GtkWidget * widget, GdkEventButton * event) {
	/**
	 * true: Core event, false: XInput event
	 */
	gboolean isCore = (event->device == gdk_device_get_core_pointer());

	INPUTDBG("ButtonPress (%s) (x,y)=(%.2f,%.2f), button %d, modifier %x, isCore %i", gdk_device_get_name(event->device), event->x, event->y,
			event->button, event->state, isCore);

	GtkXournal * xournal = GTK_XOURNAL(widget);
	Settings * settings = xournal->view->getControl()->getSettings();

	if(isCore && settings->isXinputEnabled() && settings->isIgnoreCoreEvents()) {
		INPUTDBG2("gtk_xournal_button_press_event return false (ignore core)");
		return false;
	}

	XInputUtils::fixXInputCoords((GdkEvent*) event, widget);

	if (event->type != GDK_BUTTON_PRESS) {
		INPUTDBG2("gtk_xournal_button_press_event return false (event->type != GDK_BUTTON_PRESS)");
		return false; // this event is not handled here
	}

	if (event->button > 3) { // scroll wheel events
		XInputUtils::handleScrollEvent(event, widget);
		INPUTDBG2("gtk_xournal_button_press_event return true handled scroll event");
		return true;
	}

	gtk_widget_grab_focus(widget);

	ToolHandler * h = xournal->view->getControl()->getToolHandler();

	// none button release event was sent, send one now
	if (xournal->currentInputPage) {
		INPUTDBG2("gtk_xournal_button_press_event (xournal->currentInputPage != NULL)");

		GdkEventButton ev = *event;
		xournal->currentInputPage->translateEvent((GdkEvent*) &ev, xournal->x, xournal->y);
		xournal->currentInputPage->onButtonReleaseEvent(widget, &ev);
	}

	// Change the tool depending on the key or device
	ButtonConfig * cfg = NULL;
	ButtonConfig * cfgTouch = settings->getTouchButtonConfig();
	if (event->button == 2) { // Middle Button
		cfg = settings->getMiddleButtonConfig();
	} else if (event->button == 3) { // Right Button
		cfg = settings->getRightButtonConfig();
	} else if (event->device->source == GDK_SOURCE_ERASER) {
		cfg = settings->getEraserButtonConfig();
	} else if (cfgTouch->device == event->device->name) {
		cfg = cfgTouch;

		// If an action is defined we do it, even if it's a drawing action...
		if (cfg->getDisableDrawing() && cfg->getAction() == TOOL_NONE) {
			ToolType tool = h->getToolType();
			if (tool == TOOL_PEN || tool == TOOL_ERASER || tool == TOOL_HILIGHTER) {
				printf("ignore touchscreen for drawing!\n");
				return true;
			}
		}
	}

	if (cfg && cfg->getAction() != TOOL_NONE) {
		h->copyCurrentConfig();
		cfg->acceptActions(h);
	}

	// hand tool don't change the selection, so you can scroll e.g.
	// with your touchscreen without remove the selection
	if (h->getToolType() == TOOL_HAND) {
		Cursor * cursor = xournal->view->getCursor();
		cursor->setMouseDown(true);
		xournal->lastMousePositionX = 0;
		xournal->lastMousePositionY = 0;
		xournal->inScrolling = true;
		gtk_widget_get_pointer(widget, &xournal->lastMousePositionX, &xournal->lastMousePositionY);

		INPUTDBG2("gtk_xournal_button_press_event (h->getToolType() == TOOL_HAND) return true");
		return true;
	} else if (xournal->selection) {
		EditSelection * selection = xournal->selection;

		PageView * view = selection->getView();
		GdkEventButton ev = *event;
		view->translateEvent((GdkEvent*) &ev, xournal->x, xournal->y);
		CursorSelectionType selType = selection->getSelectionTypeForPos(ev.x, ev.y, xournal->view->getZoom());
		if (selType) {
			xournal->view->getCursor()->setMouseDown(true);
			xournal->selection->mouseDown(selType, ev.x, ev.y);
			INPUTDBG2("gtk_xournal_button_press_event (selection) return true");
			return true;
		} else {
			xournal->view->clearSelection();
		}
	}

	PageView * pv = gtk_xournal_get_page_view_for_pos_cached(xournal, event->x, event->y);
	if (pv) {
		xournal->currentInputPage = pv;
		pv->translateEvent((GdkEvent*) event, xournal->x, xournal->y);
		INPUTDBG2("gtk_xournal_button_press_event (pv->onButtonPressEvent) return");

		xournal->view->getDocument()->indexOf(pv->getPage());
		return pv->onButtonPressEvent(widget, event);
	}

	INPUTDBG2("gtk_xournal_button_press_event (not handled) return false");
	return false; // not handled
}
Ejemplo n.º 23
0
void
panel_applet_position_menu (GtkMenu   *menu,
			    int       *x,
			    int       *y,
			    gboolean  *push_in,
			    GtkWidget *applet)
{
	GtkAllocation   allocation;
	GtkRequisition  requisition;
	GdkScreen      *screen;
	GtkWidget      *parent;
	int             menu_x = 0;
	int             menu_y = 0;
	int             pointer_x;
	int             pointer_y;

	parent = gtk_widget_get_parent (applet);

	g_return_if_fail (PANEL_IS_WIDGET (parent));

	screen = gtk_widget_get_screen (applet);

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

	gdk_window_get_origin (gtk_widget_get_window (applet), &menu_x, &menu_y);
	gtk_widget_get_pointer (applet, &pointer_x, &pointer_y);

	gtk_widget_get_allocation (applet, &allocation);

	if (!gtk_widget_get_has_window (applet)) {
		menu_x += allocation.x;
		menu_y += allocation.y;
	}

	if (PANEL_WIDGET (parent)->orient == GTK_ORIENTATION_HORIZONTAL) {
		if (gtk_widget_get_direction (GTK_WIDGET (menu)) != GTK_TEXT_DIR_RTL) {
			if (pointer_x < allocation.width &&
			    requisition.width < pointer_x)
				menu_x += MIN (pointer_x,
					       allocation.width - requisition.width);
		} else {
			menu_x += allocation.width - requisition.width;
			if (pointer_x > 0 && pointer_x < allocation.width &&
			    pointer_x < allocation.width - requisition.width) {
				menu_x -= MIN (allocation.width - pointer_x,
					       allocation.width - requisition.width);
			}
		}
		menu_x = MIN (menu_x, gdk_screen_get_width (screen) - requisition.width);

		if (menu_y > gdk_screen_get_height (screen) / 2)
			menu_y -= requisition.height;
		else
			menu_y += allocation.height;
	} else {
		if (pointer_y < allocation.height &&
		    requisition.height < pointer_y)
			menu_y += MIN (pointer_y, allocation.height - requisition.height);
		menu_y = MIN (menu_y, gdk_screen_get_height (screen) - requisition.height);

		if (menu_x > gdk_screen_get_width (screen) / 2)
			menu_x -= requisition.width;
		else
			menu_x += allocation.width;
	}

	*x = menu_x;
	*y = menu_y;
	*push_in = FALSE;
}
Ejemplo n.º 24
0
gboolean gtk_xournal_button_press_event(GtkWidget* widget,
                                        GdkEventButton* event)
{
	/**
	 * true: Core event, false: XInput event
	 */
	gboolean isCore = (event->device == gdk_device_get_core_pointer());

	INPUTDBG("ButtonPress (%s) (x,y)=(%.2f,%.2f), button %d, modifier %x, isCore %i",
	         gdk_device_get_name(event->device), event->x, event->y,
	         event->button, event->state, isCore);

	GtkXournal* xournal = GTK_XOURNAL(widget);
	Settings* settings = xournal->view->getControl()->getSettings();

	if(isCore && settings->isXinputEnabled() && settings->isIgnoreCoreEvents())
	{
		INPUTDBG2("gtk_xournal_button_press_event return false (ignore core)");
		return false;
	}

	XInputUtils::fixXInputCoords((GdkEvent*) event, widget);

	if (event->type != GDK_BUTTON_PRESS)
	{
		INPUTDBG2("gtk_xournal_button_press_event return false (event->type != GDK_BUTTON_PRESS)");
		return false; // this event is not handled here
	}

	if (event->button > 3)   // scroll wheel events
	{
		XInputUtils::handleScrollEvent(event, widget);
		INPUTDBG2("gtk_xournal_button_press_event return true handled scroll event");
		return true;
	}

	gtk_widget_grab_focus(widget);

	// none button release event was sent, send one now
	if (xournal->currentInputPage)
	{
		INPUTDBG2("gtk_xournal_button_press_event (xournal->currentInputPage != NULL)");

		GdkEventButton ev = *event;
		xournal->currentInputPage->translateEvent((GdkEvent*) &ev, xournal->x,
		                                          xournal->y);
		xournal->currentInputPage->onButtonReleaseEvent(widget, &ev);
	}

	ToolHandler* h = xournal->view->getControl()->getToolHandler();

	// Change the tool depending on the key or device
	if(change_tool(settings, event, xournal))
		return true;

	// hand tool don't change the selection, so you can scroll e.g.
	// with your touchscreen without remove the selection
	if (h->getToolType() == TOOL_HAND)
	{
		Cursor* cursor = xournal->view->getCursor();
		cursor->setMouseDown(true);
		xournal->lastMousePositionX = 0;
		xournal->lastMousePositionY = 0;
		xournal->inScrolling = true;
		gtk_widget_get_pointer(widget, &xournal->lastMousePositionX,
		                       &xournal->lastMousePositionY);

		INPUTDBG2("gtk_xournal_button_press_event (h->getToolType() == TOOL_HAND) return true");
		return true;
	}
	else if (xournal->selection)
	{
		EditSelection* selection = xournal->selection;

		PageView* view = selection->getView();
		GdkEventButton ev = *event;
		view->translateEvent((GdkEvent*) &ev, xournal->x, xournal->y);
		CursorSelectionType selType = selection->getSelectionTypeForPos(ev.x, ev.y,
		                                                                xournal->view->getZoom());
		if (selType)
		{

			if(selType == CURSOR_SELECTION_MOVE && event->button == 3)
			{
				selection->copySelection();
			}

			xournal->view->getCursor()->setMouseDown(true);
			xournal->selection->mouseDown(selType, ev.x, ev.y);
			INPUTDBG2("gtk_xournal_button_press_event (selection) return true");
			return true;
		}
		else
		{
			xournal->view->clearSelection();
			if(change_tool(settings, event, xournal))
				return true;
		}
	}

	PageView* pv = gtk_xournal_get_page_view_for_pos_cached(xournal, event->x,
	                                                        event->y);

	current_view = pv;

	if (pv)
	{
		xournal->currentInputPage = pv;
		pv->translateEvent((GdkEvent*) event, xournal->x, xournal->y);
		INPUTDBG2("gtk_xournal_button_press_event (pv->onButtonPressEvent) return");

		xournal->view->getDocument()->indexOf(pv->getPage());
		return pv->onButtonPressEvent(widget, event);
	}

	INPUTDBG2("gtk_xournal_button_press_event (not handled) return false");
	return false; // not handled
}
Ejemplo n.º 25
0
/* List Selection Callback */
static gboolean selection_made_callback(GtkTreeSelection *selection,
	gpointer data)
{
	gchar *entry_name;
	gchar *entry_pass;
	gchar *entry_service;
	gboolean autoconnect;
	int x, y;
	GtkTreeViewColumn *column = NULL;
	GtkTreeIter sel;
	GList *path_list;

	gint sel_count = gtk_tree_selection_count_selected_rows(selection);

	if (sel_count < 1 || sel_count > 1) {
		gtk_entry_set_text(GTK_ENTRY(username), "");
		gtk_entry_set_text(GTK_ENTRY(password), "");

		if (sel_count > 1) {
			gtk_widget_set_sensitive(GTK_WIDGET(mod_button), FALSE);
			gtk_widget_set_sensitive(GTK_WIDGET(del_button), TRUE);
			gtk_combo_box_set_active(GTK_COMBO_BOX(service_type),
				-1);
		} else {
			gtk_widget_set_sensitive(GTK_WIDGET(mod_button), FALSE);
			gtk_widget_set_sensitive(GTK_WIDGET(del_button), FALSE);
			gtk_combo_box_set_active(GTK_COMBO_BOX(service_type),
				-1);
		}

		return FALSE;
	}

	path_list = gtk_tree_selection_get_selected_rows(selection, NULL);

	gtk_tree_model_get_iter(GTK_TREE_MODEL(account_list_store), &sel,
		path_list->data);

	g_list_foreach(path_list, (GFunc) gtk_tree_path_free, NULL);
	g_list_free(path_list);

	selected_row = sel;

	gtk_widget_get_pointer(account_list, &x, &y);
	gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(account_list),
		x, y, NULL, &column, NULL, NULL);

	if (column && !strcmp(gtk_tree_view_column_get_title(column), _("C"))) {
		gboolean autoconnect;

		gtk_tree_model_get(GTK_TREE_MODEL(account_list_store),
			&selected_row, CONNECT, &autoconnect, -1);

		gtk_list_store_set(account_list_store, &selected_row,
			CONNECT, !autoconnect, -1);
	}

	gtk_tree_model_get(GTK_TREE_MODEL(account_list_store), &sel,
		CONNECT, &autoconnect,
		USER_NAME, &entry_name,
		PASSWORD, &entry_pass, SERVICE_TYPE, &entry_service, -1);

	gtk_entry_set_text(GTK_ENTRY(username), entry_name);
	gtk_entry_set_text(GTK_ENTRY(password), entry_pass);
	{
		int i;
		LList *l, *list = get_service_list();
		for (l = list, i = 0; l; l = l_list_next(l), i++) {
			char *name = l->data;
			if (!strcmp(name, entry_service)) {
				gtk_combo_box_set_active(GTK_COMBO_BOX
					(service_type), i);
				break;
			}
		}
		l_list_free(list);

	}
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(connect_at_startup),
		autoconnect);

	gtk_widget_set_sensitive(GTK_WIDGET(mod_button), TRUE);
	gtk_widget_set_sensitive(GTK_WIDGET(del_button), TRUE);

	return FALSE;
}
Ejemplo n.º 26
0
static gboolean
gossip_cell_renderer_expander_activate (GtkCellRenderer      *cell,
                                        GdkEvent             *event,
                                        GtkWidget            *widget,
                                        const gchar          *path_string,
                                        const GdkRectangle   *background_area,
                                        const GdkRectangle   *cell_area,
                                        GtkCellRendererState flags)
{
    GossipCellRendererExpander     *expander;
    GossipCellRendererExpanderPriv *priv;
    GtkTreePath                    *path;
    GtkSettings                    *settings;
    gboolean                        animate = FALSE;
    gboolean                        expanding;
    gboolean                        in_cell;
    int                             mouse_x;
    int                             mouse_y;

    expander = GOSSIP_CELL_RENDERER_EXPANDER (cell);
    priv = GET_PRIV (cell);

    if (!GTK_IS_TREE_VIEW (widget) || !priv->activatable)
        return FALSE;

    path = gtk_tree_path_new_from_string (path_string);

    gtk_widget_get_pointer (widget, &mouse_x, &mouse_y);
    gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW (widget),
                                                       mouse_x, mouse_y,
                                                       &mouse_x, &mouse_y);

    /* check if click is within the cell */
    if (mouse_x - cell_area->x >= 0
        && mouse_x - cell_area->x <= cell_area->width) {
        in_cell = TRUE;
    } else {
        in_cell = FALSE;
    }

    if (! in_cell) {
        return FALSE;
    }

#if 0
    if (gtk_tree_path_get_depth (path) > 1) {
        gtk_tree_path_free (path);
        return TRUE;
    }
#endif
    settings = gtk_widget_get_settings (GTK_WIDGET (widget));
    if (g_object_class_find_property (G_OBJECT_GET_CLASS (settings), "gtk-enable-animations")) {
        g_object_get (settings,
                      "gtk-enable-animations", &animate,
                      NULL);
    }

    if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
        gtk_tree_view_collapse_row (GTK_TREE_VIEW (widget), path);
        expanding = FALSE;
    } else {
        gtk_tree_view_expand_row (GTK_TREE_VIEW (widget), path, FALSE);
        expanding = TRUE;
    }

    if (animate) {
        gossip_cell_renderer_expander_start_animation (expander,
                                                       GTK_TREE_VIEW (widget),
                                                       path,
                                                       expanding,
                                                       background_area);
    }

    gtk_tree_path_free (path);

    return TRUE;
}
Ejemplo n.º 27
0
void *dt_control_expose(void *voidptr)
{
  int width, height, pointerx, pointery;
  if(!darktable.gui->surface) return NULL;
  width  = cairo_image_surface_get_width(darktable.gui->surface);
  height = cairo_image_surface_get_height(darktable.gui->surface);
  GtkWidget *widget = dt_ui_center(darktable.gui->ui);
  gtk_widget_get_pointer(widget, &pointerx, &pointery);

  //create a gtk-independent surface to draw on
  cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t *cr = cairo_create(cst);

  // TODO: control_expose: only redraw the part not overlapped by temporary control panel show!
  //
  float tb = 8;//fmaxf(10, width/100.0);
  darktable.control->tabborder = tb;
  darktable.control->width = width;
  darktable.control->height = height;

  GtkStyle *style = gtk_widget_get_style(widget);
  cairo_set_source_rgb (cr,
                        style->bg[GTK_STATE_NORMAL].red/65535.0,
                        style->bg[GTK_STATE_NORMAL].green/65535.0,
                        style->bg[GTK_STATE_NORMAL].blue/65535.0
                       );

  cairo_set_line_width(cr, tb);
  cairo_rectangle(cr, tb/2., tb/2., width-tb, height-tb);
  cairo_stroke(cr);
  cairo_set_line_width(cr, 1.5);
  cairo_set_source_rgb (cr, .1, .1, .1);
  cairo_rectangle(cr, tb, tb, width-2*tb, height-2*tb);
  cairo_stroke(cr);

  cairo_save(cr);
  cairo_translate(cr, tb, tb);
  cairo_rectangle(cr, 0, 0, width - 2*tb, height - 2*tb);
  cairo_clip(cr);
  cairo_new_path(cr);
  // draw view
  dt_view_manager_expose(darktable.view_manager, cr, width-2*tb, height-2*tb,
                         pointerx-tb, pointery-tb);
  cairo_restore(cr);

  // draw status bar, if any
  if(darktable.control->progress < 100.0)
  {
    tb = fmaxf(20, width/40.0);
    char num[10];
    cairo_rectangle(cr, width*0.4, height*0.85,
                    width*0.2*darktable.control->progress/100.0f, tb);
    cairo_fill(cr);
    cairo_set_source_rgb(cr, 0., 0., 0.);
    cairo_rectangle(cr, width*0.4, height*0.85, width*0.2, tb);
    cairo_stroke(cr);
    cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
    cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, tb/3);
    cairo_move_to (cr, width/2.0-10, height*0.85+2.*tb/3.);
    snprintf(num, sizeof(num), "%d%%", (int)darktable.control->progress);
    cairo_show_text (cr, num);
  }
  // draw log message, if any
  dt_pthread_mutex_lock(&darktable.control->log_mutex);
  if(darktable.control->log_ack != darktable.control->log_pos)
  {
    cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_BOLD);
    const float fontsize = 14;
    cairo_set_font_size (cr, fontsize);
    cairo_text_extents_t ext;
    cairo_text_extents (cr,
                        darktable.control->log_message[darktable.control->log_ack], &ext);
    const float pad = 20.0f, xc = width/2.0;
    const float yc = height*0.85+10, wd = pad + ext.width*.5f;
    float rad = 14;
    cairo_set_line_width(cr, 1.);
    cairo_move_to( cr, xc-wd,yc+rad);
    for(int k=0; k<5; k++)
    {
      cairo_arc (cr, xc-wd, yc, rad, M_PI/2.0, 3.0/2.0*M_PI);
      cairo_line_to (cr, xc+wd, yc-rad);
      cairo_arc (cr, xc+wd, yc, rad, 3.0*M_PI/2.0, M_PI/2.0);
      cairo_line_to (cr, xc-wd, yc+rad);
      if(k == 0)
      {
        cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
        cairo_fill_preserve (cr);
      }
      cairo_set_source_rgba(cr, 0., 0., 0., 1.0/(1+k));
      cairo_stroke (cr);
      rad += .5f;
    }
    cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
    cairo_move_to (cr, xc-wd+.5f*pad, yc + 1./3.*fontsize);
    cairo_show_text (cr,
                     darktable.control->log_message[darktable.control->log_ack]);
  }
  // draw busy indicator
  if(darktable.control->log_busy > 0)
  {
    cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_BOLD);
    const float fontsize = 14;
    cairo_set_font_size (cr, fontsize);
    cairo_text_extents_t ext;
    cairo_text_extents (cr, _("working.."), &ext);
    const float xc = width/2.0, yc = height*0.85-30, wd = ext.width*.5f;
    cairo_move_to (cr, xc-wd, yc + 1./3.*fontsize);
    cairo_text_path (cr, _("working.."));
    cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
    cairo_fill_preserve(cr);
    cairo_set_line_width(cr, 0.7);
    cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
    cairo_stroke(cr);
  }
  dt_pthread_mutex_unlock(&darktable.control->log_mutex);

  cairo_destroy(cr);

  cairo_t *cr_pixmap = cairo_create(darktable.gui->surface);
  cairo_set_source_surface (cr_pixmap, cst, 0, 0);
  cairo_paint(cr_pixmap);
  cairo_destroy(cr_pixmap);

  cairo_surface_destroy(cst);
  return NULL;
}
Ejemplo n.º 28
0
/**
 * gimp_display_shell_scale_get_zoom_focus:
 * @shell:
 * @new_scale:
 * @x:
 * @y:
 *
 * Calculates the viewport coordinate to focus on when zooming
 * independently for each axis.
 **/
static void
gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell,
                                         gdouble           new_scale,
                                         gdouble           current_scale,
                                         gdouble          *x,
                                         gdouble          *y,
                                         GimpZoomFocus     zoom_focus)
{
  GtkWidget *window = GTK_WIDGET (gimp_display_shell_get_window (shell));
  GdkEvent  *event;
  gint       image_center_x;
  gint       image_center_y;
  gint       other_x;
  gint       other_y;

  /* Calculate stops-to-fit focus point */
  gimp_display_shell_scale_get_image_center_viewport (shell,
                                                      &image_center_x,
                                                      &image_center_y);

  /* Calculate other focus point, default is the canvas center */
  other_x = shell->disp_width  / 2;
  other_y = shell->disp_height / 2;

  /*  Center on the mouse position instead of the display center if
   *  one of the following conditions are fulfilled and pointer is
   *  within the canvas:
   *
   *   (1) there's no current event (the action was triggered by an
   *       input controller)
   *   (2) the event originates from the canvas (a scroll event)
   *   (3) the event originates from the window (a key press event)
   *
   *  Basically the only situation where we don't want to center on
   *  mouse position is if the action is being called from a menu.
   */
  event = gtk_get_current_event ();

  if (! event ||
      gtk_get_event_widget (event) == shell->canvas ||
      gtk_get_event_widget (event) == window)
    {
      GdkPoint *point = g_queue_pop_head (shell->zoom_focus_pointer_queue);
      gint      canvas_pointer_x;
      gint      canvas_pointer_y;

      if (point)
        {
          canvas_pointer_x = point->x;
          canvas_pointer_y = point->y;

          g_slice_free (GdkPoint, point);
        }
      else
        {
          gtk_widget_get_pointer (shell->canvas,
                                  &canvas_pointer_x,
                                  &canvas_pointer_y);
        }

      if (canvas_pointer_x >= 0 &&
          canvas_pointer_y >= 0 &&
          canvas_pointer_x <  shell->disp_width &&
          canvas_pointer_y <  shell->disp_height)
        {
          other_x = canvas_pointer_x;
          other_y = canvas_pointer_y;
        }
    }

  /* Decide which one to use for each axis */
  if (zoom_focus == GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS)
    {
      if (gimp_display_shell_scale_viewport_coord_almost_centered (shell,
                                                                   image_center_x,
                                                                   image_center_y,
                                                                   NULL,
                                                                   NULL))
        {
          zoom_focus = GIMP_ZOOM_FOCUS_IMAGE_CENTER;
        }
      else
        {
          zoom_focus = GIMP_ZOOM_FOCUS_BEST_GUESS;
        }
    }

  switch (zoom_focus)
    {
    case GIMP_ZOOM_FOCUS_POINTER:
      *x = other_x;
      *y = other_y;
      break;

    case GIMP_ZOOM_FOCUS_IMAGE_CENTER:
      *x = image_center_x;
      *y = image_center_y;
      break;

    case GIMP_ZOOM_FOCUS_BEST_GUESS:
    default:
      {
        gboolean within_horizontally, within_vertically;
        gboolean stops_horizontally, stops_vertically;

        gimp_display_shell_scale_image_is_within_viewport (shell,
                                                           &within_horizontally,
                                                           &within_vertically);

        gimp_display_shell_scale_image_stops_to_fit (shell,
                                                     new_scale,
                                                     current_scale,
                                                     &stops_horizontally,
                                                     &stops_vertically);

        *x = within_horizontally && ! stops_horizontally ? image_center_x : other_x;
        *y = within_vertically   && ! stops_vertically   ? image_center_y : other_y;
      }
      break;
    }
}
Ejemplo n.º 29
0
gboolean ly_3lrc_widget_on_seek_cb(GtkWidget * widget, GdkEventButton *event, gpointer data)
{
	LyMdhMetadata *md=ly_pqm_get_current_md();
	if(!md)
		return FALSE;
	
	int length=ly_lrc_get_length();
	if(length<=0)
		return FALSE;
		
	//GdkCursor *cursor;
	int index=0;
	if (event->button == 1)
	{
		switch(event->type)
		{
			case GDK_BUTTON_PRESS:
				flag_seek=TRUE;
				ly_3lrc_widget_pos_old[X] = event->x;
				ly_3lrc_widget_pos_old[Y] = event->y;
				index_mark=ly_lrc_get_index();
				break;
			case GDK_BUTTON_RELEASE:
				if(flag_seek==TRUE&&flag_seeked==TRUE)
				{
					LyLrcLyric **array=ly_lrc_get_array();
					index=ly_lrc_get_index();
					ly_aud_set_position(array[index]->time/(double)ly_mdh_time_str2int(md->duration));
				}
				flag_seek = FALSE;
				flag_seeked=FALSE;
				ly_lrc_set_update_state(TRUE);

				break;
			default:
				break;
		}
	}
	if(flag_seek)
	{
		int pos[2]={0,0};
		gtk_widget_get_pointer(widget, &pos[X], &pos[Y]);
		ly_3lrc_widget_pos_delta[Y]=pos[Y]-ly_3lrc_widget_pos_old[Y];
		if(pos[Y]-ly_3lrc_widget_pos_old[Y])
			flag_seeked=TRUE;
			ly_lrc_set_update_state(FALSE);
	}
	if(flag_seek&&flag_seeked)
	{
		gint lrc_gap=20;
		if(!ly_reg_get("lrc_gap","%d",&lrc_gap))
		{
			ly_reg_set("lrc_gap","%d",lrc_gap);
		}
		index=index_mark;
		if(ly_3lrc_widget_pos_delta[Y]>=0)
		{
			index-=(int)(abs(ly_3lrc_widget_pos_delta[Y])/lrc_gap);
			if(index<0)
			{
				index=0;
			}
		}
		else
		{
			index+=(int)(abs(ly_3lrc_widget_pos_delta[Y])/lrc_gap);
			if(index>=length)
			{
				index=length-1;
			}
		}
		ly_lrc_set_index(index);
	}
	return FALSE;
}
Ejemplo n.º 30
0
gboolean
pointer_update (GtkWidget* window)
{
	gint       pointer_rel_x;
	gint       pointer_rel_y;
	gint       pointer_abs_x;
	gint       pointer_abs_y;
	gint       win_x;
	gint       win_y;
	gint       width;
	gint       height;
	gboolean   old_mouse_over;
	gfloat     old_distance = 0;

	if (!GTK_IS_WINDOW (window))
		return FALSE;

	old_mouse_over = g_mouse_over;

	if (gtk_widget_get_realized (window))
	{
		gint distance_x = 0;
		gint distance_y = 0;

		gtk_widget_get_pointer (window, &pointer_rel_x, &pointer_rel_y);
		gtk_window_get_position (GTK_WINDOW (window), &win_x, &win_y);
		pointer_abs_x = win_x + pointer_rel_x;
		pointer_abs_y = win_y + pointer_rel_y;
		gtk_window_get_size (GTK_WINDOW (window), &width, &height);
		if (pointer_abs_x >= win_x &&
		    pointer_abs_x <= win_x + width &&
		    pointer_abs_y >= win_y &&
		    pointer_abs_y <= win_y + height)
			g_mouse_over = TRUE;
		else
			g_mouse_over = FALSE;

		if (pointer_abs_x >= win_x &&
		    pointer_abs_x <= win_x + width)
			distance_x = 0;
		else
		{
			if (pointer_abs_x < win_x)
				distance_x = abs (pointer_rel_x);

			if (pointer_abs_x > win_x + width)
				distance_x = abs (pointer_rel_x - width);
		}

		if (pointer_abs_y >= win_y &&
		    pointer_abs_y <= win_y + height)
			distance_y = 0;
		else
		{
			if (pointer_abs_y < win_y)
				distance_y = abs (pointer_rel_y);

			if (pointer_abs_y > win_y + height)
				distance_y = abs (pointer_rel_y - height);
		}

		old_distance = g_distance;
		g_distance = sqrt (distance_x * distance_x +
				       distance_y * distance_y) /
				       (double) 40;
	}

	if (old_mouse_over != g_mouse_over)
		set_bg_blur (window, !g_mouse_over);

	if (old_distance != g_distance)
		gtk_widget_queue_draw (window);

	return TRUE;
}