1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
/********************************************************************************
* *
* Data Target Test *
* *
*********************************************************************************
* Copyright (C) 1997 by Jeroen van der Zijp. All Rights Reserved. *
*********************************************************************************
* $Id: datatarget.cpp,v 1.28 2001/09/05 05:47:23 jeroen Exp $ *
********************************************************************************/
#include "fx.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <signal.h>
#ifndef WIN32
#include <unistd.h>
#endif
/*******************************************************************************/
// Mini application object
class DataTargetWindow : public FXMainWindow {
FXDECLARE(DataTargetWindow)
protected:
FXMenubar* menubar;
FXMenuPane* filemenu;
FXMenuPane* optionmenu;
FXPopup* popup;
FXMatrix* matrix;
FXint some_int;
FXdouble some_double;
FXint some_option;
FXString some_string;
FXColor some_color;
FXint some_progress;
FXDataTarget int_target;
FXDataTarget double_target;
FXDataTarget string_target;
FXDataTarget option_target;
FXDataTarget color_target;
FXDataTarget progress_target;
FXProgressDialog *progressdialog;
public:
long onCmdTimer(FXObject*,FXSelector,void*);
long onCmdQuit(FXObject*,FXSelector,void*);
long onCmdProgress(FXObject*,FXSelector,void*);
long onCmdTextField(FXObject*,FXSelector,void*);
public:
DataTargetWindow(){}
public:
enum {
ID_TIMER=FXMainWindow::ID_LAST,
ID_PROGRESS,
ID_TEXTFIELD,
ID_QUIT
};
public:
DataTargetWindow(FXApp *a);
void create();
virtual ~DataTargetWindow();
};
/*******************************************************************************/
// Map
FXDEFMAP(DataTargetWindow) DataTargetWindowMap[]={
FXMAPFUNC(SEL_TIMEOUT,DataTargetWindow::ID_TIMER, DataTargetWindow::onCmdTimer),
FXMAPFUNC(SEL_SIGNAL, DataTargetWindow::ID_QUIT, DataTargetWindow::onCmdQuit),
FXMAPFUNC(SEL_COMMAND,DataTargetWindow::ID_PROGRESS, DataTargetWindow::onCmdProgress),
FXMAPFUNC(SEL_COMMAND,DataTargetWindow::ID_TEXTFIELD,DataTargetWindow::onCmdTextField),
};
// Object implementation
FXIMPLEMENT(DataTargetWindow,FXMainWindow,DataTargetWindowMap,ARRAYNUMBER(DataTargetWindowMap))
// Make some windows
DataTargetWindow::DataTargetWindow(FXApp* a):FXMainWindow(a,"Data Target Test",NULL,NULL,DECOR_ALL,20,20,700,460){
// Initialize some simple variables
some_int = 10;
some_double = 3.1415927;
some_string = "FOX";
some_color = FXRGB(255,0,0);
some_option = 0;
some_progress = 0;
// Connect INTEGER target
int_target.connect(some_int);
// Connect DOUBLE target
double_target.connect(some_double);
// Connect STRING target
string_target.connect(some_string);
// Connect COLOR target
color_target.connect(some_color);
// Connect option target
option_target.connect(some_option);
// Connect progress target
progress_target.connect(some_progress);
// Create progress dialog
progressdialog=new FXProgressDialog(this,"Progress","We zijn druk, we zijn druk\nWe zijn ongelooflijk druk.",PROGRESSDIALOG_CANCEL|DECOR_BORDER|DECOR_RESIZE);
progressdialog->setTarget(&int_target);
progressdialog->setSelector(FXDataTarget::ID_VALUE);
// Menubar
menubar=new FXMenubar(this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X);
// File menu
filemenu=new FXMenuPane(this);
new FXMenuCommand(filemenu,"Progress dialog...",NULL,this,ID_PROGRESS);
new FXMenuCommand(filemenu,"&Quit\tCtl-Q",NULL,getApp(),FXApp::ID_QUIT);
new FXMenuTitle(menubar,"&File",NULL,filemenu);
// Option menu
optionmenu=new FXMenuPane(this);
// The menu commands change the "some_option" variable via the option_target
new FXMenuCommand(optionmenu,"Option 1",NULL,&option_target,FXDataTarget::ID_OPTION+0);
new FXMenuCommand(optionmenu,"Option 2",NULL,&option_target,FXDataTarget::ID_OPTION+1);
new FXMenuCommand(optionmenu,"Option 3",NULL,&option_target,FXDataTarget::ID_OPTION+2);
new FXMenuCommand(optionmenu,"Option 4",NULL,&option_target,FXDataTarget::ID_OPTION+3);
new FXMenuTitle(menubar,"&Option",NULL,optionmenu);
// Lone progress bar at the bottom, which reflects the value of variable "some_progress"
new FXProgressBar(this,&progress_target,FXDataTarget::ID_VALUE,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|FRAME_SUNKEN|FRAME_THICK);
new FXHorizontalSeparator(this,LAYOUT_SIDE_TOP|SEPARATOR_GROOVE|LAYOUT_FILL_X);
FXHorizontalFrame *horframe=new FXHorizontalFrame(this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X);
new FXLabel(horframe,
"FXDataTarget can be used to connect a Widget to an application variable without any of the\n"
"tradional \"glue\" programming code.\n\n"
"The widgets below are connected (via FXDataTarget) to an integer, real, string, option, and\n"
"color variable, respectively.\n\n"
"Changing one of them will cause all widgets connected to the same FXDataTarget to \n"
"update so as to reflect the value of the application variable.\n\n"
"The progress bar below shows a time-varying variable, demonstrating that widgets\n"
"can be updated via FXDataTarget's regardless how the variables are changed.\n\n"
"Note that the \"Option\" pulldown menu is also connected to the option variable!",
NULL,LAYOUT_LEFT|JUSTIFY_LEFT);
new FXProgressBar(horframe,&int_target,FXDataTarget::ID_VALUE,PROGRESSBAR_PERCENTAGE|PROGRESSBAR_DIAL|LAYOUT_RIGHT|LAYOUT_FILL_Y|LAYOUT_FILL_X);
new FXHorizontalSeparator(this,LAYOUT_SIDE_TOP|SEPARATOR_GROOVE|LAYOUT_FILL_X);
new FXSlider(this,&int_target,FXDataTarget::ID_VALUE,SLIDER_VERTICAL|SLIDER_INSIDE_BAR|LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH,0,0,20,0);
// Arange nicely
matrix=new FXMatrix(this,7,MATRIX_BY_COLUMNS|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y);
// First row
new FXLabel(matrix,"&Integer",NULL,LAYOUT_CENTER_Y|LAYOUT_CENTER_X|JUSTIFY_RIGHT|LAYOUT_FILL_ROW);
// The value of variable "some_int" may be changed by any of these widgets below
new FXTextField(matrix,10,&int_target,FXDataTarget::ID_VALUE,TEXTFIELD_INTEGER|JUSTIFY_RIGHT|LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_ROW);
new FXTextField(matrix,10,&int_target,FXDataTarget::ID_VALUE,TEXTFIELD_INTEGER|JUSTIFY_RIGHT|LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_ROW);
new FXSlider(matrix,&int_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_FILL_ROW|LAYOUT_FIX_WIDTH,0,0,100);
new FXDial(matrix,&int_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_FILL_ROW|LAYOUT_FIX_WIDTH|DIAL_HORIZONTAL|DIAL_HAS_NOTCH,0,0,100);
new FXSpinner(matrix,5,&int_target,FXDataTarget::ID_VALUE,SPIN_CYCLIC|FRAME_SUNKEN|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_FILL_ROW);
new FXProgressBar(matrix,&int_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_FILL_X|FRAME_SUNKEN|FRAME_THICK|PROGRESSBAR_PERCENTAGE|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
// Second row
new FXLabel(matrix,"&Real",NULL,LAYOUT_CENTER_Y|LAYOUT_CENTER_X|JUSTIFY_RIGHT|LAYOUT_FILL_ROW);
// The value of variable "some_double" may be changed by the widgets below
new FXTextField(matrix,10,&double_target,FXDataTarget::ID_VALUE,TEXTFIELD_REAL|JUSTIFY_RIGHT|LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_ROW);
new FXTextField(matrix,10,&double_target,FXDataTarget::ID_VALUE,TEXTFIELD_REAL|JUSTIFY_RIGHT|LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_ROW);
new FXSlider(matrix,&double_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_FILL_X|LAYOUT_FILL_ROW|LAYOUT_FIX_WIDTH,0,0,100);
new FXDial(matrix,&double_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_FILL_X|LAYOUT_FILL_ROW|LAYOUT_FIX_WIDTH|DIAL_HORIZONTAL|DIAL_HAS_NOTCH,0,0,100);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
// Third row
new FXLabel(matrix,"&String",NULL,LAYOUT_CENTER_Y|LAYOUT_CENTER_X|JUSTIFY_RIGHT|LAYOUT_FILL_ROW);
// The string variable "some_string" can be changed by these text fields
new FXTextField(matrix,10,&string_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_ROW);
new FXTextField(matrix,10,&string_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_ROW);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
// Fourth row
new FXLabel(matrix,"&Option",NULL,LAYOUT_CENTER_Y|LAYOUT_CENTER_X|JUSTIFY_RIGHT|LAYOUT_FILL_ROW);
// The variable "some_option" is changed by the following widgets
new FXTextField(matrix,10,&option_target,FXDataTarget::ID_VALUE,TEXTFIELD_INTEGER|LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_ROW);
new FXRadioButton(matrix,"Option &1",&option_target,FXDataTarget::ID_OPTION+0,LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW|ICON_BEFORE_TEXT);
new FXRadioButton(matrix,"Option &2",&option_target,FXDataTarget::ID_OPTION+1,LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW|ICON_BEFORE_TEXT);
new FXRadioButton(matrix,"Option &3",&option_target,FXDataTarget::ID_OPTION+2,LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW|ICON_BEFORE_TEXT);
new FXRadioButton(matrix,"Option &4",&option_target,FXDataTarget::ID_OPTION+3,LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW|ICON_BEFORE_TEXT);
// Even option menus can be hooked up
popup=new FXPopup(this);
new FXOption(popup,"First",NULL,&option_target,FXDataTarget::ID_OPTION+0,JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
new FXOption(popup,"Second",NULL,&option_target,FXDataTarget::ID_OPTION+1,JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
new FXOption(popup,"Third",NULL,&option_target,FXDataTarget::ID_OPTION+2,JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
new FXOption(popup,"Fourth",NULL,&option_target,FXDataTarget::ID_OPTION+3,JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
FXOptionMenu *options=new FXOptionMenu(matrix,popup,LAYOUT_TOP|FRAME_RAISED|FRAME_THICK|JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
options->setTarget(&option_target);
options->setSelector(FXDataTarget::ID_VALUE);
//new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
// Fifth
new FXLabel(matrix,"&Color",NULL,LAYOUT_CENTER_Y|LAYOUT_CENTER_X|JUSTIFY_RIGHT|LAYOUT_FILL_ROW);
// Two colorwells connect to the variable "some_color"
new FXColorWell(matrix,0,&color_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_FILL_X|LAYOUT_FILL_ROW,0,0,0,0, 0,0,0,0);
new FXColorWell(matrix,0,&color_target,FXDataTarget::ID_VALUE,LAYOUT_CENTER_Y|LAYOUT_FILL_X|LAYOUT_FILL_ROW,0,0,0,0, 0,0,0,0);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
new FXFrame(matrix,LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
// Install an accelerator
getAccelTable()->addAccel(fxparseaccel("Ctl-Q"),getApp(),MKUINT(FXApp::ID_QUIT,SEL_COMMAND));
string_target.setTarget(this);
string_target.setSelector(ID_TEXTFIELD);
}
// Clean up
DataTargetWindow::~DataTargetWindow(){
delete filemenu;
delete optionmenu;
delete popup;
}
// Timer
long DataTargetWindow::onCmdTimer(FXObject*,FXSelector,void*){
// Increment modulo 100
some_progress=(some_progress+1)%100;
// Reset timer for next time
getApp()->addTimeout(80,this,ID_TIMER);
return 1;
}
// Quit
long DataTargetWindow::onCmdQuit(FXObject*,FXSelector,void*){
getApp()->exit(0);
return 1;
}
// Show progress
long DataTargetWindow::onCmdProgress(FXObject*,FXSelector,void*){
progressdialog->show(PLACEMENT_OWNER);
return 1;
}
long DataTargetWindow::onCmdTextField(FXObject*,FXSelector,void*){
FXString *list;
FXint count,i;
FXTRACE((100,"some_string=%s\n",some_string.text()));
count=FXFile::listFiles(list,some_string,"*",LIST_MATCHING_FILES|LIST_ALL_DIRS);
for(i=0; i<count; i++){
FXTRACE((100,"file[%d]=%s\n",i,list[i].text()));
}
delete [] list;
return 1;
}
// Start
void DataTargetWindow::create(){
// Create windows
FXMainWindow::create();
// Kick off the timer
getApp()->addTimeout(80,this,ID_TIMER);
// Show
show(PLACEMENT_SCREEN);
}
/*******************************************************************************/
// Start the whole thing
int main(int argc,char *argv[]){
// Make application
FXApp application("DataTarget","FoxTest");
// Open display
application.init(argc,argv);
// Main window
DataTargetWindow* window=new DataTargetWindow(&application);
// Handle interrupt to save stuff nicely
application.addSignal(SIGINT,window,DataTargetWindow::ID_QUIT);
// Create app
application.create();
// Run
return application.run();
}
|