1998-10-21 20:29:01 +04:00
|
|
|
//
|
2005-02-06 19:28:36 +03:00
|
|
|
// "$Id$"
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
|
|
|
// FLUID main entry for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// Copyright 1998-2005 by Bill Spitzak and others.
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2000-06-06 01:21:24 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Double_Window.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
2001-09-30 02:59:45 +04:00
|
|
|
#include <FL/Fl_File_Icon.H>
|
2001-09-29 18:38:59 +04:00
|
|
|
#include <FL/Fl_Help_Dialog.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl_Hold_Browser.H>
|
|
|
|
#include <FL/Fl_Menu_Bar.H>
|
|
|
|
#include <FL/Fl_Input.H>
|
|
|
|
#include <FL/fl_ask.H>
|
|
|
|
#include <FL/fl_draw.H>
|
2001-09-30 21:37:06 +04:00
|
|
|
#include <FL/Fl_File_Chooser.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/fl_message.H>
|
|
|
|
#include <FL/filename.H>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2001-08-11 20:09:26 +04:00
|
|
|
|
2002-04-01 20:19:32 +04:00
|
|
|
#include "../src/flstring.h"
|
2002-04-30 22:11:49 +04:00
|
|
|
#include "alignment_panel.h"
|
2002-10-31 21:49:05 +03:00
|
|
|
#include "function_panel.h"
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2000-04-04 21:57:05 +04:00
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
2001-03-16 01:39:57 +03:00
|
|
|
# include <direct.h>
|
|
|
|
# include <windows.h>
|
2005-03-19 17:54:54 +03:00
|
|
|
# include <io.h>
|
1998-10-06 22:21:25 +04:00
|
|
|
#else
|
2001-03-16 01:39:57 +03:00
|
|
|
# include <unistd.h>
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
2001-12-21 21:16:50 +03:00
|
|
|
#ifdef __EMX__
|
|
|
|
# include <X11/Xlibint.h>
|
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
|
1998-12-06 18:09:22 +03:00
|
|
|
#include "about_panel.h"
|
2005-03-20 07:00:48 +03:00
|
|
|
#include "undo.h"
|
1998-10-06 22:21:25 +04:00
|
|
|
|
1998-12-06 18:09:22 +03:00
|
|
|
#include "Fl_Type.h"
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
static Fl_Help_Dialog *help_dialog = 0;
|
2001-08-11 20:09:26 +04:00
|
|
|
|
2002-04-30 22:11:49 +04:00
|
|
|
Fl_Preferences fluid_prefs(Fl_Preferences::USER, "fltk.org", "fluid");
|
2002-05-01 23:17:24 +04:00
|
|
|
int gridx = 5;
|
|
|
|
int gridy = 5;
|
|
|
|
int snap = 1;
|
2005-02-26 23:27:19 +03:00
|
|
|
int show_guides = 1;
|
2002-04-30 22:11:49 +04:00
|
|
|
|
|
|
|
// File history info...
|
|
|
|
char absolute_history[10][1024];
|
|
|
|
char relative_history[10][1024];
|
|
|
|
|
2002-05-01 14:36:08 +04:00
|
|
|
void load_history();
|
|
|
|
void update_history(const char *);
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2002-05-01 14:36:08 +04:00
|
|
|
// Shell command support...
|
|
|
|
void show_shell_window();
|
2001-08-11 20:09:26 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static const char *filename;
|
|
|
|
void set_filename(const char *c);
|
2005-03-19 11:38:21 +03:00
|
|
|
void set_modflag(int mf);
|
1998-10-06 22:21:25 +04:00
|
|
|
int modflag;
|
|
|
|
|
|
|
|
static char* pwd;
|
|
|
|
static char in_source_dir;
|
|
|
|
void goto_source_dir() {
|
|
|
|
if (in_source_dir) return;
|
|
|
|
if (!filename || !*filename) return;
|
2002-03-26 00:08:42 +03:00
|
|
|
const char *p = fl_filename_name(filename);
|
1998-10-06 22:21:25 +04:00
|
|
|
if (p <= filename) return; // it is in the current directory
|
|
|
|
char buffer[1024];
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcpy(buffer, filename, sizeof(buffer));
|
1998-10-06 22:21:25 +04:00
|
|
|
int n = p-filename; if (n>1) n--; buffer[n] = 0;
|
|
|
|
if (!pwd) {
|
|
|
|
pwd = getcwd(0,1024);
|
|
|
|
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",
|
1999-01-19 22:10:39 +03:00
|
|
|
pwd, strerror(errno));}
|
1998-10-06 22:21:25 +04:00
|
|
|
in_source_dir = 0;
|
|
|
|
}
|
|
|
|
|
2002-11-03 03:01:21 +03:00
|
|
|
char position_window(Fl_Window *w, const char *prefsName, int Visible, int X, int Y, int W=0, int H=0 ) {
|
2002-10-31 21:49:05 +03:00
|
|
|
Fl_Preferences pos(fluid_prefs, prefsName);
|
2002-11-03 03:01:21 +03:00
|
|
|
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 );
|
2002-10-31 21:49:05 +03:00
|
|
|
}
|
2002-11-03 03:01:21 +03:00
|
|
|
pos.get("visible", Visible, Visible);
|
|
|
|
return Visible;
|
2002-10-31 21:49:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2004-09-08 00:59:18 +04:00
|
|
|
pos.set("visible", (int)(w->shown() && w->visible()));
|
2002-10-31 21:49:05 +03:00
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Window *main_window;
|
2005-03-18 00:57:17 +03:00
|
|
|
Fl_Menu_Bar *main_menubar;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
void save_cb(Fl_Widget *, void *v) {
|
|
|
|
const char *c = filename;
|
|
|
|
if (v || !c || !*c) {
|
2005-03-19 11:38:21 +03:00
|
|
|
fl_ok = "Save";
|
|
|
|
c=fl_file_chooser("Save to:", "FLUID Files (*.f[ld])", c);
|
|
|
|
fl_ok = "OK";
|
|
|
|
if (!c) return;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
set_filename(c);
|
|
|
|
}
|
|
|
|
if (!write_file(c)) {
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Error writing %s: %s", c, strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(0);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_save = undo_current;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
1999-04-19 03:43:42 +04:00
|
|
|
void exit_cb(Fl_Widget *,void *) {
|
|
|
|
if (modflag)
|
2005-03-19 11:38:21 +03:00
|
|
|
switch (fl_choice("Do you want to save changes to this user\n"
|
2005-03-20 02:49:46 +03:00
|
|
|
"interface before exiting?", "Don't Save",
|
|
|
|
"Save", "Cancel"))
|
1999-04-19 03:43:42 +04:00
|
|
|
{
|
2005-03-20 02:49:46 +03:00
|
|
|
case 2 : /* Cancel */
|
1999-04-19 03:43:42 +04:00
|
|
|
return;
|
2005-03-20 02:49:46 +03:00
|
|
|
case 1 : /* Save */
|
1999-04-19 03:43:42 +04:00
|
|
|
save_cb(NULL, NULL);
|
|
|
|
if (modflag) return; // Didn't save!
|
|
|
|
}
|
|
|
|
|
2002-10-31 21:49:05 +03:00
|
|
|
save_position(main_window,"main_window_pos");
|
|
|
|
|
|
|
|
if (widgetbin_panel) {
|
|
|
|
save_position(widgetbin_panel,"widgetbin_pos");
|
|
|
|
delete widgetbin_panel;
|
|
|
|
}
|
2001-08-11 20:09:26 +04:00
|
|
|
if (about_panel)
|
|
|
|
delete about_panel;
|
|
|
|
if (help_dialog)
|
|
|
|
delete help_dialog;
|
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_clear();
|
|
|
|
|
1999-04-19 03:43:42 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2003-06-01 04:23:57 +04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
# include <FL/x.H>
|
|
|
|
|
|
|
|
void
|
|
|
|
apple_open_cb(const char *c) {
|
2005-03-19 11:38:21 +03:00
|
|
|
if (modflag)
|
|
|
|
{
|
|
|
|
switch (fl_choice("Do you want to save changes to this user\n"
|
2005-03-20 02:49:46 +03:00
|
|
|
"interface before opening another one?", "Don't Save",
|
|
|
|
"Save", "Cancel"))
|
2005-03-19 11:38:21 +03:00
|
|
|
{
|
2005-03-20 02:49:46 +03:00
|
|
|
case 2 : /* Cancel */
|
2005-03-19 11:38:21 +03:00
|
|
|
return;
|
2005-03-20 02:49:46 +03:00
|
|
|
case 1 : /* Save */
|
2005-03-19 11:38:21 +03:00
|
|
|
save_cb(NULL, NULL);
|
|
|
|
if (modflag) return; // Didn't save!
|
|
|
|
}
|
|
|
|
}
|
2003-06-01 04:23:57 +04:00
|
|
|
const char *oldfilename;
|
|
|
|
oldfilename = filename;
|
|
|
|
filename = NULL;
|
|
|
|
set_filename(c);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_suspend();
|
2003-06-01 04:23:57 +04:00
|
|
|
if (!read_file(c, 0)) {
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
2003-06-01 04:23:57 +04:00
|
|
|
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...
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(0);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
|
|
|
undo_clear();
|
2003-06-01 04:23:57 +04:00
|
|
|
if (oldfilename) free((void *)oldfilename);
|
|
|
|
}
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void open_cb(Fl_Widget *, void *v) {
|
2005-03-19 11:38:21 +03:00
|
|
|
if (!v && modflag)
|
|
|
|
{
|
|
|
|
switch (fl_choice("Do you want to save changes to this user\n"
|
2005-03-20 02:49:46 +03:00
|
|
|
"interface before opening another one?", "Don't Save",
|
|
|
|
"Save", "Cancel"))
|
2005-03-19 11:38:21 +03:00
|
|
|
{
|
2005-03-20 02:49:46 +03:00
|
|
|
case 2 : /* Cancel */
|
2005-03-19 11:38:21 +03:00
|
|
|
return;
|
2005-03-20 02:49:46 +03:00
|
|
|
case 1 : /* Save */
|
2005-03-19 11:38:21 +03:00
|
|
|
save_cb(NULL, NULL);
|
|
|
|
if (modflag) return; // Didn't save!
|
|
|
|
}
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *c;
|
2002-05-02 14:08:44 +04:00
|
|
|
const char *oldfilename;
|
2005-03-19 11:38:21 +03:00
|
|
|
fl_ok = "Open";
|
|
|
|
c = fl_file_chooser("Open:", "FLUID Files (*.f[ld])", filename);
|
|
|
|
fl_ok = "OK";
|
|
|
|
if (!c) return;
|
2002-05-02 14:08:44 +04:00
|
|
|
oldfilename = filename;
|
|
|
|
filename = NULL;
|
|
|
|
set_filename(c);
|
2005-03-20 07:00:48 +03:00
|
|
|
if (v != 0) undo_checkpoint();
|
|
|
|
undo_suspend();
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!read_file(c, v!=0)) {
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't read %s: %s", c, strerror(errno));
|
2002-05-02 14:08:44 +04:00
|
|
|
free((void *)filename);
|
|
|
|
filename = oldfilename;
|
|
|
|
if (main_window) main_window->label(filename);
|
1998-10-06 22:21:25 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
2002-05-02 14:08:44 +04:00
|
|
|
if (v) {
|
|
|
|
// Inserting a file; restore the original filename...
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(1);
|
2002-05-02 14:08:44 +04:00
|
|
|
free((void *)filename);
|
|
|
|
filename = oldfilename;
|
|
|
|
if (main_window) main_window->label(filename);
|
|
|
|
} else {
|
|
|
|
// Loaded a file; free the old filename...
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(0);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_clear();
|
2002-05-02 14:08:44 +04:00
|
|
|
if (oldfilename) free((void *)oldfilename);
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2002-04-30 22:11:49 +04:00
|
|
|
void open_history_cb(Fl_Widget *, void *v) {
|
2005-03-19 11:38:21 +03:00
|
|
|
if (modflag)
|
|
|
|
{
|
|
|
|
switch (fl_choice("Do you want to save changes to this user\n"
|
2005-03-20 02:49:46 +03:00
|
|
|
"interface before opening another one?", "Don't Save",
|
|
|
|
"Save", "Cancel"))
|
2005-03-19 11:38:21 +03:00
|
|
|
{
|
2005-03-20 02:49:46 +03:00
|
|
|
case 2 : /* Cancel */
|
2005-03-19 11:38:21 +03:00
|
|
|
return;
|
2005-03-20 02:49:46 +03:00
|
|
|
case 1 : /* Save */
|
2005-03-19 11:38:21 +03:00
|
|
|
save_cb(NULL, NULL);
|
|
|
|
if (modflag) return; // Didn't save!
|
|
|
|
}
|
|
|
|
}
|
2002-05-02 14:08:44 +04:00
|
|
|
const char *oldfilename = filename;
|
|
|
|
filename = NULL;
|
|
|
|
set_filename((char *)v);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_suspend();
|
2002-05-02 14:08:44 +04:00
|
|
|
if (!read_file(filename, 0)) {
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
|
|
|
undo_clear();
|
2002-05-02 14:08:44 +04:00
|
|
|
fl_message("Can't read %s: %s", filename, strerror(errno));
|
|
|
|
free((void *)filename);
|
|
|
|
filename = oldfilename;
|
|
|
|
if (main_window) main_window->label(filename);
|
2002-04-30 22:11:49 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(0);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
|
|
|
undo_clear();
|
2002-05-02 14:08:44 +04:00
|
|
|
if (oldfilename) free((void *)oldfilename);
|
2002-04-30 22:11:49 +04:00
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void new_cb(Fl_Widget *, void *v) {
|
2005-03-19 11:38:21 +03:00
|
|
|
if (!v && modflag)
|
|
|
|
{
|
|
|
|
switch (fl_choice("Do you want to save changes to this user\n"
|
2005-03-20 02:49:46 +03:00
|
|
|
"interface before creating a new one?", "Don't Save",
|
|
|
|
"Save", "Cancel"))
|
2005-03-19 11:38:21 +03:00
|
|
|
{
|
2005-03-20 02:49:46 +03:00
|
|
|
case 2 : /* Cancel */
|
2005-03-19 11:38:21 +03:00
|
|
|
return;
|
2005-03-20 02:49:46 +03:00
|
|
|
case 1 : /* Save */
|
2005-03-19 11:38:21 +03:00
|
|
|
save_cb(NULL, NULL);
|
|
|
|
if (modflag) return; // Didn't save!
|
|
|
|
}
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
delete_all();
|
2005-03-19 11:38:21 +03:00
|
|
|
set_filename(NULL);
|
|
|
|
set_modflag(0);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_clear();
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
1999-11-20 12:17:21 +03:00
|
|
|
int compile_only = 0;
|
2000-06-08 12:26:45 +04:00
|
|
|
int compile_strings = 0;
|
1999-03-04 21:10:01 +03:00
|
|
|
int header_file_set = 0;
|
|
|
|
int code_file_set = 0;
|
1998-12-06 17:59:14 +03:00
|
|
|
const char* header_file_name = ".h";
|
|
|
|
const char* code_file_name = ".cxx";
|
2000-04-24 22:22:50 +04:00
|
|
|
int i18n_type = 0;
|
|
|
|
const char* i18n_include = "";
|
|
|
|
const char* i18n_function = "";
|
|
|
|
const char* i18n_file = "";
|
|
|
|
const char* i18n_set = "";
|
2000-04-25 05:57:51 +04:00
|
|
|
char i18n_program[1024] = "";
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
void write_cb(Fl_Widget *, void *) {
|
|
|
|
if (!filename) {
|
|
|
|
save_cb(0,0);
|
|
|
|
if (!filename) return;
|
|
|
|
}
|
|
|
|
char cname[1024];
|
|
|
|
char hname[1024];
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcpy(i18n_program, fl_filename_name(filename), sizeof(i18n_program));
|
|
|
|
fl_filename_setext(i18n_program, sizeof(i18n_program), "");
|
2001-08-02 20:17:04 +04:00
|
|
|
if (*code_file_name == '.' && strchr(code_file_name, '/') == NULL) {
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcpy(cname, fl_filename_name(filename), sizeof(cname));
|
|
|
|
fl_filename_setext(cname, sizeof(cname), code_file_name);
|
1998-10-06 22:21:25 +04:00
|
|
|
} else {
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcpy(cname, code_file_name, sizeof(hname));
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2001-08-02 20:17:04 +04:00
|
|
|
if (*header_file_name == '.' && strchr(header_file_name, '/') == NULL) {
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcpy(hname, fl_filename_name(filename), sizeof(hname));
|
|
|
|
fl_filename_setext(hname, sizeof(hname), header_file_name);
|
1998-10-06 22:21:25 +04:00
|
|
|
} else {
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcpy(hname, header_file_name, sizeof(hname));
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
1999-03-09 09:59:05 +03:00
|
|
|
if (!compile_only) goto_source_dir();
|
1998-10-06 22:21:25 +04:00
|
|
|
int x = write_code(cname,hname);
|
1999-03-09 09:59:05 +03:00
|
|
|
if (!compile_only) leave_source_dir();
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcat(cname, " and ", sizeof(cname));
|
|
|
|
strlcat(cname, hname, sizeof(cname));
|
1998-10-06 22:21:25 +04:00
|
|
|
if (compile_only) {
|
|
|
|
if (!x) {fprintf(stderr,"%s : %s\n",cname,strerror(errno)); exit(1);}
|
|
|
|
} else {
|
|
|
|
if (!x) {
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't write %s: %s", cname, strerror(errno));
|
2002-04-30 22:11:49 +04:00
|
|
|
} else if (completion_button->value()) {
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Wrote %s", cname, 0);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-24 22:22:50 +04:00
|
|
|
void write_strings_cb(Fl_Widget *, void *) {
|
2000-08-20 08:35:17 +04:00
|
|
|
static const char *exts[] = { ".txt", ".po", ".msg" };
|
2000-04-24 22:22:50 +04:00
|
|
|
if (!filename) {
|
|
|
|
save_cb(0,0);
|
|
|
|
if (!filename) return;
|
|
|
|
}
|
|
|
|
char sname[1024];
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcpy(sname, fl_filename_name(filename), sizeof(sname));
|
|
|
|
fl_filename_setext(sname, sizeof(sname), exts[i18n_type]);
|
2000-04-24 22:22:50 +04:00
|
|
|
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));
|
2002-04-30 22:11:49 +04:00
|
|
|
} else if (completion_button->value()) {
|
2000-04-24 22:22:50 +04:00
|
|
|
fl_message("Wrote %s", sname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
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 *);
|
2005-03-20 03:12:21 +03:00
|
|
|
void select_none_cb(Fl_Widget *,void *);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
void group_cb(Fl_Widget *, void *);
|
|
|
|
|
|
|
|
void ungroup_cb(Fl_Widget *, void *);
|
|
|
|
|
|
|
|
extern int pasteoffset;
|
|
|
|
static int ipasteoffset;
|
|
|
|
|
2005-03-18 00:57:17 +03:00
|
|
|
static char* cutfname(int which = 0) {
|
|
|
|
static char name[2][1024];
|
2002-04-30 22:11:49 +04:00
|
|
|
static char beenhere = 0;
|
|
|
|
|
|
|
|
if (!beenhere) {
|
|
|
|
beenhere = 1;
|
2005-03-18 00:57:17 +03:00
|
|
|
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]));
|
2001-02-01 20:30:28 +03:00
|
|
|
}
|
|
|
|
|
2005-03-18 00:57:17 +03:00
|
|
|
return name[which];
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void copy_cb(Fl_Widget*, void*) {
|
2005-03-18 00:57:17 +03:00
|
|
|
if (!Fl_Type::current) {
|
|
|
|
fl_beep();
|
|
|
|
return;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
ipasteoffset = 10;
|
|
|
|
if (!write_file(cutfname(),1)) {
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't write %s: %s", cutfname(), strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void select_only(Fl_Type *);
|
|
|
|
void cut_cb(Fl_Widget *, void *) {
|
2005-03-18 00:57:17 +03:00
|
|
|
if (!Fl_Type::current) {
|
|
|
|
fl_beep();
|
|
|
|
return;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!write_file(cutfname(),1)) {
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't write %s: %s", cutfname(), strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_checkpoint();
|
|
|
|
set_modflag(1);
|
|
|
|
ipasteoffset = 0;
|
|
|
|
Fl_Type *p = Fl_Type::current->parent;
|
|
|
|
while (p && p->selected) p = p->parent;
|
1998-10-06 22:21:25 +04:00
|
|
|
delete_all(1);
|
|
|
|
if (p) select_only(p);
|
|
|
|
}
|
|
|
|
|
2005-03-20 04:49:46 +03:00
|
|
|
void delete_cb(Fl_Widget *, void *) {
|
|
|
|
if (!Fl_Type::current) {
|
|
|
|
fl_beep();
|
|
|
|
return;
|
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_checkpoint();
|
|
|
|
set_modflag(1);
|
2005-03-20 04:49:46 +03:00
|
|
|
ipasteoffset = 0;
|
|
|
|
Fl_Type *p = Fl_Type::current->parent;
|
|
|
|
while (p && p->selected) p = p->parent;
|
|
|
|
delete_all(1);
|
|
|
|
if (p) select_only(p);
|
|
|
|
}
|
|
|
|
|
2002-05-01 23:17:24 +04:00
|
|
|
extern int force_parent;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
void paste_cb(Fl_Widget*, void*) {
|
2003-07-19 10:10:20 +04:00
|
|
|
//if (ipasteoffset) force_parent = 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
pasteoffset = ipasteoffset;
|
|
|
|
if (gridx>1) pasteoffset = ((pasteoffset-1)/gridx+1)*gridx;
|
|
|
|
if (gridy>1) pasteoffset = ((pasteoffset-1)/gridy+1)*gridy;
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_checkpoint();
|
|
|
|
undo_suspend();
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!read_file(cutfname(), 1)) {
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't read %s: %s", cutfname(), strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
1998-10-06 22:21:25 +04:00
|
|
|
pasteoffset = 0;
|
|
|
|
ipasteoffset += 10;
|
|
|
|
force_parent = 0;
|
|
|
|
}
|
|
|
|
|
2005-03-18 00:57:17 +03:00
|
|
|
// 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;
|
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_checkpoint();
|
|
|
|
undo_suspend();
|
2005-03-18 00:57:17 +03:00
|
|
|
if (!read_file(cutfname(1), 1)) {
|
|
|
|
fl_message("Can't read %s: %s", cutfname(1), strerror(errno));
|
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
2005-03-18 00:57:17 +03:00
|
|
|
|
|
|
|
force_parent = 0;
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2002-05-01 23:17:24 +04:00
|
|
|
void show_project_cb(Fl_Widget *, void *);
|
|
|
|
void show_grid_cb(Fl_Widget *, void *);
|
2002-04-30 22:11:49 +04:00
|
|
|
void show_settings_cb(Fl_Widget *, void *);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-05-01 21:35:30 +04:00
|
|
|
void align_widget_cb(Fl_Widget *, long);
|
2005-03-19 07:09:32 +03:00
|
|
|
void widget_size_cb(Fl_Widget *, long);
|
2002-05-01 21:35:30 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void about_cb(Fl_Widget *, void *) {
|
2002-01-01 18:11:33 +03:00
|
|
|
if (!about_panel) make_about_panel();
|
1998-10-06 22:21:25 +04:00
|
|
|
about_panel->show();
|
|
|
|
}
|
|
|
|
|
2001-09-23 17:08:03 +04:00
|
|
|
void show_help(const char *name) {
|
|
|
|
const char *docdir;
|
2002-08-10 02:57:00 +04:00
|
|
|
char helpname[1024];
|
2001-09-23 17:08:03 +04:00
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
if (!help_dialog) help_dialog = new Fl_Help_Dialog();
|
2001-09-23 17:08:03 +04:00
|
|
|
|
2001-12-21 21:16:50 +03:00
|
|
|
if ((docdir = getenv("FLTK_DOCDIR")) == NULL) {
|
|
|
|
#ifdef __EMX__
|
|
|
|
// Doesn't make sense to have a hardcoded fallback
|
|
|
|
static char fltk_docdir[1024];
|
|
|
|
|
2002-08-10 02:57:00 +04:00
|
|
|
strlcpy(fltk_docdir, __XOS2RedirRoot("/XFree86/lib/X11/fltk/doc"),
|
|
|
|
sizeof(fltk_docdir));
|
2001-09-23 17:08:03 +04:00
|
|
|
|
2001-12-21 21:16:50 +03:00
|
|
|
docdir = fltk_docdir;
|
|
|
|
#else
|
|
|
|
docdir = FLTK_DOCDIR;
|
|
|
|
#endif // __EMX__
|
|
|
|
}
|
2002-08-10 02:57:00 +04:00
|
|
|
snprintf(helpname, sizeof(helpname), "%s/%s", docdir, name);
|
2001-09-23 17:08:03 +04:00
|
|
|
|
2002-08-10 02:57:00 +04:00
|
|
|
help_dialog->load(helpname);
|
2001-08-11 20:09:26 +04:00
|
|
|
help_dialog->show();
|
|
|
|
}
|
|
|
|
|
2001-09-23 17:08:03 +04:00
|
|
|
void help_cb(Fl_Widget *, void *) {
|
|
|
|
show_help("fluid.html");
|
|
|
|
}
|
|
|
|
|
2001-08-11 20:09:26 +04:00
|
|
|
void manual_cb(Fl_Widget *, void *) {
|
2001-09-23 17:08:03 +04:00
|
|
|
show_help("index.html");
|
2001-08-11 20:09:26 +04:00
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
extern Fl_Menu_Item New_Menu[];
|
|
|
|
|
2005-03-20 03:12:21 +03:00
|
|
|
void toggle_widgetbin_cb(Fl_Widget *, void *);
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Menu_Item Main_Menu[] = {
|
1999-01-19 22:10:39 +03:00
|
|
|
{"&File",0,0,0,FL_SUBMENU},
|
2005-03-19 11:38:21 +03:00
|
|
|
{"&New", FL_CTRL+'n', new_cb, 0},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Open...", FL_CTRL+'o', open_cb, 0},
|
|
|
|
{"Open &Previous",0,0,0,FL_SUBMENU},
|
2002-04-30 22:11:49 +04:00
|
|
|
{relative_history[0], FL_CTRL+'0', open_history_cb, absolute_history[0]},
|
|
|
|
{relative_history[1], FL_CTRL+'1', open_history_cb, absolute_history[1]},
|
|
|
|
{relative_history[2], FL_CTRL+'2', open_history_cb, absolute_history[2]},
|
|
|
|
{relative_history[3], FL_CTRL+'3', open_history_cb, absolute_history[3]},
|
|
|
|
{relative_history[4], FL_CTRL+'4', open_history_cb, absolute_history[4]},
|
|
|
|
{relative_history[5], FL_CTRL+'5', open_history_cb, absolute_history[5]},
|
|
|
|
{relative_history[6], FL_CTRL+'6', open_history_cb, absolute_history[6]},
|
|
|
|
{relative_history[7], FL_CTRL+'7', open_history_cb, absolute_history[7]},
|
|
|
|
{relative_history[8], FL_CTRL+'8', open_history_cb, absolute_history[8]},
|
|
|
|
{relative_history[9], FL_CTRL+'9', open_history_cb, absolute_history[9]},
|
|
|
|
{0},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Insert...", FL_CTRL+'i', open_cb, (void*)1, FL_MENU_DIVIDER},
|
|
|
|
{"&Save", FL_CTRL+'s', save_cb, 0},
|
2005-03-20 04:49:46 +03:00
|
|
|
{"Save &As...", FL_CTRL+FL_SHIFT+'s', save_cb, (void*)1},
|
2005-03-19 07:09:32 +03:00
|
|
|
{"Write &Code...", FL_CTRL+FL_SHIFT+'c', write_cb, 0},
|
|
|
|
{"&Write Strings...", FL_CTRL+FL_SHIFT+'w', write_strings_cb, 0, FL_MENU_DIVIDER},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Quit", FL_CTRL+'q', exit_cb},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
1999-01-19 22:10:39 +03:00
|
|
|
{"&Edit",0,0,0,FL_SUBMENU},
|
2005-03-20 07:00:48 +03:00
|
|
|
{"&Undo", FL_CTRL+'z', undo_cb},
|
|
|
|
{"&Redo", FL_CTRL+FL_SHIFT+'z', redo_cb, 0, FL_MENU_DIVIDER},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"C&ut", FL_CTRL+'x', cut_cb},
|
|
|
|
{"&Copy", FL_CTRL+'c', copy_cb},
|
2005-03-20 04:49:46 +03:00
|
|
|
{"&Delete", FL_Delete, delete_cb},
|
|
|
|
{"Dup&licate", FL_CTRL+'d', duplicate_cb},
|
|
|
|
{"&Paste", FL_CTRL+'v', paste_cb},
|
2005-03-20 03:12:21 +03:00
|
|
|
{"Select &All", FL_CTRL+'a', select_all_cb},
|
|
|
|
{"Select &None", FL_CTRL+FL_SHIFT+'a', select_none_cb, 0, FL_MENU_DIVIDER},
|
2005-03-20 04:49:46 +03:00
|
|
|
{"&Show Widget Panel...", FL_F+1, openwidget_cb},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Sort",0,sort_cb},
|
|
|
|
{"&Earlier", FL_F+2, earlier_cb},
|
|
|
|
{"&Later", FL_F+3, later_cb},
|
|
|
|
{"&Group", FL_F+7, group_cb},
|
2005-03-20 03:12:21 +03:00
|
|
|
{"Ung&roup", FL_F+8, ungroup_cb,0, FL_MENU_DIVIDER},
|
|
|
|
{"Hide O&verlays",FL_CTRL+FL_SHIFT+'o',toggle_overlays},
|
2005-03-20 04:49:46 +03:00
|
|
|
{"Show Widget &Bin...",FL_ALT+'b',toggle_widgetbin_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},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
1999-01-19 22:10:39 +03:00
|
|
|
{"&New", 0, 0, (void *)New_Menu, FL_SUBMENU_POINTER},
|
2002-05-01 21:35:30 +04:00
|
|
|
{"&Layout",0,0,0,FL_SUBMENU},
|
|
|
|
{"&Align",0,0,0,FL_SUBMENU},
|
|
|
|
{"&Left",0,(Fl_Callback *)align_widget_cb,(void*)10},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Center",0,(Fl_Callback *)align_widget_cb,(void*)11},
|
2002-05-01 21:35:30 +04:00
|
|
|
{"&Right",0,(Fl_Callback *)align_widget_cb,(void*)12},
|
|
|
|
{"&Top",0,(Fl_Callback *)align_widget_cb,(void*)13},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Middle",0,(Fl_Callback *)align_widget_cb,(void*)14},
|
2002-05-01 21:35:30 +04:00
|
|
|
{"&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},
|
2005-03-19 07:09:32 +03:00
|
|
|
{"&Center In Group",0,0,0,FL_SUBMENU},
|
2002-05-01 21:35:30 +04:00
|
|
|
{"&Horizontal",0,(Fl_Callback *)align_widget_cb,(void*)40},
|
|
|
|
{"&Vertical",0,(Fl_Callback *)align_widget_cb,(void*)41},
|
|
|
|
{0},
|
2005-03-20 04:49:46 +03:00
|
|
|
{"&Set Widget Size",0,0,0,FL_SUBMENU|FL_MENU_DIVIDER},
|
|
|
|
{"&Tiny",FL_ALT+'1',(Fl_Callback *)widget_size_cb,(void*)8,FL_MENU_RADIO,FL_NORMAL_LABEL,FL_HELVETICA,8},
|
|
|
|
{"&Small",FL_ALT+'2',(Fl_Callback *)widget_size_cb,(void*)11,FL_MENU_RADIO,FL_NORMAL_LABEL,FL_HELVETICA,11},
|
|
|
|
{"&Normal",FL_ALT+'3',(Fl_Callback *)widget_size_cb,(void*)14,FL_MENU_RADIO|FL_MENU_VALUE},
|
2005-03-19 07:09:32 +03:00
|
|
|
{0},
|
2005-03-20 04:49:46 +03:00
|
|
|
{"&Grid...",FL_ALT+'g',show_grid_cb},
|
2002-05-01 21:35:30 +04:00
|
|
|
{0},
|
2002-05-01 14:36:08 +04:00
|
|
|
{"&Shell",0,0,0,FL_SUBMENU},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"Execute &Command...",FL_ALT+'x',(Fl_Callback *)show_shell_window},
|
2005-03-17 10:11:57 +03:00
|
|
|
{"Execute &Again...",FL_ALT+'g',(Fl_Callback *)do_shell_command},
|
2002-05-01 14:36:08 +04:00
|
|
|
{0},
|
1999-01-19 22:10:39 +03:00
|
|
|
{"&Help",0,0,0,FL_SUBMENU},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&About FLUID...",0,about_cb},
|
|
|
|
{"&On FLUID...",0,help_cb},
|
|
|
|
{"&Manual...",0,manual_cb},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
|
|
|
{0}};
|
|
|
|
|
|
|
|
#define BROWSERWIDTH 300
|
|
|
|
#define BROWSERHEIGHT 500
|
|
|
|
#define WINWIDTH 300
|
2002-04-28 14:12:41 +04:00
|
|
|
#define MENUHEIGHT 25
|
1998-10-06 22:21:25 +04:00
|
|
|
#define WINHEIGHT (BROWSERHEIGHT+MENUHEIGHT)
|
|
|
|
|
|
|
|
extern void fill_in_New_Menu();
|
|
|
|
|
2005-03-20 03:51:02 +03:00
|
|
|
void scheme_cb(Fl_Choice *, void *) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
fluid_prefs.set("scheme", scheme_choice->value());
|
|
|
|
}
|
|
|
|
|
2005-03-20 03:12:21 +03:00
|
|
|
void toggle_widgetbin_cb(Fl_Widget *, void *) {
|
|
|
|
if (!widgetbin_panel) {
|
|
|
|
make_widgetbin();
|
|
|
|
widgetbin_panel->callback(toggle_widgetbin_cb);
|
|
|
|
if (!position_window(widgetbin_panel,"widgetbin_pos", 1, 320, 30)) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widgetbin_panel->visible()) {
|
|
|
|
widgetbin_panel->hide();
|
2005-03-20 04:49:46 +03:00
|
|
|
Main_Menu[38].label("Show Widget &Bin...");
|
2005-03-20 03:12:21 +03:00
|
|
|
} else {
|
|
|
|
widgetbin_panel->show();
|
2005-03-20 04:49:46 +03:00
|
|
|
Main_Menu[38].label("Hide Widget &Bin");
|
2005-03-20 03:12:21 +03:00
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
|
2005-03-20 03:12:21 +03:00
|
|
|
void make_main_window() {
|
2005-02-26 23:27:19 +03:00
|
|
|
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);
|
2002-04-30 22:11:49 +04:00
|
|
|
|
|
|
|
load_history();
|
|
|
|
|
2002-05-01 23:17:24 +04:00
|
|
|
make_grid_window();
|
2002-04-30 22:11:49 +04:00
|
|
|
make_settings_window();
|
2002-05-01 14:36:08 +04:00
|
|
|
make_shell_window();
|
2002-04-30 22:11:49 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!main_window) {
|
|
|
|
Fl_Widget *o;
|
|
|
|
main_window = new Fl_Double_Window(WINWIDTH,WINHEIGHT,"fluid");
|
|
|
|
main_window->box(FL_NO_BOX);
|
|
|
|
o = make_widget_browser(0,MENUHEIGHT,BROWSERWIDTH,BROWSERHEIGHT);
|
|
|
|
o->box(FL_FLAT_BOX);
|
2001-09-30 02:59:45 +04:00
|
|
|
o->tooltip("Double-click to view or change an item.");
|
1998-10-06 22:21:25 +04:00
|
|
|
main_window->resizable(o);
|
2005-03-18 00:57:17 +03:00
|
|
|
main_menubar = new Fl_Menu_Bar(0,0,BROWSERWIDTH,MENUHEIGHT);
|
|
|
|
main_menubar->menu(Main_Menu);
|
|
|
|
main_menubar->global();
|
1998-10-06 22:21:25 +04:00
|
|
|
fill_in_New_Menu();
|
|
|
|
main_window->end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:11:49 +04:00
|
|
|
// Load file history from preferences...
|
|
|
|
void load_history() {
|
|
|
|
int i; // Looping var
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i ++) {
|
2002-05-01 02:25:18 +04:00
|
|
|
fluid_prefs.get( Fl_Preferences::Name("file%d", i), absolute_history[i], "", sizeof(absolute_history[i]));
|
2002-04-30 22:11:49 +04:00
|
|
|
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]);
|
|
|
|
|
|
|
|
Main_Menu[i + 4].flags = 0;
|
|
|
|
} else Main_Menu[i + 4].flags = FL_MENU_INVISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!absolute_history[0][0]) Main_Menu[3].flags |= FL_MENU_INACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update file history from preferences...
|
2002-08-10 02:57:00 +04:00
|
|
|
void update_history(const char *flname) {
|
2002-04-30 22:11:49 +04:00
|
|
|
int i; // Looping var
|
|
|
|
char absolute[1024];
|
|
|
|
|
2002-08-10 02:57:00 +04:00
|
|
|
fl_filename_absolute(absolute, sizeof(absolute), flname);
|
2002-04-30 22:11:49 +04:00
|
|
|
|
|
|
|
for (i = 0; i < 10; i ++)
|
|
|
|
#if defined(WIN32) || defined(__APPLE__)
|
|
|
|
if (!strcasecmp(absolute, absolute_history[i])) break;
|
|
|
|
#else
|
2002-05-02 01:41:59 +04:00
|
|
|
if (!strcmp(absolute, absolute_history[i])) break;
|
2002-04-30 22:11:49 +04:00
|
|
|
#endif // WIN32 || __APPLE__
|
|
|
|
|
|
|
|
if (i == 0) return;
|
|
|
|
|
|
|
|
if (i >= 10) i = 9;
|
|
|
|
|
2002-08-10 02:57:00 +04:00
|
|
|
// Move the other flnames down in the list...
|
2002-04-30 22:11:49 +04:00
|
|
|
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...
|
2002-05-16 16:47:44 +04:00
|
|
|
strlcpy(absolute_history[0], absolute, sizeof(absolute_history[0]));
|
2002-04-30 22:11:49 +04:00
|
|
|
|
|
|
|
fl_filename_relative(relative_history[0], sizeof(relative_history[0]),
|
|
|
|
absolute_history[0]);
|
|
|
|
|
|
|
|
// Update the menu items as needed...
|
|
|
|
for (i = 0; i < 10; i ++) {
|
2002-05-01 02:25:18 +04:00
|
|
|
fluid_prefs.set( Fl_Preferences::Name("file%d", i), absolute_history[i]);
|
2002-04-30 22:11:49 +04:00
|
|
|
if (absolute_history[i][0]) Main_Menu[i + 4].flags = 0;
|
|
|
|
else Main_Menu[i + 4].flags = FL_MENU_INVISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Main_Menu[3].flags &= ~FL_MENU_INACTIVE;
|
|
|
|
}
|
|
|
|
|
2002-05-01 14:36:08 +04:00
|
|
|
// Shell command support...
|
2003-08-02 16:38:10 +04:00
|
|
|
#if (!defined(WIN32) || defined(__CYGWIN__)) && !defined(__MWERKS__)
|
2002-05-01 14:44:55 +04:00
|
|
|
// Support the full piped shell command...
|
2002-11-01 03:32:05 +03:00
|
|
|
static FILE *shell_pipe = 0;
|
2002-05-01 14:36:08 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
shell_pipe_cb(int, void*) {
|
|
|
|
char line[1024]; // Line from command output...
|
|
|
|
|
|
|
|
if (fgets(line, sizeof(line), shell_pipe) != NULL) {
|
|
|
|
// Add the line to the output list...
|
2003-04-01 23:58:08 +04:00
|
|
|
shell_run_buffer->append(line);
|
2002-05-01 14:36:08 +04:00
|
|
|
} else {
|
|
|
|
// End of file; tell the parent...
|
|
|
|
Fl::remove_fd(fileno(shell_pipe));
|
|
|
|
|
|
|
|
pclose(shell_pipe);
|
|
|
|
shell_pipe = NULL;
|
2003-04-01 23:58:08 +04:00
|
|
|
shell_run_buffer->append("... END SHELL COMMAND ...\n");
|
2002-05-01 14:36:08 +04:00
|
|
|
}
|
2003-04-01 23:58:08 +04:00
|
|
|
|
|
|
|
shell_run_display->scroll(shell_run_display->count_lines(0,
|
|
|
|
shell_run_buffer->length(), 1), 0);
|
2002-05-01 14:36:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
do_shell_command(Fl_Return_Button*, void*) {
|
|
|
|
const char *command; // Command to run
|
|
|
|
|
|
|
|
|
|
|
|
shell_window->hide();
|
|
|
|
|
2002-11-01 03:32:05 +03:00
|
|
|
if (shell_pipe) {
|
|
|
|
fl_alert("Previous shell command still running!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-05-01 14:36:08 +04:00
|
|
|
if ((command = shell_command_input->value()) == NULL || !*command) {
|
|
|
|
fl_alert("No shell command entered!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the output window and clear things...
|
2003-04-01 23:58:08 +04:00
|
|
|
shell_run_buffer->text("");
|
|
|
|
shell_run_buffer->append(command);
|
|
|
|
shell_run_buffer->append("\n");
|
2002-05-01 14:36:08 +04:00
|
|
|
shell_run_window->label("Shell Command Running...");
|
|
|
|
|
2004-09-08 19:42:47 +04:00
|
|
|
if ((shell_pipe = popen((char *)command, "r")) == NULL) {
|
2002-05-01 14:36:08 +04:00
|
|
|
fl_alert("Unable to run shell command: %s", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
shell_run_button->deactivate();
|
2003-04-01 23:58:08 +04:00
|
|
|
shell_run_window->hotspot(shell_run_display);
|
2002-05-01 14:36:08 +04:00
|
|
|
shell_run_window->show();
|
|
|
|
|
|
|
|
Fl::add_fd(fileno(shell_pipe), shell_pipe_cb);
|
|
|
|
|
|
|
|
while (shell_pipe) Fl::wait();
|
|
|
|
|
|
|
|
shell_run_button->activate();
|
|
|
|
shell_run_window->label("Shell Command Complete");
|
|
|
|
fl_beep();
|
|
|
|
|
|
|
|
while (shell_run_window->shown()) Fl::wait();
|
|
|
|
}
|
2002-05-01 14:44:55 +04:00
|
|
|
#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...
|
|
|
|
|
|
|
|
|
|
|
|
shell_window->hide();
|
|
|
|
|
|
|
|
if ((command = shell_command_input->value()) == NULL || !*command) {
|
|
|
|
fl_alert("No shell command entered!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((status = system(command)) != 0) {
|
|
|
|
fl_alert("Shell command returned status %d!", status);
|
|
|
|
} else if (completion_button->value()) {
|
|
|
|
fl_message("Shell command completed successfully!");
|
|
|
|
}
|
|
|
|
}
|
2003-08-02 16:38:10 +04:00
|
|
|
#endif // (!WIN32 || __CYGWIN__) && !__MWERKS__
|
2002-05-01 14:44:55 +04:00
|
|
|
|
2002-05-01 14:36:08 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
show_shell_window() {
|
|
|
|
shell_window->hotspot(shell_command_input);
|
|
|
|
shell_window->show();
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void set_filename(const char *c) {
|
|
|
|
if (filename) free((void *)filename);
|
2005-03-19 11:38:21 +03:00
|
|
|
filename = c ? strdup(c) : NULL;
|
|
|
|
|
|
|
|
if (filename) update_history(filename);
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(modflag);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the "modified" flag and update the title of the main window...
|
|
|
|
void set_modflag(int mf) {
|
|
|
|
const char *basename;
|
|
|
|
static char title[1024];
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2005-03-20 03:12:21 +03:00
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
// Enable/disable the Save menu item...
|
2005-03-20 03:12:21 +03:00
|
|
|
if (modflag) Main_Menu[16].activate();
|
|
|
|
else Main_Menu[16].deactivate();
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static int arg(int argc, char** argv, int& i) {
|
|
|
|
if (argv[i][1] == 'c' && !argv[i][2]) {compile_only = 1; i++; return 1;}
|
2000-06-08 12:26:45 +04:00
|
|
|
if (argv[i][1] == 'c' && argv[i][2] == 's' && !argv[i][3]) {compile_only = 1; compile_strings = 1; i++; return 1;}
|
1998-10-06 22:21:25 +04:00
|
|
|
if (argv[i][1] == 'o' && !argv[i][2] && i+1 < argc) {
|
1999-03-04 21:10:01 +03:00
|
|
|
code_file_name = argv[i+1];
|
|
|
|
code_file_set = 1;
|
|
|
|
i += 2;
|
|
|
|
return 2;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
if (argv[i][1] == 'h' && !argv[i][2]) {
|
1999-03-04 21:10:01 +03:00
|
|
|
header_file_name = argv[i+1];
|
|
|
|
header_file_set = 1;
|
|
|
|
i += 2;
|
|
|
|
return 2;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-10-30 00:59:15 +03:00
|
|
|
#if ! (defined(WIN32) && !defined (__CYGWIN__))
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
int quit_flag = 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
#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
|
|
|
|
|
2000-08-20 08:35:17 +04:00
|
|
|
extern "C" {
|
1998-10-06 22:21:25 +04:00
|
|
|
static void sigint(SIGARG) {
|
|
|
|
signal(SIGINT,sigint);
|
2005-03-20 07:00:48 +03:00
|
|
|
quit_flag = 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2000-08-20 08:35:17 +04:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int main(int argc,char **argv) {
|
|
|
|
int i = 1;
|
|
|
|
if (!Fl::args(argc,argv,i,arg) || i < argc-1) {
|
|
|
|
fprintf(stderr,"usage: %s <switches> name.fl\n"
|
1998-12-06 17:59:14 +03:00
|
|
|
" -c : write .cxx and .h and exit\n"
|
2000-06-08 12:26:45 +04:00
|
|
|
" -cs : write .cxx and .h and strings and exit\n"
|
1998-12-06 17:59:14 +03:00
|
|
|
" -o <name> : .cxx output filename, or extension if <name> starts with '.'\n"
|
|
|
|
" -h <name> : .h output filename, or extension if <name> starts with '.'\n"
|
1998-10-06 22:21:25 +04:00
|
|
|
"%s\n", argv[0], Fl::help);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const char *c = argv[i];
|
2002-08-17 00:10:21 +04:00
|
|
|
|
|
|
|
fl_register_images();
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
make_main_window();
|
2002-09-02 14:41:51 +04:00
|
|
|
|
2003-06-01 04:23:57 +04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
fl_open_callback(apple_open_cb);
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
if (c) set_filename(c);
|
|
|
|
if (!compile_only) {
|
|
|
|
Fl::visual((Fl_Mode)(FL_DOUBLE|FL_INDEX));
|
2001-09-30 02:59:45 +04:00
|
|
|
Fl_File_Icon::load_system_icons();
|
1998-10-06 22:21:25 +04:00
|
|
|
main_window->callback(exit_cb);
|
2002-11-03 03:01:21 +03:00
|
|
|
position_window(main_window,"main_window_pos", 1, 10, 30, WINWIDTH, WINHEIGHT );
|
1998-10-06 22:21:25 +04:00
|
|
|
main_window->show(argc,argv);
|
2002-11-03 03:01:21 +03:00
|
|
|
toggle_widgetbin_cb(0,0);
|
2002-04-30 22:11:49 +04:00
|
|
|
if (!c && openlast_button->value() && absolute_history[0][0]) {
|
|
|
|
// Open previous file when no file specified...
|
|
|
|
open_history_cb(0, absolute_history[0]);
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_suspend();
|
1998-10-06 22:21:25 +04:00
|
|
|
if (c && !read_file(c,0)) {
|
|
|
|
if (compile_only) {
|
|
|
|
fprintf(stderr,"%s : %s\n", c, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't read %s: %s", c, strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
2002-05-01 23:17:24 +04:00
|
|
|
if (compile_only) {
|
|
|
|
if (compile_strings) write_strings_cb(0,0);
|
|
|
|
write_cb(0,0);
|
|
|
|
exit(0);
|
|
|
|
}
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(0);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_clear();
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
signal(SIGINT,sigint);
|
|
|
|
#endif
|
2002-05-01 23:17:24 +04:00
|
|
|
|
|
|
|
grid_cb(horizontal_input, 0); // Makes sure that windows get snap params...
|
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
Fl::run();
|
|
|
|
#else
|
|
|
|
while (!quit_flag) Fl::wait();
|
|
|
|
|
|
|
|
if (quit_flag) exit_cb(0,0);
|
|
|
|
#endif // WIN32
|
|
|
|
|
|
|
|
undo_clear();
|
|
|
|
|
|
|
|
return (0);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
1998-10-21 20:29:01 +04:00
|
|
|
|
|
|
|
//
|
2005-02-06 19:28:36 +03:00
|
|
|
// End of "$Id$".
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|