Exemplo n.º 1
0
double Scrollbar::getWheelDelta(GdkScrollDirection direction) {
	double delta;
	GtkRange * range = GTK_RANGE(this->scrollbar);

	if (GTK_IS_SCROLLBAR(range)) {
		delta = pow(gtk_adjustment_get_page_size(this->adj), 2.0 / 3.0);
	} else {
		delta = gtk_adjustment_get_step_increment(this->adj) * 2;
	}

	if (direction == GDK_SCROLL_UP || direction == GDK_SCROLL_LEFT) {
		delta = -delta;
	}

	if (gtk_range_get_inverted(range)) {
		delta = -delta;
	}

	return delta;
}
Exemplo n.º 2
0
static gboolean
realize_hook(GSignalInvocationHint*, unsigned, const GValue* param_values, void*)
{
    void* p = g_value_peek_pointer(param_values);
    if (GTK_IS_SCROLLBAR(p))
    {
        GtkWindow* toplevel = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(p)));
        GtkWindow* transient_parent = gtk_window_get_transient_for(toplevel);
        if (transient_parent && gtk_window_has_group(toplevel))
        {
            GtkWindowGroup* group = gtk_window_get_group(toplevel);
            GtkWindowGroup* group_parent = gtk_window_get_group(transient_parent);
            if (group != group_parent)
            {
                gtk_window_group_add_window(group_parent, toplevel);
                gtk_grab_add(GTK_WIDGET(toplevel));
            }
        }
    }
    return true;
}
static void
moblin_netbook_draw_box (GtkStyle     *style,
                         GdkWindow    *window,
                         GtkStateType  state_type,
                         GtkShadowType shadow_type,
                         GdkRectangle *area,
                         GtkWidget    *widget,
                         const gchar  *detail,
                         gint          x,
                         gint          y,
                         gint          width,
                         gint          height)
{
  cairo_t *cr;
  MoblinNetbookStyle *mb_style = MOBLIN_NETBOOK_STYLE (style);
  gint radius = mb_style->radius;

  DEBUG;

  if (DETAIL ("paned") || DETAIL ("buttondefault"))
    return;


  /* we want hover and focused widgets to look the same */
  if (widget && GTK_WIDGET_HAS_FOCUS (widget))
    state_type = GTK_STATE_PRELIGHT;


  /* scrollbar troughs are a plain rectangle */
  if (widget && GTK_IS_SCROLLBAR (widget) && DETAIL ("trough"))
    {
      cr = moblin_netbook_cairo_create (window, area);

      cairo_rectangle (cr, x, y, width, height);
      gdk_cairo_set_source_color (cr, &style->base[state_type]);
      cairo_fill (cr);

      cairo_destroy (cr);

      return;
    }

  SANITIZE_SIZE;

  /*** treeview headers ***/
  if (widget && GTK_IS_TREE_VIEW (widget->parent))
    {
      cr = moblin_netbook_cairo_create (window, area);

      cairo_rectangle (cr, x, y, width, height);
      gdk_cairo_set_source_color (cr, &style->bg[state_type]);
      cairo_fill (cr);
      cairo_destroy (cr);

      gtk_paint_vline (style, window, state_type, area, widget, detail,
                       y + 5, y + height - 5, x + width - 1);
      return;
    }

  /*** spin buttons ***/
  if (DETAIL ("spinbutton_down") || DETAIL ("spinbutton_up"))
    return;

  if (DETAIL ("spinbutton"))
    {
      /* FIXME: for RTL */
      width += 10;
      x -= 10;

      /* always draw button as shadow out to match the entry */
      shadow_type = GTK_SHADOW_OUT;

      /* draw the buttons with the same state type as the entry */
      state_type = widget->state;
    }

  /*** combo boxes ***/
  if (DETAIL ("button") && widget && GTK_IS_COMBO_BOX_ENTRY (widget->parent))
    {
      GtkWidget *entry;

      entry = g_object_get_data (G_OBJECT (widget->parent),
                                 "moblin-netbook-combo-entry");
      g_object_set_data (G_OBJECT (widget->parent),
                         "moblin-netbook-combo-button", widget);

      /* always draw combo box entry buttons as shadow out to match the entry */
      shadow_type = GTK_SHADOW_OUT;

      if (GTK_IS_ENTRY (entry))
        {
          gtk_widget_queue_draw (entry);
        }

      /* FIXME: RTL */
      width += 10;
      x -= 10;
    }

  if (widget
      && (DETAIL ("trough")
          || DETAIL ("trough-fill-level")
          || DETAIL ("trough-fill-level-full"))
      && GTK_IS_SCALE (widget))
    {
      if (mb_style->shadow)
        {
          width--;
          height--;
        }
      if (width > height)
        {
          y = y + (height / 2.0 - 2);
          height = 4;
        }
      else
        {
          x = x + (width / 2.0 - 2);
          width = 4;
        }
    }


  /* scrollbar buttons */
  if (DETAIL ("hscrollbar") || DETAIL ("vscrollbar"))
    {
      x += 2;
      y += 2;
      width -= 4;
      height -= 4;
    }

  /* scrollbar slider */
  if (DETAIL ("slider"))
    {
      if (widget && GTK_IS_HSCROLLBAR (widget))
        {
          y += 2;
          height -= 4;
        }
      else
        {
          x += 2;
          width -= 4;
        }
    }

  cr = moblin_netbook_cairo_create (window, area);

  cairo_set_line_width (cr, LINE_WIDTH);


  /* special "fill" indicator */
  if (DETAIL ("trough-fill-level-full")
      || DETAIL ("trough-fill-level"))
    {
      gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_SELECTED]);

      if (width > height)
        cairo_rectangle (cr, x, y + 1, width, height - 2);
      else
        cairo_rectangle (cr, x + 1, y, width - 2, height);

      cairo_fill (cr);
      cairo_destroy (cr);
      return;
    }

  if (mb_style->shadow)
    {
      if (shadow_type == GTK_SHADOW_OUT)
        {
          /* outer shadow */
          moblin_netbook_rounded_rectangle (cr, x, y, width, height,
                                            radius + 1);
          cairo_set_source_rgba (cr, 0, 0, 0, mb_style->shadow);
          cairo_fill (cr);

          /* reduce size for outer shadow */
          height--;
          width--;
        }
      else if (shadow_type == GTK_SHADOW_IN)
        {
          x++;
          y++;
          width--;
          height--;
        }
    }


  /* fill */
  moblin_netbook_rounded_rectangle (cr, x, y, width, height, radius);

  if (DETAIL ("light-switch-trough"))
    {
      cairo_pattern_t *crp;

      crp = cairo_pattern_create_linear (x, y, x, height);

      /* FIXME: these colours really should not be defined here */

      if (state_type == GTK_STATE_SELECTED)
        {
          cairo_pattern_add_color_stop_rgb (crp, 0, 0.365, 0.820, 0.953);
          cairo_pattern_add_color_stop_rgb (crp, 1, 0.627, 0.894, 0.973);
        }
      else
        {
          cairo_pattern_add_color_stop_rgb (crp, 0, 0.937, 0.941, 0.929);
          cairo_pattern_add_color_stop_rgb (crp, 1, 1.0, 1.0, 1.0);
        }

      cairo_set_source (cr, crp);
    }
  else
    gdk_cairo_set_source_color (cr, &style->bg[state_type]);

  cairo_fill (cr);

  /* extra hilight for "button" widgets, also used as focus rectangle since
   * state_type is set to prelight for focused widgets (see above) */
  if (state_type == GTK_STATE_PRELIGHT && DETAIL ("button")
      && !(widget && GTK_IS_COMBO_BOX_ENTRY (widget->parent)))
    {
      cairo_set_line_width (cr, 2.0);
      moblin_netbook_rounded_rectangle (cr, x + 2, y + 2, width - 4,
                                        height - 4, radius - 1);
      gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_SELECTED]);
      cairo_stroke (cr);
      cairo_set_line_width (cr, 1.0);
    }

  if (shadow_type != GTK_SHADOW_NONE)
    {
      /* border */
      moblin_netbook_rounded_rectangle (cr, x + 0.5, y + 0.5,
                                        width - 1, height - 1, radius);
      moblin_netbook_set_border_color (cr, style, state_type);
      cairo_stroke (cr);
    }

  /* add a grip to handles */
  if (DETAIL ("light-switch-handle") || DETAIL ("hscale"))
    {
      gdk_cairo_set_source_color (cr, &style->mid[state_type]);
      moblin_netbook_draw_grip (cr, FALSE, x, y, width, height);
    }
  else if (DETAIL ("vscale"))
    {
      gdk_cairo_set_source_color (cr, &style->mid[state_type]);
      moblin_netbook_draw_grip (cr, TRUE, x, y, width, height);
    }
  cairo_destroy (cr);

}