fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / tabledesign / TableFieldDescWin.cxx
blob0c38e1e88b8036d88a68beee50a53f2d900feebd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "TableFieldDescWin.hxx"
21 #include <osl/diagnose.h>
22 #include "FieldDescriptions.hxx"
23 #include "dbu_tbl.hrc"
24 #include "TableDesignHelpBar.hxx"
25 #include <vcl/fixed.hxx>
26 #include <vcl/settings.hxx>
27 #include "dbaccess_helpid.hrc"
28 #include "moduledbu.hxx"
29 #include <boost/scoped_ptr.hpp>
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
46 using namespace dbaui;
47 // class OTableFieldDescWin
48 OTableFieldDescWin::OTableFieldDescWin( vcl::Window* pParent)
49 : TabPage(pParent, WB_3DLOOK)
50 , m_eChildFocus(NONE)
52 // Header
53 m_pHeader = VclPtr<FixedText>::Create( this, WB_CENTER | WB_INFO );
54 m_pHeader->SetText( OUString(ModuleRes(STR_TAB_PROPERTIES)) );
55 m_pHeader->Show();
57 // HelpBar
58 m_pHelpBar = VclPtr<OTableDesignHelpBar>::Create( this );
59 m_pHelpBar->SetHelpId(HID_TAB_DESIGN_HELP_TEXT_FRAME);
60 m_pHelpBar->Show();
62 m_pGenPage = VclPtr<OFieldDescGenWin>::Create( this, m_pHelpBar );
63 getGenPage()->SetHelpId( HID_TABLE_DESIGN_TABPAGE_GENERAL );
64 getGenPage()->Show();
67 OTableFieldDescWin::~OTableFieldDescWin()
69 disposeOnce();
72 void OTableFieldDescWin::dispose()
74 // destroy children
75 m_pHelpBar->Hide();
76 getGenPage()->Hide();
77 m_pHeader->Hide();
79 m_pGenPage.disposeAndClear();
80 m_pHeader.disposeAndClear();
81 m_pHelpBar.disposeAndClear();
82 TabPage::dispose();
85 void OTableFieldDescWin::Init()
87 OSL_ENSURE(getGenPage() != NULL, "OTableFieldDescWin::Init : ups ... no GenericPage ... this will crash ...");
88 getGenPage()->Init();
91 void OTableFieldDescWin::SetReadOnly( bool bRead )
93 getGenPage()->SetReadOnly( bRead );
96 void OTableFieldDescWin::DisplayData( OFieldDescription* pFieldDescr )
98 getGenPage()->DisplayData( pFieldDescr );
101 void OTableFieldDescWin::SaveData( OFieldDescription* pFieldDescr )
103 getGenPage()->SaveData( pFieldDescr );
106 void OTableFieldDescWin::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/)
108 // 3D-line at the top window border
109 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
111 rRenderContext.SetLineColor(rStyleSettings.GetLightColor());
112 rRenderContext.DrawLine(Point(0,0), Point(GetSizePixel().Width(), 0));
114 // 3D-line for the separation of the header
115 rRenderContext.DrawLine(Point(3, DETAILS_HEADER_HEIGHT), Point(GetSizePixel().Width() - 6, DETAILS_HEADER_HEIGHT));
116 rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
117 rRenderContext.DrawLine(Point(3, DETAILS_HEADER_HEIGHT - 1), Point(GetSizePixel().Width() - 6, DETAILS_HEADER_HEIGHT - 1));
120 void OTableFieldDescWin::Resize()
122 // dimensions of the parent window
123 Size aOutputSize( GetOutputSizePixel() );
124 long nOutputWidth = aOutputSize.Width();
125 long nOutputHeight = aOutputSize.Height();
127 // since the GenPage can scroll, but I can't, I position the HelpWindow, in case I become too slim,
128 // _below_ the Genpage, not on the right side. But before that I try to make it a bit smaller
130 long nHelpX, nHelpY;
131 long nHelpWidth, nHelpHeight;
132 long nPageWidth, nPageHeight;
134 // do both fit next to each other (margin + page + margin + help)?
135 if (STANDARD_MARGIN + DETAILS_OPT_PAGE_WIDTH + STANDARD_MARGIN + DETAILS_MIN_HELP_WIDTH <= nOutputWidth)
136 { // yes -> then we wonder if can give the help its optimum width
137 nHelpWidth = DETAILS_OPT_HELP_WIDTH;
138 nPageWidth = nOutputWidth - nHelpWidth - STANDARD_MARGIN - STANDARD_MARGIN;
139 if (nPageWidth < DETAILS_OPT_PAGE_WIDTH)
140 { // rather resize the help from its optimal width to its minimum width
141 long nTransfer = DETAILS_OPT_PAGE_WIDTH - nPageWidth;
142 nPageWidth += nTransfer;
143 nHelpWidth -= nTransfer;
145 nHelpX = nOutputWidth - nHelpWidth;
146 // the heights are simple in that case...
147 nHelpY = DETAILS_HEADER_HEIGHT + 1;
148 nHelpHeight = nOutputHeight - nHelpY;
149 nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
151 else
152 { // doesn't work next to each other, thus below each other (margin + header + page + help)
153 if (STANDARD_MARGIN + DETAILS_HEADER_HEIGHT + DETAILS_OPT_PAGE_HEIGHT + DETAILS_MIN_HELP_HEIGHT <= nOutputHeight)
154 { // it's at least enough, to fit both below each other (page optimal, help minimal)
155 nHelpHeight = DETAILS_OPT_HELP_HEIGHT;
156 nPageHeight = nOutputHeight - nHelpHeight - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
157 if (nPageHeight < DETAILS_OPT_PAGE_HEIGHT)
158 { // like above: page optimal, help gets whatever is left (which is bigger/equal to its minimum)
159 long nTransfer = DETAILS_OPT_PAGE_HEIGHT - nPageHeight;
160 nPageHeight += nTransfer;
161 nHelpHeight -= nTransfer;
163 nHelpY = nOutputHeight - nHelpHeight;
164 // and across the entire width
165 nHelpX = 0; // without margin, since the HelpCtrl has its own one
166 nHelpWidth = nOutputWidth; // dito
167 nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
169 else
170 { // unfortunately that's not even enough, to show page at its optimum and help with minimum widthn
171 nHelpX = nHelpY = nHelpWidth = nHelpHeight = 0; // thus no help window
172 nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
173 nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
177 m_pHeader->SetPosSizePixel( Point(0, STANDARD_MARGIN), Size(nOutputWidth, 15) );
179 getGenPage()->SetPosSizePixel(Point ( STANDARD_MARGIN,
180 STANDARD_MARGIN + DETAILS_HEADER_HEIGHT
182 Size ( nPageWidth,
183 nPageHeight
186 if (nHelpHeight)
188 m_pHelpBar->Show();
189 m_pHelpBar->SetPosSizePixel(Point ( nHelpX,
190 nHelpY
192 Size ( nHelpWidth,
193 nHelpHeight
197 else
199 m_pHelpBar->Hide();
201 Invalidate();
204 IClipboardTest* OTableFieldDescWin::getActiveChild() const
206 IClipboardTest* pTest = NULL;
207 switch(m_eChildFocus)
209 case DESCRIPTION:
210 pTest = getGenPage();
211 break;
212 default:
213 pTest = getHelpBar();
214 break;
216 return pTest;
219 bool OTableFieldDescWin::isCopyAllowed()
221 return getActiveChild() && getActiveChild()->isCopyAllowed();
224 bool OTableFieldDescWin::isCutAllowed()
226 return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isCutAllowed());
229 bool OTableFieldDescWin::isPasteAllowed()
231 return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isPasteAllowed());
234 void OTableFieldDescWin::cut()
236 if ( getGenPage() && getGenPage()->HasChildPathFocus() )
237 getGenPage()->cut();
240 void OTableFieldDescWin::copy()
242 if ( getActiveChild() )
243 getActiveChild()->copy();
246 void OTableFieldDescWin::paste()
248 if ( getGenPage() && getGenPage()->HasChildPathFocus() )
249 getGenPage()->paste();
252 void OTableFieldDescWin::GetFocus()
254 if ( getGenPage() )
255 getGenPage()->GetFocus();
258 void OTableFieldDescWin::LoseFocus()
260 if ( getGenPage() )
261 getGenPage()->LoseFocus();
264 bool OTableFieldDescWin::PreNotify( NotifyEvent& rNEvt )
266 bool bHandled = false;
267 if (rNEvt.GetType() == MouseNotifyEvent::GETFOCUS)
269 if( getGenPage() && getGenPage()->HasChildPathFocus() )
270 m_eChildFocus = DESCRIPTION;
271 else
272 m_eChildFocus = HELP;
274 return bHandled || TabPage::PreNotify(rNEvt);
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */