Skip to content

Commit 4a32314

Browse files
authored
Revert "change to Gtk4 (#2) (#3)" (#4)
This reverts commit 1ce58fd.
1 parent 1ce58fd commit 4a32314

File tree

5 files changed

+63
-83
lines changed

5 files changed

+63
-83
lines changed

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
GIT Testprojekt
44

55
## Change log
6-
Version Branch Änderung
7-
0.0.2 main Gtk Grundgerüst
8-
0.0.4 feature-gtk4 Umstellung auf gtk4
9-
'apt install libgtk-4-1 libgtk-4-dev libgtk-4-bin libgtk-4-common'
6+
Version Branch Änderung
7+
0.0.2 main Gtk Grundgerüst

GITHELP.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
# GIT Help
22

3-
Marker : feature-keybord branch
4-
5-
Noch eine Änderung
6-
7-
## Strategie
8-
9-
10-
113
## First steps
124

135
git init

main.c

Lines changed: 49 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,85 @@
11
#include <gtk/gtk.h>
2-
// https://docs.gtk.org/gtk4/
3-
4-
#define BUTTON_NUM 20
52

63
GtkWidget *window;
74
GtkWidget *entry;
85
GtkWidget *button;
96
GtkWidget *grid;
10-
GtkWidget *buttons[BUTTON_NUM];
7+
GtkWidget *buttons[10];
118
GtkWidget *box;
129

13-
const char *buttonlabels[BUTTON_NUM] = {"C","/","*","-","7","8","9","+","4","5","6","(","1","2","3",")"," ","0",",","="};
14-
1510
// Funktion zum Behandeln des Button-Klicks
16-
void button_clicked(GtkWidget *button, gpointer data)
17-
{
18-
const char *text = gtk_editable_get_text(GTK_EDITABLE(data));
11+
void button_clicked(GtkWidget *button, gpointer data) {
12+
const char *text = gtk_entry_get_text(GTK_ENTRY(data));
1913
printf("Der eingegebene Text ist: %s\n", text);
2014
}
2115

2216
// Funktion zum Behandeln der Ziffern-Buttons
23-
void number_button_clicked(GtkWidget *button, gpointer data)
24-
{
25-
const char *label = gtk_button_get_label(GTK_BUTTON(button));
26-
char button_char = *label;
27-
switch (button_char) {
28-
case 'C':
29-
// gtk_entry_set_text (GTK_ENTRY(data), "");
30-
gtk_editable_set_text(GTK_EDITABLE(data), "");
31-
break;
32-
default:
33-
GtkEntryBuffer *buffer = gtk_entry_get_buffer (GTK_ENTRY(data));
34-
gtk_entry_buffer_insert_text (buffer, -1, label, -1);
35-
}
17+
void number_button_clicked(GtkWidget *button, gpointer data) {
18+
const char *number = gtk_button_get_label(GTK_BUTTON(button));
19+
gtk_entry_set_text(GTK_ENTRY(data), number);
20+
// gtk_entry_append_text(GTK_ENTRY(data), number);
3621
}
3722

38-
static void activate (GtkApplication *app, gpointer user_data)
39-
{
23+
int main(int argc, char *argv[]) {
24+
gtk_init(&argc, &argv);
25+
4026
// Erstellen Sie ein Fenster
41-
window = gtk_application_window_new (app);
42-
gtk_window_set_title(GTK_WINDOW(window), "Hello World Gtk4");
43-
gtk_window_set_default_size(GTK_WINDOW(window), 320, 100);
27+
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
28+
gtk_window_set_title(GTK_WINDOW(window), "Hello World");
29+
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
4430

45-
// Erstellt ein Eingabefeld
31+
// Erstellen Sie ein Eingabefeld
4632
entry = gtk_entry_new();
4733

48-
// Erstellt einen Button
34+
// Erstellen Sie einen Button
4935
button = gtk_button_new_with_label("Eingabe ausgeben");
50-
51-
// Verbindt den Button-Klick mit der Funktion button_clicked
36+
37+
// Verbinden Sie den Button-Klick mit der Funktion button_clicked
5238
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), entry);
5339

54-
// Erstellt ein GtkGrid-Widget für den Tastenblock
40+
// Verbinden Sie den delete-event-Handler mit gtk_main_quit()
41+
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
42+
43+
/**/
44+
45+
// Erstellen Sie ein GtkGrid-Widget für den Tastenblock
5546
grid = gtk_grid_new();
5647
gtk_grid_set_column_spacing(GTK_GRID(grid), 5);
5748
gtk_grid_set_row_spacing(GTK_GRID(grid), 5);
5849

59-
for (int i = 0; i < BUTTON_NUM; i++) {
60-
// Erstellen der Buttons
61-
buttons[i] = gtk_button_new_with_label(buttonlabels[i]);
50+
// Erstellen Sie 10 Buttons für die Ziffern 0-9
51+
for (int i = 0; i < 10; i++) {
52+
buttons[i] = gtk_button_new_with_label(g_strdup_printf("%d", i));
6253
g_signal_connect(buttons[i], "clicked", G_CALLBACK(number_button_clicked), entry);
54+
}
6355

64-
// Fügt die Buttons in das Grid-Widget ein
65-
gtk_grid_attach(GTK_GRID(grid), buttons[i], i % 4, i / 4, 1, 1);
56+
// Fügen Sie die Buttons in das Grid-Widget ein
57+
int row = 0, column = 0;
58+
for (int i = 0; i < 10; i++) {
59+
gtk_grid_attach(GTK_GRID(grid), buttons[i], column, row, 1, 1);
60+
if (column == 2) {
61+
column = 0;
62+
row++;
63+
} else {
64+
column++;
65+
}
6666
}
6767

68+
/**/
6869
// Erstellen Sie einen Box-Container und fügen Sie das Eingabefeld, den Button und den Tastenblock hinzu
69-
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
70-
gtk_box_append(GTK_BOX(box), entry);
71-
gtk_widget_set_margin_top(entry, 10);
72-
gtk_widget_set_margin_start(entry, 10);
73-
gtk_widget_set_margin_end(entry, 10);
74-
75-
gtk_box_append(GTK_BOX(box), grid);
76-
gtk_widget_set_halign(grid, GTK_ALIGN_CENTER);
77-
gtk_widget_set_margin_top(grid, 10);
78-
gtk_widget_set_margin_bottom(grid, 10);
79-
80-
gtk_box_append(GTK_BOX(box), button);
81-
gtk_widget_set_margin_start(button, 10);
82-
gtk_widget_set_margin_end(button, 10);
83-
gtk_widget_set_margin_bottom(button, 10);
70+
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
71+
gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
72+
gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
73+
gtk_box_pack_start(GTK_BOX(box), grid, TRUE, TRUE, 0);
8474

8575
// Fügen Sie den Box-Container zum Fenster hinzu
86-
gtk_window_set_child (GTK_WINDOW (window), box);
87-
88-
gtk_window_present (GTK_WINDOW (window));
89-
}
90-
76+
gtk_container_add(GTK_CONTAINER(window), box);
9177

92-
int main (int argc, char **argv)
93-
{
94-
GtkApplication *app;
95-
int status;
78+
// Zeigen Sie alle Widgets an
79+
gtk_widget_show_all(window);
9680

97-
app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
98-
g_signal_connect(app, "activate", G_CALLBACK (activate), NULL);
99-
status = g_application_run (G_APPLICATION (app), argc, argv);
100-
g_object_unref (app);
81+
// Starten Sie die GTK+-Hauptschleife
82+
gtk_main();
10183

102-
return status;
103-
}
84+
return 0;
85+
}

makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,27 @@ HDRS = \
1212

1313
# Bibliotheken
1414
LIBS = \
15-
-lgtk4
15+
-lgtk3
1616

1717
# Objektdateien
1818
OBJS = $(SRCS:.c=.o)
1919

2020
# Flagge für GTK+-Entwicklung
21-
GTK3_CFLAGS = -Wall `pkg-config --cflags gtk4`
21+
GTK3_CFLAGS = -Wall `pkg-config --cflags glib-2.0` \
22+
-I/usr/include/gtk-3.0 \
23+
-I/usr/include/glib-2.0 \
24+
-I/usr/include/pango-1.0 \
25+
-I/usr/include/harfbuzz \
26+
-I/usr/include/cairo \
27+
-I/usr/include/gdk-pixbuf-2.0 \
28+
-I/usr/include/atk-1.0
2229

2330
# Flagge für C-Compiler
2431
CFLAGS = $(GTK3_CFLAGS)
2532

2633
# Flagge für Linker
27-
LDFLAGS = `pkg-config --libs gtk4` -L/usr/local/lib -L/usr/lib
34+
LDFLAGS = `pkg-config --libs gtk+-3.0` -L/usr/local/lib -L/usr/lib
35+
#LDFLAGS = `pkg-config --libs glib-2.0` -L/usr/local/lib -L/usr/lib
2836

2937
# Programmname
3038
PROGRAM = $(PROJECT)

settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"c_cpp.includePath": [
3-
"/usr/include/gtk-4.0" // Ersetzen Sie diesen Pfad nach Bedarf
3+
"/usr/include/gtk-3.0" // Ersetzen Sie diesen Pfad nach Bedarf
44
]
55
}

0 commit comments

Comments
 (0)