Bump version to 5.0-14
[LibreOffice.git] / sc / workben / test.cxx
blobf6b32ad1f5e3023142b88c618ab05201502a8726
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/libcall.hxx>
21 #include <vcl/msgbox.hxx>
22 #include <vcl/window.hxx>
23 #include <vcl/button.hxx>
24 #include <vcl/field.hxx>
25 #include <vcl/fixed.hxx>
26 #include <vcl/help.hxx>
27 #include <usr/conver.hxx>
28 #include <usr/uno.hxx>
29 #include <usr/refl.hxx>
30 #include <stardiv/one/frame/xcollect.hxx>
31 #include <stardiv/one/text/offfield.hxx>
32 #include <stardiv/one/offmisc.hxx>
33 #include <stardiv/one/sheet/offtable.hxx>
34 #include <stardiv/one/text/offtext.hxx>
35 #include <stardiv/one/offstyle.hxx>
36 #include <stardiv/one/offview.hxx>
37 #include <stardiv/uno/repos/serinfo.hxx>
38 #include <stardiv/one/sheet/sctypes.hxx>
39 #include <stardiv/one/sheet/scmodel.hxx>
40 #include <stardiv/one/sheet/sccells.hxx>
41 #include <stardiv/one/sheet/sctables.hxx>
42 #include <stardiv/one/sheet/sctable.hxx>
43 #include <stardiv/one/sheet/sccell.hxx>
44 #include <stardiv/one/sheet/scpostit.hxx>
45 #include <stardiv/one/sheet/scview.hxx>
46 #include <stardiv/one/sheet/scdata.hxx>
47 #include <stardiv/one/sheet/scattr.hxx>
49 //! das muss als Konstante in irgendeine idl-Datei!!!!
50 #define TEXTCONTROLCHAR_PARAGRAPH_BREAK 0
52 class MyFixedText : public FixedText
54 protected:
55 void RequestHelp( const HelpEvent& rHEvt );
56 public:
57 MyFixedText(vcl::Window* pParent) : FixedText(pParent) {}
60 class MyWindow : public vcl::Window
62 private:
63 NumericField aCountField;
64 PushButton aCountButton;
65 MyFixedText aTimeText;
66 NumericField aColField;
67 NumericField aRowField;
68 NumericField aPosField;
69 NumericField aLenField;
70 Edit aTextEdit;
71 PushButton aTextButton;
72 PushButton aBlaButton;
73 PushButton aTabButton;
74 PushButton aViewButton;
76 public:
77 MyWindow( vcl::Window *pParent );
79 DECL_LINK(CountHdl, PushButton*);
80 DECL_LINK(TextHdl, PushButton*);
81 DECL_LINK(BlaHdl, PushButton*);
82 DECL_LINK(TabHdl, PushButton*);
83 DECL_LINK(ViewHdl, PushButton*);
86 class ScTestListener : public XSelectionChangeListener, public UsrObject
88 private:
89 FixedText* pFixedText;
91 public:
92 ScTestListener(FixedText* pF);
93 virtual ~ScTestListener();
95 SMART_UNO_DECLARATION( ScTestListener, UsrObject );
97 virtual XInterface * queryInterface( UsrUik );
98 virtual XIdlClassRef getIdlClass();
100 virtual void disposing(const EventObject& Source);
102 // XSelectionChangeListener
103 virtual void selectionChanged(const EventObject& aEvent);
106 static long nBla = 0;
108 static XCellRef xGlobalCell;
110 ScTestListener::ScTestListener(FixedText* pF) :
111 pFixedText( pF )
115 ScTestListener::~ScTestListener()
119 XInterface* ScTestListener::queryInterface( UsrUik aUIK )
121 if ( aUIK == XSelectionChangeListener::getSmartUik() )
122 return (XSelectionChangeListener*) this;
124 return UsrObject::queryInterface( aUIK );
127 XIdlClassRef ScTestListener::getIdlClass()
129 static XIdlClassRef xClass = createStandardClass( L"ScTestListener",
130 UsrObject::getUsrObjectIdlClass(),
131 1, XSelectionChangeListener_getReflection() );
132 return xClass;
135 void ScTestListener::disposing(const EventObject& Source)
139 // XSelectionChangeListener
141 void ScTestListener::selectionChanged(const EventObject& aEvent)
143 static sal_uInt16 nBla = 0;
144 pFixedText->SetText(++nBla);
146 XInterfaceRef xInt = aEvent.Source;
147 if (!xInt) return;
148 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
149 if (!xView) return;
150 XInterfaceRef xSelInt = xView->getSelection();
151 if (!xSelInt) return;
152 XCellCollectionRef xCells = (XCellCollection*)
153 xSelInt->queryInterface(XCellCollection::getSmartUik());
154 if (!xCells) return;
156 String aStr = OUStringToString( xCells->getAddress(), CHARSET_SYSTEM );
157 pFixedText->SetText(aStr);
160 extern "C" vcl::Window* SAL_CALL CreateWindow( vcl::Window *pParent, const String& rParam )
162 MyWindow *pWin = new MyWindow( pParent );
163 return pWin;
166 void MyFixedText::RequestHelp( const HelpEvent& rHEvt )
168 String aTxtStr=GetText();
169 Size aTxtSize=GetTextSize(aTxtStr);
170 Point aShowPoint= OutputToScreenPixel(Point(0,0));
171 if ( ( rHEvt.GetMode() & HELPMODE_QUICK ) == HELPMODE_QUICK &&
172 aTxtSize.Width()>GetSizePixel().Width())
173 Help::ShowQuickHelp( Rectangle(aShowPoint,aTxtSize), aTxtStr, QuickHelpFlags::Top|QuickHelpFlags::Left );
174 else
175 FixedText::RequestHelp( rHEvt );
178 MyWindow::MyWindow( vcl::Window *pParent ) :
179 Window( pParent ),
180 aCountField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
181 aCountButton( this ),
182 aTimeText( this ),
183 aColField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
184 aRowField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
185 aPosField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
186 aLenField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
187 aTextEdit( this, WinBits(WB_BORDER) ),
188 aTextButton( this ),
189 aBlaButton( this ),
190 aTabButton( this ),
191 aViewButton( this )
193 aCountField.SetPosSizePixel( Point(10,10), Size(40,20) );
194 aCountField.SetValue(1);
196 aCountButton.SetPosSizePixel( Point(10,40), Size(100,30) );
197 aCountButton.SetText("hochzaehlen");
199 aTimeText.SetPosSizePixel( Point(10,80), Size(100,20) );
201 aColField.SetPosSizePixel( Point(10,120), Size(40,20) );
202 aRowField.SetPosSizePixel( Point(60,120), Size(40,20) );
203 aPosField.SetPosSizePixel( Point(10,150), Size(40,20) );
204 aLenField.SetPosSizePixel( Point(60,150), Size(40,20) );
205 aTextEdit.SetPosSizePixel( Point(10,180), Size(100,20) );
207 aTextButton.SetPosSizePixel( Point(10,210), Size(100,30) );
208 aTextButton.SetText("col/row/pos/len");
210 aBlaButton.SetPosSizePixel( Point(10,260), Size(100,30) );
211 aBlaButton.SetText("Bla");
213 aTabButton.SetPosSizePixel( Point(10,310), Size(100,30) );
214 aTabButton.SetText("Tabellen");
216 aViewButton.SetPosSizePixel( Point(10,360), Size(100,30) );
217 aViewButton.SetText("Pfui");
219 aCountButton.SetClickHdl(LINK(this, MyWindow, CountHdl));
220 aTextButton.SetClickHdl(LINK(this, MyWindow, TextHdl));
221 aBlaButton.SetClickHdl(LINK(this, MyWindow, BlaHdl));
222 aTabButton.SetClickHdl(LINK(this, MyWindow, TabHdl));
223 aViewButton.SetClickHdl(LINK(this, MyWindow, ViewHdl));
225 aCountField.Show();
226 aCountButton.Show();
227 aTimeText.Show();
228 aColField.Show();
229 aRowField.Show();
230 aPosField.Show();
231 aLenField.Show();
232 aTextEdit.Show();
233 aTextButton.Show();
234 aBlaButton.Show();
235 aTabButton.Show();
236 aViewButton.Show();
239 XSpreadsheetDocumentRef lcl_GetDocument()
241 XServiceManagerRef xProv = getGlobalServiceManager();
242 OSL_ENSURE( xProv.is(), "Kein ServiceManager!" );
244 XServiceRegistryRef xReg = (XServiceRegistry*)xProv->queryInterface(XServiceRegistry::getSmartUik());
245 if ( !xReg )
246 return NULL;
248 Sequence<Uik> aIfaces( 1 );
249 aIfaces.getArray()[0] = XModelCollection::getSmartUik();
250 XServiceProviderRef xSSI = xProv->getServiceProvider( L"stardiv.desktop.ModelCollection",
251 aIfaces, Sequence<Uik>() );
253 XModelCollectionRef aCollRef = (XModelCollection*)
254 xSSI->newInstance()->queryInterface( XModelCollection::getSmartUik() );
255 sal_uInt16 nCount = aCollRef->getCount();
257 XSpreadsheetDocumentRef xModel; // Calc-Model
258 for (sal_uInt16 nMod=0; nMod<nCount && !xModel; nMod++) // Calc-Doc suchen
260 XModelRef aRef = aCollRef->getItemByIndex( nMod );
261 if ( aRef )
263 aRef->acquire();
264 xModel = (XSpreadsheetDocument*) aRef->queryInterface( XSpreadsheetDocument::getSmartUik() );
265 aRef->release();
268 return xModel;
271 XInterfaceRef lcl_GetView()
273 XInterfaceRef xView;
274 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
275 if (xDoc)
276 xView = xDoc->getDDELinks(); //! temporaer zum Testen !!!!!!!!!
278 return xView;
281 void lcl_OutputNames( const XInterfaceRef& xSource, // XNameAccess
282 const XSpreadsheetDocumentRef& xDoc,
283 sal_uInt16 nCol, sal_uInt16 nRow, sal_uInt16 nTab )
285 CellAddress aAdr;
286 aAdr.Sheet = nTab;
287 aAdr.Column = nCol;
288 aAdr.Row = nRow;
290 XNameAccessRef xNames = (XNameAccess*)xSource->queryInterface(XNameAccess::getSmartUik());
291 if (!xNames) return;
292 Sequence<UString> aSeq = xNames->getElementNames();
294 sal_uInt16 nLen = (sal_uInt16)aSeq.getLen();
296 XCellRef xCell = xDoc->getCell(aAdr);
297 if (!xCell) return;
298 xCell->setValue( nLen );
299 ++aAdr.Row;
301 UString* pAry = aSeq.getArray();
302 for (sal_uInt16 i=0; i<nLen; i++)
304 xCell = xDoc->getCell(aAdr);
305 if (!xCell) return;
306 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
307 if (!xText) return;
308 xText->setText( pAry[i] );
309 ++aAdr.Row;
313 void lcl_SetText( const XTextRef& xText )
315 if (!xText.is()) return;
316 XTextCursorRef xCursor = xText->createTextCursor();
317 if (!xCursor.is()) return;
318 XTextPositionRef xPos = (XTextPosition*)xCursor->queryInterface(XTextPosition::getSmartUik());
319 XPropertySetRef xProp = (XPropertySet*)xCursor->queryInterface(XPropertySet::getSmartUik());
320 XControlCharacterInsertableRef xControl = (XControlCharacterInsertable*)
321 xCursor->queryInterface(XControlCharacterInsertable::getSmartUik());
322 XParagraphCursorRef xPara = (XParagraphCursor*)
323 xCursor->queryInterface(XParagraphCursor::getSmartUik());
325 if (!xPos.is() || !xControl.is() || !xPara.is()) return; // PropertySet kann fehlen
327 xText->setText(L"bla fasel");
328 xCursor->gotoEnd(false);
329 xControl->insertControlCharacter( TEXTCONTROLCHAR_PARAGRAPH_BREAK );
330 xPos->collapseToEnd();
331 xPos->setText(L"s\xFClz"); // zweiter Absatz
333 xCursor->gotoStart(false);
334 xPara->gotoEndOfParagraph(false);
335 xCursor->goLeft(5, true); // letzte 5 Zeichen im 1. Absatz
336 if (xProp.is())
337 xProp->setPropertyValue(L"Bold", UsrAny((sal_Bool)true));
340 void lcl_DoCount()
342 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
343 if (xDoc)
345 XActionLockableRef xLock = (XActionLockable*)
346 xDoc->queryInterface(XActionLockable::getSmartUik());
347 XCalculateRef xCalc = (XCalculate*)
348 xDoc->queryInterface(XCalculate::getSmartUik());
349 if (xLock)
350 xLock->addActionLock(); // nicht zwischendurch painten
351 if (xCalc)
352 xCalc->setAutomaticCalculation(false);
354 CellAddress aPos;
355 aPos.Sheet = 0;
357 for (sal_uInt16 nRow = 0; nRow < 20; nRow++)
359 aPos.Row = nRow;
360 for (sal_uInt16 nCol = 0; nCol < 10; nCol++)
362 aPos.Column = nCol;
363 XCellRef xCell = xDoc->getCell(aPos);
364 if ( xCell )
366 // Wert der Zelle um 1 hochzaehlen
368 double fVal = xCell->getValue();
369 fVal += 1.0;
370 xCell->setValue( fVal );
375 if (xCalc)
376 xCalc->setAutomaticCalculation(true);
377 if (xLock)
378 xLock->removeActionLock();
382 void lcl_GlobalCell()
384 if ( xGlobalCell )
386 String aStr = OUStringToString( xGlobalCell->getFormula(), CHARSET_SYSTEM );
387 aStr+='0';
388 xGlobalCell->setFormula( StringToOUString( aStr, CHARSET_SYSTEM ) );
392 void lcl_Annotations( FixedText& aTimeText )
394 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
395 if (xDoc)
397 CellAddress aPos;
398 aPos.Sheet = 0;
399 aPos.Column = 1;
400 aPos.Row = 2;
401 XCellRef xCell = xDoc->getCell(aPos);
402 if ( xCell )
404 XSheetAnnotationAnchorRef xAnchor =
405 (XSheetAnnotationAnchor*)xCell->queryInterface(XSheetAnnotationAnchor::getSmartUik());
406 if ( xAnchor )
408 XSheetAnnotationRef xAnnotation = xAnchor->getAnnotation();
409 if ( xAnnotation )
411 String aBlubb = OUStringToString( xAnnotation->getAuthor(), CHARSET_SYSTEM )+
412 String(" - ")+
413 OUStringToString( xAnnotation->getDate(), CHARSET_SYSTEM );
414 aTimeText.SetText(aBlubb);
416 XTextRef xAnnotationText =
417 (XText*)xAnnotation->queryInterface(XText::getSmartUik());
418 if ( xAnnotationText )
420 XTextCursorRef xCursor = xAnnotationText->createTextCursor();
421 if (xCursor)
423 XTextPositionRef xPos = (XTextPosition*)
424 xCursor->queryInterface(XTextPosition::getSmartUik());
425 XControlCharacterInsertableRef xControl = (XControlCharacterInsertable*)
426 xCursor->queryInterface(XControlCharacterInsertable::getSmartUik());
428 if (xPos && xControl)
430 sal_uInt64 nStart = tools::Time::GetSystemTicks();
432 xAnnotationText->setText(L"bla");
433 xCursor->gotoEnd(false);
434 xCursor->goLeft(1,true);
435 xPos->setText(L"ubb");
436 for (sal_uInt16 i=0; i<10; i++)
438 xPos->collapseToEnd();
439 xControl->insertControlCharacter( TEXTCONTROLCHAR_PARAGRAPH_BREAK );
440 xPos->collapseToEnd();
441 xPos->setText(L"dumdi");
444 sal_uInt64 nEnd = tools::Time::GetSystemTicks();
445 aTimeText.SetText(String(nEnd-nStart)+String(" ms"));
455 void lcl_Cursor( FixedText& aTimeText )
457 aTimeText.SetText( "..." );
458 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
459 if (xDoc)
461 XActionLockableRef xLock = (XActionLockable*)
462 xDoc->queryInterface(XActionLockable::getSmartUik());
463 if (xLock)
464 xLock->addActionLock();
466 CellAddress aPos;
467 aPos.Sheet = 0;
468 aPos.Column = 1;
469 aPos.Row = 2;
470 XCellRef xCell = xDoc->getCell(aPos);
471 if ( xCell )
473 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
474 XCellCollectionRef xColl = (XCellCollection*)xCell->queryInterface(XCellCollection::getSmartUik());
475 if ( xText && xColl )
477 xText->setText(L"bla");
478 XLineCursorRef xCursor = xColl->createCursor();
479 if ( xCursor )
481 XCellCursorRef xCC = (XCellCursor*)xCursor->queryInterface(XCellCursor::getSmartUik());
482 XCellRangesCursorRef xRC = (XCellRangesCursor*)
483 xCursor->queryInterface(XCellRangesCursor::getSmartUik());
485 if ( xCC && xRC )
487 xCursor->goDown( 1, false );
489 xColl = xCC->getRanges();
490 if ( xColl )
492 // XText ist drin, wenn's ne einzelne Zelle ist
493 xText = (XText*)xColl->queryInterface(XText::getSmartUik());
494 if ( xText )
496 xText->setText(L"fasel");
500 CellRangeAddress aSecond;
501 aSecond.Sheet = 0;
502 aSecond.StartColumn = 3;
503 aSecond.StartRow = 4;
504 aSecond.EndColumn = 3;
505 aSecond.EndRow = 4;
506 xRC->gotoUnion(aSecond);
508 xColl = xCC->getRanges();
509 if ( xColl )
511 XPropertySetRef xProp = (XPropertySet*)
512 xColl->queryInterface(XPropertySet::getSmartUik());
513 if ( xProp )
515 UsrAny aAny;
517 aAny = xProp->getPropertyValue(L"ShadowFormat");
518 if ( aAny.getReflection()->getName() ==
519 ShadowFormat_getReflection()->getName() )
521 //ShadowFormat* pOld = (ShadowFormat*)aAny.get();
522 ShadowFormat aNew;
523 aNew.Location = SHADOWLOCATION_BOTTOMRIGHT;
524 aNew.ShadowWidth = 100;
525 aNew.IsTransparent = false;
526 aNew.Color = 0xff0000L;
527 aAny.set( &aNew, aAny.getReflection() );
528 xProp->setPropertyValue(L"ShadowFormat", aAny);
531 aAny = xProp->getPropertyValue(L"RotationValue");
532 aAny.setINT32(4500);
533 xProp->setPropertyValue(L"RotationValue", aAny);
535 aAny = xProp->getPropertyValue(L"FontHeight");
536 aAny.setUINT32(280);
537 xProp->setPropertyValue(L"FontHeight", aAny);
539 aAny = xProp->getPropertyValue(L"TransparentBackground");
540 aAny.setBOOL(false);
541 xProp->setPropertyValue(L"TransparentBackground", aAny);
543 aAny = xProp->getPropertyValue(L"BackgroundColor");
544 aAny.setUINT32(0xffff00);
545 xProp->setPropertyValue(L"BackgroundColor", aAny);
547 aAny = xProp->getPropertyValue(L"CellProtection");
548 if ( aAny.getReflection()->getName() ==
549 CellProtection_getReflection()->getName() )
551 //CellProtection* pOld = (CellProtection*)aAny.get();
552 CellProtection aNew;
553 aNew.Locked = false;
554 aNew.FormulaHidden = false;
555 aNew.Hidden = false;
556 aNew.PrintHidden = false;
557 aAny.set( &aNew, aAny.getReflection() );
558 xProp->setPropertyValue(L"CellProtection", aAny);
562 // XIndexAccess gibts nur wenn's mehrere sind (??!??!)
563 XIndexAccessRef xIndex = (XIndexAccess*)
564 xColl->queryInterface(XIndexAccess::getSmartUik());
565 if ( xIndex )
567 sal_uInt16 nCount = (sal_uInt16)xIndex->getCount();
568 aTimeText.SetText( String(nCount) );
576 if (xLock)
577 xLock->removeActionLock();
581 void lcl_Cells( FixedText& aTimeText )
583 aTimeText.SetText( "..." );
584 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
585 if (xDoc)
587 long nCount = 0;
588 sal_uInt64 nStart = tools::Time::GetSystemTicks();
590 XActionLockableRef xLock = (XActionLockable*)
591 xDoc->queryInterface(XActionLockable::getSmartUik());
592 // if (xLock)
593 // xLock->addActionLock();
595 CellRangeAddress aRngAddr;
596 aRngAddr.Sheet = 0;
597 aRngAddr.StartColumn = 0;
598 aRngAddr.StartRow = 0;
599 aRngAddr.EndColumn = 9;
600 aRngAddr.EndRow = 19;
601 XCellRangeRef xRange = xDoc->getCellRange(aRngAddr);
602 if (xRange)
604 XCellCollectionRef xColl = (XCellCollection*)
605 xRange->queryInterface(XCellCollection::getSmartUik());
606 if (xColl)
608 XEnumerationAccessRef xEnAcc = xColl->getCells();
609 if (xEnAcc)
611 XEnumerationRef xEnum = xEnAcc->getEnumeration();
612 if (xEnum)
614 while (xEnum->hasMoreElements())
616 XInterfaceRef xInt = xEnum->nextElement();
617 if (xInt)
619 ++nCount;
627 sal_uInt64 nEnd = tools::Time::GetSystemTicks();
628 aTimeText.SetText(String(nCount)+String(" ")+String(nEnd-nStart)+String(" ms"));
630 // if (xLock)
631 // xLock->removeActionLock();
635 void lcl_Sheet( FixedText& aTimeText )
637 aTimeText.SetText( "..." );
638 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
639 if (!xDoc) return;
640 XSpreadsheetsRef xSheets = xDoc->getSheets();
641 if (!xSheets) return;
642 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
643 if (!xSheet) return;
644 XNamedRef xNamed = (XNamed*)xSheet->queryInterface(XNamed::getSmartUik());
645 if (!xNamed) return;
647 String aName = OUStringToString( xNamed->getName(), CHARSET_SYSTEM );
648 aName += 'X';
649 xNamed->setName(StringToOUString( aName, CHARSET_SYSTEM ));
651 XCellRangeRef xRange = (XCellRange*)xSheet->queryInterface(XCellRange::getSmartUik());
652 if (!xRange) return;
653 XCellRef xCell = xRange->getCell(2,1);
654 if (!xCell) return;
655 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
656 if (!xText) return;
657 String aBla = OUStringToString( xText->getText(), CHARSET_SYSTEM );
658 aBla += "bla";
659 xText->setText(StringToOUString( aBla, CHARSET_SYSTEM ));
661 XColumnRowRangeRef xCRR = (XColumnRowRange*)xSheet->queryInterface(XColumnRowRange::getSmartUik());
662 if (!xCRR) return;
664 XTableColumnsRef xCols = xCRR->getColumns();
665 if (!xCols) return;
666 XPropertySetRef xCol = xCols->getColumnByIndex(2);
667 if (!xCol) return;
669 UINT16 nWidth = TypeConversion::toUINT16(xCol->getPropertyValue(L"Width"));
670 // UINT16 nNewWidth = nWidth + 100;
671 // xCol->setPropertyValue(L"Width", UsrAny(nNewWidth));
673 xCol->setPropertyValue(L"OptimalWidth", UsrAny((sal_Bool)true));
674 xCol->setPropertyValue(L"NewPage", UsrAny((sal_Bool)false));
676 UsrAny aAny = xCol->getPropertyValue(L"ShadowFormat");
677 if ( aAny.getReflection()->getName() ==
678 ShadowFormat_getReflection()->getName() )
680 //ShadowFormat* pOld = (ShadowFormat*)aAny.get();
681 ShadowFormat aNew;
682 aNew.Location = SHADOWLOCATION_BOTTOMRIGHT;
683 aNew.ShadowWidth = 100;
684 aNew.IsTransparent = false;
685 aNew.Color = 0xff0000L;
686 aAny.set( &aNew, aAny.getReflection() );
687 xCol->setPropertyValue(L"ShadowFormat", aAny);
690 XTableRowsRef xRows = xCRR->getRows();
691 if (!xRows) return;
692 XPropertySetRef xRow = xRows->getRowByIndex(1);
693 if (!xRow) return;
695 xRows->removeRowsByIndex( 2, 1 );
697 UINT16 nHeight = TypeConversion::toUINT16(xRow->getPropertyValue(L"Height"));
698 sal_Bool bOptH = TypeConversion::toBOOL(xRow->getPropertyValue(L"OptimalHeight"));
700 UINT16 nNewHeight = nHeight + 100;
701 xRow->setPropertyValue(L"Height", UsrAny(nNewHeight));
703 aTimeText.SetText(String("W:")+String(nWidth)+String(" H:")+String(nHeight)+
704 String(" ")+String((sal_uInt16)bOptH));
707 void lcl_Names( FixedText& aTimeText )
709 aTimeText.SetText( "..." );
710 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
711 if (!xDoc) return;
712 XNamedRangesRef xNames = xDoc->getNamedRanges();
713 if (!xNames) return;
714 XNamedRangeRef xName = xNames->getRangeByName(L"bla");
715 if (!xName) return;
716 String aCont = OUStringToString( xName->getContent(), CHARSET_SYSTEM );
717 aTimeText.SetText(aCont);
719 XCellRangeSourceRef xSource = (XCellRangeSource*)
720 xName->queryInterface(XCellRangeSource::getSmartUik());
721 if (!xSource) return;
722 XCellRangeRef xRange = xSource->getReferredCells();
723 if (!xRange) return;
724 XPropertySetRef xProp = (XPropertySet*)xRange->queryInterface(XPropertySet::getSmartUik());
725 if (!xProp) return;
726 UsrAny aAny = xProp->getPropertyValue(L"RotationValue");
727 aAny.setINT32(3000);
728 xProp->setPropertyValue(L"RotationValue", aAny);
731 void lcl_Sheets( FixedText& aTimeText )
733 aTimeText.SetText( "..." );
734 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
735 if (!xDoc) return;
736 XSpreadsheetsRef xSheets = xDoc->getSheets();
737 if (!xSheets) return;
739 xSheets->moveSheet(0, 1, true);
740 xSheets->moveSheet(0, 2, false);
743 void lcl_Goal( FixedText& aTimeText )
745 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
746 if (!xDoc) return;
747 XGoalSeekRef xGoal = (XGoalSeek*)xDoc->queryInterface(XGoalSeek::getSmartUik());
748 if (!xGoal) return;
750 double fResult;
751 CellAddress aFormula; // A1
752 aFormula.Sheet = 0;
753 aFormula.Column = 0;
754 aFormula.Row = 0;
755 CellAddress aVar; // A2
756 aVar.Sheet = 0;
757 aVar.Column = 0;
758 aVar.Row = 1;
759 sal_Bool bFound = xGoal->doGoalSeek(fResult, aFormula, aVar, L"42");
761 if (bFound)
763 CellAddress aOut; // A3
764 aOut.Sheet = 0;
765 aOut.Column = 0;
766 aOut.Row = 2;
768 XCellRef xCell = xDoc->getCell(aOut);
769 if (!xCell) return;
770 xCell->setValue(fResult);
774 void lcl_TabOp( FixedText& aTimeText )
776 // Mehrfachoperation auf Tabelle2
777 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
778 if (!xDoc) return;
780 XCellRangeRef xRange;
781 XTableOperationRef xGoal;
782 CellRangeAddress aRangeAddr;
783 CellRangeAddress aFormulaRange;
784 CellAddress aColumnCell;
785 CellAddress aRowCell;
786 TableOperationMode nMode;
788 aRangeAddr.Sheet = 1; // c9:e11
789 aRangeAddr.StartColumn = 2;
790 aRangeAddr.StartRow = 8;
791 aRangeAddr.EndColumn = 4;
792 aRangeAddr.EndRow = 10;
793 aFormulaRange.Sheet = 1; // c6:c7
794 aFormulaRange.StartColumn = 2;
795 aFormulaRange.StartRow = 5;
796 aFormulaRange.EndColumn = 2;
797 aFormulaRange.EndRow = 6;
798 aColumnCell.Sheet = 0; // nicht benutzt
799 aColumnCell.Column = 0;
800 aColumnCell.Row = 0;
801 aRowCell.Sheet = 1; // c5
802 aRowCell.Column = 2;
803 aRowCell.Row = 4;
804 nMode = TABLEOP_ROW;
806 xRange = xDoc->getCellRange(aRangeAddr);
807 if (!xRange) return;
808 xGoal = (XTableOperation*)xRange->queryInterface(XTableOperation::getSmartUik());
809 if (!xGoal) return;
810 xGoal->setTableOperation( nMode, aFormulaRange, aColumnCell, aRowCell );
812 aRangeAddr.Sheet = 1; // b19:d21
813 aRangeAddr.StartColumn = 1;
814 aRangeAddr.StartRow = 18;
815 aRangeAddr.EndColumn = 3;
816 aRangeAddr.EndRow = 20;
817 aFormulaRange.Sheet = 1; // c16:d16
818 aFormulaRange.StartColumn = 2;
819 aFormulaRange.StartRow = 15;
820 aFormulaRange.EndColumn = 3;
821 aFormulaRange.EndRow = 15;
822 aColumnCell.Sheet = 1; // b16
823 aColumnCell.Column = 1;
824 aColumnCell.Row = 15;
825 aRowCell.Sheet = 0; // nicht benutzt
826 aRowCell.Column = 0;
827 aRowCell.Row = 0;
828 nMode = TABLEOP_COLUMN;
830 xRange = xDoc->getCellRange(aRangeAddr);
831 if (!xRange) return;
832 xGoal = (XTableOperation*)xRange->queryInterface(XTableOperation::getSmartUik());
833 if (!xGoal) return;
834 xGoal->setTableOperation( nMode, aFormulaRange, aColumnCell, aRowCell );
836 aRangeAddr.Sheet = 1; // b29:e32
837 aRangeAddr.StartColumn = 1;
838 aRangeAddr.StartRow = 28;
839 aRangeAddr.EndColumn = 4;
840 aRangeAddr.EndRow = 31;
841 aFormulaRange.Sheet = 1; // c27:c27
842 aFormulaRange.StartColumn = 2;
843 aFormulaRange.StartRow = 26;
844 aFormulaRange.EndColumn = 2;
845 aFormulaRange.EndRow = 26;
846 aColumnCell.Sheet = 1; // c25
847 aColumnCell.Column = 2;
848 aColumnCell.Row = 24;
849 aRowCell.Sheet = 1; // c26
850 aRowCell.Column = 2;
851 aRowCell.Row = 25;
852 nMode = TABLEOP_BOTH;
854 xRange = xDoc->getCellRange(aRangeAddr);
855 if (!xRange) return;
856 xGoal = (XTableOperation*)xRange->queryInterface(XTableOperation::getSmartUik());
857 if (!xGoal) return;
858 xGoal->setTableOperation( nMode, aFormulaRange, aColumnCell, aRowCell );
861 void lcl_Fill( FixedText& aTimeText )
863 XInterfaceRef xInt = lcl_GetView();
864 if (!xInt) return;
865 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
866 if (!xView) return;
868 XInterfaceRef xSelInt = xView->getSelection();
869 if (!xSelInt) return;
871 XCellSeriesRef xFill = (XCellSeries*)xSelInt->queryInterface(XCellSeries::getSmartUik());
872 if (!xFill) return;
874 // xFill->fillAuto( FILL_DIRECTION_TO_BOTTOM, 2 );
876 xFill->fillSeries( FILL_DIRECTION_TO_LEFT, FILL_MODE_GROWTH, FILL_DATE_DAY,
877 2.0, 1000.0 );
880 void lcl_Audi( FixedText& aTimeText )
882 aTimeText.SetText( "..." );
883 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
884 if (!xDoc) return;
885 XSpreadsheetsRef xSheets = xDoc->getSheets();
886 if (!xSheets) return;
887 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
888 if (!xSheet) return;
890 XSheetAuditingRef xAudi = (XSheetAuditing*)xSheet->queryInterface(XSheetAuditing::getSmartUik());
891 if (!xAudi) return;
893 CellAddress aPosition;
894 aPosition.Sheet = 0;
895 aPosition.Column = 0;
896 aPosition.Row = 0;
897 xAudi->showDependents(aPosition);
900 void lcl_Consoli( FixedText& aTimeText )
902 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
903 if (!xDoc) return;
904 XConsolidationRef xCons = (XConsolidation*)xDoc->queryInterface(XConsolidation::getSmartUik());
905 if (!xCons) return;
906 XConsolidationDescriptorRef xDesc = xCons->createConsolidationDescriptor(false);
907 if (!xDesc) return;
908 xDesc->setFunction(SUMMARY_COUNTNUMS);
909 xCons->consolidate(xDesc);
912 void lcl_Sort( FixedText& aTimeText )
914 XInterfaceRef xInt = lcl_GetView();
915 if (!xInt) return;
916 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
917 if (!xView) return;
918 XInterfaceRef xSelInt = xView->getSelection();
919 if (!xSelInt) return;
920 XSortableRef xSort = (XSortable*)xSelInt->queryInterface(XSortable::getSmartUik());
921 if (!xSort) return;
922 XSortDescriptorRef xDesc = xSort->createSortDescriptor(false);
923 if (!xDesc) return;
924 Sequence<SortField> aFields = xDesc->getSortFields();
925 if (aFields.getLen())
927 // 1.Feld umkehren
928 SortField* pAry = aFields.getArray();
929 if (!pAry) return;
930 pAry[0].Ascending = !pAry[0].Ascending;
932 else // neue Sequence, 1. Spalte aufsteigend
934 aFields = Sequence<SortField>(1);
935 SortField* pAry = aFields.getArray();
936 if (!pAry) return;
937 pAry[0].Field = 0;
938 pAry[0].Ascending = true;
939 pAry[0].Type = SORT_FIELD_AUTOMATIC;
941 xDesc->setSortFields(aFields);
943 XTableSortDescriptorRef xTableSort = (XTableSortDescriptor*)
944 xDesc->queryInterface(XTableSortDescriptor::getSmartUik());
945 if (!xTableSort) return;
946 CellAddress aOutPos;
947 aOutPos.Sheet = 2;
948 aOutPos.Column = 0;
949 aOutPos.Row = 0;
950 xTableSort->setUseOutputPosition(true);
951 xTableSort->setOutputPosition(aOutPos);
953 XPropertySetRef xPropSet = (XPropertySet*)
954 xDesc->queryInterface(XPropertySet::getSmartUik());
955 if (!xPropSet) return;
956 xPropSet->setPropertyValue(L"IncludeFormats", UsrAny((sal_Bool)false));
958 xSort->sort(xDesc);
961 void lcl_Filter( FixedText& aTimeText )
963 aTimeText.SetText("...");
965 XInterfaceRef xInt = lcl_GetView();
966 if (!xInt) return;
967 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
968 if (!xView) return;
969 XInterfaceRef xSelInt = xView->getSelection();
970 if (!xSelInt) return;
971 XFilterableRef xFilter = (XFilterable*)xSelInt->queryInterface(XFilterable::getSmartUik());
972 if (!xFilter) return;
974 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
975 if (!xDoc) return;
976 CellRangeAddress aAddress;
977 aAddress.Sheet = 3;
978 aAddress.StartColumn = 0;
979 aAddress.StartRow = 0;
980 aAddress.EndColumn = 1;
981 aAddress.EndRow = 2;
982 XCellRangeRef xRange = xDoc->getCellRange(aAddress);
983 if (!xRange) return;
984 XAdvancedFilterSourceRef xSource = (XAdvancedFilterSource*)
985 xRange->queryInterface(XAdvancedFilterSource::getSmartUik());
986 if (!xSource) return;
988 XTableFilterDescriptorRef xDesc = xSource->createAdvancedFilter(xFilter);
989 if (!xDesc)
991 aTimeText.SetText("kein Filter");
992 return;
994 aTimeText.SetText("Filter gefunden");
995 xFilter->filter(xDesc);
998 void lcl_AutoFilter( FixedText& aTimeText )
1000 XInterfaceRef xInt = lcl_GetView();
1001 if (!xInt) return;
1002 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1003 if (!xView) return;
1004 XInterfaceRef xSelInt = xView->getSelection();
1005 if (!xSelInt) return;
1006 XFilterableRef xFilter = (XFilterable*)xSelInt->queryInterface(XFilterable::getSmartUik());
1007 if (!xFilter) return;
1009 sal_Bool bAuto = xFilter->getAutoFilter();
1010 xFilter->setAutoFilter(!bAuto);
1013 void lcl_Merge( FixedText& aTimeText )
1015 static sal_Bool bMerged = false;
1017 XInterfaceRef xInt = lcl_GetView();
1018 if (!xInt) return;
1019 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1020 if (!xView) return;
1021 XInterfaceRef xSelInt = xView->getSelection();
1022 if (!xSelInt) return;
1023 XMergeableRef xMerge = (XMergeable*)xSelInt->queryInterface(XMergeable::getSmartUik());
1024 if (!xMerge) return;
1026 if (bMerged)
1027 xMerge->unmergeCells();
1028 else
1029 xMerge->mergeCells();
1030 bMerged = !bMerged;
1033 void lcl_Outline( FixedText& aTimeText )
1035 static sal_Bool bOutline = false;
1037 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1038 if (!xDoc) return;
1039 XSpreadsheetsRef xSheets = xDoc->getSheets();
1040 if (!xSheets) return;
1041 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
1042 if (!xSheet) return;
1043 XSheetOutlineRef xOut = (XSheetOutline*)xSheet->queryInterface(XSheetOutline::getSmartUik());
1044 if (!xOut) return;
1046 XInterfaceRef xInt = lcl_GetView();
1047 if (!xInt) return;
1048 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1049 if (!xView) return;
1050 XInterfaceRef xSelInt = xView->getSelection();
1051 if (!xSelInt) return;
1052 XAddressableCellRangeRef xRange = (XAddressableCellRange*)
1053 xSelInt->queryInterface(XAddressableCellRange::getSmartUik());
1054 if (!xRange) return;
1055 CellRangeAddress aRange = xRange->getRangeAddress();
1057 if (bOutline)
1058 xOut->showDetail( aRange );
1059 else
1060 xOut->hideDetail( aRange );
1062 bOutline = !bOutline;
1065 void lcl_Bla( FixedText& aTimeText )
1067 aTimeText.SetText("...");
1069 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1070 if (!xDoc) return;
1071 XActionLockableRef xLock = (XActionLockable*)xDoc->queryInterface(XActionLockable::getSmartUik());
1072 if (!xLock) return;
1073 xLock->addActionLock();
1074 xLock->addActionLock();
1075 sal_uInt16 nCount = xLock->resetActionLocks(); // sollte 2 sein
1076 String aBla = nCount;
1077 xLock->setActionLocks(nCount);
1078 xLock->removeActionLock();
1079 xLock->removeActionLock();
1081 aBla += '/'; aBla += xLock->resetActionLocks(); // sollte 0 sein
1083 aTimeText.SetText(aBla);
1086 void lcl_CellCursor( FixedText& aTimeText )
1088 static int nCursorCount = 0;
1090 XInterfaceRef xInt = lcl_GetView();
1091 if (!xInt) return;
1092 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1093 if (!xView) return;
1094 XInterfaceRef xSelInt = xView->getSelection();
1095 if (!xSelInt) return;
1096 XCellCollectionRef xColl = (XCellCollection*)xSelInt->queryInterface(XCellCollection::getSmartUik());
1097 if (!xColl) return;
1099 XLineCursorRef xCursor = xColl->createCursor();
1100 if (!xCursor) return;
1101 XCellCursorRef xCC = (XCellCursor*)xCursor->queryInterface(XCellCursor::getSmartUik());
1102 if (!xCC) return;
1103 XCellRangesCursorRef xCRC = (XCellRangesCursor*)xCursor->queryInterface(XCellRangesCursor::getSmartUik());
1104 if (!xCRC) return;
1105 XCellRangeCursorRef xCR = (XCellRangeCursor*)xCursor->queryInterface(XCellRangeCursor::getSmartUik());
1106 if (!xCR) return;
1107 XCellContentCursorRef xCCC = (XCellContentCursor*)xCursor->queryInterface(XCellContentCursor::getSmartUik());
1108 if (!xCCC) return;
1109 XFormulaCursorRef xFC = (XFormulaCursor*)xCursor->queryInterface(XFormulaCursor::getSmartUik());
1110 if (!xFC) return;
1112 CellAddress aPos;
1113 aPos.Sheet = 0; // ignored
1114 aPos.Row = 3;
1115 aPos.Column = 2;
1117 switch (nCursorCount++)
1119 case 0:
1120 xFC->gotoDependents(false);
1121 break;
1122 case 1:
1123 xFC->gotoDependents(true);
1124 break;
1125 case 2:
1126 xFC->gotoPrecedents(false);
1127 break;
1128 case 3:
1129 xFC->gotoPrecedents(true);
1131 nCursorCount = 0;
1132 break;
1135 XCellCollectionRef xNew = xCC->getRanges();
1136 if (!xNew) return;
1137 xView->select( xNew );
1140 void lcl_Notes( FixedText& aTimeText )
1142 aTimeText.SetText( "..." );
1143 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1144 if (!xDoc) return;
1145 XSpreadsheetsRef xSheets = xDoc->getSheets();
1146 if (!xSheets) return;
1147 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
1148 if (!xSheet) return;
1150 XSheetAnnotationsRef xNotes = xSheet->getAnnotations();
1151 if (!xNotes) return;
1152 XIndexAccessRef xNIndex = (XIndexAccess*)xNotes->queryInterface(XIndexAccess::getSmartUik());
1153 if (!xNIndex) return;
1155 CellAddress aPos;
1156 aPos.Column = 0;
1157 aPos.Row = 0;
1158 aPos.Sheet = 0;
1159 xNotes->addAnnotation( L"neu", aPos );
1161 sal_uLong nCount = xNIndex->getCount();
1162 for (sal_uLong i=0; i<nCount; i++)
1164 XSheetAnnotationRef xAnn = xNotes->getAnnotationByIndex((UINT16)i);
1165 XTextRef xText = (XText*)xAnn->queryInterface(XText::getSmartUik());
1166 if (xText)
1168 String aStr = OUStringToString( xText->getText(), CHARSET_SYSTEM );
1169 aStr += "x";
1170 xText->setText(StringToOUString( aStr, CHARSET_SYSTEM ));
1175 void lcl_Scenario( FixedText& aTimeText )
1177 aTimeText.SetText( "..." );
1178 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1179 if (!xDoc) return;
1180 XSpreadsheetsRef xSheets = xDoc->getSheets();
1181 if (!xSheets) return;
1182 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
1183 if (!xSheet) return;
1185 XScenariosRef xColl = xSheet->getScenarios();
1186 if (!xColl) return;
1188 Sequence<CellRangeAddress> aRanges(2);
1189 CellRangeAddress* pAry = aRanges.getArray();
1190 if (!pAry) return;
1191 pAry[0].Sheet = 0;
1192 pAry[0].StartColumn = 0;
1193 pAry[0].StartRow = 0;
1194 pAry[0].EndColumn = 1;
1195 pAry[0].EndRow = 1;
1196 pAry[1].Sheet = 0;
1197 pAry[1].StartColumn = 3;
1198 pAry[1].StartRow = 3;
1199 pAry[1].EndColumn = 4;
1200 pAry[1].EndRow = 4;
1202 xColl->addScenario( aRanges, L"bla", L"bla blubb" );
1204 XIndexAccessRef xIndex = (XIndexAccess*)xColl->queryInterface(XIndexAccess::getSmartUik());
1205 if (!xIndex) return;
1206 sal_uLong nCount = xIndex->getCount();
1207 aTimeText.SetText( nCount );
1209 XScenarioRef xScen = xColl->getScenarioByIndex(0);
1210 if (!xScen) return;
1212 aRanges = Sequence<CellRangeAddress>(1);
1213 pAry = aRanges.getArray();
1214 if (!pAry) return;
1215 pAry[0].Sheet = 0;
1216 pAry[0].StartColumn = 6;
1217 pAry[0].StartRow = 6;
1218 pAry[0].EndColumn = 7;
1219 pAry[0].EndRow = 7;
1221 xScen->addRanges( aRanges );
1223 XTableSheetRef xSh2 = xSheets->getSheetByIndex(1);
1224 if (!xSh2) return;
1226 xSh2->setVisible( true );
1227 xSh2->setVisible( false );
1230 void lcl_Formula( FixedText& aTimeText )
1232 aTimeText.SetText("...");
1234 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1235 if (!xDoc) return;
1236 CellAddress aPos;
1237 aPos.Sheet = 0;
1238 aPos.Column = 0;
1239 aPos.Row = 0;
1240 XCellRef xCell = xDoc->getCell(aPos);
1241 if (!xCell) return;
1243 // String aStr = OUStringToString( xCell->getFormula(), CHARSET_SYSTEM );
1244 // aTimeText.SetText(aStr);
1246 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
1247 if (!xText) return;
1248 String aStr = OUStringToString( xText->getText(), CHARSET_SYSTEM );
1249 aTimeText.SetText(aStr);
1252 void lcl_DBRange( FixedText& aTimeText ) // 23
1254 aTimeText.SetText("...");
1256 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1257 if (!xDoc) return;
1258 XDatabaseRangesRef xDBs = xDoc->getDatabaseRanges();
1259 if (!xDBs) return;
1261 CellRangeAddress aRange;
1262 aRange.Sheet = 0;
1263 aRange.StartColumn = 1;
1264 aRange.StartRow = 1;
1265 aRange.EndColumn = 3;
1266 aRange.EndRow = 10;
1268 xDBs->addRange( L"blubb", aRange );
1270 xDBs->removeRangeByName( L"gaga" );
1272 XDatabaseRangeRef xDB = xDBs->getRangeByName( L"blubb" );
1273 if (!xDB) return;
1275 String aName = OUStringToString( xDB->getName(), CHARSET_SYSTEM );
1276 aTimeText.SetText(aName);
1278 xDB->setName( L"gaga" );
1280 CellRangeAddress aDBRange = xDB->getDataArea();
1281 ++aDBRange.Sheet;
1282 xDB->setDataArea(aDBRange);
1285 void lcl_FillTab( FixedText& aTimeText ) // 24
1287 aTimeText.SetText("...");
1289 XInterfaceRef xInt = lcl_GetView();
1290 if (!xInt) return;
1291 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1292 if (!xView) return;
1293 XInterfaceRef xSelInt = xView->getSelection();
1294 if (!xSelInt) return;
1296 XCellRangesRef xRanges = (XCellRanges*)xSelInt->queryInterface(XCellRanges::getSmartUik());
1297 XIndexAccessRef xIndex = (XIndexAccess*)xSelInt->queryInterface(XIndexAccess::getSmartUik());
1298 if (!xRanges || !xIndex) return;
1300 sal_uLong nCount = xIndex->getCount();
1301 aTimeText.SetText(nCount);
1304 void lcl_Listener( FixedText& aTimeText ) // 25
1306 XInterfaceRef xInt = lcl_GetView();
1307 if (!xInt) return;
1308 XStarCalcViewRef xView = (XStarCalcView*)xInt->queryInterface(XStarCalcView::getSmartUik());
1309 if (!xView) return;
1310 xView->addSelectionChangeListener( new ScTestListener(&aTimeText) );
1313 void lcl_CellAttrib( FixedText& aTimeText ) // 26
1315 XInterfaceRef xInt = lcl_GetView();
1316 if (!xInt) return;
1317 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1318 if (!xView) return;
1319 XInterfaceRef xSelInt = xView->getSelection();
1320 if (!xSelInt) return;
1321 XTextRef xText = (XText*)xSelInt->queryInterface(XText::getSmartUik());
1322 if (!xText) return;
1324 XTextCursorRef xCursor = xText->createTextCursor();
1325 if (!xCursor) return;
1327 XTextPositionRef xPos = (XTextPosition*)xCursor->queryInterface(XTextPosition::getSmartUik());
1328 XPropertySetRef xProp = (XPropertySet*)xCursor->queryInterface(XPropertySet::getSmartUik());
1329 XParagraphCursorRef xPar = (XParagraphCursor*)xCursor->queryInterface(XParagraphCursor::getSmartUik());
1330 if (!xPos || !xProp || !xPar) return;
1332 xCursor->gotoStart(false);
1333 xCursor->goRight(1,false);
1334 xCursor->goRight(1,true);
1336 UsrAny aAny = xProp->getPropertyValue(L"FontHeight");
1337 sal_uInt32 nOld = aAny.getUINT32();
1338 aAny.setUINT32(nOld*11/10);
1339 xProp->setPropertyValue(L"FontHeight", aAny);
1341 xPos->collapseToEnd();
1342 xCursor->goRight(1,true);
1344 xProp->setPropertyValue(L"Bold", UsrAny((sal_Bool)true));
1346 xPos->setText(L"x");
1348 xPos->collapseToEnd();
1349 xPar->gotoNextParagraph(false,true);
1350 xProp->setPropertyValue(L"Italic", UsrAny((sal_Bool)true));
1351 xProp->setPropertyValue(L"Underlined", UsrAny((sal_Bool)true));
1354 void lcl_Styles( FixedText& aTimeText ) // 27
1356 aTimeText.SetText("...");
1357 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1358 if (!xDoc) return;
1359 XStyleFamiliesRef xFamilies = xDoc->getStyleFamilies();
1360 if (!xFamilies) return;
1361 XStyleFamilyRef xFamily = xFamilies->getStyleFamilyByType( STYLE_FAMILY_CELL );
1362 // XStyleFamilyRef xFamily = xFamilies->getStyleFamilyByType( STYLE_FAMILY_PAGE );
1363 if (!xFamily) return;
1364 long nCount = xFamily->getCount();
1365 aTimeText.SetText(nCount);
1367 XStyleRef xStyle = xFamily->getStyleByName(L"rot");
1368 if (!xStyle) return;
1369 // XPropertySetRef xProp = (XPropertySet*)xStyle->queryInterface(XPropertySet::getSmartUik());
1370 // if (!xProp) return;
1372 XStyleRef xNew = xFamily->addStyle( L"gaga", xStyle );
1373 if (!xNew) return;
1374 XPropertySetRef xProp = (XPropertySet*)xNew->queryInterface(XPropertySet::getSmartUik());
1375 if (!xProp) return;
1377 UsrAny aAny;
1378 aAny = xProp->getPropertyValue(L"TransparentBackground");
1379 aAny.setBOOL(false);
1380 xProp->setPropertyValue(L"TransparentBackground", aAny);
1381 aAny = xProp->getPropertyValue(L"BackgroundColor");
1382 aAny.setUINT32(0xffff00);
1383 xProp->setPropertyValue(L"BackgroundColor", aAny);
1385 xFamily->removeStyle( L"rot" );
1388 void lcl_PageStyle( FixedText& aTimeText ) // 28
1390 aTimeText.SetText("...");
1392 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1393 if (!xDoc) return;
1394 XStyleFamiliesRef xFamilies = xDoc->getStyleFamilies();
1395 if (!xFamilies) return;
1396 XStyleFamilyRef xFamily = xFamilies->getStyleFamilyByType( STYLE_FAMILY_PAGE );
1397 if (!xFamily) return;
1398 XStyleRef xStyle = xFamily->getStyleByName(L"Standard");
1399 if (!xStyle) return;
1400 XPropertySetRef xProp = (XPropertySet*)xStyle->queryInterface(XPropertySet::getSmartUik());
1401 if (!xProp) return;
1403 UsrAny aAny;
1404 aAny = xProp->getPropertyValue(L"RightPageHeaderContent");
1406 // geht nicht:
1407 // if ( !XHeaderFooterContent_getReflection()->equals(*aAny.getReflection()) )
1408 // return;
1410 XHeaderFooterContentRef* pxContent = (XHeaderFooterContentRef*)aAny.get();
1411 if (!pxContent || !pxContent->is()) return;
1413 XTextRef xText = (*pxContent)->getCenterText();
1414 if (!xText) return;
1416 String aVal = OUStringToString(xText->getText(), CHARSET_SYSTEM);
1417 aTimeText.SetText(aVal);
1419 // xText->setText(L"Bla fasel s\xFClz");
1420 lcl_SetText(xText);
1422 xProp->setPropertyValue(L"RightPageHeaderContent", aAny);
1425 void lcl_AutoForm( FixedText& aTimeText ) // 29
1427 XInterfaceRef xInt = lcl_GetView();
1428 if (!xInt) return;
1430 XTableAutoFormatsRef xFormats;
1432 XTableAutoFormatRef xFormat = xFormats->getAutoFormatByName(L"gaga");
1433 if (!xFormat) return;
1434 XPropertySetRef xProp = (XPropertySet*)xFormat->queryInterface(XPropertySet::getSmartUik());
1435 if (!xProp) return;
1437 sal_Bool bVal = TypeConversion::toBOOL(xProp->getPropertyValue(L"IncludeBackground"));
1438 xProp->setPropertyValue(L"IncludeBackground", UsrAny(sal_Bool(!bVal)));
1440 XNamedRef xNamed = (XNamed*)xFormat->queryInterface(XNamed::getSmartUik());
1441 if (!xNamed) return;
1442 xNamed->setName(L"zzz");
1444 xFormats->addAutoFormat(L"gaga");
1445 XTableAutoFormatRef xNew = xFormats->getAutoFormatByName(L"gaga");
1446 if (!xNew) return;
1448 for (sal_uInt16 i=0; i<16; i++)
1450 XPropertySetRef xNewProp = xNew->getFieldByIndex(i);
1451 if (!xNewProp) return;
1453 xNewProp->setPropertyValue(L"TransparentBackground", UsrAny(sal_Bool(false)));
1454 sal_uInt32 nColor = 0x111100 * i;
1455 xNewProp->setPropertyValue(L"BackgroundColor", UsrAny(nColor));
1459 void lcl_Pivot( FixedText& aTimeText ) // 30
1461 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1462 if (!xDoc) return;
1464 XSpreadsheetsRef xSheets = xDoc->getSheets();
1465 if (!xSheets) return;
1466 XIndexAccessRef xInd = (XIndexAccess*)xSheets->queryInterface(XIndexAccess::getSmartUik());
1467 if (!xInd) return;
1468 sal_uInt16 nCount = (sal_uInt16)xInd->getCount();
1470 for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
1472 XTableSheetRef xSheet = xSheets->getSheetByIndex(nTab);
1473 if (!xSheet) return;
1474 XDataPilotTablesRef xPivots = xSheet->getDataPilotTables();
1475 if (!xPivots) return;
1476 lcl_OutputNames( xPivots, xDoc, nTab,0,0 );
1477 XIndexAccessRef xPInd = (XIndexAccess*)xPivots->queryInterface(XIndexAccess::getSmartUik());
1478 if (!xPInd) return;
1479 sal_uInt16 nPCount = (sal_uInt16)xPInd->getCount();
1480 for (sal_uInt16 nP=0; nP<nPCount; nP++)
1482 XDataPilotTableRef xTable = xPivots->getTableByIndex(nP);
1483 if (!xTable) return;
1485 // xTable->refreshTable();
1487 XDataPilotDescriptorRef xDesc = (XDataPilotDescriptor*)
1488 xTable->queryInterface(XDataPilotDescriptor::getSmartUik());
1489 if (!xDesc) return;
1490 CellRangeAddress aSource = xDesc->getSourceRange();
1491 ++aSource.Sheet;
1492 xDesc->setSourceRange(aSource);
1494 CellRangeAddress aAddr = xTable->getOutputRange();
1495 XCellRangeRef xRange = xDoc->getCellRange(aAddr);
1496 if (!xRange) return;
1497 XPropertySetRef xProp = (XPropertySet*)xRange->queryInterface(XPropertySet::getSmartUik());
1498 if (!xProp) return;
1499 xProp->setPropertyValue(L"TransparentBackground", UsrAny(sal_Bool(false)));
1500 xProp->setPropertyValue(L"BackgroundColor", UsrAny((sal_uInt32)0x00FF00));
1505 IMPL_LINK_NOARG(MyWindow, CountHdl)
1508 long nCount = aCountField.GetValue();
1509 switch ( nCount )
1511 case 0:
1513 sal_uInt64 nStart = tools::Time::GetSystemTicks();
1514 lcl_DoCount();
1515 sal_uInt64 nEnd = tools::Time::GetSystemTicks();
1516 aTimeText.SetText(String("Count: ")+String(nEnd-nStart)+String(" ms"));
1518 break;
1519 case 1:
1520 lcl_GlobalCell();
1521 break;
1522 case 2:
1523 lcl_Annotations(aTimeText);
1524 break;
1525 case 3:
1526 lcl_Cursor(aTimeText);
1527 break;
1528 case 4:
1529 lcl_Cells(aTimeText);
1530 break;
1531 case 5:
1532 lcl_Sheet(aTimeText);
1533 break;
1534 case 6:
1535 lcl_Names(aTimeText);
1536 break;
1537 case 7:
1538 lcl_Sheets(aTimeText);
1539 break;
1540 case 8:
1541 lcl_Goal(aTimeText);
1542 break;
1543 case 9:
1544 lcl_TabOp(aTimeText);
1545 break;
1546 case 10:
1547 lcl_Fill(aTimeText);
1548 break;
1549 case 11:
1550 lcl_Audi(aTimeText);
1551 break;
1552 case 12:
1553 lcl_Consoli(aTimeText);
1554 break;
1555 case 13:
1556 lcl_Sort(aTimeText);
1557 break;
1558 case 14:
1559 lcl_Filter(aTimeText);
1560 break;
1561 case 15:
1562 lcl_AutoFilter(aTimeText);
1563 break;
1564 case 16:
1565 lcl_Merge(aTimeText);
1566 break;
1567 case 17:
1568 lcl_Outline(aTimeText);
1569 break;
1570 case 18:
1571 lcl_Bla(aTimeText);
1572 break;
1573 case 19:
1574 lcl_CellCursor(aTimeText);
1575 break;
1576 case 20:
1577 lcl_Notes(aTimeText);
1578 break;
1579 case 21:
1580 lcl_Scenario(aTimeText);
1581 break;
1582 case 22:
1583 lcl_Formula(aTimeText);
1584 break;
1585 case 23:
1586 lcl_DBRange(aTimeText);
1587 break;
1588 case 24:
1589 lcl_FillTab(aTimeText);
1590 break;
1591 case 25:
1592 lcl_Listener(aTimeText);
1593 break;
1594 case 26:
1595 lcl_CellAttrib(aTimeText);
1596 break;
1597 case 27:
1598 lcl_Styles(aTimeText);
1599 break;
1600 case 28:
1601 lcl_PageStyle(aTimeText);
1602 break;
1603 case 29:
1604 lcl_AutoForm(aTimeText);
1605 break;
1606 case 30:
1607 lcl_Pivot(aTimeText);
1608 break;
1611 return 0;
1614 IMPL_LINK_NOARG(MyWindow, TextHdl)
1616 sal_uInt16 nCol = (sal_uInt16)aColField.GetValue();
1617 sal_uInt16 nRow = (sal_uInt16)aRowField.GetValue();
1618 sal_uInt16 nPos = (sal_uInt16)aPosField.GetValue();
1619 sal_uInt16 nLen = (sal_uInt16)aLenField.GetValue();
1620 String aStr = aTextEdit.GetText();
1622 aTimeText.SetText("...");
1624 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1625 if (xDoc)
1627 sal_uInt16 nTab = 0;
1628 CellAddress aPos;
1629 aPos.Sheet = 0;
1630 aPos.Column = nCol;
1631 aPos.Row = nRow;
1632 XCellRef xCell = xDoc->getCell(aPos);
1633 if ( xCell )
1635 XTextRef xCellText = (XText*)xCell->queryInterface(XText::getSmartUik());
1636 if (xCellText)
1638 XTextCursorRef xCursor = xCellText->createTextCursor();
1639 if (xCursor)
1641 XTextPositionRef xPos = (XTextPosition*)
1642 xCursor->queryInterface(XTextPosition::getSmartUik());
1643 XControlCharacterInsertableRef xControl = (XControlCharacterInsertable*)
1644 xCursor->queryInterface(XControlCharacterInsertable::getSmartUik());
1646 if (xPos && xControl)
1648 xCursor->gotoStart(false);
1649 xCursor->goRight(11,true);
1650 String aVal = OUStringToString( xPos->getText(), CHARSET_SYSTEM );
1651 aTimeText.SetText(aVal);
1658 return 0;
1661 IMPL_LINK_NOARG(MyWindow, BlaHdl)
1663 aTimeText.SetText("...");
1665 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1666 if (xDoc)
1668 CellAddress aPos;
1669 aPos.Sheet = 0;
1670 aPos.Column = 1;
1671 aPos.Row = 2;
1672 XCellRef xCell = xDoc->getCell(aPos);
1673 if ( xCell )
1675 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
1676 XFieldContainerRef xCont = (XFieldContainer*)
1677 xCell->queryInterface(XFieldContainer::getSmartUik());
1679 if ( xText && xCont )
1681 XFieldTypesRef xTypes = xCont->getFieldTypes();
1682 if ( xTypes )
1684 XTextFieldTypeRef xType = xTypes->getFieldType( FIELDTYPE_INTERNET );
1685 XTextCursorRef xCursor = xText->createTextCursor();
1686 if ( xCursor && xType )
1689 // letztes Feld loeschen
1690 XIndexAccessRef xIndex = (XIndexAccess*)
1691 xType->queryInterface(XIndexAccess::getSmartUik());
1692 if (xIndex)
1694 String aBla;
1695 sal_uLong nCount = xIndex->getCount();
1696 for (sal_uLong i=0; i<nCount; i++)
1698 XInterfaceRef xInt = xIndex->getElementByIndex(i);
1699 if (xInt)
1701 XPropertySetRef xProp = (XPropertySet*)xInt->
1702 queryInterface(XPropertySet::getSmartUik());
1703 if ( xProp )
1705 if (aBla.Len()) aBla += ',';
1706 aBla += OUStringToString(
1707 TypeConversion::toString(
1708 xProp->getPropertyValue(L"URL") ),
1709 CHARSET_SYSTEM );
1711 if ( i+1 == nCount ) // letztes
1713 XTextFieldRef xField = (XTextField*)xInt->
1714 queryInterface(XTextField::getSmartUik());
1715 if (xField)
1716 xTypes->removeTextField(xField);
1720 aTimeText.SetText(aBla);
1727 xGlobalCell = xCell;
1729 return 0;
1732 IMPL_LINK_NOARG(MyWindow, TabHdl)
1734 String aResult;
1736 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1737 if (xDoc)
1739 XSpreadsheetsRef xSheets = xDoc->getSheets();
1740 if (xSheets)
1742 XIndexAccessRef xIndex = (XIndexAccess*)xSheets->queryInterface(XIndexAccess::getSmartUik());
1743 if (xIndex)
1745 sal_uInt16 nCount = (sal_uInt16) xIndex->getCount();
1746 for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
1748 XInterfaceRef xInt = xIndex->getElementByIndex(nTab);
1749 if (xInt)
1751 XNamedRef xNamed = (XNamed*)xInt->queryInterface(XNamed::getSmartUik());
1752 if (xNamed)
1754 if (nTab)
1755 aResult += ",";
1756 aResult += OUStringToString( xNamed->getName(), CHARSET_SYSTEM );
1762 CellAddress aPos;
1763 aPos.Sheet = 0;
1764 aPos.Column = 0;
1765 aPos.Row = 0;
1767 XEnumerationAccessRef xEAcc = (XEnumerationAccess*)
1768 xSheets->queryInterface(XEnumerationAccess::getSmartUik());
1769 if (xEAcc)
1771 XEnumerationRef xEnum = xEAcc->getEnumeration();
1772 if (xEnum)
1774 while (xEnum->hasMoreElements())
1776 XInterfaceRef xInt = xEnum->nextElement();
1777 if (xInt)
1779 XNamedRef xNamed = (XNamed*)xInt->queryInterface(XNamed::getSmartUik());
1780 if (xNamed)
1782 UString aName = xNamed->getName();
1783 XCellRef xCell = xDoc->getCell(aPos);
1784 if ( xCell )
1786 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
1787 xText->setText( aName );
1788 ++aPos.Row;
1798 aTimeText.SetText(aResult);
1800 return 0;
1803 void lcl_FillCells(XCellCollectionRef xColl)
1805 XEnumerationAccessRef xEnAcc = xColl->getCells();
1806 if (!xEnAcc) return;
1807 XEnumerationRef xEnum = xEnAcc->getEnumeration();
1808 if (!xEnum) return;
1809 while (xEnum->hasMoreElements())
1811 XInterfaceRef xInt = xEnum->nextElement();
1812 if (xInt)
1814 XCellRef xCell = (XCell*)xInt->queryInterface(XCell::getSmartUik());
1815 if (xCell)
1817 xCell->setValue(42.0);
1823 IMPL_LINK_NOARG(MyWindow, ViewHdl)
1825 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1826 XInterfaceRef xInt = lcl_GetView();
1827 if (!xInt) return 0;
1828 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1829 if (!xView) return 0;
1831 XInterfaceRef xSelInt = xView->getSelection();
1832 if (!xSelInt) return 0;
1834 XAutoFormattableRef xAuto = (XAutoFormattable*)xSelInt->
1835 queryInterface(XAutoFormattable::getSmartUik());
1836 if ( xAuto )
1837 xAuto->applyAutoFormat( L"gaga" );
1839 XFormulaArrayRef xArr = (XFormulaArray*)xSelInt->queryInterface(XFormulaArray::getSmartUik());
1840 if ( xArr )
1842 // xArr->setFormulaArray( "123" );
1843 String aFormula = OUStringToString( xArr->getFormulaArray(), CHARSET_SYSTEM );
1844 aTimeText.SetText(aFormula);
1846 else
1847 aTimeText.SetText("...");
1849 XTextRef xText = (XText*)xSelInt->queryInterface(XText::getSmartUik());
1850 if ( xText )
1852 String aStr = OUStringToString( xText->getText(), CHARSET_SYSTEM );
1853 aStr += 'X';
1854 xText->setText(StringToOUString(aStr, CHARSET_SYSTEM));
1857 XPrintableRef xPrint = (XPrintable*)xInt->queryInterface(XPrintable::getSmartUik());
1858 String aName = OUStringToString( xPrint->getPrinterName(), CHARSET_SYSTEM );
1859 // aTimeText.SetText(aName);
1861 xPrint->setPrinterName(L"HP5_2");
1862 // xPrint->setPrinterName(L"blubb");
1864 // XPropertySetRef xOptions;
1865 // xPrint->print(xOptions);
1867 /* XViewPaneRef xPane = (XViewPane*)xInt->queryInterface(XViewPane::getSmartUik());
1868 if (!xPane) return 0;
1869 xPane->setScrollRow( 2 );
1872 XCellRangeSourceRef xSrc = (XCellRangeSource*)
1873 xInt->queryInterface(XCellRangeSource::getSmartUik());
1874 if (!xSrc) return 0;
1875 XCellRangeRef xRange = xSrc->getReferredCells();
1876 if (!xRange) return 0;
1877 XCellCollectionRef xColl = (XCellCollection*)
1878 xRange->queryInterface(XCellCollection::getSmartUik());
1879 if (!xColl) return 0;
1881 XActionLockableRef xLock = (XActionLockable*)
1882 xDoc->queryInterface(XActionLockable::getSmartUik());
1883 if (xLock)
1884 xLock->addActionLock(); // nicht zwischendurch painten
1886 // lcl_FillCells(xColl);
1888 if (xLock)
1889 xLock->removeActionLock(); // nicht zwischendurch painten
1891 XStarCalcViewRef xCalc = (XStarCalcView*)xInt->queryInterface(XStarCalcView::getSmartUik());
1892 if (!xCalc) return 0;
1894 return 0;
1897 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */