00001 #ifndef xmenu_h
00002 #define xmenu_h
00003
00004 #include <InterViews/window.h>
00005 #include <InterViews/box.h>
00006 #include <InterViews/event.h>
00007 #include <OS/list.h>
00008 #include <OS/string.h>
00009 #include <IV-look/kit.h>
00010 #include <IV-look/stepper.h>
00011 #include <IV-look/dialogs.h>
00012 #if defined(WIN32) || defined(MAC) || defined(CYGWIN)
00013 #define UseFieldEditor 1
00014 #else
00015 #define UseFieldEditor 0 // Use the FieldSEditor
00016 #endif
00017 #if UseFieldEditor
00018 #include <IV-look/field.h>
00019 #define FieldSEditor FieldEditor
00020 #else
00021 #include "field.h"
00022 #endif
00023 #include "ocglyph.h"
00024 #include "apwindow.h"
00025 #include "ivocconf.h"
00026
00027 class HocPanel;
00028 class HocMenu;
00029 class HocAction;
00030 class HocValEditor;
00031 class HocValAction;
00032 class HocItem;
00033 class HocDataPaths;
00034 class HocCommand;
00035 class HocVarLabel;
00036 class HocUpdateItem;
00037 class Patch;
00038 class BoundedValue;
00039 class HocRadioAction;
00040 class StepperMenu;
00041 class ValEdLabel;
00042 class ScenePicker;
00043 struct HocSymExtension;
00044
00045 declarePtrList(HocUpdateItemList, HocUpdateItem)
00046 declarePtrList(HocItemList, HocItem)
00047 declarePtrList(HocPanelList, HocPanel)
00048
00049 class HocPanel : public OcGlyph {
00050 public:
00051 HocPanel(const char* name, boolean horizontal=false);
00052 virtual ~HocPanel();
00053 virtual void map_window(int scroll = -1);
00054
00055 void pushButton(const char* name, const char* action, boolean activate = false, Object* pyact = 0);
00056 void stateButton(double *pd, const char* name, const char* action, int style, Object* pyvar = nil, Object* pyact = nil);
00057 HocMenu* menu(const char* name, boolean add2menubar = false);
00058 MenuItem* menuItem(const char* name, const char* action, boolean activate = false, Object* pyact = 0);
00059 MenuItem* menuStateItem(double *pd, const char* name, const char* action, Object* pyvar = nil, Object* pyact = nil);
00060 void valueEd(const char* prompt, const char* variable, const char* action=0,
00061 boolean canrun=false, double* pd=nil, boolean deflt=false,
00062 boolean keep_updated=false, HocSymExtension* extra=nil,
00063 Object* pyvar=nil, Object* pyact=nil);
00064 void valueEd(const char* prompt, Object* pyvar, Object* pyact=0,
00065 boolean canrun=false, boolean deflt=false,
00066 boolean keep_updated=false);
00067
00068
00069 void slider(double*, float low = 0, float high = 100,
00070 float resolution = 1, int steps = 10,
00071 const char* send_cmd = nil, boolean vert = false,
00072 boolean slow = false, Object* pyvar=nil, Object* pysend=nil);
00073 virtual void write(ostream&);
00074 virtual void save(ostream&);
00075 virtual HocItem* hoc_item();
00076 void label(const char*);
00077 void var_label(char**, Object* pyvar = nil);
00078 PolyGlyph* box();
00079 const char* getName();
00080 void itemAppend(const char*);
00081 void notifyHocValue();
00082 void check_valid_pointers(void*, int);
00083 Coord left_, bottom_;
00084 static void save_all(ostream&);
00085 void data_path(HocDataPaths*, boolean);
00086 void item_append(HocItem*);
00087 #if MAC
00088 void mac_menubar();
00089 void mac_menubar(int&, int&, int);
00090 #endif
00091 static void keep_updated();
00092 static void keep_updated(HocUpdateItem*, boolean);
00093 static void paneltool(const char* name, const char* procname, const char* action, ScenePicker*, Object* pycallback = nil, Object* pyselact = nil);
00094 static void update_ptrs();
00095 private:
00096 PolyGlyph* box_;
00097 HocUpdateItemList elist_;
00098 HocItemList ilist_;
00099 static HocUpdateItemList* update_list_;
00100 boolean horizontal_;
00101 InputHandler* ih_;
00102 };
00103
00104 class HocItem : public Resource {
00105 public:
00106 HocItem(const char*, HocItem* parent = nil);
00107 virtual ~HocItem();
00108 virtual void write(ostream&);
00109 const char* getStr();
00110 virtual void help(const char* childpath = nil);
00111 virtual void help_parent(HocItem*);
00112 #if MAC
00113 virtual int mac_menubar(int&, int, int);
00114 #endif
00115 private:
00116 CopyString str_;
00117 HocItem* help_parent_;
00118 };
00119
00120 class HocPushButton : public HocItem {
00121 public:
00122 HocPushButton(const char*, HocAction*, HocItem* parent = nil);
00123 virtual ~HocPushButton();
00124 virtual void write(ostream&);
00125 #if MAC
00126 virtual int mac_menubar(int&, int, int);
00127 #endif
00128 private:
00129 HocAction* a_;
00130 };
00131
00132 class HocRadioButton : public HocItem {
00133 public:
00134 HocRadioButton(const char*, HocRadioAction*, HocItem* parent = nil);
00135 virtual ~HocRadioButton();
00136 virtual void write(ostream&);
00137 #if MAC
00138 virtual int mac_menubar(int&, int, int);
00139 #endif
00140 private:
00141 HocRadioAction* a_;
00142 };
00143
00144 class HocMenu : public HocItem {
00145 public:
00146 HocMenu(const char*, Menu*, MenuItem*, HocItem* parent = nil, boolean add2menubar = false);
00147 virtual ~HocMenu();
00148 virtual void write(ostream&);
00149 virtual Menu* menu() { return menu_;}
00150 virtual MenuItem* item() { return mi_; }
00151 #if MAC
00152 virtual int mac_menubar(int&, int, int);
00153 #endif
00154 private:
00155 MenuItem* mi_;
00156 Menu* menu_;
00157 boolean add2menubar_;
00158 };
00159
00160 class HocUpdateItem : public HocItem {
00161 public:
00162 HocUpdateItem(const char*, HocItem* parent = nil);
00163 virtual ~HocUpdateItem();
00164 virtual void update_hoc_item();
00165 virtual void check_pointer(void*, int vector_size);
00166 virtual void data_path(HocDataPaths*, boolean);
00167 virtual void update_ptrs(){}
00168 void update_ptrs_helper(double**);
00169 };
00170
00171 class HocLabel : public HocItem {
00172 public:
00173 HocLabel(const char*);
00174 virtual ~HocLabel();
00175 virtual void write(ostream&);
00176 };
00177
00178 class HocVarLabel : public HocUpdateItem {
00179 public:
00180 HocVarLabel(char**, PolyGlyph*, Object* pyvar = nil);
00181 virtual ~HocVarLabel();
00182 virtual void write(ostream&);
00183 virtual void update_hoc_item();
00184 virtual void check_pointer(void*, int);
00185 virtual void data_path(HocDataPaths*, boolean);
00186 private:
00187 Patch* p_;
00188 char** cpp_;
00189 char* cp_;
00190 CopyString* variable_;
00191 Object* pyvar_;
00192 };
00193
00194 class HocAction : public Action {
00195 public:
00196 HocAction(const char* action, Object* pyact = nil);
00197 virtual ~HocAction();
00198 virtual void execute();
00199 const char* name() const;
00200 virtual void help();
00201 void hoc_item(HocItem*);
00202 private:
00203 HocCommand* action_;
00204 HocItem* hi_;
00205 };
00206
00207 class HocMenuAction : public HocAction {
00208 public:
00209 HocMenuAction(const char* action, HocMenu*);
00210 virtual ~HocMenuAction();
00211 virtual void execute();
00212 private:
00213 HocMenu* hm_;
00214 HocPanel* hp_;
00215 };
00216
00217 class HocEditorForItem : public FieldSEditor {
00218 public:
00219 HocEditorForItem(HocValEditor*, HocValAction*);
00220 virtual ~HocEditorForItem();
00221
00222 virtual void keystroke(const Event&);
00223 virtual void press(const Event&);
00224 virtual void drag(const Event&);
00225 virtual void release(const Event&);
00226 virtual void val_inc(const Event&);
00227
00228 virtual InputHandler* focus_in();
00229 virtual void focus_out();
00230 private:
00231 HocValEditor* hve_;
00232 Coord y_;
00233 int index_;
00234 EventButton b_;
00235 };
00236
00237 class HocValStepper : public Stepper {
00238 public:
00239 static HocValStepper* instance(HocValEditor*);
00240 HocValStepper(HocValEditor*, Glyph*, Style*, TelltaleState*);
00241 virtual ~HocValStepper();
00242
00243 virtual void press(const Event&);
00244 virtual void release(const Event&);
00245 virtual void menu_up(Event&);
00246 void default_inc(boolean, double);
00247 double default_inc();
00248 static StepperMenu* menu() { return menu_;}
00249 protected:
00250 virtual void adjust();
00251 private:
00252 void left();
00253 void middle();
00254 void right();
00255 private:
00256 boolean geometric_;
00257 int steps_;
00258 float default_inc_;
00259 float inc_;
00260 HocValEditor* hve_;
00261 static StepperMenu* menu_;
00262 };
00263
00264 class HocValEditor : public HocUpdateItem {
00265 public:
00266 HocValEditor(const char* name, const char* variable, ValEdLabel*,
00267 HocValAction*, double* pd=0, boolean canrun=false,
00268 HocItem* parent = nil, Object* pvar = nil);
00269 virtual ~HocValEditor();
00270 FieldSEditor* field_editor() { return fe_; }
00271 virtual Stepper* stepper() { return nil; }
00272 virtual void update_hoc_item();
00273 void evalField();
00274 void audit();
00275 virtual void updateField();
00276 virtual void write(ostream&);
00277 virtual void data_path(HocDataPaths*, boolean);
00278 virtual void check_pointer(void*, int);
00279 virtual void print(Printer*, const Allocation&)const;
00280 virtual int hoc_default_val_editor() {return 0;}
00281 void set_val(double);
00282 double get_val();
00283 virtual void exec_action();
00284 const char* variable() const;
00285 virtual void setlimits(float*);
00286 virtual double domain_limits(double);
00287 boolean active() { return active_;}
00288 virtual void update_ptrs();
00289 private:
00290 friend class HocEditorForItem;
00291 friend class HocValStepper;
00292 HocEditorForItem* fe_;
00293 boolean active_;
00294 boolean canrun_;
00295 HocAction* action_;
00296 CopyString* variable_;
00297 double* pval_;
00298 ValEdLabel* prompt_;
00299 float* domain_limits_;
00300 Object* pyvar_;
00301 };
00302
00303 class HocDefaultValEditor : public HocValEditor {
00304 public:
00305 HocDefaultValEditor(const char* name, const char* variable, ValEdLabel*,
00306 HocValAction*, double* pd=0, boolean canrun=false,
00307 HocItem* parent = nil, Object* pyvar=nil);
00308 virtual ~HocDefaultValEditor();
00309 virtual Stepper* stepper() { return vs_; }
00310 virtual void updateField();
00311 virtual int hoc_default_val_editor() {return 1;}
00312 void deflt(double);
00313 void def_action();
00314 void def_change(float, float);
00315 Button* checkbox() { return checkbox_; }
00316 private:
00317 Button* checkbox_;
00318 double deflt_;
00319 double most_recent_;
00320 HocValStepper* vs_;
00321 };
00322
00323 class HocValEditorKeepUpdated : public HocValEditor {
00324 public:
00325 HocValEditorKeepUpdated(const char* name, const char* variable, ValEdLabel*,
00326 HocValAction*, double*, HocItem* parent = nil, Object* pyvar=nil);
00327 virtual ~HocValEditorKeepUpdated();
00328 virtual void write(ostream&);
00329 };
00330
00331 class HocValAction : public HocAction {
00332 public:
00333 HocValAction(const char* action, Object* pyact = 0);
00334 HocValAction(Object* pyaction);
00335 virtual ~HocValAction();
00336 void accept(FieldSEditor*);
00337 void execute();
00338 void setFieldSEditor(HocValEditor*);
00339 #if UseFieldEditor
00340 FieldEditorAction* fea(){return fea_;}
00341 #else
00342 FieldSEditorAction* fea(){return fea_;}
00343 #endif
00344 private:
00345 HocValEditor* fe_;
00346 #if UseFieldEditor
00347 FieldEditorAction* fea_;
00348 #else
00349 FieldSEditorAction* fea_;
00350 #endif
00351 };
00352
00353
00354
00355 class OcSlider : public HocUpdateItem, public Observer {
00356 public:
00357 OcSlider(double*, float low, float high,
00358 float resolution, int nsteps,
00359 const char* send_cmd, boolean vert,
00360 boolean slow = false, Object* pyvar=nil, Object* pysend=nil);
00361 virtual ~OcSlider();
00362 virtual void write(ostream&);
00363
00364 Adjustable* adjustable();
00365
00366 virtual void update(Observable*);
00367
00368 virtual void update_hoc_item();
00369 virtual void check_pointer(void*, int vector_size);
00370 virtual void data_path(HocDataPaths*, boolean);
00371 virtual double slider_val();
00372 virtual void update_ptrs();
00373 private:
00374 void audit();
00375 private:
00376 float resolution_;
00377 BoundedValue* bv_;
00378 HocCommand* send_;
00379 double *pval_;
00380 Object* pyvar_;
00381 CopyString* variable_;
00382 boolean scrolling_;
00383 boolean vert_;
00384 boolean slow_;
00385 };
00386
00387
00388
00389 class HocStateButton : public HocUpdateItem, public Observer {
00390 public:
00391 HocStateButton(double*, const char*, Button*, HocAction*, int, HocItem* parent = nil, Object* pyvar = nil);
00392 virtual ~HocStateButton();
00393 virtual void write(ostream&);
00394
00395 boolean chosen();
00396 void button_action();
00397
00398 virtual void update_hoc_item();
00399 virtual void check_pointer(void*, int);
00400 virtual void data_path(HocDataPaths*, boolean);
00401 virtual void print(Printer*, const Allocation&) const;
00402 virtual void update_ptrs();
00403 enum { CHECKBOX,PALETTE };
00404
00405 private:
00406 int style_;
00407 CopyString* variable_;
00408 CopyString* name_;
00409 double* pval_;
00410 Object* pyvar_;
00411 Button* b_;
00412 HocAction* action_;
00413 };
00414
00415
00416 class HocStateMenuItem : public HocUpdateItem, public Observer {
00417 public:
00418 HocStateMenuItem(double*, const char*, MenuItem*, HocAction*, HocItem* parent = nil, Object* pyvar = nil);
00419 virtual ~HocStateMenuItem();
00420 virtual void write(ostream&);
00421
00422 boolean chosen();
00423 void button_action();
00424
00425 virtual void update_hoc_item();
00426 virtual void check_pointer(void*, int);
00427 virtual void data_path(HocDataPaths*, boolean);
00428 virtual void print(Printer*, const Allocation&) const;
00429 virtual void update_ptrs();
00430
00431 private:
00432 CopyString* variable_;
00433 CopyString* name_;
00434 double* pval_;
00435 Object* pyvar_;
00436 MenuItem* b_;
00437 HocAction* action_;
00438 };
00439
00440
00441 #endif
00442
00443
00444