LCOV - code coverage report
Current view: top level - extensions/source/bibliography - general.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 376 0.3 %
Date: 2014-11-03 Functions: 2 23 8.7 %
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/form/ListSourceType.hpp>
      27             : #include <com/sun/star/awt/XWindow.hpp>
      28             : #include <toolkit/helper/vclunohelper.hxx>
      29             : #include <cppuhelper/implbase1.hxx>
      30             : #include <vcl/builder.hxx>
      31             : #include <vcl/settings.hxx>
      32             : #include "general.hxx"
      33             : #include "bibresid.hxx"
      34             : #include "datman.hxx"
      35             : #include "bibconfig.hxx"
      36             : #include "bibprop.hrc"
      37             : #include "bib.hrc"
      38             : #include "bibmod.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             :     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 = *(uno::Reference< uno::XInterface > *)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 != OUString('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, ::getCppuType((Sequence<sal_Int16>*)0));
     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           0 :     pDatMan(pMan)
     172             : {
     173           0 :     get(pIdentifierFT, "shortname");
     174           0 :     get(pAuthTypeFT, "authtype");
     175           0 :     get(pGrid, "grid");
     176           0 :     get(pScrolledWindow, "scrolledwindow");
     177           0 :     get(pYearFT, "year");
     178           0 :     get(pAuthorFT, "authors");
     179           0 :     get(pTitleFT, "title");
     180           0 :     get(pPublisherFT, "publisher");
     181           0 :     get(pAddressFT, "address");
     182           0 :     get(pISBNFT, "isbn");
     183           0 :     get(pChapterFT, "chapter");
     184           0 :     get(pPagesFT, "pages");
     185           0 :     get(pEditorFT, "editor");
     186           0 :     get(pEditionFT, "edition");
     187           0 :     get(pBooktitleFT, "booktitle");
     188           0 :     get(pVolumeFT, "volume");
     189           0 :     get(pHowpublishedFT, "publicationtype");
     190           0 :     get(pOrganizationsFT, "organization");
     191           0 :     get(pInstitutionFT, "institution");
     192           0 :     get(pSchoolFT, "university");
     193           0 :     get(pReportTypeFT, "reporttype");
     194           0 :     get(pMonthFT, "month");
     195           0 :     get(pJournalFT, "journal");
     196           0 :     get(pNumberFT, "number");
     197           0 :     get(pSeriesFT, "series");
     198           0 :     get(pAnnoteFT, "annotation");
     199           0 :     get(pNoteFT, "note");
     200           0 :     get(pURLFT, "url");
     201           0 :     get(pCustom1FT, "custom1");
     202           0 :     get(pCustom2FT, "custom2");
     203           0 :     get(pCustom3FT, "custom3");
     204           0 :     get(pCustom4FT, "custom4");
     205           0 :     get(pCustom5FT, "custom5");
     206             : 
     207           0 :     aBibTypeArr[0] = BIB_RESSTR(ST_TYPE_ARTICLE);
     208           0 :     aBibTypeArr[1] = BIB_RESSTR(ST_TYPE_BOOK);
     209           0 :     aBibTypeArr[2] = BIB_RESSTR(ST_TYPE_BOOKLET);
     210           0 :     aBibTypeArr[3] = BIB_RESSTR(ST_TYPE_CONFERENCE);
     211           0 :     aBibTypeArr[4] = BIB_RESSTR(ST_TYPE_INBOOK );
     212           0 :     aBibTypeArr[5] = BIB_RESSTR(ST_TYPE_INCOLLECTION);
     213           0 :     aBibTypeArr[6] = BIB_RESSTR(ST_TYPE_INPROCEEDINGS);
     214           0 :     aBibTypeArr[7] = BIB_RESSTR(ST_TYPE_JOURNAL       );
     215           0 :     aBibTypeArr[8] = BIB_RESSTR(ST_TYPE_MANUAL    );
     216           0 :     aBibTypeArr[9] = BIB_RESSTR(ST_TYPE_MASTERSTHESIS);
     217           0 :     aBibTypeArr[10] = BIB_RESSTR(ST_TYPE_MISC      );
     218           0 :     aBibTypeArr[11] = BIB_RESSTR(ST_TYPE_PHDTHESIS );
     219           0 :     aBibTypeArr[12] = BIB_RESSTR(ST_TYPE_PROCEEDINGS   );
     220           0 :     aBibTypeArr[13] = BIB_RESSTR(ST_TYPE_TECHREPORT    );
     221           0 :     aBibTypeArr[14] = BIB_RESSTR(ST_TYPE_UNPUBLISHED   );
     222           0 :     aBibTypeArr[15] = BIB_RESSTR(ST_TYPE_EMAIL     );
     223           0 :     aBibTypeArr[16] = BIB_RESSTR(ST_TYPE_WWW           );
     224           0 :     aBibTypeArr[17] = BIB_RESSTR(ST_TYPE_CUSTOM1       );
     225           0 :     aBibTypeArr[18] = BIB_RESSTR(ST_TYPE_CUSTOM2       );
     226           0 :     aBibTypeArr[19] = BIB_RESSTR(ST_TYPE_CUSTOM3       );
     227           0 :     aBibTypeArr[20] = BIB_RESSTR(ST_TYPE_CUSTOM4       );
     228           0 :     aBibTypeArr[21] = BIB_RESSTR(ST_TYPE_CUSTOM5       );
     229             : 
     230           0 :     InitFixedTexts();
     231             : 
     232           0 :     sal_Int16* pMap = nFT2CtrlMap;
     233           0 :     for( sal_uInt16 i = 0 ; i < FIELD_COUNT ; ++i, ++pMap )
     234             :     {
     235           0 :         aControls[ i ] = 0;
     236           0 :         *pMap = -1;
     237             :     }
     238             : 
     239           0 :     BibConfig* pBibConfig = BibModul::GetConfig();
     240           0 :     BibDBDescriptor aDesc;
     241           0 :     aDesc.sDataSource = pDatMan->getActiveDataSource();
     242           0 :     aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
     243           0 :     aDesc.nCommandType = CommandType::TABLE;
     244           0 :     const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
     245             : 
     246           0 :     xCtrlContnr = VCLUnoHelper::CreateControlContainer(pGrid);
     247             : 
     248           0 :     std::vector<vcl::Window*> aChildren;
     249             : 
     250             :     AddControlWithError(lcl_GetColumnName(pMapping, IDENTIFIER_POS), *pIdentifierFT,
     251             :         sTableErrorString,
     252           0 :         HID_BIB_IDENTIFIER_POS, 0, aChildren);
     253             : 
     254           0 :     sTypeColumnName = lcl_GetColumnName(pMapping, AUTHORITYTYPE_POS);
     255             : 
     256             :     AddControlWithError(sTypeColumnName, *pAuthTypeFT, sTableErrorString,
     257           0 :         HID_BIB_AUTHORITYTYPE_POS, 1, aChildren);
     258             : 
     259             :     AddControlWithError(lcl_GetColumnName(pMapping, YEAR_POS), *pYearFT,
     260           0 :         sTableErrorString, HID_BIB_YEAR_POS, 2, aChildren);
     261             : 
     262             :     AddControlWithError(lcl_GetColumnName(pMapping, AUTHOR_POS), *pAuthorFT,
     263           0 :         sTableErrorString, HID_BIB_AUTHOR_POS, 3, aChildren);
     264             : 
     265             :     AddControlWithError(lcl_GetColumnName(pMapping, TITLE_POS), *pTitleFT, sTableErrorString,
     266           0 :         HID_BIB_TITLE_POS, 4, aChildren);
     267             : 
     268             :     AddControlWithError(lcl_GetColumnName(pMapping, PUBLISHER_POS), *pPublisherFT,
     269           0 :         sTableErrorString, HID_BIB_PUBLISHER_POS, 5, aChildren);
     270             : 
     271             :     AddControlWithError(lcl_GetColumnName(pMapping, ADDRESS_POS), *pAddressFT,
     272           0 :         sTableErrorString, HID_BIB_ADDRESS_POS, 6, aChildren);
     273             : 
     274             :     AddControlWithError(lcl_GetColumnName(pMapping, ISBN_POS), *pISBNFT,
     275           0 :         sTableErrorString, HID_BIB_ISBN_POS, 7, aChildren);
     276             : 
     277             :     AddControlWithError(lcl_GetColumnName(pMapping, CHAPTER_POS), *pChapterFT,
     278           0 :         sTableErrorString, HID_BIB_CHAPTER_POS, 8, aChildren);
     279             : 
     280             :     AddControlWithError(lcl_GetColumnName(pMapping, PAGES_POS), *pPagesFT,
     281           0 :         sTableErrorString, HID_BIB_PAGES_POS, 9, aChildren);
     282             : 
     283             :     AddControlWithError(lcl_GetColumnName(pMapping, EDITOR_POS), *pEditorFT,
     284           0 :         sTableErrorString, HID_BIB_EDITOR_POS, 10, aChildren);
     285             : 
     286             :     AddControlWithError(lcl_GetColumnName(pMapping, EDITION_POS), *pEditionFT,
     287           0 :         sTableErrorString, HID_BIB_EDITION_POS, 11, aChildren);
     288             : 
     289             :     AddControlWithError(lcl_GetColumnName(pMapping, BOOKTITLE_POS), *pBooktitleFT,
     290           0 :         sTableErrorString, HID_BIB_BOOKTITLE_POS, 12, aChildren);
     291             : 
     292             :     AddControlWithError(lcl_GetColumnName(pMapping, VOLUME_POS), *pVolumeFT,
     293           0 :         sTableErrorString, HID_BIB_VOLUME_POS, 13, aChildren);
     294             : 
     295             :     AddControlWithError(lcl_GetColumnName(pMapping, HOWPUBLISHED_POS), *pHowpublishedFT,
     296           0 :         sTableErrorString, HID_BIB_HOWPUBLISHED_POS, 14, aChildren);
     297             : 
     298             :     AddControlWithError(lcl_GetColumnName(pMapping, ORGANIZATIONS_POS), *pOrganizationsFT,
     299           0 :         sTableErrorString, HID_BIB_ORGANIZATIONS_POS, 15, aChildren);
     300             : 
     301             :     AddControlWithError(lcl_GetColumnName(pMapping, INSTITUTION_POS), *pInstitutionFT,
     302           0 :         sTableErrorString, HID_BIB_INSTITUTION_POS, 16, aChildren);
     303             : 
     304             :     AddControlWithError(lcl_GetColumnName(pMapping, SCHOOL_POS), *pSchoolFT,
     305           0 :         sTableErrorString, HID_BIB_SCHOOL_POS, 17, aChildren);
     306             : 
     307             :     AddControlWithError(lcl_GetColumnName(pMapping, REPORTTYPE_POS), *pReportTypeFT,
     308           0 :         sTableErrorString, HID_BIB_REPORTTYPE_POS, 18, aChildren);
     309             : 
     310             :     AddControlWithError(lcl_GetColumnName(pMapping, MONTH_POS), *pMonthFT,
     311           0 :         sTableErrorString, HID_BIB_MONTH_POS, 19, aChildren);
     312             : 
     313             :     AddControlWithError(lcl_GetColumnName(pMapping, JOURNAL_POS), *pJournalFT,
     314           0 :         sTableErrorString, HID_BIB_JOURNAL_POS, 20, aChildren);
     315             : 
     316             :     AddControlWithError(lcl_GetColumnName(pMapping, NUMBER_POS), *pNumberFT,
     317           0 :         sTableErrorString, HID_BIB_NUMBER_POS, 21, aChildren);
     318             : 
     319             :     AddControlWithError(lcl_GetColumnName(pMapping, SERIES_POS), *pSeriesFT,
     320           0 :         sTableErrorString, HID_BIB_SERIES_POS, 22, aChildren);
     321             : 
     322             :     AddControlWithError(lcl_GetColumnName(pMapping, ANNOTE_POS), *pAnnoteFT,
     323           0 :         sTableErrorString, HID_BIB_ANNOTE_POS, 23, aChildren);
     324             : 
     325             :     AddControlWithError(lcl_GetColumnName(pMapping, NOTE_POS),*pNoteFT,
     326           0 :         sTableErrorString, HID_BIB_NOTE_POS, 24, aChildren);
     327             : 
     328             :     AddControlWithError(lcl_GetColumnName(pMapping, URL_POS), *pURLFT,
     329           0 :         sTableErrorString, HID_BIB_URL_POS, 25, aChildren);
     330             : 
     331             :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM1_POS), *pCustom1FT,
     332           0 :         sTableErrorString, HID_BIB_CUSTOM1_POS, 26, aChildren);
     333             : 
     334             :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM2_POS), *pCustom2FT,
     335           0 :         sTableErrorString, HID_BIB_CUSTOM2_POS, 27, aChildren);
     336             : 
     337             :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM3_POS), *pCustom3FT,
     338           0 :         sTableErrorString, HID_BIB_CUSTOM3_POS, 28, aChildren);
     339             : 
     340             :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM4_POS), *pCustom4FT,
     341           0 :         sTableErrorString, HID_BIB_CUSTOM4_POS, 29, aChildren);
     342             : 
     343             :     AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM5_POS), *pCustom5FT,
     344           0 :         sTableErrorString, HID_BIB_CUSTOM5_POS, 30, aChildren);
     345             : 
     346           0 :     VclBuilder::reorderWithinParent(aChildren, false);
     347             : 
     348           0 :     xPosListener = new BibPosListener(this);
     349           0 :     uno::Reference< sdbc::XRowSet >  xRowSet(pDatMan->getForm(), UNO_QUERY);
     350           0 :     if(xRowSet.is())
     351           0 :         xRowSet->addRowSetListener(xPosListener);
     352           0 :     uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
     353           0 :     xFormCtrl->setContainer(xCtrlContnr);
     354           0 :     xFormCtrl->activateTabOrder();
     355             : 
     356           0 :     if(!sTableErrorString.isEmpty())
     357           0 :         sTableErrorString = sErrorPrefix + sTableErrorString;
     358             : 
     359           0 :     SetText(BIB_RESSTR(ST_TYPE_TITLE));
     360             : 
     361           0 :     Size aSize(LogicToPixel(Size(0, 209), MapMode(MAP_APPFONT)));
     362           0 :     set_height_request(aSize.Height());
     363           0 : }
     364             : 
     365           0 : BibGeneralPage::~BibGeneralPage()
     366             : {
     367           0 :     if (pDatMan && xPosListener.is())
     368             :     {
     369           0 :         uno::Reference< sdbc::XRowSet >  xRowSet(pDatMan->getForm(), UNO_QUERY);
     370           0 :         if(xRowSet.is())
     371           0 :             xRowSet->removeRowSetListener(xPosListener);
     372             :     }
     373           0 : }
     374             : 
     375           0 : void BibGeneralPage::RemoveListeners()
     376             : {
     377           0 :     for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
     378             :     {
     379           0 :         if(aControls[i].is())
     380             :         {
     381           0 :             uno::Reference< awt::XWindow > xCtrWin(aControls[i], uno::UNO_QUERY );
     382           0 :             xCtrWin->removeFocusListener( this );
     383           0 :             aControls[i] = 0;
     384             :         }
     385             :     }
     386           0 : }
     387             : 
     388           0 : void BibGeneralPage::CommitActiveControl()
     389             : {
     390           0 :     uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
     391           0 :     uno::Reference< awt::XControl >  xCurr = xFormCtrl->getCurrentControl();
     392           0 :     if(xCurr.is())
     393             :     {
     394           0 :         uno::Reference< awt::XControlModel >  xModel = xCurr->getModel();
     395           0 :         uno::Reference< form::XBoundComponent >  xBound(xModel, UNO_QUERY);
     396           0 :         if(xBound.is())
     397           0 :             xBound->commit();
     398           0 :     }
     399           0 : }
     400             : 
     401           0 : void BibGeneralPage::AddControlWithError( const OUString& rColumnName, FixedText &rLabel,
     402             :     OUString& rErrorString, const OString& sHelpId, sal_uInt16 nIndexInFTArray, std::vector<vcl::Window*> &rChildren)
     403             : {
     404           0 :     const OUString aColumnUIName(rLabel.GetText());
     405             :     // adds also the XControl and creates a map entry in nFT2CtrlMap[] for mapping between control and FT
     406             : 
     407           0 :     sal_Int16                                   nIndex = -1;
     408           0 :     uno::Reference< awt::XControlModel >    xTmp = AddXControl(rColumnName, rLabel, sHelpId, nIndex, rChildren);
     409           0 :     if( xTmp.is() )
     410             :     {
     411             :         DBG_ASSERT( nIndexInFTArray < FIELD_COUNT, "*BibGeneralPage::AddControlWithError(): wrong array index!" );
     412             :         DBG_ASSERT( nFT2CtrlMap[ nIndexInFTArray ] < 0, "+BibGeneralPage::AddControlWithError(): index already in use!" );
     413             : 
     414           0 :         nFT2CtrlMap[ nIndexInFTArray ] = nIndex;
     415             :     }
     416             :     else
     417             :     {
     418           0 :         if( !rErrorString.isEmpty() )
     419           0 :             rErrorString += "\n";
     420             : 
     421           0 :         rErrorString += MnemonicGenerator::EraseAllMnemonicChars( aColumnUIName );
     422           0 :     }
     423           0 : }
     424             : 
     425           0 : uno::Reference< awt::XControlModel >  BibGeneralPage::AddXControl(
     426             :         const OUString& rName,
     427             :         FixedText& rLabel, const OString& sHelpId, sal_Int16& rIndex,
     428             :         std::vector<vcl::Window*>& rChildren)
     429             : {
     430           0 :     uno::Reference< awt::XControlModel >  xCtrModel;
     431             :     try
     432             :     {
     433           0 :         bool bTypeListBox = sTypeColumnName == rName;
     434           0 :         xCtrModel = pDatMan->loadControlModel(rName, bTypeListBox);
     435           0 :         if ( xCtrModel.is() )
     436             :         {
     437           0 :             uno::Reference< beans::XPropertySet >  xPropSet( xCtrModel, UNO_QUERY );
     438             : 
     439           0 :             if( xPropSet.is())
     440             :             {
     441           0 :                 uno::Reference< beans::XPropertySetInfo >  xPropInfo = xPropSet->getPropertySetInfo();
     442             : 
     443           0 :                 uno::Any aAny = xPropSet->getPropertyValue( "DefaultControl" );
     444           0 :                 OUString aControlName;
     445           0 :                 aAny >>= aControlName;
     446             : 
     447           0 :                 OUString uProp("HelpURL");
     448           0 :                 if(xPropInfo->hasPropertyByName(uProp))
     449             :                 {
     450           0 :                     OUString sId = OUString::createFromAscii( INET_HID_SCHEME );
     451             :                     DBG_ASSERT( INetURLObject( OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
     452           0 :                     sId += OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 );
     453           0 :                     xPropSet->setPropertyValue( uProp, makeAny( sId ) );
     454             :                 }
     455             : 
     456           0 :                 if(bTypeListBox)
     457             :                 {
     458             :                     //uno::Reference< beans::XPropertySet >  xPropSet(xControl, UNO_QUERY);
     459           0 :                     aAny <<= (sal_Int16)1;
     460           0 :                     xPropSet->setPropertyValue("BoundColumn", aAny);
     461           0 :                     ListSourceType eSet = ListSourceType_VALUELIST;
     462           0 :                     aAny.setValue( &eSet, ::cppu::UnoType<ListSourceType>::get() );
     463           0 :                     xPropSet->setPropertyValue("ListSourceType", aAny);
     464             : 
     465           0 :                     uno::Sequence<OUString> aListSource(TYPE_COUNT);
     466           0 :                     OUString* pListSourceArr = aListSource.getArray();
     467             :                     //pListSourceArr[0] = "select TypeName, TypeIndex from TypeNms";
     468           0 :                     for(sal_Int32 i = 0; i < TYPE_COUNT; ++i)
     469           0 :                         pListSourceArr[i] = OUString::number(i);
     470           0 :                     aAny.setValue(&aListSource, ::getCppuType((uno::Sequence<OUString>*)0));
     471             : 
     472           0 :                     xPropSet->setPropertyValue("ListSource", aAny);
     473             : 
     474           0 :                     uno::Sequence<OUString> aValues(TYPE_COUNT + 1);
     475           0 :                     OUString* pValuesArr = aValues.getArray();
     476           0 :                     for(sal_uInt16 j = 0; j < TYPE_COUNT; j++)
     477           0 :                         pValuesArr[j]  = aBibTypeArr[j];
     478             :                     // empty string if an invalid value no values is set
     479           0 :                     pValuesArr[TYPE_COUNT] = OUString();
     480             : 
     481           0 :                     aAny.setValue(&aValues, ::getCppuType((uno::Sequence<OUString>*)0));
     482             : 
     483           0 :                     xPropSet->setPropertyValue("StringItemList", aAny);
     484             : 
     485           0 :                     sal_Bool bTrue = sal_True;
     486           0 :                     aAny.setValue( &bTrue, ::getBooleanCppuType() );
     487           0 :                     xPropSet->setPropertyValue( "Dropdown", aAny );
     488             : 
     489           0 :                     aControlName = "com.sun.star.form.control.ListBox";
     490           0 :                     xLBModel = Reference< form::XBoundComponent >(xCtrModel, UNO_QUERY);
     491             : 
     492             :                 }
     493             : 
     494           0 :                 uno::Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     495           0 :                 uno::Reference< awt::XControl > xControl( xContext->getServiceManager()->createInstanceWithContext(aControlName, xContext), UNO_QUERY);
     496           0 :                 if ( xControl.is() )
     497             :                 {
     498           0 :                     xControl->setModel( xCtrModel);
     499             : 
     500             :                     // Peer as Child to the FrameWindow
     501           0 :                     xCtrlContnr->addControl(rName, xControl);
     502           0 :                     uno::Reference< awt::XWindow >  xCtrWin(xControl, UNO_QUERY );
     503           0 :                     xCtrWin->addFocusListener( this );
     504           0 :                     rIndex = -1;    // -> implies, that not found
     505           0 :                     for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
     506           0 :                         if(!aControls[i].is())
     507             :                         {
     508           0 :                             aControls[i] = xCtrWin;
     509           0 :                             rIndex = sal_Int16( i );
     510           0 :                             break;
     511             :                         }
     512             :                     // initially switch on the design mode - switch it off _after_ loading the form
     513           0 :                     xCtrWin->setVisible( sal_True );
     514           0 :                     xControl->setDesignMode( sal_True );
     515             : 
     516           0 :                     vcl::Window* pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
     517           0 :                     pWindow->set_grid_top_attach(rLabel.get_grid_top_attach());
     518           0 :                     pWindow->set_grid_left_attach(rLabel.get_grid_left_attach()+1);
     519           0 :                     pWindow->set_valign(VCL_ALIGN_CENTER);
     520           0 :                     rLabel.set_mnemonic_widget(pWindow);
     521           0 :                     if (&rLabel == pTitleFT)
     522           0 :                         pWindow->set_grid_width(3);
     523             :                     else
     524           0 :                         pWindow->set_hexpand(true);
     525           0 :                     rChildren.push_back(&rLabel);
     526           0 :                     rChildren.push_back(pWindow);
     527           0 :                 }
     528           0 :             }
     529             :         }
     530             :     }
     531           0 :     catch(const Exception& rEx)
     532             :     {
     533             :         (void) rEx; // make compiler happy
     534             :         OSL_FAIL("BibGeneralPage::AddXControl: something went wrong!");
     535             :     }
     536           0 :     return xCtrModel;
     537             : }
     538             : 
     539           0 : void BibGeneralPage::InitFixedTexts( void )
     540             : {
     541           0 :     aFixedTexts[0] = pIdentifierFT;
     542           0 :     aFixedTexts[1] = pAuthTypeFT;
     543           0 :     aFixedTexts[2] = pYearFT;
     544           0 :     aFixedTexts[3] = pAuthorFT;
     545           0 :     aFixedTexts[4] = pTitleFT;
     546           0 :     aFixedTexts[5] = pPublisherFT;
     547           0 :     aFixedTexts[6] = pAddressFT;
     548           0 :     aFixedTexts[7] = pISBNFT;
     549           0 :     aFixedTexts[8] = pChapterFT;
     550           0 :     aFixedTexts[9] = pPagesFT;
     551             : 
     552           0 :     aFixedTexts[10] = pEditorFT;
     553           0 :     aFixedTexts[11] = pEditionFT;
     554           0 :     aFixedTexts[12] = pBooktitleFT;
     555           0 :     aFixedTexts[13] = pVolumeFT;
     556           0 :     aFixedTexts[14] = pHowpublishedFT;
     557           0 :     aFixedTexts[15] = pOrganizationsFT;
     558           0 :     aFixedTexts[16] = pInstitutionFT;
     559           0 :     aFixedTexts[17] = pSchoolFT;
     560           0 :     aFixedTexts[18] = pReportTypeFT;
     561           0 :     aFixedTexts[19] = pMonthFT;
     562             : 
     563           0 :     aFixedTexts[20] = pJournalFT;
     564           0 :     aFixedTexts[21] = pNumberFT;
     565           0 :     aFixedTexts[22] = pSeriesFT;
     566           0 :     aFixedTexts[23] = pAnnoteFT;
     567           0 :     aFixedTexts[24] = pNoteFT;
     568           0 :     aFixedTexts[25] = pURLFT;
     569             : 
     570           0 :     aFixedTexts[26] = pCustom1FT;
     571           0 :     aFixedTexts[27] = pCustom2FT;
     572           0 :     aFixedTexts[28] = pCustom3FT;
     573           0 :     aFixedTexts[29] = pCustom4FT;
     574           0 :     aFixedTexts[30] = pCustom5FT;
     575             : 
     576             :     int                 i;
     577             : 
     578           0 :     MnemonicGenerator   aMnemonicGenerator;
     579             : 
     580           0 :     OUString aFixedStrings[ FIELD_COUNT ];
     581           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     582           0 :         aFixedStrings[i] = aFixedTexts[i]->GetText();
     583             : 
     584             :     // init mnemonics, first register all strings
     585           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     586           0 :         aMnemonicGenerator.RegisterMnemonic( aFixedStrings[ i ] );
     587             : 
     588             :     // ... then get all strings
     589           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     590           0 :         aMnemonicGenerator.CreateMnemonic( aFixedStrings[ i ] );
     591             : 
     592             :     // set texts
     593           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     594           0 :         aFixedTexts[ i ]->SetText( aFixedStrings[ i ] );
     595           0 : }
     596             : 
     597           0 : void BibGeneralPage::focusGained(const awt::FocusEvent& rEvent) throw( uno::RuntimeException, std::exception )
     598             : {
     599           0 :     Reference<awt::XWindow> xCtrWin(rEvent.Source, UNO_QUERY );
     600           0 :     if(xCtrWin.is())
     601             :     {
     602           0 :         ::Size aOutSize = pScrolledWindow->getVisibleChildSize();
     603           0 :         awt::Rectangle aRect = xCtrWin->getPosSize();
     604           0 :         Point aOffset(pGrid->GetPosPixel());
     605           0 :         long nX = aRect.X + aOffset.X();
     606           0 :         if (nX < 0 || nX > aOutSize.Width())
     607             :         {
     608           0 :             pScrolledWindow->getHorzScrollBar().DoScroll(aRect.X);
     609             :         }
     610             : 
     611           0 :         long nY = aRect.Y + aOffset.Y();
     612           0 :         if (nY < 0 || nY > aOutSize.Height())
     613             :         {
     614           0 :             pScrolledWindow->getVertScrollBar().DoScroll(aRect.Y);
     615             :         }
     616           0 :     }
     617           0 : }
     618             : 
     619           0 : void BibGeneralPage::focusLost(const awt::FocusEvent& ) throw( uno::RuntimeException, std::exception )
     620             : {
     621           0 :     CommitActiveControl();
     622           0 : }
     623             : 
     624           0 : void BibGeneralPage::disposing(const lang::EventObject& /*Source*/) throw( uno::RuntimeException, std::exception )
     625             : {
     626           0 : }
     627             : 
     628           0 : void BibGeneralPage::GetFocus()
     629             : {
     630           0 :     Reference< awt::XWindow >*  pxControl = aControls;
     631             : 
     632           0 :     for( int i = FIELD_COUNT ; i ; --i, ++pxControl )
     633             :     {
     634           0 :         if( pxControl->is() )
     635             :         {
     636           0 :             ( *pxControl )->setFocus();
     637           0 :             return;
     638             :         }
     639             :     }
     640             : 
     641             :     // fallback
     642           0 :     GrabFocus();
     643             : }
     644             : 
     645           0 : bool BibGeneralPage::HandleShortCutKey( const KeyEvent& rKeyEvent )
     646             : {
     647             :     DBG_ASSERT( KEY_MOD2 == rKeyEvent.GetKeyCode().GetModifier(), "+BibGeneralPage::HandleShortCutKey(): this is not for me!" );
     648             : 
     649           0 :     const vcl::I18nHelper&      rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
     650           0 :     const sal_Unicode           c = rKeyEvent.GetCharCode();
     651           0 :     bool                        bHandled = false;
     652             : 
     653             :     sal_Int16                   i;
     654             : 
     655             :     typedef std::vector< sal_Int16 >    sal_Int16_vector;
     656             : 
     657           0 :     sal_Int16_vector::size_type nFocused = 0xFFFF;  // index of focused in vector, no one focused initial
     658             :     DBG_ASSERT( nFocused > 0, "*BibGeneralPage::HandleShortCutKey(): size_type works not as expected!" );
     659             : 
     660           0 :     sal_Int16_vector            aMatchList;
     661             : 
     662           0 :     for( i = 0 ; i < FIELD_COUNT ; ++i )
     663             :     {
     664           0 :         if( rI18nHelper.MatchMnemonic( aFixedTexts[ i ]->GetText(), c ) )
     665             :         {
     666           0 :             bHandled = true;
     667           0 :             sal_Int16           nCtrlIndex = nFT2CtrlMap[ i ];
     668             : 
     669           0 :             if( nCtrlIndex >= 0 )
     670             :             {   // store index of control
     671             :                 DBG_ASSERT( aControls[ nCtrlIndex ].is(), "-BibGeneralPage::HandleShortCutKey(): valid index and no control?" );
     672             : 
     673           0 :                 uno::Reference< awt::XControl >  xControl( aControls[ nCtrlIndex ], UNO_QUERY );
     674             :                 DBG_ASSERT( xControl.is(), "-BibGeneralPage::HandleShortCutKey(): a control which is not a control!" );
     675             : 
     676           0 :                 vcl::Window*         pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
     677             : 
     678           0 :                 if( pWindow )
     679             :                 {
     680           0 :                     aMatchList.push_back( nCtrlIndex );
     681           0 :                     if( pWindow->HasChildPathFocus() )
     682             :                     {   // save focused control
     683             :                         DBG_ASSERT( nFocused == 0xFFFF, "+BibGeneralPage::HandleShortCutKey(): more than one with focus?!" );
     684             :                         DBG_ASSERT( !aMatchList.empty(), "+BibGeneralPage::HandleShortCutKey(): push_back and no content?!" );
     685           0 :                         nFocused = aMatchList.size() - 1;
     686             :                     }
     687           0 :                 }
     688             :             }
     689             :         }
     690             :     }
     691             : 
     692           0 :     if( bHandled )
     693             :     {
     694             :         DBG_ASSERT( !aMatchList.empty(), "*BibGeneralPage::HandleShortCutKey(): be prepared to crash..." );
     695             : 
     696           0 :         if( nFocused >= ( aMatchList.size() - 1 ) )
     697             :             // >=... includes 0xFFFF
     698             :             // no one or last focused, take first
     699           0 :             nFocused = 0;
     700             :         else
     701             :             // take next one
     702           0 :             nFocused++;
     703             : 
     704           0 :         aControls[ aMatchList[ nFocused ] ]->setFocus();
     705             :     }
     706             : 
     707           0 :     return bHandled;
     708          12 : }
     709             : 
     710             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10