sc: factor out some more code
[LibreOffice.git] / sw / source / ui / frmdlg / frmpage.cxx
blobd4265da6df75b31ef3fc903af3740634ffa9d27a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/embed/Aspects.hpp>
21 #include <com/sun/star/embed/EmbedMisc.hpp>
22 #include <com/sun/star/embed/XEmbeddedObject.hpp>
24 #include <cmdid.h>
25 #include <hintids.hxx>
26 #include <bitmaps.hlst>
27 #include <o3tl/safeint.hxx>
28 #include <vcl/mnemonic.hxx>
29 #include <svl/stritem.hxx>
30 #include <sfx2/htmlmode.hxx>
31 #include <editeng/opaqitem.hxx>
32 #include <editeng/protitem.hxx>
33 #include <editeng/prntitem.hxx>
34 #include <editeng/brushitem.hxx>
35 #include <editeng/ulspitem.hxx>
36 #include <editeng/frmdiritem.hxx>
37 #include <svx/swframeposstrings.hxx>
38 #include <svx/swframevalidation.hxx>
39 #include <svx/sdangitm.hxx>
40 #include <comphelper/classids.hxx>
41 #include <tools/globname.hxx>
42 #include <tools/urlobj.hxx>
43 #include <fmturl.hxx>
44 #include <fmteiro.hxx>
45 #include <fmtcnct.hxx>
46 #include <fmtsrnd.hxx>
47 #include <view.hxx>
48 #include <wrtsh.hxx>
49 #include <swmodule.hxx>
50 #include <uitool.hxx>
51 #include <docsh.hxx>
52 #include <viewopt.hxx>
53 #include <frmdlg.hxx>
54 #include <frmmgr.hxx>
55 #include <frmpage.hxx>
56 #include <colmgr.hxx>
57 #include <grfatr.hxx>
58 #include <fmtfollowtextflow.hxx>
59 #include <svx/sdtaitm.hxx>
60 #include <sal/macros.h>
61 #include <osl/diagnose.h>
63 #include <strings.hrc>
64 #include <formatflysplit.hxx>
65 #include <fmtcntnt.hxx>
66 #include <svx/strings.hrc>
67 #include <svx/dialmgr.hxx>
68 #include <svx/graphichelper.hxx>
69 #include <sfx2/filedlghelper.hxx>
70 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
71 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
72 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
73 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
74 #include <vcl/graphicfilter.hxx>
75 #include <svtools/embedhlp.hxx>
76 #include <comphelper/lok.hxx>
77 #include <memory>
79 using namespace ::com::sun::star;
80 using namespace ::sfx2;
82 #define SwFPos SvxSwFramePosString
84 namespace {
86 struct StringIdPair_Impl
88 SvxSwFramePosString::StringId eHori;
89 SvxSwFramePosString::StringId eVert;
94 #define MAX_PERCENT_WIDTH SAL_CONST_INT64(254)
95 #define MAX_PERCENT_HEIGHT SAL_CONST_INT64(254)
97 namespace {
99 enum class LB {
100 NONE = 0x00000000L,
101 Frame = 0x00000001L, // text region of the paragraph
102 PrintArea = 0x00000002L, // text region of the paragraph + indentions
103 VertFrame = 0x00000004L, // vertical text region of the paragraph
104 VertPrintArea = 0x00000008L, // vertical text region of the paragraph + indentions
105 RelFrameLeft = 0x00000010L, // left paragraph edge
106 RelFrameRight = 0x00000020L, // right paragraph edge
108 RelPageLeft = 0x00000040L, // left page edge
109 RelPageRight = 0x00000080L, // right page edge
110 RelPageFrame = 0x00000100L, // whole page
111 RelPagePrintArea = 0x00000200L, // text region of the page
113 FlyRelPageLeft = 0x00000400L, // left frame edge
114 FlyRelPageRight = 0x00000800L, // right frame edge
115 FlyRelPageFrame = 0x00001000L, // whole frame
116 FlyRelPagePrintArea = 0x00002000L, // inside of the frame
118 RelBase = 0x00010000L, // character alignment Base
119 RelChar = 0x00020000L, // character alignment Character
120 RelRow = 0x00040000L, // character alignment Row
122 FlyVertFrame = 0x00100000L, // vertical entire frame
123 FlyVertPrintArea = 0x00200000L, // vertical frame text area
125 VertLine = 0x00400000L, // vertical text line
130 namespace o3tl {
131 template<> struct typed_flags<LB> : is_typed_flags<LB, 0x00773fffL> {};
134 namespace {
136 struct RelationMap
138 SvxSwFramePosString::StringId eStrId;
139 SvxSwFramePosString::StringId eMirrorStrId;
140 LB nLBRelation;
141 sal_Int16 nRelation;
146 struct FrameMap
148 SvxSwFramePosString::StringId eStrId;
149 SvxSwFramePosString::StringId eMirrorStrId;
150 sal_Int16 nAlign;
151 LB nLBRelations;
155 RelationMap const aRelationMap[] =
157 {SwFPos::FRAME, SwFPos::FRAME, LB::Frame, text::RelOrientation::FRAME},
158 {SwFPos::PRTAREA, SwFPos::PRTAREA, LB::PrintArea, text::RelOrientation::PRINT_AREA},
159 {SwFPos::REL_PG_LEFT, SwFPos::MIR_REL_PG_LEFT, LB::RelPageLeft, text::RelOrientation::PAGE_LEFT},
160 {SwFPos::REL_PG_RIGHT, SwFPos::MIR_REL_PG_RIGHT, LB::RelPageRight, text::RelOrientation::PAGE_RIGHT},
161 {SwFPos::REL_FRM_LEFT, SwFPos::MIR_REL_FRM_LEFT, LB::RelFrameLeft, text::RelOrientation::FRAME_LEFT},
162 {SwFPos::REL_FRM_RIGHT, SwFPos::MIR_REL_FRM_RIGHT, LB::RelFrameRight, text::RelOrientation::FRAME_RIGHT},
163 {SwFPos::REL_PG_FRAME, SwFPos::REL_PG_FRAME, LB::RelPageFrame, text::RelOrientation::PAGE_FRAME},
164 {SwFPos::REL_PG_PRTAREA, SwFPos::REL_PG_PRTAREA, LB::RelPagePrintArea, text::RelOrientation::PAGE_PRINT_AREA},
165 {SwFPos::REL_CHAR, SwFPos::REL_CHAR, LB::RelChar, text::RelOrientation::CHAR},
167 {SwFPos::FLY_REL_PG_LEFT, SwFPos::FLY_MIR_REL_PG_LEFT, LB::FlyRelPageLeft, text::RelOrientation::PAGE_LEFT},
168 {SwFPos::FLY_REL_PG_RIGHT, SwFPos::FLY_MIR_REL_PG_RIGHT, LB::FlyRelPageRight, text::RelOrientation::PAGE_RIGHT},
169 {SwFPos::FLY_REL_PG_FRAME, SwFPos::FLY_REL_PG_FRAME, LB::FlyRelPageFrame, text::RelOrientation::PAGE_FRAME},
170 {SwFPos::FLY_REL_PG_PRTAREA, SwFPos::FLY_REL_PG_PRTAREA, LB::FlyRelPagePrintArea, text::RelOrientation::PAGE_PRINT_AREA},
172 {SwFPos::REL_BORDER, SwFPos::REL_BORDER, LB::VertFrame, text::RelOrientation::FRAME},
173 {SwFPos::REL_PRTAREA, SwFPos::REL_PRTAREA, LB::VertPrintArea, text::RelOrientation::PRINT_AREA},
175 {SwFPos::FLY_REL_PG_FRAME, SwFPos::FLY_REL_PG_FRAME, LB::FlyVertFrame, text::RelOrientation::FRAME},
176 {SwFPos::FLY_REL_PG_PRTAREA, SwFPos::FLY_REL_PG_PRTAREA, LB::FlyVertPrintArea, text::RelOrientation::PRINT_AREA},
178 {SwFPos::REL_LINE, SwFPos::REL_LINE, LB::VertLine, text::RelOrientation::TEXT_LINE}
181 RelationMap const aAsCharRelationMap[] =
183 {SwFPos::REL_BASE, SwFPos::REL_BASE, LB::RelBase, text::RelOrientation::FRAME},
184 {SwFPos::REL_CHAR, SwFPos::REL_CHAR, LB::RelChar, text::RelOrientation::FRAME},
185 {SwFPos::REL_ROW, SwFPos::REL_ROW, LB::RelRow, text::RelOrientation::FRAME}
188 // site anchored
189 constexpr auto HORI_PAGE_REL = LB::RelPageFrame | LB::RelPagePrintArea | LB::RelPageLeft |
190 LB::RelPageRight;
192 FrameMap const aHPageMap[] =
194 {SwFPos::LEFT, SwFPos::MIR_LEFT, text::HoriOrientation::LEFT, HORI_PAGE_REL},
195 {SwFPos::RIGHT, SwFPos::MIR_RIGHT, text::HoriOrientation::RIGHT, HORI_PAGE_REL},
196 {SwFPos::CENTER_HORI, SwFPos::CENTER_HORI, text::HoriOrientation::CENTER, HORI_PAGE_REL},
197 {SwFPos::FROMLEFT, SwFPos::MIR_FROMLEFT, text::HoriOrientation::NONE, HORI_PAGE_REL}
200 FrameMap const aHPageHtmlMap[] =
202 {SwFPos::FROMLEFT, SwFPos::MIR_FROMLEFT, text::HoriOrientation::NONE, LB::RelPageFrame}
205 #define VERT_PAGE_REL (LB::RelPageFrame|LB::RelPagePrintArea)
207 FrameMap const aVPageMap[] =
209 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, VERT_PAGE_REL},
210 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::BOTTOM, VERT_PAGE_REL},
211 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::CENTER, VERT_PAGE_REL},
212 {SwFPos::FROMTOP, SwFPos::FROMTOP, text::VertOrientation::NONE, VERT_PAGE_REL}
215 FrameMap const aVPageHtmlMap[] =
217 {SwFPos::FROMTOP, SwFPos::FROMTOP, text::VertOrientation::NONE, LB::RelPageFrame}
220 // frame anchored
221 constexpr auto HORI_FRAME_REL = LB::FlyRelPageFrame | LB::FlyRelPagePrintArea |
222 LB::FlyRelPageLeft | LB::FlyRelPageRight;
224 FrameMap const aHFrameMap[] =
226 {SwFPos::LEFT, SwFPos::MIR_LEFT, text::HoriOrientation::LEFT, HORI_FRAME_REL},
227 {SwFPos::RIGHT, SwFPos::MIR_RIGHT, text::HoriOrientation::RIGHT, HORI_FRAME_REL},
228 {SwFPos::CENTER_HORI, SwFPos::CENTER_HORI, text::HoriOrientation::CENTER, HORI_FRAME_REL},
229 {SwFPos::FROMLEFT, SwFPos::MIR_FROMLEFT, text::HoriOrientation::NONE, HORI_FRAME_REL}
232 FrameMap const aHFlyHtmlMap[] =
234 {SwFPos::LEFT, SwFPos::MIR_LEFT, text::HoriOrientation::LEFT, LB::FlyRelPageFrame},
235 {SwFPos::FROMLEFT, SwFPos::MIR_FROMLEFT, text::HoriOrientation::NONE, LB::FlyRelPageFrame}
238 // own vertical alignment map for objects anchored to frame
239 #define VERT_FRAME_REL (LB::FlyVertFrame|LB::FlyVertPrintArea)
241 FrameMap const aVFrameMap[] =
243 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, VERT_FRAME_REL},
244 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::BOTTOM, VERT_FRAME_REL},
245 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::CENTER, VERT_FRAME_REL},
246 {SwFPos::FROMTOP, SwFPos::FROMTOP, text::VertOrientation::NONE, VERT_FRAME_REL}
249 FrameMap const aVFlyHtmlMap[] =
251 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, LB::FlyVertFrame},
252 {SwFPos::FROMTOP, SwFPos::FROMTOP, text::VertOrientation::NONE, LB::FlyVertFrame}
255 // paragraph anchored
256 constexpr auto HORI_PARA_REL = LB::Frame | LB::PrintArea | LB::RelPageLeft | LB::RelPageRight |
257 LB::RelPageFrame | LB::RelPagePrintArea | LB::RelFrameLeft |
258 LB::RelFrameRight;
260 FrameMap const aHParaMap[] =
262 {SwFPos::LEFT, SwFPos::MIR_LEFT, text::HoriOrientation::LEFT, HORI_PARA_REL},
263 {SwFPos::RIGHT, SwFPos::MIR_RIGHT, text::HoriOrientation::RIGHT, HORI_PARA_REL},
264 {SwFPos::CENTER_HORI, SwFPos::CENTER_HORI, text::HoriOrientation::CENTER, HORI_PARA_REL},
265 {SwFPos::FROMLEFT, SwFPos::MIR_FROMLEFT, text::HoriOrientation::NONE, HORI_PARA_REL}
268 #define HTML_HORI_PARA_REL (LB::Frame|LB::PrintArea)
270 FrameMap const aHParaHtmlMap[] =
272 {SwFPos::LEFT, SwFPos::LEFT, text::HoriOrientation::LEFT, HTML_HORI_PARA_REL},
273 {SwFPos::RIGHT, SwFPos::RIGHT, text::HoriOrientation::RIGHT, HTML_HORI_PARA_REL}
276 FrameMap const aHParaHtmlAbsMap[] =
278 {SwFPos::LEFT, SwFPos::MIR_LEFT, text::HoriOrientation::LEFT, HTML_HORI_PARA_REL},
279 {SwFPos::RIGHT, SwFPos::MIR_RIGHT, text::HoriOrientation::RIGHT, HTML_HORI_PARA_REL}
282 // allow vertical alignment at page areas
283 constexpr auto VERT_PARA_REL = LB::VertFrame | LB::VertPrintArea |
284 LB::RelPageFrame | LB::RelPagePrintArea;
286 FrameMap const aVParaMap[] =
288 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, VERT_PARA_REL},
289 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::BOTTOM, VERT_PARA_REL},
290 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::CENTER, VERT_PARA_REL},
291 {SwFPos::FROMTOP, SwFPos::FROMTOP, text::VertOrientation::NONE, VERT_PARA_REL}
294 FrameMap const aVParaHtmlMap[] =
296 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, LB::VertPrintArea}
299 // anchored relative to the character
300 constexpr auto HORI_CHAR_REL = LB::Frame|LB::PrintArea | LB::RelPageLeft | LB::RelPageRight |
301 LB::RelPageFrame | LB::RelPagePrintArea | LB::RelFrameLeft |
302 LB::RelFrameRight | LB::RelChar;
304 FrameMap const aHCharMap[] =
306 {SwFPos::LEFT, SwFPos::MIR_LEFT, text::HoriOrientation::LEFT, HORI_CHAR_REL},
307 {SwFPos::RIGHT, SwFPos::MIR_RIGHT, text::HoriOrientation::RIGHT, HORI_CHAR_REL},
308 {SwFPos::CENTER_HORI, SwFPos::CENTER_HORI, text::HoriOrientation::CENTER, HORI_CHAR_REL},
309 {SwFPos::FROMLEFT, SwFPos::MIR_FROMLEFT, text::HoriOrientation::NONE, HORI_CHAR_REL}
312 #define HTML_HORI_CHAR_REL (LB::Frame|LB::PrintArea|LB::RelChar)
314 FrameMap const aHCharHtmlMap[] =
316 {SwFPos::LEFT, SwFPos::LEFT, text::HoriOrientation::LEFT, HTML_HORI_CHAR_REL},
317 {SwFPos::RIGHT, SwFPos::RIGHT, text::HoriOrientation::RIGHT, HTML_HORI_CHAR_REL}
320 FrameMap const aHCharHtmlAbsMap[] =
322 {SwFPos::LEFT, SwFPos::MIR_LEFT, text::HoriOrientation::LEFT, LB::PrintArea|LB::RelChar},
323 {SwFPos::RIGHT, SwFPos::MIR_RIGHT, text::HoriOrientation::RIGHT, LB::PrintArea},
324 {SwFPos::FROMLEFT, SwFPos::MIR_FROMLEFT, text::HoriOrientation::NONE, LB::RelPageFrame}
327 // allow vertical alignment at page areas
328 constexpr auto VERT_CHAR_REL = LB::VertFrame | LB::VertPrintArea |
329 LB::RelPageFrame | LB::RelPagePrintArea;
331 FrameMap const aVCharMap[] =
333 // introduce mappings for new vertical alignment at top of line <LB::VertLine>
334 // and correct mapping for vertical alignment at character for position <FROM_BOTTOM>
335 // Note: Because of these adjustments the map becomes ambiguous in its values
336 // <eStrId>/<eMirrorStrId> and <nAlign>. These ambiguities are considered
337 // in the methods <SwFramePage::FillRelLB(..)>, <SwFramePage::GetAlignment(..)>
338 // and <SwFramePage::FillPosLB(..)>
339 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, VERT_CHAR_REL|LB::RelChar},
340 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::BOTTOM, VERT_CHAR_REL|LB::RelChar},
341 {SwFPos::BELOW, SwFPos::BELOW, text::VertOrientation::CHAR_BOTTOM, LB::RelChar},
342 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::CENTER, VERT_CHAR_REL|LB::RelChar},
343 {SwFPos::FROMTOP, SwFPos::FROMTOP, text::VertOrientation::NONE, VERT_CHAR_REL},
344 {SwFPos::FROMBOTTOM, SwFPos::FROMBOTTOM, text::VertOrientation::NONE, LB::RelChar|LB::VertLine},
345 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::LINE_TOP, LB::VertLine},
346 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::LINE_BOTTOM, LB::VertLine},
347 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::LINE_CENTER, LB::VertLine}
350 FrameMap const aVCharHtmlMap[] =
352 {SwFPos::BELOW, SwFPos::BELOW, text::VertOrientation::CHAR_BOTTOM, LB::RelChar}
355 FrameMap const aVCharHtmlAbsMap[] =
357 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, LB::RelChar},
358 {SwFPos::BELOW, SwFPos::BELOW, text::VertOrientation::CHAR_BOTTOM, LB::RelChar}
361 // anchored as character
362 FrameMap const aVAsCharMap[] =
364 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, LB::RelBase},
365 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::BOTTOM, LB::RelBase},
366 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::CENTER, LB::RelBase},
368 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::CHAR_TOP, LB::RelChar},
369 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::CHAR_BOTTOM, LB::RelChar},
370 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::CHAR_CENTER, LB::RelChar},
372 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::LINE_TOP, LB::RelRow},
373 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::LINE_BOTTOM, LB::RelRow},
374 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::LINE_CENTER, LB::RelRow},
376 {SwFPos::FROMBOTTOM, SwFPos::FROMBOTTOM, text::VertOrientation::NONE, LB::RelBase}
379 FrameMap const aVAsCharHtmlMap[] =
381 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::TOP, LB::RelBase},
382 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::CENTER, LB::RelBase},
384 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::CHAR_TOP, LB::RelChar},
386 {SwFPos::TOP, SwFPos::TOP, text::VertOrientation::LINE_TOP, LB::RelRow},
387 {SwFPos::BOTTOM, SwFPos::BOTTOM, text::VertOrientation::LINE_BOTTOM, LB::RelRow},
388 {SwFPos::CENTER_VERT, SwFPos::CENTER_VERT, text::VertOrientation::LINE_CENTER, LB::RelRow}
391 const WhichRangesContainer SwFramePage::s_aPageRg(svl::Items<
392 RES_FRM_SIZE, RES_FRM_SIZE,
393 RES_PROTECT, RES_PROTECT,
394 RES_VERT_ORIENT, RES_ANCHOR,
395 RES_COL, RES_COL,
396 RES_FOLLOW_TEXT_FLOW, RES_FOLLOW_TEXT_FLOW
398 const WhichRangesContainer SwFrameAddPage::s_aAddPgRg(svl::Items<
399 RES_PRINT, RES_PRINT,
400 FN_SET_FRM_NAME, FN_SET_FRM_NAME,
401 FN_SET_FRM_ALT_NAME, FN_SET_FRM_ALT_NAME,
402 FN_UNO_DESCRIPTION, FN_UNO_DESCRIPTION
405 static size_t lcl_GetFrameMapCount( const FrameMap* pMap)
407 if ( pMap )
409 if( pMap == aVParaHtmlMap)
410 return std::size(aVParaHtmlMap);
411 if( pMap == aVAsCharHtmlMap)
412 return std::size(aVAsCharHtmlMap);
413 if( pMap == aHParaHtmlMap)
414 return std::size(aHParaHtmlMap);
415 if( pMap == aHParaHtmlAbsMap)
416 return std::size(aHParaHtmlAbsMap);
417 if ( pMap == aVPageMap )
418 return std::size(aVPageMap);
419 if ( pMap == aVPageHtmlMap )
420 return std::size(aVPageHtmlMap);
421 if ( pMap == aVAsCharMap )
422 return std::size(aVAsCharMap);
423 if ( pMap == aVParaMap )
424 return std::size(aVParaMap);
425 if ( pMap == aHParaMap )
426 return std::size(aHParaMap);
427 if ( pMap == aHFrameMap )
428 return std::size(aHFrameMap);
429 if ( pMap == aVFrameMap )
430 return std::size(aVFrameMap);
431 if ( pMap == aHCharMap )
432 return std::size(aHCharMap);
433 if ( pMap == aHCharHtmlMap )
434 return std::size(aHCharHtmlMap);
435 if ( pMap == aHCharHtmlAbsMap )
436 return std::size(aHCharHtmlAbsMap);
437 if ( pMap == aVCharMap )
438 return std::size(aVCharMap);
439 if ( pMap == aVCharHtmlMap )
440 return std::size(aVCharHtmlMap);
441 if ( pMap == aVCharHtmlAbsMap )
442 return std::size(aVCharHtmlAbsMap);
443 if ( pMap == aHPageHtmlMap )
444 return std::size(aHPageHtmlMap);
445 if ( pMap == aHFlyHtmlMap )
446 return std::size(aHFlyHtmlMap);
447 if ( pMap == aVFlyHtmlMap )
448 return std::size(aVFlyHtmlMap);
449 return std::size(aHPageMap);
451 return 0;
454 static void lcl_InsertVectors(weld::ComboBox& rBox,
455 const std::vector< OUString >& rPrev, const std::vector< OUString >& rThis,
456 const std::vector< OUString >& rNext, const std::vector< OUString >& rRemain)
458 for(const auto& rItem : rPrev)
459 rBox.append_text(rItem);
460 for(const auto& rItem : rThis)
461 rBox.append_text(rItem);
462 for(const auto& rItem : rNext)
463 rBox.append_text(rItem);
464 rBox.append_separator(u""_ustr);
465 //now insert all strings sorted
466 const auto nStartPos = rBox.get_count();
468 for(const auto& rItem : rPrev)
469 ::InsertStringSorted(u""_ustr, rItem, rBox, nStartPos );
470 for(const auto& rItem : rThis)
471 ::InsertStringSorted(u""_ustr, rItem, rBox, nStartPos );
472 for(const auto& rItem : rNext)
473 ::InsertStringSorted(u""_ustr, rItem, rBox, nStartPos );
474 for(const auto& rItem : rRemain)
475 ::InsertStringSorted(u""_ustr, rItem, rBox, nStartPos );
478 // --> OD 2009-08-31 #mongolianlayout#
479 // add input parameter
480 static SvxSwFramePosString::StringId lcl_ChangeResIdToVerticalOrRTL(SvxSwFramePosString::StringId eStringId, bool bVertical, bool bVerticalL2R, bool bRTL)
482 //special handling of STR_FROMLEFT
483 if ( SwFPos::FROMLEFT == eStringId )
485 eStringId = bVertical
486 ? ( bRTL
487 ? SwFPos::FROMBOTTOM
488 : SwFPos::FROMTOP )
489 : ( bRTL
490 ? SwFPos::FROMRIGHT
491 : SwFPos::FROMLEFT );
492 return eStringId;
494 // --> OD 2009-08-31 #mongolianlayout#
495 // special handling of STR_FROMTOP in case of mongolianlayout (vertical left-to-right)
496 if ( SwFPos::FROMTOP == eStringId &&
497 bVertical && bVerticalL2R )
499 eStringId = SwFPos::FROMLEFT;
500 return eStringId;
502 if ( bVertical )
504 //exchange horizontal strings with vertical strings and vice versa
505 static const StringIdPair_Impl aHoriIds[] =
507 {SwFPos::LEFT, SwFPos::TOP},
508 {SwFPos::RIGHT, SwFPos::BOTTOM},
509 {SwFPos::CENTER_HORI, SwFPos::CENTER_VERT},
510 {SwFPos::FROMTOP, SwFPos::FROMRIGHT},
511 {SwFPos::REL_PG_LEFT, SwFPos::REL_PG_TOP},
512 {SwFPos::REL_PG_RIGHT, SwFPos::REL_PG_BOTTOM} ,
513 {SwFPos::REL_FRM_LEFT, SwFPos::REL_FRM_TOP},
514 {SwFPos::REL_FRM_RIGHT, SwFPos::REL_FRM_BOTTOM}
516 static const StringIdPair_Impl aVertIds[] =
518 {SwFPos::TOP, SwFPos::RIGHT},
519 {SwFPos::BOTTOM, SwFPos::LEFT },
520 {SwFPos::CENTER_VERT, SwFPos::CENTER_HORI},
521 {SwFPos::FROMTOP, SwFPos::FROMRIGHT },
522 {SwFPos::REL_PG_TOP, SwFPos::REL_PG_LEFT },
523 {SwFPos::REL_PG_BOTTOM, SwFPos::REL_PG_RIGHT } ,
524 {SwFPos::REL_FRM_TOP, SwFPos::REL_FRM_LEFT },
525 {SwFPos::REL_FRM_BOTTOM, SwFPos::REL_FRM_RIGHT }
527 // --> OD 2009-08-31 #monglianlayout#
528 static const StringIdPair_Impl aVertL2RIds[] =
530 {SwFPos::TOP, SwFPos::LEFT },
531 {SwFPos::BOTTOM, SwFPos::RIGHT },
532 {SwFPos::CENTER_VERT, SwFPos::CENTER_HORI },
533 {SwFPos::FROMTOP, SwFPos::FROMLEFT },
534 {SwFPos::REL_PG_TOP, SwFPos::REL_PG_LEFT },
535 {SwFPos::REL_PG_BOTTOM, SwFPos::REL_PG_RIGHT } ,
536 {SwFPos::REL_FRM_TOP, SwFPos::REL_FRM_LEFT },
537 {SwFPos::REL_FRM_BOTTOM, SwFPos::REL_FRM_RIGHT }
539 for(const StringIdPair_Impl & rHoriId : aHoriIds)
541 if(rHoriId.eHori == eStringId)
543 eStringId = rHoriId.eVert;
544 return eStringId;
547 for(size_t nIndex = 0; nIndex < SAL_N_ELEMENTS(aVertIds); ++nIndex)
549 // --> OD 2009-08-31 #mongolianlayout#
550 if ( !bVerticalL2R )
552 if(aVertIds[nIndex].eHori == eStringId)
554 eStringId = aVertIds[nIndex].eVert;
555 break;
558 else
560 if(aVertL2RIds[nIndex].eHori == eStringId)
562 eStringId = aVertL2RIds[nIndex].eVert;
563 break;
568 return eStringId;
571 // helper method in order to determine all possible
572 // listbox relations in a relation map for a given relation
573 static LB lcl_GetLBRelationsForRelations( const sal_Int16 _nRel )
575 LB nLBRelations = LB::NONE;
577 for (RelationMap const & i : aRelationMap)
579 if ( i.nRelation == _nRel )
581 nLBRelations |= i.nLBRelation;
585 return nLBRelations;
588 // helper method on order to determine all possible
589 // listbox relations in a relation map for a given string ID
590 static LB lcl_GetLBRelationsForStrID( const FrameMap* _pMap,
591 const SvxSwFramePosString::StringId _eStrId,
592 const bool _bUseMirrorStr )
594 LB nLBRelations = LB::NONE;
596 size_t nRelMapSize = lcl_GetFrameMapCount( _pMap );
597 for ( size_t nRelMapPos = 0; nRelMapPos < nRelMapSize; ++nRelMapPos )
599 if ( ( !_bUseMirrorStr && _pMap[nRelMapPos].eStrId == _eStrId ) ||
600 ( _bUseMirrorStr && _pMap[nRelMapPos].eMirrorStrId == _eStrId ) )
602 nLBRelations |= _pMap[nRelMapPos].nLBRelations;
606 return nLBRelations;
609 // standard frame TabPage
610 namespace
612 void HandleAutoCB(bool _bChecked, weld::Label& _rFT_man, weld::Label& _rFT_auto, weld::MetricSpinButton& _rPF_Edit)
614 _rFT_man.set_visible( !_bChecked );
615 _rFT_auto.set_visible( _bChecked );
616 OUString accName = _bChecked ? _rFT_auto.get_label() : _rFT_man.get_label();
617 _rPF_Edit.set_accessible_name(accName);
621 SwFramePage::SwFramePage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet)
622 : SfxTabPage(pPage, pController, u"modules/swriter/ui/frmtypepage.ui"_ustr, u"FrameTypePage"_ustr, &rSet)
623 , m_bAtHorzPosModified(false)
624 , m_bAtVertPosModified(false)
625 , m_bFormat(false)
626 , m_bNew(true)
627 , m_bNoModifyHdl(true)
628 , m_bIsVerticalFrame(false)
629 , m_bIsVerticalL2R(false)
630 , m_bIsInRightToLeft(false)
631 , m_bHtmlMode(false)
632 , m_nHtmlMode(0)
633 , m_nUpperBorder(0)
634 , m_nLowerBorder(0)
635 , m_fWidthHeightRatio(1.0)
636 , mpToCharContentPos(nullptr)
637 , m_nOldH(text::HoriOrientation::CENTER)
638 , m_nOldHRel(text::RelOrientation::FRAME)
639 , m_nOldV(text::VertOrientation::TOP)
640 , m_nOldVRel(text::RelOrientation::PRINT_AREA)
641 , m_pVMap(nullptr)
642 , m_pHMap(nullptr)
643 , m_bAllowVertPositioning( true )
644 , m_bIsMathOLE(false)
645 , m_bIsMathBaselineAlignment(true)
646 , m_aRatioTop(ConnectorType::Top)
647 , m_aRatioBottom(ConnectorType::Bottom)
648 , m_xWidthFT(m_xBuilder->weld_label(u"widthft"_ustr))
649 , m_xWidthAutoFT(m_xBuilder->weld_label(u"autowidthft"_ustr))
650 , m_xRelWidthCB(m_xBuilder->weld_check_button(u"relwidth"_ustr))
651 , m_xRelWidthRelationLB(m_xBuilder->weld_combo_box(u"relwidthrelation"_ustr))
652 , m_xAutoWidthCB(m_xBuilder->weld_check_button(u"autowidth"_ustr))
653 , m_xHeightFT(m_xBuilder->weld_label(u"heightft"_ustr))
654 , m_xHeightAutoFT(m_xBuilder->weld_label(u"autoheightft"_ustr))
655 , m_xRelHeightCB(m_xBuilder->weld_check_button(u"relheight"_ustr))
656 , m_xRelHeightRelationLB(m_xBuilder->weld_combo_box(u"relheightrelation"_ustr))
657 , m_xAutoHeightCB(m_xBuilder->weld_check_button(u"autoheight"_ustr))
658 , m_xFixedRatioCB(m_xBuilder->weld_check_button(u"CBX_SCALE"_ustr))
659 , m_xCbxScaleImg(m_xBuilder->weld_image(u"imRatio"_ustr))
660 , m_xImgRatioTop(new weld::CustomWeld(*m_xBuilder, u"daRatioTop"_ustr, m_aRatioTop))
661 , m_xImgRatioBottom(new weld::CustomWeld(*m_xBuilder, u"daRatioBottom"_ustr, m_aRatioBottom))
662 , m_xRealSizeBT(m_xBuilder->weld_button(u"origsize"_ustr))
663 , m_xProtectFrame(m_xBuilder->weld_widget(u"protect"_ustr))
664 , m_xProtectContentCB(m_xBuilder->weld_check_button(u"protectcontent"_ustr))
665 , m_xProtectFrameCB(m_xBuilder->weld_check_button(u"protectframe"_ustr))
666 , m_xProtectSizeCB(m_xBuilder->weld_check_button(u"protectsize"_ustr))
667 , m_xAnchorFrame(m_xBuilder->weld_widget(u"anchorframe"_ustr))
668 , m_xAnchorAtPageRB(m_xBuilder->weld_radio_button(u"topage"_ustr))
669 , m_xAnchorAtParaRB(m_xBuilder->weld_radio_button(u"topara"_ustr))
670 , m_xAnchorAtCharRB(m_xBuilder->weld_radio_button(u"tochar"_ustr))
671 , m_xAnchorAsCharRB(m_xBuilder->weld_radio_button(u"aschar"_ustr))
672 , m_xAnchorAtFrameRB(m_xBuilder->weld_radio_button(u"toframe"_ustr))
673 , m_xHorizontalFT(m_xBuilder->weld_label(u"horiposft"_ustr))
674 , m_xHorizontalDLB(m_xBuilder->weld_combo_box(u"horipos"_ustr))
675 , m_xAtHorzPosFT(m_xBuilder->weld_label(u"horibyft"_ustr))
676 , m_xAtHorzPosED(m_xBuilder->weld_metric_spin_button(u"byhori"_ustr, FieldUnit::CM))
677 , m_xHoriRelationFT(m_xBuilder->weld_label(u"horitoft"_ustr))
678 , m_xHoriRelationLB(m_xBuilder->weld_combo_box(u"horianchor"_ustr))
679 , m_xMirrorPagesCB(m_xBuilder->weld_check_button(u"mirror"_ustr))
680 , m_xVerticalFT(m_xBuilder->weld_label(u"vertposft"_ustr))
681 , m_xVerticalDLB(m_xBuilder->weld_combo_box(u"vertpos"_ustr))
682 , m_xAtVertPosFT(m_xBuilder->weld_label(u"vertbyft"_ustr))
683 , m_xAtVertPosED(m_xBuilder->weld_metric_spin_button(u"byvert"_ustr, FieldUnit::CM))
684 , m_xVertRelationFT(m_xBuilder->weld_label(u"verttoft"_ustr))
685 , m_xVertRelationLB(m_xBuilder->weld_combo_box(u"vertanchor"_ustr))
686 , m_xFollowTextFlowCB(m_xBuilder->weld_check_button(u"followtextflow"_ustr))
687 , m_xFlySplitCB(m_xBuilder->weld_check_button(u"flysplit"_ustr))
688 , m_xExampleWN(new weld::CustomWeld(*m_xBuilder, u"preview"_ustr, m_aExampleWN))
689 , m_xWidthED(new SwPercentField(m_xBuilder->weld_metric_spin_button(u"width"_ustr, FieldUnit::CM)))
690 , m_xHeightED(new SwPercentField(m_xBuilder->weld_metric_spin_button(u"height"_ustr, FieldUnit::CM)))
692 const auto nWidthRequest = m_xAtHorzPosED->get_preferred_size().Width();
693 m_xAtHorzPosED->set_size_request(nWidthRequest, -1);
694 m_xAtVertPosED->set_size_request(nWidthRequest, -1);
696 setOptimalFrameWidth();
697 setOptimalRelWidth();
699 SetExchangeSupport();
701 Link<weld::MetricSpinButton&,void> aLk3 = LINK(this, SwFramePage, ModifyHdl);
702 m_xWidthED->connect_value_changed( aLk3 );
703 m_xHeightED->connect_value_changed( aLk3 );
704 m_xAtHorzPosED->connect_value_changed( aLk3 );
705 m_xAtVertPosED->connect_value_changed( aLk3 );
706 m_xFollowTextFlowCB->connect_toggled(LINK(this, SwFramePage, RangeModifyClickHdl));
708 Link<weld::Toggleable&,void> aLk2 = LINK(this, SwFramePage, AnchorTypeHdl);
709 m_xAnchorAtPageRB->connect_toggled( aLk2 );
710 m_xAnchorAtParaRB->connect_toggled( aLk2 );
711 m_xAnchorAtCharRB->connect_toggled( aLk2 );
712 m_xAnchorAsCharRB->connect_toggled( aLk2 );
713 m_xAnchorAtFrameRB->connect_toggled( aLk2 );
715 m_xHorizontalDLB->connect_changed(LINK(this, SwFramePage, PosHdl));
716 m_xVerticalDLB->connect_changed(LINK(this, SwFramePage, PosHdl));
718 m_xHoriRelationLB->connect_changed(LINK(this, SwFramePage, RelHdl));
719 m_xVertRelationLB->connect_changed(LINK(this, SwFramePage, RelHdl));
721 m_xMirrorPagesCB->connect_toggled(LINK(this, SwFramePage, MirrorHdl));
723 aLk2 = LINK(this, SwFramePage, RelSizeClickHdl);
724 m_xRelWidthCB->connect_toggled(aLk2);
725 m_xRelHeightCB->connect_toggled(aLk2);
727 m_xAutoWidthCB->connect_toggled(LINK(this, SwFramePage, AutoWidthClickHdl));
728 m_xAutoHeightCB->connect_toggled(LINK(this, SwFramePage, AutoHeightClickHdl));
730 m_xFixedRatioCB->connect_toggled(LINK(this, SwFramePage, RatioClickHdl));
732 if (comphelper::LibreOfficeKit::isActive())
734 m_xAnchorAtPageRB->hide();
735 m_xAnchorAtFrameRB->hide();
739 SwFramePage::~SwFramePage()
743 namespace
745 struct FrameMaps
747 FrameMap const * pMap;
748 size_t nCount;
752 void SwFramePage::setOptimalFrameWidth()
754 static FrameMaps const aMaps[] = {
755 { aHPageMap, std::size(aHPageMap) },
756 { aHPageHtmlMap, std::size(aHPageHtmlMap) },
757 { aVPageMap, std::size(aVPageMap) },
758 { aVPageHtmlMap, std::size(aVPageHtmlMap) },
759 { aHFrameMap, std::size(aHFrameMap) },
760 { aHFlyHtmlMap, std::size(aHFlyHtmlMap) },
761 { aVFrameMap, std::size(aVFrameMap) },
762 { aVFlyHtmlMap, std::size(aVFlyHtmlMap) },
763 { aHParaMap, std::size(aHParaMap) },
764 { aHParaHtmlMap, std::size(aHParaHtmlMap) },
765 { aHParaHtmlAbsMap, std::size(aHParaHtmlAbsMap) },
766 { aVParaMap, std::size(aVParaMap) },
767 { aVParaHtmlMap, std::size(aVParaHtmlMap) },
768 { aHCharMap, std::size(aHCharMap) },
769 { aHCharHtmlMap, std::size(aHCharHtmlMap) },
770 { aHCharHtmlAbsMap, std::size(aHCharHtmlAbsMap) },
771 { aVCharMap, std::size(aVCharMap) },
772 { aVCharHtmlMap, std::size(aVCharHtmlMap) },
773 { aVCharHtmlAbsMap, std::size(aVCharHtmlAbsMap) },
774 { aVAsCharMap, std::size(aVAsCharMap) },
775 { aVAsCharHtmlMap, std::size(aVAsCharHtmlMap) }
778 std::vector<SvxSwFramePosString::StringId> aFrames;
779 for (const FrameMaps & rMap : aMaps)
781 for (size_t j = 0; j < rMap.nCount; ++j)
783 aFrames.push_back(rMap.pMap[j].eStrId);
784 aFrames.push_back(rMap.pMap[j].eMirrorStrId);
788 std::sort(aFrames.begin(), aFrames.end());
789 aFrames.erase(std::unique(aFrames.begin(), aFrames.end()), aFrames.end());
791 for (const auto& rFrame : aFrames)
793 m_xHorizontalDLB->append_text(SvxSwFramePosString::GetString(rFrame));
796 Size aBiggest(m_xHorizontalDLB->get_preferred_size());
797 m_xHorizontalDLB->set_size_request(aBiggest.Width(), -1);
798 m_xVerticalDLB->set_size_request(aBiggest.Width(), -1);
799 m_xHorizontalDLB->clear();
802 namespace
804 struct RelationMaps
806 RelationMap const * pMap;
807 size_t nCount;
810 /// Checks if the current fly frame contains exactly one table.
811 bool ContainsSingleTable(const SwFrameFormat& rFlyFormat)
813 const SwNodeIndex* pStartNode = rFlyFormat.GetContent().GetContentIdx();
814 if (!pStartNode)
816 return false;
819 // Check if the frame content starts with a table.
820 SwNodeIndex aNodeIndex(*pStartNode);
821 ++aNodeIndex;
822 if (!aNodeIndex.GetNode().IsTableNode())
824 return false;
827 // Check if the frame content ends with the same table.
828 SwNodeIndex aEndIndex(*aNodeIndex.GetNode().EndOfSectionNode());
829 ++aEndIndex;
830 if (&aEndIndex.GetNode() != pStartNode->GetNode().EndOfSectionNode())
832 return false;
835 return true;
838 bool ContainsChain(const SwFrameFormat& rFlyFormat)
840 const SwFormatChain& rChain = rFlyFormat.GetChain();
841 return rChain.GetPrev() || rChain.GetNext();
844 /// Determines if rFlyFormat is anchored in a fly frame that is part of a draw-format + fly-format
845 /// ("textbox") pair.
846 bool InTextBox(const SwFrameFormat& rFlyFormat)
848 const SwFormatAnchor& rAnchor = rFlyFormat.GetAnchor();
849 SwNode* pAnchorNode = rAnchor.GetAnchorNode();
850 if (!pAnchorNode)
852 return false;
855 const SwStartNode* pFlyNode = pAnchorNode->FindFlyStartNode();
856 if (!pFlyNode)
858 return false;
861 if (!pFlyNode->GetFlyFormat()->GetOtherTextBoxFormats())
863 return false;
866 return true;
870 void SwFramePage::setOptimalRelWidth()
872 static const RelationMaps aMaps[] = {
873 { aRelationMap, SAL_N_ELEMENTS(aRelationMap) },
874 { aAsCharRelationMap, SAL_N_ELEMENTS(aAsCharRelationMap) }
877 std::vector<SvxSwFramePosString::StringId> aRels;
878 for (const RelationMaps & rMap : aMaps)
880 for (size_t j = 0; j < rMap.nCount; ++j)
882 aRels.push_back(rMap.pMap[j].eStrId);
883 aRels.push_back(rMap.pMap[j].eMirrorStrId);
887 std::sort(aRels.begin(), aRels.end());
888 aRels.erase(std::unique(aRels.begin(), aRels.end()), aRels.end());
890 for (const auto& rRel : aRels)
892 m_xHoriRelationLB->append_text(SvxSwFramePosString::GetString(rRel));
895 Size aBiggest(m_xHoriRelationLB->get_preferred_size());
896 m_xHoriRelationLB->set_size_request(aBiggest.Width(), -1);
897 m_xVertRelationLB->set_size_request(aBiggest.Width(), -1);
898 m_xRelWidthRelationLB->set_size_request(aBiggest.Width(), -1);
899 m_xRelHeightRelationLB->set_size_request(aBiggest.Width(), -1);
900 m_xHoriRelationLB->clear();
903 std::unique_ptr<SfxTabPage> SwFramePage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
905 return std::make_unique<SwFramePage>(pPage, pController, *rSet);
908 void SwFramePage::EnableGraficMode()
910 // i#39692 - mustn't be called more than once
911 if (!m_xRealSizeBT->get_visible())
913 m_xWidthFT->show();
914 m_xWidthAutoFT->hide();
915 m_xAutoHeightCB->hide();
917 m_xHeightFT->show();
918 m_xHeightAutoFT->hide();
919 m_xAutoWidthCB->hide();
921 m_xRealSizeBT->show();
925 SwWrtShell *SwFramePage::getFrameDlgParentShell()
927 return static_cast<SwFrameDlg*>(GetDialogController())->GetWrtShell();
930 void SwFramePage::Reset( const SfxItemSet *rSet )
932 SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() :
933 getFrameDlgParentShell();
934 OSL_ENSURE(pSh , "shell not found");
935 if (!pSh)
936 return;
938 m_nHtmlMode = ::GetHtmlMode(pSh->GetView().GetDocShell());
939 m_bHtmlMode = (m_nHtmlMode & HTMLMODE_ON) != 0;
941 FieldUnit aMetric = ::GetDfltMetric(m_bHtmlMode);
942 m_xWidthED->SetMetric(aMetric);
943 m_xHeightED->SetMetric(aMetric);
944 ::SetFieldUnit(*m_xAtHorzPosED, aMetric);
945 ::SetFieldUnit(*m_xAtVertPosED, aMetric);
947 const SwFormatAnchor& rAnchor = rSet->Get(RES_ANCHOR);
949 if (const SfxBoolItem* pMathItem = rSet->GetItemIfSet(FN_OLE_IS_MATH, false))
950 m_bIsMathOLE = pMathItem->GetValue();
951 if (const SfxBoolItem* pAlignItem = rSet->GetItemIfSet(FN_MATH_BASELINE_ALIGNMENT, false))
952 m_bIsMathBaselineAlignment = pAlignItem->GetValue();
953 EnableVerticalPositioning( !(m_bIsMathOLE && m_bIsMathBaselineAlignment
954 && RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId()) );
956 if (m_bFormat)
958 // at formats no to-fly anchor
959 m_xAnchorAtFrameRB->set_sensitive(false);
960 if (rSet->GetItemState(FN_KEEP_ASPECT_RATIO) != SfxItemState::SET)
962 m_xFixedRatioCB->set_sensitive(false);
965 else
967 if (rAnchor.GetAnchorId() != RndStdIds::FLY_AT_FLY && !pSh->IsFlyInFly())
968 m_xAnchorAtFrameRB->hide();
969 if ( pSh->IsFrameVertical( true, m_bIsInRightToLeft, m_bIsVerticalL2R ) )
971 OUString sHLabel = m_xHorizontalFT->get_label();
972 m_xHorizontalFT->set_label(m_xVerticalFT->get_label());
973 m_xVerticalFT->set_label(sHLabel);
974 m_bIsVerticalFrame = true;
978 if ( m_sDlgType == "PictureDialog" || m_sDlgType == "ObjectDialog" )
980 pSh->GetGrfSize( m_aGrfSize );
982 if ( !m_bNew )
984 m_xRealSizeBT->connect_clicked(LINK(this, SwFramePage, RealSizeHdl));
985 EnableGraficMode();
988 if (m_sDlgType == "PictureDialog")
990 m_xFixedRatioCB->set_active(false);
991 m_xCbxScaleImg->set_from_icon_name(RID_SVXBMP_UNLOCKED);
993 else
995 if ( m_bNew )
996 SetPageTitle(SwResId(STR_FRMUI_OLE_INSERT));
997 else
998 SetPageTitle(SwResId(STR_FRMUI_OLE_EDIT));
1001 else
1003 m_aGrfSize = rSet->Get(RES_FRM_SIZE).GetSize();
1006 // entering percent value made possible
1008 // the available space is not yet known so the RefValue has to be calculated from size and relative size values
1009 // this is needed only if relative values are already set
1010 const SwFormatFrameSize& rFrameSize = rSet->Get(RES_FRM_SIZE);
1012 m_xRelWidthRelationLB->append_text(SvxSwFramePosString::GetString(SwFPos::FRAME));
1013 m_xRelWidthRelationLB->append_text(SvxSwFramePosString::GetString(SwFPos::REL_PG_FRAME));
1014 if (rFrameSize.GetWidthPercent() != SwFormatFrameSize::SYNCED && rFrameSize.GetWidthPercent() != 0)
1016 //calculate the reference value from the width and relative width values
1017 sal_Int32 nSpace = rFrameSize.GetWidth() * 100 / rFrameSize.GetWidthPercent();
1018 m_xWidthED->SetRefValue( nSpace );
1020 m_xRelWidthRelationLB->set_sensitive(true);
1022 else
1023 m_xRelWidthRelationLB->set_sensitive(false);
1025 m_xRelHeightRelationLB->append_text(SvxSwFramePosString::GetString(SwFPos::FRAME));
1026 m_xRelHeightRelationLB->append_text(SvxSwFramePosString::GetString(SwFPos::REL_PG_FRAME));
1027 if (rFrameSize.GetHeightPercent() != SwFormatFrameSize::SYNCED && rFrameSize.GetHeightPercent() != 0)
1029 //calculate the reference value from the with and relative width values
1030 sal_Int32 nSpace = rFrameSize.GetHeight() * 100 / rFrameSize.GetHeightPercent();
1031 m_xHeightED->SetRefValue( nSpace );
1033 m_xRelHeightRelationLB->set_sensitive(true);
1035 else
1036 m_xRelHeightRelationLB->set_sensitive(false);
1038 // general initialisation part
1039 switch(rAnchor.GetAnchorId())
1041 case RndStdIds::FLY_AT_PAGE: m_xAnchorAtPageRB->set_active(true); break;
1042 case RndStdIds::FLY_AT_PARA: m_xAnchorAtParaRB->set_active(true); break;
1043 case RndStdIds::FLY_AT_CHAR: m_xAnchorAtCharRB->set_active(true); break;
1044 case RndStdIds::FLY_AS_CHAR: m_xAnchorAsCharRB->set_active(true); break;
1045 case RndStdIds::FLY_AT_FLY: m_xAnchorAtFrameRB->set_active(true);break;
1046 default:; //prevent warning
1049 // i#22341 - determine content position of character
1050 // Note: content position can be NULL
1051 mpToCharContentPos = rAnchor.GetAnchorNode() ? &rAnchor : nullptr;
1053 // i#18732 - init checkbox value
1055 const bool bFollowTextFlow =
1056 rSet->Get(RES_FOLLOW_TEXT_FLOW).GetValue();
1057 m_xFollowTextFlowCB->set_active(bFollowTextFlow);
1060 const bool bFlySplit = rSet->Get(RES_FLY_SPLIT).GetValue();
1061 m_xFlySplitCB->set_active(bFlySplit);
1064 if(m_bHtmlMode)
1066 m_xAutoHeightCB->set_sensitive(false);
1067 m_xAutoWidthCB->set_sensitive(false);
1068 m_xMirrorPagesCB->hide();
1069 if (m_sDlgType == "FrameDialog")
1070 m_xFixedRatioCB->set_sensitive(false);
1071 // i#18732 hide checkbox in HTML mode
1072 m_xFollowTextFlowCB->hide();
1073 m_xProtectFrame->hide();
1075 else
1077 // enable/disable of check box 'Mirror on..'
1078 m_xMirrorPagesCB->set_sensitive(!m_xAnchorAsCharRB->get_active());
1080 // enable/disable check box 'Follow text flow'.
1081 // enable check box 'Follow text
1082 // flow' also for anchor type to-frame.
1083 m_xFollowTextFlowCB->set_sensitive(m_xAnchorAtParaRB->get_active() ||
1084 m_xAnchorAtCharRB->get_active() ||
1085 m_xAnchorAtFrameRB->get_active());
1086 m_xFlySplitCB->set_sensitive(m_xAnchorAtParaRB->get_active());
1089 const SwFrameFormat* pFlyFormat = pSh->GetFlyFrameFormat();
1090 if (!pFlyFormat || !ContainsSingleTable(*pFlyFormat) || ContainsChain(*pFlyFormat))
1092 bool bSingleTable = false;
1093 if (!pFlyFormat && m_bNew)
1095 // No fly is selected: check if a whole table is selected. If so, allow moving that into
1096 // a split fly.
1097 if (SwFlyFrameAttrMgr::SingleTableSelected(*pSh))
1099 bSingleTable = true;
1103 // Only allow fly split if the frame contains a single table, otherwise it would be hard to
1104 // save the resulting model to Word formats.
1105 if (!bSingleTable)
1107 m_xFlySplitCB->hide();
1110 else if (!m_bNew && InTextBox(*pFlyFormat))
1112 // Disallow split flys in fly frames which form a textbox, i.e. non-editeng shape text.
1113 m_xFlySplitCB->hide();
1116 // Pos Protected
1117 const SvxProtectItem& rProt = rSet->Get(RES_PROTECT);
1118 m_xProtectFrameCB->set_active(rProt.IsPosProtected());
1119 m_xProtectContentCB->set_active(rProt.IsContentProtected());
1120 m_xProtectSizeCB->set_active(rProt.IsSizeProtected());
1122 Init(*rSet);
1123 m_xAtVertPosED->save_value();
1124 m_xAtHorzPosED->save_value();
1125 m_xFollowTextFlowCB->save_state();
1126 m_xFlySplitCB->save_state();
1128 m_xWidthED->save_value();
1129 m_xHeightED->save_value();
1131 m_bNoModifyHdl = false;
1132 //lock PercentFields
1133 m_xWidthED->LockAutoCalculation(true);
1134 m_xHeightED->LockAutoCalculation(true);
1135 RangeModifyHdl(); // set all maximum values initially
1136 m_xHeightED->LockAutoCalculation(false);
1137 m_xWidthED->LockAutoCalculation(false);
1139 m_xAutoHeightCB->save_state();
1140 m_xAutoWidthCB->save_state();
1142 SwTwips nWidth = static_cast< SwTwips >(m_xWidthED->DenormalizePercent(m_xWidthED->get_value(FieldUnit::TWIP)));
1143 SwTwips nHeight = static_cast< SwTwips >(m_xHeightED->DenormalizePercent(m_xHeightED->get_value(FieldUnit::TWIP)));
1144 m_fWidthHeightRatio = nHeight ? double(nWidth) / double(nHeight) : 1.0;
1147 // stuff attributes into the set when OK
1148 bool SwFramePage::FillItemSet(SfxItemSet *rSet)
1150 bool bRet = false;
1152 const SfxPoolItem* pOldItem;
1153 SvxProtectItem aProt(GetItemSet().Get(RES_PROTECT));
1154 aProt.SetContentProtect(m_xProtectContentCB->get_active());
1155 aProt.SetSizeProtect(m_xProtectSizeCB->get_active());
1156 aProt.SetPosProtect(m_xProtectFrameCB->get_active());
1157 if (nullptr == (pOldItem = GetOldItem(*rSet, FN_SET_PROTECT)) || aProt != *pOldItem)
1158 bRet |= nullptr != rSet->Put(aProt);
1160 const SfxItemSet& rOldSet = GetItemSet();
1161 pOldItem = nullptr;
1163 RndStdIds eAnchorId = GetAnchor();
1165 if ( !m_bFormat || eAnchorId != RndStdIds::FLY_AT_FLY )
1167 pOldItem = GetOldItem(*rSet, RES_ANCHOR);
1168 if (m_bNew || !pOldItem || eAnchorId != static_cast<const SwFormatAnchor*>(pOldItem)->GetAnchorId())
1170 SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell()
1171 : getFrameDlgParentShell();
1172 OSL_ENSURE( pSh , "shell not found");
1173 if (pSh)
1175 SwFormatAnchor aAnc( eAnchorId, eAnchorId == RndStdIds::FLY_AT_PAGE ? pSh->GetPhyPageNum() : 0 );
1176 bRet = nullptr != rSet->Put( aAnc );
1181 if ( m_pHMap )
1183 SwFormatHoriOrient aHoriOrient( rOldSet.Get(RES_HORI_ORIENT) );
1185 const sal_Int32 nMapPos = GetMapPos(m_pHMap, *m_xHorizontalDLB);
1186 const sal_Int16 eHOri = GetAlignment(m_pHMap, nMapPos, *m_xHoriRelationLB);
1187 const sal_Int16 eRel = GetRelation(*m_xHoriRelationLB);
1189 aHoriOrient.SetHoriOrient( eHOri );
1190 aHoriOrient.SetRelationOrient( eRel );
1191 aHoriOrient.SetPosToggle(m_xMirrorPagesCB->get_active());
1193 bool bMod = m_xAtHorzPosED->get_value_changed_from_saved();
1194 bMod |= m_xMirrorPagesCB->get_state_changed_from_saved();
1196 if ( eHOri == text::HoriOrientation::NONE &&
1197 (m_bNew || (m_bAtHorzPosModified || bMod) || m_nOldH != eHOri ) )
1199 SwTwips nX = static_cast< SwTwips >(m_xAtHorzPosED->denormalize(m_xAtHorzPosED->get_value(FieldUnit::TWIP)));
1200 aHoriOrient.SetPos( nX );
1203 pOldItem = GetOldItem(*rSet, FN_HORI_ORIENT);
1204 bool bSame = false;
1205 if ((m_bNew == m_bFormat) && pOldItem)
1207 bSame = aHoriOrient == static_cast<const SwFormatHoriOrient&>(*pOldItem);
1209 if ((m_bNew && !m_bFormat) || ((m_bAtHorzPosModified || bMod) && !bSame))
1211 bRet |= nullptr != rSet->Put( aHoriOrient );
1215 if ( m_pVMap )
1217 // alignment vertical
1218 SwFormatVertOrient aVertOrient( rOldSet.Get(RES_VERT_ORIENT) );
1220 const sal_Int32 nMapPos = GetMapPos(m_pVMap, *m_xVerticalDLB);
1221 const sal_Int16 eVOri = GetAlignment(m_pVMap, nMapPos, *m_xVertRelationLB);
1222 const sal_Int16 eRel = GetRelation(*m_xVertRelationLB);
1224 aVertOrient.SetVertOrient ( eVOri);
1225 aVertOrient.SetRelationOrient( eRel );
1227 bool bMod = m_xAtVertPosED->get_value_changed_from_saved();
1229 if ( eVOri == text::VertOrientation::NONE &&
1230 ( m_bNew || (m_bAtVertPosModified || bMod) || m_nOldV != eVOri) )
1232 // vertical position
1233 // recalculate offset for character bound frames
1234 SwTwips nY = static_cast< SwTwips >(m_xAtVertPosED->denormalize(m_xAtVertPosED->get_value(FieldUnit::TWIP)));
1235 if (eAnchorId == RndStdIds::FLY_AS_CHAR)
1237 nY *= -1;
1239 aVertOrient.SetPos( nY );
1241 pOldItem = GetOldItem(*rSet, FN_VERT_ORIENT);
1242 bool bSame = false;
1243 if((m_bNew == m_bFormat) && pOldItem)
1245 bSame = m_bFormat ?
1246 aVertOrient.GetVertOrient() == static_cast<const SwFormatVertOrient*>(pOldItem)->GetVertOrient() &&
1247 aVertOrient.GetRelationOrient() == static_cast<const SwFormatVertOrient*>(pOldItem)->GetRelationOrient() &&
1248 aVertOrient.GetPos() == static_cast<const SwFormatVertOrient*>(pOldItem)->GetPos()
1249 : aVertOrient == static_cast<const SwFormatVertOrient&>(*pOldItem);
1251 if( ( m_bNew && !m_bFormat ) || ((m_bAtVertPosModified || bMod) && !bSame ))
1253 bRet |= nullptr != rSet->Put( aVertOrient );
1257 // set size
1258 // new exception: when the size of pMgr(, 0), then the properties
1259 // for a graphic that isn't even loaded, are set. Then no SetSize
1260 // is done here when the size settings were not changed by the
1261 // user.
1262 const SwFormatFrameSize& rOldSize = rOldSet.Get(RES_FRM_SIZE);
1263 SwFormatFrameSize aSz( rOldSize );
1265 auto nRelWidthRelation = m_xRelWidthRelationLB->get_active();
1266 if (nRelWidthRelation != -1)
1268 if (nRelWidthRelation == 0)
1269 aSz.SetWidthPercentRelation(text::RelOrientation::FRAME);
1270 else if (nRelWidthRelation == 1)
1271 aSz.SetWidthPercentRelation(text::RelOrientation::PAGE_FRAME);
1273 auto nRelHeightRelation = m_xRelHeightRelationLB->get_active();
1274 if (nRelHeightRelation != -1)
1276 if (nRelHeightRelation == 0)
1277 aSz.SetHeightPercentRelation(text::RelOrientation::FRAME);
1278 else if (nRelHeightRelation == 1)
1279 aSz.SetHeightPercentRelation(text::RelOrientation::PAGE_FRAME);
1282 bool bValueModified = m_xWidthED->get_value_changed_from_saved() ||
1283 m_xHeightED->get_value_changed_from_saved();
1284 bool bCheckChanged = m_xRelWidthCB->get_state_changed_from_saved() ||
1285 m_xRelHeightCB->get_state_changed_from_saved() ||
1286 m_xFixedRatioCB->get_state_changed_from_saved();
1288 bool bLegalValue = !(!rOldSize.GetWidth () && !rOldSize.GetHeight() &&
1289 m_xWidthED->get_value() == m_xWidthED->get_min() &&
1290 m_xHeightED->get_value() == m_xHeightED->get_min());
1292 if ((m_bNew && !m_bFormat) || ((bValueModified || bCheckChanged) && bLegalValue))
1294 sal_Int64 nNewWidth = m_xWidthED->DenormalizePercent(m_xWidthED->GetRealValue(FieldUnit::TWIP));
1295 sal_Int64 nNewHeight = m_xHeightED->DenormalizePercent(m_xHeightED->GetRealValue(FieldUnit::TWIP));
1296 aSz.SetWidth (static_cast< SwTwips >(nNewWidth));
1297 aSz.SetHeight(static_cast< SwTwips >(nNewHeight));
1299 if (m_xRelWidthCB->get_active())
1301 aSz.SetWidthPercent(static_cast<sal_uInt8>(std::min(MAX_PERCENT_WIDTH, m_xWidthED->Convert(m_xWidthED->NormalizePercent(nNewWidth), FieldUnit::TWIP, FieldUnit::PERCENT))));
1303 else
1304 aSz.SetWidthPercent(0);
1305 if (m_xRelHeightCB->get_active())
1306 aSz.SetHeightPercent(static_cast<sal_uInt8>(std::min(MAX_PERCENT_HEIGHT, m_xHeightED->Convert(m_xHeightED->NormalizePercent(nNewHeight), FieldUnit::TWIP, FieldUnit::PERCENT))));
1307 else
1308 aSz.SetHeightPercent(0);
1310 if (m_xFixedRatioCB->get_active() && (m_xRelWidthCB->get_active() != m_xRelHeightCB->get_active()))
1312 if (m_xRelWidthCB->get_active())
1313 aSz.SetHeightPercent(SwFormatFrameSize::SYNCED);
1314 else
1315 aSz.SetWidthPercent(SwFormatFrameSize::SYNCED);
1319 if( !IsInGraficMode() )
1321 if (m_xAutoHeightCB->get_state_changed_from_saved())
1323 SwFrameSize eFrameSize = m_xAutoHeightCB->get_active()? SwFrameSize::Minimum : SwFrameSize::Fixed;
1324 if( eFrameSize != aSz.GetHeightSizeType() )
1325 aSz.SetHeightSizeType(eFrameSize);
1327 if (m_xAutoWidthCB->get_state_changed_from_saved())
1329 SwFrameSize eFrameSize = m_xAutoWidthCB->get_active()? SwFrameSize::Minimum : SwFrameSize::Fixed;
1330 if( eFrameSize != aSz.GetWidthSizeType() )
1331 aSz.SetWidthSizeType( eFrameSize );
1334 if (m_xFixedRatioCB->get_state_changed_from_saved())
1335 bRet |= nullptr != rSet->Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO, m_xFixedRatioCB->get_active()));
1337 pOldItem = GetOldItem(*rSet, RES_FRM_SIZE);
1339 bool bSizeChanged = pOldItem && aSz != *pOldItem;
1340 if (!bSizeChanged && m_bNew)
1342 // If no custom size is provided, always set a size for a new frame, to avoid ~zero width.
1343 bSizeChanged = true;
1345 if (bSizeChanged || (!pOldItem && !m_bFormat) ||
1346 (m_bFormat &&
1347 (aSz.GetWidth() > 0 || aSz.GetWidthPercent() > 0) &&
1348 (aSz.GetHeight() > 0 || aSz.GetHeightPercent() > 0)))
1350 if (aSz.GetHeightSizeType() == SwFrameSize::Variable) // there is no VAR_SIZE in frames
1351 aSz.SetHeightSizeType(SwFrameSize::Minimum);
1353 bRet |= nullptr != rSet->Put( aSz );
1354 if (bRet)
1356 SvxSizeItem aGSz(SID_ATTR_GRAF_FRMSIZE);
1357 aGSz.SetSize(aSz.GetSize());
1358 bRet |= nullptr != rSet->Put(aGSz);
1361 if (m_xFollowTextFlowCB->get_state_changed_from_saved())
1363 bRet |= nullptr != rSet->Put(SwFormatFollowTextFlow(m_xFollowTextFlowCB->get_active()));
1365 if (m_xFlySplitCB->get_state_changed_from_saved())
1367 bRet |= rSet->Put(SwFormatFlySplit(m_xFlySplitCB->get_active())) != nullptr;
1369 return bRet;
1372 // initialise horizontal and vertical Pos
1373 void SwFramePage::InitPos(RndStdIds eId,
1374 sal_Int16 nH,
1375 sal_Int16 nHRel,
1376 sal_Int16 nV,
1377 sal_Int16 nVRel,
1378 tools::Long nX,
1379 tools::Long nY)
1381 auto nPos = m_xVerticalDLB->get_active();
1382 if (nPos != -1 && m_pVMap)
1384 m_nOldV = m_pVMap[nPos].nAlign;
1386 nPos = m_xVertRelationLB->get_active();
1387 if (nPos != -1)
1388 m_nOldVRel = weld::fromId<RelationMap*>(m_xVertRelationLB->get_id(nPos))->nRelation;
1391 nPos = m_xHorizontalDLB->get_active();
1392 if (nPos != -1 && m_pHMap)
1394 m_nOldH = m_pHMap[nPos].nAlign;
1396 nPos = m_xHoriRelationLB->get_active();
1397 if (nPos != -1)
1398 m_nOldHRel = weld::fromId<RelationMap*>(m_xHoriRelationLB->get_id(nPos))->nRelation;
1401 bool bEnable = true;
1402 if ( eId == RndStdIds::FLY_AT_PAGE )
1404 m_pVMap = m_bHtmlMode ? aVPageHtmlMap : aVPageMap;
1405 m_pHMap = m_bHtmlMode ? aHPageHtmlMap : aHPageMap;
1407 else if ( eId == RndStdIds::FLY_AT_FLY )
1409 // own vertical alignment map for to frame
1410 // anchored objects.
1411 m_pVMap = m_bHtmlMode ? aVFlyHtmlMap : aVFrameMap;
1412 m_pHMap = m_bHtmlMode ? aHFlyHtmlMap : aHFrameMap;
1414 else if ( eId == RndStdIds::FLY_AT_PARA )
1416 if(m_bHtmlMode)
1418 m_pVMap = aVParaHtmlMap;
1419 m_pHMap = aHParaHtmlAbsMap;
1421 else
1423 m_pVMap = aVParaMap;
1424 m_pHMap = aHParaMap;
1427 else if ( eId == RndStdIds::FLY_AT_CHAR )
1429 if(m_bHtmlMode)
1431 m_pVMap = aVCharHtmlAbsMap;
1432 m_pHMap = aHCharHtmlAbsMap;
1434 else
1436 m_pVMap = aVCharMap;
1437 m_pHMap = aHCharMap;
1440 else if ( eId == RndStdIds::FLY_AS_CHAR )
1442 m_pVMap = m_bHtmlMode ? aVAsCharHtmlMap : aVAsCharMap;
1443 m_pHMap = nullptr;
1444 bEnable = false;
1446 m_xHorizontalDLB->set_sensitive( bEnable );
1447 m_xHorizontalFT->set_sensitive( bEnable );
1449 // select current Pos
1450 // horizontal
1451 if ( nH < 0 )
1453 nH = m_nOldH;
1454 nHRel = m_nOldHRel;
1456 sal_Int32 nMapPos = FillPosLB(m_pHMap, nH, nHRel, *m_xHorizontalDLB);
1457 FillRelLB(m_pHMap, nMapPos, nH, nHRel, *m_xHoriRelationLB, *m_xHoriRelationFT);
1459 // vertical
1460 if ( nV < 0 )
1462 nV = m_nOldV;
1463 nVRel = m_nOldVRel;
1465 nMapPos = FillPosLB(m_pVMap, nV, nVRel, *m_xVerticalDLB);
1466 FillRelLB(m_pVMap, nMapPos, nV, nVRel, *m_xVertRelationLB, *m_xVertRelationFT);
1468 bEnable = nH == text::HoriOrientation::NONE && eId != RndStdIds::FLY_AS_CHAR;
1469 if (!bEnable)
1470 m_xAtHorzPosED->set_value(0, FieldUnit::TWIP);
1471 else
1473 if (nX != LONG_MAX)
1474 m_xAtHorzPosED->set_value(m_xAtHorzPosED->normalize(nX), FieldUnit::TWIP);
1476 m_xAtHorzPosFT->set_sensitive( bEnable );
1477 m_xAtHorzPosED->set_sensitive( bEnable );
1479 bEnable = nV == text::VertOrientation::NONE;
1480 if ( !bEnable )
1481 m_xAtVertPosED->set_value(0, FieldUnit::TWIP);
1482 else
1484 if (eId == RndStdIds::FLY_AS_CHAR)
1486 if ( nY == LONG_MAX )
1487 nY = 0;
1488 else
1489 nY *= -1;
1491 if ( nY != LONG_MAX )
1492 m_xAtVertPosED->set_value(m_xAtVertPosED->normalize(nY), FieldUnit::TWIP);
1494 m_xAtVertPosFT->set_sensitive( bEnable && m_bAllowVertPositioning );
1495 m_xAtVertPosED->set_sensitive( bEnable && m_bAllowVertPositioning );
1496 UpdateExample();
1499 sal_Int32 SwFramePage::FillPosLB(const FrameMap* _pMap,
1500 const sal_Int16 _nAlign,
1501 const sal_Int16 _nRel,
1502 weld::ComboBox& _rLB )
1504 OUString sSelEntry;
1505 const OUString sOldEntry = _rLB.get_active_text();
1507 _rLB.clear();
1509 // i#22341 determine all possible listbox relations for
1510 // given relation for map <aVCharMap>
1511 const LB nLBRelations = (_pMap != aVCharMap)
1512 ? LB::NONE
1513 : ::lcl_GetLBRelationsForRelations( _nRel );
1515 // fill Listbox
1516 size_t nCount = ::lcl_GetFrameMapCount(_pMap);
1517 for (size_t i = 0; _pMap && i < nCount; ++i)
1519 // Why not from the left/from inside or from above?
1520 SvxSwFramePosString::StringId eStrId = m_xMirrorPagesCB->get_active() ? _pMap[i].eMirrorStrId : _pMap[i].eStrId;
1521 // --> OD 2009-08-31 #mongolianlayout#
1522 eStrId = lcl_ChangeResIdToVerticalOrRTL( eStrId,
1523 m_bIsVerticalFrame,
1524 m_bIsVerticalL2R,
1525 m_bIsInRightToLeft);
1526 OUString sEntry(SvxSwFramePosString::GetString(eStrId));
1527 if (_rLB.find_text(sEntry) == -1)
1529 // don't insert entries when frames are character bound
1530 _rLB.append_text(sEntry);
1532 // i#22341 - add condition to handle map <aVCharMap>
1533 // that is ambiguous in the alignment.
1534 if ( _pMap[i].nAlign == _nAlign &&
1535 ( (_pMap != aVCharMap) || _pMap[i].nLBRelations & nLBRelations ) )
1537 sSelEntry = sEntry;
1541 _rLB.set_active_text(sSelEntry);
1542 if (_rLB.get_active() == -1)
1543 _rLB.set_active_text(sOldEntry);
1545 if (_rLB.get_active() == -1 && _rLB.get_count())
1546 _rLB.set_active(0);
1548 PosHdl(_rLB);
1550 return GetMapPos(_pMap, _rLB);
1553 void SwFramePage::FillRelLB(const FrameMap* _pMap,
1554 const sal_uInt16 _nLBSelPos,
1555 const sal_Int16 _nAlign,
1556 const sal_Int16 _nRel,
1557 weld::ComboBox& _rLB,
1558 weld::Label& _rFT)
1560 OUString sSelEntry;
1561 LB nLBRelations = LB::NONE;
1562 size_t nMapCount = ::lcl_GetFrameMapCount(_pMap);
1564 _rLB.clear();
1566 if (_nLBSelPos < nMapCount)
1568 if (_pMap == aVAsCharHtmlMap || _pMap == aVAsCharMap)
1570 const OUString sOldEntry(_rLB.get_active_text());
1571 SvxSwFramePosString::StringId eStrId = _pMap[_nLBSelPos].eStrId;
1573 for (size_t nMapPos = 0; nMapPos < nMapCount; nMapPos++)
1575 if (_pMap[nMapPos].eStrId == eStrId)
1577 nLBRelations = _pMap[nMapPos].nLBRelations;
1578 for (RelationMap const & rCharMap : aAsCharRelationMap)
1580 if (nLBRelations & rCharMap.nLBRelation)
1582 // --> OD 2009-08-31 #mongolianlayout#
1583 SvxSwFramePosString::StringId sStrId1 =
1584 lcl_ChangeResIdToVerticalOrRTL( rCharMap.eStrId,
1585 m_bIsVerticalFrame,
1586 m_bIsVerticalL2R,
1587 m_bIsInRightToLeft);
1588 const OUString sEntry = SvxSwFramePosString::GetString(sStrId1);
1589 _rLB.append(weld::toId(&rCharMap), sEntry);
1590 if (_pMap[nMapPos].nAlign == _nAlign)
1591 sSelEntry = sEntry;
1592 break;
1597 if (!sSelEntry.isEmpty())
1598 _rLB.set_active_text(sSelEntry);
1599 else
1601 _rLB.set_active_text(sOldEntry);
1603 if (_rLB.get_active() == -1)
1605 for (int i = 0; i < _rLB.get_count(); i++)
1607 RelationMap *pEntry = weld::fromId<RelationMap*>(_rLB.get_id(i));
1608 if (pEntry->nLBRelation == LB::RelChar) // default
1610 _rLB.set_active(i);
1611 break;
1617 else
1619 // special handling for map <aVCharMap>,
1620 // because its ambiguous in its <eStrId>/<eMirrorStrId>.
1621 if ( _pMap == aVCharMap )
1623 nLBRelations = ::lcl_GetLBRelationsForStrID( _pMap,
1624 ( m_xMirrorPagesCB->get_active()
1625 ? _pMap[_nLBSelPos].eMirrorStrId
1626 : _pMap[_nLBSelPos].eStrId),
1627 m_xMirrorPagesCB->get_active() );
1629 else
1631 nLBRelations = _pMap[_nLBSelPos].nLBRelations;
1634 for (sal_uLong nBit = 1; nBit < 0x80000000; nBit <<= 1)
1636 if (nLBRelations & static_cast<LB>(nBit))
1638 for (RelationMap const & rMap : aRelationMap)
1640 if (rMap.nLBRelation == static_cast<LB>(nBit))
1642 SvxSwFramePosString::StringId eStrId1 = m_xMirrorPagesCB->get_active() ?
1643 rMap.eMirrorStrId : rMap.eStrId;
1644 // --> OD 2009-08-31 #mongolianlayout#
1645 eStrId1 =
1646 lcl_ChangeResIdToVerticalOrRTL( eStrId1,
1647 m_bIsVerticalFrame,
1648 m_bIsVerticalL2R,
1649 m_bIsInRightToLeft);
1650 const OUString sEntry = SvxSwFramePosString::GetString(eStrId1);
1651 _rLB.append(weld::toId(&rMap), sEntry);
1652 if (sSelEntry.isEmpty() && rMap.nRelation == _nRel)
1653 sSelEntry = sEntry;
1658 if (!sSelEntry.isEmpty())
1659 _rLB.set_active_text(sSelEntry);
1660 else
1662 // Probably anchor switch. So look for similar relation
1663 sal_Int16 nSimRel = -1;
1664 switch (_nRel)
1666 case text::RelOrientation::FRAME:
1667 nSimRel = text::RelOrientation::PAGE_FRAME;
1668 break;
1669 case text::RelOrientation::PRINT_AREA:
1670 nSimRel = text::RelOrientation::PAGE_PRINT_AREA;
1671 break;
1672 case text::RelOrientation::PAGE_LEFT:
1673 nSimRel = text::RelOrientation::FRAME_LEFT;
1674 break;
1675 case text::RelOrientation::PAGE_RIGHT:
1676 nSimRel = text::RelOrientation::FRAME_RIGHT;
1677 break;
1678 case text::RelOrientation::FRAME_LEFT:
1679 nSimRel = text::RelOrientation::PAGE_LEFT;
1680 break;
1681 case text::RelOrientation::FRAME_RIGHT:
1682 nSimRel = text::RelOrientation::PAGE_RIGHT;
1683 break;
1684 case text::RelOrientation::PAGE_FRAME:
1685 nSimRel = text::RelOrientation::FRAME;
1686 break;
1687 case text::RelOrientation::PAGE_PRINT_AREA:
1688 nSimRel = text::RelOrientation::PRINT_AREA;
1689 break;
1691 default:
1692 if (_rLB.get_active() != -1)
1694 RelationMap *pEntry = weld::fromId<RelationMap*>(_rLB.get_id(_rLB.get_count() - 1));
1695 nSimRel = pEntry->nRelation;
1697 break;
1700 for (int i = 0; i < _rLB.get_count(); i++)
1702 RelationMap *pEntry = weld::fromId<RelationMap*>(_rLB.get_id(i));
1703 if (pEntry->nRelation == nSimRel)
1705 _rLB.set_active(i);
1706 break;
1710 if (_rLB.get_active() == -1)
1711 _rLB.set_active(0);
1716 const bool bEnable = _rLB.get_count() != 0
1717 && (&_rLB != m_xVertRelationLB.get() || m_bAllowVertPositioning);
1718 _rLB.set_sensitive( bEnable );
1719 _rFT.set_sensitive( bEnable );
1721 RelHdl(_rLB);
1724 sal_Int16 SwFramePage::GetRelation(const weld::ComboBox& rRelationLB)
1726 const auto nPos = rRelationLB.get_active();
1727 if (nPos != -1)
1729 RelationMap *pEntry = weld::fromId<RelationMap *>(rRelationLB.get_id(nPos));
1730 return pEntry->nRelation;
1733 return 0;
1736 sal_Int16 SwFramePage::GetAlignment(FrameMap const *pMap, sal_Int32 nMapPos,
1737 const weld::ComboBox& rRelationLB)
1739 if (!pMap || nMapPos < 0)
1740 return 0;
1742 const size_t nMapCount = ::lcl_GetFrameMapCount(pMap);
1744 if (o3tl::make_unsigned(nMapPos) >= nMapCount)
1745 return 0;
1747 // i#22341 special handling also for map <aVCharMap>,
1748 // because it contains ambiguous items for alignment
1749 if ( pMap != aVAsCharHtmlMap && pMap != aVAsCharMap && pMap != aVCharMap )
1750 return pMap[nMapPos].nAlign;
1752 if (rRelationLB.get_active() == -1)
1753 return 0;
1755 const RelationMap *const pRelationMap = weld::fromId<const RelationMap*>(
1756 rRelationLB.get_active_id());
1757 const LB nRel = pRelationMap->nLBRelation;
1758 const SvxSwFramePosString::StringId eStrId = pMap[nMapPos].eStrId;
1760 for (size_t i = 0; i < nMapCount; ++i)
1762 if (pMap[i].eStrId == eStrId && (pMap[i].nLBRelations & nRel))
1763 return pMap[i].nAlign;
1766 return 0;
1769 sal_Int32 SwFramePage::GetMapPos(const FrameMap *pMap, const weld::ComboBox& rAlignLB)
1771 sal_Int32 nMapPos = 0;
1772 auto nLBSelPos = rAlignLB.get_active();
1774 if (nLBSelPos != -1)
1776 if (pMap == aVAsCharHtmlMap || pMap == aVAsCharMap)
1778 const size_t nMapCount = ::lcl_GetFrameMapCount(pMap);
1779 const OUString sSelEntry(rAlignLB.get_active_text());
1781 for (size_t i = 0; i < nMapCount; i++)
1783 SvxSwFramePosString::StringId eResId = pMap[i].eStrId;
1785 OUString sEntry = SvxSwFramePosString::GetString(eResId);
1786 sEntry = MnemonicGenerator::EraseAllMnemonicChars( sEntry );
1788 if (sEntry == sSelEntry)
1790 nMapPos = static_cast< sal_Int32 >(i);
1791 break;
1795 else
1796 nMapPos = nLBSelPos;
1799 return nMapPos;
1802 RndStdIds SwFramePage::GetAnchor() const
1804 RndStdIds nRet = RndStdIds::FLY_AT_PAGE;
1805 if (m_xAnchorAtParaRB->get_active())
1807 nRet = RndStdIds::FLY_AT_PARA;
1809 else if (m_xAnchorAtCharRB->get_active())
1811 nRet = RndStdIds::FLY_AT_CHAR;
1813 else if (m_xAnchorAsCharRB->get_active())
1815 nRet = RndStdIds::FLY_AS_CHAR;
1817 else if (m_xAnchorAtFrameRB->get_active())
1819 nRet = RndStdIds::FLY_AT_FLY;
1821 return nRet;
1824 // Bsp - Update
1825 void SwFramePage::ActivatePage(const SfxItemSet& rSet)
1827 m_bNoModifyHdl = true;
1828 Init(rSet);
1829 m_bNoModifyHdl = false;
1830 //lock PercentFields
1831 m_xWidthED->LockAutoCalculation(true);
1832 m_xHeightED->LockAutoCalculation(true);
1833 RangeModifyHdl(); // set all maximum values initially
1834 m_xHeightED->LockAutoCalculation(false);
1835 m_xWidthED->LockAutoCalculation(false);
1836 m_xFollowTextFlowCB->save_state();
1837 m_xFlySplitCB->save_state();
1840 DeactivateRC SwFramePage::DeactivatePage(SfxItemSet * _pSet)
1842 if ( _pSet )
1844 FillItemSet( _pSet );
1846 if (!m_bFormat) // tdf#112574 no anchor in styles
1848 //FillItemSet doesn't set the anchor into the set when it matches
1849 //the original. But for the other pages we need the current anchor.
1850 SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell()
1851 : getFrameDlgParentShell();
1852 if (pSh)
1854 RndStdIds eAnchorId = GetAnchor();
1855 SwFormatAnchor aAnc( eAnchorId, eAnchorId == RndStdIds::FLY_AT_PAGE ? pSh->GetPhyPageNum() : 0 );
1856 _pSet->Put( aAnc );
1861 return DeactivateRC::LeavePage;
1864 // swap left/right with inside/outside
1865 IMPL_LINK_NOARG(SwFramePage, MirrorHdl, weld::Toggleable&, void)
1867 RndStdIds eId = GetAnchor();
1868 InitPos(eId, -1, 0, -1, 0, LONG_MAX, LONG_MAX);
1871 IMPL_LINK( SwFramePage, RelSizeClickHdl, weld::Toggleable&, rBtn, void )
1873 if (&rBtn == m_xRelWidthCB.get())
1875 m_xWidthED->ShowPercent(rBtn.get_active());
1876 m_xRelWidthRelationLB->set_sensitive(rBtn.get_active());
1877 if (rBtn.get_active())
1878 m_xWidthED->get()->set_max(MAX_PERCENT_WIDTH, FieldUnit::NONE);
1880 else // rBtn == m_xRelHeightCB.get()
1882 m_xHeightED->ShowPercent(rBtn.get_active());
1883 m_xRelHeightRelationLB->set_sensitive(rBtn.get_active());
1884 if (rBtn.get_active())
1885 m_xHeightED->get()->set_max(MAX_PERCENT_HEIGHT, FieldUnit::NONE);
1888 RangeModifyHdl(); // correct the values again
1890 if (&rBtn == m_xRelWidthCB.get())
1891 ModifyHdl(*m_xWidthED->get());
1892 else // rBtn == m_xRelHeightCB.get()
1893 ModifyHdl(*m_xHeightED->get());
1896 // range check
1897 IMPL_LINK_NOARG(SwFramePage, RangeModifyClickHdl, weld::Toggleable&, void)
1899 RangeModifyHdl();
1902 void SwFramePage::RangeModifyHdl()
1904 if (m_bNoModifyHdl)
1905 return;
1907 SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell()
1908 : getFrameDlgParentShell();
1909 OSL_ENSURE(pSh , "shell not found");
1910 if (!pSh)
1911 return;
1913 SwFlyFrameAttrMgr aMgr( m_bNew, pSh, GetItemSet() );
1914 SvxSwFrameValidation aVal;
1916 aVal.nAnchorType = GetAnchor();
1917 aVal.bAutoHeight = m_xAutoHeightCB->get_active();
1918 aVal.bMirror = m_xMirrorPagesCB->get_active();
1919 aVal.bFollowTextFlow = m_xFollowTextFlowCB->get_active();
1921 if ( m_pHMap )
1923 // alignment horizontal
1924 const sal_Int32 nMapPos = GetMapPos(m_pHMap, *m_xHorizontalDLB);
1925 aVal.nHoriOrient = GetAlignment(m_pHMap, nMapPos, *m_xHoriRelationLB);
1926 aVal.nHRelOrient = GetRelation(*m_xHoriRelationLB);
1928 else
1929 aVal.nHoriOrient = text::HoriOrientation::NONE;
1931 if ( m_pVMap )
1933 // alignment vertical
1934 const sal_Int32 nMapPos = GetMapPos(m_pVMap, *m_xVerticalDLB);
1935 aVal.nVertOrient = GetAlignment(m_pVMap, nMapPos, *m_xVertRelationLB);
1936 aVal.nVRelOrient = GetRelation(*m_xVertRelationLB);
1938 else
1939 aVal.nVertOrient = text::VertOrientation::NONE;
1941 const tools::Long nAtHorzPosVal = static_cast< tools::Long >(
1942 m_xAtHorzPosED->denormalize(m_xAtHorzPosED->get_value(FieldUnit::TWIP)) );
1943 const tools::Long nAtVertPosVal = static_cast< tools::Long >(
1944 m_xAtVertPosED->denormalize(m_xAtVertPosED->get_value(FieldUnit::TWIP)) );
1946 aVal.nHPos = nAtHorzPosVal;
1947 aVal.nVPos = nAtVertPosVal;
1949 aMgr.ValidateMetrics(aVal, mpToCharContentPos, true); // one time, to get reference values for percental values
1951 // set reference values for percental values (100%) ...
1952 m_xWidthED->SetRefValue(aVal.aPercentSize.Width());
1953 m_xHeightED->SetRefValue(aVal.aPercentSize.Height());
1955 // ... and correctly convert width and height with it
1956 SwTwips nWidth = static_cast< SwTwips >(m_xWidthED->DenormalizePercent(m_xWidthED->get_value(FieldUnit::TWIP)));
1957 SwTwips nHeight = static_cast< SwTwips >(m_xHeightED->DenormalizePercent(m_xHeightED->get_value(FieldUnit::TWIP)));
1958 aVal.nWidth = nWidth;
1959 aVal.nHeight = nHeight;
1961 aMgr.ValidateMetrics(aVal, mpToCharContentPos); // one more time, to determine all remaining values with correct width and height.
1963 // all columns have to be correct
1964 const SfxItemSet* pExampleSet = GetDialogExampleSet();
1965 if (pExampleSet && SfxItemState::DEFAULT <= pExampleSet->GetItemState(RES_COL))
1967 const SwFormatCol& rCol = pExampleSet->Get(RES_COL);
1968 if ( rCol.GetColumns().size() > 1 )
1970 for (const SwColumn & i : rCol.GetColumns())
1972 aVal.nMinWidth += i.GetLeft() +
1973 i.GetRight() +
1974 MINFLY;
1976 aVal.nMinWidth -= MINFLY;//one was already in there!
1980 nWidth = aVal.nWidth;
1981 nHeight = aVal.nHeight;
1983 // minimum range also for template
1984 m_xHeightED->set_min(m_xHeightED->NormalizePercent(aVal.nMinHeight), FieldUnit::TWIP);
1985 m_xWidthED->set_min(m_xWidthED->NormalizePercent(aVal.nMinWidth), FieldUnit::TWIP);
1987 SwTwips nMaxWidth(aVal.nMaxWidth);
1988 SwTwips nMaxHeight(aVal.nMaxHeight);
1990 if (aVal.bAutoHeight && (m_sDlgType == "PictureDialog" || m_sDlgType == "ObjectDialog"))
1992 SwTwips nTmp = std::min(nWidth * nMaxHeight / std::max(nHeight, SwTwips(1)), nMaxHeight);
1993 m_xWidthED->set_max(m_xWidthED->NormalizePercent(nTmp), FieldUnit::TWIP);
1995 nTmp = std::min(nHeight * nMaxWidth / std::max(nWidth, SwTwips(1)), nMaxWidth);
1996 m_xHeightED->set_max(m_xWidthED->NormalizePercent(nTmp), FieldUnit::TWIP);
1998 else
2000 SwTwips nTmp = static_cast< SwTwips >(m_xHeightED->NormalizePercent(nMaxHeight));
2001 m_xHeightED->set_max(nTmp, FieldUnit::TWIP);
2003 nTmp = static_cast< SwTwips >(m_xWidthED->NormalizePercent(nMaxWidth));
2004 m_xWidthED->set_max(nTmp, FieldUnit::TWIP);
2007 m_xAtHorzPosED->set_range(m_xAtHorzPosED->normalize(aVal.nMinHPos),
2008 m_xAtHorzPosED->normalize(aVal.nMaxHPos),
2009 FieldUnit::TWIP);
2010 if (aVal.nHPos != nAtHorzPosVal)
2011 m_xAtHorzPosED->set_value(m_xAtHorzPosED->normalize(aVal.nHPos), FieldUnit::TWIP);
2013 const SwTwips nUpperOffset = (aVal.nAnchorType == RndStdIds::FLY_AS_CHAR)
2014 ? m_nUpperBorder : 0;
2015 const SwTwips nLowerOffset = (aVal.nAnchorType == RndStdIds::FLY_AS_CHAR)
2016 ? m_nLowerBorder : 0;
2018 m_xAtVertPosED->set_range(m_xAtVertPosED->normalize(aVal.nMinVPos + nLowerOffset + nUpperOffset),
2019 m_xAtVertPosED->normalize(aVal.nMaxVPos),
2020 FieldUnit::TWIP);
2021 if (aVal.nVPos != nAtVertPosVal)
2022 m_xAtVertPosED->set_value(m_xAtVertPosED->normalize(aVal.nVPos), FieldUnit::TWIP);
2025 IMPL_LINK_NOARG(SwFramePage, AnchorTypeHdl, weld::Toggleable&, void)
2027 m_xMirrorPagesCB->set_sensitive(!m_xAnchorAsCharRB->get_active());
2029 // i#18732 - enable check box 'Follow text flow' for anchor
2030 // type to-paragraph' and to-character
2031 // i#22305 - enable check box 'Follow text
2032 // flow' also for anchor type to-frame.
2033 m_xFollowTextFlowCB->set_sensitive(m_xAnchorAtParaRB->get_active() ||
2034 m_xAnchorAtCharRB->get_active() ||
2035 m_xAnchorAtFrameRB->get_active());
2036 m_xFlySplitCB->set_sensitive(m_xAnchorAtParaRB->get_active());
2038 RndStdIds eId = GetAnchor();
2040 InitPos( eId, -1, 0, -1, 0, LONG_MAX, LONG_MAX);
2041 RangeModifyHdl();
2043 if(m_bHtmlMode)
2045 PosHdl(*m_xHorizontalDLB);
2046 PosHdl(*m_xVerticalDLB);
2049 EnableVerticalPositioning( !(m_bIsMathOLE && m_bIsMathBaselineAlignment
2050 && RndStdIds::FLY_AS_CHAR == eId) );
2053 IMPL_LINK( SwFramePage, PosHdl, weld::ComboBox&, rLB, void )
2055 bool bHori = &rLB == m_xHorizontalDLB.get();
2056 weld::ComboBox *pRelLB = bHori ? m_xHoriRelationLB.get() : m_xVertRelationLB.get();
2057 weld::Label *pRelFT = bHori ? m_xHoriRelationFT.get() : m_xVertRelationFT.get();
2058 FrameMap const *pMap = bHori ? m_pHMap : m_pVMap;
2060 const sal_Int32 nMapPos = GetMapPos(pMap, rLB);
2061 const sal_Int16 nAlign = GetAlignment(pMap, nMapPos, *pRelLB);
2063 if (bHori)
2065 bool bEnable = text::HoriOrientation::NONE == nAlign;
2066 m_xAtHorzPosED->set_sensitive( bEnable );
2067 m_xAtHorzPosFT->set_sensitive( bEnable );
2069 else
2071 bool bEnable = text::VertOrientation::NONE == nAlign && m_bAllowVertPositioning;
2072 m_xAtVertPosED->set_sensitive( bEnable );
2073 m_xAtVertPosFT->set_sensitive( bEnable );
2076 RangeModifyHdl();
2078 sal_Int16 nRel = 0;
2079 if (rLB.get_active() != -1)
2081 if (pRelLB->get_active() != -1)
2082 nRel = weld::fromId<RelationMap*>(pRelLB->get_active_id())->nRelation;
2083 FillRelLB(pMap, nMapPos, nAlign, nRel, *pRelLB, *pRelFT);
2085 else
2086 pRelLB->clear();
2088 UpdateExample();
2090 if (bHori)
2091 m_bAtHorzPosModified = true;
2092 else
2093 m_bAtVertPosModified = true;
2095 // special treatment for HTML-Mode with horizontal-vertical-dependencies
2096 if(!(m_bHtmlMode && (RndStdIds::FLY_AT_CHAR == GetAnchor())))
2097 return;
2099 bool bSet = false;
2100 if(bHori)
2102 // right is allowed only above - from the left only above
2103 // from the left at character -> below
2104 if((text::HoriOrientation::LEFT == nAlign || text::HoriOrientation::RIGHT == nAlign) &&
2105 0 == m_xVerticalDLB->get_active())
2107 if(text::RelOrientation::FRAME == nRel)
2108 m_xVerticalDLB->set_active(1);
2109 else
2110 m_xVerticalDLB->set_active(0);
2111 bSet = true;
2113 else if(text::HoriOrientation::LEFT == nAlign && 1 == m_xVerticalDLB->get_active())
2115 m_xVerticalDLB->set_active(0);
2116 bSet = true;
2118 else if(text::HoriOrientation::NONE == nAlign && 1 == m_xVerticalDLB->get_active())
2120 m_xVerticalDLB->set_active(0);
2121 bSet = true;
2123 if(bSet)
2124 PosHdl(*m_xVerticalDLB);
2126 else
2128 if(text::VertOrientation::TOP == nAlign)
2130 if (1 == m_xHorizontalDLB->get_active())
2132 m_xHorizontalDLB->set_active(0);
2133 bSet = true;
2135 m_xHoriRelationLB->set_active(1);
2137 else if(text::VertOrientation::CHAR_BOTTOM == nAlign)
2139 if (2 == m_xHorizontalDLB->get_active())
2141 m_xHorizontalDLB->set_active(0);
2142 bSet = true;
2144 m_xHoriRelationLB->set_active(0) ;
2146 if(bSet)
2147 PosHdl(*m_xHorizontalDLB);
2151 // horizontal Pos
2152 IMPL_LINK( SwFramePage, RelHdl, weld::ComboBox&, rLB, void )
2154 bool bHori = &rLB == m_xHoriRelationLB.get();
2156 UpdateExample();
2158 if (bHori)
2159 m_bAtHorzPosModified = true;
2160 else
2161 m_bAtVertPosModified = true;
2163 if (m_bHtmlMode && (RndStdIds::FLY_AT_CHAR == GetAnchor()))
2165 if(bHori)
2167 const sal_Int16 nRel = GetRelation(*m_xHoriRelationLB);
2168 if(text::RelOrientation::PRINT_AREA == nRel && 0 == m_xVerticalDLB->get_active())
2170 m_xVerticalDLB->set_active(1);
2172 else if(text::RelOrientation::CHAR == nRel && 1 == m_xVerticalDLB->get_active())
2174 m_xVerticalDLB->set_active(0);
2178 RangeModifyHdl();
2181 IMPL_LINK_NOARG(SwFramePage, RealSizeHdl, weld::Button&, void)
2183 m_xWidthED->set_value(m_xWidthED->NormalizePercent(m_aGrfSize.Width()), FieldUnit::TWIP);
2184 m_xHeightED->set_value(m_xHeightED->NormalizePercent(m_aGrfSize.Height()), FieldUnit::TWIP);
2185 m_fWidthHeightRatio = m_aGrfSize.Height() ? double(m_aGrfSize.Width()) / double(m_aGrfSize.Height()) : 1.0;
2186 UpdateExample();
2189 IMPL_LINK_NOARG(SwFramePage, AutoWidthClickHdl, weld::Toggleable&, void)
2191 if( !IsInGraficMode() )
2192 HandleAutoCB( m_xAutoWidthCB->get_active(), *m_xWidthFT, *m_xWidthAutoFT, *m_xWidthED->get() );
2195 IMPL_LINK_NOARG(SwFramePage, AutoHeightClickHdl, weld::Toggleable&, void)
2197 if (!IsInGraficMode())
2198 HandleAutoCB(m_xAutoHeightCB->get_active(), *m_xHeightFT, *m_xHeightAutoFT, *m_xWidthED->get());
2201 IMPL_LINK_NOARG(SwFramePage, RatioClickHdl, weld::Toggleable&, void)
2203 m_xCbxScaleImg->set_from_icon_name(m_xFixedRatioCB->get_active() ? RID_SVXBMP_LOCKED : RID_SVXBMP_UNLOCKED);
2206 IMPL_LINK( SwFramePage, ModifyHdl, weld::MetricSpinButton&, rEdit, void )
2208 SwTwips nWidth = static_cast< SwTwips >(m_xWidthED->DenormalizePercent(m_xWidthED->get_value(FieldUnit::TWIP)));
2209 SwTwips nHeight = static_cast< SwTwips >(m_xHeightED->DenormalizePercent(m_xHeightED->get_value(FieldUnit::TWIP)));
2210 if (m_xFixedRatioCB->get_active() && !m_bIgnoreFixedRatio)
2212 if (&rEdit == m_xWidthED->get())
2214 nHeight = SwTwips(static_cast<double>(nWidth) / m_fWidthHeightRatio);
2215 m_xHeightED->set_value(m_xHeightED->NormalizePercent(nHeight), FieldUnit::TWIP);
2217 else if (&rEdit == m_xHeightED->get())
2219 nWidth = SwTwips(static_cast<double>(nHeight) * m_fWidthHeightRatio);
2220 m_xWidthED->set_value(m_xWidthED->NormalizePercent(nWidth), FieldUnit::TWIP);
2223 m_fWidthHeightRatio = nHeight ? double(nWidth) / double(nHeight) : 1.0;
2224 UpdateExample();
2227 void SwFramePage::UpdateExample()
2229 auto nPos = m_xHorizontalDLB->get_active();
2230 if (m_pHMap && nPos != -1)
2232 const sal_Int32 nMapPos = GetMapPos(m_pHMap, *m_xHorizontalDLB);
2233 m_aExampleWN.SetHAlign(GetAlignment(m_pHMap, nMapPos, *m_xHoriRelationLB));
2234 m_aExampleWN.SetHoriRel(GetRelation(*m_xHoriRelationLB));
2237 nPos = m_xVerticalDLB->get_active();
2238 if (m_pVMap && nPos != -1)
2240 const sal_Int32 nMapPos = GetMapPos(m_pVMap, *m_xVerticalDLB);
2241 m_aExampleWN.SetVAlign(GetAlignment(m_pVMap, nMapPos, *m_xVertRelationLB));
2242 m_aExampleWN.SetVertRel(GetRelation(*m_xVertRelationLB));
2245 // size
2246 auto nXPos = m_xAtHorzPosED->denormalize(m_xAtHorzPosED->get_value(FieldUnit::TWIP));
2247 auto nYPos = m_xAtVertPosED->denormalize(m_xAtVertPosED->get_value(FieldUnit::TWIP));
2248 m_aExampleWN.SetRelPos(Point(nXPos, nYPos));
2250 m_aExampleWN.SetAnchor(GetAnchor());
2251 m_aExampleWN.Invalidate();
2254 void SwFramePage::Init(const SfxItemSet& rSet)
2256 if(!m_bFormat)
2258 SwWrtShell* pSh = getFrameDlgParentShell();
2260 // size
2261 const bool bSizeFixed = pSh->IsSelObjProtected( FlyProtectFlags::Fixed ) != FlyProtectFlags::NONE;
2263 m_xWidthED->set_sensitive( !bSizeFixed );
2264 m_xHeightED->set_sensitive( !bSizeFixed );
2266 // size controls for math OLE objects
2267 if ( m_sDlgType == "ObjectDialog" && ! m_bNew )
2269 // disable width and height for math objects
2270 const SvGlobalName aFactNm( pSh->GetOLEObject()->getClassID() );
2272 static struct GlobalNameId {
2273 sal_uInt32 n1;
2274 sal_uInt16 n2, n3;
2275 sal_uInt8 b8, b9, b10, b11, b12, b13, b14, b15;
2276 } const aGlbNmIds[] = { { SO3_SM_CLASSID_60 }, { SO3_SM_CLASSID_50 },
2277 { SO3_SM_CLASSID_40 }, { SO3_SM_CLASSID_30 } };
2279 for (const GlobalNameId & rId : aGlbNmIds) {
2280 SvGlobalName aGlbNm( rId.n1, rId.n2, rId.n3,
2281 rId.b8, rId.b9, rId.b10, rId.b11,
2282 rId.b12, rId.b13, rId.b14, rId.b15 );
2284 if( aFactNm == aGlbNm )
2286 // disable size controls for math OLE objects
2287 m_xWidthFT->set_sensitive(false);
2288 m_xWidthED->set_sensitive(false);
2289 m_xRelWidthCB->set_sensitive(false);
2290 m_xHeightFT->set_sensitive(false);
2291 m_xHeightED->set_sensitive(false);
2292 m_xRelHeightCB->set_sensitive(false);
2293 m_xFixedRatioCB->set_sensitive(false);
2294 m_xRealSizeBT->set_sensitive(false);
2295 break;
2299 // TODO/LATER: get correct aspect
2300 if(0 != (pSh->GetOLEObject()->getStatus( embed::Aspects::MSOLE_CONTENT ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
2301 m_xRealSizeBT->set_sensitive(false);
2305 SwFormatFrameSize rSize = rSet.Get(RES_FRM_SIZE);
2306 // size could already have been set from another (Crop) page
2307 if (const SvxSizeItem* pSizeItem = rSet.GetItemIfSet(SID_ATTR_GRAF_FRMSIZE, false))
2309 if (pSizeItem->GetSize() != rSize.GetSize())
2310 rSize.SetSize(pSizeItem->GetSize());
2313 sal_Int64 nWidth = m_xWidthED->NormalizePercent(rSize.GetWidth());
2314 sal_Int64 nHeight = m_xHeightED->NormalizePercent(rSize.GetHeight());
2316 if (nWidth != m_xWidthED->get_value(FieldUnit::TWIP))
2317 m_xWidthED->set_value(nWidth, FieldUnit::TWIP);
2319 if (nHeight != m_xHeightED->get_value(FieldUnit::TWIP))
2320 m_xHeightED->set_value(nHeight, FieldUnit::TWIP);
2322 if (!IsInGraficMode())
2324 SwFrameSize eSize = rSize.GetHeightSizeType();
2325 bool bCheck = eSize != SwFrameSize::Fixed;
2326 m_xAutoHeightCB->set_active(bCheck);
2327 HandleAutoCB( bCheck, *m_xHeightFT, *m_xHeightAutoFT, *m_xWidthED->get() );
2328 if( eSize == SwFrameSize::Variable )
2329 m_xHeightED->set_value(m_xHeightED->get_min());
2331 eSize = rSize.GetWidthSizeType();
2332 bCheck = eSize != SwFrameSize::Fixed;
2333 m_xAutoWidthCB->set_active(bCheck);
2334 HandleAutoCB( bCheck, *m_xWidthFT, *m_xWidthAutoFT, *m_xWidthED->get() );
2335 if( eSize == SwFrameSize::Variable )
2336 m_xWidthED->set_value(m_xWidthED->get_min());
2338 if ( !m_bFormat )
2340 SwWrtShell* pSh = getFrameDlgParentShell();
2341 const SwFrameFormat* pFormat = pSh->GetFlyFrameFormat();
2342 if( pFormat && pFormat->GetChain().GetNext() )
2343 m_xAutoHeightCB->set_sensitive( false );
2346 else
2347 m_xAutoHeightCB->hide();
2349 // organise circulation-gap for character bound frames
2350 const SvxULSpaceItem &rUL = rSet.Get(RES_UL_SPACE);
2351 m_nUpperBorder = rUL.GetUpper();
2352 m_nLowerBorder = rUL.GetLower();
2354 if (SfxItemState::SET == rSet.GetItemState(FN_KEEP_ASPECT_RATIO))
2355 m_xFixedRatioCB->set_active(rSet.Get(FN_KEEP_ASPECT_RATIO).GetValue());
2356 // see tdf#132591 and tdf#151382 for some examples of FN_KEEP_ASPECT_RATIO cases
2357 m_xFixedRatioCB->save_state();
2359 // columns
2360 SwFormatCol aCol( rSet.Get(RES_COL) );
2361 ::FitToActualSize( aCol, o3tl::narrowing<sal_uInt16>(rSize.GetWidth()) );
2363 RndStdIds eAnchorId = GetAnchor();
2365 if ( m_bNew && !m_bFormat )
2366 InitPos(eAnchorId, -1, 0, -1, 0, LONG_MAX, LONG_MAX);
2367 else
2369 const SwFormatHoriOrient& rHori = rSet.Get(RES_HORI_ORIENT);
2370 const SwFormatVertOrient& rVert = rSet.Get(RES_VERT_ORIENT);
2371 m_nOldH = rHori.GetHoriOrient();
2372 m_nOldHRel = rHori.GetRelationOrient();
2373 m_nOldV = rVert.GetVertOrient();
2374 m_nOldVRel = rVert.GetRelationOrient();
2376 if (eAnchorId == RndStdIds::FLY_AT_PAGE)
2378 if (m_nOldHRel == text::RelOrientation::FRAME)
2379 m_nOldHRel = text::RelOrientation::PAGE_FRAME;
2380 else if (m_nOldHRel == text::RelOrientation::PRINT_AREA)
2381 m_nOldHRel = text::RelOrientation::PAGE_PRINT_AREA;
2382 if (m_nOldVRel == text::RelOrientation::FRAME)
2383 m_nOldVRel = text::RelOrientation::PAGE_FRAME;
2384 else if (m_nOldVRel == text::RelOrientation::PRINT_AREA)
2385 m_nOldVRel = text::RelOrientation::PAGE_PRINT_AREA;
2388 m_xMirrorPagesCB->set_active(rHori.IsPosToggle());
2389 m_xMirrorPagesCB->save_state();
2391 InitPos(eAnchorId,
2392 m_nOldH,
2393 m_nOldHRel,
2394 m_nOldV,
2395 m_nOldVRel,
2396 rHori.GetPos(),
2397 rVert.GetPos());
2400 // transparent for example
2401 // circulation for example
2402 const SwFormatSurround& rSurround = rSet.Get(RES_SURROUND);
2403 m_aExampleWN.SetWrap( rSurround.GetSurround() );
2405 if ( rSurround.GetSurround() == css::text::WrapTextMode_THROUGH )
2407 const SvxOpaqueItem& rOpaque = rSet.Get(RES_OPAQUE);
2408 m_aExampleWN.SetTransparent(!rOpaque.GetValue());
2411 // switch to percent if applicable
2412 RangeModifyHdl(); // set reference values (for 100%)
2414 if (rSize.GetWidthPercent() == SwFormatFrameSize::SYNCED || rSize.GetHeightPercent() == SwFormatFrameSize::SYNCED)
2415 m_xFixedRatioCB->set_active(true);
2416 if (rSize.GetWidthPercent() && rSize.GetWidthPercent() != SwFormatFrameSize::SYNCED &&
2417 !m_xRelWidthCB->get_active())
2419 m_xRelWidthCB->set_active(true);
2420 m_bIgnoreFixedRatio = true;
2421 RelSizeClickHdl(*m_xRelWidthCB);
2422 m_bIgnoreFixedRatio = false;
2423 m_xWidthED->set_value(rSize.GetWidthPercent(), FieldUnit::PERCENT);
2425 if (rSize.GetHeightPercent() && rSize.GetHeightPercent() != SwFormatFrameSize::SYNCED &&
2426 !m_xRelHeightCB->get_active())
2428 m_xRelHeightCB->set_active(true);
2429 m_bIgnoreFixedRatio = true;
2430 RelSizeClickHdl(*m_xRelHeightCB);
2431 m_bIgnoreFixedRatio = false;
2432 m_xHeightED->set_value(rSize.GetHeightPercent(), FieldUnit::PERCENT);
2434 m_xRelWidthCB->save_state();
2435 m_xRelHeightCB->save_state();
2437 if (rSize.GetWidthPercentRelation() == text::RelOrientation::PAGE_FRAME)
2438 m_xRelWidthRelationLB->set_active(1);
2439 else
2440 m_xRelWidthRelationLB->set_active(0);
2442 if (rSize.GetHeightPercentRelation() == text::RelOrientation::PAGE_FRAME)
2443 m_xRelHeightRelationLB->set_active(1);
2444 else
2445 m_xRelHeightRelationLB->set_active(0);
2446 m_xCbxScaleImg->set_from_icon_name(m_xFixedRatioCB->get_active() ? RID_SVXBMP_LOCKED : RID_SVXBMP_UNLOCKED);
2449 void SwFramePage::SetFormatUsed(bool bFormatUsed)
2451 m_bFormat = bFormatUsed;
2452 if (m_bFormat)
2453 m_xAnchorAtFrameRB->hide();
2456 void SwFramePage::EnableVerticalPositioning( bool bEnable )
2458 m_bAllowVertPositioning = bEnable;
2459 m_xVerticalFT->set_sensitive( bEnable );
2460 m_xVerticalDLB->set_sensitive( bEnable );
2461 m_xAtVertPosFT->set_sensitive( bEnable );
2462 m_xAtVertPosED->set_sensitive( bEnable );
2463 m_xVertRelationFT->set_sensitive( bEnable );
2464 m_xVertRelationLB->set_sensitive( bEnable );
2467 SwGrfExtPage::SwGrfExtPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet)
2468 : SfxTabPage(pPage, pController, u"modules/swriter/ui/picturepage.ui"_ustr, u"PicturePage"_ustr, &rSet)
2469 , m_bHtmlMode(false)
2470 , m_xMirror(m_xBuilder->weld_widget(u"flipframe"_ustr))
2471 , m_xMirrorVertBox(m_xBuilder->weld_check_button(u"vert"_ustr))
2472 , m_xMirrorHorzBox(m_xBuilder->weld_check_button(u"hori"_ustr))
2473 , m_xAllPagesRB(m_xBuilder->weld_radio_button(u"allpages"_ustr))
2474 , m_xLeftPagesRB(m_xBuilder->weld_radio_button(u"leftpages"_ustr))
2475 , m_xRightPagesRB(m_xBuilder->weld_radio_button(u"rightpages"_ustr))
2476 , m_xConnectED(m_xBuilder->weld_entry(u"entry"_ustr))
2477 , m_xBrowseBT(m_xBuilder->weld_button(u"browse"_ustr))
2478 , m_xLinkFrame(m_xBuilder->weld_frame(u"linkframe"_ustr))
2479 // RotGrfFlyFrame: Need Angle and RotateControls now
2480 , m_xFlAngle(m_xBuilder->weld_frame(u"FL_ANGLE"_ustr))
2481 , m_xNfAngle(m_xBuilder->weld_metric_spin_button(u"NF_ANGLE"_ustr, FieldUnit::DEGREE))
2482 , m_xCtlAngle(new svx::DialControl)
2483 , m_xCtlAngleWin(new weld::CustomWeld(*m_xBuilder, u"CTL_ANGLE"_ustr, *m_xCtlAngle))
2484 , m_xBmpWin(new weld::CustomWeld(*m_xBuilder, u"preview"_ustr, m_aBmpWin))
2485 // tdf#138843 place holder for the graphic type
2486 , m_xLabelGraphicType(m_xBuilder->weld_label(u"label-graphic-type"_ustr))
2488 m_aBmpWin.SetBitmapEx(BitmapEx(RID_BMP_PREVIEW_FALLBACK));
2490 m_xCtlAngle->SetLinkedField(m_xNfAngle.get(), 2);
2492 SetExchangeSupport();
2493 m_xMirrorHorzBox->connect_toggled(LINK(this, SwGrfExtPage, MirrorHdl));
2494 m_xMirrorVertBox->connect_toggled(LINK(this, SwGrfExtPage, MirrorHdl));
2495 m_xBrowseBT->connect_clicked(LINK(this, SwGrfExtPage, BrowseHdl));
2498 SwGrfExtPage::~SwGrfExtPage()
2500 m_xBmpWin.reset();
2501 m_xCtlAngleWin.reset();
2502 m_xCtlAngle.reset();
2503 m_xGrfDlg.reset();
2506 std::unique_ptr<SfxTabPage> SwGrfExtPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
2508 return std::make_unique<SwGrfExtPage>(pPage, pController, *rSet);
2511 void SwGrfExtPage::Reset(const SfxItemSet *rSet)
2513 const sal_uInt16 nHtmlMode = ::GetHtmlMode(static_cast<const SwDocShell*>(SfxObjectShell::Current()));
2514 m_bHtmlMode = (nHtmlMode & HTMLMODE_ON) != 0;
2516 const SfxBoolItem* pConnectItem = rSet->GetItemIfSet( FN_PARAM_GRF_CONNECT );
2517 if( pConnectItem && pConnectItem->GetValue() )
2519 m_xBrowseBT->set_sensitive(true);
2520 m_xConnectED->set_editable(true);
2523 // RotGrfFlyFrame: Get RotationAngle and set at control
2524 if(const SdrAngleItem* pAngleItem = rSet->GetItemIfSet( SID_ATTR_TRANSFORM_ANGLE, false))
2526 m_xCtlAngle->SetRotation(pAngleItem->GetValue());
2528 else
2530 m_xCtlAngle->SetRotation(0_deg100);
2532 m_xCtlAngle->SaveValue();
2534 ActivatePage(*rSet);
2537 void SwGrfExtPage::ActivatePage(const SfxItemSet& rSet)
2539 const SvxProtectItem& rProt = rSet.Get(RES_PROTECT);
2540 bool bProtContent = rProt.IsContentProtected();
2542 const SfxPoolItem* pItem = nullptr;
2543 bool bEnable = false;
2544 bool bEnableMirrorRB = false;
2546 SfxItemState eState = rSet.GetItemState(RES_GRFATR_MIRRORGRF, true, &pItem);
2547 if (SfxItemState::UNKNOWN != eState && !bProtContent && !m_bHtmlMode)
2549 if( SfxItemState::SET != eState )
2550 pItem = &rSet.Get( RES_GRFATR_MIRRORGRF );
2552 bEnable = true;
2554 MirrorGraph eMirror = static_cast<const SwMirrorGrf* >(pItem)->GetValue();
2555 switch( eMirror )
2557 case MirrorGraph::Dont: break;
2558 case MirrorGraph::Vertical: m_xMirrorHorzBox->set_active(true); break;
2559 case MirrorGraph::Horizontal: m_xMirrorVertBox->set_active(true); break;
2560 case MirrorGraph::Both: m_xMirrorHorzBox->set_active(true);
2561 m_xMirrorVertBox->set_active(true);
2562 break;
2563 default:
2567 const int nPos = (static_cast<const SwMirrorGrf* >(pItem)->IsGrfToggle() ? 1 : 0)
2568 + ((eMirror == MirrorGraph::Vertical || eMirror == MirrorGraph::Both) ? 2 : 0);
2570 bEnableMirrorRB = nPos != 0;
2572 switch (nPos)
2574 case 1: // mirror at left / even pages
2575 m_xLeftPagesRB->set_active(true);
2576 m_xMirrorHorzBox->set_active(true);
2577 break;
2578 case 2: // mirror on all pages
2579 m_xAllPagesRB->set_active(true);
2580 break;
2581 case 3: // mirror on right / odd pages
2582 m_xRightPagesRB->set_active(true);
2583 break;
2584 default:
2585 m_xAllPagesRB->set_active(true);
2586 break;
2590 if( const SvxBrushItem* pGraphicBrushItem = rSet.GetItemIfSet( SID_ATTR_GRAF_GRAPHIC, false ) )
2592 if( !pGraphicBrushItem->GetGraphicLink().isEmpty() )
2594 m_aGrfName = m_aNewGrfName = pGraphicBrushItem->GetGraphicLink();
2595 m_xConnectED->set_text(m_aNewGrfName);
2597 OUString referer;
2598 SfxStringItem const * it = rSet.GetItem(SID_REFERER);
2599 if (it != nullptr) {
2600 referer = it->GetValue();
2602 const Graphic* pGrf = pGraphicBrushItem->GetGraphic(referer);
2603 if( pGrf )
2605 m_aBmpWin.SetGraphic( *pGrf );
2606 m_xLabelGraphicType->set_label(GraphicHelper::GetImageType(*pGrf));
2610 m_xConnectED->save_value();
2612 m_xMirror->set_sensitive(bEnable);
2613 m_xAllPagesRB->set_sensitive(bEnableMirrorRB);
2614 m_xLeftPagesRB->set_sensitive(bEnableMirrorRB);
2615 m_xRightPagesRB->set_sensitive(bEnableMirrorRB);
2617 m_xAllPagesRB->save_state();
2618 m_xLeftPagesRB->save_state();
2619 m_xRightPagesRB->save_state();
2620 m_xMirrorHorzBox->save_state();
2621 m_xMirrorVertBox->save_state();
2623 m_aBmpWin.MirrorHorz( m_xMirrorVertBox->get_active() );
2624 m_aBmpWin.MirrorVert( m_xMirrorHorzBox->get_active() );
2625 m_aBmpWin.Invalidate();
2628 bool SwGrfExtPage::FillItemSet( SfxItemSet *rSet )
2630 bool bModified = false;
2631 if ( m_xMirrorHorzBox->get_state_changed_from_saved() ||
2632 m_xMirrorVertBox->get_state_changed_from_saved() ||
2633 m_xAllPagesRB->get_state_changed_from_saved() ||
2634 m_xLeftPagesRB->get_state_changed_from_saved() ||
2635 m_xRightPagesRB->get_state_changed_from_saved() )
2637 bModified = true;
2639 bool bHori = false;
2641 if (m_xMirrorHorzBox->get_active() &&
2642 !m_xLeftPagesRB->get_active())
2643 bHori = true;
2645 MirrorGraph eMirror;
2646 eMirror = m_xMirrorVertBox->get_active() && bHori ?
2647 MirrorGraph::Both : bHori ?
2648 MirrorGraph::Vertical : m_xMirrorVertBox->get_active() ?
2649 MirrorGraph::Horizontal : MirrorGraph::Dont;
2651 bool bMirror = !m_xAllPagesRB->get_active();
2652 SwMirrorGrf aMirror( eMirror );
2653 aMirror.SetGrfToggle(bMirror );
2654 rSet->Put( aMirror );
2657 if (m_aGrfName != m_aNewGrfName || m_xConnectED->get_value_changed_from_saved())
2659 bModified = true;
2660 m_aGrfName = m_xConnectED->get_text();
2661 rSet->Put( SvxBrushItem( m_aGrfName, m_aFilterName, GPOS_LT,
2662 SID_ATTR_GRAF_GRAPHIC ));
2665 // RotGrfFlyFrame: Safe rotation if modified
2666 if(m_xCtlAngle->IsValueModified())
2668 rSet->Put(SdrAngleItem(SID_ATTR_TRANSFORM_ANGLE, m_xCtlAngle->GetRotation()));
2669 bModified = true;
2672 return bModified;
2675 DeactivateRC SwGrfExtPage::DeactivatePage(SfxItemSet *_pSet)
2677 if( _pSet )
2678 FillItemSet( _pSet );
2679 return DeactivateRC::LeavePage;
2682 IMPL_LINK_NOARG(SwGrfExtPage, BrowseHdl, weld::Button&, void)
2684 if(!m_xGrfDlg)
2686 m_xGrfDlg.reset(new FileDialogHelper(
2687 ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
2688 FileDialogFlags::Graphic, GetFrameWeld()));
2689 m_xGrfDlg->SetTitle(m_xLinkFrame->get_label());
2691 m_xGrfDlg->SetDisplayDirectory(m_xConnectED->get_text());
2692 uno::Reference < ui::dialogs::XFilePicker3 > xFP = m_xGrfDlg->GetFilePicker();
2693 uno::Reference < ui::dialogs::XFilePickerControlAccess > xCtrlAcc(xFP, uno::UNO_QUERY);
2694 xCtrlAcc->setValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, uno::Any(true) );
2696 if ( m_xGrfDlg->Execute() != ERRCODE_NONE )
2697 return;
2699 // remember selected filter
2700 m_aFilterName = m_xGrfDlg->GetCurrentFilter();
2701 m_aNewGrfName = INetURLObject::decode( m_xGrfDlg->GetPath(),
2702 INetURLObject::DecodeMechanism::Unambiguous );
2703 m_xConnectED->set_text(m_aNewGrfName);
2704 //reset mirrors because maybe a Bitmap was swapped with
2705 //another type of graphic that cannot be mirrored.
2706 m_xMirrorVertBox->set_active(false);
2707 m_xMirrorHorzBox->set_active(false);
2708 m_xAllPagesRB->set_sensitive(false);
2709 m_xLeftPagesRB->set_sensitive(false);
2710 m_xRightPagesRB->set_sensitive(false);
2711 m_aBmpWin.MirrorHorz(false);
2712 m_aBmpWin.MirrorVert(false);
2714 Graphic aGraphic;
2715 (void)GraphicFilter::LoadGraphic(m_xGrfDlg->GetPath(), OUString(), aGraphic);
2716 m_aBmpWin.SetGraphic(aGraphic);
2717 m_xLabelGraphicType->set_label(GraphicHelper::GetImageType(aGraphic));
2719 bool bEnable = GraphicType::Bitmap == aGraphic.GetType() ||
2720 GraphicType::GdiMetafile == aGraphic.GetType();
2721 m_xMirrorVertBox->set_sensitive(bEnable);
2722 m_xMirrorHorzBox->set_sensitive(bEnable);
2723 m_xAllPagesRB->set_sensitive(bEnable);
2724 m_xLeftPagesRB->set_sensitive(bEnable);
2725 m_xRightPagesRB->set_sensitive(bEnable);
2729 IMPL_LINK_NOARG(SwGrfExtPage, MirrorHdl, weld::Toggleable&, void)
2731 bool bEnable = m_xMirrorHorzBox->get_active();
2733 m_aBmpWin.MirrorHorz( m_xMirrorVertBox->get_active() );
2734 m_aBmpWin.MirrorVert( bEnable );
2736 m_xAllPagesRB->set_sensitive(bEnable);
2737 m_xLeftPagesRB->set_sensitive(bEnable);
2738 m_xRightPagesRB->set_sensitive(bEnable);
2740 if (!m_xAllPagesRB->get_active() && !m_xLeftPagesRB->get_active() && !m_xRightPagesRB->get_active())
2741 m_xAllPagesRB->set_active(true);
2744 // example window
2745 BmpWindow::BmpWindow()
2746 : m_bHorz(false)
2747 , m_bVert(false)
2748 , m_bGraphic(false)
2752 void BmpWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
2754 CustomWidgetController::SetDrawingArea(pDrawingArea);
2755 Size aSize = pDrawingArea->get_ref_device().LogicToPixel(Size(127 , 66), MapMode(MapUnit::MapAppFont));
2756 set_size_request(aSize.Width(), aSize.Height());
2757 SetOutputSizePixel(aSize);
2760 void BmpWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
2762 // Setup
2763 rRenderContext.SetBackground(Wallpaper(Application::GetSettings().GetStyleSettings().GetDialogColor()));
2764 rRenderContext.Erase();
2765 // #i119307# the graphic might have transparency, set up white as the color
2766 // to use when drawing a rectangle under the image
2767 rRenderContext.SetLineColor(COL_WHITE);
2768 rRenderContext.SetFillColor(COL_WHITE);
2770 // Paint
2771 Point aPntPos;
2772 Size aPntSz(GetOutputSizePixel());
2773 Size aGrfSize;
2774 if (m_bGraphic)
2775 aGrfSize = ::GetGraphicSizeTwip(m_aGraphic, &rRenderContext);
2776 //it should show the default bitmap also if no graphic can be found
2777 if (!aGrfSize.Width() && !aGrfSize.Height())
2778 aGrfSize = rRenderContext.PixelToLogic(m_aBmp.GetSizePixel());
2780 tools::Long nRelGrf = aGrfSize.Width() * 100 / aGrfSize.Height();
2781 tools::Long nRelWin = aPntSz.Width() * 100 / aPntSz.Height();
2782 if (nRelGrf < nRelWin)
2784 const tools::Long nWidth = aPntSz.Width();
2785 // if we use a replacement preview, try to draw at original size
2786 if (!m_bGraphic && (aGrfSize.Width() <= aPntSz.Width())
2787 && (aGrfSize.Height() <= aPntSz.Height()))
2789 const tools::Long nHeight = aPntSz.Height();
2790 aPntSz.setWidth( aGrfSize.Width() );
2791 aPntSz.setHeight( aGrfSize.Height() );
2792 aPntPos.AdjustY((nHeight - aPntSz.Height()) / 2 );
2794 else
2795 aPntSz.setWidth( aPntSz.Height() * nRelGrf /100 );
2797 aPntPos.AdjustX(nWidth - aPntSz.Width() ) ;
2800 // #i119307# clear window background, the graphic might have transparency
2801 rRenderContext.DrawRect(tools::Rectangle(aPntPos, aPntSz));
2803 if (m_bHorz || m_bVert)
2805 BitmapEx aTmpBmp(m_bGraphic ? m_aGraphic.GetBitmapEx() : m_aBmp);
2806 BmpMirrorFlags nMirrorFlags(BmpMirrorFlags::NONE);
2807 if (m_bHorz)
2808 nMirrorFlags |= BmpMirrorFlags::Vertical;
2809 if (m_bVert)
2810 nMirrorFlags |= BmpMirrorFlags::Horizontal;
2811 aTmpBmp.Mirror(nMirrorFlags);
2812 rRenderContext.DrawBitmapEx(aPntPos, aPntSz, aTmpBmp);
2814 else if (m_bGraphic) //draw unmirrored preview graphic
2816 m_aGraphic.Draw(rRenderContext, aPntPos, aPntSz);
2818 else //draw unmirrored stock sample image
2820 rRenderContext.DrawBitmapEx(aPntPos, aPntSz, m_aBmp);
2824 BmpWindow::~BmpWindow()
2828 void BmpWindow::SetGraphic(const Graphic& rGraphic)
2830 m_aGraphic = rGraphic;
2831 Size aSize = m_aGraphic.GetPrefSize();
2832 m_bGraphic = aSize.Width() && aSize.Height();
2833 Invalidate();
2836 void BmpWindow::SetBitmapEx(const BitmapEx& rBmp)
2838 m_aBmp = rBmp;
2839 Invalidate();
2842 // set URL and ImageMap at frames
2843 SwFrameURLPage::SwFrameURLPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet)
2844 : SfxTabPage(pPage, pController, u"modules/swriter/ui/frmurlpage.ui"_ustr, u"FrameURLPage"_ustr, &rSet)
2845 , m_xURLED(m_xBuilder->weld_entry(u"url"_ustr))
2846 , m_xSearchPB(m_xBuilder->weld_button(u"search"_ustr))
2847 , m_xNameED(m_xBuilder->weld_entry(u"name"_ustr))
2848 , m_xFrameCB(m_xBuilder->weld_combo_box(u"frame"_ustr))
2849 , m_xServerCB(m_xBuilder->weld_check_button(u"server"_ustr))
2850 , m_xClientCB(m_xBuilder->weld_check_button(u"client"_ustr))
2852 m_xSearchPB->connect_clicked(LINK(this, SwFrameURLPage, InsertFileHdl));
2855 SwFrameURLPage::~SwFrameURLPage()
2859 void SwFrameURLPage::Reset( const SfxItemSet *rSet )
2861 if ( SfxItemState::SET == rSet->GetItemState( SID_DOCFRAME ))
2863 TargetList aList;
2864 SfxFrame::GetDefaultTargetList(aList);
2865 size_t nCount = aList.size();
2866 for (size_t i = 0; i < nCount; ++i)
2868 m_xFrameCB->append_text(aList.at(i));
2872 if ( const SwFormatURL* pFormatURL = rSet->GetItemIfSet( RES_URL ) )
2874 m_xURLED->set_text(INetURLObject::decode(pFormatURL->GetURL(),
2875 INetURLObject::DecodeMechanism::Unambiguous));
2876 m_xNameED->set_text(pFormatURL->GetName());
2878 m_xClientCB->set_sensitive(pFormatURL->GetMap() != nullptr);
2879 m_xClientCB->set_active(pFormatURL->GetMap() != nullptr);
2880 m_xServerCB->set_active(pFormatURL->IsServerMap());
2882 m_xFrameCB->set_entry_text(pFormatURL->GetTargetFrameName());
2883 m_xFrameCB->save_value();
2885 else
2886 m_xClientCB->set_sensitive(false);
2888 m_xServerCB->save_state();
2889 m_xClientCB->save_state();
2892 bool SwFrameURLPage::FillItemSet(SfxItemSet *rSet)
2894 bool bModified = false;
2895 const SwFormatURL* pOldURL = GetOldItem(*rSet, RES_URL);
2896 std::unique_ptr<SwFormatURL> pFormatURL;
2897 if(pOldURL)
2898 pFormatURL.reset(pOldURL->Clone());
2899 else
2900 pFormatURL.reset(new SwFormatURL());
2903 const OUString sText = m_xURLED->get_text();
2905 if( pFormatURL->GetURL() != sText ||
2906 pFormatURL->GetName() != m_xNameED->get_text() ||
2907 m_xServerCB->get_active() != pFormatURL->IsServerMap() )
2909 pFormatURL->SetURL(sText, m_xServerCB->get_active());
2910 pFormatURL->SetName(m_xNameED->get_text());
2911 bModified = true;
2915 if (!m_xClientCB->get_active() && pFormatURL->GetMap() != nullptr)
2917 pFormatURL->SetMap(nullptr);
2918 bModified = true;
2921 if(pFormatURL->GetTargetFrameName() != m_xFrameCB->get_active_text())
2923 pFormatURL->SetTargetFrameName(m_xFrameCB->get_active_text());
2924 bModified = true;
2926 rSet->Put(std::move(pFormatURL));
2927 return bModified;
2930 std::unique_ptr<SfxTabPage> SwFrameURLPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
2932 return std::make_unique<SwFrameURLPage>(pPage, pController, *rSet);
2935 IMPL_LINK_NOARG(SwFrameURLPage, InsertFileHdl, weld::Button&, void)
2937 FileDialogHelper aDlgHelper(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
2938 FileDialogFlags::NONE, GetFrameWeld());
2939 uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
2943 const OUString sTemp(m_xURLED->get_text());
2944 if(!sTemp.isEmpty())
2945 xFP->setDisplayDirectory(sTemp);
2947 catch( const uno::Exception& ) {}
2948 if( aDlgHelper.Execute() == ERRCODE_NONE )
2950 m_xURLED->set_text(xFP->getSelectedFiles().getConstArray()[0]);
2954 SwFrameAddPage::SwFrameAddPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet)
2955 : SfxTabPage(pPage, pController, u"modules/swriter/ui/frmaddpage.ui"_ustr, u"FrameAddPage"_ustr, &rSet)
2956 , m_pWrtSh(nullptr)
2957 , m_bHtmlMode(false)
2958 , m_bFormat(false)
2959 , m_bNew(false)
2960 , m_xNameFrame(m_xBuilder->weld_widget(u"nameframe"_ustr))
2961 , m_xNameFT(m_xBuilder->weld_label(u"name_label"_ustr))
2962 , m_xNameED(m_xBuilder->weld_entry(u"name"_ustr))
2963 , m_xAltNameFT(m_xBuilder->weld_label(u"altname_label"_ustr))
2964 , m_xAltNameED(m_xBuilder->weld_entry(u"altname"_ustr))
2965 , m_xDescriptionFT(m_xBuilder->weld_label(u"description_label"_ustr))
2966 , m_xDescriptionED(m_xBuilder->weld_text_view(u"description"_ustr))
2967 , m_xDecorativeCB(m_xBuilder->weld_check_button(u"decorative"_ustr))
2968 , m_xSequenceFrame(m_xBuilder->weld_widget(u"frmSequence"_ustr))
2969 , m_xPrevLB(m_xBuilder->weld_combo_box(u"prev"_ustr))
2970 , m_xNextLB(m_xBuilder->weld_combo_box(u"next"_ustr))
2971 , m_xContentAlignFrame(m_xBuilder->weld_widget(u"contentalign"_ustr))
2972 , m_xVertAlignLB(m_xBuilder->weld_combo_box(u"vertalign"_ustr))
2973 , m_xPropertiesFrame(m_xBuilder->weld_widget(u"properties"_ustr))
2974 , m_xEditInReadonlyCB(m_xBuilder->weld_check_button(u"editinreadonly"_ustr))
2975 , m_xPrintFrameCB(m_xBuilder->weld_check_button(u"printframe"_ustr))
2976 , m_xTextFlowFT(m_xBuilder->weld_label(u"textflow_label"_ustr))
2977 , m_xTextFlowLB(new svx::FrameDirectionListBox(m_xBuilder->weld_combo_box(u"textflow"_ustr)))
2979 m_xTextFlowLB->append(SvxFrameDirection::Horizontal_LR_TB, SvxResId(RID_SVXSTR_FRAMEDIR_LTR));
2980 m_xTextFlowLB->append(SvxFrameDirection::Horizontal_RL_TB, SvxResId(RID_SVXSTR_FRAMEDIR_RTL));
2981 m_xTextFlowLB->append(SvxFrameDirection::Vertical_RL_TB, SvxResId(RID_SVXSTR_PAGEDIR_RTL_VERT));
2982 m_xTextFlowLB->append(SvxFrameDirection::Vertical_LR_TB, SvxResId(RID_SVXSTR_PAGEDIR_LTR_VERT));
2983 m_xTextFlowLB->append(SvxFrameDirection::Vertical_LR_BT, SvxResId(RID_SVXSTR_PAGEDIR_LTR_BTT_VERT));
2984 m_xTextFlowLB->append(SvxFrameDirection::Environment, SvxResId(RID_SVXSTR_FRAMEDIR_SUPER));
2985 m_xDescriptionED->set_size_request(-1, m_xDescriptionED->get_preferred_size().Height());
2987 m_xDecorativeCB->connect_toggled(LINK(this, SwFrameAddPage, DecorativeHdl));
2990 SwFrameAddPage::~SwFrameAddPage()
2992 m_xTextFlowLB.reset();
2995 std::unique_ptr<SfxTabPage> SwFrameAddPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
2997 return std::make_unique<SwFrameAddPage>(pPage, pController, *rSet);
3000 void SwFrameAddPage::Reset(const SfxItemSet *rSet )
3002 sal_uInt16 nHtmlMode = ::GetHtmlMode(static_cast<const SwDocShell*>(SfxObjectShell::Current()));
3003 m_bHtmlMode = (nHtmlMode & HTMLMODE_ON) != 0;
3004 if (m_bHtmlMode)
3006 m_xEditInReadonlyCB->hide();
3007 m_xPrintFrameCB->hide();
3009 if (m_sDlgType == "PictureDialog" || m_sDlgType == "ObjectDialog")
3011 m_xSequenceFrame->hide();
3012 m_xEditInReadonlyCB->hide();
3013 if (m_bHtmlMode)
3015 m_xPropertiesFrame->hide();
3017 m_xContentAlignFrame->hide();
3020 if(const SfxStringItem* pNameItem = rSet->GetItemIfSet(FN_SET_FRM_ALT_NAME, false))
3022 m_xAltNameED->set_text(pNameItem->GetValue());
3023 m_xAltNameED->save_value();
3026 if(const SfxStringItem* pDescriptionItem = rSet->GetItemIfSet(FN_UNO_DESCRIPTION, false))
3028 m_xDescriptionED->set_text(pDescriptionItem->GetValue());
3029 m_xDescriptionED->save_value();
3032 if(!m_bFormat)
3034 // insert graphic - properties
3035 // bNew is not set, so recognise by selection
3036 OUString aTmpName1;
3037 if(const SfxStringItem* pNameItem = rSet->GetItemIfSet(FN_SET_FRM_NAME, false))
3039 aTmpName1 = pNameItem->GetValue();
3042 OSL_ENSURE(m_pWrtSh, "no Shell?");
3043 if( m_bNew || aTmpName1.isEmpty() )
3045 if (m_sDlgType == "PictureDialog")
3046 aTmpName1 = m_pWrtSh->GetUniqueGrfName();
3047 else if (m_sDlgType == "ObjectDialog")
3048 aTmpName1 = m_pWrtSh->GetUniqueOLEName();
3049 else
3050 aTmpName1 = m_pWrtSh->GetUniqueFrameName();
3052 m_pWrtSh->SetFlyName(aTmpName1);
3055 m_xNameED->set_text( aTmpName1 );
3056 m_xNameED->save_value();
3058 else
3060 m_xNameED->set_sensitive( false );
3061 m_xAltNameED->set_sensitive(false);
3062 m_xNameFT->set_sensitive( false );
3063 m_xAltNameFT->set_sensitive(false);
3065 if (m_sDlgType == "FrameDialog" && m_xAltNameFT->get_visible())
3067 m_xAltNameFT->hide();
3068 m_xAltNameED->hide();
3070 else
3072 m_xNameED->connect_changed(LINK(this, SwFrameAddPage, EditModifyHdl));
3075 if (!m_bNew)
3077 SwFrameFormat* pFormat = m_pWrtSh->GetFlyFrameFormat();
3079 if (pFormat)
3081 const SwFormatChain &rChain = pFormat->GetChain();
3082 const SwFlyFrameFormat* pFlyFormat;
3083 OUString sNextChain, sPrevChain;
3084 pFlyFormat = rChain.GetPrev();
3085 if (pFlyFormat != nullptr)
3087 sPrevChain = pFlyFormat->GetName();
3090 pFlyFormat = rChain.GetNext();
3091 if (pFlyFormat != nullptr)
3093 sNextChain = pFlyFormat->GetName();
3095 //determine chainable frames
3096 std::vector< OUString > aPrevPageFrames;
3097 std::vector< OUString > aThisPageFrames;
3098 std::vector< OUString > aNextPageFrames;
3099 std::vector< OUString > aRemainFrames;
3100 m_pWrtSh->GetConnectableFrameFormats(*pFormat, sNextChain, false,
3101 aPrevPageFrames, aThisPageFrames, aNextPageFrames, aRemainFrames );
3102 for (sal_Int32 nEntry = m_xPrevLB->get_count(); nEntry > 1; nEntry--)
3103 m_xPrevLB->remove(nEntry - 1);
3104 lcl_InsertVectors(*m_xPrevLB, aPrevPageFrames, aThisPageFrames, aNextPageFrames, aRemainFrames);
3105 if(!sPrevChain.isEmpty())
3107 if (m_xPrevLB->find_text(sPrevChain) == -1)
3108 m_xPrevLB->insert_text(1, sPrevChain);
3109 m_xPrevLB->set_active_text(sPrevChain);
3111 else
3112 m_xPrevLB->set_active(0);
3113 aPrevPageFrames.clear();
3114 aNextPageFrames.clear();
3115 aThisPageFrames.clear();
3116 aRemainFrames.clear();
3118 m_pWrtSh->GetConnectableFrameFormats(*pFormat, sPrevChain, true,
3119 aPrevPageFrames, aThisPageFrames, aNextPageFrames, aRemainFrames );
3120 for (sal_Int32 nEntry = m_xNextLB->get_count(); nEntry > 1; nEntry--)
3121 m_xNextLB->remove(nEntry - 1);
3122 lcl_InsertVectors(*m_xNextLB, aPrevPageFrames, aThisPageFrames, aNextPageFrames, aRemainFrames);
3123 if(!sNextChain.isEmpty())
3125 if (m_xNextLB->find_text(sNextChain) == -1)
3126 m_xNextLB->insert_text(1, sNextChain);
3127 m_xNextLB->set_active_text(sNextChain);
3129 else
3130 m_xNextLB->set_active(0);
3131 Link<weld::ComboBox&,void> aLink(LINK(this, SwFrameAddPage, ChainModifyHdl));
3132 m_xPrevLB->connect_changed(aLink);
3133 m_xNextLB->connect_changed(aLink);
3137 const SwFormatEditInReadonly& rEdit = rSet->Get(RES_EDIT_IN_READONLY);
3138 m_xEditInReadonlyCB->set_active(rEdit.GetValue());
3139 m_xEditInReadonlyCB->save_state();
3141 // print
3142 const SvxPrintItem& rPrt = rSet->Get(RES_PRINT);
3143 m_xPrintFrameCB->set_active(rPrt.GetValue());
3144 m_xPrintFrameCB->save_state();
3146 SfxBoolItem const& rDecorative = rSet->Get(RES_DECORATIVE);
3147 m_xDecorativeCB->set_active(rDecorative.GetValue());
3148 m_xDecorativeCB->save_state();
3150 // textflow
3151 if( (!m_bHtmlMode || (0 != (nHtmlMode&HTMLMODE_SOME_STYLES)))
3152 && m_sDlgType != "PictureDialog" && m_sDlgType != "ObjectDialog"
3153 && SfxItemState::UNKNOWN != rSet->GetItemState( RES_FRAMEDIR ) )
3155 m_xTextFlowFT->show();
3156 m_xTextFlowLB->show();
3158 //vertical text flow is not possible in HTML
3159 if(m_bHtmlMode)
3161 m_xTextFlowLB->remove_id(SvxFrameDirection::Vertical_RL_TB);
3163 SvxFrameDirection nVal = rSet->Get(RES_FRAMEDIR).GetValue();
3164 m_xTextFlowLB->set_active_id(nVal);
3165 m_xTextFlowLB->save_value();
3167 else
3169 m_xTextFlowFT->hide();
3170 m_xTextFlowLB->hide();
3173 // Content alignment
3174 if ( rSet->GetItemState(RES_TEXT_VERT_ADJUST) > SfxItemState::DEFAULT )
3176 SdrTextVertAdjust nAdjust = rSet->Get(RES_TEXT_VERT_ADJUST).GetValue();
3177 sal_Int32 nPos = 0;
3178 switch(nAdjust)
3180 case SDRTEXTVERTADJUST_TOP: nPos = 0; break;
3181 case SDRTEXTVERTADJUST_CENTER:
3182 case SDRTEXTVERTADJUST_BLOCK: nPos = 1; break;
3183 case SDRTEXTVERTADJUST_BOTTOM: nPos = 2; break;
3185 m_xVertAlignLB->set_active(nPos);
3187 m_xVertAlignLB->save_value();
3189 DecorativeHdl(*m_xDecorativeCB);
3192 bool SwFrameAddPage::FillItemSet(SfxItemSet *rSet)
3194 bool bRet = false;
3195 if (m_xNameED->get_value_changed_from_saved())
3196 bRet |= nullptr != rSet->Put(SfxStringItem(FN_SET_FRM_NAME, m_xNameED->get_text()));
3197 if (m_xAltNameED->get_value_changed_from_saved())
3198 bRet |= nullptr != rSet->Put(SfxStringItem(FN_SET_FRM_ALT_NAME, m_xAltNameED->get_text()));
3199 if (m_xDescriptionED->get_value_changed_from_saved())
3200 bRet |= nullptr != rSet->Put(SfxStringItem(FN_UNO_DESCRIPTION, m_xDescriptionED->get_text()));
3202 if ( m_xEditInReadonlyCB->get_state_changed_from_saved() )
3203 bRet |= nullptr != rSet->Put( SwFormatEditInReadonly( RES_EDIT_IN_READONLY, m_xEditInReadonlyCB->get_active()));
3205 if ( m_xPrintFrameCB->get_state_changed_from_saved() )
3206 bRet |= nullptr != rSet->Put( SvxPrintItem( RES_PRINT, m_xPrintFrameCB->get_active()));
3208 if (m_xDecorativeCB->get_state_changed_from_saved())
3210 bRet |= nullptr != rSet->Put(SfxBoolItem(RES_DECORATIVE, m_xDecorativeCB->get_active()));
3213 // textflow
3214 if (m_xTextFlowLB->get_visible() && m_xTextFlowLB->get_value_changed_from_saved())
3216 SvxFrameDirection eDirection = m_xTextFlowLB->get_active_id();
3217 bRet |= nullptr != rSet->Put( SvxFrameDirectionItem(eDirection, RES_FRAMEDIR ));
3219 if(m_pWrtSh)
3221 const SwFrameFormat* pFormat = m_pWrtSh->GetFlyFrameFormat();
3222 if (pFormat)
3224 OUString sCurrentPrevChain, sCurrentNextChain;
3225 if (m_xPrevLB->get_active())
3226 sCurrentPrevChain = m_xPrevLB->get_active_text();
3227 if (m_xNextLB->get_active())
3228 sCurrentNextChain = m_xNextLB->get_active_text();
3229 const SwFormatChain &rChain = pFormat->GetChain();
3230 const SwFlyFrameFormat* pFlyFormat;
3231 OUString sNextChain, sPrevChain;
3232 pFlyFormat = rChain.GetPrev();
3233 if (pFlyFormat != nullptr)
3234 sPrevChain = pFlyFormat->GetName();
3236 pFlyFormat = rChain.GetNext();
3237 if (pFlyFormat != nullptr)
3238 sNextChain = pFlyFormat->GetName();
3239 if(sPrevChain != sCurrentPrevChain)
3240 bRet |= nullptr != rSet->Put(SfxStringItem(FN_PARAM_CHAIN_PREVIOUS, sCurrentPrevChain));
3241 if(sNextChain != sCurrentNextChain)
3242 bRet |= nullptr != rSet->Put(SfxStringItem(FN_PARAM_CHAIN_NEXT, sCurrentNextChain));
3246 if (m_xVertAlignLB->get_value_changed_from_saved())
3248 SdrTextVertAdjust nAdjust;
3249 switch (m_xVertAlignLB->get_active())
3251 default:
3252 case 0 : nAdjust = SDRTEXTVERTADJUST_TOP; break;
3253 case 1 : nAdjust = SDRTEXTVERTADJUST_CENTER; break;
3254 case 2 : nAdjust = SDRTEXTVERTADJUST_BOTTOM; break;
3256 bRet |= nullptr != rSet->Put(SdrTextVertAdjustItem(nAdjust, RES_TEXT_VERT_ADJUST));
3259 return bRet;
3262 IMPL_LINK_NOARG(SwFrameAddPage, EditModifyHdl, weld::Entry&, void)
3264 bool bEnable = !m_xNameED->get_text().isEmpty();
3265 m_xAltNameED->set_sensitive(bEnable);
3266 m_xAltNameFT->set_sensitive(bEnable);
3269 IMPL_LINK_NOARG(SwFrameAddPage, DecorativeHdl, weld::Toggleable&, void)
3271 bool const bEnable(!m_xDecorativeCB->get_active());
3272 m_xAltNameED->set_sensitive(bEnable);
3273 m_xAltNameFT->set_sensitive(bEnable);
3274 m_xDescriptionED->set_sensitive(bEnable);
3275 m_xDescriptionFT->set_sensitive(bEnable);
3278 void SwFrameAddPage::SetFormatUsed(bool bFormatUsed)
3280 m_bFormat = bFormatUsed;
3281 if (m_bFormat)
3283 m_xNameFrame->hide();
3287 IMPL_LINK(SwFrameAddPage, ChainModifyHdl, weld::ComboBox&, rBox, void)
3289 OUString sCurrentPrevChain, sCurrentNextChain;
3290 if (m_xPrevLB->get_active())
3291 sCurrentPrevChain = m_xPrevLB->get_active_text();
3292 if (m_xNextLB->get_active())
3293 sCurrentNextChain = m_xNextLB->get_active_text();
3294 SwFrameFormat* pFormat = m_pWrtSh->GetFlyFrameFormat();
3295 if (!pFormat)
3296 return;
3298 bool bNextBox = m_xNextLB.get() == &rBox;
3299 weld::ComboBox& rChangeLB = bNextBox ? *m_xPrevLB : *m_xNextLB;
3300 for (sal_Int32 nEntry = rChangeLB.get_count(); nEntry > 1; nEntry--)
3301 rChangeLB.remove(nEntry - 1);
3302 //determine chainable frames
3303 std::vector< OUString > aPrevPageFrames;
3304 std::vector< OUString > aThisPageFrames;
3305 std::vector< OUString > aNextPageFrames;
3306 std::vector< OUString > aRemainFrames;
3307 m_pWrtSh->GetConnectableFrameFormats(*pFormat, bNextBox ? sCurrentNextChain : sCurrentPrevChain, !bNextBox,
3308 aPrevPageFrames, aThisPageFrames, aNextPageFrames, aRemainFrames );
3309 lcl_InsertVectors(rChangeLB,
3310 aPrevPageFrames, aThisPageFrames, aNextPageFrames, aRemainFrames);
3311 const OUString sToSelect = bNextBox ? sCurrentPrevChain : sCurrentNextChain;
3312 if (rChangeLB.find_text(sToSelect) != -1)
3313 rChangeLB.set_active_text(sToSelect);
3314 else
3315 rChangeLB.set_active(0);
3319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */