bump product version to 4.1.6.2
[LibreOffice.git] / sc / workben / test.cxx
blob2ec6a2fcbee18ad9299d744de214c198bc4e3068
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
53 class MyFixedText : public FixedText
55 protected:
56 void RequestHelp( const HelpEvent& rHEvt );
57 public:
58 MyFixedText(Window* pParent) : FixedText(pParent) {}
61 class MyWindow : public Window
63 private:
64 NumericField aCountField;
65 PushButton aCountButton;
66 MyFixedText aTimeText;
67 NumericField aColField;
68 NumericField aRowField;
69 NumericField aPosField;
70 NumericField aLenField;
71 Edit aTextEdit;
72 PushButton aTextButton;
73 PushButton aBlaButton;
74 PushButton aTabButton;
75 PushButton aViewButton;
77 public:
78 MyWindow( Window *pParent );
80 DECL_LINK(CountHdl, PushButton*);
81 DECL_LINK(TextHdl, PushButton*);
82 DECL_LINK(BlaHdl, PushButton*);
83 DECL_LINK(TabHdl, PushButton*);
84 DECL_LINK(ViewHdl, PushButton*);
87 //-----------------------------------------------------------------------
89 class ScTestListener : public XSelectionChangeListener, public UsrObject
91 private:
92 FixedText* pFixedText;
94 public:
95 ScTestListener(FixedText* pF);
96 virtual ~ScTestListener();
98 SMART_UNO_DECLARATION( ScTestListener, UsrObject );
100 virtual XInterface * queryInterface( UsrUik );
101 virtual XIdlClassRef getIdlClass(void);
103 virtual void disposing(const EventObject& Source);
105 // XSelectionChangeListener
106 virtual void selectionChanged(const EventObject& aEvent);
109 //-----------------------------------------------------------------------
111 static long nBla = 0;
113 static XCellRef xGlobalCell;
115 //-----------------------------------------------------------------------
117 ScTestListener::ScTestListener(FixedText* pF) :
118 pFixedText( pF )
122 ScTestListener::~ScTestListener()
126 XInterface* ScTestListener::queryInterface( UsrUik aUIK )
128 if ( aUIK == XSelectionChangeListener::getSmartUik() )
129 return (XSelectionChangeListener*) this;
131 return UsrObject::queryInterface( aUIK );
134 XIdlClassRef ScTestListener::getIdlClass(void)
136 static XIdlClassRef xClass = createStandardClass( L"ScTestListener",
137 UsrObject::getUsrObjectIdlClass(),
138 1, XSelectionChangeListener_getReflection() );
139 return xClass;
142 void ScTestListener::disposing(const EventObject& Source)
146 // XSelectionChangeListener
148 void ScTestListener::selectionChanged(const EventObject& aEvent)
150 static sal_uInt16 nBla = 0;
151 pFixedText->SetText(++nBla);
153 XInterfaceRef xInt = aEvent.Source;
154 if (!xInt) return;
155 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
156 if (!xView) return;
157 XInterfaceRef xSelInt = xView->getSelection();
158 if (!xSelInt) return;
159 XCellCollectionRef xCells = (XCellCollection*)
160 xSelInt->queryInterface(XCellCollection::getSmartUik());
161 if (!xCells) return;
163 String aStr = OUStringToString( xCells->getAddress(), CHARSET_SYSTEM );
164 pFixedText->SetText(aStr);
168 //-----------------------------------------------------------------------
170 extern "C" Window* SAL_CALL CreateWindow( Window *pParent, const String& rParam )
172 MyWindow *pWin = new MyWindow( pParent );
173 return pWin;
176 void MyFixedText::RequestHelp( const HelpEvent& rHEvt )
178 String aTxtStr=GetText();
179 Size aTxtSize=GetTextSize(aTxtStr);
180 Point aShowPoint= OutputToScreenPixel(Point(0,0));
181 if ( ( rHEvt.GetMode() & HELPMODE_QUICK ) == HELPMODE_QUICK &&
182 aTxtSize.Width()>GetSizePixel().Width())
183 Help::ShowQuickHelp( Rectangle(aShowPoint,aTxtSize), aTxtStr, QUICKHELP_TOP|QUICKHELP_LEFT );
184 else
185 FixedText::RequestHelp( rHEvt );
188 MyWindow::MyWindow( Window *pParent ) :
189 Window( pParent ),
190 aCountField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
191 aCountButton( this ),
192 aTimeText( this ),
193 aColField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
194 aRowField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
195 aPosField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
196 aLenField( this, WinBits(WB_SPIN | WB_REPEAT | WB_BORDER) ),
197 aTextEdit( this, WinBits(WB_BORDER) ),
198 aTextButton( this ),
199 aBlaButton( this ),
200 aTabButton( this ),
201 aViewButton( this )
203 aCountField.SetPosSizePixel( Point(10,10), Size(40,20) );
204 aCountField.SetValue(1);
206 aCountButton.SetPosSizePixel( Point(10,40), Size(100,30) );
207 aCountButton.SetText("hochzaehlen");
209 aTimeText.SetPosSizePixel( Point(10,80), Size(100,20) );
211 aColField.SetPosSizePixel( Point(10,120), Size(40,20) );
212 aRowField.SetPosSizePixel( Point(60,120), Size(40,20) );
213 aPosField.SetPosSizePixel( Point(10,150), Size(40,20) );
214 aLenField.SetPosSizePixel( Point(60,150), Size(40,20) );
215 aTextEdit.SetPosSizePixel( Point(10,180), Size(100,20) );
217 aTextButton.SetPosSizePixel( Point(10,210), Size(100,30) );
218 aTextButton.SetText("col/row/pos/len");
220 aBlaButton.SetPosSizePixel( Point(10,260), Size(100,30) );
221 aBlaButton.SetText("Bla");
223 aTabButton.SetPosSizePixel( Point(10,310), Size(100,30) );
224 aTabButton.SetText("Tabellen");
226 aViewButton.SetPosSizePixel( Point(10,360), Size(100,30) );
227 aViewButton.SetText("Pfui");
229 aCountButton.SetClickHdl(LINK(this, MyWindow, CountHdl));
230 aTextButton.SetClickHdl(LINK(this, MyWindow, TextHdl));
231 aBlaButton.SetClickHdl(LINK(this, MyWindow, BlaHdl));
232 aTabButton.SetClickHdl(LINK(this, MyWindow, TabHdl));
233 aViewButton.SetClickHdl(LINK(this, MyWindow, ViewHdl));
235 aCountField.Show();
236 aCountButton.Show();
237 aTimeText.Show();
238 aColField.Show();
239 aRowField.Show();
240 aPosField.Show();
241 aLenField.Show();
242 aTextEdit.Show();
243 aTextButton.Show();
244 aBlaButton.Show();
245 aTabButton.Show();
246 aViewButton.Show();
249 //-----------------------------------------------------------------------
251 XSpreadsheetDocumentRef lcl_GetDocument()
253 XServiceManagerRef xProv = getGlobalServiceManager();
254 OSL_ENSURE( xProv.is(), "Kein ServiceManager!" );
256 XServiceRegistryRef xReg = (XServiceRegistry*)xProv->queryInterface(XServiceRegistry::getSmartUik());
257 if ( !xReg )
258 return NULL;
260 Sequence<Uik> aIfaces( 1 );
261 aIfaces.getArray()[0] = XModelCollection::getSmartUik();
262 XServiceProviderRef xSSI = xProv->getServiceProvider( L"stardiv.desktop.ModelCollection",
263 aIfaces, Sequence<Uik>() );
265 XModelCollectionRef aCollRef = (XModelCollection*)
266 xSSI->newInstance()->queryInterface( XModelCollection::getSmartUik() );
267 sal_uInt16 nCount = aCollRef->getCount();
269 XSpreadsheetDocumentRef xModel; // Calc-Model
270 for (sal_uInt16 nMod=0; nMod<nCount && !xModel; nMod++) // Calc-Doc suchen
272 XModelRef aRef = aCollRef->getItemByIndex( nMod );
273 if ( aRef )
275 aRef->acquire();
276 xModel = (XSpreadsheetDocument*) aRef->queryInterface( XSpreadsheetDocument::getSmartUik() );
277 aRef->release();
280 return xModel;
283 XInterfaceRef lcl_GetView()
285 XInterfaceRef xView;
286 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
287 if (xDoc)
288 xView = xDoc->getDDELinks(); //! temporaer zum Testen !!!!!!!!!
290 return xView;
293 //-----------------------------------------------------------------------
295 void lcl_OutputNames( const XInterfaceRef& xSource, // XNameAccess
296 const XSpreadsheetDocumentRef& xDoc,
297 sal_uInt16 nCol, sal_uInt16 nRow, sal_uInt16 nTab )
299 CellAddress aAdr;
300 aAdr.Sheet = nTab;
301 aAdr.Column = nCol;
302 aAdr.Row = nRow;
304 XNameAccessRef xNames = (XNameAccess*)xSource->queryInterface(XNameAccess::getSmartUik());
305 if (!xNames) return;
306 Sequence<UString> aSeq = xNames->getElementNames();
308 sal_uInt16 nLen = (sal_uInt16)aSeq.getLen();
310 XCellRef xCell = xDoc->getCell(aAdr);
311 if (!xCell) return;
312 xCell->setValue( nLen );
313 ++aAdr.Row;
315 UString* pAry = aSeq.getArray();
316 for (sal_uInt16 i=0; i<nLen; i++)
318 xCell = xDoc->getCell(aAdr);
319 if (!xCell) return;
320 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
321 if (!xText) return;
322 xText->setText( pAry[i] );
323 ++aAdr.Row;
327 //-----------------------------------------------------------------------
329 void lcl_SetText( const XTextRef& xText )
331 if (!xText.is()) return;
332 XTextCursorRef xCursor = xText->createTextCursor();
333 if (!xCursor.is()) return;
334 XTextPositionRef xPos = (XTextPosition*)xCursor->queryInterface(XTextPosition::getSmartUik());
335 XPropertySetRef xProp = (XPropertySet*)xCursor->queryInterface(XPropertySet::getSmartUik());
336 XControlCharacterInsertableRef xControl = (XControlCharacterInsertable*)
337 xCursor->queryInterface(XControlCharacterInsertable::getSmartUik());
338 XParagraphCursorRef xPara = (XParagraphCursor*)
339 xCursor->queryInterface(XParagraphCursor::getSmartUik());
341 if (!xPos.is() || !xControl.is() || !xPara.is()) return; // PropertySet kann fehlen
343 xText->setText(L"bla fasel");
344 xCursor->gotoEnd(false);
345 xControl->insertControlCharacter( TEXTCONTROLCHAR_PARAGRAPH_BREAK );
346 xPos->collapseToEnd();
347 xPos->setText(L"s\xFClz"); // zweiter Absatz
349 xCursor->gotoStart(false);
350 xPara->gotoEndOfParagraph(false);
351 xCursor->goLeft(5, true); // letzte 5 Zeichen im 1. Absatz
352 if (xProp.is())
353 xProp->setPropertyValue(L"Bold", UsrAny((sal_Bool)true));
356 //-----------------------------------------------------------------------
358 void lcl_DoCount()
360 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
361 if (xDoc)
363 XActionLockableRef xLock = (XActionLockable*)
364 xDoc->queryInterface(XActionLockable::getSmartUik());
365 XCalculateRef xCalc = (XCalculate*)
366 xDoc->queryInterface(XCalculate::getSmartUik());
367 if (xLock)
368 xLock->addActionLock(); // nicht zwischendurch painten
369 if (xCalc)
370 xCalc->setAutomaticCalculation(false);
372 CellAddress aPos;
373 aPos.Sheet = 0;
375 for (sal_uInt16 nRow = 0; nRow < 20; nRow++)
377 aPos.Row = nRow;
378 for (sal_uInt16 nCol = 0; nCol < 10; nCol++)
380 aPos.Column = nCol;
381 XCellRef xCell = xDoc->getCell(aPos);
382 if ( xCell )
384 // Wert der Zelle um 1 hochzaehlen
386 double fVal = xCell->getValue();
387 fVal += 1.0;
388 xCell->setValue( fVal );
393 if (xCalc)
394 xCalc->setAutomaticCalculation(true);
395 if (xLock)
396 xLock->removeActionLock();
401 void lcl_GlobalCell()
403 if ( xGlobalCell )
405 String aStr = OUStringToString( xGlobalCell->getFormula(), CHARSET_SYSTEM );
406 aStr+='0';
407 xGlobalCell->setFormula( StringToOUString( aStr, CHARSET_SYSTEM ) );
412 void lcl_Annotations( FixedText& aTimeText )
414 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
415 if (xDoc)
417 CellAddress aPos;
418 aPos.Sheet = 0;
419 aPos.Column = 1;
420 aPos.Row = 2;
421 XCellRef xCell = xDoc->getCell(aPos);
422 if ( xCell )
424 XSheetAnnotationAnchorRef xAnchor =
425 (XSheetAnnotationAnchor*)xCell->queryInterface(XSheetAnnotationAnchor::getSmartUik());
426 if ( xAnchor )
428 XSheetAnnotationRef xAnnotation = xAnchor->getAnnotation();
429 if ( xAnnotation )
431 String aBlubb = OUStringToString( xAnnotation->getAuthor(), CHARSET_SYSTEM )+
432 String(" - ")+
433 OUStringToString( xAnnotation->getDate(), CHARSET_SYSTEM );
434 aTimeText.SetText(aBlubb);
436 XTextRef xAnnotationText =
437 (XText*)xAnnotation->queryInterface(XText::getSmartUik());
438 if ( xAnnotationText )
440 XTextCursorRef xCursor = xAnnotationText->createTextCursor();
441 if (xCursor)
443 XTextPositionRef xPos = (XTextPosition*)
444 xCursor->queryInterface(XTextPosition::getSmartUik());
445 XControlCharacterInsertableRef xControl = (XControlCharacterInsertable*)
446 xCursor->queryInterface(XControlCharacterInsertable::getSmartUik());
448 if (xPos && xControl)
450 sal_uLong nStart = Time::GetSystemTicks();
452 xAnnotationText->setText(L"bla");
453 xCursor->gotoEnd(false);
454 xCursor->goLeft(1,true);
455 xPos->setText(L"ubb");
456 for (sal_uInt16 i=0; i<10; i++)
458 xPos->collapseToEnd();
459 xControl->insertControlCharacter( TEXTCONTROLCHAR_PARAGRAPH_BREAK );
460 xPos->collapseToEnd();
461 xPos->setText(L"dumdi");
464 sal_uLong nEnd = Time::GetSystemTicks();
465 aTimeText.SetText(String(nEnd-nStart)+String(" ms"));
476 void lcl_Cursor( FixedText& aTimeText )
478 aTimeText.SetText( "..." );
479 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
480 if (xDoc)
482 XActionLockableRef xLock = (XActionLockable*)
483 xDoc->queryInterface(XActionLockable::getSmartUik());
484 if (xLock)
485 xLock->addActionLock();
487 CellAddress aPos;
488 aPos.Sheet = 0;
489 aPos.Column = 1;
490 aPos.Row = 2;
491 XCellRef xCell = xDoc->getCell(aPos);
492 if ( xCell )
494 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
495 XCellCollectionRef xColl = (XCellCollection*)xCell->queryInterface(XCellCollection::getSmartUik());
496 if ( xText && xColl )
498 xText->setText(L"bla");
499 XLineCursorRef xCursor = xColl->createCursor();
500 if ( xCursor )
502 XCellCursorRef xCC = (XCellCursor*)xCursor->queryInterface(XCellCursor::getSmartUik());
503 XCellRangesCursorRef xRC = (XCellRangesCursor*)
504 xCursor->queryInterface(XCellRangesCursor::getSmartUik());
506 if ( xCC && xRC )
508 xCursor->goDown( 1, false );
510 xColl = xCC->getRanges();
511 if ( xColl )
513 // XText ist drin, wenn's ne einzelne Zelle ist
514 xText = (XText*)xColl->queryInterface(XText::getSmartUik());
515 if ( xText )
517 xText->setText(L"fasel");
521 CellRangeAddress aSecond;
522 aSecond.Sheet = 0;
523 aSecond.StartColumn = 3;
524 aSecond.StartRow = 4;
525 aSecond.EndColumn = 3;
526 aSecond.EndRow = 4;
527 xRC->gotoUnion(aSecond);
529 xColl = xCC->getRanges();
530 if ( xColl )
532 XPropertySetRef xProp = (XPropertySet*)
533 xColl->queryInterface(XPropertySet::getSmartUik());
534 if ( xProp )
536 UsrAny aAny;
538 aAny = xProp->getPropertyValue(L"ShadowFormat");
539 if ( aAny.getReflection()->getName() ==
540 ShadowFormat_getReflection()->getName() )
542 //ShadowFormat* pOld = (ShadowFormat*)aAny.get();
543 ShadowFormat aNew;
544 aNew.Location = SHADOWLOCATION_BOTTOMRIGHT;
545 aNew.ShadowWidth = 100;
546 aNew.IsTransparent = false;
547 aNew.Color = 0xff0000L;
548 aAny.set( &aNew, aAny.getReflection() );
549 xProp->setPropertyValue(L"ShadowFormat", aAny);
552 aAny = xProp->getPropertyValue(L"RotationValue");
553 aAny.setINT32(4500);
554 xProp->setPropertyValue(L"RotationValue", aAny);
556 aAny = xProp->getPropertyValue(L"FontHeight");
557 aAny.setUINT32(280);
558 xProp->setPropertyValue(L"FontHeight", aAny);
560 aAny = xProp->getPropertyValue(L"TransparentBackground");
561 aAny.setBOOL(false);
562 xProp->setPropertyValue(L"TransparentBackground", aAny);
564 aAny = xProp->getPropertyValue(L"BackgroundColor");
565 aAny.setUINT32(0xffff00);
566 xProp->setPropertyValue(L"BackgroundColor", aAny);
568 aAny = xProp->getPropertyValue(L"CellProtection");
569 if ( aAny.getReflection()->getName() ==
570 CellProtection_getReflection()->getName() )
572 //CellProtection* pOld = (CellProtection*)aAny.get();
573 CellProtection aNew;
574 aNew.Locked = false;
575 aNew.FormulaHidden = false;
576 aNew.Hidden = false;
577 aNew.PrintHidden = false;
578 aAny.set( &aNew, aAny.getReflection() );
579 xProp->setPropertyValue(L"CellProtection", aAny);
583 // XIndexAccess gibts nur wenn's mehrere sind (??!??!)
584 XIndexAccessRef xIndex = (XIndexAccess*)
585 xColl->queryInterface(XIndexAccess::getSmartUik());
586 if ( xIndex )
588 sal_uInt16 nCount = (sal_uInt16)xIndex->getCount();
589 aTimeText.SetText( String(nCount) );
597 if (xLock)
598 xLock->removeActionLock();
603 void lcl_Cells( FixedText& aTimeText )
605 aTimeText.SetText( "..." );
606 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
607 if (xDoc)
609 long nCount = 0;
610 sal_uLong nStart = Time::GetSystemTicks();
612 XActionLockableRef xLock = (XActionLockable*)
613 xDoc->queryInterface(XActionLockable::getSmartUik());
614 // if (xLock)
615 // xLock->addActionLock();
617 CellRangeAddress aRngAddr;
618 aRngAddr.Sheet = 0;
619 aRngAddr.StartColumn = 0;
620 aRngAddr.StartRow = 0;
621 aRngAddr.EndColumn = 9;
622 aRngAddr.EndRow = 19;
623 XCellRangeRef xRange = xDoc->getCellRange(aRngAddr);
624 if (xRange)
626 XCellCollectionRef xColl = (XCellCollection*)
627 xRange->queryInterface(XCellCollection::getSmartUik());
628 if (xColl)
630 XEnumerationAccessRef xEnAcc = xColl->getCells();
631 if (xEnAcc)
633 XEnumerationRef xEnum = xEnAcc->getEnumeration();
634 if (xEnum)
636 while (xEnum->hasMoreElements())
638 XInterfaceRef xInt = xEnum->nextElement();
639 if (xInt)
641 ++nCount;
649 sal_uLong nEnd = Time::GetSystemTicks();
650 aTimeText.SetText(String(nCount)+String(" ")+String(nEnd-nStart)+String(" ms"));
653 // if (xLock)
654 // xLock->removeActionLock();
658 void lcl_Sheet( FixedText& aTimeText )
660 aTimeText.SetText( "..." );
661 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
662 if (!xDoc) return;
663 XSpreadsheetsRef xSheets = xDoc->getSheets();
664 if (!xSheets) return;
665 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
666 if (!xSheet) return;
667 XNamedRef xNamed = (XNamed*)xSheet->queryInterface(XNamed::getSmartUik());
668 if (!xNamed) return;
670 String aName = OUStringToString( xNamed->getName(), CHARSET_SYSTEM );
671 aName += 'X';
672 xNamed->setName(StringToOUString( aName, CHARSET_SYSTEM ));
674 XCellRangeRef xRange = (XCellRange*)xSheet->queryInterface(XCellRange::getSmartUik());
675 if (!xRange) return;
676 XCellRef xCell = xRange->getCell(2,1);
677 if (!xCell) return;
678 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
679 if (!xText) return;
680 String aBla = OUStringToString( xText->getText(), CHARSET_SYSTEM );
681 aBla += "bla";
682 xText->setText(StringToOUString( aBla, CHARSET_SYSTEM ));
684 XColumnRowRangeRef xCRR = (XColumnRowRange*)xSheet->queryInterface(XColumnRowRange::getSmartUik());
685 if (!xCRR) return;
687 XTableColumnsRef xCols = xCRR->getColumns();
688 if (!xCols) return;
689 XPropertySetRef xCol = xCols->getColumnByIndex(2);
690 if (!xCol) return;
692 UINT16 nWidth = TypeConversion::toUINT16(xCol->getPropertyValue(L"Width"));
693 // UINT16 nNewWidth = nWidth + 100;
694 // xCol->setPropertyValue(L"Width", UsrAny(nNewWidth));
696 xCol->setPropertyValue(L"OptimalWidth", UsrAny((sal_Bool)true));
697 xCol->setPropertyValue(L"NewPage", UsrAny((sal_Bool)false));
699 UsrAny aAny = xCol->getPropertyValue(L"ShadowFormat");
700 if ( aAny.getReflection()->getName() ==
701 ShadowFormat_getReflection()->getName() )
703 //ShadowFormat* pOld = (ShadowFormat*)aAny.get();
704 ShadowFormat aNew;
705 aNew.Location = SHADOWLOCATION_BOTTOMRIGHT;
706 aNew.ShadowWidth = 100;
707 aNew.IsTransparent = false;
708 aNew.Color = 0xff0000L;
709 aAny.set( &aNew, aAny.getReflection() );
710 xCol->setPropertyValue(L"ShadowFormat", aAny);
713 XTableRowsRef xRows = xCRR->getRows();
714 if (!xRows) return;
715 XPropertySetRef xRow = xRows->getRowByIndex(1);
716 if (!xRow) return;
718 xRows->removeRowsByIndex( 2, 1 );
720 UINT16 nHeight = TypeConversion::toUINT16(xRow->getPropertyValue(L"Height"));
721 sal_Bool bOptH = TypeConversion::toBOOL(xRow->getPropertyValue(L"OptimalHeight"));
723 UINT16 nNewHeight = nHeight + 100;
724 xRow->setPropertyValue(L"Height", UsrAny(nNewHeight));
726 aTimeText.SetText(String("W:")+String(nWidth)+String(" H:")+String(nHeight)+
727 String(" ")+String((sal_uInt16)bOptH));
730 void lcl_Names( FixedText& aTimeText )
732 aTimeText.SetText( "..." );
733 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
734 if (!xDoc) return;
735 XNamedRangesRef xNames = xDoc->getNamedRanges();
736 if (!xNames) return;
737 XNamedRangeRef xName = xNames->getRangeByName(L"bla");
738 if (!xName) return;
739 String aCont = OUStringToString( xName->getContent(), CHARSET_SYSTEM );
740 aTimeText.SetText(aCont);
742 XCellRangeSourceRef xSource = (XCellRangeSource*)
743 xName->queryInterface(XCellRangeSource::getSmartUik());
744 if (!xSource) return;
745 XCellRangeRef xRange = xSource->getReferredCells();
746 if (!xRange) return;
747 XPropertySetRef xProp = (XPropertySet*)xRange->queryInterface(XPropertySet::getSmartUik());
748 if (!xProp) return;
749 UsrAny aAny = xProp->getPropertyValue(L"RotationValue");
750 aAny.setINT32(3000);
751 xProp->setPropertyValue(L"RotationValue", aAny);
754 void lcl_Sheets( FixedText& aTimeText )
756 aTimeText.SetText( "..." );
757 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
758 if (!xDoc) return;
759 XSpreadsheetsRef xSheets = xDoc->getSheets();
760 if (!xSheets) return;
762 xSheets->moveSheet(0, 1, true);
763 xSheets->moveSheet(0, 2, false);
766 void lcl_Goal( FixedText& aTimeText )
768 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
769 if (!xDoc) return;
770 XGoalSeekRef xGoal = (XGoalSeek*)xDoc->queryInterface(XGoalSeek::getSmartUik());
771 if (!xGoal) return;
773 double fResult;
774 CellAddress aFormula; // A1
775 aFormula.Sheet = 0;
776 aFormula.Column = 0;
777 aFormula.Row = 0;
778 CellAddress aVar; // A2
779 aVar.Sheet = 0;
780 aVar.Column = 0;
781 aVar.Row = 1;
782 sal_Bool bFound = xGoal->doGoalSeek(fResult, aFormula, aVar, L"42");
784 if (bFound)
786 CellAddress aOut; // A3
787 aOut.Sheet = 0;
788 aOut.Column = 0;
789 aOut.Row = 2;
791 XCellRef xCell = xDoc->getCell(aOut);
792 if (!xCell) return;
793 xCell->setValue(fResult);
797 void lcl_TabOp( FixedText& aTimeText )
799 // Mehrfachoperation auf Tabelle2
800 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
801 if (!xDoc) return;
803 XCellRangeRef xRange;
804 XTableOperationRef xGoal;
805 CellRangeAddress aRangeAddr;
806 CellRangeAddress aFormulaRange;
807 CellAddress aColumnCell;
808 CellAddress aRowCell;
809 TableOperationMode nMode;
811 aRangeAddr.Sheet = 1; // c9:e11
812 aRangeAddr.StartColumn = 2;
813 aRangeAddr.StartRow = 8;
814 aRangeAddr.EndColumn = 4;
815 aRangeAddr.EndRow = 10;
816 aFormulaRange.Sheet = 1; // c6:c7
817 aFormulaRange.StartColumn = 2;
818 aFormulaRange.StartRow = 5;
819 aFormulaRange.EndColumn = 2;
820 aFormulaRange.EndRow = 6;
821 aColumnCell.Sheet = 0; // nicht benutzt
822 aColumnCell.Column = 0;
823 aColumnCell.Row = 0;
824 aRowCell.Sheet = 1; // c5
825 aRowCell.Column = 2;
826 aRowCell.Row = 4;
827 nMode = TABLEOP_ROW;
829 xRange = xDoc->getCellRange(aRangeAddr);
830 if (!xRange) return;
831 xGoal = (XTableOperation*)xRange->queryInterface(XTableOperation::getSmartUik());
832 if (!xGoal) return;
833 xGoal->setTableOperation( nMode, aFormulaRange, aColumnCell, aRowCell );
835 aRangeAddr.Sheet = 1; // b19:d21
836 aRangeAddr.StartColumn = 1;
837 aRangeAddr.StartRow = 18;
838 aRangeAddr.EndColumn = 3;
839 aRangeAddr.EndRow = 20;
840 aFormulaRange.Sheet = 1; // c16:d16
841 aFormulaRange.StartColumn = 2;
842 aFormulaRange.StartRow = 15;
843 aFormulaRange.EndColumn = 3;
844 aFormulaRange.EndRow = 15;
845 aColumnCell.Sheet = 1; // b16
846 aColumnCell.Column = 1;
847 aColumnCell.Row = 15;
848 aRowCell.Sheet = 0; // nicht benutzt
849 aRowCell.Column = 0;
850 aRowCell.Row = 0;
851 nMode = TABLEOP_COLUMN;
853 xRange = xDoc->getCellRange(aRangeAddr);
854 if (!xRange) return;
855 xGoal = (XTableOperation*)xRange->queryInterface(XTableOperation::getSmartUik());
856 if (!xGoal) return;
857 xGoal->setTableOperation( nMode, aFormulaRange, aColumnCell, aRowCell );
859 aRangeAddr.Sheet = 1; // b29:e32
860 aRangeAddr.StartColumn = 1;
861 aRangeAddr.StartRow = 28;
862 aRangeAddr.EndColumn = 4;
863 aRangeAddr.EndRow = 31;
864 aFormulaRange.Sheet = 1; // c27:c27
865 aFormulaRange.StartColumn = 2;
866 aFormulaRange.StartRow = 26;
867 aFormulaRange.EndColumn = 2;
868 aFormulaRange.EndRow = 26;
869 aColumnCell.Sheet = 1; // c25
870 aColumnCell.Column = 2;
871 aColumnCell.Row = 24;
872 aRowCell.Sheet = 1; // c26
873 aRowCell.Column = 2;
874 aRowCell.Row = 25;
875 nMode = TABLEOP_BOTH;
877 xRange = xDoc->getCellRange(aRangeAddr);
878 if (!xRange) return;
879 xGoal = (XTableOperation*)xRange->queryInterface(XTableOperation::getSmartUik());
880 if (!xGoal) return;
881 xGoal->setTableOperation( nMode, aFormulaRange, aColumnCell, aRowCell );
884 void lcl_Fill( FixedText& aTimeText )
886 XInterfaceRef xInt = lcl_GetView();
887 if (!xInt) return;
888 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
889 if (!xView) return;
891 XInterfaceRef xSelInt = xView->getSelection();
892 if (!xSelInt) return;
894 XCellSeriesRef xFill = (XCellSeries*)xSelInt->queryInterface(XCellSeries::getSmartUik());
895 if (!xFill) return;
897 // xFill->fillAuto( FILL_DIRECTION_TO_BOTTOM, 2 );
899 xFill->fillSeries( FILL_DIRECTION_TO_LEFT, FILL_MODE_GROWTH, FILL_DATE_DAY,
900 2.0, 1000.0 );
903 void lcl_Audi( FixedText& aTimeText )
905 aTimeText.SetText( "..." );
906 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
907 if (!xDoc) return;
908 XSpreadsheetsRef xSheets = xDoc->getSheets();
909 if (!xSheets) return;
910 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
911 if (!xSheet) return;
913 XSheetAuditingRef xAudi = (XSheetAuditing*)xSheet->queryInterface(XSheetAuditing::getSmartUik());
914 if (!xAudi) return;
916 CellAddress aPosition;
917 aPosition.Sheet = 0;
918 aPosition.Column = 0;
919 aPosition.Row = 0;
920 xAudi->showDependents(aPosition);
923 void lcl_Consoli( FixedText& aTimeText )
925 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
926 if (!xDoc) return;
927 XConsolidationRef xCons = (XConsolidation*)xDoc->queryInterface(XConsolidation::getSmartUik());
928 if (!xCons) return;
929 XConsolidationDescriptorRef xDesc = xCons->createConsolidationDescriptor(false);
930 if (!xDesc) return;
931 xDesc->setFunction(SUMMARY_COUNTNUMS);
932 xCons->consolidate(xDesc);
935 void lcl_Sort( FixedText& aTimeText )
937 XInterfaceRef xInt = lcl_GetView();
938 if (!xInt) return;
939 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
940 if (!xView) return;
941 XInterfaceRef xSelInt = xView->getSelection();
942 if (!xSelInt) return;
943 XSortableRef xSort = (XSortable*)xSelInt->queryInterface(XSortable::getSmartUik());
944 if (!xSort) return;
945 XSortDescriptorRef xDesc = xSort->createSortDescriptor(false);
946 if (!xDesc) return;
947 Sequence<SortField> aFields = xDesc->getSortFields();
948 if (aFields.getLen())
950 // 1.Feld umkehren
951 SortField* pAry = aFields.getArray();
952 if (!pAry) return;
953 pAry[0].Ascending = !pAry[0].Ascending;
955 else // neue Sequence, 1. Spalte aufsteigend
957 aFields = Sequence<SortField>(1);
958 SortField* pAry = aFields.getArray();
959 if (!pAry) return;
960 pAry[0].Field = 0;
961 pAry[0].Ascending = true;
962 pAry[0].Type = SORT_FIELD_AUTOMATIC;
964 xDesc->setSortFields(aFields);
966 XTableSortDescriptorRef xTableSort = (XTableSortDescriptor*)
967 xDesc->queryInterface(XTableSortDescriptor::getSmartUik());
968 if (!xTableSort) return;
969 CellAddress aOutPos;
970 aOutPos.Sheet = 2;
971 aOutPos.Column = 0;
972 aOutPos.Row = 0;
973 xTableSort->setUseOutputPosition(true);
974 xTableSort->setOutputPosition(aOutPos);
976 XPropertySetRef xPropSet = (XPropertySet*)
977 xDesc->queryInterface(XPropertySet::getSmartUik());
978 if (!xPropSet) return;
979 xPropSet->setPropertyValue(L"IncludeFormats", UsrAny((sal_Bool)false));
981 xSort->sort(xDesc);
984 void lcl_Filter( FixedText& aTimeText )
986 aTimeText.SetText("...");
988 XInterfaceRef xInt = lcl_GetView();
989 if (!xInt) return;
990 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
991 if (!xView) return;
992 XInterfaceRef xSelInt = xView->getSelection();
993 if (!xSelInt) return;
994 XFilterableRef xFilter = (XFilterable*)xSelInt->queryInterface(XFilterable::getSmartUik());
995 if (!xFilter) return;
997 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
998 if (!xDoc) return;
999 CellRangeAddress aAddress;
1000 aAddress.Sheet = 3;
1001 aAddress.StartColumn = 0;
1002 aAddress.StartRow = 0;
1003 aAddress.EndColumn = 1;
1004 aAddress.EndRow = 2;
1005 XCellRangeRef xRange = xDoc->getCellRange(aAddress);
1006 if (!xRange) return;
1007 XAdvancedFilterSourceRef xSource = (XAdvancedFilterSource*)
1008 xRange->queryInterface(XAdvancedFilterSource::getSmartUik());
1009 if (!xSource) return;
1011 XTableFilterDescriptorRef xDesc = xSource->createAdvancedFilter(xFilter);
1012 if (!xDesc)
1014 aTimeText.SetText("kein Filter");
1015 return;
1017 aTimeText.SetText("Filter gefunden");
1018 xFilter->filter(xDesc);
1021 void lcl_AutoFilter( FixedText& aTimeText )
1023 XInterfaceRef xInt = lcl_GetView();
1024 if (!xInt) return;
1025 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1026 if (!xView) return;
1027 XInterfaceRef xSelInt = xView->getSelection();
1028 if (!xSelInt) return;
1029 XFilterableRef xFilter = (XFilterable*)xSelInt->queryInterface(XFilterable::getSmartUik());
1030 if (!xFilter) return;
1032 sal_Bool bAuto = xFilter->getAutoFilter();
1033 xFilter->setAutoFilter(!bAuto);
1036 void lcl_Merge( FixedText& aTimeText )
1038 static sal_Bool bMerged = false;
1040 XInterfaceRef xInt = lcl_GetView();
1041 if (!xInt) return;
1042 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1043 if (!xView) return;
1044 XInterfaceRef xSelInt = xView->getSelection();
1045 if (!xSelInt) return;
1046 XMergeableRef xMerge = (XMergeable*)xSelInt->queryInterface(XMergeable::getSmartUik());
1047 if (!xMerge) return;
1049 if (bMerged)
1050 xMerge->unmergeCells();
1051 else
1052 xMerge->mergeCells();
1053 bMerged = !bMerged;
1056 void lcl_Outline( FixedText& aTimeText )
1058 static sal_Bool bOutline = false;
1060 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1061 if (!xDoc) return;
1062 XSpreadsheetsRef xSheets = xDoc->getSheets();
1063 if (!xSheets) return;
1064 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
1065 if (!xSheet) return;
1066 XSheetOutlineRef xOut = (XSheetOutline*)xSheet->queryInterface(XSheetOutline::getSmartUik());
1067 if (!xOut) return;
1069 XInterfaceRef xInt = lcl_GetView();
1070 if (!xInt) return;
1071 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1072 if (!xView) return;
1073 XInterfaceRef xSelInt = xView->getSelection();
1074 if (!xSelInt) return;
1075 XAddressableCellRangeRef xRange = (XAddressableCellRange*)
1076 xSelInt->queryInterface(XAddressableCellRange::getSmartUik());
1077 if (!xRange) return;
1078 CellRangeAddress aRange = xRange->getRangeAddress();
1080 if (bOutline)
1081 xOut->showDetail( aRange );
1082 else
1083 xOut->hideDetail( aRange );
1085 bOutline = !bOutline;
1088 void lcl_Bla( FixedText& aTimeText )
1090 aTimeText.SetText("...");
1092 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1093 if (!xDoc) return;
1094 XActionLockableRef xLock = (XActionLockable*)xDoc->queryInterface(XActionLockable::getSmartUik());
1095 if (!xLock) return;
1096 xLock->addActionLock();
1097 xLock->addActionLock();
1098 sal_uInt16 nCount = xLock->resetActionLocks(); // sollte 2 sein
1099 String aBla = nCount;
1100 xLock->setActionLocks(nCount);
1101 xLock->removeActionLock();
1102 xLock->removeActionLock();
1104 aBla += '/'; aBla += xLock->resetActionLocks(); // sollte 0 sein
1106 aTimeText.SetText(aBla);
1109 void lcl_CellCursor( FixedText& aTimeText )
1111 static int nCursorCount = 0;
1113 XInterfaceRef xInt = lcl_GetView();
1114 if (!xInt) return;
1115 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1116 if (!xView) return;
1117 XInterfaceRef xSelInt = xView->getSelection();
1118 if (!xSelInt) return;
1119 XCellCollectionRef xColl = (XCellCollection*)xSelInt->queryInterface(XCellCollection::getSmartUik());
1120 if (!xColl) return;
1122 XLineCursorRef xCursor = xColl->createCursor();
1123 if (!xCursor) return;
1124 XCellCursorRef xCC = (XCellCursor*)xCursor->queryInterface(XCellCursor::getSmartUik());
1125 if (!xCC) return;
1126 XCellRangesCursorRef xCRC = (XCellRangesCursor*)xCursor->queryInterface(XCellRangesCursor::getSmartUik());
1127 if (!xCRC) return;
1128 XCellRangeCursorRef xCR = (XCellRangeCursor*)xCursor->queryInterface(XCellRangeCursor::getSmartUik());
1129 if (!xCR) return;
1130 XCellContentCursorRef xCCC = (XCellContentCursor*)xCursor->queryInterface(XCellContentCursor::getSmartUik());
1131 if (!xCCC) return;
1132 XFormulaCursorRef xFC = (XFormulaCursor*)xCursor->queryInterface(XFormulaCursor::getSmartUik());
1133 if (!xFC) return;
1135 CellAddress aPos;
1136 aPos.Sheet = 0; // ignored
1137 aPos.Row = 3;
1138 aPos.Column = 2;
1140 switch (nCursorCount++)
1142 case 0:
1143 xFC->gotoDependents(false);
1144 break;
1145 case 1:
1146 xFC->gotoDependents(true);
1147 break;
1148 case 2:
1149 xFC->gotoPrecedents(false);
1150 break;
1151 case 3:
1152 xFC->gotoPrecedents(true);
1154 nCursorCount = 0;
1155 break;
1158 XCellCollectionRef xNew = xCC->getRanges();
1159 if (!xNew) return;
1160 xView->select( xNew );
1163 void lcl_Notes( FixedText& aTimeText )
1165 aTimeText.SetText( "..." );
1166 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1167 if (!xDoc) return;
1168 XSpreadsheetsRef xSheets = xDoc->getSheets();
1169 if (!xSheets) return;
1170 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
1171 if (!xSheet) return;
1173 XSheetAnnotationsRef xNotes = xSheet->getAnnotations();
1174 if (!xNotes) return;
1175 XIndexAccessRef xNIndex = (XIndexAccess*)xNotes->queryInterface(XIndexAccess::getSmartUik());
1176 if (!xNIndex) return;
1178 CellAddress aPos;
1179 aPos.Column = 0;
1180 aPos.Row = 0;
1181 aPos.Sheet = 0;
1182 xNotes->addAnnotation( L"neu", aPos );
1184 sal_uLong nCount = xNIndex->getCount();
1185 for (sal_uLong i=0; i<nCount; i++)
1187 XSheetAnnotationRef xAnn = xNotes->getAnnotationByIndex((UINT16)i);
1188 XTextRef xText = (XText*)xAnn->queryInterface(XText::getSmartUik());
1189 if (xText)
1191 String aStr = OUStringToString( xText->getText(), CHARSET_SYSTEM );
1192 aStr += "x";
1193 xText->setText(StringToOUString( aStr, CHARSET_SYSTEM ));
1198 void lcl_Scenario( FixedText& aTimeText )
1200 aTimeText.SetText( "..." );
1201 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1202 if (!xDoc) return;
1203 XSpreadsheetsRef xSheets = xDoc->getSheets();
1204 if (!xSheets) return;
1205 XTableSheetRef xSheet = xSheets->getSheetByIndex(0);
1206 if (!xSheet) return;
1208 XScenariosRef xColl = xSheet->getScenarios();
1209 if (!xColl) return;
1211 Sequence<CellRangeAddress> aRanges(2);
1212 CellRangeAddress* pAry = aRanges.getArray();
1213 if (!pAry) return;
1214 pAry[0].Sheet = 0;
1215 pAry[0].StartColumn = 0;
1216 pAry[0].StartRow = 0;
1217 pAry[0].EndColumn = 1;
1218 pAry[0].EndRow = 1;
1219 pAry[1].Sheet = 0;
1220 pAry[1].StartColumn = 3;
1221 pAry[1].StartRow = 3;
1222 pAry[1].EndColumn = 4;
1223 pAry[1].EndRow = 4;
1225 xColl->addScenario( aRanges, L"bla", L"bla blubb" );
1227 XIndexAccessRef xIndex = (XIndexAccess*)xColl->queryInterface(XIndexAccess::getSmartUik());
1228 if (!xIndex) return;
1229 sal_uLong nCount = xIndex->getCount();
1230 aTimeText.SetText( nCount );
1232 XScenarioRef xScen = xColl->getScenarioByIndex(0);
1233 if (!xScen) return;
1235 aRanges = Sequence<CellRangeAddress>(1);
1236 pAry = aRanges.getArray();
1237 if (!pAry) return;
1238 pAry[0].Sheet = 0;
1239 pAry[0].StartColumn = 6;
1240 pAry[0].StartRow = 6;
1241 pAry[0].EndColumn = 7;
1242 pAry[0].EndRow = 7;
1244 xScen->addRanges( aRanges );
1246 XTableSheetRef xSh2 = xSheets->getSheetByIndex(1);
1247 if (!xSh2) return;
1249 xSh2->setVisible( true );
1250 xSh2->setVisible( false );
1253 void lcl_Formula( FixedText& aTimeText )
1255 aTimeText.SetText("...");
1257 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1258 if (!xDoc) return;
1259 CellAddress aPos;
1260 aPos.Sheet = 0;
1261 aPos.Column = 0;
1262 aPos.Row = 0;
1263 XCellRef xCell = xDoc->getCell(aPos);
1264 if (!xCell) return;
1266 // String aStr = OUStringToString( xCell->getFormula(), CHARSET_SYSTEM );
1267 // aTimeText.SetText(aStr);
1269 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
1270 if (!xText) return;
1271 String aStr = OUStringToString( xText->getText(), CHARSET_SYSTEM );
1272 aTimeText.SetText(aStr);
1275 void lcl_DBRange( FixedText& aTimeText ) // 23
1277 aTimeText.SetText("...");
1279 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1280 if (!xDoc) return;
1281 XDatabaseRangesRef xDBs = xDoc->getDatabaseRanges();
1282 if (!xDBs) return;
1284 CellRangeAddress aRange;
1285 aRange.Sheet = 0;
1286 aRange.StartColumn = 1;
1287 aRange.StartRow = 1;
1288 aRange.EndColumn = 3;
1289 aRange.EndRow = 10;
1291 xDBs->addRange( L"blubb", aRange );
1293 xDBs->removeRangeByName( L"gaga" );
1295 XDatabaseRangeRef xDB = xDBs->getRangeByName( L"blubb" );
1296 if (!xDB) return;
1298 String aName = OUStringToString( xDB->getName(), CHARSET_SYSTEM );
1299 aTimeText.SetText(aName);
1301 xDB->setName( L"gaga" );
1303 CellRangeAddress aDBRange = xDB->getDataArea();
1304 ++aDBRange.Sheet;
1305 xDB->setDataArea(aDBRange);
1308 void lcl_FillTab( FixedText& aTimeText ) // 24
1310 aTimeText.SetText("...");
1312 XInterfaceRef xInt = lcl_GetView();
1313 if (!xInt) return;
1314 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1315 if (!xView) return;
1316 XInterfaceRef xSelInt = xView->getSelection();
1317 if (!xSelInt) return;
1319 XCellRangesRef xRanges = (XCellRanges*)xSelInt->queryInterface(XCellRanges::getSmartUik());
1320 XIndexAccessRef xIndex = (XIndexAccess*)xSelInt->queryInterface(XIndexAccess::getSmartUik());
1321 if (!xRanges || !xIndex) return;
1323 sal_uLong nCount = xIndex->getCount();
1324 aTimeText.SetText(nCount);
1327 void lcl_Listener( FixedText& aTimeText ) // 25
1329 XInterfaceRef xInt = lcl_GetView();
1330 if (!xInt) return;
1331 XStarCalcViewRef xView = (XStarCalcView*)xInt->queryInterface(XStarCalcView::getSmartUik());
1332 if (!xView) return;
1333 xView->addSelectionChangeListener( new ScTestListener(&aTimeText) );
1336 void lcl_CellAttrib( FixedText& aTimeText ) // 26
1338 XInterfaceRef xInt = lcl_GetView();
1339 if (!xInt) return;
1340 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1341 if (!xView) return;
1342 XInterfaceRef xSelInt = xView->getSelection();
1343 if (!xSelInt) return;
1344 XTextRef xText = (XText*)xSelInt->queryInterface(XText::getSmartUik());
1345 if (!xText) return;
1347 XTextCursorRef xCursor = xText->createTextCursor();
1348 if (!xCursor) return;
1350 XTextPositionRef xPos = (XTextPosition*)xCursor->queryInterface(XTextPosition::getSmartUik());
1351 XPropertySetRef xProp = (XPropertySet*)xCursor->queryInterface(XPropertySet::getSmartUik());
1352 XParagraphCursorRef xPar = (XParagraphCursor*)xCursor->queryInterface(XParagraphCursor::getSmartUik());
1353 if (!xPos || !xProp || !xPar) return;
1355 xCursor->gotoStart(false);
1356 xCursor->goRight(1,false);
1357 xCursor->goRight(1,true);
1359 UsrAny aAny = xProp->getPropertyValue(L"FontHeight");
1360 sal_uInt32 nOld = aAny.getUINT32();
1361 aAny.setUINT32(nOld*11/10);
1362 xProp->setPropertyValue(L"FontHeight", aAny);
1364 xPos->collapseToEnd();
1365 xCursor->goRight(1,true);
1367 xProp->setPropertyValue(L"Bold", UsrAny((sal_Bool)true));
1369 xPos->setText(L"x");
1371 xPos->collapseToEnd();
1372 xPar->gotoNextParagraph(false,true);
1373 xProp->setPropertyValue(L"Italic", UsrAny((sal_Bool)true));
1374 xProp->setPropertyValue(L"Underlined", UsrAny((sal_Bool)true));
1377 void lcl_Styles( FixedText& aTimeText ) // 27
1379 aTimeText.SetText("...");
1380 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1381 if (!xDoc) return;
1382 XStyleFamiliesRef xFamilies = xDoc->getStyleFamilies();
1383 if (!xFamilies) return;
1384 XStyleFamilyRef xFamily = xFamilies->getStyleFamilyByType( STYLE_FAMILY_CELL );
1385 // XStyleFamilyRef xFamily = xFamilies->getStyleFamilyByType( STYLE_FAMILY_PAGE );
1386 if (!xFamily) return;
1387 long nCount = xFamily->getCount();
1388 aTimeText.SetText(nCount);
1390 XStyleRef xStyle = xFamily->getStyleByName(L"rot");
1391 if (!xStyle) return;
1392 // XPropertySetRef xProp = (XPropertySet*)xStyle->queryInterface(XPropertySet::getSmartUik());
1393 // if (!xProp) return;
1395 XStyleRef xNew = xFamily->addStyle( L"gaga", xStyle );
1396 if (!xNew) return;
1397 XPropertySetRef xProp = (XPropertySet*)xNew->queryInterface(XPropertySet::getSmartUik());
1398 if (!xProp) return;
1400 UsrAny aAny;
1401 aAny = xProp->getPropertyValue(L"TransparentBackground");
1402 aAny.setBOOL(false);
1403 xProp->setPropertyValue(L"TransparentBackground", aAny);
1404 aAny = xProp->getPropertyValue(L"BackgroundColor");
1405 aAny.setUINT32(0xffff00);
1406 xProp->setPropertyValue(L"BackgroundColor", aAny);
1408 xFamily->removeStyle( L"rot" );
1411 void lcl_PageStyle( FixedText& aTimeText ) // 28
1413 aTimeText.SetText("...");
1415 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1416 if (!xDoc) return;
1417 XStyleFamiliesRef xFamilies = xDoc->getStyleFamilies();
1418 if (!xFamilies) return;
1419 XStyleFamilyRef xFamily = xFamilies->getStyleFamilyByType( STYLE_FAMILY_PAGE );
1420 if (!xFamily) return;
1421 XStyleRef xStyle = xFamily->getStyleByName(L"Standard");
1422 if (!xStyle) return;
1423 XPropertySetRef xProp = (XPropertySet*)xStyle->queryInterface(XPropertySet::getSmartUik());
1424 if (!xProp) return;
1426 UsrAny aAny;
1427 aAny = xProp->getPropertyValue(L"RightPageHeaderContent");
1429 // geht nicht:
1430 // if ( !XHeaderFooterContent_getReflection()->equals(*aAny.getReflection()) )
1431 // return;
1433 XHeaderFooterContentRef* pxContent = (XHeaderFooterContentRef*)aAny.get();
1434 if (!pxContent || !pxContent->is()) return;
1436 XTextRef xText = (*pxContent)->getCenterText();
1437 if (!xText) return;
1439 String aVal = OUStringToString(xText->getText(), CHARSET_SYSTEM);
1440 aTimeText.SetText(aVal);
1442 // xText->setText(L"Bla fasel s\xFClz");
1443 lcl_SetText(xText);
1445 xProp->setPropertyValue(L"RightPageHeaderContent", aAny);
1448 void lcl_AutoForm( FixedText& aTimeText ) // 29
1450 XInterfaceRef xInt = lcl_GetView();
1451 if (!xInt) return;
1453 XTableAutoFormatsRef xFormats;
1455 XTableAutoFormatRef xFormat = xFormats->getAutoFormatByName(L"gaga");
1456 if (!xFormat) return;
1457 XPropertySetRef xProp = (XPropertySet*)xFormat->queryInterface(XPropertySet::getSmartUik());
1458 if (!xProp) return;
1460 sal_Bool bVal = TypeConversion::toBOOL(xProp->getPropertyValue(L"IncludeBackground"));
1461 xProp->setPropertyValue(L"IncludeBackground", UsrAny(sal_Bool(!bVal)));
1463 XNamedRef xNamed = (XNamed*)xFormat->queryInterface(XNamed::getSmartUik());
1464 if (!xNamed) return;
1465 xNamed->setName(L"zzz");
1467 xFormats->addAutoFormat(L"gaga");
1468 XTableAutoFormatRef xNew = xFormats->getAutoFormatByName(L"gaga");
1469 if (!xNew) return;
1471 for (sal_uInt16 i=0; i<16; i++)
1473 XPropertySetRef xNewProp = xNew->getFieldByIndex(i);
1474 if (!xNewProp) return;
1476 xNewProp->setPropertyValue(L"TransparentBackground", UsrAny(sal_Bool(false)));
1477 sal_uInt32 nColor = 0x111100 * i;
1478 xNewProp->setPropertyValue(L"BackgroundColor", UsrAny(nColor));
1482 void lcl_Pivot( FixedText& aTimeText ) // 30
1484 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1485 if (!xDoc) return;
1487 XSpreadsheetsRef xSheets = xDoc->getSheets();
1488 if (!xSheets) return;
1489 XIndexAccessRef xInd = (XIndexAccess*)xSheets->queryInterface(XIndexAccess::getSmartUik());
1490 if (!xInd) return;
1491 sal_uInt16 nCount = (sal_uInt16)xInd->getCount();
1493 for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
1495 XTableSheetRef xSheet = xSheets->getSheetByIndex(nTab);
1496 if (!xSheet) return;
1497 XDataPilotTablesRef xPivots = xSheet->getDataPilotTables();
1498 if (!xPivots) return;
1499 lcl_OutputNames( xPivots, xDoc, nTab,0,0 );
1500 XIndexAccessRef xPInd = (XIndexAccess*)xPivots->queryInterface(XIndexAccess::getSmartUik());
1501 if (!xPInd) return;
1502 sal_uInt16 nPCount = (sal_uInt16)xPInd->getCount();
1503 for (sal_uInt16 nP=0; nP<nPCount; nP++)
1505 XDataPilotTableRef xTable = xPivots->getTableByIndex(nP);
1506 if (!xTable) return;
1508 // xTable->refreshTable();
1510 XDataPilotDescriptorRef xDesc = (XDataPilotDescriptor*)
1511 xTable->queryInterface(XDataPilotDescriptor::getSmartUik());
1512 if (!xDesc) return;
1513 CellRangeAddress aSource = xDesc->getSourceRange();
1514 ++aSource.Sheet;
1515 xDesc->setSourceRange(aSource);
1517 CellRangeAddress aAddr = xTable->getOutputRange();
1518 XCellRangeRef xRange = xDoc->getCellRange(aAddr);
1519 if (!xRange) return;
1520 XPropertySetRef xProp = (XPropertySet*)xRange->queryInterface(XPropertySet::getSmartUik());
1521 if (!xProp) return;
1522 xProp->setPropertyValue(L"TransparentBackground", UsrAny(sal_Bool(false)));
1523 xProp->setPropertyValue(L"BackgroundColor", UsrAny((sal_uInt32)0x00FF00));
1528 IMPL_LINK_NOARG(MyWindow, CountHdl)
1531 long nCount = aCountField.GetValue();
1532 switch ( nCount )
1534 case 0:
1536 sal_uLong nStart = Time::GetSystemTicks();
1537 lcl_DoCount();
1538 sal_uLong nEnd = Time::GetSystemTicks();
1539 aTimeText.SetText(String("Count: ")+String(nEnd-nStart)+String(" ms"));
1541 break;
1542 case 1:
1543 lcl_GlobalCell();
1544 break;
1545 case 2:
1546 lcl_Annotations(aTimeText);
1547 break;
1548 case 3:
1549 lcl_Cursor(aTimeText);
1550 break;
1551 case 4:
1552 lcl_Cells(aTimeText);
1553 break;
1554 case 5:
1555 lcl_Sheet(aTimeText);
1556 break;
1557 case 6:
1558 lcl_Names(aTimeText);
1559 break;
1560 case 7:
1561 lcl_Sheets(aTimeText);
1562 break;
1563 case 8:
1564 lcl_Goal(aTimeText);
1565 break;
1566 case 9:
1567 lcl_TabOp(aTimeText);
1568 break;
1569 case 10:
1570 lcl_Fill(aTimeText);
1571 break;
1572 case 11:
1573 lcl_Audi(aTimeText);
1574 break;
1575 case 12:
1576 lcl_Consoli(aTimeText);
1577 break;
1578 case 13:
1579 lcl_Sort(aTimeText);
1580 break;
1581 case 14:
1582 lcl_Filter(aTimeText);
1583 break;
1584 case 15:
1585 lcl_AutoFilter(aTimeText);
1586 break;
1587 case 16:
1588 lcl_Merge(aTimeText);
1589 break;
1590 case 17:
1591 lcl_Outline(aTimeText);
1592 break;
1593 case 18:
1594 lcl_Bla(aTimeText);
1595 break;
1596 case 19:
1597 lcl_CellCursor(aTimeText);
1598 break;
1599 case 20:
1600 lcl_Notes(aTimeText);
1601 break;
1602 case 21:
1603 lcl_Scenario(aTimeText);
1604 break;
1605 case 22:
1606 lcl_Formula(aTimeText);
1607 break;
1608 case 23:
1609 lcl_DBRange(aTimeText);
1610 break;
1611 case 24:
1612 lcl_FillTab(aTimeText);
1613 break;
1614 case 25:
1615 lcl_Listener(aTimeText);
1616 break;
1617 case 26:
1618 lcl_CellAttrib(aTimeText);
1619 break;
1620 case 27:
1621 lcl_Styles(aTimeText);
1622 break;
1623 case 28:
1624 lcl_PageStyle(aTimeText);
1625 break;
1626 case 29:
1627 lcl_AutoForm(aTimeText);
1628 break;
1629 case 30:
1630 lcl_Pivot(aTimeText);
1631 break;
1634 return 0;
1637 //-----------------------------------------------------------------------
1639 IMPL_LINK_NOARG(MyWindow, TextHdl)
1641 sal_uInt16 nCol = (sal_uInt16)aColField.GetValue();
1642 sal_uInt16 nRow = (sal_uInt16)aRowField.GetValue();
1643 sal_uInt16 nPos = (sal_uInt16)aPosField.GetValue();
1644 sal_uInt16 nLen = (sal_uInt16)aLenField.GetValue();
1645 String aStr = aTextEdit.GetText();
1647 aTimeText.SetText("...");
1649 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1650 if (xDoc)
1652 sal_uInt16 nTab = 0;
1653 CellAddress aPos;
1654 aPos.Sheet = 0;
1655 aPos.Column = nCol;
1656 aPos.Row = nRow;
1657 XCellRef xCell = xDoc->getCell(aPos);
1658 if ( xCell )
1660 XTextRef xCellText = (XText*)xCell->queryInterface(XText::getSmartUik());
1661 if (xCellText)
1663 XTextCursorRef xCursor = xCellText->createTextCursor();
1664 if (xCursor)
1666 XTextPositionRef xPos = (XTextPosition*)
1667 xCursor->queryInterface(XTextPosition::getSmartUik());
1668 XControlCharacterInsertableRef xControl = (XControlCharacterInsertable*)
1669 xCursor->queryInterface(XControlCharacterInsertable::getSmartUik());
1671 if (xPos && xControl)
1673 xCursor->gotoStart(false);
1674 xCursor->goRight(11,true);
1675 String aVal = OUStringToString( xPos->getText(), CHARSET_SYSTEM );
1676 aTimeText.SetText(aVal);
1683 return 0;
1686 //-----------------------------------------------------------------------
1688 IMPL_LINK_NOARG(MyWindow, BlaHdl)
1690 aTimeText.SetText("...");
1692 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1693 if (xDoc)
1695 CellAddress aPos;
1696 aPos.Sheet = 0;
1697 aPos.Column = 1;
1698 aPos.Row = 2;
1699 XCellRef xCell = xDoc->getCell(aPos);
1700 if ( xCell )
1702 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
1703 XFieldContainerRef xCont = (XFieldContainer*)
1704 xCell->queryInterface(XFieldContainer::getSmartUik());
1706 if ( xText && xCont )
1708 XFieldTypesRef xTypes = xCont->getFieldTypes();
1709 if ( xTypes )
1711 XTextFieldTypeRef xType = xTypes->getFieldType( FIELDTYPE_INTERNET );
1712 XTextCursorRef xCursor = xText->createTextCursor();
1713 if ( xCursor && xType )
1716 // letztes Feld loeschen
1717 XIndexAccessRef xIndex = (XIndexAccess*)
1718 xType->queryInterface(XIndexAccess::getSmartUik());
1719 if (xIndex)
1721 String aBla;
1722 sal_uLong nCount = xIndex->getCount();
1723 for (sal_uLong i=0; i<nCount; i++)
1725 XInterfaceRef xInt = xIndex->getElementByIndex(i);
1726 if (xInt)
1728 XPropertySetRef xProp = (XPropertySet*)xInt->
1729 queryInterface(XPropertySet::getSmartUik());
1730 if ( xProp )
1732 if (aBla.Len()) aBla += ',';
1733 aBla += OUStringToString(
1734 TypeConversion::toString(
1735 xProp->getPropertyValue(L"URL") ),
1736 CHARSET_SYSTEM );
1738 if ( i+1 == nCount ) // letztes
1740 XTextFieldRef xField = (XTextField*)xInt->
1741 queryInterface(XTextField::getSmartUik());
1742 if (xField)
1743 xTypes->removeTextField(xField);
1747 aTimeText.SetText(aBla);
1754 xGlobalCell = xCell;
1756 return 0;
1760 //-----------------------------------------------------------------------
1762 IMPL_LINK_NOARG(MyWindow, TabHdl)
1764 String aResult;
1766 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1767 if (xDoc)
1769 XSpreadsheetsRef xSheets = xDoc->getSheets();
1770 if (xSheets)
1772 XIndexAccessRef xIndex = (XIndexAccess*)xSheets->queryInterface(XIndexAccess::getSmartUik());
1773 if (xIndex)
1775 sal_uInt16 nCount = (sal_uInt16) xIndex->getCount();
1776 for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
1778 XInterfaceRef xInt = xIndex->getElementByIndex(nTab);
1779 if (xInt)
1781 XNamedRef xNamed = (XNamed*)xInt->queryInterface(XNamed::getSmartUik());
1782 if (xNamed)
1784 if (nTab)
1785 aResult += ",";
1786 aResult += OUStringToString( xNamed->getName(), CHARSET_SYSTEM );
1792 CellAddress aPos;
1793 aPos.Sheet = 0;
1794 aPos.Column = 0;
1795 aPos.Row = 0;
1797 XEnumerationAccessRef xEAcc = (XEnumerationAccess*)
1798 xSheets->queryInterface(XEnumerationAccess::getSmartUik());
1799 if (xEAcc)
1801 XEnumerationRef xEnum = xEAcc->getEnumeration();
1802 if (xEnum)
1804 while (xEnum->hasMoreElements())
1806 XInterfaceRef xInt = xEnum->nextElement();
1807 if (xInt)
1809 XNamedRef xNamed = (XNamed*)xInt->queryInterface(XNamed::getSmartUik());
1810 if (xNamed)
1812 UString aName = xNamed->getName();
1813 XCellRef xCell = xDoc->getCell(aPos);
1814 if ( xCell )
1816 XTextRef xText = (XText*)xCell->queryInterface(XText::getSmartUik());
1817 xText->setText( aName );
1818 ++aPos.Row;
1828 aTimeText.SetText(aResult);
1830 return 0;
1833 //-----------------------------------------------------------------------
1835 void lcl_FillCells(XCellCollectionRef xColl)
1837 XEnumerationAccessRef xEnAcc = xColl->getCells();
1838 if (!xEnAcc) return;
1839 XEnumerationRef xEnum = xEnAcc->getEnumeration();
1840 if (!xEnum) return;
1841 while (xEnum->hasMoreElements())
1843 XInterfaceRef xInt = xEnum->nextElement();
1844 if (xInt)
1846 XCellRef xCell = (XCell*)xInt->queryInterface(XCell::getSmartUik());
1847 if (xCell)
1849 xCell->setValue(42.0);
1855 IMPL_LINK_NOARG(MyWindow, ViewHdl)
1857 XSpreadsheetDocumentRef xDoc = lcl_GetDocument(); // Calc-Model
1858 XInterfaceRef xInt = lcl_GetView();
1859 if (!xInt) return 0;
1860 XDocumentViewRef xView = (XDocumentView*)xInt->queryInterface(XDocumentView::getSmartUik());
1861 if (!xView) return 0;
1863 XInterfaceRef xSelInt = xView->getSelection();
1864 if (!xSelInt) return 0;
1866 XAutoFormattableRef xAuto = (XAutoFormattable*)xSelInt->
1867 queryInterface(XAutoFormattable::getSmartUik());
1868 if ( xAuto )
1869 xAuto->applyAutoFormat( L"gaga" );
1871 XFormulaArrayRef xArr = (XFormulaArray*)xSelInt->queryInterface(XFormulaArray::getSmartUik());
1872 if ( xArr )
1874 // xArr->setFormulaArray( "123" );
1875 String aFormula = OUStringToString( xArr->getFormulaArray(), CHARSET_SYSTEM );
1876 aTimeText.SetText(aFormula);
1878 else
1879 aTimeText.SetText("...");
1881 XTextRef xText = (XText*)xSelInt->queryInterface(XText::getSmartUik());
1882 if ( xText )
1884 String aStr = OUStringToString( xText->getText(), CHARSET_SYSTEM );
1885 aStr += 'X';
1886 xText->setText(StringToOUString(aStr, CHARSET_SYSTEM));
1889 XPrintableRef xPrint = (XPrintable*)xInt->queryInterface(XPrintable::getSmartUik());
1890 String aName = OUStringToString( xPrint->getPrinterName(), CHARSET_SYSTEM );
1891 // aTimeText.SetText(aName);
1893 xPrint->setPrinterName(L"HP5_2");
1894 // xPrint->setPrinterName(L"blubb");
1896 // XPropertySetRef xOptions;
1897 // xPrint->print(xOptions);
1899 /* XViewPaneRef xPane = (XViewPane*)xInt->queryInterface(XViewPane::getSmartUik());
1900 if (!xPane) return 0;
1901 xPane->setScrollRow( 2 );
1904 XCellRangeSourceRef xSrc = (XCellRangeSource*)
1905 xInt->queryInterface(XCellRangeSource::getSmartUik());
1906 if (!xSrc) return 0;
1907 XCellRangeRef xRange = xSrc->getReferredCells();
1908 if (!xRange) return 0;
1909 XCellCollectionRef xColl = (XCellCollection*)
1910 xRange->queryInterface(XCellCollection::getSmartUik());
1911 if (!xColl) return 0;
1913 XActionLockableRef xLock = (XActionLockable*)
1914 xDoc->queryInterface(XActionLockable::getSmartUik());
1915 if (xLock)
1916 xLock->addActionLock(); // nicht zwischendurch painten
1918 // lcl_FillCells(xColl);
1920 if (xLock)
1921 xLock->removeActionLock(); // nicht zwischendurch painten
1923 XStarCalcViewRef xCalc = (XStarCalcView*)xInt->queryInterface(XStarCalcView::getSmartUik());
1924 if (!xCalc) return 0;
1926 return 0;
1929 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */