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