summaryrefslogtreecommitdiff
path: root/packages/gnome1/examples
diff options
context:
space:
mode:
authormarco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-01-27 12:24:32 +0000
committermarco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-01-27 12:24:32 +0000
commit506070267b8daa0186cf2a3d159ced12d10583e3 (patch)
treed476761c35aadca28ff4c76dfc8320535cb4cf67 /packages/gnome1/examples
parentd7b92f2ae62cdbbcbf6ffc8f58d86dd8dd8edd72 (diff)
downloadfpc-506070267b8daa0186cf2a3d159ced12d10583e3.tar.gz
* gnome1 moved
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@10040 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/gnome1/examples')
-rw-r--r--packages/gnome1/examples/gconfcallback1.pp69
-rw-r--r--packages/gnome1/examples/gconfcallback2.pp53
-rw-r--r--packages/gnome1/examples/gconfexample.pp83
-rw-r--r--packages/gnome1/examples/gnometest.pp30
-rw-r--r--packages/gnome1/examples/testzvt.pp195
5 files changed, 430 insertions, 0 deletions
diff --git a/packages/gnome1/examples/gconfcallback1.pp b/packages/gnome1/examples/gconfcallback1.pp
new file mode 100644
index 0000000000..f1ceaa13d1
--- /dev/null
+++ b/packages/gnome1/examples/gconfcallback1.pp
@@ -0,0 +1,69 @@
+program gconfcallback1;
+
+{$Mode ObjFPC}
+
+Uses glib, gtk, gconf, gconfclient;
+
+Procedure key_changed_callback(client : PGConfClient;
+ cnxn_id : guint;
+ entry : PGConfEntry;
+ user_data: gpointer); cdecl;
+
+var
+ thelabel : PGtkWidget;
+ thevalue : PGConfValue;
+begin
+ thelabel := GTK_WIDGET(user_data);
+
+ if (entry = nil) then
+ gtk_label_set_text(GTK_LABEL(thelabel), '<unset>')
+ else begin
+ theValue := gconf_entry_get_value (entry);
+ if (thevalue^.thetype = GCONF_VALUE_STRING) then
+ gtk_label_set_text(GTK_LABEL(thelabel), gconf_value_get_string(thevalue))
+ else
+ gtk_label_set_text(GTK_LABEL(thelabel), '<wrong type>');
+ end;
+end;
+
+var
+ window : PGtkWidget;
+ thelabel : PGtkWidget;
+ client : PGConfClient;
+ str : Pgchar;
+
+begin
+ gtk_init(@argc, @argv);
+ gconf_init(argc, argv, nil);
+
+ client := gconf_client_get_default;
+
+ window := gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ gtk_signal_connect(PGtkOBJECT (window), 'delete_event',
+ gtk_SIGNAL_FUNC (@gtk_exit), NIL);
+
+
+ str := gconf_client_get_string(client, '/extra/test/directory/key',nil);
+
+ If Str <> nil then
+ thelabel := gtk_label_new(str)
+ else
+ thelabel := gtk_label_new('<unset>');
+
+ gtk_container_add(GTK_CONTAINER(window), thelabel);
+
+ gconf_client_add_dir(client,
+ '/extra/test/directory',
+ GCONF_CLIENT_PRELOAD_NONE,
+ nil);
+
+ gconf_client_notify_add(client, '/extra/test/directory/key',
+ @key_changed_callback,
+ thelabel,
+ nil, nil);
+
+ gtk_widget_show_all(window);
+
+ gtk_main();
+end.
diff --git a/packages/gnome1/examples/gconfcallback2.pp b/packages/gnome1/examples/gconfcallback2.pp
new file mode 100644
index 0000000000..801603c5a7
--- /dev/null
+++ b/packages/gnome1/examples/gconfcallback2.pp
@@ -0,0 +1,53 @@
+Program gconfcallback2;
+
+{$Mode ObjFpc}
+
+Uses glib, gtk, gconf, gconfclient;
+
+Procedure entry_activated_callback(entry : PGtkWidget; user_data : gpointer); cdecl;
+var
+ client : PGConfClient;
+ str : Pgchar;
+begin
+ client := PGConfClient(user_data);
+
+ str := gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
+
+ gconf_client_set_string(client, '/extra/test/directory/key',
+ str, nil);
+
+ g_free(str);
+end;
+
+var
+ window : PGtkWidget;
+ entry : PGtkWidget;
+ client : PGConfClient;
+begin
+ gtk_init(@argc, @argv);
+ gconf_init(argc, argv, nil);
+
+ window := gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_signal_connect(PGtkOBJECT (window), 'delete_event',
+ gtk_SIGNAL_FUNC (@gtk_exit), NIL);
+
+ entry := gtk_entry_new();
+
+ gtk_container_add(GTK_CONTAINER(window), entry);
+
+ client := gconf_client_get_default;
+
+ gconf_client_add_dir(client,
+ '/extra/test/directory',
+ GCONF_CLIENT_PRELOAD_NONE,
+ NULL);
+
+
+ gtk_signal_connect(GTK_OBJECT(entry), 'activate',
+ GTK_SIGNAL_FUNC(@entry_activated_callback),
+ client);
+
+ gtk_widget_show_all(window);
+
+ gtk_main();
+end.
diff --git a/packages/gnome1/examples/gconfexample.pp b/packages/gnome1/examples/gconfexample.pp
new file mode 100644
index 0000000000..4334623e7f
--- /dev/null
+++ b/packages/gnome1/examples/gconfexample.pp
@@ -0,0 +1,83 @@
+Program gconfexample;
+
+Uses glib, gtk, gconf, gconfclient;
+
+Const
+ PATH : PChar = '/apps/GNOMEnclature/gconf_example';
+ KEY : PChar= '/apps/GNOMEnclature/gconf_example/my_option';
+
+{ Update the GConf key when the user toggles the check button. }
+Procedure button_toggled_cb (button : PGtkWidget; data : gpointer); cdecl;
+var
+ client : PGConfClient;
+ thevalue : gboolean;
+begin
+ client := gconf_client_get_default ();
+
+ thevalue := gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ gconf_client_set_bool (client, KEY, thevalue, nil);
+end;
+
+{ This is called when our key is changed. }
+Procedure gconf_notify_func (client : PGConfClient; cnxn_id : guint;
+ entry : PGConfEntry; user_data : gpointer); cdecl;
+var
+ check_button : PGtkWidget;
+ thevalue : PGConfValue;
+ checked : gboolean;
+begin
+ check_button := GTK_WIDGET (user_data);
+
+ thevalue := gconf_entry_get_value (entry);
+
+ checked := gconf_value_get_bool (thevalue);
+
+ { Update the check button accordingly. }
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
+ checked);
+end;
+
+var
+ window : PGtkWidget;
+ check_button : PGTKWidget;
+ client : PGConfClient;
+ thevalue : gboolean;
+
+begin
+ gtk_init (@argc, @argv);
+ gconf_init(argc, argv, nil);
+
+ client := gconf_client_get_default ();
+
+ window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_signal_connect(GTK_OBJECT (window), 'destroy',
+ @gtk_main_quit, nil);
+
+ { Get the initial value from GConf. }
+ thevalue := gconf_client_get_bool (client, KEY, nil);
+
+ check_button := gtk_check_button_new_with_label ('My option');
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
+ thevalue);
+
+ gtk_signal_connect (GTK_OBJECT (check_button), 'toggled',
+ gtk_SIGNAL_FUNC(@button_toggled_cb), nil);
+
+ gtk_container_add (GTK_CONTAINER (window), check_button);
+
+ gtk_widget_show_all (window);
+
+ (* Add our directory to the list of directories the GConfClient will
+ * watch.
+ *)
+
+ gconf_client_add_dir (client, PATH, GCONF_CLIENT_PRELOAD_NONE, nil);
+
+ { Listen to changes to our key. }
+
+ gconf_client_notify_add (client, KEY, @gconf_notify_func, check_button, nil, nil);
+
+ gtk_main ();
+
+end.
diff --git a/packages/gnome1/examples/gnometest.pp b/packages/gnome1/examples/gnometest.pp
new file mode 100644
index 0000000000..46abc5622d
--- /dev/null
+++ b/packages/gnome1/examples/gnometest.pp
@@ -0,0 +1,30 @@
+Program gnometest;
+
+uses glib, gdk, gtk, libgnome, libgnomeui;
+
+const
+ Authors : Array[0..2] of Pchar = ('me', 'myself', 'I');
+var
+ AboutBox : PGTKWidget;
+ App : PGTKWidget;
+ Appbar : PGTKWidget;
+ Clock : PGTKWidget;
+ calc : PGTKWIdget;
+begin
+ gnome_init('libgnometest', '0.1',argc, argv);
+ App := gnome_app_new('libgnometest', 'gnome-test #1');
+ AppBar := gnome_appbar_new(False, True,GNOME_PREFERENCES_USER);
+ GTK_Widget_show(AppBar);
+ gnome_app_set_statusbar (PGnomeApp(App), Appbar);
+ Clock := gtk_clock_new(GTK_CLOCK_REALTIME);
+ gtk_clock_set_update_interval(GTK_Clock(Clock), 1);
+ gtk_widget_show(Clock);
+ gtk_clock_set_format(GTK_Clock(Clock), '%H:%M:%S');
+ gnome_app_set_contents(Gnome_App(App), Clock);
+ GTK_Widget_Show(App);
+ AboutBox := gnome_about_new(gnome_app_id, nil, 'none', @Authors[0],'blah, blah, blah','/usr/share/icons/dialog_box.xpm');
+ GTK_Widget_Show(AboutBox);
+ gtk_signal_connect(GTK_OBJECT (AboutBox), 'destroy',
+ @gtk_main_quit, nil);
+ gtk_main;
+end.
diff --git a/packages/gnome1/examples/testzvt.pp b/packages/gnome1/examples/testzvt.pp
new file mode 100644
index 0000000000..93d55e2f98
--- /dev/null
+++ b/packages/gnome1/examples/testzvt.pp
@@ -0,0 +1,195 @@
+{
+
+ TestZVT - An FPC Example Program demonstrating the most common use
+ of ZVTTerm in a GNOME application.
+
+ Copyright (C) 2002 Andrew Johnson <aj_genius@hotmail.com>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser 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.
+
+ **********************************************************************}
+Program TestZVT;
+
+(* Try to Execute mc (midnight commander) instead of sh *)
+{$Define exec_mc}
+
+Uses
+ SysUtils,
+
+ { Linux/UNIX Unit, for execvp }
+ {$IfDef ver1_0}linux{$Else}Unix{$EndIF},
+
+ { Standard GTK+ 1.x Interface }
+ glib, gdk, gtk,
+
+ { Standard GNOME 1.x Interface }
+ libgnome, libgnomeui,
+
+ { Standard libzvt 1.x Interface }
+ libzvt;
+
+const
+ (* what to execvp in terminal widget *)
+ {$Ifdef exec_mc}
+ Command : PChar = 'mc';
+ Params : array[0..1] of PChar = ('TERM=xterm', nil);
+ {$else}
+ Command : PChar = 'sh';
+ Params : array[0..0] of PChar = (nil);
+ {$EndIf}
+ Terminals : Longint = 0;//# of terminals currently open
+
+ (* Program Information for GNOME & About Box *)
+ ProgramName : PChar = 'TestZVT';
+ ProgramVersion : PChar = '1.0';
+
+ (* Information for About Box *)
+ Copyright : PChar = 'Copyright (C) 2002 Andrew Johnson';
+ Authors : array[0..1] of PChar = ('Andrew Johnson <aj_genius@hotmail.com>', nil);
+ Comments : PChar = 'An FPC Example Program demonstrating the most common use of ZVTTerm in a GNOME application.';
+
+var
+ app, mdichild : pointer;
+
+Procedure quit_testzvt(Widget : PGTKWidget; Data : Pointer); cdecl;
+begin
+ (* Quite Main Loop *)
+ gtk_main_quit;
+end;
+
+Procedure exit_terminal(Widget : PGTKWidget; Data : Pointer); cdecl;
+begin
+ (* Destroy terminal on process exit, and quit if only terminal open *)
+ gnome_mdi_remove_view(App, Data, 1);
+ Dec(Terminals);
+end;
+
+Procedure close_activechild(Widget : PGTKWidget; Data : Pointer); cdecl;
+begin
+ (* close active view *)
+ exit_terminal(Widget, gnome_mdi_get_active_view(App));
+end;
+
+Procedure new_child(Widget : PGTKWidget; Data : Pointer); cdecl;
+begin
+ (* create new view& set active *)
+ gnome_mdi_add_view(app, mdichild);
+end;
+
+Procedure about_testzvt(Widget : PGTKWidget; Data : Pointer); cdecl;
+var
+ AboutBox : Pointer;
+begin
+ (* Create and Run an About Box *)
+ AboutBox := gnome_about_new(gnome_app_id, ProgramVersion, Copyright,
+ @Authors[0],Comments,nil);
+ gnome_dialog_set_parent(AboutBox, GTK_Window(gnome_mdi_get_active_window(App)));
+ gnome_dialog_run_and_close(AboutBox);
+end;
+
+Procedure show_terminal(Widget : PGTKWidget; Data : Pointer); cdecl;
+begin
+ (* fork terminal process, and Exec Command *)
+ If zvt_term_forkpty(ZVT_TERM(Widget), ZVT_TERM_DO_UTMP_LOG or ZVT_TERM_DO_WTMP_LOG or ZVT_TERM_DO_LASTLOG) = 0 then
+ execvp (Command, @Command, @Params[0]);
+
+ (* close app when fork'ed terminal process finishes/dies *)
+ gtk_signal_connect (GTK_OBJECT(Widget), 'child_died', GTK_SIGNAL_FUNC (@exit_terminal), Data);
+end;
+
+Function NewTerminalView: PGTKWidget; cdecl;
+var
+ hBox, SB, Term : gPointer;
+begin
+ (* Create hbox for layout of Terminal/Scrollbar *)
+ hBox := gtk_hbox_new(FALSE, 0);
+
+ term := zvt_term_new_with_size(80,30);//start with average size
+
+ (* Set up terminal options *)
+ zvt_term_set_shadow_type(term, GTK_SHADOW_IN);//give the terminal a small indented frame
+ zvt_term_set_font_name(term, '-misc-fixed-medium-r-normal-*-12-200-*-*-c-75-*-*');
+ zvt_term_set_scrollback(term, 10000);//give a decent amount of scrollback
+ zvt_term_set_scroll_on_keystroke(term, True);//default on most terminals
+ zvt_term_set_scroll_on_output(term, False);//default on most terminals
+ zvt_term_set_background(ZVT_TERM (term), nil, False, 0);//ensure is not transparent
+
+ gtk_signal_connect_after(term, 'show', GTK_SIGNAL_FUNC (@show_terminal), hBox);
+ (* Create scrollbar *)
+ sb := gtk_vscrollbar_new(GTK_ADJUSTMENT (ZVT_TERM(term)^.adjustment));
+
+ GTK_WIDGET_UNSET_FLAGS(sb, GTK_CAN_FOCUS);//Should never capture keyboard
+
+ (* Pack Box *)
+ gtk_box_pack_start(hBox, term, TRUE, TRUE, 0);
+ gtk_box_pack_start(hBox, sb, FALSE, TRUE, 0);
+ gtk_object_set_data(hbox, 'caption', Pchar('Terminal #' + IntToStr(Terminals)));
+ gtk_widget_show_all(hBox);
+ NewTerminalView := hBox;
+ Inc(Terminals);
+end;
+
+Function CreateMDIChildWidget : Pointer;
+var
+ child : Pointer;
+begin
+ child := gnome_mdi_generic_child_new('Terminal');
+ gnome_mdi_generic_child_set_view_creator(child, @NewTerminalView, nil);
+ CreateMDIChildWidget := child;
+end;
+
+var
+ file_menu : array[0..4] of TGnomeUIInfo;
+ help_menu : array[0..1] of TGnomeUIInfo;
+ Menus : array[0..2] of TGnomeUIInfo;
+begin
+ (* Initialize GNOME with Current Program Name and Version *)
+ gnome_init(ProgramName, ProgramVersion, argc, argv);
+
+ (* Create Main App *)
+ app := gnome_mdi_new(gnome_app_id, 'FPC GNOME ZVT Test');
+ gtk_signal_connect(app, 'destroy', GTK_SIGNAL_FUNC (@quit_testzvt), nil);
+
+ (* Create Stock Menus *)
+ file_menu[0] := GNOMEUIINFO_MENU_NEW_ITEM('New Shell Process', 'Opens a new shell process', @new_child, nil);
+ file_menu[1] := GNOMEUIINFO_MENU_CLOSE_ITEM(@close_activechild,nil);
+ file_menu[2] := GNOMEUIINFO_SEPARATOR;
+ file_menu[3] := GNOMEUIINFO_MENU_EXIT_ITEM(@quit_testzvt,nil);
+ file_menu[4] := GNOMEUIINFO_END;
+
+ help_menu[0] := GNOMEUIINFO_MENU_ABOUT_ITEM(@about_testzvt, app);
+ help_menu[1] := GNOMEUIINFO_END;
+
+ menus[0] := GNOMEUIINFO_MENU_FILE_TREE(@file_menu[0]);
+ menus[1] := GNOMEUIINFO_MENU_HELP_TREE(@help_menu[0]);
+ menus[2] := GNOMEUIINFO_END;
+
+ mdichild := CreateMDIChildWidget;
+
+ (* Set App Menu/Contents, and Show All *)
+ gnome_mdi_set_mode(App, GNOME_MDI_NOTEBOOK);
+ gnome_mdi_set_menubar_template(App, @Menus[0]);
+ gnome_mdi_open_toplevel(app);
+ gnome_mdi_add_child(app, mdichild);
+ gnome_mdi_add_view(app, mdichild);
+ gnome_mdi_add_view(app, mdichild);
+
+ (* Run Main Loop *)
+ gtk_main();
+
+ (* cleanup and exit *)
+ gtk_exit(0);
+end.