1 /********************************************************************************
2 * *
3 * R e d u c e M e n u s D i a l o g *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2000,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 * (built by A C Norman based in FXReplaceDialog.cpp, 2014 *
8 *********************************************************************************
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU Lesser General Public *
11 * License as published by the Free Software Foundation; either *
12 * version 2.1 of the License. The A C Norman extensions here must not have *
13 * GPL 2.1 compatibility removed, but as a special concession may be used with *
14 * GPL 3 code. *
15 * This library is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18 * Lesser General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU Lesser General Public *
21 * License along with this library; if not, write to the Free Software *
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
23 *********************************************************************************
24 * $Id: FXReduceDialog.cpp 3297 2015-12-14 20:30:04Z arthurcnorman $ *
25 ********************************************************************************/
26 #include "xincs.h"
27 #include "fxver.h"
28 #include "fxdefs.h"
29 #include "fxkeys.h"
30 #include "FXHash.h"
31 #include "FXThread.h"
32 #include "FXStream.h"
33 #include "FXString.h"
34 #include "FXSize.h"
35 #include "FXPoint.h"
36 #include "FXRectangle.h"
37 #include "FXRegistry.h"
38 #include "FXAccelTable.h"
39 #include "FXApp.h"
40 #include "FXFont.h"
41 #include "FXImage.h"
42 #include "FXIcon.h"
43 #include "FXGIFIcon.h"
44 #include "FXWindow.h"
45 #include "FXFrame.h"
46 #include "FXArrowButton.h"
47 #include "FXSeparator.h"
48 #include "FXLabel.h"
49 #include "FXButton.h"
50 #include "FXCheckButton.h"
51 #include "FXRadioButton.h"
52 #include "FXPacker.h"
53 #include "FXScrollBar.h"
54 #include "FXTextField.h"
55 #include "FXVerticalFrame.h"
56 #include "FXHorizontalFrame.h"
57 #include "FXReduceDialog.h"
58
59
60 using namespace FX;
61
62 /*******************************************************************************/
63
64 namespace FX {
65
66
67 // Map
68 FXDEFMAP(FXReduceDialog) FXReduceDialogMap[]={
69 FXMAPFUNC(SEL_COMMAND,FXReduceDialog::ID_ACCEPT,FXReduceDialog::onCmdAccept),
70 };
71
72
73 // Object implementation
FXIMPLEMENT(FXReduceDialog,FXDialogBox,FXReduceDialogMap,ARRAYNUMBER (FXReduceDialogMap))74 FXIMPLEMENT(FXReduceDialog,FXDialogBox,FXReduceDialogMap,ARRAYNUMBER(FXReduceDialogMap))
75
76
77 // Generic Reduce Dialog
78 FXReduceDialog::FXReduceDialog(FXWindow* owner1,const FXString& caption,FXIcon* ic,FXuint opts,FXint x,FXint y,FXint w,FXint h):
79 FXDialogBox(owner1,caption,opts|DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE,x,y,w,h,10,10,10,10, 10,10)
80 {
81 #if 0
82 FXHorizontalFrame* buttons=new FXHorizontalFrame(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH|PACK_UNIFORM_HEIGHT,0,0,0,0,0,0,0,0);
83 accept=new FXButton(buttons,tr("&Reduce"),NULL,this,ID_ACCEPT,BUTTON_INITIAL|BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_Y|LAYOUT_RIGHT,0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
84 cancel=new FXButton(buttons,tr("&Cancel"),NULL,this,ID_CANCEL,BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_Y|LAYOUT_RIGHT,0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
85 FXHorizontalFrame* pair=new FXHorizontalFrame(buttons,LAYOUT_FILL_Y|LAYOUT_RIGHT,0,0,0,0, 0,0,0,0);
86 FXHorizontalFrame* toppart=new FXHorizontalFrame(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0, 10,10);
87 new FXLabel(toppart,FXString::null,ic,ICON_BEFORE_TEXT|JUSTIFY_CENTER_X|JUSTIFY_CENTER_Y|LAYOUT_FILL_Y|LAYOUT_FILL_X);
88 FXVerticalFrame* entry=new FXVerticalFrame(toppart,LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0);
89 searchlabel=new FXLabel(entry,tr("S&earch for:"),NULL,JUSTIFY_LEFT|ICON_BEFORE_TEXT|LAYOUT_TOP|LAYOUT_LEFT|LAYOUT_FILL_X);
90 searchbox=new FXHorizontalFrame(entry,FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0, 0,0);
91 searchtext=new FXTextField(searchbox,26,this,ID_SEARCH_TEXT,TEXTFIELD_ENTER_ONLY|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 4,4,4,4);
92 FXVerticalFrame* searcharrows=new FXVerticalFrame(searchbox,LAYOUT_RIGHT|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0, 0,0);
93 current=0;
94 #endif
95 }
96
97
98 // Return text or pattern the user has entered
getReduceText() const99 FXString FXReduceDialog::getReduceText() const {
100 // return resulttext->getText();
101 return FXString("Boo!;");
102 }
103
104
105 // Return from the dialog
onCmdAccept(FXObject *,FXSelector,void *)106 long FXReduceDialog::onCmdAccept(FXObject*,FXSelector,void*){
107 #if 0
108 getApp()->stopModal(this,REPLACE);
109 #else
110 getApp()->stopModal(this,0);
111 #endif
112 hide();
113 return 1;
114 }
115
116
117
118 // Force the initial text to be selected
execute(FXuint placement)119 FXuint FXReduceDialog::execute(FXuint placement){
120 create();
121 // searchtext->setFocus();
122 show(placement);
123 return getApp()->runModalFor(this);
124 }
125
126
127 // Cleanup
~FXReduceDialog()128 FXReduceDialog::~FXReduceDialog(){
129 #if 0
130 searchlabel=(FXLabel*)-1L;
131 searchtext=(FXTextField*)-1L;
132 searchbox=(FXHorizontalFrame*)-1L;
133 replacelabel=(FXLabel*)-1L;
134 replacetext=(FXTextField*)-1L;
135 replacebox=(FXHorizontalFrame*)-1L;
136 #endif
137 accept=(FXButton*)-1L;
138 cancel=(FXButton*)-1L;
139 }
140
141 //@@ class FXAPI FXReduceInputDialog : public FXDialogBox {
142 //@@ FXDECLARE(FXReduceInputDialog)
143 //@@ protected:
144 //@@ FXTextField *input[7]; // Text field widgets
145 //@@ protected:
146 //@@ FXReduceInputDialog(){}
147 //@@ private:
148 //@@ FXReduceInputDialog(const FXReduceInputDialog&);
149 //@@ FXReduceInputDialog &operator=(const FXReduceInputDialog&);
150 //@@ void initialize(int num, const FXString labels[]);
151 //@@ public:
152 //@@ long onCmdAccept(FXObject*,FXSelector,void*);
153 //@@ public:
154 //@@
155 //@@ /// Construct input dialog box with given caption, icon, and prompt text
156 //@@ FXReduceInputDialog(FXWindow* owner1,const FXString& caption,
157 //@@ int num, const FXString labels[];
158 //@@ FXint x=0,FXint y=0,FXint w=0,FXint h=0);
159 //@@
160 //@@ /// Get input string
161 //@@ FXString getText(int num) const;
162 //@@
163 //@@ /// Set input string
164 //@@ void setText(int num, const FXString& text);
165 //@@
166 //@@ /// Run modal invocation of the dialog
167 //@@ virtual FXuint execute(FXuint placement=PLACEMENT_CURSOR);
168 //@@
169 //@@ };
170
171 // Padding for buttons
172 #define HORZ_PAD 20
173 #define VERT_PAD 2
174
175 /*******************************************************************************/
176
177 // Map
178 FXDEFMAP(FXReduceInputDialog) FXReduceInputDialogMap[]={
179 FXMAPFUNC(SEL_COMMAND,FXReduceInputDialog::ID_ACCEPT,FXReduceInputDialog::onCmdAccept),
180 };
181
182
183 // Object implementation
FXIMPLEMENT(FXReduceInputDialog,FXDialogBox,FXReduceInputDialogMap,ARRAYNUMBER (FXReduceInputDialogMap))184 FXIMPLEMENT(FXReduceInputDialog,FXDialogBox,FXReduceInputDialogMap,ARRAYNUMBER(FXReduceInputDialogMap))
185
186
187
188
189 // Create input dialog box
190 FXReduceInputDialog::FXReduceInputDialog(FXWindow* owner1,
191 const FXString& caption,
192 int num, const FXString labels[], FXint x,FXint y,FXint w,FXint h):
193 FXDialogBox(owner1,caption,DECOR_TITLE|DECOR_BORDER,
194 x,y,w,h,10,10,10,10, 10,10){
195 initialize(num, labels);
196 }
197
198
199 // Build contents
initialize(int num,const FXString labels[])200 void FXReduceInputDialog::initialize(int num, const FXString labels[]){
201 FXuint textopts=
202 TEXTFIELD_ENTER_ONLY|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X;
203 FXHorizontalFrame* buttons=
204 new FXHorizontalFrame(this,
205 LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,0,0,0,0,0,0,0,0);
206 new FXButton(buttons,tr("&OK"),NULL,this,ID_ACCEPT,
207 BUTTON_INITIAL|BUTTON_DEFAULT|FRAME_RAISED|
208 FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT,
209 0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
210 new FXButton(buttons,tr("&Cancel"),NULL,this,ID_CANCEL,
211 BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT,
212 0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
213 new FXHorizontalSeparator(this,
214 SEPARATOR_GROOVE|LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X);
215 FXHorizontalFrame* toppart=
216 new FXHorizontalFrame(this,
217 LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0, 10,10);
218 //: new FXLabel(toppart,FXString::null,icon1,
219 //: ICON_BEFORE_TEXT|JUSTIFY_CENTER_X|JUSTIFY_CENTER_Y|
220 //: LAYOUT_FILL_Y|LAYOUT_FILL_X);
221 FXVerticalFrame* entry=
222 new FXVerticalFrame(toppart,
223 LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0);
224 int i;
225 for (i=0; i<num; i++) {
226 new FXLabel(entry,labels[i],NULL,
227 JUSTIFY_LEFT|ICON_BEFORE_TEXT|LAYOUT_TOP|LAYOUT_LEFT|LAYOUT_FILL_X);
228 input[i]=new FXTextField(entry,20,this,ID_ACCEPT,
229 textopts, 0,0,0,0, 8,8,4,4);
230 }
231 while (i < 7) input[i++] = NULL;
232 }
233
234
235 // Get input string
getText(int num) const236 FXString FXReduceInputDialog::getText(int num) const {
237 if (input[num] == NULL) return "";
238 else return input[num]->getText();
239 }
240
241
242 // Set input string
setText(int num,const FXString & text)243 void FXReduceInputDialog::setText(int num, const FXString& text){
244 if (input[num] != NULL) input[num]->setText(text);
245 }
246
247
248 // We have to do this so as to force the initial text to be seleced
execute(FXuint placement)249 FXuint FXReduceInputDialog::execute(FXuint placement){
250 create();
251 input[0]->setFocus();
252 input[0]->selectAll();
253 show(placement);
254 return getApp()->runModalFor(this);
255 }
256
257
258 // Close dialog with an accept.
onCmdAccept(FXObject * sender,FXSelector sel,void * ptr)259 long FXReduceInputDialog::onCmdAccept(FXObject* sender,FXSelector sel,void* ptr){
260 FXDialogBox::onCmdAccept(sender,sel,ptr);
261 return 1;
262 }
263
264 }
265
266 /*******************************************************************************/
267
268 // end of FXReduceDialog.cpp
269
270