NCBI C++ ToolKit
draw_styled_text.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: draw_styled_text.cpp 47464 2023-04-20 00:19:10Z evgeniev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
36 
38 
40 {
41  if (!text.empty()) {
42  list<string> lines;
43  NStr::Split(text, "\n\r", lines, NStr::fSplit_Tokenize);
44  ITERATE (list<string>, it, lines) {
45  *this << *it;
46  NewLine();
47  }
48  }
49 }
50 
51 CBaseTextOStream::CBaseTextOStream(wxDC& dc, int x, int y,
52  size_t rowHeight, size_t indentStep) :
53  m_DC(dc), m_StartX(x), m_StartY(y),
54  m_RowHeight(static_cast<int>(rowHeight)), m_IndentStep(static_cast<int>(indentStep)),
55  m_x(x), m_Row(0), m_CurrentStyle(0), m_CurrentLineLength(0),
56  m_NB(false), m_NBRect(x, y, 0, static_cast<int>(rowHeight))
57 {
58  m_BackgroundMode = m_DC.GetBackgroundMode();
59  m_TextForeground = m_DC.GetTextForeground();
60  m_TextBackground = m_DC.GetTextBackground();
61  m_SaveFont = m_DC.GetFont();
62  m_SaveBrush = m_DC.GetBrush();
63  m_SavePen = m_DC.GetPen();
64 
65 }
66 
68 {
70 }
71 
73 {
75  m_x += width;
76 }
77 
78 
80 {
81  if (style == m_CurrentStyle)
82  return;
83 
84  m_CurrentStyle = style;
85  if (m_CurrentStyle == 0)
87  else {
88  m_DC.SetBackgroundMode(m_CurrentStyle->GetBackgroundMode());
89  m_DC.SetTextForeground(m_CurrentStyle->GetTextForeground());
90  m_DC.SetTextBackground(m_CurrentStyle->GetTextBackground());
91 
92  wxFont font;
93  font.SetNativeFontInfo(m_SaveFont.GetNativeFontInfoDesc());
94  font.SetStyle(
95  m_CurrentStyle->IsTextItalic() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
96  font.SetWeight(
97  m_CurrentStyle->IsTextBold() ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
98 
99  m_DC.SetFont(font);
100  }
101 }
102 
103 
105 {
106  m_DC.SetBackgroundMode(m_BackgroundMode);
107  m_DC.SetTextForeground(m_TextForeground);
108  m_DC.SetTextBackground(m_TextBackground);
109  m_DC.SetFont(m_SaveFont);
110  m_DC.SetBrush(m_SaveBrush);
111  m_DC.SetPen(m_SavePen);
112 }
113 
115 {
116  ++m_Row;
117  m_x = m_StartX;
119 
120  if (m_NB) {
121  m_NB = false;
122  x_OnNBEnd();
123  }
124 }
125 
127 {
128  if (m_NB) {
129  m_NB = false;
130  x_OnNBEnd();
131  }
132  else {
133  m_NB = true;
134  m_NBRect.x = m_x;
136  m_NBRect.width = 0;
137  m_NBRect.height = m_RowHeight;
138  x_OnNBStart();
139  }
140 }
141 
143 {
144  if (m_NB) {
145  if (m_NBRect.height < size.GetHeight())
146  m_NBRect.height = size.GetHeight();
147  m_NBRect.width += size.GetWidth();
148  }
149 }
150 
CBaseTextOStream(wxDC &dc, int x, int y, size_t rowHeight, size_t indentStep)
const CTextStyle * m_CurrentStyle
void x_UpdateNBRect(wxSize size)
virtual void NBtoggle()
virtual void NewLine()
virtual void SetStyle(const CTextStyle *style)
void x_UpdatePos(int chars, int width)
virtual void SetDefaultStyle()
virtual void x_OnNBEnd()
virtual void NewLine()=0
void WriteMultiLineText(const string &text)
virtual void x_OnNBStart()
wxColor GetTextForeground() const
wxColor GetTextBackground() const
bool IsTextBold() const
bool IsTextItalic() const
int GetBackgroundMode() const
#define false
Definition: bool.h:36
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3452
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2510
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
static void text(MDB_val *v)
Definition: mdb_dump.c:62
const struct ncbi::grid::netcache::search::fields::SIZE size
static const BitmapCharRec *const chars[]
Definition: ncbi_10x20.c:1829
Modified on Fri Sep 20 14:57:34 2024 by modify_doxy.py rev. 669887