[Libreoffice-commits] core.git: 2 commits - desktop/source include/LibreOfficeKit include/sfx2 include/svl libreofficekit/qa libreofficekit/source sfx2/sdi svl/source sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu May 28 08:38:04 PDT 2015


 desktop/source/lib/init.cxx                         |    2 +
 include/LibreOfficeKit/LibreOfficeKitGtk.h          |    3 +
 include/sfx2/msg.hxx                                |    2 -
 include/svl/memberid.hrc                            |    2 +
 include/svl/srchitem.hxx                            |    9 +++++
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |   10 +++++-
 libreofficekit/source/gtk/lokdocview.cxx            |    8 +++++
 sfx2/sdi/sfxitems.sdi                               |    2 +
 svl/source/items/srchitem.cxx                       |   32 ++++++++++++++++++--
 sw/source/uibase/uiview/viewsrch.cxx                |   10 ++++++
 10 files changed, 76 insertions(+), 4 deletions(-)

New commits:
commit 3c9fb5898159fbda9d5b23f3f518044a5df03f72
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu May 28 17:21:50 2015 +0200

    gtktiledviewer: use SearchItem.SearchStartPoint*
    
    Change-Id: If0219eda3a2ca3b97c37bea70e35d47e49d38e02

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 320121e..b3e50d3 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -74,6 +74,9 @@ void            lok_docview_post_command    (LOKDocView* pDocView, const char* p
 
 /// Posts a keyboard event to LibreOfficeKit.
 void            lok_docview_post_key    (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData);
+
+/// Get the visible area of the document (in twips).
+void lok_docview_get_visarea(LOKDocView* pThis, GdkRectangle* pArea);
 #ifdef __cplusplus
 }
 #endif
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 5fbd337..d20f43d 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -158,10 +158,18 @@ static void doSearch(bool bBackwards)
     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/value", '/'), pText);
     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_DOCVIEW(pDocView);
+    GdkRectangle aArea;
+    lok_docview_get_visarea(pLOKDocView, &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");
+    aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointY/value", '/'), aArea.y);
+
     std::stringstream aStream;
     boost::property_tree::write_json(aStream, aTree);
 
-    LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
     lok_docview_post_command(pLOKDocView, ".uno:ExecuteSearch", aStream.str().c_str());
 }
 
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index e3c03db..064e534 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1319,4 +1319,12 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_post_key(GtkWidget* /*pWidget*/, GdkEventK
     pDocView->m_pImpl->signalKey(pEvent);
 }
 
+SAL_DLLPUBLIC_EXPORT void lok_docview_get_visarea(LOKDocView* pThis, GdkRectangle* pArea)
+{
+    GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(pThis));
+    pArea->x = pThis->m_pImpl->pixelToTwip(gtk_adjustment_get_value(pHAdjustment));
+    GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(pThis));
+    pArea->y = pThis->m_pImpl->pixelToTwip(gtk_adjustment_get_value(pVAdjustment));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 1dc60bc9e99304c58007bfd5a964ff3f78480106
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu May 28 17:13:38 2015 +0200

    SvxSearchItem: add m_nStartPoint{X,Y}
    
    The idea is that if you have your cursor at the begining of a Writer
    document, and you scroll down a lot, then search, then it's annoying
    that search jumps back to the start of the document for the first hit.
    
    Add an optional way to provide what is the starting point of such a
    search, so we can have "when nothing is selected, then search from the
    top left corner of the visible area".
    
    No UI yet to enable this, but available via the UNO API.
    
    Change-Id: Ibcf3a5f2eeba1372b1dfe8474081e6591a6e0134

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 3ca2744..3993015 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -742,6 +742,8 @@ static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::Propert
                 aValue.Value <<= OUString::fromUtf8(rValue.c_str());
             else if (rType == "boolean")
                 aValue.Value <<= OString(rValue.c_str()).toBoolean();
+            else if (rType == "long")
+                aValue.Value <<= OString(rValue.c_str()).toInt32();
             else
                 SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'");
             aArguments.push_back(aValue);
diff --git a/include/sfx2/msg.hxx b/include/sfx2/msg.hxx
index 58785ff..89faffd 100644
--- a/include/sfx2/msg.hxx
+++ b/include/sfx2/msg.hxx
@@ -155,7 +155,7 @@ SFX_DECL_TYPE(13); // for SwAddPrinterItem, Sd...
 SFX_DECL_TYPE(14);
 SFX_DECL_TYPE(16); // for SwDocDisplayItem
 SFX_DECL_TYPE(17); // for SvxAddressItem
-SFX_DECL_TYPE(18); // for SvxSearchItem
+SFX_DECL_TYPE(20); // for SvxSearchItem
 
 // all SfxTypes must be in this header
 #undef SFX_DECL_TYPE
diff --git a/include/svl/memberid.hrc b/include/svl/memberid.hrc
index ef56395..1593e23 100644
--- a/include/svl/memberid.hrc
+++ b/include/svl/memberid.hrc
@@ -53,6 +53,8 @@
 #define MID_SEARCH_INSERTEDCHARS        17
 #define MID_SEARCH_TRANSLITERATEFLAGS   18
 #define MID_SEARCH_COMMAND              19
+#define MID_SEARCH_STARTPOINTX          20
+#define MID_SEARCH_STARTPOINTY          21
 
 #endif
 
diff --git a/include/svl/srchitem.hxx b/include/svl/srchitem.hxx
index 7ce0f77..9a29858 100644
--- a/include/svl/srchitem.hxx
+++ b/include/svl/srchitem.hxx
@@ -84,6 +84,10 @@ class SVL_DLLPUBLIC SvxSearchItem :
     bool            bContent;           // search in content
     bool            bAsianOptions;      // use asian options?
 
+    // Start search at this point (absolute twips).
+    sal_Int32       m_nStartPointX;
+    sal_Int32       m_nStartPointY;
+
     virtual void    ImplCommit() SAL_OVERRIDE;
 
 public:
@@ -184,6 +188,11 @@ public:
 
     inline  bool            IsUseAsianOptions() const           { return bAsianOptions; }
     inline  void            SetUseAsianOptions( bool bVal ) { bAsianOptions = bVal; }
+
+    sal_Int32 GetStartPointX() const;
+    sal_Int32 GetStartPointY() const;
+    /// Either x or y start point is set.
+    bool HasStartPoint() const;
 };
 
 const OUString SvxSearchItem::GetSearchString() const
diff --git a/sfx2/sdi/sfxitems.sdi b/sfx2/sdi/sfxitems.sdi
index 1d7649e..f293e5c 100644
--- a/sfx2/sdi/sfxitems.sdi
+++ b/sfx2/sdi/sfxitems.sdi
@@ -89,6 +89,8 @@
         INT32       InsertedChars   MID_SEARCH_INSERTEDCHARS;
         INT32       TransliterateFlags MID_SEARCH_TRANSLITERATEFLAGS;
         INT16       Command         MID_SEARCH_COMMAND;
+        INT32       SearchStartPointX MID_SEARCH_STARTPOINTX;
+        INT32       SearchStartPointY MID_SEARCH_STARTPOINTY;
     };
     item SvxSearch SvxSearchItem;
 
diff --git a/svl/source/items/srchitem.cxx b/svl/source/items/srchitem.cxx
index e46d255..986463e 100644
--- a/svl/source/items/srchitem.cxx
+++ b/svl/source/items/srchitem.cxx
@@ -125,7 +125,9 @@ SvxSearchItem::SvxSearchItem( const sal_uInt16 nId ) :
     bBackward       ( false ),
     bPattern        ( false ),
     bContent        ( false ),
-    bAsianOptions   ( false )
+    bAsianOptions   ( false ),
+    m_nStartPointX(0),
+    m_nStartPointY(0)
 {
     EnableNotification( lcl_GetNotifyNames() );
 
@@ -211,7 +213,9 @@ SvxSearchItem::SvxSearchItem( const SvxSearchItem& rItem ) :
     bBackward       ( rItem.bBackward ),
     bPattern        ( rItem.bPattern ),
     bContent        ( rItem.bContent ),
-    bAsianOptions   ( rItem.bAsianOptions )
+    bAsianOptions   ( rItem.bAsianOptions ),
+    m_nStartPointX(rItem.m_nStartPointX),
+    m_nStartPointY(rItem.m_nStartPointY)
 {
     EnableNotification( lcl_GetNotifyNames() );
 }
@@ -604,6 +608,16 @@ bool SvxSearchItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nM
             }
             break;
         }
+        case MID_SEARCH_STARTPOINTX:
+        {
+            bRet = (rVal >>= m_nStartPointX);
+            break;
+        }
+        case MID_SEARCH_STARTPOINTY:
+        {
+            bRet = (rVal >>= m_nStartPointY);
+            break;
+        }
         default:
             OSL_FAIL( "Unknown MemberId" );
     }
@@ -611,5 +625,19 @@ bool SvxSearchItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nM
     return bRet;
 }
 
+sal_Int32 SvxSearchItem::GetStartPointX() const
+{
+    return m_nStartPointX;
+}
+
+sal_Int32 SvxSearchItem::GetStartPointY() const
+{
+    return m_nStartPointY;
+}
+
+bool SvxSearchItem::HasStartPoint() const
+{
+    return m_nStartPointX > 0 || m_nStartPointY > 0;
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx
index 3d3dff1..dbd792b 100644
--- a/sw/source/uibase/uiview/viewsrch.cxx
+++ b/sw/source/uibase/uiview/viewsrch.cxx
@@ -476,6 +476,16 @@ bool SwView::SearchAndWrap(bool bApi)
     // selected regions as the cursor doesn't mark the selection in that case.)
     m_pWrtShell->GetCrsr()->Normalize( m_pSrchItem->GetBackward() );
 
+    if (!m_pWrtShell->HasSelection() && (m_pSrchItem->HasStartPoint()))
+    {
+        // No selection -> but we have a start point (top left corner of the
+        // current view), start searching from there, not from the current
+        // cursor position.
+        SwEditShell& rShell = GetWrtShell();
+        Point aPosition(m_pSrchItem->GetStartPointX(), m_pSrchItem->GetStartPointY());
+        rShell.SetCrsr(aPosition);
+    }
+
         // If you want to search in selected areas, they must not be unselected.
     if (!m_pSrchItem->GetSelection())
         m_pWrtShell->KillSelection(0, false);


More information about the Libreoffice-commits mailing list