Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Librem5
debs
gtk
Commits
ad019892
Commit
ad019892
authored
Jul 30, 2018
by
Dorota Czaplejewicz
Browse files
WIP: Render im span as selection
parent
77b4c443
Pipeline
#548
failed with stage
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
gtk/Makefile.am
View file @
ad019892
...
...
@@ -312,6 +312,7 @@ gtk_public_h_sources = \
gtkswitch.h
\
gtktestutils.h
\
gtktextattributes.h
\
gtktextattrspan.h
\
gtktextbuffer.h
\
gtktextbufferrichtext.h
\
gtktextchild.h
\
...
...
@@ -921,6 +922,7 @@ gtk_base_c_sources = \
gtkswitch.c
\
gtktestutils.c
\
gtktextattributes.c
\
gtktextattrspan.c
\
gtktextbtree.c
\
gtktextbuffer.c
\
gtktextbufferrichtext.c
\
...
...
gtk/gtktextattributes.h
View file @
ad019892
...
...
@@ -98,6 +98,9 @@ struct _GtkTextAppearance
guint
underline
:
4
;
/* PangoUnderline */
guint
strikethrough
:
1
;
/* Used to represent IM cursor span */
guint
selected
:
1
;
/* Whether to use background-related values; this is irrelevant for
* the values struct when in a tag, but is used for the composite
* values struct; it's true if any of the tags being composited
...
...
gtk/gtktextattrspan.c
0 → 100644
View file @
ad019892
/* GtkTextAttrSpan.c - text attributes
*
* Copyright (c) 1992-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* Copyright (c) 2000 Red Hat, Inc.
* Copyright (c) 2018 Purism SPC
* Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
*
* This software is copyrighted by the Regents of the University of
* California, Sun Microsystems, Inc., and other parties. The
* following terms apply to all files associated with the software
* unless explicitly disclaimed in individual files.
*
* The authors hereby grant permission to use, copy, modify,
* distribute, and license this software and its documentation for any
* purpose, provided that existing copyright notices are retained in
* all copies and that this notice is included verbatim in any
* distributions. No written agreement, license, or royalty fee is
* required for any of the authorized uses. Modifications to this
* software may be copyrighted by their authors and need not follow
* the licensing terms described here, provided that the new terms are
* clearly indicated on the first page of each file where they apply.
*
* IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
* OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
* NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
* AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* GOVERNMENT USE: If you are acquiring this software on behalf of the
* U.S. government, the Government shall have only "Restricted Rights"
* in the software and related documentation as defined in the Federal
* Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
* are acquiring the software on behalf of the Department of Defense,
* the software shall be classified as "Commercial Computer Software"
* and the Government shall have only "Restricted Rights" as defined
* in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
* foregoing, the authors grant the U.S. Government and others acting
* in its behalf permission to use and distribute the software in
* accordance with the terms specified in this license.
*
*/
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
#include
"config.h"
#include
"gtktextattrspan.h"
PangoAttrType
gtk_text_attr_span_type
=
0
;
/**
* gtk_text_attr_span_copy:
* @src: a #GtkTextAttrSpan to be copied
*
* Copies @src and returns a new #GtkTextAttrSpan. This is e1uivalent to
* creating a new one, because #GtkTextAttrSpan doesn't carry any additional
* information.
*
* Returns: a copy of @src
*/
PangoAttribute
*
gtk_text_attr_span_copy
(
const
PangoAttribute
*
attr
)
{
return
gtk_text_attr_span_new
();
}
static
gboolean
gtk_text_attr_span_compare
(
const
PangoAttribute
*
attr1
,
const
PangoAttribute
*
attr2
)
{
return
TRUE
;
}
/**
* gtk_text_attr_span_destroy:
* @values: a #GtkTextAttrSpan
**/
static
void
gtk_text_attr_span_destroy
(
PangoAttribute
*
attr
)
{
GtkTextAttrSpan
*
span_attr
=
(
GtkTextAttrSpan
*
)
attr
;
g_slice_free
(
GtkTextAttrSpan
,
span_attr
);
}
/**
* gtk_text_attr_span_new:
*
* Creates a #GtkTextAttrSpan, which indicates that the text is a marked part
* of a preedit text.
*
* Returns: a new #GtkTextAttrSpan,
* free with gtk_span_attribute_unref().
*/
PangoAttribute
*
gtk_text_attr_span_new
()
{
static
PangoAttrClass
klass
=
{
0
,
gtk_text_attr_span_copy
,
gtk_text_attr_span_destroy
,
gtk_text_attr_span_compare
};
GtkTextAttrSpan
*
result
;
if
(
!
klass
.
type
)
klass
.
type
=
gtk_text_attr_span_type
=
pango_attr_type_register
(
"GtkTextAttrSpan"
);
result
=
g_slice_new
(
GtkTextAttrSpan
);
result
->
attr
.
klass
=
&
klass
;
return
(
PangoAttribute
*
)
result
;
}
gtk/gtktextattrspan.h
0 → 100644
View file @
ad019892
/* GTK - The GIMP Toolkit
* gtktextattrspan.h
*
* Copyright (c) 1992-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* Copyright (c) 2000 Red Hat, Inc.
* Copyright (c) 2000 Purism SPC
* Tk->Gtk port by Havoc Pennington
* Pango support by Owen Taylor
*
* Based on gtktextlayout.h.
*
* This file can be used under your choice of two licenses, the LGPL
* and the original Tk license.
*
* LGPL:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Original Tk license:
*
* This software is copyrighted by the Regents of the University of
* California, Sun Microsystems, Inc., and other parties. The
* following terms apply to all files associated with the software
* unless explicitly disclaimed in individual files.
*
* The authors hereby grant permission to use, copy, modify,
* distribute, and license this software and its documentation for any
* purpose, provided that existing copyright notices are retained in
* all copies and that this notice is included verbatim in any
* distributions. No written agreement, license, or royalty fee is
* required for any of the authorized uses. Modifications to this
* software may be copyrighted by their authors and need not follow
* the licensing terms described here, provided that the new terms are
* clearly indicated on the first page of each file where they apply.
*
* IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
* OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
* NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
* AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* GOVERNMENT USE: If you are acquiring this software on behalf of the
* U.S. government, the Government shall have only "Restricted Rights"
* in the software and related documentation as defined in the Federal
* Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
* are acquiring the software on behalf of the Department of Defense,
* the software shall be classified as "Commercial Computer Software"
* and the Government shall have only "Restricted Rights" as defined
* in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
* foregoing, the authors grant the U.S. Government and others acting
* in its behalf permission to use and distribute the software in
* accordance with the terms specified in this license.
*
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GTK_TEXT_ATTR_SPAN_H__
#define __GTK_TEXT_ATTR_SPAN_H__
/* This is a "semi-private" header; it is intended for
* use by the input methods, and the Pango renderers,
* but that’s all.
*/
#ifndef GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
#error "You are not supposed to be including this file; the equivalent public API is in gtktextview.h"
#endif
#include
<gtk/gtk.h>
G_BEGIN_DECLS
typedef
struct
_GtkTextAttrSpan
GtkTextAttrSpan
;
struct
_GtkTextAttrSpan
{
PangoAttribute
attr
;
GtkTextAppearance
appearance
;
};
#ifdef GTK_COMPILATION
extern
G_GNUC_INTERNAL
PangoAttrType
gtk_text_attr_span_type
;
#endif
GDK_AVAILABLE_IN_ALL
PangoAttribute
*
gtk_text_attr_span_new
();
GDK_AVAILABLE_IN_ALL
PangoAttribute
*
gtk_text_attr_span_copy
(
const
PangoAttribute
*
attr
);
G_END_DECLS
#endif
/* __GTK_TEXT_ATTR_SPAN_H__ */
gtk/gtktextdisplay.c
View file @
ad019892
...
...
@@ -3,6 +3,7 @@
* Copyright (c) 1992-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* Copyright (c) 2000 Red Hat, Inc.
* Copyright (c) 2018 Purism SPC
* Tk->Gtk port by Havoc Pennington
*
* This file can be used under your choice of two licenses, the LGPL
...
...
@@ -76,6 +77,7 @@
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
#include
"config.h"
#include
"gtktextattributesprivate.h"
#include
"gtktextattrspan.h"
#include
"gtktextdisplay.h"
#include
"gtkwidgetprivate.h"
#include
"gtkstylecontextprivate.h"
...
...
@@ -149,7 +151,7 @@ text_renderer_set_rgba (GtkTextRenderer *text_renderer,
}
static
GtkTextAppearance
*
get_item_appearance
(
PangoItem
*
item
)
get_item_appearance
(
PangoItem
*
item
,
GtkStyleContext
*
context
)
{
GSList
*
tmp_list
=
item
->
analysis
.
extra_attrs
;
...
...
@@ -166,6 +168,22 @@ get_item_appearance (PangoItem *item)
return
NULL
;
}
static
gboolean
is_item_span
(
PangoItem
*
item
)
{
GSList
*
tmp_list
=
item
->
analysis
.
extra_attrs
;
while
(
tmp_list
)
{
PangoAttribute
*
attr
=
tmp_list
->
data
;
if
(
attr
->
klass
->
type
==
gtk_text_attr_span_type
)
return
TRUE
;
tmp_list
=
tmp_list
->
next
;
}
return
FALSE
;
}
extern
GtkCssNode
*
gtk_text_view_get_text_node
(
GtkTextView
*
text_view
);
extern
GtkCssNode
*
gtk_text_view_get_selection_node
(
GtkTextView
*
text_view
);
...
...
@@ -178,16 +196,23 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer,
GdkRGBA
*
bg_rgba
=
NULL
;
GdkRGBA
*
fg_rgba
=
NULL
;
GtkTextAppearance
*
appearance
;
gboolean
span
;
PANGO_RENDERER_CLASS
(
_gtk_text_renderer_parent_class
)
->
prepare_run
(
renderer
,
run
);
appearance
=
get_item_appearance
(
run
->
item
);
context
=
gtk_widget_get_style_context
(
text_renderer
->
widget
);
appearance
=
get_item_appearance
(
run
->
item
,
context
);
g_assert
(
appearance
!=
NULL
);
context
=
gtk_widget_get_style_context
(
text_renderer
->
widget
);
span
=
is_item_span
(
run
->
item
);
if
(
appearance
->
draw_bg
&&
text_renderer
->
state
==
NORMAL
)
bg_rgba
=
appearance
->
rgba
[
0
];
else
if
(
span
)
gtk_style_context_get
(
context
,
gtk_style_context_get_state
(
context
)
|
GTK_STATE_FLAG_SELECTED
,
"background-color"
,
&
bg_rgba
,
NULL
);
else
bg_rgba
=
NULL
;
...
...
@@ -212,6 +237,10 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer,
"background-color"
,
&
fg_rgba
,
NULL
);
}
else
if
(
span
)
gtk_style_context_get
(
context
,
gtk_style_context_get_state
(
context
)
|
GTK_STATE_FLAG_SELECTED
,
"color"
,
&
fg_rgba
,
NULL
);
else
fg_rgba
=
appearance
->
rgba
[
1
];
...
...
gtk/gtktextlayout.c
View file @
ad019892
...
...
@@ -4,6 +4,7 @@
* Copyright (c) 1992-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* Copyright (c) 2000 Red Hat, Inc.
* Copyright (c) 2018 Purism SPC
* Tk->Gtk port by Havoc Pennington
* Pango support by Owen Taylor
*
...
...
@@ -83,6 +84,7 @@
#include
"gtktextbufferprivate.h"
#include
"gtktextiterprivate.h"
#include
"gtktextattributesprivate.h"
#include
"gtktextattrspan.h"
#include
"gtktextutil.h"
#include
"gtkintl.h"
...
...
@@ -2014,7 +2016,7 @@ add_preedit_attrs (GtkTextLayout *layout,
{
PangoAttribute
*
attr
=
tmp_list
->
data
;
GdkRGBA
rgba
;
break
;
switch
(
attr
->
klass
->
type
)
{
case
PANGO_ATTR_FOREGROUND
:
...
...
@@ -2058,12 +2060,14 @@ add_preedit_attrs (GtkTextLayout *layout,
g_slist_free
(
extra_attrs
);
insert_attr
=
pango_attr_iterator_get
(
iter
,
gtk_text_attr_span_type
);
if
(
insert_attr
)
pango_attr_list_insert
(
attrs
,
gtk_text_attr_span_copy
(
insert_attr
));
insert_attr
=
pango_attr_font_desc_new
(
font_desc
);
insert_attr
->
start_index
=
start
+
offset
;
insert_attr
->
end_index
=
end
+
offset
;
pango_attr_list_insert
(
attrs
,
insert_attr
);
if
(
language
)
{
insert_attr
=
pango_attr_language_new
(
language
);
...
...
modules/input/imwayland.c
View file @
ad019892
...
...
@@ -617,7 +617,7 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
!=
context_wayland
->
current_preedit
.
cursor_end
)
{
/* FIXME: Oh noes, how to highlight while taking into account user preferences? */
PangoAttribute
*
cursor
=
pango_attr_weight_new
(
PANGO_WEIGHT_BOLD
);
PangoAttribute
*
cursor
=
gtk_text_attr_span_new
(
);
cursor
->
start_index
=
context_wayland
->
current_preedit
.
cursor_begin
;
cursor
->
end_index
=
context_wayland
->
current_preedit
.
cursor_end
;
pango_attr_list_insert
(
*
attrs
,
cursor
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment