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 .
21 #include "TableFieldDescWin.hxx"
22 #include <osl/diagnose.h>
23 #include "FieldDescriptions.hxx"
24 #include "dbu_tbl.hrc"
25 #include "TableDesignHelpBar.hxx"
26 #include <vcl/fixed.hxx>
27 #include "dbaccess_helpid.hrc"
28 #include "moduledbu.hxx"
31 #define STANDARD_MARGIN 6
32 #define DETAILS_HEADER_HEIGHT 25
33 #define CONTROL_SPACING_X 18 // 6
34 #define CONTROL_SPACING_Y 5
35 #define CONTROL_HEIGHT 20
36 #define CONTROL_WIDTH_1 140 // 100
37 #define CONTROL_WIDTH_3 250
38 #define CONTROL_WIDTH_4 (CONTROL_WIDTH_3 - CONTROL_HEIGHT - 5)
39 #define DETAILS_OPT_PAGE_WIDTH (CONTROL_WIDTH_1 + CONTROL_SPACING_X + CONTROL_WIDTH_4 + 50)
40 #define DETAILS_OPT_PAGE_HEIGHT ((CONTROL_HEIGHT + CONTROL_SPACING_Y) * 5)
41 #define DETAILS_MIN_HELP_WIDTH 100
42 #define DETAILS_OPT_HELP_WIDTH 200
43 #define DETAILS_MIN_HELP_HEIGHT 50
44 #define DETAILS_OPT_HELP_HEIGHT 100
47 using namespace dbaui
;
48 //==================================================================
49 // class OTableFieldDescWin
50 //==================================================================
51 DBG_NAME(OTableFieldDescWin
)
52 //------------------------------------------------------------------------------
53 OTableFieldDescWin::OTableFieldDescWin( Window
* pParent
)
54 :TabPage(pParent
, WB_3DLOOK
)
56 DBG_CTOR(OTableFieldDescWin
,NULL
);
57 //////////////////////////////////////////////////////////////////////
59 m_pHeader
= new FixedText( this, WB_CENTER
| WB_INFO
); // | WB_3DLOOK
60 m_pHeader
->SetText( String(ModuleRes(STR_TAB_PROPERTIES
)) );
63 //////////////////////////////////////////////////////////////////////
65 m_pHelpBar
= new OTableDesignHelpBar( this );
66 m_pHelpBar
->SetHelpId(HID_TAB_DESIGN_HELP_TEXT_FRAME
);
69 m_pGenPage
= new OFieldDescGenWin( this, m_pHelpBar
);
70 getGenPage()->SetHelpId( HID_TABLE_DESIGN_TABPAGE_GENERAL
);
74 //------------------------------------------------------------------------------
75 OTableFieldDescWin::~OTableFieldDescWin()
77 DBG_DTOR(OTableFieldDescWin
,NULL
);
78 //////////////////////////////////////////////////////////////////////
79 // Children zerstoeren
85 SAL_WNODEPRECATED_DECLARATIONS_PUSH
86 ::std::auto_ptr
<Window
> aTemp(m_pGenPage
);
87 SAL_WNODEPRECATED_DECLARATIONS_POP
91 SAL_WNODEPRECATED_DECLARATIONS_PUSH
92 ::std::auto_ptr
<Window
> aTemp(m_pHeader
);
93 SAL_WNODEPRECATED_DECLARATIONS_POP
97 SAL_WNODEPRECATED_DECLARATIONS_PUSH
98 ::std::auto_ptr
<Window
> aTemp(m_pHelpBar
);
99 SAL_WNODEPRECATED_DECLARATIONS_POP
104 //------------------------------------------------------------------------------
105 void OTableFieldDescWin::Init()
107 OSL_ENSURE(getGenPage() != NULL
, "OTableFieldDescWin::Init : ups ... no GenericPage ... this will crash ...");
108 getGenPage()->Init();
111 //------------------------------------------------------------------------------
112 void OTableFieldDescWin::SetReadOnly( sal_Bool bRead
)
114 DBG_CHKTHIS(OTableFieldDescWin
,NULL
);
115 getGenPage()->SetReadOnly( bRead
);
118 //------------------------------------------------------------------------------
119 void OTableFieldDescWin::DisplayData( OFieldDescription
* pFieldDescr
)
121 DBG_CHKTHIS(OTableFieldDescWin
,NULL
);
122 getGenPage()->DisplayData( pFieldDescr
);
125 //------------------------------------------------------------------------------
126 void OTableFieldDescWin::SaveData( OFieldDescription
* pFieldDescr
)
128 DBG_CHKTHIS(OTableFieldDescWin
,NULL
);
129 getGenPage()->SaveData( pFieldDescr
);
132 //------------------------------------------------------------------------------
133 void OTableFieldDescWin::Paint( const Rectangle
& /*rRect*/ )
135 DBG_CHKTHIS(OTableFieldDescWin
,NULL
);
136 //////////////////////////////////////////////////////////////////////
137 // 3D-Linie am oberen Fensterrand
138 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
140 SetLineColor( rStyleSettings
.GetLightColor() );
141 DrawLine( Point(0,0), Point(GetSizePixel().Width(),0) );
143 //////////////////////////////////////////////////////////////////////
144 // 3D-Linie zum Abtrennen des Headers
145 DrawLine( Point(3, DETAILS_HEADER_HEIGHT
), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT
) );
146 SetLineColor( rStyleSettings
.GetShadowColor() );
147 DrawLine( Point(3, DETAILS_HEADER_HEIGHT
-1), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT
-1) );
150 //------------------------------------------------------------------------------
151 void OTableFieldDescWin::Resize()
153 DBG_CHKTHIS(OTableFieldDescWin
,NULL
);
154 //////////////////////////////////////////////////////////////////////
155 // Abmessungen parent window
156 Size
aOutputSize( GetOutputSizePixel() );
157 long nOutputWidth
= aOutputSize
.Width();
158 long nOutputHeight
= aOutputSize
.Height();
160 // da die GenPage scrollen kann, ich selber aber nicht, positioniere ich das HelpFenster, wenn ich zu schmal werde,
161 // _unter_ der Genpage, nicht rechts daneben. Zuvor versuche ich aber noch, es etwas schmaler zu machen
164 long nHelpWidth
, nHelpHeight
;
165 long nPageWidth
, nPageHeight
;
167 // passen beide nebeneinander (Rand + Page + Rand + Help) ?
168 if (STANDARD_MARGIN
+ DETAILS_OPT_PAGE_WIDTH
+ STANDARD_MARGIN
+ DETAILS_MIN_HELP_WIDTH
<= nOutputWidth
)
169 { // ja -> dann ist die Frage, ob man der Hilfe ihre Optimal-Breite geben kann
170 nHelpWidth
= DETAILS_OPT_HELP_WIDTH
;
171 nPageWidth
= nOutputWidth
- nHelpWidth
- STANDARD_MARGIN
- STANDARD_MARGIN
;
172 if (nPageWidth
< DETAILS_OPT_PAGE_WIDTH
)
173 { // dann doch lieber die Hilfe von ihrer optimalen in Richtung auf die minimale Groesse
174 long nTransfer
= DETAILS_OPT_PAGE_WIDTH
- nPageWidth
;
175 nPageWidth
+= nTransfer
;
176 nHelpWidth
-= nTransfer
;
178 nHelpX
= nOutputWidth
- nHelpWidth
;
179 // die Hoehen sind dann einfach ...
180 nHelpY
= DETAILS_HEADER_HEIGHT
+ 1;
181 nHelpHeight
= nOutputHeight
- nHelpY
;
182 nPageHeight
= nOutputHeight
- STANDARD_MARGIN
- DETAILS_HEADER_HEIGHT
- STANDARD_MARGIN
;
185 { // nebeneinander geht nicht, also untereinander (Rand + Header + Page + Help)
186 if (STANDARD_MARGIN
+ DETAILS_HEADER_HEIGHT
+ DETAILS_OPT_PAGE_HEIGHT
+ DETAILS_MIN_HELP_HEIGHT
<= nOutputHeight
)
187 { // es reicht zumindest, um beide untereinander (Page optimal, Help minimal) unterzubringen
188 nHelpHeight
= DETAILS_OPT_HELP_HEIGHT
;
189 nPageHeight
= nOutputHeight
- nHelpHeight
- DETAILS_HEADER_HEIGHT
- STANDARD_MARGIN
;
190 if (nPageHeight
< DETAILS_OPT_PAGE_HEIGHT
)
191 { // wie oben : Page optimal, Hilfe soviel wie eben bleibt (das ist groesser/gleich ihrem Minimum)
192 long nTransfer
= DETAILS_OPT_PAGE_HEIGHT
- nPageHeight
;
193 nPageHeight
+= nTransfer
;
194 nHelpHeight
-= nTransfer
;
196 nHelpY
= nOutputHeight
- nHelpHeight
;
197 // und ueber die ganze Breite
198 nHelpX
= 0; // ohne Margin, da das HelpCtrl einen eigenen hat
199 nHelpWidth
= nOutputWidth
; // dito
200 nPageWidth
= nOutputWidth
- STANDARD_MARGIN
- STANDARD_MARGIN
;
203 { // dummerweise reicht es nicht mal, um Page optimal und Help minimal zu zeigen
204 nHelpX
= nHelpY
= nHelpWidth
= nHelpHeight
= 0; // -> kein Help-Fenster
205 nPageWidth
= nOutputWidth
- STANDARD_MARGIN
- STANDARD_MARGIN
;
206 nPageHeight
= nOutputHeight
- STANDARD_MARGIN
- DETAILS_HEADER_HEIGHT
- STANDARD_MARGIN
;
210 m_pHeader
->SetPosSizePixel( Point(0, STANDARD_MARGIN
), Size(nOutputWidth
, 15) );
212 getGenPage()->SetPosSizePixel(Point ( STANDARD_MARGIN
,
213 STANDARD_MARGIN
+ DETAILS_HEADER_HEIGHT
222 m_pHelpBar
->SetPosSizePixel(Point ( nHelpX
,
236 // -----------------------------------------------------------------------------
237 IClipboardTest
* OTableFieldDescWin::getActiveChild() const
239 IClipboardTest
* pTest
= NULL
;
240 switch(m_eChildFocus
)
243 pTest
= getGenPage();
246 pTest
= getHelpBar();
251 // -----------------------------------------------------------------------------
252 sal_Bool
OTableFieldDescWin::isCopyAllowed()
254 return getActiveChild() && getActiveChild()->isCopyAllowed();
256 // -----------------------------------------------------------------------------
257 sal_Bool
OTableFieldDescWin::isCutAllowed()
259 return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isCutAllowed());
261 // -----------------------------------------------------------------------------
262 sal_Bool
OTableFieldDescWin::isPasteAllowed()
264 return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isPasteAllowed());
266 // -----------------------------------------------------------------------------
267 void OTableFieldDescWin::cut()
269 if ( getGenPage() && getGenPage()->HasChildPathFocus() )
272 // -----------------------------------------------------------------------------
273 void OTableFieldDescWin::copy()
275 if ( getActiveChild() )
276 getActiveChild()->copy();
278 // -----------------------------------------------------------------------------
279 void OTableFieldDescWin::paste()
281 if ( getGenPage() && getGenPage()->HasChildPathFocus() )
282 getGenPage()->paste();
284 // -----------------------------------------------------------------------------
285 void OTableFieldDescWin::GetFocus()
288 getGenPage()->GetFocus();
290 // -----------------------------------------------------------------------------
291 void OTableFieldDescWin::LoseFocus()
294 getGenPage()->LoseFocus();
296 // -----------------------------------------------------------------------------
297 long OTableFieldDescWin::PreNotify( NotifyEvent
& rNEvt
)
299 sal_Bool bHandled
= sal_False
;
300 switch(rNEvt
.GetType())
303 if( getGenPage() && getGenPage()->HasChildPathFocus() )
304 m_eChildFocus
= DESCRIPTION
;
306 m_eChildFocus
= HELP
;
310 return bHandled
? 1L : TabPage::PreNotify(rNEvt
);
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */