Kaydet (Commit) fc2a0de9 authored tarafından Caolán McNamara's avatar Caolán McNamara

turn the no-space edit widgets into a editwidget feature

especially because most of them don't handle intercepting text getting *pasted*
into them right, so start with the one which does that right.

Change-Id: If6770798872ed3c72c469656ebf0d4fd76d2171d
üst 4e4a350d
......@@ -42,9 +42,6 @@
<glade-widget-class title="Thesaurus Edit" name="cuilo-ReplaceEdit"
generic-name="ReplaceEdit" parent="GtkEntry"
icon-name="widget-gtk-textentry"/>
<glade-widget-class title="TableName Edit" name="swlo-TableNameEdit"
generic-name="TableNameEdit" parent="GtkEntry"
icon-name="widget-gtk-textentry"/>
<glade-widget-class title="Thesaurus Lookup" name="cuilo-LookUpComboBox"
generic-name="LookUpComboBox" parent="GtkEntry"
icon-name="widget-gtk-comboboxtext"/>
......@@ -618,10 +615,6 @@
generic-name="Reference Edit" parent="GtkEntry"
icon-name="widget-gtk-textentry"/>
<glade-widget-class title="NoSpace Edit" name="swlo-NoSpaceEdit"
generic-name="NoSpace Edit" parent="GtkEntry"
icon-name="widget-gtk-textentry"/>
<glade-widget-class title="Another NoSpace Edit" name="cuilo-SvxNoSpaceEdit"
generic-name="Another NoSpace Edit" parent="GtkEntry"
icon-name="widget-gtk-textentry">
......
......@@ -41,24 +41,34 @@ struct Impl_IMEInfos;
// - Edit-Types -
#define EDIT_NOLIMIT SAL_MAX_INT32
#define EDIT_UPDATEDATA_TIMEOUT 350
typedef OUString (*FncGetSpecialChars)( Window* pWin, const Font& rFont );
class VCL_DLLPUBLIC TextFilter
{
private:
OUString sForbiddenChars;
public:
void SetForbiddenChars(const OUString& rSet) { sForbiddenChars = rSet; }
const OUString& GetForbiddenChars() { return sForbiddenChars; }
// - Edit -
virtual OUString filter(const OUString &rText);
TextFilter(const OUString &rForbiddenChars = OUString(" "));
virtual ~TextFilter();
};
enum AutocompleteAction{ AUTOCOMPLETE_KEYINPUT, AUTOCOMPLETE_TABFORWARD, AUTOCOMPLETE_TABBACKWARD };
// - Edit -
class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
{
private:
Edit* mpSubEdit;
Timer* mpUpdateDataTimer;
TextFilter* mpFilterText;
DDInfo* mpDDInfo;
Impl_IMEInfos* mpIMEInfos;
OUStringBuffer maText;
......@@ -116,6 +126,7 @@ private:
SAL_DLLPRIVATE long ImplGetTextYPosition() const;
SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > ImplGetInputSequenceChecker();
SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > ImplGetBreakIterator() const;
SAL_DLLPRIVATE void filterText();
protected:
using Control::ImplInitSettings;
......@@ -252,6 +263,8 @@ public:
virtual Selection GetSurroundingTextSelection() const SAL_OVERRIDE;
virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE;
void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; }
// returns the minimum size a bordered Edit should have given the current
// global style settings (needed by sc's inputwin.cxx)
static Size GetMinimumEditSize();
......
......@@ -116,7 +116,8 @@ struct GroupUserData
class SwNewGlosNameDlg : public ModalDialog
{
Edit* m_pNewName;
NoSpaceEdit* m_pNewShort;
TextFilter m_aNoSpaceFilter;
Edit* m_pNewShort;
OKButton* m_pOk;
Edit* m_pOldName;
Edit* m_pOldShort;
......@@ -142,6 +143,7 @@ SwNewGlosNameDlg::SwNewGlosNameDlg(Window* pParent,
{
get(m_pNewName, "newname");
get(m_pNewShort, "newsc");
m_pNewShort->SetTextFilter(&m_aNoSpaceFilter);
get(m_pOk, "ok");
get(m_pOldName, "oldname");
get(m_pOldShort, "oldsc");
......@@ -185,6 +187,7 @@ SwGlossaryDlg::SwGlossaryDlg(SfxViewFrame* pViewFrame,
get(m_pNameED, "name");
get(m_pShortNameLbl, "shortnameft");
get(m_pShortNameEdit, "shortname");
m_pShortNameEdit->SetTextFilter(&m_aNoSpaceFilter);
get(m_pCategoryBox, "category");
get(m_pFileRelCB, "relfile");
get(m_pNetRelCB, "relnet");
......
......@@ -71,11 +71,13 @@ void SwInsTableDlg::GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rC
SwInsTableDlg::SwInsTableDlg( SwView& rView )
: SfxModalDialog(rView.GetWindow(), "InsertTableDialog", "modules/swriter/ui/inserttable.ui")
, m_aTextFilter(" .<>")
, pShell(&rView.GetWrtShell())
, pTAutoFmt(0)
, nEnteredValRepeatHeaderNF(-1)
{
get(m_pNameEdit, "nameedit");
m_pNameEdit->SetTextFilter(&m_aTextFilter);
get(m_pColNF, "colspin");
get(m_pRowNF, "rowspin");
get(m_pHeaderCB, "headercb");
......
......@@ -63,6 +63,7 @@ using namespace ::com::sun::star;
SwFormatTablePage::SwFormatTablePage(Window* pParent, const SfxItemSet& rSet)
: SfxTabPage(pParent, "FormatTablePage", "modules/swriter/ui/formattablepage.ui", &rSet)
, m_aTextFilter(" .<>")
, pTblData(0)
, nSaveWidth(0)
, nMinTableWidth(MINLAY)
......
......@@ -56,11 +56,11 @@ SwRenameXNamedDlg::SwRenameXNamedDlg( Window* pWin,
uno::Reference< container::XNameAccess > & xNA )
: ModalDialog(pWin, "RenameObjectDialog",
"modules/swriter/ui/renameobjectdialog.ui")
, m_sRemoveWarning(SW_RESSTR(STR_REMOVE_WARNING))
, xNamed(xN)
, xNameAccess(xNA)
{
get(m_pNewNameED, "entry");
m_pNewNameED->SetTextFilter(&m_aTextFilter);
get(m_pOk, "ok");
OUString sTmp(GetText());
......@@ -88,26 +88,10 @@ IMPL_LINK_NOARG(SwRenameXNamedDlg, OkHdl)
return 0;
}
IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, NoSpaceEdit*, pEdit)
IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, Edit*, pEdit)
{
OUString sTmp(pEdit->GetText());
// prevent from pasting illegal characters
const sal_Int32 nLen = sTmp.getLength();
OUString sMsg;
for(sal_Int32 i = 0; i < pEdit->GetForbiddenChars().getLength(); ++i)
{
const sal_Int32 nTmpLen = sTmp.getLength();
sTmp = comphelper::string::remove(sTmp, pEdit->GetForbiddenChars()[i]);
if(sTmp.getLength() != nTmpLen)
sMsg += OUString(pEdit->GetForbiddenChars()[i]);
}
if(sTmp.getLength() != nLen)
{
pEdit->SetText(sTmp);
InfoBox(this, m_sRemoveWarning + sMsg).Execute();
}
m_pOk->Enable(!sTmp.isEmpty()
&& !xNameAccess->hasByName(sTmp)
&& (!xSecondAccess.is() || !xSecondAccess->hasByName(sTmp))
......
......@@ -48,31 +48,6 @@ bool NumEditAction::Notify( NotifyEvent& rNEvt )
return nHandled;
}
NoSpaceEdit::NoSpaceEdit(Window* pParent)
: Edit(pParent, WB_BORDER|WB_TABSTOP)
, sForbiddenChars(OUString(" "))
{
}
void NoSpaceEdit::Modify()
{
Selection aSel = GetSelection();
OUString sTemp = GetText();
for(sal_uInt16 i = 0; i < sForbiddenChars.getLength(); i++)
{
sTemp = comphelper::string::remove(sTemp, sForbiddenChars[i]);
}
sal_Int32 nDiff = GetText().getLength() - sTemp.getLength();
if(nDiff)
{
aSel.setMin(aSel.getMin() - nDiff);
aSel.setMax(aSel.getMin());
SetText(sTemp);
SetSelection(aSel);
}
Edit::Modify();
}
void ReturnActionEdit::KeyInput( const KeyEvent& rEvt)
{
const KeyCode aKeyCode = rEvt.GetKeyCode();
......@@ -87,18 +62,6 @@ void ReturnActionEdit::KeyInput( const KeyEvent& rEvt)
Edit::KeyInput(rEvt);
}
extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeTableNameEdit(Window *pParent, VclBuilder::stringmap &rMap)
{
VclBuilder::ensureDefaultWidthChars(rMap);
return new TableNameEdit(pParent);
}
extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeNoSpaceEdit(Window *pParent, VclBuilder::stringmap &rMap)
{
VclBuilder::ensureDefaultWidthChars(rMap);
return new NoSpaceEdit(pParent);
}
extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeReturnActionEdit(Window *pParent, VclBuilder::stringmap &rMap)
{
VclBuilder::ensureDefaultWidthChars(rMap);
......
......@@ -38,30 +38,6 @@ public:
const Link& GetActionHdl() const { return aActionLink; }
};
// Edit that doesn't accept spaces
class SW_DLLPUBLIC NoSpaceEdit : public Edit
{
OUString sForbiddenChars;
protected:
virtual void Modify() SAL_OVERRIDE;
public:
NoSpaceEdit( Window* pParent );
void SetForbiddenChars(const OUString& rSet){sForbiddenChars = rSet;}
const OUString& GetForbiddenChars(){return sForbiddenChars;}
};
// No space and no full stop
class TableNameEdit : public NoSpaceEdit
{
public:
TableNameEdit(Window* pWin)
: NoSpaceEdit(pWin)
{
SetForbiddenChars(OUString(" .<>"));
}
};
// call a link when KEY_RETURN is pressed
class SW_DLLPUBLIC ReturnActionEdit : public Edit
{
......
......@@ -91,7 +91,8 @@ class SwGlossaryDlg : public SvxStandardDialog
CheckBox* m_pInsertTipCB;
Edit* m_pNameED;
FixedText* m_pShortNameLbl;
NoSpaceEdit* m_pShortNameEdit;
TextFilter m_aNoSpaceFilter;
Edit* m_pShortNameEdit;
SwGlTreeListBox* m_pCategoryBox;
CheckBox* m_pFileRelCB;
CheckBox* m_pNetRelCB;
......
......@@ -34,7 +34,8 @@ struct SwInsertTableOptions;
class SwInsTableDlg : public SfxModalDialog
{
TableNameEdit* m_pNameEdit;
Edit* m_pNameEdit;
TextFilter m_aTextFilter;
NumericField* m_pColNF;
NumericField* m_pRowNF;
......
......@@ -32,10 +32,9 @@
class SwRenameXNamedDlg : public ModalDialog
{
NoSpaceEdit* m_pNewNameED;
OKButton* m_pOk;
OUString m_sRemoveWarning;
Edit* m_pNewNameED;
TextFilter m_aTextFilter;
OKButton* m_pOk;
::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed > & xNamed;
::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > & xNameAccess;
......@@ -43,7 +42,7 @@ class SwRenameXNamedDlg : public ModalDialog
::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xThirdAccess;
DECL_LINK(OkHdl, void *);
DECL_LINK(ModifyHdl, NoSpaceEdit*);
DECL_LINK(ModifyHdl, Edit*);
public:
SwRenameXNamedDlg( Window* pParent,
......@@ -52,7 +51,7 @@ public:
void SetForbiddenChars(const OUString& rSet)
{
m_pNewNameED->SetForbiddenChars(rSet);
m_aTextFilter.SetForbiddenChars(rSet);
}
void SetAlternativeAccess(
......
......@@ -37,7 +37,8 @@ struct TColumn
class SwFormatTablePage : public SfxTabPage
{
TableNameEdit* m_pNameED;
Edit* m_pNameED;
TextFilter m_aTextFilter;
FixedText* m_pWidthFT;
PercentField m_aWidthMF;
CheckBox* m_pRelWidthCB;
......
......@@ -276,7 +276,7 @@
</packing>
</child>
<child>
<object class="swlo-NoSpaceEdit" id="shortname">
<object class="GtkEntry" id="shortname">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
......
......@@ -109,7 +109,7 @@
</packing>
</child>
<child>
<object class="swlo-NoSpaceEdit" id="entry">
<object class="GtkEntry" id="entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
......
......@@ -201,10 +201,9 @@
</packing>
</child>
<child>
<object class="swlo-NoSpaceEdit" id="newsc">
<object class="GtkEntry" id="newsc">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char"></property>
<property name="width_chars">6</property>
<property name="invisible_char_set">True</property>
</object>
......
......@@ -109,7 +109,7 @@
</packing>
</child>
<child>
<object class="swlo-NoSpaceEdit" id="entry">
<object class="GtkEntry" id="entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
......
......@@ -276,6 +276,7 @@ void Edit::ImplInitEditData()
{
mpSubEdit = NULL;
mpUpdateDataTimer = NULL;
mpFilterText = NULL;
mnXOffset = 0;
mnAlign = EDIT_ALIGN_LEFT;
mnMaxTextLen = EDIT_NOLIMIT;
......@@ -2334,8 +2335,48 @@ void Edit::ImplHideDDCursor()
}
}
TextFilter::TextFilter(const OUString &rForbiddenChars)
: sForbiddenChars(rForbiddenChars)
{
}
TextFilter::~TextFilter()
{
}
OUString TextFilter::filter(const OUString &rText)
{
OUString sTemp(rText);
for (sal_uInt16 i = 0; i < sForbiddenChars.getLength(); ++i)
{
sTemp = comphelper::string::remove(sTemp, sForbiddenChars[i]);
}
return sTemp;
}
void Edit::filterText()
{
Selection aSel = GetSelection();
OUString sOrig = GetText();
OUString sNew = mpFilterText->filter(GetText());
if (sOrig != sNew)
{
sal_Int32 nDiff = sOrig.getLength() - sNew.getLength();
if (nDiff)
{
aSel.setMin(aSel.getMin() - nDiff);
aSel.setMax(aSel.getMin());
}
SetText(sNew);
SetSelection(aSel);
}
}
void Edit::Modify()
{
if (mpFilterText)
filterText();
if ( mbIsSubEdit )
{
((Edit*)GetParent())->Modify();
......
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