diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-07-13 19:34:41 +0530 |
---|---|---|
committer | pranavk <pranavk@collabora.co.uk> | 2017-07-14 09:33:24 +0200 |
commit | f059293344ba93d76fcc6e64015923dfa639c4bf (patch) | |
tree | 429f59ba36f9d4d577c1a7ac941fe2b1949dcd7a /libreofficekit | |
parent | b7b2887d62ea249310f02f03c4ce31cbd8f21307 (diff) |
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/39913
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Diffstat (limited to 'libreofficekit')
20 files changed, 3617 insertions, 2299 deletions
diff --git a/libreofficekit/Executable_gtktiledviewer.mk b/libreofficekit/Executable_gtktiledviewer.mk index 3d7ed665157d..f0667e247680 100644 --- a/libreofficekit/Executable_gtktiledviewer.mk +++ b/libreofficekit/Executable_gtktiledviewer.mk @@ -12,6 +12,7 @@ $(eval $(call gb_Executable_Executable,gtktiledviewer)) $(eval $(call gb_Executable_set_include,gtktiledviewer,\ $$(INCLUDE) \ -I$(SRCDIR)/desktop/inc \ + -I$(SRCDIR)/libreofficekit/qa/gtktiledviewer/ \ )) $(eval $(call gb_Executable_use_externals,gtktiledviewer,\ @@ -43,7 +44,15 @@ $(eval $(call gb_Executable_add_libs,gtktiledviewer,\ endif $(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: diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx deleted file mode 100644 index 3d9301b7549f..000000000000 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ /dev/null @@ -1,2298 +0,0 @@ -/* -*- 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 <assert.h> -#include <stdio.h> -#include <string.h> -#include <pwd.h> -#include <cmath> -#include <string> -#include <map> -#include <iostream> - -#include <boost/property_tree/json_parser.hpp> -#include <boost/optional.hpp> -#include <gdk/gdkkeysyms.h> - -#include <sal/types.h> - -#include <LibreOfficeKit/LibreOfficeKitGtk.h> -#include <LibreOfficeKit/LibreOfficeKitEnums.h> - -#ifndef g_info -#define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__) -#endif - -static int help() -{ - fprintf(stderr, "Usage: gtktiledviewer <absolute-path-to-libreoffice-install's-program-directory> <path-to-document> [<options> ... ]\n\n"); - fprintf(stderr, "Options:\n\n"); - fprintf(stderr, "--background-color <color>: Set custom background color, e.g. 'yellow'.\n"); - fprintf(stderr, "--hide-page-shadow: Hide page/slide shadow.\n"); - fprintf(stderr, "--hide-whitespace: Hide whitespace between pages in text documents.\n"); - fprintf(stderr, "--user-profile: Path to a custom user profile.\n"); - return 1; -} - -/// Represents the comment sidebar widget (only for text documents as of now) -class CommentsSidebar -{ -public: - /// Main Vertical Box containing comments box and additional controls (eg. buttons) - GtkWidget* m_pMainVBox; - /// Button to issue a .uno:ViewAnnotations command - GtkWidget* m_pViewAnnotationsButton; - /// top level container for all comments in the sidebar - GtkWidget* m_pCommentsVBox; - /// scrolled window for main comments box - GtkWidget* m_pScrolledWindow; - - /// Prepare and return a comment object (GtkBox) - static GtkWidget* createCommentBox(const boost::property_tree::ptree& aComment); - /// Click even handler for m_pViewAnnotationsButton - static void unoViewAnnotations(GtkWidget* pWidget, gpointer userdata); -}; - - -/// Represents the row or column header widget for spreadsheets. -class TiledRowColumnBar -{ -public: - /// 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) - { - } - }; - - enum TiledBarType { ROW, COLUMN }; - - static const int ROW_HEADER_WIDTH = 50; - static const int COLUMN_HEADER_HEIGHT = 20; - - GtkWidget* m_pDrawingArea; - std::vector<Header> m_aHeaders; - /// 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; - TiledBarType m_eType; - - explicit TiledRowColumnBar(TiledBarType eType); - static gboolean draw(GtkWidget* pWidget, cairo_t* pCairo, gpointer pData); - gboolean drawImpl(GtkWidget* pWidget, cairo_t* pCairo); - static gboolean docConfigureEvent(GtkWidget* pWidget, GdkEventConfigure* pEvent, gpointer pData); - /// Adjustments of the doc widget changed -- horizontal or vertical scroll. - static void docAdjustmentChanged(GtkAdjustment* pAdjustment, gpointer pData); - /// Draws rText at the center of rRectangle on pCairo. - static void drawText(cairo_t* pCairo, const GdkRectangle& rRectangle, const std::string& rText); -}; - -/// Represents the button at the top left corner for spreadsheets. -class TiledCornerButton -{ -public: - GtkWidget* m_pDrawingArea; - TiledCornerButton(); - static gboolean draw(GtkWidget* pWidget, cairo_t* pCairo, gpointer pData); - static gboolean drawImpl(GtkWidget* pWidget, cairo_t* pCairo); -}; - -/// Represents all the state that is specific to one GtkWindow of this app. -class TiledWindow -{ -public: - GtkWidget* m_pDocView; - GtkWidget* m_pStatusBar; - GtkWidget* m_pProgressBar; - GtkWidget* m_pStatusbarLabel; - GtkWidget* m_pRedlineLabel; - GtkWidget* m_pZoomLabel; - GtkToolItem* m_pSaveButton; - GtkToolItem* m_pCopyButton; - GtkToolItem* m_pPasteButton; - GtkToolItem* m_pUndo; - GtkToolItem* m_pRedo; - GtkToolItem* m_pEnableEditing; - GtkToolItem* m_pBold; - GtkToolItem* m_pItalic; - GtkToolItem* m_pUnderline; - GtkToolItem* m_pStrikethrough; - GtkToolItem* m_pSuperscript; - GtkToolItem* m_pSubscript; - GtkToolItem* m_pLeftpara; - GtkToolItem* m_pCenterpara; - GtkToolItem* m_pRightpara; - GtkToolItem* m_pJustifypara; - GtkToolItem* m_pInsertAnnotation; - GtkToolItem* m_pDeleteComment; - GtkToolItem* m_pTrackChanges; - GtkWidget* m_pAddressbarEntry; - GtkWidget* m_pFormulabarEntry; - GtkWidget* m_pScrolledWindow; - std::map<GtkToolItem*, std::string> m_aToolItemCommandNames; - std::map<GtkToolItem*, std::string> m_aToolItemCommandArgs; - std::map<std::string, GtkToolItem*> m_aCommandNameToolItems; - /// Sensitivity (enabled or disabled) or each tool item, ignoring edit - /// state. - std::map<GtkToolItem*, bool> m_aToolItemSensitivities; - bool m_bToolItemBroadcast; - GtkWidget* m_pVBox; - GtkWidget* m_pMainHBox; - GtkComboBoxText* m_pPartSelector; - GtkWidget* m_pPartModeComboBox; - /// Should the part selector avoid calling lok::Document::setPart()? - bool m_bPartSelectorBroadcast; - GtkWidget* m_pFindbar; - GtkWidget* m_pFindbarEntry; - GtkWidget* m_pFindbarLabel; - bool m_bFindAll; - std::shared_ptr<TiledRowColumnBar> m_pRowBar; - std::shared_ptr<TiledRowColumnBar> m_pColumnBar; - std::shared_ptr<TiledCornerButton> m_pCornerButton; - std::shared_ptr<CommentsSidebar> m_pCommentsSidebar; - /// Rendering arguments, which are the same for all views. - boost::property_tree::ptree m_aRenderingArguments; - /// Author of this window - std::string m_aAuthor; - - TiledWindow() - : m_pDocView(nullptr), - m_pStatusBar(nullptr), - m_pProgressBar(nullptr), - m_pStatusbarLabel(nullptr), - m_pRedlineLabel(nullptr), - m_pZoomLabel(nullptr), - m_pSaveButton(nullptr), - m_pCopyButton(nullptr), - m_pPasteButton(nullptr), - m_pUndo(nullptr), - m_pRedo(nullptr), - m_pEnableEditing(nullptr), - m_pBold(nullptr), - m_pItalic(nullptr), - m_pUnderline(nullptr), - m_pStrikethrough(nullptr), - m_pSuperscript(nullptr), - m_pSubscript(nullptr), - m_pLeftpara(nullptr), - m_pCenterpara(nullptr), - m_pRightpara(nullptr), - m_pJustifypara(nullptr), - m_pInsertAnnotation(nullptr), - m_pDeleteComment(nullptr), - m_pTrackChanges(nullptr), - m_pAddressbarEntry(nullptr), - m_pFormulabarEntry(nullptr), - m_pScrolledWindow(nullptr), - m_bToolItemBroadcast(true), - m_pVBox(nullptr), - m_pMainHBox(nullptr), - m_pPartSelector(nullptr), - m_pPartModeComboBox(nullptr), - m_bPartSelectorBroadcast(true), - m_pFindbar(nullptr), - m_pFindbarEntry(nullptr), - m_pFindbarLabel(nullptr), - m_bFindAll(false) - { - } -}; - -static std::map<GtkWidget*, TiledWindow> g_aWindows; - -static void setupDocView(GtkWidget* pDocView); -static GtkWidget* createWindow(TiledWindow& rWindow); -static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpointer userdata); -/// Handler for m_pPartModeComboBox. -static void changePartMode( GtkWidget* pSelector, gpointer /*pItem*/); -/// Handler for m_pPartSelector. -static void changePart( GtkWidget* pSelector, gpointer /*pItem*/ ); -/// Part selector populator -static void populatePartSelector(LOKDocView* pLOKDocView); -/// Part mode selector populator -static void populatePartModeSelector( GtkComboBoxText* pSelector ); - -static TiledWindow& lcl_getTiledWindow(GtkWidget* pWidget) -{ - GtkWidget* pToplevel = gtk_widget_get_toplevel(pWidget); - assert(g_aWindows.find(pToplevel) != g_aWindows.end()); - return g_aWindows[pToplevel]; -} - -/// Generate an author string for multiple views. -static std::string getNextAuthor() -{ - static int nCounter = 0; - struct passwd* pPasswd = getpwuid(getuid()); - return std::string(pPasswd->pw_gecos) + " #" + std::to_string(++nCounter); -} - -static void lcl_registerToolItem(TiledWindow& rWindow, GtkToolItem* pItem, const std::string& rName, const std::string& rArgs = "") -{ - rWindow.m_aToolItemCommandNames[pItem] = rName; - rWindow.m_aToolItemCommandArgs[pItem] = rArgs; - rWindow.m_aCommandNameToolItems[rName] = pItem; - rWindow.m_aToolItemSensitivities[pItem] = true; -} - -static void userPromptDialog(GtkWidget* pDocView, const std::string& aTitle, std::map<std::string, std::string>& aEntries) -{ - GtkWidget* pDialog = gtk_dialog_new_with_buttons (aTitle.c_str(), - GTK_WINDOW (gtk_widget_get_toplevel(pDocView)), - 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: - GList* pList = gtk_container_get_children(GTK_CONTAINER(pEntryArea)); - - for (GList* l = pList; 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); -} - -static void editButtonClicked(GtkWidget* pWidget, gpointer userdata) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pWidget); - std::map<std::string, std::string> aEntries; - aEntries["Text"] = ""; - - userPromptDialog(rWindow.m_pDocView, "Edit comment", aEntries); - - gchar *commentId = static_cast<gchar*>(g_object_get_data(G_OBJECT(userdata), "id")); - - boost::property_tree::ptree aTree; - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "type", nullptr), '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "value", nullptr), '/'), std::string(commentId)); - - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), aEntries["Text"]); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - std::string aArguments = aStream.str(); - - lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), ".uno:EditAnnotation", aArguments.c_str(), false); -} - -static void replyButtonClicked(GtkWidget* pWidget, gpointer userdata) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pWidget); - std::map<std::string, std::string> aEntries; - aEntries["Text"] = ""; - - userPromptDialog(rWindow.m_pDocView, "Reply comment", aEntries); - - gchar *commentId = static_cast<gchar*>(g_object_get_data(G_OBJECT(userdata), "id")); - - boost::property_tree::ptree aTree; - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "type", nullptr), '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "value", nullptr), '/'), std::string(commentId)); - - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), aEntries["Text"]); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - std::string aArguments = aStream.str(); - - // Different reply UNO command for impress - std::string replyCommand = ".uno:ReplyComment"; - LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(rWindow.m_pDocView)); - if (pDocument && pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_PRESENTATION) - replyCommand = ".uno:ReplyToAnnotation"; - lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), replyCommand.c_str(), aArguments.c_str(), false); -} - -static void deleteCommentButtonClicked(GtkWidget* pWidget, gpointer userdata) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pWidget); - - gchar *commentid = static_cast<gchar*>(g_object_get_data(G_OBJECT(userdata), "id")); - - boost::property_tree::ptree aTree; - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "type", nullptr), '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "value", nullptr), '/'), std::string(commentid)); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - std::string aArguments = aStream.str(); - - lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), rWindow.m_aToolItemCommandNames[rWindow.m_pDeleteComment].c_str(), aArguments.c_str(), false); -} - -GtkWidget* CommentsSidebar::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; -} - -void CommentsSidebar::unoViewAnnotations(GtkWidget* pWidget, gpointer /*userdata*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pWidget); - - LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(rWindow.m_pDocView)); - char* pValues = pDocument->pClass->getCommandValues(pDocument, ".uno:ViewAnnotations"); - g_info("lok::Document::getCommandValues(%s) : %s", ".uno:ViewAnnotations", pValues); - std::stringstream aStream(pValues); - free(pValues); - - gtk_widget_destroy(rWindow.m_pCommentsSidebar->m_pScrolledWindow); - - rWindow.m_pCommentsSidebar->m_pScrolledWindow = gtk_scrolled_window_new(nullptr, nullptr); - gtk_widget_set_vexpand(rWindow.m_pCommentsSidebar->m_pScrolledWindow, TRUE); - rWindow.m_pCommentsSidebar->m_pCommentsVBox = gtk_grid_new(); - g_object_set(rWindow.m_pCommentsSidebar->m_pCommentsVBox, "orientation", GTK_ORIENTATION_VERTICAL, nullptr); - - gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pScrolledWindow), rWindow.m_pCommentsSidebar->m_pCommentsVBox); - gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pMainVBox), rWindow.m_pCommentsSidebar->m_pScrolledWindow); - - 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 = CommentsSidebar::createCommentBox(rValue.second); - gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pCommentsVBox), pCommentBox); - } - gtk_widget_show_all(rWindow.m_pCommentsSidebar->m_pScrolledWindow); - } - catch(boost::property_tree::ptree_bad_path& rException) - { - std::cerr << "CommentsSidebar::unoViewAnnotations: failed to get comments" << rException.what() << std::endl; - } -} - -TiledRowColumnBar::TiledRowColumnBar(TiledBarType eType) - : m_pDrawingArea(gtk_drawing_area_new()), - m_nSizePixel(0), - m_eType(eType) -{ - if (m_eType == ROW) - gtk_widget_set_size_request(m_pDrawingArea, ROW_HEADER_WIDTH, -1); - else - gtk_widget_set_size_request(m_pDrawingArea, -1, COLUMN_HEADER_HEIGHT); - g_signal_connect(m_pDrawingArea, "draw", G_CALLBACK(TiledRowColumnBar::draw), this); -} - -gboolean TiledRowColumnBar::draw(GtkWidget* pWidget, cairo_t* pCairo, gpointer pData) -{ - return static_cast<TiledRowColumnBar*>(pData)->drawImpl(pWidget, pCairo); -} - -void TiledRowColumnBar::drawText(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 TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo) -{ - cairo_set_source_rgb(pCairo, 0, 0, 0); - - int nPrevious = 0; - for (const Header& rHeader : m_aHeaders) - { - GdkRectangle aRectangle; - if (m_eType == 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 - { - 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); - } - drawText(pCairo, aRectangle, rHeader.m_aText); - nPrevious = rHeader.m_nSize; - if (rHeader.m_nSize > m_nSizePixel) - break; - } - - return FALSE; -} - -void TiledRowColumnBar::docAdjustmentChanged(GtkAdjustment* /*pAdjustment*/, gpointer pData) -{ - GtkWidget* pDocView = static_cast<GtkWidget*>(pData); - docConfigureEvent(pDocView, nullptr, nullptr); -} - -gboolean TiledRowColumnBar::docConfigureEvent(GtkWidget* pDocView, GdkEventConfigure* /*pEvent*/, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pDocView); - GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(rWindow.m_pScrolledWindow)); - rWindow.m_pRowBar->m_nSizePixel = gtk_adjustment_get_page_size(pVAdjustment); - rWindow.m_pRowBar->m_nPositionPixel = gtk_adjustment_get_value(pVAdjustment); - GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(rWindow.m_pScrolledWindow)); - rWindow.m_pColumnBar->m_nSizePixel = gtk_adjustment_get_page_size(pHAdjustment); - rWindow.m_pColumnBar->m_nPositionPixel = gtk_adjustment_get_value(pHAdjustment); - - LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pDocView)); - if (pDocument && pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_SPREADSHEET) - { - std::stringstream aCommand; - aCommand << ".uno:ViewRowColumnHeaders"; - aCommand << "?x=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), rWindow.m_pColumnBar->m_nPositionPixel)); - aCommand << "&width=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), rWindow.m_pColumnBar->m_nSizePixel)); - aCommand << "&y=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), rWindow.m_pRowBar->m_nPositionPixel)); - aCommand << "&height=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), rWindow.m_pRowBar->m_nSizePixel)); - std::stringstream ss; - ss << "lok::Document::getCommandValues(" << aCommand.str() << ")"; - g_info("%s", ss.str().c_str()); - char* pValues = pDocument->pClass->getCommandValues(pDocument, aCommand.str().c_str()); - g_info("lok::Document::getCommandValues() returned '%s'", pValues); - std::stringstream aStream(pValues); - free(pValues); - assert(!aStream.str().empty()); - boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); - - gtk_widget_show(rWindow.m_pCornerButton->m_pDrawingArea); - - rWindow.m_pRowBar->m_aHeaders.clear(); - try - { - for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("rows")) - { - int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str()))); - if (nSize >= rWindow.m_pRowBar->m_nPositionPixel) - { - int nScrolledSize = nSize - rWindow.m_pRowBar->m_nPositionPixel; - Header aHeader(nScrolledSize, rValue.second.get<std::string>("text")); - rWindow.m_pRowBar->m_aHeaders.push_back(aHeader); - } - } - } - catch (boost::property_tree::ptree_bad_path& rException) - { - std::cerr << "TiledRowColumnBar::docConfigureEvent: failed to get rows: " << rException.what() << std::endl; - } - gtk_widget_show(rWindow.m_pRowBar->m_pDrawingArea); - gtk_widget_queue_draw(rWindow.m_pRowBar->m_pDrawingArea); - - rWindow.m_pColumnBar->m_aHeaders.clear(); - try - { - for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("columns")) - { - int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str()))); - if (nSize >= rWindow.m_pColumnBar->m_nPositionPixel) - { - int nScrolledSize = nSize - rWindow.m_pColumnBar->m_nPositionPixel; - Header aHeader(nScrolledSize, rValue.second.get<std::string>("text")); - rWindow.m_pColumnBar->m_aHeaders.push_back(aHeader); - } - } - } - catch (boost::property_tree::ptree_bad_path& rException) - { - std::cerr << "TiledRowColumnBar::docConfigureEvent: failed to get columns: " << rException.what() << std::endl; - } - gtk_widget_show(rWindow.m_pColumnBar->m_pDrawingArea); - gtk_widget_queue_draw(rWindow.m_pColumnBar->m_pDrawingArea); - gtk_widget_show(rWindow.m_pAddressbarEntry); - gtk_widget_show(rWindow.m_pFormulabarEntry); - - } - - return TRUE; -} - -TiledCornerButton::TiledCornerButton() - : m_pDrawingArea(gtk_drawing_area_new()) -{ - gtk_widget_set_size_request(m_pDrawingArea, TiledRowColumnBar::ROW_HEADER_WIDTH, TiledRowColumnBar::COLUMN_HEADER_HEIGHT); - g_signal_connect(m_pDrawingArea, "draw", G_CALLBACK(TiledCornerButton::draw), this); -} - -gboolean TiledCornerButton::draw(GtkWidget* pWidget, cairo_t* pCairo, gpointer) -{ - return drawImpl(pWidget, pCairo); -} - -gboolean TiledCornerButton::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo) -{ - cairo_set_source_rgb(pCairo, 0, 0, 0); - - GdkRectangle aRectangle; - aRectangle.x = 0; - aRectangle.y = 0; - aRectangle.width = TiledRowColumnBar::ROW_HEADER_WIDTH; - aRectangle.height = TiledRowColumnBar::COLUMN_HEADER_HEIGHT; - cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, aRectangle.width, aRectangle.height); - cairo_stroke(pCairo); - - return FALSE; -} - -const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 }; - -static void iterateUnoParams(GtkWidget* pWidget, gpointer userdata) -{ - boost::property_tree::ptree *pTree = static_cast<boost::property_tree::ptree*>(userdata); - - GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pWidget)); - GList* pIt; - guint i = 0; - const gchar* unoParam[3]; - for (pIt = pChildren, i = 0; pIt != nullptr && i < 3; pIt = pIt->next, i++) - { - unoParam[i] = gtk_entry_get_text(GTK_ENTRY(pIt->data)); - } - - pTree->put(boost::property_tree::ptree::path_type(g_strconcat(unoParam[1], "/", "type", nullptr), '/'), unoParam[0]); - pTree->put(boost::property_tree::ptree::path_type(g_strconcat(unoParam[1], "/", "value", nullptr), '/'), unoParam[2]); -} - -static void removeUnoParam(GtkWidget* pWidget, gpointer userdata) -{ - GtkWidget* pParamAreaBox = GTK_WIDGET(userdata); - GtkWidget* pParamContainer = gtk_widget_get_parent(pWidget); - - gtk_container_remove(GTK_CONTAINER(pParamAreaBox), pParamContainer); -} - -static void addMoreUnoParam(GtkWidget* /*pWidget*/, gpointer userdata) -{ - GtkWidget* pUnoParamAreaBox = GTK_WIDGET(userdata); - - GtkWidget* pParamContainer = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start(GTK_BOX(pUnoParamAreaBox), pParamContainer, TRUE, TRUE, 2); - - GtkWidget* pTypeEntry = gtk_entry_new(); - gtk_box_pack_start(GTK_BOX(pParamContainer), pTypeEntry, TRUE, TRUE, 2); -#if GTK_CHECK_VERSION(3,2,0) - gtk_entry_set_placeholder_text(GTK_ENTRY(pTypeEntry), "Param type (Eg. boolean, string etc.)"); -#endif - - GtkWidget* pNameEntry = gtk_entry_new(); - gtk_box_pack_start(GTK_BOX(pParamContainer), pNameEntry, TRUE, TRUE, 2); -#if GTK_CHECK_VERSION(3,2,0) - gtk_entry_set_placeholder_text(GTK_ENTRY(pNameEntry), "Param name"); -#endif - - GtkWidget* pValueEntry = gtk_entry_new(); - gtk_box_pack_start(GTK_BOX(pParamContainer), pValueEntry, TRUE, TRUE, 2); -#if GTK_CHECK_VERSION(3,2,0) - gtk_entry_set_placeholder_text(GTK_ENTRY(pValueEntry), "Param value"); -#endif - - GtkWidget* pRemoveButton = gtk_button_new_from_icon_name("list-remove-symbolic", GTK_ICON_SIZE_BUTTON); - g_signal_connect(pRemoveButton, "clicked", G_CALLBACK(removeUnoParam), pUnoParamAreaBox); - gtk_box_pack_start(GTK_BOX(pParamContainer), pRemoveButton, TRUE, TRUE, 2); - - gtk_widget_show_all(pUnoParamAreaBox); -} - -/// Exposes the info returned for tracked changes. -static void documentRedline(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - LOKDocView* pDocView = LOK_DOC_VIEW(rWindow.m_pDocView); - // Get the data. - LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pDocView); - char* pValues = pDocument->pClass->getCommandValues(pDocument, ".uno:AcceptTrackedChanges"); - if (!pValues) - return; - - std::stringstream aInfo; - aInfo << "lok::Document::getCommandValues('.uno:AcceptTrackedChanges') returned '" << pValues << "'" << std::endl; - g_info("%s", aInfo.str().c_str()); - std::stringstream aStream(pValues); - free(pValues); - assert(!aStream.str().empty()); - boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); - - // Create the dialog. - GtkWidget* pDialog = gtk_dialog_new_with_buttons("Manage Changes", - GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))), - GTK_DIALOG_MODAL, - "Accept", - GTK_RESPONSE_YES, - "Reject", - GTK_RESPONSE_NO, - "Jump", - GTK_RESPONSE_APPLY, - nullptr); - gtk_window_set_default_size(GTK_WINDOW(pDialog), 800, 600); - GtkWidget* pContentArea = gtk_dialog_get_content_area(GTK_DIALOG (pDialog)); - GtkWidget* pScrolledWindow = gtk_scrolled_window_new(nullptr, nullptr); - - // Build the table. - GtkTreeStore* pTreeStore = gtk_tree_store_new(6, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - for (const auto& rValue : aTree.get_child("redlines")) - { - GtkTreeIter aTreeIter; - gtk_tree_store_append(pTreeStore, &aTreeIter, nullptr); - gtk_tree_store_set(pTreeStore, &aTreeIter, - 0, rValue.second.get<int>("index"), - 1, rValue.second.get<std::string>("author").c_str(), - 2, rValue.second.get<std::string>("type").c_str(), - 3, rValue.second.get<std::string>("comment").c_str(), - 4, rValue.second.get<std::string>("description").c_str(), - 5, rValue.second.get<std::string>("dateTime").c_str(), - -1); - } - GtkWidget* pTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pTreeStore)); - std::vector<std::string> aColumns = {"Index", "Author", "Type", "Comment", "Description", "Timestamp"}; - for (size_t nColumn = 0; nColumn < aColumns.size(); ++nColumn) - { - GtkCellRenderer* pRenderer = gtk_cell_renderer_text_new(); - GtkTreeViewColumn* pColumn = gtk_tree_view_column_new_with_attributes(aColumns[nColumn].c_str(), - pRenderer, - "text", nColumn, - nullptr); - gtk_tree_view_append_column(GTK_TREE_VIEW(pTreeView), pColumn); - } - gtk_container_add(GTK_CONTAINER(pScrolledWindow), pTreeView); - gtk_box_pack_start(GTK_BOX(pContentArea), pScrolledWindow, TRUE, TRUE, 2); - - // Show the dialog. - gtk_widget_show_all(pDialog); - gint res = gtk_dialog_run(GTK_DIALOG(pDialog)); - - // Dispatch the matching command, if necessary. - if (res == GTK_RESPONSE_YES || res == GTK_RESPONSE_NO || res == GTK_RESPONSE_APPLY) - { - GtkTreeSelection* pSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pTreeView)); - GtkTreeIter aTreeIter; - GtkTreeModel* pTreeModel; - if (gtk_tree_selection_get_selected(pSelection, &pTreeModel, &aTreeIter)) - { - gint nIndex = 0; - // 0: index - gtk_tree_model_get(pTreeModel, &aTreeIter, 0, &nIndex, -1); - std::string aCommand; - if (res == GTK_RESPONSE_YES) - aCommand = ".uno:AcceptTrackedChange"; - else if (res == GTK_RESPONSE_NO) - aCommand = ".uno:RejectTrackedChange"; - else - // Just select the given redline, don't accept or reject it. - aCommand = ".uno:NextTrackedChange"; - // Without the '.uno:' prefix. - std::string aKey = aCommand.substr(strlen(".uno:")); - - // Post the command. - boost::property_tree::ptree aCommandTree; - aCommandTree.put(boost::property_tree::ptree::path_type(aKey + "/type", '/'), "unsigned short"); - aCommandTree.put(boost::property_tree::ptree::path_type(aKey + "/value", '/'), nIndex); - - aStream.str(std::string()); - boost::property_tree::write_json(aStream, aCommandTree); - std::string aArguments = aStream.str(); - lok_doc_view_post_command(pDocView, aCommand.c_str(), aArguments.c_str(), false); - } - } - - gtk_widget_destroy(pDialog); -} - -static void documentRepair(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - LOKDocView* pDocView = LOK_DOC_VIEW(rWindow.m_pDocView); - // Get the data. - LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pDocView); - // Show it in linear time, so first redo in reverse order, then undo. - std::vector<std::string> aTypes = {".uno:Redo", ".uno:Undo"}; - std::vector<boost::property_tree::ptree> aTrees; - for (size_t nType = 0; nType < aTypes.size(); ++nType) - { - const std::string& rType = aTypes[nType]; - char* pValues = pDocument->pClass->getCommandValues(pDocument, rType.c_str()); - std::stringstream aInfo; - aInfo << "lok::Document::getCommandValues('" << rType << "') returned '" << pValues << "'" << std::endl; - g_info("%s", aInfo.str().c_str()); - std::stringstream aStream(pValues); - free(pValues); - assert(!aStream.str().empty()); - boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); - aTrees.push_back(aTree); - } - - // Create the dialog. - GtkWidget* pDialog = gtk_dialog_new_with_buttons("Repair document", - GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))), - GTK_DIALOG_MODAL, - "Jump to state", - GTK_RESPONSE_OK, - nullptr); - gtk_window_set_default_size(GTK_WINDOW(pDialog), 800, 600); - GtkWidget* pContentArea = gtk_dialog_get_content_area(GTK_DIALOG (pDialog)); - GtkWidget* pScrolledWindow = gtk_scrolled_window_new(nullptr, nullptr); - - // Build the table. - GtkTreeStore* pTreeStore = gtk_tree_store_new(5, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - for (size_t nTree = 0; nTree < aTrees.size(); ++nTree) - { - const auto& rTree = aTrees[nTree]; - for (const auto& rValue : rTree.get_child("actions")) - { - GtkTreeIter aTreeIter; - gtk_tree_store_append(pTreeStore, &aTreeIter, nullptr); - gtk_tree_store_set(pTreeStore, &aTreeIter, - 0, aTypes[nTree].c_str(), - 1, rValue.second.get<int>("index"), - 2, rValue.second.get<std::string>("comment").c_str(), - 3, rValue.second.get<std::string>("viewId").c_str(), - 4, rValue.second.get<std::string>("dateTime").c_str(), - -1); - } - } - GtkWidget* pTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pTreeStore)); - std::vector<std::string> aColumns = {"Type", "Index", "Comment", "View ID", "Timestamp"}; - for (size_t nColumn = 0; nColumn < aColumns.size(); ++nColumn) - { - GtkCellRenderer* pRenderer = gtk_cell_renderer_text_new(); - GtkTreeViewColumn* pColumn = gtk_tree_view_column_new_with_attributes(aColumns[nColumn].c_str(), - pRenderer, - "text", nColumn, - nullptr); - gtk_tree_view_append_column(GTK_TREE_VIEW(pTreeView), pColumn); - } - gtk_container_add(GTK_CONTAINER(pScrolledWindow), pTreeView); - gtk_box_pack_start(GTK_BOX(pContentArea), pScrolledWindow, TRUE, TRUE, 2); - - // Show the dialog. - gtk_widget_show_all(pDialog); - gint res = gtk_dialog_run(GTK_DIALOG(pDialog)); - - // Dispatch the matching command, if necessary. - if (res == GTK_RESPONSE_OK) - { - GtkTreeSelection* pSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pTreeView)); - GtkTreeIter aTreeIter; - GtkTreeModel* pTreeModel; - if (gtk_tree_selection_get_selected(pSelection, &pTreeModel, &aTreeIter)) - { - gchar* pType = nullptr; - gint nIndex = 0; - // 0: type, 1: index - gtk_tree_model_get(pTreeModel, &aTreeIter, 0, &pType, 1, &nIndex, -1); - // '.uno:Undo' or '.uno:Redo' - const std::string aType(pType); - // Without the '.uno:' prefix. - std::string aKey = aType.substr(strlen(".uno:")); - g_free(pType); - - // Post the command. - boost::property_tree::ptree aTree; - aTree.put(boost::property_tree::ptree::path_type(aKey + "/type", '/'), "unsigned short"); - aTree.put(boost::property_tree::ptree::path_type(aKey + "/value", '/'), nIndex + 1); - - // Without this, we could only undo our own commands. - aTree.put(boost::property_tree::ptree::path_type("Repair/type", '/'), "boolean"); - aTree.put(boost::property_tree::ptree::path_type("Repair/value", '/'), true); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - std::string aArguments = aStream.str(); - lok_doc_view_post_command(pDocView, aType.c_str(), aArguments.c_str(), false); - } - } - - gtk_widget_destroy(pDialog); -} - -static void unoCommandDebugger(GtkWidget* pButton, gpointer /* pItem */) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - LOKDocView* pDocView = LOK_DOC_VIEW(rWindow.m_pDocView); - - GtkWidget* pUnoCmdDialog = gtk_dialog_new_with_buttons ("Execute UNO command", - GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))), - GTK_DIALOG_MODAL, - "Execute", - GTK_RESPONSE_OK, - nullptr); - g_object_set(G_OBJECT(pUnoCmdDialog), "resizable", FALSE, nullptr); - GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pUnoCmdDialog)); - GtkWidget* pUnoCmdAreaBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pUnoCmdAreaBox, TRUE, TRUE, 2); - - GtkWidget* pUnoCmdLabel = gtk_label_new("Enter UNO command"); - gtk_box_pack_start(GTK_BOX(pUnoCmdAreaBox), pUnoCmdLabel, TRUE, TRUE, 2); - - GtkWidget* pUnoCmdEntry = gtk_entry_new (); - gtk_box_pack_start(GTK_BOX(pUnoCmdAreaBox), pUnoCmdEntry, TRUE, TRUE, 2); -#if GTK_CHECK_VERSION(3,2,0) - gtk_entry_set_placeholder_text(GTK_ENTRY(pUnoCmdEntry), "UNO command (Eg. Bold, Italic etc.)"); -#endif - GtkWidget* pUnoParamAreaBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pUnoParamAreaBox, TRUE, TRUE, 2); - - GtkWidget* pAddMoreButton = gtk_button_new_with_label("Add UNO parameter"); - gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pAddMoreButton, TRUE, TRUE, 2); - g_signal_connect(G_OBJECT(pAddMoreButton), "clicked", G_CALLBACK(addMoreUnoParam), pUnoParamAreaBox); - - gtk_widget_show_all(pUnoCmdDialog); - - gint res = gtk_dialog_run (GTK_DIALOG(pUnoCmdDialog)); - switch (res) - { - case GTK_RESPONSE_OK: - { - const gchar* sUnoCmd = g_strconcat(".uno:", gtk_entry_get_text(GTK_ENTRY(pUnoCmdEntry)), nullptr); - - boost::property_tree::ptree aTree; - gtk_container_foreach(GTK_CONTAINER(pUnoParamAreaBox), iterateUnoParams, &aTree); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - std::string aArguments = aStream.str(); - - g_info("Generated UNO command: %s %s", sUnoCmd, aArguments.c_str()); - - lok_doc_view_post_command(pDocView, sUnoCmd, (aArguments.empty() ? nullptr : aArguments.c_str()), false); - } - break; - } - - gtk_widget_destroy(pUnoCmdDialog); -} - -/// Get the visible area of the scrolled window -static void getVisibleAreaTwips(GtkWidget* pDocView, GdkRectangle* pArea) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pDocView); - - GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(rWindow.m_pScrolledWindow)); - GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(rWindow.m_pScrolledWindow)); - - pArea->x = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), - gtk_adjustment_get_value(pHAdjustment)); - pArea->y = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), - gtk_adjustment_get_value(pVAdjustment)); - pArea->width = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), - gtk_adjustment_get_page_size(pHAdjustment)); - pArea->height = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), - gtk_adjustment_get_page_size(pVAdjustment)); -} - -static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ ) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - GtkWidget* pDocView = rWindow.m_pDocView; - - const char *sName = gtk_tool_button_get_icon_name( GTK_TOOL_BUTTON(pButton) ); - - float fZoom = 0; - float fCurrentZoom = 0; - - if ( pDocView ) - { - fCurrentZoom = lok_doc_view_get_zoom( LOK_DOC_VIEW(pDocView) ); - } - - if ( strcmp(sName, "zoom-in-symbolic") == 0) - { - for ( unsigned int i = 0; i < SAL_N_ELEMENTS( fZooms ); i++ ) - { - if ( fCurrentZoom < fZooms[i] ) - { - fZoom = fZooms[i]; - break; - } - } - } - else if ( strcmp(sName, "zoom-original-symbolic") == 0) - { - fZoom = 1; - } - else if ( strcmp(sName, "zoom-out-symbolic") == 0) - { - for ( unsigned int i = 0; i < SAL_N_ELEMENTS( fZooms ); i++ ) - { - if ( fCurrentZoom > fZooms[i] ) - { - fZoom = fZooms[i]; - } - } - } - - if ( fZoom != 0 ) - { - if ( pDocView ) - { - lok_doc_view_set_zoom( LOK_DOC_VIEW(pDocView), fZoom ); - GdkRectangle aVisibleArea; - getVisibleAreaTwips(pDocView, &aVisibleArea); - lok_doc_view_set_visible_area(LOK_DOC_VIEW(pDocView), &aVisibleArea); - } - } - std::string aZoom = std::string("Zoom: ") + std::to_string(int(fZoom * 100)) + std::string("%"); - gtk_label_set_text(GTK_LABEL(rWindow.m_pZoomLabel), aZoom.c_str()); -} - -/// User clicked on the button -> inform LOKDocView. -static void toggleEditing(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - - LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView); - bool bActive = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(rWindow.m_pEnableEditing)); - if (bool(lok_doc_view_get_edit(pLOKDocView)) != bActive) - lok_doc_view_set_edit(pLOKDocView, bActive); -} - -/// Toggles if search should find all results or only the first one. -static void toggleFindAll(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - GtkEntry* pEntry = GTK_ENTRY(rWindow.m_pFindbarEntry); - const char* pText = gtk_entry_get_text(pEntry); - - rWindow.m_bFindAll = !rWindow.m_bFindAll; - lok_doc_view_highlight_all(LOK_DOC_VIEW(rWindow.m_pDocView), pText); -} - -/// Toggle the visibility of the findbar. -static void toggleFindbar(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - if (gtk_widget_get_visible(rWindow.m_pFindbar)) - { - gtk_widget_hide(rWindow.m_pFindbar); - } - else - { - gtk_widget_show_all(rWindow.m_pFindbar); - gtk_widget_grab_focus(rWindow.m_pFindbarEntry); - } -} - -static void -setLOKFeatures (GtkWidget* pDocView, gboolean bTiledAnnotations) -{ - g_object_set(G_OBJECT(pDocView), - "doc-password", TRUE, - "doc-password-to-modify", TRUE, - "tiled-annotations", bTiledAnnotations, - nullptr); -} - -/// Common initialization, regardless if it's just a new view or a full init. -static TiledWindow& setupWidgetAndCreateWindow(GtkWidget* pDocView, gboolean bTiledAnnotations) -{ - setupDocView(pDocView); - setLOKFeatures(pDocView, bTiledAnnotations); - TiledWindow aWindow; - aWindow.m_pDocView = pDocView; - GtkWidget* pWindow = createWindow(aWindow); - return lcl_getTiledWindow(pWindow); -} - -/// Register handlers on the combo boxes. -static void registerSelectorHandlers(TiledWindow& rWindow) -{ - // Connect these signals after populating the selectors, to avoid re-rendering on setting the default part/partmode. - g_signal_connect(G_OBJECT(rWindow.m_pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0); - g_signal_connect(G_OBJECT(rWindow.m_pPartSelector), "changed", G_CALLBACK(changePart), 0); -} - -/// Helper function to do some tasks after widget is fully loaded (including -/// document load) -static void initWindow(TiledWindow& rWindow) -{ - rWindow.m_bPartSelectorBroadcast = false; - populatePartSelector(LOK_DOC_VIEW(rWindow.m_pDocView)); - rWindow.m_bPartSelectorBroadcast = true; - - populatePartModeSelector( GTK_COMBO_BOX_TEXT(rWindow.m_pPartModeComboBox) ); - registerSelectorHandlers(rWindow); - - registerSelectorHandlers(rWindow); - - GList *focusChain = nullptr; - focusChain = g_list_append( focusChain, rWindow.m_pDocView ); - gtk_container_set_focus_chain ( GTK_CONTAINER (rWindow.m_pVBox), focusChain ); - - gtk_widget_show_all(rWindow.m_pStatusBar); - gtk_widget_hide(rWindow.m_pProgressBar); - - gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(rWindow.m_pEnableEditing), TRUE); - - LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(rWindow.m_pDocView)); - if (pDocument) - { - if (pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_SPREADSHEET) - { - // Align to top left corner, so the tiles are in sync with the - // row/column bar, even when zooming out enough that not all space is - // used. - gtk_widget_set_halign(GTK_WIDGET(rWindow.m_pDocView), GTK_ALIGN_START); - gtk_widget_set_valign(GTK_WIDGET(rWindow.m_pDocView), GTK_ALIGN_START); - - // Change cell alignment uno commands for spreadsheet - lcl_registerToolItem(rWindow, rWindow.m_pLeftpara, ".uno:AlignLeft"); - lcl_registerToolItem(rWindow, rWindow.m_pCenterpara, ".uno:AlignHorizontalCenter"); - lcl_registerToolItem(rWindow, rWindow.m_pRightpara, ".uno:AlignRight"); - gtk_widget_hide(GTK_WIDGET(rWindow.m_pJustifypara)); - - lcl_registerToolItem(rWindow, rWindow.m_pDeleteComment, ".uno:DeleteNote"); - } - else if (pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_PRESENTATION) - { - lcl_registerToolItem(rWindow, rWindow.m_pDeleteComment, ".uno:DeleteAnnotation"); - } - } - - // Fill our comments sidebar - gboolean bTiledAnnotations; - g_object_get(G_OBJECT(rWindow.m_pDocView), "tiled-annotations", &bTiledAnnotations, nullptr); - - // comments api implemented only for writer, calc as of now - if (!bTiledAnnotations && pDocument) - { - if (!rWindow.m_pCommentsSidebar) - { - rWindow.m_pCommentsSidebar.reset(new CommentsSidebar); - rWindow.m_pCommentsSidebar->m_pCommentsVBox = nullptr; - rWindow.m_pCommentsSidebar->m_pScrolledWindow = nullptr; - rWindow.m_pCommentsSidebar->m_pMainVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_container_add(GTK_CONTAINER(rWindow.m_pMainHBox), rWindow.m_pCommentsSidebar->m_pMainVBox); - - rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton = 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(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton, 20); - gtk_widget_set_margin_end(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton, 20); -#endif - gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pMainVBox), rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton); - g_signal_connect(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton, "clicked", G_CALLBACK(CommentsSidebar::unoViewAnnotations), nullptr); - - gtk_widget_show_all(rWindow.m_pCommentsSidebar->m_pMainVBox); - - gtk_button_clicked(GTK_BUTTON(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton)); - } - } -} - -/// Creates a new view, i.e. no LOK init or document load. -static void createView(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - - boost::property_tree::ptree aTree = rWindow.m_aRenderingArguments; - rWindow.m_aAuthor = getNextAuthor(); - aTree.put(boost::property_tree::ptree::path_type(".uno:Author/type", '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type(".uno:Author/value", '/'), rWindow.m_aAuthor); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - std::string aArguments = aStream.str(); - - GtkWidget* pDocView = lok_doc_view_new_from_widget(LOK_DOC_VIEW(rWindow.m_pDocView), aArguments.c_str()); - gboolean bTiledAnnotations; - g_object_get(G_OBJECT(rWindow.m_pDocView), "tiled-annotations", &bTiledAnnotations, nullptr); - TiledWindow& rNewWindow = setupWidgetAndCreateWindow(pDocView, bTiledAnnotations); - initWindow(rNewWindow); - // Hide the unused progress bar. - gtk_widget_show_all(rNewWindow.m_pStatusBar); - gtk_widget_hide(rNewWindow.m_pProgressBar); -} - -/// Creates a new model, i.e. LOK init and document load, one view implicitly. -static void createModelAndView(const char* pLOPath, const char* pDocPath, const std::vector<std::string>& rArguments) -{ - std::string aUserProfile; - gboolean bTiledAnnotations = FALSE; - for (size_t i = 0; i < rArguments.size(); ++i) - { - const std::string& rArgument = rArguments[i]; - if (rArgument == "--user-profile" && i + 1 < rArguments.size()) - aUserProfile = std::string("vnd.sun.star.pathname:") - + rArguments[i + 1].c_str(); - else if (rArgument == "--enable-tiled-annotations") - bTiledAnnotations = TRUE; - } - const gchar* pUserProfile = aUserProfile.empty() ? nullptr : aUserProfile.c_str(); - GtkWidget* pDocView = lok_doc_view_new_from_user_profile(pLOPath, pUserProfile, nullptr, nullptr); - - TiledWindow& rWindow = setupWidgetAndCreateWindow(pDocView, bTiledAnnotations); - - boost::property_tree::ptree aTree; - for (size_t i = 0; i < rArguments.size(); ++i) - { - const std::string& rArgument = rArguments[i]; - if (rArgument == "--background-color" && i + 1 < rArguments.size()) - { - GdkRGBA color; - gdk_rgba_parse(&color, rArguments[i + 1].c_str()); - SAL_WNODEPRECATED_DECLARATIONS_PUSH - gtk_widget_override_background_color(gtk_widget_get_toplevel(pDocView), GTK_STATE_FLAG_NORMAL, &color); - SAL_WNODEPRECATED_DECLARATIONS_POP - } - else if (rArgument == "--hide-page-shadow") - { - aTree.put(boost::property_tree::ptree::path_type(".uno:ShowBorderShadow/type", '/'), "boolean"); - aTree.put(boost::property_tree::ptree::path_type(".uno:ShowBorderShadow/value", '/'), false); - } - else if (rArgument == "--hide-whitespace") - { - aTree.put(boost::property_tree::ptree::path_type(".uno:HideWhitespace/type", '/'), "boolean"); - aTree.put(boost::property_tree::ptree::path_type(".uno:HideWhitespace/value", '/'), true); - } - } - - // Save rendering arguments for views which are created later. - rWindow.m_aRenderingArguments = aTree; - rWindow.m_aAuthor = getNextAuthor(); - aTree.put(boost::property_tree::ptree::path_type(".uno:Author/type", '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type(".uno:Author/value", '/'), rWindow.m_aAuthor); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - std::string aArguments = aStream.str(); - lok_doc_view_open_document(LOK_DOC_VIEW(pDocView), pDocPath, aArguments.c_str(), nullptr, openDocumentCallback, pDocView); -} - -/// 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); -} - -/// Same as gtk_clipboard_set_text(), but sets HTML. -static void clipboardSetHtml(GtkClipboard* pClipboard, const char* pSelection) -{ - GtkTargetList* pList = gtk_target_list_new(nullptr, 0); - GdkAtom aAtom(gdk_atom_intern("text/html", false)); - gtk_target_list_add(pList, aAtom, 0, 0); - gint nTargets = 0; - GtkTargetEntry* pTargets = gtk_target_table_new_from_list(pList, &nTargets); - - gtk_clipboard_set_with_data(pClipboard, pTargets, nTargets, htmlGetFunc, htmlClearFunc, g_strdup(pSelection)); - - gtk_target_table_free(pTargets, nTargets); - gtk_target_list_unref(pList); -} - -/// Handler for the copy button: write clipboard. -static void doCopy(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView); - char* pUsedFormat = nullptr; - // TODO: Should check `text-selection` signal before trying to copy - char* pSelection = lok_doc_view_copy_selection(pLOKDocView, "text/html", &pUsedFormat); - if (!pSelection) - return; - - GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(rWindow.m_pDocView), GDK_SELECTION_CLIPBOARD); - std::string aUsedFormat(pUsedFormat); - if (aUsedFormat == "text/plain;charset=utf-8") - gtk_clipboard_set_text(pClipboard, pSelection, -1); - else - clipboardSetHtml(pClipboard, pSelection); - - free(pSelection); - free(pUsedFormat); -} - -static void doPaste(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView); - - GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(rWindow.m_pDocView), GDK_SELECTION_CLIPBOARD); - - GdkAtom* pTargets; - gint nTargets; - std::map<std::string, GdkAtom> aTargets; - if (gtk_clipboard_wait_for_targets(pClipboard, &pTargets, &nTargets)) - { - for (gint i = 0; i < nTargets; ++i) - { - gchar* pName = gdk_atom_name(pTargets[i]); - aTargets[pName] = pTargets[i]; - g_free(pName); - } - g_free(pTargets); - } - - boost::optional<GdkAtom> oTarget; - std::string aTargetName; - - std::vector<std::string> aPreferredNames = - { - std::string("image/png"), - std::string("text/html") - }; - for (const std::string& rName : aPreferredNames) - { - std::map<std::string, GdkAtom>::iterator it = aTargets.find(rName); - if (it != aTargets.end()) - { - aTargetName = it->first; - oTarget = it->second; - break; - } - } - - if (oTarget) - { - GtkSelectionData* pSelectionData = gtk_clipboard_wait_for_contents(pClipboard, *oTarget); - if (!pSelectionData) - { - return; - } - gint nLength; - const guchar* pData = gtk_selection_data_get_data_with_length(pSelectionData, &nLength); - bool bSuccess = lok_doc_view_paste(pLOKDocView, aTargetName.c_str(), reinterpret_cast<const char*>(pData), nLength); - gtk_selection_data_free(pSelectionData); - if (bSuccess) - return; - } - - gchar* pText = gtk_clipboard_wait_for_text(pClipboard); - if (pText) - lok_doc_view_paste(pLOKDocView, "text/plain;charset=utf-8", pText, strlen(pText)); -} - -/// Click handler for the search next button. -static void signalSearchNext(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - GtkEntry* pEntry = GTK_ENTRY(rWindow.m_pFindbarEntry); - const char* pText = gtk_entry_get_text(pEntry); - - lok_doc_view_find_next(LOK_DOC_VIEW(rWindow.m_pDocView), pText, rWindow.m_bFindAll); -} - -/// Click handler for the search previous button. -static void signalSearchPrev(GtkWidget* pButton, gpointer /*pItem*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pButton); - GtkEntry* pEntry = GTK_ENTRY(rWindow.m_pFindbarEntry); - const char* pText = gtk_entry_get_text(pEntry); - - lok_doc_view_find_prev(LOK_DOC_VIEW(rWindow.m_pDocView), pText, rWindow.m_bFindAll); -} - -/// Handles the key-press-event of the search entry widget. -static gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pWidget); - gtk_label_set_text(GTK_LABEL(rWindow.m_pFindbarLabel), ""); - switch(pEvent->keyval) - { - case GDK_KEY_Return: - { - // Search forward. - signalSearchNext(pWidget, nullptr); - return TRUE; - } - case GDK_KEY_Escape: - { - // Hide the findbar. - gtk_widget_hide(rWindow.m_pFindbar); - return TRUE; - } - } - return FALSE; -} - -/// Handles the key-press-event of the address entry widget. -static gboolean signalAddressbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pWidget); - switch(pEvent->keyval) - { - case GDK_KEY_Return: - { - GtkEntry* pEntry = GTK_ENTRY(rWindow.m_pAddressbarEntry); - const char* pText = gtk_entry_get_text(pEntry); - - boost::property_tree::ptree aTree; - aTree.put(boost::property_tree::ptree::path_type("ToPoint/type", '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type("ToPoint/value", '/'), pText); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - std::string aArguments = aStream.str(); - - lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), ".uno:GoToCell", aArguments.c_str(), false); - gtk_widget_grab_focus(rWindow.m_pDocView); - return TRUE; - } - case GDK_KEY_Escape: - { - std::string aArguments; - lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), ".uno:Cancel", aArguments.c_str(), false); - gtk_widget_grab_focus(rWindow.m_pDocView); - return TRUE; - } - } - return FALSE; -} - -/// Handles the key-press-event of the formula entry widget. -static gboolean signalFormulabar(GtkWidget* /*pWidget*/, GdkEventKey* /*pEvent*/, gpointer /*pData*/) -{ - // for now it just displays the callback - // TODO - submit the edited formula - return TRUE; -} - -/// Set sensitivity based on rWindow.m_aToolItemSensitivities, taking edit -/// state into account. -static void setSensitiveIfInEdit(GtkToolItem* pItem, gboolean bEdit, TiledWindow& rWindow) -{ - gtk_widget_set_sensitive(GTK_WIDGET(pItem), bEdit && rWindow.m_aToolItemSensitivities[pItem]); -} - -/// LOKDocView changed edit state -> inform the tool button. -static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - gboolean bEdit = lok_doc_view_get_edit(pLOKDocView); - g_info("signalEdit: %d -> %d", bWasEdit, bEdit); - - // Set toggle button sensitivity - setSensitiveIfInEdit(rWindow.m_pBold, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pItalic, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pUnderline, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pStrikethrough, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pSuperscript, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pSubscript, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pLeftpara, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pCenterpara, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pRightpara, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pJustifypara, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pInsertAnnotation, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pDeleteComment, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pUndo, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pRedo, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pPasteButton, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pSaveButton, bEdit, rWindow); - setSensitiveIfInEdit(rWindow.m_pTrackChanges, bEdit, rWindow); -} - -/// LOKDocView changed command state -> inform the tool button. -static void signalCommand(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - - std::string aPayload(pPayload); - size_t nPosition = aPayload.find('='); - if (nPosition != std::string::npos) - { - std::string aKey = aPayload.substr(0, nPosition); - std::string aValue = aPayload.substr(nPosition + 1); - if (rWindow.m_aCommandNameToolItems.find(aKey) != rWindow.m_aCommandNameToolItems.end()) - { - GtkToolItem* pItem = rWindow.m_aCommandNameToolItems[aKey]; - if (aValue == "true" || aValue == "false") { - gboolean bEdit = aValue == "true"; - if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pItem)) != bEdit) - { - // Avoid invoking lok_doc_view_post_command(). - rWindow.m_bToolItemBroadcast = false; - gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pItem), bEdit); - rWindow.m_bToolItemBroadcast = true; - } - } else if (aValue == "enabled" || aValue == "disabled") { - gboolean bSensitive = aValue == "enabled"; - gtk_widget_set_sensitive(GTK_WIDGET(pItem), bSensitive); - - // Remember state, so in case edit is disable and enabled - // later, the correct sensitivity can be restored. - rWindow.m_aToolItemSensitivities[pItem] = bSensitive; - } - } - else if (aKey == ".uno:TrackedChangeIndex") - { - std::string aText = std::string("Current redline: "); - if (aValue.empty()) - aText += "none"; - else - aText += aValue; - gtk_label_set_text(GTK_LABEL(rWindow.m_pRedlineLabel), aText.c_str()); - } - } -} - -/// LOKDocView command finished -> just write it to the console, not that useful for the viewer. -static void signalCommandResult(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer /*pData*/) -{ - fprintf(stderr, "Command finished: %s\n", pPayload); -} - -static void loadChanged(LOKDocView* /*pLOKDocView*/, gdouble fValue, gpointer pData) -{ - GtkWidget* pProgressBar = GTK_WIDGET (pData); - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(pProgressBar), fValue); -} - -/// LOKDocView found no search matches -> set the search label accordingly. -static void signalSearch(LOKDocView* pLOKDocView, char* /*pPayload*/, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - gtk_label_set_text(GTK_LABEL(rWindow.m_pFindbarLabel), "Search key not found"); -} - -/// LOKDocView found some search matches -> set the search label accordingly. -static void signalSearchResultCount(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - std::stringstream ss; - ss << pPayload << " match(es)"; - gtk_label_set_text(GTK_LABEL(rWindow.m_pFindbarLabel), ss.str().c_str()); -} - -static void signalPart(LOKDocView* pLOKDocView, int nPart, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - rWindow.m_bPartSelectorBroadcast = false; - gtk_combo_box_set_active(GTK_COMBO_BOX(rWindow.m_pPartSelector), nPart); - rWindow.m_bPartSelectorBroadcast = true; -} - -/// User clicked on a command button -> inform LOKDocView. -static void signalHyperlink(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pData*/) -{ - GError* pError = nullptr; -#if GTK_CHECK_VERSION(3,22,0) - gtk_show_uri_on_window( - GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pLOKDocView))), - pPayload, GDK_CURRENT_TIME, &pError); -#else - (void) pLOKDocView; - gtk_show_uri(nullptr, pPayload, GDK_CURRENT_TIME, &pError); -#endif - if (pError != nullptr) - { - g_warning("Unable to show URI %s : %s", pPayload, pError->message); - g_error_free(pError); - } -} - -/// Cursor position changed -static void cursorChanged(LOKDocView* pDocView, gint nX, gint nY, - gint /*nWidth*/, gint /*nHeight*/, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pDocView)); - - GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(rWindow.m_pScrolledWindow)); - GtkAdjustment* hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(rWindow.m_pScrolledWindow)); - GdkRectangle visArea; - gdouble upper; - gint x = -1, y = -1; - - getVisibleAreaTwips(GTK_WIDGET(pDocView), &visArea); - - // check vertically - if (nY < visArea.y) - { - y = nY - visArea.height/2; - if (y < 0) - y = gtk_adjustment_get_lower(vadj); - } - else if (nY > visArea.y + visArea.height) - { - y = nY - visArea.height/2; - upper = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), gtk_adjustment_get_upper(vadj)); - if (y > upper) - y = upper; - - } - - if (nX < visArea.x) - { - x = nX - visArea.width/2; - if (x < 0) - x = gtk_adjustment_get_lower(hadj); - } - else if (nX > visArea.x + visArea.width) - { - x = nX - visArea.width/2; - upper = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), gtk_adjustment_get_upper(hadj)); - if (x > upper) - x = upper; - } - - if (y!=-1) - gtk_adjustment_set_value(vadj, lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), y)); - if (x!=-1) - gtk_adjustment_set_value(hadj, lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), x)); -} - -/// LOKDocView the address has changed -static void addressChanged(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - gtk_entry_set_text(GTK_ENTRY(rWindow.m_pAddressbarEntry), pPayload); -} - -/// LOKDocView the formula has changed -static void formulaChanged(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - gtk_entry_set_text(GTK_ENTRY(rWindow.m_pFormulabarEntry), pPayload); -} - -/// LOKDocView password is required to open the document -static void passwordRequired(LOKDocView* pLOKDocView, gchar* pUrl, gboolean bModify, gpointer /*pData*/) -{ - GtkWidget* pPasswordDialog = gtk_dialog_new_with_buttons ("Password required", - GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pLOKDocView))), - GTK_DIALOG_MODAL, - "OK", - GTK_RESPONSE_OK, - nullptr); - g_object_set(G_OBJECT(pPasswordDialog), "resizable", FALSE, nullptr); - GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pPasswordDialog)); - GtkWidget* pPasswordEntry = gtk_entry_new (); - gtk_entry_set_visibility (GTK_ENTRY(pPasswordEntry), FALSE); - gtk_entry_set_invisible_char (GTK_ENTRY(pPasswordEntry), '*'); - gtk_box_pack_end(GTK_BOX(pDialogMessageArea), pPasswordEntry, TRUE, TRUE, 2); - if (bModify) - { - GtkWidget* pSecondaryLabel = gtk_label_new ("Document requires password to edit"); - gtk_box_pack_end(GTK_BOX(pDialogMessageArea), pSecondaryLabel, TRUE, TRUE, 2); - gtk_dialog_add_button (GTK_DIALOG (pPasswordDialog), "Open as read-only", GTK_RESPONSE_ACCEPT); - } - gtk_widget_show_all(pPasswordDialog); - - gint res = gtk_dialog_run (GTK_DIALOG(pPasswordDialog)); - switch (res) - { - case GTK_RESPONSE_OK: - lok_doc_view_set_document_password (pLOKDocView, pUrl, gtk_entry_get_text(GTK_ENTRY(pPasswordEntry))); - break; - case GTK_RESPONSE_ACCEPT: - // User accepts to open this document as read-only - case GTK_RESPONSE_DELETE_EVENT: - lok_doc_view_set_document_password (pLOKDocView, pUrl, nullptr); - break; - } - - gtk_widget_destroy(pPasswordDialog); -} - -static void commentCallback(LOKDocView* pLOKDocView, gchar* pComment, gpointer /* pData */) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - std::stringstream aStream(pComment); - boost::property_tree::ptree aRoot; - boost::property_tree::read_json(aStream, aRoot); - boost::property_tree::ptree aComment = aRoot.get_child("comment"); - GtkWidget* pCommentsGrid = rWindow.m_pCommentsSidebar->m_pCommentsVBox; - GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pCommentsGrid)); - GtkWidget* pSelf = nullptr; - GtkWidget* pParent = nullptr; - for (GList* l = pChildren; l != nullptr; l = l->next) - { - gchar *id = static_cast<gchar*>(g_object_get_data(G_OBJECT(l->data), "id")); - - if (g_strcmp0(id, aComment.get<std::string>("id").c_str()) == 0) - pSelf = GTK_WIDGET(l->data); - - // There is no 'parent' in Remove callbacks - if (g_strcmp0(id, aComment.get("parent", std::string("0")).c_str()) == 0) - pParent = GTK_WIDGET(l->data); - } - - if (aComment.get<std::string>("action") == "Remove") - { - if (pSelf) - gtk_widget_destroy(pSelf); - else - g_warning("Can't find the comment to remove in the list !!"); - } - else if (aComment.get<std::string>("action") == "Add" || aComment.get<std::string>("action") == "Modify") - { - GtkWidget* pCommentBox = CommentsSidebar::createCommentBox(aComment); - if (pSelf != nullptr || pParent != nullptr) - { - gtk_grid_insert_next_to(GTK_GRID(pCommentsGrid), pSelf != nullptr ? pSelf : pParent, GTK_POS_BOTTOM); - gtk_grid_attach_next_to(GTK_GRID(pCommentsGrid), pCommentBox, pSelf != nullptr ? pSelf : pParent, GTK_POS_BOTTOM, 1, 1); - } - else - gtk_container_add(GTK_CONTAINER(pCommentsGrid), pCommentBox); - - gtk_widget_show_all(pCommentBox); - - // We added the widget already below the existing one, so destroy the - // already existing one now - if (pSelf) - gtk_widget_destroy(pSelf); - } -} - -static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/) -{ - TiledWindow& rWindow = lcl_getTiledWindow(pWidget); - - if (rWindow.m_bToolItemBroadcast) - { - LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView); - GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget); - const std::string& rString = rWindow.m_aToolItemCommandNames[pItem]; - std::string& rArguments = rWindow.m_aToolItemCommandArgs[pItem]; - - if (rString == ".uno:InsertAnnotation") - { - std::map<std::string, std::string> aEntries; - aEntries["Text"] = ""; - userPromptDialog(rWindow.m_pDocView, "Insert Comment", aEntries); - - boost::property_tree::ptree aTree; - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string"); - aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), aEntries["Text"]); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - rArguments = aStream.str(); - } - - g_info("toggleToolItem: lok_doc_view_post_command('%s %s')", rString.c_str(), rArguments.c_str()); - - // notify about the finished Save - gboolean bNotify = (rString == ".uno:Save"); - - lok_doc_view_post_command(pLOKDocView, rString.c_str(), rArguments.c_str(), bNotify); - } -} - -static void populatePartSelector(LOKDocView* pLOKDocView) -{ - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView)); - gtk_list_store_clear( GTK_LIST_STORE( - gtk_combo_box_get_model( - GTK_COMBO_BOX(rWindow.m_pPartSelector) )) ); - - if (!pLOKDocView) - { - return; - } - - const int nMaxLength = 50; - char sText[nMaxLength]; - - int nParts = lok_doc_view_get_parts(pLOKDocView); - for ( int i = 0; i < nParts; i++ ) - { - char* pName = lok_doc_view_get_part_name(pLOKDocView, i); - assert( pName ); - snprintf( sText, nMaxLength, "%i (%s)", i+1, pName ); - free( pName ); - - gtk_combo_box_text_append_text( rWindow.m_pPartSelector, sText ); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(rWindow.m_pPartSelector), lok_doc_view_get_part(pLOKDocView)); -} - -static void changePart( GtkWidget* pSelector, gpointer /* pItem */ ) -{ - int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) ); - TiledWindow& rWindow = lcl_getTiledWindow(pSelector); - - if (rWindow.m_bPartSelectorBroadcast && rWindow.m_pDocView) - { - lok_doc_view_set_part( LOK_DOC_VIEW(rWindow.m_pDocView), nPart ); - lok_doc_view_reset_view(LOK_DOC_VIEW(rWindow.m_pDocView)); - } -} - -static void removeChildrenFromStatusbar(GtkWidget* children, gpointer pData) -{ - GtkWidget* pStatusBar = static_cast<GtkWidget*>(pData); - - gtk_container_remove(GTK_CONTAINER(pStatusBar), children); -} - -static void populatePartModeSelector( GtkComboBoxText* pSelector ) -{ - gtk_combo_box_text_append_text( pSelector, "Standard" ); - gtk_combo_box_text_append_text( pSelector, "Notes" ); - gtk_combo_box_set_active( GTK_COMBO_BOX(pSelector), 0 ); -} - -static void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ ) -{ - // Just convert directly back to the LibreOfficeKitPartMode enum. - // I.e. the ordering above should match the enum member ordering. - LibreOfficeKitPartMode ePartMode = - LibreOfficeKitPartMode( gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) ) ); - TiledWindow& rWindow = lcl_getTiledWindow(pSelector); - - if ( rWindow.m_pDocView ) - { - lok_doc_view_set_partmode( LOK_DOC_VIEW(rWindow.m_pDocView), ePartMode ); - } -} - -static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpointer /*userdata*/) -{ - LOKDocView* pDocView = LOK_DOC_VIEW (source_object); - TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pDocView)); - GError* error = nullptr; - - if (!lok_doc_view_open_document_finish(pDocView, res, &error)) - { - GtkWidget* pDialog = gtk_message_dialog_new(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "Error occurred while opening the document: '%s'", - error->message); - gtk_dialog_run(GTK_DIALOG(pDialog)); - gtk_widget_destroy(pDialog); - - g_error_free(error); - gtk_widget_destroy(GTK_WIDGET(pDocView)); - gtk_main_quit(); - return; - } - - initWindow(rWindow); -} - -/** - * Wrapper around gtk_widget_destroy() that quits when the last tiled window is - * destroyed. - */ -static void destroyWindow(GtkWidget* pWidget) -{ - gtk_widget_destroy(pWidget); - auto it = g_aWindows.find(pWidget); - if (it != g_aWindows.end()) - g_aWindows.erase(it); - - if (g_aWindows.empty()) - gtk_main_quit(); -} - -/// Creates the GtkWindow that has main widget as children and registers it in the window map. -static GtkWidget* createWindow(TiledWindow& rWindow) -{ - GtkWidget *pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(pWindow), "LibreOfficeKit GTK Tiled Viewer"); - gtk_window_set_default_size(GTK_WINDOW(pWindow), 1024, 768); - g_signal_connect(pWindow, "destroy", G_CALLBACK(destroyWindow), pWindow); - - rWindow.m_pVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_container_add(GTK_CONTAINER(pWindow), rWindow.m_pVBox); - - // Upper toolbar. - GtkWidget* pUpperToolbar = gtk_toolbar_new(); - gtk_toolbar_set_style(GTK_TOOLBAR(pUpperToolbar), GTK_TOOLBAR_ICONS); - - // Save. - rWindow.m_pSaveButton = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pSaveButton), "document-save-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pSaveButton, "Save"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), rWindow.m_pSaveButton, -1); - g_signal_connect(G_OBJECT(rWindow.m_pSaveButton), "clicked", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pSaveButton, ".uno:Save"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pSaveButton), false); - - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), gtk_separator_tool_item_new(), -1); - - // Copy and paste. - rWindow.m_pCopyButton = gtk_tool_button_new( nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pCopyButton), "edit-copy-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pCopyButton, "Copy"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), rWindow.m_pCopyButton, -1); - g_signal_connect(G_OBJECT(rWindow.m_pCopyButton), "clicked", G_CALLBACK(doCopy), nullptr); - - rWindow.m_pPasteButton = gtk_tool_button_new( nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pPasteButton), "edit-paste-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pPasteButton, "Paste"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), rWindow.m_pPasteButton, -1); - g_signal_connect(G_OBJECT(rWindow.m_pPasteButton), "clicked", G_CALLBACK(doPaste), nullptr); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pPasteButton), false); - - gtk_toolbar_insert( GTK_TOOLBAR(pUpperToolbar), gtk_separator_tool_item_new(), -1); - - // Undo, redo and document repair. - rWindow.m_pUndo = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pUndo), "edit-undo-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pUndo, "Undo"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), rWindow.m_pUndo, -1); - g_signal_connect(G_OBJECT(rWindow.m_pUndo), "clicked", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pUndo, ".uno:Undo"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pUndo), false); - - rWindow.m_pRedo = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pRedo), "edit-redo-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pRedo, "Redo"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), rWindow.m_pRedo, -1); - g_signal_connect(G_OBJECT(rWindow.m_pRedo), "clicked", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pRedo, ".uno:Redo"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pRedo), false); - - GtkToolItem* pDocumentRepair = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(pDocumentRepair), "document-properties"); - gtk_tool_item_set_tooltip_text(pDocumentRepair, "Document repair"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pDocumentRepair, -1); - g_signal_connect(G_OBJECT(pDocumentRepair), "clicked", G_CALLBACK(documentRepair), nullptr); - - GtkToolItem* pDocumentRedline = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(pDocumentRedline), "system-run"); - gtk_tool_item_set_tooltip_text(pDocumentRedline, "Document redlines"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pDocumentRedline, -1); - g_signal_connect(G_OBJECT(pDocumentRedline), "clicked", G_CALLBACK(documentRedline), nullptr); - - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), gtk_separator_tool_item_new(), -1); - - // Find. - GtkToolItem* pFindButton = gtk_tool_button_new( nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindButton), "edit-find-symbolic"); - gtk_tool_item_set_tooltip_text(pFindButton, "Find"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pFindButton, -1); - g_signal_connect(G_OBJECT(pFindButton), "clicked", G_CALLBACK(toggleFindbar), nullptr); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), gtk_separator_tool_item_new(), -1); - - // Misc upper toolbar. - GtkToolItem* pZoomIn = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pZoomIn), "zoom-in-symbolic"); - gtk_tool_item_set_tooltip_text(pZoomIn, "Zoom In"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pZoomIn, -1); - g_signal_connect(G_OBJECT(pZoomIn), "clicked", G_CALLBACK(changeZoom), nullptr); - - GtkToolItem* pZoom1 = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(pZoom1), "zoom-original-symbolic"); - gtk_tool_item_set_tooltip_text(pZoom1, "Normal Size"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pZoom1, -1); - g_signal_connect(G_OBJECT(pZoom1), "clicked", G_CALLBACK(changeZoom), nullptr); - - GtkToolItem* pZoomOut = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pZoomOut), "zoom-out-symbolic"); - gtk_tool_item_set_tooltip_text(pZoomOut, "Zoom Out"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pZoomOut, -1); - g_signal_connect(G_OBJECT(pZoomOut), "clicked", G_CALLBACK(changeZoom), nullptr); - - GtkToolItem* pPartSelectorToolItem = gtk_tool_item_new(); - GtkWidget* pComboBox = gtk_combo_box_text_new(); - gtk_container_add(GTK_CONTAINER(pPartSelectorToolItem), pComboBox); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pPartSelectorToolItem, -1); - - rWindow.m_pPartSelector = GTK_COMBO_BOX_TEXT(pComboBox); - - GtkToolItem* pPartModeSelectorToolItem = gtk_tool_item_new(); - rWindow.m_pPartModeComboBox = gtk_combo_box_text_new(); - gtk_container_add(GTK_CONTAINER(pPartModeSelectorToolItem), rWindow.m_pPartModeComboBox); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pPartModeSelectorToolItem, -1); - - GtkToolItem* pEnableEditing = gtk_toggle_tool_button_new(); - rWindow.m_pEnableEditing = pEnableEditing; - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pEnableEditing), "insert-text-symbolic"); - gtk_tool_item_set_tooltip_text(pEnableEditing, "Edit"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pEnableEditing, -1); - g_signal_connect(G_OBJECT(pEnableEditing), "toggled", G_CALLBACK(toggleEditing), nullptr); - - // UNO command dialog debugger - GtkToolItem* pUnoCmdDebugger = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(pUnoCmdDebugger), "dialog-question-symbolic"); - gtk_tool_item_set_tooltip_text(pUnoCmdDebugger, "UNO Command Debugger"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pUnoCmdDebugger, -1); - g_signal_connect(G_OBJECT(pUnoCmdDebugger), "clicked", G_CALLBACK(unoCommandDebugger), nullptr); - - // New view button. - GtkToolItem* pNewViewButton = gtk_tool_button_new( nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pNewViewButton), "view-continuous-symbolic"); - gtk_tool_item_set_tooltip_text(pNewViewButton, "New View"); - gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pNewViewButton, -1); - g_signal_connect(G_OBJECT(pNewViewButton), "clicked", G_CALLBACK(createView), nullptr); - - gtk_box_pack_start(GTK_BOX(rWindow.m_pVBox), pUpperToolbar, FALSE, FALSE, 0 ); // Adds to top. - - // Lower toolbar. - GtkWidget* pLowerToolbar = gtk_toolbar_new(); - gtk_toolbar_set_style(GTK_TOOLBAR(pLowerToolbar), GTK_TOOLBAR_ICONS); - - // Bold, italic, underline and strikethrough. - rWindow.m_pBold = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pBold), "format-text-bold-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pBold, "Bold"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pBold, -1); - g_signal_connect(G_OBJECT(rWindow.m_pBold), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pBold, ".uno:Bold"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pBold), false); - - rWindow.m_pItalic = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (rWindow.m_pItalic), "format-text-italic-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pItalic, "Italic"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pItalic, -1); - g_signal_connect(G_OBJECT(rWindow.m_pItalic), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pItalic, ".uno:Italic"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pItalic), false); - - rWindow.m_pUnderline = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (rWindow.m_pUnderline), "format-text-underline-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pUnderline, "Underline"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pUnderline, -1); - g_signal_connect(G_OBJECT(rWindow.m_pUnderline), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pUnderline, ".uno:Underline"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pUnderline), false); - - rWindow.m_pStrikethrough = gtk_toggle_tool_button_new (); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pStrikethrough), "format-text-strikethrough-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pStrikethrough, "Strikethrough"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pStrikethrough, -1); - g_signal_connect(G_OBJECT(rWindow.m_pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pStrikethrough, ".uno:Strikeout"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pStrikethrough), false); - - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), gtk_separator_tool_item_new(), -1); - - // Superscript and subscript. - rWindow.m_pSuperscript = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pSuperscript), "go-up-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pSuperscript, "Superscript"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pSuperscript, -1); - g_signal_connect(G_OBJECT(rWindow.m_pSuperscript), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pSuperscript, ".uno:SuperScript"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pSuperscript), false); - - rWindow.m_pSubscript = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pSubscript), "go-down-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pSubscript, "Subscript"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pSubscript, -1); - g_signal_connect(G_OBJECT(rWindow.m_pSubscript), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pSubscript, ".uno:SubScript"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pSubscript), false); - - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), gtk_separator_tool_item_new(), -1); - - // Align left, center horizontally, align right and justified. - rWindow.m_pLeftpara = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pLeftpara), "format-justify-left-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pLeftpara, "Align Left"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pLeftpara, -1); - g_signal_connect(G_OBJECT(rWindow.m_pLeftpara), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pLeftpara, ".uno:LeftPara"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pLeftpara), false); - - rWindow.m_pCenterpara = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pCenterpara), "format-justify-center-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pCenterpara, "Center Horizontally"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pCenterpara, -1); - g_signal_connect(G_OBJECT(rWindow.m_pCenterpara), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pCenterpara, ".uno:CenterPara"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pCenterpara), false); - - rWindow.m_pRightpara = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pRightpara), "format-justify-right-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pRightpara, "Align Right"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pRightpara, -1); - g_signal_connect(G_OBJECT(rWindow.m_pRightpara), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pRightpara, ".uno:RightPara"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pRightpara), false); - - rWindow.m_pJustifypara = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pJustifypara), "format-justify-fill-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pJustifypara, "Justified"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pJustifypara, -1); - g_signal_connect(G_OBJECT(rWindow.m_pJustifypara), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pJustifypara, ".uno:JustifyPara"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pJustifypara), false); - - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), gtk_separator_tool_item_new(), -1); - - // Insert/delete comments. - rWindow.m_pInsertAnnotation = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pInsertAnnotation), "changes-allow-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pInsertAnnotation, "Insert Comment"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pInsertAnnotation, -1); - g_signal_connect(G_OBJECT(rWindow.m_pInsertAnnotation), "clicked", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pInsertAnnotation, ".uno:InsertAnnotation"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pInsertAnnotation), false); - - rWindow.m_pDeleteComment = gtk_tool_button_new(nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pDeleteComment), "changes-prevent-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pDeleteComment, "Delete Comment"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pDeleteComment, -1); - g_signal_connect(G_OBJECT(rWindow.m_pDeleteComment), "clicked", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pDeleteComment, ".uno:DeleteComment"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pDeleteComment), false); - - // Track changes - rWindow.m_pTrackChanges = gtk_toggle_tool_button_new(); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pTrackChanges), "media-record-symbolic"); - gtk_tool_item_set_tooltip_text(rWindow.m_pTrackChanges, "Track Changes"); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pTrackChanges, -1); - g_signal_connect(G_OBJECT(rWindow.m_pTrackChanges), "toggled", G_CALLBACK(toggleToolItem), nullptr); - lcl_registerToolItem(rWindow, rWindow.m_pTrackChanges, ".uno:TrackChanges"); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pTrackChanges), false); - - // Address bar - GtkToolItem* pAddressEntryContainer = gtk_tool_item_new(); - rWindow.m_pAddressbarEntry = gtk_entry_new(); - gtk_container_add(GTK_CONTAINER(pAddressEntryContainer), rWindow.m_pAddressbarEntry); - g_signal_connect(rWindow.m_pAddressbarEntry, "key-press-event", G_CALLBACK(signalAddressbar), 0); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), pAddressEntryContainer, -1); - gtk_box_pack_start(GTK_BOX(rWindow.m_pVBox), pLowerToolbar, FALSE, FALSE, 0 ); // Adds to top. - - // Formula bar - GtkToolItem* pFormulaEntryContainer = gtk_tool_item_new(); - rWindow.m_pFormulabarEntry = gtk_entry_new(); - gtk_container_add(GTK_CONTAINER(pFormulaEntryContainer), rWindow.m_pFormulabarEntry); - g_signal_connect(rWindow.m_pFormulabarEntry, "key-press-event", G_CALLBACK(signalFormulabar), 0); - gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), pFormulaEntryContainer, -1); - gtk_box_pack_start(GTK_BOX(rWindow.m_pVBox), pLowerToolbar, FALSE, FALSE, 0 ); // Adds to top. - - // Findbar - rWindow.m_pFindbar = gtk_toolbar_new(); - gtk_toolbar_set_style(GTK_TOOLBAR(rWindow.m_pFindbar), GTK_TOOLBAR_ICONS); - - GtkToolItem* pFindbarClose = gtk_tool_button_new( nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarClose), "window-close-symbolic"); - gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindbarClose, -1); - g_signal_connect(G_OBJECT(pFindbarClose), "clicked", G_CALLBACK(toggleFindbar), nullptr); - - GtkToolItem* pEntryContainer = gtk_tool_item_new(); - rWindow.m_pFindbarEntry = gtk_entry_new(); - gtk_container_add(GTK_CONTAINER(pEntryContainer), rWindow.m_pFindbarEntry); - g_signal_connect(rWindow.m_pFindbarEntry, "key-press-event", G_CALLBACK(signalFindbar), 0); - gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pEntryContainer, -1); - - GtkToolItem* pFindbarNext = gtk_tool_button_new( nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarNext), "go-down-symbolic"); - gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindbarNext, -1); - g_signal_connect(G_OBJECT(pFindbarNext), "clicked", G_CALLBACK(signalSearchNext), nullptr); - - GtkToolItem* pFindbarPrev = gtk_tool_button_new( nullptr, nullptr); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarPrev), "go-up-symbolic"); - gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindbarPrev, -1); - g_signal_connect(G_OBJECT(pFindbarPrev), "clicked", G_CALLBACK(signalSearchPrev), nullptr); - - GtkToolItem* pFindAll = gtk_toggle_tool_button_new(); - gtk_tool_button_set_label(GTK_TOOL_BUTTON(pFindAll), "Highlight All"); - gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindAll, -1); - g_signal_connect(G_OBJECT(pFindAll), "toggled", G_CALLBACK(toggleFindAll), nullptr); - - GtkToolItem* pFindbarLabelContainer = gtk_tool_item_new(); - rWindow.m_pFindbarLabel = gtk_label_new(""); - gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), rWindow.m_pFindbarLabel); - gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindbarLabelContainer, -1); - - gtk_box_pack_end(GTK_BOX(rWindow.m_pVBox), rWindow.m_pFindbar, FALSE, FALSE, 0); - - rWindow.m_pMainHBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_container_add(GTK_CONTAINER(rWindow.m_pVBox), rWindow.m_pMainHBox); - - // Grid for the row/column bar + doc view. - GtkWidget* pGrid = gtk_grid_new(); - gtk_container_add(GTK_CONTAINER(rWindow.m_pMainHBox), pGrid); - rWindow.m_pCornerButton.reset(new TiledCornerButton()); - // "A1" cell of the grid. - gtk_grid_attach(GTK_GRID(pGrid), rWindow.m_pCornerButton->m_pDrawingArea, 0, 0, 1, 1); - rWindow.m_pRowBar.reset(new TiledRowColumnBar(TiledRowColumnBar::ROW)); - // "A2" cell of the grid. - gtk_grid_attach(GTK_GRID(pGrid), rWindow.m_pRowBar->m_pDrawingArea, 0, 1, 1, 1); - rWindow.m_pColumnBar.reset(new TiledRowColumnBar(TiledRowColumnBar::COLUMN)); - // "B1" cell of the grid. - gtk_grid_attach(GTK_GRID(pGrid), rWindow.m_pColumnBar->m_pDrawingArea, 1, 0, 1, 1); - - // Scrolled window for DocView - rWindow.m_pScrolledWindow = gtk_scrolled_window_new(nullptr, nullptr); - gtk_widget_set_hexpand(rWindow.m_pScrolledWindow, TRUE); - gtk_widget_set_vexpand(rWindow.m_pScrolledWindow, TRUE); - // "B2" cell of the grid - gtk_grid_attach(GTK_GRID(pGrid), rWindow.m_pScrolledWindow, 1, 1, 1, 1); - - gtk_container_add(GTK_CONTAINER(rWindow.m_pScrolledWindow), rWindow.m_pDocView); - GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(rWindow.m_pScrolledWindow)); - g_signal_connect(pHAdjustment, "value-changed", G_CALLBACK(TiledRowColumnBar::docAdjustmentChanged), rWindow.m_pDocView); - GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(rWindow.m_pScrolledWindow)); - g_signal_connect(pVAdjustment, "value-changed", G_CALLBACK(TiledRowColumnBar::docAdjustmentChanged), rWindow.m_pDocView); - - rWindow.m_pProgressBar = gtk_progress_bar_new (); - g_signal_connect(rWindow.m_pDocView, "load-changed", G_CALLBACK(loadChanged), rWindow.m_pProgressBar); - - GtkWidget* pStatusBar = gtk_statusbar_new(); - rWindow.m_pStatusBar = pStatusBar; - gtk_container_forall(GTK_CONTAINER(pStatusBar), removeChildrenFromStatusbar, pStatusBar); - gtk_container_add (GTK_CONTAINER(rWindow.m_pVBox), pStatusBar); - gtk_container_add (GTK_CONTAINER(pStatusBar), rWindow.m_pProgressBar); - gtk_widget_set_hexpand(rWindow.m_pProgressBar, true); - - rWindow.m_pStatusbarLabel = gtk_label_new(""); - gtk_widget_set_hexpand(rWindow.m_pStatusbarLabel, TRUE); - gtk_container_add(GTK_CONTAINER(pStatusBar), rWindow.m_pStatusbarLabel); - - rWindow.m_pRedlineLabel = gtk_label_new("Current redline: none"); - gtk_container_add(GTK_CONTAINER(pStatusBar), rWindow.m_pRedlineLabel); - rWindow.m_pZoomLabel = gtk_label_new("Zoom: 100%"); - gtk_container_add(GTK_CONTAINER(pStatusBar), rWindow.m_pZoomLabel); - - gtk_widget_show_all(pWindow); - // Hide the findbar by default. - gtk_widget_hide(rWindow.m_pFindbar); - // Same for the row/column bar. - gtk_widget_hide(rWindow.m_pCornerButton->m_pDrawingArea); - gtk_widget_hide(rWindow.m_pRowBar->m_pDrawingArea); - gtk_widget_hide(rWindow.m_pColumnBar->m_pDrawingArea); - gtk_widget_hide(rWindow.m_pAddressbarEntry); - gtk_widget_hide(rWindow.m_pFormulabarEntry); - // Hide the non-progressbar children of the status bar by default. - gtk_widget_hide(rWindow.m_pStatusbarLabel); - gtk_widget_hide(rWindow.m_pRedlineLabel); - gtk_widget_hide(rWindow.m_pZoomLabel); - - g_aWindows[pWindow] = rWindow; - - g_signal_connect(rWindow.m_pDocView, "configure-event", G_CALLBACK(TiledRowColumnBar::docConfigureEvent), 0); - return pWindow; -} - -/// Common setup for DocView (regardless if it's just a new view or a document to be loaded). -static void setupDocView(GtkWidget* pDocView) -{ -#if GLIB_CHECK_VERSION(2,40,0) - g_assert_nonnull(pDocView); -#endif - g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), nullptr); - g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), nullptr); - g_signal_connect(pDocView, "command-result", G_CALLBACK(signalCommandResult), nullptr); - g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), nullptr); - g_signal_connect(pDocView, "search-result-count", G_CALLBACK(signalSearchResultCount), nullptr); - g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), nullptr); - g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), nullptr); - g_signal_connect(pDocView, "cursor-changed", G_CALLBACK(cursorChanged), nullptr); - g_signal_connect(pDocView, "address-changed", G_CALLBACK(addressChanged), nullptr); - g_signal_connect(pDocView, "formula-changed", G_CALLBACK(formulaChanged), nullptr); - g_signal_connect(pDocView, "password-required", G_CALLBACK(passwordRequired), nullptr); - g_signal_connect(pDocView, "comment", G_CALLBACK(commentCallback), nullptr); -} - -int main( int argc, char* argv[] ) -{ - if( argc < 3 || - ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) ) - return help(); - - if ( argv[1][0] != '/' ) - { - fprintf(stderr, "Absolute path required to libreoffice install\n"); - return 1; - } - - gtk_init( &argc, &argv ); - - std::vector<std::string> aArguments; - for (int i = 3; i < argc; ++i) - aArguments.push_back(argv[i]); - createModelAndView(argv[1], argv[2], aArguments); - - gtk_main(); - - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx new file mode 100644 index 000000000000..d69d09fc9e4f --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx @@ -0,0 +1,411 @@ +/* -*- 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 <memory> + +#include <LibreOfficeKit/LibreOfficeKitGtk.h> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> + +#include <gtv-application-window.hxx> +#include <gtv-main-toolbar.hxx> +#include <gtv-helpers.hxx> +#include <gtv-signal-handlers.hxx> +#include <gtv-lokdocview-signal-handlers.hxx> +#include <gtv-calc-header-bar.hxx> +#include <gtv-comments-sidebar.hxx> + +#include <boost/property_tree/json_parser.hpp> +#include <boost/optional.hpp> + +struct GtvApplicationWindowPrivate +{ + GtkWidget* container; + GtkWidget* gridcontainer; + GtkWidget* toolbarcontainer; + GtkWidget* scrolledwindowcontainer; + + gboolean toolbarBroadcast; + gboolean partSelectorBroadcast; + + // Rendering args; options with which lokdocview was rendered in this window + GtvRenderingArgs* m_pRenderingArgs; +}; + +G_DEFINE_TYPE_WITH_PRIVATE(GtvApplicationWindow, gtv_application_window, GTK_TYPE_APPLICATION_WINDOW); + +static GtvApplicationWindowPrivate* +getPrivate(GtvApplicationWindow* win) +{ + return static_cast<GtvApplicationWindowPrivate*>(gtv_application_window_get_instance_private(win)); +} + +static void +gtv_application_window_init(GtvApplicationWindow* win) +{ + const std::string uiFilePath = GtvHelpers::getDirPath(__FILE__) + std::string(UI_FILE_NAME); + GtvGtkWrapper<GtkBuilder> builder(gtk_builder_new_from_file(uiFilePath.c_str()), + [](GtkBuilder* pBuilder) { + g_object_unref(pBuilder); + }); + GtvApplicationWindowPrivate* priv = getPrivate(win); + + // This is the parent GtkBox holding everything + priv->container = GTK_WIDGET(gtk_builder_get_object(builder.get(), "container")); + // 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); + + priv->gridcontainer = GTK_WIDGET(gtk_builder_get_object(builder.get(), "maingrid")); + // scrolled window containing the main drawing area + win->scrolledwindow = GTK_WIDGET(gtk_builder_get_object(builder.get(), "scrolledwindow")); + // scrolledwindow container + priv->scrolledwindowcontainer = GTK_WIDGET(gtk_builder_get_object(builder.get(), "scrolledwindowcontainer")); + + GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(win->scrolledwindow)); + g_signal_connect(pHAdjustment, "value-changed", G_CALLBACK(docAdjustmentChanged), win); + GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(win->scrolledwindow)); + g_signal_connect(pVAdjustment, "value-changed", G_CALLBACK(docAdjustmentChanged), win); + + // calc header row bar + win->cornerarea = gtv_calc_header_bar_new(); + gtv_calc_header_bar_set_type_and_width(GTV_CALC_HEADER_BAR(win->cornerarea), CalcHeaderType::CORNER); + win->rowbar = gtv_calc_header_bar_new(); + gtv_calc_header_bar_set_type_and_width(GTV_CALC_HEADER_BAR(win->rowbar), CalcHeaderType::ROW); + win->columnbar = gtv_calc_header_bar_new(); + gtv_calc_header_bar_set_type_and_width(GTV_CALC_HEADER_BAR(win->columnbar), CalcHeaderType::COLUMN); + + // attach row/colum/corner to the container + gtk_grid_attach(GTK_GRID(priv->gridcontainer), win->cornerarea, 0, 0, 1, 1); + gtk_grid_attach(GTK_GRID(priv->gridcontainer), win->rowbar, 0, 1, 1, 1); + gtk_grid_attach(GTK_GRID(priv->gridcontainer), win->columnbar, 1, 0, 1, 1); + + // statusbar + win->statusbar = GTK_WIDGET(gtk_builder_get_object(builder.get(), "statusbar")); + win->redlinelabel = GTK_WIDGET(gtk_builder_get_object(builder.get(), "redlinelabel")); + win->zoomlabel = GTK_WIDGET(gtk_builder_get_object(builder.get(), "zoomlabel")); + + win->findtoolbar = GTK_WIDGET(gtk_builder_get_object(builder.get(), "findtoolbar")); + win->findbarlabel = GTK_WIDGET(gtk_builder_get_object(builder.get(), "findbar_label")); + win->findbarEntry = GTK_WIDGET(gtk_builder_get_object(builder.get(), "findbar_entry")); + win->findAll = GTK_WIDGET(gtk_builder_get_object(builder.get(), "findbar_findall")); + priv->toolbarBroadcast = true; + priv->partSelectorBroadcast = true; + + gtk_container_add(GTK_CONTAINER(win), priv->container); + + priv->m_pRenderingArgs = new GtvRenderingArgs(); +} + +static void +gtv_application_window_dispose(GObject* object) +{ + GtvApplicationWindowPrivate* priv = getPrivate(GTV_APPLICATION_WINDOW(object)); + + delete priv->m_pRenderingArgs; + priv->m_pRenderingArgs = nullptr; + + G_OBJECT_CLASS (gtv_application_window_parent_class)->dispose (object); +} + +static void +gtv_application_window_class_init(GtvApplicationWindowClass* klass) +{ + G_OBJECT_CLASS(klass)->dispose = gtv_application_window_dispose; +} + +/// Helper function to do some tasks after widget is fully loaded (including +/// document load) +static void initWindow(GtvApplicationWindow* window) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + + GList *focusChain = nullptr; + focusChain = g_list_append( focusChain, window->lokdocview ); + gtk_container_set_focus_chain ( GTK_CONTAINER (priv->container), focusChain ); + + // TODO: Implement progressbar in statubar + LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview)); + if (pDocument) + { + LibreOfficeKitDocumentType eDocType = static_cast<LibreOfficeKitDocumentType>(pDocument->pClass->getDocumentType(pDocument)); + if (eDocType == LOK_DOCTYPE_SPREADSHEET) + { + // Align to top left corner, so the tiles are in sync with the + // row/column bar, even when zooming out enough that not all space is + // used. + gtk_widget_set_halign(GTK_WIDGET(window->lokdocview), GTK_ALIGN_START); + gtk_widget_set_valign(GTK_WIDGET(window->lokdocview), GTK_ALIGN_START); + } + + // By default make the document editable in a new window + lok_doc_view_set_edit(LOK_DOC_VIEW(window->lokdocview), true); + // Let toolbar adjust its button accordingly + gtv_main_toolbar_doc_loaded(GTV_MAIN_TOOLBAR(priv->toolbarcontainer), eDocType, true /* Edit button state */); + } + + // Fill our comments sidebar + gboolean bTiledAnnotations; + g_object_get(G_OBJECT(window->lokdocview), "tiled-annotations", &bTiledAnnotations, nullptr); + if (!bTiledAnnotations && pDocument) + { + window->commentssidebar = gtv_comments_sidebar_new(); + gtk_container_add(GTK_CONTAINER(priv->scrolledwindowcontainer), window->commentssidebar); + // fill the comments sidebar + gtv_comments_sidebar_view_annotations(GTV_COMMENTS_SIDEBAR(window->commentssidebar)); + } +} + +static void +gtv_application_open_document_callback(GObject* source_object, GAsyncResult* res, gpointer /*userdata*/) +{ + LOKDocView* pDocView = LOK_DOC_VIEW (source_object); + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + GError* error = nullptr; + if (!lok_doc_view_open_document_finish(pDocView, res, &error)) + { + GtkWidget* pDialog = gtk_message_dialog_new(GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Error occurred while opening the document: '%s'", + error->message); + gtk_dialog_run(GTK_DIALOG(pDialog)); + gtk_widget_destroy(pDialog); + + g_error_free(error); + gtk_widget_destroy(GTK_WIDGET(pDocView)); + gtk_main_quit(); + return; + } + + initWindow(window); +} + +/// Get the visible area of the scrolled window +void gtv_application_window_get_visible_area(GtvApplicationWindow* pWindow, GdkRectangle* pArea) +{ + GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(pWindow->scrolledwindow)); + GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(pWindow->scrolledwindow)); + + pArea->x = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pWindow->lokdocview), + gtk_adjustment_get_value(pHAdjustment)); + pArea->y = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pWindow->lokdocview), + gtk_adjustment_get_value(pVAdjustment)); + pArea->width = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pWindow->lokdocview), + gtk_adjustment_get_page_size(pHAdjustment)); + pArea->height = lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pWindow->lokdocview), + gtk_adjustment_get_page_size(pVAdjustment)); +} + +void gtv_application_window_toggle_findbar(GtvApplicationWindow* window) +{ + if (gtk_widget_get_visible(window->findtoolbar)) + { + gtk_widget_hide(window->findtoolbar); + } + else + { + gtk_widget_show_all(window->findtoolbar); + gtk_widget_grab_focus(window->findtoolbar); + } +} + +GtkToolItem* gtv_application_window_find_tool_by_unocommand(GtvApplicationWindow* window, const std::string& unoCmd) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + GtkToolItem* result = nullptr; + + // Find in the first toolbar + GtkContainer* pToolbar1 = gtv_main_toolbar_get_first_toolbar(GTV_MAIN_TOOLBAR(priv->toolbarcontainer)); + GtvGtkWrapper<GList> pList(gtk_container_get_children(pToolbar1), + [](GList* l) + { + g_list_free(l); + }); + for (GList* l = pList.get(); l != nullptr; l = l->next) + { + if (GTK_IS_TOOL_BUTTON(l->data)) + { + GtkToolButton* pButton = GTK_TOOL_BUTTON(l->data); + const gchar* pLabel = gtk_tool_button_get_label(pButton); + if (g_strcmp0(unoCmd.c_str(), pLabel) == 0) + { + result = GTK_TOOL_ITEM(pButton); + } + } + } + + // Look in second toolbar if not found + GtkContainer* pToolbar2 = gtv_main_toolbar_get_second_toolbar(GTV_MAIN_TOOLBAR(priv->toolbarcontainer)); + pList.reset(gtk_container_get_children(pToolbar2)); + for (GList* l = pList.get(); result == nullptr && l != nullptr; l = l->next) + { + if (GTK_IS_TOOL_BUTTON(l->data)) + { + GtkToolButton* pButton = GTK_TOOL_BUTTON(l->data); + const gchar* pLabel = gtk_tool_button_get_label(pButton); + if (g_strcmp0(unoCmd.c_str(), pLabel) == 0) + { + result = GTK_TOOL_ITEM(pButton); + } + } + } + + return result; +} + +static const std::string +createRenderingArgsJSON(const GtvRenderingArgs* pRenderingArgs) +{ + boost::property_tree::ptree aTree; + if (pRenderingArgs->m_bHidePageShadow) + { + aTree.put(boost::property_tree::ptree::path_type(".uno:ShowBorderShadow/type", '/'), "boolean"); + aTree.put(boost::property_tree::ptree::path_type(".uno:ShowBorderShadow/value", '/'), false); + } + if (pRenderingArgs->m_bHideWhiteSpace) + { + aTree.put(boost::property_tree::ptree::path_type(".uno:HideWhitespace/type", '/'), "boolean"); + aTree.put(boost::property_tree::ptree::path_type(".uno:HideWhitespace/value", '/'), true); + } + aTree.put(boost::property_tree::ptree::path_type(".uno:Author/type", '/'), "string"); + aTree.put(boost::property_tree::ptree::path_type(".uno:Author/value", '/'), GtvHelpers::getNextAuthor()); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + return aStream.str(); +} + +static void setupDocView(GtvApplicationWindow* window) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + g_object_set(G_OBJECT(window->lokdocview), + "doc-password", TRUE, + "doc-password-to-modify", TRUE, + "tiled-annotations", priv->m_pRenderingArgs->m_bEnableTiledAnnotations, + nullptr); + +#if GLIB_CHECK_VERSION(2,40,0) + g_assert_nonnull(window->lokdocview); +#endif + g_signal_connect(window->lokdocview, "edit-changed", G_CALLBACK(LOKDocViewSigHandlers::editChanged), nullptr); + g_signal_connect(window->lokdocview, "command-changed", G_CALLBACK(LOKDocViewSigHandlers::commandChanged), nullptr); + g_signal_connect(window->lokdocview, "command-result", G_CALLBACK(LOKDocViewSigHandlers::commandResult), nullptr); + g_signal_connect(window->lokdocview, "search-not-found", G_CALLBACK(LOKDocViewSigHandlers::searchNotFound), nullptr); + g_signal_connect(window->lokdocview, "search-result-count", G_CALLBACK(LOKDocViewSigHandlers::searchResultCount), nullptr); + g_signal_connect(window->lokdocview, "part-changed", G_CALLBACK(LOKDocViewSigHandlers::partChanged), nullptr); + g_signal_connect(window->lokdocview, "hyperlink-clicked", G_CALLBACK(LOKDocViewSigHandlers::hyperlinkClicked), nullptr); + g_signal_connect(window->lokdocview, "cursor-changed", G_CALLBACK(LOKDocViewSigHandlers::cursorChanged), nullptr); + g_signal_connect(window->lokdocview, "address-changed", G_CALLBACK(LOKDocViewSigHandlers::addressChanged), nullptr); + g_signal_connect(window->lokdocview, "formula-changed", G_CALLBACK(LOKDocViewSigHandlers::formulaChanged), nullptr); + g_signal_connect(window->lokdocview, "password-required", G_CALLBACK(LOKDocViewSigHandlers::passwordRequired), nullptr); + g_signal_connect(window->lokdocview, "comment", G_CALLBACK(LOKDocViewSigHandlers::comment), nullptr); + + g_signal_connect(window->lokdocview, "configure-event", G_CALLBACK(LOKDocViewSigHandlers::configureEvent), nullptr); +} + +void +gtv_application_window_create_view_from_window(GtvApplicationWindow* window) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + GApplication* app = g_application_get_default(); + + GtvApplicationWindow* newWindow = GTV_APPLICATION_WINDOW(gtv_application_window_new(GTK_APPLICATION(app))); + const std::string aArguments = createRenderingArgsJSON(priv->m_pRenderingArgs); + newWindow->lokdocview = lok_doc_view_new_from_widget(LOK_DOC_VIEW(window->lokdocview), aArguments.c_str()); + setupDocView(newWindow); + + gtk_container_add(GTK_CONTAINER(newWindow->scrolledwindow), newWindow->lokdocview); + gtk_widget_show_all(newWindow->scrolledwindow); + gtk_window_present(GTK_WINDOW(newWindow)); + + initWindow(newWindow); +} + +void +gtv_application_window_load_document(GtvApplicationWindow* window, + const GtvRenderingArgs* aArgs, + const std::string& aDocPath) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + // keep a copy of it; we need to use these for creating new views later + *(priv->m_pRenderingArgs) = *aArgs; + + // setup lokdocview + window->lokdocview = lok_doc_view_new_from_user_profile(priv->m_pRenderingArgs->m_aLoPath.c_str(), + priv->m_pRenderingArgs->m_aUserProfile.empty() ? nullptr : priv->m_pRenderingArgs->m_aUserProfile.c_str(), + nullptr, nullptr); + gtk_container_add(GTK_CONTAINER(window->scrolledwindow), window->lokdocview); + + setupDocView(window); + + // Create argument JSON + const std::string aArguments = createRenderingArgsJSON(priv->m_pRenderingArgs); + lok_doc_view_open_document(LOK_DOC_VIEW(window->lokdocview), aDocPath.c_str(), + aArguments.c_str(), nullptr, + gtv_application_open_document_callback, window->lokdocview); + + gtk_widget_show_all(GTK_WIDGET(window->scrolledwindow)); +} + +GtvMainToolbar* +gtv_application_window_get_main_toolbar(GtvApplicationWindow* window) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + return GTV_MAIN_TOOLBAR(priv->toolbarcontainer); +} + +void +gtv_application_window_set_toolbar_broadcast(GtvApplicationWindow* window, bool broadcast) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + priv->toolbarBroadcast = broadcast; +} + +gboolean +gtv_application_window_get_toolbar_broadcast(GtvApplicationWindow* window) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + return priv->toolbarBroadcast; +} + +void +gtv_application_window_set_part_broadcast(GtvApplicationWindow* window, bool broadcast) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + priv->partSelectorBroadcast = broadcast; +} + +gboolean +gtv_application_window_get_part_broadcast(GtvApplicationWindow* window) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + return priv->partSelectorBroadcast; +} + +GtvApplicationWindow* +gtv_application_window_new(GtkApplication* app) +{ + g_return_val_if_fail(GTK_IS_APPLICATION(app), nullptr); + + return GTV_APPLICATION_WINDOW(g_object_new(GTV_TYPE_APPLICATION_WINDOW, + "application", app, + "width-request", 1024, + "height-request", 768, + "title", "LibreOffice GtkTiledViewer", + "window-position", GTK_WIN_POS_CENTER, + "show-menubar", false, + nullptr)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx new file mode 100644 index 000000000000..21a84e37cdac --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx @@ -0,0 +1,106 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application.cxx b/libreofficekit/qa/gtktiledviewer/gtv-application.cxx new file mode 100644 index 000000000000..c7691a83d195 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-application.cxx @@ -0,0 +1,157 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application.hxx b/libreofficekit/qa/gtktiledviewer/gtv-application.hxx new file mode 100644 index 000000000000..b04e16cb3631 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-application.hxx @@ -0,0 +1,42 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-calc-header-bar.cxx b/libreofficekit/qa/gtktiledviewer/gtv-calc-header-bar.cxx new file mode 100644 index 000000000000..107ea781c16e --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-calc-header-bar.cxx @@ -0,0 +1,220 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-calc-header-bar.hxx b/libreofficekit/qa/gtktiledviewer/gtv-calc-header-bar.hxx new file mode 100644 index 000000000000..6e0815cf5b3a --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-calc-header-bar.hxx @@ -0,0 +1,58 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.cxx b/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.cxx new file mode 100644 index 000000000000..8e25cea56938 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.cxx @@ -0,0 +1,112 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.hxx b/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.hxx new file mode 100644 index 000000000000..8ed096423242 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.hxx @@ -0,0 +1,48 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx new file mode 100644 index 000000000000..eb3aebf97675 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx @@ -0,0 +1,151 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx b/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx new file mode 100644 index 000000000000..033b974f0fbd --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx @@ -0,0 +1,45 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx new file mode 100644 index 000000000000..33f705262808 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx @@ -0,0 +1,321 @@ +/* -*- 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-window.hxx> +#include <gtv-helpers.hxx> +#include <gtv-signal-handlers.hxx> +#include <gtv-calc-header-bar.hxx> +#include <gtv-comments-sidebar.hxx> +#include <gtv-lokdocview-signal-handlers.hxx> + +#include <boost/property_tree/json_parser.hpp> +#include <boost/optional.hpp> + +void LOKDocViewSigHandlers::editChanged(LOKDocView* pDocView, gboolean bWasEdit, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + gboolean bEdit = lok_doc_view_get_edit(LOK_DOC_VIEW(window->lokdocview)); + g_info("signalEdit: %d -> %d", bWasEdit, bEdit); + + // Let the main toolbar know, so that it can enable disable the button + GtvMainToolbar* pMainToolbar = gtv_application_window_get_main_toolbar(GTV_APPLICATION_WINDOW(window)); + gtv_main_toolbar_set_edit(pMainToolbar, bEdit); +} + +void LOKDocViewSigHandlers::commandChanged(LOKDocView* pDocView, char* pPayload, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + std::string aPayload(pPayload); + size_t nPosition = aPayload.find('='); + if (nPosition != std::string::npos) + { + const std::string aKey = aPayload.substr(0, nPosition); + const std::string aValue = aPayload.substr(nPosition + 1); + GtkToolItem* pItem = gtv_application_window_find_tool_by_unocommand(window, aKey); + if (pItem != nullptr) + { + if (aValue == "true" || aValue == "false") { + gboolean bEdit = aValue == "true"; + if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pItem)) != bEdit) + { + // Avoid invoking lok_doc_view_post_command(). + // FIXME: maybe block/unblock the signal (see + // g_signal_handlers_block_by_func) ? + gtv_application_window_set_toolbar_broadcast(window, false); + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pItem), bEdit); + gtv_application_window_set_toolbar_broadcast(window, true); + + } + } else if (aValue == "enabled" || aValue == "disabled") { + gboolean bSensitive = aValue == "enabled"; + gtk_widget_set_sensitive(GTK_WIDGET(pItem), bSensitive); + + // Remember state, so in case edit is disable and enabled + // later, the correct sensitivity can be restored. + GtvMainToolbar* pMainToolbar = gtv_application_window_get_main_toolbar(window); + gtv_main_toolbar_set_sensitive_internal(pMainToolbar, pItem, bSensitive); + } + } + else if (aKey == ".uno:TrackedChangeIndex") + { + std::string aText = std::string("Current redline: "); + if (aValue.empty()) + aText += "none"; + else + aText += aValue; + gtk_label_set_text(GTK_LABEL(window->redlinelabel), aText.c_str()); + } + } +} + +void LOKDocViewSigHandlers::commandResult(LOKDocView*, char* pPayload, gpointer) +{ + fprintf(stderr, "Command finished: %s\n", pPayload); +} + +void LOKDocViewSigHandlers::searchNotFound(LOKDocView* pDocView, char* , gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + gtk_label_set_text(GTK_LABEL(window->findbarlabel), "Search key not found"); +} + +void LOKDocViewSigHandlers::searchResultCount(LOKDocView* pDocView, char* pPayload, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + std::stringstream ss; + ss << pPayload << " match(es)"; + gtk_label_set_text(GTK_LABEL(window->findbarlabel), ss.str().c_str()); +} + +void LOKDocViewSigHandlers::partChanged(LOKDocView* /*pDocView*/, int, gpointer) +{ +// GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + //rWindow.m_bPartSelectorBroadcast = false; +// gtk_combo_box_set_active(GTK_COMBO_BOX(rWindow.m_pPartSelector), nPart); + // rWindow.m_bPartSelectorBroadcast = true; +} + +void LOKDocViewSigHandlers::hyperlinkClicked(LOKDocView* pDocView, char* pPayload, gpointer) +{ + GError* pError = nullptr; +#if GTK_CHECK_VERSION(3,22,0) + gtk_show_uri_on_window( + GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))), + pPayload, GDK_CURRENT_TIME, &pError); +#else + (void) pDocView; + gtk_show_uri(nullptr, pPayload, GDK_CURRENT_TIME, &pError); +#endif + if (pError != nullptr) + { + g_warning("Unable to show URI %s : %s", pPayload, pError->message); + g_error_free(pError); + } +} + +void LOKDocViewSigHandlers::cursorChanged(LOKDocView* pDocView, gint nX, gint nY, + gint /*nWidth*/, gint /*nHeight*/, gpointer /*pData*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(window->scrolledwindow)); + GtkAdjustment* hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(window->scrolledwindow)); + GdkRectangle visArea; + gdouble upper; + gint x = -1, y = -1; + + gtv_application_window_get_visible_area(window, &visArea); + + // check vertically + if (nY < visArea.y) + { + y = nY - visArea.height/2; + if (y < 0) + y = gtk_adjustment_get_lower(vadj); + } + else if (nY > visArea.y + visArea.height) + { + y = nY - visArea.height/2; + upper = lok_doc_view_pixel_to_twip(pDocView, gtk_adjustment_get_upper(vadj)); + if (y > upper) + y = upper; + + } + + if (nX < visArea.x) + { + x = nX - visArea.width/2; + if (x < 0) + x = gtk_adjustment_get_lower(hadj); + } + else if (nX > visArea.x + visArea.width) + { + x = nX - visArea.width/2; + upper = lok_doc_view_pixel_to_twip(pDocView, gtk_adjustment_get_upper(hadj)); + if (x > upper) + x = upper; + } + + if (y!=-1) + gtk_adjustment_set_value(vadj, lok_doc_view_twip_to_pixel(pDocView, y)); + if (x!=-1) + gtk_adjustment_set_value(hadj, lok_doc_view_twip_to_pixel(pDocView, x)); +} + +void LOKDocViewSigHandlers::addressChanged(LOKDocView* pDocView, char* pPayload, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + GtvMainToolbar* toolbar = gtv_application_window_get_main_toolbar(window); + GtkEntry* pAddressbar = GTK_ENTRY(toolbar->m_pAddressbar); + gtk_entry_set_text(pAddressbar, pPayload); +} + +void LOKDocViewSigHandlers::formulaChanged(LOKDocView* pDocView, char* pPayload, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + GtvMainToolbar* toolbar = gtv_application_window_get_main_toolbar(window); + GtkEntry* pFormulabar = GTK_ENTRY(toolbar->m_pFormulabar); + gtk_entry_set_text(pFormulabar, pPayload); +} + +void LOKDocViewSigHandlers::passwordRequired(LOKDocView* pDocView, char* pUrl, gboolean bModify, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + GtkWidget* pPasswordDialog = gtk_dialog_new_with_buttons ("Password required", + GTK_WINDOW (window), + GTK_DIALOG_MODAL, + "OK", + GTK_RESPONSE_OK, + nullptr); + g_object_set(G_OBJECT(pPasswordDialog), "resizable", FALSE, nullptr); + GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pPasswordDialog)); + GtkWidget* pPasswordEntry = gtk_entry_new (); + gtk_entry_set_visibility (GTK_ENTRY(pPasswordEntry), FALSE); + gtk_entry_set_invisible_char (GTK_ENTRY(pPasswordEntry), '*'); + gtk_box_pack_end(GTK_BOX(pDialogMessageArea), pPasswordEntry, TRUE, TRUE, 2); + if (bModify) + { + GtkWidget* pSecondaryLabel = gtk_label_new ("Document requires password to edit"); + gtk_box_pack_end(GTK_BOX(pDialogMessageArea), pSecondaryLabel, TRUE, TRUE, 2); + gtk_dialog_add_button (GTK_DIALOG (pPasswordDialog), "Open as read-only", GTK_RESPONSE_ACCEPT); + } + gtk_widget_show_all(pPasswordDialog); + + gint res = gtk_dialog_run (GTK_DIALOG(pPasswordDialog)); + switch (res) + { + case GTK_RESPONSE_OK: + lok_doc_view_set_document_password (LOK_DOC_VIEW(window->lokdocview), pUrl, gtk_entry_get_text(GTK_ENTRY(pPasswordEntry))); + break; + case GTK_RESPONSE_ACCEPT: + // User accepts to open this document as read-only + case GTK_RESPONSE_DELETE_EVENT: + lok_doc_view_set_document_password (LOK_DOC_VIEW(window->lokdocview), pUrl, nullptr); + break; + } + + gtk_widget_destroy(pPasswordDialog); +} + +void LOKDocViewSigHandlers::comment(LOKDocView* pDocView, gchar* pComment, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + + std::stringstream aStream(pComment); + boost::property_tree::ptree aRoot; + boost::property_tree::read_json(aStream, aRoot); + boost::property_tree::ptree aComment = aRoot.get_child("comment"); + GtvCommentsSidebar* sidebar = GTV_COMMENTS_SIDEBAR(window->commentssidebar); + GtkWidget* pCommentsGrid = sidebar->commentsgrid; + GtvGtkWrapper<GList> pChildren(gtk_container_get_children(GTK_CONTAINER(pCommentsGrid)), + [](GList* l) + { + g_list_free(l); + }); + GtkWidget* pSelf = nullptr; + GtkWidget* pParent = nullptr; + for (GList* l = pChildren.get(); l != nullptr; l = l->next) + { + gchar *id = static_cast<gchar*>(g_object_get_data(G_OBJECT(l->data), "id")); + + if (g_strcmp0(id, aComment.get<std::string>("id").c_str()) == 0) + pSelf = GTK_WIDGET(l->data); + + // There is no 'parent' in Remove callbacks + if (g_strcmp0(id, aComment.get("parent", std::string("0")).c_str()) == 0) + pParent = GTK_WIDGET(l->data); + } + + if (aComment.get<std::string>("action") == "Remove") + { + if (pSelf) + gtk_widget_destroy(pSelf); + else + g_warning("Can't find the comment to remove in the list !!"); + } + else if (aComment.get<std::string>("action") == "Add" || aComment.get<std::string>("action") == "Modify") + { + GtkWidget* pCommentBox = GtvHelpers::createCommentBox(aComment); + if (pSelf != nullptr || pParent != nullptr) + { + gtk_grid_insert_next_to(GTK_GRID(pCommentsGrid), pSelf != nullptr ? pSelf : pParent, GTK_POS_BOTTOM); + gtk_grid_attach_next_to(GTK_GRID(pCommentsGrid), pCommentBox, pSelf != nullptr ? pSelf : pParent, GTK_POS_BOTTOM, 1, 1); + } + else + gtk_container_add(GTK_CONTAINER(pCommentsGrid), pCommentBox); + + gtk_widget_show_all(pCommentBox); + + // We added the widget already below the existing one, so destroy the + // already existing one now + if (pSelf) + gtk_widget_destroy(pSelf); + } +} + +gboolean LOKDocViewSigHandlers::configureEvent(GtkWidget* pWidget, GdkEventConfigure* /*pEvent*/, gpointer /*pData*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pWidget))); + LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview)); + if (pDocument && pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_SPREADSHEET) + { + GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(window->scrolledwindow)); + int rowSizePixel = GTV_CALC_HEADER_BAR(window->rowbar)->m_nSizePixel = gtk_adjustment_get_page_size(pVAdjustment); + int rowPosPixel = GTV_CALC_HEADER_BAR(window->rowbar)->m_nPositionPixel = gtk_adjustment_get_value(pVAdjustment); + GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(window->scrolledwindow)); + int colSizePixel = GTV_CALC_HEADER_BAR(window->columnbar)->m_nSizePixel = gtk_adjustment_get_page_size(pHAdjustment); + int colPosPixel = GTV_CALC_HEADER_BAR(window->columnbar)->m_nPositionPixel = gtk_adjustment_get_value(pHAdjustment); + + std::stringstream aCommand; + aCommand << ".uno:ViewRowColumnHeaders"; + aCommand << "?x=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(window->lokdocview), colPosPixel)); + aCommand << "&width=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(window->lokdocview), colSizePixel)); + aCommand << "&y=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(window->lokdocview), rowPosPixel)); + aCommand << "&height=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(window->lokdocview), rowSizePixel)); + std::stringstream ss; + ss << "lok::Document::getCommandValues(" << aCommand.str() << ")"; + g_info("%s", ss.str().c_str()); + char* pValues = pDocument->pClass->getCommandValues(pDocument, aCommand.str().c_str()); + g_info("lok::Document::getCommandValues() returned '%s'", pValues); + std::stringstream aStream(pValues); + free(pValues); + assert(!aStream.str().empty()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + gtv_calc_header_bar_configure(GTV_CALC_HEADER_BAR(window->rowbar), &aTree.get_child("rows")); + gtv_calc_header_bar_configure(GTV_CALC_HEADER_BAR(window->columnbar), &aTree.get_child("columns")); + gtv_calc_header_bar_configure(GTV_CALC_HEADER_BAR(window->cornerarea), nullptr); + } + + return TRUE; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.hxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.hxx new file mode 100644 index 000000000000..724f2031d4f5 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.hxx @@ -0,0 +1,34 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx new file mode 100644 index 000000000000..0da85fd89e65 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx @@ -0,0 +1,283 @@ +/* -*- 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-window.hxx> +#include <gtv-main-toolbar.hxx> +#include <gtv-signal-handlers.hxx> +#include <gtv-helpers.hxx> +#include <gtv-calc-header-bar.hxx> + +#include <map> +#include <memory> + +#include <boost/property_tree/json_parser.hpp> +#include <boost/optional.hpp> + +struct GtvMainToolbarPrivateImpl +{ + GtkWidget* toolbar1; + GtkWidget* toolbar2; + + GtkWidget* m_pEnableEditing; + GtkWidget* m_pLeftpara; + GtkWidget* m_pCenterpara; + GtkWidget* m_pRightpara; + GtkWidget* m_pJustifypara; + GtkWidget* m_pDeleteComment; + GtkWidget* m_pPartSelector; + GtkWidget* m_pPartModeSelector; + + /// Sensitivity (enabled or disabled) for each tool item, ignoring edit state + std::map<GtkToolItem*, bool> m_aToolItemSensitivities; + + GtvMainToolbarPrivateImpl() : + toolbar1(nullptr), + toolbar2(nullptr), + m_pEnableEditing(nullptr), + m_pLeftpara(nullptr), + m_pCenterpara(nullptr), + m_pRightpara(nullptr), + m_pJustifypara(nullptr), + m_pDeleteComment(nullptr), + m_pPartSelector(nullptr), + m_pPartModeSelector(nullptr) + { } +}; + +struct GtvMainToolbarPrivate +{ + GtvMainToolbarPrivateImpl* m_pImpl; + + GtvMainToolbarPrivateImpl* operator->() + { + return m_pImpl; + } +}; + +G_DEFINE_TYPE_WITH_PRIVATE(GtvMainToolbar, gtv_main_toolbar, GTK_TYPE_BOX); + +static GtvMainToolbarPrivate& +getPrivate(GtvMainToolbar* toolbar) +{ + return *static_cast<GtvMainToolbarPrivate*>(gtv_main_toolbar_get_instance_private(toolbar)); +} + +static void +gtv_main_toolbar_init(GtvMainToolbar* toolbar) +{ + GtvMainToolbarPrivate& priv = getPrivate(toolbar); + priv.m_pImpl = new GtvMainToolbarPrivateImpl(); + + const std::string uiFilePath = GtvHelpers::getDirPath(__FILE__) + std::string(UI_FILE_NAME); + GtvGtkWrapper<GtkBuilder> builder(gtk_builder_new_from_file(uiFilePath.c_str()), + [](GtkBuilder* pBuilder) { + g_object_unref(pBuilder); + }); + + priv->toolbar1 = GTK_WIDGET(gtk_builder_get_object(builder.get(), "toolbar1")); + gtk_box_pack_start(GTK_BOX(toolbar), priv->toolbar1, false, false, false); + priv->toolbar2 = GTK_WIDGET(gtk_builder_get_object(builder.get(), "toolbar2")); + gtk_box_pack_start(GTK_BOX(toolbar), priv->toolbar2, false, false, false); + + priv->m_pEnableEditing = GTK_WIDGET(gtk_builder_get_object(builder.get(), "btn_editmode")); + priv->m_pLeftpara = GTK_WIDGET(gtk_builder_get_object(builder.get(), "btn_justifyleft")); + priv->m_pCenterpara = GTK_WIDGET(gtk_builder_get_object(builder.get(), "btn_justifycenter")); + priv->m_pRightpara = GTK_WIDGET(gtk_builder_get_object(builder.get(), "btn_justifyright")); + priv->m_pJustifypara = GTK_WIDGET(gtk_builder_get_object(builder.get(), "btn_justifyfill")); + priv->m_pDeleteComment = GTK_WIDGET(gtk_builder_get_object(builder.get(), "btn_removeannotation")); + priv->m_pPartSelector = GTK_WIDGET(gtk_builder_get_object(builder.get(), "combo_partselector")); + priv->m_pPartModeSelector = GTK_WIDGET(gtk_builder_get_object(builder.get(), "combo_partsmodeselector")); + toolbar->m_pAddressbar = GTK_WIDGET(gtk_builder_get_object(builder.get(), "addressbar_entry")); + toolbar->m_pFormulabar = GTK_WIDGET(gtk_builder_get_object(builder.get(), "formulabar_entry")); + + // TODO: compile with -rdynamic and get rid of it + gtk_builder_add_callback_symbol(builder.get(), "btn_clicked", G_CALLBACK(btn_clicked)); + gtk_builder_add_callback_symbol(builder.get(), "doCopy", G_CALLBACK(doCopy)); + gtk_builder_add_callback_symbol(builder.get(), "doPaste", G_CALLBACK(doPaste)); + gtk_builder_add_callback_symbol(builder.get(), "createView", G_CALLBACK(createView)); + gtk_builder_add_callback_symbol(builder.get(), "unoCommandDebugger", G_CALLBACK(unoCommandDebugger)); + gtk_builder_add_callback_symbol(builder.get(), "toggleEditing", G_CALLBACK(toggleEditing)); + gtk_builder_add_callback_symbol(builder.get(), "changePartMode", G_CALLBACK(changePartMode)); + gtk_builder_add_callback_symbol(builder.get(), "changePart", G_CALLBACK(changePart)); + gtk_builder_add_callback_symbol(builder.get(), "changeZoom", G_CALLBACK(changeZoom)); + gtk_builder_add_callback_symbol(builder.get(), "toggleFindbar", G_CALLBACK(toggleFindbar)); + gtk_builder_add_callback_symbol(builder.get(), "documentRedline", G_CALLBACK(documentRedline)); + gtk_builder_add_callback_symbol(builder.get(), "documentRepair", G_CALLBACK(documentRepair)); + gtk_builder_add_callback_symbol(builder.get(), "signalAddressbar", G_CALLBACK(signalAddressbar)); + gtk_builder_add_callback_symbol(builder.get(), "signalFormulabar", G_CALLBACK(signalFormulabar)); + + // find toolbar + // Note: These buttons are not the part of GtvMainToolbar + gtk_builder_add_callback_symbol(builder.get(), "signalSearchNext", G_CALLBACK(signalSearchNext)); + gtk_builder_add_callback_symbol(builder.get(), "signalSearchPrev", G_CALLBACK(signalSearchPrev)); + gtk_builder_add_callback_symbol(builder.get(), "signalFindbar", G_CALLBACK(signalFindbar)); + gtk_builder_add_callback_symbol(builder.get(), "toggleFindAll", G_CALLBACK(toggleFindAll)); + + gtk_builder_connect_signals(builder.get(), nullptr); + + gtk_widget_show_all(GTK_WIDGET(toolbar)); +} + +static void +gtv_main_toolbar_finalize(GObject* object) +{ + GtvMainToolbarPrivate& priv = getPrivate(GTV_MAIN_TOOLBAR(object)); + + delete priv.m_pImpl; + priv.m_pImpl = nullptr; + + G_OBJECT_CLASS (gtv_main_toolbar_parent_class)->finalize (object); +} + +static void +gtv_main_toolbar_class_init(GtvMainToolbarClass* klass) +{ + G_OBJECT_CLASS(klass)->finalize = gtv_main_toolbar_finalize; +} + +static void populatePartSelector(GtvMainToolbar* toolbar) +{ + GtvMainToolbarPrivate& priv = getPrivate(toolbar); + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(toolbar))); + gtv_application_window_set_part_broadcast(window, false); + gtk_list_store_clear( GTK_LIST_STORE( + gtk_combo_box_get_model( + GTK_COMBO_BOX(priv->m_pPartSelector) )) ); + + if (!window->lokdocview) + { + return; + } + + const int nMaxLength = 50; + char sText[nMaxLength]; + + int nParts = lok_doc_view_get_parts(LOK_DOC_VIEW(window->lokdocview)); + for ( int i = 0; i < nParts; i++ ) + { + char* pName = lok_doc_view_get_part_name(LOK_DOC_VIEW(window->lokdocview), i); + assert( pName ); + snprintf( sText, nMaxLength, "%i (%s)", i+1, pName ); + free( pName ); + + gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(priv->m_pPartSelector), sText ); + } + gtk_combo_box_set_active(GTK_COMBO_BOX(priv->m_pPartSelector), lok_doc_view_get_part(LOK_DOC_VIEW(window->lokdocview))); + + gtv_application_window_set_part_broadcast(window, true); +} + +void +gtv_main_toolbar_doc_loaded(GtvMainToolbar* toolbar, LibreOfficeKitDocumentType eDocType, bool bEditMode) +{ + GtvMainToolbarPrivate& priv = getPrivate(toolbar); + gtk_widget_set_visible(toolbar->m_pAddressbar, false); + gtk_widget_set_visible(toolbar->m_pFormulabar, false); + if (eDocType == LOK_DOCTYPE_SPREADSHEET) + { + gtk_tool_button_set_label(GTK_TOOL_BUTTON(priv->m_pLeftpara), ".uno:AlignLeft"); + gtk_tool_button_set_label(GTK_TOOL_BUTTON(priv->m_pCenterpara), ".uno:AlignHorizontalCenter"); + gtk_tool_button_set_label(GTK_TOOL_BUTTON(priv->m_pRightpara), ".uno:AlignRight"); + gtk_widget_hide(priv->m_pJustifypara); + gtk_tool_button_set_label(GTK_TOOL_BUTTON(priv->m_pDeleteComment), ".uno:DeleteNote"); + + gtk_widget_set_visible(toolbar->m_pAddressbar, true); + gtk_widget_set_visible(toolbar->m_pFormulabar, true); + } + else if (eDocType == LOK_DOCTYPE_PRESENTATION) + { + gtk_tool_button_set_label(GTK_TOOL_BUTTON(priv->m_pDeleteComment), ".uno:DeleteAnnotation"); + } + + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(priv->m_pEnableEditing), bEditMode); + + // populate combo boxes + populatePartSelector(toolbar); +} + +GtkContainer* +gtv_main_toolbar_get_first_toolbar(GtvMainToolbar* toolbar) +{ + GtvMainToolbarPrivate& priv = getPrivate(toolbar); + return GTK_CONTAINER(priv->toolbar1); +} + +GtkContainer* +gtv_main_toolbar_get_second_toolbar(GtvMainToolbar* toolbar) +{ + GtvMainToolbarPrivate& priv = getPrivate(toolbar); + return GTK_CONTAINER(priv->toolbar2); +} + +void +gtv_main_toolbar_set_sensitive_internal(GtvMainToolbar* toolbar, GtkToolItem* pItem, bool isSensitive) +{ + GtvMainToolbarPrivate& priv = getPrivate(toolbar); + priv->m_aToolItemSensitivities[pItem] = isSensitive; +} + +static void setSensitiveIfEdit(GtvMainToolbar* toolbar, GtkToolItem* pItem, bool bEdit) +{ + GtvMainToolbarPrivate& priv = getPrivate(toolbar); + // some buttons remain enabled always + const gchar* pIconName = gtk_tool_button_get_icon_name(GTK_TOOL_BUTTON(pItem)); + if (g_strcmp0(pIconName, "zoom-in-symbolic") != 0 && + g_strcmp0(pIconName, "zoom-original-symbolic") != 0 && + g_strcmp0(pIconName, "zoom-out-symbolic") != 0 && + g_strcmp0(pIconName, "insert-text-symbolic") != 0 && + g_strcmp0(pIconName, "view-continuous-symbolic") != 0 && + g_strcmp0(pIconName, "document-properties") != 0 && + g_strcmp0(pIconName, "system-run") != 0) + { + bool state = true; + if (priv->m_aToolItemSensitivities.find(pItem) != priv->m_aToolItemSensitivities.end()) + state = priv->m_aToolItemSensitivities[pItem]; + + gtk_widget_set_sensitive(GTK_WIDGET(pItem), bEdit && state); + } +} + +void +gtv_main_toolbar_set_edit(GtvMainToolbar* toolbar, gboolean bEdit) +{ + GtvMainToolbarPrivate& priv = getPrivate(toolbar); + GtvGtkWrapper<GList> pList(gtk_container_get_children(GTK_CONTAINER(priv->toolbar1)), + [](GList* l) + { + g_list_free(l); + }); + for (GList* l = pList.get(); l != nullptr; l = l->next) + { + if (GTK_IS_TOOL_BUTTON(l->data)) + { + setSensitiveIfEdit(toolbar, GTK_TOOL_ITEM(l->data), bEdit); + } + } + + pList.reset(gtk_container_get_children(GTK_CONTAINER(priv->toolbar2))); + for (GList* l = pList.get(); l != nullptr; l = l->next) + { + if (GTK_IS_TOOL_BUTTON(l->data)) + { + setSensitiveIfEdit(toolbar, GTK_TOOL_ITEM(l->data), bEdit); + } + } +} + +GtkWidget* +gtv_main_toolbar_new() +{ + return GTK_WIDGET(g_object_new(GTV_TYPE_MAIN_TOOLBAR, + "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..427da0c28b66 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx @@ -0,0 +1,58 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-main.cxx b/libreofficekit/qa/gtktiledviewer/gtv-main.cxx new file mode 100644 index 000000000000..c35e6cb73abd --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-main.cxx @@ -0,0 +1,19 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.cxx new file mode 100644 index 000000000000..3c9ee3e405f2 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.cxx @@ -0,0 +1,732 @@ +/* -*- 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-window.hxx> +#include <gtv-helpers.hxx> +#include <gtv-lokdocview-signal-handlers.hxx> + +#include <sal/types.h> + +#include <map> +#include <vector> + +#include <boost/property_tree/json_parser.hpp> +#include <boost/optional.hpp> + +void btn_clicked(GtkWidget* pButton, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + GtkToolButton* pItem = GTK_TOOL_BUTTON(pButton); + const gchar* label = gtk_tool_button_get_label(pItem); + if (gtv_application_window_get_toolbar_broadcast(window) && g_str_has_prefix(label, ".uno:")) + { + std::string aArguments; + if (g_strcmp0(label, ".uno:InsertAnnotation") == 0) + { + std::map<std::string, std::string> aEntries; + aEntries["Text"] = ""; + GtvHelpers::userPromptDialog(GTK_WINDOW(window), "Insert Comment", aEntries); + + boost::property_tree::ptree aTree; + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string"); + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), aEntries["Text"]); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + aArguments = aStream.str(); + } + + bool bNotify = g_strcmp0(label, ".uno:Save") == 0; + if (window->lokdocview) + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), label, aArguments.c_str(), bNotify); + } +} + +void doCopy(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + char* pUsedFormat = nullptr; + // TODO: Should check `text-selection` signal before trying to copy + char* pSelection = lok_doc_view_copy_selection(LOK_DOC_VIEW(window->lokdocview), "text/html", &pUsedFormat); + if (!pSelection) + return; + + GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(pButton), GDK_SELECTION_CLIPBOARD); + std::string aUsedFormat(pUsedFormat); + if (aUsedFormat == "text/plain;charset=utf-8") + gtk_clipboard_set_text(pClipboard, pSelection, -1); + else + GtvHelpers::clipboardSetHtml(pClipboard, pSelection); + + free(pSelection); + free(pUsedFormat); +} + +void doPaste(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(pButton), GDK_SELECTION_CLIPBOARD); + GdkAtom* pTargets; + gint nTargets; + std::map<std::string, GdkAtom> aTargets; + if (gtk_clipboard_wait_for_targets(pClipboard, &pTargets, &nTargets)) + { + for (gint i = 0; i < nTargets; ++i) + { + gchar* pName = gdk_atom_name(pTargets[i]); + aTargets[pName] = pTargets[i]; + g_free(pName); + } + g_free(pTargets); + } + + boost::optional<GdkAtom> oTarget; + std::string aTargetName; + + std::vector<std::string> aPreferredNames = + { + std::string("image/png"), + std::string("text/html") + }; + for (const std::string& rName : aPreferredNames) + { + std::map<std::string, GdkAtom>::iterator it = aTargets.find(rName); + if (it != aTargets.end()) + { + aTargetName = it->first; + oTarget = it->second; + break; + } + } + + if (oTarget) + { + GtkSelectionData* pSelectionData = gtk_clipboard_wait_for_contents(pClipboard, *oTarget); + if (!pSelectionData) + { + return; + } + gint nLength; + const guchar* pData = gtk_selection_data_get_data_with_length(pSelectionData, &nLength); + bool bSuccess = lok_doc_view_paste(LOK_DOC_VIEW(window->lokdocview), aTargetName.c_str(), reinterpret_cast<const char*>(pData), nLength); + gtk_selection_data_free(pSelectionData); + if (bSuccess) + return; + } + + gchar* pText = gtk_clipboard_wait_for_text(pClipboard); + if (pText) + lok_doc_view_paste(LOK_DOC_VIEW(window->lokdocview), "text/plain;charset=utf-8", pText, strlen(pText)); +} + +void createView(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + gtv_application_window_create_view_from_window(GTV_APPLICATION_WINDOW(window)); +} + +static void removeUnoParam(GtkWidget* pWidget, gpointer userdata) +{ + GtkWidget* pParamAreaBox = GTK_WIDGET(userdata); + GtkWidget* pParamContainer = gtk_widget_get_parent(pWidget); + + gtk_container_remove(GTK_CONTAINER(pParamAreaBox), pParamContainer); +} + +static void addMoreUnoParam(GtkWidget* /*pWidget*/, gpointer userdata) +{ + GtkWidget* pUnoParamAreaBox = GTK_WIDGET(userdata); + + GtkWidget* pParamContainer = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start(GTK_BOX(pUnoParamAreaBox), pParamContainer, TRUE, TRUE, 2); + + GtkWidget* pTypeEntry = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(pParamContainer), pTypeEntry, TRUE, TRUE, 2); +#if GTK_CHECK_VERSION(3,2,0) + gtk_entry_set_placeholder_text(GTK_ENTRY(pTypeEntry), "Param type (Eg. boolean, string etc.)"); +#endif + + GtkWidget* pNameEntry = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(pParamContainer), pNameEntry, TRUE, TRUE, 2); +#if GTK_CHECK_VERSION(3,2,0) + gtk_entry_set_placeholder_text(GTK_ENTRY(pNameEntry), "Param name"); +#endif + + GtkWidget* pValueEntry = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(pParamContainer), pValueEntry, TRUE, TRUE, 2); +#if GTK_CHECK_VERSION(3,2,0) + gtk_entry_set_placeholder_text(GTK_ENTRY(pValueEntry), "Param value"); +#endif + + GtkWidget* pRemoveButton = gtk_button_new_from_icon_name("list-remove-symbolic", GTK_ICON_SIZE_BUTTON); + g_signal_connect(pRemoveButton, "clicked", G_CALLBACK(removeUnoParam), pUnoParamAreaBox); + gtk_box_pack_start(GTK_BOX(pParamContainer), pRemoveButton, TRUE, TRUE, 2); + + gtk_widget_show_all(pUnoParamAreaBox); +} + +static void iterateUnoParams(GtkWidget* pWidget, gpointer userdata) +{ + boost::property_tree::ptree *pTree = static_cast<boost::property_tree::ptree*>(userdata); + GtvGtkWrapper<GList> pChildren(gtk_container_get_children(GTK_CONTAINER(pWidget)), + [](GList* pList) { + g_list_free(pList); + }); + GList* pIt = nullptr; + guint i = 0; + const gchar* unoParam[3]; + for (pIt = pChildren.get(), i = 0; pIt != nullptr && i < 3; pIt = pIt->next, i++) + { + unoParam[i] = gtk_entry_get_text(GTK_ENTRY(pIt->data)); + } + + pTree->put(boost::property_tree::ptree::path_type(g_strconcat(unoParam[1], "/", "type", nullptr), '/'), unoParam[0]); + pTree->put(boost::property_tree::ptree::path_type(g_strconcat(unoParam[1], "/", "value", nullptr), '/'), unoParam[2]); +} + +void unoCommandDebugger(GtkWidget* pButton, gpointer /* pItem */) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + GtkWidget* pUnoCmdDialog = gtk_dialog_new_with_buttons ("Execute UNO command", + GTK_WINDOW (window), + GTK_DIALOG_MODAL, + "Execute", + GTK_RESPONSE_OK, + nullptr); + g_object_set(G_OBJECT(pUnoCmdDialog), "resizable", FALSE, nullptr); + GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pUnoCmdDialog)); + GtkWidget* pUnoCmdAreaBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pUnoCmdAreaBox, TRUE, TRUE, 2); + + GtkWidget* pUnoCmdLabel = gtk_label_new("Enter UNO command"); + gtk_box_pack_start(GTK_BOX(pUnoCmdAreaBox), pUnoCmdLabel, TRUE, TRUE, 2); + + GtkWidget* pUnoCmdEntry = gtk_entry_new (); + gtk_box_pack_start(GTK_BOX(pUnoCmdAreaBox), pUnoCmdEntry, TRUE, TRUE, 2); +#if GTK_CHECK_VERSION(3,2,0) + gtk_entry_set_placeholder_text(GTK_ENTRY(pUnoCmdEntry), "UNO command (Eg. Bold, Italic etc.)"); +#endif + GtkWidget* pUnoParamAreaBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pUnoParamAreaBox, TRUE, TRUE, 2); + + GtkWidget* pAddMoreButton = gtk_button_new_with_label("Add UNO parameter"); + gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pAddMoreButton, TRUE, TRUE, 2); + g_signal_connect(G_OBJECT(pAddMoreButton), "clicked", G_CALLBACK(addMoreUnoParam), pUnoParamAreaBox); + + gtk_widget_show_all(pUnoCmdDialog); + + gint res = gtk_dialog_run (GTK_DIALOG(pUnoCmdDialog)); + switch (res) + { + case GTK_RESPONSE_OK: + { + const gchar* sUnoCmd = g_strconcat(".uno:", gtk_entry_get_text(GTK_ENTRY(pUnoCmdEntry)), nullptr); + + boost::property_tree::ptree aTree; + gtk_container_foreach(GTK_CONTAINER(pUnoParamAreaBox), iterateUnoParams, &aTree); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + std::string aArguments = aStream.str(); + + g_info("Generated UNO command: %s %s", sUnoCmd, aArguments.c_str()); + + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), sUnoCmd, (aArguments.empty() ? nullptr : aArguments.c_str()), false); + } + break; + } + + gtk_widget_destroy(pUnoCmdDialog); +} + +void toggleEditing(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + bool bActive = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pButton)); + if (bool(lok_doc_view_get_edit(LOK_DOC_VIEW(window->lokdocview))) != bActive) + lok_doc_view_set_edit(LOK_DOC_VIEW(window->lokdocview), bActive); +} + +void changePart( GtkWidget* pSelector, gpointer /* pItem */ ) +{ + int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) ); + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pSelector)); + + if (gtv_application_window_get_part_broadcast(window) && window->lokdocview) + { + lok_doc_view_set_part( LOK_DOC_VIEW(window->lokdocview), nPart ); + lok_doc_view_reset_view(LOK_DOC_VIEW(window->lokdocview)); + } +} + +void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ ) +{ + // Just convert directly back to the LibreOfficeKitPartMode enum. + // I.e. the ordering above should match the enum member ordering. + LibreOfficeKitPartMode ePartMode = + LibreOfficeKitPartMode( gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) ) ); + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pSelector)); + + if ( window->lokdocview ) + { + lok_doc_view_set_partmode( LOK_DOC_VIEW(window->lokdocview), ePartMode ); + } +} + +void changeZoom( GtkWidget* pButton, gpointer /* pItem */ ) +{ + static const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 }; + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + const char *sName = gtk_tool_button_get_icon_name( GTK_TOOL_BUTTON(pButton) ); + + float fZoom = 0; + float fCurrentZoom = 0; + + if ( window->lokdocview ) + { + fCurrentZoom = lok_doc_view_get_zoom( LOK_DOC_VIEW(window->lokdocview) ); + } + + if ( strcmp(sName, "zoom-in-symbolic") == 0) + { + for ( unsigned int i = 0; i < SAL_N_ELEMENTS( fZooms ); i++ ) + { + if ( fCurrentZoom < fZooms[i] ) + { + fZoom = fZooms[i]; + break; + } + } + } + else if ( strcmp(sName, "zoom-original-symbolic") == 0) + { + fZoom = 1; + } + else if ( strcmp(sName, "zoom-out-symbolic") == 0) + { + for ( unsigned int i = 0; i < SAL_N_ELEMENTS( fZooms ); i++ ) + { + if ( fCurrentZoom > fZooms[i] ) + { + fZoom = fZooms[i]; + } + } + } + + if ( fZoom != 0 ) + { + if ( window->lokdocview ) + { + lok_doc_view_set_zoom( LOK_DOC_VIEW(window->lokdocview), fZoom ); + GdkRectangle aVisibleArea; + gtv_application_window_get_visible_area(window, &aVisibleArea); + lok_doc_view_set_visible_area(LOK_DOC_VIEW(window->lokdocview), &aVisibleArea); + } + } + const std::string aZoom = std::string("Zoom: ") + std::to_string(int(fZoom * 100)) + std::string("%"); + gtk_label_set_text(GTK_LABEL(window->zoomlabel), aZoom.c_str()); +} + +void documentRedline(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + // Get the data. + LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview)); + char* pValues = pDocument->pClass->getCommandValues(pDocument, ".uno:AcceptTrackedChanges"); + if (!pValues) + return; + + std::stringstream aInfo; + aInfo << "lok::Document::getCommandValues('.uno:AcceptTrackedChanges') returned '" << pValues << "'" << std::endl; + g_info("%s", aInfo.str().c_str()); + std::stringstream aStream(pValues); + free(pValues); + assert(!aStream.str().empty()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + // Create the dialog. + GtkWidget* pDialog = gtk_dialog_new_with_buttons("Manage Changes", + GTK_WINDOW (window), + GTK_DIALOG_MODAL, + "Accept", + GTK_RESPONSE_YES, + "Reject", + GTK_RESPONSE_NO, + "Jump", + GTK_RESPONSE_APPLY, + nullptr); + gtk_window_set_default_size(GTK_WINDOW(pDialog), 800, 600); + GtkWidget* pContentArea = gtk_dialog_get_content_area(GTK_DIALOG (pDialog)); + GtkWidget* pScrolledWindow = gtk_scrolled_window_new(nullptr, nullptr); + + // Build the table. + GtkTreeStore* pTreeStore = gtk_tree_store_new(6, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + for (const auto& rValue : aTree.get_child("redlines")) + { + GtkTreeIter aTreeIter; + gtk_tree_store_append(pTreeStore, &aTreeIter, nullptr); + gtk_tree_store_set(pTreeStore, &aTreeIter, + 0, rValue.second.get<int>("index"), + 1, rValue.second.get<std::string>("author").c_str(), + 2, rValue.second.get<std::string>("type").c_str(), + 3, rValue.second.get<std::string>("comment").c_str(), + 4, rValue.second.get<std::string>("description").c_str(), + 5, rValue.second.get<std::string>("dateTime").c_str(), + -1); + } + GtkWidget* pTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pTreeStore)); + std::vector<std::string> aColumns = {"Index", "Author", "Type", "Comment", "Description", "Timestamp"}; + for (size_t nColumn = 0; nColumn < aColumns.size(); ++nColumn) + { + GtkCellRenderer* pRenderer = gtk_cell_renderer_text_new(); + GtkTreeViewColumn* pColumn = gtk_tree_view_column_new_with_attributes(aColumns[nColumn].c_str(), + pRenderer, + "text", nColumn, + nullptr); + gtk_tree_view_append_column(GTK_TREE_VIEW(pTreeView), pColumn); + } + gtk_container_add(GTK_CONTAINER(pScrolledWindow), pTreeView); + gtk_box_pack_start(GTK_BOX(pContentArea), pScrolledWindow, TRUE, TRUE, 2); + + // Show the dialog. + gtk_widget_show_all(pDialog); + gint res = gtk_dialog_run(GTK_DIALOG(pDialog)); + + // Dispatch the matching command, if necessary. + if (res == GTK_RESPONSE_YES || res == GTK_RESPONSE_NO || res == GTK_RESPONSE_APPLY) + { + GtkTreeSelection* pSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pTreeView)); + GtkTreeIter aTreeIter; + GtkTreeModel* pTreeModel; + if (gtk_tree_selection_get_selected(pSelection, &pTreeModel, &aTreeIter)) + { + gint nIndex = 0; + // 0: index + gtk_tree_model_get(pTreeModel, &aTreeIter, 0, &nIndex, -1); + std::string aCommand; + if (res == GTK_RESPONSE_YES) + aCommand = ".uno:AcceptTrackedChange"; + else if (res == GTK_RESPONSE_NO) + aCommand = ".uno:RejectTrackedChange"; + else + // Just select the given redline, don't accept or reject it. + aCommand = ".uno:NextTrackedChange"; + // Without the '.uno:' prefix. + std::string aKey = aCommand.substr(strlen(".uno:")); + + // Post the command. + boost::property_tree::ptree aCommandTree; + aCommandTree.put(boost::property_tree::ptree::path_type(aKey + "/type", '/'), "unsigned short"); + aCommandTree.put(boost::property_tree::ptree::path_type(aKey + "/value", '/'), nIndex); + + aStream.str(std::string()); + boost::property_tree::write_json(aStream, aCommandTree); + std::string aArguments = aStream.str(); + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), aCommand.c_str(), aArguments.c_str(), false); + } + } + + gtk_widget_destroy(pDialog); +} + +void documentRepair(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + // Get the data. + LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview)); + // Show it in linear time, so first redo in reverse order, then undo. + std::vector<std::string> aTypes = {".uno:Redo", ".uno:Undo"}; + std::vector<boost::property_tree::ptree> aTrees; + for (size_t nType = 0; nType < aTypes.size(); ++nType) + { + const std::string& rType = aTypes[nType]; + char* pValues = pDocument->pClass->getCommandValues(pDocument, rType.c_str()); + std::stringstream aInfo; + aInfo << "lok::Document::getCommandValues('" << rType << "') returned '" << pValues << "'" << std::endl; + g_info("%s", aInfo.str().c_str()); + std::stringstream aStream(pValues); + free(pValues); + assert(!aStream.str().empty()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + aTrees.push_back(aTree); + } + + // Create the dialog. + GtkWidget* pDialog = gtk_dialog_new_with_buttons("Repair document", + GTK_WINDOW (window), + GTK_DIALOG_MODAL, + "Jump to state", + GTK_RESPONSE_OK, + nullptr); + gtk_window_set_default_size(GTK_WINDOW(pDialog), 800, 600); + GtkWidget* pContentArea = gtk_dialog_get_content_area(GTK_DIALOG (pDialog)); + GtkWidget* pScrolledWindow = gtk_scrolled_window_new(nullptr, nullptr); + + // Build the table. + GtkTreeStore* pTreeStore = gtk_tree_store_new(5, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + for (size_t nTree = 0; nTree < aTrees.size(); ++nTree) + { + const auto& rTree = aTrees[nTree]; + for (const auto& rValue : rTree.get_child("actions")) + { + GtkTreeIter aTreeIter; + gtk_tree_store_append(pTreeStore, &aTreeIter, nullptr); + gtk_tree_store_set(pTreeStore, &aTreeIter, + 0, aTypes[nTree].c_str(), + 1, rValue.second.get<int>("index"), + 2, rValue.second.get<std::string>("comment").c_str(), + 3, rValue.second.get<std::string>("viewId").c_str(), + 4, rValue.second.get<std::string>("dateTime").c_str(), + -1); + } + } + GtkWidget* pTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pTreeStore)); + std::vector<std::string> aColumns = {"Type", "Index", "Comment", "View ID", "Timestamp"}; + for (size_t nColumn = 0; nColumn < aColumns.size(); ++nColumn) + { + GtkCellRenderer* pRenderer = gtk_cell_renderer_text_new(); + GtkTreeViewColumn* pColumn = gtk_tree_view_column_new_with_attributes(aColumns[nColumn].c_str(), + pRenderer, + "text", nColumn, + nullptr); + gtk_tree_view_append_column(GTK_TREE_VIEW(pTreeView), pColumn); + } + gtk_container_add(GTK_CONTAINER(pScrolledWindow), pTreeView); + gtk_box_pack_start(GTK_BOX(pContentArea), pScrolledWindow, TRUE, TRUE, 2); + + // Show the dialog. + gtk_widget_show_all(pDialog); + gint res = gtk_dialog_run(GTK_DIALOG(pDialog)); + + // Dispatch the matching command, if necessary. + if (res == GTK_RESPONSE_OK) + { + GtkTreeSelection* pSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pTreeView)); + GtkTreeIter aTreeIter; + GtkTreeModel* pTreeModel; + if (gtk_tree_selection_get_selected(pSelection, &pTreeModel, &aTreeIter)) + { + gchar* pType = nullptr; + gint nIndex = 0; + // 0: type, 1: index + gtk_tree_model_get(pTreeModel, &aTreeIter, 0, &pType, 1, &nIndex, -1); + // '.uno:Undo' or '.uno:Redo' + const std::string aType(pType); + // Without the '.uno:' prefix. + std::string aKey = aType.substr(strlen(".uno:")); + g_free(pType); + + // Post the command. + boost::property_tree::ptree aTree; + aTree.put(boost::property_tree::ptree::path_type(aKey + "/type", '/'), "unsigned short"); + aTree.put(boost::property_tree::ptree::path_type(aKey + "/value", '/'), nIndex + 1); + + // Without this, we could only undo our own commands. + aTree.put(boost::property_tree::ptree::path_type("Repair/type", '/'), "boolean"); + aTree.put(boost::property_tree::ptree::path_type("Repair/value", '/'), true); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + std::string aArguments = aStream.str(); + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), aType.c_str(), aArguments.c_str(), false); + } + } + + gtk_widget_destroy(pDialog); +} + +void toggleFindbar(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + gtv_application_window_toggle_findbar(window); +} + +void docAdjustmentChanged(GtkAdjustment*, gpointer pData) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(pData); + if (window->lokdocview) + LOKDocViewSigHandlers::configureEvent(window->lokdocview, nullptr, nullptr); +} + +void signalSearchNext(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + GtkEntry* pEntry = GTK_ENTRY(window->findbarEntry); + const char* pText = gtk_entry_get_text(pEntry); + bool findAll = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(window->findAll)); + lok_doc_view_find_next(LOK_DOC_VIEW(window->lokdocview), pText, findAll); +} + +void signalSearchPrev(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + GtkEntry* pEntry = GTK_ENTRY(window->findbarEntry); + const char* pText = gtk_entry_get_text(pEntry); + bool findAll = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(window->findAll)); + lok_doc_view_find_prev(LOK_DOC_VIEW(window->lokdocview), pText, findAll); +} + +gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pWidget)); + gtk_label_set_text(GTK_LABEL(window->findbarlabel), ""); + switch(pEvent->keyval) + { + case GDK_KEY_Return: + { + // Search forward. + signalSearchNext(pWidget, nullptr); + return TRUE; + } + case GDK_KEY_Escape: + { + // Hide the findbar. + gtk_widget_hide(GTK_WIDGET(window->findtoolbar)); + return TRUE; + } + } + return FALSE; +} + +void toggleFindAll(GtkWidget* pButton, gpointer /*pItem*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton)); + GtkEntry* pEntry = GTK_ENTRY(window->findbarEntry); + const char* pText = gtk_entry_get_text(pEntry); + bool findAll = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(window->findAll)); + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(window->findAll), !findAll); + lok_doc_view_highlight_all(LOK_DOC_VIEW(window->lokdocview), pText); +} + +void editButtonClicked(GtkWidget* pWidget, gpointer userdata) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pWidget)); + std::map<std::string, std::string> aEntries; + aEntries["Text"] = ""; + + GtvHelpers::userPromptDialog(GTK_WINDOW(window), "Edit comment", aEntries); + + gchar *commentId = static_cast<gchar*>(g_object_get_data(G_OBJECT(userdata), "id")); + + boost::property_tree::ptree aTree; + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "type", nullptr), '/'), "string"); + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "value", nullptr), '/'), std::string(commentId)); + + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string"); + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), aEntries["Text"]); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + std::string aArguments = aStream.str(); + + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), ".uno:EditAnnotation", aArguments.c_str(), false); +} + +void replyButtonClicked(GtkWidget* pWidget, gpointer userdata) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pWidget)); + std::map<std::string, std::string> aEntries; + aEntries["Text"] = ""; + + GtvHelpers::userPromptDialog(GTK_WINDOW(window), "Reply comment", aEntries); + + gchar *commentId = static_cast<gchar*>(g_object_get_data(G_OBJECT(userdata), "id")); + + boost::property_tree::ptree aTree; + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "type", nullptr), '/'), "string"); + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "value", nullptr), '/'), std::string(commentId)); + + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string"); + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), aEntries["Text"]); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + std::string aArguments = aStream.str(); + + // Different reply UNO command for impress + std::string replyCommand = ".uno:ReplyComment"; + LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview)); + if (pDocument && pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_PRESENTATION) + replyCommand = ".uno:ReplyToAnnotation"; + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), replyCommand.c_str(), aArguments.c_str(), false); +} + +void deleteCommentButtonClicked(GtkWidget* pWidget, gpointer userdata) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pWidget)); + gchar *commentid = static_cast<gchar*>(g_object_get_data(G_OBJECT(userdata), "id")); + + boost::property_tree::ptree aTree; + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "type", nullptr), '/'), "string"); + aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "value", nullptr), '/'), std::string(commentid)); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + std::string aArguments = aStream.str(); + + // Different reply UNO command for impress + std::string deleteCommand = ".uno:DeleteComment"; + LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview)); + if (pDocument) + { + if (pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_PRESENTATION) + deleteCommand = ".uno:DeleteAnnotation"; + else if (pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_SPREADSHEET) + deleteCommand = ".uno:DeleteNote"; + } + + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), deleteCommand.c_str(), aArguments.c_str(), false); +} + +/// Handles the key-press-event of the address entry widget. +gboolean signalAddressbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pWidget)); + switch(pEvent->keyval) + { + case GDK_KEY_Return: + { + GtkEntry* pEntry = GTK_ENTRY(pWidget); + const char* pText = gtk_entry_get_text(pEntry); + + boost::property_tree::ptree aTree; + aTree.put(boost::property_tree::ptree::path_type("ToPoint/type", '/'), "string"); + aTree.put(boost::property_tree::ptree::path_type("ToPoint/value", '/'), pText); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + std::string aArguments = aStream.str(); + + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), ".uno:GoToCell", aArguments.c_str(), false); + gtk_widget_grab_focus(window->lokdocview); + return TRUE; + } + case GDK_KEY_Escape: + { + std::string aArguments; + lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), ".uno:Cancel", aArguments.c_str(), false); + gtk_widget_grab_focus(window->lokdocview); + return TRUE; + } + } + return FALSE; +} + +/// Handles the key-press-event of the formula entry widget. +gboolean signalFormulabar(GtkWidget* /*pWidget*/, GdkEventKey* /*pEvent*/, gpointer /*pData*/) +{ + // for now it just displays the callback + // TODO - submit the edited formula + return TRUE; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.hxx b/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.hxx new file mode 100644 index 000000000000..a19a7b5cd744 --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.hxx @@ -0,0 +1,66 @@ +/* -*- 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: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv.ui b/libreofficekit/qa/gtktiledviewer/gtv.ui new file mode 100644 index 000000000000..e27f79714a4b --- /dev/null +++ b/libreofficekit/qa/gtktiledviewer/gtv.ui @@ -0,0 +1,744 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.20.0 --> +<interface> + <requires lib="gtk+" version="3.20"/> + <object class="GtkBox" id="container"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <placeholder/> + </child> + <child> + <object class="GtkGrid" id="maingrid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkBox" id="scrolledwindowcontainer"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="shadow_type">in</property> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">1</property> + </packing> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkStatusbar" id="statusbar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">10</property> + <property name="margin_start">10</property> + <property name="margin_end">10</property> + <property name="margin_bottom">6</property> + <property name="spacing">2</property> + <child> + <object class="GtkLabel" id="zoomlabel"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">22</property> + <property name="label" translatable="yes">100%</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="redlinelabel"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">22</property> + <property name="label" translatable="yes">Current redline: </property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkToolbar" id="findtoolbar"> + <property name="can_focus">False</property> + <property name="toolbar_style">both-horiz</property> + <child> + <object class="GtkToolButton" id="findbar_close"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">__glade_unnamed_1</property> + <property name="use_underline">True</property> + <property name="icon_name">window-close-symbolic</property> + <signal name="clicked" handler="toggleFindbar" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolItem" id="findbar_entrytoolitem"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkEntry" id="findbar_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <signal name="key-press-event" handler="signalFindbar" swapped="no"/> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">False</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="findbar_next"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">__glade_unnamed_3</property> + <property name="use_underline">True</property> + <property name="icon_name">go-down-symbolic</property> + <signal name="clicked" handler="signalSearchNext" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="findbar_prev"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">toolbutton</property> + <property name="use_underline">True</property> + <property name="icon_name">go-up-symbolic</property> + <signal name="clicked" handler="signalSearchPrev" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="findbar_findall"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Highlight all</property> + <property name="use_underline">True</property> + <signal name="clicked" handler="toggleFindAll" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolItem" id="findbar_labeltoolitem"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkLabel" id="findbar_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Search not found</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + </object> + <object class="GtkToolbar" id="toolbar1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="toolbar_style">icons</property> + <child> + <object class="GtkToolButton" id="btn_save"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:Save</property> + <property name="icon_name">document-save-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkSeparatorToolItem" id="separator1"> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">False</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_copy"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Copy</property> + <property name="use_underline">True</property> + <property name="icon_name">edit-copy-symbolic</property> + <signal name="clicked" handler="doCopy" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_paste"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Paste</property> + <property name="use_underline">True</property> + <property name="icon_name">edit-paste-symbolic</property> + <signal name="clicked" handler="doPaste" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkSeparatorToolItem" id="separator2"> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">False</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_undo"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:Undo</property> + <property name="use_underline">True</property> + <property name="icon_name">edit-undo-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_redo"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:Redo</property> + <property name="use_underline">True</property> + <property name="icon_name">edit-redo-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_docrepair"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Document Repair</property> + <property name="use_underline">True</property> + <property name="icon_name">document-properties</property> + <signal name="clicked" handler="documentRepair" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_docredlines"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Document redlines</property> + <property name="use_underline">True</property> + <property name="icon_name">system-run</property> + <signal name="clicked" handler="documentRedline" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkSeparatorToolItem" id="separator3"> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">False</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_find"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Find</property> + <property name="use_underline">True</property> + <property name="icon_name">edit-find-symbolic</property> + <signal name="clicked" handler="toggleFindbar" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkSeparatorToolItem" id="separator4"> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">False</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_zoomin"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Zoom In</property> + <property name="use_underline">True</property> + <property name="icon_name">zoom-in-symbolic</property> + <signal name="clicked" handler="changeZoom" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_zoomoriginal"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Zoom Original</property> + <property name="use_underline">True</property> + <property name="icon_name">zoom-original-symbolic</property> + <signal name="clicked" handler="changeZoom" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_zoomout"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Zoom out</property> + <property name="use_underline">True</property> + <property name="icon_name">zoom-out-symbolic</property> + <signal name="clicked" handler="changeZoom" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolItem" id="partselectortoolitem"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkComboBoxText" id="combo_partselector"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <signal name="changed" handler="changePart" swapped="no"/> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolItem" id="partmodeselectortoolitem"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkComboBoxText" id="combo_partsmodeselector"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="active">0</property> + <items> + <item translatable="yes">Standard</item> + <item translatable="yes">Notes</item> + </items> + <signal name="changed" handler="changePartMode" swapped="no"/> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_editmode"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Turn on/off edit mode</property> + <property name="use_underline">True</property> + <property name="icon_name">insert-text-symbolic</property> + <signal name="clicked" handler="toggleEditing" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_unodebugger"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Uno Command Debugger</property> + <property name="use_underline">True</property> + <property name="icon_name">dialog-question-symbolic</property> + <signal name="clicked" handler="unoCommandDebugger" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_createview"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Create new view</property> + <property name="use_underline">True</property> + <property name="icon_name">view-continuous-symbolic</property> + <signal name="clicked" handler="createView" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + </object> + <object class="GtkToolbar" id="toolbar2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="toolbar_style">icons</property> + <child> + <object class="GtkToggleToolButton" id="btn_bold"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:Bold</property> + <property name="use_underline">True</property> + <property name="icon_name">format-text-bold-symbolic</property> + <signal name="toggled" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_italic"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:Italic</property> + <property name="use_underline">True</property> + <property name="icon_name">format-text-italic-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_underline"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:Underline</property> + <property name="use_underline">True</property> + <property name="icon_name">format-text-underline-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_strikethrough"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:Strikeout</property> + <property name="use_underline">True</property> + <property name="icon_name">format-text-strikethrough-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkSeparatorToolItem" id="separator5"> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">False</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_superscript"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:SuperScript</property> + <property name="use_underline">True</property> + <property name="icon_name">go-up-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_subscript"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:SubScript</property> + <property name="use_underline">True</property> + <property name="icon_name">go-down-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkSeparatorToolItem" id="separator6"> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">False</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_justifyleft"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:LeftPara</property> + <property name="use_underline">True</property> + <property name="icon_name">format-justify-left-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_justifycenter"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:CenterPara</property> + <property name="use_underline">True</property> + <property name="icon_name">format-justify-center-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_justifyright"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:RightPara</property> + <property name="use_underline">True</property> + <property name="icon_name">format-justify-right-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_justifyfill"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:JustifyPara</property> + <property name="use_underline">True</property> + <property name="icon_name">format-justify-fill-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkSeparatorToolItem" id="separator7"> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">False</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_insertannotation"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:InsertAnnotation</property> + <property name="use_underline">True</property> + <property name="icon_name">changes-allow-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolButton" id="btn_removeannotation"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:DeleteComment</property> + <property name="use_underline">True</property> + <property name="icon_name">changes-prevent-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToggleToolButton" id="btn_trackchanges"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">.uno:TrackChanges</property> + <property name="use_underline">True</property> + <property name="icon_name">media-record-symbolic</property> + <signal name="clicked" handler="btn_clicked" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolItem" id="addressbar_toolitem"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkEntry" id="addressbar_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <signal name="key-press-event" handler="signalAddressbar" swapped="no"/> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkToolItem" id="formulabar_toolitem"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkEntry" id="formulabar_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <signal name="key-press-event" handler="signalFormulabar" swapped="no"/> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + </object> +</interface> |