xref: /aoo41x/main/cui/source/dialogs/postdlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 // include ---------------------------------------------------------------
32 #include <tools/shl.hxx>
33 #include <tools/date.hxx>
34 #include <tools/time.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <svl/itempool.hxx>
38 #include <svl/itemset.hxx>
39 #include <unotools/useroptions.hxx>
40 #include <unotools/localedatawrapper.hxx>
41 #include <comphelper/processfactory.hxx>
42 #include <svx/svxids.hrc>	// SID_ATTR_...
43 #include <svx/dialogs.hrc>  // RID_SVXDLG_POSTIT
44 
45 #define _SVX_POSTDLG_CXX
46 
47 #include <cuires.hrc>
48 #include "postdlg.hrc"
49 #include <svx/postattr.hxx>
50 #include "postdlg.hxx"
51 #include <dialmgr.hxx>
52 
53 #include "helpid.hrc"
54 
55 // static ----------------------------------------------------------------
56 
57 static sal_uInt16 pRanges[] =
58 {
59 	SID_ATTR_POSTIT_AUTHOR,
60 	SID_ATTR_POSTIT_TEXT,
61 	0
62 };
63 
64 // class SvxPostItDialog -------------------------------------------------
65 
66 SvxPostItDialog::SvxPostItDialog( Window* pParent,
67 								  const SfxItemSet& rCoreSet,
68 								  sal_Bool bPrevNext,
69 								  sal_Bool bRedline ) :
70 
71 	SfxModalDialog( pParent, CUI_RES( RID_SVXDLG_POSTIT ) ),
72 
73     aPostItFL       ( this, CUI_RES( FL_POSTIT ) ),
74     aLastEditLabelFT( this, CUI_RES( FT_LASTEDITLABEL ) ),
75 	aLastEditFT 	( this, CUI_RES( FT_LASTEDIT ) ),
76 	aEditFT 		( this, CUI_RES( FT_EDIT ) ),
77 	aEditED 		( this, CUI_RES( ED_EDIT ) ),
78     aAuthorFT       ( this, CUI_RES( FT_AUTHOR) ),
79     aAuthorBtn      ( this, CUI_RES( BTN_AUTHOR ) ),
80     aOKBtn          ( this, CUI_RES( BTN_POST_OK ) ),
81 	aCancelBtn		( this, CUI_RES( BTN_POST_CANCEL ) ),
82     aHelpBtn        ( this, CUI_RES( BTN_POST_HELP ) ),
83     aPrevBtn        ( this, CUI_RES( BTN_PREV ) ),
84 	aNextBtn		( this, CUI_RES( BTN_NEXT ) ),
85 
86 	rSet		( rCoreSet ),
87 	pOutSet 	( 0 )
88 
89 {
90 	if (bRedline)	// HelpIDs fuer Redlining
91 	{
92 		SetHelpId(HID_REDLINING_DLG);
93 		aEditED.SetHelpId(HID_REDLINING_EDIT);
94 		aPrevBtn.SetHelpId(HID_REDLINING_PREV);
95 		aNextBtn.SetHelpId(HID_REDLINING_NEXT);
96 	}
97 
98 	aPrevBtn.SetClickHdl( LINK( this, SvxPostItDialog, PrevHdl ) );
99 	aNextBtn.SetClickHdl( LINK( this, SvxPostItDialog, NextHdl ) );
100 	aAuthorBtn.SetClickHdl( LINK( this, SvxPostItDialog, Stamp ) );
101 	aOKBtn.SetClickHdl( LINK( this, SvxPostItDialog, OKHdl ) );
102 
103 	Font aFont( aEditED.GetFont() );
104 	aFont.SetWeight( WEIGHT_LIGHT );
105 	aEditED.SetFont( aFont );
106 
107 	sal_Bool bNew = sal_True;
108 	sal_uInt16 nWhich			 = 0;
109 
110 	if ( !bPrevNext )
111 	{
112 		aPrevBtn.Hide();
113 		aNextBtn.Hide();
114 	}
115 
116 	nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR );
117 	String aAuthorStr, aDateStr, aTextStr;
118 
119 	if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
120 	{
121 		bNew = sal_False;
122 		const SvxPostItAuthorItem& rAuthor =
123 			(const SvxPostItAuthorItem&)rSet.Get( nWhich );
124 		aAuthorStr = rAuthor.GetValue();
125 	}
126 	else
127 		aAuthorStr = SvtUserOptions().GetID();
128 
129 	nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE );
130 
131 	if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
132 	{
133 		const SvxPostItDateItem& rDate =
134 			(const SvxPostItDateItem&)rSet.Get( nWhich );
135 		aDateStr = rDate.GetValue();
136 	}
137 	else
138 	{
139 		LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
140 		aDateStr = aLocaleWrapper.getDate( Date() );
141 	}
142 
143 	nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT );
144 
145 	if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
146 	{
147 		const SvxPostItTextItem& rText =
148 			(const SvxPostItTextItem&)rSet.Get( nWhich );
149 		aTextStr = rText.GetValue();
150 	}
151 
152 	ShowLastAuthor(aAuthorStr, aDateStr);
153 	aEditED.SetText( aTextStr.ConvertLineEnd() );
154 
155 	if ( !bNew )
156 		SetText( CUI_RESSTR( STR_NOTIZ_EDIT ) );
157 	else
158 		// neu anlegen
159 		SetText( CUI_RESSTR( STR_NOTIZ_INSERT ) );
160 
161 	FreeResource();
162 
163 	aEditED.SetAccessibleRelationLabeledBy(&aEditFT);
164 	aEditED.SetAccessibleRelationMemberOf(&aPostItFL);
165 	aAuthorBtn.SetAccessibleRelationMemberOf(&aPostItFL);
166 }
167 
168 // -----------------------------------------------------------------------
169 
170 SvxPostItDialog::~SvxPostItDialog()
171 {
172 	delete pOutSet;
173 	pOutSet = 0;
174 }
175 
176 // -----------------------------------------------------------------------
177 
178 void SvxPostItDialog::ShowLastAuthor(const String& rAuthor, const String& rDate)
179 {
180 	String sTxt( rAuthor );
181 	sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
182 	sTxt += rDate;
183 	aLastEditFT.SetText( sTxt );
184 }
185 
186 // -----------------------------------------------------------------------
187 
188 sal_uInt16* SvxPostItDialog::GetRanges()
189 {
190 	return pRanges;
191 }
192 
193 // -----------------------------------------------------------------------
194 
195 void SvxPostItDialog::EnableTravel(sal_Bool bNext, sal_Bool bPrev)
196 {
197 	aPrevBtn.Enable(bPrev);
198 	aNextBtn.Enable(bNext);
199 }
200 
201 // -----------------------------------------------------------------------
202 
203 IMPL_LINK_INLINE_START( SvxPostItDialog, PrevHdl, Button *, EMPTYARG )
204 {
205 	aPrevHdlLink.Call( this );
206 	return 0;
207 }
208 IMPL_LINK_INLINE_END( SvxPostItDialog, PrevHdl, Button *, EMPTYARG )
209 
210 // -----------------------------------------------------------------------
211 
212 IMPL_LINK_INLINE_START( SvxPostItDialog, NextHdl, Button *, EMPTYARG )
213 {
214 	aNextHdlLink.Call( this );
215 	return 0;
216 }
217 IMPL_LINK_INLINE_END( SvxPostItDialog, NextHdl, Button *, EMPTYARG )
218 
219 // -----------------------------------------------------------------------
220 
221 IMPL_LINK( SvxPostItDialog, Stamp, Button *, EMPTYARG )
222 {
223 	Date aDate;
224 	Time aTime;
225 	String aTmp( SvtUserOptions().GetID() );
226 	LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
227 	String aStr( aEditED.GetText() );
228 	aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "\n---- " ) );
229 
230 	if ( aTmp.Len() > 0 )
231 	{
232 		aStr += aTmp;
233 		aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
234 	}
235 	aStr += aLocaleWrapper.getDate(aDate);
236 	aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
237 	aStr += aLocaleWrapper.getTime(aTime, sal_False, sal_False);
238 	aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ----\n" ) );
239 
240 
241 	aEditED.SetText( aStr.ConvertLineEnd() );
242 	xub_StrLen nLen = aStr.Len();
243 	aEditED.GrabFocus();
244 	aEditED.SetSelection( Selection( nLen, nLen ) );
245 	return 0;
246 }
247 
248 // -----------------------------------------------------------------------
249 
250 IMPL_LINK( SvxPostItDialog, OKHdl, Button *, EMPTYARG )
251 {
252 	LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
253 	pOutSet = new SfxItemSet( rSet );
254 	pOutSet->Put( SvxPostItAuthorItem( SvtUserOptions().GetID(),
255 				  					   rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR ) ) );
256 	pOutSet->Put( SvxPostItDateItem( aLocaleWrapper.getDate( Date() ),
257 									 rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE ) ) );
258 	pOutSet->Put( SvxPostItTextItem( aEditED.GetText(),
259 									 rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT ) ) );
260 	EndDialog( RET_OK );
261 	return 0;
262 }
263 
264