1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scuiautofmt.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #include "scitems.hxx"
41 #include <svx/algitem.hxx>
42 #include <svx/boxitem.hxx>
43 #include <svx/brshitem.hxx>
44 #include <svx/cntritem.hxx>
45 #include <svx/colritem.hxx>
46 #include <svx/crsditem.hxx>
47 #include <svx/fontitem.hxx>
48 #include <svx/postitem.hxx>
49 #include <svx/shdditem.hxx>
50 #include <svx/udlnitem.hxx>
51 #include <svx/wghtitem.hxx>
52 #include <svtools/zforlist.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <comphelper/processfactory.hxx>
59 #include "zforauto.hxx"
60 #include "scitems.hxx"
62 #include "globstr.hrc"
63 #include "autoform.hxx"
64 #include "strindlg.hxx"
65 #include "miscdlgs.hrc"
66 #include "scuiautofmt.hxx"
67 #include "scresid.hxx"
68 #include "document.hxx"
70 //========================================================================
73 ScAutoFormatDlg::ScAutoFormatDlg( Window
* pParent
,
74 ScAutoFormat
* pAutoFormat
,
75 const ScAutoFormatData
* pSelFormatData
,
78 ModalDialog ( pParent
, ScResId( RID_SCDLG_AUTOFORMAT
) ),
80 aFlFormat ( this, ScResId( FL_FORMAT
) ),
81 aLbFormat ( this, ScResId( LB_FORMAT
) ),
82 pWndPreview ( new ScAutoFmtPreview( this, ScResId( WND_PREVIEW
), pDoc
) ),
83 aBtnOk ( this, ScResId( BTN_OK
) ),
84 aBtnCancel ( this, ScResId( BTN_CANCEL
) ),
85 aBtnHelp ( this, ScResId( BTN_HELP
) ),
86 aBtnAdd ( this, ScResId( BTN_ADD
) ),
87 aBtnRemove ( this, ScResId( BTN_REMOVE
) ),
88 aBtnMore ( this, ScResId( BTN_MORE
) ),
89 aFlFormatting ( this, ScResId( FL_FORMATTING
) ),
90 aBtnNumFormat ( this, ScResId( BTN_NUMFORMAT
) ),
91 aBtnBorder ( this, ScResId( BTN_BORDER
) ),
92 aBtnFont ( this, ScResId( BTN_FONT
) ),
93 aBtnPattern ( this, ScResId( BTN_PATTERN
) ),
94 aBtnAlignment ( this, ScResId( BTN_ALIGNMENT
) ),
95 aBtnAdjust ( this, ScResId( BTN_ADJUST
) ),
96 aBtnRename ( this, ScResId( BTN_RENAME
) ),
97 aStrTitle ( ScResId( STR_ADD_TITLE
) ),
98 aStrLabel ( ScResId( STR_ADD_LABEL
) ),
99 aStrClose ( ScResId( STR_BTN_CLOSE
) ),
100 aStrDelTitle ( ScResId( STR_DEL_TITLE
) ),
101 aStrDelMsg ( ScResId( STR_DEL_MSG
) ) ,
102 aStrRename ( ScResId( STR_RENAME_TITLE
) ),
104 pFormat ( pAutoFormat
),
105 pSelFmtData ( pSelFormatData
),
107 bCoreDataChanged( FALSE
),
108 bFmtInserted ( FALSE
)
111 pWndPreview
->NotifyChange( (*pFormat
)[0] );
115 //------------------------------------------------------------------------
117 __EXPORT
ScAutoFormatDlg::~ScAutoFormatDlg()
122 //------------------------------------------------------------------------
124 void ScAutoFormatDlg::Init()
129 aLbFormat
.SetSelectHdl( LINK( this, ScAutoFormatDlg
, SelFmtHdl
) );
130 aBtnNumFormat
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, CheckHdl
) );
131 aBtnBorder
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, CheckHdl
) );
132 aBtnFont
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, CheckHdl
) );
133 aBtnPattern
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, CheckHdl
) );
134 aBtnAlignment
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, CheckHdl
) );
135 aBtnAdjust
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, CheckHdl
) );
136 aBtnAdd
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, AddHdl
) );
137 aBtnRemove
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, RemoveHdl
) );
138 aBtnOk
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, CloseHdl
) );
139 aBtnCancel
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, CloseHdl
) );
140 aBtnRename
.SetClickHdl ( LINK( this, ScAutoFormatDlg
, RenameHdl
) );
141 aLbFormat
.SetDoubleClickHdl( LINK( this, ScAutoFormatDlg
, DblClkHdl
) );
143 aBtnMore
.AddWindow( &aBtnRename
);
144 aBtnMore
.AddWindow( &aBtnNumFormat
);
145 aBtnMore
.AddWindow( &aBtnBorder
);
146 aBtnMore
.AddWindow( &aBtnFont
);
147 aBtnMore
.AddWindow( &aBtnPattern
);
148 aBtnMore
.AddWindow( &aBtnAlignment
);
149 aBtnMore
.AddWindow( &aBtnAdjust
);
150 aBtnMore
.AddWindow( &aFlFormatting
);
152 nCount
= pFormat
->GetCount();
154 for ( USHORT i
= 0; i
< nCount
; i
++ )
156 ((*pFormat
)[i
])->GetName( aEntry
);
157 aLbFormat
.InsertEntry( aEntry
);
161 aBtnRemove
.Disable();
163 aLbFormat
.SelectEntryPos( 0 );
164 aBtnRename
.Disable();
165 aBtnRemove
.Disable();
173 aBtnRemove
.Disable();
178 //------------------------------------------------------------------------
180 void ScAutoFormatDlg::UpdateChecks()
182 ScAutoFormatData
* pData
= (*pFormat
)[nIndex
];
184 aBtnNumFormat
.Check( pData
->GetIncludeValueFormat() );
185 aBtnBorder
.Check( pData
->GetIncludeFrame() );
186 aBtnFont
.Check( pData
->GetIncludeFont() );
187 aBtnPattern
.Check( pData
->GetIncludeBackground() );
188 aBtnAlignment
.Check( pData
->GetIncludeJustify() );
189 aBtnAdjust
.Check( pData
->GetIncludeWidthHeight() );
192 //------------------------------------------------------------------------
196 IMPL_LINK( ScAutoFormatDlg
, CloseHdl
, PushButton
*, pBtn
)
198 if ( pBtn
== &aBtnOk
|| pBtn
== &aBtnCancel
)
200 if ( bCoreDataChanged
)
201 ScGlobal::GetAutoFormat()->Save();
203 EndDialog( (pBtn
== &aBtnOk
) ? RET_OK
: RET_CANCEL
);
208 //------------------------------------------------------------------------
210 IMPL_LINK_INLINE_START( ScAutoFormatDlg
, DblClkHdl
, void *, EMPTYARG
)
212 if ( bCoreDataChanged
)
213 ScGlobal::GetAutoFormat()->Save();
218 IMPL_LINK_INLINE_END( ScAutoFormatDlg
, DblClkHdl
, void *, EMPTYARG
)
220 //------------------------------------------------------------------------
222 IMPL_LINK( ScAutoFormatDlg
, CheckHdl
, Button
*, pBtn
)
224 ScAutoFormatData
* pData
= (*pFormat
)[nIndex
];
225 BOOL bCheck
= ((CheckBox
*)pBtn
)->IsChecked();
227 if ( pBtn
== &aBtnNumFormat
)
228 pData
->SetIncludeValueFormat( bCheck
);
229 else if ( pBtn
== &aBtnBorder
)
230 pData
->SetIncludeFrame( bCheck
);
231 else if ( pBtn
== &aBtnFont
)
232 pData
->SetIncludeFont( bCheck
);
233 else if ( pBtn
== &aBtnPattern
)
234 pData
->SetIncludeBackground( bCheck
);
235 else if ( pBtn
== &aBtnAlignment
)
236 pData
->SetIncludeJustify( bCheck
);
237 else if ( pBtn
== &aBtnAdjust
)
238 pData
->SetIncludeWidthHeight( bCheck
);
240 if ( !bCoreDataChanged
)
242 aBtnCancel
.SetText( aStrClose
);
243 bCoreDataChanged
= TRUE
;
246 pWndPreview
->NotifyChange( pData
);
251 //------------------------------------------------------------------------
253 IMPL_LINK( ScAutoFormatDlg
, AddHdl
, void *, EMPTYARG
)
255 if ( !bFmtInserted
&& pSelFmtData
)
257 String
aStrStandard( ScResId(STR_STANDARD
) );
259 ScStringInputDlg
* pDlg
;
264 pDlg
= new ScStringInputDlg( this,
268 HID_SC_ADD_AUTOFMT
);
270 if ( pDlg
->Execute() == RET_OK
)
272 pDlg
->GetInputString( aFormatName
);
274 if ( (aFormatName
.Len() > 0) && (aFormatName
!= aStrStandard
) )
276 ScAutoFormatData
* pNewData
277 = new ScAutoFormatData( *pSelFmtData
);
279 pNewData
->SetName( aFormatName
);
280 bFmtInserted
= pFormat
->Insert( pNewData
);
284 USHORT nAt
= pFormat
->IndexOf( pNewData
);
286 aLbFormat
.InsertEntry( aFormatName
, nAt
);
287 aLbFormat
.SelectEntry( aFormatName
);
290 if ( !bCoreDataChanged
)
292 aBtnCancel
.SetText( aStrClose
);
293 bCoreDataChanged
= TRUE
;
306 USHORT nRet
= ErrorBox( this,
307 WinBits( WB_OK_CANCEL
| WB_DEF_OK
),
308 ScGlobal::GetRscString(STR_INVALID_AFNAME
)
311 bOk
= ( nRet
== RET_CANCEL
);
324 //------------------------------------------------------------------------
326 IMPL_LINK( ScAutoFormatDlg
, RemoveHdl
, void *, EMPTYARG
)
328 if ( (nIndex
> 0) && (aLbFormat
.GetEntryCount() > 0) )
330 String
aMsg( aStrDelMsg
.GetToken( 0, '#' ) );
332 aMsg
+= aLbFormat
.GetSelectEntry();
333 aMsg
+= aStrDelMsg
.GetToken( 1, '#' );
336 QueryBox( this, WinBits( WB_YES_NO
| WB_DEF_YES
), aMsg
).Execute() )
338 aLbFormat
.RemoveEntry( nIndex
);
339 aLbFormat
.SelectEntryPos( nIndex
-1 );
342 aBtnRemove
.Disable();
344 if ( !bCoreDataChanged
)
346 aBtnCancel
.SetText( aStrClose
);
347 bCoreDataChanged
= TRUE
;
350 pFormat
->AtFree( nIndex
); // in der Core loeschen
362 IMPL_LINK( ScAutoFormatDlg
, RenameHdl
, void *, EMPTYARG
)
368 String aFormatName
=aLbFormat
.GetSelectEntry();
371 ScStringInputDlg
* pDlg
= new ScStringInputDlg( this,
375 HID_SC_RENAME_AUTOFMT
);
376 if( pDlg
->Execute() == RET_OK
)
378 BOOL bFmtRenamed
= FALSE
;
379 pDlg
->GetInputString( aFormatName
);
382 if ( aFormatName
.Len() > 0 )
384 for( n
= 0; n
< pFormat
->GetCount(); ++n
)
386 (*pFormat
)[n
]->GetName(aEntry
);
387 if ( aEntry
== aFormatName
)
390 if( n
>= pFormat
->GetCount() )
392 // Format mit dem Namen noch nicht vorhanden, also
395 aLbFormat
.RemoveEntry(nIndex
);
396 ScAutoFormatData
* p
=(*pFormat
)[ nIndex
];
397 ScAutoFormatData
* pNewData
398 = new ScAutoFormatData(*p
);
400 pFormat
->AtFree( nIndex
);
402 pNewData
->SetName( aFormatName
);
404 pFormat
->Insert( pNewData
);
406 USHORT nCount
= pFormat
->GetCount();
408 aLbFormat
.SetUpdateMode(FALSE
);
410 for ( USHORT i
= 0; i
< nCount
; i
++ )
412 ((*pFormat
)[i
])->GetName( aEntry
);
413 aLbFormat
.InsertEntry( aEntry
);
416 aLbFormat
.SetUpdateMode( TRUE
);
417 aLbFormat
.SelectEntry( aFormatName
);
419 if ( !bCoreDataChanged
)
421 aBtnCancel
.SetText( aStrClose
);
422 bCoreDataChanged
= TRUE
;
433 bOk
= RET_CANCEL
== ErrorBox( this,
434 WinBits( WB_OK_CANCEL
| WB_DEF_OK
),
435 ScGlobal::GetRscString(STR_INVALID_AFNAME
)
447 //------------------------------------------------------------------------
449 IMPL_LINK( ScAutoFormatDlg
, SelFmtHdl
, void *, EMPTYARG
)
451 nIndex
= aLbFormat
.GetSelectEntryPos();
456 aBtnRename
.Disable();
457 aBtnRemove
.Disable();
465 pWndPreview
->NotifyChange( (*pFormat
)[nIndex
] );
470 //------------------------------------------------------------------------
472 String __EXPORT
ScAutoFormatDlg::GetCurrFormatName()
476 ((*pFormat
)[nIndex
])->GetName( aResult
);