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

Go to the SVN repository for this file.

1 /* $Id: components.cpp 33815 2007-05-04 17:18:18Z kazimird $
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  * Author: Lewis Geer
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 #include <html/components.hpp>
32 #include <html/nodemap.hpp>
33 
34 
36 
37 
39 {
40  return;
41 }
42 
43 
45  : m_Name(name)
46 {
47  return;
48 }
49 
50 
51 CSubmitDescription::CSubmitDescription(const string& name, const string& label)
52  : m_Name(name), m_Label(label)
53 {
54  return;
55 }
56 
57 
59 {
60  if ( m_Name.empty() ) {
61  return 0;
62  }
63  if ( m_Label.empty() ) {
64  return new CHTML_submit(m_Name);
65  }else {
66  return new CHTML_submit(m_Name, m_Label);
67  }
68 }
69 
70 
72 {
73  if ( m_Value.empty() ) {
74  return new CHTML_option(m_Label, m_Label == def);
75  } else if ( m_Label.empty() ) {
76  return new CHTML_option(m_Value, m_Value == def);
77  } else {
78  return new CHTML_option(m_Value, m_Label, m_Value == def);
79  }
80 }
81 
82 
84 {
85  return;
86 }
87 
88 
90  : m_Name(name)
91 {
92  return;
93 }
94 
95 
96 void CSelectDescription::Add(const string& value)
97 {
98  m_List.push_back(COptionDescription(value));
99 }
100 
101 
102 void CSelectDescription::Add(const string& value, const string& label)
103 {
104  m_List.push_back(COptionDescription(value, label));
105 }
106 
107 
109 {
110  if ( m_Name.empty() || m_List.empty() ) {
111  return 0;
112  }
113  CNCBINode* select = new CHTML_select(m_Name);
114  for ( list<COptionDescription>::const_iterator i = m_List.begin();
115  i != m_List.end(); ++i ) {
116  select->AppendChild(i->CreateComponent(m_Default));
117  }
118  if ( !m_TextBefore.empty() || !m_TextAfter.empty() ) {
119  CNCBINode* combine = new CNCBINode;
120  if ( !m_TextBefore.empty() ) {
121  combine->AppendChild(new CHTMLPlainText(m_TextBefore));
122  }
123  combine->AppendChild(select);
124  if ( !m_TextAfter.empty() ) {
125  combine->AppendChild(new CHTMLPlainText(m_TextAfter));
126  }
127  select = combine;
128  }
129  return select;
130 }
131 
132 
134  : m_Width(0)
135 {
136  return;
137 }
138 
139 
141  : m_Name(name), m_Width(0)
142 {
143  return;
144 }
145 
146 
148 {
149  if ( m_Name.empty() ) {
150  return 0;
151  }
152  if ( m_Width ) {
153  return new CHTML_text(m_Name, m_Width, m_Value);
154  } else {
155  return new CHTML_text(m_Name, m_Value);
156  }
157 }
158 
159 
161  : m_Submit("cmd", "Search"), m_Database("db"),
162  m_Term("term"), m_DispMax("dispmax"),
163  m_Width(-1)
164 {
165  SetCellSpacing(0);
166  SetCellPadding(5);
167  m_Database.m_TextBefore = "Search ";
168  m_Database.m_TextAfter = "for";
169  m_DispMax.m_TextBefore = "Show ";
170  m_DispMax.m_TextAfter = "documents per page";
171 }
172 
173 
175 {
177  if ( m_Width >= 0 ) {
178  SetWidth(m_Width);
179  }
180  CheckTable();
181  int row = CalculateNumberOfRows();
182 
183  InsertAt(row, 0, m_Database.CreateComponent())->SetColSpan(2);
184  InsertAt(row + 1, 0, m_Term.CreateComponent());
185  InsertAt(row + 1, 0, m_Submit.CreateComponent());
186  InsertAt(row + 2, 0, m_DispMax.CreateComponent());
187 }
188 
189 
191 {
192  return 0;
193 }
194 
195 
196 // Pager
197 
199 {
200  return;
201 }
202 
204 {
205  CNCBINode* select = m_List.CreateComponent();
206  if ( select ) {
208  AppendChild(select);
209  }
210 }
211 
212 
214  : m_Current(-1)
215 {
216  SetCellSpacing(2);
217 }
218 
219 
220 void CPageList::x_AddImageString(CNCBINode* node, const string& name, int number,
221  const string& imageStart, const string& imageEnd)
222 {
223  string s = NStr::IntToString(number);
224 
225  for ( size_t i = 0; i < s.size(); ++i ) {
226  node->AppendChild(new CHTML_image(name, imageStart + s[i] + imageEnd, 0));
227  }
228 }
229 
230 
232  int number,
233  const string& imageStart,
234  const string& imageEnd)
235 {
236  string s = NStr::IntToString(number);
237 
238  for ( size_t i = 0; i < s.size(); ++i ) {
239  node->AppendChild(new CHTML_img(imageStart + s[i] + imageEnd));
240  }
241 }
242 
243 
245 {
246  int column = 0;
247  if ( !m_Backward.empty() ) {
248  InsertAt(0, column++,
249  new CHTML_image(m_Backward, "/images/prev.gif", 0));
250  }
252  i != m_Pages.end(); ++i ) {
253  if ( i->first == m_Current ) {
254  // Current link
255  x_AddInactiveImageString(Cell(0, column++), i->second, i->first, "/images/black_", ".gif");
256  }
257  else {
258  // Normal link
259  x_AddImageString(Cell(0, column++), i->second, i->first, "/images/", ".gif");
260  }
261  }
262  if ( !m_Forward.empty() ) {
263  InsertAt(0, column++, new CHTML_image(m_Forward, "/images/next.gif", 0));
264  }
265 }
266 
267 
268 // Pager box
269 
271  : m_Width(460),
272  m_TopButton(new CButtonList),
273  m_LeftButton(new CButtonList),
274  m_RightButton(new CButtonList),
275  m_PageList(new CPageList),
276  m_NumResults(0),
277  m_BgColor("#c0c0c0")
278 {
279  return;
280 }
281 
282 
284 {
286  CHTML_table* tableTop;
287  CHTML_table* tableBot;
288 
289  table = new CHTML_table();
291  AppendChild(table);
292 
293  tableTop = new CHTML_table();
294  tableTop->SetCellSpacing(0)->SetCellPadding(0)->SetWidth(m_Width);
295  tableBot = new CHTML_table();
296  tableBot->SetCellSpacing(0)->SetCellPadding(0)->SetWidth(m_Width);
297 
298  table->InsertAt(0, 0, tableTop);
299  table->InsertAt(1, 0, tableBot);
300  tableTop->InsertAt(0, 0, m_TopButton);
301  tableTop->InsertAt(0, 1, m_PageList);
302  tableBot->InsertAt(0, 0, m_LeftButton);
303  tableBot->InsertAt(0, 1, m_RightButton);
304  tableBot->InsertAt(0, 2, new CHTMLText(NStr::IntToString(m_NumResults) + ((m_NumResults==1)?" result":" results")));
305 }
306 
307 
309  : m_Width(460), m_PageList(0), m_NumResults(0)
310 {
311  return;
312 }
313 
314 
316 {
317  CHTML_table* Table = new CHTML_table();
318  AppendChild(Table);
320  ->SetWidth(m_Width)->SetAttribute("border", 0);
321 
322  Table->InsertAt(0, 0, new CPageList);
323  Table->InsertAt(0, 1, new CHTMLText(NStr::IntToString(m_NumResults) + ((m_NumResults==1)?" result":" results")));
324 }
325 
326 
int m_NumResults
Definition: components.hpp:195
string m_BgColor
Definition: components.hpp:138
CNCBINode * AppendChild(CNCBINode *child)
CNCBINode * CreateComponent(void) const
Definition: components.cpp:147
CSubmitDescription m_Submit
Definition: components.hpp:132
CHTMLNode * SetWidth(int width)
CButtonList * m_LeftButton
Definition: components.hpp:192
void x_AddInactiveImageString(CNCBINode *node, const string &name, int number, const string &imageStart, const string &imageEnd)
Definition: components.cpp:231
CNCBINode * CreateComponent(const string &def) const
Definition: components.cpp:71
CHTMLNode * SetBgColor(const string &color)
CSelectDescription m_Database
Definition: components.hpp:133
CHTML_tc * InsertAt(TIndex row, TIndex column, CNCBINode *node)
void CheckTable(void) const
Definition: html.cpp:1287
CHTML_tc * Cell(TIndex row, TIndex column, ECellType type=eAnyCell)
Definition: html.cpp:1271
void x_AddImageString(CNCBINode *node, const string &name, int number, const string &imageStart, const string &imageEnd)
Definition: components.cpp:220
string m_Backward
Definition: components.hpp:169
virtual void CreateSubNodes(void)
Definition: components.cpp:315
CButtonList * m_TopButton
Definition: components.hpp:191
CHTML_table * SetCellSpacing(int spacing)
CPageList(void)
Definition: components.cpp:213
int i
string m_Forward
Definition: components.hpp:168
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:4808
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
const_iterator end() const
Definition: map.hpp:152
CPageList * m_PageList
Definition: components.hpp:194
map< int, string > m_Pages
Definition: components.hpp:167
string m_BgColor
Definition: components.hpp:196
void Add(const string &value)
Definition: components.cpp:96
CSubmitDescription m_Button
Definition: components.hpp:152
CSmallPagerBox(void)
Definition: components.cpp:308
TIndex CalculateNumberOfRows(void) const
Definition: html.cpp:1302
static const char label[]
CNCBINode * CreateComponent(void) const
Definition: components.cpp:58
Definition: map.hpp:337
static const char * column
Definition: stats.c:23
CButtonList(void)
Definition: components.cpp:198
Various tag mappers classes.
static const char * table
Definition: stats.c:22
virtual void CreateSubNodes(void)
Definition: components.cpp:203
CNCBINode * CreateComponent(void) const
Definition: components.cpp:108
list< COptionDescription > m_List
Definition: components.hpp:92
virtual void CreateSubNodes(void)
Definition: components.cpp:174
virtual CNCBINode * CreateComments(void)
Definition: components.cpp:190
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1185
CTextInputDescription m_Term
Definition: components.hpp:134
The HTML page.
CButtonList * m_RightButton
Definition: components.hpp:193
static BOOL number
Definition: pcregrep.c:167
CSelectDescription m_DispMax
Definition: components.hpp:135
CPagerBox(void)
Definition: components.cpp:270
virtual void CreateSubNodes(void)
Definition: components.cpp:283
const_iterator begin() const
Definition: map.hpp:151
CQueryBox(void)
Definition: components.cpp:160
void SetAttribute(const string &name, const string &value)
CHTML_table * SetCellPadding(int padding)
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
CSelectDescription m_List
Definition: components.hpp:153
virtual void CreateSubNodes(void)
Definition: components.cpp:244
Modified on Sat Feb 24 14:01:47 2018 by modify_doxy.py rev. 546573