Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <tools/shl.hxx>
21 : #include <tools/date.hxx>
22 : #include <tools/time.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/msgbox.hxx>
25 : #include <svl/itempool.hxx>
26 : #include <svl/itemset.hxx>
27 : #include <unotools/useroptions.hxx>
28 : #include <unotools/localedatawrapper.hxx>
29 : #include <comphelper/processfactory.hxx>
30 : #include <svx/svxids.hrc> // SID_ATTR_...
31 : #include <svx/dialogs.hrc> // RID_SVXDLG_POSTIT
32 :
33 : #define _SVX_POSTDLG_CXX
34 :
35 : #include <cuires.hrc>
36 : #include "postdlg.hrc"
37 : #include <svx/postattr.hxx>
38 : #include "postdlg.hxx"
39 : #include <dialmgr.hxx>
40 :
41 : #include "helpid.hrc"
42 :
43 : // static ----------------------------------------------------------------
44 :
45 : static sal_uInt16 pRanges[] =
46 : {
47 : SID_ATTR_POSTIT_AUTHOR,
48 : SID_ATTR_POSTIT_TEXT,
49 : 0
50 : };
51 :
52 : // class SvxPostItDialog -------------------------------------------------
53 :
54 0 : SvxPostItDialog::SvxPostItDialog( Window* pParent,
55 : const SfxItemSet& rCoreSet,
56 : sal_Bool bPrevNext,
57 : sal_Bool bRedline ) :
58 :
59 0 : SfxModalDialog( pParent, CUI_RES( RID_SVXDLG_POSTIT ) ),
60 :
61 0 : aPostItFL ( this, CUI_RES( FL_POSTIT ) ),
62 0 : aLastEditLabelFT( this, CUI_RES( FT_LASTEDITLABEL ) ),
63 0 : aLastEditFT ( this, CUI_RES( FT_LASTEDIT ) ),
64 0 : aEditFT ( this, CUI_RES( FT_EDIT ) ),
65 0 : aEditED ( this, CUI_RES( ED_EDIT ) ),
66 0 : aAuthorFT ( this, CUI_RES( FT_AUTHOR) ),
67 0 : aAuthorBtn ( this, CUI_RES( BTN_AUTHOR ) ),
68 0 : aOKBtn ( this, CUI_RES( BTN_POST_OK ) ),
69 0 : aCancelBtn ( this, CUI_RES( BTN_POST_CANCEL ) ),
70 0 : aHelpBtn ( this, CUI_RES( BTN_POST_HELP ) ),
71 0 : aPrevBtn ( this, CUI_RES( BTN_PREV ) ),
72 0 : aNextBtn ( this, CUI_RES( BTN_NEXT ) ),
73 :
74 : rSet ( rCoreSet ),
75 0 : pOutSet ( 0 )
76 :
77 : {
78 0 : if (bRedline) // HelpIDs for redlining
79 : {
80 0 : SetHelpId(HID_REDLINING_DLG);
81 0 : aEditED.SetHelpId(HID_REDLINING_EDIT);
82 0 : aPrevBtn.SetHelpId(HID_REDLINING_PREV);
83 0 : aNextBtn.SetHelpId(HID_REDLINING_NEXT);
84 : }
85 :
86 0 : aPrevBtn.SetClickHdl( LINK( this, SvxPostItDialog, PrevHdl ) );
87 0 : aNextBtn.SetClickHdl( LINK( this, SvxPostItDialog, NextHdl ) );
88 0 : aAuthorBtn.SetClickHdl( LINK( this, SvxPostItDialog, Stamp ) );
89 0 : aOKBtn.SetClickHdl( LINK( this, SvxPostItDialog, OKHdl ) );
90 :
91 0 : Font aFont( aEditED.GetFont() );
92 0 : aFont.SetWeight( WEIGHT_LIGHT );
93 0 : aEditED.SetFont( aFont );
94 :
95 0 : sal_Bool bNew = sal_True;
96 0 : sal_uInt16 nWhich = 0;
97 :
98 0 : if ( !bPrevNext )
99 : {
100 0 : aPrevBtn.Hide();
101 0 : aNextBtn.Hide();
102 : }
103 :
104 0 : nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR );
105 0 : String aAuthorStr, aDateStr;
106 :
107 0 : if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
108 : {
109 0 : bNew = sal_False;
110 : const SvxPostItAuthorItem& rAuthor =
111 0 : (const SvxPostItAuthorItem&)rSet.Get( nWhich );
112 0 : aAuthorStr = rAuthor.GetValue();
113 : }
114 : else
115 0 : aAuthorStr = SvtUserOptions().GetID();
116 :
117 0 : nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE );
118 :
119 0 : if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
120 : {
121 : const SvxPostItDateItem& rDate =
122 0 : (const SvxPostItDateItem&)rSet.Get( nWhich );
123 0 : aDateStr = rDate.GetValue();
124 : }
125 : else
126 : {
127 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
128 0 : aDateStr = rLocaleWrapper.getDate( Date( Date::SYSTEM ) );
129 : }
130 :
131 0 : nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT );
132 :
133 0 : rtl::OUString aTextStr;
134 0 : if ( rSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
135 : {
136 : const SvxPostItTextItem& rText =
137 0 : (const SvxPostItTextItem&)rSet.Get( nWhich );
138 0 : aTextStr = rText.GetValue();
139 : }
140 :
141 0 : ShowLastAuthor(aAuthorStr, aDateStr);
142 0 : aEditED.SetText(convertLineEnd(aTextStr, GetSystemLineEnd()));
143 :
144 0 : if ( !bNew )
145 0 : SetText( CUI_RESSTR( STR_NOTIZ_EDIT ) );
146 : else
147 : // create newly
148 0 : SetText( CUI_RESSTR( STR_NOTIZ_INSERT ) );
149 :
150 0 : FreeResource();
151 :
152 0 : aEditED.SetAccessibleRelationLabeledBy(&aEditFT);
153 0 : aEditED.SetAccessibleRelationMemberOf(&aPostItFL);
154 0 : aAuthorBtn.SetAccessibleRelationMemberOf(&aPostItFL);
155 0 : }
156 :
157 : // -----------------------------------------------------------------------
158 :
159 0 : SvxPostItDialog::~SvxPostItDialog()
160 : {
161 0 : delete pOutSet;
162 0 : pOutSet = 0;
163 0 : }
164 :
165 : // -----------------------------------------------------------------------
166 :
167 0 : void SvxPostItDialog::ShowLastAuthor(const String& rAuthor, const String& rDate)
168 : {
169 0 : String sTxt( rAuthor );
170 0 : sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
171 0 : sTxt += rDate;
172 0 : aLastEditFT.SetText( sTxt );
173 0 : }
174 :
175 : // -----------------------------------------------------------------------
176 :
177 0 : sal_uInt16* SvxPostItDialog::GetRanges()
178 : {
179 0 : return pRanges;
180 : }
181 :
182 : // -----------------------------------------------------------------------
183 :
184 0 : void SvxPostItDialog::EnableTravel(sal_Bool bNext, sal_Bool bPrev)
185 : {
186 0 : aPrevBtn.Enable(bPrev);
187 0 : aNextBtn.Enable(bNext);
188 0 : }
189 :
190 : // -----------------------------------------------------------------------
191 :
192 0 : IMPL_LINK_NOARG_INLINE_START(SvxPostItDialog, PrevHdl)
193 : {
194 0 : aPrevHdlLink.Call( this );
195 0 : return 0;
196 : }
197 0 : IMPL_LINK_NOARG_INLINE_END(SvxPostItDialog, PrevHdl)
198 :
199 : // -----------------------------------------------------------------------
200 :
201 0 : IMPL_LINK_NOARG_INLINE_START(SvxPostItDialog, NextHdl)
202 : {
203 0 : aNextHdlLink.Call( this );
204 0 : return 0;
205 : }
206 0 : IMPL_LINK_NOARG_INLINE_END(SvxPostItDialog, NextHdl)
207 :
208 : // -----------------------------------------------------------------------
209 :
210 0 : IMPL_LINK_NOARG(SvxPostItDialog, Stamp)
211 : {
212 0 : Date aDate( Date::SYSTEM );
213 0 : Time aTime( Time::SYSTEM );
214 0 : String aTmp( SvtUserOptions().GetID() );
215 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
216 0 : String aStr( aEditED.GetText() );
217 0 : aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "\n---- " ) );
218 :
219 0 : if ( aTmp.Len() > 0 )
220 : {
221 0 : aStr += aTmp;
222 0 : aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
223 : }
224 0 : aStr += rLocaleWrapper.getDate(aDate);
225 0 : aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
226 0 : aStr += rLocaleWrapper.getTime(aTime, sal_False, sal_False);
227 0 : aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ----\n" ) );
228 :
229 0 : aStr = convertLineEnd(aStr, GetSystemLineEnd());
230 :
231 0 : aEditED.SetText(aStr);
232 0 : xub_StrLen nLen = aStr.Len();
233 0 : aEditED.GrabFocus();
234 0 : aEditED.SetSelection( Selection( nLen, nLen ) );
235 0 : return 0;
236 : }
237 :
238 : // -----------------------------------------------------------------------
239 :
240 0 : IMPL_LINK_NOARG(SvxPostItDialog, OKHdl)
241 : {
242 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
243 0 : pOutSet = new SfxItemSet( rSet );
244 : pOutSet->Put( SvxPostItAuthorItem( SvtUserOptions().GetID(),
245 0 : rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR ) ) );
246 : pOutSet->Put( SvxPostItDateItem( rLocaleWrapper.getDate( Date( Date::SYSTEM ) ),
247 0 : rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE ) ) );
248 : pOutSet->Put( SvxPostItTextItem( aEditED.GetText(),
249 0 : rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT ) ) );
250 0 : EndDialog( RET_OK );
251 0 : return 0;
252 : }
253 :
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|