[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 8 commits - include/sfx2 libreofficekit/qa
Miklos Vajna
vmiklos at collabora.co.uk
Tue Sep 15 04:59:03 PDT 2015
include/sfx2/lokhelper.hxx | 5
libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 384 +++++++++++---------
2 files changed, 231 insertions(+), 158 deletions(-)
New commits:
commit ce6be3a6f395be90beb4a7dc2988cbaf98b66600
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Sep 15 12:53:24 2015 +0200
gtktiledviewer: allow findbar in multiple windows
With this, all previously global data is now stored per-window in the
g_aWindows map.
Change-Id: I45b4449ee7d516106ea0b039d1af97db49edf759
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index d09bb69..fbd2bc3 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,10 +30,6 @@ static int help()
return 1;
}
-static GtkWidget* pFindbar;
-static GtkWidget* pFindbarEntry;
-static GtkWidget* pFindbarLabel;
-
/// Represents all the state that is specific to one GtkWindow of this app.
class TiledWindow
{
@@ -54,6 +50,9 @@ public:
GtkWidget* m_pPartModeComboBox;
/// Should the part selector avoid calling lok::Document::setPart()?
bool m_bPartSelectorBroadcast;
+ GtkWidget* m_pFindbar;
+ GtkWidget* m_pFindbarEntry;
+ GtkWidget* m_pFindbarLabel;
TiledWindow()
: m_pDocView(0),
@@ -68,7 +67,10 @@ public:
m_pVBox(0),
m_pPartSelector(0),
m_pPartModeComboBox(0),
- m_bPartSelectorBroadcast(true)
+ m_bPartSelectorBroadcast(true),
+ m_pFindbar(0),
+ m_pFindbarEntry(0),
+ m_pFindbarLabel(0)
{
}
};
@@ -173,16 +175,17 @@ static void toggleEditing(GtkWidget* pButton, gpointer /*pItem*/)
}
/// Toggle the visibility of the findbar.
-static void toggleFindbar(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+static void toggleFindbar(GtkWidget* pButton, gpointer /*pItem*/)
{
- if (gtk_widget_get_visible(pFindbar))
+ TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+ if (gtk_widget_get_visible(rWindow.m_pFindbar))
{
- gtk_widget_hide(pFindbar);
+ gtk_widget_hide(rWindow.m_pFindbar);
}
else
{
- gtk_widget_show_all(pFindbar);
- gtk_widget_grab_focus(pFindbarEntry);
+ gtk_widget_show_all(rWindow.m_pFindbar);
+ gtk_widget_grab_focus(rWindow.m_pFindbarEntry);
}
}
@@ -245,10 +248,11 @@ static void doCopy(GtkWidget* pButton, gpointer /*pItem*/)
}
-/// Searches for the next or previous text of pFindbarEntry.
+/// Searches for the next or previous text of TiledWindow::m_pFindbarEntry.
static void doSearch(GtkWidget* pButton, bool bBackwards)
{
- GtkEntry* pEntry = GTK_ENTRY(pFindbarEntry);
+ TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+ GtkEntry* pEntry = GTK_ENTRY(rWindow.m_pFindbarEntry);
const char* pText = gtk_entry_get_text(pEntry);
boost::property_tree::ptree aTree;
aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/type", '/'), "string");
@@ -256,7 +260,6 @@ static void doSearch(GtkWidget* pButton, bool bBackwards)
aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/type", '/'), "boolean");
aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/value", '/'), bBackwards);
- TiledWindow& rWindow = lcl_getTiledWindow(pButton);
LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
GdkRectangle aArea;
getVisibleAreaTwips(rWindow.m_pDocView, &aArea);
@@ -286,7 +289,8 @@ static void signalSearchPrev(GtkWidget* pButton, gpointer /*pItem*/)
/// Handles the key-press-event of the search entry widget.
static gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/)
{
- gtk_label_set_text(GTK_LABEL(pFindbarLabel), "");
+ TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
+ gtk_label_set_text(GTK_LABEL(rWindow.m_pFindbarLabel), "");
switch(pEvent->keyval)
{
case GDK_KEY_Return:
@@ -298,7 +302,7 @@ static gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer
case GDK_KEY_Escape:
{
// Hide the findbar.
- gtk_widget_hide(pFindbar);
+ gtk_widget_hide(rWindow.m_pFindbar);
return TRUE;
}
}
@@ -351,9 +355,10 @@ static void loadChanged(LOKDocView* /*pLOKDocView*/, gdouble fValue, gpointer pD
}
/// LOKDocView found no search matches -> set the search label accordingly.
-static void signalSearch(LOKDocView* /*pLOKDocView*/, char* /*pPayload*/, gpointer /*pData*/)
+static void signalSearch(LOKDocView* pLOKDocView, char* /*pPayload*/, gpointer /*pData*/)
{
- gtk_label_set_text(GTK_LABEL(pFindbarLabel), "Search key not found");
+ TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView));
+ gtk_label_set_text(GTK_LABEL(rWindow.m_pFindbarLabel), "Search key not found");
}
@@ -667,36 +672,36 @@ int main( int argc, char* argv[] )
gtk_box_pack_start( GTK_BOX(aWindow.m_pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
// Findbar
- pFindbar = gtk_toolbar_new();
- gtk_toolbar_set_style(GTK_TOOLBAR(pFindbar), GTK_TOOLBAR_ICONS);
+ aWindow.m_pFindbar = gtk_toolbar_new();
+ gtk_toolbar_set_style(GTK_TOOLBAR(aWindow.m_pFindbar), GTK_TOOLBAR_ICONS);
GtkToolItem* pFindbarClose = gtk_tool_button_new( NULL, NULL);
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarClose), "window-close-symbolic");
- gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarClose, -1);
+ gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarClose, -1);
g_signal_connect(G_OBJECT(pFindbarClose), "clicked", G_CALLBACK(toggleFindbar), NULL);
GtkToolItem* pEntryContainer = gtk_tool_item_new();
- pFindbarEntry = gtk_entry_new();
- gtk_container_add(GTK_CONTAINER(pEntryContainer), pFindbarEntry);
- g_signal_connect(pFindbarEntry, "key-press-event", G_CALLBACK(signalFindbar), 0);
- gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pEntryContainer, -1);
+ aWindow.m_pFindbarEntry = gtk_entry_new();
+ gtk_container_add(GTK_CONTAINER(pEntryContainer), aWindow.m_pFindbarEntry);
+ g_signal_connect(aWindow.m_pFindbarEntry, "key-press-event", G_CALLBACK(signalFindbar), 0);
+ gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pEntryContainer, -1);
GtkToolItem* pFindbarNext = gtk_tool_button_new( NULL, NULL);
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarNext), "go-down-symbolic");
- gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarNext, -1);
+ gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarNext, -1);
g_signal_connect(G_OBJECT(pFindbarNext), "clicked", G_CALLBACK(signalSearchNext), NULL);
GtkToolItem* pFindbarPrev = gtk_tool_button_new( NULL, NULL);
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarPrev), "go-up-symbolic");
- gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarPrev, -1);
+ gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarPrev, -1);
g_signal_connect(G_OBJECT(pFindbarPrev), "clicked", G_CALLBACK(signalSearchPrev), NULL);
GtkToolItem* pFindbarLabelContainer = gtk_tool_item_new();
- pFindbarLabel = gtk_label_new("");
- gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), pFindbarLabel);
- gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarLabelContainer, -1);
+ aWindow.m_pFindbarLabel = gtk_label_new("");
+ gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), aWindow.m_pFindbarLabel);
+ gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarLabelContainer, -1);
- gtk_box_pack_end(GTK_BOX(aWindow.m_pVBox), pFindbar, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(aWindow.m_pVBox), aWindow.m_pFindbar, FALSE, FALSE, 0);
// Docview
GtkWidget* pDocView = lok_doc_view_new (argv[1], NULL, NULL);
@@ -734,7 +739,7 @@ int main( int argc, char* argv[] )
gtk_widget_show_all( pWindow );
// Hide the findbar by default.
- gtk_widget_hide(pFindbar);
+ gtk_widget_hide(aWindow.m_pFindbar);
g_aWindows[pWindow] = aWindow;
commit d37a9404e2ff2a65b23d40b036fba33b0a4ab76c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Sep 15 12:45:58 2015 +0200
gtktiledviewer: allow part selector in multiple windows
Change-Id: Ib31fca3d8b4119704fb1a5c3cee885e7c239c247
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 58001ad..d09bb69 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,11 +30,6 @@ static int help()
return 1;
}
-static GtkWidget* pVBox;
-static GtkComboBoxText* pPartSelector;
-static GtkWidget* pPartModeComboBox;
-/// Should the part selector avoid calling lok::Document::setPart()?
-static bool g_bPartSelectorBroadcast = true;
static GtkWidget* pFindbar;
static GtkWidget* pFindbarEntry;
static GtkWidget* pFindbarLabel;
@@ -54,6 +49,11 @@ public:
std::map<GtkToolItem*, std::string> m_aToolItemCommandNames;
std::map<std::string, GtkToolItem*> m_aCommandNameToolItems;
bool m_bToolItemBroadcast;
+ GtkWidget* m_pVBox;
+ GtkComboBoxText* m_pPartSelector;
+ GtkWidget* m_pPartModeComboBox;
+ /// Should the part selector avoid calling lok::Document::setPart()?
+ bool m_bPartSelectorBroadcast;
TiledWindow()
: m_pDocView(0),
@@ -64,7 +64,11 @@ public:
m_pUnderline(0),
m_pStrikethrough(0),
m_pScrolledWindow(0),
- m_bToolItemBroadcast(true)
+ m_bToolItemBroadcast(true),
+ m_pVBox(0),
+ m_pPartSelector(0),
+ m_pPartModeComboBox(0),
+ m_bPartSelectorBroadcast(true)
{
}
};
@@ -353,11 +357,12 @@ static void signalSearch(LOKDocView* /*pLOKDocView*/, char* /*pPayload*/, gpoint
}
-static void signalPart(LOKDocView* /*pLOKDocView*/, int nPart, gpointer /*pData*/)
+static void signalPart(LOKDocView* pLOKDocView, int nPart, gpointer /*pData*/)
{
- g_bPartSelectorBroadcast = false;
- gtk_combo_box_set_active(GTK_COMBO_BOX(pPartSelector), nPart);
- g_bPartSelectorBroadcast = true;
+ 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.
@@ -438,9 +443,10 @@ static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
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(pPartSelector) )) );
+ GTK_COMBO_BOX(rWindow.m_pPartSelector) )) );
if (!pLOKDocView)
{
@@ -458,16 +464,17 @@ static void populatePartSelector(LOKDocView* pLOKDocView)
snprintf( sText, nMaxLength, "%i (%s)", i+1, pName );
free( pName );
- gtk_combo_box_text_append_text( pPartSelector, sText );
+ gtk_combo_box_text_append_text( rWindow.m_pPartSelector, sText );
}
- gtk_combo_box_set_active(GTK_COMBO_BOX(pPartSelector), lok_doc_view_get_part(pLOKDocView));
+ gtk_combo_box_set_active(GTK_COMBO_BOX(rWindow.m_pPartSelector), lok_doc_view_get_part(pLOKDocView));
}
static void signalSize(LOKDocView* pLOKDocView, gpointer /*pData*/)
{
- g_bPartSelectorBroadcast = false;
+ TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView));
+ rWindow.m_bPartSelectorBroadcast = false;
populatePartSelector(pLOKDocView);
- g_bPartSelectorBroadcast = true;
+ rWindow.m_bPartSelectorBroadcast = true;
}
static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
@@ -475,7 +482,7 @@ static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) );
TiledWindow& rWindow = lcl_getTiledWindow(pSelector);
- if (g_bPartSelectorBroadcast && rWindow.m_pDocView)
+ 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) );
@@ -524,13 +531,13 @@ static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpo
}
populatePartSelector(pDocView);
- populatePartModeSelector( GTK_COMBO_BOX_TEXT(pPartModeComboBox) );
+ populatePartModeSelector( GTK_COMBO_BOX_TEXT(rWindow.m_pPartModeComboBox) );
// Connect these signals after populating the selectors, to avoid re-rendering on setting the default part/partmode.
- g_signal_connect(G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0);
- g_signal_connect(G_OBJECT(pPartSelector), "changed", G_CALLBACK(changePart), 0);
+ 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);
focusChain = g_list_append( focusChain, pDocView );
- gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
+ gtk_container_set_focus_chain ( GTK_CONTAINER (rWindow.m_pVBox), focusChain );
gtk_widget_hide(rWindow.m_pStatusBar);
}
@@ -555,8 +562,8 @@ int main( int argc, char* argv[] )
gtk_window_set_default_size(GTK_WINDOW(pWindow), 1024, 768);
g_signal_connect( pWindow, "destroy", G_CALLBACK(gtk_main_quit), NULL );
- pVBox = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );
- gtk_container_add( GTK_CONTAINER(pWindow), pVBox );
+ aWindow.m_pVBox = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );
+ gtk_container_add( GTK_CONTAINER(pWindow), aWindow.m_pVBox );
// Toolbar
GtkWidget* pToolbar = gtk_toolbar_new();
@@ -588,14 +595,14 @@ int main( int argc, char* argv[] )
gtk_container_add( GTK_CONTAINER(pPartSelectorToolItem), pComboBox );
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartSelectorToolItem, -1 );
- pPartSelector = GTK_COMBO_BOX_TEXT(pComboBox);
+ aWindow.m_pPartSelector = GTK_COMBO_BOX_TEXT(pComboBox);
GtkToolItem* pSeparator2 = gtk_separator_tool_item_new();
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator2, -1);
GtkToolItem* pPartModeSelectorToolItem = gtk_tool_item_new();
- pPartModeComboBox = gtk_combo_box_text_new();
- gtk_container_add( GTK_CONTAINER(pPartModeSelectorToolItem), pPartModeComboBox );
+ aWindow.m_pPartModeComboBox = gtk_combo_box_text_new();
+ gtk_container_add(GTK_CONTAINER(pPartModeSelectorToolItem), aWindow.m_pPartModeComboBox);
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartModeSelectorToolItem, -1 );
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
@@ -657,7 +664,7 @@ int main( int argc, char* argv[] )
g_signal_connect(G_OBJECT(aWindow.m_pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), NULL);
lcl_registerToolItem(aWindow, aWindow.m_pStrikethrough, ".uno:Strikeout");
- gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
+ gtk_box_pack_start( GTK_BOX(aWindow.m_pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
// Findbar
pFindbar = gtk_toolbar_new();
@@ -689,7 +696,7 @@ int main( int argc, char* argv[] )
gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), pFindbarLabel);
gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarLabelContainer, -1);
- gtk_box_pack_end(GTK_BOX(pVBox), pFindbar, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(aWindow.m_pVBox), pFindbar, FALSE, FALSE, 0);
// Docview
GtkWidget* pDocView = lok_doc_view_new (argv[1], NULL, NULL);
@@ -711,7 +718,7 @@ int main( int argc, char* argv[] )
aWindow.m_pScrolledWindow = gtk_scrolled_window_new(0, 0);
gtk_widget_set_hexpand (aWindow.m_pScrolledWindow, TRUE);
gtk_widget_set_vexpand (aWindow.m_pScrolledWindow, TRUE);
- gtk_container_add(GTK_CONTAINER(pVBox), aWindow.m_pScrolledWindow);
+ gtk_container_add(GTK_CONTAINER(aWindow.m_pVBox), aWindow.m_pScrolledWindow);
gtk_container_add(GTK_CONTAINER(aWindow.m_pScrolledWindow), pDocView);
@@ -721,7 +728,7 @@ int main( int argc, char* argv[] )
GtkWidget* pStatusBar = gtk_statusbar_new ();
aWindow.m_pStatusBar = pStatusBar;
gtk_container_forall(GTK_CONTAINER(pStatusBar), removeChildrenFromStatusbar, pStatusBar);
- gtk_container_add (GTK_CONTAINER(pVBox), pStatusBar);
+ gtk_container_add (GTK_CONTAINER(aWindow.m_pVBox), pStatusBar);
gtk_container_add (GTK_CONTAINER(pStatusBar), pProgressBar);
gtk_widget_set_hexpand(pProgressBar, true);
commit 98933d3daa8d65cec6d8f36c4b03717201cb495f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Sep 15 12:36:49 2015 +0200
gtktiledviwer: tool item registration is per-window
Change-Id: I11a6cda7b9b8949c48c201c4bd467b49f2f43ca5
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 9cd4380..58001ad 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,10 +30,6 @@ static int help()
return 1;
}
-static GtkWidget* pScrolledWindow;
-static std::map<GtkToolItem*, std::string> g_aToolItemCommandNames;
-static std::map<std::string, GtkToolItem*> g_aCommandNameToolItems;
-static bool g_bToolItemBroadcast = true;
static GtkWidget* pVBox;
static GtkComboBoxText* pPartSelector;
static GtkWidget* pPartModeComboBox;
@@ -54,6 +50,10 @@ public:
GtkToolItem* m_pItalic;
GtkToolItem* m_pUnderline;
GtkToolItem* m_pStrikethrough;
+ GtkWidget* m_pScrolledWindow;
+ std::map<GtkToolItem*, std::string> m_aToolItemCommandNames;
+ std::map<std::string, GtkToolItem*> m_aCommandNameToolItems;
+ bool m_bToolItemBroadcast;
TiledWindow()
: m_pDocView(0),
@@ -62,7 +62,9 @@ public:
m_pBold(0),
m_pItalic(0),
m_pUnderline(0),
- m_pStrikethrough(0)
+ m_pStrikethrough(0),
+ m_pScrolledWindow(0),
+ m_bToolItemBroadcast(true)
{
}
};
@@ -71,13 +73,15 @@ static std::map<GtkWidget*, TiledWindow> g_aWindows;
static TiledWindow& lcl_getTiledWindow(GtkWidget* pWidget)
{
- return g_aWindows[gtk_widget_get_toplevel(pWidget)];
+ GtkWidget* pToplevel = gtk_widget_get_toplevel(pWidget);
+ assert(g_aWindows.find(pToplevel) != g_aWindows.end());
+ return g_aWindows[pToplevel];
}
-static void lcl_registerToolItem(GtkToolItem* pItem, const std::string& rName)
+static void lcl_registerToolItem(TiledWindow& rWindow, GtkToolItem* pItem, const std::string& rName)
{
- g_aToolItemCommandNames[pItem] = rName;
- g_aCommandNameToolItems[rName] = pItem;
+ rWindow.m_aToolItemCommandNames[pItem] = rName;
+ rWindow.m_aCommandNameToolItems[rName] = pItem;
}
const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 };
@@ -87,8 +91,10 @@ const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 };
static void getVisibleAreaTwips(GtkWidget* pDocView, GdkRectangle* pArea)
{
#if GTK_CHECK_VERSION(2,14,0) // we need gtk_adjustment_get_page_size()
- GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(pScrolledWindow));
- GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(pScrolledWindow));
+ 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));
@@ -307,8 +313,10 @@ static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pD
}
/// LOKDocView changed command state -> inform the tool button.
-static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer /*pData*/)
+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)
@@ -317,16 +325,16 @@ static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer
std::string aValue = aPayload.substr(nPosition + 1);
g_info("signalCommand: '%s' is '%s'", aKey.c_str(), aValue.c_str());
- if (g_aCommandNameToolItems.find(aKey) != g_aCommandNameToolItems.end())
+ if (rWindow.m_aCommandNameToolItems.find(aKey) != rWindow.m_aCommandNameToolItems.end())
{
- GtkToolItem* pItem = g_aCommandNameToolItems[aKey];
+ GtkToolItem* pItem = rWindow.m_aCommandNameToolItems[aKey];
gboolean bEdit = aValue == "true";
if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pItem)) != bEdit)
{
// Avoid invoking lok_doc_view_post_command().
- g_bToolItemBroadcast = false;
+ rWindow.m_bToolItemBroadcast = false;
gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pItem), bEdit);
- g_bToolItemBroadcast = true;
+ rWindow.m_bToolItemBroadcast = true;
}
}
}
@@ -368,8 +376,10 @@ static void signalHyperlink(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointe
static void cursorChanged(LOKDocView* pDocView, gint nX, gint nY,
gint /*nWidth*/, gint /*nHeight*/, gpointer /*pData*/)
{
- GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(pScrolledWindow));
- GtkAdjustment* hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(pScrolledWindow));
+ 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;
@@ -414,12 +424,13 @@ static void cursorChanged(LOKDocView* pDocView, gint nX, gint nY,
static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
{
- if (g_bToolItemBroadcast)
+ TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
+
+ if (rWindow.m_bToolItemBroadcast)
{
- TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
- const std::string& rString = g_aToolItemCommandNames[pItem];
+ const std::string& rString = rWindow.m_aToolItemCommandNames[pItem];
g_info("toggleToolItem: lok_doc_view_post_command('%s')", rString.c_str());
lok_doc_view_post_command(pLOKDocView, rString.c_str(), 0);
}
@@ -623,28 +634,28 @@ int main( int argc, char* argv[] )
gtk_tool_item_set_tooltip_text(aWindow.m_pBold, "Bold");
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pBold, -1);
g_signal_connect(G_OBJECT(aWindow.m_pBold), "toggled", G_CALLBACK(toggleToolItem), NULL);
- lcl_registerToolItem(aWindow.m_pBold, ".uno:Bold");
+ lcl_registerToolItem(aWindow, aWindow.m_pBold, ".uno:Bold");
aWindow.m_pItalic = gtk_toggle_tool_button_new();
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (aWindow.m_pItalic), "format-text-italic-symbolic");
gtk_tool_item_set_tooltip_text(aWindow.m_pItalic, "Italic");
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pItalic, -1);
g_signal_connect(G_OBJECT(aWindow.m_pItalic), "toggled", G_CALLBACK(toggleToolItem), NULL);
- lcl_registerToolItem(aWindow.m_pItalic, ".uno:Italic");
+ lcl_registerToolItem(aWindow, aWindow.m_pItalic, ".uno:Italic");
aWindow.m_pUnderline = gtk_toggle_tool_button_new();
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (aWindow.m_pUnderline), "format-text-underline-symbolic");
gtk_tool_item_set_tooltip_text(aWindow.m_pUnderline, "Underline");
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pUnderline, -1);
g_signal_connect(G_OBJECT(aWindow.m_pUnderline), "toggled", G_CALLBACK(toggleToolItem), NULL);
- lcl_registerToolItem(aWindow.m_pUnderline, ".uno:Underline");
+ lcl_registerToolItem(aWindow, aWindow.m_pUnderline, ".uno:Underline");
aWindow.m_pStrikethrough = gtk_toggle_tool_button_new ();
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(aWindow.m_pStrikethrough), "format-text-strikethrough-symbolic");
gtk_tool_item_set_tooltip_text(aWindow.m_pStrikethrough, "Strikethrough");
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pStrikethrough, -1);
g_signal_connect(G_OBJECT(aWindow.m_pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), NULL);
- lcl_registerToolItem(aWindow.m_pStrikethrough, ".uno:Strikeout");
+ lcl_registerToolItem(aWindow, aWindow.m_pStrikethrough, ".uno:Strikeout");
gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
@@ -697,12 +708,12 @@ int main( int argc, char* argv[] )
// Scrolled window for DocView
- pScrolledWindow = gtk_scrolled_window_new(0, 0);
- gtk_widget_set_hexpand (pScrolledWindow, TRUE);
- gtk_widget_set_vexpand (pScrolledWindow, TRUE);
- gtk_container_add(GTK_CONTAINER(pVBox), pScrolledWindow);
+ aWindow.m_pScrolledWindow = gtk_scrolled_window_new(0, 0);
+ gtk_widget_set_hexpand (aWindow.m_pScrolledWindow, TRUE);
+ gtk_widget_set_vexpand (aWindow.m_pScrolledWindow, TRUE);
+ gtk_container_add(GTK_CONTAINER(pVBox), aWindow.m_pScrolledWindow);
- gtk_container_add(GTK_CONTAINER(pScrolledWindow), pDocView);
+ gtk_container_add(GTK_CONTAINER(aWindow.m_pScrolledWindow), pDocView);
GtkWidget* pProgressBar = gtk_progress_bar_new ();
g_signal_connect(pDocView, "load-changed", G_CALLBACK(loadChanged), pProgressBar);
commit 7ca2df733c2cfe3d12f58e16ff1499778259f70b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Sep 15 12:21:10 2015 +0200
gtktiledviwer: allow GtkToolItems in multiple windows
Change-Id: I6c19a9bdd34163d12047929170e5cfa7bb9a5820
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index c0fcc43..9cd4380 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,11 +30,6 @@ static int help()
return 1;
}
-static GtkToolItem* pEnableEditing;
-static GtkToolItem* pBold;
-static GtkToolItem* pItalic;
-static GtkToolItem* pUnderline;
-static GtkToolItem* pStrikethrough;
static GtkWidget* pScrolledWindow;
static std::map<GtkToolItem*, std::string> g_aToolItemCommandNames;
static std::map<std::string, GtkToolItem*> g_aCommandNameToolItems;
@@ -54,10 +49,20 @@ class TiledWindow
public:
GtkWidget* m_pDocView;
GtkWidget* m_pStatusBar;
+ GtkToolItem* m_pEnableEditing;
+ GtkToolItem* m_pBold;
+ GtkToolItem* m_pItalic;
+ GtkToolItem* m_pUnderline;
+ GtkToolItem* m_pStrikethrough;
TiledWindow()
: m_pDocView(0),
- m_pStatusBar(0)
+ m_pStatusBar(0),
+ m_pEnableEditing(0),
+ m_pBold(0),
+ m_pItalic(0),
+ m_pUnderline(0),
+ m_pStrikethrough(0)
{
}
};
@@ -152,7 +157,7 @@ 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(pEnableEditing));
+ 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);
}
@@ -293,10 +298,12 @@ static gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer
/// 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, lok_doc_view_get_edit(pLOKDocView));
- if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing)) != bEdit)
- gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing), bEdit);
+ if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(rWindow.m_pEnableEditing)) != bEdit)
+ gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(rWindow.m_pEnableEditing), bEdit);
}
/// LOKDocView changed command state -> inform the tool button.
@@ -532,6 +539,7 @@ int main( int argc, char* argv[] )
gtk_init( &argc, &argv );
GtkWidget *pWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
+ TiledWindow aWindow;
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(gtk_main_quit), NULL );
@@ -589,7 +597,8 @@ int main( int argc, char* argv[] )
g_signal_connect(G_OBJECT(pCopyButton), "clicked", G_CALLBACK(doCopy), NULL);
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
- pEnableEditing = gtk_toggle_tool_button_new();
+ GtkToolItem* pEnableEditing = gtk_toggle_tool_button_new();
+ aWindow.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(pToolbar), pEnableEditing, -1);
@@ -609,33 +618,33 @@ int main( int argc, char* argv[] )
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
- pBold = gtk_toggle_tool_button_new();
- gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pBold), "format-text-bold-symbolic");
- gtk_tool_item_set_tooltip_text(pBold, "Bold");
- gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pBold, -1);
- g_signal_connect(G_OBJECT(pBold), "toggled", G_CALLBACK(toggleToolItem), NULL);
- lcl_registerToolItem(pBold, ".uno:Bold");
-
- pItalic = gtk_toggle_tool_button_new();
- gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pItalic), "format-text-italic-symbolic");
- gtk_tool_item_set_tooltip_text(pItalic, "Italic");
- gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pItalic, -1);
- g_signal_connect(G_OBJECT(pItalic), "toggled", G_CALLBACK(toggleToolItem), NULL);
- lcl_registerToolItem(pItalic, ".uno:Italic");
-
- pUnderline = gtk_toggle_tool_button_new();
- gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pUnderline), "format-text-underline-symbolic");
- gtk_tool_item_set_tooltip_text(pUnderline, "Underline");
- gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pUnderline, -1);
- g_signal_connect(G_OBJECT(pUnderline), "toggled", G_CALLBACK(toggleToolItem), NULL);
- lcl_registerToolItem(pUnderline, ".uno:Underline");
-
- pStrikethrough = gtk_toggle_tool_button_new ();
- gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pStrikethrough), "format-text-strikethrough-symbolic");
- gtk_tool_item_set_tooltip_text(pStrikethrough, "Strikethrough");
- gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pStrikethrough, -1);
- g_signal_connect(G_OBJECT(pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), NULL);
- lcl_registerToolItem(pStrikethrough, ".uno:Strikeout");
+ aWindow.m_pBold = gtk_toggle_tool_button_new();
+ gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (aWindow.m_pBold), "format-text-bold-symbolic");
+ gtk_tool_item_set_tooltip_text(aWindow.m_pBold, "Bold");
+ gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pBold, -1);
+ g_signal_connect(G_OBJECT(aWindow.m_pBold), "toggled", G_CALLBACK(toggleToolItem), NULL);
+ lcl_registerToolItem(aWindow.m_pBold, ".uno:Bold");
+
+ aWindow.m_pItalic = gtk_toggle_tool_button_new();
+ gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (aWindow.m_pItalic), "format-text-italic-symbolic");
+ gtk_tool_item_set_tooltip_text(aWindow.m_pItalic, "Italic");
+ gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pItalic, -1);
+ g_signal_connect(G_OBJECT(aWindow.m_pItalic), "toggled", G_CALLBACK(toggleToolItem), NULL);
+ lcl_registerToolItem(aWindow.m_pItalic, ".uno:Italic");
+
+ aWindow.m_pUnderline = gtk_toggle_tool_button_new();
+ gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (aWindow.m_pUnderline), "format-text-underline-symbolic");
+ gtk_tool_item_set_tooltip_text(aWindow.m_pUnderline, "Underline");
+ gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pUnderline, -1);
+ g_signal_connect(G_OBJECT(aWindow.m_pUnderline), "toggled", G_CALLBACK(toggleToolItem), NULL);
+ lcl_registerToolItem(aWindow.m_pUnderline, ".uno:Underline");
+
+ aWindow.m_pStrikethrough = gtk_toggle_tool_button_new ();
+ gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(aWindow.m_pStrikethrough), "format-text-strikethrough-symbolic");
+ gtk_tool_item_set_tooltip_text(aWindow.m_pStrikethrough, "Strikethrough");
+ gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pStrikethrough, -1);
+ g_signal_connect(G_OBJECT(aWindow.m_pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), NULL);
+ lcl_registerToolItem(aWindow.m_pStrikethrough, ".uno:Strikeout");
gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
@@ -673,6 +682,7 @@ int main( int argc, char* argv[] )
// Docview
GtkWidget* pDocView = lok_doc_view_new (argv[1], NULL, NULL);
+ aWindow.m_pDocView = pDocView;
#if GLIB_CHECK_VERSION(2,40,0)
g_assert_nonnull(pDocView);
#endif
@@ -698,6 +708,7 @@ int main( int argc, char* argv[] )
g_signal_connect(pDocView, "load-changed", G_CALLBACK(loadChanged), pProgressBar);
GtkWidget* pStatusBar = gtk_statusbar_new ();
+ aWindow.m_pStatusBar = pStatusBar;
gtk_container_forall(GTK_CONTAINER(pStatusBar), removeChildrenFromStatusbar, pStatusBar);
gtk_container_add (GTK_CONTAINER(pVBox), pStatusBar);
gtk_container_add (GTK_CONTAINER(pStatusBar), pProgressBar);
@@ -707,9 +718,6 @@ int main( int argc, char* argv[] )
// Hide the findbar by default.
gtk_widget_hide(pFindbar);
- TiledWindow aWindow;
- aWindow.m_pDocView = pDocView;
- aWindow.m_pStatusBar = pStatusBar;
g_aWindows[pWindow] = aWindow;
lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2], NULL, openDocumentCallback, pDocView );
commit 8cab2f32dbc0c65617985cddf8f8d0761c33daa0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Sep 15 12:10:03 2015 +0200
gtktiledviewer: allow multiple status bars
Change-Id: I84c4102937deee662814c41607ee8de380a067f2
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index da2ef07..c0fcc43 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,7 +30,6 @@ static int help()
return 1;
}
-static GtkWidget* pStatusBar;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
static GtkToolItem* pItalic;
@@ -49,13 +48,16 @@ static GtkWidget* pFindbar;
static GtkWidget* pFindbarEntry;
static GtkWidget* pFindbarLabel;
+/// Represents all the state that is specific to one GtkWindow of this app.
class TiledWindow
{
public:
GtkWidget* m_pDocView;
+ GtkWidget* m_pStatusBar;
TiledWindow()
- : m_pDocView(0)
+ : m_pDocView(0),
+ m_pStatusBar(0)
{
}
};
@@ -462,8 +464,10 @@ static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
}
}
-static void removeChildrenFromStatusbar(GtkWidget* children, gpointer)
+static void removeChildrenFromStatusbar(GtkWidget* children, gpointer pData)
{
+ GtkWidget* pStatusBar = static_cast<GtkWidget*>(pData);
+
gtk_container_remove(GTK_CONTAINER(pStatusBar), children);
}
@@ -491,6 +495,7 @@ static void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ )
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 = NULL;
GList *focusChain = NULL;
@@ -509,7 +514,7 @@ static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpo
focusChain = g_list_append( focusChain, pDocView );
gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
- gtk_widget_hide (pStatusBar);
+ gtk_widget_hide(rWindow.m_pStatusBar);
}
int main( int argc, char* argv[] )
@@ -692,8 +697,8 @@ int main( int argc, char* argv[] )
GtkWidget* pProgressBar = gtk_progress_bar_new ();
g_signal_connect(pDocView, "load-changed", G_CALLBACK(loadChanged), pProgressBar);
- pStatusBar = gtk_statusbar_new ();
- gtk_container_forall(GTK_CONTAINER(pStatusBar), removeChildrenFromStatusbar, NULL);
+ GtkWidget* pStatusBar = gtk_statusbar_new ();
+ gtk_container_forall(GTK_CONTAINER(pStatusBar), removeChildrenFromStatusbar, pStatusBar);
gtk_container_add (GTK_CONTAINER(pVBox), pStatusBar);
gtk_container_add (GTK_CONTAINER(pStatusBar), pProgressBar);
gtk_widget_set_hexpand(pProgressBar, true);
@@ -704,6 +709,7 @@ int main( int argc, char* argv[] )
TiledWindow aWindow;
aWindow.m_pDocView = pDocView;
+ aWindow.m_pStatusBar = pStatusBar;
g_aWindows[pWindow] = aWindow;
lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2], NULL, openDocumentCallback, pDocView );
commit b400483bd6b9ce5bd2c716036f30cff020c58d82
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Sep 15 11:55:09 2015 +0200
gtktiledviewer: allow multiple DocView instances
Change-Id: I4e8a08d71a94445e8fd30563867a2741cad862e5
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 7637a68..da2ef07 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,7 +30,6 @@ static int help()
return 1;
}
-static GtkWidget* pDocView;
static GtkWidget* pStatusBar;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
@@ -50,6 +49,24 @@ static GtkWidget* pFindbar;
static GtkWidget* pFindbarEntry;
static GtkWidget* pFindbarLabel;
+class TiledWindow
+{
+public:
+ GtkWidget* m_pDocView;
+
+ TiledWindow()
+ : m_pDocView(0)
+ {
+ }
+};
+
+static std::map<GtkWidget*, TiledWindow> g_aWindows;
+
+static TiledWindow& lcl_getTiledWindow(GtkWidget* pWidget)
+{
+ return g_aWindows[gtk_widget_get_toplevel(pWidget)];
+}
+
static void lcl_registerToolItem(GtkToolItem* pItem, const std::string& rName)
{
g_aToolItemCommandNames[pItem] = rName;
@@ -60,7 +77,7 @@ const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 };
/// Get the visible area of the scrolled window
-static void getVisibleAreaTwips(GdkRectangle* pArea)
+static void getVisibleAreaTwips(GtkWidget* pDocView, GdkRectangle* pArea)
{
#if GTK_CHECK_VERSION(2,14,0) // we need gtk_adjustment_get_page_size()
GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(pScrolledWindow));
@@ -79,6 +96,9 @@ static void getVisibleAreaTwips(GdkRectangle* pArea)
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;
@@ -125,9 +145,11 @@ static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
}
/// User clicked on the button -> inform LOKDocView.
-static void toggleEditing(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+static void toggleEditing(GtkWidget* pButton, gpointer /*pItem*/)
{
- LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
+ 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(pEnableEditing));
if (bool(lok_doc_view_get_edit(pLOKDocView)) != bActive)
lok_doc_view_set_edit(pLOKDocView, bActive);
@@ -148,9 +170,10 @@ static void toggleFindbar(GtkWidget* /*pButton*/, gpointer /*pItem*/)
}
/// Calls lok::Document::createView().
-static void createView(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+static void createView(GtkWidget* pButton, gpointer /*pItem*/)
{
- LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
+ TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+ LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
pDocument->pClass->createView(pDocument);
}
@@ -185,14 +208,15 @@ static void clipboardSetHtml(GtkClipboard* pClipboard, const char* pSelection)
}
/// Handler for the copy button: write clipboard.
-static void doCopy(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+static void doCopy(GtkWidget* pButton, gpointer /*pItem*/)
{
- LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
+ TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+ LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
char* pUsedFormat = 0;
char* pSelection = pDocument->pClass->getTextSelection(pDocument, "text/html", &pUsedFormat);
- GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(pDocView), GDK_SELECTION_CLIPBOARD);
+ 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);
@@ -205,7 +229,7 @@ static void doCopy(GtkWidget* /*pButton*/, gpointer /*pItem*/)
/// Searches for the next or previous text of pFindbarEntry.
-static void doSearch(bool bBackwards)
+static void doSearch(GtkWidget* pButton, bool bBackwards)
{
GtkEntry* pEntry = GTK_ENTRY(pFindbarEntry);
const char* pText = gtk_entry_get_text(pEntry);
@@ -215,9 +239,10 @@ static void doSearch(bool bBackwards)
aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/type", '/'), "boolean");
aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/value", '/'), bBackwards);
- LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
+ TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+ LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
GdkRectangle aArea;
- getVisibleAreaTwips(&aArea);
+ getVisibleAreaTwips(rWindow.m_pDocView, &aArea);
aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointX/type", '/'), "long");
aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointX/value", '/'), aArea.x);
aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointY/type", '/'), "long");
@@ -230,19 +255,19 @@ static void doSearch(bool bBackwards)
}
/// Click handler for the search next button.
-static void signalSearchNext(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+static void signalSearchNext(GtkWidget* pButton, gpointer /*pItem*/)
{
- doSearch(/*bBackwards=*/false);
+ doSearch(pButton, /*bBackwards=*/false);
}
/// Click handler for the search previous button.
-static void signalSearchPrev(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+static void signalSearchPrev(GtkWidget* pButton, gpointer /*pItem*/)
{
- doSearch(/*bBackwards=*/true);
+ doSearch(pButton, /*bBackwards=*/true);
}
/// Handles the key-press-event of the search entry widget.
-static gboolean signalFindbar(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pData*/)
+static gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/)
{
gtk_label_set_text(GTK_LABEL(pFindbarLabel), "");
switch(pEvent->keyval)
@@ -250,7 +275,7 @@ static gboolean signalFindbar(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpoin
case GDK_KEY_Return:
{
// Search forward.
- doSearch(/*bBackwards=*/false);
+ doSearch(pWidget, /*bBackwards=*/false);
return TRUE;
}
case GDK_KEY_Escape:
@@ -331,7 +356,7 @@ static void signalHyperlink(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointe
}
/// Cursor position changed
-static void cursorChanged(LOKDocView* /*pDocView*/, gint nX, gint nY,
+static void cursorChanged(LOKDocView* pDocView, gint nX, gint nY,
gint /*nWidth*/, gint /*nHeight*/, gpointer /*pData*/)
{
GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(pScrolledWindow));
@@ -340,7 +365,7 @@ static void cursorChanged(LOKDocView* /*pDocView*/, gint nX, gint nY,
gdouble upper;
gint x = -1, y = -1;
- getVisibleAreaTwips(&visArea);
+ getVisibleAreaTwips(GTK_WIDGET(pDocView), &visArea);
// check vertically
if (nY < visArea.y)
@@ -382,7 +407,8 @@ static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
{
if (g_bToolItemBroadcast)
{
- LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
+ TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
+ LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
const std::string& rString = g_aToolItemCommandNames[pItem];
g_info("toggleToolItem: lok_doc_view_post_command('%s')", rString.c_str());
@@ -390,13 +416,13 @@ static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
}
}
-static void populatePartSelector()
+static void populatePartSelector(LOKDocView* pLOKDocView)
{
gtk_list_store_clear( GTK_LIST_STORE(
gtk_combo_box_get_model(
GTK_COMBO_BOX(pPartSelector) )) );
- if ( !pDocView )
+ if (!pLOKDocView)
{
return;
}
@@ -404,35 +430,35 @@ static void populatePartSelector()
const int nMaxLength = 50;
char sText[nMaxLength];
- int nParts = lok_doc_view_get_parts( LOK_DOC_VIEW(pDocView) );
+ int nParts = lok_doc_view_get_parts(pLOKDocView);
for ( int i = 0; i < nParts; i++ )
{
- char* pName = lok_doc_view_get_part_name( LOK_DOC_VIEW(pDocView), 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( pPartSelector, sText );
}
- gtk_combo_box_set_active( GTK_COMBO_BOX(pPartSelector),
- lok_doc_view_get_part( LOK_DOC_VIEW(pDocView) ) );
+ gtk_combo_box_set_active(GTK_COMBO_BOX(pPartSelector), lok_doc_view_get_part(pLOKDocView));
}
-static void signalSize(LOKDocView* /*pLOKDocView*/, gpointer /*pData*/)
+static void signalSize(LOKDocView* pLOKDocView, gpointer /*pData*/)
{
g_bPartSelectorBroadcast = false;
- populatePartSelector();
+ populatePartSelector(pLOKDocView);
g_bPartSelectorBroadcast = true;
}
static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
{
int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) );
+ TiledWindow& rWindow = lcl_getTiledWindow(pSelector);
- if (g_bPartSelectorBroadcast && pDocView)
+ if (g_bPartSelectorBroadcast && rWindow.m_pDocView)
{
- lok_doc_view_set_part( LOK_DOC_VIEW(pDocView), nPart );
- lok_doc_view_reset_view( LOK_DOC_VIEW(pDocView) );
+ lok_doc_view_set_part( LOK_DOC_VIEW(rWindow.m_pDocView), nPart );
+ lok_doc_view_reset_view( LOK_DOC_VIEW(rWindow.m_pDocView) );
}
}
@@ -454,32 +480,33 @@ static void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ )
// 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 ( pDocView )
+ if ( rWindow.m_pDocView )
{
- lok_doc_view_set_partmode( LOK_DOC_VIEW(pDocView), ePartMode );
+ lok_doc_view_set_partmode( LOK_DOC_VIEW(rWindow.m_pDocView), ePartMode );
}
}
static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpointer /*userdata*/)
{
- LOKDocView* pDocView1 = LOK_DOC_VIEW (source_object);
+ LOKDocView* pDocView = LOK_DOC_VIEW (source_object);
GError* error = NULL;
GList *focusChain = NULL;
- if (!lok_doc_view_open_document_finish(pDocView1, res, &error))
+ if (!lok_doc_view_open_document_finish(pDocView, res, &error))
{
g_warning ("Error occurred while opening the document : %s", error->message);
g_error_free (error);
}
- populatePartSelector();
+ populatePartSelector(pDocView);
populatePartModeSelector( GTK_COMBO_BOX_TEXT(pPartModeComboBox) );
// Connect these signals after populating the selectors, to avoid re-rendering on setting the default part/partmode.
g_signal_connect(G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0);
g_signal_connect(G_OBJECT(pPartSelector), "changed", G_CALLBACK(changePart), 0);
- focusChain = g_list_append( focusChain, pDocView1 );
+ focusChain = g_list_append( focusChain, pDocView );
gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
gtk_widget_hide (pStatusBar);
@@ -640,7 +667,7 @@ int main( int argc, char* argv[] )
gtk_box_pack_end(GTK_BOX(pVBox), pFindbar, FALSE, FALSE, 0);
// Docview
- pDocView = lok_doc_view_new (argv[1], NULL, NULL);
+ GtkWidget* pDocView = lok_doc_view_new (argv[1], NULL, NULL);
#if GLIB_CHECK_VERSION(2,40,0)
g_assert_nonnull(pDocView);
#endif
@@ -675,6 +702,10 @@ int main( int argc, char* argv[] )
// Hide the findbar by default.
gtk_widget_hide(pFindbar);
+ TiledWindow aWindow;
+ aWindow.m_pDocView = pDocView;
+ g_aWindows[pWindow] = aWindow;
+
lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2], NULL, openDocumentCallback, pDocView );
gtk_main();
commit 934336f3730cbc03f2d12ad587d2ca16c6c36cf5
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Sep 15 10:59:58 2015 +0200
gtktiledviewer: these globals can be static
Change-Id: Ife0a4bb1102f6135e297dc69ba5b52b89a5dd9dd
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 6f10935..7637a68 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -38,17 +38,17 @@ static GtkToolItem* pItalic;
static GtkToolItem* pUnderline;
static GtkToolItem* pStrikethrough;
static GtkWidget* pScrolledWindow;
-std::map<GtkToolItem*, std::string> g_aToolItemCommandNames;
-std::map<std::string, GtkToolItem*> g_aCommandNameToolItems;
-bool g_bToolItemBroadcast = true;
+static std::map<GtkToolItem*, std::string> g_aToolItemCommandNames;
+static std::map<std::string, GtkToolItem*> g_aCommandNameToolItems;
+static bool g_bToolItemBroadcast = true;
static GtkWidget* pVBox;
static GtkComboBoxText* pPartSelector;
static GtkWidget* pPartModeComboBox;
/// Should the part selector avoid calling lok::Document::setPart()?
static bool g_bPartSelectorBroadcast = true;
-GtkWidget* pFindbar;
-GtkWidget* pFindbarEntry;
-GtkWidget* pFindbarLabel;
+static GtkWidget* pFindbar;
+static GtkWidget* pFindbarEntry;
+static GtkWidget* pFindbarLabel;
static void lcl_registerToolItem(GtkToolItem* pItem, const std::string& rName)
{
commit 5db5cdc1e4bac75e4690e579f2791f9b83d7c080
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Sep 15 10:31:20 2015 +0200
sfx2: add missing header guard
Change-Id: Ide261670be475f5d54d9d12c701ad82470396aeb
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 9430cd5..b57cb7d 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -7,6 +7,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#ifndef INCLUDED_SFX2_LOKHELPER_HXX
+#define INCLUDED_SFX2_LOKHELPER_HXX
+
#include <sfx2/dllapi.h>
class SfxViewShell;
@@ -23,4 +26,6 @@ public:
static int getViews();
};
+#endif
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list