1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef SC_XLESCHER_HXX
25 #define SC_XLESCHER_HXX
26
27 #include <tools/gen.hxx>
28 #include <tools/mapunit.hxx>
29 #include "fapihelper.hxx"
30 #include "xladdress.hxx"
31 #include "xlstyle.hxx"
32
33 namespace com { namespace sun { namespace star {
34 namespace drawing { class XShape; }
35 namespace awt { class XControlModel; }
36 namespace script { struct ScriptEventDescriptor; }
37 } } }
38
39 class SdrObject;
40 class Rectangle;
41 class ScDocument;
42 class SvStream;
43 class XclImpStream;
44 class XclExpStream;
45
46 // Constants and Enumerations =================================================
47
48 // (0x001C) NOTE --------------------------------------------------------------
49
50 const sal_uInt16 EXC_ID_NOTE = 0x001C;
51 const sal_uInt16 EXC_NOTE_VISIBLE = 0x0002;
52 const sal_uInt16 EXC_NOTE5_MAXLEN = 2048;
53
54 // (0x005D) OBJ ---------------------------------------------------------------
55
56 const sal_uInt16 EXC_ID_OBJ = 0x005D;
57
58 const sal_uInt16 EXC_OBJ_INVALID_ID = 0;
59
60 // object types
61 const sal_uInt16 EXC_OBJTYPE_GROUP = 0;
62 const sal_uInt16 EXC_OBJTYPE_LINE = 1;
63 const sal_uInt16 EXC_OBJTYPE_RECTANGLE = 2;
64 const sal_uInt16 EXC_OBJTYPE_OVAL = 3;
65 const sal_uInt16 EXC_OBJTYPE_ARC = 4;
66 const sal_uInt16 EXC_OBJTYPE_CHART = 5;
67 const sal_uInt16 EXC_OBJTYPE_TEXT = 6;
68 const sal_uInt16 EXC_OBJTYPE_BUTTON = 7;
69 const sal_uInt16 EXC_OBJTYPE_PICTURE = 8;
70 const sal_uInt16 EXC_OBJTYPE_POLYGON = 9; // new in BIFF4
71 const sal_uInt16 EXC_OBJTYPE_CHECKBOX = 11; // new in BIFF5
72 const sal_uInt16 EXC_OBJTYPE_OPTIONBUTTON = 12;
73 const sal_uInt16 EXC_OBJTYPE_EDIT = 13;
74 const sal_uInt16 EXC_OBJTYPE_LABEL = 14;
75 const sal_uInt16 EXC_OBJTYPE_DIALOG = 15;
76 const sal_uInt16 EXC_OBJTYPE_SPIN = 16;
77 const sal_uInt16 EXC_OBJTYPE_SCROLLBAR = 17;
78 const sal_uInt16 EXC_OBJTYPE_LISTBOX = 18;
79 const sal_uInt16 EXC_OBJTYPE_GROUPBOX = 19;
80 const sal_uInt16 EXC_OBJTYPE_DROPDOWN = 20;
81 const sal_uInt16 EXC_OBJTYPE_NOTE = 25; // new in BIFF8
82 const sal_uInt16 EXC_OBJTYPE_DRAWING = 30;
83 const sal_uInt16 EXC_OBJTYPE_UNKNOWN = 0xFFFF; /// For internal use only.
84
85 // BIFF3-BIFF5 flags
86 const sal_uInt16 EXC_OBJ_HIDDEN = 0x0100;
87 const sal_uInt16 EXC_OBJ_VISIBLE = 0x0200;
88 const sal_uInt16 EXC_OBJ_PRINTABLE = 0x0400;
89
90 // BIFF5 line formatting
91 const sal_uInt8 EXC_OBJ_LINE_AUTOCOLOR = 64;
92
93 const sal_uInt8 EXC_OBJ_LINE_SOLID = 0;
94 const sal_uInt8 EXC_OBJ_LINE_DASH = 1;
95 const sal_uInt8 EXC_OBJ_LINE_DOT = 2;
96 const sal_uInt8 EXC_OBJ_LINE_DASHDOT = 3;
97 const sal_uInt8 EXC_OBJ_LINE_DASHDOTDOT = 4;
98 const sal_uInt8 EXC_OBJ_LINE_MEDTRANS = 5;
99 const sal_uInt8 EXC_OBJ_LINE_DARKTRANS = 6;
100 const sal_uInt8 EXC_OBJ_LINE_LIGHTTRANS = 7;
101 const sal_uInt8 EXC_OBJ_LINE_NONE = 255;
102
103 const sal_uInt8 EXC_OBJ_LINE_HAIR = 0;
104 const sal_uInt8 EXC_OBJ_LINE_THIN = 1;
105 const sal_uInt8 EXC_OBJ_LINE_MEDIUM = 2;
106 const sal_uInt8 EXC_OBJ_LINE_THICK = 3;
107
108 const sal_uInt8 EXC_OBJ_LINE_AUTO = 0x01;
109
110 const sal_uInt8 EXC_OBJ_ARROW_NONE = 0;
111 const sal_uInt8 EXC_OBJ_ARROW_OPEN = 1;
112 const sal_uInt8 EXC_OBJ_ARROW_FILLED = 2;
113 const sal_uInt8 EXC_OBJ_ARROW_OPENBOTH = 3;
114 const sal_uInt8 EXC_OBJ_ARROW_FILLEDBOTH = 4;
115
116 const sal_uInt8 EXC_OBJ_ARROW_NARROW = 0;
117 const sal_uInt8 EXC_OBJ_ARROW_MEDIUM = 1;
118 const sal_uInt8 EXC_OBJ_ARROW_WIDE = 2;
119
120 const sal_uInt8 EXC_OBJ_LINE_TL = 0;
121 const sal_uInt8 EXC_OBJ_LINE_TR = 1;
122 const sal_uInt8 EXC_OBJ_LINE_BR = 2;
123 const sal_uInt8 EXC_OBJ_LINE_BL = 3;
124
125 // BIFF5 fill formatting
126 const sal_uInt8 EXC_OBJ_FILL_AUTOCOLOR = 65;
127
128 const sal_uInt8 EXC_OBJ_FILL_AUTO = 0x01;
129
130 // BIFF5 frame formatting
131 const sal_uInt16 EXC_OBJ_FRAME_SHADOW = 0x0002;
132
133 // BIFF5 text objects
134 const sal_uInt8 EXC_OBJ_HOR_LEFT = 1;
135 const sal_uInt8 EXC_OBJ_HOR_CENTER = 2;
136 const sal_uInt8 EXC_OBJ_HOR_RIGHT = 3;
137 const sal_uInt8 EXC_OBJ_HOR_JUSTIFY = 4;
138
139 const sal_uInt8 EXC_OBJ_VER_TOP = 1;
140 const sal_uInt8 EXC_OBJ_VER_CENTER = 2;
141 const sal_uInt8 EXC_OBJ_VER_BOTTOM = 3;
142 const sal_uInt8 EXC_OBJ_VER_JUSTIFY = 4;
143
144 const sal_uInt16 EXC_OBJ_ORIENT_NONE = 0;
145 const sal_uInt16 EXC_OBJ_ORIENT_STACKED = 1; /// Stacked top to bottom.
146 const sal_uInt16 EXC_OBJ_ORIENT_90CCW = 2; /// 90 degr. counterclockwise.
147 const sal_uInt16 EXC_OBJ_ORIENT_90CW = 3; /// 90 degr. clockwise.
148
149 const sal_uInt16 EXC_OBJ_TEXT_AUTOSIZE = 0x0080;
150 const sal_uInt16 EXC_OBJ_TEXT_LOCKED = 0x0200;
151
152 const sal_Int32 EXC_OBJ_TEXT_MARGIN = 20000; /// Automatic text margin (EMUs).
153
154 // BIFF5 arc objects
155 const sal_uInt8 EXC_OBJ_ARC_TR = 0;
156 const sal_uInt8 EXC_OBJ_ARC_TL = 1;
157 const sal_uInt8 EXC_OBJ_ARC_BL = 2;
158 const sal_uInt8 EXC_OBJ_ARC_BR = 3;
159
160 // BIFF5 polygon objects
161 const sal_uInt16 EXC_OBJ_POLY_CLOSED = 0x0100;
162
163 // BIFF5 pictures/OLE objects
164 const sal_uInt16 EXC_OBJ_PIC_MANUALSIZE = 0x0001;
165 const sal_uInt16 EXC_OBJ_PIC_DDE = 0x0002;
166 const sal_uInt16 EXC_OBJ_PIC_SYMBOL = 0x0008;
167 const sal_uInt16 EXC_OBJ_PIC_CONTROL = 0x0010; /// Form control (BIFF8).
168 const sal_uInt16 EXC_OBJ_PIC_CTLSSTREAM = 0x0020; /// Data in Ctls stream (BIFF8).
169 const sal_uInt16 EXC_OBJ_PIC_AUTOLOAD = 0x0200; /// Auto-load form control (BIFF8).
170
171 // BIFF5 button objects
172 const sal_uInt16 EXC_OBJ_BUTTON_DEFAULT = 0x0001;
173 const sal_uInt16 EXC_OBJ_BUTTON_HELP = 0x0002;
174 const sal_uInt16 EXC_OBJ_BUTTON_CANCEL = 0x0004;
175 const sal_uInt16 EXC_OBJ_BUTTON_CLOSE = 0x0008;
176
177 // BIFF5 checkboxs, radio buttons
178 const sal_uInt16 EXC_OBJ_CHECKBOX_UNCHECKED = 0;
179 const sal_uInt16 EXC_OBJ_CHECKBOX_CHECKED = 1;
180 const sal_uInt16 EXC_OBJ_CHECKBOX_TRISTATE = 2;
181 const sal_uInt16 EXC_OBJ_CHECKBOX_FLAT = 0x0001;
182
183 // BIFF5 editbox objects
184 const sal_uInt16 EXC_OBJ_EDIT_TEXT = 0;
185 const sal_uInt16 EXC_OBJ_EDIT_INTEGER = 1;
186 const sal_uInt16 EXC_OBJ_EDIT_DOUBLE = 2;
187 const sal_uInt16 EXC_OBJ_EDIT_REFERENCE = 3;
188 const sal_uInt16 EXC_OBJ_EDIT_FORMULA = 4;
189
190 // BIFF5 scrollbars/spinbuttons
191 const sal_uInt16 EXC_OBJ_SCROLLBAR_MIN = 0;
192 const sal_uInt16 EXC_OBJ_SCROLLBAR_MAX = 30000;
193
194 const sal_uInt16 EXC_OBJ_SCROLLBAR_HOR = 0x0001;
195
196 const sal_uInt16 EXC_OBJ_SCROLLBAR_DEFFLAGS = 0x0001;
197 const sal_uInt16 EXC_OBJ_SCROLLBAR_FLAT = 0x0008;
198
199 // BIFF5 listboxes/dropdowns
200 const sal_uInt8 EXC_OBJ_LISTBOX_SINGLE = 0; /// Single selection.
201 const sal_uInt8 EXC_OBJ_LISTBOX_MULTI = 1; /// Multi selection.
202 const sal_uInt8 EXC_OBJ_LISTBOX_RANGE = 2; /// Range selection.
203
204 const sal_uInt16 EXC_OBJ_LISTBOX_EDIT = 0x0002;
205 const sal_uInt16 EXC_OBJ_LISTBOX_FLAT = 0x0008;
206
207 // BIFF5 dropdown listboxes
208 const sal_uInt16 EXC_OBJ_DROPDOWN_LISTBOX = 0; /// Listbox, text not editable.
209 const sal_uInt16 EXC_OBJ_DROPDOWN_COMBOBOX = 1; /// Dropdown listbox with editable text.
210 const sal_uInt16 EXC_OBJ_DROPDOWN_SIMPLE = 2; /// Dropdown button only, no text area.
211 const sal_uInt16 EXC_OBJ_DROPDOWN_MAX = 3;
212 const sal_uInt16 EXC_OBJ_DROPDOWN_FILTERED = 0x0008; /// Drowdown style: filtered.
213
214 // BIFF5 groupboxes
215 const sal_uInt16 EXC_OBJ_GROUPBOX_FLAT = 0x0001;
216
217 // BIFF8 sub records
218 const sal_uInt16 EXC_ID_OBJEND = 0x0000; /// End of OBJ.
219 const sal_uInt16 EXC_ID_OBJMACRO = 0x0004; /// Macro link.
220 const sal_uInt16 EXC_ID_OBJBUTTON = 0x0005; /// Button data.
221 const sal_uInt16 EXC_ID_OBJGMO = 0x0006; /// Group marker.
222 const sal_uInt16 EXC_ID_OBJCF = 0x0007; /// Clipboard format.
223 const sal_uInt16 EXC_ID_OBJFLAGS = 0x0008; /// Option flags.
224 const sal_uInt16 EXC_ID_OBJPICTFMLA = 0x0009; /// OLE link formula.
225 const sal_uInt16 EXC_ID_OBJCBLS = 0x000A; /// Check box/radio button data.
226 const sal_uInt16 EXC_ID_OBJRBO = 0x000B; /// Radio button group data.
227 const sal_uInt16 EXC_ID_OBJSBS = 0x000C; /// Scroll bar data.
228 const sal_uInt16 EXC_ID_OBJNTS = 0x000D; /// Note data.
229 const sal_uInt16 EXC_ID_OBJSBSFMLA = 0x000E; /// Scroll bar/list box/combo box cell link.
230 const sal_uInt16 EXC_ID_OBJGBODATA = 0x000F; /// Group box data.
231 const sal_uInt16 EXC_ID_OBJEDODATA = 0x0010; /// Edit box data.
232 const sal_uInt16 EXC_ID_OBJRBODATA = 0x0011; /// Radio button group data.
233 const sal_uInt16 EXC_ID_OBJCBLSDATA = 0x0012; /// Check box/radio button data.
234 const sal_uInt16 EXC_ID_OBJLBSDATA = 0x0013; /// List box/combo box data.
235 const sal_uInt16 EXC_ID_OBJCBLSFMLA = 0x0014; /// Check box/radio button cell link.
236 const sal_uInt16 EXC_ID_OBJCMO = 0x0015; /// Common object settings.
237 const sal_uInt16 EXC_ID_OBJUNKNOWN = 0xFFFF; /// For internal use only.
238
239 // BIFF8 OBJCMO: flags
240 const sal_uInt16 EXC_OBJCMO_PRINTABLE = 0x0010; /// Object printable.
241 const sal_uInt16 EXC_OBJCMO_AUTOLINE = 0x2000; /// Automatic line formatting.
242 const sal_uInt16 EXC_OBJCMO_AUTOFILL = 0x4000; /// Automatic fill formatting.
243
244 /** Value binding mode for cells linked to form controls. */
245 enum XclCtrlBindMode
246 {
247 EXC_CTRL_BINDCONTENT, /// Binds cell to content of control.
248 EXC_CTRL_BINDPOSITION /// Binds cell to position in control (e.g. listbox selection index).
249 };
250
251 // (0x007F) IMGDATA -----------------------------------------------------------
252
253 const sal_uInt16 EXC_ID3_IMGDATA = 0x007F;
254 const sal_uInt16 EXC_ID8_IMGDATA = 0x00E9;
255
256 const sal_uInt16 EXC_IMGDATA_WMF = 2;
257 const sal_uInt16 EXC_IMGDATA_BMP = 9;
258
259 const sal_uInt16 EXC_IMGDATA_WIN = 1;
260 const sal_uInt16 EXC_IMGDATA_MAC = 2;
261
262 const sal_uInt32 EXC_IMGDATA_MAXREC8 = 0x201C;
263 const sal_uInt32 EXC_IMGDATA_MAXCONT8 = 0x2014;
264
265 // (0x00A9) COORDLIST ---------------------------------------------------------
266
267 const sal_uInt16 EXC_ID_COORDLIST = 0x00A9;
268
269 // (0x00EB) MSODRAWINGGROUP ---------------------------------------------------
270
271 const sal_uInt16 EXC_ID_MSODRAWINGGROUP = 0x00EB;
272
273 // (0x00EC) MSODRAWING --------------------------------------------------------
274
275 const sal_uInt16 EXC_ID_MSODRAWING = 0x00EC;
276
277 // additional flags not extant in svx headers
278 const sal_uInt16 EXC_ESC_ANCHOR_POSLOCKED = 0x0001;
279 const sal_uInt16 EXC_ESC_ANCHOR_SIZELOCKED = 0x0002;
280 const sal_uInt16 EXC_ESC_ANCHOR_LOCKED = EXC_ESC_ANCHOR_POSLOCKED|EXC_ESC_ANCHOR_SIZELOCKED;
281
282 // (0x00ED) MSODRAWINGSELECTION -----------------------------------------------
283
284 const sal_uInt16 EXC_ID_MSODRAWINGSEL = 0x00ED;
285
286 // (0x01B6) TXO ---------------------------------------------------------------
287
288 const sal_uInt16 EXC_ID_TXO = 0x01B6;
289
290 // TXO constants are eqzal to BIFF5 OBJ text object flags
291
292 // Structs and classes ========================================================
293
294 /** Identifies a drawing object by sheet index and object identifier. */
295 struct XclObjId
296 {
297 SCTAB mnScTab; /// Calc sheet index.
298 sal_uInt16 mnObjId; /// Excel object identifier.
299
300 explicit XclObjId();
301 explicit XclObjId( SCTAB nScTab, sal_uInt16 nObjId );
302 };
303
304 bool operator==( const XclObjId& rL, const XclObjId& rR );
305 bool operator<( const XclObjId& rL, const XclObjId& rR );
306
307 // ----------------------------------------------------------------------------
308
309 /** Represents the position (anchor) of an object in a Calc document. */
310 struct XclObjAnchor : public XclRange
311 {
312 sal_uInt16 mnLX; /// X offset in left column (1/1024 of column width).
313 sal_uInt16 mnTY; /// Y offset in top row (1/256 of row height).
314 sal_uInt16 mnRX; /// X offset in right column (1/1024 of column width).
315 sal_uInt16 mnBY; /// Y offset in bottom row (1/256 of row height).
316
317 explicit XclObjAnchor();
318
319 /** Calculates a rectangle from the contained coordinates. */
320 Rectangle GetRect( const XclRoot& rRoot, SCTAB nScTab, MapUnit eMapUnit ) const;
321 /** Initializes the anchor coordinates for a sheet. */
322 void SetRect( const XclRoot& rRoot, SCTAB nScTab, const Rectangle& rRect, MapUnit eMapUnit );
323
324 /** Initializes the anchor coordinates for an embedded draw page. */
325 void SetRect( const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY,
326 const Rectangle& rRect, MapUnit eMapUnit, bool bDffAnchor );
327 };
328
329 template< typename StreamType >
operator >>(StreamType & rStrm,XclObjAnchor & rAnchor)330 StreamType& operator>>( StreamType& rStrm, XclObjAnchor& rAnchor )
331 {
332 return rStrm
333 >> rAnchor.maFirst.mnCol >> rAnchor.mnLX
334 >> rAnchor.maFirst.mnRow >> rAnchor.mnTY
335 >> rAnchor.maLast.mnCol >> rAnchor.mnRX
336 >> rAnchor.maLast.mnRow >> rAnchor.mnBY;
337 }
338
339 template< typename StreamType >
operator <<(StreamType & rStrm,const XclObjAnchor & rAnchor)340 StreamType& operator<<( StreamType& rStrm, const XclObjAnchor& rAnchor )
341 {
342 return rStrm
343 << rAnchor.maFirst.mnCol << rAnchor.mnLX
344 << rAnchor.maFirst.mnRow << rAnchor.mnTY
345 << rAnchor.maLast.mnCol << rAnchor.mnRX
346 << rAnchor.maLast.mnRow << rAnchor.mnBY;
347 }
348
349 // ----------------------------------------------------------------------------
350
351 struct XclObjLineData
352 {
353 sal_uInt8 mnColorIdx;
354 sal_uInt8 mnStyle;
355 sal_uInt8 mnWidth;
356 sal_uInt8 mnAuto;
357
358 explicit XclObjLineData();
359
IsAutoXclObjLineData360 inline bool IsAuto() const { return ::get_flag( mnAuto, EXC_OBJ_LINE_AUTO ); }
IsVisibleXclObjLineData361 inline bool IsVisible() const { return IsAuto() || (mnStyle != EXC_OBJ_LINE_NONE); }
362 };
363
364 XclImpStream& operator>>( XclImpStream& rStrm, XclObjLineData& rLineData );
365
366 // ----------------------------------------------------------------------------
367
368 struct XclObjFillData
369 {
370 sal_uInt8 mnBackColorIdx;
371 sal_uInt8 mnPattColorIdx;
372 sal_uInt8 mnPattern;
373 sal_uInt8 mnAuto;
374
375 explicit XclObjFillData();
376
IsAutoXclObjFillData377 inline bool IsAuto() const { return ::get_flag( mnAuto, EXC_OBJ_FILL_AUTO ); }
IsFilledXclObjFillData378 inline bool IsFilled() const { return IsAuto() || (mnPattern != EXC_PATT_NONE); }
379 };
380
381 XclImpStream& operator>>( XclImpStream& rStrm, XclObjFillData& rFillData );
382
383 // ----------------------------------------------------------------------------
384
385 struct XclObjTextData
386 {
387 sal_uInt16 mnTextLen;
388 sal_uInt16 mnFormatSize;
389 sal_uInt16 mnLinkSize;
390 sal_uInt16 mnDefFontIdx;
391 sal_uInt16 mnFlags;
392 sal_uInt16 mnOrient;
393 sal_uInt16 mnButtonFlags;
394 sal_uInt16 mnShortcut;
395 sal_uInt16 mnShortcutEA;
396
397 explicit XclObjTextData();
398
399 /** Reads text data from a BIFF3/BIFF4 OBJ record. */
400 void ReadObj3( XclImpStream& rStrm );
401 /** Reads text data from a BIFF5 OBJ record. */
402 void ReadObj5( XclImpStream& rStrm );
403 /** Reads text data from a BIFF8 TXO record. */
404 void ReadTxo8( XclImpStream& rStrm );
405
GetHorAlignXclObjTextData406 inline sal_uInt8 GetHorAlign() const { return ::extract_value< sal_uInt8 >( mnFlags, 1, 3 ); }
GetVerAlignXclObjTextData407 inline sal_uInt8 GetVerAlign() const { return ::extract_value< sal_uInt8 >( mnFlags, 4, 3 ); }
408 };
409
410 // ============================================================================
411
412 enum XclTbxEventType
413 {
414 EXC_TBX_EVENT_ACTION, /// XActionListener.actionPerformed
415 EXC_TBX_EVENT_MOUSE, /// XMouseListener.mouseReleased
416 EXC_TBX_EVENT_TEXT, /// XTextListener.textChanged
417 EXC_TBX_EVENT_VALUE, /// XAdjustmentListener.adjustmentValueChanged
418 EXC_TBX_EVENT_CHANGE /// XChangeListener.changed
419 };
420
421 // ----------------------------------------------------------------------------
422
423 /** Provides static helper functions for form controls. */
424 class XclControlHelper
425 {
426 public:
427 /** Returns the API control model from the passed API shape object. */
428 static ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >
429 GetControlModel( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape );
430
431 /** Fills the macro descriptor according to the passed macro name. */
432 static bool FillMacroDescriptor(
433 ::com::sun::star::script::ScriptEventDescriptor& rDescriptor,
434 XclTbxEventType eEventType,
435 const String& rXclMacroName,
436 SfxObjectShell* pDocShell = 0 );
437 /** Tries to extract an Excel macro name from the passed macro descriptor. */
438 static String ExtractFromMacroDescriptor(
439 const ::com::sun::star::script::ScriptEventDescriptor& rDescriptor,
440 XclTbxEventType eEventType );
441 };
442
443 // ============================================================================
444
445 #endif
446
447