Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SimpleTextImager.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5namespace Stroika::Frameworks::Led {
6
7#if qStroika_Frameworks_Led_SupportGDI
8 /*
9 ********************************************************************************
10 ***************************** Implementation Details ***************************
11 ********************************************************************************
12 */
13 // defined out of order cuz used earlier
14 inline SimpleTextImager::RowReference::RowReference (PartitionMarker* partitionMarker)
15 : fPartitionMarker (partitionMarker)
16 {
17 }
18 inline void SimpleTextImager::InvalidateTotalRowsInWindow ()
19 {
20 fTotalRowsInWindow = 0; // zero is sentinel meaning invalid
21 }
22 inline SimpleTextImager::RowReference SimpleTextImager::GetTopRowReferenceInWindow () const
23 {
24 RequireNotNull (PeekAtTextStore ()); // Must associate textstore before we can ask for row-references
25 EnsureNotNull (fTopLinePartitionMarkerInWindow);
26 return (RowReference (fTopLinePartitionMarkerInWindow));
27 }
28 inline size_t SimpleTextImager::GetTotalRowsInWindow_ () const
29 {
30 if (fTotalRowsInWindow == 0) { // cached value invalid
31 fTotalRowsInWindow = ComputeRowsThatWouldFitInWindowWithTopRow (GetTopRowReferenceInWindow ());
32 }
33 Assert (fTotalRowsInWindow >= 1); // always have at least one row...
34 Assert (fTotalRowsInWindow == ComputeRowsThatWouldFitInWindowWithTopRow (GetTopRowReferenceInWindow ()));
35 return (fTotalRowsInWindow);
36 }
37
38 // class SimpleTextImager::RowReference
39 inline SimpleTextImager::RowReference::RowReference (const RowReference& from)
40 : fPartitionMarker (from.fPartitionMarker)
41 {
42 }
43 inline SimpleTextImager::RowReference& SimpleTextImager::RowReference::operator= (const SimpleTextImager::RowReference& rhs)
44 {
45 fPartitionMarker = rhs.fPartitionMarker;
46 return (*this);
47 }
48 inline SimpleTextImager::PartitionMarker* SimpleTextImager::RowReference::GetPartitionMarker () const
49 {
50 return (fPartitionMarker);
51 }
52
53 // class SimpleTextImager
54 /*
55 @METHOD: SimpleTextImager::GetRowHeight
56 @DESCRIPTION: <p>Gets the row height for all rows in the Imager. Note that for SimpleTextImager, all rows have
57 the same height. This function caches the value (computed by @'SimpleTextImager::ReCalcRowHeight' ()). To cause
58 the value to be recomputed, call @'SimpleTextImager::InvalidateRowHeight' (). This is automatically done for you
59 from </p>
60 */
61 inline DistanceType SimpleTextImager::GetRowHeight () const
62 {
63 if (fRowHeight == DistanceType (-1)) {
64 // use mutable when available
65 const_cast<SimpleTextImager*> (this)->fRowHeight = ReCalcRowHeight ();
66 }
67 Ensure (fRowHeight > 0);
68 Ensure (fRowHeight != DistanceType (-1));
69 return fRowHeight;
70 }
71 /*
72 @METHOD: SimpleTextImager::InvalidateRowHeight
73 @DESCRIPTION: <p>Note that the rowHeight associated with this TextImager is invalid. Next time the value is
74 requested (via @'SimpleTextImager::GetRowHeight' ()), recalculate it first.</p>
75 */
76 inline void SimpleTextImager::InvalidateRowHeight ()
77 {
78 fRowHeight = DistanceType (-1);
79 }
80 /*
81 @METHOD: SimpleTextImager::GetNextRowReference
82 @DESCRIPTION: <p>Advance the given row reference argument to the next row. Return true if there
83 is a valid next row. And false if <code>adjustMeInPlace</code> was already on the last row.</p>
84 <p>See also @'SimpleTextImager::GetPreviousRowReference'.</p>
85 */
86 inline bool SimpleTextImager::GetNextRowReference (RowReference* adjustMeInPlace) const
87 {
88 RequireNotNull (adjustMeInPlace);
89 PartitionMarker* cur = adjustMeInPlace->GetPartitionMarker ();
90 size_t subRow = 0;
91
92 if (subRow + 1 < 1) {
93 ++subRow;
94 *adjustMeInPlace = RowReference{cur};
95 return true;
96 }
97 else {
98 if (cur->GetNext () == NULL) {
99 return false;
100 }
101 else {
102 cur = cur->GetNext ();
103 subRow = 0;
104 *adjustMeInPlace = RowReference{cur};
105 return true;
106 }
107 }
108 }
109 /*
110 @METHOD: SimpleTextImager::GetPreviousRowReference
111 @DESCRIPTION: <p>Retreat the given row reference argument to the previous row. Return true if there
112 is a valid previous row. And false if <code>adjustMeInPlace</code> was already on the first row.</p>
113 <p>See also @'SimpleTextImager::GetNextRowReference'.</p>
114 */
115 inline bool SimpleTextImager::GetPreviousRowReference (RowReference* adjustMeInPlace) const
116 {
117 AssertNotNull (adjustMeInPlace);
118 PartitionMarker* cur = adjustMeInPlace->GetPartitionMarker ();
119 size_t subRow = 0;
120
121 if (subRow > 0) {
122 --subRow;
123 *adjustMeInPlace = RowReference (cur);
124 return true;
125 }
126 else {
127 if (cur->GetPrevious () == NULL) {
128 return false;
129 }
130 else {
131 cur = cur->GetPrevious ();
132 subRow = 0;
133 *adjustMeInPlace = RowReference (cur);
134 return true;
135 }
136 }
137 }
138 /*
139 @METHOD: SimpleTextImager::GetIthRowReferenceFromHere
140 @DESCRIPTION: <p>Adjust <code>fromHere</code> by <code>ith</code> rows. If <code>ith</code> is zero, then
141 this returns <code>fromHere</code>. It asserts there are at least ith rows from the given one to retrieve.
142 It calls @'SimpleTextImager::GetIthRowReferenceFromHere' todo its work (which returns a bool rather than asserting).</p>
143 <p>See also @'SimpleTextImager::GetNextRowReference', @'SimpleTextImager::GetPreviousRowReference'.</p>
144 */
145 inline SimpleTextImager::RowReference SimpleTextImager::GetIthRowReferenceFromHere (RowReference fromHere, ptrdiff_t ith) const
146 {
147 [[maybe_unused]] bool result = GetIthRowReferenceFromHere (&fromHere, ith);
148 Assert (result);
149 return (fromHere);
150 }
151 /*
152 @METHOD: SimpleTextImager::GetIthRowReference
153 @DESCRIPTION: <p>Get the <code>ith</code> row reference in the document. Asserts value <code>ith</code> refers to
154 a valid row number.</p>
155 <p>It calls @'SimpleTextImager::GetIthRowReferenceFromHere' todo its work (which returns a bool rather than asserting).</p>
156 */
157 inline SimpleTextImager::RowReference SimpleTextImager::GetIthRowReference (size_t ith) const
158 {
159 RowReference fromHere ((PartitionMarker*)GetFirstPartitionMarker ());
160 [[maybe_unused]] bool result = GetIthRowReferenceFromHere (&fromHere, ith);
161 Assert (result);
162 return fromHere;
163 }
164 /*
165 @METHOD: SimpleTextImager::GetRowLength
166 @DESCRIPTION: <p>Gets the length of the given row (in @'Led_tChar's).</p>
167 <p>See also @'SimpleTextImager::GetStartOfRow' and @'SimpleTextImager::GetEndOfRow'.</p>
168 */
169 inline size_t SimpleTextImager::GetRowLength (RowReference row) const
170 {
171 return (GetEndOfRow (row) - GetStartOfRow (row));
172 }
173 /*
174 @METHOD: SimpleTextImager::GetLastRowReferenceInWindow
175 @DESCRIPTION: <p>Returns the last row-reference in the window (end of window).</p>
176 */
177 inline SimpleTextImager::RowReference SimpleTextImager::GetLastRowReferenceInWindow () const
178 {
179 RowReference row = GetTopRowReferenceInWindow ();
180 Assert (GetTotalRowsInWindow_ () >= 1);
181 (void)GetIthRowReferenceFromHere (&row, GetTotalRowsInWindow_ () - 1);
182 return (row);
183 }
184 inline void SimpleTextImager::SetTopRowInWindow_ (RowReference row)
185 {
186 fTopLinePartitionMarkerInWindow = row.GetPartitionMarker ();
187 AssertNotNull (fTopLinePartitionMarkerInWindow);
188 InvalidateTotalRowsInWindow ();
189 }
190 /*
191 @METHOD: SimpleTextImager::GetInterLineSpace
192 @DESCRIPTION: <p>Get the interline space associated with a SimpleTextImager. Set the per-buffer value with
193 @'SimpleTextImager::GetInterLineSpace'.</p>
194 <p>NB: There is also a one-arg version of @'SimpleTextImager::GetInterLineSpace' which takes a PM
195 as arg. See its docs, or @'SimpleTextImager::ChangedInterLineSpace' for more details.</p>
196 */
197 inline DistanceType SimpleTextImager::GetInterLineSpace () const
198 {
199 return (fInterlineSpace);
200 }
201
202 inline bool operator== (SimpleTextImager::RowReference lhs, SimpleTextImager::RowReference rhs)
203 {
204 return (lhs.GetPartitionMarker () == rhs.GetPartitionMarker ());
205 }
206 inline bool operator!= (SimpleTextImager::RowReference lhs, SimpleTextImager::RowReference rhs)
207 {
208 return (lhs.GetPartitionMarker () != rhs.GetPartitionMarker ());
209 }
210#endif
211
212}
#define AssertNotNull(p)
Definition Assertions.h:333
#define EnsureNotNull(p)
Definition Assertions.h:340
#define RequireNotNull(p)
Definition Assertions.h:347