1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include <vcl/msgbox.hxx>
24 #include <DropDownFieldDialog.hxx>
25 #include <flddropdown.hxx>
28 using namespace ::com::sun::star
;
31 /*--------------------------------------------------------------------
32 Description: edit insert-field
33 --------------------------------------------------------------------*/
34 sw::DropDownFieldDialog::DropDownFieldDialog(Window
*pParent
, SwWrtShell
&rS
,
35 SwField
* pField
, sal_Bool bNextButton
)
36 : SvxStandardDialog(pParent
, "DropdownFieldDialog",
37 "modules/swriter/ui/dropdownfielddialog.ui")
41 get(m_pListItemsLB
, "list");
42 m_pListItemsLB
->SetDropDownLineCount(12);
43 m_pListItemsLB
->set_width_request(m_pListItemsLB
->approximate_char_width()*32);
45 get(m_pNextPB
, "next");
46 get(m_pEditPB
, "edit");
48 Link aButtonLk
= LINK(this, DropDownFieldDialog
, ButtonHdl
);
49 m_pEditPB
->SetClickHdl(aButtonLk
);
53 m_pNextPB
->SetClickHdl(aButtonLk
);
55 if( RES_DROPDOWN
== pField
->GetTyp()->Which() )
58 pDropField
= (SwDropDownField
*)pField
;
59 String sTitle
= GetText();
60 sTitle
+= pDropField
->GetPar2();
62 uno::Sequence
< OUString
> aItems
= pDropField
->GetItemSequence();
63 const OUString
* pArray
= aItems
.getConstArray();
64 for(sal_Int32 i
= 0; i
< aItems
.getLength(); i
++)
65 m_pListItemsLB
->InsertEntry(pArray
[i
]);
66 m_pListItemsLB
->SelectEntry(pDropField
->GetSelectedItem());
69 sal_Bool bEnable
= !rSh
.IsCrsrReadonly();
70 m_pOKPB
->Enable( bEnable
);
72 m_pListItemsLB
->GrabFocus();
75 void sw::DropDownFieldDialog::Apply()
79 OUString sSelect
= m_pListItemsLB
->GetSelectEntry();
80 if(pDropField
->GetPar1() != sSelect
)
84 ::std::auto_ptr
<SwDropDownField
> const pCopy(
85 static_cast<SwDropDownField
*>( pDropField
->CopyField() ) );
87 pCopy
->SetPar1(sSelect
);
88 rSh
.SwEditShell::UpdateFlds(*pCopy
);
90 rSh
.SetUndoNoResetModified();
96 IMPL_LINK(sw::DropDownFieldDialog
, ButtonHdl
, PushButton
*, pButton
)
98 EndDialog(m_pNextPB
== pButton
? RET_OK
: RET_YES
);
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */