/[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 3460 - (hide annotations) (download)
Sat Feb 2 07:48:50 2019 UTC (5 years, 2 months ago) by persson
File size: 5657 byte(s)
* Use GDK Seat API if available to grab pointer
* Improve version checks for pangomm
* Fix the instrument list tooltip handling so it doesn't generate GTK
  assertion error messages
* Use English quotation marks in tooltips instead of German
* Use multiple columns in controller value popups, as tall popup menus
  work really badly in some GTK environments

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

  ViewVC Help
Powered by ViewVC