1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "TableFieldDescWin.hxx"
#include <osl/diagnose.h>
#include "FieldDescriptions.hxx"
#include "dbu_tbl.hrc"
#include "TableDesignHelpBar.hxx"
#include <vcl/fixed.hxx>
#include <vcl/settings.hxx>
#include "dbaccess_helpid.hrc"
#include "moduledbu.hxx"
#include <boost/scoped_ptr.hpp>
#define STANDARD_MARGIN 6
#define DETAILS_HEADER_HEIGHT 25
#define CONTROL_SPACING_X 18 // 6
#define CONTROL_SPACING_Y 5
#define CONTROL_HEIGHT 20
#define CONTROL_WIDTH_1 140 // 100
#define CONTROL_WIDTH_3 250
#define CONTROL_WIDTH_4 (CONTROL_WIDTH_3 - CONTROL_HEIGHT - 5)
#define DETAILS_OPT_PAGE_WIDTH (CONTROL_WIDTH_1 + CONTROL_SPACING_X + CONTROL_WIDTH_4 + 50)
#define DETAILS_OPT_PAGE_HEIGHT ((CONTROL_HEIGHT + CONTROL_SPACING_Y) * 5)
#define DETAILS_MIN_HELP_WIDTH 100
#define DETAILS_OPT_HELP_WIDTH 200
#define DETAILS_MIN_HELP_HEIGHT 50
#define DETAILS_OPT_HELP_HEIGHT 100
using namespace dbaui;
// class OTableFieldDescWin
OTableFieldDescWin::OTableFieldDescWin( Window* pParent)
: TabPage(pParent, WB_3DLOOK)
, m_eChildFocus(NONE)
{
// Header
m_pHeader = new FixedText( this, WB_CENTER | WB_INFO ); // | WB_3DLOOK
m_pHeader->SetText( OUString(ModuleRes(STR_TAB_PROPERTIES)) );
m_pHeader->Show();
// HelpBar
m_pHelpBar = new OTableDesignHelpBar( this );
m_pHelpBar->SetHelpId(HID_TAB_DESIGN_HELP_TEXT_FRAME);
m_pHelpBar->Show();
m_pGenPage = new OFieldDescGenWin( this, m_pHelpBar );
getGenPage()->SetHelpId( HID_TABLE_DESIGN_TABPAGE_GENERAL );
getGenPage()->Show();
}
OTableFieldDescWin::~OTableFieldDescWin()
{
// destroy children
m_pHelpBar->Hide();
getGenPage()->Hide();
m_pHeader->Hide();
{
boost::scoped_ptr<Window> aTemp(m_pGenPage);
m_pGenPage = NULL;
}
{
boost::scoped_ptr<Window> aTemp(m_pHeader);
m_pHeader = NULL;
}
{
boost::scoped_ptr<Window> aTemp(m_pHelpBar);
m_pHelpBar = NULL;
}
}
void OTableFieldDescWin::Init()
{
OSL_ENSURE(getGenPage() != NULL, "OTableFieldDescWin::Init : ups ... no GenericPage ... this will crash ...");
getGenPage()->Init();
}
void OTableFieldDescWin::SetReadOnly( bool bRead )
{
getGenPage()->SetReadOnly( bRead );
}
void OTableFieldDescWin::DisplayData( OFieldDescription* pFieldDescr )
{
getGenPage()->DisplayData( pFieldDescr );
}
void OTableFieldDescWin::SaveData( OFieldDescription* pFieldDescr )
{
getGenPage()->SaveData( pFieldDescr );
}
void OTableFieldDescWin::Paint( const Rectangle& /*rRect*/ )
{
// 3D-line at the top window border
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
SetLineColor( rStyleSettings.GetLightColor() );
DrawLine( Point(0,0), Point(GetSizePixel().Width(),0) );
// 3D-line for the separation of the header
DrawLine( Point(3, DETAILS_HEADER_HEIGHT), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT) );
SetLineColor( rStyleSettings.GetShadowColor() );
DrawLine( Point(3, DETAILS_HEADER_HEIGHT-1), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT-1) );
}
void OTableFieldDescWin::Resize()
{
// dimensions of the parent window
Size aOutputSize( GetOutputSizePixel() );
long nOutputWidth = aOutputSize.Width();
long nOutputHeight = aOutputSize.Height();
// since the GenPage can scroll, but I can't, I position the HelpWindow, in case I become too slim,
// _below_ the Genpage, not on the right side. But before that I try to make it a bit smaller
long nHelpX, nHelpY;
long nHelpWidth, nHelpHeight;
long nPageWidth, nPageHeight;
// do both fit next to each other (margin + page + margin + help)?
if (STANDARD_MARGIN + DETAILS_OPT_PAGE_WIDTH + STANDARD_MARGIN + DETAILS_MIN_HELP_WIDTH <= nOutputWidth)
{ // yes -> then we wonder if can give the help its optimum width
nHelpWidth = DETAILS_OPT_HELP_WIDTH;
nPageWidth = nOutputWidth - nHelpWidth - STANDARD_MARGIN - STANDARD_MARGIN;
if (nPageWidth < DETAILS_OPT_PAGE_WIDTH)
{ // rather resize the help from its optimal width to its minimum width
long nTransfer = DETAILS_OPT_PAGE_WIDTH - nPageWidth;
nPageWidth += nTransfer;
nHelpWidth -= nTransfer;
}
nHelpX = nOutputWidth - nHelpWidth;
// the heights are simple in that case...
nHelpY = DETAILS_HEADER_HEIGHT + 1;
nHelpHeight = nOutputHeight - nHelpY;
nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
}
else
{ // doesn't work next to each other, thus below each other (margin + header + page + help)
if (STANDARD_MARGIN + DETAILS_HEADER_HEIGHT + DETAILS_OPT_PAGE_HEIGHT + DETAILS_MIN_HELP_HEIGHT <= nOutputHeight)
{ // it's at least enough, to fit both below each other (page optimal, help minimal)
nHelpHeight = DETAILS_OPT_HELP_HEIGHT;
nPageHeight = nOutputHeight - nHelpHeight - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
if (nPageHeight < DETAILS_OPT_PAGE_HEIGHT)
{ // like above: page optimal, help gets whatever is left (which is bigger/equal to its minimum)
long nTransfer = DETAILS_OPT_PAGE_HEIGHT - nPageHeight;
nPageHeight += nTransfer;
nHelpHeight -= nTransfer;
}
nHelpY = nOutputHeight - nHelpHeight;
// and across the entire width
nHelpX = 0; // without margin, since the HelpCtrl has its own one
nHelpWidth = nOutputWidth; // dito
nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
}
else
{ // unfortunately that's not even enough, to show page at its optimum and help with minimum widthn
nHelpX = nHelpY = nHelpWidth = nHelpHeight = 0; // thus no help window
nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
}
}
m_pHeader->SetPosSizePixel( Point(0, STANDARD_MARGIN), Size(nOutputWidth, 15) );
getGenPage()->SetPosSizePixel(Point ( STANDARD_MARGIN,
STANDARD_MARGIN + DETAILS_HEADER_HEIGHT
),
Size ( nPageWidth,
nPageHeight
)
);
if (nHelpHeight)
{
m_pHelpBar->Show();
m_pHelpBar->SetPosSizePixel(Point ( nHelpX,
nHelpY
),
Size ( nHelpWidth,
nHelpHeight
)
);
}
else
{
m_pHelpBar->Hide();
}
Invalidate();
}
IClipboardTest* OTableFieldDescWin::getActiveChild() const
{
IClipboardTest* pTest = NULL;
switch(m_eChildFocus)
{
case DESCRIPTION:
pTest = getGenPage();
break;
default:
pTest = getHelpBar();
break;
}
return pTest;
}
bool OTableFieldDescWin::isCopyAllowed()
{
return getActiveChild() && getActiveChild()->isCopyAllowed();
}
bool OTableFieldDescWin::isCutAllowed()
{
return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isCutAllowed());
}
bool OTableFieldDescWin::isPasteAllowed()
{
return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isPasteAllowed());
}
void OTableFieldDescWin::cut()
{
if ( getGenPage() && getGenPage()->HasChildPathFocus() )
getGenPage()->cut();
}
void OTableFieldDescWin::copy()
{
if ( getActiveChild() )
getActiveChild()->copy();
}
void OTableFieldDescWin::paste()
{
if ( getGenPage() && getGenPage()->HasChildPathFocus() )
getGenPage()->paste();
}
void OTableFieldDescWin::GetFocus()
{
if ( getGenPage() )
getGenPage()->GetFocus();
}
void OTableFieldDescWin::LoseFocus()
{
if ( getGenPage() )
getGenPage()->LoseFocus();
}
bool OTableFieldDescWin::PreNotify( NotifyEvent& rNEvt )
{
bool bHandled = false;
switch(rNEvt.GetType())
{
case EVENT_GETFOCUS:
if( getGenPage() && getGenPage()->HasChildPathFocus() )
m_eChildFocus = DESCRIPTION;
else
m_eChildFocus = HELP;
break;
}
return bHandled || TabPage::PreNotify(rNEvt);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|