/*自己定义一个基于GtkEntry的控件,然后把GtkEntryClass中的cut_clipboard,copy_clipboard,paste_clipboard置为空就可以了,下面给你一个示例。
限制entry COPY PASTE CUT
myentry.h:
*/
#ifndef _MY_ENTRY_H_
#define _MY_ENTRY_H_
#include <gtk/gtk.h>
#define MY_TYPE_ENTRY (my_entry_get_type ())
#define MY_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_ENTRY, MyEntry))
#define MY_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MY_TYPE_ENTRY, MyEntryClass))
#define MY_IS_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_ENTRY))
#define MY_IS_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MY_TYPE_ENTRY))
#define MY_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MY_TYPE_ENTRY, MyEntryClass))
typedef struct _MyEntry {
GtkEntry parent;
} MyEntry;
typedef struct _MyEntryClass {
GtkEntryClass parent_class;
} MyEntryClass;
GType my_entry_get_type (void) G_GNUC_CONST;
GtkWidget* my_entry_new (void);
#endif
myentry.c:
#include "myentry.h"
G_DEFINE_TYPE (MyEntry, my_entry, GTK_TYPE_ENTRY)
static void my_entry_class_init (MyEntryClass *klass)
{
GtkEntryClass *entry_class = GTK_ENTRY_CLASS (klass);
entry_class->cut_clipboard = NULL;
entry_class->copy_clipboard = NULL;
entry_class->paste_clipboard = NULL;
}
static void my_entry_init (MyEntry *entry)
{
}
GtkWidget *my_entry_new (void)
{
return g_object_new (MY_TYPE_ENTRY, NULL);
}
main.c:
#include <stdio.h>
#include <gtk/gtk.h>
#include "myentry.h"
int
main (int argc, char **argv)
{
GtkWidget *mainwindow;
GtkWidget *entry;
gtk_init(&argc, &argv);
mainwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (mainwindow),
"delete_event",
G_CALLBACK (gtk_main_quit),
NULL);
entry = my_entry_new ();
gtk_widget_show (entry);
gtk_container_add (GTK_CONTAINER (mainwindow), entry);
gtk_widget_show_all (GTK_WIDGET (mainwindow));
gtk_main ();
return 0;
}
限制entry COPY PASTE CUT
myentry.h:
*/
#ifndef _MY_ENTRY_H_
#define _MY_ENTRY_H_
#include <gtk/gtk.h>
#define MY_TYPE_ENTRY (my_entry_get_type ())
#define MY_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_ENTRY, MyEntry))
#define MY_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MY_TYPE_ENTRY, MyEntryClass))
#define MY_IS_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_ENTRY))
#define MY_IS_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MY_TYPE_ENTRY))
#define MY_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MY_TYPE_ENTRY, MyEntryClass))
typedef struct _MyEntry {
GtkEntry parent;
} MyEntry;
typedef struct _MyEntryClass {
GtkEntryClass parent_class;
} MyEntryClass;
GType my_entry_get_type (void) G_GNUC_CONST;
GtkWidget* my_entry_new (void);
#endif
myentry.c:
#include "myentry.h"
G_DEFINE_TYPE (MyEntry, my_entry, GTK_TYPE_ENTRY)
static void my_entry_class_init (MyEntryClass *klass)
{
GtkEntryClass *entry_class = GTK_ENTRY_CLASS (klass);
entry_class->cut_clipboard = NULL;
entry_class->copy_clipboard = NULL;
entry_class->paste_clipboard = NULL;
}
static void my_entry_init (MyEntry *entry)
{
}
GtkWidget *my_entry_new (void)
{
return g_object_new (MY_TYPE_ENTRY, NULL);
}
main.c:
#include <stdio.h>
#include <gtk/gtk.h>
#include "myentry.h"
int
main (int argc, char **argv)
{
GtkWidget *mainwindow;
GtkWidget *entry;
gtk_init(&argc, &argv);
mainwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (mainwindow),
"delete_event",
G_CALLBACK (gtk_main_quit),
NULL);
entry = my_entry_new ();
gtk_widget_show (entry);
gtk_container_add (GTK_CONTAINER (mainwindow), entry);
gtk_widget_show_all (GTK_WIDGET (mainwindow));
gtk_main ();
return 0;
}