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