mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 00:20:42 -05:00
Initial import of the Text actor from Tidy
The TidyText actor is meant as a replacement for both ClutterLabel and ClutterText. Any text-displaying and editing actor should derive from ClutterText and implement the various visual cues to differentiate the editable from the non-editable state. Those visual cues usually belong to a high-level toolkit, especially if themeing is involved.
This commit is contained in:
parent
4973b684a6
commit
a98720ae19
@ -86,6 +86,7 @@ source_h = \
|
||||
$(srcdir)/clutter-stage.h \
|
||||
$(srcdir)/clutter-stage-manager.h \
|
||||
$(srcdir)/clutter-texture.h \
|
||||
$(srcdir)/clutter-text.h \
|
||||
$(srcdir)/clutter-timeline.h \
|
||||
$(srcdir)/clutter-timeout-pool.h \
|
||||
$(srcdir)/clutter-types.h \
|
||||
@ -180,6 +181,7 @@ source_c = \
|
||||
clutter-stage-manager.c \
|
||||
clutter-stage-window.c \
|
||||
clutter-texture.c \
|
||||
clutter-text.c \
|
||||
clutter-timeline.c \
|
||||
clutter-timeout-pool.c \
|
||||
clutter-units.c \
|
||||
|
1561
clutter/clutter-text.c
Normal file
1561
clutter/clutter-text.c
Normal file
File diff suppressed because it is too large
Load Diff
136
clutter/clutter-text.h
Normal file
136
clutter/clutter-text.h
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Copyright (C) 2006-2008 OpenedHand
|
||||
*
|
||||
* Authored By Øyvind Kolås <pippin@o-hand.com>
|
||||
*
|
||||
* 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, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __CLUTTER_TEXT_H__
|
||||
#define __CLUTTER_TEXT_H__
|
||||
|
||||
#include <clutter/clutter-label.h>
|
||||
#include <clutter/clutter-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_TEXT (clutter_text_get_type ())
|
||||
|
||||
#define CLUTTER_TEXT(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
CLUTTER_TYPE_TEXT, ClutterText))
|
||||
|
||||
#define CLUTTER_TEXT_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
||||
CLUTTER_TYPE_TEXT, ClutterTextClass))
|
||||
|
||||
#define CLUTTER_IS_TEXT(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||
CLUTTER_TYPE_TEXT))
|
||||
|
||||
#define CLUTTER_IS_TEXT_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
|
||||
CLUTTER_TYPE_TEXT))
|
||||
|
||||
#define CLUTTER_TEXT_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||
CLUTTER_TYPE_TEXT, ClutterTextClass))
|
||||
|
||||
typedef struct _ClutterText ClutterText;
|
||||
typedef struct _ClutterTextPrivate ClutterTextPrivate;
|
||||
typedef struct _ClutterTextClass ClutterTextClass;
|
||||
|
||||
struct _ClutterText
|
||||
{
|
||||
ClutterLabel parent_instance;
|
||||
|
||||
/*< private >*/
|
||||
ClutterTextPrivate *priv;
|
||||
};
|
||||
|
||||
struct _ClutterTextClass
|
||||
{
|
||||
ClutterLabelClass parent_class;
|
||||
|
||||
void (* text_changed) (ClutterText *text);
|
||||
void (* activate) (ClutterText *text);
|
||||
void (* cursor_event) (ClutterText *text,
|
||||
ClutterGeometry *geometry);
|
||||
};
|
||||
|
||||
GType clutter_text_get_type (void) G_GNUC_CONST;
|
||||
|
||||
ClutterActor *clutter_text_new_full (const gchar *font_name,
|
||||
const gchar *text,
|
||||
const ClutterColor *color);
|
||||
ClutterActor *clutter_text_new_with_text (const gchar *font_name,
|
||||
const gchar *text);
|
||||
|
||||
void clutter_text_set_editable (ClutterText *label,
|
||||
gboolean editable);
|
||||
gboolean clutter_text_get_editable (ClutterText *label);
|
||||
void clutter_text_set_activatable (ClutterText *label,
|
||||
gboolean activatable);
|
||||
gboolean clutter_text_get_activatable (ClutterText *label);
|
||||
|
||||
gint clutter_text_get_cursor_position (ClutterText *label);
|
||||
void clutter_text_set_cursor_position (ClutterText *label,
|
||||
gint position);
|
||||
void clutter_text_set_cursor_visible (ClutterText *label,
|
||||
gboolean cursor_visible);
|
||||
gboolean clutter_text_get_cursor_visible (ClutterText *label);
|
||||
void clutter_text_set_cursor_color (ClutterText *text,
|
||||
const ClutterColor *color);
|
||||
void clutter_text_get_cursor_color (ClutterText *text,
|
||||
ClutterColor *color);
|
||||
void clutter_text_set_selectable (ClutterText *label,
|
||||
gboolean selectable);
|
||||
gboolean clutter_text_get_selectable (ClutterText *label);
|
||||
void clutter_text_set_selection_bound (ClutterText *text,
|
||||
gint selection_bound);
|
||||
gint clutter_text_get_selection_bound (ClutterText *text);
|
||||
gchar * clutter_text_get_selection (ClutterText *text);
|
||||
void clutter_text_insert_unichar (ClutterText *ttext,
|
||||
gunichar wc);
|
||||
|
||||
|
||||
/* add a custom action that can be used in keybindings */
|
||||
void clutter_text_add_action (ClutterText *ttext,
|
||||
const gchar *name,
|
||||
gboolean (*func) (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event));
|
||||
|
||||
/* invoke an action registered by you or one of the tidy text default actions */
|
||||
gboolean clutter_text_action (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event);
|
||||
|
||||
void clutter_text_mappings_clear (ClutterText *ttext);
|
||||
|
||||
/* Add a keybinding to handle for the default keypress vfunc handler */
|
||||
void clutter_text_add_mapping (ClutterText *ttext,
|
||||
guint keyval,
|
||||
ClutterModifierType state,
|
||||
const gchar *commandline);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_TEXT_H__ */
|
@ -68,6 +68,7 @@
|
||||
#include "clutter-stage.h"
|
||||
#include "clutter-stage-manager.h"
|
||||
#include "clutter-texture.h"
|
||||
#include "clutter-text.h"
|
||||
#include "clutter-timeline.h"
|
||||
#include "clutter-timeout-pool.h"
|
||||
#include "clutter-types.h"
|
||||
|
@ -38,7 +38,8 @@ UNIT_TESTS = \
|
||||
test-layout.c \
|
||||
test-animation.c \
|
||||
test-easing.c \
|
||||
test-binding-pool.c
|
||||
test-binding-pool.c \
|
||||
test-text.c
|
||||
|
||||
if X11_TESTS
|
||||
UNIT_TESTS += test-pixmap.c
|
||||
|
176
tests/interactive/test-text.c
Normal file
176
tests/interactive/test-text.c
Normal file
@ -0,0 +1,176 @@
|
||||
/* Try this text editor, it has issues but does work,
|
||||
* try ctrl+A, ctrl+C, ctrl+V, ctrl+X as well as selecting text with
|
||||
* mouse and keyboard, /Øyvind K
|
||||
*/
|
||||
|
||||
#include <gmodule.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define FONT "Mono Bold 22px"
|
||||
|
||||
static gchar *clipboard = NULL;
|
||||
|
||||
static gchar *runes =
|
||||
"ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ\n"
|
||||
"ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ\n"
|
||||
"ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬\n";
|
||||
|
||||
|
||||
static gboolean
|
||||
select_all (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint len;
|
||||
len = g_utf8_strlen (clutter_label_get_text (CLUTTER_LABEL (ttext)), -1);
|
||||
|
||||
clutter_text_set_cursor_position (ttext, 0);
|
||||
clutter_text_set_selection_bound (ttext, len);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
copy (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
if (clipboard)
|
||||
g_free (clipboard);
|
||||
clipboard = clutter_text_get_selection (ttext);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
paste (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
const gchar *p;
|
||||
if (!clipboard)
|
||||
return TRUE;
|
||||
|
||||
for (p=clipboard; *p!='\0'; p=g_utf8_next_char (p))
|
||||
{
|
||||
clutter_text_insert_unichar (ttext, g_utf8_get_char_validated (p, 3));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cut (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
clutter_text_action (ttext, "copy", NULL);
|
||||
clutter_text_action (ttext, "truncate-selection", NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pageup (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint i;
|
||||
for (i=0;i<10;i++)
|
||||
clutter_text_action (ttext, "move-up", event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pagedown (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint i;
|
||||
for (i=0;i<10;i++)
|
||||
clutter_text_action (ttext, "move-down", event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void cursor_event (ClutterText *text,
|
||||
ClutterGeometry *geometry)
|
||||
{
|
||||
gint y;
|
||||
|
||||
y = clutter_actor_get_y (CLUTTER_ACTOR (text));
|
||||
|
||||
if (y + geometry->y < 50)
|
||||
{
|
||||
clutter_actor_set_y (CLUTTER_ACTOR (text), y + 100);
|
||||
}
|
||||
else if (y + geometry->y > 720)
|
||||
{
|
||||
clutter_actor_set_y (CLUTTER_ACTOR (text), y - 100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT gint
|
||||
test_text_main (gint argc,
|
||||
gchar **argv)
|
||||
{
|
||||
ClutterActor *stage;
|
||||
ClutterActor *text;
|
||||
ClutterColor text_color = {0x33, 0xff, 0x33, 0xff};
|
||||
ClutterColor cursor_color = {0xff, 0x33, 0x33, 0xff};
|
||||
ClutterColor background_color = {0x00, 0x00, 0x00, 0xff};
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color);
|
||||
|
||||
text = clutter_text_new_full (FONT, "·", &text_color);
|
||||
|
||||
clutter_container_add (CLUTTER_CONTAINER (stage), text, NULL);
|
||||
clutter_actor_set_position (text, 40, 30);
|
||||
clutter_actor_set_width (text, 1024);
|
||||
clutter_label_set_line_wrap (CLUTTER_LABEL (text), TRUE);
|
||||
|
||||
clutter_actor_set_reactive (text, TRUE);
|
||||
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), text);
|
||||
|
||||
clutter_text_set_editable (CLUTTER_TEXT (text), TRUE);
|
||||
clutter_text_set_selectable (CLUTTER_TEXT (text), TRUE);
|
||||
clutter_text_set_cursor_color (CLUTTER_TEXT (text), &cursor_color);
|
||||
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "select-all", select_all);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "copy", copy);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "paste", paste);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "cut", cut);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "pageup", pageup);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "pagedown", pagedown);
|
||||
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_a, CLUTTER_CONTROL_MASK, "select-all");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_c, CLUTTER_CONTROL_MASK, "copy");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_v, CLUTTER_CONTROL_MASK, "paste");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_x, CLUTTER_CONTROL_MASK, "cut");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_Page_Up, 0, "pageup");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_Page_Down, 0, "pagedown");
|
||||
|
||||
if (argv[1])
|
||||
{
|
||||
gchar *utf8;
|
||||
g_file_get_contents (argv[1], &utf8, NULL, NULL);
|
||||
clutter_label_set_text (CLUTTER_LABEL (text), utf8);
|
||||
}
|
||||
else
|
||||
{
|
||||
clutter_label_set_text (CLUTTER_LABEL (text), runes);
|
||||
}
|
||||
|
||||
g_signal_connect (text, "cursor-event", G_CALLBACK (cursor_event), NULL);
|
||||
|
||||
clutter_actor_set_size (stage, 1024, 768);
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user