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