Esempio n. 1
0
void tooltip_window_create( GtkWidget* dock_window )
{
    eric_window* w = eric_window_create( 10, 10, "" );
    gtk_window_move( GTK_WINDOW( w->window ), 0, 1040 );
    gtk_window_set_type_hint( GTK_WINDOW( w->window ), GDK_WINDOW_TYPE_HINT_DIALOG );
    gtk_window_set_decorated( GTK_WINDOW( w->window ), FALSE );
    gtk_window_set_skip_pager_hint( GTK_WINDOW( w->window ), TRUE );
    gtk_window_set_transient_for( GTK_WINDOW( w->window ), GTK_WINDOW( dock_window ) );
    gtk_window_set_keep_above( GTK_WINDOW( w->window ), TRUE );
    
    gtk_widget_add_events( w->window, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK );
    g_signal_connect( G_OBJECT( w->window ), "focus-out-event", G_CALLBACK(tooltip_window_lose_focus), NULL );

    //Add Dock icon box
    pager_items_box = gtk_button_box_new( GTK_ORIENTATION_VERTICAL );
    gtk_button_box_set_layout( GTK_BUTTON_BOX( pager_items_box ), GTK_BUTTONBOX_CENTER );
    //gtk_button_box_set_child_non_homogeneous( GTK_BUTTON_BOX( dock_icons_box ), TRUE );
    gtk_container_add( GTK_CONTAINER( w->window ), pager_items_box );
    gtk_widget_show( pager_items_box );

    //Pango stuff
    char fontdesc[80];
    pango_context = gtk_widget_create_pango_context( w->window );
    sprintf( fontdesc, "Source Sans Pro Regular %ipx", (int)(SCALE_VALUE( 16 )) );
    PangoFontDescription* font = pango_font_description_from_string( fontdesc );
    pango_context_set_font_description( pango_context, font );

    tooltip_window = w;
}
Esempio n. 2
0
decor_frame_t *
decor_frame_new (const gchar *type)
{
    GdkScreen     *gdkscreen = gdk_screen_get_default ();
    GdkVisual     *visual;
    decor_frame_t *frame = malloc (sizeof (decor_frame_t));

    if (!frame)
    {
        g_critical ("Couldn't allocate frame!");
        return NULL;
    }

    frame->type = strdup (type);
    frame->refcount = 0;
    frame->titlebar_height = 17;
    frame->max_titlebar_height = 17;
    frame->border_shadow_active = NULL;
    frame->border_shadow_inactive = NULL;
    frame->border_no_shadow = NULL;
    frame->max_border_no_shadow = NULL;
    frame->max_border_shadow_active = NULL;
    frame->max_border_shadow_inactive = NULL;
    frame->titlebar_font = NULL;

    frame->style_window_rgba = gtk_window_new (GTK_WINDOW_POPUP);

    visual = gdk_screen_get_rgba_visual (gdkscreen);
    if (visual)
        gtk_widget_set_visual (frame->style_window_rgba, visual);

    gtk_widget_realize (frame->style_window_rgba);

    gtk_widget_set_size_request (frame->style_window_rgba, 0, 0);
    gtk_window_move (GTK_WINDOW (frame->style_window_rgba), -100, -100);

    frame->pango_context = gtk_widget_create_pango_context (frame->style_window_rgba);

    g_signal_connect_data (frame->style_window_rgba, "style-updated",
                           G_CALLBACK (style_updated),
                           (gpointer) frame->pango_context, 0, 0);

    frame->style_window_rgb = gtk_window_new (GTK_WINDOW_POPUP);

    visual = gdk_screen_get_system_visual (gdkscreen);
    if (visual)
        gtk_widget_set_visual (frame->style_window_rgb, visual);

    gtk_widget_realize (frame->style_window_rgb);

    gtk_widget_set_size_request (frame->style_window_rgb, 0, 0);
    gtk_window_move (GTK_WINDOW (frame->style_window_rgb), -100, -100);

    g_signal_connect_data (frame->style_window_rgb, "style-updated",
                           G_CALLBACK (style_updated),
                           (gpointer) frame->pango_context, 0, 0);

    return frame;
}
Esempio n. 3
0
TGlyphCache *glyph_cache_new(GtkWidget *widget,
                             PangoFontDescription *font_desc)
{
	TGlyphCache *cache;

	cache = g_new(TGlyphCache, 1);
	memset(cache, 0, sizeof(*cache));

	cache->context = gtk_widget_create_pango_context(widget);
	cache->lang = pango_context_get_language(cache->context);

	cache->display = gtk_widget_get_display(widget);
	g_object_ref (cache->display);
	cache->screen = gtk_widget_get_screen(widget);
	g_object_ref (cache->screen);

	if (font_desc)
		glyph_cache_set_font(cache, font_desc);

	return cache;
}
Esempio n. 4
0
static void
gimp_tag_popup_constructed (GObject *object)
{
  GimpTagPopup        *popup = GIMP_TAG_POPUP (object);
  GimpTaggedContainer *container;
  GtkWidget           *entry;
  GtkAllocation        entry_allocation;
  GtkStyle            *frame_style;
  gint                 x;
  gint                 y;
  gint                 width;
  gint                 height;
  gint                 popup_height;
  GHashTable          *tag_hash;
  GList               *tag_list;
  GList               *tag_iterator;
  gint                 i;
  gint                 max_height;
  gint                 screen_height;
  gchar              **current_tags;
  gint                 current_count;
  GdkRectangle         popup_rects[2]; /* variants of popup placement */
  GdkRectangle         popup_rect; /* best popup rect in screen coordinates */

  if (G_OBJECT_CLASS (parent_class)->constructed)
    G_OBJECT_CLASS (parent_class)->constructed (object);

  entry = GTK_WIDGET (popup->combo_entry);

  gtk_window_set_screen (GTK_WINDOW (popup), gtk_widget_get_screen (entry));

  popup->context = gtk_widget_create_pango_context (GTK_WIDGET (popup));
  popup->layout  = pango_layout_new (popup->context);

  gtk_widget_get_allocation (entry, &entry_allocation);

  gtk_widget_style_get (GTK_WIDGET (popup),
                        "scroll-arrow-vlength", &popup->scroll_arrow_height,
                        NULL);

  pango_layout_set_attributes (popup->layout,
                               popup->combo_entry->normal_item_attr);

  current_tags  = gimp_tag_entry_parse_tags (GIMP_TAG_ENTRY (popup->combo_entry));
  current_count = g_strv_length (current_tags);

  container = GIMP_TAG_ENTRY (popup->combo_entry)->container;

  tag_hash = container->tag_ref_counts;
  tag_list = g_hash_table_get_keys (tag_hash);
  tag_list = g_list_sort (tag_list, gimp_tag_compare_func);

  popup->tag_count = g_list_length (tag_list);
  popup->tag_data  = g_new0 (PopupTagData, popup->tag_count);

  for (i = 0, tag_iterator = tag_list;
       i < popup->tag_count;
       i++, tag_iterator = g_list_next (tag_iterator))
    {
      PopupTagData *tag_data = &popup->tag_data[i];
      gint          j;

      tag_data->tag   = tag_iterator->data;
      tag_data->state = GTK_STATE_NORMAL;

      for (j = 0; j < current_count; j++)
        {
          if (! gimp_tag_compare_with_string (tag_data->tag, current_tags[j]))
            {
              tag_data->state = GTK_STATE_SELECTED;
              break;
            }
        }
    }

  g_list_free (tag_list);
  g_strfreev (current_tags);

  if (GIMP_TAG_ENTRY (popup->combo_entry)->mode == GIMP_TAG_ENTRY_MODE_QUERY)
    {
      for (i = 0; i < popup->tag_count; i++)
        {
          if (popup->tag_data[i].state != GTK_STATE_SELECTED)
            {
              popup->tag_data[i].state = GTK_STATE_INSENSITIVE;
            }
        }

      gimp_container_foreach (GIMP_CONTAINER (container),
                              (GFunc) gimp_tag_popup_check_can_toggle,
                              popup);
    }

  frame_style = gtk_widget_get_style (popup->frame);

  width  = (entry_allocation.width -
            2 * frame_style->xthickness);
  height = (gimp_tag_popup_layout_tags (popup, width) +
            2 * frame_style->ythickness);

  gdk_window_get_origin (gtk_widget_get_window (entry), &x, &y);

  max_height = entry_allocation.height * 10;

  screen_height = gdk_screen_get_height (gtk_widget_get_screen (entry));

  popup_height = MIN (height, max_height);

  popup_rects[0].x      = x;
  popup_rects[0].y      = 0;
  popup_rects[0].width  = entry_allocation.width;
  popup_rects[0].height = y + entry_allocation.height;

  popup_rects[1].x      = x;
  popup_rects[1].y      = y;
  popup_rects[1].width  = popup_rects[0].width;
  popup_rects[1].height = screen_height - popup_rects[0].height;

  if (popup_rects[0].height >= popup_height)
    {
      popup_rect = popup_rects[0];
      popup_rect.y += popup_rects[0].height - popup_height;
      popup_rect.height = popup_height;
    }
  else if (popup_rects[1].height >= popup_height)
    {
      popup_rect = popup_rects[1];
      popup_rect.height = popup_height;
    }
  else
    {
      if (popup_rects[0].height >= popup_rects[1].height)
        {
          popup_rect = popup_rects[0];
          popup_rect.y += popup->scroll_arrow_height + frame_style->ythickness;
        }
      else
        {
          popup_rect = popup_rects[1];
          popup_rect.y -= popup->scroll_arrow_height + frame_style->ythickness;
        }

      popup_height = popup_rect.height;
    }

  if (popup_height < height)
    {
      popup->arrows_visible    = TRUE;
      popup->upper_arrow_state = GTK_STATE_INSENSITIVE;

      gtk_alignment_set_padding (GTK_ALIGNMENT (popup->alignment),
                                 popup->scroll_arrow_height + 2,
                                 popup->scroll_arrow_height + 2, 0, 0);

      popup_height -= 2 * popup->scroll_arrow_height + 4;

      popup->scroll_height = height - popup_rect.height;
      popup->scroll_y      = 0;
      popup->scroll_step   = 0;
    }

  gtk_widget_set_size_request (popup->tag_area, width, popup_height);

  gtk_window_move (GTK_WINDOW (popup), popup_rect.x, popup_rect.y);
  gtk_window_resize (GTK_WINDOW (popup), popup_rect.width, popup_rect.height);
}
Esempio n. 5
0
static VALUE
rg_create_pango_context(VALUE self)
{
    return GOBJ2RVALU(gtk_widget_create_pango_context(_SELF(self)));
}
Esempio n. 6
0
static void
rotated_text_draw (GtkDrawingArea *da,
                   cairo_t        *cr,
                   int             width,
                   int             height,
                   gpointer        data)
{
#define RADIUS 150
#define N_WORDS 5
#define FONT "Serif 18"

  PangoContext *context;
  PangoLayout *layout;
  PangoFontDescription *desc;

  cairo_pattern_t *pattern;

  PangoAttrList *attrs;

  double device_radius;
  int i;

  /* Create a cairo context and set up a transformation matrix so that the user
   * space coordinates for the centered square where we draw are [-RADIUS, RADIUS],
   * [-RADIUS, RADIUS].
   * We first center, then change the scale. */
  device_radius = MIN (width, height) / 2.;
  cairo_translate (cr,
                   device_radius + (width - 2 * device_radius) / 2,
                   device_radius + (height - 2 * device_radius) / 2);
  cairo_scale (cr, device_radius / RADIUS, device_radius / RADIUS);

  /* Create and a subtle gradient source and use it. */
  pattern = cairo_pattern_create_linear (-RADIUS, -RADIUS, RADIUS, RADIUS);
  cairo_pattern_add_color_stop_rgb (pattern, 0., .5, .0, .0);
  cairo_pattern_add_color_stop_rgb (pattern, 1., .0, .0, .5);
  cairo_set_source (cr, pattern);

  /* Create a PangoContext and set up our shape renderer */
  context = gtk_widget_create_pango_context (GTK_WIDGET (da));
  pango_cairo_context_set_shape_renderer (context,
                                          fancy_shape_renderer,
                                          NULL, NULL);

  /* Create a PangoLayout, set the text, font, and attributes */
  layout = pango_layout_new (context);
  pango_layout_set_text (layout, text, -1);
  desc = pango_font_description_from_string (FONT);
  pango_layout_set_font_description (layout, desc);

  attrs = create_fancy_attr_list_for_layout (layout);
  pango_layout_set_attributes (layout, attrs);
  pango_attr_list_unref (attrs);

  /* Draw the layout N_WORDS times in a circle */
  for (i = 0; i < N_WORDS; i++)
    {
      int width, height;

      /* Inform Pango to re-layout the text with the new transformation matrix */
      pango_cairo_update_layout (cr, layout);

      pango_layout_get_pixel_size (layout, &width, &height);
      cairo_move_to (cr, - width / 2, - RADIUS * .9);
      pango_cairo_show_layout (cr, layout);

      /* Rotate for the next turn */
      cairo_rotate (cr, G_PI*2 / N_WORDS);
    }

  /* free the objects we created */
  pango_font_description_free (desc);
  g_object_unref (layout);
  g_object_unref (context);
  cairo_pattern_destroy (pattern);
}
Esempio n. 7
0
void
comments_dialog (PsppireDataWindow *de)
{
    GtkTextIter iter;
    gint response ;
    struct comment_dialog cd;

    GtkBuilder *xml = builder_new ("psppire.ui");

    GtkWidget *dialog = get_widget_assert (xml, "comments-dialog");
    GtkWidget *textview = get_widget_assert (xml, "comments-textview1");
    GtkWidget *label = get_widget_assert (xml, "column-number-label");
    GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));

    PsppireVarStore *vs = NULL;

    g_object_get (de->data_editor, "var-store", &vs, NULL);

    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));

    {
        PangoContext * context ;
        PangoLayout *  layout ;
        PangoRectangle rect;

        /* Since we're going to truncate lines to 80 chars,
           we need a monospaced font otherwise it'll look silly */
        PangoFontDescription *font_desc =
            pango_font_description_from_string ("monospace");

        gtk_widget_modify_font (textview, font_desc);


        /* and let's just make sure that a complete line fits into the
           widget's width */
        context = gtk_widget_create_pango_context (textview);
        layout = pango_layout_new (context);

        pango_layout_set_text (layout, "M", 1);

        pango_layout_set_font_description (layout, font_desc);

        pango_layout_get_extents (layout, NULL, &rect);

        g_object_set (textview, "width-request",
                      PANGO_PIXELS (rect.width) * DOC_LINE_LENGTH + 20, NULL);

        g_object_unref (G_OBJECT (layout));
        g_object_unref (G_OBJECT (context));

        pango_font_description_free (font_desc);
    }

    cd.xml = xml;
    g_object_get (vs, "dictionary", &cd.dict, NULL);

    g_signal_connect (buffer, "mark-set",
                      G_CALLBACK (set_column_number), label);

    g_signal_connect_after (buffer, "insert-text",
                            G_CALLBACK (wrap_line), NULL);

    gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
    gtk_text_buffer_place_cursor (buffer, &iter);


    g_signal_connect (dialog, "refresh", G_CALLBACK (refresh),  &cd);


    response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));

    switch (response)
    {
    case GTK_RESPONSE_OK:
        g_free (execute_syntax_string (de, generate_syntax (&cd)));
        break;
    case PSPPIRE_RESPONSE_PASTE:
        g_free (paste_syntax_to_window (generate_syntax (&cd)));
        break;
    default:
        break;
    }


    g_object_unref (xml);
}