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

📄 fl_type.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 2 页
字号:
//// "$Id: Fl_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).//// Each object described by Fluid is one of these objects.  They// are all stored in a double-linked list.//// They "type" of the object is covered by the virtual functions.// There will probably be a lot of these virtual functions.//// The type browser is also a list of these objects, but they// are "factory" instances, not "real" ones.  These objects exist// only so the "make" method can be called on them.  They are// not in the linked list and are not written to files or// copied or otherwise examined.//// 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_Browser_.H>#include <FL/fl_draw.H>#include <ctype.h>#include <stdlib.h>#include <string.h>#include <stdio.h>#include "Fl_Type.h"////////////////////////////////////////////////////////////////class Widget_Browser : public Fl_Browser_ {  friend class Fl_Type;  // required routines for Fl_Browser_ subclass:  void *item_first() const ;  void *item_next(void *) const ;  void *item_prev(void *) const ;  int item_selected(void *) const ;  void item_select(void *,int);  int item_width(void *) const ;  int item_height(void *) const ;  void item_draw(void *,int,int,int,int) const ;  int incr_height() const ;public:	  int handle(int);  void callback();  Widget_Browser(int,int,int,int,const char * =0);};static Widget_Browser *widget_browser;Fl_Widget *make_widget_browser(int x,int y,int w,int h) {  return (widget_browser = new Widget_Browser(x,y,w,h));}void select(Fl_Type *o, int v) {  widget_browser->select(o,v,1);  //  Fl_Type::current = o;}void select_only(Fl_Type *o) {  widget_browser->select_only(o,1);}void deselect() {  widget_browser->deselect();  //Fl_Type::current = 0; // this breaks the paste & merge functions}Fl_Type *Fl_Type::first;Fl_Type *Fl_Type::last;static void Widget_Browser_callback(Fl_Widget *o,void *) {  ((Widget_Browser *)o)->callback();}Widget_Browser::Widget_Browser(int x,int y,int w,int h,const char*l): Fl_Browser_(x,y,w,h,l) {  type(FL_MULTI_BROWSER);  Fl_Widget::callback(Widget_Browser_callback);  when(FL_WHEN_RELEASE);}void *Widget_Browser::item_first() const {return Fl_Type::first;}void *Widget_Browser::item_next(void *l) const {return ((Fl_Type*)l)->next;}void *Widget_Browser::item_prev(void *l) const {return ((Fl_Type*)l)->prev;}int Widget_Browser::item_selected(void *l) const {return ((Fl_Type*)l)->new_selected;}void Widget_Browser::item_select(void *l,int v) {((Fl_Type*)l)->new_selected = v;}int Widget_Browser::item_height(void *l) const {  return ((Fl_Type *)l)->visible ? textsize()+2 : 0;}int Widget_Browser::incr_height() const {return textsize()+2;}static Fl_Type* pushedtitle;// Generate a descriptive text for this item, to put in browser & window titlesconst char* Fl_Type::title() {  const char* c = name(); if (c) return c;  return type_name();}extern const char* subclassname(Fl_Type*);void Widget_Browser::item_draw(void *v, int x, int y, int, int) const {  Fl_Type *l = (Fl_Type *)v;  x += 3 + l->level * 10;  fl_color(FL_BLACK);  if (l->is_parent()) {    if (!l->next || l->next->level <= l->level) {      if (l->open_!=(l==pushedtitle)) {	fl_loop(x,y+7,x+5,y+12,x+10,y+7);      } else {	fl_loop(x+2,y+2,x+7,y+7,x+2,y+12);      }    } else {      if (l->open_!=(l==pushedtitle)) {	fl_polygon(x,y+7,x+5,y+12,x+10,y+7);      } else {	fl_polygon(x+2,y+2,x+7,y+7,x+2,y+12);      }    }    x += 10;  }  if (l->is_widget() || l->is_class()) {    const char* c = subclassname(l);    if (!strncmp(c,"Fl_",3)) c += 3;    fl_font(textfont(), textsize());    fl_draw(c, x, y+13);    x += int(fl_width(c)+fl_width('n'));    c = l->name();    if (c) {      fl_font(textfont()|FL_BOLD, textsize());      fl_draw(c, x, y+13);    } else if ((c=l->label())) {      char buf[50]; char* p = buf;      *p++ = '"';      for (int i = 20; i--;) {	if (! (*c & -32)) break;	*p++ = *c++;      }      if (*c) {strcpy(p,"..."); p+=3;}      *p++ = '"';      *p = 0;      fl_draw(buf, x, y+13);    }  } else {    const char* c = l->title();    char buf[60]; char* p = buf;    for (int i = 55; i--;) {      if (! (*c & -32)) break;      *p++ = *c++;    }    if (*c) {strcpy(p,"..."); p+=3;}    *p = 0;    fl_font(textfont() | (l->is_code_block() && (l->level==0 || l->parent->is_class())?0:FL_BOLD), textsize());    fl_draw(buf, x, y+13);  }}int Widget_Browser::item_width(void *v) const {  Fl_Type *l = (Fl_Type *)v;  if (!l->visible) return 0;  int w = 3 + l->level*10;  if (l->is_parent()) w += 10;  if (l->is_widget() || l->is_class()) {    const char* c = l->type_name();    if (!strncmp(c,"Fl_",3)) c += 3;    fl_font(textfont(), textsize());    w += int(fl_width(c) + fl_width('n'));    c = l->name();    if (c) {      fl_font(textfont()|FL_BOLD, textsize());      w += int(fl_width(c));    } else if ((c=l->label())) {      char buf[50]; char* p = buf;      *p++ = '"';      for (int i = 20; i--;) {	if (! (*c & -32)) break;	*p++ = *c++;      }      if (*c) {strcpy(p,"..."); p+=3;}      *p++ = '"';      *p = 0;      w += int(fl_width(buf));    }  } else {    const char* c = l->title();    char buf[60]; char* p = buf;    for (int i = 55; i--;) {      if (! (*c & -32)) break;      *p++ = *c++;    }    if (*c) {strcpy(p,"..."); p+=3;}    *p = 0;    fl_font(textfont() | (l->is_code_block() && (l->level==0 || l->parent->is_class())?0:FL_BOLD), textsize());    w += int(fl_width(buf));  }  return w;}void redraw_browser() {  widget_browser->redraw();}void Widget_Browser::callback() {  selection_changed((Fl_Type*)selection());}int Widget_Browser::handle(int e) {  static Fl_Type *title;  Fl_Type *l;  int X,Y,W,H; bbox(X,Y,W,H);  switch (e) {  case FL_PUSH:    if (!Fl::event_inside(X,Y,W,H)) break;    l = (Fl_Type*)find_item(Fl::event_y());    if (l) {      X += 10*l->level;      if (l->is_parent() && Fl::event_x()>X && Fl::event_x()<X+13) {	title = pushedtitle = l;	redraw_line(l);	return 1;      }    }    break;  case FL_DRAG:    if (!title) break;    l = (Fl_Type*)find_item(Fl::event_y());    if (l) {      X += 10*l->level;      if (l->is_parent() && Fl::event_x()>X && Fl::event_x()<X+13) ;      else l = 0;    }    if (l != pushedtitle) {      if (pushedtitle) redraw_line(pushedtitle);      if (l) redraw_line(l);      pushedtitle = l;    }    return 1;  case FL_RELEASE:    if (!title) {      l = (Fl_Type*)find_item(Fl::event_y());      if (l && l->new_selected && (Fl::event_clicks() || Fl::event_state(FL_CTRL)))	l->open();      break;    }    l = pushedtitle;    title = pushedtitle = 0;    if (l) {      if (l->open_) {	l->open_ = 0;	for (Fl_Type*k = l->next; k&&k->level>l->level; k = k->next)	  k->visible = 0;      } else {	l->open_ = 1;	for (Fl_Type*k=l->next; k&&k->level>l->level;) {	  k->visible = 1;	  if (k->is_parent() && !k->open_) {	    Fl_Type *j;	    for (j = k->next; j && j->level>k->level; j = j->next);	    k = j;	  } else	    k = k->next;	}      }      redraw();    }    return 1;  }  return Fl_Browser_::handle(e);}Fl_Type::Fl_Type() {  factory = 0;  parent = 0;  next = prev = 0;  selected = new_selected = 0;  visible = 0;  name_ = 0;  label_ = 0;  user_data_ = 0;  user_data_type_ = 0;  callback_ = 0;  rtti = 0;  level = 0;}static void fixvisible(Fl_Type *p) {  Fl_Type *t = p;  for (;;) {    if (t->parent) t->visible = t->parent->visible && t->parent->open_;    else t->visible = 1;    t = t->next;    if (!t || t->level <= p->level) break;  }}

⌨️ 快捷键说明

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