Kaydet (Commit) a9b266ae authored tarafından Pranav Kant's avatar Pranav Kant Kaydeden (comit) Miklos Vajna

gtktiledviewer: Jump to cursor position when it changes

Change-Id: If50ac0bd21e59b0e0639aa353513451e88ae2a9f
üst 6a03b8ba
...@@ -57,6 +57,25 @@ static void lcl_registerToolItem(GtkToolItem* pItem, const std::string& rName) ...@@ -57,6 +57,25 @@ static void lcl_registerToolItem(GtkToolItem* pItem, const std::string& rName)
const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 }; 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)
{
#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));
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));
#endif
}
static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ ) static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
{ {
const char *sName = gtk_tool_button_get_icon_name( GTK_TOOL_BUTTON(pButton) ); const char *sName = gtk_tool_button_get_icon_name( GTK_TOOL_BUTTON(pButton) );
...@@ -175,23 +194,6 @@ static void doCopy(GtkWidget* /*pButton*/, gpointer /*pItem*/) ...@@ -175,23 +194,6 @@ static void doCopy(GtkWidget* /*pButton*/, gpointer /*pItem*/)
free(pUsedFormat); free(pUsedFormat);
} }
/// Get the visible area of the scrolled window
static void getVisibleAreaTwips(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));
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));
#endif
}
/// Searches for the next or previous text of pFindbarEntry. /// Searches for the next or previous text of pFindbarEntry.
static void doSearch(bool bBackwards) static void doSearch(bool bBackwards)
...@@ -319,6 +321,54 @@ static void signalHyperlink(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointe ...@@ -319,6 +321,54 @@ static void signalHyperlink(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointe
} }
} }
/// Cursor position changed
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));
GdkRectangle visArea;
gdouble upper;
gint x = -1, y = -1;
getVisibleAreaTwips(&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));
}
static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/) static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
{ {
if (g_bToolItemBroadcast) if (g_bToolItemBroadcast)
...@@ -576,6 +626,7 @@ int main( int argc, char* argv[] ) ...@@ -576,6 +626,7 @@ int main( int argc, char* argv[] )
g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL); g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
g_signal_connect(pDocView, "size-changed", G_CALLBACK(signalSize), NULL); g_signal_connect(pDocView, "size-changed", G_CALLBACK(signalSize), NULL);
g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL); g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
g_signal_connect(pDocView, "cursor-changed", G_CALLBACK(cursorChanged), NULL);
// Scrolled window for DocView // Scrolled window for DocView
......
...@@ -117,6 +117,7 @@ enum ...@@ -117,6 +117,7 @@ enum
PART_CHANGED, PART_CHANGED,
SIZE_CHANGED, SIZE_CHANGED,
HYPERLINK_CLICKED, HYPERLINK_CLICKED,
CURSOR_CHANGED,
LAST_SIGNAL LAST_SIGNAL
}; };
...@@ -518,6 +519,11 @@ callback (gpointer pData) ...@@ -518,6 +519,11 @@ callback (gpointer pData)
{ {
priv->m_aVisibleCursor = payloadToRectangle(pDocView, pCallback->m_aPayload.c_str()); priv->m_aVisibleCursor = payloadToRectangle(pDocView, pCallback->m_aPayload.c_str());
priv->m_bCursorOverlayVisible = true; priv->m_bCursorOverlayVisible = true;
g_signal_emit(pDocView, doc_view_signals[CURSOR_CHANGED], 0,
priv->m_aVisibleCursor.x,
priv->m_aVisibleCursor.y,
priv->m_aVisibleCursor.width,
priv->m_aVisibleCursor.height);
gtk_widget_queue_draw(GTK_WIDGET(pDocView)); gtk_widget_queue_draw(GTK_WIDGET(pDocView));
} }
break; break;
...@@ -1743,6 +1749,25 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) ...@@ -1743,6 +1749,25 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
g_cclosure_marshal_VOID__STRING, g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_STRING); G_TYPE_STRING);
/**
* LOKDocView::cursor-changed:
* @pDocView: the #LOKDocView on which the signal is emitted
* @nX: The new cursor position (X coordinate) in pixels
* @nY: The new cursor position (Y coordinate) in pixels
* @nWidth: The width of new cursor
* @nHeight: The height of new cursor
*/
doc_view_signals[CURSOR_CHANGED] =
g_signal_new("cursor-changed",
G_TYPE_FROM_CLASS(pGObjectClass),
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 4,
G_TYPE_INT, G_TYPE_INT,
G_TYPE_INT, G_TYPE_INT);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment