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