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 <sal/config.h>
21 :
22 : #include <boost/noncopyable.hpp>
23 : #include <boost/scoped_ptr.hpp>
24 : #include <unotools/localedatawrapper.hxx>
25 : #include <comphelper/processfactory.hxx>
26 : #include <svl/eitem.hxx>
27 : #include <svl/intitem.hxx>
28 : #include <svl/stritem.hxx>
29 : #include <svl/itemset.hxx>
30 : #include <unotools/useroptions.hxx>
31 : #include <vcl/layout.hxx>
32 : #include <vcl/msgbox.hxx>
33 : #include <vcl/svapp.hxx>
34 : #include <vcl/settings.hxx>
35 : #include <tools/datetime.hxx>
36 : #include <svtools/treelistentry.hxx>
37 : #include <svtools/miscopt.hxx>
38 :
39 : #include "versdlg.hxx"
40 : #include "dialog.hrc"
41 : #include <sfx2/dialoghelper.hxx>
42 : #include <sfx2/viewfrm.hxx>
43 : #include <sfx2/sfxresid.hxx>
44 : #include <sfx2/docfile.hxx>
45 : #include <sfx2/objsh.hxx>
46 : #include <sfx2/sfxsids.hrc>
47 : #include <sfx2/dispatch.hxx>
48 : #include <sfx2/request.hxx>
49 :
50 : #include <sfx2/sfxuno.hxx>
51 : #include <vector>
52 :
53 : using namespace com::sun::star;
54 : using ::std::vector;
55 :
56 : // **************************************************************************
57 0 : struct SfxVersionInfo
58 : {
59 : OUString aName;
60 : OUString aComment;
61 : OUString aAuthor;
62 : DateTime aCreationDate;
63 :
64 : SfxVersionInfo();
65 : };
66 :
67 : typedef vector< SfxVersionInfo* > _SfxVersionTable;
68 :
69 : class SfxVersionTableDtor: private boost::noncopyable
70 : {
71 : private:
72 : _SfxVersionTable aTableList;
73 : public:
74 : SfxVersionTableDtor( const uno::Sequence < util::RevisionTag >& rInfo );
75 : SfxVersionTableDtor( const uno::Sequence < document::CmisVersion > & rInfo );
76 0 : ~SfxVersionTableDtor()
77 0 : { DelDtor(); }
78 :
79 : void DelDtor();
80 :
81 0 : size_t size() const
82 0 : { return aTableList.size(); }
83 :
84 0 : SfxVersionInfo* at( size_t i ) const
85 0 : { return aTableList[ i ]; }
86 : };
87 :
88 0 : SfxVersionTableDtor::SfxVersionTableDtor( const uno::Sequence < util::RevisionTag >& rInfo )
89 : {
90 0 : for ( sal_Int32 n=0; n<(sal_Int32)rInfo.getLength(); n++ )
91 : {
92 0 : SfxVersionInfo* pInfo = new SfxVersionInfo;
93 0 : pInfo->aName = rInfo[n].Identifier;
94 0 : pInfo->aComment = rInfo[n].Comment;
95 0 : pInfo->aAuthor = rInfo[n].Author;
96 :
97 0 : pInfo->aCreationDate = DateTime( rInfo[n].TimeStamp );
98 0 : aTableList.push_back( pInfo );
99 : }
100 0 : }
101 :
102 0 : SfxVersionTableDtor::SfxVersionTableDtor( const uno::Sequence < document::CmisVersion >& rInfo )
103 : {
104 0 : for ( sal_Int32 n=0; n<(sal_Int32)rInfo.getLength(); n++ )
105 : {
106 0 : SfxVersionInfo* pInfo = new SfxVersionInfo;
107 0 : pInfo->aName = rInfo[n].Id;
108 0 : pInfo->aComment = rInfo[n].Comment;
109 0 : pInfo->aAuthor = rInfo[n].Author;
110 :
111 0 : pInfo->aCreationDate = DateTime( rInfo[n].TimeStamp );
112 0 : aTableList.push_back( pInfo );
113 : }
114 0 : }
115 :
116 0 : void SfxVersionTableDtor::DelDtor()
117 : {
118 0 : for ( size_t i = 0, n = aTableList.size(); i < n; ++i )
119 0 : delete aTableList[ i ];
120 0 : aTableList.clear();
121 0 : }
122 :
123 0 : SfxVersionInfo::SfxVersionInfo()
124 0 : : aCreationDate( DateTime::EMPTY )
125 : {
126 0 : }
127 :
128 0 : void SfxVersionsTabListBox_Impl::KeyInput(const KeyEvent& rKeyEvent)
129 : {
130 0 : const vcl::KeyCode& rCode = rKeyEvent.GetKeyCode();
131 0 : switch (rCode.GetCode())
132 : {
133 : case KEY_RETURN :
134 : case KEY_ESCAPE :
135 : case KEY_TAB :
136 : {
137 0 : Dialog *pParent = GetParentDialog();
138 0 : if (pParent)
139 0 : pParent->KeyInput(rKeyEvent);
140 : else
141 0 : SvSimpleTable::KeyInput(rKeyEvent);
142 0 : break;
143 : }
144 : default:
145 0 : SvSimpleTable::KeyInput( rKeyEvent );
146 0 : break;
147 : }
148 0 : }
149 :
150 0 : void SfxVersionsTabListBox_Impl::Resize()
151 : {
152 0 : SvSimpleTable::Resize();
153 0 : if (isInitialLayout(this))
154 0 : setColSizes();
155 0 : }
156 :
157 0 : void SfxVersionsTabListBox_Impl::setColSizes()
158 : {
159 0 : HeaderBar &rBar = GetTheHeaderBar();
160 0 : if (rBar.GetItemCount() < 3)
161 0 : return;
162 :
163 : // recalculate the datetime column width
164 0 : long nWidestTime(GetTextWidth(getWidestTime(Application::GetSettings().GetLocaleDataWrapper())));
165 0 : long nW1 = rBar.GetTextWidth(rBar.GetItemText(1));
166 :
167 0 : long nMax = std::max(nWidestTime, nW1) + 12; // max width + a little offset
168 0 : const long nRest = GetSizePixel().Width() - nMax;
169 :
170 0 : std::set<OUString> aAuthors;
171 0 : SfxVersionInfo aInfo;
172 0 : aAuthors.insert(SvtUserOptions().GetFullName());
173 :
174 0 : for (SvTreeListEntry* pEntry = First(); pEntry; pEntry = Next(pEntry))
175 : {
176 0 : aAuthors.insert(static_cast<SfxVersionInfo*>(pEntry->GetUserData())->aAuthor);
177 : }
178 :
179 0 : long nMaxAuthorWidth = nRest/4;
180 0 : for (std::set<OUString>::iterator aI = aAuthors.begin(), aEnd = aAuthors.end(); aI != aEnd; ++aI)
181 : {
182 0 : nMaxAuthorWidth = std::max(nMaxAuthorWidth, GetTextWidth(*aI));
183 0 : if (nMaxAuthorWidth > nRest/2)
184 : {
185 0 : nMaxAuthorWidth = nRest/2;
186 0 : break;
187 : }
188 : }
189 :
190 0 : long aStaticTabs[] = { 3, 0, 0, 0 };
191 0 : aStaticTabs[2] = nMax;
192 0 : aStaticTabs[3] = nMax + nMaxAuthorWidth;
193 0 : SvSimpleTable::SetTabs(aStaticTabs, MAP_PIXEL);
194 : }
195 :
196 0 : SfxVersionDialog::SfxVersionDialog ( SfxViewFrame* pVwFrame, bool bIsSaveVersionOnClose )
197 : : SfxModalDialog(NULL, "VersionsOfDialog", "sfx/ui/versionsofdialog.ui")
198 : , pViewFrame(pVwFrame)
199 : , m_pTable(NULL)
200 0 : , m_bIsSaveVersionOnClose(bIsSaveVersionOnClose)
201 : {
202 0 : get(m_pSaveButton, "save");
203 0 : get(m_pSaveCheckBox, "always");
204 0 : get(m_pOpenButton, "open");
205 0 : get(m_pViewButton, "show");
206 0 : get(m_pDeleteButton, "delete");
207 0 : get(m_pCompareButton, "compare");
208 0 : get(m_pCmisButton, "cmis");
209 :
210 0 : SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("versions");
211 0 : Size aControlSize(260, 114);
212 0 : aControlSize = pContainer->LogicToPixel(aControlSize, MAP_APPFONT);
213 0 : pContainer->set_width_request(aControlSize.Width());
214 0 : pContainer->set_height_request(aControlSize.Height());
215 :
216 0 : m_pVersionBox = VclPtr<SfxVersionsTabListBox_Impl>::Create(*pContainer, WB_TABSTOP);
217 :
218 0 : Link<> aClickLink = LINK( this, SfxVersionDialog, ButtonHdl_Impl );
219 0 : m_pViewButton->SetClickHdl ( aClickLink );
220 0 : m_pSaveButton->SetClickHdl ( aClickLink );
221 0 : m_pDeleteButton->SetClickHdl ( aClickLink );
222 0 : m_pCompareButton->SetClickHdl ( aClickLink );
223 0 : m_pOpenButton->SetClickHdl ( aClickLink );
224 0 : m_pSaveCheckBox->SetClickHdl ( aClickLink );
225 0 : m_pCmisButton->SetClickHdl ( aClickLink );
226 :
227 0 : m_pVersionBox->SetSelectHdl( LINK( this, SfxVersionDialog, SelectHdl_Impl ) );
228 0 : m_pVersionBox->SetDoubleClickHdl( LINK( this, SfxVersionDialog, DClickHdl_Impl ) );
229 :
230 0 : m_pVersionBox->GrabFocus();
231 0 : m_pVersionBox->SetStyle( m_pVersionBox->GetStyle() | WB_HSCROLL | WB_CLIPCHILDREN );
232 0 : m_pVersionBox->SetSelectionMode( SINGLE_SELECTION );
233 :
234 0 : long nTabs_Impl[] = { 3, 0, 0, 0 };
235 :
236 :
237 0 : m_pVersionBox->SvSimpleTable::SetTabs(&nTabs_Impl[0]);
238 0 : OUString sHeader1(get<FixedText>("datetime")->GetText());
239 0 : OUString sHeader2(get<FixedText>("savedby")->GetText());
240 0 : OUString sHeader3(get<FixedText>("comments")->GetText());
241 0 : OUStringBuffer sHeader;
242 0 : sHeader.append(sHeader1).append("\t").append(sHeader2)
243 0 : .append("\t ").append(sHeader3);
244 0 : m_pVersionBox->InsertHeaderEntry(sHeader.makeStringAndClear());
245 :
246 0 : HeaderBar &rBar = m_pVersionBox->GetTheHeaderBar();
247 0 : HeaderBarItemBits nBits = rBar.GetItemBits(1) | HeaderBarItemBits::FIXEDPOS | HeaderBarItemBits::FIXED;
248 0 : nBits &= ~HeaderBarItemBits::CLICKABLE;
249 0 : rBar.SetItemBits(1, nBits);
250 0 : rBar.SetItemBits(2, nBits);
251 0 : rBar.SetItemBits(3, nBits);
252 :
253 0 : m_pVersionBox->Resize(); // OS: Hack for correct selection
254 :
255 :
256 : // set dialog title (filename or docinfo title)
257 0 : OUString sText = GetText();
258 0 : sText = sText + " " + pViewFrame->GetObjectShell()->GetTitle();
259 0 : SetText( sText );
260 :
261 0 : Init_Impl();
262 :
263 0 : m_pVersionBox->setColSizes();
264 0 : }
265 :
266 0 : OUString ConvertWhiteSpaces_Impl( const OUString& rText )
267 : {
268 : // converted linebreaks and tabs to blanks; it's necessary for the display
269 0 : OUStringBuffer sConverted;
270 0 : const sal_Unicode* pChars = rText.getStr();
271 0 : while ( *pChars )
272 : {
273 0 : switch ( *pChars )
274 : {
275 : case '\n' :
276 : case '\t' :
277 0 : sConverted.append(' ');
278 0 : break;
279 :
280 : default:
281 0 : sConverted.append(*pChars);
282 : }
283 :
284 0 : ++pChars;
285 : }
286 :
287 0 : return sConverted.makeStringAndClear();
288 : }
289 :
290 0 : void SfxVersionDialog::Init_Impl()
291 : {
292 0 : SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
293 0 : SfxMedium* pMedium = pObjShell->GetMedium();
294 0 : uno::Sequence < util::RevisionTag > aVersions = pMedium->GetVersionList( true );
295 0 : delete m_pTable;
296 0 : m_pTable = new SfxVersionTableDtor( aVersions );
297 : {
298 0 : for ( size_t n = 0; n < m_pTable->size(); ++n )
299 : {
300 0 : SfxVersionInfo *pInfo = m_pTable->at( n );
301 0 : OUString aEntry = formatTime(pInfo->aCreationDate, Application::GetSettings().GetLocaleDataWrapper());
302 0 : aEntry += "\t";
303 0 : aEntry += pInfo->aAuthor;
304 0 : aEntry += "\t";
305 0 : aEntry += ConvertWhiteSpaces_Impl( pInfo->aComment );
306 0 : SvTreeListEntry *pEntry = m_pVersionBox->InsertEntry( aEntry );
307 0 : pEntry->SetUserData( pInfo );
308 0 : }
309 : }
310 :
311 0 : m_pSaveCheckBox->Check( m_bIsSaveVersionOnClose );
312 :
313 0 : bool bEnable = !pObjShell->IsReadOnly();
314 0 : m_pSaveButton->Enable( bEnable );
315 0 : m_pSaveCheckBox->Enable( bEnable );
316 :
317 0 : m_pOpenButton->Disable();
318 0 : m_pViewButton->Disable();
319 0 : m_pDeleteButton->Disable();
320 0 : m_pCompareButton->Disable();
321 :
322 0 : SvtMiscOptions miscOptions;
323 0 : if ( !miscOptions.IsExperimentalMode() )
324 0 : m_pCmisButton->Hide( );
325 0 : m_pCmisButton->Enable();
326 :
327 0 : SelectHdl_Impl(m_pVersionBox);
328 0 : }
329 :
330 0 : SfxVersionDialog::~SfxVersionDialog()
331 : {
332 0 : disposeOnce();
333 0 : }
334 :
335 0 : void SfxVersionDialog::dispose()
336 : {
337 0 : delete m_pTable;
338 0 : m_pVersionBox.disposeAndClear();
339 0 : m_pSaveButton.clear();
340 0 : m_pSaveCheckBox.clear();
341 0 : m_pOpenButton.clear();
342 0 : m_pViewButton.clear();
343 0 : m_pDeleteButton.clear();
344 0 : m_pCompareButton.clear();
345 0 : m_pCmisButton.clear();
346 0 : SfxModalDialog::dispose();
347 0 : }
348 :
349 0 : void SfxVersionDialog::Open_Impl()
350 : {
351 0 : SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
352 :
353 0 : SvTreeListEntry *pEntry = m_pVersionBox->FirstSelected();
354 0 : sal_uIntPtr nPos = SvTreeList::GetRelPos( pEntry );
355 0 : SfxInt16Item aItem( SID_VERSION, (short)nPos+1 );
356 0 : SfxStringItem aTarget( SID_TARGETNAME, "_blank" );
357 0 : SfxStringItem aReferer( SID_REFERER, "private:user" );
358 0 : SfxStringItem aFile( SID_FILE_NAME, pObjShell->GetMedium()->GetName() );
359 :
360 0 : uno::Sequence< beans::NamedValue > aEncryptionData;
361 0 : if ( GetEncryptionData_Impl( pObjShell->GetMedium()->GetItemSet(), aEncryptionData ) )
362 : {
363 : // there is a password, it should be used during the opening
364 0 : SfxUnoAnyItem aEncryptionDataItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) );
365 : pViewFrame->GetDispatcher()->Execute(
366 0 : SID_OPENDOC, SfxCallMode::ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, &aEncryptionDataItem, 0L );
367 : }
368 : else
369 : pViewFrame->GetDispatcher()->Execute(
370 0 : SID_OPENDOC, SfxCallMode::ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, 0L );
371 :
372 0 : Close();
373 0 : }
374 :
375 0 : IMPL_LINK_NOARG(SfxVersionDialog, DClickHdl_Impl)
376 : {
377 0 : Open_Impl();
378 0 : return 0L;
379 : }
380 :
381 0 : IMPL_LINK_NOARG(SfxVersionDialog, SelectHdl_Impl)
382 : {
383 0 : bool bEnable = ( m_pVersionBox->FirstSelected() != NULL );
384 0 : SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
385 0 : m_pDeleteButton->Enable(bEnable && !pObjShell->IsReadOnly());
386 0 : m_pOpenButton->Enable(bEnable);
387 0 : m_pViewButton->Enable(bEnable);
388 :
389 0 : const SfxPoolItem *pDummy=NULL;
390 0 : SfxItemState eState = pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_MERGE, pDummy );
391 0 : eState = pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_COMPARE, pDummy );
392 0 : m_pCompareButton->Enable(bEnable && eState >= SfxItemState::DEFAULT);
393 :
394 0 : return 0L;
395 : }
396 :
397 0 : IMPL_LINK( SfxVersionDialog, ButtonHdl_Impl, Button*, pButton )
398 : {
399 0 : SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
400 0 : SvTreeListEntry *pEntry = m_pVersionBox->FirstSelected();
401 :
402 0 : if (pButton == m_pSaveCheckBox)
403 : {
404 0 : m_bIsSaveVersionOnClose = m_pSaveCheckBox->IsChecked();
405 : }
406 0 : else if (pButton == m_pSaveButton)
407 : {
408 0 : SfxVersionInfo aInfo;
409 0 : aInfo.aAuthor = SvtUserOptions().GetFullName();
410 0 : VclPtrInstance< SfxViewVersionDialog_Impl > pDlg(this, aInfo, true);
411 0 : short nRet = pDlg->Execute();
412 0 : if ( nRet == RET_OK )
413 : {
414 0 : SfxStringItem aComment( SID_DOCINFO_COMMENTS, aInfo.aComment );
415 0 : pObjShell->SetModified( true );
416 : const SfxPoolItem* aItems[2];
417 0 : aItems[0] = &aComment;
418 0 : aItems[1] = NULL;
419 0 : pViewFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, aItems, 0 );
420 0 : m_pVersionBox->SetUpdateMode( false );
421 0 : m_pVersionBox->Clear();
422 0 : Init_Impl();
423 0 : m_pVersionBox->SetUpdateMode( true );
424 0 : }
425 : }
426 0 : if (pButton == m_pDeleteButton && pEntry)
427 : {
428 0 : pObjShell->GetMedium()->RemoveVersion_Impl( static_cast<SfxVersionInfo*>(pEntry->GetUserData())->aName );
429 0 : pObjShell->SetModified( true );
430 0 : m_pVersionBox->SetUpdateMode( false );
431 0 : m_pVersionBox->Clear();
432 0 : Init_Impl();
433 0 : m_pVersionBox->SetUpdateMode( true );
434 : }
435 0 : else if (pButton == m_pOpenButton && pEntry)
436 : {
437 0 : Open_Impl();
438 : }
439 0 : else if (pButton == m_pViewButton && pEntry)
440 : {
441 0 : SfxVersionInfo* pInfo = static_cast<SfxVersionInfo*>(pEntry->GetUserData());
442 0 : VclPtrInstance<SfxViewVersionDialog_Impl> pDlg(this, *pInfo, false);
443 0 : pDlg->Execute();
444 : }
445 0 : else if (pEntry && pButton == m_pCompareButton)
446 : {
447 0 : SfxAllItemSet aSet( pObjShell->GetPool() );
448 0 : sal_uIntPtr nPos = SvTreeList::GetRelPos( pEntry );
449 0 : aSet.Put( SfxInt16Item( SID_VERSION, (short)nPos+1 ) );
450 0 : aSet.Put( SfxStringItem( SID_FILE_NAME, pObjShell->GetMedium()->GetName() ) );
451 :
452 0 : SfxItemSet* pSet = pObjShell->GetMedium()->GetItemSet();
453 0 : SFX_ITEMSET_ARG( pSet, pFilterItem, SfxStringItem, SID_FILTER_NAME, false );
454 0 : SFX_ITEMSET_ARG( pSet, pFilterOptItem, SfxStringItem, SID_FILE_FILTEROPTIONS, false );
455 0 : if ( pFilterItem )
456 0 : aSet.Put( *pFilterItem );
457 0 : if ( pFilterOptItem )
458 0 : aSet.Put( *pFilterOptItem );
459 :
460 0 : pViewFrame->GetDispatcher()->Execute( SID_DOCUMENT_COMPARE, SfxCallMode::ASYNCHRON, aSet );
461 0 : Close();
462 : }
463 0 : else if (pButton == m_pCmisButton)
464 : {
465 0 : VclPtrInstance< SfxCmisVersionsDialog > pDlg(pViewFrame, false);
466 0 : pDlg->Execute();
467 : }
468 :
469 0 : return 0L;
470 : }
471 :
472 0 : SfxViewVersionDialog_Impl::SfxViewVersionDialog_Impl(vcl::Window *pParent, SfxVersionInfo& rInfo, bool bEdit)
473 : : SfxModalDialog(pParent, "VersionCommentDialog", "sfx/ui/versioncommentdialog.ui")
474 0 : , m_rInfo(rInfo)
475 : {
476 0 : get(m_pDateTimeText, "timestamp");
477 0 : get(m_pSavedByText, "author");
478 0 : get(m_pEdit, "textview");
479 0 : get(m_pOKButton, "ok");
480 0 : get(m_pCancelButton, "cancel");
481 0 : get(m_pCloseButton, "close");
482 :
483 0 : OUString sAuthor = rInfo.aAuthor.isEmpty() ? SfxResId(STR_NO_NAME_SET) : rInfo.aAuthor;
484 :
485 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
486 0 : m_pDateTimeText->SetText(m_pDateTimeText->GetText() + formatTime(rInfo.aCreationDate, rLocaleWrapper));
487 0 : m_pSavedByText->SetText(m_pSavedByText->GetText() + sAuthor);
488 0 : m_pEdit->SetText(rInfo.aComment);
489 0 : m_pEdit->set_height_request(7 * m_pEdit->GetTextHeight());
490 0 : m_pEdit->set_width_request(40 * m_pEdit->approximate_char_width());
491 0 : m_pOKButton->SetClickHdl(LINK(this, SfxViewVersionDialog_Impl, ButtonHdl));
492 :
493 0 : if (!bEdit)
494 : {
495 0 : m_pOKButton->Hide();
496 0 : m_pCancelButton->Hide();
497 0 : m_pEdit->SetReadOnly(true);
498 0 : SetText(SfxResId(STR_VIEWVERSIONCOMMENT));
499 0 : m_pCloseButton->GrabFocus();
500 : }
501 : else
502 : {
503 0 : m_pDateTimeText->Hide();
504 0 : m_pCloseButton->Hide();
505 0 : m_pEdit->GrabFocus();
506 0 : }
507 0 : }
508 :
509 0 : SfxViewVersionDialog_Impl::~SfxViewVersionDialog_Impl()
510 : {
511 0 : disposeOnce();
512 0 : }
513 :
514 0 : void SfxViewVersionDialog_Impl::dispose()
515 : {
516 0 : m_pDateTimeText.clear();
517 0 : m_pSavedByText.clear();
518 0 : m_pEdit.clear();
519 0 : m_pOKButton.clear();
520 0 : m_pCancelButton.clear();
521 0 : m_pCloseButton.clear();
522 0 : SfxModalDialog::dispose();
523 0 : }
524 :
525 0 : IMPL_LINK(SfxViewVersionDialog_Impl, ButtonHdl, Button*, pButton)
526 : {
527 : assert(pButton == m_pOKButton);
528 : (void)pButton;
529 0 : m_rInfo.aComment = m_pEdit->GetText();
530 0 : EndDialog(RET_OK);
531 0 : return 0L;
532 : }
533 :
534 0 : SfxCmisVersionsDialog::SfxCmisVersionsDialog ( SfxViewFrame* pVwFrame, bool bIsSaveVersionOnClose )
535 : : SfxModalDialog(NULL, "VersionsCmisDialog", "sfx/ui/versionscmis.ui")
536 : , pViewFrame(pVwFrame)
537 : , m_pTable(NULL)
538 0 : , m_bIsSaveVersionOnClose(bIsSaveVersionOnClose)
539 : {
540 0 : get(m_pOpenButton, "open");
541 0 : get(m_pViewButton, "show");
542 0 : get(m_pDeleteButton, "delete");
543 0 : get(m_pCompareButton, "compare");
544 :
545 0 : SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("versions");
546 0 : Size aControlSize(260, 114);
547 0 : aControlSize = pContainer->LogicToPixel(aControlSize, MAP_APPFONT);
548 0 : pContainer->set_width_request(aControlSize.Width());
549 0 : pContainer->set_height_request(aControlSize.Height());
550 :
551 0 : m_pVersionBox = VclPtr<SfxVersionsTabListBox_Impl>::Create(*pContainer, WB_TABSTOP);
552 :
553 0 : m_pVersionBox->GrabFocus();
554 0 : m_pVersionBox->SetStyle( m_pVersionBox->GetStyle() | WB_HSCROLL | WB_CLIPCHILDREN );
555 0 : m_pVersionBox->SetSelectionMode( SINGLE_SELECTION );
556 :
557 0 : long nTabs_Impl[] = { 3, 0, 0, 0 };
558 :
559 0 : m_pVersionBox->SvSimpleTable::SetTabs(&nTabs_Impl[0]);
560 0 : OUString sHeader1(get<FixedText>("datetime")->GetText());
561 0 : OUString sHeader2(get<FixedText>("savedby")->GetText());
562 0 : OUString sHeader3(get<FixedText>("comments")->GetText());
563 0 : OUStringBuffer sHeader;
564 0 : sHeader.append(sHeader1).append("\t").append(sHeader2)
565 0 : .append("\t ").append(sHeader3);
566 0 : m_pVersionBox->InsertHeaderEntry(sHeader.makeStringAndClear());
567 :
568 0 : HeaderBar &rBar = m_pVersionBox->GetTheHeaderBar();
569 0 : HeaderBarItemBits nBits = rBar.GetItemBits(1) | HeaderBarItemBits::FIXEDPOS | HeaderBarItemBits::FIXED;
570 0 : nBits &= ~HeaderBarItemBits::CLICKABLE;
571 0 : rBar.SetItemBits(1, nBits);
572 0 : rBar.SetItemBits(2, nBits);
573 0 : rBar.SetItemBits(3, nBits);
574 :
575 0 : m_pVersionBox->Resize();
576 :
577 0 : OUString sText = GetText();
578 0 : sText = sText + " " + pViewFrame->GetObjectShell()->GetTitle();
579 0 : SetText( sText );
580 :
581 0 : LoadVersions();
582 :
583 0 : m_pVersionBox->setColSizes();
584 :
585 0 : }
586 :
587 0 : SfxCmisVersionsDialog::~SfxCmisVersionsDialog()
588 : {
589 0 : disposeOnce();
590 0 : }
591 :
592 0 : void SfxCmisVersionsDialog::dispose()
593 : {
594 0 : delete m_pTable;
595 0 : m_pVersionBox.disposeAndClear();
596 0 : m_pOpenButton.clear();
597 0 : m_pViewButton.clear();
598 0 : m_pDeleteButton.clear();
599 0 : m_pCompareButton.clear();
600 0 : SfxModalDialog::dispose();
601 0 : }
602 :
603 0 : void SfxCmisVersionsDialog::LoadVersions()
604 : {
605 0 : SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
606 0 : uno::Sequence < document::CmisVersion > aVersions = pObjShell->GetCmisVersions( );
607 0 : delete m_pTable;
608 0 : m_pTable = new SfxVersionTableDtor( aVersions );
609 : {
610 0 : for ( size_t n = 0; n < m_pTable->size(); ++n )
611 : {
612 0 : SfxVersionInfo *pInfo = m_pTable->at( n );
613 0 : OUString aEntry = formatTime(pInfo->aCreationDate, Application::GetSettings().GetLocaleDataWrapper());
614 0 : aEntry += "\t";
615 0 : aEntry += pInfo->aAuthor;
616 0 : aEntry += "\t";
617 0 : aEntry += ConvertWhiteSpaces_Impl( pInfo->aComment );
618 0 : SvTreeListEntry *pEntry = m_pVersionBox->InsertEntry( aEntry );
619 0 : pEntry->SetUserData( pInfo );
620 0 : }
621 0 : }
622 :
623 648 : }
624 :
625 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|