1999-01-07 19:58:26 +03:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1999-01-07 19:58:26 +03:00
|
|
|
//
|
|
|
|
// Main demo program for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2018-02-01 00:17:17 +03:00
|
|
|
// Copyright 1998-2018 by Bill Spitzak and others.
|
1999-01-07 19:58:26 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// 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:
|
|
|
|
//
|
2018-12-04 16:16:55 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1999-01-07 19:58:26 +03:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
2018-12-04 16:16:55 +03:00
|
|
|
// https://www.fltk.org/str.php
|
1999-01-07 19:58:26 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2017-10-15 13:46:16 +03:00
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
// *FIXME*
|
|
|
|
// Implement fl_putenv(). Then remove the following comment
|
|
|
|
// and the #define's of fl_putenv below
|
2017-10-15 13:46:16 +03:00
|
|
|
|
|
|
|
// Visual C++ 2005 incorrectly displays a warning about the use of
|
|
|
|
// POSIX APIs on Windows, which is supposed to be POSIX compliant...
|
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# define fl_putenv _putenv
|
1999-01-07 19:58:26 +03:00
|
|
|
#else
|
2017-11-12 21:00:45 +03:00
|
|
|
# define fl_putenv putenv
|
|
|
|
#endif // _MSC_VER
|
|
|
|
|
|
|
|
// *FIXME* To do:
|
|
|
|
// Check whether '#include <unistd.h>' can be removed since chdir()
|
|
|
|
// has been replaced with fl_chdir() (AlbrechtS, Nov 12, 2017)
|
|
|
|
|
|
|
|
#if defined __APPLE__
|
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
|
|
|
#include <unistd.h> // no longer necessary with fl_chdir() ?
|
1999-01-07 19:58:26 +03:00
|
|
|
#endif
|
2017-11-12 21:00:45 +03:00
|
|
|
|
1999-01-07 19:58:26 +03:00
|
|
|
#include <FL/Fl.H>
|
2009-04-21 13:09:37 +04:00
|
|
|
#include <FL/Fl_Double_Window.H>
|
1999-01-07 19:58:26 +03:00
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
2006-10-11 07:12:15 +04:00
|
|
|
#include <FL/Fl_Choice.H>
|
1999-01-07 19:58:26 +03:00
|
|
|
#include <FL/filename.H>
|
2018-02-01 00:17:17 +03:00
|
|
|
#include <FL/platform.H>
|
1999-01-07 19:58:26 +03:00
|
|
|
|
2016-01-31 00:00:12 +03:00
|
|
|
/* Define a macro to decide if a trailing 'd' needs to be removed
|
|
|
|
from the executable file name. Previous versions of Visual Studio
|
|
|
|
added a 'd' to the executable file name ('demod.exe') in Debug
|
|
|
|
configurations that needed to be removed.
|
|
|
|
This is no longer true with CMake-generated IDE's since FLTK 1.4.
|
|
|
|
The 'old' behavior obviously applied or still applies to
|
|
|
|
CodeWarrior (__MWERKS__).
|
|
|
|
*FIXME* is this still true and necessary?
|
|
|
|
*/
|
|
|
|
|
|
|
|
// #if ( defined _MSC_VER || defined __MWERKS__ ) && defined _DEBUG
|
|
|
|
|
2018-02-09 17:39:42 +03:00
|
|
|
#if defined(_WIN32) && defined(__MWERKS__) && defined(_DEBUG)
|
2016-01-31 00:00:12 +03:00
|
|
|
# define DEBUG_EXE_WITH_D 1
|
|
|
|
#else
|
|
|
|
# define DEBUG_EXE_WITH_D 0
|
|
|
|
#endif
|
|
|
|
|
1999-01-07 19:58:26 +03:00
|
|
|
/* The form description */
|
|
|
|
|
|
|
|
void doexit(Fl_Widget *, void *);
|
|
|
|
void doback(Fl_Widget *, void *);
|
|
|
|
void dobut(Fl_Widget *, long);
|
2006-10-11 07:12:15 +04:00
|
|
|
void doscheme(Fl_Choice *c, void *) {
|
|
|
|
Fl::scheme(c->text(c->value()));
|
|
|
|
}
|
1999-01-07 19:58:26 +03:00
|
|
|
|
2009-04-21 13:09:37 +04:00
|
|
|
Fl_Double_Window *form;
|
1999-01-07 19:58:26 +03:00
|
|
|
Fl_Button *but[9];
|
|
|
|
|
|
|
|
void create_the_forms() {
|
|
|
|
Fl_Widget *obj;
|
2009-04-21 13:09:37 +04:00
|
|
|
form = new Fl_Double_Window(350, 440);
|
2008-12-21 18:38:52 +03:00
|
|
|
obj = new Fl_Box(FL_FRAME_BOX,10,15,330,40,"FLTK Demonstration");
|
1999-01-07 19:58:26 +03:00
|
|
|
obj->color(FL_GRAY-4);
|
|
|
|
obj->labelsize(24);
|
|
|
|
obj->labelfont(FL_BOLD);
|
|
|
|
obj->labeltype(FL_ENGRAVED_LABEL);
|
2008-12-21 18:38:52 +03:00
|
|
|
obj = new Fl_Box(FL_FRAME_BOX,10,65,330,330,0);
|
1999-01-07 19:58:26 +03:00
|
|
|
obj->color(FL_GRAY-8);
|
2008-12-21 18:38:52 +03:00
|
|
|
obj = new Fl_Button(280,405,60,25,"Exit");
|
1999-01-07 19:58:26 +03:00
|
|
|
obj->callback(doexit);
|
2008-12-21 18:38:52 +03:00
|
|
|
Fl_Choice *choice = new Fl_Choice(75, 405, 100, 25, "Scheme:");
|
2006-10-11 07:12:15 +04:00
|
|
|
choice->labelfont(FL_HELVETICA_BOLD);
|
|
|
|
choice->add("none");
|
|
|
|
choice->add("gtk+");
|
2014-02-27 01:21:14 +04:00
|
|
|
choice->add("gleam");
|
2006-10-11 07:12:15 +04:00
|
|
|
choice->add("plastic");
|
|
|
|
choice->callback((Fl_Callback *)doscheme);
|
|
|
|
Fl::scheme(NULL);
|
|
|
|
if (!Fl::scheme()) choice->value(0);
|
|
|
|
else if (!strcmp(Fl::scheme(), "gtk+")) choice->value(1);
|
2014-02-27 01:21:14 +04:00
|
|
|
else if (!strcmp(Fl::scheme(), "gleam")) choice->value(2);
|
|
|
|
else if (!strcmp(Fl::scheme(), "plastic")) choice->value(3);
|
|
|
|
else choice->value(0);
|
2008-12-21 18:38:52 +03:00
|
|
|
obj = new Fl_Button(10,15,330,380); obj->type(FL_HIDDEN_BUTTON);
|
1999-01-07 19:58:26 +03:00
|
|
|
obj->callback(doback);
|
2008-12-21 18:38:52 +03:00
|
|
|
obj = but[0] = new Fl_Button( 30, 85,90,90);
|
|
|
|
obj = but[1] = new Fl_Button(130, 85,90,90);
|
|
|
|
obj = but[2] = new Fl_Button(230, 85,90,90);
|
|
|
|
obj = but[3] = new Fl_Button( 30,185,90,90);
|
|
|
|
obj = but[4] = new Fl_Button(130,185,90,90);
|
|
|
|
obj = but[5] = new Fl_Button(230,185,90,90);
|
|
|
|
obj = but[6] = new Fl_Button( 30,285,90,90);
|
|
|
|
obj = but[7] = new Fl_Button(130,285,90,90);
|
|
|
|
obj = but[8] = new Fl_Button(230,285,90,90);
|
1999-01-07 19:58:26 +03:00
|
|
|
for (int i=0; i<9; i++) {
|
|
|
|
but[i]->align(FL_ALIGN_WRAP);
|
|
|
|
but[i]->callback(dobut, i);
|
|
|
|
}
|
2008-12-21 18:38:52 +03:00
|
|
|
form->end();
|
1999-01-07 19:58:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Maintaining and building up the menus. */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char name[64];
|
|
|
|
int numb;
|
|
|
|
char iname[9][64];
|
|
|
|
char icommand[9][64];
|
|
|
|
} MENU;
|
|
|
|
|
|
|
|
#define MAXMENU 32
|
|
|
|
|
|
|
|
MENU menus[MAXMENU];
|
|
|
|
int mennumb = 0;
|
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Return the number of a given menu name. */
|
|
|
|
int find_menu(const char* nnn) {
|
1999-01-07 19:58:26 +03:00
|
|
|
int i;
|
|
|
|
for (i=0; i<mennumb; i++)
|
|
|
|
if (strcmp(menus[i].name,nnn) == 0) return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Create a new menu with name nnn */
|
|
|
|
void create_menu(const char* nnn) {
|
1999-01-07 19:58:26 +03:00
|
|
|
if (mennumb == MAXMENU -1) return;
|
|
|
|
strcpy(menus[mennumb].name,nnn);
|
|
|
|
menus[mennumb].numb = 0;
|
|
|
|
mennumb++;
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Add an item to a menu */
|
|
|
|
void addto_menu(const char* men, const char* item, const char* comm) {
|
1999-01-07 19:58:26 +03:00
|
|
|
int n = find_menu(men);
|
|
|
|
if (n<0) { create_menu(men); n = find_menu(men); }
|
|
|
|
if (menus[n].numb == 9) return;
|
|
|
|
strcpy(menus[n].iname[menus[n].numb],item);
|
|
|
|
strcpy(menus[n].icommand[menus[n].numb],comm);
|
|
|
|
menus[n].numb++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Button to Item conversion and back. */
|
|
|
|
|
|
|
|
int b2n[][9] = {
|
|
|
|
{ -1, -1, -1, -1, 0, -1, -1, -1, -1},
|
|
|
|
{ -1, -1, -1, 0, -1, 1, -1, -1, -1},
|
|
|
|
{ 0, -1, -1, -1, 1, -1, -1, -1, 2},
|
|
|
|
{ 0, -1, 1, -1, -1, -1, 2, -1, 3},
|
|
|
|
{ 0, -1, 1, -1, 2, -1, 3, -1, 4},
|
|
|
|
{ 0, -1, 1, 2, -1, 3, 4, -1, 5},
|
|
|
|
{ 0, -1, 1, 2, 3, 4, 5, -1, 6},
|
|
|
|
{ 0, 1, 2, 3, -1, 4, 5, 6, 7},
|
|
|
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8}
|
2009-12-07 01:21:55 +03:00
|
|
|
};
|
1999-01-07 19:58:26 +03:00
|
|
|
int n2b[][9] = {
|
|
|
|
{ 4, -1, -1, -1, -1, -1, -1, -1, -1},
|
|
|
|
{ 3, 5, -1, -1, -1, -1, -1, -1, -1},
|
|
|
|
{ 0, 4, 8, -1, -1, -1, -1, -1, -1},
|
|
|
|
{ 0, 2, 6, 8, -1, -1, -1, -1, -1},
|
|
|
|
{ 0, 2, 4, 6, 8, -1, -1, -1, -1},
|
|
|
|
{ 0, 2, 3, 5, 6, 8, -1, -1, -1},
|
|
|
|
{ 0, 2, 3, 4, 5, 6, 8, -1, -1},
|
|
|
|
{ 0, 1, 2, 3, 5, 6, 7, 8, -1},
|
|
|
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8}
|
2009-12-07 01:21:55 +03:00
|
|
|
};
|
1999-01-07 19:58:26 +03:00
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Transform a button number to an item number when there are
|
|
|
|
maxnumb items in total. -1 if the button should not exist. */
|
1999-01-07 19:58:26 +03:00
|
|
|
int but2numb(int bnumb, int maxnumb)
|
2009-12-07 01:21:55 +03:00
|
|
|
{ return b2n[maxnumb][bnumb]; }
|
1999-01-07 19:58:26 +03:00
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Transform an item number to a button number when there are
|
|
|
|
maxnumb items in total. -1 if the item should not exist. */
|
1999-01-07 19:58:26 +03:00
|
|
|
int numb2but(int inumb, int maxnumb)
|
2009-12-07 01:21:55 +03:00
|
|
|
{ return n2b[maxnumb][inumb]; }
|
1999-01-07 19:58:26 +03:00
|
|
|
|
|
|
|
/* Pushing and Popping menus */
|
|
|
|
|
|
|
|
char stack[64][32];
|
2005-04-11 11:35:33 +04:00
|
|
|
int stsize = 0;
|
1999-01-07 19:58:26 +03:00
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Push a menu to be visible */
|
|
|
|
void push_menu(const char* nnn) {
|
1999-01-07 19:58:26 +03:00
|
|
|
int n,i,bn;
|
|
|
|
int men = find_menu(nnn);
|
|
|
|
if (men < 0) return;
|
|
|
|
n = menus[men].numb;
|
|
|
|
for (i=0; i<9; i++) but[i]->hide();
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
{
|
|
|
|
bn = numb2but(i,n-1);
|
|
|
|
but[bn]->show();
|
|
|
|
but[bn]->label(menus[men].iname[i]);
|
2001-08-02 01:24:49 +04:00
|
|
|
if (menus[men].icommand[i][0] != '@') but[bn]->tooltip(menus[men].icommand[i]);
|
|
|
|
else but[bn]->tooltip(0);
|
1999-01-07 19:58:26 +03:00
|
|
|
}
|
2005-12-30 13:13:17 +03:00
|
|
|
if (stack[stsize]!=nnn)
|
|
|
|
strcpy(stack[stsize],nnn);
|
1999-01-07 19:58:26 +03:00
|
|
|
stsize++;
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Pop a menu */
|
|
|
|
void pop_menu() {
|
1999-01-07 19:58:26 +03:00
|
|
|
if (stsize<=1) return;
|
|
|
|
stsize -= 2;
|
|
|
|
push_menu(stack[stsize]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The callback Routines */
|
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Handle a button push */
|
|
|
|
void dobut(Fl_Widget *, long arg) {
|
1999-01-07 19:58:26 +03:00
|
|
|
int men = find_menu(stack[stsize-1]);
|
|
|
|
int n = menus[men].numb;
|
|
|
|
int bn = but2numb( (int) arg, n-1);
|
2017-11-12 21:00:45 +03:00
|
|
|
if (menus[men].icommand[bn][0] == '@') {
|
1999-01-07 19:58:26 +03:00
|
|
|
push_menu(menus[men].icommand[bn]);
|
2017-11-12 21:00:45 +03:00
|
|
|
} else {
|
|
|
|
|
2018-02-09 17:39:42 +03:00
|
|
|
#ifdef _WIN32
|
2017-11-12 21:00:45 +03:00
|
|
|
|
1999-01-07 19:58:26 +03:00
|
|
|
STARTUPINFO suInfo; // Process startup information
|
|
|
|
PROCESS_INFORMATION prInfo; // Process information
|
2016-03-05 17:40:49 +03:00
|
|
|
|
|
|
|
# if DEBUG_EXE_WITH_D
|
|
|
|
const char *exe = "d.exe"; // exe name with trailing 'd'
|
|
|
|
# else
|
|
|
|
const char *exe = ".exe"; // exe name w/o trailing 'd'
|
|
|
|
# endif
|
|
|
|
|
1999-01-07 19:58:26 +03:00
|
|
|
memset(&suInfo, 0, sizeof(suInfo));
|
|
|
|
suInfo.cb = sizeof(suInfo);
|
2009-12-07 01:21:55 +03:00
|
|
|
|
1999-02-23 00:09:13 +03:00
|
|
|
int icommand_length = strlen(menus[men].icommand[bn]);
|
2009-12-07 01:21:55 +03:00
|
|
|
|
1999-02-23 00:09:13 +03:00
|
|
|
char* copy_of_icommand = new char[icommand_length+1];
|
|
|
|
strcpy(copy_of_icommand,menus[men].icommand[bn]);
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2018-02-09 17:39:42 +03:00
|
|
|
// On Windows the .exe suffix needs to be appended to the command
|
1999-02-23 00:09:13 +03:00
|
|
|
// whilst leaving any additional parameters unchanged - this
|
|
|
|
// is required to handle the correct conversion of cases such as :
|
|
|
|
// `../fluid/fluid valuators.fl' to '../fluid/fluid.exe valuators.fl'.
|
2016-03-05 17:40:49 +03:00
|
|
|
|
1999-02-23 00:09:13 +03:00
|
|
|
// skip leading spaces.
|
|
|
|
char* start_command = copy_of_icommand;
|
2016-03-05 17:40:49 +03:00
|
|
|
while (*start_command == ' ') ++start_command;
|
|
|
|
|
1999-02-23 00:09:13 +03:00
|
|
|
// find the space between the command and parameters if one exists.
|
|
|
|
char* start_parameters = strchr(start_command,' ');
|
2016-03-05 17:40:49 +03:00
|
|
|
|
1999-02-23 00:09:13 +03:00
|
|
|
char* command = new char[icommand_length+6]; // 6 for extra 'd.exe\0'
|
2016-03-05 17:40:49 +03:00
|
|
|
|
1999-02-23 00:09:13 +03:00
|
|
|
if (start_parameters==NULL) { // no parameters required.
|
2016-03-05 17:40:49 +03:00
|
|
|
sprintf(command, "%s%s", start_command, exe);
|
1999-02-23 00:09:13 +03:00
|
|
|
} else { // parameters required.
|
|
|
|
// break the start_command at the intermediate space between
|
|
|
|
// start_command and start_parameters.
|
|
|
|
*start_parameters = 0;
|
|
|
|
// move start_paremeters to skip over the intermediate space.
|
|
|
|
++start_parameters;
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2016-03-05 17:40:49 +03:00
|
|
|
sprintf(command, "%s%s %s", start_command, exe, start_parameters);
|
1999-02-23 00:09:13 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
|
1999-01-07 19:58:26 +03:00
|
|
|
CreateProcess(NULL, command, NULL, NULL, FALSE,
|
|
|
|
NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo, &prInfo);
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2005-12-30 13:13:17 +03:00
|
|
|
delete[] command;
|
|
|
|
delete[] copy_of_icommand;
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2012-12-05 18:53:03 +04:00
|
|
|
#elif defined __APPLE__
|
2017-11-12 21:00:45 +03:00
|
|
|
|
2009-12-07 01:21:55 +03:00
|
|
|
char *cmd = strdup(menus[men].icommand[bn]);
|
|
|
|
char *arg = strchr(cmd, ' ');
|
2008-09-11 03:56:49 +04:00
|
|
|
|
2010-02-22 01:46:13 +03:00
|
|
|
char command[2048], path[2048], app_path[2048];
|
|
|
|
|
2016-03-05 17:40:49 +03:00
|
|
|
// this neat little block of code ensures that the current directory
|
|
|
|
// is set to the location of the Demo application.
|
2010-02-22 01:46:13 +03:00
|
|
|
CFBundleRef app = CFBundleGetMainBundle();
|
|
|
|
CFURLRef url = CFBundleCopyBundleURL(app);
|
|
|
|
CFStringRef cc_app_path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
|
2012-12-05 18:53:03 +04:00
|
|
|
CFRelease(url);
|
2010-02-22 01:46:13 +03:00
|
|
|
CFStringGetCString(cc_app_path, app_path, 2048, kCFStringEncodingUTF8);
|
2012-12-05 18:53:03 +04:00
|
|
|
CFRelease(cc_app_path);
|
2010-02-22 01:46:13 +03:00
|
|
|
if (*app_path) {
|
2016-08-31 20:01:27 +03:00
|
|
|
if (memcmp(app_path + strlen(app_path) - 4, ".app", 4) == 0) {
|
|
|
|
char *n = strrchr(app_path, '/');
|
|
|
|
if (n) *n = 0;
|
2010-02-22 01:46:13 +03:00
|
|
|
}
|
2017-11-12 21:00:45 +03:00
|
|
|
fl_chdir(app_path);
|
2010-02-22 01:46:13 +03:00
|
|
|
}
|
|
|
|
|
2012-12-10 16:49:59 +04:00
|
|
|
char *name = new char[strlen(cmd) + 5];
|
|
|
|
strcpy(name, cmd);
|
2015-04-08 18:44:57 +03:00
|
|
|
if (arg) name[arg-cmd] = 0;
|
2012-12-10 16:49:59 +04:00
|
|
|
strcat(name, ".app");
|
|
|
|
// check whether app bundle exists
|
|
|
|
if ( ! fl_filename_isdir(name) ) strcpy(name, cmd);
|
2009-12-07 01:21:55 +03:00
|
|
|
if (arg) {
|
2012-12-05 18:53:03 +04:00
|
|
|
const char *fluidpath;
|
2009-12-07 01:21:55 +03:00
|
|
|
*arg = 0;
|
2012-12-05 18:53:03 +04:00
|
|
|
#if defined USING_XCODE
|
|
|
|
fl_filename_absolute(path, 2048, "../../../../test/");
|
2018-12-04 16:16:55 +03:00
|
|
|
fluidpath = "fluid.app";
|
2012-12-05 18:53:03 +04:00
|
|
|
#else
|
|
|
|
strcpy(path, app_path); strcat(path, "/");
|
|
|
|
fluidpath = "../fluid/fluid.app";
|
2012-12-10 16:49:59 +04:00
|
|
|
// check whether fluid bundle exists
|
|
|
|
if ( ! fl_filename_isdir(fluidpath) ) fluidpath = "../fluid";
|
2012-12-05 18:53:03 +04:00
|
|
|
#endif
|
2010-02-22 01:46:13 +03:00
|
|
|
if (strcmp(cmd, "../fluid/fluid")==0) {
|
2012-12-05 18:53:03 +04:00
|
|
|
sprintf(command, "open %s --args %s%s", fluidpath, path, arg+1);
|
2010-02-22 01:46:13 +03:00
|
|
|
} else {
|
2012-12-10 16:49:59 +04:00
|
|
|
sprintf(command, "open %s --args %s%s", name, path, arg+1);
|
2010-02-22 01:46:13 +03:00
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
} else {
|
2012-12-10 16:49:59 +04:00
|
|
|
sprintf(command, "open %s", name);
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2012-12-10 16:49:59 +04:00
|
|
|
delete[] name;
|
2017-11-12 21:00:45 +03:00
|
|
|
// puts(command);
|
2008-09-11 03:56:49 +04:00
|
|
|
system(command);
|
2009-12-07 01:21:55 +03:00
|
|
|
free(cmd);
|
2017-11-12 21:00:45 +03:00
|
|
|
|
2018-02-09 17:39:42 +03:00
|
|
|
#else // Non Windows systems.
|
2017-11-12 21:00:45 +03:00
|
|
|
|
1999-02-23 00:09:13 +03:00
|
|
|
int icommand_length = strlen(menus[men].icommand[bn]);
|
|
|
|
char* command = new char[icommand_length+5]; // 5 for extra './' and ' &\0'
|
2017-11-12 21:00:45 +03:00
|
|
|
|
1999-01-07 19:58:26 +03:00
|
|
|
sprintf(command, "./%s &", menus[men].icommand[bn]);
|
2010-10-29 01:47:01 +04:00
|
|
|
if (system(command)==-1) { /* ignore */ }
|
2017-11-12 21:00:45 +03:00
|
|
|
|
2005-12-30 13:13:17 +03:00
|
|
|
delete[] command;
|
2017-11-12 21:00:45 +03:00
|
|
|
|
2018-02-09 17:39:42 +03:00
|
|
|
#endif // _WIN32
|
1999-01-07 19:58:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void doback(Fl_Widget *, void *) {pop_menu();}
|
|
|
|
|
|
|
|
void doexit(Fl_Widget *, void *) {exit(0);}
|
|
|
|
|
2017-11-12 21:00:45 +03:00
|
|
|
/* Load the menu file. Returns whether successful. */
|
|
|
|
int load_the_menu(char* fname) {
|
2010-02-21 00:14:47 +03:00
|
|
|
FILE *fin = 0;
|
1999-01-07 19:58:26 +03:00
|
|
|
char line[256], mname[64],iname[64],cname[64];
|
2011-01-02 06:50:54 +03:00
|
|
|
int i, j;
|
2010-11-18 23:00:01 +03:00
|
|
|
fin = fl_fopen(fname,"r");
|
2016-08-31 19:14:39 +03:00
|
|
|
#if defined ( __APPLE__ )
|
2011-01-02 06:50:54 +03:00
|
|
|
if (fin == NULL) {
|
2009-12-07 01:21:55 +03:00
|
|
|
// mac os bundle menu detection:
|
2010-02-21 20:56:25 +03:00
|
|
|
char* pos = strrchr(fname,'/');
|
|
|
|
if (!pos) return 0;
|
2016-04-09 15:37:44 +03:00
|
|
|
*pos = '\0';
|
2010-02-21 20:56:25 +03:00
|
|
|
pos = strrchr(fname,'/');
|
|
|
|
if (!pos) return 0;
|
|
|
|
strcpy(pos,"/Resources/demo.menu");
|
2010-11-18 23:00:01 +03:00
|
|
|
fin = fl_fopen(fname,"r");
|
2011-01-02 06:50:54 +03:00
|
|
|
}
|
2008-08-25 21:01:31 +04:00
|
|
|
#endif
|
2011-01-02 06:50:54 +03:00
|
|
|
if (fin == NULL) {
|
|
|
|
return 0;
|
1999-01-07 19:58:26 +03:00
|
|
|
}
|
|
|
|
for (;;) {
|
2011-01-02 06:50:54 +03:00
|
|
|
if (fgets(line,256,fin) == NULL) break;
|
2007-02-23 22:27:43 +03:00
|
|
|
// remove all carriage returns that Cygwin may have inserted
|
|
|
|
char *s = line, *d = line;
|
|
|
|
for (;;++d) {
|
|
|
|
while (*s=='\r') s++;
|
|
|
|
*d = *s++;
|
|
|
|
if (!*d) break;
|
|
|
|
}
|
2016-04-09 15:37:44 +03:00
|
|
|
// interpret the line
|
1999-01-07 19:58:26 +03:00
|
|
|
j = 0; i = 0;
|
|
|
|
while (line[i] == ' ' || line[i] == '\t') i++;
|
|
|
|
if (line[i] == '\n') continue;
|
|
|
|
if (line[i] == '#') continue;
|
|
|
|
while (line[i] != ':' && line[i] != '\n') mname[j++] = line[i++];
|
|
|
|
mname[j] = '\0';
|
|
|
|
if (line[i] == ':') i++;
|
|
|
|
j = 0;
|
2016-04-09 15:37:44 +03:00
|
|
|
while (line[i] != ':' && line[i] != '\n') {
|
1999-01-07 19:58:26 +03:00
|
|
|
if (line[i] == '\\') {
|
2009-12-07 01:21:55 +03:00
|
|
|
i++;
|
|
|
|
if (line[i] == 'n') iname[j++] = '\n';
|
|
|
|
else iname[j++] = line[i];
|
|
|
|
i++;
|
1999-01-07 19:58:26 +03:00
|
|
|
} else
|
|
|
|
iname[j++] = line[i++];
|
|
|
|
}
|
|
|
|
iname[j] = '\0';
|
|
|
|
if (line[i] == ':') i++;
|
|
|
|
j = 0;
|
|
|
|
while (line[i] != ':' && line[i] != '\n') cname[j++] = line[i++];
|
|
|
|
cname[j] = '\0';
|
|
|
|
addto_menu(mname,iname,cname);
|
|
|
|
}
|
2011-01-02 06:50:54 +03:00
|
|
|
fclose(fin);
|
1999-01-07 19:58:26 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2017-11-12 21:00:45 +03:00
|
|
|
fl_putenv((char *)"FLTK_DOCDIR=../documentation/html");
|
2010-12-20 00:20:10 +03:00
|
|
|
char buf[FL_PATH_MAX];
|
2001-12-21 17:35:34 +03:00
|
|
|
strcpy(buf, argv[0]);
|
2016-01-31 00:00:12 +03:00
|
|
|
#if DEBUG_EXE_WITH_D
|
2017-11-12 21:00:45 +03:00
|
|
|
// MS_VisualC appends a 'd' to debugging executables. Remove it.
|
2002-03-26 00:08:42 +03:00
|
|
|
fl_filename_setext( buf, "" );
|
2001-12-21 17:35:34 +03:00
|
|
|
buf[ strlen(buf)-1 ] = 0;
|
2001-12-01 04:54:30 +03:00
|
|
|
#endif
|
2002-03-26 00:08:42 +03:00
|
|
|
fl_filename_setext(buf,".menu");
|
2016-04-09 15:37:44 +03:00
|
|
|
char *fname = buf;
|
1999-01-07 19:58:26 +03:00
|
|
|
int i = 0;
|
|
|
|
if (!Fl::args(argc,argv,i) || i < argc-1)
|
2005-07-18 17:08:09 +04:00
|
|
|
Fl::fatal("Usage: %s <switches> <menufile>\n%s",argv[0],Fl::help);
|
1999-01-07 19:58:26 +03:00
|
|
|
if (i < argc) fname = argv[i];
|
2009-12-07 01:21:55 +03:00
|
|
|
|
2006-10-11 07:12:15 +04:00
|
|
|
create_the_forms();
|
2009-12-07 01:21:55 +03:00
|
|
|
|
1999-01-07 19:58:26 +03:00
|
|
|
if (!load_the_menu(fname)) Fl::fatal("Can't open %s",fname);
|
2016-04-09 15:37:44 +03:00
|
|
|
if (buf != fname)
|
2005-12-30 13:13:17 +03:00
|
|
|
strcpy(buf,fname);
|
2002-03-26 00:08:42 +03:00
|
|
|
const char *c = fl_filename_name(buf);
|
2010-10-29 01:47:01 +04:00
|
|
|
if (c > buf) {
|
|
|
|
buf[c-buf] = 0;
|
2017-11-12 21:00:45 +03:00
|
|
|
if (fl_chdir(buf) == -1) { /* ignore */ }
|
2010-10-29 01:47:01 +04:00
|
|
|
}
|
1999-01-07 19:58:26 +03:00
|
|
|
push_menu("@main");
|
|
|
|
form->show(argc,argv);
|
|
|
|
Fl::run();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1999-01-07 19:58:26 +03:00
|
|
|
//
|