| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133 |
- //
- // "$Id: fluid.cxx 10113 2014-02-25 04:24:41Z greg.ercolano $"
- //
- // FLUID main entry for the Fast Light Tool Kit (FLTK).
- //
- // Copyright 1998-2010 by Bill Spitzak and others.
- //
- // This library is free software. Distribution and use rights are outlined in
- // the file "COPYING" which should have been included with this file. If this
- // file is missing or damaged, see the license at:
- //
- // http://www.fltk.org/COPYING.php
- //
- // Please report all bugs and problems on the following page:
- //
- // http://www.fltk.org/str.php
- //
- #undef IDE_SUPPORT
- #include <FL/Fl.H>
- #include <FL/Fl_Double_Window.H>
- #include <FL/Fl_Box.H>
- #include <FL/Fl_Button.H>
- #include <FL/Fl_File_Icon.H>
- #include <FL/Fl_Help_Dialog.H>
- #include <FL/Fl_Hold_Browser.H>
- #include <FL/Fl_Menu_Bar.H>
- #include <FL/Fl_Input.H>
- #include <FL/Fl_Plugin.H>
- #include <FL/fl_ask.H>
- #include <FL/fl_draw.H>
- #include <FL/Fl_File_Chooser.H>
- #include <FL/Fl_PNG_Image.H>
- #include <FL/fl_message.H>
- #include <FL/filename.H>
- #include <FL/Fl_Native_File_Chooser.H>
- #include <FL/Fl_Printer.H>
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <sys/stat.h>
- #include <time.h> // time(), localtime(), etc.
- #include "../src/flstring.h"
- #include "alignment_panel.h"
- #include "function_panel.h"
- #include "template_panel.h"
- #if defined(WIN32) && !defined(__CYGWIN__)
- # include <direct.h>
- # include <windows.h>
- # include <io.h>
- # include <fcntl.h>
- # include <commdlg.h>
- # include <FL/x.H>
- # ifndef __WATCOMC__
- // Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
- // on Windows, which is supposed to be POSIX compliant...
- # define access _access
- # define chdir _chdir
- # define getcwd _getcwd
- # endif // !__WATCOMC__
- #else
- # include <unistd.h>
- #endif
- #ifdef __EMX__
- # include <X11/Xlibint.h>
- #endif
- #include "about_panel.h"
- #include "undo.h"
- #include "Fl_Type.h"
- extern "C"
- {
- #if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
- # include <zlib.h>
- # ifdef HAVE_PNG_H
- # include <png.h>
- # else
- # include <libpng/png.h>
- # endif // HAVE_PNG_H
- #endif // HAVE_LIBPNG && HAVE_LIBZ
- }
- static Fl_Help_Dialog *help_dialog = 0;
- Fl_Preferences fluid_prefs(Fl_Preferences::USER, "fltk.org", "fluid");
- int gridx = 5;
- int gridy = 5;
- int snap = 1;
- int show_guides = 1;
- int show_comments = 1;
- int show_coredevmenus = 1;
- // File history info...
- char absolute_history[10][FL_PATH_MAX];
- char relative_history[10][FL_PATH_MAX];
- void load_history();
- void update_history(const char *);
- // Shell command support...
- void show_shell_window();
- Fl_Menu_Item *save_item = 0L;
- Fl_Menu_Item *history_item = 0L;
- Fl_Menu_Item *widgetbin_item = 0L;
- Fl_Menu_Item *sourceview_item = 0L;
- ////////////////////////////////////////////////////////////////
- static const char *filename;
- void set_filename(const char *c);
- void set_modflag(int mf);
- int modflag;
- static char* pwd;
- static char in_source_dir;
- void goto_source_dir() {
- if (in_source_dir) return;
- if (!filename || !*filename) return;
- const char *p = fl_filename_name(filename);
- if (p <= filename) return; // it is in the current directory
- char buffer[FL_PATH_MAX];
- strlcpy(buffer, filename, sizeof(buffer));
- int n = p-filename; if (n>1) n--; buffer[n] = 0;
- if (!pwd) {
- pwd = getcwd(0,FL_PATH_MAX);
- if (!pwd) {fprintf(stderr,"getwd : %s\n",strerror(errno)); return;}
- }
- if (chdir(buffer)<0) {fprintf(stderr, "Can't chdir to %s : %s\n",
- buffer, strerror(errno)); return;}
- in_source_dir = 1;
- }
- void leave_source_dir() {
- if (!in_source_dir) return;
- if (chdir(pwd)<0) {fprintf(stderr, "Can't chdir to %s : %s\n",
- pwd, strerror(errno));}
- in_source_dir = 0;
- }
- char position_window(Fl_Window *w, const char *prefsName, int Visible, int X, int Y, int W=0, int H=0 ) {
- Fl_Preferences pos(fluid_prefs, prefsName);
- if (prevpos_button->value()) {
- pos.get("x", X, X);
- pos.get("y", Y, Y);
- if ( W!=0 ) {
- pos.get("w", W, W);
- pos.get("h", H, H);
- w->resize( X, Y, W, H );
- }
- else
- w->position( X, Y );
- }
- pos.get("visible", Visible, Visible);
- return Visible;
- }
- void save_position(Fl_Window *w, const char *prefsName) {
- Fl_Preferences pos(fluid_prefs, prefsName);
- pos.set("x", w->x());
- pos.set("y", w->y());
- pos.set("w", w->w());
- pos.set("h", w->h());
- pos.set("visible", (int)(w->shown() && w->visible()));
- }
- Fl_Window *main_window;
- Fl_Menu_Bar *main_menubar;
- static char* cutfname(int which = 0) {
- static char name[2][FL_PATH_MAX];
- static char beenhere = 0;
- if (!beenhere) {
- beenhere = 1;
- fluid_prefs.getUserdataPath(name[0], sizeof(name[0]));
- strlcat(name[0], "cut_buffer", sizeof(name[0]));
- fluid_prefs.getUserdataPath(name[1], sizeof(name[1]));
- strlcat(name[1], "dup_buffer", sizeof(name[1]));
- }
- return name[which];
- }
- void save_cb(Fl_Widget *, void *v) {
- Fl_Native_File_Chooser fnfc;
- const char *c = filename;
- if (v || !c || !*c) {
- fnfc.title("Save To:");
- fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
- fnfc.filter("FLUID Files\t*.f[ld]");
- if (fnfc.show() != 0) return;
- c = fnfc.filename();
- if (!access(c, 0)) {
- const char *basename;
- if ((basename = strrchr(c, '/')) != NULL)
- basename ++;
- #if defined(WIN32) || defined(__EMX__)
- if ((basename = strrchr(c, '\\')) != NULL)
- basename ++;
- #endif // WIN32 || __EMX__
- else
- basename = c;
- if (fl_choice("The file \"%s\" already exists.\n"
- "Do you want to replace it?", "Cancel",
- "Replace", NULL, basename) == 0) return;
- }
- if (v != (void *)2) set_filename(c);
- }
- if (!write_file(c)) {
- fl_alert("Error writing %s: %s", c, strerror(errno));
- return;
- }
- if (v != (void *)2) {
- set_modflag(0);
- undo_save = undo_current;
- }
- }
- void save_template_cb(Fl_Widget *, void *) {
- // Setup the template panel...
- if (!template_panel) make_template_panel();
- template_clear();
- template_browser->add("New Template");
- template_load();
- template_name->show();
- template_name->value("");
- template_instance->hide();
- template_delete->show();
- template_delete->deactivate();
- template_submit->label("Save");
- template_submit->deactivate();
- template_panel->label("Save Template");
- // Show the panel and wait for the user to do something...
- template_panel->show();
- while (template_panel->shown()) Fl::wait();
- // Get the template name, return if it is empty...
- const char *c = template_name->value();
- if (!c || !*c) return;
- // Convert template name to filename_with_underscores
- char safename[FL_PATH_MAX], *safeptr;
- strlcpy(safename, c, sizeof(safename));
- for (safeptr = safename; *safeptr; safeptr ++) {
- if (isspace(*safeptr)) *safeptr = '_';
- }
- // Find the templates directory...
- char filename[FL_PATH_MAX];
- fluid_prefs.getUserdataPath(filename, sizeof(filename));
- strlcat(filename, "templates", sizeof(filename));
- #if defined(WIN32) && !defined(__CYGWIN__)
- if (access(filename, 0)) mkdir(filename);
- #else
- if (access(filename, 0)) mkdir(filename, 0777);
- #endif // WIN32 && !__CYGWIN__
- strlcat(filename, "/", sizeof(filename));
- strlcat(filename, safename, sizeof(filename));
- char *ext = filename + strlen(filename);
- if (ext >= (filename + sizeof(filename) - 5)) {
- fl_alert("The template name \"%s\" is too long!", c);
- return;
- }
- // Save the .fl file...
- strcpy(ext, ".fl");
- if (!access(filename, 0)) {
- if (fl_choice("The template \"%s\" already exists.\n"
- "Do you want to replace it?", "Cancel",
- "Replace", NULL, c) == 0) return;
- }
- if (!write_file(filename)) {
- fl_alert("Error writing %s: %s", filename, strerror(errno));
- return;
- }
- #if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
- // Get the screenshot, if any...
- Fl_Type *t;
- for (t = Fl_Type::first; t; t = t->next) {
- // Find the first window...
- if (t->is_window()) break;
- }
- if (!t) return;
- // Grab a screenshot...
- Fl_Window_Type *wt = (Fl_Window_Type *)t;
- uchar *pixels;
- int w, h;
- if ((pixels = wt->read_image(w, h)) == NULL) return;
- // Save to a PNG file...
- strcpy(ext, ".png");
- FILE *fp;
- if ((fp = fl_fopen(filename, "wb")) == NULL) {
- delete[] pixels;
- fl_alert("Error writing %s: %s", filename, strerror(errno));
- return;
- }
- png_structp pptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
- png_infop iptr = png_create_info_struct(pptr);
- png_bytep ptr = (png_bytep)pixels;
- png_init_io(pptr, fp);
- png_set_IHDR(pptr, iptr, w, h, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
- png_set_sRGB(pptr, iptr, PNG_sRGB_INTENT_PERCEPTUAL);
- png_write_info(pptr, iptr);
- for (int i = h; i > 0; i --, ptr += w * 3) {
- png_write_row(pptr, ptr);
- }
- png_write_end(pptr, iptr);
- png_destroy_write_struct(&pptr, &iptr);
- fclose(fp);
- # if 0 // The original PPM output code...
- strcpy(ext, ".ppm");
- fp = fl_fopen(filename, "wb");
- fprintf(fp, "P6\n%d %d 255\n", w, h);
- fwrite(pixels, w * h, 3, fp);
- fclose(fp);
- # endif // 0
- delete[] pixels;
- #endif // HAVE_LIBPNG && HAVE_LIBZ
- }
- void revert_cb(Fl_Widget *,void *) {
- if (modflag) {
- if (!fl_choice("This user interface has been changed. Really revert?",
- "Cancel", "Revert", NULL)) return;
- }
- undo_suspend();
- if (!read_file(filename, 0)) {
- undo_resume();
- fl_message("Can't read %s: %s", filename, strerror(errno));
- return;
- }
- undo_resume();
- set_modflag(0);
- undo_clear();
- }
- void exit_cb(Fl_Widget *,void *) {
- if (modflag)
- switch (fl_choice("Do you want to save changes to this user\n"
- "interface before exiting?", "Cancel",
- "Save", "Don't Save"))
- {
- case 0 : /* Cancel */
- return;
- case 1 : /* Save */
- save_cb(NULL, NULL);
- if (modflag) return; // Didn't save!
- }
- save_position(main_window,"main_window_pos");
- if (widgetbin_panel) {
- save_position(widgetbin_panel,"widgetbin_pos");
- delete widgetbin_panel;
- }
- if (sourceview_panel) {
- Fl_Preferences svp(fluid_prefs, "sourceview");
- svp.set("autorefresh", sv_autorefresh->value());
- svp.set("autoposition", sv_autoposition->value());
- svp.set("tab", sv_tab->find(sv_tab->value()));
- save_position(sourceview_panel,"sourceview_pos");
- delete sourceview_panel;
- }
- if (about_panel)
- delete about_panel;
- if (help_dialog)
- delete help_dialog;
- undo_clear();
- exit(0);
- }
- extern void* const LOAD;
- #ifdef USE_LUA
- #define VM_SCRIPT_EXT ".lua"
- #include "widget_panel.h"
- #include "luacpp.h"
- lua::Lua *Lua = NULL;
- void my_lua_show_error_func(const char* error_message){
- fl_alert(error_message);
- }
- void my_close_script_vm(){
- if(Lua) delete Lua;
- Lua = NULL;
- }
- void my_open_script_vm(){
- my_close_script_vm();
- Lua = new lua::Lua();
- Lua->set_lua_error(my_lua_show_error_func);
- }
- int vm_script_preprocess_file(const char *file_name){
- return Lua->lua_preprocess_file(file_name);
- }
- int vm_script_loadstring(const char *script){
- return Lua->loadstring(script);
- }
- int vm_script_dofile(const char *file_name){
- return Lua->dofile(file_name);
- }
- void vm_script_gvar(const char* key, const char *value){
- Lua->gvar(key, value);
- }
- #endif
- #ifdef USE_SQUILU
- #define VM_SCRIPT_EXT ".nut"
- #include "widget_panel.h"
- #include "squirrel.h"
- #include <sqstdblob.h>
- #include <sqstdsystem.h>
- #include <sqstdio.h>
- #include <sqstdmath.h>
- #include <sqstdstring.h>
- #include <sqstdaux.h>
- HSQUIRRELVM sqvm = NULL;
- void sq_errorfunc(HSQUIRRELVM v,const SQChar *s,...)
- {
- SQChar buf[1024];
- va_list vl;
- va_start(vl, s);
- scsnprintf(buf, sizeof(buf), s, vl);
- va_end(vl);
- fl_alert(buf);
- }
- void my_close_script_vm(){
- if(sqvm) sq_close(sqvm);
- sqvm = NULL;
- }
- void my_open_script_vm(){
- my_close_script_vm();
- sqvm = sq_open(1024);
- sq_setprintfunc(sqvm,sq_errorfunc,sq_errorfunc);
- sq_pushroottable(sqvm);
- sqstd_register_bloblib(sqvm);
- sqstd_register_iolib(sqvm);
- sqstd_register_systemlib(sqvm);
- sqstd_register_mathlib(sqvm);
- sqstd_register_stringlib(sqvm);
- sq_poptop(sqvm);
- }
- int vm_script_preprocess_file(const char *file_name){
- int top = sq_gettop(sqvm); //saves the stack top
- int ret_value = -1;
- sq_pushstring(sqvm, _SC("preprocess_file"), -1);
- if(sq_getonroottable(sqvm) == SQ_OK){
- SQObjectType stype = sq_gettype(sqvm, -1);
- if(stype == OT_CLOSURE || stype == OT_NATIVECLOSURE){
- sq_pushroottable(sqvm);
- sq_pushstring(sqvm, file_name, -1);
- if(sq_call(sqvm, 2, SQTrue, SQFalse) == SQ_OK){
- if(sq_gettype(sqvm, -1) == OT_INTEGER){
- sq_getinteger(sqvm, -1, &ret_value);
- }
- }
- }
- }
- sq_settop(sqvm, top); //returns stack to it's orign
- return ret_value;
- }
- int vm_script_loadstring(const char *script){
- SQInteger top = sq_gettop(sqvm);
- int result = sq_compilebuffer(sqvm, script, strlen(script), "script", SQFalse);
- sq_settop(sqvm, top);
- return result;
- }
- int vm_script_dofile(const char *file_name){
- return sqstd_dofile(sqvm, file_name, SQFalse, SQFalse);
- }
- void vm_script_gvar(const char* key, const char *value){
- sq_pushstring(sqvm, key, -1);
- sq_pushstring(sqvm, value, -1);
- sq_setonroottable(sqvm);
- }
- #endif
- #if defined(USE_LUA) || defined(USE_SQUILU)
- #define USE_VM_SCRIPT
- #endif
- #if USE_VM_SCRIPT
- void get_user_vm_script_file_name(char *buf, size_t buf_size){
- fluid_prefs.getUserdataPath(buf, buf_size);
- strlcat(buf, "user_script" VM_SCRIPT_EXT, buf_size);
- }
- void get_project_vm_script_file_name(char *buf, size_t buf_size){
- snprintf(buf, buf_size, "%s" VM_SCRIPT_EXT, filename);
- }
- #endif
- void save_vm_script_cb(Fl_Button *, void *v){
- if (v == LOAD) return;
- #ifdef USE_VM_SCRIPT
- char uls_filename[FL_PATH_MAX];
- get_user_vm_script_file_name(uls_filename, sizeof(uls_filename));
- vm_script_user_editor->buffer()->savefile(uls_filename);
- get_project_vm_script_file_name(uls_filename, sizeof(uls_filename));
- vm_script_project_editor->buffer()->savefile(uls_filename);
- #endif
- }
- void check_vm_script_cb(Fl_Button *, void *v){
- if (v == LOAD) return;
- #ifdef USE_VM_SCRIPT
- int ret_value;
- if(vm_script_user_editor->visible_r())
- ret_value = vm_script_loadstring(vm_script_user_editor->buffer()->text());
- else
- ret_value = vm_script_loadstring(vm_script_project_editor->buffer()->text());
- if(!ret_value) fl_alert("Parse OK !");
- #endif
- }
- static bool vm_script_already_loaded = false;
- void reload_vm_script_cb(Fl_Button *, void *v){
- #ifdef USE_VM_SCRIPT
- //printf("reload_lua_cb\n");
- if (v == LOAD && vm_script_already_loaded) return;
- vm_script_already_loaded = true;
- my_open_script_vm();
- char uls_filename[FL_PATH_MAX];
- get_user_vm_script_file_name(uls_filename, sizeof(uls_filename));
- vm_script_user_editor->buffer()->loadfile(uls_filename);
- vm_script_dofile(uls_filename); //first user script
- get_project_vm_script_file_name(uls_filename, sizeof(uls_filename));
- vm_script_project_editor->buffer()->loadfile(uls_filename);
- vm_script_dofile(uls_filename); //then project script
- vm_script_gvar("PROJECT_SCRIPT_FILE_NAME", uls_filename);
- #endif
- }
- void vm_script_editor_cb(CodeEditor *, void *v){
- if (v == LOAD) return;
- }
- //#endif
- #ifdef __APPLE__
- # include <FL/x.H>
- void
- apple_open_cb(const char *c) {
- if (modflag) {
- switch (fl_choice("Do you want to save changes to this user\n"
- "interface before opening another one?", "Don't Save",
- "Save", "Cancel"))
- {
- case 0 : /* Cancel */
- return;
- case 1 : /* Save */
- save_cb(NULL, NULL);
- if (modflag) return; // Didn't save!
- }
- }
- const char *oldfilename;
- oldfilename = filename;
- filename = NULL;
- set_filename(c);
- undo_suspend();
- if (!read_file(c, 0)) {
- undo_resume();
- fl_message("Can't read %s: %s", c, strerror(errno));
- free((void *)filename);
- filename = oldfilename;
- if (main_window) main_window->label(filename);
- return;
- }
- // Loaded a file; free the old filename...
- set_modflag(0);
- undo_resume();
- undo_clear();
- if (oldfilename) free((void *)oldfilename);
- }
- #endif // __APPLE__
- void open_cb(Fl_Widget *, void *v) {
- if (!v && modflag) {
- switch (fl_choice("Do you want to save changes to this user\n"
- "interface before opening another one?", "Cancel",
- "Save", "Don't Save"))
- {
- case 0 : /* Cancel */
- return;
- case 1 : /* Save */
- save_cb(NULL, NULL);
- if (modflag) return; // Didn't save!
- }
- }
- const char *c;
- const char *oldfilename;
- Fl_Native_File_Chooser fnfc;
- fnfc.title("Open:");
- fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE);
- fnfc.filter("FLUID Files\t*.f[ld]\n");
- if (fnfc.show() != 0) return;
- c = fnfc.filename();
- oldfilename = filename;
- filename = NULL;
- set_filename(c);
- if (v != 0) undo_checkpoint();
- undo_suspend();
- if (!read_file(c, v!=0)) {
- undo_resume();
- fl_message("Can't read %s: %s", c, strerror(errno));
- free((void *)filename);
- filename = oldfilename;
- if (main_window) set_modflag(modflag);
- return;
- }
- undo_resume();
- if (v) {
- // Inserting a file; restore the original filename...
- free((void *)filename);
- filename = oldfilename;
- set_modflag(1);
- } else {
- // Loaded a file; free the old filename...
- set_modflag(0);
- undo_clear();
- if (oldfilename) free((void *)oldfilename);
- }
- #ifdef USE_VM_SCRIPT
- vm_script_already_loaded = false;
- #endif
- }
- void open_history_cb(Fl_Widget *, void *v) {
- if (modflag) {
- switch (fl_choice("Do you want to save changes to this user\n"
- "interface before opening another one?", "Cancel",
- "Save", "Don't Save"))
- {
- case 0 : /* Cancel */
- return;
- case 1 : /* Save */
- save_cb(NULL, NULL);
- if (modflag) return; // Didn't save!
- }
- }
- const char *oldfilename = filename;
- filename = NULL;
- set_filename((char *)v);
- undo_suspend();
- if (!read_file(filename, 0)) {
- undo_resume();
- undo_clear();
- fl_message("Can't read %s: %s", filename, strerror(errno));
- free((void *)filename);
- filename = oldfilename;
- if (main_window) main_window->label(filename);
- return;
- }
- set_modflag(0);
- undo_resume();
- undo_clear();
- if (oldfilename) free((void *)oldfilename);
- }
- void new_cb(Fl_Widget *, void *v) {
- // Check if the current file has been modified...
- if (!v && modflag) {
- // Yes, ask the user what to do...
- switch (fl_choice("Do you want to save changes to this user\n"
- "interface before creating a new one?", "Cancel",
- "Save", "Don't Save"))
- {
- case 0 : /* Cancel */
- return;
- case 1 : /* Save */
- save_cb(NULL, NULL);
- if (modflag) return; // Didn't save!
- }
- }
- // Setup the template panel...
- if (!template_panel) make_template_panel();
- template_clear();
- template_browser->add("Blank");
- template_load();
- template_name->hide();
- template_name->value("");
- template_instance->show();
- template_instance->deactivate();
- template_instance->value("");
- template_delete->hide();
- template_submit->label("New");
- template_submit->deactivate();
- template_panel->label("New");
- // Show the panel and wait for the user to do something...
- template_panel->show();
- while (template_panel->shown()) Fl::wait();
- // See if the user chose anything...
- int item = template_browser->value();
- if (item < 1) return;
- // Clear the current data...
- delete_all();
- set_filename(NULL);
- // Load the template, if any...
- const char *tname = (const char *)template_browser->data(item);
- if (tname) {
- // Grab the instance name...
- const char *iname = template_instance->value();
- if (iname && *iname) {
- // Copy the template to a temp file, then read it in...
- char line[1024], *ptr, *next;
- FILE *infile, *outfile;
- if ((infile = fl_fopen(tname, "r")) == NULL) {
- fl_alert("Error reading template file \"%s\":\n%s", tname,
- strerror(errno));
- set_modflag(0);
- undo_clear();
- return;
- }
- if ((outfile = fl_fopen(cutfname(1), "w")) == NULL) {
- fl_alert("Error writing buffer file \"%s\":\n%s", cutfname(1),
- strerror(errno));
- fclose(infile);
- set_modflag(0);
- undo_clear();
- return;
- }
- while (fgets(line, sizeof(line), infile)) {
- // Replace @INSTANCE@ with the instance name...
- for (ptr = line; (next = strstr(ptr, "@INSTANCE@")) != NULL; ptr = next + 10) {
- fwrite(ptr, next - ptr, 1, outfile);
- fputs(iname, outfile);
- }
- fputs(ptr, outfile);
- }
- fclose(infile);
- fclose(outfile);
- undo_suspend();
- read_file(cutfname(1), 0);
- unlink(cutfname(1));
- undo_resume();
- } else {
- // No instance name, so read the template without replacements...
- undo_suspend();
- read_file(tname, 0);
- undo_resume();
- }
- }
- set_modflag(0);
- undo_clear();
- }
- int exit_early = 0;
- int compile_only = 0;
- int compile_strings = 0;
- int header_file_set = 0;
- int code_file_set = 0;
- const char* header_file_name = ".h";
- const char* code_file_name = ".cxx";
- int i18n_type = 0;
- const char* i18n_include = "";
- const char* i18n_function = "";
- const char* i18n_file = "";
- const char* i18n_set = "";
- char i18n_program[FL_PATH_MAX] = "";
- void write_cb(Fl_Widget *, void *) {
- if (!filename) {
- save_cb(0,0);
- if (!filename) return;
- }
- char cname[FL_PATH_MAX];
- char hname[FL_PATH_MAX];
- strlcpy(i18n_program, fl_filename_name(filename), sizeof(i18n_program));
- fl_filename_setext(i18n_program, sizeof(i18n_program), "");
- if (*code_file_name == '.' && strchr(code_file_name, '/') == NULL) {
- strlcpy(cname, fl_filename_name(filename), sizeof(cname));
- fl_filename_setext(cname, sizeof(cname), code_file_name);
- } else {
- strlcpy(cname, code_file_name, sizeof(hname));
- }
- if (*header_file_name == '.' && strchr(header_file_name, '/') == NULL) {
- strlcpy(hname, fl_filename_name(filename), sizeof(hname));
- fl_filename_setext(hname, sizeof(hname), header_file_name);
- } else {
- strlcpy(hname, header_file_name, sizeof(hname));
- }
- if (!compile_only) goto_source_dir();
- int x = write_code(cname,hname);
- #ifdef USE_VM_SCRIPT
- if(x){
- //order is important header file first
- //because most lua scripts goes to the header
- //and itialize variables
- vm_script_preprocess_file(hname);
- vm_script_preprocess_file(cname);
- }
- #endif
- if (!compile_only) leave_source_dir();
- strlcat(cname, " and ", sizeof(cname));
- strlcat(cname, hname, sizeof(cname));
- if (compile_only) {
- if (!x) {fprintf(stderr,"%s : %s\n",cname,strerror(errno)); exit(1);}
- } else {
- if (!x) {
- fl_message("Can't write %s: %s", cname, strerror(errno));
- } else if (completion_button->value()) {
- fl_message("Wrote %s", cname);
- }
- }
- }
- void save_write_exit_cb(Fl_Widget *w, void *v) {
- save_cb(w,v);
- write_cb(w,v);
- exit_cb(w,v);
- }
- void write_strings_cb(Fl_Widget *, void *) {
- static const char *exts[] = { ".txt", ".po", ".msg" };
- if (!filename) {
- save_cb(0,0);
- if (!filename) return;
- }
- char sname[FL_PATH_MAX];
- strlcpy(sname, fl_filename_name(filename), sizeof(sname));
- fl_filename_setext(sname, sizeof(sname), exts[i18n_type]);
- if (!compile_only) goto_source_dir();
- int x = write_strings(sname);
- if (!compile_only) leave_source_dir();
- if (compile_only) {
- if (x) {fprintf(stderr,"%s : %s\n",sname,strerror(errno)); exit(1);}
- } else {
- if (x) {
- fl_message("Can't write %s: %s", sname, strerror(errno));
- } else if (completion_button->value()) {
- fl_message("Wrote %s", sname);
- }
- }
- }
- void openwidget_cb(Fl_Widget *, void *) {
- if (!Fl_Type::current) {
- fl_message("Please select a widget");
- return;
- }
- Fl_Type::current->open();
- }
- void toggle_overlays(Fl_Widget *,void *);
- void select_all_cb(Fl_Widget *,void *);
- void select_none_cb(Fl_Widget *,void *);
- void group_cb(Fl_Widget *, void *);
- void ungroup_cb(Fl_Widget *, void *);
- extern int pasteoffset;
- static int ipasteoffset;
- void copy_cb(Fl_Widget*, void*) {
- if (!Fl_Type::current) {
- fl_beep();
- return;
- }
- ipasteoffset = 10;
- if (!write_file(cutfname(),1)) {
- fl_message("Can't write %s: %s", cutfname(), strerror(errno));
- return;
- }
- }
- extern void select_only(Fl_Type *);
- void cut_cb(Fl_Widget *, void *) {
- if (!Fl_Type::current) {
- fl_beep();
- return;
- }
- if (!write_file(cutfname(),1)) {
- fl_message("Can't write %s: %s", cutfname(), strerror(errno));
- return;
- }
- undo_checkpoint();
- set_modflag(1);
- ipasteoffset = 0;
- Fl_Type *p = Fl_Type::current->parent;
- while (p && p->selected) p = p->parent;
- delete_all(1);
- if (p) select_only(p);
- }
- void delete_cb(Fl_Widget *, void *) {
- if (!Fl_Type::current) {
- fl_beep();
- return;
- }
- undo_checkpoint();
- set_modflag(1);
- ipasteoffset = 0;
- Fl_Type *p = Fl_Type::current->parent;
- while (p && p->selected) p = p->parent;
- delete_all(1);
- if (p) select_only(p);
- }
- extern int force_parent;
- void paste_cb(Fl_Widget*, void*) {
- //if (ipasteoffset) force_parent = 1;
- pasteoffset = ipasteoffset;
- if (gridx>1) pasteoffset = ((pasteoffset-1)/gridx+1)*gridx;
- if (gridy>1) pasteoffset = ((pasteoffset-1)/gridy+1)*gridy;
- undo_checkpoint();
- undo_suspend();
- if (!read_file(cutfname(), 1)) {
- fl_message("Can't read %s: %s", cutfname(), strerror(errno));
- }
- undo_resume();
- pasteoffset = 0;
- ipasteoffset += 10;
- force_parent = 0;
- }
- // Duplicate the selected widgets...
- void duplicate_cb(Fl_Widget*, void*) {
- if (!Fl_Type::current) {
- fl_beep();
- return;
- }
- if (!write_file(cutfname(1),1)) {
- fl_message("Can't write %s: %s", cutfname(1), strerror(errno));
- return;
- }
- pasteoffset = 0;
- force_parent = 1;
- undo_checkpoint();
- undo_suspend();
- if (!read_file(cutfname(1), 1)) {
- fl_message("Can't read %s: %s", cutfname(1), strerror(errno));
- }
- unlink(cutfname(1));
- undo_resume();
- force_parent = 0;
- }
- void earlier_cb(Fl_Widget*,void*);
- void later_cb(Fl_Widget*,void*);
- Fl_Type *sort(Fl_Type *parent);
- static void sort_cb(Fl_Widget *,void *) {
- sort((Fl_Type*)0);
- }
- Fl_Type *sort_by_name(Fl_Type *parent);
- static void sort_by_name_cb(Fl_Widget *,void *) {
- sort_by_name((Fl_Type*)0);
- }
- void show_project_cb(Fl_Widget *, void *);
- void show_grid_cb(Fl_Widget *, void *);
- void show_settings_cb(Fl_Widget *, void *);
- void show_global_settings_cb(Fl_Widget *, void *);
- void align_widget_cb(Fl_Widget *, long);
- void widget_size_cb(Fl_Widget *, long);
- void about_cb(Fl_Widget *, void *) {
- if (!about_panel) make_about_panel();
- about_panel->show();
- }
- void show_help(const char *name) {
- const char *docdir;
- char helpname[FL_PATH_MAX];
- if (!help_dialog) help_dialog = new Fl_Help_Dialog();
- if ((docdir = getenv("FLTK_DOCDIR")) == NULL) {
- #ifdef __EMX__
- // Doesn't make sense to have a hardcoded fallback
- static char fltk_docdir[FL_PATH_MAX];
- strlcpy(fltk_docdir, __XOS2RedirRoot("/XFree86/lib/X11/fltk/doc"),
- sizeof(fltk_docdir));
- docdir = fltk_docdir;
- #else
- docdir = FLTK_DOCDIR;
- #endif // __EMX__
- }
- snprintf(helpname, sizeof(helpname), "%s/%s", docdir, name);
- // make sure that we can read the file
- FILE *f = fopen(helpname, "rb");
- if (f) {
- fclose(f);
- help_dialog->load(helpname);
- } else {
- // if we can not read the file, we display the canned version instead
- // or ask the native browser to open the page on www.fltk.org
- if (strcmp(name, "fluid.html")==0) {
- if (!Fl_Shared_Image::find("embedded:/fluid-org.png"))
- new Fl_PNG_Image("embedded:/fluid-org.png", fluid_org_png, sizeof(fluid_org_png));
- help_dialog->value
- (
- "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
- "<html><head><title>FLTK: Programming with FLUID</title></head><body>\n"
- "<h2>What is FLUID?</h2>\n"
- "The Fast Light User Interface Designer, or FLUID, is a graphical editor "
- "that is used to produce FLTK source code. FLUID edits and saves its state "
- "in <code>.fl</code> files. These files are text, and you can (with care) "
- "edit them in a text editor, perhaps to get some special effects.<p>\n"
- "FLUID can \"compile\" the <code>.fl</code> file into a <code>.cxx</code> "
- "and a <code>.h</code> file. The <code>.cxx</code> file defines all the "
- "objects from the <code>.fl</code> file and the <code>.h</code> file "
- "declares all the global ones. FLUID also supports localization "
- "(Internationalization) of label strings using message files and the GNU "
- "gettext or POSIX catgets interfaces.<p>\n"
- "A simple program can be made by putting all your code (including a <code>"
- "main()</code> function) into the <code>.fl</code> file and thus making the "
- "<code>.cxx</code> file a single source file to compile. Most programs are "
- "more complex than this, so you write other <code>.cxx</code> files that "
- "call the FLUID functions. These <code>.cxx</code> files must <code>"
- "#include</code> the <code>.h</code> file or they can <code>#include</code> "
- "the <code>.cxx</code> file so it still appears to be a single source file.<p>"
- "<img src=\"embedded:/fluid-org.png\"></p>"
- "<p>More information is available online at <a href="
- "\"http://www.fltk.org/doc-1.3/fluid.html\">http://www.fltk.org/</a>"
- "</body></html>"
- );
- } else if (strcmp(name, "license.html")==0) {
- fl_open_uri("http://www.fltk.org/doc-1.3/license.html");
- return;
- } else if (strcmp(name, "index.html")==0) {
- fl_open_uri("http://www.fltk.org/doc-1.3/index.html");
- return;
- } else {
- snprintf(helpname, sizeof(helpname), "http://www.fltk.org/%s", name);
- fl_open_uri(helpname);
- return;
- }
- }
- help_dialog->show();
- }
- void help_cb(Fl_Widget *, void *) {
- show_help("fluid.html");
- }
- void manual_cb(Fl_Widget *, void *) {
- show_help("index.html");
- }
- ////////////////////////////////////////////////////////////////
- void print_menu_cb(Fl_Widget *, void *) {
- int w, h, ww, hh;
- int frompage, topage;
- Fl_Type *t; // Current widget
- int num_windows; // Number of windows
- Fl_Window_Type *windows[1000]; // Windows to print
- int winpage; // Current window page
- Fl_Window *win;
- for (t = Fl_Type::first, num_windows = 0; t; t = t->next) {
- if (t->is_window()) {
- windows[num_windows] = (Fl_Window_Type *)t;
- if (!((Fl_Window*)(windows[num_windows]->o))->shown()) continue;
- num_windows ++;
- }
- }
- Fl_Printer printjob;
- if ( printjob.start_job(num_windows, &frompage, &topage) ) return;
- int pagecount = 0;
- for (winpage = 0; winpage < num_windows; winpage++) {
- float scale = 1, scale_x = 1, scale_y = 1;
- if (winpage+1 < frompage || winpage+1 > topage) continue;
- printjob.start_page();
- printjob.printable_rect(&w, &h);
- // Get the time and date...
- time_t curtime = time(NULL);
- struct tm *curdate = localtime(&curtime);
- char date[1024];
- strftime(date, sizeof(date), "%c", curdate);
- fl_font(FL_HELVETICA, 12);
- fl_color(FL_BLACK);
- fl_draw(date, (w - (int)fl_width(date))/2, fl_height());
- sprintf(date, "%d/%d", ++pagecount, topage-frompage+1);
- fl_draw(date, w - (int)fl_width(date), fl_height());
- // Get the base filename...
- const char *basename = strrchr(filename,
- #ifdef WIN32
- '\\'
- #else
- '/'
- #endif
- );
- if (basename) basename ++;
- else basename = filename;
- sprintf(date, "%s", basename);
- fl_draw(date, 0, fl_height());
- // print centered and scaled to fit in the page
- win = (Fl_Window*)windows[winpage]->o;
- ww = win->decorated_w();
- if(ww > w) scale_x = float(w)/ww;
- hh = win->decorated_h();
- if(hh > h) scale_y = float(h)/hh;
- if (scale_x < scale) scale = scale_x;
- if (scale_y < scale) scale = scale_y;
- if (scale < 1) {
- printjob.scale(scale);
- printjob.printable_rect(&w, &h);
- }
- printjob.origin(w/2, h/2);
- printjob.print_window(win, -ww/2, -hh/2);
- printjob.end_page();
- }
- printjob.end_job();
- }
- ////////////////////////////////////////////////////////////////
- extern Fl_Menu_Item New_Menu[];
- void toggle_widgetbin_cb(Fl_Widget *, void *);
- void toggle_sourceview_cb(Fl_Double_Window *, void *);
- Fl_Menu_Item Main_Menu[] = {
- {"&File",0,0,0,FL_SUBMENU},
- {"&New...", FL_COMMAND+'n', new_cb, 0},
- {"&Open...", FL_COMMAND+'o', open_cb, 0},
- {"&Insert...", FL_COMMAND+'i', open_cb, (void*)1, FL_MENU_DIVIDER},
- {"&Save", FL_COMMAND+'s', save_cb, 0},
- {"Save &As...", FL_COMMAND+FL_SHIFT+'s', save_cb, (void*)1},
- {"Sa&ve A Copy...", 0, save_cb, (void*)2},
- {"Save &Template...", 0, save_template_cb},
- {"&Revert...", 0, revert_cb, 0, FL_MENU_DIVIDER},
- {"&Print...", FL_COMMAND+'p', print_menu_cb},
- {"Write &Code...", FL_COMMAND+FL_SHIFT+'c', write_cb, 0},
- {"Sa&ve, Write code, Exit", FL_F+12, save_write_exit_cb, 0},
- {"&Write Strings...", FL_COMMAND+FL_SHIFT+'w', write_strings_cb, 0, FL_MENU_DIVIDER},
- {relative_history[0], FL_COMMAND+'0', open_history_cb, absolute_history[0]},
- {relative_history[1], FL_COMMAND+'1', open_history_cb, absolute_history[1]},
- {relative_history[2], FL_COMMAND+'2', open_history_cb, absolute_history[2]},
- {relative_history[3], FL_COMMAND+'3', open_history_cb, absolute_history[3]},
- {relative_history[4], FL_COMMAND+'4', open_history_cb, absolute_history[4]},
- {relative_history[5], FL_COMMAND+'5', open_history_cb, absolute_history[5]},
- {relative_history[6], FL_COMMAND+'6', open_history_cb, absolute_history[6]},
- {relative_history[7], FL_COMMAND+'7', open_history_cb, absolute_history[7]},
- {relative_history[8], FL_COMMAND+'8', open_history_cb, absolute_history[8]},
- {relative_history[9], FL_COMMAND+'9', open_history_cb, absolute_history[9], FL_MENU_DIVIDER},
- {"&Quit", FL_COMMAND+'q', exit_cb},
- {0},
- {"&Edit",0,0,0,FL_SUBMENU},
- {"&Undo", FL_COMMAND+'z', undo_cb},
- {"&Redo", FL_COMMAND+FL_SHIFT+'z', redo_cb, 0, FL_MENU_DIVIDER},
- {"C&ut", FL_COMMAND+'x', cut_cb},
- {"&Copy", FL_COMMAND+'c', copy_cb},
- {"&Paste", FL_COMMAND+'v', paste_cb},
- {"Dup&licate", FL_COMMAND+'u', duplicate_cb},
- {"&Delete", FL_Delete, delete_cb, 0, FL_MENU_DIVIDER},
- {"Select &All", FL_COMMAND+'a', select_all_cb},
- {"Select &None", FL_COMMAND+FL_SHIFT+'a', select_none_cb, 0, FL_MENU_DIVIDER},
- {"Pr&operties...", FL_F+1, openwidget_cb},
- {"&Sort",0,sort_cb},
- {"Sort by name",0,sort_by_name_cb},
- {"&Earlier", FL_F+2, earlier_cb},
- {"&Later", FL_F+3, later_cb},
- {"&Group", FL_F+7, group_cb},
- {"Ung&roup", FL_F+8, ungroup_cb,0, FL_MENU_DIVIDER},
- {"Hide O&verlays",FL_COMMAND+FL_SHIFT+'o',toggle_overlays},
- {"Show Widget &Bin...",FL_ALT+'b',toggle_widgetbin_cb},
- {"Show Source Code...",FL_ALT+FL_SHIFT+'s', (Fl_Callback*)toggle_sourceview_cb, 0, FL_MENU_DIVIDER},
- {"Pro&ject Settings...",FL_ALT+'p',show_project_cb},
- {"GU&I Settings...",FL_ALT+FL_SHIFT+'p',show_settings_cb,0,FL_MENU_DIVIDER},
- {"Global &FLTK Settings...",FL_ALT+FL_SHIFT+'g',show_global_settings_cb},
- {0},
- {"&New", 0, 0, (void *)New_Menu, FL_SUBMENU_POINTER},
- {"&Layout",0,0,0,FL_SUBMENU},
- {"&Align",0,0,0,FL_SUBMENU},
- {"&Left",0,(Fl_Callback *)align_widget_cb,(void*)10},
- {"&Center",0,(Fl_Callback *)align_widget_cb,(void*)11},
- {"&Right",0,(Fl_Callback *)align_widget_cb,(void*)12},
- {"&Top",0,(Fl_Callback *)align_widget_cb,(void*)13},
- {"&Middle",0,(Fl_Callback *)align_widget_cb,(void*)14},
- {"&Bottom",0,(Fl_Callback *)align_widget_cb,(void*)15},
- {0},
- {"&Space Evenly",0,0,0,FL_SUBMENU},
- {"&Across",0,(Fl_Callback *)align_widget_cb,(void*)20},
- {"&Down",0,(Fl_Callback *)align_widget_cb,(void*)21},
- {0},
- {"&Make Same Size",0,0,0,FL_SUBMENU},
- {"&Width",0,(Fl_Callback *)align_widget_cb,(void*)30},
- {"&Height",0,(Fl_Callback *)align_widget_cb,(void*)31},
- {"&Both",0,(Fl_Callback *)align_widget_cb,(void*)32},
- {0},
- {"Make Same Size as Parent",0,0,0,FL_SUBMENU},
- {"Width",0,(Fl_Callback *)align_widget_cb,(void*)300},
- {"Height",0,(Fl_Callback *)align_widget_cb,(void*)310},
- {"Both",0,(Fl_Callback *)align_widget_cb,(void*)320},
- {0},
- {"Fill Parent Same Size",0,0,0,FL_SUBMENU},
- {"Width",0,(Fl_Callback *)align_widget_cb,(void*)3000},
- {"Height",0,(Fl_Callback *)align_widget_cb,(void*)3100},
- {"Both",0,(Fl_Callback *)align_widget_cb,(void*)3200},
- {0},
- {"&Center In Group",0,0,0,FL_SUBMENU},
- {"&Horizontal",0,(Fl_Callback *)align_widget_cb,(void*)40},
- {"&Vertical",0,(Fl_Callback *)align_widget_cb,(void*)41},
- {0},
- {"Set &Widget Size",0,0,0,FL_SUBMENU|FL_MENU_DIVIDER},
- {"&Tiny",FL_ALT+'1',(Fl_Callback *)widget_size_cb,(void*)8,0,FL_NORMAL_LABEL,FL_HELVETICA,8},
- {"&Small",FL_ALT+'2',(Fl_Callback *)widget_size_cb,(void*)11,0,FL_NORMAL_LABEL,FL_HELVETICA,11},
- {"&Normal",FL_ALT+'3',(Fl_Callback *)widget_size_cb,(void*)14,0,FL_NORMAL_LABEL,FL_HELVETICA,14},
- {"&Medium",FL_ALT+'4',(Fl_Callback *)widget_size_cb,(void*)18,0,FL_NORMAL_LABEL,FL_HELVETICA,18},
- {"&Large",FL_ALT+'5',(Fl_Callback *)widget_size_cb,(void*)24,0,FL_NORMAL_LABEL,FL_HELVETICA,24},
- {"&Huge",FL_ALT+'6',(Fl_Callback *)widget_size_cb,(void*)32,0,FL_NORMAL_LABEL,FL_HELVETICA,32},
- {0},
- {"&Grid and Size Settings...",FL_COMMAND+'g',show_grid_cb},
- {0},
- {"&Shell",0,0,0,FL_SUBMENU},
- {"Execute &Command...",FL_ALT+'x',(Fl_Callback *)show_shell_window},
- {"Execute &Again...",FL_ALT+'g',(Fl_Callback *)do_shell_command},
- {0},
- {"&Help",0,0,0,FL_SUBMENU},
- {"&Rapid development with FLUID...",0,help_cb},
- {"&FLTK Programmers Manual...",0,manual_cb, 0, FL_MENU_DIVIDER},
- {"&About FLUID...",0,about_cb},
- {0},
- {0}};
- #define BROWSERWIDTH 300
- #define BROWSERHEIGHT 500
- #define WINWIDTH 300
- #define MENUHEIGHT 25
- #define WINHEIGHT (BROWSERHEIGHT+MENUHEIGHT*2)
- extern void fill_in_New_Menu();
- void scheme_cb(Fl_Choice *, void *) {
- if (compile_only)
- return;
- switch (scheme_choice->value()) {
- case 0 : // Default
- Fl::scheme(NULL);
- break;
- case 1 : // None
- Fl::scheme("none");
- break;
- case 2 : // Plastic
- Fl::scheme("plastic");
- break;
- case 3 : // GTK+
- Fl::scheme("gtk+");
- break;
- case 4 : // Gleam
- Fl::scheme("gleam");
- break;
- }
- fluid_prefs.set("scheme", scheme_choice->value());
- }
- void toggle_widgetbin_cb(Fl_Widget *, void *) {
- if (!widgetbin_panel) {
- make_widgetbin();
- if (!position_window(widgetbin_panel,"widgetbin_pos", 1, 320, 30)) return;
- }
- if (widgetbin_panel->visible()) {
- widgetbin_panel->hide();
- widgetbin_item->label("Show Widget &Bin...");
- } else {
- widgetbin_panel->show();
- widgetbin_item->label("Hide Widget &Bin");
- }
- }
- void toggle_sourceview_cb(Fl_Double_Window *, void *) {
- if (!sourceview_panel) {
- make_sourceview();
- sourceview_panel->callback((Fl_Callback*)toggle_sourceview_cb);
- Fl_Preferences svp(fluid_prefs, "sourceview");
- int autorefresh;
- svp.get("autorefresh", autorefresh, 1);
- sv_autorefresh->value(autorefresh);
- int autoposition;
- svp.get("autoposition", autoposition, 1);
- sv_autoposition->value(autoposition);
- int tab;
- svp.get("tab", tab, 0);
- if (tab>=0 && tab<sv_tab->children()) sv_tab->value(sv_tab->child(tab));
- if (!position_window(sourceview_panel,"sourceview_pos", 0, 320, 120, 550, 500)) return;
- }
- if (sourceview_panel->visible()) {
- sourceview_panel->hide();
- sourceview_item->label("Show Source Code...");
- } else {
- sourceview_panel->show();
- sourceview_item->label("Hide Source Code...");
- update_sourceview_cb(0,0);
- }
- }
- void toggle_sourceview_b_cb(Fl_Button*, void *) {
- toggle_sourceview_cb(0,0);
- }
- extern void select(Fl_Type *o, int v);
- extern void deselect();
- Fl_Hold_Browser *widget_borwser_alphabetical = NULL;
- void widget_borwser_alphabetical_cb(Fl_Hold_Browser* o, void* v) {
- Fl_Type *t = (Fl_Type *)o->data(o->value());
- if(t) {
- deselect();
- select(t,1);
- t->open();
- }
- }
- void main_tabs_cb(Fl_Tabs* o, void* v) {
- if(widget_borwser_alphabetical && widget_borwser_alphabetical->visible_r()) {
- //fl_alert("Alphabetical !");
- Fl_Hold_Browser *wba = widget_borwser_alphabetical;
- Fl_Type *f;
- wba->clear();
- char buf[1024];
- char *p;
- #define MAX_WNAME 160
- for (f = Fl_Type::first; f ; f = f->next) {
- if(f->is_code_block()) continue;
- const char *name = f->name();
- Fl_Type *parent = f->parent;
- const char *parent_name = parent ? parent->name() : NULL;
- if(!name) name = (f->title() ? f->title() : "?");
- if(!parent_name) parent_name = (parent && parent->title() ? parent->title() : "?");
- snprintf(buf, MAX_WNAME, "%s -> %s", name, parent_name);
- buf[MAX_WNAME] = '\0';
- for(p=buf; *p; p++) if(*p == '\n') *p=' ';
- wba->add(buf, f);
- }
- wba->sort(FL_SORT_ASCENDING);
- }
- }
- void make_main_window() {
- if (!compile_only) {
- fluid_prefs.get("snap", snap, 1);
- fluid_prefs.get("gridx", gridx, 5);
- fluid_prefs.get("gridy", gridy, 5);
- fluid_prefs.get("show_guides", show_guides, 0);
- fluid_prefs.get("widget_size", Fl_Widget_Type::default_size, 14);
- fluid_prefs.get("show_comments", show_comments, 1);
- make_layout_window();
- make_shell_window();
- }
- if (!main_window) {
- Fl_Widget *o;
- main_window = new Fl_Double_Window(WINWIDTH,WINHEIGHT,"fluid");
- main_window->box(FL_FLAT_BOX);
- main_window->color(FL_BACKGROUND_COLOR);
- Fl_Tabs *tabs = new Fl_Tabs(0,MENUHEIGHT,BROWSERWIDTH,BROWSERHEIGHT+MENUHEIGHT);
- Fl_Group *gmain = new Fl_Group(0, MENUHEIGHT*2,BROWSERWIDTH,BROWSERHEIGHT, "Main View");
- o = make_widget_browser(0,MENUHEIGHT*2,BROWSERWIDTH,BROWSERHEIGHT);
- o->box(FL_FLAT_BOX);
- o->tooltip("Double-click to view or change an item.");
- gmain->end();
- gmain->resizable(o);
- Fl_Group *galpha = new Fl_Group(0, MENUHEIGHT*2,BROWSERWIDTH,BROWSERHEIGHT, "Alphabetical View");
- widget_borwser_alphabetical = new Fl_Hold_Browser(0,MENUHEIGHT*2,BROWSERWIDTH,BROWSERHEIGHT);
- o = widget_borwser_alphabetical;
- o->box(FL_FLAT_BOX);
- o->tooltip("Double-click to view or change an item.");
- o->callback((Fl_Callback*)widget_borwser_alphabetical_cb);
- galpha->end();
- tabs->end();
- tabs->resizable(gmain);
- tabs->callback((Fl_Callback*)main_tabs_cb);
- main_window->resizable(tabs);
- main_menubar = new Fl_Menu_Bar(0,0,BROWSERWIDTH,MENUHEIGHT);
- main_menubar->menu(Main_Menu);
- // quick access to all dynamic menu items
- save_item = (Fl_Menu_Item*)main_menubar->find_item(save_cb);
- history_item = (Fl_Menu_Item*)main_menubar->find_item(open_history_cb);
- widgetbin_item = (Fl_Menu_Item*)main_menubar->find_item(toggle_widgetbin_cb);
- sourceview_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_sourceview_cb);
- main_menubar->global();
- fill_in_New_Menu();
- main_window->end();
- }
- if (!compile_only) {
- load_history();
- make_settings_window();
- make_global_settings_window();
- }
- }
- // Load file history from preferences...
- void load_history() {
- int i; // Looping var
- int max_files;
- fluid_prefs.get("recent_files", max_files, 5);
- if (max_files > 10) max_files = 10;
- for (i = 0; i < max_files; i ++) {
- fluid_prefs.get( Fl_Preferences::Name("file%d", i), absolute_history[i], "", sizeof(absolute_history[i]));
- if (absolute_history[i][0]) {
- // Make a relative version of the filename for the menu...
- fl_filename_relative(relative_history[i], sizeof(relative_history[i]),
- absolute_history[i]);
- if (i == 9) history_item[i].flags = FL_MENU_DIVIDER;
- else history_item[i].flags = 0;
- } else break;
- }
- for (; i < 10; i ++) {
- if (i) history_item[i-1].flags |= FL_MENU_DIVIDER;
- history_item[i].hide();
- }
- }
- // Update file history from preferences...
- void update_history(const char *flname) {
- int i; // Looping var
- char absolute[FL_PATH_MAX];
- int max_files;
- fluid_prefs.get("recent_files", max_files, 5);
- if (max_files > 10) max_files = 10;
- fl_filename_absolute(absolute, sizeof(absolute), flname);
- for (i = 0; i < max_files; i ++)
- #if defined(WIN32) || defined(__APPLE__)
- if (!strcasecmp(absolute, absolute_history[i])) break;
- #else
- if (!strcmp(absolute, absolute_history[i])) break;
- #endif // WIN32 || __APPLE__
- if (i == 0) return;
- if (i >= max_files) i = max_files - 1;
- // Move the other flnames down in the list...
- memmove(absolute_history + 1, absolute_history,
- i * sizeof(absolute_history[0]));
- memmove(relative_history + 1, relative_history,
- i * sizeof(relative_history[0]));
- // Put the new file at the top...
- strlcpy(absolute_history[0], absolute, sizeof(absolute_history[0]));
- fl_filename_relative(relative_history[0], sizeof(relative_history[0]),
- absolute_history[0]);
- // Update the menu items as needed...
- for (i = 0; i < max_files; i ++) {
- fluid_prefs.set( Fl_Preferences::Name("file%d", i), absolute_history[i]);
- if (absolute_history[i][0]) {
- if (i == 9) history_item[i].flags = FL_MENU_DIVIDER;
- else history_item[i].flags = 0;
- } else break;
- }
- for (; i < 10; i ++) {
- fluid_prefs.set( Fl_Preferences::Name("file%d", i), "");
- if (i) history_item[i-1].flags |= FL_MENU_DIVIDER;
- history_item[i].hide();
- }
- fluid_prefs.flush();
- }
- // ********** portable process class definition **********
- class Fl_Process {
- public:
- // construction / destruction
- Fl_Process() {_fpt= NULL;}
- ~Fl_Process() {if (_fpt) close();}
- // FIXME: popen needs the utf8 equivalen fl_popen
- FILE * popen (const char *cmd, const char *mode="r");
- //not necessary here: FILE * fl_fopen (const char *file, const char *mode="r");
- int close();
- FILE * desc() const { return _fpt;} // non null if file is open
- char * get_line(char * line, size_t s) const {return _fpt ? fgets(line, s, _fpt) : NULL;}
- #if defined(WIN32) && !defined(__CYGWIN__)
- protected:
- HANDLE pin[2], pout[2], perr[2];
- char ptmode;
- PROCESS_INFORMATION pi;
- STARTUPINFO si;
- static bool createPipe(HANDLE * h, BOOL bInheritHnd=TRUE);
- private:
- FILE * freeHandles() {
- clean_close(pin[0]); clean_close(pin[1]);
- clean_close(pout[0]); clean_close(pout[1]);
- clean_close(perr[0]); clean_close(perr[1]);
- return NULL; // convenient for error management
- }
- static void clean_close(HANDLE& h);
- #endif
- protected:
- FILE * _fpt;
- };
- #if defined(WIN32) && !defined(__CYGWIN__)
- bool Fl_Process::createPipe(HANDLE * h, BOOL bInheritHnd) {
- SECURITY_ATTRIBUTES sa;
- sa.nLength = sizeof(sa);
- sa.lpSecurityDescriptor = NULL;
- sa.bInheritHandle = bInheritHnd;
- return CreatePipe (&h[0],&h[1],&sa,0) ? true : false;
- }
- #endif
- // portable open process:
- FILE * Fl_Process::popen(const char *cmd, const char *mode) {
- #if defined(WIN32) && !defined(__CYGWIN__)
- // PRECONDITIONS
- if (!mode || !*mode || (*mode!='r' && *mode!='w') ) return NULL;
- if (_fpt) close(); // close first before reuse
- ptmode = *mode;
- pin[0] = pin[1] = pout[0] = pout[1] = perr[0] = perr[1] = INVALID_HANDLE_VALUE;
- // stderr to stdout wanted ?
- int fusion = (strstr(cmd,"2>&1") !=NULL);
- // Create windows pipes
- if (!createPipe(pin) || !createPipe(pout) || (!fusion && !createPipe(perr) ) )
- return freeHandles(); // error
- // Initialize Startup Info
- ZeroMemory(&si, sizeof(STARTUPINFO));
- si.cb = sizeof(STARTUPINFO);
- si.dwFlags = STARTF_USESTDHANDLES;
- si.hStdInput = pin[0];
- si.hStdOutput = pout[1];
- si.hStdError = fusion ? pout[1] : perr [1];
- if ( CreateProcess(NULL, (LPTSTR) cmd,NULL,NULL,TRUE,
- DETACHED_PROCESS,NULL,NULL, &si, &pi)) {
- // don't need theses handles inherited by child process:
- clean_close(pin[0]); clean_close(pout[1]); clean_close(perr[1]);
- HANDLE & h = *mode == 'r' ? pout[0] : pin[1];
- _fpt = _fdopen(_open_osfhandle((fl_intptr_t) h,_O_BINARY),mode);
- h= INVALID_HANDLE_VALUE; // reset the handle pointer that is shared
- // with _fpt so we don't free it twice
- }
- if (!_fpt) freeHandles();
- return _fpt;
- #else
- _fpt=::popen(cmd,mode);
- return _fpt;
- #endif
- }
- int Fl_Process::close() {
- #if defined(WIN32) && !defined(__CYGWIN__)
- if (_fpt) {
- fclose(_fpt);
- clean_close(perr[0]);
- clean_close(pin[1]);
- clean_close(pout[0]);
- _fpt = NULL;
- return 0;
- }
- return -1;
- #else
- int ret = ::pclose(_fpt);
- _fpt=NULL;
- return ret;
- #endif
- }
- #if defined(WIN32) && !defined(__CYGWIN__)
- void Fl_Process::clean_close(HANDLE& h) {
- if (h!= INVALID_HANDLE_VALUE) CloseHandle(h);
- h = INVALID_HANDLE_VALUE;
- }
- #endif
- // ********** Fl_Process class end **********
- static Fl_Process s_proc;
- // Shell command support...
- static bool prepare_shell_command(const char * &command) { // common pre-shell command code all platforms
- shell_window->hide();
- if (s_proc.desc()) {
- fl_alert("Previous shell command still running!");
- return false;
- }
- if ((command = shell_command_input->value()) == NULL || !*command) {
- fl_alert("No shell command entered!");
- return false;
- }
- if (shell_savefl_button->value()) {
- save_cb(0, 0);
- }
- if (shell_writecode_button->value()) {
- compile_only = 1;
- write_cb(0, 0);
- compile_only = 0;
- }
- if (shell_writemsgs_button->value()) {
- compile_only = 1;
- write_strings_cb(0, 0);
- compile_only = 0;
- }
- return true;
- }
- #if !defined(__MWERKS__)
- // Support the full piped shell command...
- void
- shell_pipe_cb(FL_SOCKET, void*) {
- char line[1024]=""; // Line from command output...
- if (s_proc.get_line(line, sizeof(line)) != NULL) {
- // Add the line to the output list...
- shell_run_buffer->append(line);
- } else {
- // End of file; tell the parent...
- Fl::remove_fd(fileno(s_proc.desc()));
- s_proc.close();
- shell_run_buffer->append("... END SHELL COMMAND ...\n");
- }
- shell_run_display->scroll(shell_run_display->count_lines(0,
- shell_run_buffer->length(), 1), 0);
- }
- void
- do_shell_command(Fl_Return_Button*, void*) {
- const char *command=NULL; // Command to run
- if (!prepare_shell_command(command)) return;
- // Show the output window and clear things...
- shell_run_buffer->text("");
- shell_run_buffer->append(command);
- shell_run_buffer->append("\n");
- shell_run_window->label("Shell Command Running...");
- if (s_proc.popen((char *)command) == NULL) {
- fl_alert("Unable to run shell command: %s", strerror(errno));
- return;
- }
- shell_run_button->deactivate();
- shell_run_window->hotspot(shell_run_display);
- shell_run_window->show();
- Fl::add_fd(fileno(s_proc.desc()), shell_pipe_cb);
- while (s_proc.desc()) Fl::wait();
- shell_run_button->activate();
- shell_run_window->label("Shell Command Complete");
- fl_beep();
- while (shell_run_window->shown()) Fl::wait();
- }
- #else
- // Just do basic shell command stuff, no status window...
- void
- do_shell_command(Fl_Return_Button*, void*) {
- const char *command; // Command to run
- int status; // Status from command...
- if (!prepare_shell_command(command)) return;
- if ((status = system(command)) != 0) {
- fl_alert("Shell command returned status %d!", status);
- } else if (completion_button->value()) {
- fl_message("Shell command completed successfully!");
- }
- }
- #endif // !__MWERKS__
- void
- show_shell_window() {
- shell_window->hotspot(shell_command_input);
- shell_window->show();
- }
- void set_filename(const char *c) {
- if (filename) free((void *)filename);
- filename = c ? strdup(c) : NULL;
- if (filename && !compile_only)
- update_history(filename);
- set_modflag(modflag);
- }
- //
- // The Source View system offers an immediate preview of the code
- // files that will be generated by FLUID. It also marks the code
- // generated for the last selected item in the header and the source
- // file.
- //
- // Can we patent this? ;-) - Matt, [email protected]
- //
- //
- // Update the header and source code highlighting depending on the
- // currently selected object
- //
- void update_sourceview_position()
- {
- if (!sourceview_panel || !sourceview_panel->visible())
- return;
- if (sv_autoposition->value()==0)
- return;
- if (sourceview_panel && sourceview_panel->visible() && Fl_Type::current) {
- int pos0, pos1;
- if (sv_source->visible_r()) {
- pos0 = Fl_Type::current->code_position;
- pos1 = Fl_Type::current->code_position_end;
- if (pos0>=0) {
- if (pos1<pos0)
- pos1 = pos0;
- sv_source->buffer()->highlight(pos0, pos1);
- int line = sv_source->buffer()->count_lines(0, pos0);
- sv_source->scroll(line, 0);
- }
- }
- if (sv_header->visible_r()) {
- pos0 = Fl_Type::current->header_position;
- pos1 = Fl_Type::current->header_position_end;
- if (pos0>=0) {
- if (pos1<pos0)
- pos1 = pos0;
- sv_header->buffer()->highlight(pos0, pos1);
- int line = sv_header->buffer()->count_lines(0, pos0);
- sv_header->scroll(line, 0);
- }
- }
- }
- }
- //
- // Update the selected object depending on the view position
- //
- void update_selected_object_by_view_position(int source_position, int header_position)
- {
- Fl_Type *t, *found = NULL;
- for (t = Fl_Type::first; t; t = t->next) {
- // Find the first window...
- if(source_position >= 0) {
- if( (source_position >= t->code_position) && (source_position <= t->code_position_end) ){
- found = t;
- };
- } else if(header_position >= 0) {
- if( (header_position >= t->header_position) && (header_position <= t->header_position_end) ) {
- found = t;
- };
- } else return;
- }
- if (found){
- deselect();
- //Fl_Type::current = t;
- select(found,1);
- found->open();
- }
- }
- void update_sourceview_position_cb(Fl_Tabs*, void*)
- {
- update_sourceview_position();
- }
- void update_widget_browser_position_cb(CodeViewer *source, CodeViewer *header, Fl_Input *ii){
- char buf[64];
- int start, end, line;
- CodeViewer *o = source ? source : header;
- if(o) {
- o->buffer()->selection_position(&start, &end);
- line = o->buffer()->count_lines(0, start);
- sprintf(buf,"%d", line);
- ii->value(buf);
- update_selected_object_by_view_position(source ? start : -1, header ? start : -1);
- }
- }
- static char *sv_source_filename = 0;
- static char *sv_header_filename = 0;
- //
- // Generate a header and source file in a temporary directory and
- // load those into the Code Viewer widgets.
- //
- void update_sourceview_cb(Fl_Button*, void*)
- {
- if (!sourceview_panel || !sourceview_panel->visible())
- return;
- // generate space for the source and header file filenames
- if (!sv_source_filename) {
- sv_source_filename = (char*)malloc(FL_PATH_MAX);
- fluid_prefs.getUserdataPath(sv_source_filename, FL_PATH_MAX);
- strlcat(sv_source_filename, "source_view_tmp.cxx", FL_PATH_MAX);
- }
- if (!sv_header_filename) {
- sv_header_filename = (char*)malloc(FL_PATH_MAX);
- fluid_prefs.getUserdataPath(sv_header_filename, FL_PATH_MAX);
- strlcat(sv_header_filename, "source_view_tmp.h", FL_PATH_MAX);
- }
- strlcpy(i18n_program, fl_filename_name(sv_source_filename), sizeof(i18n_program));
- fl_filename_setext(i18n_program, sizeof(i18n_program), "");
- const char *code_file_name_bak = code_file_name;
- code_file_name = sv_source_filename;
- const char *header_file_name_bak = header_file_name;
- header_file_name = sv_header_filename;
- // generate the code and load the files
- write_sourceview = 1;
- // generate files
- if (write_code(sv_source_filename, sv_header_filename))
- {
- // load file into source editor
- int pos = sv_source->top_line();
- sv_source->buffer()->loadfile(sv_source_filename);
- sv_source->scroll(pos, 0);
- // load file into header editor
- pos = sv_header->top_line();
- sv_header->buffer()->loadfile(sv_header_filename);
- sv_header->scroll(pos, 0);
- // update the source code highlighting
- update_sourceview_position();
- }
- write_sourceview = 0;
- code_file_name = code_file_name_bak;
- header_file_name = header_file_name_bak;
- }
- void update_sourceview_timer(void*)
- {
- update_sourceview_cb(0,0);
- }
- // Set the "modified" flag and update the title of the main window...
- void set_modflag(int mf) {
- const char *basename;
- static char title[FL_PATH_MAX];
- modflag = mf;
- if (main_window) {
- if (!filename) basename = "Untitled.fl";
- else if ((basename = strrchr(filename, '/')) != NULL) basename ++;
- #if defined(WIN32) || defined(__EMX__)
- else if ((basename = strrchr(filename, '\\')) != NULL) basename ++;
- #endif // WIN32 || __EMX__
- else basename = filename;
- if (modflag) {
- snprintf(title, sizeof(title), "%s (modified)", basename);
- main_window->label(title);
- } else main_window->label(basename);
- }
- // if the UI was modified in any way, update the Source View panel
- if (sourceview_panel && sourceview_panel->visible() && sv_autorefresh->value())
- {
- // we will only update ealiest 0.5 seconds after the last change, and only
- // if no other change was made, so dragging a widget will not generate any
- // CPU load
- Fl::remove_timeout(update_sourceview_timer, 0);
- Fl::add_timeout(0.5, update_sourceview_timer, 0);
- }
- // Enable/disable the Save menu item...
- if (modflag) save_item->activate();
- else save_item->deactivate();
- }
- ////////////////////////////////////////////////////////////////
- static int arg(int argc, char** argv, int& i) {
- if (argv[i][1] == 'c' && !argv[i][2]) {compile_only = 1; i++; return 1;}
- if (argv[i][1] == 'c' && argv[i][2] == 's' && !argv[i][3]) {compile_only = 1; compile_strings = 1; i++; return 1;}
- if (argv[i][1] == 'o' && !argv[i][2] && i+1 < argc) {
- code_file_name = argv[i+1];
- code_file_set = 1;
- i += 2;
- return 2;
- }
- if (argv[i][1] == 'h' && !argv[i][2]) {
- header_file_name = argv[i+1];
- header_file_set = 1;
- i += 2;
- return 2;
- }
- Fl_Plugin_Manager pm("commandline");
- int j, n = pm.plugins();
- for (j=0; j<n; j++) {
- Fl_Commandline_Plugin *pi = (Fl_Commandline_Plugin*)pm.plugin(j);
- int r = pi->arg(argc, argv, i);
- if (r) return r;
- }
- return 0;
- }
- #if ! (defined(WIN32) && !defined (__CYGWIN__))
- int quit_flag = 0;
- #include <signal.h>
- #ifdef _sigargs
- #define SIGARG _sigargs
- #else
- #ifdef __sigargs
- #define SIGARG __sigargs
- #else
- #define SIGARG int // you may need to fix this for older systems
- #endif
- #endif
- extern "C" {
- static void sigint(SIGARG) {
- signal(SIGINT,sigint);
- quit_flag = 1;
- }
- }
- #endif
- int main(int argc,char **argv) {
- int i = 1;
- if (!Fl::args(argc,argv,i,arg) || i < argc-1) {
- static const char *msg =
- "usage: %s <switches> name.fl\n"
- " -c : write .cxx and .h and exit\n"
- " -cs : write .cxx and .h and strings and exit\n"
- " -o <name> : .cxx output filename, or extension if <name> starts with '.'\n"
- " -h <name> : .h output filename, or extension if <name> starts with '.'\n";
- int len = strlen(msg) + strlen(argv[0]) + strlen(Fl::help);
- Fl_Plugin_Manager pm("commandline");
- int i, n = pm.plugins();
- for (i=0; i<n; i++) {
- Fl_Commandline_Plugin *pi = (Fl_Commandline_Plugin*)pm.plugin(i);
- if (pi) len += strlen(pi->help());
- }
- char *buf = (char*)malloc(len+1);
- sprintf(buf, msg, argv[0]);
- for (i=0; i<n; i++) {
- Fl_Commandline_Plugin *pi = (Fl_Commandline_Plugin*)pm.plugin(i);
- if (pi) strcat(buf, pi->help());
- }
- strcat(buf, Fl::help);
- #ifdef _MSC_VER
- fl_message("%s\n", buf);
- #else
- fprintf(stderr, "%s\n", buf);
- #endif
- free(buf);
- return 1;
- }
- if (exit_early)
- exit(0);
- #ifdef USE_VM_SCRIPT
- my_open_script_vm();
- #endif
- const char *c = argv[i];
- fl_register_images();
- make_main_window();
- if (c) set_filename(c);
- if (!compile_only) {
- #ifdef __APPLE__
- fl_open_callback(apple_open_cb);
- #endif // __APPLE__
- Fl::visual((Fl_Mode)(FL_DOUBLE|FL_INDEX));
- Fl_File_Icon::load_system_icons();
- main_window->callback(exit_cb);
- position_window(main_window,"main_window_pos", 1, 10, 30, WINWIDTH, WINHEIGHT );
- main_window->show(argc,argv);
- toggle_widgetbin_cb(0,0);
- toggle_sourceview_cb(0,0);
- if (!c && openlast_button->value() && absolute_history[0][0]) {
- // Open previous file when no file specified...
- open_history_cb(0, absolute_history[0]);
- }
- }
- undo_suspend();
- if (c && !read_file(c,0)) {
- if (compile_only) {
- fprintf(stderr,"%s : %s\n", c, strerror(errno));
- exit(1);
- }
- fl_message("Can't read %s: %s", c, strerror(errno));
- }
- undo_resume();
- if (compile_only) {
- if (compile_strings) write_strings_cb(0,0);
- write_cb(0,0);
- exit(0);
- }
- set_modflag(0);
- undo_clear();
- #ifndef WIN32
- signal(SIGINT,sigint);
- #endif
- grid_cb(horizontal_input, 0); // Makes sure that windows get snap params...
- #ifdef WIN32
- Fl::run();
- #else
- while (!quit_flag) Fl::wait();
- if (quit_flag) exit_cb(0,0);
- #endif // WIN32
- undo_clear();
- #ifdef USE_VM_SCRIPT
- my_close_script_vm();
- #endif
- return (0);
- }
- //
- // End of "$Id: fluid.cxx 10113 2014-02-25 04:24:41Z greg.ercolano $".
- //
|