xref: /AOO41X/main/sw/source/ui/chrdlg/break.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 #include <sfx2/request.hxx>
33 #include <svl/stritem.hxx>
34 #ifndef _MSGBOX_HXX //autogen
35 #include <vcl/msgbox.hxx>
36 #endif
37 
38 #ifndef _CMDID_H
39 #include <cmdid.h>
40 #endif
41 #include <uitool.hxx>
42 #include <swtypes.hxx>
43 #include <wrtsh.hxx>
44 #ifndef _BASESH_HXX
45 #include <basesh.hxx>
46 #endif
47 #ifndef _VIEW_HXX
48 #include <view.hxx>
49 #endif
50 #include <viewopt.hxx>
51 #include <break.hxx>
52 #include <pagedesc.hxx>
53 #include <poolfmt.hxx>
54 
55 #ifndef _BREAK_HRC
56 #include <break.hrc>
57 #endif
58 #ifndef _CHRDLG_HRC
59 #include <chrdlg.hrc>
60 #endif
61 #include <SwStyleNameMapper.hxx>
62 
Apply()63 void SwBreakDlg::Apply()
64 {
65     nKind = 0;
66     if(aLineBtn.IsChecked())
67         nKind = 1;
68     else if(aColumnBtn.IsChecked())
69         nKind = 2;
70     else if(aPageBtn.IsChecked())
71     {
72         nKind = 3;
73         const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos();
74         if(0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos)
75         {
76             aTemplate = aPageCollBox.GetSelectEntry();
77             nPgNum = aPageNumBox.IsChecked() ? (sal_uInt16)aPageNumEdit.GetValue() : 0;
78         }
79     }
80 }
81 
82 
IMPL_LINK_INLINE_START(SwBreakDlg,ClickHdl,void *,EMPTYARG)83 IMPL_LINK_INLINE_START( SwBreakDlg, ClickHdl, void *, EMPTYARG )
84 {
85     CheckEnable();
86     return 0;
87 }
IMPL_LINK_INLINE_END(SwBreakDlg,ClickHdl,void *,EMPTYARG)88 IMPL_LINK_INLINE_END( SwBreakDlg, ClickHdl, void *, EMPTYARG )
89 
90 /*------------------------------------------------------------------------
91  Beschreibung:  Handler fuer Aendern Seitenummer
92 ------------------------------------------------------------------------*/
93 
94 IMPL_LINK_INLINE_START( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
95 {
96     if(pBox->IsChecked()) aPageNumEdit.SetValue(1);
97     else aPageNumEdit.SetText(aEmptyStr);
98     return 0;
99 }
IMPL_LINK_INLINE_END(SwBreakDlg,PageNumHdl,CheckBox *,pBox)100 IMPL_LINK_INLINE_END( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
101 
102 /*------------------------------------------------------------------------
103  Beschreibung:  Durch Aendern der Seitennummer wird die Checkbox gecheckt.
104 ------------------------------------------------------------------------*/
105 
106 IMPL_LINK_INLINE_START( SwBreakDlg, PageNumModifyHdl, Edit *, EMPTYARG )
107 {
108     aPageNumBox.Check();
109     return 0;
110 }
IMPL_LINK_INLINE_END(SwBreakDlg,PageNumModifyHdl,Edit *,EMPTYARG)111 IMPL_LINK_INLINE_END( SwBreakDlg, PageNumModifyHdl, Edit *, EMPTYARG )
112 
113 /*------------------------------------------------------------------------
114  Beschreibung:  Ok-Handler;
115                 prueft, ob die Seitenummer nPage eine legale Seitennummer
116                 ist (linke Seiten mit geraden Nummern etc. bei einer Seitenvorlage
117                 mit wechselnden Seiten)
118 ------------------------------------------------------------------------*/
119 
120 IMPL_LINK( SwBreakDlg, OkHdl, Button *, EMPTYARG )
121 {
122     if(aPageNumBox.IsChecked()) {
123             // wenn unterschiedliche Seitenvorlagen, testen auf Gueltigkeit
124         const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos();
125             // auf Position 0 steht 'Ohne'.
126         const SwPageDesc *pPageDesc;
127         if ( 0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos )
128             pPageDesc = rSh.FindPageDescByName( aPageCollBox.GetSelectEntry(),
129                                                 sal_True );
130         else
131             pPageDesc = &rSh.GetPageDesc(rSh.GetCurPageDesc());
132 
133         ASSERT(pPageDesc, Seitenvorlage nicht gefunden.);
134         const sal_uInt16 nUserPage = sal_uInt16(aPageNumEdit.GetValue());
135         sal_Bool bOk = sal_True;
136         switch(pPageDesc->GetUseOn())
137         {
138             case nsUseOnPage::PD_MIRROR:
139             case nsUseOnPage::PD_ALL: break;
140             case nsUseOnPage::PD_LEFT: bOk = 0 == nUserPage % 2; break;
141             case nsUseOnPage::PD_RIGHT: bOk = static_cast< sal_Bool >(nUserPage % 2); break;
142             default:; //prevent warning
143         }
144         if(!bOk) {
145             InfoBox(this, SW_RES(MSG_ILLEGAL_PAGENUM)).Execute();
146             aPageNumEdit.GrabFocus();
147             return 0;
148         }
149     }
150     EndDialog(RET_OK);
151     return 0;
152 }
153 
SwBreakDlg(Window * pParent,SwWrtShell & rS)154 SwBreakDlg::SwBreakDlg( Window *pParent, SwWrtShell &rS ) :
155 
156     SvxStandardDialog( pParent,SW_RES(DLG_BREAK) ),
157 
158     rSh(rS),
159     aBreakFL(this,SW_RES(FL_BREAK)),
160     aLineBtn(this,SW_RES(RB_LINE)),
161     aColumnBtn(this,SW_RES(RB_COL)),
162     aPageBtn(this,SW_RES(RB_PAGE)),
163     aPageCollText(this, SW_RES(FT_COLL)),
164     aPageCollBox(this, SW_RES(LB_COLL)),
165     aPageNumBox(this, SW_RES(CB_PAGENUM)),
166     aPageNumEdit(this, SW_RES(ED_PAGENUM)),
167 
168     aOkBtn(this,SW_RES(BT_OK)),
169     aCancelBtn(this,SW_RES(BT_CANCEL)),
170     aHelpBtn(this,SW_RES(BT_HELP)),
171 
172     nKind(0),
173     nPgNum(0),
174 
175     bHtmlMode(0 != ::GetHtmlMode(rS.GetView().GetDocShell()))
176 {
177     aPageNumEdit.SetAccessibleRelationLabeledBy(&aPageNumBox);
178     aPageNumEdit.SetAccessibleName(aPageNumBox.GetText());
179 
180     Link aLk = LINK(this,SwBreakDlg,ClickHdl);
181     aPageBtn.SetClickHdl( aLk );
182     aLineBtn.SetClickHdl( aLk );
183     aColumnBtn.SetClickHdl( aLk );
184     aPageCollBox.SetSelectHdl( aLk );
185 
186     aOkBtn.SetClickHdl(LINK(this,SwBreakDlg,OkHdl));
187     aPageNumBox.SetClickHdl(LINK(this,SwBreakDlg,PageNumHdl));
188     aPageNumEdit.SetModifyHdl(LINK(this,SwBreakDlg,PageNumModifyHdl));
189 
190 
191     // Einfuegen der vorhandenen Seitenvorlagen in die Listbox
192     const sal_uInt16 nCount = rSh.GetPageDescCnt();
193     sal_uInt16 i;
194 
195     for( i = 0; i < nCount; ++i)
196     {
197         const SwPageDesc &rPageDesc = rSh.GetPageDesc(i);
198         ::InsertStringSorted(rPageDesc.GetName(), aPageCollBox, 1 );
199     }
200 
201     String aFmtName;
202     for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
203         if(LISTBOX_ENTRY_NOTFOUND == aPageCollBox.GetEntryPos( aFmtName =
204                                     SwStyleNameMapper::GetUIName( i, aFmtName )))
205             ::InsertStringSorted(aFmtName, aPageCollBox, 1 );
206     //add landscape page
207     if(LISTBOX_ENTRY_NOTFOUND == aPageCollBox.GetEntryPos( aFmtName =
208                                     SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, aFmtName )))
209             ::InsertStringSorted(aFmtName, aPageCollBox, 1 );
210     CheckEnable();
211     aPageNumEdit.SetText( aEmptyStr );
212     FreeResource();
213 }
214 
215 
CheckEnable()216 void SwBreakDlg::CheckEnable()
217 {
218     sal_Bool bEnable = sal_True;
219     if ( bHtmlMode )
220     {
221         aColumnBtn  .Enable(sal_False);
222         aPageCollBox.Enable(sal_False);
223         bEnable = sal_False;
224     }
225     else if(rSh.GetFrmType(0,sal_True)
226         & (FRMTYPE_FLY_ANY | FRMTYPE_HEADER | FRMTYPE_FOOTER  | FRMTYPE_FOOTNOTE))
227     {
228         aPageBtn.Enable(sal_False);
229         if(aPageBtn.IsChecked())
230             aLineBtn.Check(sal_True);
231         bEnable = sal_False;
232     }
233     const sal_Bool bPage = aPageBtn.IsChecked();
234     aPageCollText.Enable( bPage );
235     aPageCollBox.Enable ( bPage );
236 
237     bEnable &= bPage;
238     if ( bEnable )
239     {
240         // auf Position 0 steht 'Ohne' Seitenvorlage.
241         const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos();
242         if ( 0 == nPos || LISTBOX_ENTRY_NOTFOUND == nPos )
243             bEnable = sal_False;
244     }
245     aPageNumBox .Enable(bEnable);
246     aPageNumEdit.Enable(bEnable);
247 }
248 
~SwBreakDlg()249 SwBreakDlg::~SwBreakDlg()
250 {
251 }
252