From d6fc4399089248a29acfa6cfb63165f988180813 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 5 Aug 2024 05:21:28 +0300 Subject: [PATCH] draft append method --- src/app/browser/container/page.cpp | 24 ++++++++- src/app/browser/container/page.h | 10 ++++ src/app/browser/container/tab.cpp | 84 +++++++++++++++++++++++++++++- src/app/browser/container/tab.h | 17 ++++++ 4 files changed, 133 insertions(+), 2 deletions(-) diff --git a/src/app/browser/container/page.cpp b/src/app/browser/container/page.cpp index 6097ac12..02a2c8ab 100644 --- a/src/app/browser/container/page.cpp +++ b/src/app/browser/container/page.cpp @@ -6,7 +6,9 @@ namespace app { namespace container { - // Construct + /** + * Construct + */ Page::Page( Container *container ) { @@ -22,6 +24,26 @@ namespace app ) ); } + + /** + * Init empty page + */ + void Page::init( + char *request, + bool focus + ) { + // @TODO + } + + /** + * Open page request + */ + void Page::open( + char *request, + bool history + ) { + // @TODO + } } } } \ No newline at end of file diff --git a/src/app/browser/container/page.h b/src/app/browser/container/page.h index a9de872d..5c758462 100644 --- a/src/app/browser/container/page.h +++ b/src/app/browser/container/page.h @@ -22,6 +22,16 @@ namespace app Page( Container *container ); + + void init( + char *request, + bool focus + ); + + void open( + char *request, + bool history + ); }; }; }; diff --git a/src/app/browser/container/tab.cpp b/src/app/browser/container/tab.cpp index 3ae6e33b..e19d0f93 100644 --- a/src/app/browser/container/tab.cpp +++ b/src/app/browser/container/tab.cpp @@ -6,10 +6,15 @@ namespace app { namespace container { - // Construct + /** + * Construct + */ Tab::Tab( Container *container ) { + // Init dependencies + this->container = container; + // Init GTK this->gtk = gtk_notebook_new(); @@ -26,6 +31,83 @@ namespace app ) ); } + + /** + * Append new tab + */ + void Tab::append( + char *request, + bool open = true, + bool focus = true + ) { + + // Init new page + Page *page = new Page( + this->container + ); + + gtk_notebook_append_page( + GTK_NOTEBOOK( + this->gtk + ), + GTK_WIDGET( + page->gtk + ), + NULL // @TODO label + ); + + gtk_notebook_set_tab_reorderable( + GTK_NOTEBOOK( + this->gtk + ), + GTK_WIDGET( + page->gtk + ), + Tab::REORDERABLE + ); + + // Page open requested + if (open) + { + page->open( + request, + false // history + ); + } + + else + { + page->init( + request, + true // focus @TODO boolean empty(request) + ); + } + + // Focus requested + if (focus) + { + gtk_notebook_set_current_page( + GTK_NOTEBOOK( + this->gtk + ), + gtk_notebook_page_num( + GTK_NOTEBOOK( + this->gtk + ), + GTK_WIDGET( + page->gtk + ) + ) + ); + } + + // Render + gtk_widget_show( + GTK_WIDGET( + this->gtk + ) + ); + } } } } diff --git a/src/app/browser/container/tab.h b/src/app/browser/container/tab.h index c63ddd21..764ccffe 100644 --- a/src/app/browser/container/tab.h +++ b/src/app/browser/container/tab.h @@ -1,8 +1,12 @@ #ifndef APP_BROWSER_CONTAINER_TAB_H #define APP_BROWSER_CONTAINER_TAB_H +// Dependencies #include "../container.h" +// Requirements +#include "page.h" + namespace app { namespace browser @@ -11,18 +15,31 @@ namespace app namespace container { + class Page; // @TODO not required here + class Tab { public: + // GTK GtkWidget *gtk; + // Defaults const gboolean REORDERABLE = true; const gboolean SCROLLABLE = true; + // Dependencies + Container *container; + Tab( Container *container ); + + void append( + char *request, + bool open, + bool focus + ); }; }; };