LCOV - code coverage report
Current view: top level - extensions/source/bibliography - general.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 409 0.2 %
Date: 2015-06-13 12:38:46 Functions: 2 27 7.4 %
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 <comphelper/processfactory.hxx>
      21             : #include <com/sun/star/awt/PosSize.hpp>
      22             : #include <com/sun/star/sdbc/XRowSet.hpp>
      23             : #include <com/sun/star/sdb/XColumn.hpp>
      24             : #include <com/sun/star/sdb/CommandType.hpp>
      25             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      26             : #include <com/sun/star/awt/XWindow.hpp>
      27             : #include <toolkit/helper/vclunohelper.hxx>
      28             : #include <cppuhelper/implbase1.hxx>
      29             : #include <vcl/builder.hxx>
      30             : #include <vcl/settings.hxx>
      31             : #include "general.hxx"
      32             : #include "bibresid.hxx"
      33             : #include "datman.hxx"
      34             : #include "bibconfig.hxx"
      35             : #include "bibprop.hrc"
      36             : #include "bib.hrc"
      37             : #include "bibmod.hxx"
      38             : #include "bibview.hxx"
      39             : #include "bibtools.hxx"
      40             : #include "bibliography.hrc"
      41             : #include <tools/debug.hxx>
      42             : #include <vcl/svapp.hxx>
      43             : #include <vcl/i18nhelp.hxx>
      44             : #include <vcl/mnemonic.hxx>
      45             : #include <algorithm>
      46             : #include <functional>
      47             : #include <vector>
      48             : #include <tools/urlobj.hxx>
      49             : 
      50             : using namespace ::com::sun::star;
      51             : using namespace ::com::sun::star::uno;
      52             : using namespace ::com::sun::star::form;
      53             : using namespace ::com::sun::star::sdb;
      54             : 
      55           0 : static OUString lcl_GetColumnName( const Mapping* pMapping, sal_uInt16 nIndexPos )
      56             : {
      57           0 :     BibConfig* pBibConfig = BibModul::GetConfig();
      58           0 :     OUString sRet = pBibConfig->GetDefColumnName(nIndexPos);
      59           0 :     if(pMapping)
      60           0 :         for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
      61             :         {
      62           0 :             if(pMapping->aColumnPairs[i].sLogicalColumnName == sRet)
      63             :             {
      64           0 :                 sRet = pMapping->aColumnPairs[i].sRealColumnName;
      65           0 :                 break;
      66             :             }
      67             :         }
      68           0 :     return sRet;
      69             : }
      70             : 
      71           0 : class BibPosListener    :public cppu::WeakImplHelper1 <sdbc::XRowSetListener>
      72             : {
      73             :     VclPtr<BibGeneralPage>     pParentPage;
      74             : public:
      75             :     BibPosListener(BibGeneralPage* pParent);
      76             : 
      77             :     //XPositioningListener
      78             :     virtual void SAL_CALL cursorMoved(const lang::EventObject& event) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      79           0 :     virtual void SAL_CALL rowChanged(const lang::EventObject& /*event*/) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE { /* not interested in */ }
      80           0 :     virtual void SAL_CALL rowSetChanged(const lang::EventObject& /*event*/) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE { /* not interested in */ }
      81             : 
      82             :     //XEventListener
      83             :     virtual void SAL_CALL disposing(const lang::EventObject& Source) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      84             : 
      85             : };
      86             : 
      87           0 : BibPosListener::BibPosListener(BibGeneralPage* pParent) :
      88           0 :     pParentPage(pParent)
      89             : {
      90           0 : }
      91             : 
      92           0 : void BibPosListener::cursorMoved(const lang::EventObject& /*aEvent*/) throw( uno::RuntimeException, std::exception )
      93             : {
      94             :     try
      95             :     {
      96           0 :         uno::Reference< form::XBoundComponent >  xLstBox = pParentPage->GetTypeListBoxModel();
      97           0 :         uno::Reference< beans::XPropertySet >  xPropSet(xLstBox, UNO_QUERY);
      98           0 :         if(xPropSet.is())
      99             :         {
     100           0 :             BibConfig* pBibConfig = BibModul::GetConfig();
     101           0 :             BibDataManager* pDatMan = pParentPage->GetDataManager();
     102           0 :             BibDBDescriptor aDesc;
     103           0 :             aDesc.sDataSource = pDatMan->getActiveDataSource();
     104           0 :             aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
     105           0 :             aDesc.nCommandType = CommandType::TABLE;
     106             : 
     107           0 :             const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
     108           0 :             OUString sTypeMapping = pBibConfig->GetDefColumnName(AUTHORITYTYPE_POS);
     109           0 :             if(pMapping)
     110             :             {
     111           0 :                 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
     112             :                 {
     113           0 :                     if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == sTypeMapping)
     114             :                     {
     115           0 :                         sTypeMapping = pMapping->aColumnPairs[nEntry].sRealColumnName;
     116           0 :                         break;
     117             :                     }
     118             :                 }
     119             :             }
     120           0 :             OUString uTypeMapping = sTypeMapping;
     121             : 
     122           0 :             uno::Reference< form::XForm >  xForm = pDatMan->getForm();
     123           0 :             uno::Reference< sdbcx::XColumnsSupplier >  xSupplyCols(xForm, UNO_QUERY);
     124           0 :             uno::Reference< container::XNameAccess >  xValueAcc;
     125           0 :             if (xSupplyCols.is())
     126           0 :                 xValueAcc = xSupplyCols->getColumns();
     127             : 
     128           0 :             sal_Int16 nTempVal = -1;
     129           0 :             if(xValueAcc.is() && xValueAcc->hasByName(uTypeMapping))
     130             :             {
     131           0 :                 uno::Any aVal = xValueAcc->getByName(uTypeMapping);
     132           0 :                 uno::Reference< uno::XInterface >  xInt = *static_cast<uno::Reference< uno::XInterface > const *>(aVal.getValue());
     133           0 :                 uno::Reference< sdb::XColumn >  xCol(xInt, UNO_QUERY);
     134             :                 DBG_ASSERT(xCol.is(), "BibPosListener::cursorMoved : invalid column (no sdb::XColumn) !");
     135           0 :                 if (xCol.is())
     136             :                 {
     137           0 :                     nTempVal = xCol->getShort();
     138             :                     // getShort returns zero if the value is not a number
     139           0 :                     if (!nTempVal || xCol->wasNull())
     140             :                     {
     141           0 :                         OUString sTempVal = xCol->getString();
     142           0 :                         if(sTempVal != "0")
     143           0 :                             nTempVal = -1;
     144             :                     }
     145           0 :                 }
     146             :             }
     147           0 :             if(nTempVal < 0 || nTempVal >= TYPE_COUNT)
     148             :             {
     149           0 :                 uno::Any aSel;
     150           0 :                 uno::Sequence<sal_Int16> aSelSeq(1);
     151           0 :                 sal_Int16* pArr = aSelSeq.getArray();
     152           0 :                 pArr[0] = TYPE_COUNT;
     153           0 :                 aSel.setValue(&aSelSeq, cppu::UnoType<Sequence<sal_Int16>>::get());
     154           0 :                 xPropSet->setPropertyValue("SelectedItems", aSel);
     155           0 :             }
     156           0 :         }
     157             :     }
     158           0 :     catch(const Exception&)
     159             :     {
     160             :         OSL_FAIL("BibPosListener::cursorMoved: something went wrong !");
     161             :     }
     162           0 : }
     163             : 
     164           0 : void BibPosListener::disposing(const lang::EventObject& /*Source*/) throw( uno::RuntimeException, std::exception )
     165             : {
     166           0 : }
     167             : 
     168           0 : BibGeneralPage::BibGeneralPage(vcl::Window* pParent, BibDataManager* pMan):
     169             :     BibTabPage(pParent, "GeneralPage", "modules/sbibliography/ui/generalpage.ui"),
     170             :     sErrorPrefix(BIB_RESSTR(ST_ERROR_PREFIX)),
     171             :     maBibGeneralPageFocusListener(this),
     172           0 :     pDatMan(pMan)
     173             : {
     174           0 :     get(pIdentifierFT, "shortname");
     175           0 :     get(pAuthTypeFT, "authtype");
     176           0 :     get(pGrid, "grid");
     177           0 :     get(pScrolledWindow, "scrolledwindow");
     178           0 :     get(pYearFT, "year");
     179           0 :     get(pAuthorFT, "authors");
     180           0 :     get(pTitleFT, "title");
     181           0 :     get(pPublisherFT, "publisher");
     182           0 :     get(pAddressFT, "address");
     183           0 :     get(pISBNFT, "isbn");
     184           0 :     get(pChapterFT, "chapter");
     185           0 :     get(pPagesFT, "pages");
     186           0 :     get(pEditorFT, "editor");
     187           0 :     get(pEditionFT, "edition");
     188           0 :     get(pBooktitleFT, "booktitle");
     189           0 :     get(pVolumeFT, "volume");
     190           0 :     get(pHowpublishedFT, "publicationtype");
     191           0 :     get(pOrganizationsFT, "organization");
     192           0 :     get(pInstitutionFT, "institution");
     193           0 :     get(pSchoolFT, "university");
     194           0 :     get(pReportTypeFT, "reporttype");
     195           0 :     get(pMonthFT, "month");
     196           0 :     get(pJournalFT, "journal");
     197           0 :     get(pNumberFT, "number");
     198           0 :     get(pSeriesFT, "series");
     199           0 :     get(pAnnoteFT, "annotation");
     200           0 :     get(pNoteFT, "note");
     201           0 :     get(pURLFT, "url");
     202           0 :     get(pCustom1FT, "custom1");
     203           0 :     get(pCustom2FT, "custom2");
     204           0 :     get(pCustom3FT, "custom3");
     205           0 :     get(pCustom4FT, "custom4");
     206           0 :     get(pCustom5FT, "custom5");
     207             : 
     208           0 :     InitFixedTexts();
     209             : 
     210           0 :     sal_Int16* pMap = nFT2CtrlMap;
     211           0 :     for( sal_uInt16 i = 0 ; i < FIELD_COUNT ; ++i, ++pMap )
     212             :     {
     213           0 :         aControls[ i ] = 0;
     214           0 :         *pMap = -1;
     215             :     }
     216             : 
     217           0 :     BibConfig* pBibConfig = BibModul::GetConfig();
     218           0 :     BibDBDescriptor aDesc;
     219           0 :     aDesc.sDataSource = pDatMan->getActiveDataSource();
     220           0 :     aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
     221           0 :     aDesc.nCommandType = CommandType::TABLE;
     222           0 :     const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
     223             : 
     224           0 :     xCtrlContnr = VCLUnoHelper::CreateControlContainer(pGrid);
     225             : 
     226           0 :     std::vector<vcl::Window*> aChildren;
     227             : 
     228           0 :     AddControlWithError(lcl_GetColumnName(pMapping, IDENTIFIER_POS), *pIdentifierFT,
     229             :         sTableErrorString,
     230           0 :         HID_BIB_IDENTIFIER_POS, 0, aChildren);
     231             : 
     232           0 :     sTypeColumnName = lcl_GetColumnName(pMapping, AUTHORITYTYPE_POS);
     233             : 
     234           0 :     AddControlWithError(sTypeColumnName, *pAuthTypeFT, sTableErrorString,
     235           0 :         HID_BIB_AUTHORITYTYPE_POS, 1, aChildren);
     236             : 
     237           0 :     AddControlWithError(lcl_GetColumnName(pMapping, YEAR_POS), *pYearFT,
     238           0 :         sTableErrorString, HID_BIB_YEAR_POS, 2, aChildren);
     239             : 
     240           0 :     AddControlWithError(lcl_GetColumnName(pMapping, AUTHOR_POS), *pAuthorFT,
     241           0 :         sTableErrorString, HID_BIB_AUTHOR_POS, 3, aChildren);
     242             : 
     243           0 :     AddControlWithError(lcl_GetColumnName(pMapping, TITLE_POS), *pTitleFT, sTableErrorString,
     244           0 :         HID_BIB_TITLE_POS, 4, aChildren);
     245             : 
     246           0 :     AddControlWithError(lcl_GetColumnName(pMapping, PUBLISHER_POS), *pPublisherFT,
     247           0 :         sTableErrorString, HID_BIB_PUBLISHER_POS, 5, aChildren);
     248             : 
     249           0 :     AddControlWithError(lcl_GetColumnName(pMapping, ADDRESS_POS), *pAddressFT,
     250           0 :         sTableErrorString, HID_BIB_ADDRESS_POS, 6, aChildren);
     251             : 
     252           0 :     AddControlWithError(lcl_GetColumnName(pMapping, ISBN_POS), *pISBNFT,
     253           0 :         sTableErrorString, HID_BIB_ISBN_POS, 7, aChildren);
     254             : 
     255           0 :     AddControlWithError(lcl_GetColumnName(pMapping, CHAPTER_POS), *pChapterFT,
     256           0 :         sTableErrorString, HID_BIB_CHAPTER_POS, 8, aChildren);
     257             : 
     258           0 :     AddControlWithError(lcl_GetColumnName(pMapping, PAGES_POS), *pPagesFT,
     259           0 :         sTableErrorString, HID_BIB_PAGES_POS, 9, aChildren);
     260             : 
     261           0 :     AddControlWithError(lcl_GetColumnName(pMapping, EDITOR_POS), *pEditorFT,
     262           0 :         sTableErrorString, HID_BIB_EDITOR_POS, 10, aChildren);
     263             : 
     264           0 :     AddControlWithError(lcl_GetColumnName(pMapping, EDITION_POS), *pEditionFT,
     265           0 :         sTableErrorString, HID_BIB_EDITION_POS, 11, aChildren);
     266             : 
     267           0 :     AddControlWithError(lcl_GetColumnName(pMapping, BOOKTITLE_POS), *pBooktitleFT,
     268           0 :         sTableErrorString, HID_BIB_BOOKTITLE_POS, 12, aChildren);
     269             : 
     270           0 :     AddControlWithError(lcl_GetColumnName(pMapping, VOLUME_POS), *pVolumeFT,
     271           0 :         sTableErrorString, HID_BIB_VOLUME_POS, 13, aChildren);
     272             : 
     273           0 :     AddControlWithError(lcl_GetColumnName(pMapping, HOWPUBLISHED_POS), *pHowpublishedFT,
     274           0 :         sTableErrorString, HID_BIB_HOWPUBLISHED_POS, 14, aChildren);
     275             : 
     276           0 :     AddControlWithError(lcl_GetColumnName(pMapping, ORGANIZATIONS_POS), *pOrganizationsFT,
     277           0 :         sTableErrorString, HID_BIB_ORGANIZATIONS_POS, 15, aChildren);
     278             : 
     279           0 :     AddControlWithError(lcl_GetColumnName(pMapping, INSTITUTION_POS), *pInstitutionFT,
     280           0 :         sTableErrorString, HID_BIB_INSTITUTION_POS, 16, aChildren);
     281             : 
     282           0 :     AddControlWithError(lcl_GetColumnName(pMapping, SCHOOL_POS), *pSchoolFT,
     283           0 :         sTableErrorString, HID_BIB_SCHOOL_POS, 17, aChildren);
     284             : 
     285           0 :     AddControlWithError(lcl_GetColumnName(pMapping, REPORTTYPE_POS), *pReportTypeFT,
     286           0 :         sTableErrorString, HID_BIB_REPORTTYPE_POS, 18, aChildren);
     287             : 
     288           0 :     AddControlWithError(lcl_GetColumnName(pMapping, MONTH_POS), *pMonthFT,
     289           0 :         sTableErrorString, HID_BIB_MONTH_POS, 19, aChildren);
     290             : 
     291           0 :     AddControlWithError(lcl_GetColumnName(pMapping, JOURNAL_POS), *pJournalFT,
     292           0 :         sTableErrorString, HID_BIB_JOURNAL_POS, 20, aChildren);
     293             : 
     294           0 :     AddControlWithError(lcl_GetColumnName(pMapping, NUMBER_POS), *pNumberFT,
     295           0 :         sTableErrorString, HID_BIB_NUMBER_POS, 21, aChildren);
     296             : 
     297           0 :     AddControlWithError(lcl_GetColumnName(pMapping, SERIES_POS), *pSeriesFT,
     298           0 :         sTableErrorString, HID_BIB_SERIES_POS, 22, aChildren);
     299             : 
     300           0 :     AddControlWithError(lcl_GetColumnName(pMapping, ANNOTE_POS), *pAnnoteFT,
     301           0 :         sTableErrorString, HID_BIB_ANNOTE_POS, 23, aChildren);
     302             : 
     303           0 :     AddControlWithError(lcl_GetColumnName(pMapping, NOTE_POS),*pNoteFT,
     304           0 :         sTableErrorString, HID_BIB_NOTE_POS, 24, aChildren);
     305             : 
     306           0 :     AddControlWithError(lcl_GetColumnName(pMapping, URL_POS), *pURLFT,
     307           0 :         sTableErrorString, HID_BIB_URL_POS, 25, aChildren);
     308             : 
     309           0 :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM1_POS), *pCustom1FT,
     310           0 :         sTableErrorString, HID_BIB_CUSTOM1_POS, 26, aChildren);
     311             : 
     312           0 :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM2_POS), *pCustom2FT,
     313           0 :         sTableErrorString, HID_BIB_CUSTOM2_POS, 27, aChildren);
     314             : 
     315           0 :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM3_POS), *pCustom3FT,
     316           0 :         sTableErrorString, HID_BIB_CUSTOM3_POS, 28, aChildren);
     317             : 
     318           0 :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM4_POS), *pCustom4FT,
     319           0 :         sTableErrorString, HID_BIB_CUSTOM4_POS, 29, aChildren);
     320             : 
     321           0 :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM5_POS), *pCustom5FT,
     322           0 :         sTableErrorString, HID_BIB_CUSTOM5_POS, 30, aChildren);
     323             : 
     324           0 :     VclBuilder::reorderWithinParent(aChildren, false);
     325             : 
     326           0 :     xPosListener = new BibPosListener(this);
     327           0 :     uno::Reference< sdbc::XRowSet >  xRowSet(pDatMan->getForm(), UNO_QUERY);
     328           0 :     if(xRowSet.is())
     329           0 :         xRowSet->addRowSetListener(xPosListener);
     330           0 :     uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
     331           0 :     xFormCtrl->setContainer(xCtrlContnr);
     332           0 :     xFormCtrl->activateTabOrder();
     333             : 
     334           0 :     if(!sTableErrorString.isEmpty())
     335           0 :         sTableErrorString = sErrorPrefix + sTableErrorString;
     336             : 
     337           0 :     SetText(BIB_RESSTR(ST_TYPE_TITLE));
     338             : 
     339           0 :     Size aSize(LogicToPixel(Size(0, 209), MapMode(MAP_APPFONT)));
     340           0 :     set_height_request(aSize.Height());
     341           0 : }
     342             : 
     343           0 : BibGeneralPage::~BibGeneralPage()
     344             : {
     345           0 :     disposeOnce();
     346           0 : }
     347             : 
     348           0 : void BibGeneralPage::dispose()
     349             : {
     350           0 :     if (pDatMan && xPosListener.is())
     351             :     {
     352           0 :         uno::Reference< sdbc::XRowSet >  xRowSet(pDatMan->getForm(), UNO_QUERY);
     353           0 :         if(xRowSet.is())
     354           0 :             xRowSet->removeRowSetListener(xPosListener);
     355             :     }
     356           0 :     pGrid.clear();
     357           0 :     pScrolledWindow.clear();
     358           0 :     pIdentifierFT.clear();
     359           0 :     pAuthTypeFT.clear();
     360           0 :     pYearFT.clear();
     361           0 :     pAuthorFT.clear();
     362           0 :     pTitleFT.clear();
     363           0 :     pPublisherFT.clear();
     364           0 :     pAddressFT.clear();
     365           0 :     pISBNFT.clear();
     366           0 :     pChapterFT.clear();
     367           0 :     pPagesFT.clear();
     368           0 :     pEditorFT.clear();
     369           0 :     pEditionFT.clear();
     370           0 :     pBooktitleFT.clear();
     371           0 :     pVolumeFT.clear();
     372           0 :     pHowpublishedFT.clear();
     373           0 :     pOrganizationsFT.clear();
     374           0 :     pInstitutionFT.clear();
     375           0 :     pSchoolFT.clear();
     376           0 :     pReportTypeFT.clear();
     377           0 :     pMonthFT.clear();
     378           0 :     pJournalFT.clear();
     379           0 :     pNumberFT.clear();
     380           0 :     pSeriesFT.clear();
     381           0 :     pAnnoteFT.clear();
     382           0 :     pNoteFT.clear();
     383           0 :     pURLFT.clear();
     384           0 :     pCustom1FT.clear();
     385           0 :     pCustom2FT.clear();
     386           0 :     pCustom3FT.clear();
     387           0 :     pCustom4FT.clear();
     388           0 :     pCustom5FT.clear();
     389           0 :     for (auto & a: aFixedTexts) a.clear();
     390           0 :     BibTabPage::dispose();
     391           0 : }
     392             : 
     393           0 : void BibGeneralPage::RemoveListeners()
     394             : {
     395           0 :     for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
     396             :     {
     397           0 :         if(aControls[i].is())
     398             :         {
     399           0 :             uno::Reference< awt::XWindow > xCtrWin(aControls[i], uno::UNO_QUERY );
     400           0 :             xCtrWin->removeFocusListener( &maBibGeneralPageFocusListener );
     401           0 :             aControls[i] = 0;
     402             :         }
     403             :     }
     404           0 : }
     405             : 
     406           0 : void BibGeneralPage::CommitActiveControl()
     407             : {
     408           0 :     uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
     409           0 :     uno::Reference< awt::XControl >  xCurr = xFormCtrl->getCurrentControl();
     410           0 :     if(xCurr.is())
     411             :     {
     412           0 :         uno::Reference< awt::XControlModel >  xModel = xCurr->getModel();
     413           0 :         uno::Reference< form::XBoundComponent >  xBound(xModel, UNO_QUERY);
     414           0 :         if(xBound.is())
     415           0 :             xBound->commit();
     416           0 :     }
     417           0 : }
     418             : 
     419           0 : void BibGeneralPage::AddControlWithError( const OUString& rColumnName, FixedText &rLabel,
     420             :     OUString& rErrorString, const OString& sHelpId, sal_uInt16 nIndexInFTArray, std::vector<vcl::Window*> &rChildren)
     421             : {
     422           0 :     const OUString aColumnUIName(rLabel.GetText());
     423             :     // adds also the XControl and creates a map entry in nFT2CtrlMap[] for mapping between control and FT
     424             : 
     425           0 :     sal_Int16                                   nIndex = -1;
     426           0 :     uno::Reference< awt::XControlModel >    xTmp = AddXControl(rColumnName, rLabel, sHelpId, nIndex, rChildren);
     427           0 :     if( xTmp.is() )
     428             :     {
     429             :         DBG_ASSERT( nIndexInFTArray < FIELD_COUNT, "*BibGeneralPage::AddControlWithError(): wrong array index!" );
     430             :         DBG_ASSERT( nFT2CtrlMap[ nIndexInFTArray ] < 0, "+BibGeneralPage::AddControlWithError(): index already in use!" );
     431             : 
     432           0 :         nFT2CtrlMap[ nIndexInFTArray ] = nIndex;
     433             :     }
     434             :     else
     435             :     {
     436           0 :         if( !rErrorString.isEmpty() )
     437           0 :             rErrorString += "\n";
     438             : 
     439           0 :         rErrorString += MnemonicGenerator::EraseAllMnemonicChars( aColumnUIName );
     440           0 :     }
     441           0 : }
     442             : 
     443           0 : uno::Reference< awt::XControlModel >  BibGeneralPage::AddXControl(
     444             :         const OUString& rName,
     445             :         FixedText& rLabel, const OString& sHelpId, sal_Int16& rIndex,
     446             :         std::vector<vcl::Window*>& rChildren)
     447             : {
     448           0 :     uno::Reference< awt::XControlModel >  xCtrModel;
     449             :     try
     450             :     {
     451           0 :         const bool bTypeListBox = sTypeColumnName == rName;
     452           0 :         xCtrModel = pDatMan->loadControlModel(rName, bTypeListBox);
     453           0 :         if ( xCtrModel.is() )
     454             :         {
     455           0 :             uno::Reference< beans::XPropertySet >  xPropSet( xCtrModel, UNO_QUERY );
     456             : 
     457           0 :             if( xPropSet.is())
     458             :             {
     459           0 :                 uno::Reference< beans::XPropertySetInfo >  xPropInfo = xPropSet->getPropertySetInfo();
     460             : 
     461           0 :                 OUString aControlName;
     462           0 :                 if (bTypeListBox)
     463             :                 {
     464           0 :                     aControlName = "com.sun.star.form.control.ListBox";
     465           0 :                     xLBModel = Reference< form::XBoundComponent >(xCtrModel, UNO_QUERY);
     466             :                 }
     467             :                 else
     468             :                 {
     469           0 :                     uno::Any aAny = xPropSet->getPropertyValue( "DefaultControl" );
     470           0 :                     aAny >>= aControlName;
     471             :                 }
     472             : 
     473           0 :                 OUString uProp("HelpURL");
     474           0 :                 if(xPropInfo->hasPropertyByName(uProp))
     475             :                 {
     476           0 :                     OUString sId( INET_HID_SCHEME );
     477             :                     DBG_ASSERT( INetURLObject( OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INetProtocol::NotValid, "Wrong HelpId!" );
     478           0 :                     sId += OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 );
     479           0 :                     xPropSet->setPropertyValue( uProp, makeAny( sId ) );
     480             :                 }
     481             : 
     482           0 :                 uno::Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     483           0 :                 uno::Reference< awt::XControl > xControl( xContext->getServiceManager()->createInstanceWithContext(aControlName, xContext), UNO_QUERY);
     484           0 :                 if ( xControl.is() )
     485             :                 {
     486           0 :                     xControl->setModel( xCtrModel);
     487             : 
     488             :                     // Peer as Child to the FrameWindow
     489           0 :                     xCtrlContnr->addControl(rName, xControl);
     490           0 :                     uno::Reference< awt::XWindow >  xCtrWin(xControl, UNO_QUERY );
     491           0 :                     xCtrWin->addFocusListener( &maBibGeneralPageFocusListener );
     492           0 :                     rIndex = -1;    // -> implies, that not found
     493           0 :                     for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
     494           0 :                         if(!aControls[i].is())
     495             :                         {
     496           0 :                             aControls[i] = xCtrWin;
     497           0 :                             rIndex = sal_Int16( i );
     498           0 :                             break;
     499             :                         }
     500             :                     // initially switch on the design mode - switch it off _after_ loading the form
     501           0 :                     xCtrWin->setVisible( sal_True );
     502           0 :                     xControl->setDesignMode( sal_True );
     503             : 
     504           0 :                     vcl::Window* pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
     505           0 :                     pWindow->set_grid_top_attach(rLabel.get_grid_top_attach());
     506           0 :                     pWindow->set_grid_left_attach(rLabel.get_grid_left_attach()+1);
     507           0 :                     pWindow->set_valign(VCL_ALIGN_CENTER);
     508           0 :                     rLabel.set_mnemonic_widget(pWindow);
     509           0 :                     if (&rLabel == pTitleFT)
     510           0 :                         pWindow->set_grid_width(3);
     511             :                     else
     512           0 :                         pWindow->set_hexpand(true);
     513           0 :                     rChildren.push_back(&rLabel);
     514           0 :                     rChildren.push_back(pWindow);
     515           0 :                 }
     516           0 :             }
     517             :         }
     518             :     }
     519           0 :     catch(const Exception& rEx)
     520             :     {
     521             :         (void) rEx; // make compiler happy
     522             :         OSL_FAIL("BibGeneralPage::AddXControl: something went wrong!");
     523             :     }
     524           0 :     return xCtrModel;
     525             : }
     526             : 
     527           0 : void BibGeneralPage::InitFixedTexts()
     528             : {
     529           0 :     aFixedTexts[0] = pIdentifierFT;
     530           0 :     aFixedTexts[1] = pAuthTypeFT;
     531           0 :     aFixedTexts[2] = pYearFT;
     532           0 :     aFixedTexts[3] = pAuthorFT;
     533           0 :     aFixedTexts[4] = pTitleFT;
     534           0 :     aFixedTexts[5] = pPublisherFT;
     535           0 :     aFixedTexts[6] = pAddressFT;
     536           0 :     aFixedTexts[7] = pISBNFT;
     537           0 :     aFixedTexts[8] = pChapterFT;
     538           0 :     aFixedTexts[9] = pPagesFT;
     539             : 
     540           0 :     aFixedTexts[10] = pEditorFT;
     541           0 :     aFixedTexts[11] = pEditionFT;
     542           0 :     aFixedTexts[12] = pBooktitleFT;
     543           0 :     aFixedTexts[13] = pVolumeFT;
     544           0 :     aFixedTexts[14] = pHowpublishedFT;
     545           0 :     aFixedTexts[15] = pOrganizationsFT;
     546           0 :     aFixedTexts[16] = pInstitutionFT;
     547           0 :     aFixedTexts[17] = pSchoolFT;
     548           0 :     aFixedTexts[18] = pReportTypeFT;
     549           0 :     aFixedTexts[19] = pMonthFT;
     550             : 
     551           0 :     aFixedTexts[20] = pJournalFT;
     552           0 :     aFixedTexts[21] = pNumberFT;
     553           0 :     aFixedTexts[22] = pSeriesFT;
     554           0 :     aFixedTexts[23] = pAnnoteFT;
     555           0 :     aFixedTexts[24] = pNoteFT;
     556           0 :     aFixedTexts[25] = pURLFT;
     557             : 
     558           0 :     aFixedTexts[26] = pCustom1FT;
     559           0 :     aFixedTexts[27] = pCustom2FT;
     560           0 :     aFixedTexts[28] = pCustom3FT;
     561           0 :     aFixedTexts[29] = pCustom4FT;
     562           0 :     aFixedTexts[30] = pCustom5FT;
     563             : 
     564             :     int                 i;
     565             : 
     566           0 :     MnemonicGenerator   aMnemonicGenerator;
     567             : 
     568           0 :     OUString aFixedStrings[ FIELD_COUNT ];
     569           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     570           0 :         aFixedStrings[i] = aFixedTexts[i]->GetText();
     571             : 
     572             :     // init mnemonics, first register all strings
     573           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     574           0 :         aMnemonicGenerator.RegisterMnemonic( aFixedStrings[ i ] );
     575             : 
     576             :     // ... then get all strings
     577           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     578           0 :         aMnemonicGenerator.CreateMnemonic( aFixedStrings[ i ] );
     579             : 
     580             :     // set texts
     581           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     582           0 :         aFixedTexts[ i ]->SetText( aFixedStrings[ i ] );
     583           0 : }
     584             : 
     585           0 : void BibGeneralPage::focusGained(const awt::FocusEvent& rEvent) throw( uno::RuntimeException, std::exception )
     586             : {
     587           0 :     Reference<awt::XWindow> xCtrWin(rEvent.Source, UNO_QUERY );
     588           0 :     if(xCtrWin.is())
     589             :     {
     590           0 :         ::Size aOutSize = pScrolledWindow->getVisibleChildSize();
     591           0 :         awt::Rectangle aRect = xCtrWin->getPosSize();
     592           0 :         Point aOffset(pGrid->GetPosPixel());
     593           0 :         long nX = aRect.X + aOffset.X();
     594           0 :         if (nX < 0 || nX > aOutSize.Width())
     595             :         {
     596           0 :             pScrolledWindow->getHorzScrollBar().DoScroll(aRect.X);
     597             :         }
     598             : 
     599           0 :         long nY = aRect.Y + aOffset.Y();
     600           0 :         if (nY < 0 || nY > aOutSize.Height())
     601             :         {
     602           0 :             pScrolledWindow->getVertScrollBar().DoScroll(aRect.Y);
     603             :         }
     604           0 :     }
     605           0 : }
     606             : 
     607           0 : void BibGeneralPage::focusLost(const awt::FocusEvent& ) throw( uno::RuntimeException, std::exception )
     608             : {
     609           0 :     CommitActiveControl();
     610           0 : }
     611             : 
     612           0 : void BibGeneralPage::GetFocus()
     613             : {
     614           0 :     Reference< awt::XWindow >*  pxControl = aControls;
     615             : 
     616           0 :     for( int i = FIELD_COUNT ; i ; --i, ++pxControl )
     617             :     {
     618           0 :         if( pxControl->is() )
     619             :         {
     620           0 :             ( *pxControl )->setFocus();
     621           0 :             return;
     622             :         }
     623             :     }
     624             : 
     625             :     // fallback
     626           0 :     GrabFocus();
     627             : }
     628             : 
     629           0 : bool BibGeneralPage::HandleShortCutKey( const KeyEvent& rKeyEvent )
     630             : {
     631             :     DBG_ASSERT( KEY_MOD2 == rKeyEvent.GetKeyCode().GetModifier(), "+BibGeneralPage::HandleShortCutKey(): this is not for me!" );
     632             : 
     633           0 :     const vcl::I18nHelper&      rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
     634           0 :     const sal_Unicode           c = rKeyEvent.GetCharCode();
     635           0 :     bool                        bHandled = false;
     636             : 
     637             :     sal_Int16                   i;
     638             : 
     639             :     typedef std::vector< sal_Int16 >    sal_Int16_vector;
     640             : 
     641           0 :     sal_Int16_vector::size_type nFocused = 0xFFFF;  // index of focused in vector, no one focused initial
     642             :     DBG_ASSERT( nFocused > 0, "*BibGeneralPage::HandleShortCutKey(): size_type works not as expected!" );
     643             : 
     644           0 :     sal_Int16_vector            aMatchList;
     645             : 
     646           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     647             :     {
     648           0 :         if( rI18nHelper.MatchMnemonic( aFixedTexts[ i ]->GetText(), c ) )
     649             :         {
     650           0 :             bHandled = true;
     651           0 :             sal_Int16           nCtrlIndex = nFT2CtrlMap[ i ];
     652             : 
     653           0 :             if( nCtrlIndex >= 0 )
     654             :             {   // store index of control
     655             :                 DBG_ASSERT( aControls[ nCtrlIndex ].is(), "-BibGeneralPage::HandleShortCutKey(): valid index and no control?" );
     656             : 
     657           0 :                 uno::Reference< awt::XControl >  xControl( aControls[ nCtrlIndex ], UNO_QUERY );
     658             :                 DBG_ASSERT( xControl.is(), "-BibGeneralPage::HandleShortCutKey(): a control which is not a control!" );
     659             : 
     660           0 :                 vcl::Window*         pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
     661             : 
     662           0 :                 if( pWindow )
     663             :                 {
     664           0 :                     aMatchList.push_back( nCtrlIndex );
     665           0 :                     if( pWindow->HasChildPathFocus() )
     666             :                     {   // save focused control
     667             :                         DBG_ASSERT( nFocused == 0xFFFF, "+BibGeneralPage::HandleShortCutKey(): more than one with focus?!" );
     668             :                         DBG_ASSERT( !aMatchList.empty(), "+BibGeneralPage::HandleShortCutKey(): push_back and no content?!" );
     669           0 :                         nFocused = aMatchList.size() - 1;
     670             :                     }
     671           0 :                 }
     672             :             }
     673             :         }
     674             :     }
     675             : 
     676           0 :     if( bHandled )
     677             :     {
     678             :         DBG_ASSERT( !aMatchList.empty(), "*BibGeneralPage::HandleShortCutKey(): be prepared to crash..." );
     679             : 
     680           0 :         if( nFocused >= ( aMatchList.size() - 1 ) )
     681             :             // >=... includes 0xFFFF
     682             :             // no one or last focused, take first
     683           0 :             nFocused = 0;
     684             :         else
     685             :             // take next one
     686           0 :             nFocused++;
     687             : 
     688           0 :         aControls[ aMatchList[ nFocused ] ]->setFocus();
     689             :     }
     690             : 
     691           0 :     return bHandled;
     692             : }
     693             : 
     694           0 : BibGeneralPageFocusListener::BibGeneralPageFocusListener(BibGeneralPage *pBibGeneralPage): mpBibGeneralPage(pBibGeneralPage)
     695           0 : {}
     696             : 
     697           0 : void BibGeneralPageFocusListener::focusGained( const ::com::sun::star::awt::FocusEvent& e ) throw( com::sun::star::uno::RuntimeException, std::exception )
     698             : {
     699           0 :     mpBibGeneralPage->focusGained(e);
     700           0 : }
     701             : 
     702           0 : void BibGeneralPageFocusListener::focusLost( const ::com::sun::star::awt::FocusEvent& e ) throw( com::sun::star::uno::RuntimeException, std::exception )
     703             : {
     704           0 :     mpBibGeneralPage->focusLost(e);
     705           0 : }
     706             : 
     707           0 : void BibGeneralPageFocusListener::disposing( const ::com::sun::star::lang::EventObject& ) throw( com::sun::star::uno::RuntimeException, std::exception )
     708           6 : {}
     709             : 
     710             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11