fl_widget_type.cxx
来自「SRI international 发布的OAA框架软件」· CXX 代码 · 共 1,977 行 · 第 1/5 页
CXX
1,977 行
// directory they chose is preserved, we change to a normal text label.
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* p = (Fl_Widget_Type*)o;
dont_touch_image = 1;
p->setimage(i);
p->label(ui_find_image_name);
dont_touch_image = 0;
}
label_cb(label_input,LOAD);
a->when(FL_WHEN_RELEASE|FL_WHEN_NOT_CHANGED);
}
#endif /* 0 */
Fl_Menu_Item labeltypemenu[] = {
{"NORMAL_LABEL",0,0,(void*)0},
{"SHADOW_LABEL",0,0,(void*)FL_SHADOW_LABEL},
{"ENGRAVED_LABEL",0,0,(void*)FL_ENGRAVED_LABEL},
{"EMBOSSED_LABEL",0,0,(void*)FL_EMBOSSED_LABEL},
{"NO_LABEL",0,0,(void*)(FL_NO_LABEL)},
{0}};
void labeltype_cb(Fl_Choice* i, void *v) {
if (v == LOAD) {
int n;
n = current_widget->o->labeltype();
i->when(FL_WHEN_RELEASE);
for (int j = 0; j < int(sizeof(labeltypemenu)/sizeof(*labeltypemenu)); j++)
if (labeltypemenu[j].argument() == n) {i->value(j); break;}
} else {
int m = i->value();
int n = int(labeltypemenu[m].argument());
if (n<0) return; // should not happen
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* p = (Fl_Widget_Type*)o;
p->o->labeltype((Fl_Labeltype)n);
p->redraw();
}
}
}
////////////////////////////////////////////////////////////////
void color_cb(Fl_Button* i, void *v) {
Fl_Color c = current_widget->o->color();
if (v == LOAD) {
if (current_widget->is_menu_item()) {i->deactivate(); return;} else i->activate();
} else {
Fl_Color d = fl_show_colormap(c);
if (d == c) return;
c = d;
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
q->o->color(c); q->o->redraw();
}
}
i->color(c); i->labelcolor(fl_contrast(FL_BLACK,c)); i->redraw();
}
void color2_cb(Fl_Button* i, void *v) {
Fl_Color c = current_widget->o->selection_color();
if (v == LOAD) {
if (current_widget->is_menu_item()) {i->deactivate(); return;} else i->activate();
} else {
Fl_Color d = fl_show_colormap(c);
if (d == c) return;
c = d;
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
q->o->selection_color(c); q->o->redraw();
}
}
i->color(c); i->labelcolor(fl_contrast(FL_BLACK,c)); i->redraw();
}
void labelcolor_cb(Fl_Button* i, void *v) {
Fl_Color c = current_widget->o->labelcolor();
if (v != LOAD) {
Fl_Color d = fl_show_colormap(c);
if (d == c) return;
c = d;
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
q->o->labelcolor(c); q->redraw();
}
}
i->color(c); i->labelcolor(fl_contrast(FL_BLACK,c)); i->redraw();
}
static Fl_Button* relative(Fl_Widget* o, int i) {
Fl_Group* g = (Fl_Group*)(o->parent());
return (Fl_Button*)(g->child(g->find(*o)+i));
}
static Fl_Menu_Item alignmenu[] = {
{"FL_ALIGN_CENTER",0,0,(void*)(FL_ALIGN_CENTER)},
{"FL_ALIGN_TOP",0,0,(void*)(FL_ALIGN_TOP)},
{"FL_ALIGN_BOTTOM",0,0,(void*)(FL_ALIGN_BOTTOM)},
{"FL_ALIGN_LEFT",0,0,(void*)(FL_ALIGN_LEFT)},
{"FL_ALIGN_RIGHT",0,0,(void*)(FL_ALIGN_RIGHT)},
{"FL_ALIGN_INSIDE",0,0,(void*)(FL_ALIGN_INSIDE)},
{"FL_ALIGN_CLIP",0,0,(void*)(FL_ALIGN_CLIP)},
{"FL_ALIGN_WRAP",0,0,(void*)(FL_ALIGN_WRAP)},
{"FL_ALIGN_TEXT_OVER_IMAGE",0,0,(void*)(FL_ALIGN_TEXT_OVER_IMAGE)},
{"FL_ALIGN_TOP_LEFT",0,0,(void*)(FL_ALIGN_TOP_LEFT)},
{"FL_ALIGN_TOP_RIGHT",0,0,(void*)(FL_ALIGN_TOP_RIGHT)},
{"FL_ALIGN_BOTTOM_LEFT",0,0,(void*)(FL_ALIGN_BOTTOM_LEFT)},
{"FL_ALIGN_BOTTOM_RIGHT",0,0,(void*)(FL_ALIGN_BOTTOM_RIGHT)},
{"FL_ALIGN_LEFT_TOP",0,0,(void*)(FL_ALIGN_LEFT_TOP)},
{"FL_ALIGN_RIGHT_TOP",0,0,(void*)(FL_ALIGN_RIGHT_TOP)},
{"FL_ALIGN_LEFT_BOTTOM",0,0,(void*)(FL_ALIGN_LEFT_BOTTOM)},
{"FL_ALIGN_RIGHT_BOTTOM",0,0,(void*)(FL_ALIGN_RIGHT_BOTTOM)},
{0}};
void align_cb(Fl_Button* i, void *v) {
int b = int(long(i->user_data()));
if (v == LOAD) {
if (current_widget->is_menu_item()) {i->deactivate(); return;} else i->activate();
i->value(current_widget->o->align() & b);
} else {
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
int x = q->o->align();
int y;
if (i->value()) {
y = x | b;
if (b == FL_ALIGN_LEFT || b == FL_ALIGN_TOP) {
Fl_Button *b1 = relative(i,+1);
b1->clear();
y = y & ~(b1->argument());
}
if (b == FL_ALIGN_RIGHT || b == FL_ALIGN_BOTTOM) {
Fl_Button *b1 = relative(i,-1);
b1->clear();
y = y & ~(b1->argument());
}
} else {
y = x & ~b;
}
if (x != y) {q->o->align(y); q->redraw();}
}
}
}
////////////////////////////////////////////////////////////////
void callback_cb(Fl_Text_Editor* i, void *v) {
if (v == LOAD) {
const char *cbtext = current_widget->callback();
i->buffer()->text( cbtext ? cbtext : "" );
} else {
char *c = i->buffer()->text();
const char *d = c_check(c);
if (d) {fl_message("Error in callback: %s",d); haderror = 1; return;}
for (Fl_Type *o = Fl_Type::first; o; o = o->next) if (o->selected) {
o->callback(c);
}
free(c);
}
}
void user_data_cb(Fl_Input *i, void *v) {
if (v == LOAD) {
i->static_value(current_widget->user_data());
} else {
const char *c = i->value();
const char *d = c_check(c);
if (d) {fl_message("Error in user_data: %s",d); haderror = 1; return;}
for (Fl_Type *o = Fl_Type::first; o; o = o->next) if (o->selected) {
o->user_data(c);
}
}
}
void user_data_type_cb(Fl_Input *i, void *v) {
static const char *dflt = "void*";
if (v == LOAD) {
const char *c = current_widget->user_data_type();
if (!c) c = dflt;
i->static_value(c);
} else {
const char *c = i->value();
const char *d = c_check(c);
if (!*c) i->value(dflt);
else if (!strcmp(c,dflt)) c = 0;
if (!d) {
if (c && *c && c[strlen(c)-1] != '*' && strcmp(c,"long"))
d = "must be pointer or long";
}
if (d) {fl_message("Error in type: %s",d); haderror = 1; return;}
for (Fl_Type *o = Fl_Type::first; o; o = o->next) if (o->selected) {
o->user_data_type(c);
}
}
}
// "v_attributes" let user type in random code for attribute settings:
void v_input_cb(Fl_Input* i, void* v) {
int n = int(long(i->user_data()));
if (v == LOAD) {
i->static_value(current_widget->extra_code(n));
} else {
const char *c = i->value();
const char *d = c_check(c&&c[0]=='#' ? c+1 : c);
if (d) {fl_message("Error in %s: %s",i->label(),d); haderror = 1; return;}
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type *t = (Fl_Widget_Type*)o;
t->extra_code(n,c);
}
}
}
void subclass_cb(Fl_Input* i, void* v) {
if (v == LOAD) {
if (current_widget->is_menu_item()) {i->deactivate(); return;} else i->activate();
i->static_value(current_widget->subclass());
} else {
const char *c = i->value();
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type *t = (Fl_Widget_Type*)o;
t->subclass(c);
}
}
}
////////////////////////////////////////////////////////////////
// textstuff: set textfont, textsize, textcolor attributes:
// default widget returns 0 to indicate not-implemented:
int Fl_Widget_Type::textstuff(int, Fl_Font&, int&, Fl_Color&) {return 0;}
void textfont_cb(Fl_Choice* i, void* v) {
Fl_Font n; int s; Fl_Color c;
if (v == LOAD) {
if (!current_widget->textstuff(0,n,s,c)) {i->deactivate(); return;}
i->activate();
if (n > 15) n = FL_HELVETICA;
i->value(n);
} else {
n = (Fl_Font)i->value();
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
q->textstuff(1,n,s,c);
q->o->redraw();
}
}
}
void textsize_cb(Fl_Value_Input* i, void* v) {
Fl_Font n; int s; Fl_Color c;
if (v == LOAD) {
if (!current_widget->textstuff(0,n,s,c)) {i->deactivate(); return;}
i->activate();
} else {
s = int(i->value());
if (s <= 0) s = FL_NORMAL_SIZE;
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
q->textstuff(2,n,s,c);
q->o->redraw();
}
}
i->value(s);
}
void textcolor_cb(Fl_Button* i, void* v) {
Fl_Font n; int s; Fl_Color c;
if (v == LOAD) {
if (!current_widget->textstuff(0,n,s,c)) {i->deactivate(); return;}
i->activate();
} else {
c = i->color();
Fl_Color d = fl_show_colormap(c);
if (d == c) return;
c = d;
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
q->textstuff(3,n,s,c); q->o->redraw();
}
}
i->color(c); i->labelcolor(fl_contrast(FL_BLACK,c)); i->redraw();
}
////////////////////////////////////////////////////////////////
// Kludges to the panel for subclasses:
void slider_size_cb(Fl_Value_Input* i, void* v) {
if (v == LOAD) {
if (current_widget->is_valuator()!=2) {i->deactivate(); return;}
i->activate();
i->value(((Fl_Slider*)(current_widget->o))->slider_size());
} else {
double n = i->value();
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
if (q->is_valuator()==2) {
((Fl_Slider*)(q->o))->slider_size(n);
q->o->redraw();
}
}
}
}
void min_cb(Fl_Value_Input* i, void* v) {
if (v == LOAD) {
if (!current_widget->is_valuator()) {i->deactivate(); return;}
i->activate();
i->value(((Fl_Valuator*)(current_widget->o))->minimum());
} else {
double n = i->value();
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
if (q->is_valuator()) {
((Fl_Valuator*)(q->o))->minimum(n);
q->o->redraw();
}
}
}
}
void max_cb(Fl_Value_Input* i, void* v) {
if (v == LOAD) {
if (!current_widget->is_valuator()) {i->deactivate(); return;}
i->activate();
i->value(((Fl_Valuator*)(current_widget->o))->maximum());
} else {
double n = i->value();
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
if (q->is_valuator()) {
((Fl_Valuator*)(q->o))->maximum(n);
q->o->redraw();
}
}
}
}
void step_cb(Fl_Value_Input* i, void* v) {
if (v == LOAD) {
if (!current_widget->is_valuator()) {i->deactivate(); return;}
i->activate();
i->value(((Fl_Valuator*)(current_widget->o))->step());
} else {
double n = i->value();
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
if (q->is_valuator()) {
((Fl_Valuator*)(q->o))->step(n);
q->o->redraw();
}
}
}
}
void value_cb(Fl_Value_Input* i, void* v) {
if (v == LOAD) {
if (current_widget->is_valuator()) {
i->activate();
i->value(((Fl_Valuator*)(current_widget->o))->value());
} else if (current_widget->is_button()) {
i->activate();
i->value(((Fl_Button*)(current_widget->o))->value());
} else
i->deactivate();
} else {
double n = i->value();
for (Fl_Type *o = Fl_Type::first; o; o = o->next)
if (o->selected && o->is_widget()) {
Fl_Widget_Type* q = (Fl_Widget_Type*)o;
if (q->is_valuator()) {
((Fl_Valuator*)(q->o))->value(n);
} else if (q->is_button()) {
((Fl_Button*)(q->o))->value(n != 0);
if (q->is_menu_item()) q->redraw();
}
}
}
}
////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?