1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSGUI_VALIDATOR
15#define OSGUI_VALIDATOR
18#include <osgUI/Export>
23class OSGUI_EXPORT Validator : public osg::Object
27 Validator(const Validator& validator, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
28 META_Object(osgUI, Validator);
37 /** entry point to validate(..) method, checks for "validate" CallbackObject and calls it if present, otherwise calls validateImplementation(..)
38 str parameter is the string that needs to be validated
39 cursorpos is the position of the cursor within the str string.
40 return validatidy State. */
41 virtual State validate(std::string& /*str*/, int& cursorpos) const;
43 /// override in subclasses to proviude the validate implementation.
44 virtual State validateImplementation(std::string& /*str*/, int& /*cursorpos*/) const;
46 /** entry point to fixup, checks for "validate" Callbac Object and calls it if present, otherwise calls validateImplementation(..)
47 fixup(..) is called when user pressers return/enter in a field being edited.
48 str parameter is string that needs to be corrected.*/
49 virtual void fixup(std::string& /*str*/) const;
51 /// override in subclass to provide the fixup implementation.
52 virtual void fixupImplementation(std::string& /*str*/) const;
55 virtual ~Validator() {}
58class OSGUI_EXPORT IntValidator : public Validator
62 IntValidator(const IntValidator& widget, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
63 META_Object(osgUI, IntValidator);
65 /// set the bottom value that is accepted as valid, default -INT_MAX
66 void setBottom(int bottom) { _bottom = bottom; }
67 int getBottom() const { return _bottom; }
69 /// set the top value that is accepted as valid, default INT_MAX
70 void setTop(int top) { _top = top; }
71 int getTop() const { return _top; }
73 /// override validate implementation.
74 virtual State validateImplementation(std::string& str, int& cursorpos) const;
75 /// override validate implementation.
76 virtual void fixupImplementation(std::string& str) const;
79 virtual ~IntValidator() {}
84class OSGUI_EXPORT DoubleValidator : public Validator
88 DoubleValidator(const DoubleValidator& widget, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
89 META_Object(osgUI, DoubleValidator);
91 /** set the number of decimal places to accept, default is -1,
92 all negative values disable validation against maximum number of places thus allows any number of decimals places. */
93 void setDecimals(int numDecimals) { _decimals = numDecimals; }
94 int getDecimals() const { return _decimals; }
96 /// set the bottom value that is accepted as valid, default -DBL_MAX
97 void setBottom(double bottom) { _bottom = bottom; }
98 double getBottom() const { return _bottom; }
100 /// set the top value that is accepted as valid, default DBL_MAX
101 void setTop(double top) { _top = top; }
102 double getTop() const { return _top; }
104 /// override validate implementation.
105 virtual State validateImplementation(std::string& str, int& cursorpos) const;
106 /// override validate implementation.
107 virtual void fixupImplementation(std::string& str) const;
110 virtual ~DoubleValidator() {}