mirror of
https://github.com/ToshioCP/Gtk4-tutorial.git
synced 2025-01-12 20:03:28 +01:00
Update GFM files by rake.
This commit is contained in:
parent
2f27d6db62
commit
18a22b63c9
10 changed files with 36 additions and 34 deletions
20
gfm/sec10.md
20
gfm/sec10.md
|
@ -143,7 +143,7 @@ Whenever the buffer is saved to disk, call gtk_text_buffer_set_modified (buffer
|
|||
|
||||
In Gtk, all objects derived from GObject have class and instance.
|
||||
Instance is memories which has a structure defined by C structure declaration as I mentioned in the previous two subsections.
|
||||
And instance can be generated two or more.
|
||||
An instance can be generated two times or more.
|
||||
Those instances have the same structure.
|
||||
Instance, which is structured memories, only keeps status of the object.
|
||||
Therefore, it is insufficient to define its behavior.
|
||||
|
@ -209,7 +209,7 @@ void (*dispose) (GObject *object);
|
|||
|
||||
The declaration is a bit complicated.
|
||||
The asterisk before the identifier `dispose` means pointer.
|
||||
So, the pointer `disopse` points a function which has one parameter , which points a GObject structure, and returns no value because of void type.
|
||||
So, the pointer `dispose` points to a function which has one parameter , which points a GObject structure, and returns no value because of void type.
|
||||
In the same way, line 23 says `finalize` is a pointer to the function which has one paremeter, which points a GObject structure, and returns no value.
|
||||
|
||||
~~~C
|
||||
|
@ -220,8 +220,8 @@ Look at the declaration of `_GObjectClass` so that you would find that most of t
|
|||
|
||||
- 10: A function pointed by `constructor` is called when the instance is generated. It completes the initialization of the instance.
|
||||
- 22: A function pointed by `dispose` is called when the instance destructs itself. Destruction process is divided into two phases. The first one is called disposing and the instance releases all the references to other instances. The second one is finalizing.
|
||||
- 23: A funtion pointed by `finalize` finishes the destruction process.
|
||||
- The other pointers point functions which are called while the instance lives.
|
||||
- 23: A function pointed by `finalize` finishes the destruction process.
|
||||
- The other pointers point to functions which are called while the instance lives.
|
||||
|
||||
## TfeTextView class
|
||||
|
||||
|
@ -336,7 +336,7 @@ The following is extracts from the source files (not exactly the same).
|
|||
101 gpointer padding[8];
|
||||
102 };
|
||||
103
|
||||
104 /* The following definition is generated by the macro G_DECLARE_FINAL_TYPE
|
||||
104 /* The following definition is generated by the macro G_DECLARE_FINAL_TYPE */
|
||||
105 typedef struct {
|
||||
106 GtkTextView parent_class;
|
||||
107 } TfeTextViewClass;
|
||||
|
@ -347,7 +347,7 @@ The following is extracts from the source files (not exactly the same).
|
|||
So, they are not written in either `tfe_text_view.h` or `tfe_text_view.c`.
|
||||
- 2, 73, 106: Each derived class puts its parent class at the first member of its structure.
|
||||
It is the same as instance structures.
|
||||
- Class members in ancesters are open to the descendent class.
|
||||
- Class members in ancestors are open to the descendent class.
|
||||
So, they can be changed in `tfe_text_view_class_init` function.
|
||||
For example, the `dispose` pointer in GObjectClass will be overridden later in `tfe_text_view_class_init`.
|
||||
(Override is an object oriented programing terminology.
|
||||
|
@ -355,7 +355,7 @@ Override is rewriting ancestors' class methods in the descendent class.)
|
|||
- Some class methods are often overridden.
|
||||
`set_property`, `get_property`, `dispose`, `finalize` and `constructed` are such methods.
|
||||
|
||||
TfeTextViewClass includes its ancsestors' class in it.
|
||||
TfeTextViewClass includes its ancestors' class in it.
|
||||
It is illustrated in the following diagram.
|
||||
|
||||
![The structure of TfeTextView Class](../image/TfeTextViewClass.png)
|
||||
|
@ -363,8 +363,8 @@ It is illustrated in the following diagram.
|
|||
## Destruction of TfeTextView
|
||||
|
||||
Every Object derived from GObject has a reference count.
|
||||
If an object A uses an object B, then A keeps a pointr to B in A and at the same time increaces the reference count of B by one with the function `g_object_ref (B)`.
|
||||
If A doesn't need B any longer, then A discards the pointer to B (usually it is done by assigning NULL to the pointer) and decreaces the reference count of B by one with the function `g_object_unref (B)`.
|
||||
If an object A uses an object B, then A keeps a pointer to B in A and at the same time increases the reference count of B by one with the function `g_object_ref (B)`.
|
||||
If A doesn't need B any longer, then A discards the pointer to B (usually it is done by assigning NULL to the pointer) and decreases the reference count of B by one with the function `g_object_unref (B)`.
|
||||
|
||||
If two objects A and B refer to C, then the reference count of C is two.
|
||||
After A used C and if A no longer needs C, A discards the pointer to C and decreases the reference count in C by one.
|
||||
|
@ -403,7 +403,7 @@ You must write the code in the dispose handler `tfe_text_view_dispose`.
|
|||
- 8: invoke parent's despose handler. (This will be explained later.)
|
||||
|
||||
In the desposing process, the object uses the pointer in its class to call the handler.
|
||||
Therefore, `tfe_text_view_dispose` needs to be registerd in the class when the TfeTextView class is initialized.
|
||||
Therefore, `tfe_text_view_dispose` needs to be registered in the class when the TfeTextView class is initialized.
|
||||
The function `tfe_text_view_class_init` is the class initialization function and it is declared in the replacement produced by `G_DEFINE_TYPE` macro.
|
||||
|
||||
~~~C
|
||||
|
|
|
@ -79,7 +79,7 @@ Parameter:
|
|||
Return value:
|
||||
|
||||
- A pointer to the generated TfeTextView object but it is casted to a pointer to GtkWidget.
|
||||
If an error occures during the genration process, NULL is returned.
|
||||
If an error occurs during the generation process, NULL is returned.
|
||||
|
||||
Each function is defined as follows.
|
||||
|
||||
|
@ -148,7 +148,7 @@ void tfe_text_view_saveas (TfeTextView *tv)
|
|||
|
||||
`saveas` function uses GtkFileChooserDialog and lets the user to give a new file to the program. Then, the function changes `tv->file` and save the contents to the specified new file.
|
||||
|
||||
If an error occures, it is shown to the user through the message dialog.
|
||||
If an error occurs, it is shown to the user through the message dialog.
|
||||
The error is managed only in the object and no information is notified to the caller.
|
||||
|
||||
~~~C
|
||||
|
|
|
@ -38,7 +38,7 @@ It connects the command line given by the user and GTK application.
|
|||
- 12: Run the application.
|
||||
- 13-14: release the reference to the application and return the status.
|
||||
|
||||
## statup signal handler
|
||||
## startup signal handler
|
||||
|
||||
Startup signal is emitted just after the application is generated.
|
||||
What the signal handler needs to do is initialization of the application.
|
||||
|
@ -98,7 +98,7 @@ CSS will be explained in the next subsection.
|
|||
|
||||
## CSS in GTK
|
||||
|
||||
CSS is an abbretiation of Cascading Style Sheet.
|
||||
CSS is an abbreviation of Cascading Style Sheet.
|
||||
It is originally used with HTML to describe the presentation semantics of a document.
|
||||
You might have found that the widgets in GTK is simialr to the window in a browser.
|
||||
It implies that CSS can also be apllied to GTK windowing system.
|
||||
|
@ -116,7 +116,7 @@ For example GtkTextView has `textview` node.
|
|||
If you want to set style to GtkTextView, set "textview" to the selector.
|
||||
|
||||
~~~css
|
||||
textview {color: yeallow; ...}
|
||||
textview {color: yellow; ...}
|
||||
~~~
|
||||
|
||||
Class, ID and some other things can be applied to the selector like Web CSS. Refer GTK4 API reference for further information.
|
||||
|
|
|
@ -26,12 +26,12 @@ Choose a file in the list and click on `Open` button.
|
|||
Then the file is read and a new Notebook Page appears.
|
||||
- Edit the file and click on `Save` button, then the text is saved to the original file.
|
||||
- Click `Close`, then the Notebook Page disappears.
|
||||
- Click `Close` again, then the `Untitle` Notebook Page disappears and at the same time the appication quits.
|
||||
- Click `Close` again, then the `Untitled` Notebook Page disappears and at the same time the application quits.
|
||||
|
||||
This is a very simple editor.
|
||||
It is a good practice for you to add more features.
|
||||
|
||||
## meson.buld
|
||||
## meson.build
|
||||
|
||||
~~~meson
|
||||
1 project('tfe', 'c')
|
||||
|
|
|
@ -20,6 +20,9 @@ If you install gtk4 to your computer, do it at your own risk.
|
|||
I installed gtk4 under the directory `$HOME/local`.
|
||||
This is a private user area.
|
||||
|
||||
If you want to install it in the system area, `/opt/gtk4` is one of good choices.
|
||||
[Gtk4 API Reference](https://gnome.pages.gitlab.gnome.org/gtk/gtk/gtk-building.html) gives an installation example to `/opt/gtk4`.
|
||||
|
||||
Don't install it to `/usr/local` which is the default.
|
||||
It is used by ubuntu applications, which are not build on gtk4.
|
||||
Therefore, the risk is high and probably bad things will happen.
|
||||
|
@ -53,7 +56,7 @@ After that, compile glib.
|
|||
$ ninja -C _build
|
||||
$ ninja -C _build install
|
||||
|
||||
Set sevral environment variables so that the glib libraries installed can be used by build tools.
|
||||
Set several environment variables so that the glib libraries installed can be used by build tools.
|
||||
Make a text file below and save it as `env.sh`
|
||||
|
||||
# compiler
|
||||
|
@ -94,7 +97,7 @@ Then, compile and install pango.
|
|||
$ ninja -C _build install
|
||||
|
||||
It installs Pnago-1.0.gir under `$HOME/local/share/gir-1.0`.
|
||||
If you installed pango without --prefix option, then it would be located at `/usr/local/share/gir-1.0`.
|
||||
If you installed pango without `--prefix` option, then it would be located at `/usr/local/share/gir-1.0`.
|
||||
This directory (/usr/local/share) is used by applications.
|
||||
They find the directory by the environment variable `XDG_DATA_DIRS`.
|
||||
It is a text file which keep the list of 'share' directoryes like `/usr/share`, `usr/local/share` and so on.
|
||||
|
|
|
@ -239,7 +239,7 @@ This is a recommended way.
|
|||
|
||||
#### Connect it to GtkApplication.
|
||||
|
||||
The function `gtk_window_set_application` is used to connect GtkWidow to GtkApplication.
|
||||
The function `gtk_window_set_application` is used to connect GtkWindow to GtkApplication.
|
||||
|
||||
~~~C
|
||||
gtk_window_set_application (GTK_WINDOW (win), GTK_APPLICATION (app));
|
||||
|
|
|
@ -6,7 +6,7 @@ Up: [Readme.md](../Readme.md), Prev: [Section 3](sec3.md), Next: [Section 5](se
|
|||
|
||||
### GtkLabel
|
||||
|
||||
We made an window and show it on the screen in the previous section.
|
||||
We made a window and show it on the screen in the previous section.
|
||||
Now we go on to the next topic, widgets in the window.
|
||||
The simplest widget is GtkLabel.
|
||||
It is a widget with a string in it.
|
||||
|
@ -90,7 +90,7 @@ Child widgets are always located inside its parent widget in the screen.
|
|||
See the window appeared on the screen.
|
||||
The window includes the label.
|
||||
|
||||
The window `win` dosen't have any parents.
|
||||
The window `win` doesn't have any parents.
|
||||
We call such a window top-level window.
|
||||
One application can have two or more top-level windows.
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ Up: [Readme.md](../Readme.md), Prev: [Section 5](sec5.md), Next: [Section 7](se
|
|||
|
||||
GtkTextView, GtkTextBuffer and GtkScrolledWindow have given us a minimum editor in the previous section.
|
||||
Next, we will add a read function to this program and remake it into a file viewer.
|
||||
There are many way to implement the function.
|
||||
However, because this is a tutorial for beginners, we take the simplest way.
|
||||
There are many ways to implement the function.
|
||||
However, because this is a tutorial for beginners, we'll take the easiest one.
|
||||
|
||||
When the program starts, we give a filename as an argument.
|
||||
|
||||
|
@ -76,7 +76,7 @@ The parameters are as follows:
|
|||
|
||||
- application --- the application (usually GtkApplication)
|
||||
- files --- an array of GFiles. [array length=n\_files] [element-type GFile]
|
||||
- n\_files --- the length of files
|
||||
- n\_files --- the number of files
|
||||
- hint --- a hint provided by the calling instance (usually it can be ignored)
|
||||
- user\_data --- user data set when the signal handler was connected.
|
||||
|
||||
|
|
12
gfm/sec7.md
12
gfm/sec7.md
|
@ -43,11 +43,11 @@ What we are thinking about now is "child object".
|
|||
A child object includes its parent object.
|
||||
And a child object derives everything from the parent object.
|
||||
|
||||
![Child widget of GtkTwxtView](../image/child.png)
|
||||
![Child widget of GtkTextView](../image/child.png)
|
||||
|
||||
We will define TfeTextView as a child object of GtkTextView.
|
||||
It has everything that GtkTextView has.
|
||||
For example, TfeTextView has GtkTextbuffer correspods to GtkTextView inside TfeTextView.
|
||||
For example, TfeTextView has GtkTextbuffer corresponds to GtkTextView inside TfeTextView.
|
||||
And important thing is that TfeTextView can have a memory to keep a pointer to GFile.
|
||||
|
||||
However, to understand the general theory about gobjects is very hard especially for beginners.
|
||||
|
@ -96,7 +96,7 @@ tfe_text_view_new (void) {
|
|||
~~~
|
||||
|
||||
If you are curious about the background theory of this program, It's very good for you.
|
||||
Because to know the theory is very important for you to program GTK applications.
|
||||
Because knowing the theory is very important for you to program GTK applications.
|
||||
Look at GObject API reference.
|
||||
All you need is described in it.
|
||||
However, it's a tough journey especially for beginners.
|
||||
|
@ -142,8 +142,8 @@ In this code no property needs to be initialized.
|
|||
And the return value must be casted to GtkWidget.
|
||||
|
||||
This program is not perfect.
|
||||
It has some problem.
|
||||
But I don't discuss it now.
|
||||
It has some problems.
|
||||
But I don't discuss them now.
|
||||
It will be modified later.
|
||||
|
||||
## Close-request signal
|
||||
|
@ -153,7 +153,7 @@ GtkWindow emits "close-request" signal before it closes.
|
|||
We connect the signal and the handler `before_close`.
|
||||
A handler is a C function.
|
||||
When a function is connected to a certain signal, we call it handler.
|
||||
The function `before_close` is invoked when the signal "close-request" is emittd.
|
||||
The function `before_close` is invoked when the signal "close-request" is emitted.
|
||||
|
||||
~~~C
|
||||
g_signal_connect (win, "close-request", G_CALLBACK (before_close), NULL);
|
||||
|
|
|
@ -5,7 +5,7 @@ Up: [Readme.md](../Readme.md), Prev: [Section 7](sec7.md), Next: [Section 9](se
|
|||
## New, open and save button
|
||||
|
||||
We made the simplest editor in the previous section.
|
||||
It reads the files in `on_open` funciton at start-up and writes it at closing window.
|
||||
It reads the files in `on_open` function at start-up and writes it when closing the window.
|
||||
It works but is not good.
|
||||
It is better to make "New", "Open", "Save" and "Close" buttons.
|
||||
This section describes how to put those buttons into the window.
|
||||
|
@ -200,8 +200,7 @@ First, let's look at the ui file `tfe3.ui` that defines a structure of the widge
|
|||
~~~
|
||||
|
||||
This is coded with XML structure.
|
||||
Constructs begin with `<` and end with `>` is called tags.
|
||||
And it is divided into two parts, start tag and end tag.
|
||||
Constructs beginning with `<` and ending with `>` are called tags, and are divided into two parts, start tag and end tag.
|
||||
For example, `<interface>` is a start tag and `</interface>` is an end tag.
|
||||
Ui file begins and ends with interface tags.
|
||||
Some tags, for example, object tags can have a class and id attributes inside the start tag.
|
||||
|
|
Loading…
Reference in a new issue