Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SW_WRITERHELPER
21 : #define SW_WRITERHELPER
22 :
23 : #include <typeinfo>
24 : #include <vector>
25 : #include <map>
26 : #include <com/sun/star/embed/XEmbeddedObject.hpp>
27 :
28 : #include <sfx2/objsh.hxx>
29 : #include "types.hxx"
30 : #include <svl/itempool.hxx>
31 : #include <svl/itemset.hxx>
32 : #include <format.hxx>
33 : #include <node.hxx>
34 : #include <pam.hxx>
35 : #include <tools/poly.hxx>
36 : #include <doc.hxx>
37 :
38 : class SwTxtFmtColl;
39 : class SwCharFmt;
40 : class SdrObject;
41 : class SdrOle2Obj;
42 : class OutlinerParaObject;
43 : class SwNumFmt;
44 : class SwTxtNode;
45 : class SwNoTxtNode;
46 : class SwFmtCharFmt;
47 : class Graphic;
48 : class SwDoc;
49 : class SwNumRule;
50 :
51 : namespace sw
52 : {
53 : namespace util
54 : {
55 : class ItemSort
56 : : public std::binary_function<sal_uInt16, sal_uInt16, bool>
57 : {
58 : public:
59 : bool operator()(sal_uInt16 nA, sal_uInt16 nB) const;
60 : };
61 : }
62 : }
63 :
64 : namespace sw
65 : {
66 : /// STL container of Paragraph Styles (SwTxtFmtColl)
67 : typedef std::vector<SwTxtFmtColl *> ParaStyles;
68 : /// STL iterator for ParaStyles
69 : typedef ParaStyles::iterator ParaStyleIter;
70 : /// STL container of SfxPoolItems (Attributes)
71 : typedef std::map<sal_uInt16, const SfxPoolItem *, sw::util::ItemSort> PoolItems;
72 : /// STL const iterator for ParaStyles
73 : typedef PoolItems::const_iterator cPoolItemIter;
74 :
75 : /** Make exporting a Writer Frame easy
76 :
77 : In word all frames are effectively anchored to character or as
78 : character. This is nice and simple, writer is massively complex in this
79 : area, so this sw::Frame simplies matters by providing a single unified
80 : view of the multitute of elements in writer and their differing quirks.
81 :
82 : A sw::Frame wraps a writer frame and is guaranted to have a suitable
83 : anchor position available from it. It hides much of the needless
84 : complexity of the multitude of floating/inline elements in writer, it...
85 :
86 : Guarantees an anchor position for a frame.
87 : Provides a readable way to see if we are anchored inline. (as character)
88 : Provides a simple way to flag what type of entity this frame describes.
89 : Provides the size of the element as drawn by writer.
90 :
91 : @author
92 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
93 : */
94 6053 : class Frame
95 : {
96 : public:
97 : enum WriterSource {eTxtBox, eGraphic, eOle, eDrawing, eFormControl,eBulletGrf};
98 : private:
99 : const SwFrmFmt* mpFlyFrm;
100 : SwPosition maPos;
101 : Size maSize;
102 : // #i43447# - Size of the frame in the layout.
103 : // Especially needed for graphics, whose layout size can differ from its
104 : // size, because it is scaled into its environment.
105 : Size maLayoutSize;
106 :
107 : WriterSource meWriterType;
108 : const SwNode *mpStartFrameContent;
109 : bool mbIsInline;
110 : bool mbForBullet:1;
111 : Graphic maGrf;
112 : public:
113 : Frame(const SwFrmFmt &rFlyFrm, const SwPosition &rPos);
114 : Frame(const Graphic&, const SwPosition &);
115 :
116 : /** Get the writer SwFrmFmt that this object describes
117 :
118 : @return
119 : The wrapped SwFrmFmt
120 : */
121 3414 : const SwFrmFmt &GetFrmFmt() const { return *mpFlyFrm; }
122 :
123 : /** Get the position this frame is anchored at
124 :
125 : @return
126 : The anchor position of this frame
127 : */
128 53952 : const SwPosition &GetPosition() const { return maPos; }
129 :
130 : /** Get the node this frame is anchored into
131 :
132 : @return
133 : The SwTxtNode this frame is anchored inside
134 : */
135 518 : const SwCntntNode *GetCntntNode() const
136 518 : { return maPos.nNode.GetNode().GetCntntNode(); }
137 :
138 : /** Get the type of frame that this wraps
139 :
140 : @return
141 : a WriterSource which describes the source type of this wrapper
142 : */
143 488 : WriterSource GetWriterType() const { return meWriterType; }
144 :
145 : /** Is this frame inline (as character)
146 :
147 : @return
148 : whether this is inline or not
149 : */
150 : bool IsInline() const;
151 :
152 : /** Even if the frame isn't an inline frame, force it to behave as one
153 :
154 : There are a variety of circumstances where word cannot have
155 : anything except inline elements, e.g. inside frames. So its easier
156 : to force this sw::Frame into behaving as one, instead of special
157 : casing export code all over the place.
158 :
159 : */
160 : void ForceTreatAsInline();
161 :
162 : /** Get the first node of content in the frame
163 :
164 : @return
165 : the first node of content in the frame, might not be any at all.
166 : */
167 97 : const SwNode *GetContent() const { return mpStartFrameContent; }
168 0 : const Graphic &GetGraphic() const { return maGrf; }
169 0 : bool HasGraphic() const { return mbForBullet; }
170 :
171 : /** Does this sw::Frame refer to the same writer content as another
172 :
173 : @return
174 : if the two sw::Frames are handling the same writer frame
175 : */
176 0 : bool RefersToSameFrameAs(const Frame &rOther) const
177 : {
178 0 : if (mbForBullet && rOther.mbForBullet)
179 0 : return (maGrf == rOther.maGrf);
180 0 : else if ((!mbForBullet) && (!rOther.mbForBullet))
181 0 : return (mpFlyFrm == rOther.mpFlyFrm);
182 :
183 0 : return false;
184 : }
185 :
186 : /** The Size of the contained element
187 :
188 : @return
189 : the best size to use to export to word
190 : */
191 242 : const Size GetSize() const { return maSize; }
192 :
193 : /** The layout size of the contained element
194 :
195 : #i43447# - Needed for graphics, which are scaled into its environment
196 :
197 : @return layout size
198 : */
199 174 : const Size GetLayoutSize() const
200 : {
201 174 : return maLayoutSize;
202 : }
203 : };
204 :
205 : /// STL container of Frames
206 : typedef std::vector<Frame> Frames;
207 : /// STL iterator for Frames
208 : typedef std::vector<Frame>::iterator FrameIter;
209 : }
210 :
211 : namespace sw
212 : {
213 : namespace util
214 : {
215 : /** Provide a dynamic_cast style cast for SfxPoolItems
216 :
217 : A SfxPoolItem generally need to be cast back to its original type
218 : to be useful, which is both tedious and errorprone. So item_cast is
219 : a helper template to aid the process and test if the cast is
220 : correct.
221 :
222 : @param rItem
223 : The SfxPoolItem which is to be casted
224 :
225 : @tplparam T
226 : A SfxPoolItem derived class to cast rItem to
227 :
228 : @return A rItem upcasted back to a T
229 :
230 : @exception std::bad_cast Thrown if the rItem was not a T
231 :
232 : @author
233 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
234 : */
235 44786 : template<class T> const T & item_cast(const SfxPoolItem &rItem)
236 : throw(std::bad_cast)
237 : {
238 44786 : if (!rItem.IsA(STATICTYPE(T)))
239 0 : throw std::bad_cast();
240 44786 : return static_cast<const T &>(rItem);
241 : }
242 :
243 : /** Provide a dynamic_cast style cast for SfxPoolItems
244 :
245 : A SfxPoolItem generally need to be cast back to its original type
246 : to be useful, which is both tedious and errorprone. So item_cast is
247 : a helper template to aid the process and test if the cast is
248 : correct.
249 :
250 : @param pItem
251 : The SfxPoolItem which is to be casted
252 :
253 : @tplparam T
254 : A SfxPoolItem derived class to cast pItem to
255 :
256 : @return A pItem upcasted back to a T or 0 if pItem was not a T
257 :
258 : @author
259 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
260 : */
261 11966 : template<class T> const T * item_cast(const SfxPoolItem *pItem)
262 : {
263 11966 : if (pItem && !pItem->IsA(STATICTYPE(T)))
264 0 : pItem = 0;
265 11966 : return static_cast<const T *>(pItem);
266 : }
267 :
268 : /** Extract a SfxPoolItem derived property from a SwCntntNode
269 :
270 : Writer's attributes are retrieved by passing a numeric identifier
271 : and receiving a SfxPoolItem reference which must then typically be
272 : cast back to its original type which is both tedious and verbose.
273 :
274 : ItemGet uses item_cast () on the retrieved reference to test that the
275 : retrieved property is of the type that the developer thinks it is.
276 :
277 : @param rNode
278 : The SwCntntNode to retrieve the property from
279 :
280 : @param eType
281 : The numeric identifier of the property to be retrieved
282 :
283 : @tplparam T
284 : A SfxPoolItem derived class of the retrieved property
285 :
286 : @exception std::bad_cast Thrown if the property was not a T
287 :
288 : @return The T requested
289 :
290 : @author
291 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
292 : */
293 19525 : template<class T> const T & ItemGet(const SwCntntNode &rNode,
294 : sal_uInt16 eType) throw(std::bad_cast)
295 : {
296 19525 : return item_cast<T>(rNode.GetAttr(eType));
297 : }
298 :
299 : /** Extract a SfxPoolItem derived property from a SwFmt
300 :
301 : Writer's attributes are retrieved by passing a numeric identifier
302 : and receiving a SfxPoolItem reference which must then typically be
303 : cast back to its original type which is both tedious and verbose.
304 :
305 : ItemGet uses item_cast () on the retrieved reference to test that the
306 : retrieved property is of the type that the developer thinks it is.
307 :
308 : @param rFmt
309 : The SwFmt to retrieve the property from
310 :
311 : @param eType
312 : The numeric identifier of the property to be retrieved
313 :
314 : @tplparam T
315 : A SfxPoolItem derived class of the retrieved property
316 :
317 : @exception std::bad_cast Thrown if the property was not a T
318 :
319 : @author
320 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
321 : */
322 10667 : template<class T> const T & ItemGet(const SwFmt &rFmt,
323 : sal_uInt16 eType) throw(std::bad_cast, css::uno::RuntimeException)
324 : {
325 10667 : return item_cast<T>(rFmt.GetFmtAttr(eType));
326 : }
327 :
328 : /** Extract a SfxPoolItem derived property from a SfxItemSet
329 :
330 : Writer's attributes are retrieved by passing a numeric identifier
331 : and receiving a SfxPoolItem reference which must then typically be
332 : cast back to its original type which is both tedious and verbose.
333 :
334 : ItemGet uses item_cast () on the retrieved reference to test that the
335 : retrieved property is of the type that the developer thinks it is.
336 :
337 : @param rSet
338 : The SfxItemSet to retrieve the property from
339 :
340 : @param eType
341 : The numeric identifier of the property to be retrieved
342 :
343 : @tplparam T
344 : A SfxPoolItem derived class of the retrieved property
345 :
346 : @exception std::bad_cast Thrown if the property was not a T
347 :
348 : @return The T requested
349 :
350 : @author
351 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
352 : */
353 12939 : template<class T> const T & ItemGet(const SfxItemSet &rSet,
354 : sal_uInt16 eType) throw(std::bad_cast)
355 : {
356 12939 : return item_cast<T>(rSet.Get(eType));
357 : }
358 :
359 : /** Extract a default SfxPoolItem derived property from a SfxItemPool
360 :
361 : Writer's attributes are retrieved by passing a numeric identifier
362 : and receiving a SfxPoolItem reference which must then typically be
363 : cast back to its original type which is both tedious and verbose.
364 :
365 : DefaultItemGet returns a reference to the default property of a
366 : given SfxItemPool for a given property id, e.g. default fontsize
367 :
368 : DefaultItemGet uses item_cast () on the retrieved reference to test
369 : that the retrieved property is of the type that the developer thinks
370 : it is.
371 :
372 : @param rPool
373 : The SfxItemPool whose default property we want
374 :
375 : @param eType
376 : The numeric identifier of the default property to be retrieved
377 :
378 : @tplparam T
379 : A SfxPoolItem derived class of the retrieved property
380 :
381 : @exception std::bad_cast Thrown if the property was not a T
382 :
383 : @return The T requested
384 :
385 : @author
386 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
387 : */
388 14 : template<class T> const T & DefaultItemGet(const SfxItemPool &rPool,
389 : sal_uInt16 eType) throw(std::bad_cast)
390 : {
391 14 : return item_cast<T>(rPool.GetDefaultItem(eType));
392 : }
393 :
394 : /** Extract a default SfxPoolItem derived property from a SwDoc
395 :
396 : Writer's attributes are retrieved by passing a numeric identifier
397 : and receiving a SfxPoolItem reference which must then typically be
398 : cast back to its original type which is both tedious and verbose.
399 :
400 : DefaultItemGet returns a reference to the default property of a
401 : given SwDoc (Writer Document) for a given property id, e.g default
402 : fontsize
403 :
404 : DefaultItemGet uses item_cast () on the retrieved reference to test
405 : that the retrieved property is of the type that the developer thinks
406 : it is.
407 :
408 : @param rPool
409 : The SfxItemPool whose default property we want
410 :
411 : @param eType
412 : The numeric identifier of the default property to be retrieved
413 :
414 : @tplparam T
415 : A SfxPoolItem derived class of the retrieved property
416 :
417 : @exception std::bad_cast Thrown if the property was not a T
418 :
419 : @return The T requested
420 :
421 : @author
422 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
423 : */
424 14 : template<class T> const T & DefaultItemGet(const SwDoc &rDoc,
425 : sal_uInt16 eType) throw(std::bad_cast)
426 : {
427 14 : return DefaultItemGet<T>(rDoc.GetAttrPool(), eType);
428 : }
429 :
430 : /** Return a pointer to a SfxPoolItem derived class if it exists in an
431 : SfxItemSet
432 :
433 : Writer's attributes are retrieved by passing a numeric identifier
434 : and receiving a SfxPoolItem reference which must then typically be
435 : cast back to its original type which is both tedious and verbose.
436 :
437 : HasItem returns a pointer to the requested SfxPoolItem for a given
438 : property id if it exists in the SfxItemSet or its chain of parents,
439 : e.g. fontsize
440 :
441 : HasItem uses item_cast () on the retrieved pointer to test that the
442 : retrieved property is of the type that the developer thinks it is.
443 :
444 : @param rSet
445 : The SfxItemSet whose property we want
446 :
447 : @param eType
448 : The numeric identifier of the default property to be retrieved
449 :
450 : @tplparam T
451 : A SfxPoolItem derived class of the retrieved property
452 :
453 : @return The T requested or 0 if no T found with id eType
454 :
455 : @author
456 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
457 : */
458 4509 : template<class T> const T* HasItem(const SfxItemSet &rSet,
459 : sal_uInt16 eType)
460 : {
461 4509 : return item_cast<T>(rSet.GetItem(eType));
462 : }
463 :
464 : /** Return a pointer to a SfxPoolItem derived class if it exists in an
465 : SwFmt
466 :
467 : Writer's attributes are retrieved by passing a numeric identifier
468 : and receiving a SfxPoolItem reference which must then typically be
469 : cast back to its original type which is both tedious and verbose.
470 :
471 : HasItem returns a pointer to the requested SfxPoolItem for a given
472 : property id if it exists in the SwFmt e.g. fontsize
473 :
474 : HasItem uses item_cast () on the retrieved pointer to test that the
475 : retrieved property is of the type that the developer thinks it is.
476 :
477 : @param rSet
478 : The SwFmt whose property we want
479 :
480 : @param eType
481 : The numeric identifier of the default property to be retrieved
482 :
483 : @tplparam T
484 : A SfxPoolItem derived class of the retrieved property
485 :
486 : @return The T requested or 0 if no T found with id eType
487 :
488 : @author
489 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
490 : */
491 : template<class T> const T* HasItem(const SwFmt &rFmt,
492 : sal_uInt16 eType)
493 : {
494 : return HasItem<T>(rFmt.GetAttrSet(), eType);
495 : }
496 :
497 : /** Get the Paragraph Styles of a SwDoc
498 :
499 : Writer's styles are in one of those dreaded macro based pre-STL
500 : containers. Give me an STL container of the paragraph styles
501 : instead.
502 :
503 : @param rDoc
504 : The SwDoc document to get the styles from
505 :
506 : @return A ParaStyles containing the SwDoc's Paragraph Styles
507 :
508 : @author
509 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
510 : */
511 : ParaStyles GetParaStyles(const SwDoc &rDoc);
512 :
513 : /** Get a Paragraph Style which fits a given name
514 :
515 : Its surprisingly tricky to get a style when all you have is a name,
516 : but that's what this does
517 :
518 : @param rDoc
519 : The SwDoc document to search in
520 :
521 : @param rName
522 : The name of the style to search for
523 :
524 : @return A Paragraph Style if one exists which matches the name
525 :
526 : @author
527 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
528 : */
529 : SwTxtFmtColl* GetParaStyle(SwDoc &rDoc, const OUString& rName);
530 :
531 : /** Get a Character Style which fits a given name
532 :
533 : Its surprisingly tricky to get a style when all you have is a name,
534 : but that's what this does
535 :
536 : @param rDoc
537 : The SwDoc document to search in
538 :
539 : @param rName
540 : The name of the style to search for
541 :
542 : @return A Character Style if one exists which matches the name
543 :
544 : @author
545 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
546 : */
547 : SwCharFmt* GetCharStyle(SwDoc &rDoc, const OUString& rName);
548 :
549 : /** Sort sequence of Paragraph Styles by assigned outline style list level
550 :
551 : Sort ParaStyles in ascending order of assigned outline style list level,
552 : e.g. given Normal/Heading1/Heading2/.../Heading10 at their default
553 : assigned outline style list levels of body level/level 1/level 2/.../level 10
554 :
555 : #i98791#
556 : adjust the sorting algorithm due to introduced outline level attribute
557 :
558 : @param rStyles
559 : The ParaStyles to sort
560 :
561 : @author
562 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
563 : */
564 : void SortByAssignedOutlineStyleListLevel(ParaStyles &rStyles);
565 :
566 : /** Get the SfxPoolItems of a SfxItemSet
567 :
568 : Writer's SfxPoolItems (attributes) are in one of those dreaded
569 : macro based pre-STL containers. Give me an STL container of the
570 : items instead.
571 :
572 : @param rSet
573 : The SfxItemSet to get the items from
574 :
575 : @param rItems
576 : The sw::PoolItems to put the items into
577 :
578 : @author
579 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
580 : */
581 : void GetPoolItems(const SfxItemSet &rSet, PoolItems &rItems, bool bExportParentItemSet );
582 :
583 : const SfxPoolItem *SearchPoolItems(const PoolItems &rItems,
584 : sal_uInt16 eType);
585 :
586 7457 : template<class T> const T* HasItem(const sw::PoolItems &rItems,
587 : sal_uInt16 eType)
588 : {
589 7457 : return item_cast<T>(SearchPoolItems(rItems, eType));
590 : }
591 :
592 : /** Remove properties from an SfxItemSet which a SwFmtCharFmt overrides
593 :
594 : Given an SfxItemSet and a SwFmtCharFmt remove from the rSet all the
595 : properties which the SwFmtCharFmt would override. An SfxItemSet
596 : contains attributes, and a SwFmtCharFmt is a "Character Style",
597 : so if the SfxItemSet contains bold and so does the character style
598 : then delete bold from the SfxItemSet
599 :
600 : @param
601 : rFmt the SwFmtCharFmt which describes the Character Style
602 :
603 : @param
604 : rSet the SfxItemSet from which we want to remove any properties
605 : which the rFmt would override
606 :
607 : @author
608 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
609 :
610 : @see #i24291# for examples
611 : */
612 : void ClearOverridesFromSet(const SwFmtCharFmt &rFmt, SfxItemSet &rSet);
613 :
614 : /** Get the Floating elements in a SwDoc
615 :
616 : Writer's FrmFmts may or may not be anchored to some text content,
617 : e.g. Page Anchored elements will not be. For the winword export we
618 : need them to have something to be anchored to. So this method
619 : returns all the floating elements in a document as a STL container
620 : of sw::Frames which are guaranteed to have an appropriate anchor.
621 :
622 : @param rDoc
623 : The SwDoc document to get the styles from
624 :
625 : @param pPaM
626 : The SwPam to describe the selection in the document to get the
627 : elements from. 0 means the entire document.
628 :
629 : @return A Frames containing the selections Floating elements
630 :
631 : @author
632 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
633 : */
634 : Frames GetFrames(const SwDoc &rDoc, SwPaM *pPaM = 0);
635 :
636 : /** Get the Frames anchored to a given node
637 :
638 : Given a container of frames, find the ones anchored to a given node
639 :
640 : @param rFrames
641 : The container of frames to search in
642 :
643 : @param rNode
644 : The SwNode to check for anchors to
645 :
646 : @return the Frames in rFrames anchored to rNode
647 :
648 : @author
649 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
650 : */
651 : Frames GetFramesInNode(const Frames &rFrames, const SwNode &rNode);
652 :
653 : /** Get the Numbering Format used on a paragraph
654 :
655 : There are two differing types of numbering formats that may be on a
656 : paragraph, normal and outline. The outline is that numbering you
657 : see in tools->outline numbering. Theres no difference in the
658 : numbering itself, just how you get it from the SwTxtNode. Needless
659 : to say the filter generally couldn't care less what type of
660 : numbering is in use.
661 :
662 : @param rTxtNode
663 : The SwTxtNode that is the paragraph
664 :
665 : @return A SwNumFmt pointer that describes the numbering level
666 : on this paragraph, or 0 if there is none.
667 :
668 : @author
669 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
670 : */
671 : const SwNumFmt* GetNumFmtFromTxtNode(const SwTxtNode &rTxtNode);
672 :
673 : /** Get the Numbering Format for a given level from a numbering rule
674 :
675 : @param rRule
676 : The numbering rule
677 :
678 : @param nLevel
679 : The numbering level
680 :
681 : @return A SwNumFmt pointer that describes the numbering level
682 : or 0 if the nLevel is out of range
683 :
684 : @author
685 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
686 : */
687 : const SwNumFmt* GetNumFmtFromSwNumRuleLevel(const SwNumRule &rRule,
688 : int nLevel);
689 :
690 : const SwNumRule* GetNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
691 : const SwNumRule* GetNormalNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
692 :
693 : /** Get the SwNoTxtNode associated with a SwFrmFmt if here is one
694 :
695 : There are two differing types of numbering formats that may be on a
696 : paragraph, normal and outline. The outline is that numbering you
697 : see in tools->outline numbering. Theres no difference in the
698 : numbering itself, just how you get it from the SwTxtNode. Needless
699 : to say the filter generally couldn't care less what type of
700 : numbering is in use.
701 :
702 : @param rFmt
703 : The SwFrmFmt that may describe a graphic
704 :
705 : @return A SwNoTxtNode pointer that describes the graphic of this
706 : frame if there is one, or 0 if there is none.
707 :
708 : @author
709 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
710 : */
711 : SwNoTxtNode *GetNoTxtNodeFromSwFrmFmt(const SwFrmFmt &rFmt);
712 :
713 : /** Does a node have a "page break before" applied
714 :
715 : Both text nodes and tables in writer can have "page break before"
716 : This function gives a unified view to both entities
717 :
718 : @param rNode
719 : The SwNode to query the page break of
720 :
721 : @return true if there is a page break, false otherwise
722 :
723 : @author
724 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
725 : */
726 : bool HasPageBreak(const SwNode &rNode);
727 :
728 : /** Make a best fit Polygon from a PolyPolygon
729 :
730 : For custom contours in writer we use a PolyPolygon, while word uses
731 : a simple polygon, so we need to try and make the best polygon from
732 : a PolyPolygon
733 :
734 : @param rPolyPoly
735 : The PolyPolygon to try and turn into a Polygon
736 :
737 : @return best fit Polygon from rPolyPoly
738 :
739 : @author
740 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
741 : */
742 : Polygon PolygonFromPolyPolygon(const PolyPolygon &rPolyPoly);
743 :
744 : /** Make setting a drawing object's layer in a Writer document easy
745 :
746 : Word has the simple concept of a drawing object either in the
747 : foreground and in the background. We have an additional complexity
748 : that form components live in a separate layer, which seems
749 : unnecessarily complicated. So in the winword filter we set the
750 : object's layer through this class with either SendObjectToHell for
751 : the bottom layer and SendObjectToHeaven for the top and we don't
752 : worry about the odd form layer design wrinkle.
753 :
754 : @author
755 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
756 : */
757 : class SetLayer
758 : {
759 : private:
760 : sal_uInt8 mnHeavenLayer, mnHellLayer, mnFormLayer;
761 : enum Layer {eHeaven, eHell};
762 : void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
763 : void Swap(SetLayer &rOther) throw();
764 : public:
765 :
766 : /** Make Object live in the bottom drawing layer
767 :
768 : @param rObject
769 : The object to be set to the bottom layer
770 : */
771 : void SendObjectToHell(SdrObject &rObject) const;
772 :
773 : /** Make Object lives in the top top layer
774 :
775 : @param rObject
776 : The object to be set to the bottom layer
777 : */
778 : void SendObjectToHeaven(SdrObject &rObject) const;
779 :
780 : /** Normal constructor
781 :
782 : @param rDoc
783 : The Writer document whose drawing layers we will be inserting
784 : objects into
785 : */
786 : SetLayer(const SwDoc &rDoc);
787 :
788 : SetLayer(const SetLayer &rOther) throw();
789 : SetLayer& operator=(const SetLayer &rOther) throw();
790 : };
791 : }
792 :
793 : namespace hack
794 : {
795 : /** Map an ID valid in one SfxItemPool to its equivalent in another
796 :
797 : Given a WhichId (the id that identifies a property e.g. bold) which
798 : is correct in a given SfxItemPool, get the equivalent whichId in
799 : another SfxItemPool
800 :
801 : This arises because the drawing layer uses the same properties as
802 : writer e.g. SvxWeight, but for some reason uses different ids
803 : for the same properties as writer.
804 :
805 : @param rDestPool
806 : The SfxItemPool in whose terms the Id is returned
807 :
808 : @param rSrcPool
809 : The SfxItemPool in whose terms the Id is passed in
810 :
811 : @param nWhich
812 : The Id to transform from source to dest
813 :
814 : @return 0 on failure, the correct property Id on success
815 :
816 : @author
817 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
818 : */
819 : sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool,
820 : const SfxItemPool &rSrcPool, sal_uInt16 nWhich);
821 :
822 : /** Map a SwDoc WhichId to the equivalent Id for a given SfxItemSet
823 :
824 : Given a WhichId (the id that identifies a property e.g. bold) which
825 : is correct for a Writer document, get the equivalent whichId which
826 : for a given SfxItemSet.
827 :
828 : This arises because the drawing layer uses the same properties as
829 : writer e.g. SvxWeight, but for some reason uses different ids
830 : for the same properties as writer.
831 :
832 : This is effectively the same as TransformWhichBetweenPools except
833 : at a slightly different layer.
834 :
835 : @param rSet
836 : The SfxItemSet in whose terms the Id is returned
837 :
838 : @param rDoc
839 : The SwDoc in whose terms the Id is passed in
840 :
841 : @param nWhich
842 : The Id to transform from writer to the SfxItemSet's domain
843 :
844 : @return 0 on failure, the correct SfxItemSet Id on success
845 :
846 : @author
847 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
848 : */
849 : sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
850 : const SwDoc &rDoc, sal_uInt16 nWhich);
851 :
852 : /** Make inserting an OLE object into a Writer document easy
853 :
854 : The rest of Office uses SdrOle2Obj for their OLE objects, Writer
855 : doesn't, which makes things a bit difficult as this is the type of
856 : object that the escher import code shared by the MSOffice filters
857 : produces when it imports an OLE object.
858 :
859 : This utility class takes ownership of the OLE object away from a
860 : SdrOle2Obj and can massage it into the condition best suited to
861 : insertion into Writer.
862 :
863 : If the object was not transferred into Writer then it is deleted
864 : during destruction.
865 :
866 : @author
867 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
868 : */
869 : class DrawingOLEAdaptor
870 : {
871 : private:
872 : OUString msOrigPersistName;
873 : com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject > mxIPRef;
874 : SfxObjectShell& mrPers;
875 : const Graphic* mpGraphic;
876 : public:
877 : /** Take ownership of a SdrOle2Objs OLE object
878 :
879 : @param rObj
880 : The SdrOle2Obj whose OLE object we want to take control of
881 :
882 : @param rPers
883 : The SvPersist of a SwDoc (SwDoc::GetPersist()) into which we
884 : may want to move the object, or remove it from if unwanted.
885 : */
886 : DrawingOLEAdaptor(SdrOle2Obj &rObj, SfxObjectShell &rPers);
887 :
888 : /// Destructor will destroy the owned OLE object if not transferred
889 : ~DrawingOLEAdaptor();
890 :
891 : /** Transfer ownership of the OLE object to a document's SvPersist
892 :
893 : TransferToDoc moves the object into the persist under the name
894 : passed in. This name is then suitable to be used as an argument
895 : to SwDoc::InsertOLE.
896 :
897 : The object is no longer owned by the adaptor after this call,
898 : subsequent calls are an error and return false.
899 :
900 : @param rName
901 : The name to store the object under in the document.
902 :
903 : @return On success true is returned, otherwise false. On
904 : success rName is then suitable for user with SwDoc::InsertOLE
905 : */
906 : bool TransferToDoc(OUString &rName);
907 : private:
908 : /// No assigning allowed
909 : DrawingOLEAdaptor& operator=(const DrawingOLEAdaptor&);
910 : /// No copying allowed
911 : DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc);
912 : };
913 : }
914 : }
915 :
916 : #endif
917 :
918 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|