Wtx ~ Wt Extension Library
WtxLib
FieldDefLineEdit.cpp
1 /**************************************************************************
2 ###########################################################################
3 ##
4 ## $SHOWOFFDB_BEGIN_LICENSE$
5 ## Copyright (C) 2011 Lorimark Solutions, LLC and/or its subsidiary(-ies).
6 ## All rights reserved.
7 ## Contact: Lorimark Solutions, LLC (info@showoff-db.org)
8 ##
9 ## This file is part of the Showoff Database Application Framework.
10 ##
11 ## Commercial Usage
12 ## Licensees holding valid ShowoffDB Commercial licenses may use this file in
13 ## accordance with the ShowoffDB Commercial License Agreement provided with the
14 ## Software or, alternatively, in accordance with the terms contained in
15 ## a written agreement between you and Lorimark Solutions, LLC.
16 ##
17 ## GNU Lesser General Public License Usage
18 ## Alternatively, this file may be used under the terms of the GNU Lesser
19 ## General Public License version 2.1 as published by the Free Software
20 ## Foundation and appearing in the file LICENSE.LGPL included in the
21 ## packaging of this file. Please review the following information to
22 ## ensure the GNU Lesser General Public License version 2.1 requirements
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ##
25 ## In addition, as a special exception, Lorimark Solutions, LLC gives
26 ## you certain additional rights. These rights are described in the
27 ## Lorimark Solutions, LLC ShowoffDB LGPL Exception version 1.0, included in
28 ## the file LGPL_EXCEPTION.txt in this package.
29 ##
30 ## GNU General Public License Usage
31 ## Alternatively, this file may be used under the terms of the GNU
32 ## General Public License version 3.0 as published by the Free Software
33 ## Foundation and appearing in the file LICENSE.GPL included in the
34 ## packaging of this file. Please review the following information to
35 ## ensure the GNU General Public License version 3.0 requirements will be
36 ## met: http://www.gnu.org/copyleft/gpl.html.
37 ##
38 ## If you have questions regarding the use of this file, please contact
39 ## Lorimark Solutions, LLC at info@showoff-db.org.
40 ## $SHOWOFFDB_END_LICENSE$
41 ##
42 #############################################################################
43 ****************************************************************************/
44 
45 #include <Wt/WEvent.h>
46 #include <Wt/WLineEdit.h>
47 #include <Wt/WRegExpValidator.h>
48 
49 #include <Wtx/Util/Util.h>
50 
51 #include "FieldDefLineEdit.h"
52 
54 (
55  TableDef & td,
56  const char * fn,
57  int w,
58  int h,
59  Flags f,
60  std::string lb,
61  std::string ph,
62  std::string inf,
63  std::string tt,
64  int ht
65 )
66 : Wtx::Dbo::FieldDefBase( td, fn, w, w, f, lb, ph, inf, tt, ht )
67 {
68 }
69 
71 (
72  TableDef & td,
73  const char * fn,
74  std::string lb,
75  std::string ph,
76  std::string inf,
77  std::string tt,
78  int ht
79 )
80 : Wtx::Dbo::FieldDefBase( td, fn, lb, ph, inf, tt, ht )
81 {
82 }
83 
84 /*
85 ** This object incorporates features such as forceUppercase() and
86 ** so on.
87 **
88 */
89 class SmartLineEdit
90 : public Wt::WLineEdit
91 {
92  void init()
93  {
94  /*
95  ** only hook force-uppercase if it's been asked for.
96  **
97  */
98  if( m_fieldDef.forceUppercase() )
99  {
100  Wt::WLineEdit::blurred().connect( this, &SmartLineEdit::on_blurred );
101  }
102 
103  }
104 
105  public:
106 
107  SmartLineEdit( const Wtx::Dbo::FieldDefBase & fieldDef )
108  : Wt::WLineEdit(),
109  m_fieldDef(fieldDef)
110  {
111  init();
112  }
113 
114  SmartLineEdit( const Wtx::Dbo::FieldDefBase & fieldDef, const Wt::WString & content )
115  : Wt::WLineEdit(content),
116  m_fieldDef(fieldDef)
117  {
118  init();
119  }
120 
121 
122  private:
123 
124  /*
125  ** Do post-processing of the field input, such as forcing the content
126  ** to be all upper-case.
127  **
128  */
129  void on_blurred()
130  {
131  if( m_fieldDef.forceUppercase() )
132  {
133  setValueText( Wtx::ucase( valueText().toUTF8() ) );
134  }
135 
136  }
137 
138  const Wtx::Dbo::FieldDefBase & m_fieldDef;
139 
140 }; // endclass SmartLineEdit
141 
142 
143 
144 std::unique_ptr<Wt::WWidget> Wtx::Dbo::FieldDefLineEdit::createEditWidget( int sid, Wtx::Dbo::Session & session ) const
145 {
146  auto retVal = std::make_unique<SmartLineEdit>(*this);
147 // auto retVal = std::make_unique<Wt::WLineEdit>();
148 
149  retVal-> setToolTip( toolTip() );
150  retVal-> setPlaceholderText( placeholderText() );
151  retVal-> setInputMask( inputMask() );
152 
153  /*
154  ** the validator only 'checks' input for proper content, it does
155  ** not ~mask~ the input to prevent typing wrong characters. What
156  ** we want is to simply ~force~ all input to appear as upper-case
157  ** characters, so we will use the custom object above until we have
158  ** a better solution.
159  **
160  */
161 // if( forceUppercase() )
162 // {
163 // auto validator = std::make_shared<Wt::WRegExpValidator>("[A-Z0-9]+");
164 //
165 // retVal-> setValidator( validator );
166 //
167 // }
168 
169  return retVal;
170 }
171 
172 
173 
Table Definition.
Definition: TableDef.h:72
FieldDefLineEdit(TableDef &td, const char *fn, int w=-1, int h=-1, Flags f=Flags::None, std::string lb="", std::string ph="", std::string inf="", std::string tt="", int ht=-1)
ctor
std::string ucase(const std::string &value)
Upper Case a string.
Definition: Util.cpp:441
Flags
Field Definition Flags.
Definition: FieldDefBase.h:101