1 /********************************************************************************
2 *                                                                               *
3 *                         I n p u t   D i a l o g   B o x                       *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 2000,2020 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify          *
9 * it under the terms of the GNU Lesser General Public License as published by   *
10 * the Free Software Foundation; either version 3 of the License, or             *
11 * (at your option) any later version.                                           *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
16 * GNU Lesser General Public License for more details.                           *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public License      *
19 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
20 ********************************************************************************/
21 #ifndef FXINPUTDIALOG_H
22 #define FXINPUTDIALOG_H
23 
24 #ifndef FXDIALOGBOX_H
25 #include "FXDialogBox.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 /// Input dialog options
32 enum {
33   INPUTDIALOG_STRING   = 0,             /// Ask for a string
34   INPUTDIALOG_INTEGER  = 0x02000000,    /// Ask for an integer number
35   INPUTDIALOG_REAL     = 0x04000000,    /// Ask for a real number
36   INPUTDIALOG_PASSWORD = 0x08000000     /// Do not reveal key-in
37   };
38 
39 
40 class FXTextField;
41 
42 
43 /**
44 * An Input Dialog is a simple dialog which is used
45 * to obtain a text string, integer, or real number from the user.
46 * A password mode allows the key-in to remain hidden.
47 */
48 class FXAPI FXInputDialog : public FXDialogBox {
49   FXDECLARE(FXInputDialog)
50 protected:
51   FXTextField *input;       // Text field widget
52   FXdouble     limlo;       // Lower limit
53   FXdouble     limhi;       // Upper limit
54 protected:
FXInputDialog()55   FXInputDialog(){}
56 private:
57   FXInputDialog(const FXInputDialog&);
58   FXInputDialog &operator=(const FXInputDialog&);
59   virtual void initialize(const FXString& text,FXIcon* icon);
60 public:
61   long onCmdAccept(FXObject*,FXSelector,void*);
62 public:
63 
64   /// Construct input dialog box with given caption, icon, and prompt text
65   FXInputDialog(FXWindow* owner,const FXString& caption,const FXString& label,FXIcon* icon=NULL,FXuint opts=INPUTDIALOG_STRING,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
66 
67   /// Construct free floating input dialog box with given caption, icon, and prompt text
68   FXInputDialog(FXApp* app,const FXString& caption,const FXString& label,FXIcon* icon=NULL,FXuint opts=INPUTDIALOG_STRING,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
69 
70   /// Get input string
71   FXString getText() const;
72 
73   /// Set input string
74   void setText(const FXString& text);
75 
76   /// Change number of visible columns of text
77   void setNumColumns(FXint num);
78 
79   /// Return number of visible columns of text
80   FXint getNumColumns() const;
81 
82   /// Change limits
setLimits(FXdouble lo,FXdouble hi)83   void setLimits(FXdouble lo,FXdouble hi){ limlo=lo; limhi=hi; }
84 
85   /// Return limits
getLimits(FXdouble & lo,FXdouble & hi)86   void getLimits(FXdouble& lo,FXdouble& hi){ lo=limlo; hi=limhi; }
87 
88   /// Run modal invocation of the dialog
89   virtual FXuint execute(FXuint placement=PLACEMENT_CURSOR);
90 
91   /**
92   * Prompt for a string, start with the initial value.
93   * Return true if the new value is accepted, and false otherwise.
94   */
95   static FXbool getString(FXString& result,FXWindow* owner,const FXString& caption,const FXString& label,FXIcon* icon=NULL);
96 
97   /**
98   * Prompt for a string, in free floating window.
99   */
100   static FXbool getString(FXString& result,FXApp* app,const FXString& caption,const FXString& label,FXIcon* icon=NULL);
101 
102   /**
103   * Prompt for an integer number, start with the given initial value.
104   * Return true if the new value is accepted, and false otherwise.
105   * The input is constrained between lo and hi.
106   */
107   static FXbool getInteger(FXint& result,FXWindow* owner,const FXString& caption,const FXString& label,FXIcon* icon=NULL,FXint lo=-2147483647,FXint hi=2147483647);
108 
109   /**
110   * Prompt for a integer number, in free floating window.
111   */
112   static FXbool getInteger(FXint& result,FXApp* app,const FXString& caption,const FXString& label,FXIcon* icon=NULL,FXint lo=-2147483647,FXint hi=2147483647);
113 
114   /**
115   * Prompt for an real number, start with the given initial value.
116   * Return true if the new value is accepted, and false otherwise.
117   * The input is constrained between lo and hi.
118   */
119   static FXbool getReal(FXdouble& result,FXWindow* owner,const FXString& caption,const FXString& label,FXIcon* icon=NULL,FXdouble lo=-1.797693134862315e+308,FXdouble hi=1.797693134862315e+308);
120 
121   /**
122   * Prompt for a real number, in free floating window.
123   */
124   static FXbool getReal(FXdouble& result,FXApp* app,const FXString& caption,const FXString& label,FXIcon* icon=NULL,FXdouble lo=-1.797693134862315e+308,FXdouble hi=1.797693134862315e+308);
125   };
126 
127 }
128 
129 #endif
130