forked from AuroraMiddleware/gtk
threads example from Erik Mouw. New question on GtkLabel background
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org> * docs/gtkfaq.sgml: threads example from Erik Mouw. New question on GtkLabel background colors. * docs/gtk_tut.sgml: - Correct the example code callback function definitions. - Update the gtkdial example code, from Frans van Schaik. - Update setselection.c to current API. * examples/Makefile examples/*/*.c: Update to code listed in tutorial.
This commit is contained in:
parent
e4df9fa95b
commit
ee3d137660
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
|||||||
|
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
|
||||||
|
|
||||||
|
* docs/gtkfaq.sgml: threads example from Erik Mouw.
|
||||||
|
New question on GtkLabel background colors.
|
||||||
|
|
||||||
|
* docs/gtk_tut.sgml:
|
||||||
|
- Correct the example code callback
|
||||||
|
function definitions.
|
||||||
|
- Update the gtkdial example code, from Frans van Schaik.
|
||||||
|
- Update setselection.c to current API.
|
||||||
|
|
||||||
|
* examples/Makefile examples/*/*.c: Update to code
|
||||||
|
listed in tutorial.
|
||||||
|
|
||||||
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
||||||
|
|
||||||
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
|
||||||
|
|
||||||
|
* docs/gtkfaq.sgml: threads example from Erik Mouw.
|
||||||
|
New question on GtkLabel background colors.
|
||||||
|
|
||||||
|
* docs/gtk_tut.sgml:
|
||||||
|
- Correct the example code callback
|
||||||
|
function definitions.
|
||||||
|
- Update the gtkdial example code, from Frans van Schaik.
|
||||||
|
- Update setselection.c to current API.
|
||||||
|
|
||||||
|
* examples/Makefile examples/*/*.c: Update to code
|
||||||
|
listed in tutorial.
|
||||||
|
|
||||||
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
||||||
|
|
||||||
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
|
||||||
|
|
||||||
|
* docs/gtkfaq.sgml: threads example from Erik Mouw.
|
||||||
|
New question on GtkLabel background colors.
|
||||||
|
|
||||||
|
* docs/gtk_tut.sgml:
|
||||||
|
- Correct the example code callback
|
||||||
|
function definitions.
|
||||||
|
- Update the gtkdial example code, from Frans van Schaik.
|
||||||
|
- Update setselection.c to current API.
|
||||||
|
|
||||||
|
* examples/Makefile examples/*/*.c: Update to code
|
||||||
|
listed in tutorial.
|
||||||
|
|
||||||
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
||||||
|
|
||||||
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
|
||||||
|
|
||||||
|
* docs/gtkfaq.sgml: threads example from Erik Mouw.
|
||||||
|
New question on GtkLabel background colors.
|
||||||
|
|
||||||
|
* docs/gtk_tut.sgml:
|
||||||
|
- Correct the example code callback
|
||||||
|
function definitions.
|
||||||
|
- Update the gtkdial example code, from Frans van Schaik.
|
||||||
|
- Update setselection.c to current API.
|
||||||
|
|
||||||
|
* examples/Makefile examples/*/*.c: Update to code
|
||||||
|
listed in tutorial.
|
||||||
|
|
||||||
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
||||||
|
|
||||||
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
|
||||||
|
|
||||||
|
* docs/gtkfaq.sgml: threads example from Erik Mouw.
|
||||||
|
New question on GtkLabel background colors.
|
||||||
|
|
||||||
|
* docs/gtk_tut.sgml:
|
||||||
|
- Correct the example code callback
|
||||||
|
function definitions.
|
||||||
|
- Update the gtkdial example code, from Frans van Schaik.
|
||||||
|
- Update setselection.c to current API.
|
||||||
|
|
||||||
|
* examples/Makefile examples/*/*.c: Update to code
|
||||||
|
listed in tutorial.
|
||||||
|
|
||||||
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
||||||
|
|
||||||
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
|
||||||
|
|
||||||
|
* docs/gtkfaq.sgml: threads example from Erik Mouw.
|
||||||
|
New question on GtkLabel background colors.
|
||||||
|
|
||||||
|
* docs/gtk_tut.sgml:
|
||||||
|
- Correct the example code callback
|
||||||
|
function definitions.
|
||||||
|
- Update the gtkdial example code, from Frans van Schaik.
|
||||||
|
- Update setselection.c to current API.
|
||||||
|
|
||||||
|
* examples/Makefile examples/*/*.c: Update to code
|
||||||
|
listed in tutorial.
|
||||||
|
|
||||||
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
||||||
|
|
||||||
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
|
||||||
|
|
||||||
|
* docs/gtkfaq.sgml: threads example from Erik Mouw.
|
||||||
|
New question on GtkLabel background colors.
|
||||||
|
|
||||||
|
* docs/gtk_tut.sgml:
|
||||||
|
- Correct the example code callback
|
||||||
|
function definitions.
|
||||||
|
- Update the gtkdial example code, from Frans van Schaik.
|
||||||
|
- Update setselection.c to current API.
|
||||||
|
|
||||||
|
* examples/Makefile examples/*/*.c: Update to code
|
||||||
|
listed in tutorial.
|
||||||
|
|
||||||
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
1999-11-10 Tor Lillqvist <tml@iki.fi>
|
||||||
|
|
||||||
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG -->
|
<!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG -->
|
||||||
<author>Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd
|
<author>Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd
|
||||||
|
|
||||||
<date>October 30th 1999
|
<date>November 9th 1999
|
||||||
|
|
||||||
<abstract> This document is intended to answer questions that are likely to be
|
<abstract> This document is intended to answer questions that are likely to be
|
||||||
frequently asked by programmers using GTK+ or people who are just looking at
|
frequently asked by programmers using GTK+ or people who are just looking at
|
||||||
@ -950,6 +950,149 @@ are made outside of the GTK+ lock. So, within a signal
|
|||||||
handler you do not need to call gdk_threads_enter(), but
|
handler you do not need to call gdk_threads_enter(), but
|
||||||
within the other types of callbacks, you do.
|
within the other types of callbacks, you do.
|
||||||
|
|
||||||
|
Erik Mouw contributed the following code example to illustrate how to
|
||||||
|
use threads within GTK+ programs.
|
||||||
|
|
||||||
|
<tscreen><verb>
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Filename: gtk-thread.c
|
||||||
|
* Version: 0.99.1
|
||||||
|
* Copyright: Copyright (C) 1999, Erik Mouw
|
||||||
|
* Author: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
|
||||||
|
* Description: GTK threads example.
|
||||||
|
* Created at: Sun Oct 17 21:27:09 1999
|
||||||
|
* Modified by: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
|
||||||
|
* Modified at: Sun Oct 24 17:21:41 1999
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Compile with:
|
||||||
|
*
|
||||||
|
* cc -o gtk-thread gtk-thread.c `gtk-config --cflags --libs gthread`
|
||||||
|
*
|
||||||
|
* Thanks to Sebastian Wilhelmi and Owen Taylor for pointing out some
|
||||||
|
* bugs.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <glib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#define YES_IT_IS (1)
|
||||||
|
#define NO_IT_IS_NOT (0)
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GtkWidget *label;
|
||||||
|
int what;
|
||||||
|
} yes_or_no_args;
|
||||||
|
|
||||||
|
G_LOCK_DEFINE_STATIC (yes_or_no);
|
||||||
|
static volatile int yes_or_no = YES_IT_IS;
|
||||||
|
|
||||||
|
void destroy(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
gtk_main_quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void *argument_thread(void *args)
|
||||||
|
{
|
||||||
|
yes_or_no_args *data = (yes_or_no_args *)args;
|
||||||
|
gboolean say_something;
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
/* sleep a while */
|
||||||
|
sleep(rand() / (RAND_MAX / 3) + 1);
|
||||||
|
|
||||||
|
/* lock the yes_or_no_variable */
|
||||||
|
G_LOCK(yes_or_no);
|
||||||
|
|
||||||
|
/* do we have to say something? */
|
||||||
|
say_something = (yes_or_no != data->what);
|
||||||
|
|
||||||
|
if(say_something)
|
||||||
|
{
|
||||||
|
/* set the variable */
|
||||||
|
yes_or_no = data->what;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unlock the yes_or_no variable */
|
||||||
|
G_UNLOCK(yes_or_no);
|
||||||
|
|
||||||
|
if(say_something)
|
||||||
|
{
|
||||||
|
/* get GTK thread lock */
|
||||||
|
gdk_threads_enter();
|
||||||
|
|
||||||
|
/* set label text */
|
||||||
|
if(data->what == YES_IT_IS)
|
||||||
|
gtk_label_set_text(GTK_LABEL(data->label), "O yes, it is!");
|
||||||
|
else
|
||||||
|
gtk_label_set_text(GTK_LABEL(data->label), "O no, it isn't!");
|
||||||
|
|
||||||
|
/* release GTK thread lock */
|
||||||
|
gdk_threads_leave();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
GtkWidget *window;
|
||||||
|
GtkWidget *label;
|
||||||
|
yes_or_no_args yes_args, no_args;
|
||||||
|
pthread_t no_tid, yes_tid;
|
||||||
|
|
||||||
|
/* init threads */
|
||||||
|
g_thread_init(NULL);
|
||||||
|
|
||||||
|
/* init gtk */
|
||||||
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
|
/* init random number generator */
|
||||||
|
srand((unsigned int)time(NULL));
|
||||||
|
|
||||||
|
/* create a window */
|
||||||
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
||||||
|
gtk_signal_connect(GTK_OBJECT (window), "destroy",
|
||||||
|
GTK_SIGNAL_FUNC(destroy), NULL);
|
||||||
|
|
||||||
|
gtk_container_set_border_width(GTK_CONTAINER (window), 10);
|
||||||
|
|
||||||
|
/* create a label */
|
||||||
|
label = gtk_label_new("And now for something completely different ...");
|
||||||
|
gtk_container_add(GTK_CONTAINER(window), label);
|
||||||
|
|
||||||
|
/* show everything */
|
||||||
|
gtk_widget_show(label);
|
||||||
|
gtk_widget_show (window);
|
||||||
|
|
||||||
|
/* create the threads */
|
||||||
|
yes_args.label = label;
|
||||||
|
yes_args.what = YES_IT_IS;
|
||||||
|
pthread_create(&yes_tid, NULL, argument_thread, &yes_args);
|
||||||
|
|
||||||
|
no_args.label = label;
|
||||||
|
no_args.what = NO_IT_IS_NOT;
|
||||||
|
pthread_create(&no_tid, NULL, argument_thread, &no_args);
|
||||||
|
|
||||||
|
/* enter the GTK main loop */
|
||||||
|
gdk_threads_enter();
|
||||||
|
gtk_main();
|
||||||
|
gdk_threads_leave();
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
</verb></tscreen>
|
||||||
|
|
||||||
<!-- This is the old answer - TRG
|
<!-- This is the old answer - TRG
|
||||||
|
|
||||||
|
|
||||||
@ -1002,7 +1145,7 @@ carefully.
|
|||||||
Regardless, it's especially not a priority since relatively good
|
Regardless, it's especially not a priority since relatively good
|
||||||
workarounds exist. -->
|
workarounds exist. -->
|
||||||
<!-- ----------------------------------------------------------------- -->
|
<!-- ----------------------------------------------------------------- -->
|
||||||
<sect1>Why do this strange 'x io error' occur when I <tt/fork()/ in my GTK+ app?
|
<sect1>Why does this strange 'x io error' occur when I <tt/fork()/ in my GTK+ app?
|
||||||
<p>
|
<p>
|
||||||
This is not really a GTK+ problem, and the problem is not related to <tt/fork()/
|
This is not really a GTK+ problem, and the problem is not related to <tt/fork()/
|
||||||
either. If the 'x io error' occurs then you probably use the <tt/exit()/ function
|
either. If the 'x io error' occurs then you probably use the <tt/exit()/ function
|
||||||
@ -1014,7 +1157,7 @@ and the underlying X library really doesn't like this.
|
|||||||
|
|
||||||
The right function to use here is <tt/_exit()/.
|
The right function to use here is <tt/_exit()/.
|
||||||
|
|
||||||
Erik Mouw gave the following code example to illustrate handling
|
Erik Mouw contributed the following code example to illustrate handling
|
||||||
fork() and exit().
|
fork() and exit().
|
||||||
|
|
||||||
<tscreen><verb>
|
<tscreen><verb>
|
||||||
@ -1833,6 +1976,17 @@ gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f);
|
|||||||
gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f);
|
gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f);
|
||||||
</verb></tscreen>
|
</verb></tscreen>
|
||||||
|
|
||||||
|
<!-- ----------------------------------------------------------------- -->
|
||||||
|
<sect1>How do I set the background color of a GtkLabel widget?
|
||||||
|
<p>
|
||||||
|
The Gtklabel widget is one of a few GTK+ widgets that don't create
|
||||||
|
their own window to render themselves into. Instead, they draw
|
||||||
|
themselves directly onto their parents window.
|
||||||
|
|
||||||
|
This means that in order to set the background color for a GtkLabel
|
||||||
|
widget, you need to change the background color of its parent,
|
||||||
|
i.e. the object that you pack it into.
|
||||||
|
|
||||||
<!-- ----------------------------------------------------------------- -->
|
<!-- ----------------------------------------------------------------- -->
|
||||||
<sect1>How do I set the color and font of a GtkLabel using a Resource File?
|
<sect1>How do I set the color and font of a GtkLabel using a Resource File?
|
||||||
<p>
|
<p>
|
||||||
|
File diff suppressed because it is too large
Load Diff
160
docs/gtkfaq.sgml
160
docs/gtkfaq.sgml
@ -9,7 +9,7 @@
|
|||||||
<!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG -->
|
<!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG -->
|
||||||
<author>Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd
|
<author>Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd
|
||||||
|
|
||||||
<date>October 30th 1999
|
<date>November 9th 1999
|
||||||
|
|
||||||
<abstract> This document is intended to answer questions that are likely to be
|
<abstract> This document is intended to answer questions that are likely to be
|
||||||
frequently asked by programmers using GTK+ or people who are just looking at
|
frequently asked by programmers using GTK+ or people who are just looking at
|
||||||
@ -950,6 +950,149 @@ are made outside of the GTK+ lock. So, within a signal
|
|||||||
handler you do not need to call gdk_threads_enter(), but
|
handler you do not need to call gdk_threads_enter(), but
|
||||||
within the other types of callbacks, you do.
|
within the other types of callbacks, you do.
|
||||||
|
|
||||||
|
Erik Mouw contributed the following code example to illustrate how to
|
||||||
|
use threads within GTK+ programs.
|
||||||
|
|
||||||
|
<tscreen><verb>
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Filename: gtk-thread.c
|
||||||
|
* Version: 0.99.1
|
||||||
|
* Copyright: Copyright (C) 1999, Erik Mouw
|
||||||
|
* Author: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
|
||||||
|
* Description: GTK threads example.
|
||||||
|
* Created at: Sun Oct 17 21:27:09 1999
|
||||||
|
* Modified by: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
|
||||||
|
* Modified at: Sun Oct 24 17:21:41 1999
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Compile with:
|
||||||
|
*
|
||||||
|
* cc -o gtk-thread gtk-thread.c `gtk-config --cflags --libs gthread`
|
||||||
|
*
|
||||||
|
* Thanks to Sebastian Wilhelmi and Owen Taylor for pointing out some
|
||||||
|
* bugs.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <glib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#define YES_IT_IS (1)
|
||||||
|
#define NO_IT_IS_NOT (0)
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GtkWidget *label;
|
||||||
|
int what;
|
||||||
|
} yes_or_no_args;
|
||||||
|
|
||||||
|
G_LOCK_DEFINE_STATIC (yes_or_no);
|
||||||
|
static volatile int yes_or_no = YES_IT_IS;
|
||||||
|
|
||||||
|
void destroy(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
gtk_main_quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void *argument_thread(void *args)
|
||||||
|
{
|
||||||
|
yes_or_no_args *data = (yes_or_no_args *)args;
|
||||||
|
gboolean say_something;
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
/* sleep a while */
|
||||||
|
sleep(rand() / (RAND_MAX / 3) + 1);
|
||||||
|
|
||||||
|
/* lock the yes_or_no_variable */
|
||||||
|
G_LOCK(yes_or_no);
|
||||||
|
|
||||||
|
/* do we have to say something? */
|
||||||
|
say_something = (yes_or_no != data->what);
|
||||||
|
|
||||||
|
if(say_something)
|
||||||
|
{
|
||||||
|
/* set the variable */
|
||||||
|
yes_or_no = data->what;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unlock the yes_or_no variable */
|
||||||
|
G_UNLOCK(yes_or_no);
|
||||||
|
|
||||||
|
if(say_something)
|
||||||
|
{
|
||||||
|
/* get GTK thread lock */
|
||||||
|
gdk_threads_enter();
|
||||||
|
|
||||||
|
/* set label text */
|
||||||
|
if(data->what == YES_IT_IS)
|
||||||
|
gtk_label_set_text(GTK_LABEL(data->label), "O yes, it is!");
|
||||||
|
else
|
||||||
|
gtk_label_set_text(GTK_LABEL(data->label), "O no, it isn't!");
|
||||||
|
|
||||||
|
/* release GTK thread lock */
|
||||||
|
gdk_threads_leave();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
GtkWidget *window;
|
||||||
|
GtkWidget *label;
|
||||||
|
yes_or_no_args yes_args, no_args;
|
||||||
|
pthread_t no_tid, yes_tid;
|
||||||
|
|
||||||
|
/* init threads */
|
||||||
|
g_thread_init(NULL);
|
||||||
|
|
||||||
|
/* init gtk */
|
||||||
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
|
/* init random number generator */
|
||||||
|
srand((unsigned int)time(NULL));
|
||||||
|
|
||||||
|
/* create a window */
|
||||||
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
||||||
|
gtk_signal_connect(GTK_OBJECT (window), "destroy",
|
||||||
|
GTK_SIGNAL_FUNC(destroy), NULL);
|
||||||
|
|
||||||
|
gtk_container_set_border_width(GTK_CONTAINER (window), 10);
|
||||||
|
|
||||||
|
/* create a label */
|
||||||
|
label = gtk_label_new("And now for something completely different ...");
|
||||||
|
gtk_container_add(GTK_CONTAINER(window), label);
|
||||||
|
|
||||||
|
/* show everything */
|
||||||
|
gtk_widget_show(label);
|
||||||
|
gtk_widget_show (window);
|
||||||
|
|
||||||
|
/* create the threads */
|
||||||
|
yes_args.label = label;
|
||||||
|
yes_args.what = YES_IT_IS;
|
||||||
|
pthread_create(&yes_tid, NULL, argument_thread, &yes_args);
|
||||||
|
|
||||||
|
no_args.label = label;
|
||||||
|
no_args.what = NO_IT_IS_NOT;
|
||||||
|
pthread_create(&no_tid, NULL, argument_thread, &no_args);
|
||||||
|
|
||||||
|
/* enter the GTK main loop */
|
||||||
|
gdk_threads_enter();
|
||||||
|
gtk_main();
|
||||||
|
gdk_threads_leave();
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
</verb></tscreen>
|
||||||
|
|
||||||
<!-- This is the old answer - TRG
|
<!-- This is the old answer - TRG
|
||||||
|
|
||||||
|
|
||||||
@ -1002,7 +1145,7 @@ carefully.
|
|||||||
Regardless, it's especially not a priority since relatively good
|
Regardless, it's especially not a priority since relatively good
|
||||||
workarounds exist. -->
|
workarounds exist. -->
|
||||||
<!-- ----------------------------------------------------------------- -->
|
<!-- ----------------------------------------------------------------- -->
|
||||||
<sect1>Why do this strange 'x io error' occur when I <tt/fork()/ in my GTK+ app?
|
<sect1>Why does this strange 'x io error' occur when I <tt/fork()/ in my GTK+ app?
|
||||||
<p>
|
<p>
|
||||||
This is not really a GTK+ problem, and the problem is not related to <tt/fork()/
|
This is not really a GTK+ problem, and the problem is not related to <tt/fork()/
|
||||||
either. If the 'x io error' occurs then you probably use the <tt/exit()/ function
|
either. If the 'x io error' occurs then you probably use the <tt/exit()/ function
|
||||||
@ -1014,7 +1157,7 @@ and the underlying X library really doesn't like this.
|
|||||||
|
|
||||||
The right function to use here is <tt/_exit()/.
|
The right function to use here is <tt/_exit()/.
|
||||||
|
|
||||||
Erik Mouw gave the following code example to illustrate handling
|
Erik Mouw contributed the following code example to illustrate handling
|
||||||
fork() and exit().
|
fork() and exit().
|
||||||
|
|
||||||
<tscreen><verb>
|
<tscreen><verb>
|
||||||
@ -1833,6 +1976,17 @@ gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f);
|
|||||||
gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f);
|
gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f);
|
||||||
</verb></tscreen>
|
</verb></tscreen>
|
||||||
|
|
||||||
|
<!-- ----------------------------------------------------------------- -->
|
||||||
|
<sect1>How do I set the background color of a GtkLabel widget?
|
||||||
|
<p>
|
||||||
|
The Gtklabel widget is one of a few GTK+ widgets that don't create
|
||||||
|
their own window to render themselves into. Instead, they draw
|
||||||
|
themselves directly onto their parents window.
|
||||||
|
|
||||||
|
This means that in order to set the background color for a GtkLabel
|
||||||
|
widget, you need to change the background color of its parent,
|
||||||
|
i.e. the object that you pack it into.
|
||||||
|
|
||||||
<!-- ----------------------------------------------------------------- -->
|
<!-- ----------------------------------------------------------------- -->
|
||||||
<sect1>How do I set the color and font of a GtkLabel using a Resource File?
|
<sect1>How do I set the color and font of a GtkLabel using a Resource File?
|
||||||
<p>
|
<p>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -27,6 +27,7 @@ SUBDIRS = arrow \
|
|||||||
rangewidgets \
|
rangewidgets \
|
||||||
rulers \
|
rulers \
|
||||||
scribble-simple \
|
scribble-simple \
|
||||||
|
scribble-xinput \
|
||||||
scrolledwin \
|
scrolledwin \
|
||||||
selection \
|
selection \
|
||||||
spinbutton \
|
spinbutton \
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
int
|
int main( int argc,
|
||||||
main (int argc, char *argv[])
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *aspect_frame;
|
GtkWidget *aspect_frame;
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
/* Create a Button Box with the specified parameters */
|
/* Create a Button Box with the specified parameters */
|
||||||
GtkWidget *create_bbox (gint horizontal,
|
GtkWidget *create_bbox( gint horizontal,
|
||||||
char* title,
|
char *title,
|
||||||
gint spacing,
|
gint spacing,
|
||||||
gint child_w,
|
gint child_w,
|
||||||
gint child_h,
|
gint child_h,
|
||||||
gint layout)
|
gint layout )
|
||||||
{
|
{
|
||||||
GtkWidget *frame;
|
GtkWidget *frame;
|
||||||
GtkWidget *bbox;
|
GtkWidget *bbox;
|
||||||
|
@ -75,7 +75,6 @@ int main( int argc,
|
|||||||
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
|
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
|
||||||
GTK_SIGNAL_FUNC (gtk_exit), NULL);
|
GTK_SIGNAL_FUNC (gtk_exit), NULL);
|
||||||
|
|
||||||
|
|
||||||
/* Sets the border width of the window. */
|
/* Sets the border width of the window. */
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
||||||
gtk_widget_realize(window);
|
gtk_widget_realize(window);
|
||||||
|
@ -2,28 +2,30 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
void enter_callback(GtkWidget *widget, GtkWidget *entry)
|
void enter_callback( GtkWidget *widget,
|
||||||
|
GtkWidget *entry )
|
||||||
{
|
{
|
||||||
gchar *entry_text;
|
gchar *entry_text;
|
||||||
entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
|
entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
|
||||||
printf("Entry contents: %s\n", entry_text);
|
printf("Entry contents: %s\n", entry_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void entry_toggle_editable (GtkWidget *checkbutton,
|
void entry_toggle_editable( GtkWidget *checkbutton,
|
||||||
GtkWidget *entry)
|
GtkWidget *entry )
|
||||||
{
|
{
|
||||||
gtk_entry_set_editable(GTK_ENTRY(entry),
|
gtk_entry_set_editable(GTK_ENTRY(entry),
|
||||||
GTK_TOGGLE_BUTTON(checkbutton)->active);
|
GTK_TOGGLE_BUTTON(checkbutton)->active);
|
||||||
}
|
}
|
||||||
|
|
||||||
void entry_toggle_visibility (GtkWidget *checkbutton,
|
void entry_toggle_visibility( GtkWidget *checkbutton,
|
||||||
GtkWidget *entry)
|
GtkWidget *entry )
|
||||||
{
|
{
|
||||||
gtk_entry_set_visibility(GTK_ENTRY(entry),
|
gtk_entry_set_visibility(GTK_ENTRY(entry),
|
||||||
GTK_TOGGLE_BUTTON(checkbutton)->active);
|
GTK_TOGGLE_BUTTON(checkbutton)->active);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
|
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
int
|
int main( int argc,
|
||||||
main (int argc, char *argv[])
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *event_box;
|
GtkWidget *event_box;
|
||||||
|
@ -3,17 +3,20 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
/* Get the selected filename and print it to the console */
|
/* Get the selected filename and print it to the console */
|
||||||
void file_ok_sel (GtkWidget *w, GtkFileSelection *fs)
|
void file_ok_sel( GtkWidget *w,
|
||||||
|
GtkFileSelection *fs )
|
||||||
{
|
{
|
||||||
g_print ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
|
g_print ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy (GtkWidget *widget, gpointer data)
|
void destroy( GtkWidget *widget,
|
||||||
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *filew;
|
GtkWidget *filew;
|
||||||
|
|
||||||
@ -29,7 +32,8 @@ int main (int argc, char *argv[])
|
|||||||
"clicked", (GtkSignalFunc) file_ok_sel, filew );
|
"clicked", (GtkSignalFunc) file_ok_sel, filew );
|
||||||
|
|
||||||
/* Connect the cancel_button to destroy the widget */
|
/* Connect the cancel_button to destroy the widget */
|
||||||
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
|
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
|
||||||
|
(filew)->cancel_button),
|
||||||
"clicked", (GtkSignalFunc) gtk_widget_destroy,
|
"clicked", (GtkSignalFunc) gtk_widget_destroy,
|
||||||
GTK_OBJECT (filew));
|
GTK_OBJECT (filew));
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ int main( int argc,
|
|||||||
button = gtk_button_new_with_label ("Press me");
|
button = gtk_button_new_with_label ("Press me");
|
||||||
|
|
||||||
/* When the button receives the "clicked" signal, it will call the
|
/* When the button receives the "clicked" signal, it will call the
|
||||||
* function move_button() passing it the Fixed Containter as its
|
* function move_button() passing it the Fixed Container as its
|
||||||
* argument. */
|
* argument. */
|
||||||
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||||
GTK_SIGNAL_FUNC (move_button), fixed);
|
GTK_SIGNAL_FUNC (move_button), fixed);
|
||||||
|
@ -30,7 +30,7 @@ int main( int argc,
|
|||||||
frame = gtk_frame_new(NULL);
|
frame = gtk_frame_new(NULL);
|
||||||
gtk_container_add(GTK_CONTAINER(window), frame);
|
gtk_container_add(GTK_CONTAINER(window), frame);
|
||||||
|
|
||||||
/* Set the frames label */
|
/* Set the frame's label */
|
||||||
gtk_frame_set_label( GTK_FRAME(frame), "GTK Frame Widget" );
|
gtk_frame_set_label( GTK_FRAME(frame), "GTK Frame Widget" );
|
||||||
|
|
||||||
/* Align the label at the right of the frame */
|
/* Align the label at the right of the frame */
|
||||||
|
@ -275,12 +275,14 @@ gtk_dial_expose (GtkWidget *widget,
|
|||||||
GdkEventExpose *event)
|
GdkEventExpose *event)
|
||||||
{
|
{
|
||||||
GtkDial *dial;
|
GtkDial *dial;
|
||||||
GdkPoint points[3];
|
GdkPoint points[6];
|
||||||
gdouble s,c;
|
gdouble s,c;
|
||||||
gdouble theta;
|
gdouble theta, last, increment;
|
||||||
|
GtkStyle *blankstyle;
|
||||||
gint xc, yc;
|
gint xc, yc;
|
||||||
|
gint upper, lower;
|
||||||
gint tick_length;
|
gint tick_length;
|
||||||
gint i;
|
gint i, inc;
|
||||||
|
|
||||||
g_return_val_if_fail (widget != NULL, FALSE);
|
g_return_val_if_fail (widget != NULL, FALSE);
|
||||||
g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE);
|
g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE);
|
||||||
@ -291,37 +293,22 @@ gtk_dial_expose (GtkWidget *widget,
|
|||||||
|
|
||||||
dial = GTK_DIAL (widget);
|
dial = GTK_DIAL (widget);
|
||||||
|
|
||||||
gdk_window_clear_area (widget->window,
|
/* gdk_window_clear_area (widget->window,
|
||||||
0, 0,
|
0, 0,
|
||||||
widget->allocation.width,
|
widget->allocation.width,
|
||||||
widget->allocation.height);
|
widget->allocation.height);
|
||||||
|
*/
|
||||||
xc = widget->allocation.width/2;
|
xc = widget->allocation.width/2;
|
||||||
yc = widget->allocation.height/2;
|
yc = widget->allocation.height/2;
|
||||||
|
|
||||||
/* Draw ticks */
|
upper = dial->adjustment->upper;
|
||||||
|
lower = dial->adjustment->lower;
|
||||||
|
|
||||||
for (i=0; i<25; i++)
|
/* Erase old pointer */
|
||||||
{
|
|
||||||
theta = (i*M_PI/18. - M_PI/6.);
|
|
||||||
s = sin(theta);
|
|
||||||
c = cos(theta);
|
|
||||||
|
|
||||||
tick_length = (i%6 == 0) ? dial->pointer_width : dial->pointer_width/2;
|
|
||||||
|
|
||||||
gdk_draw_line (widget->window,
|
|
||||||
widget->style->fg_gc[widget->state],
|
|
||||||
xc + c*(dial->radius - tick_length),
|
|
||||||
yc - s*(dial->radius - tick_length),
|
|
||||||
xc + c*dial->radius,
|
|
||||||
yc - s*dial->radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Draw pointer */
|
|
||||||
|
|
||||||
s = sin(dial->angle);
|
|
||||||
c = cos(dial->angle);
|
|
||||||
|
|
||||||
|
s = sin(dial->last_angle);
|
||||||
|
c = cos(dial->last_angle);
|
||||||
|
dial->last_angle = dial->angle;
|
||||||
|
|
||||||
points[0].x = xc + s*dial->pointer_width/2;
|
points[0].x = xc + s*dial->pointer_width/2;
|
||||||
points[0].y = yc + c*dial->pointer_width/2;
|
points[0].y = yc + c*dial->pointer_width/2;
|
||||||
@ -329,14 +316,90 @@ gtk_dial_expose (GtkWidget *widget,
|
|||||||
points[1].y = yc - s*dial->radius;
|
points[1].y = yc - s*dial->radius;
|
||||||
points[2].x = xc - s*dial->pointer_width/2;
|
points[2].x = xc - s*dial->pointer_width/2;
|
||||||
points[2].y = yc - c*dial->pointer_width/2;
|
points[2].y = yc - c*dial->pointer_width/2;
|
||||||
|
points[3].x = xc - c*dial->radius/10;
|
||||||
|
points[3].y = yc + s*dial->radius/10;
|
||||||
|
points[4].x = points[0].x;
|
||||||
|
points[4].y = points[0].y;
|
||||||
|
|
||||||
|
blankstyle = gtk_style_new ();
|
||||||
|
blankstyle->bg_gc[GTK_STATE_NORMAL] =
|
||||||
|
widget->style->bg_gc[GTK_STATE_NORMAL];
|
||||||
|
blankstyle->dark_gc[GTK_STATE_NORMAL] =
|
||||||
|
widget->style->bg_gc[GTK_STATE_NORMAL];
|
||||||
|
blankstyle->light_gc[GTK_STATE_NORMAL] =
|
||||||
|
widget->style->bg_gc[GTK_STATE_NORMAL];
|
||||||
|
blankstyle->black_gc =
|
||||||
|
widget->style->bg_gc[GTK_STATE_NORMAL];
|
||||||
|
|
||||||
|
gtk_draw_polygon (blankstyle,
|
||||||
|
widget->window,
|
||||||
|
GTK_STATE_NORMAL,
|
||||||
|
GTK_SHADOW_OUT,
|
||||||
|
points, 5,
|
||||||
|
FALSE);
|
||||||
|
|
||||||
|
gtk_style_unref(blankstyle);
|
||||||
|
|
||||||
|
|
||||||
|
/* Draw ticks */
|
||||||
|
|
||||||
|
if ((upper - lower) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
increment = (100*M_PI)/(dial->radius*dial->radius);
|
||||||
|
|
||||||
|
inc = (upper - lower);
|
||||||
|
|
||||||
|
while (inc < 100) inc *=10;
|
||||||
|
while (inc >= 1000) inc /=10;
|
||||||
|
last = -1;
|
||||||
|
|
||||||
|
for (i=0; i<=inc; i++)
|
||||||
|
{
|
||||||
|
theta = ((gfloat)i*M_PI/(18*inc/24.) - M_PI/6.);
|
||||||
|
|
||||||
|
if ((theta - last) < (increment))
|
||||||
|
continue;
|
||||||
|
last = theta;
|
||||||
|
|
||||||
|
s = sin(theta);
|
||||||
|
c = cos(theta);
|
||||||
|
|
||||||
|
tick_length = (i%(inc/10) == 0) ? dial->pointer_width : dial->pointer_width/2;
|
||||||
|
|
||||||
|
gdk_draw_line (widget->window,
|
||||||
|
widget->style->fg_gc[widget->state],
|
||||||
|
xc + c*(dial->radius - tick_length),
|
||||||
|
yc - s*(dial->radius - tick_length),
|
||||||
|
xc + c*dial->radius,
|
||||||
|
yc - s*dial->radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Draw pointer */
|
||||||
|
|
||||||
|
s = sin(dial->angle);
|
||||||
|
c = cos(dial->angle);
|
||||||
|
dial->last_angle = dial->angle;
|
||||||
|
|
||||||
|
points[0].x = xc + s*dial->pointer_width/2;
|
||||||
|
points[0].y = yc + c*dial->pointer_width/2;
|
||||||
|
points[1].x = xc + c*dial->radius;
|
||||||
|
points[1].y = yc - s*dial->radius;
|
||||||
|
points[2].x = xc - s*dial->pointer_width/2;
|
||||||
|
points[2].y = yc - c*dial->pointer_width/2;
|
||||||
|
points[3].x = xc - c*dial->radius/10;
|
||||||
|
points[3].y = yc + s*dial->radius/10;
|
||||||
|
points[4].x = points[0].x;
|
||||||
|
points[4].y = points[0].y;
|
||||||
|
|
||||||
|
|
||||||
gtk_draw_polygon (widget->style,
|
gtk_draw_polygon (widget->style,
|
||||||
widget->window,
|
widget->window,
|
||||||
GTK_STATE_NORMAL,
|
GTK_STATE_NORMAL,
|
||||||
GTK_SHADOW_OUT,
|
GTK_SHADOW_OUT,
|
||||||
points, 3,
|
points, 5,
|
||||||
TRUE);
|
TRUE);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ struct _GtkDial
|
|||||||
|
|
||||||
/* Current angle */
|
/* Current angle */
|
||||||
gfloat angle;
|
gfloat angle;
|
||||||
|
gfloat last_angle;
|
||||||
|
|
||||||
/* Old values from adjustment stored so we know when something changes */
|
/* Old values from adjustment stored so we know when something changes */
|
||||||
gfloat old_value;
|
gfloat old_value;
|
||||||
|
@ -50,7 +50,7 @@ int main( int argc,
|
|||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
||||||
/* When the window is given the "delete_event" signal (this is given
|
/* When the window is given the "delete_event" signal (this is given
|
||||||
* by the window manager, usually by the 'close' option, or on the
|
* by the window manager, usually by the "close" option, or on the
|
||||||
* titlebar), we ask it to call the delete_event () function
|
* titlebar), we ask it to call the delete_event () function
|
||||||
* as defined above. The data passed to the callback
|
* as defined above. The data passed to the callback
|
||||||
* function is NULL and is ignored in the callback function. */
|
* function is NULL and is ignored in the callback function. */
|
||||||
@ -59,7 +59,7 @@ int main( int argc,
|
|||||||
|
|
||||||
/* Here we connect the "destroy" event to a signal handler.
|
/* Here we connect the "destroy" event to a signal handler.
|
||||||
* This event occurs when we call gtk_widget_destroy() on the window,
|
* This event occurs when we call gtk_widget_destroy() on the window,
|
||||||
* or if we return 'FALSE' in the "delete_event" callback. */
|
* or if we return FALSE in the "delete_event" callback. */
|
||||||
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||||
GTK_SIGNAL_FUNC (destroy), NULL);
|
GTK_SIGNAL_FUNC (destroy), NULL);
|
||||||
|
|
||||||
|
@ -11,11 +11,12 @@ void callback( GtkWidget *widget,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* another callback */
|
/* another callback */
|
||||||
void delete_event( GtkWidget *widget,
|
gint delete_event( GtkWidget *widget,
|
||||||
GdkEvent *event,
|
GdkEvent *event,
|
||||||
gpointer data )
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit ();
|
gtk_main_quit();
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc,
|
int main( int argc,
|
||||||
@ -33,7 +34,7 @@ int main( int argc,
|
|||||||
/* Create a new window */
|
/* Create a new window */
|
||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
||||||
/* This is a new call, this just sets the title of our
|
/* This is a new call, which just sets the title of our
|
||||||
* new window to "Hello Buttons!" */
|
* new window to "Hello Buttons!" */
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "Hello Buttons!");
|
gtk_window_set_title (GTK_WINDOW (window), "Hello Buttons!");
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ int main( int argc,
|
|||||||
label = gtk_label_new ("This is an example of a line-wrapped, filled label. " \
|
label = gtk_label_new ("This is an example of a line-wrapped, filled label. " \
|
||||||
"It should be taking "\
|
"It should be taking "\
|
||||||
"up the entire width allocated to it. " \
|
"up the entire width allocated to it. " \
|
||||||
"Here is a seneance to prove "\
|
"Here is a sentence to prove "\
|
||||||
"my point. Here is another sentence. "\
|
"my point. Here is another sentence. "\
|
||||||
"Here comes the sun, do de do de do.\n"\
|
"Here comes the sun, do de do de do.\n"\
|
||||||
" This is a new paragraph.\n"\
|
" This is a new paragraph.\n"\
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* example-start list list.c */
|
/* example-start list list.c */
|
||||||
|
|
||||||
/* Include the gtk+ header files
|
/* Include the GTK header files
|
||||||
* Include stdio.h, we need that for the printf() function
|
* Include stdio.h, we need that for the printf() function
|
||||||
*/
|
*/
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
@ -13,7 +13,7 @@ const gchar *list_item_data_key="list_item_data";
|
|||||||
|
|
||||||
|
|
||||||
/* prototypes for signal handler that we are going to connect
|
/* prototypes for signal handler that we are going to connect
|
||||||
* to the GtkList widget
|
* to the List widget
|
||||||
*/
|
*/
|
||||||
static void sigh_print_selection( GtkWidget *gtklist,
|
static void sigh_print_selection( GtkWidget *gtklist,
|
||||||
gpointer func_data);
|
gpointer func_data);
|
||||||
@ -25,8 +25,8 @@ static void sigh_button_event( GtkWidget *gtklist,
|
|||||||
|
|
||||||
/* Main function to set up the user interface */
|
/* Main function to set up the user interface */
|
||||||
|
|
||||||
gint main (int argc,
|
gint main( int argc,
|
||||||
gchar *argv[])
|
gchar *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *separator;
|
GtkWidget *separator;
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
@ -41,7 +41,7 @@ gint main (int argc,
|
|||||||
gchar buffer[64];
|
gchar buffer[64];
|
||||||
|
|
||||||
|
|
||||||
/* Initialize gtk+ (and subsequently gdk) */
|
/* Initialize GTK (and subsequently GDK) */
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
@ -65,15 +65,15 @@ gint main (int argc,
|
|||||||
gtk_container_add(GTK_CONTAINER(window), vbox);
|
gtk_container_add(GTK_CONTAINER(window), vbox);
|
||||||
gtk_widget_show(vbox);
|
gtk_widget_show(vbox);
|
||||||
|
|
||||||
/* This is the scrolled window to put the GtkList widget inside */
|
/* This is the scrolled window to put the List widget inside */
|
||||||
scrolled_window=gtk_scrolled_window_new(NULL, NULL);
|
scrolled_window=gtk_scrolled_window_new(NULL, NULL);
|
||||||
gtk_widget_set_usize(scrolled_window, 250, 150);
|
gtk_widget_set_usize(scrolled_window, 250, 150);
|
||||||
gtk_container_add(GTK_CONTAINER(vbox), scrolled_window);
|
gtk_container_add(GTK_CONTAINER(vbox), scrolled_window);
|
||||||
gtk_widget_show(scrolled_window);
|
gtk_widget_show(scrolled_window);
|
||||||
|
|
||||||
/* Create the GtkList widget.
|
/* Create thekList widget.
|
||||||
* Connect the sigh_print_selection() signal handler
|
* Connect the sigh_print_selection() signal handler
|
||||||
* function to the "selection_changed" signal of the GtkList
|
* function to the "selection_changed" signal of the List
|
||||||
* to print out the selected items each time the selection
|
* to print out the selected items each time the selection
|
||||||
* has changed */
|
* has changed */
|
||||||
gtklist=gtk_list_new();
|
gtklist=gtk_list_new();
|
||||||
@ -93,7 +93,7 @@ gint main (int argc,
|
|||||||
gtk_container_add(GTK_CONTAINER(vbox), frame);
|
gtk_container_add(GTK_CONTAINER(vbox), frame);
|
||||||
gtk_widget_show(frame);
|
gtk_widget_show(frame);
|
||||||
|
|
||||||
/* Connect the sigh_button_event() signal handler to the GtkList
|
/* Connect the sigh_button_event() signal handler to the List
|
||||||
* which will handle the "arresting" of list items
|
* which will handle the "arresting" of list items
|
||||||
*/
|
*/
|
||||||
gtk_signal_connect(GTK_OBJECT(gtklist),
|
gtk_signal_connect(GTK_OBJECT(gtklist),
|
||||||
@ -106,7 +106,7 @@ gint main (int argc,
|
|||||||
gtk_container_add(GTK_CONTAINER(vbox), separator);
|
gtk_container_add(GTK_CONTAINER(vbox), separator);
|
||||||
gtk_widget_show(separator);
|
gtk_widget_show(separator);
|
||||||
|
|
||||||
/* Finally create a button and connect it's "clicked" signal
|
/* Finally create a button and connect its "clicked" signal
|
||||||
* to the destruction of the window */
|
* to the destruction of the window */
|
||||||
button=gtk_button_new_with_label("Close");
|
button=gtk_button_new_with_label("Close");
|
||||||
gtk_container_add(GTK_CONTAINER(vbox), button);
|
gtk_container_add(GTK_CONTAINER(vbox), button);
|
||||||
@ -117,8 +117,8 @@ gint main (int argc,
|
|||||||
GTK_OBJECT(window));
|
GTK_OBJECT(window));
|
||||||
|
|
||||||
|
|
||||||
/* Now we create 5 list items, each having it's own
|
/* Now we create 5 list items, each having its own
|
||||||
* label and add them to the GtkList using gtk_container_add()
|
* label and add them to the List using gtk_container_add()
|
||||||
* Also we query the text string from the label and
|
* Also we query the text string from the label and
|
||||||
* associate it with the list_item_data_key for each list item
|
* associate it with the list_item_data_key for each list item
|
||||||
*/
|
*/
|
||||||
@ -176,7 +176,7 @@ gint main (int argc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This is the signal handler that got connected to button
|
/* This is the signal handler that got connected to button
|
||||||
* press/release events of the GtkList
|
* press/release events of the List
|
||||||
*/
|
*/
|
||||||
void sigh_button_event( GtkWidget *gtklist,
|
void sigh_button_event( GtkWidget *gtklist,
|
||||||
GdkEventButton *event,
|
GdkEventButton *event,
|
||||||
@ -218,7 +218,7 @@ void sigh_button_event( GtkWidget *gtklist,
|
|||||||
g_list_free(free_list);
|
g_list_free(free_list);
|
||||||
|
|
||||||
/* If we have a new prisoner, remove him from the
|
/* If we have a new prisoner, remove him from the
|
||||||
* GtkList and put him into the frame "Prison".
|
* List and put him into the frame "Prison".
|
||||||
* We need to unselect the item first.
|
* We need to unselect the item first.
|
||||||
*/
|
*/
|
||||||
if (new_prisoner) {
|
if (new_prisoner) {
|
||||||
@ -235,16 +235,16 @@ void sigh_button_event( GtkWidget *gtklist,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the signal handler that gets called if GtkList
|
/* This is the signal handler that gets called if List
|
||||||
* emits the "selection_changed" signal
|
* emits the "selection_changed" signal
|
||||||
*/
|
*/
|
||||||
void sigh_print_selection( GtkWidget *gtklist,
|
void sigh_print_selection( GtkWidget *gtklist,
|
||||||
gpointer func_data)
|
gpointer func_data )
|
||||||
{
|
{
|
||||||
GList *dlist;
|
GList *dlist;
|
||||||
|
|
||||||
/* Fetch the doubly linked list of selected items
|
/* Fetch the doubly linked list of selected items
|
||||||
* of the GtkList, remember to treat this as read-only!
|
* of the List, remember to treat this as read-only!
|
||||||
*/
|
*/
|
||||||
dlist=GTK_LIST(gtklist)->selection;
|
dlist=GTK_LIST(gtklist)->selection;
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
/* Obligatory basic callback */
|
/* Obligatory basic callback */
|
||||||
static void print_hello(GtkWidget *w, gpointer data) {
|
static void print_hello( GtkWidget *w,
|
||||||
g_message("Hello, World!\n");
|
gpointer data )
|
||||||
|
{
|
||||||
|
g_message ("Hello, World!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the GtkItemFactoryEntry structure used to generate new menus.
|
/* This is the GtkItemFactoryEntry structure used to generate new menus.
|
||||||
@ -27,31 +29,33 @@ static void print_hello(GtkWidget *w, gpointer data) {
|
|||||||
"<RadioItem>" -> create a radio item
|
"<RadioItem>" -> create a radio item
|
||||||
<path> -> path of a radio item to link against
|
<path> -> path of a radio item to link against
|
||||||
"<Separator>" -> create a separator
|
"<Separator>" -> create a separator
|
||||||
"<Branch>" -> create an item to hold sub items
|
"<Branch>" -> create an item to hold sub items (optional)
|
||||||
"<LastBranch>" -> create a right justified branch
|
"<LastBranch>" -> create a right justified branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static GtkItemFactoryEntry menu_items[] = {
|
static GtkItemFactoryEntry menu_items[] = {
|
||||||
{"/_File", NULL, NULL, 0, "<Branch>"},
|
{ "/_File", NULL, NULL, 0, "<Branch>" },
|
||||||
{"/File/_New", "<control>N", print_hello, 0, NULL},
|
{ "/File/_New", "<control>N", print_hello, 0, NULL },
|
||||||
{"/File/_Open", "<control>O", print_hello, 0, NULL},
|
{ "/File/_Open", "<control>O", print_hello, 0, NULL },
|
||||||
{"/File/_Save", "<control>S", print_hello, 0, NULL},
|
{ "/File/_Save", "<control>S", print_hello, 0, NULL },
|
||||||
{"/File/Save _As", NULL, NULL, 0, NULL},
|
{ "/File/Save _As", NULL, NULL, 0, NULL },
|
||||||
{"/File/sep1", NULL, NULL, 0, "<Separator>"},
|
{ "/File/sep1", NULL, NULL, 0, "<Separator>" },
|
||||||
{"/File/Quit", "<control>Q", gtk_main_quit, 0, NULL},
|
{ "/File/Quit", "<control>Q", gtk_main_quit, 0, NULL },
|
||||||
{"/_Options", NULL, NULL, 0, "<Branch>"},
|
{ "/_Options", NULL, NULL, 0, "<Branch>" },
|
||||||
{"/Options/Test", NULL, NULL, 0, NULL},
|
{ "/Options/Test", NULL, NULL, 0, NULL },
|
||||||
{"/_Help", NULL, NULL, 0, "<LastBranch>"},
|
{ "/_Help", NULL, NULL, 0, "<LastBranch>" },
|
||||||
{"/_Help/About", NULL, NULL, 0, NULL},
|
{ "/_Help/About", NULL, NULL, 0, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void get_main_menu(GtkWidget *window, GtkWidget ** menubar) {
|
void get_main_menu( GtkWidget *window,
|
||||||
int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
|
GtkWidget **menubar )
|
||||||
|
{
|
||||||
GtkItemFactory *item_factory;
|
GtkItemFactory *item_factory;
|
||||||
GtkAccelGroup *accel_group;
|
GtkAccelGroup *accel_group;
|
||||||
|
gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
|
||||||
|
|
||||||
accel_group = gtk_accel_group_new();
|
accel_group = gtk_accel_group_new ();
|
||||||
|
|
||||||
/* This function initializes the item factory.
|
/* This function initializes the item factory.
|
||||||
Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
|
Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
|
||||||
@ -61,47 +65,49 @@ void get_main_menu(GtkWidget *window, GtkWidget ** menubar) {
|
|||||||
the accelerator table while generating menus.
|
the accelerator table while generating menus.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>",
|
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
|
||||||
accel_group);
|
accel_group);
|
||||||
|
|
||||||
/* This function generates the menu items. Pass the item factory,
|
/* This function generates the menu items. Pass the item factory,
|
||||||
the number of items in the array, the array itself, and any
|
the number of items in the array, the array itself, and any
|
||||||
callback data for the the menu items. */
|
callback data for the the menu items. */
|
||||||
gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL);
|
gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
|
||||||
|
|
||||||
/* Attach the new accelerator group to the window. */
|
/* Attach the new accelerator group to the window. */
|
||||||
gtk_accel_group_attach (accel_group, GTK_OBJECT (window));
|
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
|
||||||
|
|
||||||
if (menubar)
|
if (menubar)
|
||||||
/* Finally, return the actual menu bar created by the item factory. */
|
/* Finally, return the actual menu bar created by the item factory. */
|
||||||
*menubar = gtk_item_factory_get_widget(item_factory, "<main>");
|
*menubar = gtk_item_factory_get_widget (item_factory, "<main>");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *main_vbox;
|
GtkWidget *main_vbox;
|
||||||
GtkWidget *menubar;
|
GtkWidget *menubar;
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
gtk_signal_connect(GTK_OBJECT(window), "destroy",
|
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||||
GTK_SIGNAL_FUNC(gtk_main_quit),
|
GTK_SIGNAL_FUNC (gtk_main_quit),
|
||||||
"WM destroy");
|
"WM destroy");
|
||||||
gtk_window_set_title(GTK_WINDOW(window), "Item Factory");
|
gtk_window_set_title (GTK_WINDOW(window), "Item Factory");
|
||||||
gtk_widget_set_usize(GTK_WIDGET(window), 300, 200);
|
gtk_widget_set_usize (GTK_WIDGET(window), 300, 200);
|
||||||
|
|
||||||
main_vbox = gtk_vbox_new(FALSE, 1);
|
main_vbox = gtk_vbox_new (FALSE, 1);
|
||||||
gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
|
gtk_container_border_width (GTK_CONTAINER (main_vbox), 1);
|
||||||
gtk_container_add(GTK_CONTAINER(window), main_vbox);
|
gtk_container_add (GTK_CONTAINER (window), main_vbox);
|
||||||
gtk_widget_show(main_vbox);
|
gtk_widget_show (main_vbox);
|
||||||
|
|
||||||
get_main_menu(window, &menubar);
|
get_main_menu (window, &menubar);
|
||||||
gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0);
|
||||||
gtk_widget_show(menubar);
|
gtk_widget_show (menubar);
|
||||||
|
|
||||||
gtk_widget_show(window);
|
gtk_widget_show (window);
|
||||||
gtk_main();
|
gtk_main ();
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
static gint button_press (GtkWidget *, GdkEvent *);
|
static gint button_press (GtkWidget *, GdkEvent *);
|
||||||
static void menuitem_response (gchar *);
|
static void menuitem_response (gchar *);
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
|
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
@ -21,17 +22,17 @@ int main (int argc, char *argv[])
|
|||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
/* create a new window */
|
/* create a new window */
|
||||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);
|
gtk_widget_set_usize (GTK_WIDGET (window), 200, 100);
|
||||||
gtk_window_set_title(GTK_WINDOW (window), "GTK Menu Test");
|
gtk_window_set_title (GTK_WINDOW (window), "GTK Menu Test");
|
||||||
gtk_signal_connect(GTK_OBJECT (window), "delete_event",
|
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
|
||||||
(GtkSignalFunc) gtk_main_quit, NULL);
|
(GtkSignalFunc) gtk_main_quit, NULL);
|
||||||
|
|
||||||
/* Init the menu-widget, and remember -- never
|
/* Init the menu-widget, and remember -- never
|
||||||
* gtk_show_widget() the menu widget!!
|
* gtk_show_widget() the menu widget!!
|
||||||
* This is the menu that holds the menu items, the one that
|
* This is the menu that holds the menu items, the one that
|
||||||
* will pop up when you click on the "Root Menu" in the app */
|
* will pop up when you click on the "Root Menu" in the app */
|
||||||
menu = gtk_menu_new();
|
menu = gtk_menu_new ();
|
||||||
|
|
||||||
/* Next we make a little loop that makes three menu-entries for "test-menu".
|
/* Next we make a little loop that makes three menu-entries for "test-menu".
|
||||||
* Notice the call to gtk_menu_append. Here we are adding a list of
|
* Notice the call to gtk_menu_append. Here we are adding a list of
|
||||||
@ -39,64 +40,64 @@ int main (int argc, char *argv[])
|
|||||||
* signal on each of the menu items and setup a callback for it,
|
* signal on each of the menu items and setup a callback for it,
|
||||||
* but it's omitted here to save space. */
|
* but it's omitted here to save space. */
|
||||||
|
|
||||||
for(i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
/* Copy the names to the buf. */
|
/* Copy the names to the buf. */
|
||||||
sprintf(buf, "Test-undermenu - %d", i);
|
sprintf (buf, "Test-undermenu - %d", i);
|
||||||
|
|
||||||
/* Create a new menu-item with a name... */
|
/* Create a new menu-item with a name... */
|
||||||
menu_items = gtk_menu_item_new_with_label(buf);
|
menu_items = gtk_menu_item_new_with_label (buf);
|
||||||
|
|
||||||
/* ...and add it to the menu. */
|
/* ...and add it to the menu. */
|
||||||
gtk_menu_append(GTK_MENU (menu), menu_items);
|
gtk_menu_append (GTK_MENU (menu), menu_items);
|
||||||
|
|
||||||
/* Do something interesting when the menuitem is selected */
|
/* Do something interesting when the menuitem is selected */
|
||||||
gtk_signal_connect_object(GTK_OBJECT(menu_items), "activate",
|
gtk_signal_connect_object (GTK_OBJECT (menu_items), "activate",
|
||||||
GTK_SIGNAL_FUNC(menuitem_response), (gpointer) g_strdup(buf));
|
GTK_SIGNAL_FUNC (menuitem_response), (gpointer) g_strdup (buf));
|
||||||
|
|
||||||
/* Show the widget */
|
/* Show the widget */
|
||||||
gtk_widget_show(menu_items);
|
gtk_widget_show (menu_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the root menu, and will be the label
|
/* This is the root menu, and will be the label
|
||||||
* displayed on the menu bar. There won't be a signal handler attached,
|
* displayed on the menu bar. There won't be a signal handler attached,
|
||||||
* as it only pops up the rest of the menu when pressed. */
|
* as it only pops up the rest of the menu when pressed. */
|
||||||
root_menu = gtk_menu_item_new_with_label("Root Menu");
|
root_menu = gtk_menu_item_new_with_label ("Root Menu");
|
||||||
|
|
||||||
gtk_widget_show(root_menu);
|
gtk_widget_show (root_menu);
|
||||||
|
|
||||||
/* Now we specify that we want our newly created "menu" to be the menu
|
/* Now we specify that we want our newly created "menu" to be the menu
|
||||||
* for the "root menu" */
|
* for the "root menu" */
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM (root_menu), menu);
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);
|
||||||
|
|
||||||
/* A vbox to put a menu and a button in: */
|
/* A vbox to put a menu and a button in: */
|
||||||
vbox = gtk_vbox_new(FALSE, 0);
|
vbox = gtk_vbox_new (FALSE, 0);
|
||||||
gtk_container_add(GTK_CONTAINER(window), vbox);
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||||
gtk_widget_show(vbox);
|
gtk_widget_show (vbox);
|
||||||
|
|
||||||
/* Create a menu-bar to hold the menus and add it to our main window */
|
/* Create a menu-bar to hold the menus and add it to our main window */
|
||||||
menu_bar = gtk_menu_bar_new();
|
menu_bar = gtk_menu_bar_new ();
|
||||||
gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, FALSE, 2);
|
gtk_box_pack_start (GTK_BOX (vbox), menu_bar, FALSE, FALSE, 2);
|
||||||
gtk_widget_show(menu_bar);
|
gtk_widget_show (menu_bar);
|
||||||
|
|
||||||
/* Create a button to which to attach menu as a popup */
|
/* Create a button to which to attach menu as a popup */
|
||||||
button = gtk_button_new_with_label("press me");
|
button = gtk_button_new_with_label ("press me");
|
||||||
gtk_signal_connect_object(GTK_OBJECT(button), "event",
|
gtk_signal_connect_object (GTK_OBJECT (button), "event",
|
||||||
GTK_SIGNAL_FUNC (button_press), GTK_OBJECT(menu));
|
GTK_SIGNAL_FUNC (button_press), GTK_OBJECT (menu));
|
||||||
gtk_box_pack_end(GTK_BOX(vbox), button, TRUE, TRUE, 2);
|
gtk_box_pack_end (GTK_BOX (vbox), button, TRUE, TRUE, 2);
|
||||||
gtk_widget_show(button);
|
gtk_widget_show (button);
|
||||||
|
|
||||||
/* And finally we append the menu-item to the menu-bar -- this is the
|
/* And finally we append the menu-item to the menu-bar -- this is the
|
||||||
* "root" menu-item I have been raving about =) */
|
* "root" menu-item I have been raving about =) */
|
||||||
gtk_menu_bar_append(GTK_MENU_BAR (menu_bar), root_menu);
|
gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), root_menu);
|
||||||
|
|
||||||
/* always display the window as the last step so it all splashes on
|
/* always display the window as the last step so it all splashes on
|
||||||
* the screen at once. */
|
* the screen at once. */
|
||||||
gtk_widget_show(window);
|
gtk_widget_show (window);
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
return 0;
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Respond to a button-press by posting a menu passed in as widget.
|
/* Respond to a button-press by posting a menu passed in as widget.
|
||||||
@ -105,12 +106,13 @@ int main (int argc, char *argv[])
|
|||||||
* the button that was pressed.
|
* the button that was pressed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static gint button_press (GtkWidget *widget, GdkEvent *event)
|
static gint button_press( GtkWidget *widget,
|
||||||
|
GdkEvent *event )
|
||||||
{
|
{
|
||||||
|
|
||||||
if (event->type == GDK_BUTTON_PRESS) {
|
if (event->type == GDK_BUTTON_PRESS) {
|
||||||
GdkEventButton *bevent = (GdkEventButton *) event;
|
GdkEventButton *bevent = (GdkEventButton *) event;
|
||||||
gtk_menu_popup (GTK_MENU(widget), NULL, NULL, NULL, NULL,
|
gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL,
|
||||||
bevent->button, bevent->time);
|
bevent->button, bevent->time);
|
||||||
/* Tell calling code that we have handled this event; the buck
|
/* Tell calling code that we have handled this event; the buck
|
||||||
* stops here. */
|
* stops here. */
|
||||||
@ -124,8 +126,8 @@ static gint button_press (GtkWidget *widget, GdkEvent *event)
|
|||||||
|
|
||||||
/* Print a string when a menu item is selected */
|
/* Print a string when a menu item is selected */
|
||||||
|
|
||||||
static void menuitem_response (gchar *string)
|
static void menuitem_response( gchar *string )
|
||||||
{
|
{
|
||||||
printf("%s\n", string);
|
printf ("%s\n", string);
|
||||||
}
|
}
|
||||||
/* example-end */
|
/* example-end */
|
||||||
|
@ -3,13 +3,15 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
/* This function rotates the position of the tabs */
|
/* This function rotates the position of the tabs */
|
||||||
void rotate_book (GtkButton *button, GtkNotebook *notebook)
|
void rotate_book( GtkButton *button,
|
||||||
|
GtkNotebook *notebook )
|
||||||
{
|
{
|
||||||
gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos +1) %4);
|
gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos +1) %4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add/Remove the page tabs and the borders */
|
/* Add/Remove the page tabs and the borders */
|
||||||
void tabsborder_book (GtkButton *button, GtkNotebook *notebook)
|
void tabsborder_book( GtkButton *button,
|
||||||
|
GtkNotebook *notebook )
|
||||||
{
|
{
|
||||||
gint tval = FALSE;
|
gint tval = FALSE;
|
||||||
gint bval = FALSE;
|
gint bval = FALSE;
|
||||||
@ -23,7 +25,8 @@ void tabsborder_book (GtkButton *button, GtkNotebook *notebook)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Remove a page from the notebook */
|
/* Remove a page from the notebook */
|
||||||
void remove_book (GtkButton *button, GtkNotebook *notebook)
|
void remove_book( GtkButton *button,
|
||||||
|
GtkNotebook *notebook )
|
||||||
{
|
{
|
||||||
gint page;
|
gint page;
|
||||||
|
|
||||||
@ -34,12 +37,16 @@ void remove_book (GtkButton *button, GtkNotebook *notebook)
|
|||||||
gtk_widget_draw(GTK_WIDGET(notebook), NULL);
|
gtk_widget_draw(GTK_WIDGET(notebook), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete (GtkWidget *widget, GtkWidget *event, gpointer data)
|
gint delete( GtkWidget *widget,
|
||||||
|
GtkWidget *event,
|
||||||
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit ();
|
gtk_main_quit();
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
@ -70,7 +77,7 @@ int main (int argc, char *argv[])
|
|||||||
gtk_table_attach_defaults(GTK_TABLE(table), notebook, 0,6,0,1);
|
gtk_table_attach_defaults(GTK_TABLE(table), notebook, 0,6,0,1);
|
||||||
gtk_widget_show(notebook);
|
gtk_widget_show(notebook);
|
||||||
|
|
||||||
/* Lets append a bunch of pages to the notebook */
|
/* Let's append a bunch of pages to the notebook */
|
||||||
for (i=0; i < 5; i++) {
|
for (i=0; i < 5; i++) {
|
||||||
sprintf(bufferf, "Append Frame %d", i+1);
|
sprintf(bufferf, "Append Frame %d", i+1);
|
||||||
sprintf(bufferl, "Page %d", i+1);
|
sprintf(bufferl, "Page %d", i+1);
|
||||||
@ -88,7 +95,7 @@ int main (int argc, char *argv[])
|
|||||||
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now lets add a page to a specific spot */
|
/* Now let's add a page to a specific spot */
|
||||||
checkbutton = gtk_check_button_new_with_label ("Check me please!");
|
checkbutton = gtk_check_button_new_with_label ("Check me please!");
|
||||||
gtk_widget_set_usize(checkbutton, 100, 75);
|
gtk_widget_set_usize(checkbutton, 100, 75);
|
||||||
gtk_widget_show (checkbutton);
|
gtk_widget_show (checkbutton);
|
||||||
@ -96,7 +103,7 @@ int main (int argc, char *argv[])
|
|||||||
label = gtk_label_new ("Add page");
|
label = gtk_label_new ("Add page");
|
||||||
gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), checkbutton, label, 2);
|
gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), checkbutton, label, 2);
|
||||||
|
|
||||||
/* Now finally lets prepend pages to the notebook */
|
/* Now finally let's prepend pages to the notebook */
|
||||||
for (i=0; i < 5; i++) {
|
for (i=0; i < 5; i++) {
|
||||||
sprintf(bufferf, "Prepend Frame %d", i+1);
|
sprintf(bufferf, "Prepend Frame %d", i+1);
|
||||||
sprintf(bufferl, "PPage %d", i+1);
|
sprintf(bufferl, "PPage %d", i+1);
|
||||||
@ -140,7 +147,8 @@ int main (int argc, char *argv[])
|
|||||||
|
|
||||||
button = gtk_button_new_with_label ("tab position");
|
button = gtk_button_new_with_label ("tab position");
|
||||||
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||||
(GtkSignalFunc) rotate_book, GTK_OBJECT(notebook));
|
(GtkSignalFunc) rotate_book,
|
||||||
|
GTK_OBJECT(notebook));
|
||||||
gtk_table_attach_defaults(GTK_TABLE(table), button, 3,4,1,2);
|
gtk_table_attach_defaults(GTK_TABLE(table), button, 3,4,1,2);
|
||||||
gtk_widget_show(button);
|
gtk_widget_show(button);
|
||||||
|
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
/* example-start packbox packbox.c */
|
/* example-start packbox packbox.c */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "gtk/gtk.h"
|
#include "gtk/gtk.h"
|
||||||
|
|
||||||
void delete_event( GtkWidget *widget,
|
gint delete_event( GtkWidget *widget,
|
||||||
GdkEvent *event,
|
GdkEvent *event,
|
||||||
gpointer data )
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit ();
|
gtk_main_quit();
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a new hbox filled with button-labels. Arguments for the
|
/* Make a new hbox filled with button-labels. Arguments for the
|
||||||
@ -82,7 +84,7 @@ int main( int argc,
|
|||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n");
|
fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n");
|
||||||
/* this just does cleanup in GTK, and exits with an exit status of 1. */
|
/* This just does cleanup in GTK and exits with an exit status of 1. */
|
||||||
gtk_exit (1);
|
gtk_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +93,8 @@ int main( int argc,
|
|||||||
/* Create our window */
|
/* Create our window */
|
||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
||||||
/* You should always remember to connect the destroy signal to the
|
/* You should always remember to connect the delete_event signal
|
||||||
* main window. This is very important for proper intuitive
|
* to the main window. This is very important for proper intuitive
|
||||||
* behavior */
|
* behavior */
|
||||||
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
|
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
|
||||||
GTK_SIGNAL_FUNC (delete_event), NULL);
|
GTK_SIGNAL_FUNC (delete_event), NULL);
|
||||||
@ -128,7 +130,7 @@ int main( int argc,
|
|||||||
gtk_widget_show (box2);
|
gtk_widget_show (box2);
|
||||||
|
|
||||||
/* Call our make box function - homogeneous = FALSE, spacing = 0,
|
/* Call our make box function - homogeneous = FALSE, spacing = 0,
|
||||||
* expand = FALSE, fill = FALSE, padding = 0 */
|
* expand = TRUE, fill = FALSE, padding = 0 */
|
||||||
box2 = make_box (FALSE, 0, TRUE, FALSE, 0);
|
box2 = make_box (FALSE, 0, TRUE, FALSE, 0);
|
||||||
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
|
||||||
gtk_widget_show (box2);
|
gtk_widget_show (box2);
|
||||||
@ -142,8 +144,8 @@ int main( int argc,
|
|||||||
* but they are quite simple. */
|
* but they are quite simple. */
|
||||||
separator = gtk_hseparator_new ();
|
separator = gtk_hseparator_new ();
|
||||||
|
|
||||||
/* Cack the separator into the vbox. Remember each of these
|
/* Pack the separator into the vbox. Remember each of these
|
||||||
* widgets are being packed into a vbox, so they'll be stacked
|
* widgets is being packed into a vbox, so they'll be stacked
|
||||||
* vertically. */
|
* vertically. */
|
||||||
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
|
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
|
||||||
gtk_widget_show (separator);
|
gtk_widget_show (separator);
|
||||||
@ -166,7 +168,8 @@ int main( int argc,
|
|||||||
|
|
||||||
/* Another new separator. */
|
/* Another new separator. */
|
||||||
separator = gtk_hseparator_new ();
|
separator = gtk_hseparator_new ();
|
||||||
/* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */
|
/* The last 3 arguments to gtk_box_pack_start are:
|
||||||
|
* expand, fill, padding. */
|
||||||
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
|
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
|
||||||
gtk_widget_show (separator);
|
gtk_widget_show (separator);
|
||||||
|
|
||||||
@ -192,7 +195,8 @@ int main( int argc,
|
|||||||
gtk_widget_show (box2);
|
gtk_widget_show (box2);
|
||||||
|
|
||||||
separator = gtk_hseparator_new ();
|
separator = gtk_hseparator_new ();
|
||||||
/* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */
|
/* The last 3 arguments to gtk_box_pack_start are:
|
||||||
|
* expand, fill, padding. */
|
||||||
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
|
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
|
||||||
gtk_widget_show (separator);
|
gtk_widget_show (separator);
|
||||||
|
|
||||||
@ -255,14 +259,13 @@ int main( int argc,
|
|||||||
/* Our quit button. */
|
/* Our quit button. */
|
||||||
button = gtk_button_new_with_label ("Quit");
|
button = gtk_button_new_with_label ("Quit");
|
||||||
|
|
||||||
/* Setup the signal to destroy the window. Remember that this will send
|
/* Setup the signal to terminate the program when the button is clicked */
|
||||||
* the "destroy" signal to the window which will be caught by our signal
|
|
||||||
* handler as defined above. */
|
|
||||||
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
|
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
|
||||||
GTK_SIGNAL_FUNC (gtk_main_quit),
|
GTK_SIGNAL_FUNC (gtk_main_quit),
|
||||||
GTK_OBJECT (window));
|
GTK_OBJECT (window));
|
||||||
/* Pack the button into the quitbox.
|
/* Pack the button into the quitbox.
|
||||||
* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */
|
* The last 3 arguments to gtk_box_pack_start are:
|
||||||
|
* expand, fill, padding. */
|
||||||
gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0);
|
||||||
/* pack the quitbox into the vbox (box1) */
|
/* pack the quitbox into the vbox (box1) */
|
||||||
gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0);
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
/* Create the list of "messages" */
|
/* Create the list of "messages" */
|
||||||
GtkWidget *
|
GtkWidget *create_list( void )
|
||||||
create_list (void)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
GtkWidget *scrolled_window;
|
GtkWidget *scrolled_window;
|
||||||
@ -22,8 +21,8 @@ create_list (void)
|
|||||||
|
|
||||||
/* Create a new list and put it in the scrolled window */
|
/* Create a new list and put it in the scrolled window */
|
||||||
list = gtk_list_new ();
|
list = gtk_list_new ();
|
||||||
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
|
gtk_scrolled_window_add_with_viewport (
|
||||||
list);
|
GTK_SCROLLED_WINDOW (scrolled_window), list);
|
||||||
gtk_widget_show (list);
|
gtk_widget_show (list);
|
||||||
|
|
||||||
/* Add some messages to the window */
|
/* Add some messages to the window */
|
||||||
@ -44,8 +43,8 @@ when our window is realized. We could also force our window to be
|
|||||||
realized with gtk_widget_realize, but it would have to be part of
|
realized with gtk_widget_realize, but it would have to be part of
|
||||||
a hierarchy first */
|
a hierarchy first */
|
||||||
|
|
||||||
void
|
void realize_text( GtkWidget *text,
|
||||||
realize_text (GtkWidget *text, gpointer data)
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_text_freeze (GTK_TEXT (text));
|
gtk_text_freeze (GTK_TEXT (text));
|
||||||
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
|
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
|
||||||
@ -62,8 +61,7 @@ realize_text (GtkWidget *text, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create a scrolled text area that displays a "message" */
|
/* Create a scrolled text area that displays a "message" */
|
||||||
GtkWidget *
|
GtkWidget *create_text( void )
|
||||||
create_text (void)
|
|
||||||
{
|
{
|
||||||
GtkWidget *table;
|
GtkWidget *table;
|
||||||
GtkWidget *text;
|
GtkWidget *text;
|
||||||
@ -100,8 +98,8 @@ create_text (void)
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main( int argc,
|
||||||
main (int argc, char *argv[])
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *vpaned;
|
GtkWidget *vpaned;
|
||||||
|
@ -29,18 +29,24 @@ static const char * xpm_data[] = {
|
|||||||
|
|
||||||
/* when invoked (via signal delete_event), terminates the application.
|
/* when invoked (via signal delete_event), terminates the application.
|
||||||
*/
|
*/
|
||||||
void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) {
|
gint close_application( GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data )
|
||||||
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* is invoked when the button is clicked. It just prints a message.
|
/* is invoked when the button is clicked. It just prints a message.
|
||||||
*/
|
*/
|
||||||
void button_clicked( GtkWidget *widget, gpointer data ) {
|
void button_clicked( GtkWidget *widget,
|
||||||
printf( "button clicked\n" );
|
gpointer data ) {
|
||||||
|
g_print( "button clicked\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
/* GtkWidget is the storage type for widgets */
|
/* GtkWidget is the storage type for widgets */
|
||||||
GtkWidget *window, *pixmapwid, *button;
|
GtkWidget *window, *pixmapwid, *button;
|
||||||
|
@ -115,7 +115,7 @@ int main( int argc,
|
|||||||
gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);
|
gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);
|
||||||
gtk_widget_show(align);
|
gtk_widget_show(align);
|
||||||
|
|
||||||
/* Create a GtkAdjusment object to hold the range of the
|
/* Create a Adjusment object to hold the range of the
|
||||||
* progress bar */
|
* progress bar */
|
||||||
adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 150, 0, 0, 0);
|
adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 150, 0, 0, 0);
|
||||||
|
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
void close_application( GtkWidget *widget,
|
gint close_application( GtkWidget *widget,
|
||||||
GdkEvent *event,
|
GdkEvent *event,
|
||||||
gpointer data )
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc,
|
int main( int argc,
|
||||||
|
@ -102,7 +102,7 @@ void create_range_controls( void )
|
|||||||
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
||||||
gtk_widget_show (box2);
|
gtk_widget_show (box2);
|
||||||
|
|
||||||
/* calue, lower, upper, step_increment, page_increment, page_size */
|
/* value, lower, upper, step_increment, page_increment, page_size */
|
||||||
/* Note that the page_size value only makes a difference for
|
/* Note that the page_size value only makes a difference for
|
||||||
* scrollbar widgets, and the highest value you'll get is actually
|
* scrollbar widgets, and the highest value you'll get is actually
|
||||||
* (upper - page_size). */
|
* (upper - page_size). */
|
||||||
@ -218,7 +218,7 @@ void create_range_controls( void )
|
|||||||
box2 = gtk_hbox_new (FALSE, 10);
|
box2 = gtk_hbox_new (FALSE, 10);
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
||||||
|
|
||||||
/* A GtkHScale widget for adjusting the number of digits on the
|
/* An HScale widget for adjusting the number of digits on the
|
||||||
* sample scales. */
|
* sample scales. */
|
||||||
label = gtk_label_new ("Scale Digits:");
|
label = gtk_label_new ("Scale Digits:");
|
||||||
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
|
||||||
@ -238,7 +238,7 @@ void create_range_controls( void )
|
|||||||
box2 = gtk_hbox_new (FALSE, 10);
|
box2 = gtk_hbox_new (FALSE, 10);
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
||||||
|
|
||||||
/* And, one last GtkHScale widget for adjusting the page size of the
|
/* And, one last HScale widget for adjusting the page size of the
|
||||||
* scrollbar. */
|
* scrollbar. */
|
||||||
label = gtk_label_new ("Scrollbar Page Size:");
|
label = gtk_label_new ("Scrollbar Page Size:");
|
||||||
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
|
||||||
|
@ -8,12 +8,17 @@
|
|||||||
#define YSIZE 400
|
#define YSIZE 400
|
||||||
|
|
||||||
/* This routine gets control when the close button is clicked */
|
/* This routine gets control when the close button is clicked */
|
||||||
void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) {
|
gint close_application( GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data )
|
||||||
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The main routine */
|
/* The main routine */
|
||||||
int main( int argc, char *argv[] ) {
|
int main( int argc,
|
||||||
|
char *argv[] ) {
|
||||||
GtkWidget *window, *table, *area, *hrule, *vrule;
|
GtkWidget *window, *table, *area, *hrule, *vrule;
|
||||||
|
|
||||||
/* Initialize GTK and create the main window */
|
/* Initialize GTK and create the main window */
|
||||||
@ -32,28 +37,33 @@ int main( int argc, char *argv[] ) {
|
|||||||
gtk_drawing_area_size( (GtkDrawingArea *)area, XSIZE, YSIZE );
|
gtk_drawing_area_size( (GtkDrawingArea *)area, XSIZE, YSIZE );
|
||||||
gtk_table_attach( GTK_TABLE(table), area, 1, 2, 1, 2,
|
gtk_table_attach( GTK_TABLE(table), area, 1, 2, 1, 2,
|
||||||
GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 );
|
GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 );
|
||||||
gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK );
|
gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK |
|
||||||
|
GDK_POINTER_MOTION_HINT_MASK );
|
||||||
|
|
||||||
/* The horizontal ruler goes on top. As the mouse moves across the drawing area,
|
/* The horizontal ruler goes on top. As the mouse moves across the
|
||||||
* a motion_notify_event is passed to the appropriate event handler for the ruler. */
|
* drawing area, a motion_notify_event is passed to the
|
||||||
|
* appropriate event handler for the ruler. */
|
||||||
hrule = gtk_hruler_new();
|
hrule = gtk_hruler_new();
|
||||||
gtk_ruler_set_metric( GTK_RULER(hrule), GTK_PIXELS );
|
gtk_ruler_set_metric( GTK_RULER(hrule), GTK_PIXELS );
|
||||||
gtk_ruler_set_range( GTK_RULER(hrule), 7, 13, 0, 20 );
|
gtk_ruler_set_range( GTK_RULER(hrule), 7, 13, 0, 20 );
|
||||||
gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
|
gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
|
||||||
(GtkSignalFunc)EVENT_METHOD(hrule, motion_notify_event),
|
(GtkSignalFunc)EVENT_METHOD(hrule,
|
||||||
|
motion_notify_event),
|
||||||
GTK_OBJECT(hrule) );
|
GTK_OBJECT(hrule) );
|
||||||
/* GTK_WIDGET_CLASS(GTK_OBJECT(hrule)->klass)->motion_notify_event, */
|
/* GTK_WIDGET_CLASS(GTK_OBJECT(hrule)->klass)->motion_notify_event, */
|
||||||
gtk_table_attach( GTK_TABLE(table), hrule, 1, 2, 0, 1,
|
gtk_table_attach( GTK_TABLE(table), hrule, 1, 2, 0, 1,
|
||||||
GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0 );
|
GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0 );
|
||||||
|
|
||||||
/* The vertical ruler goes on the left. As the mouse moves across the drawing area,
|
/* The vertical ruler goes on the left. As the mouse moves across
|
||||||
* a motion_notify_event is passed to the appropriate event handler for the ruler. */
|
* the drawing area, a motion_notify_event is passed to the
|
||||||
|
* appropriate event handler for the ruler. */
|
||||||
vrule = gtk_vruler_new();
|
vrule = gtk_vruler_new();
|
||||||
gtk_ruler_set_metric( GTK_RULER(vrule), GTK_PIXELS );
|
gtk_ruler_set_metric( GTK_RULER(vrule), GTK_PIXELS );
|
||||||
gtk_ruler_set_range( GTK_RULER(vrule), 0, YSIZE, 10, YSIZE );
|
gtk_ruler_set_range( GTK_RULER(vrule), 0, YSIZE, 10, YSIZE );
|
||||||
gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
|
gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
|
||||||
(GtkSignalFunc)
|
(GtkSignalFunc)
|
||||||
GTK_WIDGET_CLASS(GTK_OBJECT(vrule)->klass)->motion_notify_event,
|
GTK_WIDGET_CLASS(GTK_OBJECT(vrule)->klass)->
|
||||||
|
motion_notify_event,
|
||||||
GTK_OBJECT(vrule) );
|
GTK_OBJECT(vrule) );
|
||||||
gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2,
|
gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2,
|
||||||
GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 );
|
GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 );
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
static GdkPixmap *pixmap = NULL;
|
static GdkPixmap *pixmap = NULL;
|
||||||
|
|
||||||
/* Create a new backing pixmap of the appropriate size */
|
/* Create a new backing pixmap of the appropriate size */
|
||||||
static gint
|
static gint configure_event( GtkWidget *widget,
|
||||||
configure_event (GtkWidget *widget, GdkEventConfigure *event)
|
GdkEventConfigure *event )
|
||||||
{
|
{
|
||||||
if (pixmap)
|
if (pixmap)
|
||||||
gdk_pixmap_unref(pixmap);
|
gdk_pixmap_unref(pixmap);
|
||||||
@ -46,8 +46,8 @@ configure_event (GtkWidget *widget, GdkEventConfigure *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Redraw the screen from the backing pixmap */
|
/* Redraw the screen from the backing pixmap */
|
||||||
static gint
|
static gint expose_event( GtkWidget *widget,
|
||||||
expose_event (GtkWidget *widget, GdkEventExpose *event)
|
GdkEventExpose *event )
|
||||||
{
|
{
|
||||||
gdk_draw_pixmap(widget->window,
|
gdk_draw_pixmap(widget->window,
|
||||||
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
|
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
|
||||||
@ -60,8 +60,9 @@ expose_event (GtkWidget *widget, GdkEventExpose *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Draw a rectangle on the screen */
|
/* Draw a rectangle on the screen */
|
||||||
static void
|
static void draw_brush( GtkWidget *widget,
|
||||||
draw_brush (GtkWidget *widget, gdouble x, gdouble y)
|
gdouble x,
|
||||||
|
gdouble y)
|
||||||
{
|
{
|
||||||
GdkRectangle update_rect;
|
GdkRectangle update_rect;
|
||||||
|
|
||||||
@ -77,8 +78,8 @@ draw_brush (GtkWidget *widget, gdouble x, gdouble y)
|
|||||||
gtk_widget_draw (widget, &update_rect);
|
gtk_widget_draw (widget, &update_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint button_press_event( GtkWidget *widget,
|
||||||
button_press_event (GtkWidget *widget, GdkEventButton *event)
|
GdkEventButton *event )
|
||||||
{
|
{
|
||||||
if (event->button == 1 && pixmap != NULL)
|
if (event->button == 1 && pixmap != NULL)
|
||||||
draw_brush (widget, event->x, event->y);
|
draw_brush (widget, event->x, event->y);
|
||||||
@ -86,8 +87,8 @@ button_press_event (GtkWidget *widget, GdkEventButton *event)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint motion_notify_event( GtkWidget *widget,
|
||||||
motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
|
GdkEventMotion *event )
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
GdkModifierType state;
|
GdkModifierType state;
|
||||||
@ -107,14 +108,13 @@ motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void quit ()
|
||||||
quit ()
|
|
||||||
{
|
{
|
||||||
gtk_exit (0);
|
gtk_exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main( int argc,
|
||||||
main (int argc, char *argv[])
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *drawing_area;
|
GtkWidget *drawing_area;
|
||||||
|
8
examples/scribble-xinput/Makefile
Normal file
8
examples/scribble-xinput/Makefile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
scribble-xinput: scribble-xinput.c
|
||||||
|
$(CC) `gtk-config --cflags` scribble-xinput.c -o scribble-xinput `gtk-config --libs`
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o scribble-xinput
|
270
examples/scribble-xinput/scribble-xinput.c
Normal file
270
examples/scribble-xinput/scribble-xinput.c
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
/* example-start scribble-xinput scribble-xinput.c */
|
||||||
|
|
||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
/* Backing pixmap for drawing area */
|
||||||
|
static GdkPixmap *pixmap = NULL;
|
||||||
|
|
||||||
|
/* Create a new backing pixmap of the appropriate size */
|
||||||
|
static gint
|
||||||
|
configure_event (GtkWidget *widget, GdkEventConfigure *event)
|
||||||
|
{
|
||||||
|
if (pixmap)
|
||||||
|
gdk_pixmap_unref(pixmap);
|
||||||
|
|
||||||
|
pixmap = gdk_pixmap_new(widget->window,
|
||||||
|
widget->allocation.width,
|
||||||
|
widget->allocation.height,
|
||||||
|
-1);
|
||||||
|
gdk_draw_rectangle (pixmap,
|
||||||
|
widget->style->white_gc,
|
||||||
|
TRUE,
|
||||||
|
0, 0,
|
||||||
|
widget->allocation.width,
|
||||||
|
widget->allocation.height);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Redraw the screen from the backing pixmap */
|
||||||
|
static gint
|
||||||
|
expose_event (GtkWidget *widget, GdkEventExpose *event)
|
||||||
|
{
|
||||||
|
gdk_draw_pixmap(widget->window,
|
||||||
|
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
|
||||||
|
pixmap,
|
||||||
|
event->area.x, event->area.y,
|
||||||
|
event->area.x, event->area.y,
|
||||||
|
event->area.width, event->area.height);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Draw a rectangle on the screen, size depending on pressure,
|
||||||
|
and color on the type of device */
|
||||||
|
static void
|
||||||
|
draw_brush (GtkWidget *widget, GdkInputSource source,
|
||||||
|
gdouble x, gdouble y, gdouble pressure)
|
||||||
|
{
|
||||||
|
GdkGC *gc;
|
||||||
|
GdkRectangle update_rect;
|
||||||
|
|
||||||
|
switch (source)
|
||||||
|
{
|
||||||
|
case GDK_SOURCE_MOUSE:
|
||||||
|
gc = widget->style->dark_gc[GTK_WIDGET_STATE (widget)];
|
||||||
|
break;
|
||||||
|
case GDK_SOURCE_PEN:
|
||||||
|
gc = widget->style->black_gc;
|
||||||
|
break;
|
||||||
|
case GDK_SOURCE_ERASER:
|
||||||
|
gc = widget->style->white_gc;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gc = widget->style->light_gc[GTK_WIDGET_STATE (widget)];
|
||||||
|
}
|
||||||
|
|
||||||
|
update_rect.x = x - 10 * pressure;
|
||||||
|
update_rect.y = y - 10 * pressure;
|
||||||
|
update_rect.width = 20 * pressure;
|
||||||
|
update_rect.height = 20 * pressure;
|
||||||
|
gdk_draw_rectangle (pixmap, gc, TRUE,
|
||||||
|
update_rect.x, update_rect.y,
|
||||||
|
update_rect.width, update_rect.height);
|
||||||
|
gtk_widget_draw (widget, &update_rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_button_press (guint32 deviceid)
|
||||||
|
{
|
||||||
|
GList *tmp_list;
|
||||||
|
|
||||||
|
/* gdk_input_list_devices returns an internal list, so we shouldn't
|
||||||
|
free it afterwards */
|
||||||
|
tmp_list = gdk_input_list_devices();
|
||||||
|
|
||||||
|
while (tmp_list)
|
||||||
|
{
|
||||||
|
GdkDeviceInfo *info = (GdkDeviceInfo *)tmp_list->data;
|
||||||
|
|
||||||
|
if (info->deviceid == deviceid)
|
||||||
|
{
|
||||||
|
g_print("Button press on device '%s'\n", info->name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp_list = tmp_list->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
button_press_event (GtkWidget *widget, GdkEventButton *event)
|
||||||
|
{
|
||||||
|
print_button_press (event->deviceid);
|
||||||
|
|
||||||
|
if (event->button == 1 && pixmap != NULL)
|
||||||
|
draw_brush (widget, event->source, event->x, event->y, event->pressure);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
|
||||||
|
{
|
||||||
|
gdouble x, y;
|
||||||
|
gdouble pressure;
|
||||||
|
GdkModifierType state;
|
||||||
|
|
||||||
|
if (event->is_hint)
|
||||||
|
gdk_input_window_get_pointer (event->window, event->deviceid,
|
||||||
|
&x, &y, &pressure,
|
||||||
|
NULL, NULL, &state);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = event->x;
|
||||||
|
y = event->y;
|
||||||
|
pressure = event->pressure;
|
||||||
|
state = event->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state & GDK_BUTTON1_MASK && pixmap != NULL)
|
||||||
|
draw_brush (widget, event->source, x, y, pressure);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
input_dialog_destroy (GtkWidget *w, gpointer data)
|
||||||
|
{
|
||||||
|
*((GtkWidget **)data) = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
create_input_dialog ()
|
||||||
|
{
|
||||||
|
static GtkWidget *inputd = NULL;
|
||||||
|
|
||||||
|
if (!inputd)
|
||||||
|
{
|
||||||
|
inputd = gtk_input_dialog_new();
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT(inputd), "destroy",
|
||||||
|
(GtkSignalFunc)input_dialog_destroy, &inputd);
|
||||||
|
gtk_signal_connect_object (GTK_OBJECT(GTK_INPUT_DIALOG(inputd)->close_button),
|
||||||
|
"clicked",
|
||||||
|
(GtkSignalFunc)gtk_widget_hide,
|
||||||
|
GTK_OBJECT(inputd));
|
||||||
|
gtk_widget_hide ( GTK_INPUT_DIALOG(inputd)->save_button);
|
||||||
|
|
||||||
|
gtk_widget_show (inputd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!GTK_WIDGET_MAPPED(inputd))
|
||||||
|
gtk_widget_show(inputd);
|
||||||
|
else
|
||||||
|
gdk_window_raise(inputd->window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
quit ()
|
||||||
|
{
|
||||||
|
gtk_exit (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
GtkWidget *window;
|
||||||
|
GtkWidget *drawing_area;
|
||||||
|
GtkWidget *vbox;
|
||||||
|
|
||||||
|
GtkWidget *button;
|
||||||
|
|
||||||
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
gtk_widget_set_name (window, "Test Input");
|
||||||
|
|
||||||
|
vbox = gtk_vbox_new (FALSE, 0);
|
||||||
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||||
|
gtk_widget_show (vbox);
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||||
|
GTK_SIGNAL_FUNC (quit), NULL);
|
||||||
|
|
||||||
|
/* Create the drawing area */
|
||||||
|
|
||||||
|
drawing_area = gtk_drawing_area_new ();
|
||||||
|
gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200);
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
gtk_widget_show (drawing_area);
|
||||||
|
|
||||||
|
/* Signals used to handle backing pixmap */
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
|
||||||
|
(GtkSignalFunc) expose_event, NULL);
|
||||||
|
gtk_signal_connect (GTK_OBJECT(drawing_area),"configure_event",
|
||||||
|
(GtkSignalFunc) configure_event, NULL);
|
||||||
|
|
||||||
|
/* Event signals */
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (drawing_area), "motion_notify_event",
|
||||||
|
(GtkSignalFunc) motion_notify_event, NULL);
|
||||||
|
gtk_signal_connect (GTK_OBJECT (drawing_area), "button_press_event",
|
||||||
|
(GtkSignalFunc) button_press_event, NULL);
|
||||||
|
|
||||||
|
gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK
|
||||||
|
| GDK_LEAVE_NOTIFY_MASK
|
||||||
|
| GDK_BUTTON_PRESS_MASK
|
||||||
|
| GDK_POINTER_MOTION_MASK
|
||||||
|
| GDK_POINTER_MOTION_HINT_MASK);
|
||||||
|
|
||||||
|
/* The following call enables tracking and processing of extension
|
||||||
|
events for the drawing area */
|
||||||
|
gtk_widget_set_extension_events (drawing_area, GDK_EXTENSION_EVENTS_CURSOR);
|
||||||
|
|
||||||
|
/* .. And some buttons */
|
||||||
|
button = gtk_button_new_with_label ("Input Dialog");
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||||
|
GTK_SIGNAL_FUNC (create_input_dialog), NULL);
|
||||||
|
gtk_widget_show (button);
|
||||||
|
|
||||||
|
button = gtk_button_new_with_label ("Quit");
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
|
||||||
|
GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
||||||
|
GTK_OBJECT (window));
|
||||||
|
gtk_widget_show (button);
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
|
||||||
|
gtk_main ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* example-end */
|
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
void destroy(GtkWidget *widget, gpointer data)
|
void destroy( GtkWidget *widget,
|
||||||
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
static GtkWidget *window;
|
static GtkWidget *window;
|
||||||
GtkWidget *scrolled_window;
|
GtkWidget *scrolled_window;
|
||||||
@ -19,9 +21,7 @@ int main (int argc, char *argv[])
|
|||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
/* Create a new dialog window for the scrolled window to be
|
/* Create a new dialog window for the scrolled window to be
|
||||||
* packed into. A dialog is just like a normal window except it has a
|
* packed into. */
|
||||||
* vbox and a horizontal separator packed into it. It's just a shortcut
|
|
||||||
* for creating dialogs */
|
|
||||||
window = gtk_dialog_new ();
|
window = gtk_dialog_new ();
|
||||||
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||||
(GtkSignalFunc) destroy, NULL);
|
(GtkSignalFunc) destroy, NULL);
|
||||||
@ -54,8 +54,8 @@ int main (int argc, char *argv[])
|
|||||||
gtk_table_set_col_spacings (GTK_TABLE (table), 10);
|
gtk_table_set_col_spacings (GTK_TABLE (table), 10);
|
||||||
|
|
||||||
/* pack the table into the scrolled window */
|
/* pack the table into the scrolled window */
|
||||||
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
|
gtk_scrolled_window_add_with_viewport (
|
||||||
table);
|
GTK_SCROLLED_WINDOW (scrolled_window), table);
|
||||||
gtk_widget_show (table);
|
gtk_widget_show (table);
|
||||||
|
|
||||||
/* this simply creates a grid of toggle buttons on the table
|
/* this simply creates a grid of toggle buttons on the table
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
void selection_received (GtkWidget *widget,
|
void selection_received( GtkWidget *widget,
|
||||||
GtkSelectionData *selection_data,
|
GtkSelectionData *selection_data,
|
||||||
gpointer data);
|
gpointer data );
|
||||||
|
|
||||||
/* Signal handler invoked when user clicks on the "Get Targets" button */
|
/* Signal handler invoked when user clicks on the "Get Targets" button */
|
||||||
void
|
void get_targets( GtkWidget *widget,
|
||||||
get_targets (GtkWidget *widget, gpointer data)
|
gpointer data )
|
||||||
{
|
{
|
||||||
static GdkAtom targets_atom = GDK_NONE;
|
static GdkAtom targets_atom = GDK_NONE;
|
||||||
|
|
||||||
@ -22,9 +22,9 @@ get_targets (GtkWidget *widget, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Signal handler called when the selections owner returns the data */
|
/* Signal handler called when the selections owner returns the data */
|
||||||
void
|
void selection_received( GtkWidget *widget,
|
||||||
selection_received (GtkWidget *widget, GtkSelectionData *selection_data,
|
GtkSelectionData *selection_data,
|
||||||
gpointer data)
|
gpointer data )
|
||||||
{
|
{
|
||||||
GdkAtom *atoms;
|
GdkAtom *atoms;
|
||||||
GList *item_list;
|
GList *item_list;
|
||||||
@ -60,8 +60,8 @@ selection_received (GtkWidget *widget, GtkSelectionData *selection_data,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main( int argc,
|
||||||
main (int argc, char *argv[])
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
/* Callback when the user toggles the selection */
|
/* Callback when the user toggles the selection */
|
||||||
void
|
void selection_toggled( GtkWidget *widget,
|
||||||
selection_toggled (GtkWidget *widget, gint *have_selection)
|
gint *have_selection )
|
||||||
{
|
{
|
||||||
if (GTK_TOGGLE_BUTTON(widget)->active)
|
if (GTK_TOGGLE_BUTTON(widget)->active)
|
||||||
{
|
{
|
||||||
@ -32,9 +32,9 @@ selection_toggled (GtkWidget *widget, gint *have_selection)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Called when another application claims the selection */
|
/* Called when another application claims the selection */
|
||||||
gint
|
gint selection_clear( GtkWidget *widget,
|
||||||
selection_clear (GtkWidget *widget, GdkEventSelection *event,
|
GdkEventSelection *event,
|
||||||
gint *have_selection)
|
gint *have_selection )
|
||||||
{
|
{
|
||||||
*have_selection = FALSE;
|
*have_selection = FALSE;
|
||||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), FALSE);
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), FALSE);
|
||||||
@ -43,15 +43,16 @@ selection_clear (GtkWidget *widget, GdkEventSelection *event,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Supplies the current time as the selection. */
|
/* Supplies the current time as the selection. */
|
||||||
void
|
void selection_handle( GtkWidget *widget,
|
||||||
selection_handle (GtkWidget *widget,
|
GtkSelectionData *selection_data,
|
||||||
GtkSelectionData *selection_data,
|
guint info,
|
||||||
gpointer data)
|
guint time_stamp,
|
||||||
|
gpointer data )
|
||||||
{
|
{
|
||||||
gchar *timestr;
|
gchar *timestr;
|
||||||
time_t current_time;
|
time_t current_time;
|
||||||
|
|
||||||
current_time = time (NULL);
|
current_time = time(NULL);
|
||||||
timestr = asctime (localtime(¤t_time));
|
timestr = asctime (localtime(¤t_time));
|
||||||
/* When we return a single string, it should not be null terminated.
|
/* When we return a single string, it should not be null terminated.
|
||||||
That will be done for us */
|
That will be done for us */
|
||||||
@ -60,11 +61,10 @@ selection_handle (GtkWidget *widget,
|
|||||||
8, timestr, strlen(timestr));
|
8, timestr, strlen(timestr));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main( int argc,
|
||||||
main (int argc, char *argv[])
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
|
|
||||||
GtkWidget *selection_button;
|
GtkWidget *selection_button;
|
||||||
|
|
||||||
static int have_selection = FALSE;
|
static int have_selection = FALSE;
|
||||||
@ -91,9 +91,12 @@ main (int argc, char *argv[])
|
|||||||
gtk_signal_connect (GTK_OBJECT(selection_button), "selection_clear_event",
|
gtk_signal_connect (GTK_OBJECT(selection_button), "selection_clear_event",
|
||||||
GTK_SIGNAL_FUNC (selection_clear), &have_selection);
|
GTK_SIGNAL_FUNC (selection_clear), &have_selection);
|
||||||
|
|
||||||
gtk_selection_add_handler (selection_button, GDK_SELECTION_PRIMARY,
|
gtk_selection_add_target (selection_button,
|
||||||
GDK_SELECTION_TYPE_STRING,
|
GDK_SELECTION_PRIMARY,
|
||||||
selection_handle, NULL);
|
GDK_SELECTION_TYPE_STRING,
|
||||||
|
1);
|
||||||
|
gtk_signal_connect (GTK_OBJECT(selection_button), "selection_get",
|
||||||
|
GTK_SIGNAL_FUNC (selection_handle), &have_selection);
|
||||||
|
|
||||||
gtk_widget_show (selection_button);
|
gtk_widget_show (selection_button);
|
||||||
gtk_widget_show (window);
|
gtk_widget_show (window);
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
GtkWidget *status_bar;
|
GtkWidget *status_bar;
|
||||||
|
|
||||||
void push_item (GtkWidget *widget, gpointer data)
|
void push_item( GtkWidget *widget,
|
||||||
|
gpointer data )
|
||||||
{
|
{
|
||||||
static int count = 1;
|
static int count = 1;
|
||||||
char buff[20];
|
char buff[20];
|
||||||
@ -16,13 +17,15 @@ void push_item (GtkWidget *widget, gpointer data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop_item (GtkWidget *widget, gpointer data)
|
void pop_item( GtkWidget *widget,
|
||||||
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_statusbar_pop( GTK_STATUSBAR(status_bar), GPOINTER_TO_INT(data) );
|
gtk_statusbar_pop( GTK_STATUSBAR(status_bar), GPOINTER_TO_INT(data) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
|
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
@ -48,7 +51,8 @@ int main (int argc, char *argv[])
|
|||||||
gtk_box_pack_start (GTK_BOX (vbox), status_bar, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (vbox), status_bar, TRUE, TRUE, 0);
|
||||||
gtk_widget_show (status_bar);
|
gtk_widget_show (status_bar);
|
||||||
|
|
||||||
context_id = gtk_statusbar_get_context_id( GTK_STATUSBAR(status_bar), "Statusbar example");
|
context_id = gtk_statusbar_get_context_id(
|
||||||
|
GTK_STATUSBAR(status_bar), "Statusbar example");
|
||||||
|
|
||||||
button = gtk_button_new_with_label("push item");
|
button = gtk_button_new_with_label("push item");
|
||||||
gtk_signal_connect(GTK_OBJECT(button), "clicked",
|
gtk_signal_connect(GTK_OBJECT(button), "clicked",
|
||||||
|
@ -11,11 +11,12 @@ void callback( GtkWidget *widget,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This callback quits the program */
|
/* This callback quits the program */
|
||||||
void delete_event( GtkWidget *widget,
|
gint delete_event( GtkWidget *widget,
|
||||||
GdkEvent *event,
|
GdkEvent *event,
|
||||||
gpointer data )
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc,
|
int main( int argc,
|
||||||
|
@ -19,12 +19,14 @@ void text_toggle_word_wrap (GtkWidget *checkbutton,
|
|||||||
GTK_TOGGLE_BUTTON(checkbutton)->active);
|
GTK_TOGGLE_BUTTON(checkbutton)->active);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_application( GtkWidget *widget, gpointer data )
|
void close_application( GtkWidget *widget,
|
||||||
|
gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *box1;
|
GtkWidget *box1;
|
||||||
@ -37,7 +39,7 @@ int main (int argc, char *argv[])
|
|||||||
GtkWidget *vscrollbar;
|
GtkWidget *vscrollbar;
|
||||||
GtkWidget *text;
|
GtkWidget *text;
|
||||||
GdkColormap *cmap;
|
GdkColormap *cmap;
|
||||||
GdkColor colour;
|
GdkColor color;
|
||||||
GdkFont *fixed_font;
|
GdkFont *fixed_font;
|
||||||
|
|
||||||
FILE *infile;
|
FILE *infile;
|
||||||
@ -85,28 +87,29 @@ int main (int argc, char *argv[])
|
|||||||
GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
|
GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
|
||||||
gtk_widget_show (vscrollbar);
|
gtk_widget_show (vscrollbar);
|
||||||
|
|
||||||
/* Get the system colour map and allocate the colour red */
|
/* Get the system color map and allocate the color red */
|
||||||
cmap = gdk_colormap_get_system();
|
cmap = gdk_colormap_get_system();
|
||||||
colour.red = 0xffff;
|
color.red = 0xffff;
|
||||||
colour.green = 0;
|
color.green = 0;
|
||||||
colour.blue = 0;
|
color.blue = 0;
|
||||||
if (!gdk_color_alloc(cmap, &colour)) {
|
if (!gdk_color_alloc(cmap, &color)) {
|
||||||
g_error("couldn't allocate colour");
|
g_error("couldn't allocate color");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load a fixed font */
|
/* Load a fixed font */
|
||||||
fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*");
|
fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*");
|
||||||
|
|
||||||
/* Realizing a widget creates a window for it, ready for us to insert some text */
|
/* Realizing a widget creates a window for it,
|
||||||
|
* ready for us to insert some text */
|
||||||
gtk_widget_realize (text);
|
gtk_widget_realize (text);
|
||||||
|
|
||||||
/* Freeze the text widget, ready for multiple updates */
|
/* Freeze the text widget, ready for multiple updates */
|
||||||
gtk_text_freeze (GTK_TEXT (text));
|
gtk_text_freeze (GTK_TEXT (text));
|
||||||
|
|
||||||
/* Insert some coloured text */
|
/* Insert some colored text */
|
||||||
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
|
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
|
||||||
"Supports ", -1);
|
"Supports ", -1);
|
||||||
gtk_text_insert (GTK_TEXT (text), NULL, &colour, NULL,
|
gtk_text_insert (GTK_TEXT (text), NULL, &color, NULL,
|
||||||
"colored ", -1);
|
"colored ", -1);
|
||||||
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
|
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
|
||||||
"text and different ", -1);
|
"text and different ", -1);
|
||||||
|
@ -68,8 +68,10 @@ tictactoe_class_init (TictactoeClass *class)
|
|||||||
tictactoe_signals[TICTACTOE_SIGNAL] = gtk_signal_new ("tictactoe",
|
tictactoe_signals[TICTACTOE_SIGNAL] = gtk_signal_new ("tictactoe",
|
||||||
GTK_RUN_FIRST,
|
GTK_RUN_FIRST,
|
||||||
object_class->type,
|
object_class->type,
|
||||||
GTK_SIGNAL_OFFSET (TictactoeClass, tictactoe),
|
GTK_SIGNAL_OFFSET (TictactoeClass,
|
||||||
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
tictactoe),
|
||||||
|
gtk_signal_default_marshaller,
|
||||||
|
GTK_TYPE_NONE, 0);
|
||||||
|
|
||||||
|
|
||||||
gtk_object_class_add_signals (object_class, tictactoe_signals, LAST_SIGNAL);
|
gtk_object_class_add_signals (object_class, tictactoe_signals, LAST_SIGNAL);
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "tictactoe.h"
|
#include "tictactoe.h"
|
||||||
|
|
||||||
void
|
void win( GtkWidget *widget,
|
||||||
win (GtkWidget *widget, gpointer data)
|
gpointer data )
|
||||||
{
|
{
|
||||||
g_print ("Yay!\n");
|
g_print ("Yay!\n");
|
||||||
tictactoe_clear (TICTACTOE (widget));
|
tictactoe_clear (TICTACTOE (widget));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main( int argc,
|
||||||
main (int argc, char *argv[])
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *ttt;
|
GtkWidget *ttt;
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
/* for all the GtkItem:: and GtkTreeItem:: signals */
|
/* for all the GtkItem:: and GtkTreeItem:: signals */
|
||||||
static void cb_itemsignal (GtkWidget *item, gchar *signame)
|
static void cb_itemsignal( GtkWidget *item,
|
||||||
|
gchar *signame )
|
||||||
{
|
{
|
||||||
gchar *name;
|
gchar *name;
|
||||||
GtkLabel *label;
|
GtkLabel *label;
|
||||||
|
|
||||||
/* It's a GtkBin, so it has one child, which we know to be a
|
/* It's a Bin, so it has one child, which we know to be a
|
||||||
label, so get that */
|
label, so get that */
|
||||||
label = GTK_LABEL (GTK_BIN (item)->child);
|
label = GTK_LABEL (GTK_BIN (item)->child);
|
||||||
/* Get the text of the label */
|
/* Get the text of the label */
|
||||||
@ -19,8 +20,9 @@ static void cb_itemsignal (GtkWidget *item, gchar *signame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Note that this is never called */
|
/* Note that this is never called */
|
||||||
static void cb_unselect_child (GtkWidget *root_tree, GtkWidget *child,
|
static void cb_unselect_child( GtkWidget *root_tree,
|
||||||
GtkWidget *subtree)
|
GtkWidget *child,
|
||||||
|
GtkWidget *subtree )
|
||||||
{
|
{
|
||||||
g_print ("unselect_child called for root tree %p, subtree %p, child %p\n",
|
g_print ("unselect_child called for root tree %p, subtree %p, child %p\n",
|
||||||
root_tree, subtree, child);
|
root_tree, subtree, child);
|
||||||
@ -35,7 +37,7 @@ static void cb_select_child (GtkWidget *root_tree, GtkWidget *child,
|
|||||||
root_tree, subtree, child);
|
root_tree, subtree, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cb_selection_changed (GtkWidget *tree)
|
static void cb_selection_changed( GtkWidget *tree )
|
||||||
{
|
{
|
||||||
GList *i;
|
GList *i;
|
||||||
|
|
||||||
@ -58,7 +60,8 @@ static void cb_selection_changed (GtkWidget *tree)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main( int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
GtkWidget *window, *scrolled_win, *tree;
|
GtkWidget *window, *scrolled_win, *tree;
|
||||||
static gchar *itemnames[] = {"Foo", "Bar", "Baz", "Quux",
|
static gchar *itemnames[] = {"Foo", "Bar", "Baz", "Quux",
|
||||||
|
@ -120,11 +120,16 @@ static char * WheelbarrowFull_xpm[] = {
|
|||||||
|
|
||||||
|
|
||||||
/* When invoked (via signal delete_event), terminates the application */
|
/* When invoked (via signal delete_event), terminates the application */
|
||||||
void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) {
|
gint close_application( GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data )
|
||||||
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc,
|
||||||
|
char *argv[] )
|
||||||
{
|
{
|
||||||
/* GtkWidget is the storage type for widgets */
|
/* GtkWidget is the storage type for widgets */
|
||||||
GtkWidget *window, *pixmap, *fixed;
|
GtkWidget *window, *pixmap, *fixed;
|
||||||
|
Loading…
Reference in New Issue
Block a user