diff options
Diffstat (limited to 'sw/source/ui/index/cnttab.cxx')
-rw-r--r-- | sw/source/ui/index/cnttab.cxx | 293 |
1 files changed, 160 insertions, 133 deletions
diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx index 5ae40724d85b..4fc60b300dfb 100644 --- a/sw/source/ui/index/cnttab.cxx +++ b/sw/source/ui/index/cnttab.cxx @@ -111,17 +111,6 @@ static const sal_Unicode aDeliEnd = ']'; //fuer die form #define IDX_FILE_EXTENSION String::CreateFromAscii( \ RTL_CONSTASCII_STRINGPARAM( "*.sdi" )) -static boost::ptr_vector<Control>::iterator FindControl (boost::ptr_vector<Control> &list, Control *ctrl) -{ - for (boost::ptr_vector<Control>::iterator it = list.begin(); it != list.end(); ++it) - { - if ((&(*it)) == ctrl) - return it; - } - - return list.end(); -} - String lcl_CreateAutoMarkFileDlg( const String& rURL, const String& rFileString, sal_Bool bOpen ) { @@ -2879,6 +2868,13 @@ SwTokenWindow::SwTokenWindow(SwTOXEntryTabPage* pParent, const ResId& rResId) : SwTokenWindow::~SwTokenWindow() { + for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it) + { + Control* pControl = (*it); + pControl->SetGetFocusHdl( Link() ); + pControl->SetLoseFocusHdl( Link() ); + delete pControl; + } } void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL) @@ -2886,9 +2882,14 @@ void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL) SetActiveControl(0); bValid = sal_True; - //apply current level settings to the form if(pForm) + { + //apply current level settings to the form + for (ctrl_iterator iter = aControlList.begin(); iter != aControlList.end(); ++iter) + delete (*iter); + aControlList.clear(); + } nLevel = nL; pForm = &rForm; @@ -2986,17 +2987,17 @@ Control* SwTokenWindow::InsertItem(const String& rText, const SwFormToken& rT Point aControlPos; if(!aControlList.empty()) - { - ctrl_const_reverse_iterator iterLast = aControlList.rbegin(); + { + Control* pLast = *(aControlList.rbegin()); - aControlSize = iterLast->GetSizePixel(); - aControlPos = iterLast->GetPosPixel(); + aControlSize = pLast->GetSizePixel(); + aControlPos = pLast->GetPosPixel(); aControlPos.X() += aControlSize.Width(); } if(TOKEN_TEXT == rToken.eTokenType) { - SwTOXEdit *pEdit = new SwTOXEdit(&aCtrlParentWin, this, rToken); + SwTOXEdit* pEdit = new SwTOXEdit(&aCtrlParentWin, this, rToken); pEdit->SetPosPixel(aControlPos); aControlList.push_back(pEdit); @@ -3063,73 +3064,71 @@ void SwTokenWindow::InsertAtSelection( //<insert> LS //<insert> LE //<insert> - bool bPreStartLinkFound = false; - bool bPreEndLinkFound = false; + sal_Bool bPreStartLinkFound = sal_False; + sal_Bool bPreEndLinkFound = sal_False; - const Control *pExchange = 0; - ctrl_const_iterator it = aControlList.begin(); + const Control* pControl = 0; + const Control* pExchange = 0; - while ( it != aControlList.end()) + ctrl_const_iterator it = aControlList.begin(); + for( ; it != aControlList.end() && pActiveCtrl != (*it); ++it ) { - if ((&(*it)) == pActiveCtrl) - break; + pControl = *it; - if( WINDOW_EDIT != it->GetType()) + if( WINDOW_EDIT != pControl->GetType()) { const SwFormToken& rNewToken = - (reinterpret_cast<const SwTOXButton&>(*it)).GetFormToken(); + ((SwTOXButton*)pControl)->GetFormToken(); if( TOKEN_LINK_START == rNewToken.eTokenType ) { - bPreStartLinkFound = true; + bPreStartLinkFound = sal_True; pExchange = 0; } else if(TOKEN_LINK_END == rNewToken.eTokenType) { if( bPreStartLinkFound ) - bPreStartLinkFound = false; + bPreStartLinkFound = sal_False; else { - bPreEndLinkFound = false; - pExchange = const_cast<Control*>(&(*it)); + bPreEndLinkFound = sal_False; + pExchange = pControl; } } } - - ++it; } bool bPostLinkStartFound = false; if(!bPreStartLinkFound && !bPreEndLinkFound) { - while(it != aControlList.end()) + for( ; it != aControlList.end(); ++it ) { - if( (&(*it)) != pActiveCtrl && - WINDOW_EDIT != it->GetType()) + pControl = *it; + + if( pControl != pActiveCtrl && + WINDOW_EDIT != pControl->GetType()) { const SwFormToken& rNewToken = - reinterpret_cast<const SwTOXButton&>(*it).GetFormToken(); + ((SwTOXButton*)pControl)->GetFormToken(); if( TOKEN_LINK_START == rNewToken.eTokenType ) { if(bPostLinkStartFound) break; - bPostLinkStartFound = true; - pExchange = const_cast<Control*>(&(*it)); + bPostLinkStartFound = sal_True; + pExchange = pControl; } else if(TOKEN_LINK_END == rNewToken.eTokenType ) { if(bPostLinkStartFound) { - bPostLinkStartFound = false; + bPostLinkStartFound = sal_False; pExchange = 0; } break; } } - - ++it; } } @@ -3142,7 +3141,6 @@ void SwTokenWindow::InsertAtSelection( if(bPostLinkStartFound) { OSL_ENSURE(pExchange, "no control to exchange?"); - if(pExchange) { ((SwTOXButton*)pExchange)->SetLinkEnd(); @@ -3164,7 +3162,9 @@ void SwTokenWindow::InsertAtSelection( //if the active control is text then insert a new button at the selection //else replace the button - ctrl_iterator iterActive = FindControl(aControlList,pActiveCtrl); + ctrl_iterator iterActive = std::find(aControlList.begin(), + aControlList.end(), pActiveCtrl); + ctrl_iterator iterInsert = iterActive; Size aControlSize(GetOutputSizePixel()); @@ -3187,7 +3187,7 @@ void SwTokenWindow::InsertAtSelection( SwFormToken aTmpToken(TOKEN_TEXT); SwTOXEdit* pEdit = new SwTOXEdit(&aCtrlParentWin, this, aTmpToken); - aControlList.insert(iterInsert,pEdit); + aControlList.insert(iterInsert, pEdit); pEdit->SetText(sRight); pEdit->SetSizePixel(aControlSize); @@ -3199,13 +3199,15 @@ void SwTokenWindow::InsertAtSelection( } else { - pActiveCtrl->Hide(); aControlList.erase(iterActive); + pActiveCtrl->Hide(); + delete pActiveCtrl; } //now the new button SwTOXButton* pButton = new SwTOXButton(&aCtrlParentWin, this, aToInsertToken); - aControlList.insert(iterInsert,pButton); + + aControlList.insert(iterInsert, pButton); pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl)); pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl)); @@ -3237,7 +3239,7 @@ void SwTokenWindow::RemoveControl(SwTOXButton* pDel, sal_Bool bInternalCall ) if(bInternalCall && TOX_AUTHORITIES == pForm->GetTOXType()) m_pParent->PreTokenButtonRemoved(pDel->GetFormToken()); - ctrl_iterator it = FindControl(aControlList,pDel); + ctrl_iterator it = std::find(aControlList.begin(), aControlList.end(), pDel); OSL_ENSURE(it != aControlList.end(), "Control does not exist!"); @@ -3246,22 +3248,26 @@ void SwTokenWindow::RemoveControl(SwTOXButton* pDel, sal_Bool bInternalCall ) OSL_ENSURE(it != aControlList.begin() && it != aControlList.end() - 1, "Button at first or last position?"); - Control *pLeftCtrl = const_cast<Control*>(&(*(it-1))); - Control *pRightCtrl = const_cast<Control*>(&(*(it+1))); + ctrl_iterator itLeft = it, itRight = it; + --itLeft; + ++itRight; + Control *pLeftEdit = *itLeft; + Control *pRightEdit = *itRight; - String sTemp(((SwTOXEdit*)pLeftCtrl)->GetText()); - sTemp += ((SwTOXEdit*)pRightCtrl)->GetText(); - ((SwTOXEdit*)pLeftCtrl)->SetText(sTemp); - ((SwTOXEdit*)pLeftCtrl)->AdjustSize(); + String sTemp(((SwTOXEdit*)pLeftEdit)->GetText()); + sTemp += ((SwTOXEdit*)pRightEdit)->GetText(); + ((SwTOXEdit*)pLeftEdit)->SetText(sTemp); + ((SwTOXEdit*)pLeftEdit)->AdjustSize(); - aControlList.erase(it+1); - aControlList.erase(it); + aControlList.erase(itRight); + delete pRightEdit; + aControlList.erase(it); pActiveCtrl->Hide(); + delete pActiveCtrl; - SetActiveControl(pLeftCtrl); + SetActiveControl(pLeftEdit); AdjustPositions(); - if(aModifyHdl.IsSet()) aModifyHdl.Call(0); } @@ -3271,14 +3277,17 @@ void SwTokenWindow::AdjustPositions() if(aControlList.size() > 1) { ctrl_iterator it = aControlList.begin(); + Control* pCtrl = *it; + ++it; - Point aNextPos = it->GetPosPixel(); - aNextPos.X() += it->GetSizePixel().Width(); + Point aNextPos = pCtrl->GetPosPixel(); + aNextPos.X() += pCtrl->GetSizePixel().Width(); - for (++it; it != aControlList.end(); ++it) - { - it->SetPosPixel(aNextPos); - aNextPos.X() += it->GetSizePixel().Width(); + for(; it != aControlList.end(); ++it) + { + pCtrl = *it; + pCtrl->SetPosPixel(aNextPos); + aNextPos.X() += pCtrl->GetSizePixel().Width(); } AdjustScrolling(); @@ -3290,10 +3299,12 @@ void SwTokenWindow::MoveControls(long nOffset) // move the complete list for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - Point aPos = it->GetPosPixel(); + Control *pCtrl = *it; + + Point aPos = pCtrl->GetPosPixel(); aPos.X() += nOffset; - it->SetPosPixel(aPos); + pCtrl->SetPosPixel(aPos); } } @@ -3302,19 +3313,21 @@ void SwTokenWindow::AdjustScrolling() if(aControlList.size() > 1) { //validate scroll buttons - ctrl_const_reverse_iterator iterLast = aControlList.rbegin(); - ctrl_const_iterator iterFirst = aControlList.begin(); + Control* pFirstCtrl = *(aControlList.begin()); + Control* pLastCtrl = *(aControlList.rbegin()); long nSpace = aCtrlParentWin.GetSizePixel().Width(); - long nWidth = iterLast->GetPosPixel().X() - iterFirst->GetPosPixel().X() - + iterLast->GetSizePixel().Width(); + long nWidth = pLastCtrl->GetPosPixel().X() - pFirstCtrl->GetPosPixel().X() + + pLastCtrl->GetSizePixel().Width(); bool bEnable = nWidth > nSpace; + //the active control must be visible if(bEnable && pActiveCtrl) { - long nMove = 0; Point aActivePos(pActiveCtrl->GetPosPixel()); + long nMove = 0; + if(aActivePos.X() < 0) nMove = -aActivePos.X(); else if((aActivePos.X() + pActiveCtrl->GetSizePixel().Width()) > nSpace) @@ -3323,16 +3336,20 @@ void SwTokenWindow::AdjustScrolling() if(nMove) MoveControls(nMove); - aLeftScrollWin.Enable(iterFirst->GetPosPixel().X() < 0); - aRightScrollWin.Enable((iterLast->GetPosPixel().X() + iterLast->GetSizePixel().Width()) > nSpace); + aLeftScrollWin.Enable(pFirstCtrl->GetPosPixel().X() < 0); + + aRightScrollWin.Enable((pLastCtrl->GetPosPixel().X() + pLastCtrl->GetSizePixel().Width()) > nSpace); } else { - //if the control fits into the space then the first control must be at postion 0 - long nFirstPos = iterFirst->GetPosPixel().X(); + if(pFirstCtrl) + { + //if the control fits into the space then the first control must be at postion 0 + long nFirstPos = pFirstCtrl->GetPosPixel().X(); - if(nFirstPos != 0) - MoveControls(-nFirstPos); + if(nFirstPos != 0) + MoveControls(-nFirstPos); + } aRightScrollWin.Enable(false); aLeftScrollWin.Enable(false); @@ -3346,7 +3363,6 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn ) return 0; const long nSpace = aCtrlParentWin.GetSizePixel().Width(); - #if OSL_DEBUG_LEVEL > 1 //find all start/end positions and print it String sMessage(String::CreateFromAscii("Space: ")); @@ -3355,8 +3371,10 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn ) for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - long nDebugXPos = it->GetPosPixel().X(); - long nDebugWidth = it->GetSizePixel().Width(); + Control *pDebugCtrl = *it; + + long nDebugXPos = pDebugCtrl->GetPosPixel().X(); + long nDebugWidth = pDebugCtrl->GetSizePixel().Width(); sMessage += String::CreateFromInt32( nDebugXPos ); sMessage += String::CreateFromAscii(" "); @@ -3372,11 +3390,13 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn ) //find the first completely visible control (left edge visible) for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - long nXPos = it->GetPosPixel().X(); + Control *pCtrl = *it; + + long nXPos = pCtrl->GetPosPixel().X(); if (nXPos >= 0) { - if(it == aControlList.begin()) + if (it == aControlList.begin()) { //move the current control to the left edge nMove = -nXPos; @@ -3384,8 +3404,11 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn ) else { //move the left neighbor to the start position - ctrl_iterator iterLeft = it-1; - nMove = -iterLeft->GetPosPixel().X(); + ctrl_iterator itLeft = it; + --itLeft; + Control *pLeft = *itLeft; + + nMove = -pLeft->GetPosPixel().X(); } break; @@ -3397,16 +3420,20 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn ) //find the first completely visible control (right edge visible) for (ctrl_reverse_iterator it = aControlList.rbegin(); it != aControlList.rend(); ++it) { - long nCtrlWidth = it->GetSizePixel().Width(); - long nXPos = it->GetPosPixel().X() + nCtrlWidth; + Control *pCtrl = *it; + + long nCtrlWidth = pCtrl->GetSizePixel().Width(); + long nXPos = pCtrl->GetPosPixel().X() + nCtrlWidth; if (nXPos <= nSpace) { if (it != aControlList.rbegin()) { //move the right neighbor to the right edge right aligned - ctrl_reverse_iterator iterRight = it-1; - nMove = nSpace - iterRight->GetPosPixel().X() - iterRight->GetSizePixel().Width(); + ctrl_reverse_iterator itRight = it; + --it; + Control *pRight = *itRight; + nMove = nSpace - pRight->GetPosPixel().X() - pRight->GetSizePixel().Width(); } break; @@ -3419,20 +3446,23 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn ) if(nMove) { // move the complete list + + Control *pCtrl = 0; + for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - Point aPos = it->GetPosPixel(); + pCtrl = *it; + Point aPos = pCtrl->GetPosPixel(); aPos.X() += nMove; - - it->SetPosPixel(aPos); + pCtrl->SetPosPixel(aPos); } - ctrl_iterator iterCtrl = aControlList.begin(); - aLeftScrollWin.Enable(iterCtrl->GetPosPixel().X() < 0); + pCtrl = *(aControlList.begin()); + aLeftScrollWin.Enable(pCtrl->GetPosPixel().X() < 0); - iterCtrl = aControlList.end()-1; - aRightScrollWin.Enable((iterCtrl->GetPosPixel().X() + iterCtrl->GetSizePixel().Width()) > nSpace); + pCtrl = *(aControlList.rbegin()); + aRightScrollWin.Enable((pCtrl->GetPosPixel().X() + pCtrl->GetSizePixel().Width()) > nSpace); #if OSL_DEBUG_LEVEL > 1 sMessage.AppendAscii("Move: "); @@ -3447,14 +3477,14 @@ IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn ) String SwTokenWindow::GetPattern() const { String sRet; - const Control *ctrl = 0; + for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - ctrl = &(*it); + const Control *pCtrl = *it; - const SwFormToken& rNewToken = WINDOW_EDIT == ctrl->GetType() - ? ((SwTOXEdit*)ctrl)->GetFormToken() - : ((SwTOXButton*)ctrl)->GetFormToken(); + const SwFormToken &rNewToken = pCtrl->GetType() == WINDOW_EDIT + ? ((SwTOXEdit*)pCtrl)->GetFormToken() + : ((SwTOXButton*)pCtrl)->GetFormToken(); //TODO: prevent input of TOX_STYLE_DELIMITER in KeyInput sRet += rNewToken.GetString(); @@ -3469,15 +3499,14 @@ String SwTokenWindow::GetPattern() const sal_Bool SwTokenWindow::Contains(FormTokenType eSearchFor) const { bool bRet = false; - const Control* pControl = 0; for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - pControl = &(*it); + const Control *pCtrl = *it; - const SwFormToken& rNewToken = WINDOW_EDIT == pControl->GetType() - ? ((SwTOXEdit*)pControl)->GetFormToken() - : ((SwTOXButton*)pControl)->GetFormToken(); + const SwFormToken &rNewToken = pCtrl->GetType() == WINDOW_EDIT + ? ((SwTOXEdit*)pCtrl)->GetFormToken() + : ((SwTOXButton*)pCtrl)->GetFormToken(); if (eSearchFor == rNewToken.eTokenType) { @@ -3563,24 +3592,22 @@ IMPL_LINK(SwTokenWindow, EditResize, Edit*, pEdit) IMPL_LINK(SwTokenWindow, NextItemHdl, SwTOXEdit*, pEdit) { - ctrl_iterator it = FindControl(aControlList,pEdit); + ctrl_iterator it = std::find(aControlList.begin(),aControlList.end(),pEdit); if (it == aControlList.end()) return 0; - ctrl_iterator lastIter = aControlList.end()-1; + ctrl_iterator itTest = it; + ++itTest; if ((it != aControlList.begin() && !pEdit->IsNextControl()) || - (it != lastIter && pEdit->IsNextControl())) + (itTest != aControlList.end() && pEdit->IsNextControl())) { ctrl_iterator iterFocus = it; - pEdit->IsNextControl() ? ++iterFocus : --iterFocus; - Control *pCtrlFocus = &(*iterFocus); - + Control *pCtrlFocus = *iterFocus; pCtrlFocus->GrabFocus(); - reinterpret_cast<SwTOXButton*>(pCtrlFocus)->Check(); AdjustScrolling(); @@ -3593,7 +3620,7 @@ IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXEdit*, pEdit) { for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - Control *pCtrl = &(*it); + Control *pCtrl = *it; if (pCtrl && pCtrl->GetType() != WINDOW_EDIT) reinterpret_cast<SwTOXButton*>(pCtrl)->Check(false); @@ -3606,31 +3633,29 @@ IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXEdit*, pEdit) IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton*, pBtn ) { - ctrl_iterator iter = FindControl(aControlList,pBtn); + ctrl_iterator it = std::find(aControlList.begin(),aControlList.end(),pBtn); - if (iter == aControlList.end()) + if (it == aControlList.end()) return 0; - ctrl_iterator lastIter = aControlList.end()-1; + ctrl_iterator itTest = it; + ++itTest; - if((iter != aControlList.begin() && !pBtn->IsNextControl()) || - (iter != lastIter && pBtn->IsNextControl())) + if (!pBtn->IsNextControl() || (itTest != aControlList.end() && pBtn->IsNextControl())) { - bool bNext = pBtn->IsNextControl(); - - ctrl_iterator iterFocus = iter; + bool isNext = pBtn->IsNextControl(); - bNext ? ++iterFocus : --iterFocus; - - Control *pCtrlFocus = &(*iterFocus); + ctrl_iterator iterFocus = it; + isNext ? ++iterFocus : --iterFocus; + Control *pCtrlFocus = *iterFocus; pCtrlFocus->GrabFocus(); - Selection aSel(0,0); - if(!bNext) + if (!isNext) { - sal_uInt16 nLen = ((SwTOXEdit*)pCtrlFocus)->GetText().Len(); + sal_uInt16 nLen = reinterpret_cast<SwTOXEdit*>(pCtrlFocus)->GetText().Len(); + aSel.A() = nLen; aSel.B() = nLen; } @@ -3647,10 +3672,9 @@ IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton*, pBtn ) IMPL_LINK(SwTokenWindow, TbxFocusBtnHdl, SwTOXButton*, pBtn ) { - Control *pControl = 0; - for (ctrl_iterator sit = aControlList.begin(); sit != aControlList.end(); ++sit) + for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - pControl = &(*sit); + Control *pControl = *it; if (pControl && WINDOW_EDIT != pControl->GetType()) reinterpret_cast<SwTOXButton*>(pControl)->Check(pBtn == pControl); @@ -3667,11 +3691,14 @@ void SwTokenWindow::GetFocus() { if (!aControlList.empty()) { - Control *pFirst = &(*aControlList.begin()); + Control *pFirst = *aControlList.begin(); - pFirst->GrabFocus(); - SetActiveControl(pFirst); - AdjustScrolling(); + if (pFirst) + { + pFirst->GrabFocus(); + SetActiveControl(pFirst); + AdjustScrolling(); + } } } } |