/[svn]/gigedit/trunk/src/gigedit/wrapLabel.cc
ViewVC logotype

Annotation of /gigedit/trunk/src/gigedit/wrapLabel.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1799 - (hide annotations) (download)
Sat Dec 6 13:49:26 2008 UTC (15 years, 3 months ago) by persson
File size: 4864 byte(s)
* minor gui fix: made multi line lables expand to use full width

1 persson 1799 /* *************************************************************************
2     * Copyright (c) 2005 VMware, Inc.
3     *
4     * Permission is hereby granted, free of charge, to any person obtaining
5     * a copy of this software and associated documentation files (the
6     * "Software"), to deal in the Software without restriction, including
7     * without limitation the rights to use, copy, modify, merge, publish,
8     * distribute, sublicense, and/or sell copies of the Software, and to
9     * permit persons to whom the Software is furnished to do so, subject to
10     * the following conditions:
11     *
12     * The above copyright notice and this permission notice shall be
13     * included in all copies or substantial portions of the Software.
14     *
15     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16     * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17     * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18     * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19     * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20     * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21     * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22     * *************************************************************************/
23    
24     #include <wrapLabel.hh>
25    
26    
27     /*
28     * wrapLabel.cc --
29     *
30     * A wrappable label widget.
31     */
32    
33    
34     namespace view {
35    
36    
37     /*
38     *-----------------------------------------------------------------------------
39     *
40     * view::WrapLabel::WrapLabel --
41     *
42     * Constructor.
43     *
44     * Results:
45     * None.
46     *
47     * Side effects:
48     * None.
49     *
50     *-----------------------------------------------------------------------------
51     */
52    
53     WrapLabel::WrapLabel(const Glib::ustring &text) // IN: The label text
54     : mWrapWidth(0)
55     {
56     get_layout()->set_wrap(Pango::WRAP_WORD_CHAR);
57     set_alignment(0.0, 0.0);
58     set_text(text);
59     }
60    
61    
62     /*
63     *-----------------------------------------------------------------------------
64     *
65     * view::WrapLabel::set_text --
66     *
67     * Override function for Label::set_text() that re-sets the wrapping
68     * width after the text is set.
69     *
70     * Results:
71     * None.
72     *
73     * Side effects:
74     * None.
75     *
76     *-----------------------------------------------------------------------------
77     */
78    
79     void
80     WrapLabel::set_text(const Glib::ustring &str) // IN: The text to set
81     {
82     Label::set_text(str);
83    
84     SetWrapWidth(mWrapWidth);
85     }
86    
87    
88     /*
89     *-----------------------------------------------------------------------------
90     *
91     * view::WrapLabel::set_markup --
92     *
93     * Override function for Label::set_markup() that re-sets the wrapping
94     * width after the text is set.
95     *
96     * Results:
97     * None.
98     *
99     * Side effects:
100     * None.
101     *
102     *-----------------------------------------------------------------------------
103     */
104    
105     void
106     WrapLabel::set_markup(const Glib::ustring &str) // IN: The text to set
107     {
108     Label::set_markup(str);
109    
110     SetWrapWidth(mWrapWidth);
111     }
112    
113    
114     /*
115     *-----------------------------------------------------------------------------
116     *
117     * view::WrapLabel::on_size_request --
118     *
119     * Override handler for the "size_request" signal. Forces the height
120     * to be the size necessary for the Pango layout, while allowing the
121     * width to be flexible.
122     *
123     * Results:
124     * None.
125     *
126     * Side effects:
127     * None.
128     *
129     *-----------------------------------------------------------------------------
130     */
131    
132     void
133     WrapLabel::on_size_request(Gtk::Requisition *req) // OUT: Our requested size
134     {
135     int width;
136     int height;
137    
138     get_layout()->get_pixel_size(width, height);
139    
140     req->width = 0;
141     req->height = height;
142     }
143    
144    
145     /*
146     *-----------------------------------------------------------------------------
147     *
148     * view::WrapLabel::on_size_allocate --
149     *
150     * Override handler for the "size_allocate" signal. Sets the wrap width
151     * to the be width allocated to us.
152     *
153     * Results:
154     * None.
155     *
156     * Side effects:
157     * None.
158     *
159     *-----------------------------------------------------------------------------
160     */
161    
162     void
163     WrapLabel::on_size_allocate(Gtk::Allocation &alloc) // IN: Our allocation
164     {
165     Gtk::Label::on_size_allocate(alloc);
166    
167     SetWrapWidth(alloc.get_width());
168     }
169    
170    
171     /*
172     *-----------------------------------------------------------------------------
173     *
174     * view::WrapLabel::SetWrapWidth --
175     *
176     * Sets the point at which the text should wrap.
177     *
178     * Results:
179     * None.
180     *
181     * Side effects:
182     * None.
183     *
184     *-----------------------------------------------------------------------------
185     */
186    
187     void
188     WrapLabel::SetWrapWidth(size_t width) // IN: The wrap width
189     {
190     if (width == 0) {
191     return;
192     }
193    
194     /*
195     * We may need to reset the wrap width, so do this regardless of whether
196     * or not we've changed the width.
197     */
198     get_layout()->set_width(width * Pango::SCALE);
199    
200     if (mWrapWidth != width) {
201     mWrapWidth = width;
202     queue_resize();
203     }
204     }
205    
206    
207     }; /* namespace view */

  ViewVC Help
Powered by ViewVC