From 39d9e4f288346faa2e2eab36d608ac80de6b6cc8 Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Tue, 4 Jul 2017 19:57:04 +0530 Subject: New class for main toolbar; use XML descriptions for UI Change-Id: I30ee13e0c02346d7ef6a8faf82758edd02dd1913 --- gtv.ui | 107 +++++++++++++++++++++ .../qa/gtktiledviewer/gtv-application-window.cxx | 33 ++++--- .../qa/gtktiledviewer/gtv-application.cxx | 17 +++- .../qa/gtktiledviewer/gtv-main-toolbar.cxx | 77 +++++++++++++++ .../qa/gtktiledviewer/gtv-main-toolbar.hxx | 26 +++++ 5 files changed, 244 insertions(+), 16 deletions(-) create mode 100644 gtv.ui create mode 100644 libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx create mode 100644 libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx diff --git a/gtv.ui b/gtv.ui new file mode 100644 index 000000000000..68a35fece642 --- /dev/null +++ b/gtv.ui @@ -0,0 +1,107 @@ + + + + + + True + False + vertical + + + + + + True + False + + + True + True + True + True + in + + + + + + 1 + 1 + + + + + True + False + + + 0 + 0 + + + + + True + False + + + 0 + 1 + + + + + True + False + + + 1 + 0 + + + + + True + True + 2 + + + + + True + False + icons + + + True + False + __glade_unnamed_3 + True + gtk-save + + + + False + True + + + + + True + False + icons + + + True + False + True + gtk-bold + + + + False + True + + + + diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx index 6b7793307c02..c7567f7a558e 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx @@ -9,7 +9,11 @@ #include +#include +#include + #include +#include struct _GtvApplicationWindow { @@ -19,16 +23,11 @@ struct _GtvApplicationWindow struct GtvApplicationWindowPrivate { GtkWidget* container; - GtkWidget* toolbar1; - GtkWidget* toolbar2; - GtkWidget* btn_saveas; - GtkWidget* btn_copy; - GtkWidget* btn_paste; - GtkWidget* btn_bold; - GtkWidget* btn_italics; - GtkWidget* btn_underline; - GtkWidget* statusbar; + GtkWidget* toolbarcontainer; + GtkWidget* scrolledwindow; + GtkWidget* lokdocview; + GtkWidget* statusbar; }; G_DEFINE_TYPE_WITH_PRIVATE(GtvApplicationWindow, gtv_application_window, GTK_TYPE_APPLICATION_WINDOW); @@ -47,16 +46,24 @@ gtv_application_window_init(GtvApplicationWindow* win) // This is the parent GtkBox holding everything priv->container = GTK_WIDGET(gtk_builder_get_object(builder, "container")); - // 1st row toolbar - priv->toolbar1 = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar1")); - // 2nd row toolbar - priv->toolbar2 = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar2")); + // Toolbar container + priv->toolbarcontainer = gtv_main_toolbar_new(); + + // Attach to the toolbar to main window + gtk_box_pack_start(GTK_BOX(priv->container), priv->toolbarcontainer, false, false, false); + gtk_box_reorder_child(GTK_BOX(priv->container), priv->toolbarcontainer, 0); + // scrolled window containing the main drawing area priv->scrolledwindow = GTK_WIDGET(gtk_builder_get_object(builder, "scrolledwindow")); + // give life to lokdocview + priv->lokdocview = lok_doc_view_new_from_user_profile(pLOPath, pUserProfile, nullptr, nullptr); + // statusbar priv->statusbar = GTK_WIDGET(gtk_builder_get_object(builder, "statusbar")); gtk_container_add(GTK_CONTAINER(win), priv->container); + + g_object_unref(builder); } static void diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application.cxx b/libreofficekit/qa/gtktiledviewer/gtv-application.cxx index eab1f08bf938..4701530297c5 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-application.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-application.cxx @@ -26,18 +26,29 @@ gtv_application_activate(GApplication* application) gtk_window_present(GTK_WINDOW(win)); } -//gtv_application_open(GApplication* /*win*/, GFile** /*file*/, gint, const gchar*) +gtv_application_open(GApplication* win, GFile** file, gint, const gchar*) +{ + +} static void -gtv_application_init(GtvApplication*) +gtv_application_init(GtvApplication* app) { - // TODO + static const GOptionEntry commandLineOptions[] = + { + { "version", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, nullptr, "Show LOkit version", nullptr }, + { "lo-path", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, nullptr, "Manda", nullptr } + }; + + g_application_add_main_option_entries(G_APPLICATION(app), commandLineOptions); } static void gtv_application_class_init(GtvApplicationClass* klass) { G_APPLICATION_CLASS(klass)->activate = gtv_application_activate; + G_APPLICATION_CLASS(klass)-> = gtv_application_activate; + } GtvApplication* gtv_application_new() diff --git a/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx new file mode 100644 index 000000000000..efdd70fe453d --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +struct _GtvMainToolbar +{ + GtkBox parent; +}; + +struct GtvMainToolbarPrivate +{ + GtkWidget* toolbar1; + GtkWidget* toolbar2; + + GtkWidget* btn_save; + GtkWidget* btn_bold; +}; + +G_DEFINE_TYPE_WITH_PRIVATE(GtvMainToolbar, gtv_main_toolbar, GTK_TYPE_BOX); + +static GtvMainToolbarPrivate* +getPrivate(GtvMainToolbar* toolbar) +{ + return static_cast(gtv_main_toolbar_get_instance_private(toolbar)); +} + +static void +btn_clicked(GtkWidget* pWidget, gpointer) +{ + g_info("btn clicked"); +} + +static void +gtv_main_toolbar_init(GtvMainToolbar* toolbar) +{ + GtkBuilder* builder = gtk_builder_new_from_file("gtv.ui"); + GtvMainToolbarPrivate* priv = getPrivate(toolbar); + + priv->toolbar1 = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar1")); + gtk_box_pack_start(GTK_BOX(toolbar), priv->toolbar1, false, false, false); + priv->toolbar2 = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar2")); + gtk_box_pack_start(GTK_BOX(toolbar), priv->toolbar2, false, false, false); + + priv->btn_save = GTK_WIDGET(gtk_builder_get_object(builder, "btn_save")); + priv->btn_bold = GTK_WIDGET(gtk_builder_get_object(builder, "btn_bold")); + + gtk_widget_show_all(GTK_WIDGET(toolbar)); +} + +static void +gtv_main_toolbar_class_init(GtvMainToolbarClass*) +{ + // TODO: Use templates to bind objects maybe ? + // But that requires compiling the .ui file into C source requiring + // glib-compile-resources (another dependency) as I can't find any gtk + // method to set the template from the .ui file directly; can only be set + // from gresource +} + +GtkWidget* +gtv_main_toolbar_new() +{ + return GTK_WIDGET(g_object_new(GTV_MAIN_TOOLBAR_TYPE, + "orientation", GTK_ORIENTATION_VERTICAL, + nullptr)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx new file mode 100644 index 000000000000..83467cccdd36 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef GTV_MAIN_TOOLBAR_H +#define GTV_MAIN_TOOLBAR_H + +#include + +G_BEGIN_DECLS + +#define GTV_MAIN_TOOLBAR_TYPE (gtv_main_toolbar_get_type()) +G_DECLARE_FINAL_TYPE(GtvMainToolbar, gtv_main_toolbar, GTV, MAIN_TOOLBAR, GtkBox); + +GtkWidget* gtv_main_toolbar_new(); + +G_END_DECLS + +#endif /* GTV_MAIN_TOOLBAR_H */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3