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_dbaccess.hxx"
30 
31 #ifndef DBAUI_TABLEFIELDDESCRIPTION_HXX
32 #include "TableFieldDescWin.hxx"
33 #endif
34 #ifndef _TOOLS_DEBUG_HXX
35 #include <tools/debug.hxx>
36 #endif
37 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
38 #include "FieldDescriptions.hxx"
39 #endif
40 #ifndef _DBU_TBL_HRC_
41 #include "dbu_tbl.hrc"
42 #endif
43 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
44 #include "FieldDescriptions.hxx"
45 #endif
46 #ifndef DBAUI_TABLEDESIGNHELPBAR_HXX
47 #include "TableDesignHelpBar.hxx"
48 #endif
49 #ifndef _SV_FIXED_HXX
50 #include <vcl/fixed.hxx>
51 #endif
52 #ifndef _DBA_DBACCESS_HELPID_HRC_
53 #include "dbaccess_helpid.hrc"
54 #endif
55 #ifndef _DBAUI_MODULE_DBU_HXX_
56 #include "moduledbu.hxx"
57 #endif
58 #include <memory>
59 
60 #define STANDARD_MARGIN					 6
61 #define DETAILS_HEADER_HEIGHT			25
62 #define CONTROL_SPACING_X	18	// 6
63 #define	CONTROL_SPACING_Y	5
64 #define CONTROL_HEIGHT		20
65 #define CONTROL_WIDTH_1		140	// 100
66 #define CONTROL_WIDTH_2		100 // 60
67 #define CONTROL_WIDTH_3		250
68 #define CONTROL_WIDTH_4		(CONTROL_WIDTH_3 - CONTROL_HEIGHT - 5)
69 #define DETAILS_OPT_PAGE_WIDTH			(CONTROL_WIDTH_1 + CONTROL_SPACING_X + CONTROL_WIDTH_4 + 50)
70 #define DETAILS_OPT_PAGE_HEIGHT			((CONTROL_HEIGHT + CONTROL_SPACING_Y) * 5)
71 #define DETAILS_MIN_HELP_WIDTH			100
72 #define DETAILS_OPT_HELP_WIDTH			200
73 #define DETAILS_MIN_HELP_HEIGHT			50
74 #define DETAILS_OPT_HELP_HEIGHT			100
75 
76 
77 using namespace dbaui;
78 //==================================================================
79 // class OTableFieldDescWin
80 //==================================================================
81 DBG_NAME(OTableFieldDescWin)
82 //------------------------------------------------------------------------------
83 OTableFieldDescWin::OTableFieldDescWin( Window* pParent)
84 	:TabPage(pParent, WB_3DLOOK)
85 {
86 	DBG_CTOR(OTableFieldDescWin,NULL);
87 	//////////////////////////////////////////////////////////////////////
88 	// Header
89 	m_pHeader = new FixedText( this, WB_CENTER | WB_INFO );	//  | WB_3DLOOK
90 	m_pHeader->SetText( String(ModuleRes(STR_TAB_PROPERTIES)) );
91 	m_pHeader->Show();
92 
93 	//////////////////////////////////////////////////////////////////////
94 	// HelpBar
95 	m_pHelpBar = new OTableDesignHelpBar( this );
96 	m_pHelpBar->SetHelpId(HID_TAB_DESIGN_HELP_TEXT_FRAME);
97 	m_pHelpBar->Show();
98 
99 	m_pGenPage = new OFieldDescGenWin( this, m_pHelpBar );
100 	getGenPage()->SetHelpId( HID_TABLE_DESIGN_TABPAGE_GENERAL );
101 	getGenPage()->Show();
102 }
103 
104 //------------------------------------------------------------------------------
105 OTableFieldDescWin::~OTableFieldDescWin()
106 {
107 	DBG_DTOR(OTableFieldDescWin,NULL);
108 	//////////////////////////////////////////////////////////////////////
109 	// Childs zerstoeren
110 	m_pHelpBar->Hide();
111 	getGenPage()->Hide();
112 	m_pHeader->Hide();
113 
114 	{
115 		::std::auto_ptr<Window> aTemp(m_pGenPage);
116 		m_pGenPage = NULL;
117 	}
118 	{
119 		::std::auto_ptr<Window> aTemp(m_pHeader);
120 		m_pHeader = NULL;
121 	}
122 	{
123 		::std::auto_ptr<Window> aTemp(m_pHelpBar);
124 		m_pHelpBar = NULL;
125 	}
126 }
127 
128 //------------------------------------------------------------------------------
129 void OTableFieldDescWin::Init()
130 {
131 	DBG_ASSERT(getGenPage() != NULL, "OTableFieldDescWin::Init : ups ... no GenericPage ... this will crash ...");
132 	getGenPage()->Init();
133 }
134 
135 //------------------------------------------------------------------------------
136 void OTableFieldDescWin::SetReadOnly( sal_Bool bRead )
137 {
138 	DBG_CHKTHIS(OTableFieldDescWin,NULL);
139 	getGenPage()->SetReadOnly( bRead );
140 }
141 
142 //------------------------------------------------------------------------------
143 void OTableFieldDescWin::DisplayData( OFieldDescription* pFieldDescr )
144 {
145 	DBG_CHKTHIS(OTableFieldDescWin,NULL);
146 	getGenPage()->DisplayData( pFieldDescr );
147 }
148 
149 //------------------------------------------------------------------------------
150 void OTableFieldDescWin::SaveData( OFieldDescription* pFieldDescr )
151 {
152 	DBG_CHKTHIS(OTableFieldDescWin,NULL);
153 	getGenPage()->SaveData( pFieldDescr );
154 }
155 
156 //------------------------------------------------------------------------------
157 void OTableFieldDescWin::Paint( const Rectangle& /*rRect*/ )
158 {
159 	DBG_CHKTHIS(OTableFieldDescWin,NULL);
160 	//////////////////////////////////////////////////////////////////////
161 	// 3D-Linie am oberen Fensterrand
162 	const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
163 
164 	SetLineColor( rStyleSettings.GetLightColor() );
165 	DrawLine( Point(0,0), Point(GetSizePixel().Width(),0) );
166 
167 	//////////////////////////////////////////////////////////////////////
168 	// 3D-Linie zum Abtrennen des Headers
169 	DrawLine( Point(3, DETAILS_HEADER_HEIGHT), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT) );
170 	SetLineColor( rStyleSettings.GetShadowColor() );
171 	DrawLine( Point(3, DETAILS_HEADER_HEIGHT-1), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT-1) );
172 }
173 
174 //------------------------------------------------------------------------------
175 void OTableFieldDescWin::Resize()
176 {
177 	DBG_CHKTHIS(OTableFieldDescWin,NULL);
178 	//////////////////////////////////////////////////////////////////////
179 	// Abmessungen parent window
180 	Size aOutputSize( GetOutputSizePixel() );
181 	long nOutputWidth = aOutputSize.Width();
182 	long nOutputHeight = aOutputSize.Height();
183 
184 	// da die GenPage scrollen kann, ich selber aber nicht, positioniere ich das HelpFenster, wenn ich zu schmal werde,
185 	// _unter_ der Genpage, nicht rechts daneben. Zuvor versuche ich aber noch, es etwas schmaler zu machen
186 
187 	long nHelpX, nHelpY;
188 	long nHelpWidth, nHelpHeight;
189 	long nPageWidth, nPageHeight;
190 
191 	// passen beide nebeneinander (Rand + Page + Rand + Help) ?
192 	if (STANDARD_MARGIN + DETAILS_OPT_PAGE_WIDTH + STANDARD_MARGIN + DETAILS_MIN_HELP_WIDTH <= nOutputWidth)
193 	{	// ja -> dann ist die Frage, ob man der Hilfe ihre Optimal-Breite geben kann
194 		nHelpWidth = DETAILS_OPT_HELP_WIDTH;
195 		nPageWidth = nOutputWidth - nHelpWidth - STANDARD_MARGIN - STANDARD_MARGIN;
196 		if (nPageWidth < DETAILS_OPT_PAGE_WIDTH)
197 		{	// dann doch lieber die Hilfe von ihrer optimalen in Richtung auf die minimale Groesse
198 			long nTransfer = DETAILS_OPT_PAGE_WIDTH - nPageWidth;
199 			nPageWidth += nTransfer;
200 			nHelpWidth -= nTransfer;
201 		}
202 		nHelpX = nOutputWidth - nHelpWidth;
203 		// die Hoehen sind dann einfach ...
204 		nHelpY = DETAILS_HEADER_HEIGHT + 1;
205 		nHelpHeight = nOutputHeight - nHelpY;
206 		nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
207 	}
208 	else
209 	{	// nebeneinander geht nicht, also untereinander (Rand + Header + Page + Help)
210 		if (STANDARD_MARGIN + DETAILS_HEADER_HEIGHT + DETAILS_OPT_PAGE_HEIGHT + DETAILS_MIN_HELP_HEIGHT <= nOutputHeight)
211 		{	// es reicht zumindest, um beide untereinander (Page optimal, Help minimal) unterzubringen
212 			nHelpHeight = DETAILS_OPT_HELP_HEIGHT;
213 			nPageHeight = nOutputHeight - nHelpHeight - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
214 			if (nPageHeight < DETAILS_OPT_PAGE_HEIGHT)
215 			{	// wie oben : Page optimal, Hilfe soviel wie eben bleibt (das ist groesser/gleich ihrem Minimum)
216 				long nTransfer = DETAILS_OPT_PAGE_HEIGHT - nPageHeight;
217 				nPageHeight += nTransfer;
218 				nHelpHeight -= nTransfer;
219 			}
220 			nHelpY = nOutputHeight - nHelpHeight;
221 			// und ueber die ganze Breite
222 			nHelpX = 0;					// ohne Margin, da das HelpCtrl einen eigenen hat
223 			nHelpWidth = nOutputWidth;	// dito
224 			nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
225 		}
226 		else
227 		{	// dummerweise reicht es nicht mal, um Page optimal und Help minimal zu zeigen
228 			nHelpX = nHelpY = nHelpWidth = nHelpHeight = 0;	// -> kein Help-Fenster
229 			nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
230 			nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
231 		}
232 	}
233 
234 	m_pHeader->SetPosSizePixel( Point(0, STANDARD_MARGIN), Size(nOutputWidth, 15) );
235 
236 	getGenPage()->SetPosSizePixel(Point	(	STANDARD_MARGIN,
237 										STANDARD_MARGIN + DETAILS_HEADER_HEIGHT
238 									),
239 							  Size	(	nPageWidth,
240 										nPageHeight
241 									)
242 							 );
243 	if (nHelpHeight)
244 	{
245 		m_pHelpBar->Show();
246 		m_pHelpBar->SetPosSizePixel(Point	(	nHelpX,
247 											nHelpY
248 										),
249 								  Size	(	nHelpWidth,
250 											nHelpHeight
251 										)
252 								 );
253 	}
254 	else
255 	{
256 		m_pHelpBar->Hide();
257 	}
258 	Invalidate();
259 }
260 // -----------------------------------------------------------------------------
261 IClipboardTest* OTableFieldDescWin::getActiveChild() const
262 {
263 	IClipboardTest* pTest = NULL;
264 	switch(m_eChildFocus)
265 	{
266 		case DESCRIPTION:
267 			pTest = getGenPage();
268 			break;
269 		default:
270 			pTest = getHelpBar();
271 			break;
272 	}
273 	return pTest;
274 }
275 // -----------------------------------------------------------------------------
276 sal_Bool OTableFieldDescWin::isCopyAllowed()
277 {
278 	return getActiveChild() && getActiveChild()->isCopyAllowed();
279 }
280 // -----------------------------------------------------------------------------
281 sal_Bool OTableFieldDescWin::isCutAllowed()
282 {
283 	return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isCutAllowed());
284 }
285 // -----------------------------------------------------------------------------
286 sal_Bool OTableFieldDescWin::isPasteAllowed()
287 {
288 	return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isPasteAllowed());
289 }
290 // -----------------------------------------------------------------------------
291 void OTableFieldDescWin::cut()
292 {
293 	if ( getGenPage() && getGenPage()->HasChildPathFocus() )
294 		getGenPage()->cut();
295 }
296 // -----------------------------------------------------------------------------
297 void OTableFieldDescWin::copy()
298 {
299 	if ( getActiveChild() )
300 		getActiveChild()->copy();
301 }
302 // -----------------------------------------------------------------------------
303 void OTableFieldDescWin::paste()
304 {
305 	if ( getGenPage() && getGenPage()->HasChildPathFocus() )
306 		getGenPage()->paste();
307 }
308 // -----------------------------------------------------------------------------
309 void OTableFieldDescWin::GetFocus()
310 {
311 	if ( getGenPage() )
312 		getGenPage()->GetFocus();
313 }
314 // -----------------------------------------------------------------------------
315 void OTableFieldDescWin::LoseFocus()
316 {
317 	if ( getGenPage() )
318 		getGenPage()->LoseFocus();
319 }
320 // -----------------------------------------------------------------------------
321 long OTableFieldDescWin::PreNotify( NotifyEvent& rNEvt )
322 {
323 	sal_Bool bHandled = sal_False;
324 	switch(rNEvt.GetType())
325 	{
326 		case EVENT_GETFOCUS:
327 			if( getGenPage() && getGenPage()->HasChildPathFocus() )
328 				m_eChildFocus = DESCRIPTION;
329 			else
330 				m_eChildFocus = HELP;
331 			break;
332 	}
333 
334 	return bHandled ? 1L : TabPage::PreNotify(rNEvt);
335 }
336 
337 
338