[Libreoffice-commits] core.git: sc/inc sc/source

Henry Castro hcastro at collabora.com
Tue May 12 02:55:48 PDT 2015


 sc/inc/sc.hrc                             |    2 
 sc/inc/scabstdlg.hxx                      |    2 
 sc/source/ui/app/scdll.cxx                |    1 
 sc/source/ui/attrdlg/scdlgfact.cxx        |    5 
 sc/source/ui/attrdlg/scdlgfact.hxx        |    2 
 sc/source/ui/condformat/condformatdlg.cxx |  245 +++++++++++++++++++++++++++---
 sc/source/ui/condformat/condformatmgr.cxx |   70 +-------
 sc/source/ui/inc/condformatdlg.hxx        |   25 ++-
 sc/source/ui/inc/condformatmgr.hxx        |    2 
 sc/source/ui/inc/reffact.hxx              |    1 
 sc/source/ui/view/cellsh1.cxx             |  161 ++++++++++++-------
 sc/source/ui/view/reffact.cxx             |    3 
 sc/source/ui/view/tabvwsh.cxx             |    1 
 sc/source/ui/view/tabvwshc.cxx            |   56 ++++++
 14 files changed, 437 insertions(+), 139 deletions(-)

New commits:
commit 2b5915da481990fd6ea272104215d82b6fbf5dbb
Author: Henry Castro <hcastro at collabora.com>
Date:   Thu Jan 29 23:47:00 2015 -0400

    tdf#60573 Conditional formatting does not allow scrolling
    
    If you need to apply conditional formatting to a cell not shown presently
    on your screen you cannot scroll to the position you would like to use.
    
    Change-Id: I18549316d2c725ce032a65cffb969bed21b771c3
    Reviewed-on: https://gerrit.libreoffice.org/14258
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 174db9b..d70f489 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -1115,6 +1115,8 @@
 #define RID_POPUPPANEL_APPEARANCE_CELL_LINESTYLE (SC_DIALOGS_START + 162)
 #define RID_POPUPPANEL_APPEARANCE_CELL_BORDERSTYLE (SC_DIALOGS_START + 163)
 
+#define WID_CONDFRMT_REF                (SC_DIALOGS_START + 164)
+
 #define SC_DIALOGS_END                  (RID_POPUPPANEL_APPEARANCE_CELL_BORDERSTYLE + 1)
 
 #ifndef STD_MASKCOLOR
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index 6e6841b..3fcedfc 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -81,6 +81,8 @@ public:
     virtual ScConditionalFormatList* GetConditionalFormatList() = 0;
 
     virtual bool CondFormatsChanged() = 0;
+
+    virtual ScConditionalFormat* GetCondFormatSelected() = 0;
 };
 
 class AbstractScDataPilotDatabaseDlg  :public VclAbstractDialog
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index 40765e0..384ae4c 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -278,6 +278,7 @@ void ScDLL::Init()
 
     ScValidityRefChildWin::RegisterChildWindow(false, pMod);
     sc::SearchResultsDlgWrapper::RegisterChildWindow(false, pMod);
+    ScCondFormatDlgWrapper::RegisterChildWindow(false, pMod);
 
     // EditEngine Field; insofar not already defined in OfficeApplication::Init
     SvClassManager& rClassManager = SvxFieldItem::GetClassManager();
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx
index 0e142fd..5b9fb73 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -429,6 +429,11 @@ bool AbstractScCondFormatManagerDlg_Impl::CondFormatsChanged()
     return pDlg->CondFormatsChanged();
 }
 
+ScConditionalFormat* AbstractScCondFormatManagerDlg_Impl::GetCondFormatSelected()
+{
+    return pDlg->GetCondFormatSelected();
+}
+
 long AbstractScMetricInputDlg_Impl::GetInputValue( FieldUnit eUnit ) const
 {
 
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index 9f90132..99b9d83 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -131,6 +131,8 @@ class AbstractScCondFormatManagerDlg_Impl : public AbstractScCondFormatManagerDl
     virtual ScConditionalFormatList* GetConditionalFormatList() SAL_OVERRIDE;
 
     virtual bool CondFormatsChanged() SAL_OVERRIDE;
+
+    virtual ScConditionalFormat* GetCondFormatSelected() SAL_OVERRIDE;
 };
 
 class AbstractScDataPilotDatabaseDlg_Impl  :public AbstractScDataPilotDatabaseDlg
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index 2fa4e20..5154830 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -20,6 +20,7 @@
 #include <vcl/msgbox.hxx>
 #include <vcl/settings.hxx>
 #include <vcl/builderfactory.hxx>
+#include <libxml/tree.h>
 
 #include "anyrefdg.hxx"
 #include "document.hxx"
@@ -413,19 +414,25 @@ IMPL_LINK_NOARG( ScCondFormatList, ScrollHdl )
     return 0;
 }
 
-//ScCondFormatDlg
-
-ScCondFormatDlg::ScCondFormatDlg(vcl::Window* pParent, ScDocument* pDoc,
+// -------------------------------------------------------------------
+// Conditional Format Dialog
+//
+ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, SfxChildWindow* pCW,
+    vcl::Window* pParent, ScViewData* pViewData,
     const ScConditionalFormat* pFormat, const ScRangeList& rRange,
-    const ScAddress& rPos, condformat::dialog::ScCondFormatDialogType eType)
-    : ScAnyRefModalDlg(pParent, "ConditionalFormatDialog",
-        "modules/scalc/ui/conditionalformatdialog.ui")
+    const ScAddress& rPos, condformat::dialog::ScCondFormatDialogType eType,
+    sal_Bool bManaged)
+        : ScAnyRefDlg(pB, pCW, pParent, "ConditionalFormatDialog",
+                        "modules/scalc/ui/conditionalformatdialog.ui")
+    , mbManaged(bManaged)
     , maPos(rPos)
-    , mpDoc(pDoc)
+    , mpViewData(pViewData)
     , mpLastEdit(NULL)
 {
+    get(mpBtnOk, "ok");
     get(mpBtnAdd, "add");
     get(mpBtnRemove, "delete");
+    get(mpBtnCancel, "cancel");
 
     get(mpFtRange, "ftassign");
     get(mpEdRange, "edassign");
@@ -434,24 +441,27 @@ ScCondFormatDlg::ScCondFormatDlg(vcl::Window* pParent, ScDocument* pDoc,
     get(mpRbRange, "rbassign");
     mpRbRange->SetReferences(this, mpEdRange);
 
+    maKey = pFormat ? pFormat->GetKey() : 0;
+
     get(mpCondFormList, "list");
-    mpCondFormList->init(pDoc, this, pFormat, rRange, rPos, eType);
+    mpCondFormList->init(mpViewData->GetDocument(), this, pFormat, rRange, rPos, eType);
 
     OUStringBuffer aTitle( GetText() );
     aTitle.append(" ");
     OUString aRangeString;
-    rRange.Format(aRangeString, SCA_VALID, pDoc, pDoc->GetAddressConvention());
+    rRange.Format(aRangeString, SCA_VALID, pViewData->GetDocument(),
+                    pViewData->GetDocument()->GetAddressConvention());
     aTitle.append(aRangeString);
     SetText(aTitle.makeStringAndClear());
+    mpBtnOk->SetClickHdl(LINK(this, ScCondFormatDlg, BtnPressedHdl ) );
     mpBtnAdd->SetClickHdl( LINK( mpCondFormList, ScCondFormatList, AddBtnHdl ) );
     mpBtnRemove->SetClickHdl( LINK( mpCondFormList, ScCondFormatList, RemoveBtnHdl ) );
+    mpBtnCancel->SetClickHdl( LINK(this, ScCondFormatDlg, BtnPressedHdl ) );
     mpEdRange->SetModifyHdl( LINK( this, ScCondFormatDlg, EdRangeModifyHdl ) );
     mpEdRange->SetGetFocusHdl( LINK( this, ScCondFormatDlg, RangeGetFocusHdl ) );
     mpEdRange->SetLoseFocusHdl( LINK( this, ScCondFormatDlg, RangeLoseFocusHdl ) );
 
     mpEdRange->SetText(aRangeString);
-
-    SC_MOD()->PushNewAnyRefDlg(this);
 }
 
 ScCondFormatDlg::~ScCondFormatDlg()
@@ -461,16 +471,17 @@ ScCondFormatDlg::~ScCondFormatDlg()
 
 void ScCondFormatDlg::dispose()
 {
-    SC_MOD()->PopAnyRefDlg();
+    mpBtnOk.clear();
     mpBtnAdd.clear();
     mpBtnRemove.clear();
+    mpBtnCancel.clear();
     mpFtRange.clear();
     mpEdRange.clear();
     mpRbRange.clear();
     mpCondFormList.clear();
     mpLastEdit.clear();
 
-    ScAnyRefModalDlg::dispose();
+    ScAnyRefDlg::dispose();
 }
 
 void ScCondFormatDlg::SetActive()
@@ -485,7 +496,7 @@ void ScCondFormatDlg::SetActive()
 
 void ScCondFormatDlg::RefInputDone( bool bForced )
 {
-    ScAnyRefModalDlg::RefInputDone(bForced);
+    ScAnyRefDlg::RefInputDone(bForced);
 }
 
 bool ScCondFormatDlg::IsTableLocked() const
@@ -524,7 +535,8 @@ void ScCondFormatDlg::SetReference(const ScRange& rRef, ScDocument*)
         else
             n = ABS_DREF;
 
-        OUString aRefStr(rRef.Format(n, mpDoc, ScAddress::Details(mpDoc->GetAddressConvention(), 0, 0)));
+        OUString aRefStr(rRef.Format(n, mpViewData->GetDocument(),
+            ScAddress::Details(mpViewData->GetDocument()->GetAddressConvention(), 0, 0)));
         pEdit->SetRefString( aRefStr );
     }
 }
@@ -536,7 +548,8 @@ ScConditionalFormat* ScCondFormatDlg::GetConditionalFormat() const
         return NULL;
 
     ScRangeList aRange;
-    sal_uInt16 nFlags = aRange.Parse(aRangeStr, mpDoc, SCA_VALID, mpDoc->GetAddressConvention(), maPos.Tab());
+    sal_uInt16 nFlags = aRange.Parse(aRangeStr, mpViewData->GetDocument(),
+        SCA_VALID, mpViewData->GetDocument()->GetAddressConvention(), maPos.Tab());
     ScConditionalFormat* pFormat = mpCondFormList->GetConditionalFormat();
 
     if(nFlags & SCA_VALID && !aRange.empty() && pFormat)
@@ -555,11 +568,197 @@ void ScCondFormatDlg::InvalidateRefData()
     mpLastEdit = NULL;
 }
 
+// -------------------------------------------------------------
+// Close the Conditional Format Dialog
+//
+bool ScCondFormatDlg::Close()
+{
+    return DoClose( ScCondFormatDlgWrapper::GetChildWindowId() );
+}
+
+// ------------------------------------------------------------------------
+// Occurs when the Conditional Format Dialog the OK button is pressed.
+//
+void ScCondFormatDlg::OkPressed()
+{
+    ScConditionalFormat* pFormat = GetConditionalFormat();
+
+    if(pFormat)
+        mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(maKey,
+            pFormat, maPos.Tab(), pFormat->GetRange());
+    else
+        mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(maKey,
+            NULL, maPos.Tab(), ScRangeList());
+
+    if ( mbManaged )
+    {
+        SetDispatcherLock( false );
+        // Queue message to open Conditional Format Manager Dialog
+        GetBindings().GetDispatcher()->Execute( SID_OPENDLG_CONDFRMT_MANAGER,
+                                            SfxCallMode::ASYNCHRON );
+    }
+    Close();
+}
+
+// ------------------------------------------------------------------------
+// Occurs when the Conditional Format Dialog is cancelled.
+//
+void ScCondFormatDlg::CancelPressed()
+{
+    if ( mbManaged )
+    {
+        SetDispatcherLock( false );
+        // Queue message to open Conditional Format Manager Dialog
+        GetBindings().GetDispatcher()->Execute( SID_OPENDLG_CONDFRMT_MANAGER,
+                                            SfxCallMode::ASYNCHRON );
+    }
+    Close();
+}
+
+// ------------------------------------------------------------------------------
+// Parse xml string parameters used to initialize the Conditional Format Dialog
+// when it is created.
+//
+bool ScCondFormatDlg::ParseXmlString(const OUString&    sXMLString,
+                                     sal_uInt32&        nIndex,
+                                     sal_uInt8&         nType,
+                                     bool&              bManaged)
+{
+    bool bRetVal = false;
+    OString sTagName;
+    OUString sTagValue;
+
+    xmlNodePtr      pXmlRoot  = NULL;
+    xmlNodePtr      pXmlNode  = NULL;
+
+    OString sOString = OUStringToOString( sXMLString, RTL_TEXTENCODING_UTF8 );
+    xmlDocPtr pXmlDoc = xmlParseMemory(sOString.getStr(), sOString.getLength());
+
+    if( pXmlDoc )
+    {
+        bRetVal = true;
+        pXmlRoot = xmlDocGetRootElement( pXmlDoc );
+        pXmlNode = pXmlRoot->children;
+
+        while (pXmlNode != NULL && bRetVal)
+        {
+            sTagName  = OUStringToOString(OUString("Index"), RTL_TEXTENCODING_UTF8);
+            if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const *>(sTagName.getStr())) == 0)
+            {
+                if (pXmlNode->children != NULL && pXmlNode->children->type == XML_TEXT_NODE)
+                {
+                    sTagValue = OUString(reinterpret_cast<char*>(pXmlNode->children->content),
+                                     strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
+                                     RTL_TEXTENCODING_UTF8);
+                    nIndex   = sTagValue.toUInt32();
+                    pXmlNode = pXmlNode->next;
+                    continue;
+                }
+            }
+
+            sTagName  = OUStringToOString(OUString("Type"), RTL_TEXTENCODING_UTF8);
+            if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const *>(sTagName.getStr())) == 0)
+            {
+                if (pXmlNode->children != NULL && pXmlNode->children->type == XML_TEXT_NODE)
+                {
+                    sTagValue = OUString(reinterpret_cast<char*>(pXmlNode->children->content),
+                                     strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
+                                     RTL_TEXTENCODING_UTF8);
+                    nType    = sTagValue.toUInt32();
+                    pXmlNode = pXmlNode->next;
+                    continue;
+                }
+            }
+
+            sTagName  = OUStringToOString(OUString("Managed"), RTL_TEXTENCODING_UTF8);
+            if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const *>(sTagName.getStr())) == 0)
+            {
+                if (pXmlNode->children != NULL && pXmlNode->children->type == XML_TEXT_NODE)
+                {
+                    sTagValue = OUString(reinterpret_cast<char*>(pXmlNode->children->content),
+                                     strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
+                                     RTL_TEXTENCODING_UTF8);
+                    bManaged = sTagValue.toBoolean();
+                    pXmlNode = pXmlNode->next;
+                    continue;
+                }
+            }
+            bRetVal = false;
+        }
+    }
+
+    xmlFreeDoc(pXmlDoc);
+    return bRetVal;
+}
+
+// ---------------------------------------------------------------------------------------
+// Generate xml string parameters used to initialize the Conditional Format Dialog
+// when it is created.
+//
+OUString ScCondFormatDlg::GenerateXmlString(sal_uInt32 nIndex, sal_uInt8 nType, bool bManaged)
+{
+    OUString sReturn;
+    sal_Int32 nSize = 0;
+
+    OString sTagName;
+    OString sTagValue;
+
+    xmlNodePtr      pXmlRoot  = NULL;
+    xmlNodePtr      pXmlNode  = NULL;
+
+    xmlChar*        pBuffer   = NULL;
+    const xmlChar*  pTagName  = NULL;
+    const xmlChar*  pTagValue = NULL;
+
+    xmlDocPtr pXmlDoc = xmlNewDoc(reinterpret_cast<const xmlChar*>("1.0"));
+
+    sTagName = OUStringToOString(OUString("ScCondFormatDlg"), RTL_TEXTENCODING_UTF8);
+    pTagName = reinterpret_cast<const xmlChar*>(sTagName.getStr());
+    pXmlRoot = xmlNewDocNode(pXmlDoc, NULL, pTagName, NULL);
+
+    xmlDocSetRootElement(pXmlDoc, pXmlRoot);
+
+    sTagName  = OUStringToOString(OUString("Index"), RTL_TEXTENCODING_UTF8);
+    sTagValue = OUStringToOString(OUString::number(nIndex), RTL_TEXTENCODING_UTF8);
+    pTagName  = reinterpret_cast<const xmlChar*>(sTagName.getStr());
+    pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
+    pXmlNode  = xmlNewDocNode(pXmlDoc, NULL, pTagName, pTagValue);
+
+    xmlAddChild(pXmlRoot, pXmlNode);
+
+    sTagName  = OUStringToOString(OUString("Type"), RTL_TEXTENCODING_UTF8);
+    sTagValue = OUStringToOString(OUString::number(nType), RTL_TEXTENCODING_UTF8);
+    pTagName  = reinterpret_cast<const xmlChar*>(sTagName.getStr());
+    pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
+    pXmlNode  = xmlNewDocNode(pXmlDoc, NULL, pTagName, pTagValue);
+
+    xmlAddChild(pXmlRoot, pXmlNode);
+
+    sTagName  = OUStringToOString(OUString("Managed"), RTL_TEXTENCODING_UTF8);
+    sTagValue = OUStringToOString(OUString::boolean(bManaged), RTL_TEXTENCODING_UTF8);
+    pTagName  = reinterpret_cast<const xmlChar*>(sTagName.getStr());
+    pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
+    pXmlNode  = xmlNewDocNode(pXmlDoc, NULL, pTagName, pTagValue);
+
+    xmlAddChild(pXmlRoot, pXmlNode);
+
+    xmlDocDumpMemory(pXmlDoc, &pBuffer, (int*)&nSize);
+
+    sReturn = OUString(reinterpret_cast<char const *>(pBuffer), nSize, RTL_TEXTENCODING_UTF8);
+
+    xmlFree(pBuffer);
+    xmlFreeDoc(pXmlDoc);
+
+    return sReturn;
+}
+
+
 IMPL_LINK( ScCondFormatDlg, EdRangeModifyHdl, Edit*, pEdit )
 {
     OUString aRangeStr = pEdit->GetText();
     ScRangeList aRange;
-    sal_uInt16 nFlags = aRange.Parse(aRangeStr, mpDoc, SCA_VALID, mpDoc->GetAddressConvention());
+    sal_uInt16 nFlags = aRange.Parse(aRangeStr, mpViewData->GetDocument(),
+        SCA_VALID, mpViewData->GetDocument()->GetAddressConvention());
     if(nFlags & SCA_VALID)
         pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
     else
@@ -579,4 +778,16 @@ IMPL_STATIC_LINK_NOARG( ScCondFormatDlg, RangeLoseFocusHdl )
     return 0;
 }
 
+// ------------------------------------------------------
+// Conditional Format Dialog button click event handler.
+//
+IMPL_LINK( ScCondFormatDlg, BtnPressedHdl, Button*, pBtn)
+{
+    if (pBtn == mpBtnOk)
+        OkPressed();
+    else if (pBtn == mpBtnCancel)
+        CancelPressed();
+    return 0;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/condformat/condformatmgr.cxx b/sc/source/ui/condformat/condformatmgr.cxx
index f018fce..b7f3dce 100644
--- a/sc/source/ui/condformat/condformatmgr.cxx
+++ b/sc/source/ui/condformat/condformatmgr.cxx
@@ -154,6 +154,14 @@ ScConditionalFormatList* ScCondFormatManagerDlg::GetConditionalFormatList()
     return pList;
 }
 
+// ---------------------------------------------------------------
+// Get the current conditional format selected.
+//
+ScConditionalFormat* ScCondFormatManagerDlg::GetCondFormatSelected()
+{
+    return m_pCtrlManager->GetSelection();
+}
+
 IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl)
 {
     m_pCtrlManager->DeleteSelection();
@@ -168,72 +176,14 @@ IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnHdl)
     if(!pFormat)
         return 0;
 
-    sal_uInt16 nId = 1;
-    ScModule* pScMod = SC_MOD();
-    pScMod->SetRefDialog( nId, true );
-    VclPtrInstance<ScCondFormatDlg> pDlg(this, mpDoc, pFormat, pFormat->GetRange(),
-                                         pFormat->GetRange().GetTopLeftCorner(), condformat::dialog::NONE);
-    Show(false, 0);
-    if(pDlg->Execute() == RET_OK)
-    {
-        sal_Int32 nKey = pFormat->GetKey();
-        mpFormatList->erase(nKey);
-        ScConditionalFormat* pNewFormat = pDlg->GetConditionalFormat();
-        if(pNewFormat)
-        {
-            pNewFormat->SetKey(nKey);
-            mpFormatList->InsertNew(pNewFormat);
-        }
-
-        m_pCtrlManager->Update();
-        mbModified = true;
-    }
-    Show(true, 0);
-
-    pScMod->SetRefDialog( nId, false );
+    EndDialog( DLG_RET_EDIT );
 
     return 0;
 }
 
-namespace {
-
-sal_uInt32 FindKey(ScConditionalFormatList* pFormatList)
-{
-    sal_uInt32 nKey = 0;
-    for(ScConditionalFormatList::const_iterator itr = pFormatList->begin(), itrEnd = pFormatList->end();
-            itr != itrEnd; ++itr)
-    {
-        if(itr->GetKey() > nKey)
-            nKey = itr->GetKey();
-    }
-
-    return nKey + 1;
-}
-
-}
-
 IMPL_LINK_NOARG(ScCondFormatManagerDlg, AddBtnHdl)
 {
-    sal_uInt16 nId = 1;
-    ScModule* pScMod = SC_MOD();
-    pScMod->SetRefDialog( nId, true );
-    VclPtrInstance<ScCondFormatDlg> pDlg(this, mpDoc, nullptr, ScRangeList(),
-                                         maPos, condformat::dialog::CONDITION);
-    Show(false, 0);
-    if(pDlg->Execute() == RET_OK)
-    {
-        ScConditionalFormat* pNewFormat = pDlg->GetConditionalFormat();
-        if(pNewFormat)
-        {
-            mpFormatList->InsertNew(pNewFormat);
-            pNewFormat->SetKey(FindKey(mpFormatList));
-            m_pCtrlManager->Update();
-
-            mbModified = true;
-        }
-    }
-    Show(true, 0);
-    pScMod->SetRefDialog( nId, false );
+    EndDialog( DLG_RET_ADD );
 
     return 0;
 }
diff --git a/sc/source/ui/inc/condformatdlg.hxx b/sc/source/ui/inc/condformatdlg.hxx
index 6036861..676dc4e 100644
--- a/sc/source/ui/inc/condformatdlg.hxx
+++ b/sc/source/ui/inc/condformatdlg.hxx
@@ -21,9 +21,13 @@
 
 #include "rangelst.hxx"
 #include "condformathelper.hxx"
+#include "viewdata.hxx"
 
 #include "anyrefdg.hxx"
 
+#define DLG_RET_ADD         8
+#define DLG_RET_EDIT        16
+
 class ScDocument;
 class ScConditionalFormat;
 class ScFormatEntry;
@@ -92,19 +96,23 @@ public:
     DECL_LINK( ColFormatTypeHdl, ListBox*);
 };
 
-class ScCondFormatDlg : public ScAnyRefModalDlg
+class ScCondFormatDlg : public ScAnyRefDlg
 {
 private:
+    VclPtr<PushButton> mpBtnOk;
     VclPtr<PushButton> mpBtnAdd;
     VclPtr<PushButton> mpBtnRemove;
+    VclPtr<PushButton> mpBtnCancel;
     VclPtr<FixedText> mpFtRange;
     VclPtr<formula::RefEdit> mpEdRange;
     VclPtr<formula::RefButton> mpRbRange;
 
     VclPtr<ScCondFormatList> mpCondFormList;
+    sal_Int32 maKey;
 
+    sal_Bool mbManaged;
     ScAddress maPos;
-    ScDocument* mpDoc;
+    ScViewData* mpViewData;
 
     VclPtr<formula::RefEdit> mpLastEdit;
 
@@ -112,22 +120,31 @@ private:
 protected:
 
     virtual void RefInputDone( bool bForced = false ) SAL_OVERRIDE;
+    void OkPressed();
+    void CancelPressed();
 
 public:
-    SC_DLLPUBLIC ScCondFormatDlg(vcl::Window* pWindow, ScDocument* pDoc, const ScConditionalFormat* pFormat,
-            const ScRangeList& rRange, const ScAddress& rPos, condformat::dialog::ScCondFormatDialogType eType);
+    SC_DLLPUBLIC ScCondFormatDlg(SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* pWindow,
+                                 ScViewData* pViewData, const ScConditionalFormat* pFormat,
+                                 const ScRangeList& rRange, const ScAddress& rPos,
+                                 condformat::dialog::ScCondFormatDialogType eType, sal_Bool bManaged);
     virtual ~ScCondFormatDlg();
     virtual void dispose() SAL_OVERRIDE;
 
     SC_DLLPUBLIC ScConditionalFormat* GetConditionalFormat() const;
 
+    static OUString GenerateXmlString(sal_uInt32 nIndex, sal_uInt8 nType, bool bManaged);
+    static bool ParseXmlString(const OUString& sXMLString, sal_uInt32& nIndex,
+                               sal_uInt8& nType, bool& bManaged);
     virtual void SetReference(const ScRange&, ScDocument*) SAL_OVERRIDE;
     virtual bool IsRefInputMode() const SAL_OVERRIDE;
     virtual void SetActive() SAL_OVERRIDE;
     virtual bool IsTableLocked() const SAL_OVERRIDE;
+    virtual bool Close() SAL_OVERRIDE;
 
     void InvalidateRefData();
 
+    DECL_LINK( BtnPressedHdl, Button* );
     DECL_LINK( RangeGetFocusHdl, formula::RefEdit* );
     DECL_STATIC_LINK( ScCondFormatDlg, RangeLoseFocusHdl, void* );
 };
diff --git a/sc/source/ui/inc/condformatmgr.hxx b/sc/source/ui/inc/condformatmgr.hxx
index 1d33988..76e26fd 100644
--- a/sc/source/ui/inc/condformatmgr.hxx
+++ b/sc/source/ui/inc/condformatmgr.hxx
@@ -56,6 +56,8 @@ public:
 
     bool CondFormatsChanged() { return mbModified;}
 
+    ScConditionalFormat* GetCondFormatSelected();
+
 private:
     VclPtr<PushButton> m_pBtnAdd;
     VclPtr<PushButton> m_pBtnRemove;
diff --git a/sc/source/ui/inc/reffact.hxx b/sc/source/ui/inc/reffact.hxx
index 6d12f0e..4dee934 100644
--- a/sc/source/ui/inc/reffact.hxx
+++ b/sc/source/ui/inc/reffact.hxx
@@ -50,6 +50,7 @@ DECL_WRAPPER_WITHID(ScPrintAreasDlgWrapper)
 DECL_WRAPPER_WITHID(ScColRowNameRangesDlgWrapper)
 DECL_WRAPPER_WITHID(ScFormulaDlgWrapper)
 DECL_WRAPPER_WITHID(ScHighlightChgDlgWrapper)
+DECL_WRAPPER_WITHID(ScCondFormatDlgWrapper)
 
 class ScDescriptiveStatisticsDialogWrapper :
     public ChildWindowWrapper<SID_DESCRIPTIVE_STATISTICS_DIALOG>
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 518410b..7bb562b 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -1909,6 +1909,35 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
         case SID_OPENDLG_ICONSET:
         case SID_OPENDLG_CONDDATE:
             {
+                sal_uInt32  nIndex      = sal_uInt32(-1);
+                sal_uInt8   nType       = 0;
+                bool        bManaged    = false;
+
+                // Get the pool item stored it by Conditional Format Manager Dialog.
+                const SfxPoolItem* pItem = NULL;
+                sal_uInt32 nItems(pTabViewShell->GetPool().GetItemCount2( SCITEM_STRING ));
+                for( sal_uInt32 nIter = 0; nIter < nItems; ++nIter )
+                {
+                    if( NULL != (pItem = pTabViewShell->GetPool().GetItem2( SCITEM_STRING, nIter ) ) )
+                    {
+                        if ( ScCondFormatDlg::ParseXmlString(
+                                static_cast<const SfxStringItem*>(pItem)->GetValue(),
+                                nIndex, nType, bManaged))
+                            break;
+                    }
+                }
+
+                // Check if the Conditional Manager Dialog is editing or adding
+                // conditional format item.
+                if ( bManaged )
+                {
+                    sal_uInt16 nId = ScCondFormatDlgWrapper::GetChildWindowId();
+                    SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
+                    SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
+
+                    pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
+                    break;
+                }
 
                 ScRangeList aRangeList;
                 ScViewData* pData = GetViewData();
@@ -1928,11 +1957,11 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                     aRangeList.push_back(pRange);
                 }
 
-                sal_Int32 nKey = 0;
+                const ScConditionalFormat* pCondFormat = NULL;
                 const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
                 const std::vector<sal_uInt32>& rCondFormats = static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData();
                 bool bContainsCondFormat = !rCondFormats.empty();
-                ScopedVclPtr<ScCondFormatDlg> pCondFormatDlg;
+                bool bCondFormatDlg = false;
                 if(bContainsCondFormat)
                 {
                     bool bContainsExistingCondFormat = false;
@@ -1941,7 +1970,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                                             itr != itrEnd; ++itr)
                     {
                         // check if at least one existing conditional format has the same range
-                        const ScConditionalFormat* pCondFormat = pList->GetFormat(*itr);
+                        pCondFormat = pList->GetFormat(*itr);
                         if(!pCondFormat)
                             continue;
 
@@ -1950,16 +1979,14 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                         if(rCondFormatRange == aRangeList)
                         {
                             // found a matching range, edit this conditional format
-                            nKey = pCondFormat->GetKey();
-                            pCondFormatDlg.reset( VclPtr<ScCondFormatDlg>::Create( pTabViewShell->GetDialogParent(), pDoc, pCondFormat, rCondFormatRange, aPos, condformat::dialog::NONE ) );
+                            bCondFormatDlg = true;
                             break;
                         }
                     }
 
                     // if not found a conditional format ask whether we should edit one of the existing
                     // or should create a new overlapping conditional format
-
-                    if(!pCondFormatDlg && bContainsExistingCondFormat)
+                    if(!bCondFormatDlg && bContainsExistingCondFormat)
                     {
                         ScopedVclPtrInstance<QueryBox> aBox( pTabViewShell->GetDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
                                ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) );
@@ -1972,22 +1999,14 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                             // otherwise open the manage cond format dlg
                             if(rCondFormats.size() == 1)
                             {
-                                const ScConditionalFormat* pCondFormat = pList->GetFormat(rCondFormats[0]);
+                                pCondFormat = pList->GetFormat(rCondFormats[0]);
                                 assert(pCondFormat);
-                                const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
-                                nKey = pCondFormat->GetKey();
-                                pCondFormatDlg.reset( VclPtr<ScCondFormatDlg>::Create( pTabViewShell->GetDialogParent(), pDoc, pCondFormat, rCondFormatRange, aPos, condformat::dialog::NONE ) );
+                                bCondFormatDlg = true;
                             }
                             else
                             {
-                                ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
-                                boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
-                                if(pDlg->Execute() == RET_OK && pDlg->CondFormatsChanged())
-                                {
-                                    ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
-                                    pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
-                                }
-                                // we need step out here because we don't want to open the normal dialog
+                                // Queue message to open Conditional Format Manager Dialog.
+                                GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT_MANAGER, SfxCallMode::ASYNCHRON );
                                 break;
                             }
                         }
@@ -1996,51 +2015,50 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                             // define an overlapping conditional format
                             // does not need to be handled here
                         }
-
                     }
                 }
 
-                if(!pCondFormatDlg)
+                condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
+                switch(nSlot)
                 {
-                    condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
-                    switch(nSlot)
-                    {
-                        case SID_OPENDLG_CONDFRMT:
-                            eType = condformat::dialog::CONDITION;
-                            break;
-                        case SID_OPENDLG_COLORSCALE:
-                            eType = condformat::dialog::COLORSCALE;
-                            break;
-                        case SID_OPENDLG_DATABAR:
-                            eType = condformat::dialog::DATABAR;
-                            break;
-                        case SID_OPENDLG_ICONSET:
-                            eType = condformat::dialog::ICONSET;
-                            break;
-                        case SID_OPENDLG_CONDDATE:
-                            eType = condformat::dialog::DATE;
-                            break;
-                        default:
-                            assert(false);
-                            break;
-                    }
-                    pCondFormatDlg.reset( VclPtr<ScCondFormatDlg>::Create( pTabViewShell->GetDialogParent(), pDoc, nullptr, aRangeList, aRangeList.GetTopLeftCorner(), eType ) );
+                    case SID_OPENDLG_CONDFRMT:
+                        eType = condformat::dialog::CONDITION;
+                        break;
+                    case SID_OPENDLG_COLORSCALE:
+                        eType = condformat::dialog::COLORSCALE;
+                        break;
+                    case SID_OPENDLG_DATABAR:
+                        eType = condformat::dialog::DATABAR;
+                        break;
+                    case SID_OPENDLG_ICONSET:
+                        eType = condformat::dialog::ICONSET;
+                        break;
+                    case SID_OPENDLG_CONDDATE:
+                        eType = condformat::dialog::DATE;
+                        break;
+                    default:
+                        assert(false);
+                        break;
                 }
 
-                sal_uInt16 nId = 1;
-                pScMod->SetRefDialog( nId, true );
 
-                if( pCondFormatDlg->Execute() == RET_OK )
+                if(bCondFormatDlg || !bContainsCondFormat)
                 {
-                    ScConditionalFormat* pFormat = pCondFormatDlg->GetConditionalFormat();
-                    if(pFormat)
-                        pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nKey, pFormat, aPos.Tab(), pFormat->GetRange());
-                    else
-                        pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nKey, NULL, aPos.Tab(), ScRangeList());
-                }
+                    // Put the xml string parameter to initialize the
+                    // Conditional Format Dialog.
+                    pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
+                                                      ScCondFormatDlg::GenerateXmlString(
+                                                        pCondFormat ? pCondFormat->GetKey() : sal_uInt32(-1),
+                                                        sal_uInt8(eType),
+                                                        false
+                                                      ) ) );
 
-                pScMod->SetRefDialog( nId, false );
+                    sal_uInt16      nId      = ScCondFormatDlgWrapper::GetChildWindowId();
+                    SfxViewFrame*   pViewFrm = pTabViewShell->GetViewFrame();
+                    SfxChildWindow* pWnd     = pViewFrm->GetChildWindow( nId );
 
+                    pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
+                }
             }
             break;
 
@@ -2396,12 +2414,43 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
 
                 ScConditionalFormatList* pList = pDoc->GetCondFormList( aPos.Tab() );
-                boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
-                if(pDlg->Execute() == RET_OK && pDlg->CondFormatsChanged())
+                boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg(
+                    pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
+                short nRet = pDlg->Execute();
+                if(nRet == RET_OK && pDlg->CondFormatsChanged())
                 {
                     ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
                     pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
                 }
+                else if(nRet == DLG_RET_ADD)
+                {
+                    // Put the xml string parameter to initialize the
+                    // Conditional Format Dialog. ( add new )
+                    pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
+                                                      ScCondFormatDlg::GenerateXmlString(
+                                                        sal_uInt32(-1),
+                                                        sal_uInt8(condformat::dialog::ScCondFormatDialogType::CONDITION),
+                                                        true
+                                                      ) ) );
+
+                    // Queue message to open Conditional Format Dialog
+                    GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
+                }
+                else if (nRet == DLG_RET_EDIT)
+                {
+                    ScConditionalFormat* pFormat = pDlg->GetCondFormatSelected();
+                    // Put the xml string parameter to initialize the
+                    // Conditional Format Dialog. ( edit selected conditional format )
+                    pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
+                                                      ScCondFormatDlg::GenerateXmlString(
+                                                        pFormat ? pFormat->GetKey() : sal_uInt32(-1),
+                                                        sal_uInt8(condformat::dialog::ScCondFormatDialogType::CONDITION),
+                                                        true
+                                                      ) ) );
+
+                    // Queue message to open Conditional Format Dialog
+                    GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
+                }
             }
             break;
 
diff --git a/sc/source/ui/view/reffact.cxx b/sc/source/ui/view/reffact.cxx
index b05db95f..75c69b1 100644
--- a/sc/source/ui/view/reffact.cxx
+++ b/sc/source/ui/view/reffact.cxx
@@ -48,6 +48,7 @@ SFX_IMPL_MODELESSDIALOG_WITHID(ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
 SFX_IMPL_MODELESSDIALOG_WITHID(ScAcceptChgDlgWrapper, FID_CHG_ACCEPT )
 SFX_IMPL_MODELESSDIALOG_WITHID(ScHighlightChgDlgWrapper, FID_CHG_SHOW )
 SFX_IMPL_MODELESSDIALOG_WITHID(ScSimpleRefDlgWrapper, WID_SIMPLE_REF )
+SFX_IMPL_MODELESSDIALOG_WITHID(ScCondFormatDlgWrapper, WID_CONDFRMT_REF )
 
 SFX_IMPL_CHILDWINDOW_WITHID(ScValidityRefChildWin, SID_VALIDITY_REFERENCE)
 
@@ -309,4 +310,6 @@ ScValidityRefChildWin::~ScValidityRefChildWin()
         pWindow = NULL;
 }
 
+IMPL_CHILD_CTOR( ScCondFormatDlgWrapper, WID_CONDFRMT_REF )
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/tabvwsh.cxx b/sc/source/ui/view/tabvwsh.cxx
index 95b3903..632757d 100644
--- a/sc/source/ui/view/tabvwsh.cxx
+++ b/sc/source/ui/view/tabvwsh.cxx
@@ -100,6 +100,7 @@ void ScTabViewShell::InitInterface_Impl()
     GetStaticInterface()->RegisterChildWindow(ScFTestDialogWrapper::GetChildWindowId());
     GetStaticInterface()->RegisterChildWindow(ScZTestDialogWrapper::GetChildWindowId());
     GetStaticInterface()->RegisterChildWindow(ScChiSquareTestDialogWrapper::GetChildWindowId());
+    GetStaticInterface()->RegisterChildWindow(ScCondFormatDlgWrapper::GetChildWindowId());
 }
 
 SFX_IMPL_NAMED_VIEWFACTORY( ScTabViewShell, "Default" )
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index 4d5d2d4..38502d2 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -459,8 +459,60 @@ VclPtr<SfxModelessDialog> ScTabViewShell::CreateRefDialog(
         }
         break;
 
-        default:
-        OSL_FAIL( "ScTabViewShell::CreateRefDialog: unbekannte ID" );
+        case WID_CONDFRMT_REF:
+        {
+            sal_uInt32  nIndex      = sal_uInt32(-1);
+            sal_uInt8   nType       = 0;
+            bool        bManaged    = false;
+            bool        bFound      = false;
+
+            ScRangeList aRangeList;
+            ScConditionalFormat* pCondFormat;
+            condformat::dialog::ScCondFormatDialogType aDialogType;
+
+            // Get the pool item stored it by Conditional Format Manager Dialog.
+            const SfxPoolItem* pItem = NULL;
+            sal_uInt32 nItems(GetPool().GetItemCount2( SCITEM_STRING ));
+            for( sal_uInt32 nIter = 0; nIter < nItems; ++nIter )
+            {
+                if( NULL != (pItem = GetPool().GetItem2( SCITEM_STRING, nIter ) ) )
+                {
+                    if ( ScCondFormatDlg::ParseXmlString(
+                            static_cast<const SfxStringItem*>(pItem)->GetValue(),
+                            nIndex, nType, bManaged))
+                    {
+                        bFound = true;
+                        break;
+                    }
+                }
+            }
+
+            ScViewData& rViewData = GetViewData();
+            rViewData.SetRefTabNo( rViewData.GetTabNo() );
+
+            aDialogType = static_cast< condformat::dialog::ScCondFormatDialogType > ( nType );
+            pCondFormat = pDoc->GetCondFormList(rViewData.GetTabNo())->GetFormat ( nIndex );
+
+            if ( pCondFormat )
+                aRangeList = pCondFormat->GetRange();
+            else
+            {
+                rViewData.GetMarkData().FillRangeListWithMarks(&aRangeList, false);
+                ScAddress aPos(rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
+                if(aRangeList.empty())
+                {
+                    ScRange* pRange = new ScRange(aPos);
+                    aRangeList.push_back(pRange);
+                }
+            }
+
+            pResult = VclPtr<ScCondFormatDlg>::Create( pB, pCW, pParent, &rViewData, pCondFormat, aRangeList,
+                aRangeList.GetTopLeftCorner(), aDialogType, bManaged );
+
+            // Remove the pool item stored it by Conditional Format Manager Dialog.
+            if ( bFound && pItem )
+                GetPool().Remove( *pItem );
+        }
         break;
     }
 


More information about the Libreoffice-commits mailing list