blob: df117db30f63cb0c89676f450c3371c8b64bc12c [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_Multi_Label.cxx 7903 2010-11-28 21:06:39Z matt $"
3//
4// Multi-label widget for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28// Allows two labels to be used on a widget (by having one of them
29// be one of these it allows an infinte number!)
30
31#include <FL/Fl.H>
32#include <FL/Fl_Widget.H>
33#include <FL/Fl_Menu_Item.H>
34#include <FL/Fl_Multi_Label.H>
35
36static void multi_labeltype(
37 const Fl_Label* o, int x, int y, int w, int h, Fl_Align a)
38{
39 Fl_Multi_Label* b = (Fl_Multi_Label*)(o->value);
40 Fl_Label local = *o;
41 local.value = b->labela;
42 local.type = b->typea;
43 int W = w; int H = h; local.measure(W, H);
44 local.draw(x,y,w,h,a);
45 if (a & FL_ALIGN_BOTTOM) h -= H;
46 else if (a & FL_ALIGN_TOP) {y += H; h -= H;}
47 else if (a & FL_ALIGN_RIGHT) w -= W;
48 else if (a & FL_ALIGN_LEFT) {x += W; w -= W;}
49 else {int d = (h+H)/2; y += d; h -= d;}
50 local.value = b->labelb;
51 local.type = b->typeb;
52 local.draw(x,y,w,h,a);
53}
54
55// measurement is only correct for left-to-right appending...
56static void multi_measure(const Fl_Label* o, int& w, int& h) {
57 Fl_Multi_Label* b = (Fl_Multi_Label*)(o->value);
58 Fl_Label local = *o;
59 local.value = b->labela;
60 local.type = b->typea;
61 local.measure(w,h);
62 local.value = b->labelb;
63 local.type = b->typeb;
64 int W = 0; int H = 0; local.measure(W,H);
65 w += W; if (H>h) h = H;
66}
67
68void Fl_Multi_Label::label(Fl_Widget* o) {
69 Fl::set_labeltype(_FL_MULTI_LABEL, multi_labeltype, multi_measure);
70 o->label(_FL_MULTI_LABEL, (const char*)this);
71}
72
73void Fl_Multi_Label::label(Fl_Menu_Item* o) {
74 Fl::set_labeltype(_FL_MULTI_LABEL, multi_labeltype, multi_measure);
75 o->label(_FL_MULTI_LABEL, (const char*)this);
76}
77
78//
79// End of "$Id: Fl_Multi_Label.cxx 7903 2010-11-28 21:06:39Z matt $".
80//