📄 fluid.cxx
字号:
show_help("index.html");
}
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();
else
widgetbin_panel->show();
}
////////////////////////////////////////////////////////////////
extern Fl_Menu_Item New_Menu[];
Fl_Menu_Item Main_Menu[] = {
{"&File",0,0,0,FL_SUBMENU},
{"&New", 0, new_cb, 0},
{"&Open...", FL_CTRL+'o', open_cb, 0},
{"Open &Previous",0,0,0,FL_SUBMENU},
{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},
{"&Insert...", FL_CTRL+'i', open_cb, (void*)1, FL_MENU_DIVIDER},
{"&Save", FL_CTRL+'s', save_cb, 0},
{"Save &As...", FL_CTRL+FL_SHIFT+'s', save_cb, (void*)1, FL_MENU_DIVIDER},
{"Write &code", FL_CTRL+FL_SHIFT+'c', write_cb, 0},
{"&Write strings", FL_CTRL+FL_SHIFT+'w', write_strings_cb, 0, FL_MENU_DIVIDER},
{"&Quit", FL_CTRL+'q', exit_cb},
{0},
{"&Edit",0,0,0,FL_SUBMENU},
{"&Undo", FL_CTRL+'z', nyi},
{"C&ut", FL_CTRL+'x', cut_cb},
{"&Copy", FL_CTRL+'c', copy_cb},
{"&Paste", FL_CTRL+'v', paste_cb},
{"Select &All", FL_CTRL+'a', select_all_cb, 0, FL_MENU_DIVIDER},
{"&Open...", FL_F+1, openwidget_cb},
{"&Sort",0,sort_cb},
{"&Earlier", FL_F+2, earlier_cb},
{"&Later", FL_F+3, later_cb},
//{"Show", FL_F+5, show_cb},
//{"Hide", FL_F+6, hide_cb},
{"&Group", FL_F+7, group_cb},
{"U&ngroup", FL_F+8, ungroup_cb,0, FL_MENU_DIVIDER},
//{"Deactivate", 0, nyi},
//{"Activate", 0, nyi, 0, FL_MENU_DIVIDER},
{"O&verlays on/off",FL_CTRL+FL_SHIFT+'o',toggle_overlays},
{"Widget &Bin on/off",FL_ALT+'b',toggle_widgetbin_cb},
{"Pro&ject Settings...",FL_CTRL+'p',show_project_cb},
{"&GUI Settings...",FL_CTRL+FL_SHIFT+'p',show_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},
{"&Center In Group",0,0,0,FL_SUBMENU|FL_MENU_DIVIDER},
{"&Horizontal",0,(Fl_Callback *)align_widget_cb,(void*)40},
{"&Vertical",0,(Fl_Callback *)align_widget_cb,(void*)41},
{0},
{"&Grid...",FL_CTRL+'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},
{"&About FLUID...",0,about_cb},
{"&On FLUID...",0,help_cb},
{"&Manual...",0,manual_cb},
{0},
{0}};
#define BROWSERWIDTH 300
#define BROWSERHEIGHT 500
#define WINWIDTH 300
#define MENUHEIGHT 25
#define WINHEIGHT (BROWSERHEIGHT+MENUHEIGHT)
extern void fill_in_New_Menu();
void make_main_window() {
int i;
fluid_prefs.get("snap", i, 1);
snap = i;
fluid_prefs.get("gridx", i, 5);
gridx = i;
fluid_prefs.get("gridy", i, 5);
gridy = i;
load_history();
make_grid_window();
make_settings_window();
make_shell_window();
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);
o->tooltip("Double-click to view or change an item.");
main_window->resizable(o);
Fl_Menu_Bar *m = new Fl_Menu_Bar(0,0,BROWSERWIDTH,MENUHEIGHT);
m->menu(Main_Menu);
m->global();
fill_in_New_Menu();
main_window->end();
}
}
// Load file history from preferences...
void load_history() {
int i; // Looping var
for (i = 0; i < 10; 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]);
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...
void update_history(const char *flname) {
int i; // Looping var
char absolute[1024];
fl_filename_absolute(absolute, sizeof(absolute), flname);
for (i = 0; i < 10; 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 >= 10) i = 9;
// 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 < 10; i ++) {
fluid_prefs.set( Fl_Preferences::Name("file%d", i), absolute_history[i]);
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;
}
// Shell command support...
#if !defined(WIN32) || defined(__CYGWIN__)
// Support the full piped shell command...
static FILE *shell_pipe = 0;
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...
shell_run_list->add(line);
shell_run_list->make_visible(shell_run_list->size());
} else {
// End of file; tell the parent...
Fl::remove_fd(fileno(shell_pipe));
pclose(shell_pipe);
shell_pipe = NULL;
shell_run_list->add("... END SHELL COMMAND ...");
}
}
void
do_shell_command(Fl_Return_Button*, void*) {
const char *command; // Command to run
shell_window->hide();
if (shell_pipe) {
fl_alert("Previous shell command still running!");
return;
}
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...
shell_run_list->clear();
shell_run_list->add(command);
shell_run_window->label("Shell Command Running...");
if ((shell_pipe = popen(command, "r")) == NULL) {
fl_alert("Unable to run shell command: %s", strerror(errno));
return;
}
shell_run_button->deactivate();
shell_run_window->hotspot(shell_run_list);
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();
}
#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!");
}
}
#endif // !WIN32 || __CYGWIN__
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 = strdup(c);
if (main_window) main_window->label(filename);
update_history(filename);
}
////////////////////////////////////////////////////////////////
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;
}
return 0;
}
#if ! (defined(WIN32) && !defined (__CYGWIN__))
#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);
exit_cb(0,0);
}
}
#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"
" -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"
"%s\n", argv[0], Fl::help);
return 1;
}
const char *c = argv[i];
fl_register_images();
make_main_window();
if (c) set_filename(c);
if (!compile_only) {
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);
if (!c && openlast_button->value() && absolute_history[0][0]) {
// Open previous file when no file specified...
open_history_cb(0, absolute_history[0]);
}
}
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));
}
if (compile_only) {
if (compile_strings) write_strings_cb(0,0);
write_cb(0,0);
exit(0);
}
modflag = 0;
#ifndef WIN32
signal(SIGINT,sigint);
#endif
grid_cb(horizontal_input, 0); // Makes sure that windows get snap params...
return Fl::run();
}
//
// End of "$Id: fluid.cxx,v 1.1.1.1 2003/06/03 22:25:41 agno Exp $".
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -