LCOV - code coverage report
Current view: top level - sw/source/ui/fldui - fldvar.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 679 0.0 %
Date: 2014-04-11 Functions: 0 27 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 <swtypes.hxx>
      21             : #include <sfx2/linkmgr.hxx>
      22             : #include <usrfld.hxx>
      23             : #include <docufld.hxx>
      24             : #include <expfld.hxx>
      25             : #include <ddefld.hxx>
      26             : #include <view.hxx>
      27             : #include <wrtsh.hxx>
      28             : #include <doc.hxx>
      29             : #include <docary.hxx>
      30             : #include <swmodule.hxx>
      31             : #include <fldvar.hxx>
      32             : #include <calc.hxx>
      33             : #include <svl/zformat.hxx>
      34             : #include <globals.hrc>
      35             : #include <fldui.hrc>
      36             : 
      37             : #define USER_DATA_VERSION_1 "1"
      38             : #define USER_DATA_VERSION USER_DATA_VERSION_1
      39             : 
      40           0 : SwFldVarPage::SwFldVarPage(Window* pParent, const SfxItemSet& rCoreSet )
      41             :     : SwFldPage(pParent, "FldVarPage",
      42             :         "modules/swriter/ui/fldvarpage.ui", rCoreSet)
      43           0 :     , bInit(true)
      44             : {
      45           0 :     get(m_pTypeLB, "type");
      46           0 :     get(m_pSelection, "selectframe");
      47           0 :     get(m_pSelectionLB, "select");
      48           0 :     get(m_pFormat, "formatframe");
      49           0 :     get(m_pChapterFrame, "chapterframe");
      50           0 :     get(m_pNameFT, "nameft");
      51           0 :     get(m_pNameED, "name");
      52           0 :     get(m_pValueFT, "valueft");
      53           0 :     get(m_pValueED, "value");
      54           0 :     get(m_pNumFormatLB, "numformat");
      55           0 :     get(m_pFormatLB, "format");
      56           0 :     get(m_pChapterLevelLB, "level");
      57           0 :     get(m_pInvisibleCB, "invisible");
      58           0 :     get(m_pSeparatorFT, "separatorft");
      59           0 :     get(m_pSeparatorED, "separator");
      60           0 :     get(m_pNewDelTBX, "toolbar");
      61             : 
      62           0 :     long nHeight = m_pTypeLB->GetTextHeight() * 20;
      63           0 :     m_pTypeLB->set_height_request(nHeight);
      64           0 :     m_pSelectionLB->set_height_request(nHeight);
      65           0 :     m_pFormatLB->set_height_request(nHeight/2);
      66             : 
      67           0 :     long nWidth = m_pTypeLB->LogicToPixel(Size(FIELD_COLUMN_WIDTH, 0), MapMode(MAP_APPFONT)).Width();
      68           0 :     m_pTypeLB->set_width_request(nWidth);
      69           0 :     m_pSelectionLB->set_width_request(nWidth);
      70           0 :     m_pFormatLB->set_width_request(nWidth);
      71             : 
      72           0 :     m_nApplyId = m_pNewDelTBX->GetItemId("apply");
      73           0 :     m_nDeleteId = m_pNewDelTBX->GetItemId("delete");
      74             : 
      75           0 :     sOldValueFT = m_pValueFT->GetText();
      76           0 :     sOldNameFT = m_pNameFT->GetText();
      77             : 
      78           0 :     for (sal_uInt16 i = 1; i <= MAXLEVEL; i++)
      79           0 :         m_pChapterLevelLB->InsertEntry(OUString::number(i));
      80             : 
      81           0 :     m_pChapterLevelLB->SelectEntryPos(0);
      82             :     //enable 'active' language selection
      83           0 :     m_pNumFormatLB->SetShowLanguageControl(sal_True);
      84           0 : }
      85             : 
      86           0 : SwFldVarPage::~SwFldVarPage()
      87             : {
      88           0 : }
      89             : 
      90           0 : void SwFldVarPage::Reset(const SfxItemSet& )
      91             : {
      92           0 :     SavePos(m_pTypeLB);
      93             : 
      94           0 :     Init(); // general initialisation
      95             : 
      96           0 :     m_pTypeLB->SetUpdateMode(false);
      97           0 :     m_pTypeLB->Clear();
      98             : 
      99             :     sal_Int32 nPos;
     100             :     sal_uInt16 nTypeId;
     101             : 
     102           0 :     if (!IsFldEdit())
     103             :     {
     104             :         // initialise TypeListBox
     105           0 :         const SwFldGroupRgn& rRg = GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup());
     106             : 
     107           0 :         for (short i = rRg.nStart; i < rRg.nEnd; ++i)
     108             :         {
     109           0 :             nTypeId = GetFldMgr().GetTypeId(i);
     110           0 :             nPos = m_pTypeLB->InsertEntry(GetFldMgr().GetTypeStr(i));
     111           0 :             m_pTypeLB->SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
     112             :         }
     113             :     }
     114             :     else
     115             :     {
     116           0 :         SwField* pCurField = GetCurField();
     117           0 :         nTypeId = pCurField->GetTypeId();
     118           0 :         if (nTypeId == TYP_SETINPFLD)
     119           0 :             nTypeId = TYP_INPUTFLD;
     120           0 :         nPos = m_pTypeLB->InsertEntry(GetFldMgr().GetTypeStr(GetFldMgr().GetPos(nTypeId)));
     121           0 :         m_pTypeLB->SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
     122           0 :         m_pNumFormatLB->SetAutomaticLanguage(pCurField->IsAutomaticLanguage());
     123           0 :         SwWrtShell *pSh = GetWrtShell();
     124           0 :         if(!pSh)
     125           0 :             pSh = ::GetActiveWrtShell();
     126           0 :         if(pSh)
     127             :         {
     128           0 :             const SvNumberformat* pFormat = pSh->GetNumberFormatter()->GetEntry(pCurField->GetFormat());
     129           0 :             if(pFormat)
     130           0 :                 m_pNumFormatLB->SetLanguage(pFormat->GetLanguage());
     131             :         }
     132             :     }
     133             : 
     134             :     // select old Pos
     135           0 :     RestorePos(m_pTypeLB);
     136             : 
     137           0 :     m_pTypeLB->SetDoubleClickHdl       (LINK(this, SwFldVarPage, InsertHdl));
     138           0 :     m_pTypeLB->SetSelectHdl            (LINK(this, SwFldVarPage, TypeHdl));
     139           0 :     m_pSelectionLB->SetSelectHdl       (LINK(this, SwFldVarPage, SubTypeHdl));
     140           0 :     m_pSelectionLB->SetDoubleClickHdl  (LINK(this, SwFldVarPage, InsertHdl));
     141           0 :     m_pFormatLB->SetDoubleClickHdl     (LINK(this, SwFldVarPage, InsertHdl));
     142           0 :     m_pNumFormatLB->SetDoubleClickHdl  (LINK(this, SwFldVarPage, InsertHdl));
     143           0 :     m_pNameED->SetModifyHdl            (LINK(this, SwFldVarPage, ModifyHdl));
     144           0 :     m_pValueED->SetModifyHdl           (LINK(this, SwFldVarPage, ModifyHdl));
     145           0 :     m_pNewDelTBX->SetClickHdl          (LINK(this, SwFldVarPage, TBClickHdl));
     146           0 :     m_pChapterLevelLB->SetSelectHdl    (LINK(this, SwFldVarPage, ChapterHdl));
     147           0 :     m_pSeparatorED->SetModifyHdl       (LINK(this, SwFldVarPage, SeparatorHdl));
     148             : 
     149           0 :     if( !IsRefresh() )
     150             :     {
     151           0 :         OUString sUserData = GetUserData();
     152           0 :         if(!IsRefresh() && sUserData.getToken(0, ';').equalsIgnoreAsciiCase(USER_DATA_VERSION_1))
     153             :         {
     154           0 :             OUString sVal = sUserData.getToken(1, ';');
     155           0 :             sal_uInt16 nVal = (sal_uInt16)sVal.toInt32();
     156           0 :             if( USHRT_MAX != nVal )
     157             :             {
     158           0 :                 for(sal_Int32 i = 0; i < m_pTypeLB->GetEntryCount(); i++)
     159           0 :                     if(nVal == (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(i))
     160             :                     {
     161           0 :                         m_pTypeLB->SelectEntryPos(i);
     162           0 :                         break;
     163             :                     }
     164           0 :             }
     165           0 :         }
     166             :     }
     167           0 :     TypeHdl(0);
     168             : 
     169           0 :     m_pTypeLB->SetUpdateMode(true);
     170             : 
     171           0 :     if (IsFldEdit())
     172             :     {
     173           0 :         m_pSelectionLB->SaveValue();
     174           0 :         m_pFormatLB->SaveValue();
     175           0 :         nOldFormat = m_pNumFormatLB->GetFormat();
     176           0 :         m_pNameED->SaveValue();
     177           0 :         m_pValueED->SaveValue();
     178           0 :         m_pInvisibleCB->SaveValue();
     179           0 :         m_pChapterLevelLB->SaveValue();
     180           0 :         m_pSeparatorED->SaveValue();
     181             :     }
     182           0 : }
     183             : 
     184           0 : IMPL_LINK_NOARG(SwFldVarPage, TypeHdl)
     185             : {
     186             :     // save old ListBoxPos
     187           0 :     const sal_Int32 nOld = GetTypeSel();
     188             : 
     189             :     // current ListBoxPos
     190           0 :     SetTypeSel(m_pTypeLB->GetSelectEntryPos());
     191             : 
     192           0 :     if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND)
     193             :     {
     194           0 :         SetTypeSel(0);
     195           0 :         m_pTypeLB->SelectEntryPos(0);
     196             :     }
     197             : 
     198           0 :     if (nOld != GetTypeSel() || nOld == LISTBOX_ENTRY_NOTFOUND)
     199             :     {
     200           0 :         bInit = sal_True;
     201           0 :         if (nOld != LISTBOX_ENTRY_NOTFOUND)
     202             :         {
     203           0 :             m_pNameED->SetText(OUString());
     204           0 :             m_pValueED->SetText(OUString());
     205             :         }
     206             : 
     207           0 :         m_pValueED->SetDropEnable(false);
     208           0 :         UpdateSubType();    // initialise selection-listboxes
     209             :     }
     210             : 
     211           0 :     bInit = sal_False;
     212             : 
     213           0 :     return 0;
     214             : }
     215             : 
     216           0 : IMPL_LINK( SwFldVarPage, SubTypeHdl, ListBox *, pBox )
     217             : {
     218           0 :     sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     219           0 :     sal_Int32 nSelPos = m_pSelectionLB->GetSelectEntryPos();
     220           0 :     sal_uInt16 nSelData = USHRT_MAX;
     221             : 
     222           0 :     if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
     223           0 :         nSelData = (sal_uInt16)(sal_uLong)m_pSelectionLB->GetEntryData(nSelPos);
     224             : 
     225           0 :     if (IsFldEdit() && (!pBox || bInit))
     226             :     {
     227           0 :         if (nTypeId != TYP_FORMELFLD)
     228           0 :             m_pNameED->SetText(GetFldMgr().GetCurFldPar1());
     229             : 
     230           0 :         m_pValueED->SetText(GetFldMgr().GetCurFldPar2());
     231             :     }
     232             : 
     233           0 :     if (m_pNameFT->GetText() != OUString(sOldNameFT))
     234           0 :         m_pNameFT->SetText(sOldNameFT);
     235           0 :     if (m_pValueFT->GetText() != OUString(sOldValueFT))
     236           0 :         m_pValueFT->SetText(sOldValueFT);
     237             : 
     238           0 :     m_pNumFormatLB->SetUpdateMode(false);
     239           0 :     m_pFormatLB->SetUpdateMode(false);
     240           0 :     FillFormatLB(nTypeId);
     241             : 
     242           0 :     sal_Int32 nSize = m_pFormatLB->GetEntryCount();
     243             : 
     244           0 :     sal_Bool bValue = sal_False, bName = sal_False, bNumFmt = sal_False,
     245           0 :             bInvisible = sal_False, bShowChapterFrame = sal_False;
     246           0 :     sal_Bool bFormat = nSize != 0;
     247             : 
     248           0 :     switch (nTypeId)
     249             :     {
     250             :         case TYP_USERFLD:
     251             :         {
     252             :             // change or create user type
     253             :             SwUserFieldType* pType = (SwUserFieldType*)
     254           0 :                 GetFldMgr().GetFldType(RES_USERFLD, nSelData);
     255             : 
     256           0 :             if (pType)
     257             :             {
     258           0 :                 if (!IsFldEdit())
     259             :                 {
     260           0 :                     if (pBox || (bInit && !IsRefresh()))    // only when interacting via mouse
     261             :                     {
     262           0 :                         m_pNameED->SetText(pType->GetName());
     263             : 
     264           0 :                         if (pType->GetType() == UF_STRING)
     265             :                         {
     266           0 :                             m_pValueED->SetText(pType->GetContent());
     267           0 :                             m_pNumFormatLB->SelectEntryPos(0);
     268             :                         }
     269             :                         else
     270           0 :                             m_pValueED->SetText(pType->GetContent());
     271             :                     }
     272             :                 }
     273             :                 else
     274           0 :                     m_pValueED->SetText(pType->GetContent());
     275             :             }
     276             :             else
     277             :             {
     278           0 :                 if (pBox)   // only when interacting via mouse
     279             :                 {
     280           0 :                     m_pNameED->SetText(OUString());
     281           0 :                     m_pValueED->SetText(OUString());
     282             :                 }
     283             :             }
     284           0 :             bValue = bName = bNumFmt = bInvisible = sal_True;
     285             : 
     286           0 :             m_pValueED->SetDropEnable(true);
     287           0 :             break;
     288             :         }
     289             : 
     290             :         case TYP_SETFLD:
     291           0 :             bValue = sal_True;
     292             : 
     293           0 :             bNumFmt = bInvisible = sal_True;
     294             : 
     295           0 :             if (!IsFldDlgHtmlMode())
     296           0 :                 bName = sal_True;
     297             :             else
     298             :             {
     299           0 :                 m_pNumFormatLB->Clear();
     300           0 :                 sal_Int32 nPos = m_pNumFormatLB->InsertEntry(SW_RESSTR(FMT_SETVAR_TEXT), 0);
     301           0 :                 m_pNumFormatLB->SetEntryData(nPos, (void *)ULONG_MAX);
     302           0 :                 m_pNumFormatLB->SelectEntryPos(0);
     303             :             }
     304             :             // is there a corresponding SetField
     305           0 :             if (IsFldEdit() || pBox)    // only when interacting via mouse
     306             :             {
     307           0 :                 if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
     308             :                 {
     309           0 :                     OUString sName(m_pSelectionLB->GetSelectEntry());
     310           0 :                     m_pNameED->SetText(sName);
     311             : 
     312           0 :                     if (!IsFldDlgHtmlMode())
     313             :                     {
     314           0 :                         SwWrtShell *pSh = GetWrtShell();
     315           0 :                         if(!pSh)
     316           0 :                             pSh = ::GetActiveWrtShell();
     317           0 :                         if(pSh)
     318             :                         {
     319             :                             SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
     320           0 :                                     pSh->GetFldType(RES_SETEXPFLD, sName);
     321             : 
     322           0 :                             if (pSetTyp && pSetTyp->GetType() == nsSwGetSetExpType::GSE_STRING)
     323           0 :                                 m_pNumFormatLB->SelectEntryPos(0); // textual
     324             :                         }
     325           0 :                     }
     326             :                 }
     327             :             }
     328           0 :             if (IsFldEdit())
     329             :             {
     330             :                 // GetFormula leads to problems with date formats because
     331             :                 // only the numeric value without formatting is returned.
     332             :                 // It must be used though because otherwise in GetPar2 only
     333             :                 // the value calculated by Kalkulator would be displayed
     334             :                 // (instead of test2 = test + 1)
     335           0 :                 m_pValueED->SetText(((SwSetExpField*)GetCurField())->GetFormula());
     336             :             }
     337           0 :             m_pValueED->SetDropEnable(true);
     338           0 :             break;
     339             : 
     340             :         case TYP_FORMELFLD:
     341             :             {
     342           0 :                 bValue = sal_True;
     343           0 :                 bNumFmt = sal_True;
     344           0 :                 m_pValueFT->SetText(SW_RESSTR(STR_FORMULA));
     345           0 :                 m_pValueED->SetDropEnable(true);
     346             :             }
     347           0 :             break;
     348             : 
     349             :         case TYP_GETFLD:
     350             :             {
     351           0 :                 if (!IsFldEdit())
     352             :                 {
     353           0 :                     m_pNameED->SetText(OUString());
     354           0 :                     m_pValueED->SetText(OUString());
     355             :                 }
     356             : 
     357           0 :                 if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
     358             :                 {
     359           0 :                     OUString sName(m_pSelectionLB->GetSelectEntry());
     360           0 :                     if (!IsFldEdit())
     361           0 :                         m_pNameED->SetText(sName);
     362             : 
     363             :                     // is there a corresponding SetField
     364           0 :                     SwWrtShell *pSh = GetWrtShell();
     365           0 :                     if(!pSh)
     366           0 :                         pSh = ::GetActiveWrtShell();
     367           0 :                     if(pSh)
     368             :                     {
     369             :                         SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
     370           0 :                                 pSh->GetFldType(RES_SETEXPFLD, sName);
     371             : 
     372           0 :                         if(pSetTyp)
     373             :                         {
     374           0 :                             if (pSetTyp->GetType() & nsSwGetSetExpType::GSE_STRING)    // textual?
     375           0 :                                 bFormat = sal_True;
     376             :                             else                    // numeric
     377           0 :                                 bNumFmt = sal_True;
     378             :                         }
     379           0 :                     }
     380             :                 }
     381             :                 else
     382           0 :                     bFormat = sal_False;
     383             : 
     384           0 :                 EnableInsert(bFormat|bNumFmt);
     385             :             }
     386           0 :             break;
     387             : 
     388             :         case TYP_INPUTFLD:
     389           0 :             m_pValueFT->SetText(SW_RESSTR(STR_PROMPT));
     390             : 
     391           0 :             if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
     392             :             {
     393           0 :                 bValue = bNumFmt = sal_True;
     394             : 
     395           0 :                 OUString sName;
     396             : 
     397           0 :                 sName = m_pSelectionLB->GetSelectEntry();
     398           0 :                 m_pNameED->SetText( sName );
     399             : 
     400             :                 // User- or SetField ?
     401             :                 const sal_uInt16 nInpType = static_cast< sal_uInt16 >
     402           0 :                     (GetFldMgr().GetFldType(RES_USERFLD, sName) ? 0 : TYP_SETINPFLD);
     403             : 
     404           0 :                 if (nInpType)   // SETEXPFLD
     405             :                 {
     406             :                     // is there a corresponding SetField
     407             :                     SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
     408           0 :                                 GetFldMgr().GetFldType(RES_SETEXPFLD, sName);
     409             : 
     410           0 :                     if(pSetTyp)
     411             :                     {
     412           0 :                         if (pSetTyp->GetType() == nsSwGetSetExpType::GSE_STRING)    // textual?
     413             :                         {
     414           0 :                             m_pNumFormatLB->Clear();
     415             : 
     416           0 :                             sal_Int32 nPos = m_pNumFormatLB->InsertEntry(SW_RESSTR(FMT_USERVAR_TEXT), 0);
     417           0 :                             m_pNumFormatLB->SetEntryData(nPos, (void *)ULONG_MAX);
     418           0 :                             m_pNumFormatLB->SelectEntryPos(0);
     419             :                         }
     420             :                     }
     421           0 :                     if (IsFldEdit() && (!pBox || bInit) )
     422           0 :                         m_pValueED->SetText(((SwSetExpField*)GetCurField())->GetPromptText());
     423             :                 }
     424             :                 else    // USERFLD
     425           0 :                     bFormat = bNumFmt = sal_False;
     426             :             }
     427           0 :             break;
     428             : 
     429             :         case TYP_DDEFLD:
     430           0 :             m_pValueFT->SetText(SW_RESSTR(STR_DDE_CMD));
     431             : 
     432           0 :             if (IsFldEdit() || pBox)    // only when interacting via mouse
     433             :             {
     434           0 :                 if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
     435             :                 {
     436             :                     SwDDEFieldType* pType =
     437           0 :                         (SwDDEFieldType*) GetFldMgr().GetFldType(RES_DDEFLD, nSelData);
     438             : 
     439           0 :                     if(pType)
     440             :                     {
     441           0 :                         m_pNameED->SetText(pType->GetName());
     442             : 
     443             :                         //JP 28.08.95: DDE-Topics/-Items can have blanks in their names!
     444             :                         //              That's not considered here yet
     445           0 :                         OUString sCmd( pType->GetCmd() );
     446           0 :                         sal_Int32 nTmpPos = 0;
     447           0 :                         sCmd = sCmd.replaceFirst( OUString(sfx2::cTokenSeparator), " ", &nTmpPos );
     448           0 :                         sCmd = sCmd.replaceFirst( OUString(sfx2::cTokenSeparator), " ", &nTmpPos );
     449             : 
     450           0 :                         m_pValueED->SetText( sCmd );
     451           0 :                         m_pFormatLB->SelectEntryPos(pType->GetType());
     452             :                     }
     453             :                 }
     454             :             }
     455           0 :             bName = bValue = sal_True;
     456           0 :             break;
     457             : 
     458             :         case TYP_SEQFLD:
     459             :             {
     460           0 :                 bName = bValue = bShowChapterFrame = true;
     461             : 
     462             :                 SwFieldType* pFldTyp;
     463           0 :                 if( IsFldEdit() )
     464           0 :                     pFldTyp = GetCurField()->GetTyp();
     465             :                 else
     466             :                 {
     467           0 :                     OUString sFldTypeName( m_pSelectionLB->GetEntry( nSelPos ));
     468           0 :                     if( !sFldTypeName.isEmpty() )
     469           0 :                         pFldTyp = GetFldMgr().GetFldType( RES_SETEXPFLD,
     470           0 :                                                           sFldTypeName );
     471             :                     else
     472           0 :                         pFldTyp = 0;
     473             :                 }
     474             : 
     475           0 :                 if( IsFldEdit() )
     476           0 :                     m_pValueED->SetText( ((SwSetExpField*)GetCurField())->
     477           0 :                                         GetFormula() );
     478             : 
     479           0 :                 if( IsFldEdit() || pBox )   // only when interacting via mouse
     480           0 :                     m_pNameED->SetText( m_pSelectionLB->GetSelectEntry() );
     481             : 
     482           0 :                 if( pFldTyp )
     483             :                 {
     484           0 :                     sal_uInt8 nLevel = ((SwSetExpFieldType*)pFldTyp)->GetOutlineLvl();
     485           0 :                     if( 0x7f == nLevel )
     486           0 :                         m_pChapterLevelLB->SelectEntryPos( 0 );
     487             :                     else
     488           0 :                         m_pChapterLevelLB->SelectEntryPos( nLevel + 1 );
     489           0 :                     OUString sDelim = ((SwSetExpFieldType*)pFldTyp)->GetDelimiter();
     490           0 :                     m_pSeparatorED->SetText( sDelim );
     491           0 :                     ChapterHdl();
     492             :                 }
     493             :             }
     494           0 :             break;
     495             : 
     496             :         case TYP_SETREFPAGEFLD:
     497             :             {
     498           0 :                 bValue = sal_False;
     499           0 :                 m_pValueFT->SetText( SW_RESSTR( STR_OFFSET ));
     500             : 
     501           0 :                 if (IsFldEdit() || pBox)    // only when interacting via mouse
     502           0 :                     m_pNameED->SetText(OUString());
     503             : 
     504           0 :                 if (nSelPos != 0 && nSelPos != LISTBOX_ENTRY_NOTFOUND)
     505             :                 {
     506           0 :                     bValue = sal_True;      // SubType OFF - knows no Offset
     507           0 :                     if (IsFldEdit())
     508           0 :                         m_pValueED->SetText(OUString::number(((SwRefPageSetField*)GetCurField())->GetOffset()));
     509             :                 }
     510             :             }
     511           0 :             break;
     512             : 
     513             :         case TYP_GETREFPAGEFLD:
     514           0 :             m_pNameED->SetText(OUString());
     515           0 :             m_pValueED->SetText(OUString());
     516           0 :             break;
     517             :     }
     518             : 
     519           0 :     m_pNumFormatLB->Show(bNumFmt);
     520           0 :     m_pFormatLB->Show(!bNumFmt);
     521             : 
     522           0 :     if (IsFldEdit())
     523           0 :         bName = sal_False;
     524             : 
     525           0 :     m_pFormat->Enable(bFormat|bNumFmt);
     526           0 :     m_pNameFT->Enable(bName);
     527           0 :     m_pNameED->Enable(bName);
     528           0 :     m_pValueFT->Enable(bValue);
     529           0 :     m_pValueED->Enable(bValue);
     530             : 
     531           0 :     m_pInvisibleCB->Show(!bShowChapterFrame);
     532           0 :     m_pChapterFrame->Show(bShowChapterFrame);
     533           0 :     m_pInvisibleCB->Enable(bInvisible);
     534             : 
     535           0 :     ModifyHdl();    // apply/insert/delete status update
     536             : 
     537           0 :     m_pNumFormatLB->SetUpdateMode(true);
     538           0 :     m_pFormatLB->SetUpdateMode(true);
     539             : 
     540           0 :     if(m_pSelectionLB->IsCallAddSelection())
     541             :     {
     542           0 :         nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     543             : 
     544           0 :         switch (nTypeId)
     545             :         {
     546             :             case TYP_FORMELFLD:
     547             :                 {
     548           0 :                     nSelPos = m_pSelectionLB->GetSelectEntryPos();
     549             : 
     550           0 :                     if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
     551           0 :                         nSelData = (sal_uInt16)(sal_uLong)m_pSelectionLB->GetEntryData(nSelPos);
     552             :                     else
     553           0 :                         nSelData = USHRT_MAX;
     554             : 
     555           0 :                     if (nSelData != USHRT_MAX && pBox && !bInit)
     556             :                     {
     557           0 :                         m_pValueED->ReplaceSelected(m_pSelectionLB->GetSelectEntry());
     558           0 :                         ModifyHdl();
     559             :                     }
     560             :                 }
     561           0 :                 break;
     562             :         }
     563           0 :         m_pSelectionLB->ResetCallAddSelection();
     564             :     }
     565           0 :     return 0;
     566             : }
     567             : 
     568             : /*--------------------------------------------------------------------
     569             :      Description: renew types in SelectionBox
     570             :  --------------------------------------------------------------------*/
     571           0 : void SwFldVarPage::UpdateSubType()
     572             : {
     573           0 :     OUString sOldSel;
     574           0 :     const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     575             : 
     576           0 :     SetSelectionSel(m_pSelectionLB->GetSelectEntryPos());
     577           0 :     if(GetSelectionSel() != LISTBOX_ENTRY_NOTFOUND)
     578           0 :         sOldSel = m_pSelectionLB->GetEntry(GetSelectionSel());
     579             : 
     580             :     // fill Selection-Listbox
     581           0 :     m_pSelectionLB->SetUpdateMode(false);
     582           0 :     m_pSelectionLB->Clear();
     583             : 
     584           0 :     std::vector<OUString> aList;
     585           0 :     GetFldMgr().GetSubTypes(nTypeId, aList);
     586           0 :     size_t nCount = aList.size();
     587             :     size_t nPos;
     588             : 
     589           0 :     for(size_t i = 0; i < nCount; ++i)
     590             :     {
     591           0 :         if (nTypeId != TYP_INPUTFLD || i)
     592             :         {
     593           0 :             if (!IsFldEdit())
     594             :             {
     595           0 :                 nPos = m_pSelectionLB->InsertEntry(aList[i]);
     596           0 :                 m_pSelectionLB->SetEntryData(nPos, reinterpret_cast<void*>(i));
     597             :             }
     598             :             else
     599             :             {
     600           0 :                 sal_Bool bInsert = sal_False;
     601             : 
     602           0 :                 switch (nTypeId)
     603             :                 {
     604             :                     case TYP_INPUTFLD:
     605           0 :                         if (aList[i] == GetCurField()->GetPar1())
     606           0 :                             bInsert = sal_True;
     607           0 :                         break;
     608             : 
     609             :                     case TYP_FORMELFLD:
     610           0 :                         bInsert = sal_True;
     611           0 :                         break;
     612             : 
     613             :                     case TYP_GETFLD:
     614           0 :                         if (aList[i].equals(((const SwFormulaField*)GetCurField())->GetFormula()))
     615           0 :                             bInsert = sal_True;
     616           0 :                         break;
     617             : 
     618             :                     case TYP_SETFLD:
     619             :                     case TYP_USERFLD:
     620           0 :                         if (aList[i] == GetCurField()->GetTyp()->GetName())
     621             :                         {
     622           0 :                             bInsert = sal_True;
     623           0 :                             if (GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE)
     624           0 :                                 m_pInvisibleCB->Check();
     625             :                         }
     626           0 :                         break;
     627             : 
     628             :                     case TYP_SETREFPAGEFLD:
     629           0 :                         if ((((SwRefPageSetField*)GetCurField())->IsOn() && i) ||
     630           0 :                             (!((SwRefPageSetField*)GetCurField())->IsOn() && !i))
     631           0 :                             sOldSel = aList[i];
     632             : 
     633             :                         // allow all entries for selection:
     634           0 :                         nPos = m_pSelectionLB->InsertEntry(aList[i]);
     635           0 :                         m_pSelectionLB->SetEntryData(nPos, reinterpret_cast<void*>(i));
     636           0 :                         break;
     637             : 
     638             :                     default:
     639           0 :                         if (aList[i] == GetCurField()->GetPar1())
     640           0 :                             bInsert = sal_True;
     641           0 :                         break;
     642             :                 }
     643           0 :                 if (bInsert)
     644             :                 {
     645           0 :                     nPos = m_pSelectionLB->InsertEntry(aList[i]);
     646           0 :                     m_pSelectionLB->SetEntryData(nPos, reinterpret_cast<void*>(i));
     647           0 :                     if (nTypeId != TYP_FORMELFLD)
     648           0 :                         break;
     649             :                 }
     650             :             }
     651             :         }
     652             :     }
     653             : 
     654           0 :     sal_Bool bEnable = m_pSelectionLB->GetEntryCount() != 0;
     655           0 :     ListBox *pLB = 0;
     656             : 
     657           0 :     if (bEnable)
     658             :     {
     659           0 :         m_pSelectionLB->SelectEntry(sOldSel);
     660           0 :         if (!m_pSelectionLB->GetSelectEntryCount())
     661             :         {
     662           0 :             m_pSelectionLB->SelectEntryPos(0);
     663           0 :             pLB = m_pSelectionLB;    // newly initialise all controls
     664             :         }
     665             :     }
     666             : 
     667           0 :     m_pSelection->Enable(bEnable);
     668             : 
     669           0 :     SubTypeHdl(pLB);
     670           0 :     m_pSelectionLB->SetUpdateMode(true);
     671           0 : }
     672             : 
     673           0 : sal_Int32 SwFldVarPage::FillFormatLB(sal_uInt16 nTypeId)
     674             : {
     675           0 :     OUString sOldSel, sOldNumSel;
     676           0 :     sal_uLong nOldNumFormat = 0;
     677             : 
     678           0 :     sal_Int32 nFormatSel = m_pFormatLB->GetSelectEntryPos();
     679           0 :     if (nFormatSel != LISTBOX_ENTRY_NOTFOUND)
     680           0 :         sOldSel = m_pFormatLB->GetEntry(nFormatSel);
     681             : 
     682           0 :     sal_Int32 nNumFormatSel = m_pNumFormatLB->GetSelectEntryPos();
     683           0 :     if (nNumFormatSel != LISTBOX_ENTRY_NOTFOUND)
     684             :     {
     685           0 :         sOldNumSel = m_pNumFormatLB->GetEntry(nNumFormatSel);
     686           0 :         nOldNumFormat = m_pNumFormatLB->GetFormat();
     687             :     }
     688             : 
     689             :     // fill Format-Listbox
     690           0 :     m_pFormatLB->Clear();
     691           0 :     m_pNumFormatLB->Clear();
     692           0 :     sal_Bool bSpecialFmt = sal_False;
     693             : 
     694           0 :     if( TYP_GETREFPAGEFLD != nTypeId )
     695             :     {
     696           0 :         if (IsFldEdit())
     697             :         {
     698           0 :             bSpecialFmt = GetCurField()->GetFormat() == SAL_MAX_UINT32;
     699             : 
     700           0 :             if (!bSpecialFmt)
     701             :             {
     702           0 :                 m_pNumFormatLB->SetDefFormat(GetCurField()->GetFormat());
     703           0 :                 sOldNumSel = OUString();
     704             :             }
     705             :             else
     706           0 :                 if (nTypeId == TYP_GETFLD || nTypeId == TYP_FORMELFLD)
     707           0 :                     m_pNumFormatLB->SetFormatType(NUMBERFORMAT_NUMBER);
     708             :         }
     709             :         else
     710             :         {
     711           0 :             if (nOldNumFormat && nOldNumFormat != ULONG_MAX)
     712           0 :                 m_pNumFormatLB->SetDefFormat(nOldNumFormat);
     713             :             else
     714           0 :                 m_pNumFormatLB->SetFormatType(NUMBERFORMAT_NUMBER);
     715             :         }
     716             :     }
     717             : 
     718           0 :     switch (nTypeId)
     719             :     {
     720             :         case TYP_USERFLD:
     721             :         {
     722           0 :             if (!IsFldEdit() || bSpecialFmt)
     723             :             {
     724           0 :                 sal_Int32 nPos = m_pNumFormatLB->InsertEntry(SW_RESSTR(FMT_MARK_TEXT), 0);
     725           0 :                 m_pNumFormatLB->SetEntryData(nPos, (void *)ULONG_MAX);
     726           0 :                 nPos = m_pNumFormatLB->InsertEntry(SW_RESSTR(FMT_USERVAR_CMD), 1);
     727           0 :                 m_pNumFormatLB->SetEntryData(nPos, (void *)ULONG_MAX);
     728             :             }
     729             :         }
     730           0 :         break;
     731             : 
     732             :         case TYP_SETFLD:
     733             :         {
     734           0 :             if (!IsFldEdit() || bSpecialFmt)
     735             :             {
     736           0 :                 sal_Int32 nPos = m_pNumFormatLB->InsertEntry(SW_RESSTR(FMT_SETVAR_TEXT), 0);
     737           0 :                 m_pNumFormatLB->SetEntryData(nPos, (void *)ULONG_MAX);
     738             :             }
     739             :         }
     740           0 :         break;
     741             : 
     742             :         case TYP_FORMELFLD:
     743             :         {
     744           0 :             sal_Int32 nPos = m_pNumFormatLB->InsertEntry(SW_RESSTR(FMT_GETVAR_NAME), 0);
     745           0 :             m_pNumFormatLB->SetEntryData(nPos, (void *)ULONG_MAX);
     746             :         }
     747           0 :         break;
     748             : 
     749             :         case TYP_GETFLD:
     750             :         {
     751           0 :             sal_Int32 nPos = m_pNumFormatLB->InsertEntry(SW_RESSTR(FMT_GETVAR_NAME), 0);
     752           0 :             m_pNumFormatLB->SetEntryData(nPos, (void *)ULONG_MAX);
     753             :         }
     754           0 :         break;
     755             :     }
     756             : 
     757           0 :     if (IsFldEdit() && bSpecialFmt)
     758             :     {
     759           0 :         if (nTypeId == TYP_USERFLD && (GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_CMD))
     760           0 :             m_pNumFormatLB->SelectEntryPos(1);
     761             :         else
     762           0 :             m_pNumFormatLB->SelectEntryPos(0);
     763             :     }
     764             :     else
     765             :     {
     766           0 :         if (!nOldNumFormat && (nNumFormatSel = m_pNumFormatLB->GetEntryPos(sOldNumSel)) != LISTBOX_ENTRY_NOTFOUND)
     767           0 :             m_pNumFormatLB->SelectEntryPos(nNumFormatSel);
     768           0 :         else if (nOldNumFormat && nOldNumFormat == ULONG_MAX)
     769           0 :             m_pNumFormatLB->SelectEntry(sOldSel);
     770             :     }
     771             : 
     772           0 :     const sal_uInt16 nSize = GetFldMgr().GetFormatCount(nTypeId, false, IsFldDlgHtmlMode());
     773             : 
     774           0 :     for (sal_uInt16 i = 0; i < nSize; i++)
     775             :     {
     776           0 :         sal_Int32 nPos = m_pFormatLB->InsertEntry(GetFldMgr().GetFormatStr(nTypeId, i));
     777           0 :         const sal_uInt16 nFldId = GetFldMgr().GetFormatId( nTypeId, i );
     778           0 :         m_pFormatLB->SetEntryData( nPos, reinterpret_cast<void*>(nFldId) );
     779           0 :         if (IsFldEdit() && nFldId == GetCurField()->GetFormat())
     780           0 :             m_pFormatLB->SelectEntryPos( nPos );
     781             :     }
     782             : 
     783           0 :     if (nSize && (!IsFldEdit() || !m_pFormatLB->GetSelectEntryCount()))
     784             :     {
     785           0 :         m_pFormatLB->SelectEntry(sOldSel);
     786             : 
     787           0 :         if (!m_pFormatLB->GetSelectEntryCount())
     788             :         {
     789           0 :             m_pFormatLB->SelectEntry(SW_RESSTR(FMT_NUM_PAGEDESC));
     790           0 :             if (!m_pFormatLB->GetSelectEntryCount())
     791             :             {
     792           0 :                 m_pFormatLB->SelectEntry(SW_RESSTR(FMT_NUM_ARABIC));
     793           0 :                 if (!m_pFormatLB->GetSelectEntryCount())
     794           0 :                     m_pFormatLB->SelectEntryPos(0);
     795             :             }
     796             :         }
     797             :     }
     798             : 
     799           0 :     return nSize;
     800             : }
     801             : 
     802             : /*--------------------------------------------------------------------
     803             :     Description: Modify
     804             :  --------------------------------------------------------------------*/
     805           0 : IMPL_LINK_NOARG(SwFldVarPage, ModifyHdl)
     806             : {
     807           0 :     OUString sValue(m_pValueED->GetText());
     808           0 :     sal_Bool bHasValue = !sValue.isEmpty();
     809           0 :     const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     810           0 :     bool bInsert = false, bApply = false, bDelete = false;
     811             : 
     812           0 :     OUString sName( m_pNameED->GetText() );
     813           0 :     sal_Int32 nLen = sName.getLength();
     814             : 
     815           0 :     switch( nTypeId )
     816             :     {
     817             :     case TYP_DDEFLD:
     818             :     case TYP_USERFLD:
     819             :     case TYP_SETFLD:
     820             :     case TYP_SEQFLD:
     821           0 :         SwCalc::IsValidVarName( sName, &sName );
     822           0 :         if ( sName.getLength() != nLen )
     823             :         {
     824           0 :             nLen = sName.getLength();
     825           0 :             Selection aSel(m_pNameED->GetSelection());
     826           0 :             m_pNameED->SetText( sName );
     827           0 :             m_pNameED->SetSelection( aSel );   // restore Cursorpos
     828             :         }
     829           0 :         break;
     830             :     }
     831             : 
     832             :     // check buttons
     833           0 :     switch (nTypeId)
     834             :     {
     835             :     case TYP_DDEFLD:
     836           0 :         if( nLen )
     837             :         {
     838             :             // is there already a corrensponding type
     839           0 :             bInsert = bApply = true;
     840             : 
     841           0 :             SwFieldType* pType = GetFldMgr().GetFldType(RES_DDEFLD, sName);
     842             : 
     843           0 :             SwWrtShell *pSh = GetWrtShell();
     844           0 :             if(!pSh)
     845           0 :                 pSh = ::GetActiveWrtShell();
     846           0 :             if(pSh && pType)
     847           0 :                 bDelete = !pSh->IsUsed( *pType );
     848             :         }
     849           0 :         break;
     850             : 
     851             :     case TYP_USERFLD:
     852           0 :         if( nLen )
     853             :         {
     854             :             // is there already a corresponding type
     855           0 :             SwFieldType* pType = GetFldMgr().GetFldType(RES_USERFLD, sName);
     856             : 
     857           0 :             SwWrtShell *pSh = GetWrtShell();
     858           0 :             if(!pSh)
     859           0 :                 pSh = ::GetActiveWrtShell();
     860           0 :             if(pSh && pType)
     861           0 :                 bDelete = !pSh->IsUsed( *pType );
     862             : 
     863           0 :             pType = GetFldMgr().GetFldType(RES_SETEXPFLD, sName);
     864           0 :             if (!pType) // no name conflict with variables
     865             :             {
     866             :                 // user fields can also be inserted without content!
     867             :                 // Bug #56845
     868           0 :                 bInsert = bApply = true;
     869             :             }
     870             :         }
     871           0 :         break;
     872             : 
     873             :     default:
     874           0 :         bInsert = true;
     875             : 
     876           0 :         if (nTypeId == TYP_SETFLD || nTypeId == TYP_SEQFLD)
     877             :         {
     878             :             SwSetExpFieldType* pFldType = (SwSetExpFieldType*)
     879           0 :                 GetFldMgr().GetFldType(RES_SETEXPFLD, sName);
     880             : 
     881           0 :             if (pFldType)
     882             :             {
     883             : 
     884           0 :                 SwWrtShell *pSh = GetWrtShell();
     885           0 :                 if(!pSh)
     886           0 :                     pSh = ::GetActiveWrtShell();
     887           0 :                 if(pSh)
     888             :                 {
     889           0 :                     const SwFldTypes* p = pSh->GetDoc()->GetFldTypes();
     890             :                     sal_uInt16 i;
     891             : 
     892           0 :                     for (i = 0; i < INIT_FLDTYPES; i++)
     893             :                     {
     894           0 :                         SwFieldType* pType = (*p)[ i ];
     895           0 :                         if (pType == pFldType)
     896           0 :                             break;
     897             :                     }
     898             : 
     899           0 :                     if (i >= INIT_FLDTYPES && !pSh->IsUsed(*pFldType))
     900           0 :                         bDelete = true;
     901             : 
     902           0 :                     if (nTypeId == TYP_SEQFLD && !(pFldType->GetType() & nsSwGetSetExpType::GSE_SEQ))
     903           0 :                         bInsert = false;
     904             : 
     905           0 :                     if (nTypeId == TYP_SETFLD && (pFldType->GetType() & nsSwGetSetExpType::GSE_SEQ))
     906           0 :                         bInsert = false;
     907             :                 }
     908             :             }
     909           0 :             if (GetFldMgr().GetFldType(RES_USERFLD, sName))
     910           0 :                 bInsert = false;
     911             :         }
     912             : 
     913           0 :         if( !nLen && ( nTypeId == TYP_SETFLD ||
     914           0 :                         (!IsFldEdit() && nTypeId == TYP_GETFLD ) ) )
     915           0 :             bInsert = false;
     916             : 
     917           0 :         if( (nTypeId == TYP_SETFLD || nTypeId == TYP_FORMELFLD) &&
     918             :             !bHasValue )
     919           0 :             bInsert = false;
     920           0 :         break;
     921             :     }
     922             : 
     923           0 :     m_pNewDelTBX->EnableItem(m_nApplyId, bApply);
     924           0 :     m_pNewDelTBX->EnableItem(m_nDeleteId, bDelete);
     925           0 :     EnableInsert(bInsert);
     926             : 
     927           0 :     return 0;
     928             : }
     929             : 
     930           0 : IMPL_LINK( SwFldVarPage, TBClickHdl, ToolBox *, pBox )
     931             : {
     932           0 :     const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
     933             : 
     934           0 :     const sal_uInt16 nCurId = pBox->GetCurItemId();
     935             : 
     936           0 :     if (nCurId == m_nDeleteId)
     937             :     {
     938           0 :         if( nTypeId == TYP_USERFLD )
     939           0 :             GetFldMgr().RemoveFldType(RES_USERFLD, m_pSelectionLB->GetSelectEntry());
     940             :         else
     941             :         {
     942             :             sal_uInt16 nWhich;
     943             : 
     944           0 :             switch(nTypeId)
     945             :             {
     946             :                 case TYP_SETFLD:
     947             :                 case TYP_SEQFLD:
     948           0 :                     nWhich = RES_SETEXPFLD;
     949           0 :                     break;
     950             :                 default:
     951           0 :                     nWhich = RES_DDEFLD;
     952           0 :                     break;
     953             :             }
     954             : 
     955           0 :             GetFldMgr().RemoveFldType(nWhich, m_pSelectionLB->GetSelectEntry());
     956             :         }
     957             : 
     958           0 :         UpdateSubType();
     959           0 :         SwWrtShell *pSh = GetWrtShell();
     960           0 :         if(!pSh)
     961           0 :             pSh = ::GetActiveWrtShell();
     962           0 :         if(pSh)
     963             :         {
     964           0 :             pSh->SetModified();
     965             :         }
     966             :     }
     967           0 :     else if (nCurId == m_nApplyId)
     968             :     {
     969           0 :         OUString sName(m_pNameED->GetText()), sValue(m_pValueED->GetText());
     970           0 :         SwFieldType* pType = 0;
     971           0 :         sal_uInt16 nId = 0;
     972           0 :         sal_Int32 nNumFormatPos = m_pNumFormatLB->GetSelectEntryPos();
     973             : 
     974           0 :         switch (nTypeId)
     975             :         {
     976           0 :             case TYP_USERFLD:   nId = RES_USERFLD;  break;
     977           0 :             case TYP_DDEFLD:    nId = RES_DDEFLD;   break;
     978           0 :             case TYP_SETFLD:    nId = RES_SETEXPFLD;break;
     979             :         }
     980           0 :         pType = GetFldMgr().GetFldType(nId, sName);
     981             : 
     982           0 :         sal_uLong nFormat = m_pFormatLB->GetSelectEntryPos();
     983           0 :         if (nFormat != LISTBOX_ENTRY_NOTFOUND)
     984           0 :             nFormat = (sal_uLong)m_pFormatLB->GetEntryData((sal_Int32)nFormat);
     985             : 
     986           0 :         if (pType)  // change
     987             :         {
     988           0 :             SwWrtShell *pSh = GetWrtShell();
     989           0 :             if(!pSh)
     990           0 :                 pSh = ::GetActiveWrtShell();
     991           0 :             if(pSh)
     992             :             {
     993           0 :                 pSh->StartAllAction();
     994             : 
     995           0 :                 if (nTypeId == TYP_USERFLD)
     996             :                 {
     997           0 :                     if (nNumFormatPos != LISTBOX_ENTRY_NOTFOUND)
     998             :                     {
     999           0 :                         sal_uLong nFmt = nNumFormatPos == 0 ? 0 : m_pNumFormatLB->GetFormat();
    1000           0 :                         if (nFmt)
    1001             :                         {   // Switch language to office-language because Kalkulator expects
    1002             :                             // String in office format and it should be fed into dialog like
    1003             :                             // that
    1004           0 :                             nFmt = SwValueField::GetSystemFormat(pSh->GetNumberFormatter(), nFmt);
    1005             :                         }
    1006           0 :                         ((SwUserFieldType*)pType)->SetContent(m_pValueED->GetText(), nFmt);
    1007             :                         ((SwUserFieldType*)pType)->SetType(
    1008           0 :                             nNumFormatPos == 0 ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR );
    1009             :                     }
    1010             :                 }
    1011             :                 else
    1012             :                 {
    1013           0 :                     if (nFormat != LISTBOX_ENTRY_NOTFOUND)
    1014             :                     {
    1015             :                         // DDE-Topics/-Items can have blanks in their names!
    1016             :                         //  That's not being considered here yet.
    1017           0 :                         sal_Int32 nTmpPos = 0;
    1018           0 :                         sValue = sValue.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nTmpPos );
    1019           0 :                         sValue = sValue.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nTmpPos );
    1020           0 :                         ((SwDDEFieldType*)pType)->SetCmd(sValue);
    1021           0 :                         ((SwDDEFieldType*)pType)->SetType((sal_uInt16)nFormat);
    1022             :                     }
    1023             :                 }
    1024           0 :                 pType->UpdateFlds();
    1025             : 
    1026           0 :                 pSh->EndAllAction();
    1027             :             }
    1028             :         }
    1029             :         else        // new
    1030             :         {
    1031           0 :             if(nTypeId == TYP_USERFLD)
    1032             :             {
    1033           0 :                 SwWrtShell *pSh = GetWrtShell();
    1034           0 :                 if(!pSh)
    1035           0 :                     pSh = ::GetActiveWrtShell();
    1036           0 :                 if(pSh)
    1037             :                 {
    1038           0 :                     SwUserFieldType aType( pSh->GetDoc(), sName );
    1039             : 
    1040           0 :                     if (nNumFormatPos != LISTBOX_ENTRY_NOTFOUND)
    1041             :                     {
    1042           0 :                         aType.SetType(nNumFormatPos == 0 ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR);
    1043           0 :                         aType.SetContent( sValue, nNumFormatPos == 0 ? 0 : m_pNumFormatLB->GetFormat() );
    1044           0 :                         m_pSelectionLB->InsertEntry(sName);
    1045           0 :                         m_pSelectionLB->SelectEntry(sName);
    1046           0 :                         GetFldMgr().InsertFldType( aType ); // Userfld new
    1047           0 :                     }
    1048             :                 }
    1049             :             }
    1050             :             else
    1051             :             {
    1052           0 :                 if (nFormat != LISTBOX_ENTRY_NOTFOUND)
    1053             :                 {
    1054             :                     // DDE-Topics/-Items can have blanks in their names!
    1055             :                     //  That's not being considered here yet.
    1056           0 :                     sal_Int32 nTmpPos = 0;
    1057           0 :                     sValue = sValue.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nTmpPos );
    1058           0 :                     sValue = sValue.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nTmpPos );
    1059             : 
    1060           0 :                     SwDDEFieldType aType(sName, sValue, (sal_uInt16)nFormat);
    1061           0 :                     m_pSelectionLB->InsertEntry(sName);
    1062           0 :                     m_pSelectionLB->SelectEntry(sName);
    1063           0 :                     GetFldMgr().InsertFldType(aType);   // DDE-Field new
    1064             :                 }
    1065             :             }
    1066             :         }
    1067           0 :         if (IsFldEdit())
    1068           0 :             GetFldMgr().GetCurFld();    // update FieldManager
    1069             : 
    1070           0 :         UpdateSubType();
    1071             :     }
    1072             : 
    1073           0 :     return sal_True;
    1074             : }
    1075             : 
    1076           0 : IMPL_LINK_NOARG(SwFldVarPage, ChapterHdl)
    1077             : {
    1078           0 :     sal_Bool bEnable = m_pChapterLevelLB->GetSelectEntryPos() != 0;
    1079             : 
    1080           0 :     m_pSeparatorED->Enable(bEnable);
    1081           0 :     m_pSeparatorFT->Enable(bEnable);
    1082           0 :     SeparatorHdl();
    1083             : 
    1084           0 :     return 0;
    1085             : }
    1086             : 
    1087           0 : IMPL_LINK_NOARG(SwFldVarPage, SeparatorHdl)
    1088             : {
    1089           0 :     sal_Bool bEnable = !m_pSeparatorED->GetText().isEmpty() ||
    1090           0 :                     m_pChapterLevelLB->GetSelectEntryPos() == 0;
    1091           0 :     EnableInsert(bEnable);
    1092             : 
    1093           0 :     return 0;
    1094             : }
    1095             : 
    1096           0 : bool SwFldVarPage::FillItemSet(SfxItemSet& )
    1097             : {
    1098           0 :     const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData(GetTypeSel());
    1099             : 
    1100           0 :     OUString aVal(m_pValueED->GetText());
    1101           0 :     OUString aName(m_pNameED->GetText());
    1102             : 
    1103           0 :     const sal_Int32 nSubPos = m_pSelectionLB->GetSelectEntryPos();
    1104             :     sal_uInt16 nSubType = (nSubPos == LISTBOX_ENTRY_NOTFOUND) ? 0 :
    1105           0 :         (sal_uInt16)(sal_uLong)m_pSelectionLB->GetEntryData(nSubPos);
    1106             : 
    1107             :     sal_uLong nFormat;
    1108             : 
    1109           0 :     if (!m_pNumFormatLB->IsVisible())
    1110             :     {
    1111           0 :         sal_Int32 nFormatPos = m_pFormatLB->GetSelectEntryPos();
    1112             : 
    1113           0 :         if(nFormatPos == LISTBOX_ENTRY_NOTFOUND)
    1114           0 :             nFormat = 0;
    1115             :         else
    1116           0 :             nFormat = (sal_uLong)m_pFormatLB->GetEntryData(nFormatPos);
    1117             :     }
    1118             :     else
    1119             :     {
    1120           0 :         nFormat = m_pNumFormatLB->GetFormat();
    1121             : 
    1122           0 :         if (nFormat && nFormat != ULONG_MAX && m_pNumFormatLB->IsAutomaticLanguage())
    1123             :         {
    1124             :             // Switch language to office language because Kalkulator expects
    1125             :             // String in office format and it should be fed into the dialog
    1126             :             // like that
    1127           0 :             SwWrtShell *pSh = GetWrtShell();
    1128           0 :             if(!pSh)
    1129           0 :                 pSh = ::GetActiveWrtShell();
    1130           0 :             if(pSh)
    1131             :             {
    1132           0 :                 nFormat = SwValueField::GetSystemFormat(pSh->GetNumberFormatter(), nFormat);
    1133             :             }
    1134             :         }
    1135             :     }
    1136           0 :     sal_Unicode cSeparator = ' ';
    1137           0 :     switch (nTypeId)
    1138             :     {
    1139             :         case TYP_USERFLD:
    1140             :         {
    1141           0 :             nSubType = (nFormat == ULONG_MAX) ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR;
    1142             : 
    1143           0 :             if (nFormat == ULONG_MAX && m_pNumFormatLB->GetSelectEntry() == SW_RESSTR(FMT_USERVAR_CMD))
    1144           0 :                 nSubType |= nsSwExtendedSubType::SUB_CMD;
    1145             : 
    1146           0 :             if (m_pInvisibleCB->IsChecked())
    1147           0 :                 nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
    1148           0 :             break;
    1149             :         }
    1150             :         case TYP_FORMELFLD:
    1151             :         {
    1152           0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA;
    1153           0 :             if (m_pNumFormatLB->IsVisible() && nFormat == ULONG_MAX)
    1154           0 :                 nSubType |= nsSwExtendedSubType::SUB_CMD;
    1155           0 :             break;
    1156             :         }
    1157             :         case TYP_GETFLD:
    1158             :         {
    1159           0 :             nSubType &= 0xff00;
    1160           0 :             if (m_pNumFormatLB->IsVisible() && nFormat == ULONG_MAX)
    1161           0 :                 nSubType |= nsSwExtendedSubType::SUB_CMD;
    1162           0 :             break;
    1163             :         }
    1164             :         case TYP_INPUTFLD:
    1165             :         {
    1166           0 :             SwFieldType* pType = GetFldMgr().GetFldType(RES_USERFLD, aName);
    1167           0 :             nSubType = static_cast< sal_uInt16 >((nSubType & 0xff00) | ((pType) ? INP_USR : INP_VAR));
    1168           0 :             break;
    1169             :         }
    1170             : 
    1171             :         case TYP_SETFLD:
    1172             :         {
    1173           0 :             if (IsFldDlgHtmlMode())
    1174             :             {
    1175           0 :                 nSubType = 0x0100;
    1176           0 :                 nSubType = (nSubType & 0xff00) | nsSwGetSetExpType::GSE_STRING;
    1177             :             }
    1178             :             else
    1179           0 :                 nSubType = (nSubType & 0xff00) | ((nFormat == ULONG_MAX) ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR);
    1180             : 
    1181           0 :             if (m_pInvisibleCB->IsChecked())
    1182           0 :                 nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
    1183           0 :             break;
    1184             :         }
    1185             :         case TYP_SEQFLD:
    1186             :         {
    1187           0 :             nSubType = m_pChapterLevelLB->GetSelectEntryPos();
    1188           0 :             if (nSubType == 0)
    1189           0 :                 nSubType = 0x7f;
    1190             :             else
    1191             :             {
    1192           0 :                 nSubType--;
    1193           0 :                 OUString sSeparator = OUString(m_pSeparatorED->GetText()[0]);
    1194           0 :                 cSeparator = !sSeparator.isEmpty() ? sSeparator[0] : ' ';
    1195             :             }
    1196           0 :             break;
    1197             :         }
    1198             :         case TYP_GETREFPAGEFLD:
    1199           0 :             if( SVX_NUM_CHAR_SPECIAL == nFormat )
    1200           0 :                 aVal = m_pValueED->GetText();
    1201           0 :             break;
    1202             :     }
    1203             : 
    1204           0 :     if (!IsFldEdit() ||
    1205           0 :         m_pNameED->GetSavedValue() != m_pNameED->GetText() ||
    1206           0 :         m_pValueED->GetSavedValue() != m_pValueED->GetText() ||
    1207           0 :         m_pSelectionLB->GetSavedValue() != m_pSelectionLB->GetSelectEntryPos() ||
    1208           0 :         m_pFormatLB->GetSavedValue() != m_pFormatLB->GetSelectEntryPos() ||
    1209           0 :         nOldFormat != m_pNumFormatLB->GetFormat() ||
    1210           0 :         m_pInvisibleCB->GetState() != m_pInvisibleCB->GetSavedValue() ||
    1211           0 :         m_pChapterLevelLB->GetSavedValue() != m_pChapterLevelLB->GetSelectEntryPos() ||
    1212           0 :         m_pSeparatorED->GetSavedValue() != m_pSeparatorED->GetText())
    1213             :     {
    1214             :         InsertFld( nTypeId, nSubType, aName, aVal, nFormat,
    1215           0 :                     cSeparator, m_pNumFormatLB->IsAutomaticLanguage() );
    1216             :     }
    1217             : 
    1218           0 :     UpdateSubType();
    1219             : 
    1220           0 :     return false;
    1221             : }
    1222             : 
    1223           0 : SfxTabPage* SwFldVarPage::Create(   Window* pParent,
    1224             :                         const SfxItemSet& rAttrSet )
    1225             : {
    1226           0 :     return ( new SwFldVarPage( pParent, rAttrSet ) );
    1227             : }
    1228             : 
    1229           0 : sal_uInt16 SwFldVarPage::GetGroup()
    1230             : {
    1231           0 :     return GRP_VAR;
    1232             : }
    1233             : 
    1234           0 : SelectionListBox::SelectionListBox(Window* pParent, WinBits nStyle)
    1235             :     : ListBox(pParent, nStyle)
    1236           0 :     , bCallAddSelection(false)
    1237             : {
    1238           0 : }
    1239             : 
    1240           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSelectionListBox(Window *pParent, VclBuilder::stringmap &rMap)
    1241             : {
    1242           0 :     WinBits nBits = WB_LEFT|WB_VCENTER|WB_3DLOOK;
    1243             : 
    1244           0 :     bool bDropdown = VclBuilder::extractDropdown(rMap);
    1245             : 
    1246           0 :     if (bDropdown)
    1247           0 :         nBits |= WB_DROPDOWN;
    1248             : 
    1249           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
    1250           0 :     if (!sBorder.isEmpty())
    1251           0 :        nBits |= WB_BORDER;
    1252             : 
    1253           0 :     SelectionListBox* pListBox = new SelectionListBox(pParent, nBits|WB_SIMPLEMODE);
    1254           0 :     pListBox->EnableAutoSize(true);
    1255             : 
    1256           0 :     return pListBox;
    1257             : }
    1258             : 
    1259           0 : bool SelectionListBox::PreNotify( NotifyEvent& rNEvt )
    1260             : {
    1261           0 :     bool nHandled = ListBox::PreNotify( rNEvt );
    1262           0 :     if ( rNEvt.GetType() == EVENT_KEYUP )
    1263             :     {
    1264           0 :         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
    1265           0 :         const KeyCode aKeyCode = pKEvt->GetKeyCode();
    1266           0 :         const sal_uInt16 nModifier = aKeyCode.GetModifier();
    1267           0 :         if( aKeyCode.GetCode() == KEY_SPACE && !nModifier)
    1268           0 :             bCallAddSelection = true;
    1269             :     }
    1270           0 :     if ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
    1271             :     {
    1272           0 :         const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
    1273             : 
    1274           0 :         if (pMEvt && (pMEvt->IsMod1() || pMEvt->IsMod2()))  // Alt or Ctrl
    1275           0 :             bCallAddSelection = true;
    1276             :     }
    1277             : 
    1278           0 :     return nHandled;
    1279             : }
    1280             : 
    1281           0 : void SwFldVarPage::FillUserData()
    1282             : {
    1283           0 :     OUString sData(USER_DATA_VERSION);
    1284           0 :     sData += ";";
    1285           0 :     sal_Int32 nTypeSel = m_pTypeLB->GetSelectEntryPos();
    1286           0 :     if( LISTBOX_ENTRY_NOTFOUND == nTypeSel )
    1287           0 :         nTypeSel = USHRT_MAX;
    1288             :     else
    1289           0 :         nTypeSel = (sal_uInt16)(sal_uLong)m_pTypeLB->GetEntryData( nTypeSel );
    1290           0 :     sData += OUString::number( nTypeSel );
    1291           0 :     SetUserData(sData);
    1292           0 : }
    1293             : 
    1294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10