update dev300-m58
[ooovba.git] / dbaccess / source / ui / tabledesign / TableFieldDescWin.cxx
blob5124184256be892691b2d0eecb5fe5c5ce9edd87
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableFieldDescWin.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBAUI_TABLEFIELDDESCRIPTION_HXX
35 #include "TableFieldDescWin.hxx"
36 #endif
37 #ifndef _TOOLS_DEBUG_HXX
38 #include <tools/debug.hxx>
39 #endif
40 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
41 #include "FieldDescriptions.hxx"
42 #endif
43 #ifndef _DBU_TBL_HRC_
44 #include "dbu_tbl.hrc"
45 #endif
46 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
47 #include "FieldDescriptions.hxx"
48 #endif
49 #ifndef DBAUI_TABLEDESIGNHELPBAR_HXX
50 #include "TableDesignHelpBar.hxx"
51 #endif
52 #ifndef _SV_FIXED_HXX
53 #include <vcl/fixed.hxx>
54 #endif
55 #ifndef _DBA_DBACCESS_HELPID_HRC_
56 #include "dbaccess_helpid.hrc"
57 #endif
58 #ifndef _DBAUI_MODULE_DBU_HXX_
59 #include "moduledbu.hxx"
60 #endif
61 #include <memory>
63 #define STANDARD_MARGIN 6
64 #define DETAILS_HEADER_HEIGHT 25
65 #define CONTROL_SPACING_X 18 // 6
66 #define CONTROL_SPACING_Y 5
67 #define CONTROL_HEIGHT 20
68 #define CONTROL_WIDTH_1 140 // 100
69 #define CONTROL_WIDTH_2 100 // 60
70 #define CONTROL_WIDTH_3 250
71 #define CONTROL_WIDTH_4 (CONTROL_WIDTH_3 - CONTROL_HEIGHT - 5)
72 #define DETAILS_OPT_PAGE_WIDTH (CONTROL_WIDTH_1 + CONTROL_SPACING_X + CONTROL_WIDTH_4 + 50)
73 #define DETAILS_OPT_PAGE_HEIGHT ((CONTROL_HEIGHT + CONTROL_SPACING_Y) * 5)
74 #define DETAILS_MIN_HELP_WIDTH 100
75 #define DETAILS_OPT_HELP_WIDTH 200
76 #define DETAILS_MIN_HELP_HEIGHT 50
77 #define DETAILS_OPT_HELP_HEIGHT 100
80 using namespace dbaui;
81 //==================================================================
82 // class OTableFieldDescWin
83 //==================================================================
84 DBG_NAME(OTableFieldDescWin)
85 //------------------------------------------------------------------------------
86 OTableFieldDescWin::OTableFieldDescWin( Window* pParent)
87 :TabPage(pParent, WB_3DLOOK)
89 DBG_CTOR(OTableFieldDescWin,NULL);
90 //////////////////////////////////////////////////////////////////////
91 // Header
92 m_pHeader = new FixedText( this, WB_CENTER | WB_INFO ); // | WB_3DLOOK
93 m_pHeader->SetText( String(ModuleRes(STR_TAB_PROPERTIES)) );
94 m_pHeader->Show();
96 //////////////////////////////////////////////////////////////////////
97 // HelpBar
98 m_pHelpBar = new OTableDesignHelpBar( this );
99 m_pHelpBar->SetHelpId(HID_TAB_DESIGN_HELP_TEXT_FRAME);
100 m_pHelpBar->Show();
102 m_pGenPage = new OFieldDescGenWin( this, m_pHelpBar );
103 getGenPage()->SetHelpId( HID_TABLE_DESIGN_TABPAGE_GENERAL );
104 getGenPage()->Show();
107 //------------------------------------------------------------------------------
108 OTableFieldDescWin::~OTableFieldDescWin()
110 DBG_DTOR(OTableFieldDescWin,NULL);
111 //////////////////////////////////////////////////////////////////////
112 // Childs zerstoeren
113 m_pHelpBar->Hide();
114 getGenPage()->Hide();
115 m_pHeader->Hide();
118 ::std::auto_ptr<Window> aTemp(m_pGenPage);
119 m_pGenPage = NULL;
122 ::std::auto_ptr<Window> aTemp(m_pHeader);
123 m_pHeader = NULL;
126 ::std::auto_ptr<Window> aTemp(m_pHelpBar);
127 m_pHelpBar = NULL;
131 //------------------------------------------------------------------------------
132 void OTableFieldDescWin::Init()
134 DBG_ASSERT(getGenPage() != NULL, "OTableFieldDescWin::Init : ups ... no GenericPage ... this will crash ...");
135 getGenPage()->Init();
138 //------------------------------------------------------------------------------
139 void OTableFieldDescWin::SetReadOnly( sal_Bool bRead )
141 DBG_CHKTHIS(OTableFieldDescWin,NULL);
142 getGenPage()->SetReadOnly( bRead );
145 //------------------------------------------------------------------------------
146 void OTableFieldDescWin::DisplayData( OFieldDescription* pFieldDescr )
148 DBG_CHKTHIS(OTableFieldDescWin,NULL);
149 getGenPage()->DisplayData( pFieldDescr );
152 //------------------------------------------------------------------------------
153 void OTableFieldDescWin::SaveData( OFieldDescription* pFieldDescr )
155 DBG_CHKTHIS(OTableFieldDescWin,NULL);
156 getGenPage()->SaveData( pFieldDescr );
159 //------------------------------------------------------------------------------
160 void OTableFieldDescWin::Paint( const Rectangle& /*rRect*/ )
162 DBG_CHKTHIS(OTableFieldDescWin,NULL);
163 //////////////////////////////////////////////////////////////////////
164 // 3D-Linie am oberen Fensterrand
165 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
167 SetLineColor( rStyleSettings.GetLightColor() );
168 DrawLine( Point(0,0), Point(GetSizePixel().Width(),0) );
170 //////////////////////////////////////////////////////////////////////
171 // 3D-Linie zum Abtrennen des Headers
172 DrawLine( Point(3, DETAILS_HEADER_HEIGHT), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT) );
173 SetLineColor( rStyleSettings.GetShadowColor() );
174 DrawLine( Point(3, DETAILS_HEADER_HEIGHT-1), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT-1) );
177 //------------------------------------------------------------------------------
178 void OTableFieldDescWin::Resize()
180 DBG_CHKTHIS(OTableFieldDescWin,NULL);
181 //////////////////////////////////////////////////////////////////////
182 // Abmessungen parent window
183 Size aOutputSize( GetOutputSizePixel() );
184 long nOutputWidth = aOutputSize.Width();
185 long nOutputHeight = aOutputSize.Height();
187 // da die GenPage scrollen kann, ich selber aber nicht, positioniere ich das HelpFenster, wenn ich zu schmal werde,
188 // _unter_ der Genpage, nicht rechts daneben. Zuvor versuche ich aber noch, es etwas schmaler zu machen
190 long nHelpX, nHelpY;
191 long nHelpWidth, nHelpHeight;
192 long nPageWidth, nPageHeight;
194 // passen beide nebeneinander (Rand + Page + Rand + Help) ?
195 if (STANDARD_MARGIN + DETAILS_OPT_PAGE_WIDTH + STANDARD_MARGIN + DETAILS_MIN_HELP_WIDTH <= nOutputWidth)
196 { // ja -> dann ist die Frage, ob man der Hilfe ihre Optimal-Breite geben kann
197 nHelpWidth = DETAILS_OPT_HELP_WIDTH;
198 nPageWidth = nOutputWidth - nHelpWidth - STANDARD_MARGIN - STANDARD_MARGIN;
199 if (nPageWidth < DETAILS_OPT_PAGE_WIDTH)
200 { // dann doch lieber die Hilfe von ihrer optimalen in Richtung auf die minimale Groesse
201 long nTransfer = DETAILS_OPT_PAGE_WIDTH - nPageWidth;
202 nPageWidth += nTransfer;
203 nHelpWidth -= nTransfer;
205 nHelpX = nOutputWidth - nHelpWidth;
206 // die Hoehen sind dann einfach ...
207 nHelpY = DETAILS_HEADER_HEIGHT + 1;
208 nHelpHeight = nOutputHeight - nHelpY;
209 nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
211 else
212 { // nebeneinander geht nicht, also untereinander (Rand + Header + Page + Help)
213 if (STANDARD_MARGIN + DETAILS_HEADER_HEIGHT + DETAILS_OPT_PAGE_HEIGHT + DETAILS_MIN_HELP_HEIGHT <= nOutputHeight)
214 { // es reicht zumindest, um beide untereinander (Page optimal, Help minimal) unterzubringen
215 nHelpHeight = DETAILS_OPT_HELP_HEIGHT;
216 nPageHeight = nOutputHeight - nHelpHeight - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
217 if (nPageHeight < DETAILS_OPT_PAGE_HEIGHT)
218 { // wie oben : Page optimal, Hilfe soviel wie eben bleibt (das ist groesser/gleich ihrem Minimum)
219 long nTransfer = DETAILS_OPT_PAGE_HEIGHT - nPageHeight;
220 nPageHeight += nTransfer;
221 nHelpHeight -= nTransfer;
223 nHelpY = nOutputHeight - nHelpHeight;
224 // und ueber die ganze Breite
225 nHelpX = 0; // ohne Margin, da das HelpCtrl einen eigenen hat
226 nHelpWidth = nOutputWidth; // dito
227 nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
229 else
230 { // dummerweise reicht es nicht mal, um Page optimal und Help minimal zu zeigen
231 nHelpX = nHelpY = nHelpWidth = nHelpHeight = 0; // -> kein Help-Fenster
232 nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
233 nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
237 m_pHeader->SetPosSizePixel( Point(0, STANDARD_MARGIN), Size(nOutputWidth, 15) );
239 getGenPage()->SetPosSizePixel(Point ( STANDARD_MARGIN,
240 STANDARD_MARGIN + DETAILS_HEADER_HEIGHT
242 Size ( nPageWidth,
243 nPageHeight
246 if (nHelpHeight)
248 m_pHelpBar->Show();
249 m_pHelpBar->SetPosSizePixel(Point ( nHelpX,
250 nHelpY
252 Size ( nHelpWidth,
253 nHelpHeight
257 else
259 m_pHelpBar->Hide();
261 Invalidate();
263 // -----------------------------------------------------------------------------
264 IClipboardTest* OTableFieldDescWin::getActiveChild() const
266 IClipboardTest* pTest = NULL;
267 switch(m_eChildFocus)
269 case DESCRIPTION:
270 pTest = getGenPage();
271 break;
272 default:
273 pTest = getHelpBar();
274 break;
276 return pTest;
278 // -----------------------------------------------------------------------------
279 sal_Bool OTableFieldDescWin::isCopyAllowed()
281 return getActiveChild() && getActiveChild()->isCopyAllowed();
283 // -----------------------------------------------------------------------------
284 sal_Bool OTableFieldDescWin::isCutAllowed()
286 return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isCutAllowed());
288 // -----------------------------------------------------------------------------
289 sal_Bool OTableFieldDescWin::isPasteAllowed()
291 return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isPasteAllowed());
293 // -----------------------------------------------------------------------------
294 void OTableFieldDescWin::cut()
296 if ( getGenPage() && getGenPage()->HasChildPathFocus() )
297 getGenPage()->cut();
299 // -----------------------------------------------------------------------------
300 void OTableFieldDescWin::copy()
302 if ( getActiveChild() )
303 getActiveChild()->copy();
305 // -----------------------------------------------------------------------------
306 void OTableFieldDescWin::paste()
308 if ( getGenPage() && getGenPage()->HasChildPathFocus() )
309 getGenPage()->paste();
311 // -----------------------------------------------------------------------------
312 void OTableFieldDescWin::GetFocus()
314 if ( getGenPage() )
315 getGenPage()->GetFocus();
317 // -----------------------------------------------------------------------------
318 void OTableFieldDescWin::LoseFocus()
320 if ( getGenPage() )
321 getGenPage()->LoseFocus();
323 // -----------------------------------------------------------------------------
324 long OTableFieldDescWin::PreNotify( NotifyEvent& rNEvt )
326 BOOL bHandled = FALSE;
327 switch(rNEvt.GetType())
329 case EVENT_GETFOCUS:
330 if( getGenPage() && getGenPage()->HasChildPathFocus() )
331 m_eChildFocus = DESCRIPTION;
332 else
333 m_eChildFocus = HELP;
334 break;
337 return bHandled ? 1L : TabPage::PreNotify(rNEvt);