* Makefile.am:
[monodevelop.git] / extras / OpenOfficeSamples / OpenOfficeSpreadsheetViewSample.xpt.xml
blobe49f0d4e98762bb766243c18e25e4bf530f45b6c
1 <?xml version="1.0"?>
2 <Template originator   = "Michael Hutchinson"
3           created      = "2008/05/30"
4           lastModified = "2008/05/30">
5         
6         <!-- Template Header -->
7         <TemplateConfiguration>
8                 <_Name>Spreadsheet View Sample</_Name>
9                 <_Category>C#/OpenOffice Samples</_Category>
10                 <Icon>md-project</Icon>
11                 <LanguageName>C#</LanguageName>
12                 <_Description>Creates a new C# OpenOffice integration sample project.</_Description>
13         </TemplateConfiguration>
14         
15         <!-- Actions -->
16         <Actions>
17                 <Open filename = "Main.cs"/>
18         </Actions>
19         
20         <!-- Template Content -->
21         <Combine name = "${ProjectName}" directory = ".">
22                 <Options>
23                         <StartupProject>${ProjectName}</StartupProject>
24                 </Options>
25                 
26                 <Project name = "${ProjectName}" directory = ".">
27                         <Options/>
28                         <References>
29                                 <Reference type="Gac" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
30                                 <Reference type="Gac" refto="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
31                                 <Reference type="Gac" refto="cli_basetypes, Version=1.0.9.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
32                                 <Reference type="Gac" refto="cli_uno_bridge, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
33                                 <Reference type="Gac" refto="cli_ure, Version=1.0.12.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
34                                 <Reference type="Gac" refto="cli_types, Version=1.1.12.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
35                                 <Reference type="Gac" refto="cli_cppuhelper, Version=1.0.12.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
36                         </References>
37                         
38                         <Files>
39                                 <FileTemplateReference TemplateID="CSharpAssemblyInfo" name="AssemblyInfo.cs" />
40                                 <FileTemplateReference TemplateID="OpenOfficeSpreadsheetDocHelper" name="SpreadsheetDocHelper.cs" />
41                                 <File name="Main.cs" AddStandardHeader="False"><![CDATA[// 
42 // This library is free software; you can redistribute it and/or
43 // modify it under the terms of the GNU Lesser General Public
44 // License as published by the Free Software Foundation; either 
45 // version 2.1 of the License, or (at your option) any later version.
46 // 
47 // This library is distributed in the hope that it will be useful,
48 // but WITHOUT ANY WARRANTY; without even the implied warranty of
49 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
50 // Lesser General Public License for more details.
51 // 
52 // You should have received a copy of the GNU Lesser General Public 
53 // License along with this library.  If not, see <http://www.gnu.org/licenses/>.
55 using System;
56 using System.Threading;
57 using unoidl.com.sun.star.sheet;
58 using unoidl.com.sun.star.beans;
59 using unoidl.com.sun.star.container;
60 using unoidl.com.sun.star.table;
61 using unoidl.com.sun.star.view;
62 using unoidl.com.sun.star.frame;
64 namespace OpenOffice.Samples
66         /// <summary> Create and modify a spreadsheet view. </summary>
67         public class ViewSample : SpreadsheetDocHelper
68         {
69                 
70                 public static void Main (String [] args)
71                 {
72                         try {
73                                 using (ViewSample sample = new ViewSample (args)) {
74                                         sample.doSampleFunction ();
75                                 }
76                                 Console.WriteLine ("\nSamples done.");
77                         } catch (Exception ex) {
78                                 Console.WriteLine ("Sample caught exception! " + ex);
79                         }
80                 }
81                 
82                 public ViewSample (string[] args)
83                         : base (args)
84                 {
85                 }
86                 
87                 /// <summary>
88                 /// This sample function performs all changes on the view.
89                 /// </summary>
90                 public void doSampleFunction()
91                 {
92                         XModel model = (XModel) Document;
93                         XController xController = model.getCurrentController();
94                         
95                         // --- Spreadsheet view ---
96                         // freeze the first column and first two rows
97                         XViewFreezable xFreeze = (XViewFreezable) xController;
98                         if  (null != xFreeze)
99                                 Console.WriteLine ("got xFreeze");
100                         xFreeze.freezeAtPosition (1, 2);
101                         
102                         // --- View pane ---
103                         // get the cell range shown in the second pane and assign
104                         // a cell background to them
105                         XIndexAccess xIndex = (XIndexAccess) xController;
106                         uno.Any aPane = xIndex.getByIndex(1);
107                         XCellRangeReferrer xRefer = (XCellRangeReferrer) aPane.Value;
108                         XCellRange xRange = xRefer.getReferredCells();
109                         XPropertySet xRangeProp = (XPropertySet) xRange;
110                         xRangeProp.setPropertyValue("IsCellBackgroundTransparent", new uno.Any (false));
111                         xRangeProp.setPropertyValue("CellBackColor", new uno.Any ((int) 0xFFFFCC));
112                         
113                         // --- View settings ---
114                         // change the view to display green grid lines
115                         XPropertySet xProp = (XPropertySet) xController;
116                         xProp.setPropertyValue ("ShowGrid", new uno.Any (true));
117                         xProp.setPropertyValue ("GridColor", new uno.Any ((int) 0x00CC00));
118                         
119                         // --- Range selection ---
120                         // let the user select a range and use it as the view's selection
121                         XRangeSelection xRngSel = (XRangeSelection) xController;
122                         ExampleRangeListener aListener = new ExampleRangeListener();
123                         xRngSel.addRangeSelectionListener (aListener);
124                         PropertyValue[] aArguments = new PropertyValue[2];
125                         aArguments[0] = new PropertyValue ();
126                         aArguments[0].Name   = "Title";
127                         aArguments[0].Value  = new uno.Any ("Please select a range");
128                         aArguments[1] = new PropertyValue();
129                         aArguments[1].Name   = "CloseOnMouseRelease";
130                         aArguments[1].Value  = new uno.Any (true);
131                         xRngSel.startRangeSelection (aArguments);
132                         
133                         Monitor.Enter (aListener);
134                         try {
135                                 // wait until the selection is done
136                                 Monitor.Wait (aListener);
137                         } finally {
138                                 Monitor.Exit (aListener);
139                         }
140                         
141                         xRngSel.removeRangeSelectionListener (aListener);
142                         if  (aListener.aResult != null && aListener.aResult.Length != 0) {
143                                 XSelectionSupplier xSel = (XSelectionSupplier) xController;
144                                 XSpreadsheetView xView = (XSpreadsheetView) xController;
145                                 XSpreadsheet xSheet = xView.getActiveSheet();
146                                 XCellRange xResultRange = xSheet.getCellRangeByName (aListener.aResult);
147                                 xSel.select (new uno.Any (typeof (XCellRange), xResultRange));
148                         }
149                 }
150                 
151                 //  listener to react on finished selection
152                 private class ExampleRangeListener : XRangeSelectionListener
153                 {
154                         public string aResult;
155                         
156                         public void done (RangeSelectionEvent evt)
157                         {
158                                 aResult = evt.RangeDescriptor;
159                                 Monitor.Enter (this);
160                                 try {
161                                         Monitor.Pulse (this);
162                                 } finally {
163                                         Monitor.Exit (this);
164                                 }
165                         }
167                         public void aborted (RangeSelectionEvent aEvent)
168                         {
169                                 Monitor.Enter (this);
170                                 try {
171                                         Monitor.Pulse (this);
172                                 } finally {
173                                         Monitor.Exit (this);
174                                 }
175                         }
176                         
177                         public void disposing (unoidl.com.sun.star.lang.EventObject aObj)
178                         {
179                         }
180                 }
181         }
182 }]]></File>                     
183                         </Files>
184                 </Project>
185         </Combine>
186 </Template>