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 <wrtsh.hxx>
21 : #include <fldbas.hxx>
22 : #include <fldmgr.hxx>
23 : #include <vcl/msgbox.hxx>
24 : #include <DropDownFieldDialog.hxx>
25 : #include <flddropdown.hxx>
26 : #include <fldui.hrc>
27 :
28 : #include <boost/scoped_ptr.hpp>
29 :
30 : using namespace ::com::sun::star;
31 :
32 : // edit insert-field
33 0 : sw::DropDownFieldDialog::DropDownFieldDialog(vcl::Window *pParent, SwWrtShell &rS,
34 : SwField* pField, bool bNextButton)
35 : : SvxStandardDialog(pParent, "DropdownFieldDialog",
36 : "modules/swriter/ui/dropdownfielddialog.ui")
37 : , rSh( rS )
38 0 : , pDropField(0)
39 : {
40 0 : get(m_pListItemsLB, "list");
41 0 : m_pListItemsLB->SetDropDownLineCount(12);
42 0 : m_pListItemsLB->set_width_request(m_pListItemsLB->approximate_char_width()*32);
43 0 : get(m_pOKPB, "ok");
44 0 : get(m_pNextPB, "next");
45 0 : get(m_pEditPB, "edit");
46 :
47 0 : Link aButtonLk = LINK(this, DropDownFieldDialog, ButtonHdl);
48 0 : m_pEditPB->SetClickHdl(aButtonLk);
49 0 : if( bNextButton )
50 : {
51 0 : m_pNextPB->Show();
52 0 : m_pNextPB->SetClickHdl(aButtonLk);
53 : }
54 0 : if( RES_DROPDOWN == pField->GetTyp()->Which() )
55 : {
56 :
57 0 : pDropField = (SwDropDownField*)pField;
58 0 : OUString sTitle = GetText();
59 0 : sTitle += pDropField->GetPar2();
60 0 : SetText(sTitle);
61 0 : uno::Sequence< OUString > aItems = pDropField->GetItemSequence();
62 0 : const OUString* pArray = aItems.getConstArray();
63 0 : for(sal_Int32 i = 0; i < aItems.getLength(); i++)
64 0 : m_pListItemsLB->InsertEntry(pArray[i]);
65 0 : m_pListItemsLB->SelectEntry(pDropField->GetSelectedItem());
66 : }
67 :
68 0 : bool bEnable = !rSh.IsCrsrReadonly();
69 0 : m_pOKPB->Enable( bEnable );
70 :
71 0 : m_pListItemsLB->GrabFocus();
72 0 : }
73 :
74 0 : void sw::DropDownFieldDialog::Apply()
75 : {
76 0 : if(pDropField)
77 : {
78 0 : OUString sSelect = m_pListItemsLB->GetSelectEntry();
79 0 : if(pDropField->GetPar1() != sSelect)
80 : {
81 0 : rSh.StartAllAction();
82 :
83 : boost::scoped_ptr<SwDropDownField> const pCopy(
84 0 : static_cast<SwDropDownField *>( pDropField->CopyField() ) );
85 :
86 0 : pCopy->SetPar1(sSelect);
87 0 : rSh.SwEditShell::UpdateFlds(*pCopy);
88 :
89 0 : rSh.SetUndoNoResetModified();
90 0 : rSh.EndAllAction();
91 0 : }
92 : }
93 0 : }
94 :
95 0 : IMPL_LINK(sw::DropDownFieldDialog, ButtonHdl, PushButton*, pButton)
96 : {
97 0 : EndDialog(m_pNextPB == pButton ? RET_OK : RET_YES );
98 0 : return 0;
99 0 : }
100 :
101 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|