1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/date.hxx>
21 #include <tools/lineend.hxx>
22 #include <tools/time.hxx>
23 #include <vcl/svapp.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 <svx/svxids.hrc>
31 #include <svx/postattr.hxx>
32 #include <postdlg.hxx>
34 // class SvxPostItDialog -------------------------------------------------
36 SvxPostItDialog::SvxPostItDialog(weld::Widget
* pParent
, const SfxItemSet
& rCoreSet
,
38 : SfxDialogController(pParent
, "cui/ui/comment.ui", "CommentDialog")
40 , m_xLastEditFT(m_xBuilder
->weld_label("lastedit"))
41 , m_xAltTitle(m_xBuilder
->weld_label("alttitle"))
42 , m_xEditED(m_xBuilder
->weld_text_view("edit"))
43 , m_xInsertAuthor(m_xBuilder
->weld_widget("insertauthor"))
44 , m_xAuthorBtn(m_xBuilder
->weld_button("author"))
45 , m_xOKBtn(m_xBuilder
->weld_button("ok"))
46 , m_xPrevBtn(m_xBuilder
->weld_button("previous"))
47 , m_xNextBtn(m_xBuilder
->weld_button("next"))
49 m_xPrevBtn
->connect_clicked( LINK( this, SvxPostItDialog
, PrevHdl
) );
50 m_xNextBtn
->connect_clicked( LINK( this, SvxPostItDialog
, NextHdl
) );
51 m_xAuthorBtn
->connect_clicked( LINK( this, SvxPostItDialog
, Stamp
) );
52 m_xOKBtn
->connect_clicked( LINK( this, SvxPostItDialog
, OKHdl
) );
55 sal_uInt16 nWhich
= 0;
57 m_xPrevBtn
->set_visible(bPrevNext
);
58 m_xNextBtn
->set_visible(bPrevNext
);
60 nWhich
= m_rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR
);
61 OUString aAuthorStr
, aDateStr
;
63 if (m_rSet
.GetItemState( nWhich
) >= SfxItemState::DEFAULT
)
66 const SvxPostItAuthorItem
& rAuthor
=
67 static_cast<const SvxPostItAuthorItem
&>(m_rSet
.Get(nWhich
));
68 aAuthorStr
= rAuthor
.GetValue();
71 aAuthorStr
= SvtUserOptions().GetID();
73 nWhich
= m_rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE
);
75 if (m_rSet
.GetItemState( nWhich
) >= SfxItemState::DEFAULT
)
77 const SvxPostItDateItem
& rDate
=
78 static_cast<const SvxPostItDateItem
&>(m_rSet
.Get( nWhich
));
79 aDateStr
= rDate
.GetValue();
83 const LocaleDataWrapper
& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
84 aDateStr
= rLocaleWrapper
.getDate( Date( Date::SYSTEM
) );
87 nWhich
= m_rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT
);
90 if (m_rSet
.GetItemState( nWhich
) >= SfxItemState::DEFAULT
)
92 const SvxPostItTextItem
& rText
=
93 static_cast<const SvxPostItTextItem
&>(m_rSet
.Get( nWhich
));
94 aTextStr
= rText
.GetValue();
97 ShowLastAuthor(aAuthorStr
, aDateStr
);
99 //lock to an initial size before replacing contents
100 m_xEditED
->set_size_request(m_xEditED
->get_approximate_digit_width() * 32,
101 m_xEditED
->get_height_rows(10));
102 m_xEditED
->set_text(convertLineEnd(aTextStr
, GetSystemLineEnd()));
105 m_xDialog
->set_title(m_xAltTitle
->get_label());
109 SvxPostItDialog::~SvxPostItDialog()
113 void SvxPostItDialog::ShowLastAuthor(const OUString
& rAuthor
, const OUString
& rDate
)
115 OUString sTxt
= rAuthor
+ ", " + rDate
;
116 m_xLastEditFT
->set_label( sTxt
);
119 const sal_uInt16
* SvxPostItDialog::GetRanges()
121 static const sal_uInt16 pRanges
[] =
123 SID_ATTR_POSTIT_AUTHOR
,
124 SID_ATTR_POSTIT_TEXT
,
130 void SvxPostItDialog::EnableTravel(bool bNext
, bool bPrev
)
132 m_xPrevBtn
->set_sensitive(bPrev
);
133 m_xNextBtn
->set_sensitive(bNext
);
136 IMPL_LINK_NOARG(SvxPostItDialog
, PrevHdl
, weld::Button
&, void)
138 m_aPrevHdlLink
.Call( *this );
141 IMPL_LINK_NOARG(SvxPostItDialog
, NextHdl
, weld::Button
&, void)
143 m_aNextHdlLink
.Call( *this );
146 IMPL_LINK_NOARG(SvxPostItDialog
, Stamp
, weld::Button
&, void)
148 Date
aDate( Date::SYSTEM
);
149 tools::Time
aTime( tools::Time::SYSTEM
);
150 OUString
aTmp( SvtUserOptions().GetID() );
151 const LocaleDataWrapper
& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
152 OUString
aStr( m_xEditED
->get_text() );
155 if ( !aTmp
.isEmpty() )
159 aStr
+= rLocaleWrapper
.getDate(aDate
) + ", " + rLocaleWrapper
.getTime(aTime
, false) + " ----\n";
160 aStr
= convertLineEnd(aStr
, GetSystemLineEnd());
162 m_xEditED
->set_text(aStr
);
163 sal_Int32 nLen
= aStr
.getLength();
164 m_xEditED
->grab_focus();
165 m_xEditED
->select_region(nLen
, nLen
);
168 IMPL_LINK_NOARG(SvxPostItDialog
, OKHdl
, weld::Button
&, void)
170 const LocaleDataWrapper
& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
171 m_xOutSet
.reset(new SfxItemSet(m_rSet
));
172 m_xOutSet
->Put( SvxPostItAuthorItem(SvtUserOptions().GetID(),
173 m_rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR
) ) );
174 m_xOutSet
->Put( SvxPostItDateItem(rLocaleWrapper
.getDate( Date( Date::SYSTEM
) ),
175 m_rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE
) ) );
176 m_xOutSet
->Put( SvxPostItTextItem(m_xEditED
->get_text(),
177 m_rSet
.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT
) ) );
178 m_xDialog
->response(RET_OK
);
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */