LCOV - code coverage report
Current view: top level - dbaccess/source/ui/tabledesign - TableFieldDescWin.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 125 0.8 %
Date: 2015-06-13 12:38:46 Functions: 2 22 9.1 %
Legend: Lines: hit not hit

          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             : #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>
      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
      48           0 : OTableFieldDescWin::OTableFieldDescWin( vcl::Window* pParent)
      49             :     : TabPage(pParent, WB_3DLOOK)
      50           0 :     , m_eChildFocus(NONE)
      51             : {
      52             :     // Header
      53           0 :     m_pHeader = VclPtr<FixedText>::Create( this, WB_CENTER | WB_INFO );
      54           0 :     m_pHeader->SetText( OUString(ModuleRes(STR_TAB_PROPERTIES)) );
      55           0 :     m_pHeader->Show();
      56             : 
      57             :     // HelpBar
      58           0 :     m_pHelpBar = VclPtr<OTableDesignHelpBar>::Create( this );
      59           0 :     m_pHelpBar->SetHelpId(HID_TAB_DESIGN_HELP_TEXT_FRAME);
      60           0 :     m_pHelpBar->Show();
      61             : 
      62           0 :     m_pGenPage = VclPtr<OFieldDescGenWin>::Create( this, m_pHelpBar );
      63           0 :     getGenPage()->SetHelpId( HID_TABLE_DESIGN_TABPAGE_GENERAL );
      64           0 :     getGenPage()->Show();
      65           0 : }
      66             : 
      67           0 : OTableFieldDescWin::~OTableFieldDescWin()
      68             : {
      69           0 :     disposeOnce();
      70           0 : }
      71             : 
      72           0 : void OTableFieldDescWin::dispose()
      73             : {
      74             :     // destroy children
      75           0 :     m_pHelpBar->Hide();
      76           0 :     getGenPage()->Hide();
      77           0 :     m_pHeader->Hide();
      78             : 
      79           0 :     m_pGenPage.disposeAndClear();
      80           0 :     m_pHeader.disposeAndClear();
      81           0 :     m_pHelpBar.disposeAndClear();
      82           0 :     TabPage::dispose();
      83           0 : }
      84             : 
      85           0 : void OTableFieldDescWin::Init()
      86             : {
      87             :     OSL_ENSURE(getGenPage() != NULL, "OTableFieldDescWin::Init : ups ... no GenericPage ... this will crash ...");
      88           0 :     getGenPage()->Init();
      89           0 : }
      90             : 
      91           0 : void OTableFieldDescWin::SetReadOnly( bool bRead )
      92             : {
      93           0 :     getGenPage()->SetReadOnly( bRead );
      94           0 : }
      95             : 
      96           0 : void OTableFieldDescWin::DisplayData( OFieldDescription* pFieldDescr )
      97             : {
      98           0 :     getGenPage()->DisplayData( pFieldDescr );
      99           0 : }
     100             : 
     101           0 : void OTableFieldDescWin::SaveData( OFieldDescription* pFieldDescr )
     102             : {
     103           0 :     getGenPage()->SaveData( pFieldDescr );
     104           0 : }
     105             : 
     106           0 : void OTableFieldDescWin::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/)
     107             : {
     108             :     // 3D-line at the top window border
     109           0 :     const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
     110             : 
     111           0 :     rRenderContext.SetLineColor(rStyleSettings.GetLightColor());
     112           0 :     rRenderContext.DrawLine(Point(0,0), Point(GetSizePixel().Width(), 0));
     113             : 
     114             :     // 3D-line for the separation of the header
     115           0 :     rRenderContext.DrawLine(Point(3, DETAILS_HEADER_HEIGHT), Point(GetSizePixel().Width() - 6, DETAILS_HEADER_HEIGHT));
     116           0 :     rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
     117           0 :     rRenderContext.DrawLine(Point(3, DETAILS_HEADER_HEIGHT - 1), Point(GetSizePixel().Width() - 6, DETAILS_HEADER_HEIGHT - 1));
     118           0 : }
     119             : 
     120           0 : void OTableFieldDescWin::Resize()
     121             : {
     122             :     // dimensions of the parent window
     123           0 :     Size aOutputSize( GetOutputSizePixel() );
     124           0 :     long nOutputWidth = aOutputSize.Width();
     125           0 :     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           0 :     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           0 :         nHelpWidth = DETAILS_OPT_HELP_WIDTH;
     138           0 :         nPageWidth = nOutputWidth - nHelpWidth - STANDARD_MARGIN - STANDARD_MARGIN;
     139           0 :         if (nPageWidth < DETAILS_OPT_PAGE_WIDTH)
     140             :         {   // rather resize the help from its optimal width to its minimum width
     141           0 :             long nTransfer = DETAILS_OPT_PAGE_WIDTH - nPageWidth;
     142           0 :             nPageWidth += nTransfer;
     143           0 :             nHelpWidth -= nTransfer;
     144             :         }
     145           0 :         nHelpX = nOutputWidth - nHelpWidth;
     146             :         // the heights are simple in that case...
     147           0 :         nHelpY = DETAILS_HEADER_HEIGHT + 1;
     148           0 :         nHelpHeight = nOutputHeight - nHelpY;
     149           0 :         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           0 :         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           0 :             nHelpHeight = DETAILS_OPT_HELP_HEIGHT;
     156           0 :             nPageHeight = nOutputHeight - nHelpHeight - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
     157           0 :             if (nPageHeight < DETAILS_OPT_PAGE_HEIGHT)
     158             :             {   // like above: page optimal, help gets whatever is left (which is bigger/equal to its minimum)
     159           0 :                 long nTransfer = DETAILS_OPT_PAGE_HEIGHT - nPageHeight;
     160           0 :                 nPageHeight += nTransfer;
     161           0 :                 nHelpHeight -= nTransfer;
     162             :             }
     163           0 :             nHelpY = nOutputHeight - nHelpHeight;
     164             :             // and across the entire width
     165           0 :             nHelpX = 0;                 // without margin, since the HelpCtrl has its own one
     166           0 :             nHelpWidth = nOutputWidth;  // dito
     167           0 :             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 widthn
     171           0 :             nHelpX = nHelpY = nHelpWidth = nHelpHeight = 0; // thus no help window
     172           0 :             nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN;
     173           0 :             nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN;
     174             :         }
     175             :     }
     176             : 
     177           0 :     m_pHeader->SetPosSizePixel( Point(0, STANDARD_MARGIN), Size(nOutputWidth, 15) );
     178             : 
     179           0 :     getGenPage()->SetPosSizePixel(Point (   STANDARD_MARGIN,
     180             :                                         STANDARD_MARGIN + DETAILS_HEADER_HEIGHT
     181             :                                     ),
     182             :                               Size  (   nPageWidth,
     183             :                                         nPageHeight
     184             :                                     )
     185           0 :                              );
     186           0 :     if (nHelpHeight)
     187             :     {
     188           0 :         m_pHelpBar->Show();
     189           0 :         m_pHelpBar->SetPosSizePixel(Point   (   nHelpX,
     190             :                                             nHelpY
     191             :                                         ),
     192             :                                   Size  (   nHelpWidth,
     193             :                                             nHelpHeight
     194             :                                         )
     195           0 :                                  );
     196             :     }
     197             :     else
     198             :     {
     199           0 :         m_pHelpBar->Hide();
     200             :     }
     201           0 :     Invalidate();
     202           0 : }
     203             : 
     204           0 : IClipboardTest* OTableFieldDescWin::getActiveChild() const
     205             : {
     206           0 :     IClipboardTest* pTest = NULL;
     207           0 :     switch(m_eChildFocus)
     208             :     {
     209             :         case DESCRIPTION:
     210           0 :             pTest = getGenPage();
     211           0 :             break;
     212             :         default:
     213           0 :             pTest = getHelpBar();
     214           0 :             break;
     215             :     }
     216           0 :     return pTest;
     217             : }
     218             : 
     219           0 : bool OTableFieldDescWin::isCopyAllowed()
     220             : {
     221           0 :     return getActiveChild() && getActiveChild()->isCopyAllowed();
     222             : }
     223             : 
     224           0 : bool OTableFieldDescWin::isCutAllowed()
     225             : {
     226           0 :     return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isCutAllowed());
     227             : }
     228             : 
     229           0 : bool OTableFieldDescWin::isPasteAllowed()
     230             : {
     231           0 :     return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isPasteAllowed());
     232             : }
     233             : 
     234           0 : void OTableFieldDescWin::cut()
     235             : {
     236           0 :     if ( getGenPage() && getGenPage()->HasChildPathFocus() )
     237           0 :         getGenPage()->cut();
     238           0 : }
     239             : 
     240           0 : void OTableFieldDescWin::copy()
     241             : {
     242           0 :     if ( getActiveChild() )
     243           0 :         getActiveChild()->copy();
     244           0 : }
     245             : 
     246           0 : void OTableFieldDescWin::paste()
     247             : {
     248           0 :     if ( getGenPage() && getGenPage()->HasChildPathFocus() )
     249           0 :         getGenPage()->paste();
     250           0 : }
     251             : 
     252           0 : void OTableFieldDescWin::GetFocus()
     253             : {
     254           0 :     if ( getGenPage() )
     255           0 :         getGenPage()->GetFocus();
     256           0 : }
     257             : 
     258           0 : void OTableFieldDescWin::LoseFocus()
     259             : {
     260           0 :     if ( getGenPage() )
     261           0 :         getGenPage()->LoseFocus();
     262           0 : }
     263             : 
     264           0 : bool OTableFieldDescWin::PreNotify( NotifyEvent& rNEvt )
     265             : {
     266           0 :     bool bHandled = false;
     267           0 :     if (rNEvt.GetType() == MouseNotifyEvent::GETFOCUS)
     268             :     {
     269           0 :         if( getGenPage() && getGenPage()->HasChildPathFocus() )
     270           0 :             m_eChildFocus = DESCRIPTION;
     271             :         else
     272           0 :             m_eChildFocus = HELP;
     273             :     }
     274           0 :     return bHandled || TabPage::PreNotify(rNEvt);
     275          36 : }
     276             : 
     277             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11