⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fl_widget_type.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 4 页
字号:
//// "$Id: Fl_Widget_Type.cxx,v 1.1.1.1 2003/08/07 21:18:39 jasonk Exp $"//// Widget type code for the Fast Light Tool Kit (FLTK).//// Copyright 1998-1999 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@easysw.com".//#include <FL/Fl.H>#include <FL/Fl_Group.H>#include "Fl_Widget_Type.h"#include <FL/fl_message.H>#include <FL/Fl_Slider.H>#include <FL/Fl_Window.H>#include <string.h>#include <stdio.h>#include <stdlib.h>// Make an Fl_Widget_Type subclass instance.// It figures out the automatic size and parent of the new widget,// creates the Fl_Widget (by calling the virtual function _make),// adds it to the Fl_Widget hierarchy, creates a new Fl_Type// instance, sets the widget pointers, and makes all the display// update correctly...extern int reading_file;int force_parent;extern int gridx;extern int gridy;int Fl_Widget_Type::is_widget() const {return 1;}const char* subclassname(Fl_Type* l) {  if (l->is_widget()) {    Fl_Widget_Type* p = (Fl_Widget_Type*)l;    const char* c = p->subclass();    if (c) return c;    if (p->o->type() == FL_WINDOW+1) return "Fl_Double_Window";  }  return l->type_name();}Fl_Type *Fl_Widget_Type::make() {  // Find the current widget, or widget to copy:  Fl_Type *qq = Fl_Type::current;  while (qq && (!qq->is_widget() || qq->is_menu_item())) qq = qq->parent;  if (!qq) {    fl_message("Please select a widget");    return 0;  }  Fl_Widget_Type* q = (Fl_Widget_Type*)qq;  // find the parent widget:  Fl_Widget_Type* p = q;  if ((force_parent || !p->is_group()) && p->parent->is_widget())    p = (Fl_Widget_Type*)(p->parent);  force_parent = 0;  // Figure out a border between widget and window:  int B = p->o->w()/2; if (p->o->h()/2 < B) B = p->o->h()/2; if (B>25) B = 25;  int ULX,ULY; // parent's origin in window  if (!p->is_window()) { // if it is a group, add corner    ULX = p->o->x(); ULY = p->o->y();  } else {    ULX = ULY = 0;  }  // Figure out a position and size for the widget  int X,Y,W,H;  if (is_group()) {	// fill the parent with the widget    X = ULX+B;    W = p->o->w()-B;    Y = ULY+B;    H = p->o->h()-B;  } else if (q != p) {	// copy position and size of current widget    W = q->o->w();    H = q->o->h();    X = q->o->x()+W;    Y = q->o->y();    if (X+W > ULX+p->o->w()) {      X = q->o->x();      Y = q->o->y()+H;      if (Y+H > ULY+p->o->h()) Y = ULY+B;    }  } else {	// just make it small and square...    X = ULX+B;    Y = ULY+B;    W = H = B;  }  // satisfy the grid requirements (otherwise it edits really strangely):  if (gridx>1) {    X = (X/gridx)*gridx;    W = ((W-1)/gridx+1)*gridx;  }  if (gridy>1) {    Y = (Y/gridy)*gridy;    H = ((H-1)/gridy+1)*gridy;  }  // Construct the Fl_Type:  Fl_Widget_Type *t = _make();  if (!o) o = widget(0,0,100,100); // create template widget  t->factory = this;  // Construct the Fl_Widget:  t->o = widget(X,Y,W,H);  if (reading_file) t->o->label(0);  else if (t->o->label()) t->label(t->o->label()); // allow editing  t->o->user_data((void*)t);  // Put it in the parent:  //  ((Fl_Group *)(p->o))->add(t->o); (done by Fl_Type::add())  // add to browser:  t->add(p);  t->redraw();  return t;}#include "Fluid_Image.h"void Fl_Widget_Type::setimage(Fluid_Image *i) {  if (i == image) return;  if (image) image->decrement();  if (i) i->increment();  image = i;  if (i) i->label(o);  else o->labeltype(FL_NORMAL_LABEL);  redraw();}static char dont_touch_image;void Fl_Widget_Type::setlabel(const char *n) {  if (image) {    if (dont_touch_image) return;    Fluid_Image *i = Fluid_Image::find(n);    setimage(i);    if (i) return;  }  o->label(n);  redraw();}Fl_Widget_Type::Fl_Widget_Type() {  for (int n=0; n<NUM_EXTRA_CODE; n++) {extra_code_[n] = 0; subclass_ = 0;}  hotspot_ = 0;  image = 0;  xclass = 0;  o = 0;  public_ = 1;}Fl_Widget_Type::~Fl_Widget_Type() {  if (o) {    o->hide();    if (o->parent()) ((Fl_Group*)o->parent())->remove(*o);    delete o;  }}void Fl_Widget_Type::extra_code(int m,const char *n) {  storestring(n,extra_code_[m]);}extern void redraw_browser();void Fl_Widget_Type::subclass(const char *n) {  if (storestring(n,subclass_) && visible)    redraw_browser();}void Fl_Widget_Type::redraw() {  Fl_Type *t = this;  if (is_menu_item()) {    // find the menu button that parents this menu:    do t = t->parent; while (t && t->is_menu_item());    // kludge to cause build_menu to be called again:    t->add_child(0,0);  } else {    while (t->parent && t->parent->is_widget()) t = t->parent;    ((Fl_Widget_Type*)t)->o->redraw();  }}// the recursive part sorts all children, returns pointer to next:Fl_Type *sort(Fl_Type *parent) {  Fl_Type *f,*n=0;  for (f = parent ? parent->next : Fl_Type::first; ; f = n) {    if (!f || parent && f->level <= parent->level) return f;    n = sort(f);    if (!f->selected || (!f->is_widget() || f->is_menu_item())) continue;    Fl_Widget* fw = ((Fl_Widget_Type*)f)->o;    Fl_Type *g; // we will insert before this    for (g = parent->next; g != f; g = g->next) {      if (!g->selected || g->level > f->level) continue;      Fl_Widget* gw = ((Fl_Widget_Type*)g)->o;      if (gw->y() > fw->y()) break;      if (gw->y() == fw->y() && gw->x() > fw->x()) break;    }    if (g != f) f->move_before(g);  }}////////////////////////////////////////////////////////////////// The control panels!#include "widget_panel.h"#include <FL/fl_show_colormap.H>// All the callbacks use the argument to indicate whether to load or store.// This avoids the need for pointers to all the widgets, and keeps the// code localized in the callbacks.// A value of LOAD means to load.  The hope is that this will not collide// with any actual useful values for the argument.  I also use this to// initialized parts of the widget that are nyi by fluid.Fl_Widget_Type *current_widget; // one of the selected onesstatic int numselected; // number selectedstatic int haderror;void name_cb(Fl_Input* o, void *v) {  if (v == LOAD) {    if (numselected != 1) {      static char buf[16];      sprintf(buf,"(%d widgets)",numselected);      ((Fl_Window*)(o->parent()))->label(buf);      o->hide();    } else {      o->static_value(current_widget->name());      o->show();      ((Fl_Window*)(o->parent()))->label(current_widget->title());    }  } else {    if (numselected == 1) {      current_widget->name(o->value());      // I don't update window title, as it probably is being closed      // and wm2 (a window manager) barfs if you retitle and then      // hide a window:      // ((Fl_Window*)(o->parent()))->label(current_widget->title());    }  }}void name_public_cb(Fl_Light_Button* i, void* v) {  if (v == LOAD) {    i->value(current_widget->public_);  } else {    for (Fl_Type *o = Fl_Type::first; o; o = o->next)      if (o->selected && o->is_widget())	((Fl_Widget_Type*)o)->public_ = i->value();  }}    static char* oldlabel;static unsigned oldlabellen;static Fl_Input *label_input;void label_cb(Fl_Input* i, void *v) {  if (v == LOAD) {    label_input = i;    i->static_value(current_widget->label());    if (strlen(i->value()) >= oldlabellen) {      oldlabellen = strlen(i->value())+128;      oldlabel = (char*)realloc(oldlabel,oldlabellen);    }    strcpy(oldlabel,i->value());    if (current_widget->image) i->deactivate();    else i->activate();  } else {    for (Fl_Type *o = Fl_Type::first; o; o = o->next)      if (o->selected && o->is_widget()) o->label(i->value());  }}////////////////////////////////////////////////////////////////// turn number to string or string to number for saving to file:// does not work for hierarchial menus!const char *item_name(Fl_Menu_Item* m, int i) {  if (m) {    while (m->label()) {      if (m->argument() == i) return m->label();      m++;    }  }  static char buffer[20];  sprintf(buffer, "%d", i);  return buffer;}int item_number(Fl_Menu_Item* m, const char* i) {  if (m && i) {    if (i[0]=='F' && i[1]=='L' && i[2]=='_') i += 3;    while (m->label()) {      if (!strcmp(m->label(), i)) return int(m->argument());      m++;    }  }  return atoi(i);}#define ZERO_ENTRY 1000Fl_Menu_Item boxmenu[] = {{"NO_BOX",0,0,(void *)ZERO_ENTRY},{"boxes",0,0,0,FL_SUBMENU},{"UP_BOX",0,0,(void *)FL_UP_BOX},{"DOWN_BOX",0,0,(void *)FL_DOWN_BOX},{"FLAT_BOX",0,0,(void *)FL_FLAT_BOX},{"BORDER_BOX",0,0,(void *)FL_BORDER_BOX},{"THIN_UP_BOX",0,0,(void *)FL_THIN_UP_BOX},{"THIN_DOWN_BOX",0,0,(void *)FL_THIN_DOWN_BOX},{"ENGRAVED_BOX",0,0,(void *)FL_ENGRAVED_BOX},{"EMBOSSED_BOX",0,0,(void *)FL_EMBOSSED_BOX},{"ROUND_UP_BOX",0,0,(void *)FL_ROUND_UP_BOX},{"ROUND_DOWN_BOX",0,0,(void *)FL_ROUND_DOWN_BOX},{"DIAMOND_UP_BOX",0,0,(void *)FL_DIAMOND_UP_BOX},{"DIAMOND_DOWN_BOX",0,0,(void *)FL_DIAMOND_DOWN_BOX},{"SHADOW_BOX",0,0,(void *)FL_SHADOW_BOX},{"ROUNDED_BOX",0,0,(void *)FL_ROUNDED_BOX},{"RSHADOW_BOX",0,0,(void *)FL_RSHADOW_BOX},{"RFLAT_BOX",0,0,(void *)FL_RFLAT_BOX},{"OVAL_BOX",0,0,(void *)FL_OVAL_BOX},{"OSHADOW_BOX",0,0,(void *)FL_OSHADOW_BOX},{"OFLAT_BOX",0,0,(void *)FL_OFLAT_BOX},{0},{"frames",0,0,0,FL_SUBMENU},{"UP_FRAME",0,0,(void *)FL_UP_FRAME},{"DOWN_FRAME",0,0,(void *)FL_DOWN_FRAME},{"THIN_UP_FRAME",0,0,(void *)FL_THIN_UP_FRAME},{"THIN_DOWN_FRAME",0,0,(void *)FL_THIN_DOWN_FRAME},{"ENGRAVED_FRAME",0,0,(void *)FL_ENGRAVED_FRAME},{"EMBOSSED_FRAME",0,0,(void *)FL_EMBOSSED_FRAME},{"BORDER_FRAME",0,0,(void *)FL_BORDER_FRAME},{"SHADOW_FRAME",0,0,(void *)FL_SHADOW_FRAME},{"ROUNDED_FRAME",0,0,(void *)FL_ROUNDED_FRAME},{"OVAL_FRAME",0,0,(void *)FL_OVAL_FRAME},{0},{0}};const char *boxname(int i) {  if (!i) i = ZERO_ENTRY;  for (int j = 0; j < int(sizeof(boxmenu)/sizeof(*boxmenu)); j++)    if (boxmenu[j].argument() == i) return boxmenu[j].label();  return 0;}int boxnumber(const char *i) {  if (i[0]=='F' && i[1]=='L' && i[2]=='_') i += 3;  for (int j = 0; j < int(sizeof(boxmenu)/sizeof(*boxmenu)); j++)    if (boxmenu[j].label() && !strcmp(boxmenu[j].label(), i)) {      return int(boxmenu[j].argument());    }  return 0;}void box_cb(Fl_Choice* i, void *v) {  if (v == LOAD) {    if (current_widget->is_menu_item()) {i->hide(); return;} else i->show();    int n = current_widget->o->box(); if (!n) n = ZERO_ENTRY;    for (int j = 0; j < int(sizeof(boxmenu)/sizeof(*boxmenu)); j++)      if (boxmenu[j].argument() == n) {i->value(j); break;}  } else {    int m = i->value();    int n = int(boxmenu[m].argument());    if (!n) return; // should not happen    if (n == ZERO_ENTRY) n = 0;    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->box((Fl_Boxtype)n);        q->redraw();      }  }}void down_box_cb(Fl_Choice* i, void *v) {  if (v == LOAD) {    int n;    if (current_widget->is_button() && !current_widget->is_menu_item())      n = ((Fl_Button*)(current_widget->o))->down_box();    else if (current_widget->is_menu_button())      n = ((Fl_Menu_*)(current_widget->o))->down_box();    else {      i->hide(); return;    }    i->show();    if (!n) n = ZERO_ENTRY;    for (int j = 0; j < int(sizeof(boxmenu)/sizeof(*boxmenu)); j++)      if (boxmenu[j].argument() == n) {i->value(j); break;}  } else {    int m = i->value();    int n = int(boxmenu[m].argument());    if (!n) return; // should not happen    if (n == ZERO_ENTRY) n = 0;    for (Fl_Type *o = Fl_Type::first; o; o = o->next) if (o->selected) {      if (o->is_button() && !o->is_menu_item()) {	Fl_Widget_Type* q = (Fl_Widget_Type*)o;        ((Fl_Button*)(q->o))->down_box((Fl_Boxtype)n);        if (((Fl_Button*)(q->o))->value()) q->redraw();      } else if (o->is_menu_button()) {	Fl_Widget_Type* q = (Fl_Widget_Type*)o;        ((Fl_Menu_*)(q->o))->down_box((Fl_Boxtype)n);      }    }  }}////////////////////////////////////////////////////////////////Fl_Menu_Item whenmenu[] = {  {"never",0,0,(void*)ZERO_ENTRY},  {"Release",0,0,(void*)FL_WHEN_RELEASE},  {"Changed",0,0,(void*)FL_WHEN_CHANGED},  {"Enter key",0,0,(void*)FL_WHEN_ENTER_KEY},  //{"Release or Enter",0,0,(void*)(FL_WHEN_ENTER_KEY|FL_WHEN_RELEASE)},  {0}};static Fl_Menu_Item whensymbolmenu[] = {  {"FL_WHEN_NEVER",0,0,(void*)(FL_WHEN_NEVER)},  {"FL_WHEN_CHANGED",0,0,(void*)(FL_WHEN_CHANGED)},  {"FL_WHEN_RELEASE",0,0,(void*)(FL_WHEN_RELEASE)},  {"FL_WHEN_RELEASE_ALWAYS",0,0,(void*)(FL_WHEN_RELEASE_ALWAYS)},  {"FL_WHEN_ENTER_KEY",0,0,(void*)(FL_WHEN_ENTER_KEY)},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -