Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cui / source / dialogs / postdlg.cxx
blob1bcb6b7a015615764219bf381d7e71e2353b73ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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,
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"))
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 ) );
54 bool bNew = true;
56 m_xPrevBtn->set_visible(bPrevNext);
57 m_xNextBtn->set_visible(bPrevNext);
59 OUString aAuthorStr, aDateStr;
61 if (m_rSet.GetItemState( SID_ATTR_POSTIT_AUTHOR ) >= SfxItemState::DEFAULT)
63 bNew = false;
64 const SvxPostItAuthorItem& rAuthor = m_rSet.Get(SID_ATTR_POSTIT_AUTHOR);
65 aAuthorStr = rAuthor.GetValue();
67 else
68 aAuthorStr = SvtUserOptions().GetID();
70 if (m_rSet.GetItemState( SID_ATTR_POSTIT_DATE ) >= SfxItemState::DEFAULT)
72 const SvxPostItDateItem& rDate = m_rSet.Get( SID_ATTR_POSTIT_DATE );
73 aDateStr = rDate.GetValue();
75 else
77 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
78 aDateStr = rLocaleWrapper.getDate( Date( Date::SYSTEM ) );
81 OUString aTextStr;
82 if (m_rSet.GetItemState( SID_ATTR_POSTIT_TEXT ) >= SfxItemState::DEFAULT)
84 const SvxPostItTextItem& rText = m_rSet.Get( SID_ATTR_POSTIT_TEXT );
85 aTextStr = rText.GetValue();
88 ShowLastAuthor(aAuthorStr, aDateStr);
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()));
95 if (!bNew)
96 m_xDialog->set_title(m_xAltTitle->get_label());
100 SvxPostItDialog::~SvxPostItDialog()
104 void SvxPostItDialog::ShowLastAuthor(std::u16string_view rAuthor, std::u16string_view rDate)
106 OUString sTxt = OUString::Concat(rAuthor) + ", " + rDate;
107 m_xLastEditFT->set_label( sTxt );
110 WhichRangesContainer SvxPostItDialog::GetRanges()
112 return WhichRangesContainer(svl::Items<SID_ATTR_POSTIT_AUTHOR, SID_ATTR_POSTIT_TEXT>);
115 void SvxPostItDialog::EnableTravel(bool bNext, bool bPrev)
117 m_xPrevBtn->set_sensitive(bPrev);
118 m_xNextBtn->set_sensitive(bNext);
121 IMPL_LINK_NOARG(SvxPostItDialog, PrevHdl, weld::Button&, void)
123 m_aPrevHdlLink.Call( *this );
126 IMPL_LINK_NOARG(SvxPostItDialog, NextHdl, weld::Button&, void)
128 m_aNextHdlLink.Call( *this );
131 IMPL_LINK_NOARG(SvxPostItDialog, Stamp, weld::Button&, void)
133 Date aDate( Date::SYSTEM );
134 tools::Time aTime( tools::Time::SYSTEM );
135 OUString aTmp( SvtUserOptions().GetID() );
136 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
137 OUString aStr( m_xEditED->get_text() + "\n---- " );
139 if ( !aTmp.isEmpty() )
141 aStr += aTmp + ", ";
143 aStr += rLocaleWrapper.getDate(aDate) + ", " + rLocaleWrapper.getTime(aTime, false) + " ----\n";
144 aStr = convertLineEnd(aStr, GetSystemLineEnd());
146 m_xEditED->set_text(aStr);
147 sal_Int32 nLen = aStr.getLength();
148 m_xEditED->grab_focus();
149 m_xEditED->select_region(nLen, nLen);
152 IMPL_LINK_NOARG(SvxPostItDialog, OKHdl, weld::Button&, void)
154 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
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);
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */