LibreOffice Module starmath (master) 1
caret.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#pragma once
11
12#include <sal/config.h>
13#include "node.hxx"
14
17{
18 SmCaretPos(SmNode* selectedNode = nullptr, int iIndex = 0)
19 : pSelectedNode(selectedNode)
20 , nIndex(iIndex)
21 {
22 assert(nIndex >= 0);
23 }
24
27
36 //TODO: Special cases for SmBlankNode is needed
37 //TODO: Consider forgetting about the todo above... As it's really unpleasant.
38 int nIndex;
39
41 bool IsValid() const { return pSelectedNode != nullptr; }
42 bool operator==(const SmCaretPos& pos) const
43 {
44 return pos.pSelectedNode == pSelectedNode && nIndex == pos.nIndex;
45 }
52 {
53 if (pNode && pNode->GetType() == SmNodeType::Text)
54 return SmCaretPos(pNode, static_cast<SmTextNode*>(pNode)->GetText().getLength());
55 return SmCaretPos(pNode, 1);
56 }
57};
58
61{
62public:
63 SmCaretLine(tools::Long left = 0, tools::Long top = 0, tools::Long height = 0)
64 {
65 _top = top;
66 _left = left;
67 _height = height;
68 }
69 tools::Long GetTop() const { return _top; }
70 tools::Long GetLeft() const { return _left; }
71 tools::Long GetHeight() const { return _height; }
73 {
74 return (GetLeft() - line.GetLeft()) * (GetLeft() - line.GetLeft());
75 }
77 {
78 return (GetLeft() - pos.X()) * (GetLeft() - pos.X());
79 }
81 {
82 tools::Long d = GetTop() - line.GetTop();
83 if (d < 0)
84 d = (d * -1) - GetHeight();
85 else
86 d = d - line.GetHeight();
87 if (d < 0)
88 return 0;
89 return d * d;
90 }
92 {
93 tools::Long d = GetTop() - pos.Y();
94 if (d < 0)
95 d = (d * -1) - GetHeight();
96 if (d < 0)
97 return 0;
98 return d * d;
99 }
100
101private:
105};
106
107// SmCaretPosGraph
108
111{
113 : CaretPos{ pos }
114 , Left{ left }
115 , Right{ right }
116 {
117 }
126};
127
132{
133public:
135
137
142
143 std::vector<std::unique_ptr<SmCaretPosGraphEntry>>::iterator begin()
144 {
145 return mvEntries.begin();
146 }
147
148 std::vector<std::unique_ptr<SmCaretPosGraphEntry>>::iterator end() { return mvEntries.end(); }
149
150private:
151 std::vector<std::unique_ptr<SmCaretPosGraphEntry>> mvEntries;
152};
153
410/* TODO: Write documentation about the following keywords:
411 *
412 * Visual Selections:
413 * - Show images
414 * - Talk about how the visitor does this
415 *
416 * Modifying a Visual Line:
417 * - Find top most non-compo of the line (e.g. The subtree that constitutes a line)
418 * - Make the line into a list
419 * - Edit the list, add/remove/modify nodes
420 * - Parse the list back into a subtree
421 * - Insert the new subtree where the old was taken
422 */
423
424/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
A line that represents a caret.
Definition: caret.hxx:61
tools::Long SquaredDistanceY(const SmCaretLine &line) const
Definition: caret.hxx:80
tools::Long _left
Definition: caret.hxx:103
tools::Long _height
Definition: caret.hxx:104
tools::Long GetHeight() const
Definition: caret.hxx:71
SmCaretLine(tools::Long left=0, tools::Long top=0, tools::Long height=0)
Definition: caret.hxx:63
tools::Long _top
Definition: caret.hxx:102
tools::Long SquaredDistanceY(const Point &pos) const
Definition: caret.hxx:91
tools::Long SquaredDistanceX(const SmCaretLine &line) const
Definition: caret.hxx:72
tools::Long SquaredDistanceX(const Point &pos) const
Definition: caret.hxx:76
tools::Long GetLeft() const
Definition: caret.hxx:70
tools::Long GetTop() const
Definition: caret.hxx:69
A graph over all caret positions.
Definition: caret.hxx:132
std::vector< std::unique_ptr< SmCaretPosGraphEntry > >::iterator begin()
Definition: caret.hxx:143
std::vector< std::unique_ptr< SmCaretPosGraphEntry > >::iterator end()
Definition: caret.hxx:148
std::vector< std::unique_ptr< SmCaretPosGraphEntry > > mvEntries
Definition: caret.hxx:151
SmCaretPosGraphEntry * Add(SmCaretPos pos, SmCaretPosGraphEntry *left=nullptr)
Add a caret position.
Definition: caret.cxx:15
Definition: node.hxx:125
SmNodeType GetType() const
Gets the node type.
Definition: node.hxx:379
Text node.
Definition: node.hxx:747
OString right
OString top
double getLength(const B2DPolygon &rCandidate)
line
long Long
An entry in SmCaretPosGraph.
Definition: caret.hxx:111
SmCaretPosGraphEntry(SmCaretPos pos, SmCaretPosGraphEntry *left, SmCaretPosGraphEntry *right)
Definition: caret.hxx:112
SmCaretPosGraphEntry * Left
Entry to the left visually.
Definition: caret.hxx:121
SmCaretPosGraphEntry * Right
Entry to the right visually.
Definition: caret.hxx:123
void SetLeft(SmCaretPosGraphEntry *left)
Definition: caret.hxx:125
void SetRight(SmCaretPosGraphEntry *right)
Definition: caret.hxx:124
const SmCaretPos CaretPos
Caret position.
Definition: caret.hxx:119
Representation of caret position with an equation.
Definition: caret.hxx:17
bool operator==(const SmCaretPos &pos) const
Definition: caret.hxx:42
bool IsValid() const
True, if this is a valid caret position.
Definition: caret.hxx:41
int nIndex
Index (invariant: non-negative) within the selected node.
Definition: caret.hxx:38
SmNode * pSelectedNode
Selected node.
Definition: caret.hxx:26
static SmCaretPos GetPosAfter(SmNode *pNode)
Get the caret position after pNode, regardless of pNode.
Definition: caret.hxx:51
SmCaretPos(SmNode *selectedNode=nullptr, int iIndex=0)
Definition: caret.hxx:18
sal_uInt64 left
size_t pos