⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptk-text-renderer.c

📁 台湾人开发的Linux下的文件管理器
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ptk-text-renderer.c* Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>** This library is free software; you can redistribute it and/or* modify it under the terms of the GNU Library General Public* License as published by the Free Software Foundation; either* version 2 of the License, or (at your option) any later version.** This library is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU* Library General Public License for more details.** You should have received a copy of the GNU Library General Public* License along with this library; if not, write to the* Free Software Foundation, Inc., 59 Temple Place - Suite 330,* Boston, MA 02111-1307, USA.*//*    This file is originally copied from gtkcellrenderertext.c of gtk+ library.    2006.07.16 modified by Hong Jen Yee to produce a simplified text renderer    which supports center alignment of text to be used in PCMan File Manager.*/#include <stdlib.h>#include <gtk/gtk.h>#include <glib/gi18n.h>#include "ptk-text-renderer.h"static void ptk_text_renderer_init ( PtkTextRenderer *celltext );static void ptk_text_renderer_class_init ( PtkTextRendererClass *class );static void ptk_text_renderer_finalize ( GObject *object );static void ptk_text_renderer_get_property ( GObject *object,                                             guint param_id,                                             GValue *value,                                             GParamSpec *pspec );static void ptk_text_renderer_set_property ( GObject *object,                                             guint param_id,                                             const GValue *value,                                             GParamSpec *pspec );static void ptk_text_renderer_get_size ( GtkCellRenderer *cell,                                         GtkWidget *widget,                                         GdkRectangle *cell_area,                                         gint *x_offset,                                         gint *y_offset,                                         gint *width,                                         gint *height );static void ptk_text_renderer_render ( GtkCellRenderer *cell,                                       GdkWindow *window,                                       GtkWidget *widget,                                       GdkRectangle *background_area,                                       GdkRectangle *cell_area,                                       GdkRectangle *expose_area,                                       GtkCellRendererState flags );enum {    PROP_0,    PROP_TEXT,    PROP_WRAP_WIDTH,    /* Style args */    PROP_BACKGROUND,    PROP_FOREGROUND,    PROP_BACKGROUND_GDK,    PROP_FOREGROUND_GDK,    PROP_FONT,    PROP_FONT_DESC,    PROP_UNDERLINE,    PROP_ELLIPSIZE,    PROP_WRAP_MODE,    /* Whether-a-style-arg-is-set args */    PROP_BACKGROUND_SET,    PROP_FOREGROUND_SET,    PROP_UNDERLINE_SET,    PROP_ELLIPSIZE_SET};static gpointer parent_class;#define PTK_TEXT_RENDERER_PATH "ptk-cell-renderer-text-path"GTypeptk_text_renderer_get_type ( void ){    static GType cell_text_type = 0;    if ( !cell_text_type )    {        static const GTypeInfo cell_text_info =            {                sizeof ( PtkTextRendererClass ),                NULL,        /* base_init */                NULL,        /* base_finalize */                ( GClassInitFunc ) ptk_text_renderer_class_init,                NULL,        /* class_finalize */                NULL,        /* class_data */                sizeof ( PtkTextRenderer ),                0,               /* n_preallocs */                ( GInstanceInitFunc ) ptk_text_renderer_init,            };        cell_text_type =            g_type_register_static ( GTK_TYPE_CELL_RENDERER, "PtkTextRenderer",                                     &cell_text_info, 0 );    }    return cell_text_type;}static voidptk_text_renderer_init ( PtkTextRenderer *celltext ){    GTK_CELL_RENDERER ( celltext ) ->xalign = 0.0;    GTK_CELL_RENDERER ( celltext ) ->yalign = 0.5;    GTK_CELL_RENDERER ( celltext ) ->xpad = 2;    GTK_CELL_RENDERER ( celltext ) ->ypad = 2;    celltext->font = pango_font_description_new ();    celltext->wrap_width = -1;}static voidptk_text_renderer_class_init ( PtkTextRendererClass *class ){    GObjectClass *object_class = G_OBJECT_CLASS ( class );    GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS ( class );    parent_class = g_type_class_peek_parent ( class );    object_class->finalize = ptk_text_renderer_finalize;    object_class->get_property = ptk_text_renderer_get_property;    object_class->set_property = ptk_text_renderer_set_property;    cell_class->get_size = ptk_text_renderer_get_size;    cell_class->render = ptk_text_renderer_render;    g_object_class_install_property ( object_class,                                      PROP_TEXT,                                      g_param_spec_string ( "text",                                                            _( "Text" ),                                                            _( "Text to render" ),                                                            NULL,                                                            G_PARAM_READABLE | G_PARAM_WRITABLE ) );    g_object_class_install_property ( object_class,                                      PROP_BACKGROUND,                                      g_param_spec_string ( "background",                                                            _( "Background color name" ),                                                            _( "Background color as a string" ),                                                            NULL,                                                            G_PARAM_WRITABLE ) );    g_object_class_install_property ( object_class,                                      PROP_BACKGROUND_GDK,                                      g_param_spec_boxed ( "background-gdk",                                                           _( "Background color" ),                                                           _( "Background color as a GdkColor" ),                                                           GDK_TYPE_COLOR,                                                           G_PARAM_READABLE | G_PARAM_WRITABLE ) );    g_object_class_install_property ( object_class,                                      PROP_FOREGROUND,                                      g_param_spec_string ( "foreground",                                                            _( "Foreground color name" ),                                                            _( "Foreground color as a string" ),                                                            NULL,                                                            G_PARAM_WRITABLE ) );    g_object_class_install_property ( object_class,                                      PROP_FOREGROUND_GDK,                                      g_param_spec_boxed ( "foreground-gdk",                                                           _( "Foreground color" ),                                                           _( "Foreground color as a GdkColor" ),                                                           GDK_TYPE_COLOR,                                                           G_PARAM_READABLE | G_PARAM_WRITABLE ) );    g_object_class_install_property ( object_class,                                      PROP_FONT,                                      g_param_spec_string ( "font",                                                            _( "Font" ),                                                            _( "Font description as a string" ),                                                            NULL,                                                            G_PARAM_READABLE | G_PARAM_WRITABLE ) );    g_object_class_install_property ( object_class,                                      PROP_FONT_DESC,                                      g_param_spec_boxed ( "font-desc",                                                           _( "Font" ),                                                           _( "Font description as a PangoFontDescription struct" ),                                                           PANGO_TYPE_FONT_DESCRIPTION,                                                           G_PARAM_READABLE | G_PARAM_WRITABLE ) );    g_object_class_install_property ( object_class,                                      PROP_UNDERLINE,                                      g_param_spec_enum ( "underline",                                                          _( "Underline" ),                                                          _( "Style of underline for this text" ),                                                          PANGO_TYPE_UNDERLINE,                                                          PANGO_UNDERLINE_NONE,                                                          G_PARAM_READABLE | G_PARAM_WRITABLE ) );    /**     * PtkTextRenderer:ellipsize:       *       * Specifies the preferred place to ellipsize the string, if the cell renderer       * does not have enough room to display the entire string. Setting it to       * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property       * for another way of making the text fit into a given width.       *       * Since: 2.6     */    g_object_class_install_property ( object_class,                                      PROP_ELLIPSIZE,                                      g_param_spec_enum ( "ellipsize",                                                          _( "Ellipsize" ),                                                          _( "The preferred place to ellipsize the string, "                                                             "if the cell renderer does not have enough room "                                                             "to display the entire string, if at all" ),                                                          PANGO_TYPE_ELLIPSIZE_MODE,                                                          PANGO_ELLIPSIZE_NONE,                                                          G_PARAM_READABLE | G_PARAM_WRITABLE ) );    /**     * PtkTextRenderer:wrap-mode:       *       * Specifies how to break the string into multiple lines, if the cell       * renderer does not have enough room to display the entire string.       * This property has no effect unless the wrap-width property is set.       *       * Since: 2.8     */    g_object_class_install_property ( object_class,                                      PROP_WRAP_MODE,                                      g_param_spec_enum ( "wrap-mode",                                                          _( "Wrap mode" ),                                                          _( "How to break the string into multiple lines, "                                                             "if the cell renderer does not have enough room "                                                             "to display the entire string" ),                                                          PANGO_TYPE_WRAP_MODE,                                                          PANGO_WRAP_CHAR,                                                          G_PARAM_READABLE | G_PARAM_WRITABLE ) );    /**     * PtkTextRenderer:wrap-width:       *       * Specifies the width at which the text is wrapped. The wrap-mode property can       * be used to influence at what character positions the line breaks can be placed.       * Setting wrap-width to -1 turns wrapping off.       *       * Since: 2.8     */    g_object_class_install_property ( object_class,                                      PROP_WRAP_WIDTH,                                      g_param_spec_int ( "wrap-width",                                                         _( "Wrap width" ),                                                         _( "The width at which the text is wrapped" ),                                                         -1,                                                         G_MAXINT,                                                         -1,                                                         G_PARAM_READABLE | G_PARAM_WRITABLE ) );    /* Style props are set or not */#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE|G_PARAM_WRITABLE))    ADD_SET_PROP ( "background-set", PROP_BACKGROUND_SET,                   _( "Background set" ),                   _( "Whether this tag affects the background color" ) );    ADD_SET_PROP ( "foreground-set", PROP_FOREGROUND_SET,                   _( "Foreground set" ),                   _( "Whether this tag affects the foreground color" ) );    ADD_SET_PROP ( "underline-set", PROP_UNDERLINE_SET,                   _( "Underline set" ),                   _( "Whether this tag affects underlining" ) );    ADD_SET_PROP ( "ellipsize-set", PROP_ELLIPSIZE_SET,                   _( "Ellipsize set" ),                   _( "Whether this tag affects the ellipsize mode" ) );}static voidptk_text_renderer_finalize ( GObject *object ){    PtkTextRenderer * celltext = PTK_TEXT_RENDERER ( object );    pango_font_description_free ( celltext->font );    g_free ( celltext->text );    ( * G_OBJECT_CLASS ( parent_class ) ->finalize ) ( object );}static voidptk_text_renderer_get_property ( GObject *object,                                 guint param_id,                                 GValue *value,                                 GParamSpec *pspec ){    PtkTextRenderer * celltext = PTK_TEXT_RENDERER ( object );    switch ( param_id )    {    case PROP_TEXT:        g_value_set_string ( value, celltext->text );        break;    case PROP_BACKGROUND_GDK:        {            GdkColor color;            color.red = celltext->background.red;            color.green = celltext->background.green;            color.blue = celltext->background.blue;            g_value_set_boxed ( value, &color );        }        break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -