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/date.hxx>
21 : #include <tools/time.hxx>
22 : #include <vcl/svapp.hxx>
23 : #include <vcl/msgbox.hxx>
24 : #include <vcl/settings.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>
31 :
32 : #include <cuires.hrc>
33 : #include <svx/postattr.hxx>
34 : #include "postdlg.hxx"
35 : #include <dialmgr.hxx>
36 :
37 : #include "helpid.hrc"
38 :
39 : // class SvxPostItDialog -------------------------------------------------
40 :
41 0 : SvxPostItDialog::SvxPostItDialog(vcl::Window* pParent, const SfxItemSet& rCoreSet,
42 : bool bPrevNext)
43 : : SfxModalDialog(pParent, "CommentDialog", "cui/ui/comment.ui")
44 : , rSet(rCoreSet)
45 0 : , pOutSet(0)
46 : {
47 0 : get(m_pLastEditFT, "lastedit");
48 0 : get(m_pInsertAuthor, "insertauthor");
49 0 : get(m_pAuthorBtn, "author");
50 0 : get(m_pOKBtn, "ok");
51 0 : get(m_pPrevBtn, "previous");
52 0 : get(m_pNextBtn, "next");
53 0 : get(m_pEditED, "edit");
54 :
55 0 : m_pPrevBtn->SetClickHdl( LINK( this, SvxPostItDialog, PrevHdl ) );
56 0 : m_pNextBtn->SetClickHdl( LINK( this, SvxPostItDialog, NextHdl ) );
57 0 : m_pAuthorBtn->SetClickHdl( LINK( this, SvxPostItDialog, Stamp ) );
58 0 : m_pOKBtn->SetClickHdl( LINK( this, SvxPostItDialog, OKHdl ) );
59 :
60 0 : vcl::Font aFont( m_pEditED->GetFont() );
61 0 : aFont.SetWeight( WEIGHT_LIGHT );
62 0 : m_pEditED->SetFont( aFont );
63 :
64 0 : bool bNew = true;
65 0 : sal_uInt16 nWhich = 0;
66 :
67 0 : if ( !bPrevNext )
68 : {
69 0 : m_pPrevBtn->Hide();
70 0 : m_pNextBtn->Hide();
71 : }
72 :
73 0 : nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR );
74 0 : OUString aAuthorStr, aDateStr;
75 :
76 0 : if ( rSet.GetItemState( nWhich, true ) >= SfxItemState::DEFAULT )
77 : {
78 0 : bNew = false;
79 : const SvxPostItAuthorItem& rAuthor =
80 0 : static_cast<const SvxPostItAuthorItem&>(rSet.Get( nWhich ));
81 0 : aAuthorStr = rAuthor.GetValue();
82 : }
83 : else
84 0 : aAuthorStr = SvtUserOptions().GetID();
85 :
86 0 : nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE );
87 :
88 0 : if ( rSet.GetItemState( nWhich, true ) >= SfxItemState::DEFAULT )
89 : {
90 : const SvxPostItDateItem& rDate =
91 0 : static_cast<const SvxPostItDateItem&>(rSet.Get( nWhich ));
92 0 : aDateStr = rDate.GetValue();
93 : }
94 : else
95 : {
96 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
97 0 : aDateStr = rLocaleWrapper.getDate( Date( Date::SYSTEM ) );
98 : }
99 :
100 0 : nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT );
101 :
102 0 : OUString aTextStr;
103 0 : if ( rSet.GetItemState( nWhich, true ) >= SfxItemState::DEFAULT )
104 : {
105 : const SvxPostItTextItem& rText =
106 0 : static_cast<const SvxPostItTextItem&>(rSet.Get( nWhich ));
107 0 : aTextStr = rText.GetValue();
108 : }
109 :
110 0 : ShowLastAuthor(aAuthorStr, aDateStr);
111 :
112 : //lock to initial .ui placeholder size before replacing contents
113 0 : Size aSize(m_pEditED->get_preferred_size());
114 0 : m_pEditED->set_width_request(aSize.Width());
115 0 : m_pEditED->set_height_request(aSize.Height());
116 :
117 0 : m_pEditED->SetText(convertLineEnd(aTextStr, GetSystemLineEnd()));
118 :
119 0 : if (!bNew)
120 0 : SetText( get<FixedText>("alttitle")->GetText() );
121 0 : }
122 :
123 :
124 :
125 0 : SvxPostItDialog::~SvxPostItDialog()
126 : {
127 0 : delete pOutSet;
128 0 : pOutSet = 0;
129 0 : }
130 :
131 :
132 :
133 0 : void SvxPostItDialog::ShowLastAuthor(const OUString& rAuthor, const OUString& rDate)
134 : {
135 0 : OUString sTxt( rAuthor );
136 0 : sTxt += ", ";
137 0 : sTxt += rDate;
138 0 : m_pLastEditFT->SetText( sTxt );
139 0 : }
140 :
141 :
142 :
143 0 : const sal_uInt16* SvxPostItDialog::GetRanges()
144 : {
145 : static const sal_uInt16 pRanges[] =
146 : {
147 : SID_ATTR_POSTIT_AUTHOR,
148 : SID_ATTR_POSTIT_TEXT,
149 : 0
150 : };
151 0 : return pRanges;
152 : }
153 :
154 :
155 :
156 0 : void SvxPostItDialog::EnableTravel(bool bNext, bool bPrev)
157 : {
158 0 : m_pPrevBtn->Enable(bPrev);
159 0 : m_pNextBtn->Enable(bNext);
160 0 : }
161 :
162 :
163 :
164 0 : IMPL_LINK_NOARG_INLINE_START(SvxPostItDialog, PrevHdl)
165 : {
166 0 : aPrevHdlLink.Call( this );
167 0 : return 0;
168 : }
169 0 : IMPL_LINK_NOARG_INLINE_END(SvxPostItDialog, PrevHdl)
170 :
171 :
172 :
173 0 : IMPL_LINK_NOARG_INLINE_START(SvxPostItDialog, NextHdl)
174 : {
175 0 : aNextHdlLink.Call( this );
176 0 : return 0;
177 : }
178 0 : IMPL_LINK_NOARG_INLINE_END(SvxPostItDialog, NextHdl)
179 :
180 :
181 :
182 0 : IMPL_LINK_NOARG(SvxPostItDialog, Stamp)
183 : {
184 0 : Date aDate( Date::SYSTEM );
185 0 : tools::Time aTime( tools::Time::SYSTEM );
186 0 : OUString aTmp( SvtUserOptions().GetID() );
187 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
188 0 : OUString aStr( m_pEditED->GetText() );
189 0 : aStr += "\n---- ";
190 :
191 0 : if ( !aTmp.isEmpty() )
192 : {
193 0 : aStr += aTmp;
194 0 : aStr += ", ";
195 : }
196 0 : aStr += rLocaleWrapper.getDate(aDate);
197 0 : aStr += ", ";
198 0 : aStr += rLocaleWrapper.getTime(aTime, false, false);
199 0 : aStr += " ----\n";
200 :
201 0 : aStr = convertLineEnd(aStr, GetSystemLineEnd());
202 :
203 0 : m_pEditED->SetText(aStr);
204 0 : sal_Int32 nLen = aStr.getLength();
205 0 : m_pEditED->GrabFocus();
206 0 : m_pEditED->SetSelection( Selection( nLen, nLen ) );
207 0 : return 0;
208 : }
209 :
210 :
211 :
212 0 : IMPL_LINK_NOARG(SvxPostItDialog, OKHdl)
213 : {
214 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
215 0 : pOutSet = new SfxItemSet( rSet );
216 : pOutSet->Put( SvxPostItAuthorItem( SvtUserOptions().GetID(),
217 0 : rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR ) ) );
218 : pOutSet->Put( SvxPostItDateItem( rLocaleWrapper.getDate( Date( Date::SYSTEM ) ),
219 0 : rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE ) ) );
220 0 : pOutSet->Put( SvxPostItTextItem( m_pEditED->GetText(),
221 0 : rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT ) ) );
222 0 : EndDialog( RET_OK );
223 0 : return 0;
224 0 : }
225 :
226 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|