12ee96f1cSAndrew Rist /**************************************************************
2*5bc7d773Smseidel *
32ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
42ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file
52ee96f1cSAndrew Rist * distributed with this work for additional information
62ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
72ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the
82ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance
92ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at
10*5bc7d773Smseidel *
112ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*5bc7d773Smseidel *
132ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing,
142ee96f1cSAndrew Rist * software distributed under the License is distributed on an
152ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the
172ee96f1cSAndrew Rist * specific language governing permissions and limitations
182ee96f1cSAndrew Rist * under the License.
19*5bc7d773Smseidel *
202ee96f1cSAndrew Rist *************************************************************/
212ee96f1cSAndrew Rist
222ee96f1cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cui.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir #include <tools/shl.hxx>
29cdf0e10cSrcweir #include <tools/date.hxx>
30cdf0e10cSrcweir #include <tools/time.hxx>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir #include <vcl/msgbox.hxx>
33cdf0e10cSrcweir #include <svl/itempool.hxx>
34cdf0e10cSrcweir #include <svl/itemset.hxx>
35cdf0e10cSrcweir #include <unotools/useroptions.hxx>
36cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
37cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
38*5bc7d773Smseidel #include <svx/svxids.hrc> // SID_ATTR_...
39*5bc7d773Smseidel #include <svx/dialogs.hrc> // RID_SVXDLG_POSTIT
40cdf0e10cSrcweir
41cdf0e10cSrcweir #define _SVX_POSTDLG_CXX
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include <cuires.hrc>
44cdf0e10cSrcweir #include "postdlg.hrc"
45cdf0e10cSrcweir #include <svx/postattr.hxx>
46cdf0e10cSrcweir #include "postdlg.hxx"
47cdf0e10cSrcweir #include <dialmgr.hxx>
48cdf0e10cSrcweir
49cdf0e10cSrcweir #include "helpid.hrc"
50cdf0e10cSrcweir
51cdf0e10cSrcweir // static ----------------------------------------------------------------
52cdf0e10cSrcweir
53cdf0e10cSrcweir static sal_uInt16 pRanges[] =
54cdf0e10cSrcweir {
55cdf0e10cSrcweir SID_ATTR_POSTIT_AUTHOR,
56cdf0e10cSrcweir SID_ATTR_POSTIT_TEXT,
57cdf0e10cSrcweir 0
58cdf0e10cSrcweir };
59cdf0e10cSrcweir
60cdf0e10cSrcweir // class SvxPostItDialog -------------------------------------------------
61cdf0e10cSrcweir
SvxPostItDialog(Window * pParent,const SfxItemSet & rCoreSet,sal_Bool bPrevNext,sal_Bool bRedline)62cdf0e10cSrcweir SvxPostItDialog::SvxPostItDialog( Window* pParent,
63cdf0e10cSrcweir const SfxItemSet& rCoreSet,
64cdf0e10cSrcweir sal_Bool bPrevNext,
65cdf0e10cSrcweir sal_Bool bRedline ) :
66cdf0e10cSrcweir
67cdf0e10cSrcweir SfxModalDialog( pParent, CUI_RES( RID_SVXDLG_POSTIT ) ),
68cdf0e10cSrcweir
69*5bc7d773Smseidel aPostItFL ( this, CUI_RES( FL_POSTIT ) ),
70*5bc7d773Smseidel aLastEditLabelFT( this, CUI_RES( FT_LASTEDITLABEL ) ),
71cdf0e10cSrcweir aLastEditFT ( this, CUI_RES( FT_LASTEDIT ) ),
72cdf0e10cSrcweir aEditFT ( this, CUI_RES( FT_EDIT ) ),
73cdf0e10cSrcweir aEditED ( this, CUI_RES( ED_EDIT ) ),
74*5bc7d773Smseidel aAuthorFT ( this, CUI_RES( FT_AUTHOR) ),
75*5bc7d773Smseidel aAuthorBtn ( this, CUI_RES( BTN_AUTHOR ) ),
76*5bc7d773Smseidel aOKBtn ( this, CUI_RES( BTN_POST_OK ) ),
77cdf0e10cSrcweir aCancelBtn ( this, CUI_RES( BTN_POST_CANCEL ) ),
78*5bc7d773Smseidel aHelpBtn ( this, CUI_RES( BTN_POST_HELP ) ),
79*5bc7d773Smseidel aPrevBtn ( this, CUI_RES( BTN_PREV ) ),
80cdf0e10cSrcweir aNextBtn ( this, CUI_RES( BTN_NEXT ) ),
81cdf0e10cSrcweir
82cdf0e10cSrcweir rSet ( rCoreSet ),
83cdf0e10cSrcweir pOutSet ( 0 )
84cdf0e10cSrcweir
85cdf0e10cSrcweir {
86*5bc7d773Smseidel if (bRedline) // HelpIDs for Redlining
87cdf0e10cSrcweir {
88cdf0e10cSrcweir SetHelpId(HID_REDLINING_DLG);
89cdf0e10cSrcweir aEditED.SetHelpId(HID_REDLINING_EDIT);
90cdf0e10cSrcweir aPrevBtn.SetHelpId(HID_REDLINING_PREV);
91cdf0e10cSrcweir aNextBtn.SetHelpId(HID_REDLINING_NEXT);
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir aPrevBtn.SetClickHdl( LINK( this, SvxPostItDialog, PrevHdl ) );
95cdf0e10cSrcweir aNextBtn.SetClickHdl( LINK( this, SvxPostItDialog, NextHdl ) );
96cdf0e10cSrcweir aAuthorBtn.SetClickHdl( LINK( this, SvxPostItDialog, Stamp ) );
97cdf0e10cSrcweir aOKBtn.SetClickHdl( LINK( this, SvxPostItDialog, OKHdl ) );
98cdf0e10cSrcweir
99cdf0e10cSrcweir Font aFont( aEditED.GetFont() );
100cdf0e10cSrcweir aFont.SetWeight( WEIGHT_LIGHT );
101cdf0e10cSrcweir aEditED.SetFont( aFont );
102cdf0e10cSrcweir
103cdf0e10cSrcweir sal_Bool bNew = sal_True;
104cdf0e10cSrcweir sal_uInt16 nWhich = 0;
105cdf0e10cSrcweir
106cdf0e10cSrcweir if ( !bPrevNext )
107cdf0e10cSrcweir {
108*5bc7d773Smseidel aPrevBtn.Disable();
109*5bc7d773Smseidel aNextBtn.Disable();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
112cdf0e10cSrcweir nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR );
113cdf0e10cSrcweir String aAuthorStr, aDateStr, aTextStr;
114cdf0e10cSrcweir
115cdf0e10cSrcweir if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir bNew = sal_False;
118cdf0e10cSrcweir const SvxPostItAuthorItem& rAuthor =
119cdf0e10cSrcweir (const SvxPostItAuthorItem&)rSet.Get( nWhich );
120cdf0e10cSrcweir aAuthorStr = rAuthor.GetValue();
121cdf0e10cSrcweir }
122cdf0e10cSrcweir else
123cdf0e10cSrcweir aAuthorStr = SvtUserOptions().GetID();
124cdf0e10cSrcweir
125cdf0e10cSrcweir nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE );
126cdf0e10cSrcweir
127cdf0e10cSrcweir if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir const SvxPostItDateItem& rDate =
130cdf0e10cSrcweir (const SvxPostItDateItem&)rSet.Get( nWhich );
131cdf0e10cSrcweir aDateStr = rDate.GetValue();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir else
134cdf0e10cSrcweir {
135cdf0e10cSrcweir LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
136cdf0e10cSrcweir aDateStr = aLocaleWrapper.getDate( Date() );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT );
140cdf0e10cSrcweir
141cdf0e10cSrcweir if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir const SvxPostItTextItem& rText =
144cdf0e10cSrcweir (const SvxPostItTextItem&)rSet.Get( nWhich );
145cdf0e10cSrcweir aTextStr = rText.GetValue();
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir ShowLastAuthor(aAuthorStr, aDateStr);
149cdf0e10cSrcweir aEditED.SetText( aTextStr.ConvertLineEnd() );
150cdf0e10cSrcweir
151cdf0e10cSrcweir if ( !bNew )
152cdf0e10cSrcweir SetText( CUI_RESSTR( STR_NOTIZ_EDIT ) );
153cdf0e10cSrcweir else
154cdf0e10cSrcweir // neu anlegen
155cdf0e10cSrcweir SetText( CUI_RESSTR( STR_NOTIZ_INSERT ) );
156cdf0e10cSrcweir
157cdf0e10cSrcweir FreeResource();
158cdf0e10cSrcweir
159cdf0e10cSrcweir aEditED.SetAccessibleRelationLabeledBy(&aEditFT);
160cdf0e10cSrcweir aEditED.SetAccessibleRelationMemberOf(&aPostItFL);
161cdf0e10cSrcweir aAuthorBtn.SetAccessibleRelationMemberOf(&aPostItFL);
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir // -----------------------------------------------------------------------
165cdf0e10cSrcweir
~SvxPostItDialog()166cdf0e10cSrcweir SvxPostItDialog::~SvxPostItDialog()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir delete pOutSet;
169cdf0e10cSrcweir pOutSet = 0;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir // -----------------------------------------------------------------------
173cdf0e10cSrcweir
ShowLastAuthor(const String & rAuthor,const String & rDate)174cdf0e10cSrcweir void SvxPostItDialog::ShowLastAuthor(const String& rAuthor, const String& rDate)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir String sTxt( rAuthor );
177cdf0e10cSrcweir sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
178cdf0e10cSrcweir sTxt += rDate;
179cdf0e10cSrcweir aLastEditFT.SetText( sTxt );
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir // -----------------------------------------------------------------------
183cdf0e10cSrcweir
GetRanges()184cdf0e10cSrcweir sal_uInt16* SvxPostItDialog::GetRanges()
185cdf0e10cSrcweir {
186cdf0e10cSrcweir return pRanges;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
189cdf0e10cSrcweir // -----------------------------------------------------------------------
190cdf0e10cSrcweir
EnableTravel(sal_Bool bNext,sal_Bool bPrev)191cdf0e10cSrcweir void SvxPostItDialog::EnableTravel(sal_Bool bNext, sal_Bool bPrev)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir aPrevBtn.Enable(bPrev);
194cdf0e10cSrcweir aNextBtn.Enable(bNext);
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
197cdf0e10cSrcweir // -----------------------------------------------------------------------
198cdf0e10cSrcweir
IMPL_LINK_INLINE_START(SvxPostItDialog,PrevHdl,Button *,EMPTYARG)199cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvxPostItDialog, PrevHdl, Button *, EMPTYARG )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir aPrevHdlLink.Call( this );
202cdf0e10cSrcweir return 0;
203cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SvxPostItDialog,PrevHdl,Button *,EMPTYARG)204cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvxPostItDialog, PrevHdl, Button *, EMPTYARG )
205cdf0e10cSrcweir
206cdf0e10cSrcweir // -----------------------------------------------------------------------
207cdf0e10cSrcweir
208cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvxPostItDialog, NextHdl, Button *, EMPTYARG )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir aNextHdlLink.Call( this );
211cdf0e10cSrcweir return 0;
212cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SvxPostItDialog,NextHdl,Button *,EMPTYARG)213cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvxPostItDialog, NextHdl, Button *, EMPTYARG )
214cdf0e10cSrcweir
215cdf0e10cSrcweir // -----------------------------------------------------------------------
216cdf0e10cSrcweir
217cdf0e10cSrcweir IMPL_LINK( SvxPostItDialog, Stamp, Button *, EMPTYARG )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir Date aDate;
220cdf0e10cSrcweir Time aTime;
221cdf0e10cSrcweir String aTmp( SvtUserOptions().GetID() );
222cdf0e10cSrcweir LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
223cdf0e10cSrcweir String aStr( aEditED.GetText() );
224cdf0e10cSrcweir aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "\n---- " ) );
225cdf0e10cSrcweir
226cdf0e10cSrcweir if ( aTmp.Len() > 0 )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir aStr += aTmp;
229cdf0e10cSrcweir aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
230cdf0e10cSrcweir }
231cdf0e10cSrcweir aStr += aLocaleWrapper.getDate(aDate);
232cdf0e10cSrcweir aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
233cdf0e10cSrcweir aStr += aLocaleWrapper.getTime(aTime, sal_False, sal_False);
234cdf0e10cSrcweir aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ----\n" ) );
235cdf0e10cSrcweir
236cdf0e10cSrcweir
237cdf0e10cSrcweir aEditED.SetText( aStr.ConvertLineEnd() );
238cdf0e10cSrcweir xub_StrLen nLen = aStr.Len();
239cdf0e10cSrcweir aEditED.GrabFocus();
240cdf0e10cSrcweir aEditED.SetSelection( Selection( nLen, nLen ) );
241cdf0e10cSrcweir return 0;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir // -----------------------------------------------------------------------
245cdf0e10cSrcweir
IMPL_LINK(SvxPostItDialog,OKHdl,Button *,EMPTYARG)246cdf0e10cSrcweir IMPL_LINK( SvxPostItDialog, OKHdl, Button *, EMPTYARG )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
249cdf0e10cSrcweir pOutSet = new SfxItemSet( rSet );
250cdf0e10cSrcweir pOutSet->Put( SvxPostItAuthorItem( SvtUserOptions().GetID(),
251*5bc7d773Smseidel rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR ) ) );
252cdf0e10cSrcweir pOutSet->Put( SvxPostItDateItem( aLocaleWrapper.getDate( Date() ),
253cdf0e10cSrcweir rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE ) ) );
254cdf0e10cSrcweir pOutSet->Put( SvxPostItTextItem( aEditED.GetText(),
255cdf0e10cSrcweir rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT ) ) );
256cdf0e10cSrcweir EndDialog( RET_OK );
257cdf0e10cSrcweir return 0;
258cdf0e10cSrcweir }
259