1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifdef SW_DLLIMPLEMENTATION
32 #undef SW_DLLIMPLEMENTATION
33 #endif
34 
35 #include <wrtsh.hxx>
36 #include <fldbas.hxx>
37 #include <fldmgr.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <DropDownFieldDialog.hxx>
40 #include <flddropdown.hxx>
41 #include <fldui.hrc>
42 #include <DropDownFieldDialog.hrc>
43 
44 using namespace ::com::sun::star;
45 
46 
47 /*--------------------------------------------------------------------
48 	Beschreibung: Feldeinfuegen bearbeiten
49  --------------------------------------------------------------------*/
50 
51 sw::DropDownFieldDialog::DropDownFieldDialog( Window *pParent, SwWrtShell &rS,
52 							  SwField* pField, sal_Bool bNextButton ) :
53 
54     SvxStandardDialog(pParent,  SW_RES(DLG_FLD_DROPDOWN)),
55     aItemsFL(       this, SW_RES( FL_ITEMS       )),
56     aListItemsLB(   this, SW_RES( LB_LISTITEMS   )),
57 
58     aOKPB(          this, SW_RES( PB_OK          )),
59     aCancelPB(      this, SW_RES( PB_CANCEL      )),
60     aNextPB(        this, SW_RES( PB_NEXT        )),
61     aHelpPB(        this, SW_RES( PB_HELP        )),
62 
63     aEditPB(        this, SW_RES( PB_EDIT        )),
64 
65     rSh( rS ),
66     pDropField(0)
67 {
68     Link aButtonLk = LINK(this, DropDownFieldDialog, ButtonHdl);
69     aEditPB.SetClickHdl(aButtonLk);
70 	if( bNextButton )
71 	{
72         aNextPB.Show();
73         aNextPB.SetClickHdl(aButtonLk);
74 	}
75 	else
76 	{
77         long nDiff = aCancelPB.GetPosPixel().Y() - aOKPB.GetPosPixel().Y();
78         Point aPos = aHelpPB.GetPosPixel();
79 		aPos.Y() -= nDiff;
80         aHelpPB.SetPosPixel(aPos);
81 	}
82     if( RES_DROPDOWN == pField->GetTyp()->Which() )
83     {
84 		//
85         pDropField = (SwDropDownField*)pField;
86         String sTitle = GetText();
87         sTitle += pDropField->GetPar2();
88         SetText(sTitle);
89         uno::Sequence< rtl::OUString > aItems = pDropField->GetItemSequence();
90         const rtl::OUString* pArray = aItems.getConstArray();
91         for(sal_Int32 i = 0; i < aItems.getLength(); i++)
92             aListItemsLB.InsertEntry(pArray[i]);
93         aListItemsLB.SelectEntry(pDropField->GetSelectedItem());
94 	}
95 
96 	sal_Bool bEnable = !rSh.IsCrsrReadonly();
97     aOKPB.Enable( bEnable );
98 
99     aListItemsLB.GrabFocus();
100 	FreeResource();
101 }
102 
103 sw::DropDownFieldDialog::~DropDownFieldDialog()
104 {
105 }
106 
107 /*--------------------------------------------------------------------
108 
109  --------------------------------------------------------------------*/
110 
111 void sw::DropDownFieldDialog::Apply()
112 {
113     if(pDropField)
114     {
115         String sSelect = aListItemsLB.GetSelectEntry();
116         if(pDropField->GetPar1() != sSelect)
117         {
118             rSh.StartAllAction();
119 
120             ::std::auto_ptr<SwDropDownField> const pCopy(
121                 static_cast<SwDropDownField *>( pDropField->CopyField() ) );
122 
123             pCopy->SetPar1(sSelect);
124             rSh.SwEditShell::UpdateFlds(*pCopy);
125 
126             rSh.SetUndoNoResetModified();
127             rSh.EndAllAction();
128         }
129     }
130 }
131 /* -----------------17.06.2003 10:50-----------------
132 
133  --------------------------------------------------*/
134 IMPL_LINK(sw::DropDownFieldDialog, ButtonHdl, PushButton*, pButton)
135 {
136     EndDialog(&aNextPB == pButton ? RET_OK : RET_YES );
137 	return 0;
138 }
139 
140