diff --git a/Gtk4_Reset/src/text_app/TextEditor.cpp b/Gtk4_Reset/src/text_app/TextEditor.cpp index 58a9f2e..710fc4e 100644 --- a/Gtk4_Reset/src/text_app/TextEditor.cpp +++ b/Gtk4_Reset/src/text_app/TextEditor.cpp @@ -3,18 +3,20 @@ #include "../json_nlohmann/json.hpp" #include #include +#include "MyTitleBar.h" using json = nlohmann::json; struct _TextEditor { GtkApplicationWindow parent_instance; - GtkWidget *header; + MyTitleBar *header; GtkWidget *main_box; GtkWidget *text_view, *scrolled_win; GtkTextBuffer *text_buffer; GtkWidget *menu_btn, *popover; GtkBuilder *menu_builder, *expander_builder; + // Input keyboard GtkWidget *expander; GtkWidget *btns[26]; @@ -301,9 +303,9 @@ static void text_editor_init(TextEditor *self) json_file.close(); // Use headerbar for title and more info - self->header = gtk_header_bar_new(); + self->header = my_titlebar_new(); gtk_window_set_title(GTK_WINDOW(self), "Text editor"); - gtk_window_set_titlebar(GTK_WINDOW(self), self->header); + my_titlebar_set_window(self->header, self); gtk_window_set_default_size(GTK_WINDOW(self), width, height); // Add Actions for menu @@ -323,8 +325,7 @@ static void text_editor_init(TextEditor *self) // Add menu button self->menu_btn = gtk_menu_button_new(); gtk_menu_button_set_icon_name(GTK_MENU_BUTTON(self->menu_btn), "open-menu"); - gtk_header_bar_pack_end(GTK_HEADER_BAR(self->header), self->menu_btn); - gtk_header_bar_set_show_title_buttons(GTK_HEADER_BAR(self->header), TRUE); + my_titlebar_pack_end(self->header, self->menu_btn); // Add a menu self->menu_builder = gtk_builder_new_from_resource("/org/gtk/daleclack/text_menu.xml"); @@ -341,7 +342,7 @@ static void text_editor_init(TextEditor *self) // Add Search Button self->btnsearch = gtk_toggle_button_new(); gtk_button_set_icon_name(GTK_BUTTON(self->btnsearch), "find"); - gtk_header_bar_pack_end(GTK_HEADER_BAR(self->header), self->btnsearch); + my_titlebar_pack_end(self->header, self->btnsearch); // Add a search bar self->search_bar = gtk_search_bar_new(); diff --git a/Gtk4_Reset/src/ui/MyTitleBar.cpp b/Gtk4_Reset/src/ui/MyTitleBar.cpp index 8afa3cc..44286d5 100644 --- a/Gtk4_Reset/src/ui/MyTitleBar.cpp +++ b/Gtk4_Reset/src/ui/MyTitleBar.cpp @@ -26,6 +26,11 @@ void _my_titlebar_set_window(MyTitleBar *self, GtkWidget *window) self->ctrl_window = window; } +void _my_titlebar_pack_end(MyTitleBar *self, GtkWidget *widget) +{ + gtk_header_bar_pack_end(GTK_HEADER_BAR(self->header), widget); +} + static void my_titlebar_init(MyTitleBar *self) { // Create widgets diff --git a/Gtk4_Reset/src/ui/MyTitleBar.h b/Gtk4_Reset/src/ui/MyTitleBar.h index 7f3acde..03d02c9 100644 --- a/Gtk4_Reset/src/ui/MyTitleBar.h +++ b/Gtk4_Reset/src/ui/MyTitleBar.h @@ -2,11 +2,16 @@ #include +// For any style of pointer #define my_titlebar_set_window(title_bar, window) \ _my_titlebar_set_window(My_TitleBar(title_bar), GTK_WIDGET(window)) +#define my_titlebar_pack_end(title_bar, widget) \ + _my_titlebar_pack_end(My_TitleBar(title_bar), GTK_WIDGET(widget)) G_DECLARE_FINAL_TYPE(MyTitleBar, my_titlebar, My, TitleBar, GObject) void _my_titlebar_set_window(MyTitleBar *title_bar, GtkWidget *window); +void _my_titlebar_pack_end(MyTitleBar *title_bar, GtkWidget *widget); + MyTitleBar *my_titlebar_new(); \ No newline at end of file