xref: /trunk/main/sw/source/ui/fldui/fldwrap.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 
32 
33 #ifndef _CMDID_H
34 #include <cmdid.h>
35 #endif
36 #include <swtypes.hxx>
37 #include <sfx2/basedlgs.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <svx/htmlmode.hxx>
41 #include <viewopt.hxx>
42 #ifndef _DOCSH_HXX
43 #include <docsh.hxx>
44 #endif
45 #include <fldwrap.hxx>
46 #include <wrtsh.hxx>
47 #include <view.hxx>
48 #include <swmodule.hxx>
49 
50 #ifndef _HELPID_H
51 #include <helpid.h>
52 #endif
53 #ifndef _FLDUI_HRC
54 #include <fldui.hrc>
55 #endif
56 #ifndef _GLOBALS_HRC
57 #include <globals.hrc>
58 #endif
59 #ifndef _FLDTDLG_HRC
60 #include <fldtdlg.hrc>
61 #endif
62 #include "swabstdlg.hxx"
63 
64 SFX_IMPL_CHILDWINDOW(SwFldDlgWrapper, FN_INSERT_FIELD)
65 
66 /*--------------------------------------------------------------------
67     Beschreibung:
68  --------------------------------------------------------------------*/
69 
70 SwChildWinWrapper::SwChildWinWrapper(Window *pParentWindow, sal_uInt16 nId) :
71         SfxChildWindow(pParentWindow, nId),
72         m_pDocSh(0)
73 {
74     // Flackern der Buttons vermeiden:
75     m_aUpdateTimer.SetTimeout(200);
76     m_aUpdateTimer.SetTimeoutHdl(LINK(this, SwChildWinWrapper, UpdateHdl));
77 }
78 
79 /*--------------------------------------------------------------------
80     Beschreibung:
81  --------------------------------------------------------------------*/
82 
83 IMPL_LINK( SwChildWinWrapper, UpdateHdl, void*, EMPTYARG )
84 {
85     GetWindow()->Activate();    // Dialog aktualisieren
86 
87     return 0;
88 }
89 
90 /*--------------------------------------------------------------------
91     Beschreibung: Nach Dok-Wechsel Dialog neu initialisieren
92  --------------------------------------------------------------------*/
93 
94 sal_Bool SwChildWinWrapper::ReInitDlg(SwDocShell *)
95 {
96     sal_Bool bRet = sal_False;
97 
98     if (m_pDocSh != GetOldDocShell())
99     {
100         m_aUpdateTimer.Stop();
101         bRet = sal_True;            // Sofortiges Update
102     }
103     else
104         m_aUpdateTimer.Start();
105 
106     return bRet;
107 }
108 
109 /*--------------------------------------------------------------------
110     Beschreibung:
111  --------------------------------------------------------------------*/
112 
113 SfxChildWinInfo SwFldDlgWrapper::GetInfo() const
114 {
115     SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
116     aInfo.aPos = GetWindow()->OutputToAbsoluteScreenPixel(aInfo.aPos);
117     return aInfo;
118 }
119 
120 
121 /*--------------------------------------------------------------------
122     Beschreibung:
123  --------------------------------------------------------------------*/
124 
125 SwFldDlgWrapper::SwFldDlgWrapper( Window* _pParent, sal_uInt16 nId,
126                                     SfxBindings* pB,
127                                     SfxChildWinInfo*  )
128     : SwChildWinWrapper( _pParent, nId )
129 {
130     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
131     DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
132 
133     AbstractSwFldDlg* pDlg = pFact->CreateSwFldDlg(pB, this, _pParent, DLG_FLD_INSERT );
134     DBG_ASSERT(pDlg, "Dialogdiet fail!");
135     pDlgInterface = pDlg;
136     pWindow = pDlg->GetWindow();
137     pDlg->Start();
138     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
139 }
140 
141 /*--------------------------------------------------------------------
142     Beschreibung: Nach Dok-Wechsel Dialog neu initialisieren
143  --------------------------------------------------------------------*/
144 
145 sal_Bool SwFldDlgWrapper::ReInitDlg(SwDocShell *pDocSh)
146 {
147     sal_Bool bRet;
148 
149     if ((bRet = SwChildWinWrapper::ReInitDlg(pDocSh)) == sal_True)  // Sofort aktualisieren, Dok-Wechsel
150     {
151         pDlgInterface->ReInitDlg();
152     }
153 
154     return bRet;
155 }
156 
157 /*--------------------------------------------------------------------
158     Beschreibung:
159  --------------------------------------------------------------------*/
160 
161 void SwFldDlgWrapper::ShowPage(sal_uInt16 nPage)
162 {
163     pDlgInterface->ShowPage(nPage ? nPage : TP_FLD_REF);
164 }
165 
166 SFX_IMPL_CHILDWINDOW(SwFldDataOnlyDlgWrapper, FN_INSERT_FIELD_DATA_ONLY)
167 
168 /* -----------------04.02.2003 14:17-----------------
169  *
170  * --------------------------------------------------*/
171 SfxChildWinInfo SwFldDataOnlyDlgWrapper::GetInfo() const
172 {
173     SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
174 // prevent instatiation of dialog other than by calling
175 // the mail merge dialog
176     aInfo.bVisible = sal_False;
177     return aInfo;
178 }
179 /* -----------------04.02.2003 14:17-----------------
180  *
181  * --------------------------------------------------*/
182 SwFldDataOnlyDlgWrapper::SwFldDataOnlyDlgWrapper( Window* _pParent, sal_uInt16 nId,
183                                     SfxBindings* pB,
184                                     SfxChildWinInfo* pInfo )
185     : SwChildWinWrapper( _pParent, nId )
186 {
187     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
188     DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
189 
190     AbstractSwFldDlg* pDlg = pFact->CreateSwFldDlg(pB, this, _pParent, DLG_FLD_INSERT );
191     DBG_ASSERT(pDlg, "Dialogdiet fail!");
192     pDlgInterface = pDlg;
193 
194     pWindow = pDlg->GetWindow();
195     pDlg->ActivateDatabasePage();
196     pDlg->Start();
197     pDlg->Initialize( pInfo );
198     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
199 }
200 /* -----------------04.02.2003 14:17-----------------
201  * re-init after doc activation
202  * --------------------------------------------------*/
203 sal_Bool SwFldDataOnlyDlgWrapper::ReInitDlg(SwDocShell *pDocSh)
204 {
205     sal_Bool bRet;
206     if ((bRet = SwChildWinWrapper::ReInitDlg(pDocSh)) == sal_True)  // Sofort aktualisieren, Dok-Wechsel
207     {
208         pDlgInterface->ReInitDlg();
209     }
210 
211     return bRet;
212 }
213