LCOV - code coverage report
Current view: top level - sw/source/ui/fldui - fldfunc.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 360 0.0 %
Date: 2014-04-11 Functions: 0 26 0.0 %
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 <sfx2/app.hxx>
      21             : #include <basic/basmgr.hxx>
      22             : #include <basic/sbmod.hxx>
      23             : #include <docsh.hxx>
      24             : #include <swtypes.hxx>
      25             : #include <globals.hrc>
      26             : #include <fldbas.hxx>
      27             : #include <docufld.hxx>
      28             : #include <view.hxx>
      29             : #include <wrtsh.hxx>
      30             : #include <swmodule.hxx>
      31             : #include <fldfunc.hxx>
      32             : #include <flddropdown.hxx>
      33             : #include <fldui.hrc>
      34             : 
      35             : #define USER_DATA_VERSION_1 "1"
      36             : #define USER_DATA_VERSION USER_DATA_VERSION_1
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40           0 : SwFldFuncPage::SwFldFuncPage(Window* pParent, const SfxItemSet& rCoreSet)
      41             :     : SwFldPage(pParent, "FldFuncPage",
      42             :         "modules/swriter/ui/fldfuncpage.ui", rCoreSet)
      43           0 :     , bDropDownLBChanged(false)
      44             : {
      45           0 :     get(m_pTypeLB, "type");
      46           0 :     get(m_pFormat, "formatframe");
      47           0 :     get(m_pSelectionLB, "select");
      48           0 :     get(m_pFormatLB, "format");
      49           0 :     get(m_pNameFT, "nameft");
      50           0 :     get(m_pNameED, "name");
      51           0 :     get(m_pValueGroup, "valuegroup");
      52           0 :     get(m_pValueFT, "valueft");
      53           0 :     get(m_pValueED, "value");
      54           0 :     get(m_pCond1FT, "cond1ft");
      55           0 :     get(m_pCond1ED, "cond1");
      56           0 :     get(m_pCond2FT, "cond2ft");
      57           0 :     get(m_pCond2ED, "cond2");
      58           0 :     get(m_pMacroBT, "macro");
      59             : 
      60           0 :     get(m_pListGroup, "listgroup");
      61           0 :     get(m_pListItemFT, "itemft");
      62           0 :     get(m_pListItemED, "item");
      63           0 :     get(m_pListAddPB, "add");
      64           0 :     get(m_pListItemsFT, "listitemft");
      65           0 :     get(m_pListItemsLB, "listitems");
      66           0 :     m_pListItemsLB->SetDropDownLineCount(5);
      67           0 :     m_pListItemsLB->set_width_request(m_pListItemED->GetOptimalSize().Width());
      68           0 :     get(m_pListRemovePB, "remove");
      69           0 :     get(m_pListUpPB, "up");
      70           0 :     get(m_pListDownPB, "down");
      71           0 :     get(m_pListNameFT, "listnameft");
      72           0 :     get(m_pListNameED, "listname");
      73             : 
      74           0 :     long nHeight = m_pTypeLB->GetTextHeight() * 20;
      75           0 :     m_pTypeLB->set_height_request(nHeight);
      76           0 :     m_pFormatLB->set_height_request(nHeight);
      77             : 
      78           0 :     long nWidth = m_pTypeLB->LogicToPixel(Size(FIELD_COLUMN_WIDTH, 0), MapMode(MAP_APPFONT)).Width();
      79           0 :     m_pTypeLB->set_width_request(nWidth);
      80           0 :     m_pFormatLB->set_width_request(nWidth);
      81             : 
      82           0 :     m_pNameED->SetModifyHdl(LINK(this, SwFldFuncPage, ModifyHdl));
      83             : 
      84           0 :     m_sOldValueFT = m_pValueFT->GetText();
      85           0 :     m_sOldNameFT = m_pNameFT->GetText();
      86             : 
      87           0 :     m_pCond1ED->ShowBrackets(false);
      88           0 :     m_pCond2ED->ShowBrackets(false);
      89             : 
      90           0 : }
      91             : 
      92           0 : SwFldFuncPage::~SwFldFuncPage()
      93             : {
      94           0 : }
      95             : 
      96           0 : void SwFldFuncPage::Reset(const SfxItemSet& )
      97             : {
      98           0 :     SavePos(m_pTypeLB);
      99           0 :     Init(); // general initialisation
     100             : 
     101           0 :     m_pTypeLB->SetUpdateMode(false);
     102           0 :     m_pTypeLB->Clear();
     103             : 
     104             :     sal_Int32 nPos;
     105             : 
     106           0 :     if (!IsFldEdit())
     107             :     {
     108             :         // initialise TypeListBox
     109           0 :         const SwFldGroupRgn& rRg = GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup());
     110             : 
     111             :         // fill Typ-Listbox
     112           0 :         for(sal_uInt16 i = rRg.nStart; i < rRg.nEnd; ++i)
     113             :         {
     114           0 :             const sal_uInt16 nTypeId = GetFldMgr().GetTypeId(i);
     115           0 :             nPos = m_pTypeLB->InsertEntry(GetFldMgr().GetTypeStr(i));
     116           0 :             m_pTypeLB->SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
     117             :         }
     118             :     }
     119             :     else
     120             :     {
     121           0 :         const sal_uInt16 nTypeId = GetCurField()->GetTypeId();
     122           0 :         nPos = m_pTypeLB->InsertEntry(GetFldMgr().GetTypeStr(GetFldMgr().GetPos(nTypeId)));
     123           0 :         m_pTypeLB->SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
     124             : 
     125           0 :         if (nTypeId == TYP_MACROFLD)
     126             :         {
     127           0 :             GetFldMgr().SetMacroPath(GetCurField()->GetPar1());
     128             :         }
     129             :     }
     130             : 
     131             :     // select old Pos
     132           0 :     RestorePos(m_pTypeLB);
     133             : 
     134           0 :     m_pTypeLB->SetDoubleClickHdl       (LINK(this, SwFldFuncPage, InsertHdl));
     135           0 :     m_pTypeLB->SetSelectHdl            (LINK(this, SwFldFuncPage, TypeHdl));
     136           0 :     m_pSelectionLB->SetSelectHdl       (LINK(this, SwFldFuncPage, SelectHdl));
     137           0 :     m_pSelectionLB->SetDoubleClickHdl  (LINK(this, SwFldFuncPage, InsertMacroHdl));
     138           0 :     m_pFormatLB->SetDoubleClickHdl     (LINK(this, SwFldFuncPage, InsertHdl));
     139           0 :     m_pMacroBT->SetClickHdl            (LINK(this, SwFldFuncPage, MacroHdl));
     140           0 :     Link aListModifyLk( LINK(this, SwFldFuncPage, ListModifyHdl));
     141           0 :     m_pListAddPB->SetClickHdl(aListModifyLk);
     142           0 :     m_pListRemovePB->SetClickHdl(aListModifyLk);
     143           0 :     m_pListUpPB->SetClickHdl(aListModifyLk);
     144           0 :     m_pListDownPB->SetClickHdl(aListModifyLk);
     145           0 :     m_pListItemED->SetReturnActionLink(aListModifyLk);
     146           0 :     Link aListEnableLk = LINK(this, SwFldFuncPage, ListEnableHdl);
     147           0 :     m_pListItemED->SetModifyHdl(aListEnableLk);
     148           0 :     m_pListItemsLB->SetSelectHdl(aListEnableLk);
     149             : 
     150           0 :     if( !IsRefresh() )
     151             :     {
     152           0 :         OUString sUserData = GetUserData();
     153           0 :         if(sUserData.getToken(0, ';').equalsIgnoreAsciiCase(USER_DATA_VERSION_1))
     154             :         {
     155           0 :             OUString sVal = sUserData.getToken(1, ';');
     156           0 :             const sal_uInt16 nVal = static_cast< sal_uInt16 >(sVal.toInt32());
     157           0 :             if(nVal != USHRT_MAX)
     158             :             {
     159           0 :                 for(sal_Int32 i = 0; i < m_pTypeLB->GetEntryCount(); i++)
     160           0 :                     if(nVal == (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(i))
     161             :                     {
     162           0 :                         m_pTypeLB->SelectEntryPos(i);
     163           0 :                         break;
     164             :                     }
     165           0 :             }
     166           0 :         }
     167             :     }
     168           0 :     TypeHdl(0);
     169             : 
     170           0 :     m_pTypeLB->SetUpdateMode(true);
     171             : 
     172           0 :     if (IsFldEdit())
     173             :     {
     174           0 :         m_pNameED->SaveValue();
     175           0 :         m_pValueED->SaveValue();
     176           0 :         m_pCond1ED->SaveValue();
     177           0 :         m_pCond2ED->SaveValue();
     178           0 :         nOldFormat = GetCurField()->GetFormat();
     179             :     }
     180           0 : }
     181             : 
     182           0 : IMPL_LINK_NOARG(SwFldFuncPage, TypeHdl)
     183             : {
     184             :     // save old ListBoxPos
     185           0 :     const sal_Int32 nOld = GetTypeSel();
     186             : 
     187             :     // current ListBoxPos
     188           0 :     SetTypeSel(m_pTypeLB->GetSelectEntryPos());
     189             : 
     190           0 :     if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND)
     191             :     {
     192           0 :         SetTypeSel(0);
     193           0 :         m_pTypeLB->SelectEntryPos(0);
     194             :     }
     195             : 
     196           0 :     if (nOld != GetTypeSel())
     197             :     {
     198           0 :         const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     199             : 
     200             :         // fill Selection-Listbox
     201           0 :         UpdateSubType();
     202             : 
     203             :         // fill Format-Listbox
     204           0 :         m_pFormatLB->Clear();
     205             : 
     206           0 :         const sal_uInt16 nSize = GetFldMgr().GetFormatCount(nTypeId, false, IsFldDlgHtmlMode());
     207             : 
     208           0 :         for (sal_uInt16 i = 0; i < nSize; i++)
     209             :         {
     210           0 :             sal_Int32 nPos = m_pFormatLB->InsertEntry(GetFldMgr().GetFormatStr(nTypeId, i));
     211           0 :             m_pFormatLB->SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, i )) );
     212             :         }
     213             : 
     214           0 :         if (nSize)
     215             :         {
     216           0 :             if (IsFldEdit() && nTypeId == TYP_JUMPEDITFLD)
     217           0 :                 m_pFormatLB->SelectEntry(SW_RESSTR(FMT_MARK_BEGIN + GetCurField()->GetFormat()));
     218             : 
     219           0 :             if (!m_pFormatLB->GetSelectEntryCount())
     220           0 :                 m_pFormatLB->SelectEntryPos(0);
     221             :         }
     222             : 
     223           0 :         sal_Bool bValue = sal_False, bName = sal_False, bMacro = sal_False, bInsert = sal_True;
     224           0 :         sal_Bool bFormat = nSize != 0;
     225             : 
     226             :         // two controls for conditional text
     227           0 :         sal_Bool bDropDown = TYP_DROPDOWN == nTypeId;
     228           0 :         sal_Bool bCondTxtFld = TYP_CONDTXTFLD == nTypeId;
     229             : 
     230           0 :         m_pCond1FT->Show(!bDropDown && bCondTxtFld);
     231           0 :         m_pCond1ED->Show(!bDropDown && bCondTxtFld);
     232           0 :         m_pCond2FT->Show(!bDropDown && bCondTxtFld);
     233           0 :         m_pCond2ED->Show(!bDropDown && bCondTxtFld);
     234           0 :         m_pValueGroup->Show(!bDropDown && !bCondTxtFld);
     235           0 :         m_pMacroBT->Show(!bDropDown);
     236           0 :         m_pNameED->Show(!bDropDown);
     237           0 :         m_pNameFT->Show(!bDropDown);
     238             : 
     239           0 :         m_pListGroup->Show(bDropDown);
     240             : 
     241           0 :         m_pNameED->SetDropEnable(false);
     242             : 
     243           0 :         if (IsFldEdit())
     244             :         {
     245           0 :             if(bDropDown)
     246             :             {
     247           0 :                 const SwDropDownField* pDrop = (const SwDropDownField*)GetCurField();
     248           0 :                 uno::Sequence<OUString> aItems = pDrop->GetItemSequence();
     249           0 :                 const OUString* pArray = aItems.getConstArray();
     250           0 :                 m_pListItemsLB->Clear();
     251           0 :                 for(sal_Int32 i = 0; i < aItems.getLength(); i++)
     252           0 :                     m_pListItemsLB->InsertEntry(pArray[i]);
     253           0 :                 m_pListItemsLB->SelectEntry(pDrop->GetSelectedItem());
     254           0 :                 m_pListNameED->SetText(pDrop->GetPar2());
     255           0 :                 m_pListNameED->SaveValue();
     256           0 :                 bDropDownLBChanged = false;
     257             :             }
     258             :             else
     259             :             {
     260           0 :                 m_pNameED->SetText(GetCurField()->GetPar1());
     261           0 :                 m_pValueED->SetText(GetCurField()->GetPar2());
     262             :             }
     263             :         }
     264             :         else
     265             :         {
     266           0 :             m_pNameED->SetText(OUString());
     267           0 :             m_pValueED->SetText(OUString());
     268             :         }
     269           0 :         if(bDropDown)
     270           0 :             ListEnableHdl(0);
     271             : 
     272           0 :         if (m_pNameFT->GetText() != m_sOldNameFT)
     273           0 :             m_pNameFT->SetText(m_sOldNameFT);
     274           0 :         if (m_pValueFT->GetText() != m_sOldValueFT)
     275           0 :             m_pValueFT->SetText(m_sOldValueFT);
     276             : 
     277           0 :         switch (nTypeId)
     278             :         {
     279             :             case TYP_MACROFLD:
     280           0 :                 bMacro = sal_True;
     281           0 :                 if (!GetFldMgr().GetMacroPath().isEmpty())
     282           0 :                     bValue = sal_True;
     283             :                 else
     284           0 :                     bInsert = sal_False;
     285             : 
     286           0 :                 m_pNameFT->SetText(SW_RESSTR(STR_MACNAME));
     287           0 :                 m_pValueFT->SetText(SW_RESSTR(STR_PROMPT));
     288           0 :                 m_pNameED->SetText(GetFldMgr().GetMacroName());
     289           0 :                 m_pNameED->SetAccessibleName(m_pNameFT->GetText());
     290           0 :                 m_pValueED->SetAccessibleName(m_pValueFT->GetText());
     291           0 :                 break;
     292             : 
     293             :             case TYP_HIDDENPARAFLD:
     294           0 :                 m_pNameFT->SetText(SW_RESSTR(STR_COND));
     295           0 :                 m_pNameED->SetDropEnable(true);
     296           0 :                 bName = sal_True;
     297           0 :                 m_pNameED->SetAccessibleName(m_pNameFT->GetText());
     298           0 :                 m_pValueED->SetAccessibleName(m_pValueFT->GetText());
     299           0 :                 break;
     300             : 
     301             :             case TYP_HIDDENTXTFLD:
     302             :             {
     303           0 :                 m_pNameFT->SetText(SW_RESSTR(STR_COND));
     304           0 :                 m_pNameED->SetDropEnable(true);
     305           0 :                 m_pValueFT->SetText(SW_RESSTR(STR_INSTEXT));
     306           0 :                 SwWrtShell* pSh = GetActiveWrtShell();
     307           0 :                 if (!IsFldEdit() && pSh )
     308           0 :                     m_pValueED->SetText(pSh->GetSelTxt());
     309           0 :                 bName = bValue = sal_True;
     310           0 :                 m_pNameED->SetAccessibleName(m_pNameFT->GetText());
     311           0 :                 m_pValueED->SetAccessibleName(m_pValueFT->GetText());
     312             :             }
     313           0 :             break;
     314             : 
     315             :             case TYP_CONDTXTFLD:
     316           0 :                 m_pNameFT->SetText(SW_RESSTR(STR_COND));
     317           0 :                 m_pNameED->SetDropEnable(true);
     318           0 :                 if (IsFldEdit())
     319             :                 {
     320           0 :                     m_pCond1ED->SetText(GetCurField()->GetPar2().getToken(0, '|'));
     321           0 :                     m_pCond2ED->SetText(GetCurField()->GetPar2().getToken(1, '|'));
     322             :                 }
     323             : 
     324           0 :                 bName = bValue = sal_True;
     325           0 :                 m_pNameED->SetAccessibleName(m_pNameFT->GetText());
     326           0 :                 m_pValueED->SetAccessibleName(m_pValueFT->GetText());
     327           0 :                 break;
     328             : 
     329             :             case TYP_JUMPEDITFLD:
     330           0 :                 m_pNameFT->SetText(SW_RESSTR(STR_JUMPEDITFLD));
     331           0 :                 m_pValueFT->SetText(SW_RESSTR(STR_PROMPT));
     332           0 :                 bName = bValue = sal_True;
     333           0 :                 m_pNameED->SetAccessibleName(m_pNameFT->GetText());
     334           0 :                 m_pValueED->SetAccessibleName(m_pValueFT->GetText());
     335           0 :                 break;
     336             : 
     337             :             case TYP_INPUTFLD:
     338           0 :                 m_pValueFT->SetText(SW_RESSTR(STR_PROMPT));
     339           0 :                 bValue = sal_True;
     340           0 :                 m_pNameED->SetAccessibleName(m_pNameFT->GetText());
     341           0 :                 m_pValueED->SetAccessibleName(m_pValueFT->GetText());
     342           0 :                 break;
     343             : 
     344             :             case TYP_COMBINED_CHARS:
     345             :                 {
     346           0 :                     m_pNameFT->SetText(SW_RESSTR(STR_COMBCHRS_FT));
     347           0 :                     m_pNameED->SetDropEnable(true);
     348           0 :                     bName = sal_True;
     349             : 
     350           0 :                     const sal_Int32 nLen = m_pNameED->GetText().getLength();
     351           0 :                     if( !nLen || nLen > MAX_COMBINED_CHARACTERS )
     352           0 :                         bInsert = sal_False;
     353           0 :                     m_pNameED->SetAccessibleName(m_pNameFT->GetText());
     354           0 :                     m_pValueED->SetAccessibleName(m_pValueFT->GetText());
     355             :                 }
     356           0 :                 break;
     357             :             case TYP_DROPDOWN :
     358           0 :             break;
     359             :             default:
     360           0 :                 break;
     361             :         }
     362             : 
     363           0 :         m_pSelectionLB->Hide();
     364             : 
     365           0 :         m_pFormat->Enable(bFormat);
     366           0 :         m_pNameFT->Enable(bName);
     367           0 :         m_pNameED->Enable(bName);
     368           0 :         m_pValueGroup->Enable(bValue);
     369           0 :         m_pMacroBT->Enable(bMacro);
     370             : 
     371           0 :         EnableInsert( bInsert );
     372             :     }
     373             : 
     374           0 :     return 0;
     375             : }
     376             : 
     377           0 : IMPL_LINK_NOARG(SwFldFuncPage, SelectHdl)
     378             : {
     379           0 :     const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     380             : 
     381           0 :     if( TYP_MACROFLD == nTypeId )
     382           0 :         m_pNameED->SetText( m_pSelectionLB->GetSelectEntry() );
     383             : 
     384           0 :     return 0;
     385             : }
     386             : 
     387           0 : IMPL_LINK_NOARG(SwFldFuncPage, InsertMacroHdl)
     388             : {
     389           0 :     SelectHdl();
     390           0 :     InsertHdl();
     391             : 
     392           0 :     return 0;
     393             : }
     394             : 
     395           0 : IMPL_LINK( SwFldFuncPage, ListModifyHdl, Control*, pControl)
     396             : {
     397           0 :     m_pListItemsLB->SetUpdateMode(false);
     398           0 :     if(pControl == m_pListAddPB ||
     399           0 :             (pControl == m_pListItemED && m_pListAddPB->IsEnabled()))
     400             :     {
     401           0 :         const OUString sEntry(m_pListItemED->GetText());
     402           0 :         m_pListItemsLB->InsertEntry(sEntry);
     403           0 :         m_pListItemsLB->SelectEntry(sEntry);
     404             :     }
     405           0 :     else if(m_pListItemsLB->GetSelectEntryCount())
     406             :     {
     407           0 :         sal_Int32 nSelPos = m_pListItemsLB->GetSelectEntryPos();
     408           0 :         if(pControl == m_pListRemovePB)
     409             :         {
     410           0 :             m_pListItemsLB->RemoveEntry(nSelPos);
     411           0 :             m_pListItemsLB->SelectEntryPos(nSelPos ? nSelPos - 1 : 0);
     412             :         }
     413           0 :         else if(pControl == m_pListUpPB)
     414             :         {
     415           0 :             if(nSelPos)
     416             :             {
     417           0 :                 const OUString sEntry = m_pListItemsLB->GetSelectEntry();
     418           0 :                 m_pListItemsLB->RemoveEntry(nSelPos);
     419           0 :                 nSelPos--;
     420           0 :                 m_pListItemsLB->InsertEntry(sEntry, nSelPos);
     421           0 :                 m_pListItemsLB->SelectEntryPos(nSelPos);
     422             :             }
     423             :         }
     424           0 :         else if(pControl == m_pListDownPB)
     425             :         {
     426           0 :             if(nSelPos < m_pListItemsLB->GetEntryCount() - 1)
     427             :             {
     428           0 :                 const OUString sEntry = m_pListItemsLB->GetSelectEntry();
     429           0 :                 m_pListItemsLB->RemoveEntry(nSelPos);
     430           0 :                 nSelPos++;
     431           0 :                 m_pListItemsLB->InsertEntry(sEntry, nSelPos);
     432           0 :                 m_pListItemsLB->SelectEntryPos(nSelPos);
     433             :             }
     434             :         }
     435             :     }
     436           0 :     bDropDownLBChanged = true;
     437           0 :     m_pListItemsLB->SetUpdateMode(true);
     438           0 :     ListEnableHdl(0);
     439           0 :     return 0;
     440             : }
     441             : 
     442           0 : IMPL_LINK_NOARG(SwFldFuncPage, ListEnableHdl)
     443             : {
     444             :     //enable "Add" button when text is in the Edit that's not already member of the box
     445           0 :     m_pListAddPB->Enable(!m_pListItemED->GetText().isEmpty() &&
     446           0 :                 LISTBOX_ENTRY_NOTFOUND == m_pListItemsLB->GetEntryPos(m_pListItemED->GetText()));
     447           0 :     sal_Bool bEnableButtons = m_pListItemsLB->GetSelectEntryCount() > 0;
     448           0 :     m_pListRemovePB->Enable(bEnableButtons);
     449           0 :     m_pListUpPB->Enable(bEnableButtons && (m_pListItemsLB->GetSelectEntryPos() > 0));
     450           0 :     m_pListDownPB->Enable(bEnableButtons &&
     451           0 :                 (m_pListItemsLB->GetSelectEntryPos() < (m_pListItemsLB->GetEntryCount() - 1)));
     452             : 
     453           0 :     return 0;
     454             : }
     455             : 
     456             : /*--------------------------------------------------------------------
     457             :      Description: renew types in SelectionBox
     458             :  --------------------------------------------------------------------*/
     459           0 : void SwFldFuncPage::UpdateSubType()
     460             : {
     461           0 :     const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     462             : 
     463             :     // fill Selction-Listbox
     464           0 :     m_pSelectionLB->SetUpdateMode(false);
     465           0 :     m_pSelectionLB->Clear();
     466             : 
     467           0 :     std::vector<OUString> aLst;
     468           0 :     GetFldMgr().GetSubTypes(nTypeId, aLst);
     469           0 :     const size_t nCount = aLst.size();
     470             : 
     471           0 :     for(size_t i = 0; i < nCount; ++i)
     472             :     {
     473           0 :         size_t nPos = m_pSelectionLB->InsertEntry(aLst[i]);
     474           0 :         m_pSelectionLB->SetEntryData(nPos, reinterpret_cast<void*>(i));
     475             :     }
     476             : 
     477           0 :     sal_Bool bEnable = nCount != 0;
     478             : 
     479           0 :     m_pSelectionLB->Enable( bEnable );
     480             : 
     481           0 :     if (bEnable)
     482             :     {
     483           0 :             m_pSelectionLB->SelectEntryPos(0);
     484             :     }
     485             : 
     486           0 :     if (nTypeId == TYP_MACROFLD)
     487             :     {
     488           0 :         const bool bHasMacro = !GetFldMgr().GetMacroPath().isEmpty();
     489             : 
     490           0 :         if (bHasMacro)
     491             :         {
     492           0 :             m_pNameED->SetText(GetFldMgr().GetMacroName());
     493           0 :             m_pValueGroup->Enable();
     494             :         }
     495           0 :         EnableInsert(bHasMacro);
     496             :     }
     497             : 
     498           0 :     m_pSelectionLB->SetUpdateMode(true);
     499           0 : }
     500             : 
     501             : /*--------------------------------------------------------------------
     502             :     Description: call MacroBrowser, fill Listbox with Macros
     503             :  --------------------------------------------------------------------*/
     504           0 : IMPL_LINK( SwFldFuncPage, MacroHdl, Button *, pBtn )
     505             : {
     506           0 :     Window* pDefModalDlgParent = Application::GetDefDialogParent();
     507           0 :     Application::SetDefDialogParent( pBtn );
     508             : 
     509           0 :     const OUString sMacro(TurnMacroString(m_pNameED->GetText()).replaceAll(".", ";"));
     510           0 :     if (GetFldMgr().ChooseMacro(sMacro))
     511           0 :         UpdateSubType();
     512             : 
     513           0 :     Application::SetDefDialogParent( pDefModalDlgParent );
     514             : 
     515           0 :     return 0;
     516             : }
     517             : 
     518           0 : bool SwFldFuncPage::FillItemSet(SfxItemSet& )
     519             : {
     520           0 :     const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     521             : 
     522           0 :     sal_uInt16 nSubType = 0;
     523             : 
     524           0 :     const sal_Int32 nEntryPos = m_pFormatLB->GetSelectEntryPos();
     525             :     const sal_uLong nFormat = (nEntryPos == LISTBOX_ENTRY_NOTFOUND)
     526           0 :         ? 0 : (sal_uLong)m_pFormatLB->GetEntryData(nEntryPos);
     527             : 
     528           0 :     OUString aVal(m_pValueED->GetText());
     529           0 :     OUString aName(m_pNameED->GetText());
     530             : 
     531           0 :     switch(nTypeId)
     532             :     {
     533             :         case TYP_INPUTFLD:
     534           0 :             nSubType = INP_TXT;
     535             :             // to prevent removal of CR/LF restore old content
     536           0 :             if(!m_pNameED->IsModified() && IsFldEdit())
     537           0 :                 aName = GetCurField()->GetPar1();
     538             : 
     539           0 :             break;
     540             : 
     541             :         case TYP_MACROFLD:
     542             :             // use the full script URL, not the name in the Edit control
     543           0 :             aName = GetFldMgr().GetMacroPath();
     544           0 :             break;
     545             : 
     546             :         case TYP_CONDTXTFLD:
     547           0 :             aVal = m_pCond1ED->GetText() + "|" + m_pCond2ED->GetText();
     548           0 :             break;
     549             :         case TYP_DROPDOWN :
     550             :         {
     551           0 :             aName = m_pListNameED->GetText();
     552           0 :             for(sal_Int32 i = 0; i < m_pListItemsLB->GetEntryCount(); i++)
     553             :             {
     554           0 :                 if(i)
     555           0 :                     aVal += OUString(DB_DELIM);
     556           0 :                 aVal += m_pListItemsLB->GetEntry(i);
     557             :             }
     558             :         }
     559           0 :         break;
     560             :         default:
     561           0 :             break;
     562             :     }
     563             : 
     564           0 :     if (!IsFldEdit() ||
     565           0 :         m_pNameED->GetSavedValue() != m_pNameED->GetText() ||
     566           0 :         m_pValueED->GetSavedValue() != m_pValueED->GetText() ||
     567           0 :         m_pCond1ED->GetSavedValue() != m_pCond1ED->GetText() ||
     568           0 :         m_pCond2ED->GetSavedValue() != m_pCond2ED->GetText() ||
     569           0 :         m_pListNameED->GetSavedValue() != m_pListNameED->GetText() ||
     570           0 :         bDropDownLBChanged ||
     571           0 :         nOldFormat != nFormat)
     572             :     {
     573           0 :         InsertFld( nTypeId, nSubType, aName, aVal, nFormat );
     574             :     }
     575             : 
     576           0 :     ModifyHdl();    // enable/disable Insert if applicable
     577             : 
     578           0 :     return false;
     579             : }
     580             : 
     581           0 : OUString SwFldFuncPage::TurnMacroString(const OUString &rMacro)
     582             : {
     583           0 :     if (!rMacro.isEmpty())
     584             :     {
     585             :         // reverse content of aName
     586           0 :         OUString sMacro;
     587           0 :         sal_Int32 nPos = 0;
     588             : 
     589           0 :         for (int i = 0; i < 4 && nPos != -1; i++)
     590             :         {
     591             :             OUString sTmp = (i == 3)
     592             :                 ? rMacro.copy(nPos)
     593           0 :                 : rMacro.getToken(0, '.', nPos);
     594             : 
     595           0 :             sMacro = !sMacro.isEmpty()
     596           0 :                 ? sTmp + "." + sMacro
     597           0 :                 : sTmp;
     598           0 :         }
     599           0 :         return sMacro;
     600             :     }
     601             : 
     602           0 :     return rMacro;
     603             : }
     604             : 
     605           0 : SfxTabPage* SwFldFuncPage::Create(  Window* pParent,
     606             :                         const SfxItemSet& rAttrSet )
     607             : {
     608           0 :     return ( new SwFldFuncPage( pParent, rAttrSet ) );
     609             : }
     610             : 
     611           0 : sal_uInt16 SwFldFuncPage::GetGroup()
     612             : {
     613           0 :     return GRP_FKT;
     614             : }
     615             : 
     616           0 : void    SwFldFuncPage::FillUserData()
     617             : {
     618           0 :     const sal_Int32 nEntryPos = m_pTypeLB->GetSelectEntryPos();
     619             :     const sal_uInt16 nTypeSel = ( LISTBOX_ENTRY_NOTFOUND == nEntryPos )
     620             :         ? USHRT_MAX
     621             :         : sal::static_int_cast< sal_uInt16 >
     622           0 :             (reinterpret_cast< sal_uIntPtr >(m_pTypeLB->GetEntryData( nEntryPos )));
     623           0 :     SetUserData(USER_DATA_VERSION ";" + OUString::number( nTypeSel ));
     624           0 : }
     625             : 
     626           0 : IMPL_LINK_NOARG(SwFldFuncPage, ModifyHdl)
     627             : {
     628           0 :     const sal_Int32 nLen = m_pNameED->GetText().getLength();
     629             : 
     630           0 :     sal_Bool bEnable = sal_True;
     631           0 :     sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     632             : 
     633           0 :     if( TYP_COMBINED_CHARS == nTypeId &&
     634           0 :         (!nLen || nLen > MAX_COMBINED_CHARACTERS ))
     635           0 :         bEnable = sal_False;
     636             : 
     637           0 :     EnableInsert( bEnable );
     638             : 
     639           0 :     return 0;
     640           0 : }
     641             : 
     642             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10