1 // $Id: Flu_Label.cpp,v 1.6 2004/10/21 15:21:07 jbryan Exp $
2
3 /***************************************************************
4 * FLU - FLTK Utility Widgets
5 * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
6 *
7 * This file and its content is protected by a software license.
8 * You should have received a copy of this license with this file.
9 * If not, please contact the Ohio Supercomputer Center immediately:
10 * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
11 *
12 ***************************************************************/
13
14
15
16 #include <FL/fl_draw.H>
17 #include "Flu_Label.h"
18
Flu_Label(int x,int y,int w,int h,const char * l)19 Flu_Label :: Flu_Label( int x, int y, int w, int h, const char* l )
20 : Fl_Box( x, y, w, h, 0 )
21 {
22 _autoSize = false;
23 align( FL_ALIGN_LEFT | FL_ALIGN_WRAP | FL_ALIGN_INSIDE );
24 _label = NULL;
25 label( l );
26 box( FL_NO_BOX );
27 clear_visible_focus();
28 }
29
~Flu_Label()30 Flu_Label :: ~Flu_Label()
31 {
32 if( _label )
33 delete[] _label;
34 }
35
draw()36 void Flu_Label :: draw()
37 {
38 if( _autoSize )
39 {
40 fl_font( labelfont(), labelsize() );
41 int W = 0, H = 0;
42 fl_measure( label(), W, H );
43 if( W != w() || H != h() )
44 resize( x(), y(), W, H );
45 }
46 Fl_Box::draw();
47 }
48
label(const char * l)49 void Flu_Label :: label( const char* l )
50 {
51 if( _label )
52 delete[] _label;
53 if( l == NULL )
54 {
55 _label = new char[1];
56 _label[0] = '\0';
57 }
58 else
59 {
60 _label = new char[strlen(l)+1];
61 strcpy( _label, l );
62 }
63 Fl_Box::label( _label );
64 redraw();
65 }
66