Kaydet (Commit) 6bccdf23 authored tarafından Miklos Vajna's avatar Miklos Vajna

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
(cherry picked from commit 1dc60bc9)
üst 7a3d25c5
...@@ -742,6 +742,8 @@ static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::Propert ...@@ -742,6 +742,8 @@ static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::Propert
aValue.Value <<= OUString::fromUtf8(rValue.c_str()); aValue.Value <<= OUString::fromUtf8(rValue.c_str());
else if (rType == "boolean") else if (rType == "boolean")
aValue.Value <<= OString(rValue.c_str()).toBoolean(); aValue.Value <<= OString(rValue.c_str()).toBoolean();
else if (rType == "long")
aValue.Value <<= OString(rValue.c_str()).toInt32();
else else
SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'"); SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'");
aArguments.push_back(aValue); aArguments.push_back(aValue);
......
...@@ -155,7 +155,7 @@ SFX_DECL_TYPE(13); // for SwAddPrinterItem, Sd... ...@@ -155,7 +155,7 @@ SFX_DECL_TYPE(13); // for SwAddPrinterItem, Sd...
SFX_DECL_TYPE(14); SFX_DECL_TYPE(14);
SFX_DECL_TYPE(16); // for SwDocDisplayItem SFX_DECL_TYPE(16); // for SwDocDisplayItem
SFX_DECL_TYPE(17); // for SvxAddressItem 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 // all SfxTypes must be in this header
#undef SFX_DECL_TYPE #undef SFX_DECL_TYPE
......
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
#define MID_SEARCH_INSERTEDCHARS 17 #define MID_SEARCH_INSERTEDCHARS 17
#define MID_SEARCH_TRANSLITERATEFLAGS 18 #define MID_SEARCH_TRANSLITERATEFLAGS 18
#define MID_SEARCH_COMMAND 19 #define MID_SEARCH_COMMAND 19
#define MID_SEARCH_STARTPOINTX 20
#define MID_SEARCH_STARTPOINTY 21
#endif #endif
......
...@@ -84,6 +84,10 @@ class SVL_DLLPUBLIC SvxSearchItem : ...@@ -84,6 +84,10 @@ class SVL_DLLPUBLIC SvxSearchItem :
bool bContent; // search in content bool bContent; // search in content
bool bAsianOptions; // use asian options? 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; virtual void ImplCommit() SAL_OVERRIDE;
public: public:
...@@ -184,6 +188,11 @@ public: ...@@ -184,6 +188,11 @@ public:
inline bool IsUseAsianOptions() const { return bAsianOptions; } inline bool IsUseAsianOptions() const { return bAsianOptions; }
inline void SetUseAsianOptions( bool bVal ) { bAsianOptions = bVal; } 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 const OUString SvxSearchItem::GetSearchString() const
......
...@@ -89,6 +89,8 @@ ...@@ -89,6 +89,8 @@
INT32 InsertedChars MID_SEARCH_INSERTEDCHARS; INT32 InsertedChars MID_SEARCH_INSERTEDCHARS;
INT32 TransliterateFlags MID_SEARCH_TRANSLITERATEFLAGS; INT32 TransliterateFlags MID_SEARCH_TRANSLITERATEFLAGS;
INT16 Command MID_SEARCH_COMMAND; INT16 Command MID_SEARCH_COMMAND;
INT32 SearchStartPointX MID_SEARCH_STARTPOINTX;
INT32 SearchStartPointY MID_SEARCH_STARTPOINTY;
}; };
item SvxSearch SvxSearchItem; item SvxSearch SvxSearchItem;
......
...@@ -125,7 +125,9 @@ SvxSearchItem::SvxSearchItem( const sal_uInt16 nId ) : ...@@ -125,7 +125,9 @@ SvxSearchItem::SvxSearchItem( const sal_uInt16 nId ) :
bBackward ( false ), bBackward ( false ),
bPattern ( false ), bPattern ( false ),
bContent ( false ), bContent ( false ),
bAsianOptions ( false ) bAsianOptions ( false ),
m_nStartPointX(0),
m_nStartPointY(0)
{ {
EnableNotification( lcl_GetNotifyNames() ); EnableNotification( lcl_GetNotifyNames() );
...@@ -211,7 +213,9 @@ SvxSearchItem::SvxSearchItem( const SvxSearchItem& rItem ) : ...@@ -211,7 +213,9 @@ SvxSearchItem::SvxSearchItem( const SvxSearchItem& rItem ) :
bBackward ( rItem.bBackward ), bBackward ( rItem.bBackward ),
bPattern ( rItem.bPattern ), bPattern ( rItem.bPattern ),
bContent ( rItem.bContent ), bContent ( rItem.bContent ),
bAsianOptions ( rItem.bAsianOptions ) bAsianOptions ( rItem.bAsianOptions ),
m_nStartPointX(rItem.m_nStartPointX),
m_nStartPointY(rItem.m_nStartPointY)
{ {
EnableNotification( lcl_GetNotifyNames() ); EnableNotification( lcl_GetNotifyNames() );
} }
...@@ -604,6 +608,16 @@ bool SvxSearchItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nM ...@@ -604,6 +608,16 @@ bool SvxSearchItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nM
} }
break; break;
} }
case MID_SEARCH_STARTPOINTX:
{
bRet = (rVal >>= m_nStartPointX);
break;
}
case MID_SEARCH_STARTPOINTY:
{
bRet = (rVal >>= m_nStartPointY);
break;
}
default: default:
OSL_FAIL( "Unknown MemberId" ); OSL_FAIL( "Unknown MemberId" );
} }
...@@ -611,5 +625,19 @@ bool SvxSearchItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nM ...@@ -611,5 +625,19 @@ bool SvxSearchItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nM
return bRet; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -476,6 +476,16 @@ bool SwView::SearchAndWrap(bool bApi) ...@@ -476,6 +476,16 @@ bool SwView::SearchAndWrap(bool bApi)
// selected regions as the cursor doesn't mark the selection in that case.) // selected regions as the cursor doesn't mark the selection in that case.)
m_pWrtShell->GetCrsr()->Normalize( m_pSrchItem->GetBackward() ); 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 you want to search in selected areas, they must not be unselected.
if (!m_pSrchItem->GetSelection()) if (!m_pSrchItem->GetSelection())
m_pWrtShell->KillSelection(0, false); m_pWrtShell->KillSelection(0, false);
......
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