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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2344 - (show annotations) (download)
Sun Apr 29 16:15:45 2012 UTC (11 years, 11 months ago) by persson
File size: 4878 byte(s)
* gtkmm 3 fix: the WrapLabel custom widget is not needed in gtkmm 3

1 /* *************************************************************************
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 mWrapHeight(0)
56 {
57 get_layout()->set_wrap(Pango::WRAP_WORD_CHAR);
58 set_alignment(0.0, 0.0);
59 set_text(text);
60 }
61
62
63 /*
64 *-----------------------------------------------------------------------------
65 *
66 * view::WrapLabel::set_text --
67 *
68 * Override function for Label::set_text() that re-sets the wrapping
69 * width after the text is set.
70 *
71 * Results:
72 * None.
73 *
74 * Side effects:
75 * None.
76 *
77 *-----------------------------------------------------------------------------
78 */
79
80 void
81 WrapLabel::set_text(const Glib::ustring &str) // IN: The text to set
82 {
83 Label::set_text(str);
84
85 SetWrapWidth(mWrapWidth);
86 }
87
88
89 /*
90 *-----------------------------------------------------------------------------
91 *
92 * view::WrapLabel::set_markup --
93 *
94 * Override function for Label::set_markup() that re-sets the wrapping
95 * width after the text is set.
96 *
97 * Results:
98 * None.
99 *
100 * Side effects:
101 * None.
102 *
103 *-----------------------------------------------------------------------------
104 */
105
106 void
107 WrapLabel::set_markup(const Glib::ustring &str) // IN: The text to set
108 {
109 Label::set_markup(str);
110
111 SetWrapWidth(mWrapWidth);
112 }
113
114
115 /*
116 *-----------------------------------------------------------------------------
117 *
118 * view::WrapLabel::on_size_request --
119 *
120 * Override handler for the "size_request" signal. Forces the height
121 * to be the size necessary for the Pango layout, while allowing the
122 * width to be flexible.
123 *
124 * Results:
125 * None.
126 *
127 * Side effects:
128 * None.
129 *
130 *-----------------------------------------------------------------------------
131 */
132
133 void
134 WrapLabel::on_size_request(Gtk::Requisition *req) // OUT: Our requested size
135 {
136 req->width = 0;
137 req->height = mWrapHeight;
138 }
139
140
141 /*
142 *-----------------------------------------------------------------------------
143 *
144 * view::WrapLabel::on_size_allocate --
145 *
146 * Override handler for the "size_allocate" signal. Sets the wrap width
147 * to the be width allocated to us.
148 *
149 * Results:
150 * None.
151 *
152 * Side effects:
153 * None.
154 *
155 *-----------------------------------------------------------------------------
156 */
157
158 void
159 WrapLabel::on_size_allocate(Gtk::Allocation &alloc) // IN: Our allocation
160 {
161 Gtk::Label::on_size_allocate(alloc);
162
163 SetWrapWidth(alloc.get_width());
164 }
165
166
167 /*
168 *-----------------------------------------------------------------------------
169 *
170 * view::WrapLabel::SetWrapWidth --
171 *
172 * Sets the point at which the text should wrap.
173 *
174 * Results:
175 * None.
176 *
177 * Side effects:
178 * None.
179 *
180 *-----------------------------------------------------------------------------
181 */
182
183 void
184 WrapLabel::SetWrapWidth(int width) // IN: The wrap width
185 {
186 if (width == 0) {
187 return;
188 }
189
190 /*
191 * We may need to reset the wrap width, so do this regardless of whether
192 * or not we've changed the width.
193 */
194 get_layout()->set_width(width * Pango::SCALE);
195
196 int unused;
197 get_layout()->get_pixel_size(unused, mWrapHeight);
198
199 if (mWrapWidth != width) {
200 mWrapWidth = width;
201 queue_resize();
202 }
203 }
204
205
206 }; /* namespace view */

  ViewVC Help
Powered by ViewVC