LCOV - code coverage report
Current view: top level - libreofficekit/qa/gtktiledviewer - gtktiledviewer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 256 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <assert.h>
      11             : #include <stdio.h>
      12             : #include <string.h>
      13             : #include <string>
      14             : #include <map>
      15             : 
      16             : #include <boost/property_tree/json_parser.hpp>
      17             : #include <gdk/gdk.h>
      18             : #include <gdk/gdkkeysyms.h>
      19             : #include <gtk/gtk.h>
      20             : 
      21             : #include <LibreOfficeKit/LibreOfficeKitGtk.h>
      22             : #include <LibreOfficeKit/LibreOfficeKitInit.h>
      23             : #include <LibreOfficeKit/LibreOfficeKitEnums.h>
      24             : 
      25             : #ifndef g_info
      26             : #define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
      27             : #endif
      28             : 
      29           0 : static int help()
      30             : {
      31           0 :     fprintf( stderr, "Usage: gtktiledviewer <absolute-path-to-libreoffice-install's-program-directory> <path-to-document>\n" );
      32           0 :     return 1;
      33             : }
      34             : 
      35             : static GtkWidget* pDocView;
      36             : static GtkToolItem* pEnableEditing;
      37             : static GtkToolItem* pBold;
      38             : static GtkToolItem* pItalic;
      39             : static GtkToolItem* pUnderline;
      40             : static GtkToolItem* pStrikethrough;
      41           0 : std::map<GtkToolItem*, std::string> g_aToolItemCommandNames;
      42           0 : std::map<std::string, GtkToolItem*> g_aCommandNameToolItems;
      43             : bool g_bToolItemBroadcast = true;
      44             : static GtkWidget* pVBox;
      45             : // GtkComboBox requires gtk 2.24 or later
      46             : #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
      47             : static GtkComboBoxText* pPartSelector;
      48             : /// Should the part selector avoid calling lok::Document::setPart()?
      49             : static bool g_bPartSelectorBroadcast = true;
      50             : #endif
      51             : GtkWidget* pFindbar;
      52             : GtkWidget* pFindbarEntry;
      53             : GtkWidget* pFindbarLabel;
      54             : 
      55             : static LibreOfficeKit* pOffice;
      56             : 
      57           0 : static void lcl_registerToolItem(GtkToolItem* pItem, const std::string& rName)
      58             : {
      59           0 :     g_aToolItemCommandNames[pItem] = rName;
      60           0 :     g_aCommandNameToolItems[rName] = pItem;
      61           0 : }
      62             : 
      63             : const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 };
      64             : 
      65           0 : static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
      66             : {
      67           0 :     const char *sName = gtk_tool_button_get_stock_id( GTK_TOOL_BUTTON(pButton) );
      68             : 
      69           0 :     float fZoom = 0;
      70           0 :     float fCurrentZoom = 0;
      71             : 
      72           0 :     if ( pDocView )
      73             :     {
      74           0 :         fCurrentZoom = lok_doc_view_get_zoom( LOK_DOC_VIEW(pDocView) );
      75             :     }
      76             : 
      77           0 :     if ( strcmp(sName, "gtk-zoom-in") == 0)
      78             :     {
      79           0 :         for ( unsigned int i = 0; i < sizeof( fZooms ) / sizeof( fZooms[0] ); i++ )
      80             :         {
      81           0 :             if ( fCurrentZoom < fZooms[i] )
      82             :             {
      83           0 :                 fZoom = fZooms[i];
      84           0 :                 break;
      85             :             }
      86             :         }
      87             :     }
      88           0 :     else if ( strcmp(sName, "gtk-zoom-100") == 0)
      89             :     {
      90           0 :         fZoom = 1;
      91             :     }
      92           0 :     else if ( strcmp(sName, "gtk-zoom-out") == 0)
      93             :     {
      94           0 :         for ( unsigned int i = 0; i < sizeof( fZooms ) / sizeof( fZooms[0] ); i++ )
      95             :         {
      96           0 :             if ( fCurrentZoom > fZooms[i] )
      97             :             {
      98           0 :                 fZoom = fZooms[i];
      99             :             }
     100             :         }
     101             :     }
     102             : 
     103           0 :     if ( fZoom != 0 )
     104             :     {
     105           0 :         if ( pDocView )
     106             :         {
     107           0 :             lok_doc_view_set_zoom( LOK_DOC_VIEW(pDocView), fZoom );
     108             :         }
     109             :     }
     110           0 : }
     111             : 
     112             : /// User clicked on the button -> inform LOKDocView.
     113           0 : static void toggleEditing(GtkWidget* /*pButton*/, gpointer /*pItem*/)
     114             : {
     115           0 :     LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
     116           0 :     bool bActive = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing));
     117           0 :     if (bool(lok_doc_view_get_edit(pLOKDocView)) != bActive)
     118           0 :         lok_doc_view_set_edit(pLOKDocView, bActive);
     119           0 : }
     120             : 
     121             : /// Toggle the visibility of the findbar.
     122           0 : static void toggleFindbar(GtkWidget* /*pButton*/, gpointer /*pItem*/)
     123             : {
     124             : #if GTK_CHECK_VERSION(2,18,0) // we need gtk_widget_get_visible()
     125           0 :     if (gtk_widget_get_visible(pFindbar))
     126             :     {
     127           0 :         gtk_widget_hide(pFindbar);
     128             :     }
     129             :     else
     130             :     {
     131           0 :         gtk_widget_show_all(pFindbar);
     132           0 :         gtk_widget_grab_focus(pFindbarEntry);
     133             :     }
     134             : #endif
     135           0 : }
     136             : 
     137             : /// Handles the key-press-event of the window.
     138           0 : static gboolean signalKey(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData)
     139             : {
     140           0 :     LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
     141             : #if GTK_CHECK_VERSION(2,18,0) // we need gtk_widget_get_visible()
     142           0 :     if (!gtk_widget_get_visible(pFindbar) && bool(lok_doc_view_get_edit(pLOKDocView)))
     143             :         {
     144           0 :             lok_doc_view_post_key(pWidget, pEvent, pData);
     145           0 :             return TRUE;
     146             :         }
     147             : #endif
     148           0 :     return FALSE;
     149             : }
     150             : 
     151             : /// Searches for the next or previous text of pFindbarEntry.
     152           0 : static void doSearch(bool bBackwards)
     153             : {
     154           0 :     GtkEntry* pEntry = GTK_ENTRY(pFindbarEntry);
     155           0 :     const char* pText = gtk_entry_get_text(pEntry);
     156           0 :     boost::property_tree::ptree aTree;
     157           0 :     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/type", '/'), "string");
     158           0 :     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/value", '/'), pText);
     159           0 :     aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/type", '/'), "boolean");
     160           0 :     aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/value", '/'), bBackwards);
     161             : 
     162           0 :     LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
     163             :     GdkRectangle aArea;
     164           0 :     lok_doc_view_get_visarea(pLOKDocView, &aArea);
     165           0 :     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointX/type", '/'), "long");
     166           0 :     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointX/value", '/'), aArea.x);
     167           0 :     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointY/type", '/'), "long");
     168           0 :     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointY/value", '/'), aArea.y);
     169             : 
     170           0 :     std::stringstream aStream;
     171           0 :     boost::property_tree::write_json(aStream, aTree);
     172             : 
     173           0 :     lok_doc_view_post_command(pLOKDocView, ".uno:ExecuteSearch", aStream.str().c_str());
     174           0 : }
     175             : 
     176             : /// Click handler for the search next button.
     177           0 : static void signalSearchNext(GtkWidget* /*pButton*/, gpointer /*pItem*/)
     178             : {
     179           0 :     doSearch(/*bBackwards=*/false);
     180           0 : }
     181             : 
     182             : /// Click handler for the search previous button.
     183           0 : static void signalSearchPrev(GtkWidget* /*pButton*/, gpointer /*pItem*/)
     184             : {
     185           0 :     doSearch(/*bBackwards=*/true);
     186           0 : }
     187             : 
     188             : /// Handles the key-press-event of the search entry widget.
     189           0 : static gboolean signalFindbar(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pData*/)
     190             : {
     191           0 :     gtk_label_set_text(GTK_LABEL(pFindbarLabel), "");
     192           0 :     switch(pEvent->keyval)
     193             :     {
     194             :         case GDK_Return:
     195             :         {
     196             :             // Search forward.
     197           0 :             doSearch(/*bBackwards=*/false);
     198           0 :             return TRUE;
     199             :         }
     200             :         case GDK_Escape:
     201             :         {
     202             :             // Hide the findbar.
     203           0 :             gtk_widget_hide(pFindbar);
     204           0 :             return TRUE;
     205             :         }
     206             :     }
     207           0 :     return FALSE;
     208             : }
     209             : 
     210             : /// LOKDocView changed edit state -> inform the tool button.
     211           0 : static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pData*/)
     212             : {
     213           0 :     gboolean bEdit = lok_doc_view_get_edit(pLOKDocView);
     214           0 :     g_info("signalEdit: %d -> %d", bWasEdit, lok_doc_view_get_edit(pLOKDocView));
     215           0 :     if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing)) != bEdit)
     216           0 :         gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing), bEdit);
     217           0 : }
     218             : 
     219             : /// LOKDocView changed command state -> inform the tool button.
     220           0 : static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer /*pData*/)
     221             : {
     222           0 :     std::string aPayload(pPayload);
     223           0 :     size_t nPosition = aPayload.find("=");
     224           0 :     if (nPosition != std::string::npos)
     225             :     {
     226           0 :         std::string aKey = aPayload.substr(0, nPosition);
     227           0 :         std::string aValue = aPayload.substr(nPosition + 1);
     228           0 :         g_info("signalCommand: '%s' is '%s'", aKey.c_str(), aValue.c_str());
     229             : 
     230           0 :         if (g_aCommandNameToolItems.find(aKey) != g_aCommandNameToolItems.end())
     231             :         {
     232           0 :             GtkToolItem* pItem = g_aCommandNameToolItems[aKey];
     233           0 :             gboolean bEdit = aValue == "true";
     234           0 :             if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pItem)) != bEdit)
     235             :             {
     236             :                 // Avoid invoking lok_doc_view_post_command().
     237           0 :                 g_bToolItemBroadcast = false;
     238           0 :                 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pItem), bEdit);
     239           0 :                 g_bToolItemBroadcast = true;
     240             :             }
     241           0 :         }
     242           0 :     }
     243           0 : }
     244             : 
     245             : /// LOKDocView found no search matches -> set the search label accordingly.
     246           0 : static void signalSearch(LOKDocView* /*pLOKDocView*/, char* /*pPayload*/, gpointer /*pData*/)
     247             : {
     248           0 :     gtk_label_set_text(GTK_LABEL(pFindbarLabel), "Search key not found");
     249           0 : }
     250             : 
     251           0 : static void signalPart(LOKDocView* /*pLOKDocView*/, int nPart, gpointer /*pData*/)
     252             : {
     253             : #if GTK_CHECK_VERSION(2,24,0)
     254           0 :     g_bPartSelectorBroadcast = false;
     255           0 :     gtk_combo_box_set_active(GTK_COMBO_BOX(pPartSelector), nPart);
     256           0 :     g_bPartSelectorBroadcast = true;
     257             : #endif
     258           0 : }
     259             : 
     260             : /// User clicked on a cmmand button -> inform LOKDocView.
     261           0 : static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
     262             : {
     263           0 :     if (g_bToolItemBroadcast)
     264             :     {
     265           0 :         LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
     266           0 :         GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
     267           0 :         const std::string& rString = g_aToolItemCommandNames[pItem];
     268           0 :         g_info("toggleToolItem: lok_doc_view_post_command('%s')", rString.c_str());
     269           0 :         lok_doc_view_post_command(pLOKDocView, rString.c_str(), 0);
     270             :     }
     271           0 : }
     272             : 
     273             : // GtkComboBox requires gtk 2.24 or later
     274             : #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
     275           0 : static void populatePartSelector()
     276             : {
     277           0 :     gtk_list_store_clear( GTK_LIST_STORE(
     278             :                               gtk_combo_box_get_model(
     279           0 :                                   GTK_COMBO_BOX(pPartSelector) )) );
     280             : 
     281           0 :     if ( !pDocView )
     282             :     {
     283           0 :         return;
     284             :     }
     285             : 
     286           0 :     const int nMaxLength = 50;
     287             :     char sText[nMaxLength];
     288             : 
     289           0 :     int nParts = lok_doc_view_get_parts( LOK_DOC_VIEW(pDocView) );
     290           0 :     for ( int i = 0; i < nParts; i++ )
     291             :     {
     292           0 :         char* pName = lok_doc_view_get_part_name( LOK_DOC_VIEW(pDocView), i );
     293             :         assert( pName );
     294           0 :         snprintf( sText, nMaxLength, "%i (%s)", i+1, pName );
     295           0 :         free( pName );
     296             : 
     297           0 :         gtk_combo_box_text_append_text( pPartSelector, sText );
     298             :     }
     299           0 :     gtk_combo_box_set_active( GTK_COMBO_BOX(pPartSelector),
     300           0 :                               lok_doc_view_get_part( LOK_DOC_VIEW(pDocView) ) );
     301             : }
     302             : 
     303           0 : static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
     304             : {
     305           0 :     int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) );
     306             : 
     307           0 :     if (g_bPartSelectorBroadcast && pDocView)
     308             :     {
     309           0 :         lok_doc_view_set_part( LOK_DOC_VIEW(pDocView), nPart );
     310             :     }
     311           0 : }
     312             : 
     313           0 : static void populatePartModeSelector( GtkComboBoxText* pSelector )
     314             : {
     315           0 :     gtk_combo_box_text_append_text( pSelector, "Standard" );
     316           0 :     gtk_combo_box_text_append_text( pSelector, "Notes" );
     317           0 :     gtk_combo_box_set_active( GTK_COMBO_BOX(pSelector), 0 );
     318           0 : }
     319             : 
     320           0 : static void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ )
     321             : {
     322             :     // Just convert directly back to the LibreOfficeKitPartMode enum.
     323             :     // I.e. the ordering above should match the enum member ordering.
     324             :     LibreOfficeKitPartMode ePartMode =
     325           0 :         LibreOfficeKitPartMode( gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) ) );
     326             : 
     327           0 :     if ( pDocView )
     328             :     {
     329           0 :         lok_doc_view_set_partmode( LOK_DOC_VIEW(pDocView), ePartMode );
     330             :     }
     331           0 : }
     332             : #endif
     333             : 
     334           0 : int main( int argc, char* argv[] )
     335             : {
     336           0 :     if( argc < 3 ||
     337           0 :         ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
     338           0 :         return help();
     339             : 
     340           0 :     if ( argv[1][0] != '/' )
     341             :     {
     342           0 :         fprintf(stderr, "Absolute path required to libreoffice install\n");
     343           0 :         return 1;
     344             :     }
     345             : 
     346           0 :     pOffice = lok_init( argv[1] );
     347           0 :     if ( pOffice == NULL )
     348           0 :         return 1;
     349             : 
     350           0 :     gtk_init( &argc, &argv );
     351             : 
     352           0 :     GtkWidget *pWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
     353           0 :     gtk_window_set_title( GTK_WINDOW(pWindow), "LibreOfficeKit GTK Tiled Viewer" );
     354           0 :     gtk_window_set_default_size(GTK_WINDOW(pWindow), 1024, 768);
     355           0 :     g_signal_connect( pWindow, "destroy", G_CALLBACK(gtk_main_quit), NULL );
     356             : 
     357           0 :     pVBox = gtk_vbox_new( FALSE, 0 );
     358           0 :     gtk_container_add( GTK_CONTAINER(pWindow), pVBox );
     359             : 
     360             :     // Toolbar
     361           0 :     GtkWidget* pToolbar = gtk_toolbar_new();
     362           0 :     gtk_toolbar_set_style( GTK_TOOLBAR(pToolbar), GTK_TOOLBAR_ICONS );
     363             : 
     364           0 :     GtkToolItem* pZoomIn = gtk_tool_button_new_from_stock( GTK_STOCK_ZOOM_IN );
     365           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pZoomIn, 0);
     366           0 :     g_signal_connect( G_OBJECT(pZoomIn), "clicked", G_CALLBACK(changeZoom), NULL );
     367             : 
     368           0 :     GtkToolItem* pZoom1 = gtk_tool_button_new_from_stock( GTK_STOCK_ZOOM_100 );
     369           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pZoom1, -1);
     370           0 :     g_signal_connect( G_OBJECT(pZoom1), "clicked", G_CALLBACK(changeZoom), NULL );
     371             : 
     372           0 :     GtkToolItem* pZoomOut = gtk_tool_button_new_from_stock( GTK_STOCK_ZOOM_OUT );
     373           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pZoomOut, -1);
     374           0 :     g_signal_connect( G_OBJECT(pZoomOut), "clicked", G_CALLBACK(changeZoom), NULL );
     375             : 
     376           0 :     GtkToolItem* pSeparator1 = gtk_separator_tool_item_new();
     377           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator1, -1);
     378             : 
     379             : // GtkComboBox requires gtk 2.24 or later
     380             : #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
     381           0 :     GtkToolItem* pPartSelectorToolItem = gtk_tool_item_new();
     382           0 :     GtkWidget* pComboBox = gtk_combo_box_text_new();
     383           0 :     gtk_container_add( GTK_CONTAINER(pPartSelectorToolItem), pComboBox );
     384           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartSelectorToolItem, -1 );
     385             : 
     386           0 :     pPartSelector = GTK_COMBO_BOX_TEXT(pComboBox);
     387             : 
     388           0 :     GtkToolItem* pSeparator2 = gtk_separator_tool_item_new();
     389           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator2, -1);
     390             : 
     391           0 :     GtkToolItem* pPartModeSelectorToolItem = gtk_tool_item_new();
     392           0 :     GtkWidget* pPartModeComboBox = gtk_combo_box_text_new();
     393           0 :     gtk_container_add( GTK_CONTAINER(pPartModeSelectorToolItem), pPartModeComboBox );
     394           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartModeSelectorToolItem, -1 );
     395             : #endif
     396             : 
     397           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
     398           0 :     pEnableEditing = gtk_toggle_tool_button_new_from_stock(GTK_STOCK_EDIT);
     399           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pEnableEditing, -1);
     400           0 :     g_signal_connect(G_OBJECT(pEnableEditing), "toggled", G_CALLBACK(toggleEditing), NULL);
     401           0 :     GtkToolItem* pFindButton = gtk_tool_button_new_from_stock(GTK_STOCK_FIND);
     402           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pFindButton, -1);
     403           0 :     g_signal_connect(G_OBJECT(pFindButton), "clicked", G_CALLBACK(toggleFindbar), NULL);
     404             : 
     405           0 :     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
     406           0 :     pBold = gtk_toggle_tool_button_new_from_stock(GTK_STOCK_BOLD);
     407           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pBold, -1);
     408           0 :     g_signal_connect(G_OBJECT(pBold), "toggled", G_CALLBACK(toggleToolItem), NULL);
     409           0 :     lcl_registerToolItem(pBold, ".uno:Bold");
     410           0 :     pItalic = gtk_toggle_tool_button_new_from_stock(GTK_STOCK_ITALIC);
     411           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pItalic, -1);
     412           0 :     g_signal_connect(G_OBJECT(pItalic), "toggled", G_CALLBACK(toggleToolItem), NULL);
     413           0 :     lcl_registerToolItem(pItalic, ".uno:Italic");
     414           0 :     pUnderline = gtk_toggle_tool_button_new_from_stock(GTK_STOCK_UNDERLINE);
     415           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pUnderline, -1);
     416           0 :     g_signal_connect(G_OBJECT(pUnderline), "toggled", G_CALLBACK(toggleToolItem), NULL);
     417           0 :     lcl_registerToolItem(pUnderline, ".uno:Underline");
     418           0 :     pStrikethrough = gtk_toggle_tool_button_new_from_stock(GTK_STOCK_STRIKETHROUGH);
     419           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pStrikethrough, -1);
     420           0 :     g_signal_connect(G_OBJECT(pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), NULL);
     421           0 :     lcl_registerToolItem(pStrikethrough, ".uno:Strikeout");
     422             : 
     423           0 :     gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
     424             : 
     425             :     // Findbar
     426           0 :     pFindbar = gtk_toolbar_new();
     427           0 :     gtk_toolbar_set_style(GTK_TOOLBAR(pFindbar), GTK_TOOLBAR_ICONS);
     428             : 
     429           0 :     GtkToolItem* pFindbarClose = gtk_tool_button_new_from_stock(GTK_STOCK_CLOSE);
     430           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarClose, -1);
     431           0 :     g_signal_connect(G_OBJECT(pFindbarClose), "clicked", G_CALLBACK(toggleFindbar), NULL);
     432             : 
     433           0 :     GtkToolItem* pEntryContainer = gtk_tool_item_new();
     434           0 :     pFindbarEntry = gtk_entry_new();
     435           0 :     gtk_container_add(GTK_CONTAINER(pEntryContainer), pFindbarEntry);
     436           0 :     g_signal_connect(pFindbarEntry, "key-press-event", G_CALLBACK(signalFindbar), 0);
     437           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pEntryContainer, -1);
     438             : 
     439           0 :     GtkToolItem* pFindbarNext = gtk_tool_button_new_from_stock(GTK_STOCK_GO_DOWN);
     440           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarNext, -1);
     441           0 :     g_signal_connect(G_OBJECT(pFindbarNext), "clicked", G_CALLBACK(signalSearchNext), NULL);
     442           0 :     GtkToolItem* pFindbarPrev = gtk_tool_button_new_from_stock(GTK_STOCK_GO_UP);
     443           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarPrev, -1);
     444           0 :     g_signal_connect(G_OBJECT(pFindbarPrev), "clicked", G_CALLBACK(signalSearchPrev), NULL);
     445             : 
     446           0 :     GtkToolItem* pFindbarLabelContainer = gtk_tool_item_new();
     447           0 :     pFindbarLabel = gtk_label_new("");
     448           0 :     gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), pFindbarLabel);
     449           0 :     gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarLabelContainer, -1);
     450             : 
     451           0 :     gtk_box_pack_end(GTK_BOX(pVBox), pFindbar, FALSE, FALSE, 0);
     452             : 
     453             :     // Docview
     454           0 :     pDocView = lok_doc_view_new( pOffice );
     455           0 :     g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
     456           0 :     g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
     457           0 :     g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
     458           0 :     g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
     459             : 
     460             :     // Input handling.
     461           0 :     g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), pDocView);
     462           0 :     g_signal_connect(pWindow, "key-release-event", G_CALLBACK(signalKey), pDocView);
     463             : 
     464           0 :     gtk_container_add( GTK_CONTAINER(pVBox), pDocView );
     465             : 
     466           0 :     gtk_widget_show_all( pWindow );
     467             :     // Hide the findbar by default.
     468           0 :     gtk_widget_hide(pFindbar);
     469             : 
     470           0 :     int bOpened = lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2] );
     471           0 :     if (!bOpened)
     472           0 :         g_error("main: lok_doc_view_open_document() failed with '%s'", pOffice->pClass->getError(pOffice));
     473             :     assert(lok_doc_view_get_document(LOK_DOC_VIEW(pDocView)));
     474             : 
     475             :     // GtkComboBox requires gtk 2.24 or later
     476             : #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
     477           0 :     populatePartSelector();
     478           0 :     populatePartModeSelector( GTK_COMBO_BOX_TEXT(pPartModeComboBox) );
     479             :     // Connect these signals after populating the selectors, to avoid re-rendering on setting the default part/partmode.
     480           0 :     g_signal_connect(G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0);
     481             : 
     482           0 :     g_signal_connect(G_OBJECT(pPartSelector), "changed", G_CALLBACK(changePart), 0);
     483             : #endif
     484             : 
     485           0 :     gtk_main();
     486             : 
     487           0 :     pOffice->pClass->destroy( pOffice );
     488             : 
     489           0 :     return 0;
     490           0 : }
     491             : 
     492             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11