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>
27 #include <unotools/useroptions.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  sal_uInt16 nWhich = 0;
56 
57  m_xPrevBtn->set_visible(bPrevNext);
58  m_xNextBtn->set_visible(bPrevNext);
59 
60  nWhich = m_rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR );
61  OUString aAuthorStr, aDateStr;
62 
63  if (m_rSet.GetItemState( nWhich ) >= SfxItemState::DEFAULT)
64  {
65  bNew = false;
66  const SvxPostItAuthorItem& rAuthor =
67  static_cast<const SvxPostItAuthorItem&>(m_rSet.Get(nWhich));
68  aAuthorStr = rAuthor.GetValue();
69  }
70  else
71  aAuthorStr = SvtUserOptions().GetID();
72 
73  nWhich = m_rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE );
74 
75  if (m_rSet.GetItemState( nWhich ) >= SfxItemState::DEFAULT)
76  {
77  const SvxPostItDateItem& rDate =
78  static_cast<const SvxPostItDateItem&>(m_rSet.Get( nWhich ));
79  aDateStr = rDate.GetValue();
80  }
81  else
82  {
84  aDateStr = rLocaleWrapper.getDate( Date( Date::SYSTEM ) );
85  }
86 
87  nWhich = m_rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT );
88 
89  OUString aTextStr;
90  if (m_rSet.GetItemState( nWhich ) >= SfxItemState::DEFAULT)
91  {
92  const SvxPostItTextItem& rText =
93  static_cast<const SvxPostItTextItem&>(m_rSet.Get( nWhich ));
94  aTextStr = rText.GetValue();
95  }
96 
97  ShowLastAuthor(aAuthorStr, aDateStr);
98 
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()));
103 
104  if (!bNew)
105  m_xDialog->set_title(m_xAltTitle->get_label());
106 }
107 
108 
110 {
111 }
112 
113 void SvxPostItDialog::ShowLastAuthor(const OUString& rAuthor, const OUString& rDate)
114 {
115  OUString sTxt = rAuthor + ", " + rDate;
116  m_xLastEditFT->set_label( sTxt );
117 }
118 
119 const sal_uInt16* SvxPostItDialog::GetRanges()
120 {
121  static const sal_uInt16 pRanges[] =
122  {
123  SID_ATTR_POSTIT_AUTHOR,
124  SID_ATTR_POSTIT_TEXT,
125  0
126  };
127  return pRanges;
128 }
129 
130 void SvxPostItDialog::EnableTravel(bool bNext, bool bPrev)
131 {
132  m_xPrevBtn->set_sensitive(bPrev);
133  m_xNextBtn->set_sensitive(bNext);
134 }
135 
137 {
138  m_aPrevHdlLink.Call( *this );
139 }
140 
142 {
143  m_aNextHdlLink.Call( *this );
144 }
145 
147 {
148  Date aDate( Date::SYSTEM );
150  OUString aTmp( SvtUserOptions().GetID() );
152  OUString aStr( m_xEditED->get_text() );
153  aStr += "\n---- ";
154 
155  if ( !aTmp.isEmpty() )
156  {
157  aStr += aTmp + ", ";
158  }
159  aStr += rLocaleWrapper.getDate(aDate) + ", " + rLocaleWrapper.getTime(aTime, false) + " ----\n";
160  aStr = convertLineEnd(aStr, GetSystemLineEnd());
161 
162  m_xEditED->set_text(aStr);
163  sal_Int32 nLen = aStr.getLength();
164  m_xEditED->grab_focus();
165  m_xEditED->select_region(nLen, nLen);
166 }
167 
169 {
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);
179 }
180 
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xOKBtn
Definition: postdlg.hxx:91
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
std::unique_ptr< weld::Button > m_xPrevBtn
Definition: postdlg.hxx:92
void EnableTravel(bool bNext, bool bPrev)
Definition: postdlg.cxx:130
static const AllSettings & GetSettings()
std::unique_ptr< weld::Label > m_xAltTitle
Definition: postdlg.hxx:87
SvxPostItDialog(weld::Widget *pParent, const SfxItemSet &rCoreSet, bool bPrevNext)
Definition: postdlg.cxx:36
virtual ~SvxPostItDialog() override
Definition: postdlg.cxx:109
std::unique_ptr< weld::Label > m_xLastEditFT
Definition: postdlg.hxx:86
LineEnd GetSystemLineEnd()
static const sal_uInt16 * GetRanges()
Definition: postdlg.cxx:119
const SfxItemSet & m_rSet
Definition: postdlg.hxx:80
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const LocaleDataWrapper & GetLocaleDataWrapper(LanguageType nLang)
IMPL_LINK_NOARG(SvxPostItDialog, PrevHdl, weld::Button &, void)
Definition: postdlg.cxx:136
SfxItemPool * GetPool() const
std::unique_ptr< weld::TextView > m_xEditED
Definition: postdlg.hxx:88
std::unique_ptr< weld::Button > m_xNextBtn
Definition: postdlg.hxx:93
OUString getDate(const Date &rDate) const
std::unique_ptr< weld::Button > m_xAuthorBtn
Definition: postdlg.hxx:90
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
RET_OK
void ShowLastAuthor(const OUString &rAuthor, const OUString &rDate)
Definition: postdlg.cxx:113
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
aStr