1*cf279e26SAndrew Rist /************************************************************** 2*cf279e26SAndrew Rist * 3*cf279e26SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cf279e26SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cf279e26SAndrew Rist * distributed with this work for additional information 6*cf279e26SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cf279e26SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cf279e26SAndrew Rist * "License"); you may not use this file except in compliance 9*cf279e26SAndrew Rist * with the License. You may obtain a copy of the License at 10*cf279e26SAndrew Rist * 11*cf279e26SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*cf279e26SAndrew Rist * 13*cf279e26SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cf279e26SAndrew Rist * software distributed under the License is distributed on an 15*cf279e26SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cf279e26SAndrew Rist * KIND, either express or implied. See the License for the 17*cf279e26SAndrew Rist * specific language governing permissions and limitations 18*cf279e26SAndrew Rist * under the License. 19*cf279e26SAndrew Rist * 20*cf279e26SAndrew Rist *************************************************************/ 21*cf279e26SAndrew Rist 22cdf0e10cSrcweir 23cdf0e10cSrcweir using System; 24cdf0e10cSrcweir using System.Threading; 25cdf0e10cSrcweir 26cdf0e10cSrcweir // __________ implementation ____________________________________ 27cdf0e10cSrcweir 28cdf0e10cSrcweir /** Create and modify a spreadsheet view. 29cdf0e10cSrcweir */ 30cdf0e10cSrcweir public class ViewSample : SpreadsheetDocHelper 31cdf0e10cSrcweir { 32cdf0e10cSrcweir Main( String [] args )33cdf0e10cSrcweir public static void Main( String [] args ) 34cdf0e10cSrcweir { 35cdf0e10cSrcweir try 36cdf0e10cSrcweir { 37cdf0e10cSrcweir using ( ViewSample aSample = new ViewSample( args ) ) 38cdf0e10cSrcweir { 39cdf0e10cSrcweir aSample.doSampleFunction(); 40cdf0e10cSrcweir } 41cdf0e10cSrcweir Console.WriteLine( "\nSamples done." ); 42cdf0e10cSrcweir } 43cdf0e10cSrcweir catch (Exception ex) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir Console.WriteLine( "Sample caught exception! " + ex ); 46cdf0e10cSrcweir } 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir // ________________________________________________________________ 50cdf0e10cSrcweir ViewSample( String[] args )51cdf0e10cSrcweir public ViewSample( String[] args ) 52cdf0e10cSrcweir : base( args ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ________________________________________________________________ 57cdf0e10cSrcweir 58cdf0e10cSrcweir /** This sample function performs all changes on the view. */ doSampleFunction()59cdf0e10cSrcweir public void doSampleFunction() 60cdf0e10cSrcweir { 61cdf0e10cSrcweir unoidl.com.sun.star.sheet.XSpreadsheetDocument xDoc = getDocument(); 62cdf0e10cSrcweir unoidl.com.sun.star.frame.XModel xModel = 63cdf0e10cSrcweir (unoidl.com.sun.star.frame.XModel) xDoc; 64cdf0e10cSrcweir unoidl.com.sun.star.frame.XController xController = 65cdf0e10cSrcweir xModel.getCurrentController(); 66cdf0e10cSrcweir 67cdf0e10cSrcweir // --- Spreadsheet view --- 68cdf0e10cSrcweir // freeze the first column and first two rows 69cdf0e10cSrcweir unoidl.com.sun.star.sheet.XViewFreezable xFreeze = 70cdf0e10cSrcweir (unoidl.com.sun.star.sheet.XViewFreezable) xController; 71cdf0e10cSrcweir if ( null != xFreeze ) 72cdf0e10cSrcweir Console.WriteLine( "got xFreeze" ); 73cdf0e10cSrcweir xFreeze.freezeAtPosition( 1, 2 ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir // --- View pane --- 76cdf0e10cSrcweir // get the cell range shown in the second pane and assign 77cdf0e10cSrcweir // a cell background to them 78cdf0e10cSrcweir unoidl.com.sun.star.container.XIndexAccess xIndex = 79cdf0e10cSrcweir (unoidl.com.sun.star.container.XIndexAccess) xController; 80cdf0e10cSrcweir uno.Any aPane = xIndex.getByIndex(1); 81cdf0e10cSrcweir unoidl.com.sun.star.sheet.XCellRangeReferrer xRefer = 82cdf0e10cSrcweir (unoidl.com.sun.star.sheet.XCellRangeReferrer) aPane.Value; 83cdf0e10cSrcweir unoidl.com.sun.star.table.XCellRange xRange = xRefer.getReferredCells(); 84cdf0e10cSrcweir unoidl.com.sun.star.beans.XPropertySet xRangeProp = 85cdf0e10cSrcweir (unoidl.com.sun.star.beans.XPropertySet) xRange; 86cdf0e10cSrcweir xRangeProp.setPropertyValue( 87cdf0e10cSrcweir "IsCellBackgroundTransparent", new uno.Any( false ) ); 88cdf0e10cSrcweir xRangeProp.setPropertyValue( 89cdf0e10cSrcweir "CellBackColor", new uno.Any( (Int32) 0xFFFFCC ) ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir // --- View settings --- 92cdf0e10cSrcweir // change the view to display green grid lines 93cdf0e10cSrcweir unoidl.com.sun.star.beans.XPropertySet xProp = 94cdf0e10cSrcweir (unoidl.com.sun.star.beans.XPropertySet) xController; 95cdf0e10cSrcweir xProp.setPropertyValue( 96cdf0e10cSrcweir "ShowGrid", new uno.Any( true ) ); 97cdf0e10cSrcweir xProp.setPropertyValue( 98cdf0e10cSrcweir "GridColor", new uno.Any( (Int32) 0x00CC00 ) ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir // --- Range selection --- 101cdf0e10cSrcweir // let the user select a range and use it as the view's selection 102cdf0e10cSrcweir unoidl.com.sun.star.sheet.XRangeSelection xRngSel = 103cdf0e10cSrcweir (unoidl.com.sun.star.sheet.XRangeSelection) xController; 104cdf0e10cSrcweir ExampleRangeListener aListener = new ExampleRangeListener(); 105cdf0e10cSrcweir xRngSel.addRangeSelectionListener( aListener ); 106cdf0e10cSrcweir unoidl.com.sun.star.beans.PropertyValue[] aArguments = 107cdf0e10cSrcweir new unoidl.com.sun.star.beans.PropertyValue[2]; 108cdf0e10cSrcweir aArguments[0] = new unoidl.com.sun.star.beans.PropertyValue(); 109cdf0e10cSrcweir aArguments[0].Name = "Title"; 110cdf0e10cSrcweir aArguments[0].Value = new uno.Any( "Please select a range" ); 111cdf0e10cSrcweir aArguments[1] = new unoidl.com.sun.star.beans.PropertyValue(); 112cdf0e10cSrcweir aArguments[1].Name = "CloseOnMouseRelease"; 113cdf0e10cSrcweir aArguments[1].Value = new uno.Any( true ); 114cdf0e10cSrcweir xRngSel.startRangeSelection( aArguments ); 115cdf0e10cSrcweir Monitor.Enter( aListener ); 116cdf0e10cSrcweir try 117cdf0e10cSrcweir { 118cdf0e10cSrcweir Monitor.Wait( aListener ); // wait until the selection is done 119cdf0e10cSrcweir } 120cdf0e10cSrcweir finally 121cdf0e10cSrcweir { 122cdf0e10cSrcweir Monitor.Exit( aListener ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir xRngSel.removeRangeSelectionListener( aListener ); 125cdf0e10cSrcweir if ( aListener.aResult != null && aListener.aResult.Length != 0 ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir unoidl.com.sun.star.view.XSelectionSupplier xSel = 128cdf0e10cSrcweir (unoidl.com.sun.star.view.XSelectionSupplier) xController; 129cdf0e10cSrcweir unoidl.com.sun.star.sheet.XSpreadsheetView xView = 130cdf0e10cSrcweir (unoidl.com.sun.star.sheet.XSpreadsheetView) xController; 131cdf0e10cSrcweir unoidl.com.sun.star.sheet.XSpreadsheet xSheet = 132cdf0e10cSrcweir xView.getActiveSheet(); 133cdf0e10cSrcweir unoidl.com.sun.star.table.XCellRange xResultRange = 134cdf0e10cSrcweir xSheet.getCellRangeByName( aListener.aResult ); 135cdf0e10cSrcweir xSel.select( 136cdf0e10cSrcweir new uno.Any( 137cdf0e10cSrcweir typeof (unoidl.com.sun.star.table.XCellRange), 138cdf0e10cSrcweir xResultRange ) ); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir // ________________________________________________________________ 143cdf0e10cSrcweir 144cdf0e10cSrcweir // listener to react on finished selection 145cdf0e10cSrcweir 146cdf0e10cSrcweir private class ExampleRangeListener 147cdf0e10cSrcweir : unoidl.com.sun.star.sheet.XRangeSelectionListener 148cdf0e10cSrcweir { 149cdf0e10cSrcweir public String aResult; 150cdf0e10cSrcweir done( unoidl.com.sun.star.sheet.RangeSelectionEvent aEvent )151cdf0e10cSrcweir public void done( unoidl.com.sun.star.sheet.RangeSelectionEvent aEvent ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir aResult = aEvent.RangeDescriptor; 154cdf0e10cSrcweir Monitor.Enter( this ); 155cdf0e10cSrcweir try 156cdf0e10cSrcweir { 157cdf0e10cSrcweir Monitor.Pulse( this ); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir finally 160cdf0e10cSrcweir { 161cdf0e10cSrcweir Monitor.Exit( this ); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir aborted( unoidl.com.sun.star.sheet.RangeSelectionEvent aEvent )165cdf0e10cSrcweir public void aborted( 166cdf0e10cSrcweir unoidl.com.sun.star.sheet.RangeSelectionEvent aEvent ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir Monitor.Enter( this ); 169cdf0e10cSrcweir try 170cdf0e10cSrcweir { 171cdf0e10cSrcweir Monitor.Pulse( this ); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir finally 174cdf0e10cSrcweir { 175cdf0e10cSrcweir Monitor.Exit( this ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir disposing( unoidl.com.sun.star.lang.EventObject aObj )179cdf0e10cSrcweir public void disposing( unoidl.com.sun.star.lang.EventObject aObj ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir } 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir // ________________________________________________________________ 185cdf0e10cSrcweir 186cdf0e10cSrcweir } 187