/[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 2169 - (hide annotations) (download)
Sun Mar 6 07:51:04 2011 UTC (13 years, 1 month ago) by persson
File size: 5234 byte(s)
* ported to gtkmm 3, keeping compatibility with gtkmm 2

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 persson 2169 : mWrapWidth(0),
55     mWrapHeight(0)
56 persson 1799 {
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 persson 2169 req->width = 0;
137     req->height = mWrapHeight;
138     }
139 persson 1799
140 persson 2169 // Gigedit addtion: gtk 3 compatibility
141     void WrapLabel::get_preferred_width_vfunc(int& minimum_width, int& natural_width) const
142     {
143     minimum_width = natural_width = 0;
144     }
145 persson 1799
146 persson 2169 // Gigedit addtion: gtk 3 compatibility
147     void WrapLabel::get_preferred_height_vfunc(int& minimum_height, int& natural_height) const
148     {
149     minimum_height = natural_height = mWrapHeight;
150 persson 1799 }
151    
152     /*
153     *-----------------------------------------------------------------------------
154     *
155     * view::WrapLabel::on_size_allocate --
156     *
157     * Override handler for the "size_allocate" signal. Sets the wrap width
158     * to the be width allocated to us.
159     *
160     * Results:
161     * None.
162     *
163     * Side effects:
164     * None.
165     *
166     *-----------------------------------------------------------------------------
167     */
168    
169     void
170     WrapLabel::on_size_allocate(Gtk::Allocation &alloc) // IN: Our allocation
171     {
172     Gtk::Label::on_size_allocate(alloc);
173    
174     SetWrapWidth(alloc.get_width());
175     }
176    
177    
178     /*
179     *-----------------------------------------------------------------------------
180     *
181     * view::WrapLabel::SetWrapWidth --
182     *
183     * Sets the point at which the text should wrap.
184     *
185     * Results:
186     * None.
187     *
188     * Side effects:
189     * None.
190     *
191     *-----------------------------------------------------------------------------
192     */
193    
194     void
195 persson 2169 WrapLabel::SetWrapWidth(int width) // IN: The wrap width
196 persson 1799 {
197     if (width == 0) {
198     return;
199     }
200    
201     /*
202     * We may need to reset the wrap width, so do this regardless of whether
203     * or not we've changed the width.
204     */
205     get_layout()->set_width(width * Pango::SCALE);
206    
207 persson 2169 int unused;
208     get_layout()->get_pixel_size(unused, mWrapHeight);
209    
210 persson 1799 if (mWrapWidth != width) {
211     mWrapWidth = width;
212     queue_resize();
213     }
214     }
215    
216    
217     }; /* namespace view */

  ViewVC Help
Powered by ViewVC