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