?? sec-gdkcursor.html
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title> The Mouse Pointer </title> <meta name="GENERATOR" content= "Modular DocBook HTML Stylesheet Version 1.45"> <link rel="HOME" title="GTK+ / Gnome Application Development" href="ggad.html"> <link rel="UP" title="GDK Basics" href="cha-gdk.html"> <link rel="PREVIOUS" title="Events" href="sec-gdkevent.html"> <link rel="NEXT" title="Fonts" href="sec-gdkfont.html"> </head> <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink= "#840084" alink="#0000FF"> <div class="NAVHEADER"> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <th colspan="4" align="center"> <font color="#000000" size="2">GTK+ / Gnome Application Development</font> </th> </tr> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="sec-gdkevent.html"><font color="#0000ff" size= "2"><b><<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="sec-gdkfont.html"><font color="#0000ff" size= "2"><b>Next >>></b></font></a> </td> </tr> </table> </div> <div class="SECT1"> <h1 class="SECT1"> <a name="SEC-GDKCURSOR">The Mouse Pointer</a> </h1> <p> The mouse pointer is represented on the screen by a small bitmap called the <i class="FIRSTTERM">cursor</i>. The cursor is normally an arrow shape, but it can be changed on a window-by-window basis. As the pointer moves, it generates motion events and moves the cursor on the screen to give the user feedback. </p> <div class="SECT2"> <h2 class="SECT2"> <a name="Z129">Pointer Location</a> </h2> <p> You can query the pointer's location with <tt class= "FUNCTION">gdk_window_get_pointer()</tt> (<a href= "sec-gdkcursor.html#FL-GETPOINTER">Figure 7</a>). This function requests the X and Y coordinates of the pointer relative to the window passed as its first argument. It also requests the currently active modifiers (including modifier keys and buttons; this field is identical to the <span class="STRUCTNAME">state</span> field in several events, such as button events). If <span class= "STRUCTNAME">NULL</span> is passed for the <span class= "STRUCTNAME">x</span>, <span class="STRUCTNAME">y</span>, or <span class="STRUCTNAME">state</span> arguments, that argument will be ignored. </p> <div class="FIGURE"> <a name="FL-GETPOINTER"></a> <div class="FUNCSYNOPSIS"> <a name="FL-GETPOINTER.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gdk/gdk.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">GdkWindow* <tt class= "FUNCTION"> gdk_window_get_pointer</tt></code>(GdkWindow* <tt class="PARAMETER"><i>window</i></tt>, gint* <tt class="PARAMETER"><i>x</i></tt>, gint* <tt class= "PARAMETER"><i>y</i></tt>, GdkModifierMask* <tt class="PARAMETER"><i>state</i></tt>);</code> </p> </div> <p> <b>Figure 7. Querying Pointer Location</b> </p> </div> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="SEC-POINTERGRAB">Grabbing the Pointer</a> </h2> <p> It is possible to <i class="FIRSTTERM">grab</i> the pointer, which means that all pointer events will go to the <i class="FIRSTTERM">grab window</i> for the duration of the grab. Normally pointer events go to the window the pointer is inside. You should grab the pointer, for example, if the user is using click-and-drag selection to select a rectangular area. If they click and then inadvertently drag the pointer outside the window, you should continue to track the pointer's location and change the selection accordingly. The grab also ensures that pointer events won't be sent to other applications. </p> <p> To grab the pointer, call <tt class="FUNCTION"> gdk_pointer_grab()</tt>, shown in <a href= "sec-gdkcursor.html#FL-GRABBING">Figure 8</a>. The first argument to this function is the grab window; this window will receive events during the grab. The next argument should be <span class="STRUCTNAME">TRUE</span> or <span class="STRUCTNAME">FALSE</span>; it specifies whether events will go only to the grab window, or to its child windows as well. The <span class="STRUCTNAME"> confine_to</span> argument specifies a window to confine the pointer to. The user will not be able to move the pointer outside this window. You can specify a different <span class="STRUCTNAME">cursor</span> for the duration of the grab; see the next section for details on creating a cursor. If you don't want to change the cursor, give <span class="STRUCTNAME">NULL</span> as the <span class= "STRUCTNAME">cursor</span> argument. (Side note: it is safe to destroy the cursor immediately after calling <tt class="FUNCTION">gdk_pointer_grab()</tt> because it is a server-side resource and X will not deallocate it until the grab is over.) </p> <p> The final argument, <span class="STRUCTNAME">time</span>, specifies when the grab should take effect, in server time. This is intended to resolve conflicts if two clients try to grab the pointer simultaneously; the time must be after the last grab time, and it must not be in the future. Usually, you will want to use the <span class="STRUCTNAME">time</span> field from the event you're processing, or the <tt class="FUNCTION"> GDK_CURRENT_TIME</tt> macro. <tt class="FUNCTION"> GDK_CURRENT_TIME</tt> is a magic constant that tells the X server to substitute the current time. </p> <p> <tt class="FUNCTION">gdk_pointer_grab()</tt> returns <span class="STRUCTNAME">TRUE</span> if it succeeds. It is possible for it to fail if the grab window or <span class="STRUCTNAME">confine_to</span> window is hidden, another client has the grab already, or any of the arguments are invalid. Regrettably few applications check this return value, which is a bug (granted, a difficult-to-trigger one). </p> <p> To ungrab the pointer, call <tt class="FUNCTION"> gdk_pointer_ungrab()</tt>; the <span class="STRUCTNAME"> time</span> argument is identical to the one in <tt class="FUNCTION">gdk_pointer_grab()</tt>. You can find out if the pointer is grabbed using <tt class="FUNCTION"> gdk_pointer_is_grabbed()</tt>. You <i class="EMPHASIS"> must</i> ungrab the pointer when you're finished with it, because the user will be unable to use other applications while the pointer is grabbed. </p> <p> Note that the GDK-level concept of grabbing the pointer is distinct from the GTK+-level grab concept. A GTK+ grab redirects certain events to a grabbing <i class= "EMPHASIS">widget</i>, creating a "modal" widget such as a dialog (see <a href="z57.html#SEC-GRABS">the section called <i>Grabs</i> in the chapter called <i>GTK+ Basics</i></a>). GTK+'s grab only affects the current application; only events that occur on one of the current application's widgets are redirected. The scope of a GDK grab is wider, encompassing the entire X server, not just your application. </p> <div class="FIGURE"> <a name="FL-GRABBING"></a> <div class="FUNCSYNOPSIS"> <a name="FL-GRABBING.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gdk/gdk.h>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -