Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions sc/inc/document.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@
#include "SheetViewTypes.hxx"

#include <oox/helper/refvector.hxx>
#include <sc.hrc>
#include <refhint.hxx>
#include <refupdatecontext.hxx>


// REF_CODE_BEGIN
namespace sc {
struct RefErrorResult;
}
// REF_CODE_END
namespace com::sun::star::chart2 { class XChartDocument; }
namespace oox
{
Expand Down Expand Up @@ -99,6 +108,25 @@ class CopyFromClipContext;
class ColumnSpanSet;
struct ColumnBlockPosition;
struct RefUpdateContext;
// REF_CODE_BEGIN
//struct RefUpdateResult;
// REF_CODE_END
// REF_CODE_BEGIN
struct RefErrorResult {
bool mbRefErrorCreated;
OUString maDeletedAddressStr; // For %1 (The "Source" of the error)
OUString maErrorAddressStr; // For %2 (The "Target" cell containing #REF!)

RefErrorResult() : mbRefErrorCreated(false) {}

void reset() {
mbRefErrorCreated = false;
maDeletedAddressStr = OUString();
maErrorAddressStr = OUString();
//maFirstErrorAddress.SetInvalid();
}
};
// REF_CODE_END
class EditTextIterator;
struct NoteEntry;
class DocumentLinkManager;
Expand Down Expand Up @@ -218,6 +246,9 @@ class ScTableStyles;
namespace sc {

typedef std::map<OUString, Bitmap> IconSetBitmapMap;
// REF_CODE_BEGIN
//struct RefUpdateResult;
// REF_CODE_END

}

Expand Down Expand Up @@ -354,8 +385,43 @@ friend class sc::EditTextIterator;
friend struct ScMutationGuard;
friend struct ScMutationDisable;

// REF_CODE_BEGIN
private:
// ... other members ...
sc::RefErrorResult maPendingRefError; // This stores the error
public:
// Setter (used by token.cxx)
//void SetPendingRefError(const ScAddress& rAddr) {
// maPendingRefError.mbRefErrorCreated = true;
// maPendingRefError.maFirstErrorAddress = rAddr;
// }
void SetPendingRefError(const sc::RefErrorResult& rRes) {
maPendingRefError = rRes;
}

// Getter (used by viewfunc.cxx)
const sc::RefErrorResult& GetPendingRefError() const { return maPendingRefError; }
void ResetPendingRefError();

// Clear (used by viewfunc.cxx)
void ClearPendingRefError() {
maPendingRefError.mbRefErrorCreated = false;
//maPendingRefError.maFirstErrorAddress.SetInvalid();
maPendingRefError.reset();
}
bool HasPendingRefError() const { return maPendingRefError.mbRefErrorCreated; }

void BroadcastPendingRefError() {
if (maPendingRefError.mbRefErrorCreated) {
BroadcastRefError(maPendingRefError);
// Clear it so it doesn't pop up again on the next click
maPendingRefError.mbRefErrorCreated = false;
}
}

// REF_CODE_END
public:

enum class HardRecalcState
{
OFF, /// normal calculation of dependencies
Expand Down Expand Up @@ -1869,6 +1935,9 @@ public:
void UpdateReference( sc::RefUpdateContext& rCxt, ScDocument*
pUndoDoc = nullptr, bool bIncludeDraw = true,
bool bUpdateNoteCaptionPos = true );
// REF_CODE_BEGIN
void BroadcastRefError(const sc::RefErrorResult& rRes);
// REF_CODE_END
/**
* @param pClipDoc original clipboard doc, i.e. non-transposed
* This clip doc is used to check references pointing to cut cells.
Expand Down
9 changes: 9 additions & 0 deletions sc/inc/refupdatecontext.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ struct RefUpdateResult

SCTAB mnTab;

// REF_CODE_BEGIN
/** * Flagged true if a previously valid reference becomes #REF!
* during this specific update operation.
*/
bool mbRefErrorCreated;
/** Stores the address of the cell containing the formula that errored. */
ScAddress maFirstErrorAddress;
// REF_CODE_END

RefUpdateResult();
};

Expand Down
4 changes: 4 additions & 0 deletions sc/inc/sc.hrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class SvxZoomSliderItem;
// SC_VIEW_END (SID_SC_START + 99)
#define SC_MESSAGE_START (SID_SC_START + 100)
// SC_MESSAGE_END (SID_SC_START + 199)
// REF_CODE_BEGIN
#define SC_HINT_REF_ERROR_CREATED (SC_MESSAGE_START + 70)
#define SID_REF_ERROR_NOTIFY (SID_SC_START + 1234)
// REF_CODE_END
#ifndef SC_FUNCTION_START // duplicated in sfx2/sfxsids.hrc
#define SC_FUNCTION_START (SID_SC_START + 200)
#endif
Expand Down
4 changes: 4 additions & 0 deletions sc/inc/strings.hrc
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,8 @@

#define STR_AUTOCALC_OFF NC_("STR_AUTOCALC_OFF", "AutoCalculate: Off\nClick to enable.")

// REF_CODE_BEGIN
#define STR_LOGIC_DESTROYED NC_("STR_LOGIC_DESTROYED", "Deleting former cell <%1> broke a formula in cell <%2>. Click UNDO twice(!) to restore the formula.")
// REF_CODE_END
//
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
93 changes: 93 additions & 0 deletions sc/source/core/data/document.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@
#include <sfx2/lokhelper.hxx>
#include <SheetViewManager.hxx>

#include <sc.hrc>
#include <refhint.hxx>
#include <refupdatecontext.hxx>


// REF_CODE_BEGIN
#include <sc.hrc> // Provides the definition of SC_HINT_REF_ERROR_CREATED
#include <hints.hxx> // Provides the FULL definition of class ScHint
#include <refupdatecontext.hxx> // Provides the definition of sc::RefUpdateResult
#include <docsh.hxx> // Provides the definition of ScDocShell
#include <brdcst.hxx> // For the ScHint definition
// REF_CODE_END

using ::editeng::SvxBorderLine;
using namespace ::com::sun::star;

Expand Down Expand Up @@ -777,6 +790,24 @@ bool ScDocument::DeleteTab( SCTAB nTab )
bValid = true;
}
}

// REF_CODE_BEGIN
if (bValid)
{
// --- START OF INFOBAR TRIGGER LOGIC ---
// This logic detects if deleting the sheet caused any formula to break (producing #REF!)
// and broadcasts a hint to show an InfoBar in the UI.

if (HasPendingRefError())
{
// Debug log for development tracking
fprintf(stderr, "===[ DEBUG ]=== DeleteTab: Logic error detected in cell: %s\n",
maPendingRefError.maErrorAddressStr.toUtf8().getStr());

BroadcastPendingRefError();
}
}
// REF_CODE_END
return bValid;
}

Expand Down Expand Up @@ -867,6 +898,36 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
bValid = true;
}
}
// REF_CODE_BEGIN
if (bValid)
{
// --- START OF INFOBAR TRIGGER LOGIC ---

// 1. Create a standard Reference Update Context (Base Class)
sc::RefUpdateContext aRefCxt(*this);
aRefCxt.meMode = URM_INSDEL;

// 2. Use 'nSheets' as the verified parameter name.
aRefCxt.mnTabDelta = -(static_cast<SCTAB>(nSheets));

// 3. Define the affected range: from the deleted tab to the new end of the document.
aRefCxt.maRange = ScRange(0, 0, nTab, MaxCol(), MaxRow(), GetTableCount());

// 4. Trigger the document-wide update to find formulas that now point to #REF!
UpdateReference(aRefCxt);

// 5. If a logic error was caught, broadcast it to trigger the InfoBar in the UI
if (HasPendingRefError())
{
fprintf(stderr, "===[ DEBUG ]=== DeleteTabs: Logic error detected in cell: %s\n",
maPendingRefError.maErrorAddressStr.toUtf8().getStr());


BroadcastPendingRefError();
}
}
// REF_CODE_END

return bValid;
}

Expand Down Expand Up @@ -6946,4 +7007,36 @@ void ScDocument::MergeContextBackIntoNonThreadedContext(ScInterpreterContext& th
threadedContext.MergeDefaultFormatKeys(*GetFormatTable());
}

// REF_CODE_BEGIN
void ScDocument::BroadcastRefError(const sc::RefErrorResult& rResErr)
{
if (!rResErr.mbRefErrorCreated)
return;

// Create the hint
//ScHint aHint(static_cast<SfxHintId>(SC_HINT_REF_ERROR_CREATED), rResErr.maFirstErrorAddress);
ScHint aHint(static_cast<SfxHintId>(SC_HINT_REF_ERROR_CREATED), ScAddress());

// Get the DocShell (the UI container)
ScDocShell* pDocSh = GetDocumentShell();
if (pDocSh)
{
fprintf(stderr, "===[ DEBUG ]=== Broadcasting via DocShell for %s\n",
rResErr.maErrorAddressStr.toUtf8().getStr());
if (pDocSh) pDocSh->Broadcast(aHint); // This is the "channel" the UI listens to
}
else
{
fprintf(stderr, "===[ DEBUG ]=== No DocShell! Falling back to Document Broadcast.\n");
Broadcast(aHint);
}
fflush(stderr);
}
void ScDocument::ResetPendingRefError()
{
maPendingRefError.reset();
}
// REF_CODE_END


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Loading
Loading