亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gtk_tut-19.html

?? GTK development guide
?? HTML
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
 <TITLE>GTK v1.2 Tutorial: Managing Selections</TITLE>
 <LINK HREF="gtk_tut-20.html" REL=next>
 <LINK HREF="gtk_tut-18.html" REL=previous>
 <LINK HREF="gtk_tut.html#toc19" REL=contents>
</HEAD>
<BODY TEXT="#CCCCCC" BGCOLOR="#000000" LINK="#33cc00" VLINK="#009900" ALINK="#FF0000">
<A HREF="gtk_tut-20.html">Next</A>
<A HREF="gtk_tut-18.html">Previous</A>
<A HREF="gtk_tut.html#toc19">Contents</A>
<HR>
<H2><A NAME="s19">19. Managing Selections</A></H2>

<H2><A NAME="ss19.1">19.1 Overview</A>
</H2>

<P>One type of interprocess communication supported by X and GTK is
<EM>selections</EM>. A selection identifies a chunk of data, for
instance, a portion of text, selected by the user in some fashion, for
instance, by dragging with the mouse. Only one application on a
display (the <EM>owner</EM>) can own a particular selection at one
time, so when a selection is claimed by one application, the previous
owner must indicate to the user that selection has been
relinquished. Other applications can request the contents of a
selection in different forms, called <EM>targets</EM>. There can be
any number of selections, but most X applications only handle one, the
<EM>primary selection</EM>.
<P>In most cases, it isn't necessary for a GTK application to deal with
selections itself. The standard widgets, such as the Entry widget,
already have the capability to claim the selection when appropriate
(e.g., when the user drags over text), and to retrieve the contents of
the selection owned by another widget or another application (e.g.,
when the user clicks the second mouse button). However, there may be
cases in which you want to give other widgets the ability to supply
the selection, or you wish to retrieve targets not supported by
default.
<P>A fundamental concept needed to understand selection handling is that
of the <EM>atom</EM>. An atom is an integer that uniquely identifies a
string (on a certain display). Certain atoms are predefined by the X
server, and in some cases there are constants in <CODE>gtk.h</CODE>
corresponding to these atoms. For instance the constant
<CODE>GDK_PRIMARY_SELECTION</CODE> corresponds to the string "PRIMARY".
In other cases, you should use the functions
<CODE>gdk_atom_intern()</CODE>, to get the atom corresponding to a string,
and <CODE>gdk_atom_name()</CODE>, to get the name of an atom. Both
selections and targets are identified by atoms.
<P>
<H2><A NAME="ss19.2">19.2 Retrieving the selection</A>
</H2>

<P>Retrieving the selection is an asynchronous process. To start the
process, you call:
<P>
<BLOCKQUOTE><CODE>
<PRE>
gint gtk_selection_convert( GtkWidget *widget, 
                            GdkAtom    selection, 
                            GdkAtom    target,
                            guint32    time );
</PRE>
</CODE></BLOCKQUOTE>
<P>This <EM>converts</EM> the selection into the form specified by
<CODE>target</CODE>. If at all possible, the time field should be the time
from the event that triggered the selection. This helps make sure that
events occur in the order that the user requested them. However, if it
is not available (for instance, if the conversion was triggered by a
"clicked" signal), then you can use the constant
<CODE>GDK_CURRENT_TIME</CODE>.
<P>When the selection owner responds to the request, a
"selection_received" signal is sent to your application. The handler
for this signal receives a pointer to a <CODE>GtkSelectionData</CODE>
structure, which is defined as:
<P>
<BLOCKQUOTE><CODE>
<PRE>
struct _GtkSelectionData
{
  GdkAtom selection;
  GdkAtom target;
  GdkAtom type;
  gint    format;
  guchar *data;
  gint    length;
};
</PRE>
</CODE></BLOCKQUOTE>
<P><CODE>selection</CODE> and <CODE>target</CODE> are the values you gave in your
<CODE>gtk_selection_convert()</CODE> call. <CODE>type</CODE> is an atom that
identifies the type of data returned by the selection owner. Some
possible values are "STRING", a string of latin-1 characters, "ATOM",
a series of atoms, "INTEGER", an integer, etc. Most targets can only
return one type. <CODE>format</CODE> gives the length of the units (for
instance characters) in bits. Usually, you don't care about this when
receiving data. <CODE>data</CODE> is a pointer to the returned data, and
<CODE>length</CODE> gives the length of the returned data, in bytes. If
<CODE>length</CODE> is negative, then an error occurred and the selection
could not be retrieved. This might happen if no application owned the
selection, or if you requested a target that the application didn't
support. The buffer is actually guaranteed to be one byte longer than
<CODE>length</CODE>; the extra byte will always be zero, so it isn't
necessary to make a copy of strings just to null terminate them.
<P>In the following example, we retrieve the special target "TARGETS",
which is a list of all targets into which the selection can be
converted.
<P>
<BLOCKQUOTE><CODE>
<PRE>
/* example-start selection gettargets.c */

#include &lt;gtk/gtk.h>

void selection_received( GtkWidget        *widget, 
                         GtkSelectionData *selection_data, 
                         gpointer          data );

/* Signal handler invoked when user clicks on the "Get Targets" button */
void get_targets( GtkWidget *widget,
                  gpointer data )
{
  static GdkAtom targets_atom = GDK_NONE;

  /* Get the atom corresponding to the string "TARGETS" */
  if (targets_atom == GDK_NONE)
    targets_atom = gdk_atom_intern ("TARGETS", FALSE);

  /* And request the "TARGETS" target for the primary selection */
  gtk_selection_convert (widget, GDK_SELECTION_PRIMARY, targets_atom,
                         GDK_CURRENT_TIME);
}

/* Signal handler called when the selections owner returns the data */
void selection_received( GtkWidget        *widget,
                         GtkSelectionData *selection_data, 
                         gpointer          data )
{
  GdkAtom *atoms;
  GList *item_list;
  int i;

  /* **** IMPORTANT **** Check to see if retrieval succeeded  */
  if (selection_data->length &lt; 0)
    {
      g_print ("Selection retrieval failed\n");
      return;
    }
  /* Make sure we got the data in the expected form */
  if (selection_data->type != GDK_SELECTION_TYPE_ATOM)
    {
      g_print ("Selection \"TARGETS\" was not returned as atoms!\n");
      return;
    }
  
  /* Print out the atoms we received */
  atoms = (GdkAtom *)selection_data->data;

  item_list = NULL;
  for (i=0; i&lt;selection_data->length/sizeof(GdkAtom); i++)
    {
      char *name;
      name = gdk_atom_name (atoms[i]);
      if (name != NULL)
        g_print ("%s\n",name);
      else
        g_print ("(bad atom)\n");
    }

  return;
}

int main( int   argc,
          char *argv[] )
{
  GtkWidget *window;
  GtkWidget *button;
  
  gtk_init (&amp;argc, &amp;argv);

  /* Create the toplevel window */

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Event Box");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  gtk_signal_connect (GTK_OBJECT (window), "destroy",
                      GTK_SIGNAL_FUNC (gtk_exit), NULL);

  /* Create a button the user can click to get targets */

  button = gtk_button_new_with_label ("Get Targets");
  gtk_container_add (GTK_CONTAINER (window), button);

  gtk_signal_connect (GTK_OBJECT(button), "clicked",
                      GTK_SIGNAL_FUNC (get_targets), NULL);
  gtk_signal_connect (GTK_OBJECT(button), "selection_received",
                      GTK_SIGNAL_FUNC (selection_received), NULL);

  gtk_widget_show (button);
  gtk_widget_show (window);
  
  gtk_main ();
  
  return 0;
}
/* example-end */
</PRE>
</CODE></BLOCKQUOTE>
<P>
<H2><A NAME="ss19.3">19.3 Supplying the selection </A>
</H2>

<P>Supplying the selection is a bit more complicated. You must register 
handlers that will be called when your selection is requested. For
each selection/target pair you will handle, you make a call to:
<P>
<BLOCKQUOTE><CODE>
<PRE>
void gtk_selection_add_target (GtkWidget           *widget, 
                               GdkAtom              selection,
                               GdkAtom              target,
                               guint                info);
</PRE>
</CODE></BLOCKQUOTE>
<P><CODE>widget</CODE>, <CODE>selection</CODE>, and <CODE>target</CODE> identify the requests
this handler will manage. When a request for a selection is received,
the "selection_get" signal will be called. <CODE>info</CODE> can be used as an
enumerator to identify the specific target within the callback function.
<P>The callback function has the signature:
<P>
<BLOCKQUOTE><CODE>
<PRE>
void  "selection_get" (GtkWidget          *widget,
                       GtkSelectionData   *selection_data,
                       guint               info,
                       guint               time);
</PRE>
</CODE></BLOCKQUOTE>
<P>The GtkSelectionData is the same as above, but this time, we're
responsible for filling in the fields <CODE>type</CODE>, <CODE>format</CODE>,
<CODE>data</CODE>, and <CODE>length</CODE>. (The <CODE>format</CODE> field is actually
important here - the X server uses it to figure out whether the data
needs to be byte-swapped or not. Usually it will be 8 - <EM>i.e.</EM> a
character - or 32 - <EM>i.e.</EM> a. integer.) This is done by calling the
function:
<P>
<BLOCKQUOTE><CODE>
<PRE>
void gtk_selection_data_set( GtkSelectionData *selection_data,
                             GdkAtom           type,
                             gint              format,
                             guchar           *data,
                             gint              length );
</PRE>
</CODE></BLOCKQUOTE>
<P>This function takes care of properly making a copy of the data so that
you don't have to worry about keeping it around. (You should not fill
in the fields of the GtkSelectionData structure by hand.)
<P>When prompted by the user, you claim ownership of the selection by
calling:
<P>
<BLOCKQUOTE><CODE>
<PRE>
gint gtk_selection_owner_set( GtkWidget *widget,
                              GdkAtom    selection,
                              guint32    time );
</PRE>
</CODE></BLOCKQUOTE>
<P>If another application claims ownership of the selection, you will
receive a "selection_clear_event".
<P>As an example of supplying the selection, the following program adds
selection functionality to a toggle button. When the toggle button is
depressed, the program claims the primary selection. The only target
supported (aside from certain targets like "TARGETS" supplied by GTK
itself), is the "STRING" target. When this target is requested, a
string representation of the time is returned.
<P>
<BLOCKQUOTE><CODE>
<PRE>
/* example-start selection setselection.c */

#include &lt;gtk/gtk.h>
#include &lt;time.h>

/* Callback when the user toggles the selection */
void selection_toggled( GtkWidget *widget,
                        gint      *have_selection )
{
  if (GTK_TOGGLE_BUTTON(widget)->active)
    {
      *have_selection = gtk_selection_owner_set (widget,
                                                 GDK_SELECTION_PRIMARY,
                                                 GDK_CURRENT_TIME);
      /* if claiming the selection failed, we return the button to
         the out state */
      if (!*have_selection)
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), FALSE);
    }
  else
    {
      if (*have_selection)
        {
          /* Before clearing the selection by setting the owner to NULL,
             we check if we are the actual owner */
          if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == widget->window)
            gtk_selection_owner_set (NULL, GDK_SELECTION_PRIMARY,
                                     GDK_CURRENT_TIME);
          *have_selection = FALSE;
        }
    }
}

/* Called when another application claims the selection */
gint selection_clear( GtkWidget         *widget,
                      GdkEventSelection *event,
                      gint              *have_selection )
{
  *have_selection = FALSE;
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), FALSE);

  return TRUE;
}

/* Supplies the current time as the selection. */
void selection_handle( GtkWidget        *widget, 
                       GtkSelectionData *selection_data,
                       guint             info,
                       guint             time_stamp,
                       gpointer          data )
{
  gchar *timestr;
  time_t current_time;

  current_time = time(NULL);
  timestr = asctime (localtime(&amp;current_time)); 
  /* When we return a single string, it should not be null terminated.
     That will be done for us */

  gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING,
                          8, timestr, strlen(timestr));
}

int main( int   argc,
          char *argv[] )
{
  GtkWidget *window;
  GtkWidget *selection_button;

  static int have_selection = FALSE;
  
  gtk_init (&amp;argc, &amp;argv);

  /* Create the toplevel window */

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Event Box");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  gtk_signal_connect (GTK_OBJECT (window), "destroy",
                      GTK_SIGNAL_FUNC (gtk_exit), NULL);

  /* Create a toggle button to act as the selection */

  selection_button = gtk_toggle_button_new_with_label ("Claim Selection");
  gtk_container_add (GTK_CONTAINER (window), selection_button);
  gtk_widget_show (selection_button);

  gtk_signal_connect (GTK_OBJECT(selection_button), "toggled",
                      GTK_SIGNAL_FUNC (selection_toggled), &amp;have_selection);
  gtk_signal_connect (GTK_OBJECT(selection_button), "selection_clear_event",
                      GTK_SIGNAL_FUNC (selection_clear), &amp;have_selection);

  gtk_selection_add_target (selection_button,
                            GDK_SELECTION_PRIMARY,
                            GDK_SELECTION_TYPE_STRING,
                            1);
  gtk_signal_connect (GTK_OBJECT(selection_button), "selection_get",
                      GTK_SIGNAL_FUNC (selection_handle), &amp;have_selection);

  gtk_widget_show (selection_button);
  gtk_widget_show (window);
  
  gtk_main ();
  
  return 0;
}
/* example-end */
</PRE>
</CODE></BLOCKQUOTE>
<P>
<P>
<HR>
<A HREF="gtk_tut-20.html">Next</A>
<A HREF="gtk_tut-18.html">Previous</A>
<A HREF="gtk_tut.html#toc19">Contents</A>
</BODY>
</HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美性做爰猛烈叫床潮| 亚洲精品成人a在线观看| 一区二区三区在线播放| 精品国产一二三| 成人avav在线| 国产成人日日夜夜| 国产精品123区| 亚洲成av人片一区二区梦乃| 日本v片在线高清不卡在线观看| 欧美高清一级片在线| 欧美在线|欧美| 国产精品一区二区在线观看网站| 国产精品人妖ts系列视频| 在线免费精品视频| 韩国理伦片一区二区三区在线播放 | 中文字幕 久热精品 视频在线 | 久久久亚洲综合| 久久久精品tv| 最近日韩中文字幕| 亚洲综合视频网| 免费在线观看日韩欧美| 亚洲视频一区二区在线观看| 欧美一区二区美女| 99精品视频一区二区| 色一情一乱一乱一91av| 欧美日韩视频第一区| 欧美不卡一区二区三区四区| 久久久五月婷婷| 亚洲乱码日产精品bd| 天天综合天天做天天综合| 久久精品人人做人人综合 | 欧美日本免费一区二区三区| 日韩欧美一区二区在线视频| 国产精品美女www爽爽爽| 亚洲一区在线免费观看| 极品销魂美女一区二区三区| 97精品视频在线观看自产线路二| 欧美午夜在线一二页| 久久久国产精品午夜一区ai换脸| 亚洲免费资源在线播放| 久久电影网站中文字幕| 在线观看一区日韩| 久久影院视频免费| 日韩欧美卡一卡二| 亚洲人妖av一区二区| 蜜桃视频在线一区| 欧美性猛交xxxx黑人交| 国产人成亚洲第一网站在线播放| 无吗不卡中文字幕| 91亚洲精华国产精华精华液| 精品国产青草久久久久福利| 亚洲国产精品影院| 日韩制服丝袜先锋影音| 午夜精品在线看| 成人久久视频在线观看| 色综合天天视频在线观看 | av日韩在线网站| 91麻豆国产香蕉久久精品| 91老司机福利 在线| 久久嫩草精品久久久精品| 久久久久9999亚洲精品| 国产91精品一区二区| 国产成人免费视| k8久久久一区二区三区| 久久蜜臀精品av| 日韩一区日韩二区| 国产suv精品一区二区三区| 精品美女在线播放| 美脚の诱脚舐め脚责91| 91精品婷婷国产综合久久性色 | 欧美电影免费观看高清完整版 | 9久草视频在线视频精品| 91女厕偷拍女厕偷拍高清| 91国偷自产一区二区开放时间| 欧洲精品一区二区三区在线观看| 欧美国产日韩亚洲一区| 亚洲精品乱码久久久久久| 午夜精品123| 欧美日韩精品电影| 亚洲国产精品一区二区久久恐怖片| 91视频91自| 日韩午夜在线影院| 亚洲欧美成人一区二区三区| 奇米色一区二区| 99热精品一区二区| 自拍偷拍欧美激情| 国产一区视频在线看| 在线免费一区三区| 欧美国产在线观看| 99精品视频在线播放观看| 欧美一级在线免费| 国产成人在线视频网站| 国产精品另类一区| 欧美亚一区二区| 久久国产福利国产秒拍| 亚洲国产精品精华液2区45| 91网站视频在线观看| 欧美v日韩v国产v| 国产91精品免费| 91精品黄色片免费大全| 国产精品久久久久永久免费观看| 91麻豆视频网站| 国产欧美日韩一区二区三区在线观看 | 国产精品的网站| 欧美性视频一区二区三区| 国产精品萝li| 在线免费观看视频一区| 精品中文字幕一区二区| 国产精品福利影院| 懂色中文一区二区在线播放| 91精品国产全国免费观看| 国产一区二区电影| 日韩精品五月天| 久久精品一区四区| 国产精品88888| 精品国免费一区二区三区| 成人国产免费视频| 蜜臀久久久99精品久久久久久| 欧美日韩在线播放一区| 国产一区二区三区视频在线播放| 亚洲区小说区图片区qvod| 精品国产精品网麻豆系列| 在线观看欧美精品| 亚洲午夜在线观看视频在线| 色欧美片视频在线观看在线视频| 最新国产精品久久精品| 欧美电视剧免费全集观看| 老司机午夜精品99久久| 欧美一区二区三区公司| 波多野结衣亚洲一区| 亚洲欧美日本在线| xnxx国产精品| 日韩一区二区电影| 欧美日韩国产乱码电影| 色哟哟精品一区| 偷拍自拍另类欧美| 亚洲免费观看在线观看| 中文字幕第一区| 91丝袜美腿高跟国产极品老师 | 亚洲精选视频免费看| 欧美性大战久久久| 日本亚洲欧美天堂免费| 亚洲视频在线一区观看| 国产精品夫妻自拍| 欧美综合一区二区| av成人免费在线观看| 国产盗摄视频一区二区三区| 麻豆精品新av中文字幕| 日韩av成人高清| 欧美激情在线观看视频免费| www亚洲一区| 精品国产免费久久| 色成年激情久久综合| 粉嫩一区二区三区性色av| 亚洲永久免费av| 一个色综合网站| 亚洲国产欧美另类丝袜| 久久精品视频免费| 欧美国产日本视频| 欧美一区二区三区视频在线观看 | 国产69精品一区二区亚洲孕妇| 国产精品久久久久久久久免费丝袜 | 国产精品一区一区| 国产91精品一区二区| 日韩黄色小视频| 日韩电影免费在线看| 蜜桃精品在线观看| 国产成人亚洲综合a∨婷婷图片| 国产suv精品一区二区三区| 国产99久久久精品| 男女性色大片免费观看一区二区 | jvid福利写真一区二区三区| 日本午夜一区二区| 国产精品伦一区二区三级视频| 国产日韩精品一区二区三区在线| 国产亚洲人成网站| 一区二区高清视频在线观看| 爽好久久久欧美精品| 国产在线精品视频| 成人理论电影网| 欧美肥妇free| 久久久美女毛片| 亚洲国产成人porn| 亚洲精品免费在线观看| 亚洲aaa精品| 国产福利不卡视频| 在线播放91灌醉迷j高跟美女| 久久综合九色综合97婷婷女人| 51精品久久久久久久蜜臀| 亚洲精品一区二区三区香蕉| 中文字幕亚洲电影| 成人欧美一区二区三区视频网页| 久久婷婷综合激情| 亚洲一区二区三区影院| 国产精品一区二区视频| 欧美色图激情小说| 欧美亚洲丝袜传媒另类| 久久精品亚洲精品国产欧美kt∨| 亚洲成人av一区二区三区| 成人久久18免费网站麻豆|