📄 gtkwindow.html
字号:
<a name="gtk-window-set-policy"></a>gtk_window_set_policy ()</h3><a class="indexterm" name="id3379632"></a><pre class="programlisting">void gtk_window_set_policy (<a class="link" href="GtkWindow.html" title="GtkWindow">GtkWindow</a> *window, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> allow_shrink, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> allow_grow, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> auto_shrink);</pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p><code class="literal">gtk_window_set_policy</code> is deprecated and should not be used in newly-written code. Use <a class="link" href="GtkWindow.html#gtk-window-set-resizable"><code class="function">gtk_window_set_resizable()</code></a> instead.</p></div><p>Changes how a toplevel window deals with its size request and user resizeattempts. There are really only two reasonable ways to call this function:</p><div class="orderedlist"><ol type="1"><li><p><code class="literal">gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE)</code> means that the window is user-resizable.</p></li><li><p><code class="literal">gtk_window_set_policy (GTK_WINDOW (window), FALSE, FALSE, TRUE)</code> means that the window's size is program-controlled, and should simply match the current size request of the window's children.</p></li></ol></div><p>The first policy is the default, that is, by default windows are designed to be resized by users.</p><p>The basic ugly truth of this function is that it should be simply:<code class="literal"> void gtk_window_set_resizable (GtkWindow* window, gboolean setting);</code>...which is why GTK+ 2.0 introduces <a class="link" href="GtkWindow.html#gtk-window-set-resizable"><code class="function">gtk_window_set_resizable()</code></a>, which you should use instead of <a class="link" href="GtkWindow.html#gtk-window-set-policy"><code class="function">gtk_window_set_policy()</code></a>.</p><p>If set to <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the <em class="parameter"><code>allow_grow</code></em> parameter allows the user to expand the windowbeyond the size request of its child widgets. If <em class="parameter"><code>allow_grow</code></em> is <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, be sure tocheck that your child widgets work properly as the window is resized.</p><p>A toplevel window will always change size to ensure its child widgets receivetheir requested size. This means that if you add child widgets, the toplevelwindow will expand to contain them. However, normally the toplevel will notshrink to fit the size request of its children if it's too large; the<em class="parameter"><code>auto_shrink</code></em> parameter causes the window to shrink when child widgets have toomuch space. <em class="parameter"><code>auto_shrink</code></em> is normally used with the second of the two windowpolicies mentioned above. That is, set <em class="parameter"><code>auto_shrink</code></em> to <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if you want thewindow to have a fixed, always-optimal size determined by your program.</p><p>Note that <em class="parameter"><code>auto_shrink</code></em> doesn't do anything if <em class="parameter"><code>allow_shrink</code></em> and <em class="parameter"><code>allow_grow</code></em> areboth set to <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>.</p><p>Neither of the two suggested window policies set the <em class="parameter"><code>allow_shrink</code></em> parameter to<ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>. If <em class="parameter"><code>allow_shrink</code></em> is <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the user can shrink the window so that itschildren do not receive their full size request; this is basically a bad thing,because most widgets will look wrong if this happens. Furthermore GTK+ has atendency to re-expand the window if size is recalculated for any reason. Theupshot is that <em class="parameter"><code>allow_shrink</code></em> should always be set to <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>.</p><p>Sometimes when you think you want to use <em class="parameter"><code>allow_shrink</code></em>, the real problem is thatsome specific child widget is requesting too much space, so the user can'tshrink the window sufficiently. Perhaps you are calling <a class="link" href="GtkWidget.html#gtk-widget-set-size-request"><code class="function">gtk_widget_set_size_request()</code></a>on a child widget, and forcing its size request to be too large. Instead ofsetting the child's usize, consider using <a class="link" href="GtkWindow.html#gtk-window-set-default-size"><code class="function">gtk_window_set_default_size()</code></a> so thatthe child gets a larger allocation than it requests.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>window</code></em> :</span></p></td><td>the window</td></tr><tr><td><p><span class="term"><em class="parameter"><code>allow_shrink</code></em> :</span></p></td><td>whether the user can shrink the window below its size request</td></tr><tr><td><p><span class="term"><em class="parameter"><code>allow_grow</code></em> :</span></p></td><td>whether the user can grow the window larger than its size request</td></tr><tr><td><p><span class="term"><em class="parameter"><code>auto_shrink</code></em> :</span></p></td><td>whether the window automatically snaps back to its size request if it's larger</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3380055"></a><h3><a name="gtk-window-set-resizable"></a>gtk_window_set_resizable ()</h3><a class="indexterm" name="id3380068"></a><pre class="programlisting">void gtk_window_set_resizable (<a class="link" href="GtkWindow.html" title="GtkWindow">GtkWindow</a> *window, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> resizable);</pre><p>Sets whether the user can resize a window. Windows are user resizableby default.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>window</code></em> :</span></p></td><td> a <a class="link" href="GtkWindow.html" title="GtkWindow"><span class="type">GtkWindow</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>resizable</code></em> :</span></p></td><td> <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the user can resize this window</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3380159"></a><h3><a name="gtk-window-get-resizable"></a>gtk_window_get_resizable ()</h3><a class="indexterm" name="id3380172"></a><pre class="programlisting"><ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> gtk_window_get_resizable (<a class="link" href="GtkWindow.html" title="GtkWindow">GtkWindow</a> *window);</pre><p>Gets the value set by <a class="link" href="GtkWindow.html#gtk-window-set-resizable"><code class="function">gtk_window_set_resizable()</code></a>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>window</code></em> :</span></p></td><td> a <a class="link" href="GtkWindow.html" title="GtkWindow"><span class="type">GtkWindow</span></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the user can resize the window</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3380261"></a><h3><a name="gtk-window-add-accel-group"></a>gtk_window_add_accel_group ()</h3><a class="indexterm" name="id3380275"></a><pre class="programlisting">void gtk_window_add_accel_group (<a class="link" href="GtkWindow.html" title="GtkWindow">GtkWindow</a> *window, <a class="link" href="gtk-Keyboard-Accelerators.html#GtkAccelGroup">GtkAccelGroup</a> *accel_group);</pre><p>Associate <em class="parameter"><code>accel_group</code></em> with <em class="parameter"><code>window</code></em>, such that calling<a class="link" href="gtk-Keyboard-Accelerators.html#gtk-accel-groups-ac
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -