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: postdlg.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_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
39 #include <tools/shl.hxx>
40 #include <tools/date.hxx>
41 #include <tools/time.hxx>
42 #include <vcl/svapp.hxx>
43 #ifndef _MSGBOX_HXX //autogen
44 #include <vcl/msgbox.hxx>
46 #include <svtools/itempool.hxx>
47 #include <svtools/itemset.hxx>
48 #include <svtools/useroptions.hxx>
49 #include <unotools/localedatawrapper.hxx>
50 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
51 #include <comphelper/processfactory.hxx>
54 #define _SVX_POSTDLG_CXX
56 #include <svx/dialogs.hrc>
57 #include "postdlg.hrc"
63 #include "postattr.hxx"
64 #include "postdlg.hxx"
65 #include <svx/dialmgr.hxx>
69 // static ----------------------------------------------------------------
71 static USHORT pRanges
[] =
73 SID_ATTR_POSTIT_AUTHOR
,
78 // class SvxPostItDialog -------------------------------------------------
80 SvxPostItDialog::SvxPostItDialog( Window
* pParent
,
81 const SfxItemSet
& rCoreSet
,
85 SfxModalDialog( pParent
, SVX_RES( RID_SVXDLG_POSTIT
) ),
87 aPostItFL ( this, SVX_RES( FL_POSTIT
) ),
88 aLastEditLabelFT( this, SVX_RES( FT_LASTEDITLABEL
) ),
89 aLastEditFT ( this, SVX_RES( FT_LASTEDIT
) ),
90 aEditFT ( this, SVX_RES( FT_EDIT
) ),
91 aEditED ( this, SVX_RES( ED_EDIT
) ),
92 aAuthorFT ( this, SVX_RES( FT_AUTHOR
) ),
93 aAuthorBtn ( this, SVX_RES( BTN_AUTHOR
) ),
94 aOKBtn ( this, SVX_RES( BTN_POST_OK
) ),
95 aCancelBtn ( this, SVX_RES( BTN_POST_CANCEL
) ),
96 aHelpBtn ( this, SVX_RES( BTN_POST_HELP
) ),
97 aPrevBtn ( this, SVX_RES( BTN_PREV
) ),
98 aNextBtn ( this, SVX_RES( BTN_NEXT
) ),
104 if (bRedline
) // HelpIDs fuer Redlining
106 SetHelpId(HID_REDLINING_DLG
);
107 aEditED
.SetHelpId(HID_REDLINING_EDIT
);
108 aPrevBtn
.SetHelpId(HID_REDLINING_PREV
);
109 aNextBtn
.SetHelpId(HID_REDLINING_NEXT
);
112 aPrevBtn
.SetClickHdl( LINK( this, SvxPostItDialog
, PrevHdl
) );
113 aNextBtn
.SetClickHdl( LINK( this, SvxPostItDialog
, NextHdl
) );
114 aAuthorBtn
.SetClickHdl( LINK( this, SvxPostItDialog
, Stamp
) );
115 aOKBtn
.SetClickHdl( LINK( this, SvxPostItDialog
, OKHdl
) );
117 Font
aFont( aEditED
.GetFont() );
118 aFont
.SetWeight( WEIGHT_LIGHT
);
119 aEditED
.SetFont( aFont
);
130 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR
);
131 String aAuthorStr
, aDateStr
, aTextStr
;
133 if ( rSet
.GetItemState( nWhich
, TRUE
) >= SFX_ITEM_AVAILABLE
)
136 const SvxPostItAuthorItem
& rAuthor
=
137 (const SvxPostItAuthorItem
&)rSet
.Get( nWhich
);
138 aAuthorStr
= rAuthor
.GetValue();
141 aAuthorStr
= SvtUserOptions().GetID();
143 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE
);
145 if ( rSet
.GetItemState( nWhich
, TRUE
) >= SFX_ITEM_AVAILABLE
)
147 const SvxPostItDateItem
& rDate
=
148 (const SvxPostItDateItem
&)rSet
.Get( nWhich
);
149 aDateStr
= rDate
.GetValue();
153 LocaleDataWrapper
aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
154 aDateStr
= aLocaleWrapper
.getDate( Date() );
157 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT
);
159 if ( rSet
.GetItemState( nWhich
, TRUE
) >= SFX_ITEM_AVAILABLE
)
161 const SvxPostItTextItem
& rText
=
162 (const SvxPostItTextItem
&)rSet
.Get( nWhich
);
163 aTextStr
= rText
.GetValue();
166 ShowLastAuthor(aAuthorStr
, aDateStr
);
167 aEditED
.SetText( aTextStr
.ConvertLineEnd() );
170 SetText( SVX_RESSTR( STR_NOTIZ_EDIT
) );
173 SetText( SVX_RESSTR( STR_NOTIZ_INSERT
) );
178 // -----------------------------------------------------------------------
180 SvxPostItDialog::~SvxPostItDialog()
186 // -----------------------------------------------------------------------
188 void SvxPostItDialog::ShowLastAuthor(const String
& rAuthor
, const String
& rDate
)
190 String
sTxt( rAuthor
);
191 sTxt
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
193 aLastEditFT
.SetText( sTxt
);
196 // -----------------------------------------------------------------------
198 USHORT
* SvxPostItDialog::GetRanges()
203 // -----------------------------------------------------------------------
205 void SvxPostItDialog::EnableTravel(BOOL bNext
, BOOL bPrev
)
207 aPrevBtn
.Enable(bPrev
);
208 aNextBtn
.Enable(bNext
);
211 // -----------------------------------------------------------------------
213 IMPL_LINK_INLINE_START( SvxPostItDialog
, PrevHdl
, Button
*, EMPTYARG
)
215 aPrevHdlLink
.Call( this );
218 IMPL_LINK_INLINE_END( SvxPostItDialog
, PrevHdl
, Button
*, EMPTYARG
)
220 // -----------------------------------------------------------------------
222 IMPL_LINK_INLINE_START( SvxPostItDialog
, NextHdl
, Button
*, EMPTYARG
)
224 aNextHdlLink
.Call( this );
227 IMPL_LINK_INLINE_END( SvxPostItDialog
, NextHdl
, Button
*, EMPTYARG
)
229 // -----------------------------------------------------------------------
231 IMPL_LINK( SvxPostItDialog
, Stamp
, Button
*, EMPTYARG
)
235 String
aTmp( SvtUserOptions().GetID() );
236 LocaleDataWrapper
aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
237 String
aStr( aEditED
.GetText() );
238 aStr
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "\n---- " ) );
240 if ( aTmp
.Len() > 0 )
243 aStr
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
245 aStr
+= aLocaleWrapper
.getDate(aDate
);
246 aStr
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
247 aStr
+= aLocaleWrapper
.getTime(aTime
, FALSE
, FALSE
);
248 aStr
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ----\n" ) );
251 aEditED
.SetText( aStr
.ConvertLineEnd() );
252 xub_StrLen nLen
= aStr
.Len();
254 aEditED
.SetSelection( Selection( nLen
, nLen
) );
258 // -----------------------------------------------------------------------
260 IMPL_LINK( SvxPostItDialog
, OKHdl
, Button
*, EMPTYARG
)
262 LocaleDataWrapper
aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
263 pOutSet
= new SfxItemSet( rSet
);
264 pOutSet
->Put( SvxPostItAuthorItem( SvtUserOptions().GetID(),
265 rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR
) ) );
266 pOutSet
->Put( SvxPostItDateItem( aLocaleWrapper
.getDate( Date() ),
267 rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE
) ) );
268 pOutSet
->Put( SvxPostItTextItem( aEditED
.GetText(),
269 rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT
) ) );