Kaydet (Commit) f0592933 authored tarafından Pranav Kant's avatar Pranav Kant Kaydeden (comit) pranavk

Modernize gtktiledviewer; use GApplication

Put all the UI content in UI XML file.

Unfortunately, lots of boilerplate code because
G_DECLARE_* macros are available only since glib 2.44

Change-Id: Idc74ba8565d482c28abd00b6f6f75646ab3d40b9
Reviewed-on: https://gerrit.libreoffice.org/39913Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarpranavk <pranavk@collabora.co.uk>
üst b7b2887d
...@@ -12,6 +12,7 @@ $(eval $(call gb_Executable_Executable,gtktiledviewer)) ...@@ -12,6 +12,7 @@ $(eval $(call gb_Executable_Executable,gtktiledviewer))
$(eval $(call gb_Executable_set_include,gtktiledviewer,\ $(eval $(call gb_Executable_set_include,gtktiledviewer,\
$$(INCLUDE) \ $$(INCLUDE) \
-I$(SRCDIR)/desktop/inc \ -I$(SRCDIR)/desktop/inc \
-I$(SRCDIR)/libreofficekit/qa/gtktiledviewer/ \
)) ))
$(eval $(call gb_Executable_use_externals,gtktiledviewer,\ $(eval $(call gb_Executable_use_externals,gtktiledviewer,\
...@@ -43,7 +44,15 @@ $(eval $(call gb_Executable_add_libs,gtktiledviewer,\ ...@@ -43,7 +44,15 @@ $(eval $(call gb_Executable_add_libs,gtktiledviewer,\
endif endif
$(eval $(call gb_Executable_add_exception_objects,gtktiledviewer,\ $(eval $(call gb_Executable_add_exception_objects,gtktiledviewer,\
libreofficekit/qa/gtktiledviewer/gtktiledviewer \ libreofficekit/qa/gtktiledviewer/gtv-main \
libreofficekit/qa/gtktiledviewer/gtv-application \
libreofficekit/qa/gtktiledviewer/gtv-application-window \
libreofficekit/qa/gtktiledviewer/gtv-main-toolbar \
libreofficekit/qa/gtktiledviewer/gtv-signal-handlers \
libreofficekit/qa/gtktiledviewer/gtv-helpers \
libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers \
libreofficekit/qa/gtktiledviewer/gtv-calc-header-bar \
libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar \
)) ))
# vim: set noet sw=4 ts=4: # vim: set noet sw=4 ts=4:
This source diff could not be displayed because it is too large. You can view the blob instead.
/* -*- 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_APPLICATION_WINDOW_H
#define GTV_APPLICATION_WINDOW_H
#include <gtk/gtk.h>
#include <LibreOfficeKit/LibreOfficeKitGtk.h>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <gtv-main-toolbar.hxx>
#include <string>
struct GtvRenderingArgs
{
std::string m_aLoPath;
std::string m_aUserProfile;
bool m_bEnableTiledAnnotations;
std::string m_aBackgroundColor;
bool m_bHidePageShadow;
bool m_bHideWhiteSpace;
GtvRenderingArgs()
: m_bEnableTiledAnnotations(false),
m_bHidePageShadow(false),
m_bHideWhiteSpace(false)
{ }
};
G_BEGIN_DECLS
#define GTV_TYPE_APPLICATION_WINDOW (gtv_application_window_get_type())
#define GTV_APPLICATION_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTV_TYPE_APPLICATION_WINDOW, GtvApplicationWindow))
#define GTV_IS_APPLICATION_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTV_TYPE_APPLICATION_WINDOW))
#define GTV_APPLICATION_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTV_TYPE_APPLICATION_WINDOW, GtvApplicationWindowClass))
#define GTV_IS_APPLICATION_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTV_TYPE_APPLICATION_WINDOW))
#define GTV_APPLICATION_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTV_TYPE_APPLICATION_WINDOW, GtvApplicationWindowClass))
struct GtvApplicationWindow
{
GtkApplicationWindow parent_instance;
GtkWidget* scrolledwindow;
GtkWidget* lokdocview;
LibreOfficeKitDocumentType doctype;
GtkWidget* rowbar;
GtkWidget* columnbar;
GtkWidget* cornerarea;
GtkWidget* commentssidebar;
GtkWidget* statusbar;
GtkWidget* zoomlabel;
GtkWidget* redlinelabel;
GtkWidget* findbarlabel;
GtkWidget* findbarEntry;
GtkWidget* findAll;
GtkWidget* findtoolbar;
};
struct GtvApplicationWindowClass
{
GtkApplicationWindow parentClass;
};
GType gtv_application_window_get_type (void) G_GNUC_CONST;
GtvApplicationWindow* gtv_application_window_new(GtkApplication* application);
void gtv_application_window_load_document(GtvApplicationWindow* application,
const GtvRenderingArgs* aArgs,
const std::string& aDocPath);
void gtv_application_window_create_view_from_window(GtvApplicationWindow* window);
void gtv_application_window_get_visible_area(GtvApplicationWindow* pWindow, GdkRectangle* pArea);
void gtv_application_window_toggle_findbar(GtvApplicationWindow* window);
GtkToolItem* gtv_application_window_find_tool_by_unocommand(GtvApplicationWindow* window, const std::string& unoCmd);
GtvMainToolbar* gtv_application_window_get_main_toolbar(GtvApplicationWindow* window);
void gtv_application_window_set_toolbar_broadcast(GtvApplicationWindow* window, bool broadcast);
gboolean gtv_application_window_get_toolbar_broadcast(GtvApplicationWindow* window);
void gtv_application_window_set_part_broadcast(GtvApplicationWindow* window, bool broadcast);
gboolean gtv_application_window_get_part_broadcast(GtvApplicationWindow* window);
G_END_DECLS
#endif /* GTV_APPLICATION_WINDOW_H */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 <gtk/gtk.h>
#include <gtv-application.hxx>
#include <gtv-application-window.hxx>
#include <string>
struct GtvApplicationPrivate
{
GtvRenderingArgs* m_pRenderingArgs;
};
G_DEFINE_TYPE_WITH_PRIVATE(GtvApplication, gtv_application, GTK_TYPE_APPLICATION);
static GtvApplicationPrivate*
getPrivate(GtvApplication* app)
{
return static_cast<GtvApplicationPrivate*>(gtv_application_get_instance_private(app));
}
static void
gtv_application_open(GApplication* app, GFile** file, gint /*nFiles*/, const gchar* /*hint*/)
{
// TODO: add some option to create a new view for existing document
// For now, this just opens a new document
GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtv_application_window_new(GTK_APPLICATION(app)));
gtk_window_present(GTK_WINDOW(window));
GtvApplicationPrivate* priv = getPrivate(GTV_APPLICATION(app));
gtv_application_window_load_document(window, priv->m_pRenderingArgs, std::string(g_file_get_path(file[0])));
}
static void
gtv_application_init(GtvApplication* app)
{
static const GOptionEntry commandLineOptions[] =
{
{ "version", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, nullptr, "Show LOkit version", nullptr },
{ "lo-path", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, nullptr, "LO path", nullptr },
{ "user-profile", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, nullptr, "User profile to use", nullptr },
{ "enable-tiled-annotations", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, nullptr, "Whether tiled annotations should be enabled", nullptr },
{ "background-color", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, nullptr, "Background color", nullptr },
{ "hide-page-shadow", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, nullptr, "Hide page shadow", nullptr },
{ "hide-whitespace", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, nullptr, "Hide whitespace", nullptr }
};
g_application_add_main_option_entries(G_APPLICATION(app), commandLineOptions);
GtvApplicationPrivate* priv = getPrivate(GTV_APPLICATION(app));
priv->m_pRenderingArgs = new GtvRenderingArgs();
}
static void
gtv_application_dispose (GObject* object)
{
GtvApplicationPrivate* priv = getPrivate(GTV_APPLICATION(object));
delete priv->m_pRenderingArgs;
priv->m_pRenderingArgs = nullptr;
G_OBJECT_CLASS (gtv_application_parent_class)->dispose (object);
}
static gint
gtv_application_handle_local_options(GApplication* app, GVariantDict* options)
{
GtvApplicationPrivate* priv = getPrivate(GTV_APPLICATION(app));
// This is mandatory
if (g_variant_dict_contains(options, "lo-path"))
{
gchar* loPath = nullptr;
g_variant_dict_lookup(options, "lo-path", "s", &loPath);
if (loPath)
{
priv->m_pRenderingArgs->m_aLoPath = std::string(loPath);
g_free(loPath);
}
}
else
{
g_print("--lo-path= is mandatory. Please provide the path to LO installation.\n");
return 1; // Cannot afford to continue in absense of this param
}
if (g_variant_dict_contains(options, "version"))
{
if (!priv->m_pRenderingArgs->m_aLoPath.empty())
{
// FIXME: Crashes for some reason
GtkWidget* pDocView = lok_doc_view_new(priv->m_pRenderingArgs->m_aLoPath.c_str(), nullptr, nullptr);
const gchar* versionInfo = lok_doc_view_get_version_info(LOK_DOC_VIEW(pDocView));
if (versionInfo)
g_print("LOKit version: %s", versionInfo);
}
return 1; // exit anyway
}
// Optional args
if (g_variant_dict_contains(options, "user-profile"))
{
gchar* userProfile = nullptr;
g_variant_dict_lookup(options, "user-profile", "s", &userProfile);
if (userProfile)
{
priv->m_pRenderingArgs->m_aUserProfile = std::string("vnd.sun.star.pathname:") + std::string(userProfile);
g_free(userProfile);
}
}
if (g_variant_dict_contains(options, "background-color"))
{
gchar* backgroundColor = nullptr;
g_variant_dict_lookup(options, "background-color", "s", &backgroundColor);
if (backgroundColor)
{
priv->m_pRenderingArgs->m_aBackgroundColor = std::string(backgroundColor);
g_free(backgroundColor);
}
}
if (g_variant_dict_contains(options, "enable-tiled-annotations"))
priv->m_pRenderingArgs->m_bEnableTiledAnnotations = true;
if (g_variant_dict_contains(options, "hide-page-shadow"))
priv->m_pRenderingArgs->m_bHidePageShadow = true;
if (g_variant_dict_contains(options, "hide-whitespace"))
priv->m_pRenderingArgs->m_bHideWhiteSpace = true;
return -1;
}
static void
gtv_application_class_init(GtvApplicationClass* klass)
{
G_APPLICATION_CLASS(klass)->open = gtv_application_open;
G_APPLICATION_CLASS(klass)->handle_local_options = gtv_application_handle_local_options;
G_OBJECT_CLASS(klass)->dispose = gtv_application_dispose;
}
GtvApplication* gtv_application_new()
{
return GTV_APPLICATION(g_object_new(GTV_TYPE_APPLICATION,
"application-id", "org.libreoffice.gtktiledviewer",
"flags", G_APPLICATION_HANDLES_OPEN,
nullptr));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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_APPLICATION_H
#define GTV_APPLICATION_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GTV_TYPE_APPLICATION (gtv_application_get_type())
#define GTV_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTV_TYPE_APPLICATION, GtvApplication))
#define GTV_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTV_TYPE_APPLICATION))
#define GTV_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTV_TYPE_APPLICATION, GtvApplicationClass))
#define GTV_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTV_TYPE_APPLICATION))
#define GTV_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTV_TYPE_APPLICATION, GtvApplicationClass))
struct GtvApplication
{
GtkApplication parent;
};
struct GtvApplicationClass
{
GtkApplication parentClass;
};
GType gtv_application_get_type (void) G_GNUC_CONST;
GtvApplication* gtv_application_new();
G_END_DECLS
#endif /* GTV_APPLICATION_H */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 <gtk/gtk.h>
#include <cmath>
#include <iostream>
#include <gtv-application-window.hxx>
#include <gtv-signal-handlers.hxx>
#include <gtv-helpers.hxx>
#include <gtv-calc-header-bar.hxx>
#include <map>
#include <boost/property_tree/json_parser.hpp>
#include <boost/optional.hpp>
struct GtvCalcHeaderBarPrivateImpl
{
/// Stores size and content of a single row header.
struct Header
{
int m_nSize;
std::string m_aText;
Header(int nSize, const std::string& rText)
: m_nSize(nSize),
m_aText(rText)
{ }
};
std::vector<Header> m_aHeaders;
CalcHeaderType m_eType;
GtvCalcHeaderBarPrivateImpl()
: m_eType(CalcHeaderType::NONE)
{ }
};
struct GtvCalcHeaderBarPrivate
{
GtvCalcHeaderBarPrivateImpl* m_pImpl;
GtvCalcHeaderBarPrivateImpl* operator->()
{
return m_pImpl;
}
};
G_DEFINE_TYPE_WITH_PRIVATE(GtvCalcHeaderBar, gtv_calc_header_bar, GTK_TYPE_DRAWING_AREA);
static const int ROW_HEADER_WIDTH = 50;
static const int COLUMN_HEADER_HEIGHT = 20;
static GtvCalcHeaderBarPrivate&
getPrivate(GtvCalcHeaderBar* headerbar)
{
return *static_cast<GtvCalcHeaderBarPrivate*>(gtv_calc_header_bar_get_instance_private(headerbar));
}
static void
gtv_calc_header_bar_init(GtvCalcHeaderBar* bar)
{
GtvCalcHeaderBarPrivate& priv = getPrivate(bar);
priv.m_pImpl = new GtvCalcHeaderBarPrivateImpl();
}
static void
gtv_calc_header_bar_finalize(GObject* object)
{
GtvCalcHeaderBarPrivate& priv = getPrivate(GTV_CALC_HEADER_BAR(object));
delete priv.m_pImpl;
priv.m_pImpl = nullptr;
G_OBJECT_CLASS (gtv_calc_header_bar_parent_class)->finalize (object);
}
void gtv_calc_header_bar_draw_text(cairo_t* pCairo, const GdkRectangle& rRectangle, const std::string& rText)
{
cairo_text_extents_t extents;
cairo_text_extents(pCairo, rText.c_str(), &extents);
// Cairo reference point for text is the bottom left corner.
cairo_move_to(pCairo, rRectangle.x + rRectangle.width / 2 - extents.width / 2, rRectangle.y + rRectangle.height / 2 + extents.height / 2);
cairo_show_text(pCairo, rText.c_str());
}
gboolean gtv_calc_header_bar_draw_impl(GtkWidget* pWidget, cairo_t* pCairo)
{
GtvCalcHeaderBar* self = GTV_CALC_HEADER_BAR(pWidget);
GtvCalcHeaderBarPrivate& priv = getPrivate(GTV_CALC_HEADER_BAR(self));
cairo_set_source_rgb(pCairo, 0, 0, 0);
int nPrevious = 0;
for (const GtvCalcHeaderBarPrivateImpl::Header& rHeader : priv->m_aHeaders)
{
GdkRectangle aRectangle;
if (priv->m_eType == CalcHeaderType::ROW)
{
aRectangle.x = 0;
aRectangle.y = nPrevious - 1;
aRectangle.width = ROW_HEADER_WIDTH - 1;
aRectangle.height = rHeader.m_nSize - nPrevious;
// Left line.
cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, 1, aRectangle.height);
cairo_fill(pCairo);
// Bottom line.
cairo_rectangle(pCairo, aRectangle.x, aRectangle.y + aRectangle.height, aRectangle.width, 1);
cairo_fill(pCairo);
// Right line.
cairo_rectangle(pCairo, aRectangle.width, aRectangle.y, 1, aRectangle.height);
cairo_fill(pCairo);
}
else if (priv->m_eType == CalcHeaderType::COLUMN)
{
aRectangle.x = nPrevious - 1;
aRectangle.y = 0;
aRectangle.width = rHeader.m_nSize - nPrevious;
aRectangle.height = COLUMN_HEADER_HEIGHT - 1;
// Top line.
cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, aRectangle.width, 1);
cairo_fill(pCairo);
// Right line.
cairo_rectangle(pCairo, aRectangle.x + aRectangle.width , aRectangle.y, 1, aRectangle.height);
cairo_fill(pCairo);
// Bottom line.
cairo_rectangle(pCairo, aRectangle.x, aRectangle.height, aRectangle.width, 1);
cairo_fill(pCairo);
}
gtv_calc_header_bar_draw_text(pCairo, aRectangle, rHeader.m_aText);
nPrevious = rHeader.m_nSize;
if (rHeader.m_nSize > self->m_nSizePixel)
break;
}
if (priv->m_aHeaders.empty() && priv->m_eType == CalcHeaderType::CORNER)
{
GdkRectangle aRectangle;
aRectangle.x = 0;
aRectangle.y = 0;
aRectangle.width = ROW_HEADER_WIDTH - 1;
aRectangle.height = COLUMN_HEADER_HEIGHT - 1;
cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, aRectangle.width, aRectangle.height);
cairo_stroke(pCairo);
}
return FALSE;
}
static gboolean
gtv_calc_header_bar_draw(GtkWidget* bar, cairo_t* pCairo)
{
return gtv_calc_header_bar_draw_impl(bar, pCairo);
}
static void
gtv_calc_header_bar_class_init(GtvCalcHeaderBarClass* klass)
{
GTK_WIDGET_CLASS(klass)->draw = gtv_calc_header_bar_draw;
G_OBJECT_CLASS(klass)->finalize = gtv_calc_header_bar_finalize;
}
void gtv_calc_header_bar_configure(GtvCalcHeaderBar* bar, const boost::property_tree::ptree* values)
{
GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(bar)));
GtvCalcHeaderBarPrivate& priv = getPrivate(bar);
priv->m_aHeaders.clear();
if (values)
{
boost::property_tree::ptree val = *values;
try
{
for (boost::property_tree::ptree::value_type& rValue : val)
{
int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(window->lokdocview), std::atof(rValue.second.get<std::string>("size").c_str())));
if (nSize >= bar->m_nPositionPixel)
{
const int nScrolledSize = nSize - bar->m_nPositionPixel;
GtvCalcHeaderBarPrivateImpl::Header aHeader(nScrolledSize, rValue.second.get<std::string>("text"));
priv->m_aHeaders.push_back(aHeader);
}
}
}
catch (boost::property_tree::ptree_bad_path& rException)
{
std::cerr << "gtv_calc_header_bar_configure: " << rException.what() << std::endl;
}
}
gtk_widget_show(GTK_WIDGET(bar));
gtk_widget_queue_draw(GTK_WIDGET(bar));
}
void
gtv_calc_header_bar_set_type_and_width(GtvCalcHeaderBar* bar, CalcHeaderType eType)
{
// TODO: Install type property for this class
GtvCalcHeaderBarPrivate& priv = getPrivate(bar);
priv->m_eType = eType;
if (eType == CalcHeaderType::ROW)
gtk_widget_set_size_request(GTK_WIDGET(bar), ROW_HEADER_WIDTH, -1);
else if (eType == CalcHeaderType::COLUMN)
gtk_widget_set_size_request(GTK_WIDGET(bar), -1, COLUMN_HEADER_HEIGHT);
}
GtkWidget*
gtv_calc_header_bar_new()
{
return GTK_WIDGET(g_object_new(GTV_TYPE_CALC_HEADER_BAR,
nullptr));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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_CALC_HEADER_BAR_H
#define GTV_CALC_HEADER_BAR_H
#include <gtk/gtk.h>
#include <boost/property_tree/json_parser.hpp>
G_BEGIN_DECLS
#define GTV_TYPE_CALC_HEADER_BAR (gtv_calc_header_bar_get_type())
#define GTV_CALC_HEADER_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTV_TYPE_CALC_HEADER_BAR, GtvCalcHeaderBar))
#define GTV_IS_CALC_HEADER_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTV_TYPE_CALC_HEADER_BAR))
#define GTV_CALC_HEADER_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTV_TYPE_CALC_HEADER_BAR, GtvCalcHeaderBarClass))
#define GTV_IS_CALC_HEADER_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTV_TYPE_CALC_HEADER_BAR))
#define GTV_CALC_HEADER_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTV_TYPE_CALC_HEADER_BAR, GtvCalcHeaderBarClass))
struct GtvCalcHeaderBar
{
GtkDrawingArea parent;
/// Height for row bar, width for column bar.
int m_nSizePixel;
/// Left/top position for the column/row bar -- initially 0, then may grow due to scrolling.
int m_nPositionPixel;
};
struct GtvCalcHeaderBarClass
{
GtkDrawingAreaClass parentClass;
};
GType gtv_calc_header_bar_get_type (void) G_GNUC_CONST;
enum CalcHeaderType { ROW, COLUMN, CORNER, NONE };
GtkWidget* gtv_calc_header_bar_new();
void gtv_calc_header_bar_configure(GtvCalcHeaderBar* bar, const boost::property_tree::ptree* values);
int gtv_calc_header_bar_get_pos_pixel(GtvCalcHeaderBar* bar);
int gtv_calc_header_bar_get_size_pixel(GtvCalcHeaderBar* bar);
void gtv_calc_header_bar_set_type_and_width(GtvCalcHeaderBar* bar, CalcHeaderType eType);
G_END_DECLS
#endif /* GTV_CALC_HEADER_BAR_H */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 <gtk/gtk.h>
#include <cmath>
#include <iostream>
#include <gtv-application-window.hxx>
#include <gtv-signal-handlers.hxx>
#include <gtv-helpers.hxx>
#include <gtv-comments-sidebar.hxx>
#include <map>
#include <boost/property_tree/json_parser.hpp>
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
G_DEFINE_TYPE(GtvCommentsSidebar, gtv_comments_sidebar, GTK_TYPE_BOX);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
void
gtv_comments_sidebar_view_annotations(GtvCommentsSidebar* sidebar)
{
GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(sidebar)));
LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview));
char* pValues = pDocument->pClass->getCommandValues(pDocument, ".uno:ViewAnnotations");
g_info("lok::Document::getCommandValues(%s) : %s", ".uno:ViewAnnotations", pValues);
std::stringstream aStream(pValues);
free(pValues);
// empty the comments grid
GtvGtkWrapper<GList> children(gtk_container_get_children(GTK_CONTAINER(sidebar->commentsgrid)),
[](GList* l)
{
g_list_free(l);
});
GList* iter;
for (iter = children.get(); iter != nullptr; iter = g_list_next(iter))
gtk_widget_destroy(GTK_WIDGET(iter->data));
boost::property_tree::ptree aTree;
boost::property_tree::read_json(aStream, aTree);
try
{
for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("comments"))
{
GtkWidget* pCommentBox = GtvHelpers::createCommentBox(rValue.second);
gtk_container_add(GTK_CONTAINER(sidebar->commentsgrid), pCommentBox);
}
gtk_widget_show_all(sidebar->scrolledwindow);
}
catch(boost::property_tree::ptree_bad_path& rException)
{
std::cerr << "CommentsSidebar::unoViewAnnotations: failed to get comments" << rException.what() << std::endl;
}
}
static void
gtv_comments_sidebar_view_annotations_cb(GtkWidget* pWidget, gpointer)
{
GtvCommentsSidebar* sidebar = GTV_COMMENTS_SIDEBAR(pWidget);
gtv_comments_sidebar_view_annotations(sidebar);
}
static void
gtv_comments_sidebar_init(GtvCommentsSidebar* sidebar)
{
sidebar->scrolledwindow = gtk_scrolled_window_new(nullptr, nullptr);
gtk_widget_set_vexpand(sidebar->scrolledwindow, TRUE);
sidebar->commentsgrid = gtk_grid_new();
g_object_set(sidebar->commentsgrid, "orientation", GTK_ORIENTATION_VERTICAL, nullptr);
sidebar->viewannotationsButton = gtk_button_new_with_label(".uno:ViewAnnotations");
#if GTK_CHECK_VERSION(3,12,0)
// Hack to make sidebar grid wide enough to not need any horizontal scrollbar
gtk_widget_set_margin_start(sidebar->viewannotationsButton, 20);
gtk_widget_set_margin_end(sidebar->viewannotationsButton, 20);
#endif
gtk_container_add(GTK_CONTAINER(sidebar), sidebar->viewannotationsButton);
g_signal_connect_swapped(sidebar->viewannotationsButton, "clicked", G_CALLBACK(gtv_comments_sidebar_view_annotations_cb), sidebar);
gtk_container_add(GTK_CONTAINER(sidebar), sidebar->scrolledwindow);
gtk_container_add(GTK_CONTAINER(sidebar->scrolledwindow), sidebar->commentsgrid);
gtk_widget_show_all(GTK_WIDGET(sidebar));
}
static void
gtv_comments_sidebar_class_init(GtvCommentsSidebarClass* /*klass*/)
{
}
GtkWidget*
gtv_comments_sidebar_new()
{
return GTK_WIDGET(g_object_new(GTV_TYPE_COMMENTS_SIDEBAR,
"orientation", GTK_ORIENTATION_VERTICAL,
nullptr));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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_COMMENTS_SIDEBAR_H
#define GTV_COMMENTS_SIDEBAR_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GTV_TYPE_COMMENTS_SIDEBAR (gtv_comments_sidebar_get_type())
#define GTV_COMMENTS_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTV_TYPE_COMMENTS_SIDEBAR, GtvCommentsSidebar))
#define GTV_IS_COMMENTS_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTV_TYPE_COMMENTS_SIDEBAR))
#define GTV_COMMENTS_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTV_TYPE_COMMENTS_SIDEBAR, GtvCommentsSidebarClass))
#define GTV_IS_COMMENTS_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTV_TYPE_COMMENTS_SIDEBAR))
#define GTV_COMMENTS_SIDEBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTV_TYPE_COMMENTS_SIDEBAR, GtvCommentsSidebarClass))
struct GtvCommentsSidebar
{
GtkBox parent;
GtkWidget* viewannotationsButton;
GtkWidget* scrolledwindow;
GtkWidget* commentsgrid;
};
struct GtvCommentsSidebarClass
{
GtkBoxClass parentClass;
};
GType gtv_comments_sidebar_get_type (void) G_GNUC_CONST;
GtkWidget* gtv_comments_sidebar_new();
void gtv_comments_sidebar_view_annotations(GtvCommentsSidebar* sidebar);
G_END_DECLS
#endif /* GTV_COMMENTS_SIDEBAR_H */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 <gtk/gtk.h>
#include <pwd.h>
#include <cstring>
#include <gtv-helpers.hxx>
void GtvHelpers::userPromptDialog(GtkWindow* pWindow, const std::string& aTitle, std::map<std::string, std::string>& aEntries)
{
GtkWidget* pDialog = gtk_dialog_new_with_buttons (aTitle.c_str(),
pWindow,
GTK_DIALOG_MODAL,
"Ok",
GTK_RESPONSE_OK,
nullptr);
GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pDialog));
GtkWidget* pEntryArea = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(pDialogMessageArea), pEntryArea);
for (const auto& entry : aEntries)
{
GtkWidget* pEntry = gtk_entry_new();
#if GTK_CHECK_VERSION(3,2,0)
gtk_entry_set_placeholder_text(GTK_ENTRY(pEntry), entry.first.c_str());
#endif
gtk_container_add(GTK_CONTAINER(pEntryArea), pEntry);
}
gtk_widget_show_all(pDialog);
gint res = gtk_dialog_run(GTK_DIALOG(pDialog));
switch(res)
{
case GTK_RESPONSE_OK:
GtvGtkWrapper<GList> pList(gtk_container_get_children(GTK_CONTAINER(pEntryArea)),
[](GList* l)
{
g_list_free(l);
});
for (GList* l = pList.get(); l != nullptr; l = l->next)
{
const gchar* pKey = gtk_entry_get_placeholder_text(GTK_ENTRY(l->data));
aEntries[std::string(pKey)] = std::string(gtk_entry_get_text(GTK_ENTRY(l->data)));
}
break;
}
gtk_widget_destroy(pDialog);
}
/// Our GtkClipboardGetFunc implementation for HTML.
static void htmlGetFunc(GtkClipboard* /*pClipboard*/, GtkSelectionData* pSelectionData, guint /*info*/, gpointer pUserData)
{
GdkAtom aAtom(gdk_atom_intern("text/html", false));
const gchar* pSelection = static_cast<const gchar*>(pUserData);
gtk_selection_data_set(pSelectionData, aAtom, 8, reinterpret_cast<const guchar *>(pSelection), strlen(pSelection));
}
/// Our GtkClipboardClearFunc implementation for HTML.
static void htmlClearFunc(GtkClipboard* /*pClipboard*/, gpointer pData)
{
g_free(pData);
}
void GtvHelpers::clipboardSetHtml(GtkClipboard* pClipboard, const char* pSelection)
{
GtvGtkWrapper<GtkTargetList> pList(gtk_target_list_new(nullptr, 0),
[](GtkTargetList* pTargetList)
{
gtk_target_list_unref(pTargetList);
});
GdkAtom aAtom(gdk_atom_intern("text/html", false));
gtk_target_list_add(pList.get(), aAtom, 0, 0);
gint nTargets = 0;
GtkTargetEntry* pTargets = gtk_target_table_new_from_list(pList.get(), &nTargets);
gtk_clipboard_set_with_data(pClipboard, pTargets, nTargets, htmlGetFunc, htmlClearFunc, g_strdup(pSelection));
gtk_target_table_free(pTargets, nTargets);
}
std::string GtvHelpers::getNextAuthor()
{
static int nCounter = 0;
struct passwd* pPasswd = getpwuid(getuid());
return std::string(pPasswd->pw_gecos) + " #" + std::to_string(++nCounter);
}
GtkWidget* GtvHelpers::createCommentBox(const boost::property_tree::ptree& aComment)
{
GtkWidget* pCommentVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
gchar *id = g_strndup(aComment.get<std::string>("id").c_str(), 20);
g_object_set_data_full(G_OBJECT(pCommentVBox), "id", id, g_free);
// Set background if its a reply comment
if (aComment.get("parent", -1) > 0)
{
GtkStyleContext* pStyleContext = gtk_widget_get_style_context(pCommentVBox);
GtkCssProvider* pCssProvider = gtk_css_provider_get_default();
gtk_style_context_add_class(pStyleContext, "commentbox");
gtk_style_context_add_provider(pStyleContext, GTK_STYLE_PROVIDER(pCssProvider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_css_provider_load_from_data(pCssProvider, ".commentbox {background-color: lightgreen;}", -1, nullptr);
}
GtkWidget* pCommentText = gtk_label_new(aComment.get<std::string>("text").c_str());
GtkWidget* pCommentAuthor = gtk_label_new(aComment.get<std::string>("author").c_str());
GtkWidget* pCommentDate = gtk_label_new(aComment.get<std::string>("dateTime").c_str());
GtkWidget* pControlsHBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
GtkWidget* pEditButton = gtk_button_new_with_label("Edit");
GtkWidget* pReplyButton = gtk_button_new_with_label("Reply");
GtkWidget* pDeleteButton = gtk_button_new_with_label("Delete");
g_signal_connect(G_OBJECT(pEditButton), "clicked", G_CALLBACK(editButtonClicked), pCommentVBox);
g_signal_connect(G_OBJECT(pReplyButton), "clicked", G_CALLBACK(replyButtonClicked), pCommentVBox);
g_signal_connect(G_OBJECT(pDeleteButton), "clicked", G_CALLBACK(deleteCommentButtonClicked), pCommentVBox);
gtk_container_add(GTK_CONTAINER(pControlsHBox), pEditButton);
gtk_container_add(GTK_CONTAINER(pControlsHBox), pReplyButton);
gtk_container_add(GTK_CONTAINER(pControlsHBox), pDeleteButton);
GtkWidget* pCommentSeparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentText);
gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentAuthor);
gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentDate);
gtk_container_add(GTK_CONTAINER(pCommentVBox), pControlsHBox);
gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentSeparator);
gtk_label_set_line_wrap(GTK_LABEL(pCommentText), TRUE);
gtk_label_set_max_width_chars(GTK_LABEL(pCommentText), 35);
return pCommentVBox;
}
const std::string GtvHelpers::getDirPath(const std::string& filePath)
{
int position = filePath.find_last_of('/');
const std::string dirPath = filePath.substr(0, position + 1);
return dirPath;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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_HELPERS_H
#define GTV_HELPERS_H
#include <gtk/gtk.h>
#include <gtv-signal-handlers.hxx>
#include <map>
#include <string>
#include <memory>
#include <boost/property_tree/json_parser.hpp>
#define UI_FILE_NAME "gtv.ui"
// Wrapper with custom deleter to use for Gtk objects
template <class T>
using GtvGtkWrapper = std::unique_ptr<T, void(*)(T*)>;
namespace GtvHelpers
{
void userPromptDialog(GtkWindow* pWindow, const std::string& aTitle, std::map<std::string, std::string>& aEntries);
void clipboardSetHtml(GtkClipboard* pClipboard, const char* pSelection);
/// Generate an author string for multiple views.
std::string getNextAuthor();
GtkWidget* createCommentBox(const boost::property_tree::ptree& aComment);
const std::string getDirPath(const std::string& filePath);
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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_LOKDOCVIEW_SIGNAL_HANDLERS_H
#define GTV_LOKDOCVIEW_SIGNAL_HANDLERS_H
#include <gtk/gtk.h>
namespace LOKDocViewSigHandlers {
void editChanged(LOKDocView* pDocView, gboolean bWasEdit, gpointer);
void commandChanged(LOKDocView* pDocView, char* pPayload, gpointer);
void commandResult(LOKDocView*, char*, gpointer);
void searchNotFound(LOKDocView*, char*, gpointer);
void searchResultCount(LOKDocView*, char*, gpointer);
void partChanged(LOKDocView*, int, gpointer);
void hyperlinkClicked(LOKDocView*, char*, gpointer);
void cursorChanged(LOKDocView* pDocView, gint nX, gint nY, gint nWidth, gint nHeight, gpointer);
void addressChanged(LOKDocView* pDocView, char* pPayload, gpointer);
void formulaChanged(LOKDocView* pDocView, char* pPayload, gpointer);
void passwordRequired(LOKDocView* pDocView, char* pUrl, gboolean bModify, gpointer);
void comment(LOKDocView* pDocView, gchar* pComment, gpointer);
gboolean configureEvent(GtkWidget* pWidget, GdkEventConfigure* pEvent, gpointer pData);
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 <gtk/gtk.h>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
G_BEGIN_DECLS
#define GTV_TYPE_MAIN_TOOLBAR (gtv_main_toolbar_get_type())
#define GTV_MAIN_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTV_TYPE_MAIN_TOOLBAR, GtvMainToolbar))
#define GTV_IS_MAIN_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTV_TYPE_MAIN_TOOLBAR))
#define GTV_MAIN_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTV_TYPE_MAIN_TOOLBAR, GtvMainToolbarClass))
#define GTV_IS_MAIN_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTV_TYPE_MAIN_TOOLBAR))
#define GTV_MAIN_TOOLBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTV_TYPE_MAIN_TOOLBAR, GtvMainToolbarClass))
struct GtvMainToolbar
{
GtkBox parent;
GtkWidget* m_pAddressbar;
GtkWidget* m_pFormulabar;
};
struct GtvMainToolbarClass
{
GtkBoxClass parentClass;
};
GType gtv_main_toolbar_get_type (void) G_GNUC_CONST;
GtkWidget* gtv_main_toolbar_new();
GtkContainer* gtv_main_toolbar_get_first_toolbar(GtvMainToolbar* toolbar);
GtkContainer* gtv_main_toolbar_get_second_toolbar(GtvMainToolbar* toolbar);
void gtv_main_toolbar_set_sensitive_internal(GtvMainToolbar* toolbar, GtkToolItem* pItem, bool isSensitive);
/// Use internal sensitivity map to set actual widget's sensitivness
void gtv_main_toolbar_set_edit(GtvMainToolbar* toolbar, gboolean bEdit);
void gtv_main_toolbar_doc_loaded(GtvMainToolbar* toolbar, LibreOfficeKitDocumentType eDocType, bool bEditMode);
G_END_DECLS
#endif /* GTV_MAIN_TOOLBAR_H */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 <gtk/gtk.h>
#include <gtv-application.hxx>
int main(int argc, char* argv[])
{
return g_application_run(G_APPLICATION(gtv_application_new()), argc, argv);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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_SIGNAL_HANDLERS_H
#define GTV_SIGNAL_HANDLERS_H
#include <gtk/gtk.h>
void btn_clicked(GtkWidget* pWidget, gpointer);
void doCopy(GtkWidget* pButton, gpointer /*pItem*/);
void doPaste(GtkWidget* pButton, gpointer /*pItem*/);
void createView(GtkWidget* pButton, gpointer /*pItem*/);
void unoCommandDebugger(GtkWidget* pButton, gpointer /* pItem */);
void toggleEditing(GtkWidget* pButton, gpointer /*pItem*/);
void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ );
void changePart( GtkWidget* pSelector, gpointer /*pItem*/ );
void changeZoom( GtkWidget* pButton, gpointer /* pItem */ );
void toggleFindbar(GtkWidget* pButton, gpointer /*pItem*/);
void documentRedline(GtkWidget* pButton, gpointer /*pItem*/);
void documentRepair(GtkWidget* pButton, gpointer /*pItem*/);
void docAdjustmentChanged(GtkAdjustment*, gpointer);
/// Click handler for the search next button.
void signalSearchNext(GtkWidget* pButton, gpointer /*pItem*/);
/// Click handler for the search previous button.
void signalSearchPrev(GtkWidget* pButton, gpointer /*pItem*/);
/// Handles the key-press-event of the search entry widget.
gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/);
void toggleFindAll(GtkWidget* pButton, gpointer /*pItem*/);
void editButtonClicked(GtkWidget*, gpointer);
void replyButtonClicked(GtkWidget*, gpointer);
void deleteCommentButtonClicked(GtkWidget*, gpointer);
/// Handles the key-press-event of the address bar entry widget.
gboolean signalAddressbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/);
/// Handles the key-press-event of the formula entry widget.
gboolean signalFormulabar(GtkWidget* /*pWidget*/, GdkEventKey* /*pEvent*/, gpointer /*pData*/);
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment