fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Multi_Label.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: Fl_Multi_Label.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Multi-label widget for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 // Allows two labels to be used on a widget (by having one of them
00029 // be one of these it allows an infinte number!)
00030 
00031 #include <FL/Fl.H>
00032 #include <FL/Fl_Widget.H>
00033 #include <FL/Fl_Menu_Item.H>
00034 #include <FL/Fl_Multi_Label.H>
00035 
00036 static void multi_labeltype(
00037     const Fl_Label* o, int x, int y, int w, int h, Fl_Align a)
00038 {
00039   Fl_Multi_Label* b = (Fl_Multi_Label*)(o->value);
00040   Fl_Label local = *o;
00041   local.value = b->labela;
00042   local.type = b->typea;
00043   int W = w; int H = h; local.measure(W, H);
00044   local.draw(x,y,w,h,a);
00045   if (a & FL_ALIGN_BOTTOM) h -= H;
00046   else if (a & FL_ALIGN_TOP) {y += H; h -= H;}
00047   else if (a & FL_ALIGN_RIGHT) w -= W;
00048   else if (a & FL_ALIGN_LEFT) {x += W; w -= W;}
00049   else {int d = (h+H)/2; y += d; h -= d;}
00050   local.value = b->labelb;
00051   local.type = b->typeb;
00052   local.draw(x,y,w,h,a);
00053 }
00054 
00055 // measurement is only correct for left-to-right appending...
00056 static void multi_measure(const Fl_Label* o, int& w, int& h) {
00057   Fl_Multi_Label* b = (Fl_Multi_Label*)(o->value);
00058   Fl_Label local = *o;
00059   local.value = b->labela;
00060   local.type = b->typea;
00061   local.measure(w,h);
00062   local.value = b->labelb;
00063   local.type = b->typeb;
00064   int W = 0; int H = 0; local.measure(W,H);
00065   w += W; if (H>h) h = H;
00066 }
00067 
00068 void Fl_Multi_Label::label(Fl_Widget* o) {
00069   Fl::set_labeltype(_FL_MULTI_LABEL, multi_labeltype, multi_measure);
00070   o->label(_FL_MULTI_LABEL, (const char*)this);
00071 }
00072 
00073 void Fl_Multi_Label::label(Fl_Menu_Item* o) {
00074   Fl::set_labeltype(_FL_MULTI_LABEL, multi_labeltype, multi_measure);
00075   o->label(_FL_MULTI_LABEL, (const char*)this);
00076 }
00077 
00078 //
00079 // End of "$Id: Fl_Multi_Label.cxx 7903 2010-11-28 21:06:39Z matt $".
00080 //