Programming GTK+ Implementation of A Text Editor: Mohamed A. Aslan February 17, 2005
Programming GTK+ Implementation of A Text Editor: Mohamed A. Aslan February 17, 2005
Mohamed A. Aslan
1 Introduction 9
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2 Requirements for this book . . . . . . . . . . . . . . . . . . . . 9
1.3 Compiling The Examples . . . . . . . . . . . . . . . . . . . . . 10
1.4 Outline of the book . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Windows 11
2.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Labels 17
3.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4 Entries 19
4.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5 Text View 21
5.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 22
6 Buttons 25
6.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7 Status Bars 31
7.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3
4 CONTENTS
8 Tool Bars 33
8.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
8.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9 Menus 37
9.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
9.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 38
10 Scrolled Windows 39
10.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
10.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 39
11 Boxes 41
11.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
11.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 42
12 Tables 45
12.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
12.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 46
13 Signals 49
13.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
13.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 50
14 File Selection 51
14.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
14.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 51
15 Font Selection 55
15.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
15.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 55
16 Text Editor 59
16.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
16.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 59
List of Figures
2.1 Window 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Window 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3 Window 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1 Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.1 Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.1 Button 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6.2 Button 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
9.1 Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
11.1 Box 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
11.2 Box 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
12.1 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
13.1 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5
6 LIST OF FIGURES
2.1 Window 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2 Window 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Window 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1 Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.1 Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.1 Text View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
6.1 Button 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6.2 Button 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.1 Status Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
8.1 Tool Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9.1 Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
10.1 Scrolled Window . . . . . . . . . . . . . . . . . . . . . . . . . 39
11.1 Box 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
11.2 Box 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
12.1 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
13.1 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
14.1 File Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
15.1 Font Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
16.1 textedit.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
16.2 textedit.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7
8 LISTINGS
Chapter 1
Introduction
1.1 Introduction
Gtk+ The Gimp Toolkit is a library for creating GUI applications, It uses
the xlib which is the main library for GUI. Gtk+ works on many UNIX-like
platforms as Linux, BSD, and it also runs on Windows and MacOSX.
Gtk+ is released unders the terms of the GNU library General Public License
(LGPL), which means that is free and open source library, and you can
modify it as you like under the terms of LGPL license. Gtk+ ues a C-based
object-oriented architecture, it also can be used by other languages rather
than C, including C++, Objective-C, Guile/Scheme, Perl, Pythin, TOM,
Ada95, Pascal and Eiffel.
For more information and advanced topics you should consult the Gtk+
manual reference found at : http://www.gtk.org
4. GCC
9
10 CHAPTER 1. INTRODUCTION
. / example
And not
example
Windows
2.1 Description
Every object in Gtk+ is called Widget and every widget has its type.
We use gtk set locale() function for the Initialization of the international-
ization support for Gtk+. gtk init() will initialize everything needed to op-
erate Gtk+ and parses some standard command line options: argc, argv.
gtk widget show all() which shows the widget with all of its components.
And gtk main() which runs the Gtk main loop till gtk main quit() is called.
These functions are very important functions and will be used in all of the
examples included in this book.
This function creates a Gtk+ toplevel window and returns its handle.
this function is used to set the default size of the Gtk+ window.
11
12 CHAPTER 2. WINDOWS
GTK_WINDOW ( )
The first one sets the window position to the center of the screen, the second
one sets the window position under the mouse cursor, while the third keep
the window centred even its size changed.
2.2 Implementation
Example 1
Example 2
1 #i n c l u d e <g t k / g t k . h>
2 GtkWidget window ;
3 i n t main ( i n t argc , c h a r argv )
4 {
5 gtk_s et_loca le ( ) ;
6 gtk_init (&argc , &argv ) ;
7 window=gtk_ window_n ew ( G T K _ W I N D O W _ T O P L E V E L ) ;
8 g t k _ w i n d o w _ s e t _ t i t l e ( GTK_WINDOW ( window ) , Gtk+ Example 2 ) ;
9 g t k _ w i d g e t _ s h o w _ a l l ( window ) ;
10 gtk_main ( ) ;
11 return 0;
12 }
14 CHAPTER 2. WINDOWS
Example 3
Labels
3.1 Description
Labels is a GtkWidget used to display text.
This function creates a new label with the label text as its argument.
This function attaches a child widget to its parent as: a label to a window.
3.2 Implementation
Example
17
18 CHAPTER 3. LABELS
5 gtk_s et_loca le ( ) ;
6 gtk_init (&argc , &argv ) ;
7 window=gtk_ window_n ew ( G T K _ W I N D O W _ T O P L E V E L ) ;
8 g t k _ w i n d o w _ s e t _ t i t l e ( GTK_WINDOW ( window ) , Gtk+ Example4 ) ;
9 g t k _ w i n d o w _ s e t _ d e f a u l t _ s i z e ( GTK_WINDOW ( window ) , 2 0 0 , 2 0 0 ) ;
10 g t k _ w i n d o w _ s e t _ p o s i t i o n ( GTK_WINDOW ( window ) , G T K _ W I N _ P O S _ C E N T E R ) ;
11 label=gtk_label_new ( HelloWorld ) ;
12 gt k _ c o n t a i n e r _ a d d ( GTK_CONTAINER ( window ) , label ) ;
13 g t k _ w i d g e t _ s h o w _ a l l ( window ) ;
14 gtk_main ( ) ;
15 return 0;
16 }
Entries
4.1 Description
Entries are widgets used to enter text and numbers, Entries have only one
line for entering the text.
GtkWidget gtk_entry_new ( v o i d ) ;
This function is used to set the text that appears in the GtkEntry.
This function is used to append text to the end of the text of the GtkEntry.
This function is used to prepend text to the beginning of the text of the
GtkEntry.
19
20 CHAPTER 4. ENTRIES
4.2 Implementation
Example
Text View
5.1 Description
Text Views are widgets used to enter multi line text unlike text entries with
just one line.
GtkWidget g t k _ t e x t _ v i e w _ n e w ( v o i d ) ;
Buffer is a place for storing the text of the text view in it.
This function sets the buffer of the text view.
GtkTextBuffer g t k _ t e x t _ b u f f e r _ n e w ( G tk Te xt T ag Ta bl e table ) ;
This function creates a new text buffer which can be used with a text view.
This function is used to set the text stored in the text buffer.
This function is used to get the text stored in a text buffer, where GtkTex-
tIter is widget used to store a position in a text buffer, so start points to the
21
22 CHAPTER 5. TEXT VIEW
start of buffer and end points to the end of the buffer which we get text from
it.
5.2 Implementation
Example
Buttons
6.1 Description
Buttons are widgets that you click on them to proceed something.
This function creates a new button, by coping it from the Gtk stock, this
button usually contains a predefined image.
This function creates a new button with label but if the label is preceded by
underscore the following later will be underlined, this underlined character
represents a keyboard accelerator called a mnemonic. Pressing Alt and that
key activates the button.
25
26 CHAPTER 6. BUTTONS
6.2 Implementation
Example 1
Example 2
9 g t k _ w i n d o w _ s e t _ d e f a u l t _ s i z e ( GTK_WINDOW ( window ) , 2 0 0 , 2 0 0 ) ;
10 g t k _ w i n d o w _ s e t _ p o s i t i o n ( GTK_WINDOW ( window ) , G T K _ W I N _ P O S _ C E N T E R ) ;
11 button=g t k _ b u t t o n _ n e w _ f r o m _ s t o c k ( GTK_STOCK_OK ) ;
12 gt k _ c o n t a i n e r _ a d d ( GTK_CONTAINER ( window ) , button ) ;
13 g t k _ w i d g e t _ s h o w _ a l l ( window ) ;
14 gtk_main ( ) ;
15 return 0;
16 }
Status Bars
7.1 Description
Status Bars are Gtk+ widgets used to pop messages.
GtkWidget g t k _ s t a t u s b a r _ n e w ( v o i d ) ;
This function pushes text to the status bar, where context id is the message
id.
7.2 Implementation
Example
31
32 CHAPTER 7. STATUS BARS
11 statusbar=g t k _ s t a t u s b a r _ n e w ( ) ;
12 g t k _ s t a t u s b a r _ p u s h ( GTK_STATUSBAR ( statusbar ) , 1 , HelloWorld ) ;
13 gt k _ c o n t a i n e r _ a d d ( GTK_CONTAINER ( window ) , statusbar ) ;
14 g t k _ w i d g e t _ s h o w _ a l l ( window ) ;
15 gtk_main ( ) ;
16 return 0;
17 }
Tool Bars
8.1 Description
Tool Bars is Gtk+ widget, which contains child widgets as buttons.
GtkWidget g tk _t oo l ba r_ ne w ( v o i d ) ;
This function creates a new tool bar and returns its handle.
This function is the same as the previous one, but it prepends the item.
This function insert Gtk+ stock item in the toolbar, if the position is -1 the
item will be attached at the end of the toolbar.
33
34 CHAPTER 8. TOOL BARS
This function sets the style of a toolbar whether it contains only icons or
only text or both icons and text.
8.2 Implementation
Example
Menus
9.1 Description
Menu bars are Gtk+ widgets that contains items called menus, that contain
menu items, which we can attach a submenu to it.
GtkWidget g t k _ m e n u _ b a r _ ne w ( v o i d ) ;
GtkWidget gtk_menu_new ( v o i d ) ;
37
38 CHAPTER 9. MENUS
This function creates a menu item with image from the Gtk+ stock, where
accel group contains the keyboard accelerator group, which is the button
combination used to activate the menu items.
9.2 Implementation
Example
Scrolled Windows
10.1 Description
Scrolled window is just a parent container for other widget, scrolled window
is mostly used to contain text view, where it adds scroll bars to it.
This function creates a new scrolled window with the first argument is the
horizontal adjustment while the second is the vertical adjustment.
Note: we pass to both arguments null to cause the scrolled window to create
them for us.
10.2 Implementation
Example
39
40 CHAPTER 10. SCROLLED WINDOWS
13 g t k _ w i d g e t _ s h o w _ a l l ( window ) ;
14 gtk_main ( ) ;
15 return 0;
16 }
Boxes
11.1 Description
What about adding more than widget to the same window ?
Boxes are widgets which enables you to add more than widget to a window.
This function creates a horizontal box where widgets are added horizontally,
setting homogeneous into true makes all children are to be given equal space
allotments, the spacing is the number of pixels to place by default between
children widgets.
This function creates a vertical box where widgets are added vertically.
This function adds a child widget to the box, if expand is set to true the child
will be given extra space allocated to box, this space will be divided evenly
between all children of box, if fill is set to true the space given to child by
the expand option is actually allocated to child, rather than just padding it.
This parameter has no effect if expand is set to FALSE, padding is the extra
space in pixels to put between this child and its neighbours.
41
42 CHAPTER 11. BOXES
11.2 Implementation
Example 1: HBox
1 #i n c l u d e <g t k / g t k . h>
2 GtkWidget window , hbox , button1 , button2 ;
3 i n t main ( i n t argc , c h a r argv )
4 {
5 gtk_s et_loca le ( ) ;
6 gtk_init (&argc , &argv ) ;
7 window=gtk_ window_n ew ( G T K _ W I N D O W _ T O P L E V E L ) ;
8 g t k _ w i n d o w _ s e t _ d e f a u l t _ s i z e ( GTK_WINDOW ( window ) , 1 0 0 , 1 0 0 ) ;
9 g t k _ w i n d o w _ s e t _ p o s i t i o n ( GTK_WINDOW ( window ) , G T K _ W I N _ P O S _ C E N T E R ) ;
10 button1=g t k _ b u t t o n _ n e w _ f r o m _ s t o c k ( GTK_STOCK_OK ) ;
11 button2=g t k _ b u t t o n _ n e w _ w i t h _ l a b e l ( HellWorld ) ;
12 hbox=gtk_hbox_new ( FALSE , 0 ) ;
13 g t k _ b o x _ p a c k _ s t a r t ( GTK_BOX ( hbox ) , button1 , FALSE , FALSE , 0 ) ;
14 g t k _ b o x _ p a c k _ s t a r t ( GTK_BOX ( hbox ) , button2 , FALSE , FALSE , 0 ) ;
15 gt k _ c o n t a i n e r _ a d d ( GTK_CONTAINER ( window ) , hbox ) ;
16 g t k _ w i d g e t _ s h o w _ a l l ( window ) ;
17 gtk_main ( ) ;
18 return 0;
19 }
Example 2: VBox
Tables
12.1 Description
Tables are widgets used to attack child widgets to parent ones, tables differ
from boxes where tables can add widgets beside each other and upwards each
others , which means table is able to add widgets horizontally and vertically
at the same time.
This function creates a new table where rows is the number of rows and
columns is the number of columns of this table, while if homogeneous is set
into true which makes all children are to be given equal space allotments, the
spacing is the number of pixels to place by default between children widgets.
45
46 CHAPTER 12. TABLES
12.2 Implementation
Example
Signals
13.1 Description
What happens if you click on button, it emits a signal which call what is
called callback function.
#d e f i n e g s i g n a l c o n n e c t ( i n s t a n c e , d e t a i l e d s i g n a l , c h a n d l e r , data ) ;
The call back function is the function called by Gtk+ when a certain event
happens, this function should be connected to the widget and the signal name
first.
Some Signals
activate : As clicked but for menu items
clicked
pressed
released
49
50 CHAPTER 13. SIGNALS
13.2 Implementation
Example
File Selection
14.1 Description
File selection is a dialog used to select files either for opening or saving.
This function creates a new file selection with title, but the file selection need
its on gtk widget show all()
This function gets the complete path and name of the selected file.
14.2 Implementation
Example
51
52 CHAPTER 14. FILE SELECTION
10 window=gtk_ window_n ew ( G T K _ W I N D O W _ T O P L E V E L ) ;
11 g t k _ w i n d o w _ s e t _ d e f a u l t _ s i z e ( GTK_WINDOW ( window ) , 2 0 0 , 1 0 0 ) ;
12 vbox=gtk_vbox_new ( FALSE , 0 ) ;
13 gt k _ c o n t a i n e r _ a d d ( GTK_CONTAINER ( window ) , vbox ) ;
14 label=gtk_label_new ( NULL ) ;
15 g t k _ b o x _ p a c k _ s t a r t ( GTK_BOX ( vbox ) , label , FALSE , FALSE , 0 ) ;
16 button=g t k _ b u t t o n _ n e w _ w i t h _ l a b e l ( S e l e c t F i l e ) ;
17 g t k _ b o x _ p a c k _ s t a r t ( GTK_BOX ( vbox ) , button , FALSE , FALSE , 0 ) ;
18 g_ s i g n a l _ c o n n e c t ( G_OBJECT ( button ) , c l i c k e d , G_CALLBACK ( -
o p e n _ f i l e _ s e l e c t ) , NULL ) ;
19 g t k _ w i d g e t _ s h o w _ a l l ( window ) ;
20 gtk_main ( ) ;
21 return 0;
22 }
23 v o i d o p e n _ f i l e _ s e l e c t ( GtkWidget widget , gpointer data )
24 {
25 file_select=g t k _ f i l e _ s e l e c t i o n _ n e w ( S e l e c t A F i l e ) ;
26 file_ select_ ok=G T K _ F I L E _ S E L E C T I O N ( file_select )>ok_button ;
27 f i l e _ s e l e c t _ c a n c e l=G T K _ F I L E _ S E L E C T I O N ( file_select )>cancel_button ;
28 g_ s i g n a l _ c o n n e c t ( G_OBJECT ( file _select_ ok ) , c l i c k e d , G_CALLBACK ( -
get_filename ) , NULL ) ;
29 g_ s i g n a l _ c o n n e c t ( G_OBJECT ( f i l e _ s e l e c t _ c a n c e l ) , c l i c k e d , G_CALLBACK ( -
f i l e _ s e l e c t _ e x i t ) , NULL ) ;
30 g t k _ w i d g e t _ s h o w _ a l l ( file_select ) ;
31 }
32 v o i d get_filename ( GtkWidget widget , gpointer data )
33 {
34 c o n s t gchar filename ;
35 filename=g t k _ f i l e _ s e l e c t i o n _ g e t _ f i l e n a m e ( G T K _ F I L E _ S E L E C T I O N ( -
file_select ) ) ;
36 g t k _ l a b e l _ s e t _ t e x t ( GTK_LABEL ( label ) , filename ) ;
37 g t k _ w i d g e t _ d e s t r o y ( file_select ) ;
38 }
39 v o i d f i l e _ s e l e c t _ e x i t ( GtkWidget widget , gpointer data )
40 {
41 g t k _ w i d g e t _ d e s t r o y ( file_select ) ;
42 }
Font Selection
15.1 Description
Font selection dialog is a widget like file selection, but it is used to select
fonts not files.
gchar g t k _ f o n t _ s e l e c t i o n _ d i a l o g _ g e t _ f o n t _ n a m e ( G t k F o n t S e l e c t i o n D i a l o g fsd-
);
P a n g o F o n t D e s c r i p t i o n p a n g o _ f o n t _ d e s c r i p t i o n _ f r o m _ s t r i n g ( c o n s t c h a r str ) ;
This function returns a pango font description from the string containing the
font name, pango is one of Gtk+ required libraries responsible for font stuff.
v o i d g t k _ w i d g e t _ m o d i f y _ f o n t ( GtkWidget widget , P a n g o F o n t D e s c r i p t i o n -
font_desc ) ;
This function changes the font of a widget using pango font description.
15.2 Implementation
Example
55
56 CHAPTER 15. FONT SELECTION
51 g t k _ w i d g e t _ m o d i f y _ f o n t ( text_view , font_desc ) ;
52 }
53 v o i d f o n t _ s e l e c t _ d l g _ e x i t ( GtkWidget widget , gpointer data )
54 {
55 g t k _ w i d g e t _ d e s t r o y ( f on t_ se l ec t_ dl g ) ;
56 }
Text Editor
16.1 Description
In this chapter we will implement a small and simple text editor to illustrate
what we learned about Gtk+.
16.2 Implementation
Text Editor
59
60 CHAPTER 16. TEXT EDITOR
86 / V a r i a b l e s D e c l a r a t i o n s /
87 c o n s t gchar filename ;
211 }
212 v o i d f o n t _ d l g _ o k _ c l i c k e d ( GtkWidget widget , gpointer data )
213 {
214 gchar fontname ;
215 P a n g o F o n t D e s c r i p t i o n font_desc ;
216 fontname=g t k _ f o n t _ s e l e c t i o n _ d i a l o g _ g e t _ f o n t _ n a m e ( -
G T K _ F O N T _ S E L E C T I O N _ D I A L O G ( font_dlg ) ) ;
217 font_desc=p a n g o _ f o n t _ d e s c r i p t i o n _ f r o m _ s t r i n g ( fontname ) ;
218 g t k _ w i d g e t _ m o d i f y _ f o n t ( text_view , font_desc ) ;
219 g t k _ w i d g e t _ d e s t r o y ( font_dlg ) ;
220 }
221 v o i d f o n t _ d l g _ c a n c e l _ c l i c k e d ( GtkWidget widget , gpointer data )
222 {
223 g t k _ w i d g e t _ d e s t r o y ( font_dlg ) ;
224 }
225 v o i d f o n t _ d l g _ a p p l y _ c l i c k e d ( GtkWidget widget , gpointer data )
226 {
227 gchar fontname ;
228 P a n g o F o n t D e s c r i p t i o n font_desc ;
229 fontname=g t k _ f o n t _ s e l e c t i o n _ d i a l o g _ g e t _ f o n t _ n a m e ( -
G T K _ F O N T _ S E L E C T I O N _ D I A L O G ( font_dlg ) ) ;
230 font_desc=p a n g o _ f o n t _ d e s c r i p t i o n _ f r o m _ s t r i n g ( fontname ) ;
231 g t k _ w i d g e t _ m o d i f y _ f o n t ( text_view , font_desc ) ;
232 }
233
234 / The Text E d i t F u n c t i o n s /
235
236 v o i d text_edit_new ( )
237 {
238 tex t_ ed i t_ cl os e ( ) ;
239 }
240 v o i d text_ edit_op en ( )
241 {
242 / F i r s t C l o s e The Openned F i l e /
243 tex t_ ed i t_ cl os e ( ) ;
244 / C r e a t e The Open F i l e D i a l o g /
245 open_file_dlg=g t k _ f i l e _ s e l e c t i o n _ n e w ( Open F i l e . . . ) ;
246 o p e n _ f i l e _ d l g _ o k=G T K _ F I L E _ S E L E C T I O N ( open_file_dlg )>ok_button ;
247 o p e n _ f i l e _ d l g _ c a n c e l=G T K _ F I L E _ S E L E C T I O N ( open_file_dlg )>cancel_button ;
248 / Open F i l e D i a l o g C l i c k e d S i g n a l s /
249 g _ s i g n a l _ c o n n e c t ( G_OBJECT ( o p e n _ f i l e _ d l g _o k ) , c l i c k e d , G_CALLBACK ( -
o p e n _ f i l e _ d l g _ o k _ c l i c k e d ) , NULL ) ;
250 g _ s i g n a l _ c o n n e c t ( G_OBJECT ( o p e n _ f i l e _ d l g _ c a n c e l ) , c l i c k e d , G_CALLBACK-
( o p e n _ f i l e _ d l g _ c a n c e l _ c l i c k e d ) , NULL ) ;
251 g t k _ w i d g e t _ s h o w _ a l l ( open_file_dlg ) ;
252 }
253 v o i d text_ edit_sa ve ( )
254 {
255 i f ( filename==NULL )
256 {
257 text_edit_saveas ( ) ;
258 }
259 else
260 {
261 FILE fp ;
262 gchar text ;
263 GtkTextBuffer buffer ;
264 GtkTextIter start , end ;
265 buffer=g t k _ t e x t _ v i e w _ g e t _ b u f f e r ( GTK_TEXT_VIEW ( text_view ) ) ;
266 g t k _ t e x t _ b u f f e r _ g e t _ s t a r t _ i t e r ( buffer , &start ) ;
267 g t k _ t e x t _ b u f f e r _ g e t _ e n d _ i t e r ( buffer , &end ) ;
268 text=g t k _ t e x t _ b u f f e r _ g e t _ t e x t ( buffer , &start , &end , TRUE ) ;
66 CHAPTER 16. TEXT EDITOR