LibreOffice Module cui (master) 1
postdlg.cxx
Go to the documentation of this file.
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/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>
29#include <svx/svxids.hrc>
30
31#include <svx/postattr.hxx>
32#include <postdlg.hxx>
33
34// class SvxPostItDialog -------------------------------------------------
35
37 bool bPrevNext)
38 : SfxDialogController(pParent, "cui/ui/comment.ui", "CommentDialog")
39 , m_rSet(rCoreSet)
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"))
48{
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 ) );
53
54 bool bNew = true;
55
56 m_xPrevBtn->set_visible(bPrevNext);
57 m_xNextBtn->set_visible(bPrevNext);
58
59 OUString aAuthorStr, aDateStr;
60
61 if (m_rSet.GetItemState( SID_ATTR_POSTIT_AUTHOR ) >= SfxItemState::DEFAULT)
62 {
63 bNew = false;
64 const SvxPostItAuthorItem& rAuthor = m_rSet.Get(SID_ATTR_POSTIT_AUTHOR);
65 aAuthorStr = rAuthor.GetValue();
66 }
67 else
68 aAuthorStr = SvtUserOptions().GetID();
69
70 if (m_rSet.GetItemState( SID_ATTR_POSTIT_DATE ) >= SfxItemState::DEFAULT)
71 {
72 const SvxPostItDateItem& rDate = m_rSet.Get( SID_ATTR_POSTIT_DATE );
73 aDateStr = rDate.GetValue();
74 }
75 else
76 {
78 aDateStr = rLocaleWrapper.getDate( Date( Date::SYSTEM ) );
79 }
80
81 OUString aTextStr;
82 if (m_rSet.GetItemState( SID_ATTR_POSTIT_TEXT ) >= SfxItemState::DEFAULT)
83 {
84 const SvxPostItTextItem& rText = m_rSet.Get( SID_ATTR_POSTIT_TEXT );
85 aTextStr = rText.GetValue();
86 }
87
88 ShowLastAuthor(aAuthorStr, aDateStr);
89
90 //lock to an initial size before replacing contents
91 m_xEditED->set_size_request(m_xEditED->get_approximate_digit_width() * 32,
92 m_xEditED->get_height_rows(10));
93 m_xEditED->set_text(convertLineEnd(aTextStr, GetSystemLineEnd()));
94
95 if (!bNew)
96 m_xDialog->set_title(m_xAltTitle->get_label());
97}
98
99
101{
102}
103
104void SvxPostItDialog::ShowLastAuthor(std::u16string_view rAuthor, std::u16string_view rDate)
105{
106 OUString sTxt = OUString::Concat(rAuthor) + ", " + rDate;
107 m_xLastEditFT->set_label( sTxt );
108}
109
111{
112 return WhichRangesContainer(svl::Items<SID_ATTR_POSTIT_AUTHOR, SID_ATTR_POSTIT_TEXT>);
113}
114
115void SvxPostItDialog::EnableTravel(bool bNext, bool bPrev)
116{
117 m_xPrevBtn->set_sensitive(bPrev);
118 m_xNextBtn->set_sensitive(bNext);
119}
120
122{
123 m_aPrevHdlLink.Call( *this );
124}
125
127{
128 m_aNextHdlLink.Call( *this );
129}
130
132{
133 Date aDate( Date::SYSTEM );
135 OUString aTmp( SvtUserOptions().GetID() );
137 OUString aStr( m_xEditED->get_text() + "\n---- " );
138
139 if ( !aTmp.isEmpty() )
140 {
141 aStr += aTmp + ", ";
142 }
143 aStr += rLocaleWrapper.getDate(aDate) + ", " + rLocaleWrapper.getTime(aTime, false) + " ----\n";
145
146 m_xEditED->set_text(aStr);
147 sal_Int32 nLen = aStr.getLength();
148 m_xEditED->grab_focus();
149 m_xEditED->select_region(nLen, nLen);
150}
151
153{
155 m_xOutSet.reset(new SfxItemSet(m_rSet));
156 m_xOutSet->Put( SvxPostItAuthorItem(SvtUserOptions().GetID(), SID_ATTR_POSTIT_AUTHOR ) );
157 m_xOutSet->Put( SvxPostItDateItem(rLocaleWrapper.getDate( Date( Date::SYSTEM ) ), SID_ATTR_POSTIT_DATE ) );
158 m_xOutSet->Put( SvxPostItTextItem(m_xEditED->get_text(), SID_ATTR_POSTIT_TEXT ) );
159 m_xDialog->response(RET_OK);
160}
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static const AllSettings & GetSettings()
OUString getDate(const Date &rDate) const
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SfxItemSet & m_rSet
Definition: postdlg.hxx:83
std::unique_ptr< weld::Label > m_xAltTitle
Definition: postdlg.hxx:90
SvxPostItDialog(weld::Widget *pParent, const SfxItemSet &rCoreSet, bool bPrevNext)
Definition: postdlg.cxx:36
void ShowLastAuthor(std::u16string_view rAuthor, std::u16string_view rDate)
Definition: postdlg.cxx:104
std::unique_ptr< weld::Button > m_xNextBtn
Definition: postdlg.hxx:96
static WhichRangesContainer GetRanges()
Definition: postdlg.cxx:110
std::unique_ptr< weld::Button > m_xPrevBtn
Definition: postdlg.hxx:95
std::unique_ptr< weld::Label > m_xLastEditFT
Definition: postdlg.hxx:89
std::unique_ptr< weld::Button > m_xOKBtn
Definition: postdlg.hxx:94
std::unique_ptr< weld::Button > m_xAuthorBtn
Definition: postdlg.hxx:93
std::unique_ptr< weld::TextView > m_xEditED
Definition: postdlg.hxx:91
virtual ~SvxPostItDialog() override
Definition: postdlg.cxx:100
void EnableTravel(bool bNext, bool bPrev)
Definition: postdlg.cxx:115
LineEnd GetSystemLineEnd()
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
aStr
const LocaleDataWrapper & GetLocaleDataWrapper(LanguageType nLang)
IMPL_LINK_NOARG(SvxPostItDialog, PrevHdl, weld::Button &, void)
Definition: postdlg.cxx:121
RET_OK