Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
text-tool.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 * Jon A. Cruz <jon@joncruz.org>
10 * Abhishek Sharma
11 *
12 * Copyright (C) 1999-2005 authors
13 * Copyright (C) 2001 Ximian, Inc.
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17
18#ifndef INKSCAPE_UI_TOOLS_TEXT_TOOL_H
19#define INKSCAPE_UI_TOOLS_TEXT_TOOL_H
20
23#include "ui/tools/tool-base.h"
24
25using GtkIMContext = struct _GtkIMContext;
26
27namespace Inkscape {
28class CanvasItemCurve; // Cursor
29class CanvasItemQuad; // Highlighted text
30class CanvasItemRect; // Indicator, Frame
31class CanvasItemBpath;
32class Selection;
33} // namespace Inkscape
34
35namespace Inkscape::UI::Tools {
36
37class TextTool : public ToolBase
38{
39public:
41 ~TextTool() override;
42
43 bool pasteInline(Glib::ustring const clip_text);
44 void placeCursorAt(SPObject *text, Geom::Point const &p);
46 bool deleteSelection();
47 void deleteSelected();
48
49 SPItem *textItem() const { return text; }
50
51 // Insertion point position
52 // Fixme: Public due to hack used by text toolbar.
55
56protected:
57 bool root_handler(CanvasEvent const &event) override;
58 bool item_handler(SPItem *item, CanvasEvent const &event) override;
59
60private:
61 // The text we're editing, or null if none selected
62 SPItem *text = nullptr;
63
64 // Text item position in root coordinates
66
67 // Input method
68 GtkIMContext *imc = nullptr;
69
70 // Unicode input
71 std::string uni;
72 bool unimode = false;
73
74 // On-canvas editing
77 CanvasItemPtr<CanvasItemBpath> frame; // Highlighting flowtext shapes or textpath path
78 CanvasItemPtr<CanvasItemBpath> padding_frame; // Highlighting flowtext padding
79 std::vector<CanvasItemPtr<CanvasItemQuad>> text_selection_quads;
80
81 // Cursor blinking
82 bool show = false;
83 bool phase = false;
84 int blink_time = 0;
85
86 bool nascent_object = false; // clicked on canvas to place cursor, but no text typed yet so ->text still null
87 bool over_text = false; // true if cursor is over a text object
88 unsigned dragging_state = 0; // dragging selection over text
89 bool creating = false; // dragging rubberband to create flowtext
90 Geom::Point p0; // initial point if the flowtext rect
91
92 sigc::scoped_connection sel_changed_connection;
93 sigc::scoped_connection sel_modified_connection;
94 sigc::scoped_connection style_set_connection;
95 sigc::scoped_connection style_query_connection;
96 sigc::scoped_connection focus_in_conn;
97 sigc::scoped_connection focus_out_conn;
98 sigc::scoped_connection blink_conn;
99
100 void _updateCursor(bool scroll_to_see = true);
102 void _setupText();
103
104 void _commit(GtkIMContext *imc, char *string);
105
107 void _blinkCursor();
108 void _resetBlinkTimer();
109 void _showCursor();
110 void _forgetText();
111 void _insertUnichar();
112 void _showCurrUnichar();
113
114 void _selectionChanged(Selection *selection);
115 void _selectionModified(Selection *selection, unsigned flags);
116 bool _styleSet(SPCSSAttr const *css);
117 int _styleQueried(SPStyle *style, int property);
118};
119
120Glib::ustring get_selected_text(TextTool const &tool);
122Text::Layout::iterator const *get_cursor_position(TextTool const &tool, SPObject const *text);
123
124} // namespace Inkscape::UI::Tools
125
126inline auto SP_TEXT_CONTEXT(Inkscape::UI::Tools::ToolBase *tool) { return dynamic_cast<Inkscape::UI::Tools::TextTool*>(tool); }
127inline auto SP_TEXT_CONTEXT(Inkscape::UI::Tools::ToolBase const *tool) { return dynamic_cast<Inkscape::UI::Tools::TextTool const *>(tool); }
128
129#endif // INKSCAPE_UI_TOOLS_TEXT_TOOL_H
130
131/*
132 Local Variables:
133 mode:c++
134 c-file-style:"stroustrup"
135 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
136 indent-tabs-mode:nil
137 fill-column:99
138 End:
139*/
140// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
Two-dimensional point that doubles as a vector.
Definition point.h:66
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
Holds a position within the glyph output of Layout.
Definition Layout-TNG.h:981
int _styleQueried(SPStyle *style, int property)
Text::Layout::iterator text_sel_end
Definition text-tool.h:54
sigc::scoped_connection focus_in_conn
Definition text-tool.h:96
CanvasItemPtr< CanvasItemRect > indicator
Definition text-tool.h:76
SPItem * textItem() const
Definition text-tool.h:49
sigc::scoped_connection sel_modified_connection
Definition text-tool.h:93
void placeCursor(SPObject *text, Text::Layout::iterator where)
CanvasItemPtr< CanvasItemBpath > frame
Definition text-tool.h:77
sigc::scoped_connection focus_out_conn
Definition text-tool.h:97
void _selectionChanged(Selection *selection)
sigc::scoped_connection sel_changed_connection
Definition text-tool.h:92
sigc::scoped_connection blink_conn
Definition text-tool.h:98
std::vector< CanvasItemPtr< CanvasItemQuad > > text_selection_quads
Definition text-tool.h:79
CanvasItemPtr< CanvasItemCurve > cursor
Definition text-tool.h:75
void _updateCursor(bool scroll_to_see=true)
bool deleteSelection()
Deletes the currently selected characters.
bool root_handler(CanvasEvent const &event) override
CanvasItemPtr< CanvasItemBpath > padding_frame
Definition text-tool.h:78
bool _styleSet(SPCSSAttr const *css)
sigc::scoped_connection style_query_connection
Definition text-tool.h:95
void _insertUnichar()
Insert the character indicated by uni to replace the current selection, and reset uni to empty string...
bool pasteInline(Glib::ustring const clip_text)
Attempts to paste system clipboard into the currently edited text, returns true on success.
Text::Layout::iterator text_sel_start
Definition text-tool.h:53
void _selectionModified(Selection *selection, unsigned flags)
void _commit(GtkIMContext *imc, char *string)
sigc::scoped_connection style_set_connection
Definition text-tool.h:94
bool item_handler(SPItem *item, CanvasEvent const &event) override
Handles item specific events.
void placeCursorAt(SPObject *text, Geom::Point const &p)
Base class for Event processors.
Definition tool-base.h:95
To do: update description of desktop.
Definition desktop.h:149
Base class for visual SVG elements.
Definition sp-item.h:109
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
An SVG style object.
Definition style.h:45
std::shared_ptr< Css const > css
SPItem * item
Glib::ustring get_selected_text(TextTool const &tool)
Gets the raw characters that comprise the currently selected text, converting line breaks into lf cha...
SPCSSAttr * get_style_at_cursor(TextTool const &tool)
Text::Layout::iterator const * get_cursor_position(TextTool const &tool, SPObject const *other_text)
Helper class to stream background task notifications as a series of messages.
Abstract base class for events.
SPDesktop * desktop
_GtkIMContext GtkIMContext
Definition text-tool.h:25
auto SP_TEXT_CONTEXT(Inkscape::UI::Tools::ToolBase *tool)
Definition text-tool.h:126