fl_window_type.cxx
来自「SRI international 发布的OAA框架软件」· CXX 代码 · 共 797 行 · 第 1/2 页
CXX
797 行
//
// "$Id: Fl_Window_Type.cxx,v 1.1.1.1 2003/06/03 22:25:40 agno Exp $"
//
// Window type code for the Fast Light Tool Kit (FLTK).
//
// The widget describing an Fl_Window. This is also all the code
// for interacting with the overlay, which allows the user to
// select, move, and resize the children widgets.
//
// Copyright 1998-2002 by Bill Spitzak and others.
//
// 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.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
#include <FL/Fl.H>
#include <FL/Fl_Overlay_Window.H>
#include <FL/fl_message.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Menu_Item.H>
#include "Fl_Widget_Type.h"
#include <math.h>
#include <stdlib.h>
#include "alignment_panel.h"
#include <stdio.h>
extern int gridx;
extern int gridy;
extern int snap;
int include_H_from_C = 1;
extern int i18n_type;
extern const char* i18n_include;
extern const char* i18n_function;
extern const char* i18n_file;
extern const char* i18n_set;
extern int modflag;
extern Fl_Preferences fluid_prefs;
void grid_cb(Fl_Input *i, long v) {
int n = atoi(i->value());
if (n < 0) n = 0;
switch (v) {
case 1:
gridx = n;
fluid_prefs.set("gridx", n);
break;
case 2:
gridy = n;
fluid_prefs.set("gridy", n);
break;
case 3:
snap = n;
fluid_prefs.set("snap", n);
break;
}
// Next go through all of the windows in the project and set the
// stepping for resizes...
Fl_Type *p;
Fl_Window_Type *w;
for (p = Fl_Type::first; p; p = p->next) {
if (p->is_window()) {
w = (Fl_Window_Type *)p;
((Fl_Window *)(w->o))->size_range(gridx * snap, gridy * snap,
Fl::w(), Fl::h(),
gridx * snap, gridy * snap, 0);
}
}
}
void i18n_type_cb(Fl_Choice *c, void *) {
switch (i18n_type = c->value()) {
case 0 : /* None */
i18n_include_input->hide();
i18n_file_input->hide();
i18n_set_input->hide();
i18n_function_input->hide();
break;
case 1 : /* GNU gettext */
i18n_include_input->value("<libintl.h>");
i18n_include = i18n_include_input->value();
i18n_function_input->value("gettext");
i18n_function = i18n_function_input->value();
i18n_include_input->show();
i18n_file_input->hide();
i18n_set_input->hide();
i18n_function_input->show();
break;
case 2 : /* POSIX cat */
i18n_include_input->value("<nl_types.h>");
i18n_file_input->value("");
i18n_file = i18n_file_input->value();
i18n_set_input->value("1");
i18n_set = i18n_set_input->value();
i18n_include_input->show();
i18n_include = i18n_include_input->value();
i18n_file_input->show();
i18n_set_input->show();
i18n_function_input->hide();
break;
}
modflag = 1;
}
void i18n_text_cb(Fl_Input *i, void *) {
if (i == i18n_function_input)
i18n_function = i->value();
else if (i == i18n_file_input)
i18n_file = i->value();
else if (i == i18n_set_input)
i18n_set = i->value();
else if (i == i18n_include_input)
i18n_include = i->value();
modflag = 1;
}
extern const char* header_file_name;
extern const char* code_file_name;
void show_project_cb(Fl_Widget *, void *) {
if(project_window==0) make_project_window();
include_H_from_C_button->value(include_H_from_C);
header_file_input->value(header_file_name);
code_file_input->value(code_file_name);
i18n_type_chooser->value(i18n_type);
i18n_function_input->value(i18n_function);
i18n_file_input->value(i18n_file);
i18n_set_input->value(i18n_set);
i18n_include_input->value(i18n_include);
switch (i18n_type) {
case 0 : /* None */
i18n_include_input->hide();
i18n_file_input->hide();
i18n_set_input->hide();
i18n_function_input->hide();
break;
case 1 : /* GNU gettext */
i18n_include_input->show();
i18n_file_input->hide();
i18n_set_input->hide();
i18n_function_input->show();
break;
case 2 : /* POSIX cat */
i18n_include_input->show();
i18n_file_input->show();
i18n_set_input->show();
i18n_function_input->hide();
break;
}
project_window->hotspot(project_window);
project_window->show();
}
void show_grid_cb(Fl_Widget *, void *) {
char buf[128];
sprintf(buf,"%d",gridx); horizontal_input->value(buf);
sprintf(buf,"%d",gridy); vertical_input->value(buf);
sprintf(buf,"%d",snap); snap_input->value(buf);
grid_window->hotspot(grid_window);
grid_window->show();
}
void show_settings_cb(Fl_Widget *, void *) {
settings_window->hotspot(settings_window);
settings_window->show();
}
void header_input_cb(Fl_Input* i, void*) {
header_file_name = i->value();
}
void code_input_cb(Fl_Input* i, void*) {
code_file_name = i->value();
}
void include_H_from_C_button_cb(Fl_Light_Button* b, void*) {
include_H_from_C = b->value();
}
////////////////////////////////////////////////////////////////
Fl_Menu_Item window_type_menu[] = {
{"Single",0,0,(void*)FL_WINDOW},
{"Double",0,0,(void*)(FL_WINDOW+1)},
{0}};
static int overlays_invisible;
// The following Fl_Widget is used to simulate the windows. It has
// an overlay for the fluid ui, and special-cases the FL_NO_BOX.
class Overlay_Window : public Fl_Overlay_Window {
void draw();
void draw_overlay();
public:
Fl_Window_Type *window;
int handle(int);
Overlay_Window(int W,int H) : Fl_Overlay_Window(W,H) {Fl_Group::current(0);}
void resize(int,int,int,int);
};
void Overlay_Window::draw() {
const int CHECKSIZE = 8;
// see if box is clear or a frame or rounded:
if ((damage()&FL_DAMAGE_ALL) &&
(!box() || (box()>=4&&!(box()&2)) || box()>=_FL_ROUNDED_BOX)) {
// if so, draw checkerboard so user can see what areas are clear:
for (int Y = 0; Y < h(); Y += CHECKSIZE)
for (int X = 0; X < w(); X += CHECKSIZE) {
fl_color(((Y/(2*CHECKSIZE))&1) != ((X/(2*CHECKSIZE))&1) ?
FL_WHITE : FL_BLACK);
fl_rectf(X,Y,CHECKSIZE,CHECKSIZE);
}
}
Fl_Overlay_Window::draw();
}
void Overlay_Window::draw_overlay() {
window->draw_overlay();
}
int Overlay_Window::handle(int e) {
return window->handle(e);
}
Fl_Type *Fl_Window_Type::make() {
Fl_Type *p = Fl_Type::current;
while (p && !p->is_code_block()) p = p->parent;
if (!p) {
fl_message("Please select a function");
return 0;
}
Fl_Window_Type *myo = new Fl_Window_Type();
if (!this->o) {// template widget
this->o = new Fl_Window(100,100);
Fl_Group::current(0);
}
// Set the size ranges for this window; in order to avoid opening the
// X display we use an arbitrary maximum size...
((Fl_Window *)(this->o))->size_range(gridx * snap, gridy * snap,
3072, 2048,
gridx * snap, gridy * snap, 0);
myo->factory = this;
myo->drag = 0;
myo->numselected = 0;
Overlay_Window *w = new Overlay_Window(100,100);
w->window = myo;
myo->o = w;
myo->add(p);
myo->modal = 0;
myo->non_modal = 0;
return myo;
}
void Fl_Window_Type::add_child(Fl_Type* cc, Fl_Type* before) {
Fl_Widget_Type* c = (Fl_Widget_Type*)cc;
Fl_Widget* b = before ? ((Fl_Widget_Type*)before)->o : 0;
((Fl_Window*)o)->insert(*(c->o), b);
o->redraw();
}
void Fl_Window_Type::remove_child(Fl_Type* cc) {
Fl_Widget_Type* c = (Fl_Widget_Type*)cc;
((Fl_Window*)o)->remove(c->o);
o->redraw();
}
void Fl_Window_Type::move_child(Fl_Type* cc, Fl_Type* before) {
Fl_Widget_Type* c = (Fl_Widget_Type*)cc;
((Fl_Window*)o)->remove(c->o);
Fl_Widget* b = before ? ((Fl_Widget_Type*)before)->o : 0;
((Fl_Window*)o)->insert(*(c->o), b);
o->redraw();
}
////////////////////////////////////////////////////////////////
// Double-click on window widget shows the window, or if already shown,
// it shows the control panel.
void Fl_Window_Type::open() {
Overlay_Window *w = (Overlay_Window *)o;
if (w->shown()) {
w->show();
Fl_Widget_Type::open();
} else {
Fl_Widget *p = w->resizable();
if (!p) w->resizable(w);
w->show();
w->resizable(p);
}
}
// control panel items:
#include "widget_panel.h"
void modal_cb(Fl_Light_Button* i, void* v) {
if (v == LOAD) {
if (!current_widget->is_window()) {i->hide(); return;}
i->show();
i->value(((Fl_Window_Type *)current_widget)->modal);
} else {
((Fl_Window_Type *)current_widget)->modal = i->value();
}
}
void non_modal_cb(Fl_Light_Button* i, void* v) {
if (v == LOAD) {
if (!current_widget->is_window()) {i->hide(); return;}
i->show();
i->value(((Fl_Window_Type *)current_widget)->non_modal);
} else {
((Fl_Window_Type *)current_widget)->non_modal = i->value();
}
}
void border_cb(Fl_Light_Button* i, void* v) {
if (v == LOAD) {
if (!current_widget->is_window()) {i->hide(); return;}
i->show();
i->value(((Fl_Window*)(current_widget->o))->border());
} else {
((Fl_Window*)(current_widget->o))->border(i->value());
}
}
void xclass_cb(Fl_Input* i, void* v) {
if (v == LOAD) {
if (!current_widget->is_window()) {i->hide(); return;}
i->show();
i->value(((Fl_Widget_Type *)current_widget)->xclass);
} else {
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* w = (Fl_Widget_Type*)o;
if (w->is_window() || w->is_button())
storestring(i->value(),w->xclass);
if (w->is_window()) ((Fl_Window*)(w->o))->xclass(w->xclass);
else if (w->is_menu_item()) w->redraw();
}
}
}
////////////////////////////////////////////////////////////////
void Fl_Window_Type::setlabel(const char *n) {
if (o) ((Fl_Window *)o)->label(n);
}
// make() is called on this widget when user picks window off New menu:
Fl_Window_Type Fl_Window_type;
// Resize from window manager, try to resize it back to a legal size.
// This is not proper X behavior, but works on 4DWM and fvwm
void Overlay_Window::resize(int X,int Y,int W,int H) {
// if (!visible() || W==w() && H==h()) {
// Fl_Overlay_Window::resize(X,Y,W,H);
// return;
// }
// int nw = gridx&&W!=w() ? ((W+gridx/2)/gridx)*gridx : W;
// int nh = gridy&&H!=h() ? ((H+gridy/2)/gridy)*gridy : H;
Fl_Widget* t = resizable(); resizable(0);
Fl_Overlay_Window::resize(X,Y,W,H);
resizable(t);
// // make sure new window size surrounds the widgets:
// int b = 0;
// int r = 0;
// for (Fl_Type *o=window->next; o && o->level>window->level; o=o->next)
// if (o->is_widget() && !o->is_menu_item()) {
// Fl_Widget* w = ((Fl_Widget_Type*)o)->o;
// if (w->x()+w->w() > r) r = w->x()+w->w();
// if (w->y()+w->h() > b) b = w->y()+w->h();
// }
// if (nh < b) nh = b;
// if (nw < r) nw = r;
// // If changed, tell the window manager. Skip really big windows
// // that might be bigger than screen:
// if (nw != W && nw < Fl::w()-100 || nh != H && nh < Fl::h()-100) size(nw,nh);
}
// calculate actual move by moving mouse position (mx,my) to
// nearest multiple of gridsize, and snap to original position
void Fl_Window_Type::newdx() {
int mydx, mydy;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?