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 #include "TableFieldDescWin.hxx"
21 #include <osl/diagnose.h>
22 #include <FieldDescriptions.hxx>
23 #include <strings.hrc>
24 #include <TableDesignHelpBar.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/fixed.hxx>
27 #include <vcl/settings.hxx>
28 #include <helpids.h>
29 #include <core_resource.hxx>
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_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
45 
46 using namespace dbaui;
47 // class OTableFieldDescWin
OTableFieldDescWin(vcl::Window * pParent)48 OTableFieldDescWin::OTableFieldDescWin( vcl::Window* pParent)
49     : TabPage(pParent, WB_3DLOOK)
50     , m_eChildFocus(NONE)
51 {
52     // Header
53     m_pHeader = VclPtr<FixedText>::Create( this, WB_CENTER );
54     m_pHeader->SetText(DBA_RES(STR_TAB_PROPERTIES));
55     m_pHeader->Show();
56 
57     // HelpBar
58     m_pHelpBar = VclPtr<OTableDesignHelpBar>::Create( this );
59     m_pHelpBar->SetHelpId(HID_TAB_DESIGN_HELP_TEXT_FRAME);
60     m_pHelpBar->Show();
61 
62     m_pGenPage = VclPtr<OFieldDescGenWin>::Create( this, m_pHelpBar );
63     getGenPage()->SetHelpId( HID_TABLE_DESIGN_TABPAGE_GENERAL );
64     getGenPage()->Show();
65 }
66 
~OTableFieldDescWin()67 OTableFieldDescWin::~OTableFieldDescWin()
68 {
69     disposeOnce();
70 }
71 
dispose()72 void OTableFieldDescWin::dispose()
73 {
74     // destroy children
75     m_pHelpBar->Hide();
76     getGenPage()->Hide();
77     m_pHeader->Hide();
78 
79     m_pGenPage.disposeAndClear();
80     m_pHeader.disposeAndClear();
81     m_pHelpBar.disposeAndClear();
82     TabPage::dispose();
83 }
84 
Init()85 void OTableFieldDescWin::Init()
86 {
87     OSL_ENSURE(getGenPage() != nullptr, "OTableFieldDescWin::Init : ups ... no GenericPage ... this will crash ...");
88     getGenPage()->Init();
89 }
90 
SetReadOnly(bool bRead)91 void OTableFieldDescWin::SetReadOnly( bool bRead )
92 {
93     getGenPage()->SetReadOnly( bRead );
94 }
95 
DisplayData(OFieldDescription * pFieldDescr)96 void OTableFieldDescWin::DisplayData( OFieldDescription* pFieldDescr )
97 {
98     getGenPage()->DisplayData( pFieldDescr );
99 }
100 
SaveData(OFieldDescription * pFieldDescr)101 void OTableFieldDescWin::SaveData( OFieldDescription* pFieldDescr )
102 {
103     getGenPage()->SaveData( pFieldDescr );
104 }
105 
Paint(vcl::RenderContext & rRenderContext,const tools::Rectangle &)106 void OTableFieldDescWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
107 {
108     // 3D-line at the top window border
109     const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
110 
111     rRenderContext.SetLineColor(rStyleSettings.GetLightColor());
112     rRenderContext.DrawLine(Point(0,0), Point(GetSizePixel().Width(), 0));
113 
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));
118 }
119 
Resize()120 void OTableFieldDescWin::Resize()
121 {
122     // dimensions of the parent window
123     Size aOutputSize( GetOutputSizePixel() );
124     long nOutputWidth = aOutputSize.Width();
125     long nOutputHeight = aOutputSize.Height();
126 
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
129 
130     long nHelpX, nHelpY;
131     long nHelpWidth, nHelpHeight;
132     long nPageWidth, nPageHeight;
133 
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;
144         }
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;
150     }
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;
162             }
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;
168         }
169         else
170         {   // unfortunately that's not even enough, to show page at its optimum and help with minimum width
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;
174         }
175     }
176 
177     m_pHeader->SetPosSizePixel( Point(0, STANDARD_MARGIN), Size(nOutputWidth, 15) );
178 
179     getGenPage()->SetPosSizePixel(Point (   STANDARD_MARGIN,
180                                         STANDARD_MARGIN + DETAILS_HEADER_HEIGHT
181                                     ),
182                               Size  (   nPageWidth,
183                                         nPageHeight
184                                     )
185                              );
186     if (nHelpHeight)
187     {
188         m_pHelpBar->Show();
189         m_pHelpBar->SetPosSizePixel(Point   (   nHelpX,
190                                             nHelpY
191                                         ),
192                                   Size  (   nHelpWidth,
193                                             nHelpHeight
194                                         )
195                                  );
196     }
197     else
198     {
199         m_pHelpBar->Hide();
200     }
201     Invalidate();
202 }
203 
getActiveChild() const204 IClipboardTest* OTableFieldDescWin::getActiveChild() const
205 {
206     IClipboardTest* pTest = nullptr;
207     switch(m_eChildFocus)
208     {
209         case DESCRIPTION:
210             pTest = getGenPage();
211             break;
212         default:
213             pTest = m_pHelpBar;
214             break;
215     }
216     return pTest;
217 }
218 
isCopyAllowed()219 bool OTableFieldDescWin::isCopyAllowed()
220 {
221     return getActiveChild() && getActiveChild()->isCopyAllowed();
222 }
223 
isCutAllowed()224 bool OTableFieldDescWin::isCutAllowed()
225 {
226     return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isCutAllowed());
227 }
228 
isPasteAllowed()229 bool OTableFieldDescWin::isPasteAllowed()
230 {
231     return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isPasteAllowed());
232 }
233 
cut()234 void OTableFieldDescWin::cut()
235 {
236     if ( getGenPage() && getGenPage()->HasChildPathFocus() )
237         getGenPage()->cut();
238 }
239 
copy()240 void OTableFieldDescWin::copy()
241 {
242     if ( getActiveChild() )
243         getActiveChild()->copy();
244 }
245 
paste()246 void OTableFieldDescWin::paste()
247 {
248     if ( getGenPage() && getGenPage()->HasChildPathFocus() )
249         getGenPage()->paste();
250 }
251 
GetFocus()252 void OTableFieldDescWin::GetFocus()
253 {
254     if ( getGenPage() )
255         getGenPage()->GetFocus();
256 }
257 
LoseFocus()258 void OTableFieldDescWin::LoseFocus()
259 {
260     if ( getGenPage() )
261         getGenPage()->LoseFocus();
262 }
263 
PreNotify(NotifyEvent & rNEvt)264 bool OTableFieldDescWin::PreNotify( NotifyEvent& rNEvt )
265 {
266     if (rNEvt.GetType() == MouseNotifyEvent::GETFOCUS)
267     {
268         if( getGenPage() && getGenPage()->HasChildPathFocus() )
269             m_eChildFocus = DESCRIPTION;
270         else
271             m_eChildFocus = HELP;
272     }
273     return TabPage::PreNotify(rNEvt);
274 }
275 
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
277