5namespace Stroika::Frameworks::Led {
12 inline StandardTabStopList::StandardTabStopList ()
14 , fDefaultTabWidth (720)
18 Assert (fDefaultTabWidth > 0);
20 inline StandardTabStopList::StandardTabStopList (TWIPS eachWidth)
22 , fDefaultTabWidth (eachWidth)
25 Require (fDefaultTabWidth > 0);
27 inline StandardTabStopList::StandardTabStopList (
const vector<TWIPS>& tabstops)
29 , fDefaultTabWidth (720)
33 Assert (fDefaultTabWidth > 0);
35 inline StandardTabStopList::StandardTabStopList (
const vector<TWIPS>& tabstops, TWIPS afterTabsWidth)
37 , fDefaultTabWidth (afterTabsWidth)
38 , fTabStops (tabstops)
40 Require (fDefaultTabWidth > 0);
42 inline TWIPS StandardTabStopList::ComputeIthTab (
size_t i)
const
45 size_t smallI = min (i + 1, fTabStops.size ());
46 for (
size_t j = 0; j < smallI; ++j) {
50 r = TWIPS (
static_cast<long> ((r / fDefaultTabWidth + (i - smallI + 1)) * fDefaultTabWidth));
54 inline TWIPS StandardTabStopList::ComputeTabStopAfterPosition (TWIPS afterPos)
const
58 size_t guessIdx = afterPos / fDefaultTabWidth;
59 TWIPS guessVal = ComputeIthTab (guessIdx);
62 while (guessIdx > 0 and guessVal > afterPos) {
63 Assert (guessIdx == 0 or ComputeIthTab (guessIdx - 1) < ComputeIthTab (guessIdx));
65 guessVal = ComputeIthTab (guessIdx);
69 Assert (guessIdx == 0 or guessVal <= afterPos);
71 Assert (guessIdx == 0 or ComputeIthTab (guessIdx - 1) < ComputeIthTab (guessIdx));
72 TWIPS d = ComputeIthTab (guessIdx);
80 constexpr bool StandardTabStopList::operator== (
const StandardTabStopList& rhs)
const
82 return fDefaultTabWidth == rhs.fDefaultTabWidth and fTabStops == rhs.fTabStops;
85#if qStroika_Frameworks_Led_SupportGDI
92 inline TextImager::SimpleTabStopList::SimpleTabStopList (TWIPS twipsPerTabStop)
94 , fTWIPSPerTabStop (twipsPerTabStop)
96 Require (twipsPerTabStop > 0);
98 inline TWIPS TextImager::SimpleTabStopList::ComputeIthTab (
size_t i)
const
100 return TWIPS (
static_cast<long> ((i + 1) * fTWIPSPerTabStop));
102 inline TWIPS TextImager::SimpleTabStopList::ComputeTabStopAfterPosition (TWIPS afterPos)
const
104 Assert (fTWIPSPerTabStop > 0);
105 size_t idx = afterPos / fTWIPSPerTabStop;
106 TWIPS result = TWIPS (
static_cast<long> ((idx + 1) * fTWIPSPerTabStop));
107 Ensure (result % fTWIPSPerTabStop == 0);
108 Ensure (result > afterPos);
117 inline TextImager::GoalColumnRecomputerControlContext::GoalColumnRecomputerControlContext (TextImager& imager,
bool suppressRecompute)
118 : fTextImager (imager)
119 , fSavedSuppressRecompute (imager.fSuppressGoalColumnRecompute)
121 imager.fSuppressGoalColumnRecompute = suppressRecompute;
123 inline TextImager::GoalColumnRecomputerControlContext::~GoalColumnRecomputerControlContext ()
125 fTextImager.fSuppressGoalColumnRecompute = fSavedSuppressRecompute;
133 inline void TextImager::SetWindowRect_ (
const Led_Rect& windowRect)
135 fWindowRect = windowRect;
147 inline bool TextImager::GetForceAllRowsShowing ()
const
149 return fForceAllRowsShowing;
155 inline void TextImager::SetForceAllRowsShowing (
bool forceAllRowsShowing)
157 if (forceAllRowsShowing != fForceAllRowsShowing) {
158 fForceAllRowsShowing = forceAllRowsShowing;
159 AssureWholeWindowUsedIfNeeded ();
173 inline bool TextImager::GetImageUsingOffscreenBitmaps ()
const
175 return fImageUsingOffscreenBitmaps;
181 inline void TextImager::SetImageUsingOffscreenBitmaps (
bool imageUsingOffscreenBitmaps)
183 if (imageUsingOffscreenBitmaps != fImageUsingOffscreenBitmaps) {
184 fImageUsingOffscreenBitmaps = imageUsingOffscreenBitmaps;
194 inline CoordinateType TextImager::GetHScrollPos ()
const
196 return (fHScrollPos);
198 inline void TextImager::SetHScrollPos_ (CoordinateType hScrollPos)
200 fHScrollPos = hScrollPos;
206 inline TWIPS TextImager::GetSelectionGoalColumn ()
const
208 return (fSelectionGoalColumn);
214 inline void TextImager::SetSelectionGoalColumn (TWIPS selectionGoalColumn)
216 fSelectionGoalColumn = selectionGoalColumn;
218 inline void TextImager::InvalidateScrollBarParameters ()
235 inline bool TextImager::GetUseSelectEOLBOLRowHilightStyle ()
const
237 return fUseEOLBOLRowHilightStyle;
243 inline void TextImager::SetUseSelectEOLBOLRowHilightStyle (
bool useEOLBOLRowHilightStyle)
245 fUseEOLBOLRowHilightStyle = useEOLBOLRowHilightStyle;
247 inline bool TextImager::GetSelectionShown ()
const
249 return (fSelectionShown);
261 inline Led_Rect TextImager::GetWindowRect ()
const
263 return (fWindowRect);
270 inline FontSpecification TextImager::GetDefaultFont ()
const
272 return (fDefaultFont);
279 inline size_t TextImager::GetRowLength (
size_t rowNumber)
const
281 return (GetEndOfRow (rowNumber) - GetStartOfRow (rowNumber));
295 inline Color* TextImager::GetDefaultTextColor (DefaultColorIndex dci)
const
297 Require (dci < eMaxDefaultColorIndex);
298 return fDefaultColorIndex[dci];
312 inline Color TextImager::GetEffectiveDefaultTextColor (DefaultColorIndex dci)
const
314 Require (dci < eMaxDefaultColorIndex);
315 if (fDefaultColorIndex[dci] ==
nullptr) {
317 case eDefaultTextColor:
318 return fDefaultFont.GetTextColor ();
319 case TextImager::eDefaultBackgroundColor:
320 return Led_GetTextBackgroundColor ();
321 case TextImager::eDefaultSelectedTextColor:
322 return Led_GetSelectedTextColor ();
323 case TextImager::eDefaultSelectedTextBackgroundColor:
324 return Led_GetSelectedTextBackgroundColor ();
327 return Color::kBlack;
331 return *fDefaultColorIndex[dci];
346 inline void TextImager::ClearDefaultTextColor (DefaultColorIndex dci)
348 Require (dci < eMaxDefaultColorIndex);
349 delete fDefaultColorIndex[dci];
350 fDefaultColorIndex[dci] =
nullptr;
351 if (dci == eDefaultTextColor) {
352 fDefaultFont.SetTextColor (Led_GetTextColor ());
367 inline void TextImager::SetDefaultTextColor (DefaultColorIndex dci,
const Color& textColor)
369 Require (dci < eMaxDefaultColorIndex);
370 ClearDefaultTextColor (dci);
371 if (dci == eDefaultTextColor) {
372 fDefaultFont.SetTextColor (textColor);
374 fDefaultColorIndex[dci] =
new Color (textColor);
385 inline size_t TextImager::GetStartOfNextRowFromRowContainingPosition (
size_t charPosition)
const
388 size_t rowEnd = FindNextCharacter (GetEndOfRowContainingPosition (charPosition));
389 return GetStartOfRowContainingPosition (rowEnd);
398 inline size_t TextImager::GetStartOfPrevRowFromRowContainingPosition (
size_t charPosition)
const
401 size_t rowStart = GetStartOfRowContainingPosition (charPosition);
403 rowStart = GetStartOfRowContainingPosition (FindPreviousCharacter (rowStart));
409 inline TextImager::FontCacheInfoUpdater::~FontCacheInfoUpdater ()
411#if qStroika_Foundation_Common_Platform_Windows
412 if (fRestoreObject !=
nullptr) {
413 Verify (::SelectObject (fTablet->m_hDC, fRestoreObject));
415 if (fRestoreAttribObject !=
nullptr) {
416 Verify (::SelectObject (fTablet->m_hAttribDC, fRestoreAttribObject));
420 inline FontMetrics TextImager::FontCacheInfoUpdater::GetMetrics ()
const
422 return fImager->fCachedFontInfo;
426 template <
typename TEXTSTORE,
typename IMAGER>
432 TrivialImager<TEXTSTORE, IMAGER>::TrivialImager (Tablet* t)
436 , fBackgroundTransparent{false}
438 this->SpecifyTextStore (&fTextStore);
440 template <
typename TEXTSTORE,
typename IMAGER>
441 TrivialImager<TEXTSTORE, IMAGER>::TrivialImager (Tablet* t, Led_Rect bounds,
const Led_tString& initialText)
444 SnagAttributesFromTablet ();
445 this->SetWindowRect (bounds);
446 fTextStore.Replace (0, 0, initialText.c_str (), initialText.length ());
448 template <
typename TEXTSTORE,
typename IMAGER>
449 TrivialImager<TEXTSTORE, IMAGER>::~TrivialImager ()
451 this->SpecifyTextStore (
nullptr);
453 template <
typename TEXTSTORE,
typename IMAGER>
454 void TrivialImager<TEXTSTORE, IMAGER>::Draw (
bool printing)
456 Draw (this->GetWindowRect (), printing);
458 template <
typename TEXTSTORE,
typename IMAGER>
459 void TrivialImager<TEXTSTORE, IMAGER>::Draw (
const Led_Rect& subsetToDraw,
bool printing)
461 IMAGER::Draw (subsetToDraw, printing);
463 template <
typename TEXTSTORE,
typename IMAGER>
464 Tablet* TrivialImager<TEXTSTORE, IMAGER>::AcquireTablet ()
const
468 template <
typename TEXTSTORE,
typename IMAGER>
469 void TrivialImager<TEXTSTORE, IMAGER>::ReleaseTablet (Tablet* )
const
472 template <
typename TEXTSTORE,
typename IMAGER>
473 void TrivialImager<TEXTSTORE, IMAGER>::EraseBackground (Tablet* tablet,
const Led_Rect& subsetToDraw,
bool printing)
475 if (not fBackgroundTransparent) {
476 inherited::EraseBackground (tablet, subsetToDraw, printing);
479 template <
typename TEXTSTORE,
typename IMAGER>
489 void TrivialImager<TEXTSTORE, IMAGER>::SnagAttributesFromTablet ()
491#if qStroika_Foundation_Common_Platform_MacOS
493#elif qStroika_Foundation_Common_Platform_Windows
494 HFONT hFont = (HFONT)::GetCurrentObject (fTablet->m_hAttribDC, OBJ_FONT);
495 Verify (hFont !=
nullptr);
497 Verify (::GetObject (hFont,
sizeof (LOGFONT), &lf));
498 this->SetDefaultFont (FontSpecification (lf));
499 this->SetDefaultTextColor (TextImager::eDefaultBackgroundColor, Color (::GetBkColor (fTablet->m_hAttribDC)));
500 if (::GetBkMode (fTablet->m_hAttribDC) == TRANSPARENT) {
501 SetBackgroundTransparent (
true);
505 template <
typename TEXTSTORE,
typename IMAGER>
510 inline Color TrivialImager<TEXTSTORE, IMAGER>::GetBackgroundColor ()
const
512 return this->GetEffectiveDefaultTextColor (TextImager::eDefaultBackgroundColor);
514 template <
typename TEXTSTORE,
typename IMAGER>
521 inline void TrivialImager<TEXTSTORE, IMAGER>::SetBackgroundColor (Color c)
523 this->SetDefaultTextColor (TextImager::eDefaultBackgroundColor, c);
525 template <
typename TEXTSTORE,
typename IMAGER>
530 inline bool TrivialImager<TEXTSTORE, IMAGER>::GetBackgroundTransparent ()
const
532 return fBackgroundTransparent;
534 template <
typename TEXTSTORE,
typename IMAGER>
545 inline void TrivialImager<TEXTSTORE, IMAGER>::SetBackgroundTransparent (
bool transparent)
547 fBackgroundTransparent = transparent;
#define AssertNotReached()