| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2009 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
|
| 28 |
|
| 29 |
/******************************************************************************* |
| 30 |
file_dialog.c |
| 31 |
|
| 32 |
.VERSION |
| 33 |
090819 last modif |
| 34 |
|
| 35 |
|
| 36 |
*******************************************************************************/ |
| 37 |
|
| 38 |
#include <stdio.h> |
| 39 |
#include "UxLib.h" |
| 40 |
#include "UxTextF.h" |
| 41 |
#include "UxLabel.h" |
| 42 |
#include "UxPushB.h" |
| 43 |
#include "UxForm.h" |
| 44 |
#include "UxApplSh.h" |
| 45 |
|
| 46 |
/******************************************************************************* |
| 47 |
Includes, Defines, and Global variables from the Declarations Editor: |
| 48 |
*******************************************************************************/ |
| 49 |
|
| 50 |
#include <ExternResources.h> |
| 51 |
|
| 52 |
/******************************************************************************* |
| 53 |
The definition of the context structure: |
| 54 |
If you create multiple instances of your interface, the context |
| 55 |
structure ensures that your callbacks use the variables for the |
| 56 |
correct instance. |
| 57 |
|
| 58 |
For each swidget in the interface, each argument to the Interface |
| 59 |
function, and each variable in the Instance Specific section of the |
| 60 |
Declarations Editor, there is an entry in the context structure. |
| 61 |
and a #define. The #define makes the variable name refer to the |
| 62 |
corresponding entry in the context structure. |
| 63 |
*******************************************************************************/ |
| 64 |
|
| 65 |
typedef struct |
| 66 |
{ |
| 67 |
swidget Uxfile_dialog; |
| 68 |
swidget Uxform3; |
| 69 |
swidget Uxform5; |
| 70 |
swidget UxpushButton2; |
| 71 |
swidget UxpushButton3; |
| 72 |
swidget Uxlb_file_dialog; |
| 73 |
swidget Uxtf_file_dialog; |
| 74 |
} _UxCfile_dialog; |
| 75 |
|
| 76 |
#define file_dialog UxFile_dialogContext->Uxfile_dialog |
| 77 |
#define form3 UxFile_dialogContext->Uxform3 |
| 78 |
#define form5 UxFile_dialogContext->Uxform5 |
| 79 |
#define pushButton2 UxFile_dialogContext->UxpushButton2 |
| 80 |
#define pushButton3 UxFile_dialogContext->UxpushButton3 |
| 81 |
#define lb_file_dialog UxFile_dialogContext->Uxlb_file_dialog |
| 82 |
#define tf_file_dialog UxFile_dialogContext->Uxtf_file_dialog |
| 83 |
|
| 84 |
static _UxCfile_dialog *UxFile_dialogContext; |
| 85 |
|
| 86 |
|
| 87 |
extern void CallbackDialog(); |
| 88 |
|
| 89 |
|
| 90 |
/******************************************************************************* |
| 91 |
Forward declarations of functions that are defined later in this file. |
| 92 |
*******************************************************************************/ |
| 93 |
|
| 94 |
swidget create_file_dialog(); |
| 95 |
|
| 96 |
/******************************************************************************* |
| 97 |
The following are callback functions. |
| 98 |
*******************************************************************************/ |
| 99 |
|
| 100 |
static void activateCB_pushButton2( UxWidget, UxClientData, UxCallbackArg ) |
| 101 |
Widget UxWidget; |
| 102 |
XtPointer UxClientData, UxCallbackArg; |
| 103 |
{ |
| 104 |
_UxCfile_dialog *UxSaveCtx, *UxContext; |
| 105 |
swidget UxThisWidget; |
| 106 |
|
| 107 |
UxThisWidget = UxWidgetToSwidget( UxWidget ); |
| 108 |
UxSaveCtx = UxFile_dialogContext; |
| 109 |
UxFile_dialogContext = UxContext = |
| 110 |
(_UxCfile_dialog *) UxGetContext( UxThisWidget ); |
| 111 |
{ |
| 112 |
CallbackDialog(); |
| 113 |
} |
| 114 |
UxFile_dialogContext = UxSaveCtx; |
| 115 |
} |
| 116 |
|
| 117 |
static void activateCB_pushButton3( UxWidget, UxClientData, UxCallbackArg ) |
| 118 |
Widget UxWidget; |
| 119 |
XtPointer UxClientData, UxCallbackArg; |
| 120 |
{ |
| 121 |
_UxCfile_dialog *UxSaveCtx, *UxContext; |
| 122 |
swidget UxThisWidget; |
| 123 |
|
| 124 |
UxThisWidget = UxWidgetToSwidget( UxWidget ); |
| 125 |
UxSaveCtx = UxFile_dialogContext; |
| 126 |
UxFile_dialogContext = UxContext = |
| 127 |
(_UxCfile_dialog *) UxGetContext( UxThisWidget ); |
| 128 |
{ |
| 129 |
UxPopdownInterface(UxFindSwidget("file_dialog")); |
| 130 |
} |
| 131 |
UxFile_dialogContext = UxSaveCtx; |
| 132 |
} |
| 133 |
|
| 134 |
static void activateCB_tf_file_dialog( UxWidget, UxClientData, UxCallbackArg ) |
| 135 |
Widget UxWidget; |
| 136 |
XtPointer UxClientData, UxCallbackArg; |
| 137 |
{ |
| 138 |
_UxCfile_dialog *UxSaveCtx, *UxContext; |
| 139 |
swidget UxThisWidget; |
| 140 |
|
| 141 |
UxThisWidget = UxWidgetToSwidget( UxWidget ); |
| 142 |
UxSaveCtx = UxFile_dialogContext; |
| 143 |
UxFile_dialogContext = UxContext = |
| 144 |
(_UxCfile_dialog *) UxGetContext( UxThisWidget ); |
| 145 |
{ |
| 146 |
CallbackDialog(); |
| 147 |
} |
| 148 |
UxFile_dialogContext = UxSaveCtx; |
| 149 |
} |
| 150 |
|
| 151 |
static void losingFocusCB_tf_file_dialog( UxWidget, UxClientData, UxCallbackArg ) |
| 152 |
Widget UxWidget; |
| 153 |
XtPointer UxClientData, UxCallbackArg; |
| 154 |
{ |
| 155 |
_UxCfile_dialog *UxSaveCtx, *UxContext; |
| 156 |
swidget UxThisWidget; |
| 157 |
|
| 158 |
UxThisWidget = UxWidgetToSwidget( UxWidget ); |
| 159 |
UxSaveCtx = UxFile_dialogContext; |
| 160 |
UxFile_dialogContext = UxContext = |
| 161 |
(_UxCfile_dialog *) UxGetContext( UxThisWidget ); |
| 162 |
{ |
| 163 |
char *text; |
| 164 |
extern char Session[]; |
| 165 |
|
| 166 |
text = XmTextGetString(UxWidget); |
| 167 |
strcpy(Session, text); |
| 168 |
|
| 169 |
XtFree(text); |
| 170 |
} |
| 171 |
UxFile_dialogContext = UxSaveCtx; |
| 172 |
} |
| 173 |
|
| 174 |
/******************************************************************************* |
| 175 |
The 'init_' function sets the private properties for all the |
| 176 |
swidgets to the values specified in the Property Table. |
| 177 |
Some properties need to be set after the X widgets have been |
| 178 |
created and the setting of these properties is done in the |
| 179 |
'build_' function after the UxCreateWidget call. |
| 180 |
*******************************************************************************/ |
| 181 |
|
| 182 |
static void _Uxinit_file_dialog() |
| 183 |
{ |
| 184 |
UxPutBackground( file_dialog, WindowBackground ); |
| 185 |
UxPutGeometry( file_dialog, "+100+100" ); |
| 186 |
UxPutKeyboardFocusPolicy( file_dialog, "pointer" ); |
| 187 |
UxPutTitle( file_dialog, "" ); |
| 188 |
UxPutHeight( file_dialog, 105 ); |
| 189 |
UxPutWidth( file_dialog, 408 ); |
| 190 |
UxPutY( file_dialog, 312 ); |
| 191 |
UxPutX( file_dialog, 678 ); |
| 192 |
|
| 193 |
UxPutBackground( form3, WindowBackground ); |
| 194 |
UxPutHeight( form3, 348 ); |
| 195 |
UxPutWidth( form3, 408 ); |
| 196 |
UxPutY( form3, 0 ); |
| 197 |
UxPutX( form3, 0 ); |
| 198 |
UxPutUnitType( form3, "pixels" ); |
| 199 |
UxPutResizePolicy( form3, "resize_none" ); |
| 200 |
|
| 201 |
UxPutBackground( form5, ButtonBackground ); |
| 202 |
UxPutHeight( form5, 40 ); |
| 203 |
UxPutWidth( form5, 452 ); |
| 204 |
UxPutY( form5, 62 ); |
| 205 |
UxPutX( form5, 0 ); |
| 206 |
UxPutResizePolicy( form5, "resize_none" ); |
| 207 |
|
| 208 |
UxPutLabelString( pushButton2, "Ok" ); |
| 209 |
UxPutForeground( pushButton2, ApplyForeground ); |
| 210 |
UxPutFontList( pushButton2, BoldTextFont ); |
| 211 |
UxPutBackground( pushButton2, ButtonBackground ); |
| 212 |
UxPutHeight( pushButton2, 30 ); |
| 213 |
UxPutWidth( pushButton2, 80 ); |
| 214 |
UxPutY( pushButton2, 4 ); |
| 215 |
UxPutX( pushButton2, 8 ); |
| 216 |
|
| 217 |
UxPutLabelString( pushButton3, "Cancel" ); |
| 218 |
UxPutForeground( pushButton3, CancelForeground ); |
| 219 |
UxPutFontList( pushButton3, BoldTextFont ); |
| 220 |
UxPutBackground( pushButton3, ButtonBackground ); |
| 221 |
UxPutHeight( pushButton3, 30 ); |
| 222 |
UxPutWidth( pushButton3, 80 ); |
| 223 |
UxPutY( pushButton3, 4 ); |
| 224 |
UxPutX( pushButton3, 100 ); |
| 225 |
|
| 226 |
UxPutForeground( lb_file_dialog, TextForeground ); |
| 227 |
UxPutAlignment( lb_file_dialog, "alignment_beginning" ); |
| 228 |
UxPutLabelString( lb_file_dialog, "Output parameters file :" ); |
| 229 |
UxPutFontList( lb_file_dialog, TextFont ); |
| 230 |
UxPutBackground( lb_file_dialog, LabelBackground ); |
| 231 |
UxPutHeight( lb_file_dialog, 30 ); |
| 232 |
UxPutWidth( lb_file_dialog, 176 ); |
| 233 |
UxPutY( lb_file_dialog, 12 ); |
| 234 |
UxPutX( lb_file_dialog, 10 ); |
| 235 |
|
| 236 |
UxPutForeground( tf_file_dialog, TextForeground ); |
| 237 |
UxPutHighlightOnEnter( tf_file_dialog, "true" ); |
| 238 |
UxPutFontList( tf_file_dialog, TextFont ); |
| 239 |
UxPutBackground( tf_file_dialog, TextBackground ); |
| 240 |
UxPutHeight( tf_file_dialog, 34 ); |
| 241 |
UxPutWidth( tf_file_dialog, 210 ); |
| 242 |
UxPutY( tf_file_dialog, 10 ); |
| 243 |
UxPutX( tf_file_dialog, 190 ); |
| 244 |
|
| 245 |
} |
| 246 |
|
| 247 |
/******************************************************************************* |
| 248 |
The 'build_' function creates all the swidgets and X widgets, |
| 249 |
and sets their properties to the values specified in the |
| 250 |
Property Editor. |
| 251 |
*******************************************************************************/ |
| 252 |
|
| 253 |
static swidget _Uxbuild_file_dialog() |
| 254 |
{ |
| 255 |
/* Create the swidgets */ |
| 256 |
|
| 257 |
file_dialog = UxCreateApplicationShell( "file_dialog", NO_PARENT ); |
| 258 |
UxPutContext( file_dialog, UxFile_dialogContext ); |
| 259 |
|
| 260 |
form3 = UxCreateForm( "form3", file_dialog ); |
| 261 |
form5 = UxCreateForm( "form5", form3 ); |
| 262 |
pushButton2 = UxCreatePushButton( "pushButton2", form5 ); |
| 263 |
pushButton3 = UxCreatePushButton( "pushButton3", form5 ); |
| 264 |
lb_file_dialog = UxCreateLabel( "lb_file_dialog", form3 ); |
| 265 |
tf_file_dialog = UxCreateTextField( "tf_file_dialog", form3 ); |
| 266 |
|
| 267 |
_Uxinit_file_dialog(); |
| 268 |
|
| 269 |
/* Create the X widgets */ |
| 270 |
|
| 271 |
UxCreateWidget( file_dialog ); |
| 272 |
UxCreateWidget( form3 ); |
| 273 |
UxCreateWidget( form5 ); |
| 274 |
UxCreateWidget( pushButton2 ); |
| 275 |
UxCreateWidget( pushButton3 ); |
| 276 |
UxCreateWidget( lb_file_dialog ); |
| 277 |
UxCreateWidget( tf_file_dialog ); |
| 278 |
|
| 279 |
UxAddCallback( pushButton2, XmNactivateCallback, |
| 280 |
activateCB_pushButton2, |
| 281 |
(XtPointer) UxFile_dialogContext ); |
| 282 |
|
| 283 |
UxAddCallback( pushButton3, XmNactivateCallback, |
| 284 |
activateCB_pushButton3, |
| 285 |
(XtPointer) UxFile_dialogContext ); |
| 286 |
|
| 287 |
UxAddCallback( tf_file_dialog, XmNactivateCallback, |
| 288 |
activateCB_tf_file_dialog, |
| 289 |
(XtPointer) UxFile_dialogContext ); |
| 290 |
UxAddCallback( tf_file_dialog, XmNlosingFocusCallback, |
| 291 |
losingFocusCB_tf_file_dialog, |
| 292 |
(XtPointer) UxFile_dialogContext ); |
| 293 |
|
| 294 |
|
| 295 |
/* Finally, call UxRealizeInterface to create the X windows |
| 296 |
for the widgets created above. */ |
| 297 |
|
| 298 |
UxRealizeInterface( file_dialog ); |
| 299 |
|
| 300 |
return ( file_dialog ); |
| 301 |
} |
| 302 |
|
| 303 |
/******************************************************************************* |
| 304 |
The following function includes the code that was entered |
| 305 |
in the 'Initial Code' and 'Final Code' sections of the |
| 306 |
Declarations Editor. This function is called from the |
| 307 |
'Interface function' below. |
| 308 |
*******************************************************************************/ |
| 309 |
|
| 310 |
static swidget _Ux_create_file_dialog() |
| 311 |
{ |
| 312 |
swidget rtrn; |
| 313 |
_UxCfile_dialog *UxContext; |
| 314 |
|
| 315 |
UxFile_dialogContext = UxContext = |
| 316 |
(_UxCfile_dialog *) UxMalloc( sizeof(_UxCfile_dialog) ); |
| 317 |
|
| 318 |
rtrn = _Uxbuild_file_dialog(); |
| 319 |
|
| 320 |
return(rtrn); |
| 321 |
} |
| 322 |
|
| 323 |
/******************************************************************************* |
| 324 |
The following is the 'Interface function' which is the |
| 325 |
external entry point for creating this interface. |
| 326 |
This function should be called from your application or from |
| 327 |
a callback function. |
| 328 |
*******************************************************************************/ |
| 329 |
|
| 330 |
swidget create_file_dialog() |
| 331 |
{ |
| 332 |
swidget _Uxrtrn; |
| 333 |
|
| 334 |
_Uxrtrn = _Ux_create_file_dialog(); |
| 335 |
|
| 336 |
return ( _Uxrtrn ); |
| 337 |
} |
| 338 |
|
| 339 |
/******************************************************************************* |
| 340 |
END OF FILE |
| 341 |
*******************************************************************************/ |
| 342 |
|