sync master with lastest vba changes
[ooovba.git] / sc / source / ui / miscdlgs / anyrefdg.cxx
blob6d3a7b9fc4e11508e1115d2e21e4886b2161572c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: anyrefdg.cxx,v $
10 * $Revision: 1.21.30.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //----------------------------------------------------------------------------
38 #include "rangelst.hxx"
39 #include <sfx2/app.hxx>
40 #include <sfx2/viewsh.hxx>
41 #include <vcl/wrkwin.hxx>
42 #include <vcl/mnemonic.hxx>
43 #include <tools/shl.hxx>
44 #include <svtools/taskbar.hxx>
45 #include <sfx2/topfrm.hxx>
46 #include <sfx2/bindings.hxx>
47 #include <sfx2/dispatch.hxx>
50 #define ANYREFDG_CXX
51 #include "anyrefdg.hxx"
52 #undef ANYREFDG_CXX
54 #include "sc.hrc"
55 #include "inputhdl.hxx"
56 #include "scmod.hxx"
57 #include "scresid.hxx"
58 #include "inputwin.hxx"
59 #include "tabvwsh.hxx"
60 #include "docsh.hxx"
61 #include "rfindlst.hxx"
62 #include "compiler.hxx"
63 #include "cell.hxx"
64 #include "global.hxx"
65 #include "inputopt.hxx"
66 #include "rangeutl.hxx"
69 ScFormulaReferenceHelper::ScFormulaReferenceHelper(IAnyRefDialog* _pDlg,SfxBindings* _pBindings)
70 : m_pDlg(_pDlg)
71 , pRefEdit (NULL)
72 , m_pWindow(NULL)
73 , m_pBindings(_pBindings)
74 , pAccel( NULL )
75 , pHiddenMarks(NULL)
76 , nRefTab(0)
77 , bHighLightRef( FALSE )
78 , bAccInserted( FALSE )
80 ScInputOptions aInputOption=SC_MOD()->GetInputOptions();
81 bEnableColorRef=aInputOption.GetRangeFinder();
83 // -----------------------------------------------------------------------------
84 ScFormulaReferenceHelper::~ScFormulaReferenceHelper()
86 if (bAccInserted)
87 Application::RemoveAccel( pAccel.get() );
89 // common cleanup for ScAnyRefDlg and ScFormulaDlg is done here
91 HideReference();
92 enableInput( TRUE );
94 ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl();
95 if ( pInputHdl )
96 pInputHdl->ResetDelayTimer(); // stop the timer for disabling the input line
98 // -----------------------------------------------------------------------------
99 void ScFormulaReferenceHelper::enableInput( BOOL bEnable )
101 TypeId aType(TYPE(ScDocShell));
102 ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
103 while( pDocShell )
105 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
106 while( pFrame )
108 // #71577# enable everything except InPlace, including bean frames
109 if ( !pFrame->GetFrame()->IsInPlace() )
111 SfxViewShell* p = pFrame->GetViewShell();
112 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
113 if(pViewSh!=NULL)
115 Window *pWin=pViewSh->GetWindow();
116 if(pWin)
118 Window *pParent=pWin->GetParent();
119 if(pParent)
121 pParent->EnableInput(bEnable,TRUE /* FALSE */);
122 if(TRUE /*bChilds*/)
123 pViewSh->EnableRefInput(bEnable);
128 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
131 pDocShell = (ScDocShell*)SfxObjectShell::GetNext(*pDocShell, &aType);
134 // -----------------------------------------------------------------------------
135 void ScFormulaReferenceHelper::ShowSimpleReference( const XubString& rStr )
137 if( /*!pRefEdit &&*/ bEnableColorRef )
139 bHighLightRef=TRUE;
140 ScViewData* pViewData=ScDocShell::GetViewData();
141 if ( pViewData )
143 ScDocument* pDoc=pViewData->GetDocument();
144 ScTabViewShell* pTabViewShell=pViewData->GetViewShell();
146 ScRangeList aRangeList;
148 pTabViewShell->DoneRefMode( FALSE );
149 pTabViewShell->ClearHighlightRanges();
151 if( ParseWithNames( aRangeList, rStr, pDoc ) )
153 ScRange* pRangeEntry = aRangeList.First();
155 USHORT nIndex=0;
156 while(pRangeEntry != NULL)
158 ColorData aColName = ScRangeFindList::GetColorName(nIndex++);
159 pTabViewShell->AddHighlightRange(*pRangeEntry, aColName);
161 pRangeEntry = aRangeList.Next();
167 // -----------------------------------------------------------------------------
168 bool ScFormulaReferenceHelper::ParseWithNames( ScRangeList& rRanges, const String& rStr, ScDocument* pDoc )
170 bool bError = false;
171 rRanges.RemoveAll();
173 ScAddress::Details aDetails(pDoc->GetAddressConvention(), 0, 0);
174 ScRangeUtil aRangeUtil;
175 xub_StrLen nTokenCnt = rStr.GetTokenCount();
176 for( xub_StrLen nToken = 0; nToken < nTokenCnt; ++nToken )
178 ScRange aRange;
179 String aRangeStr( rStr.GetToken( nToken ) );
181 USHORT nFlags = aRange.ParseAny( aRangeStr, pDoc, aDetails );
182 if ( nFlags & SCA_VALID )
184 if ( (nFlags & SCA_TAB_3D) == 0 )
185 aRange.aStart.SetTab( nRefTab );
186 if ( (nFlags & SCA_TAB2_3D) == 0 )
187 aRange.aEnd.SetTab( aRange.aStart.Tab() );
188 rRanges.Append( aRange );
190 else if ( aRangeUtil.MakeRangeFromName( aRangeStr, pDoc, nRefTab, aRange, RUTL_NAMES, aDetails ) )
191 rRanges.Append( aRange );
192 else
193 bError = true;
196 return !bError;
198 // -----------------------------------------------------------------------------
199 void ScFormulaReferenceHelper::ShowFormulaReference( const XubString& rStr )
201 if( /*!pRefEdit &&*/ bEnableColorRef)
203 bHighLightRef=TRUE;
204 ScViewData* pViewData=ScDocShell::GetViewData();
205 if ( pViewData && pRefComp.get() )
207 ScTabViewShell* pTabViewShell=pViewData->GetViewShell();
208 SCCOL nCol = pViewData->GetCurX();
209 SCROW nRow = pViewData->GetCurY();
210 SCTAB nTab = pViewData->GetTabNo();
211 ScAddress aPos( nCol, nRow, nTab );
213 ScTokenArray* pScTokA=pRefComp->CompileString(rStr);
214 //pRefComp->CompileTokenArray();
216 if(pTabViewShell!=NULL && pScTokA!=NULL)
218 pTabViewShell->DoneRefMode( FALSE );
219 pTabViewShell->ClearHighlightRanges();
221 pScTokA->Reset();
222 const ScToken* pToken = static_cast<const ScToken*>(pScTokA->GetNextReference());
224 USHORT nIndex=0;
226 while(pToken!=NULL)
228 BOOL bDoubleRef=(pToken->GetType()==formula::svDoubleRef);
231 if(pToken->GetType()==formula::svSingleRef || bDoubleRef)
233 ScRange aRange;
234 if(bDoubleRef)
236 ScComplexRefData aRef( pToken->GetDoubleRef() );
237 aRef.CalcAbsIfRel( aPos );
238 aRange.aStart.Set( aRef.Ref1.nCol, aRef.Ref1.nRow, aRef.Ref1.nTab );
239 aRange.aEnd.Set( aRef.Ref2.nCol, aRef.Ref2.nRow, aRef.Ref2.nTab );
241 else
243 ScSingleRefData aRef( pToken->GetSingleRef() );
244 aRef.CalcAbsIfRel( aPos );
245 aRange.aStart.Set( aRef.nCol, aRef.nRow, aRef.nTab );
246 aRange.aEnd = aRange.aStart;
248 ColorData aColName=ScRangeFindList::GetColorName(nIndex++);
249 pTabViewShell->AddHighlightRange(aRange, aColName);
252 pToken = static_cast<const ScToken*>(pScTokA->GetNextReference());
255 if(pScTokA!=NULL) delete pScTokA;
259 // -----------------------------------------------------------------------------
260 void ScFormulaReferenceHelper::HideReference( BOOL bDoneRefMode )
262 ScViewData* pViewData=ScDocShell::GetViewData();
264 if( pViewData && /*!pRefEdit &&*/ bHighLightRef && bEnableColorRef)
266 ScTabViewShell* pTabViewShell=pViewData->GetViewShell();
268 if(pTabViewShell!=NULL)
270 // bDoneRefMode is FALSE when called from before SetReference.
271 // In that case, RefMode was just started and must not be ended now.
273 if ( bDoneRefMode )
274 pTabViewShell->DoneRefMode( FALSE );
275 pTabViewShell->ClearHighlightRanges();
277 bHighLightRef=FALSE;
280 // -----------------------------------------------------------------------------
281 void ScFormulaReferenceHelper::ShowReference( const XubString& rStr )
283 if( /*!pRefEdit &&*/ bEnableColorRef )
285 if( rStr.Search('(')!=STRING_NOTFOUND ||
286 rStr.Search('+')!=STRING_NOTFOUND ||
287 rStr.Search('*')!=STRING_NOTFOUND ||
288 rStr.Search('-')!=STRING_NOTFOUND ||
289 rStr.Search('/')!=STRING_NOTFOUND ||
290 rStr.Search('&')!=STRING_NOTFOUND ||
291 rStr.Search('<')!=STRING_NOTFOUND ||
292 rStr.Search('>')!=STRING_NOTFOUND ||
293 rStr.Search('=')!=STRING_NOTFOUND ||
294 rStr.Search('^')!=STRING_NOTFOUND)
296 ShowFormulaReference(rStr);
298 else
300 ShowSimpleReference(rStr);
304 // -----------------------------------------------------------------------------
305 void ScFormulaReferenceHelper::ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton )
307 if( !pRefEdit && pEdit )
309 m_pDlg->RefInputStart( pEdit, pButton );
310 // if( pRefEdit )
311 // pRefEdit->SilentGrabFocus();
314 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
315 if( pViewShell )
317 pViewShell->ActiveGrabFocus();
318 if( pRefEdit )
320 const ScViewData* pViewData = pViewShell->GetViewData();
321 ScDocument* pDoc = pViewData->GetDocument();
322 ScRangeList aRangeList;
323 if( ParseWithNames( aRangeList, pRefEdit->GetText(), pDoc ) )
325 const ScRange* pRange = aRangeList.GetObject( 0 );
326 if( pRange )
328 pViewShell->SetTabNo( pRange->aStart.Tab() );
329 pViewShell->MoveCursorAbs( pRange->aStart.Col(),
330 pRange->aStart.Row(), SC_FOLLOW_JUMP, FALSE, FALSE );
331 pViewShell->MoveCursorAbs( pRange->aEnd.Col(),
332 pRange->aEnd.Row(), SC_FOLLOW_JUMP, TRUE, FALSE );
333 m_pDlg->SetReference( *pRange, pDoc );
339 // -----------------------------------------------------------------------------
340 void ScFormulaReferenceHelper::Init()
342 ScViewData* pViewData=ScDocShell::GetViewData(); //! use pScViewShell?
343 if ( pViewData )
345 ScDocument* pDoc = pViewData->GetDocument();
346 SCCOL nCol = pViewData->GetCurX();
347 SCROW nRow = pViewData->GetCurY();
348 SCTAB nTab = pViewData->GetTabNo();
349 ScAddress aCursorPos( nCol, nRow, nTab );
351 String rStrExp;
352 pRefCell.reset( new ScFormulaCell( pDoc, aCursorPos, rStrExp ) );
353 pRefComp.reset( new ScCompiler( pDoc, aCursorPos) );
354 pRefComp->SetGrammar( pDoc->GetGrammar() );
355 pRefComp->SetCompileForFAP(TRUE);
357 nRefTab = nTab;
358 } // if ( pViewData )
360 // -----------------------------------------------------------------------------
361 IMPL_LINK( ScFormulaReferenceHelper, AccelSelectHdl, Accelerator *, pSelAccel )
363 if ( !pSelAccel )
364 return 0;
366 switch ( pSelAccel->GetCurKeyCode().GetCode() )
368 case KEY_RETURN:
369 case KEY_ESCAPE:
370 if( pRefEdit )
371 pRefEdit->GrabFocus();
372 m_pDlg->RefInputDone( TRUE );
373 break;
375 return TRUE;
377 //----------------------------------------------------------------------------
378 void ScFormulaReferenceHelper::RefInputDone( BOOL bForced )
380 if (pRefEdit && (bForced || !pRefBtn))
382 if (bAccInserted) // Accelerator wieder abschalten
384 Application::RemoveAccel( pAccel.get() );
385 bAccInserted = FALSE;
388 // Fenstertitel anpassen
389 m_pWindow->SetText(sOldDialogText);
391 // Fenster wieder gross
392 m_pWindow->SetOutputSizePixel(aOldDialogSize);
394 // pEditCell an alte Position
395 pRefEdit->SetPosSizePixel(aOldEditPos, aOldEditSize);
397 // set button position and image
398 if( pRefBtn )
400 pRefBtn->SetPosPixel( aOldButtonPos );
401 pRefBtn->SetStartImage();
404 // Alle anderen: Show();
405 USHORT nChildren = m_pWindow->GetChildCount();
406 for ( USHORT i = 0; i < nChildren; i++ )
407 if (pHiddenMarks[i])
409 m_pWindow->GetChild(i)->GetWindow( WINDOW_CLIENT )->Show();
411 delete [] pHiddenMarks;
413 pRefEdit = NULL;
414 pRefBtn = NULL;
417 // -----------------------------------------------------------------------------
418 void ScFormulaReferenceHelper::RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton )
420 if (!pRefEdit)
422 pRefEdit = pEdit;
423 pRefBtn = pButton;
425 // Neuen Fenstertitel basteln
426 String sNewDialogText;
427 sOldDialogText = m_pWindow->GetText();
428 sNewDialogText = sOldDialogText;
429 sNewDialogText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
431 // Alle Elemente ausser EditCell und Button verstecken
432 USHORT nChildren = m_pWindow->GetChildCount();
433 pHiddenMarks = new BOOL [nChildren];
434 for (USHORT i = 0; i < nChildren; i++)
436 pHiddenMarks[i] = FALSE;
437 Window* pWin = m_pWindow->GetChild(i);
438 pWin = pWin->GetWindow( WINDOW_CLIENT );
439 if (pWin == (Window*)pRefEdit)
441 sNewDialogText += m_pWindow->GetChild(i-1)->GetWindow( WINDOW_CLIENT )->GetText();
443 else if (pWin == (Window*)pRefBtn)
444 ; // do nothing
445 else if (pWin->IsVisible())
447 pHiddenMarks[i] = TRUE;
448 pWin->Hide();
452 // Alte Daten merken
453 aOldDialogSize = m_pWindow->GetOutputSizePixel();
454 aOldEditPos = pRefEdit->GetPosPixel();
455 aOldEditSize = pRefEdit->GetSizePixel();
456 if (pRefBtn)
457 aOldButtonPos = pRefBtn->GetPosPixel();
459 // Edit-Feld verschieben und anpassen
460 Size aNewDlgSize(aOldDialogSize.Width(), aOldEditSize.Height());
461 Size aNewEditSize(aNewDlgSize);
462 long nOffset = 0;
463 if (pRefBtn)
465 aNewEditSize.Width() -= pRefBtn->GetSizePixel().Width();
466 aNewEditSize.Width() -= aOldButtonPos.X() - (aOldEditPos.X()+aOldEditSize.Width());
468 long nHeight = pRefBtn->GetSizePixel().Height();
469 if ( nHeight > aOldEditSize.Height() )
471 aNewDlgSize.Height() = nHeight;
472 nOffset = (nHeight-aOldEditSize.Height()) / 2;
474 aNewEditSize.Width() -= nOffset;
476 pRefEdit->SetPosSizePixel(Point(nOffset, nOffset), aNewEditSize);
478 // set button position and image
479 if( pRefBtn )
481 pRefBtn->SetPosPixel( Point( aOldDialogSize.Width() - pRefBtn->GetSizePixel().Width(), 0 ) );
482 pRefBtn->SetEndImage();
485 // Fenster verkleinern
486 m_pWindow->SetOutputSizePixel(aNewDlgSize);
488 // Fenstertitel anpassen
489 m_pWindow->SetText( MnemonicGenerator::EraseAllMnemonicChars( sNewDialogText ) );
491 // if ( pButton ) // ueber den Button: Enter und Escape abfangen
492 // {
493 if (!pAccel.get())
495 pAccel.reset( new Accelerator );
496 pAccel->InsertItem( 1, KeyCode( KEY_RETURN ) );
497 pAccel->InsertItem( 2, KeyCode( KEY_ESCAPE ) );
498 pAccel->SetSelectHdl( LINK( this, ScFormulaReferenceHelper, AccelSelectHdl ) );
500 Application::InsertAccel( pAccel.get() );
501 bAccInserted = TRUE;
502 // }
505 // -----------------------------------------------------------------------------
506 void ScFormulaReferenceHelper::ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton )
508 if( pEdit )
510 if( pRefEdit == pEdit ) // is this the active ref edit field?
512 pRefEdit->GrabFocus(); // before RefInputDone()
513 m_pDlg->RefInputDone( TRUE ); // finish ref input
515 else
517 m_pDlg->RefInputDone( TRUE ); // another active ref edit?
518 m_pDlg->RefInputStart( pEdit, pButton ); // start ref input
519 // pRefEdit might differ from pEdit after RefInputStart() (i.e. ScFormulaDlg)
520 if( pRefEdit )
521 pRefEdit->GrabFocus();
525 // -----------------------------------------------------------------------------
526 BOOL ScFormulaReferenceHelper::DoClose( USHORT nId )
528 SfxApplication* pSfxApp = SFX_APP();
530 SetDispatcherLock( FALSE ); //! here and in dtor ?
532 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
533 if ( pViewFrm && pViewFrm->HasChildWindow(FID_INPUTLINE_STATUS) )
535 // Die Eingabezeile wird per ToolBox::Disable disabled, muss darum auch
536 // per ToolBox::Enable wieder aktiviert werden (vor dem Enable des AppWindow),
537 // damit die Buttons auch wieder enabled gezeichnet werden.
538 SfxChildWindow* pChild = pViewFrm->GetChildWindow(FID_INPUTLINE_STATUS);
539 if (pChild)
541 ScInputWindow* pWin = (ScInputWindow*)pChild->GetWindow();
542 pWin->Enable();
546 // find parent view frame to close dialog
547 SfxViewFrame* pMyViewFrm = NULL;
548 if ( m_pBindings )
550 SfxDispatcher* pMyDisp = m_pBindings->GetDispatcher();
551 if (pMyDisp)
552 pMyViewFrm = pMyDisp->GetFrame();
554 SC_MOD()->SetRefDialog( nId, FALSE, pMyViewFrm );
556 pSfxApp->Broadcast( SfxSimpleHint( FID_KILLEDITVIEW ) );
558 ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
559 if ( pScViewShell )
560 pScViewShell->UpdateInputHandler(TRUE);
562 return TRUE;
564 void ScFormulaReferenceHelper::SetDispatcherLock( BOOL bLock )
566 // lock / unlock only the dispatchers of Calc documents
568 TypeId aType(TYPE(ScDocShell));
569 ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
570 while( pDocShell )
572 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
573 while( pFrame )
575 SfxDispatcher* pDisp = pFrame->GetDispatcher();
576 if (pDisp)
577 pDisp->Lock( bLock );
579 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
581 pDocShell = (ScDocShell*)SfxObjectShell::GetNext(*pDocShell, &aType);
584 // if a new view is created while the dialog is open,
585 // that view's dispatcher is locked when trying to create the dialog
586 // for that view (ScTabViewShell::CreateRefDialog)
588 // -----------------------------------------------------------------------------
589 void ScFormulaReferenceHelper::ViewShellChanged(ScTabViewShell* /* pScViewShell */)
591 enableInput( FALSE );
593 EnableSpreadsheets();
595 void ScFormulaReferenceHelper::EnableSpreadsheets(BOOL bFlag, BOOL bChilds)
597 TypeId aType(TYPE(ScDocShell));
598 ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
599 while( pDocShell )
601 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
602 while( pFrame )
604 // #71577# enable everything except InPlace, including bean frames
605 if ( !pFrame->GetFrame()->IsInPlace() )
607 SfxViewShell* p = pFrame->GetViewShell();
608 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
609 if(pViewSh!=NULL)
611 Window *pWin=pViewSh->GetWindow();
612 if(pWin)
614 Window *pParent=pWin->GetParent();
615 if(pParent)
617 pParent->EnableInput(bFlag,FALSE);
618 if(bChilds)
619 pViewSh->EnableRefInput(bFlag);
624 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
627 pDocShell = (ScDocShell*)SfxObjectShell::GetNext(*pDocShell, &aType);
631 //----------------------------------------------------------------------------
635 void lcl_InvalidateWindows()
637 TypeId aType(TYPE(ScDocShell));
638 ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
639 while( pDocShell )
641 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
642 while( pFrame )
644 // #71577# enable everything except InPlace, including bean frames
645 if ( !pFrame->GetFrame()->IsInPlace() )
647 SfxViewShell* p = pFrame->GetViewShell();
648 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
649 if(pViewSh!=NULL)
651 Window *pWin=pViewSh->GetWindow();
652 if(pWin)
654 Window *pParent=pWin->GetParent();
655 if(pParent)
656 pParent->Invalidate();
660 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
663 pDocShell = (ScDocShell*)SfxObjectShell::GetNext(*pDocShell, &aType);
666 //----------------------------------------------------------------------------
668 void lcl_HideAllReferences()
670 TypeId aScType = TYPE(ScTabViewShell);
671 SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
672 while ( pSh )
674 ((ScTabViewShell*)pSh)->ClearHighlightRanges();
675 pSh = SfxViewShell::GetNext( *pSh, &aScType );
679 //============================================================================
680 // class ScAnyRefDlg
681 //----------------------------------------------------------------------------
683 ScAnyRefDlg::ScAnyRefDlg( SfxBindings* pB, SfxChildWindow* pCW,
684 Window* pParent, USHORT nResId)
685 : SfxModelessDialog ( pB, pCW, pParent, ScResId( nResId ) ),
686 m_aHelper(this,pB),
687 pMyBindings( pB ),
688 pActiveWin(NULL)
690 m_aHelper.SetWindow(this);
691 if(GetHelpId()==0) //Hack, da im SfxModelessDialog die HelpId
692 SetHelpId(GetUniqueId()); //fuer einen ModelessDialog entfernt und
693 //in eine UniqueId gewandelt wird, machen
694 //wir das an dieser Stelle rueckgaengig.
695 aTimer.SetTimeout(200);
696 aTimer.SetTimeoutHdl(LINK( this, ScAnyRefDlg, UpdateFocusHdl));
698 SC_MOD()->InputEnterHandler();
699 // ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
701 ScTabViewShell* pScViewShell = NULL;
703 // title has to be from the view that opened the dialog,
704 // even if it's not the current view
706 SfxObjectShell* pParentDoc = NULL;
707 if ( pMyBindings )
709 SfxDispatcher* pMyDisp = pMyBindings->GetDispatcher();
710 if (pMyDisp)
712 SfxViewFrame* pMyViewFrm = pMyDisp->GetFrame();
713 if (pMyViewFrm)
715 pScViewShell = PTR_CAST( ScTabViewShell, pMyViewFrm->GetViewShell() );
716 if( pScViewShell )
717 pScViewShell->UpdateInputHandler(TRUE);
718 pParentDoc = pMyViewFrm->GetObjectShell();
722 if ( !pParentDoc && pScViewShell ) // use current only if above fails
723 pParentDoc = pScViewShell->GetObjectShell();
724 if ( pParentDoc )
725 aDocName = pParentDoc->GetTitle();
727 ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl(pScViewShell);
729 DBG_ASSERT( pInputHdl, "Missing input handler :-/" );
731 if ( pInputHdl )
732 pInputHdl->NotifyChange( NULL );
734 m_aHelper.enableInput( FALSE );
736 m_aHelper.EnableSpreadsheets();
738 m_aHelper.Init();
740 m_aHelper.SetDispatcherLock( TRUE );
741 //@Test
742 //SFX_APPWINDOW->Disable(TRUE); //@BugID 54702
745 //----------------------------------------------------------------------------
747 ScAnyRefDlg::~ScAnyRefDlg()
749 lcl_HideAllReferences();
751 SetModalInputMode(FALSE);
752 SetDispatcherLock( FALSE ); //! here and in DoClose ?
754 ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
755 if( pScViewShell )
756 pScViewShell->UpdateInputHandler(TRUE);
758 //SFX_APPWINDOW->Enable(TRUE,TRUE);
759 lcl_InvalidateWindows();
762 //----------------------------------------------------------------------------
764 SfxBindings& ScAnyRefDlg::GetBindings()
766 //! SfxModelessDialog should allow access to pBindings pointer
768 return *pMyBindings;
771 //----------------------------------------------------------------------------
773 void ScAnyRefDlg::SwitchToDocument()
775 ScTabViewShell* pCurrent = ScTabViewShell::GetActiveViewShell();
776 if (pCurrent)
778 SfxObjectShell* pObjSh = pCurrent->GetObjectShell();
779 if ( pObjSh && pObjSh->GetTitle() == aDocName )
781 // right document already visible -> nothing to do
782 return;
786 TypeId aScType = TYPE(ScTabViewShell);
787 SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
788 while ( pSh )
790 SfxObjectShell* pObjSh = pSh->GetObjectShell();
791 if ( pObjSh && pObjSh->GetTitle() == aDocName )
793 // switch to first TabViewShell for document
794 ((ScTabViewShell*)pSh)->SetActive();
795 return;
797 pSh = SfxViewShell::GetNext( *pSh, &aScType );
801 //----------------------------------------------------------------------------
803 BOOL ScAnyRefDlg::IsDocAllowed(SfxObjectShell* pDocSh) const // pDocSh may be 0
805 // default: allow only same document (overridden in function dialog)
806 String aCmpName;
807 if ( pDocSh )
808 aCmpName = pDocSh->GetTitle();
810 // if aDocName isn't initialized, allow
811 return ( aDocName.Len() == 0 || aDocName == aCmpName );
814 //----------------------------------------------------------------------------
816 BOOL __EXPORT ScAnyRefDlg::IsRefInputMode() const
818 return IsVisible(); // nur wer sichtbar ist kann auch Referenzen bekommen
821 //----------------------------------------------------------------------------
823 BOOL __EXPORT ScAnyRefDlg::DoClose( USHORT nId )
825 m_aHelper.DoClose(nId);
826 return TRUE;
829 void ScAnyRefDlg::EnableSpreadsheets(BOOL bFlag, BOOL bChilds)
831 m_aHelper.EnableSpreadsheets(bFlag, bChilds);
834 void ScAnyRefDlg::SetDispatcherLock( BOOL bLock )
836 m_aHelper.SetDispatcherLock( bLock );
839 //----------------------------------------------------------------------------
841 void ScAnyRefDlg::ViewShellChanged(ScTabViewShell* pScViewShell )
843 m_aHelper.ViewShellChanged(pScViewShell);
846 //----------------------------------------------------------------------------
848 void ScAnyRefDlg::AddRefEntry()
850 // wenn nicht ueberladen, gibt es keine Mehrfach-Referenzen
853 //----------------------------------------------------------------------------
855 BOOL __EXPORT ScAnyRefDlg::IsTableLocked() const
857 // per Default kann bei Referenzeingabe auch die Tabelle umgeschaltet werden
859 return FALSE;
862 //----------------------------------------------------------------------------
864 // RefInputStart/Done: Zoom-In (AutoHide) auf einzelnes Feld
865 // (per Button oder Bewegung)
867 //----------------------------------------------------------------------------
869 void ScAnyRefDlg::RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton )
871 m_aHelper.RefInputStart( pEdit, pButton );
875 void ScAnyRefDlg::ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton )
877 m_aHelper.ToggleCollapsed( pEdit, pButton );
879 long ScAnyRefDlg::PreNotify( NotifyEvent& rNEvt )
881 USHORT nSwitch=rNEvt.GetType();
882 if(nSwitch==EVENT_GETFOCUS)
884 pActiveWin=rNEvt.GetWindow();
886 return SfxModelessDialog::PreNotify(rNEvt);
889 void ScAnyRefDlg::StateChanged( StateChangedType nStateChange )
891 SfxModelessDialog::StateChanged( nStateChange );
893 if(nStateChange == STATE_CHANGE_VISIBLE)
895 if(IsVisible())
897 m_aHelper.enableInput( FALSE );
898 m_aHelper.EnableSpreadsheets();
899 m_aHelper.SetDispatcherLock( TRUE );
900 aTimer.Start();
902 else
904 m_aHelper.enableInput( TRUE );
905 m_aHelper.SetDispatcherLock( FALSE ); //! here and in DoClose ?
910 IMPL_LINK( ScAnyRefDlg, UpdateFocusHdl, Timer*, EMPTYARG )
912 if (pActiveWin)
914 pActiveWin->GrabFocus();
916 return 0;
918 // -----------------------------------------------------------------------------
919 bool ScAnyRefDlg::ParseWithNames( ScRangeList& rRanges, const String& rStr, ScDocument* pDoc )
921 return m_aHelper.ParseWithNames( rRanges, rStr, pDoc );
923 // -----------------------------------------------------------------------------
924 void ScAnyRefDlg::HideReference( BOOL bDoneRefMode )
926 m_aHelper.HideReference( bDoneRefMode );
928 // -----------------------------------------------------------------------------
929 void ScAnyRefDlg::ShowReference( const XubString& rStr )
931 m_aHelper.ShowReference( rStr );
933 // -----------------------------------------------------------------------------
934 void ScAnyRefDlg::ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton )
936 m_aHelper.ReleaseFocus( pEdit,pButton );
938 //----------------------------------------------------------------------------
939 void ScAnyRefDlg::RefInputDone( BOOL bForced )
941 m_aHelper.RefInputDone( bForced );