[go: up one dir, main page]

File: tooltip.c

package info (click to toggle)
libforms 1.2.3-1.7
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,904 kB
  • sloc: ansic: 97,669; sh: 11,156; makefile: 951
file content (208 lines) | stat: -rw-r--r-- 4,866 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 *  This file is part of the XForms library package.
 *
 *  XForms is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation; either version 2.1, or
 *  (at your option) any later version.
 *
 *  XForms 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with XForms.  If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * \file tooltip.c
 *
 *  This file is part of the XForms library package.
 *  Copyright (c) 1998-2002  T.C. Zhao
 *  All rights reserved.
 *
 * Show message in a top-level unmanaged window. Used
 * for tooltips
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "include/forms.h"
#include "flinternal.h"


typedef struct {
     FL_FORM   * tooltipper;
     void      * vdata;
     char      * cdata;
     long        ldate;
     FL_OBJECT * text;
     int         fntstyle;
     int         fntsize;
     FL_COLOR    background;
     FL_COLOR    textcolor;
     int         boxtype;
     int         lalign;
} TOOLTIP;

static TOOLTIP *tip;


/***************************************
 ***************************************/

static void
create_it( void )
{
    FL_OBJECT *text;

    if ( tip )
        return;

    tip              = fl_calloc( 1, sizeof *tip );
    tip->fntstyle    = FL_NORMAL_STYLE;
    tip->fntsize     = FL_DEFAULT_SIZE;
    tip->boxtype     = FL_BORDER_BOX;
    tip->lalign      = fl_to_inside_lalign( FL_ALIGN_LEFT );
    tip->textcolor   = FL_BLACK;
    tip->background  = FL_YELLOW;

    tip->tooltipper  = fl_bgn_form( FL_NO_BOX, 5, 5 );

    tip->text = text = fl_add_box( tip->boxtype, 0, 0, 5, 5, "" );
    fl_set_object_bw( text, -1 );
    fl_set_object_lstyle( text, tip->fntstyle );
    fl_set_object_lsize( text, tip->fntsize );
    fl_set_object_lcolor( text, tip->textcolor );
    fl_set_object_lalign( text, tip->lalign );
    fl_set_object_color( text, tip->background, tip->background );

    fl_end_form( );
}


/***************************************
 ***************************************/

void
fl_set_tooltip_boxtype( int bt )
{
    create_it( );
    tip->boxtype = bt;
    fl_set_object_boxtype( tip->text, bt );
}


/***************************************
 ***************************************/

void
fli_show_tooltip( const char * s,
                  int          x,
                  int          y )
{
    int maxw = 0,
        maxh = 0,
        extra;

    if ( ! s )
        return;

    create_it( );

    extra =
           1 + ( tip->boxtype != FL_FLAT_BOX && tip->boxtype != FL_BORDER_BOX );
    fl_get_string_dimension( tip->fntstyle, tip->fntsize,
                             s, strlen( s ), &maxw, &maxh );

    maxw += 7 + extra;
    maxh += 7 + extra;

    if ( maxw > 800 )
        maxw = 800;
    if ( maxh > 800 )
        maxh = 800;

    fl_freeze_form( tip->tooltipper );
    fl_set_form_geometry( tip->tooltipper, x, y, maxw, maxh );
    fl_set_object_label( tip->text, s );
    fl_unfreeze_form( tip->tooltipper );

    if ( ! tip->tooltipper->visible )
        fl_show_form( tip->tooltipper, FL_PLACE_GEOMETRY | FL_FREE_SIZE,
                      FL_NOBORDER, "Tooltip" );

    fl_update_display( 1 );
}


/***************************************
 ***************************************/

void
fli_hide_tooltip( void )
{
    if ( tip && tip->tooltipper->visible )
        fl_hide_form( tip->tooltipper );
}


/***************************************
 ***************************************/

int
fli_is_tooltip_form( FL_FORM * form )
{
    return tip && tip->tooltipper == form;
}


/***************************************
 ***************************************/

void
fl_set_tooltip_color( FL_COLOR tc,
                      FL_COLOR bc )
{
    create_it( );
    fl_set_object_lcolor( tip->text, tip->textcolor = tc );
    tip->background = bc;
    fl_set_object_color( tip->text, tip->background, tip->background );
}


/***************************************
 ***************************************/

void
fl_set_tooltip_font( int style,
                     int size )
{
    create_it( );
    fl_set_object_lstyle( tip->text, tip->fntstyle = style );
    fl_set_object_lsize( tip->text, tip->fntsize = size );
}


/***************************************
 ***************************************/

void
fl_set_tooltip_lalign( int align )
{
    create_it( );
    fl_set_object_lalign( tip->text,
                          tip->lalign = fl_to_inside_lalign( align ) );
}


/*
 * Local variables:
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */