diff options
author | Caolán McNamara <caolanm@redhat.com> | 2013-07-25 14:47:01 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-07-25 14:50:05 +0100 |
commit | bb98778dbf761a0c88c96117add00a66e5cc6c95 (patch) | |
tree | b55b713b2ee10bffc1df5889cad5974aa87dd7ec | |
parent | Use inconditionally the libwpd >= 0.9.5 path (diff) | |
download | core-bb98778dbf761a0c88c96117add00a66e5cc6c95.tar.gz core-bb98778dbf761a0c88c96117add00a66e5cc6c95.zip |
Resolves: fdo#67113 split insert autotext and field controls
autotext is a modal dialog and insert field is a modeless dialog so I don't
want autotext to show a toggle in insert->autotext
At the same time we want the autotext entry in the insert toolbar to have a
dropdown and we appear to want to be able to close the insert field dialog from
the toolbar.
So split the combined handler class into two and remove the other if/else
branch in each with the insert field a SfxBoolItem and the insert autotext an
SfxVoidItem.
Change-Id: I3d59052ee70a00d63f7706166290b00ad9ae22c0
-rw-r--r-- | sw/source/ui/app/swmodule.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/inc/workctrl.hxx | 25 | ||||
-rw-r--r-- | sw/source/ui/ribbar/workctrl.cxx | 256 |
3 files changed, 186 insertions, 97 deletions
diff --git a/sw/source/ui/app/swmodule.cxx b/sw/source/ui/app/swmodule.cxx index fb53d186b249..b0465ca7672b 100644 --- a/sw/source/ui/app/swmodule.cxx +++ b/sw/source/ui/app/swmodule.cxx @@ -300,7 +300,7 @@ void SwDLL::RegisterControls() SwTbxAnchor::RegisterControl(FN_TOOL_ANCHOR, pMod ); SwTbxInsertCtrl::RegisterControl(FN_INSERT_CTRL, pMod ); SwTbxInsertCtrl::RegisterControl(FN_INSERT_OBJ_CTRL, pMod ); - SwTbxAutoTextCtrl::RegisterControl(FN_INSERT_FIELD_CTRL, pMod ); + SwTbxFieldCtrl::RegisterControl(FN_INSERT_FIELD_CTRL, pMod ); SwTbxAutoTextCtrl::RegisterControl(FN_GLOSSARY_DLG, pMod ); SvxTbxCtlCustomShapes::RegisterControl( SID_DRAWTBX_CS_BASIC, pMod ); diff --git a/sw/source/ui/inc/workctrl.hxx b/sw/source/ui/inc/workctrl.hxx index 8dcd3188233f..1c7b231717fa 100644 --- a/sw/source/ui/inc/workctrl.hxx +++ b/sw/source/ui/inc/workctrl.hxx @@ -95,7 +95,7 @@ public: SFX_DECL_TOOLBOX_CONTROL(); SwTbxAutoTextCtrl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ); - ~SwTbxAutoTextCtrl(); + virtual ~SwTbxAutoTextCtrl(); virtual SfxPopupWindowType GetPopupWindowType() const; virtual SfxPopupWindow* CreatePopupWindow(); @@ -106,6 +106,29 @@ public: DECL_LINK(PopupHdl, PopupMenu*); }; +class SwTbxFieldCtrl : public SfxToolBoxControl +{ + PopupMenu* pPopup; + SwView* pView; + + + void DelPopup(); +public: + SFX_DECL_TOOLBOX_CONTROL(); + + SwTbxFieldCtrl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ); + virtual ~SwTbxFieldCtrl(); + + virtual SfxPopupWindowType GetPopupWindowType() const; + virtual SfxPopupWindow* CreatePopupWindow(); + virtual void StateChanged( sal_uInt16 nSID, + SfxItemState eState, + const SfxPoolItem* pState ); + + DECL_LINK(PopupHdl, PopupMenu*); +}; + + //---------------------------------------------------------------------------- // diff --git a/sw/source/ui/ribbar/workctrl.cxx b/sw/source/ui/ribbar/workctrl.cxx index 384db9907ec5..ccbc2bf11d84 100644 --- a/sw/source/ui/ribbar/workctrl.cxx +++ b/sw/source/ui/ribbar/workctrl.cxx @@ -57,7 +57,8 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::frame; SFX_IMPL_TOOLBOX_CONTROL( SwTbxInsertCtrl, SfxImageItem); -SFX_IMPL_TOOLBOX_CONTROL( SwTbxAutoTextCtrl, SfxBoolItem ); +SFX_IMPL_TOOLBOX_CONTROL( SwTbxAutoTextCtrl, SfxVoidItem ); +SFX_IMPL_TOOLBOX_CONTROL( SwTbxFieldCtrl, SfxBoolItem ); SwTbxInsertCtrl::SwTbxInsertCtrl( sal_uInt16 nSlotId, @@ -187,44 +188,30 @@ SfxPopupWindow* SwTbxAutoTextCtrl::CreatePopupWindow() { Link aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl); - if (GetSlotId() == FN_INSERT_FIELD_CTRL) + pPopup = new PopupMenu; + SwGlossaryList* pGlossaryList = ::GetGlossaryList(); + sal_uInt16 nGroupCount = pGlossaryList->GetGroupCount(); + for(sal_uInt16 i = 1; i <= nGroupCount; i++) { - pPopup = new PopupMenu(SW_RES(RID_INSERT_FIELD_CTRL)); - pPopup->SetSelectHdl(aLnk); - - if (::GetHtmlMode(pView->GetDocShell()) & HTMLMODE_ON) - { - pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_PGCOUNT)); - pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_TOPIC)); - } - } - else - { - pPopup = new PopupMenu; - SwGlossaryList* pGlossaryList = ::GetGlossaryList(); - sal_uInt16 nGroupCount = pGlossaryList->GetGroupCount(); - for(sal_uInt16 i = 1; i <= nGroupCount; i++) + // Acquire group name with path extension + String sTitle; + pGlossaryList->GetGroupName(i - 1, sal_False, &sTitle); + sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1); + if(nBlockCount) { - // Acquire group name with path extension - String sTitle; - pGlossaryList->GetGroupName(i - 1, sal_False, &sTitle); - sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1); - if(nBlockCount) + sal_uInt16 nIndex = 100 * (i); + // but insert without extension + pPopup->InsertItem( i, sTitle); + PopupMenu* pSub = new PopupMenu; + pSub->SetSelectHdl(aLnk); + pPopup->SetPopupMenu(i, pSub); + for(sal_uInt16 j = 0; j < nBlockCount; j++) { - sal_uInt16 nIndex = 100 * (i); - // but insert without extension - pPopup->InsertItem( i, sTitle); - PopupMenu* pSub = new PopupMenu; - pSub->SetSelectHdl(aLnk); - pPopup->SetPopupMenu(i, pSub); - for(sal_uInt16 j = 0; j < nBlockCount; j++) - { - String sEntry; - String sLongName(pGlossaryList->GetBlockName(i - 1, j, sEntry)); - sEntry.AppendAscii(" - "); - sEntry += sLongName; - pSub->InsertItem(++nIndex, sEntry); - } + String sEntry; + String sLongName(pGlossaryList->GetBlockName(i - 1, j, sEntry)); + sEntry.AppendAscii(" - "); + sEntry += sLongName; + pSub->InsertItem(++nIndex, sEntry); } } } @@ -250,91 +237,170 @@ SfxPopupWindowType SwTbxAutoTextCtrl::GetPopupWindowType() const return SFX_POPUPWINDOW_ONTIMEOUT; } -void SwTbxAutoTextCtrl::StateChanged( sal_uInt16 nSID, - SfxItemState eState, +void SwTbxAutoTextCtrl::StateChanged( sal_uInt16, + SfxItemState, const SfxPoolItem* pState ) { GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) ); - if(FN_INSERT_FIELD_CTRL == nSID && eState >= SFX_ITEM_DEFAULT) - { - GetToolBox().CheckItem( GetId(), ((SfxBoolItem*)pState)->GetValue() ); - } } IMPL_LINK(SwTbxAutoTextCtrl, PopupHdl, PopupMenu*, pMenu) { sal_uInt16 nId = pMenu->GetCurItemId(); - if ( GetSlotId() == FN_INSERT_FIELD_CTRL) + sal_uInt16 nBlock = nId / 100; + + SwGlossaryList* pGlossaryList = ::GetGlossaryList(); + String sShortName; + String sGroup = pGlossaryList->GetGroupName(nBlock - 1, false); + pGlossaryList->GetBlockName(nBlock - 1, nId - (100 * nBlock) - 1, sShortName); + + SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl(); + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + OSL_ENSURE(pFact, "Dialogdiet fail!"); + ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc(); + if ( fnSetActGroup ) + (*fnSetActGroup)( sGroup ); + pGlosHdl->SetCurGroup(sGroup, sal_True); + pGlosHdl->InsertGlossary(sShortName); + + return 0; +} + +void SwTbxAutoTextCtrl::DelPopup() +{ + if(pPopup) { - Sequence< PropertyValue > aArgs; - const char* pChar = 0; - switch(nId) + for( sal_uInt16 i = 0; i < pPopup->GetItemCount(); i ++ ) { - case FN_INSERT_FLD_DATE: - pChar = ".uno:InsertDateField"; - break; - case FN_INSERT_FLD_TIME: - pChar = ".uno:InsertTimeField"; - break; - case FN_INSERT_FLD_PGNUMBER: - pChar = ".uno:InsertPageNumberField"; - break; - case FN_INSERT_FLD_PGCOUNT: - pChar = ".uno:InsertPageCountField"; - break; - case FN_INSERT_FLD_TOPIC: - pChar = ".uno:InsertTopicField"; - break; - case FN_INSERT_FLD_TITLE: - pChar = ".uno:InsertTitleField"; - break; - case FN_INSERT_FLD_AUTHOR: - pChar = ".uno:InsertAuthorField"; - break; - default: - pChar = ".uno:InsertFieldCtrl"; + PopupMenu* pSubPopup = pPopup->GetPopupMenu(pPopup->GetItemId(i)); + delete pSubPopup; } - Dispatch( OUString::createFromAscii( pChar ),aArgs ); - } - else - { - sal_uInt16 nBlock = nId / 100; - - SwGlossaryList* pGlossaryList = ::GetGlossaryList(); - String sShortName; - String sGroup = pGlossaryList->GetGroupName(nBlock - 1, false); - pGlossaryList->GetBlockName(nBlock - 1, nId - (100 * nBlock) - 1, sShortName); - - SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl(); - SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - OSL_ENSURE(pFact, "Dialogdiet fail!"); - ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc(); - if ( fnSetActGroup ) - (*fnSetActGroup)( sGroup ); - pGlosHdl->SetCurGroup(sGroup, sal_True); - pGlosHdl->InsertGlossary(sShortName); + delete pPopup; + pPopup = 0; } - return 0; } -void SwTbxAutoTextCtrl::DelPopup() +SwTbxFieldCtrl::SwTbxFieldCtrl( + sal_uInt16 nSlotId, + sal_uInt16 nId, + ToolBox& rTbx ) : + SfxToolBoxControl( nSlotId, nId, rTbx ), + pPopup(0), + pView(0) { - if(pPopup) + rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); +} + +SwTbxFieldCtrl::~SwTbxFieldCtrl() +{ + DelPopup(); +} + +SfxPopupWindow* SwTbxFieldCtrl::CreatePopupWindow() +{ + pView = ::GetActiveView(); + if(pView && !pView->GetDocShell()->IsReadOnly() && + !pView->GetWrtShell().HasReadonlySel() ) { - if (GetSlotId() != FN_INSERT_FIELD_CTRL) + ToolBox& rBox = GetToolBox(); + + Rectangle aItemRect( rBox.GetItemRect( GetId() ) ); + Point aPt(rBox.OutputToScreenPixel(aItemRect.TopLeft())); + aPt.X() += aItemRect.GetWidth()/2; + aPt.Y() += aItemRect.GetHeight()/2; + if(pView) { - for( sal_uInt16 i = 0; i < pPopup->GetItemCount(); i ++ ) + Link aLnk = LINK(this, SwTbxFieldCtrl, PopupHdl); + + pPopup = new PopupMenu(SW_RES(RID_INSERT_FIELD_CTRL)); + pPopup->SetSelectHdl(aLnk); + + if (::GetHtmlMode(pView->GetDocShell()) & HTMLMODE_ON) { - PopupMenu* pSubPopup = pPopup->GetPopupMenu(pPopup->GetItemId(i)); - delete pSubPopup; + pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_PGCOUNT)); + pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_TOPIC)); } } + ToolBox* pToolBox = &GetToolBox(); + sal_uInt16 nId = GetId(); + pToolBox->SetItemDown( nId, sal_True ); + + pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ), + (pToolBox->GetAlign() == WINDOWALIGN_TOP || pToolBox->GetAlign() == WINDOWALIGN_BOTTOM) ? + POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT ); + + pToolBox->SetItemDown( nId, sal_False ); + } + GetToolBox().EndSelection(); + DelPopup(); + return 0; + +} + +SfxPopupWindowType SwTbxFieldCtrl::GetPopupWindowType() const +{ + return SFX_POPUPWINDOW_ONTIMEOUT; +} + +void SwTbxFieldCtrl::StateChanged( sal_uInt16, + SfxItemState eState, + const SfxPoolItem* pState ) +{ + GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) ); + if (eState >= SFX_ITEM_DEFAULT) + { + GetToolBox().CheckItem( GetId(), ((SfxBoolItem*)pState)->GetValue() ); + } +} + +IMPL_LINK(SwTbxFieldCtrl, PopupHdl, PopupMenu*, pMenu) +{ + sal_uInt16 nId = pMenu->GetCurItemId(); + + Sequence< PropertyValue > aArgs; + const char* pChar = 0; + switch(nId) + { + case FN_INSERT_FLD_DATE: + pChar = ".uno:InsertDateField"; + break; + case FN_INSERT_FLD_TIME: + pChar = ".uno:InsertTimeField"; + break; + case FN_INSERT_FLD_PGNUMBER: + pChar = ".uno:InsertPageNumberField"; + break; + case FN_INSERT_FLD_PGCOUNT: + pChar = ".uno:InsertPageCountField"; + break; + case FN_INSERT_FLD_TOPIC: + pChar = ".uno:InsertTopicField"; + break; + case FN_INSERT_FLD_TITLE: + pChar = ".uno:InsertTitleField"; + break; + case FN_INSERT_FLD_AUTHOR: + pChar = ".uno:InsertAuthorField"; + break; + default: + pChar = ".uno:InsertFieldCtrl"; + } + Dispatch( OUString::createFromAscii( pChar ),aArgs ); + + return 0; +} + +void SwTbxFieldCtrl::DelPopup() +{ + if(pPopup) + { delete pPopup; pPopup = 0; } } + // Navigation-Popup // determine the order of the toolbox items static sal_uInt16 aNavigationInsertIds[ NAVI_ENTRIES ] = |