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

Go to the SVN repository for this file.

1 /* $Id: calc_textpos_stream.cpp 47479 2023-05-02 13:24:02Z ucko $
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  size_t rowHeight, size_t indentStep,
41  int mouseX, int mouseY) :
42  CBaseTextOStream(dc, x, y, rowHeight, indentStep),
43  m_MouseX(mouseX), m_MouseY(mouseY), m_TextPosX(0),
44  m_NBStartChar(0), m_NBRow(0)
45 
46 {
47  m_TextPosY = (m_MouseY >= m_RowHeight) ? 1 : 0;
48 }
49 
51 {
53 
54  if (m_MouseY >= (m_Row + 1)*m_RowHeight)
55  m_TextPosY = m_Row + 1;
56 }
57 
59 {
60  wxString text = ToWxString(text_in);
61  int length = static_cast<int>(text.length());
62  if (length == 0)
63  return *this;
64 
65  wxArrayInt widths;
66  m_DC.GetPartialTextExtents(text, widths);
67 
68  if (m_MouseY >= (int)(m_Row*m_RowHeight) &&
69  m_MouseY < (int)((m_Row + 1)*m_RowHeight)) {
70 
71  m_Ostr << text_in;
72 
73  m_TextPosY = m_Row;
74 
75  if (!x_InNB() && m_MouseX >= m_x) {
76  wxArrayInt::iterator it;
77  if (length < 5)
78  for (it = widths.begin();
79  it != widths.end() && m_MouseX-m_x > *it;
80  ++it);
81  else
82  it = lower_bound(widths.begin(), widths.end(), m_MouseX-m_x);
83 
84  if (it != widths.end()) {
85  int charWidth = *it;
86  if (it != widths.begin())
87  charWidth -= *(it-1);
88  if (m_MouseX-m_x + charWidth/2 >= *it)
89  ++it;
90  }
91  m_TextPosX = static_cast<int>(it - widths.begin() + m_CurrentLineLength);
92  if (it != widths.begin())
93  --it;
94  }
95  }
96 
97  x_UpdatePos(length, widths[length-1]);
98  if (x_InNB()) x_UpdateNBRect(wxSize(widths[length-1], m_RowHeight));
99 
100  return *this;
101 }
102 
103 void CCalcTextPosOStream::Indent (size_t steps)
104 {
105  if (steps == 0)
106  return;
107 
108  size_t w = m_IndentStep*steps;
109 
110  if (m_MouseY >= (int)(m_Row*m_RowHeight) &&
111  m_MouseY < (int)((m_Row + 1)*m_RowHeight)) {
112 
113  m_Ostr << string(steps, ' ');
114 
115  m_TextPosY = m_Row;
116 
117  if (!x_InNB() && m_MouseX >= m_x) {
118  size_t index = (m_MouseX - m_x + m_IndentStep/2)/m_IndentStep;
119  m_TextPosX = static_cast<int>(min(index, steps) + m_CurrentLineLength);
120  }
121  }
122 
123  x_UpdatePos(static_cast<int>(steps), static_cast<int>(w));
124  if (x_InNB()) x_UpdateNBRect(wxSize(static_cast<int>(w), m_RowHeight));
125 }
126 
128 {
129  m_NBRow = m_Row;
131 }
132 
134 {
135  wxRect rect = GetNBRect();
136 
137  if (m_MouseY >= rect.GetTop() && m_MouseY <= rect.GetBottom() &&
138  m_MouseX >= rect.GetLeft()) {
139 
140  m_TextPosY = m_Row;
141 
142  if ((m_MouseX - rect.GetLeft())*2 < rect.width)
144  else
146  }
147 }
148 
void x_UpdateNBRect(wxSize size)
virtual void NewLine()
void x_UpdatePos(int chars, int width)
virtual bool x_InNB() const
wxRect GetNBRect() const
virtual void Indent(size_t steps)
CCalcTextPosOStream(wxDC &dc, int x, int y, size_t rowHeight, size_t indentStep, int mouseX, int mouseY)
virtual CStyledTextOStream & operator<<(const string &text_in)
string
Definition: cgiapp.hpp:687
#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 void text(MDB_val *v)
Definition: mdb_dump.c:62
T min(T x_, T y_)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Thu May 30 12:28:30 2024 by modify_doxy.py rev. 669887