Skip to content

Commit

Permalink
code clean up & start using jnew_allow_null
Browse files Browse the repository at this point in the history
  • Loading branch information
jafl committed Dec 26, 2023
1 parent 22ce557 commit 3f10b6a
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 48 deletions.
8 changes: 4 additions & 4 deletions libjcore/code/JRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ class JRect
)
const
{
return left <= x && x < right &&
top <= y && y < bottom;
return (left <= x && x < right &&
top <= y && y < bottom);
};

bool
Expand All @@ -187,8 +187,8 @@ class JRect
)
const
{
return left <= r.left && r.left <= r.right && r.right <= right &&
top <= r.top && r.top <= r.bottom && r.bottom <= bottom;
return (left <= r.left && r.left <= r.right && r.right <= right &&
top <= r.top && r.top <= r.bottom && r.bottom <= bottom);
};

void
Expand Down
4 changes: 2 additions & 2 deletions libjx/code/JXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ JXContainer::GetFrame() // enclosure coordinates
{
if (itsEnclosure != nullptr)
{
return (itsEnclosure->GlobalToLocal(GetFrameGlobal()));
return itsEnclosure->GlobalToLocal(GetFrameGlobal());
}
else
{
Expand Down Expand Up @@ -585,7 +585,7 @@ inline JRect
JXContainer::GetAperture()
const
{
return (GlobalToLocal(GetApertureGlobal()));
return GlobalToLocal(GetApertureGlobal());
}

inline JCoordinate
Expand Down
2 changes: 1 addition & 1 deletion libjx/code/JXDSSSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ JXDSSSelection::ConvertData

*returnType = XA_STRING;
*dataLength = 1;
*data = jnew unsigned char[ *dataLength ];
*data = jnew_allow_null unsigned char[ *dataLength ];
if (*data != nullptr)
{
**data = 0x45; // E
Expand Down
14 changes: 7 additions & 7 deletions libjx/code/JXDockDragData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ JXDockDragData::AddTypes
const Atom selectionName
)
{
AddType((JXGetDockManager())->GetDNDMinSizeAtom());
AddType((JXGetDockManager())->GetDNDWindowAtom());
AddType(JXGetDockManager()->GetDNDMinSizeAtom());
AddType(JXGetDockManager()->GetDNDWindowAtom());
}

/******************************************************************************
Expand All @@ -70,28 +70,28 @@ JXDockDragData::ConvertData
)
const
{
if (requestType == (JXGetDockManager())->GetDNDMinSizeAtom())
if (requestType == JXGetDockManager()->GetDNDMinSizeAtom())
{
*returnType = XA_POINT;
*bitsPerBlock = 16;
*dataLength = sizeof(XPoint);
*data = jnew unsigned char[ *dataLength ];
*data = jnew_allow_null unsigned char[ *dataLength ];
if (*data != nullptr)
{
const JPoint minSize = itsWindow->GetMinSize();
auto* xpt = (XPoint*) *data;
auto* xpt = (XPoint*) *data;
xpt->x = JMin(minSize.x, SHRT_MAX);
xpt->y = JMin(minSize.y, SHRT_MAX);
return true;
}
}

else if (requestType == (JXGetDockManager())->GetDNDWindowAtom())
else if (requestType == JXGetDockManager()->GetDNDWindowAtom())
{
*returnType = XA_WINDOW;
*bitsPerBlock = 32;
*dataLength = sizeof(Window);
*data = jnew unsigned char[ *dataLength ];
*data = jnew_allow_null unsigned char[ *dataLength ];
if (*data != nullptr)
{
*((Window*) *data) = itsWindow->GetXWindow();
Expand Down
1 change: 0 additions & 1 deletion libjx/code/JXFileSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ JXFileSelection::SetData
if (itsList == nullptr)
{
itsList = jnew JDCCPtrArray<JString>(list, JPtrArrayT::kDeleteAll);
assert( itsList != nullptr );
}
else
{
Expand Down
7 changes: 3 additions & 4 deletions libjx/code/JXSelectionData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ JXSelectionData::JXSelectionDataX()
itsEndTime = CurrentTime;

itsTypeList = jnew JArray<Atom>;
assert( itsTypeList != nullptr );
itsTypeList->SetCompareFunction(CompareAtoms);

itsDataSourceID = nullptr;
Expand Down Expand Up @@ -220,7 +219,7 @@ JXSelectionData::Resolve()
Handles certain types and passes everything else off to ConvertData().
When adding special types to this function, remember to update
SetSelectionInfo() to add the jnew types.
SetSelectionInfo() to add the new types.
******************************************************************************/

Expand Down Expand Up @@ -248,7 +247,7 @@ JXSelectionData::Convert
*bitsPerBlock = 32; // XXXATOM: sizeof(Atom)*8; -- fails on 64-bit systems
*dataLength = sizeof(Atom)*atomCount;

*data = jnew unsigned char [ *dataLength ];
*data = jnew_allow_null unsigned char [ *dataLength ];
if (*data == nullptr)
{
return false;
Expand All @@ -271,7 +270,7 @@ JXSelectionData::Convert
*bitsPerBlock = 32; // sizeof(Time)*8; -- fails on 64-bit systems
*dataLength = sizeof(Time);

*data = jnew unsigned char [ *dataLength ];
*data = jnew_allow_null unsigned char [ *dataLength ];
if (*data == nullptr)
{
return false;
Expand Down
8 changes: 3 additions & 5 deletions libjx/code/JXSelectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ JXSelectionManager::JXSelectionManager
(
JXDisplay* display
)
:
itsDisplay(display)
{
itsDisplay = display;

itsDataList = jnew JPtrArray<JXSelectionData>(JPtrArrayT::kDeleteAll);
assert( itsDataList != nullptr );

itsDataList = jnew JPtrArray<JXSelectionData>(JPtrArrayT::kDeleteAll);
itsMaxDataChunkSize = XMaxRequestSize(*display) * 4/5;

itsReceivedAllocErrorFlag = false;
Expand Down
18 changes: 6 additions & 12 deletions libjx/code/JXTEBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ JXTEBase::TEBeginDND()

auto* data = jnew JXTextSelection(this, kSelectionDataID);

return BeginDND(*(itsDNDDragInfo->pt), *(itsDNDDragInfo->buttonStates),
*(itsDNDDragInfo->modifiers), data);
return BeginDND(*itsDNDDragInfo->pt, *itsDNDDragInfo->buttonStates,
*itsDNDDragInfo->modifiers, data);
}

/******************************************************************************
Expand All @@ -416,7 +416,7 @@ JXTEBase::TEBeginDND()
void
JXTEBase::DNDFinish
(
const bool isDrop,
const bool isDrop,
const JXContainer* target
)
{
Expand Down Expand Up @@ -516,10 +516,8 @@ JXTEBase::GetSelectionData
auto* textData = dynamic_cast<JXTextSelection*>(data);
assert( textData != nullptr );

auto* text = jnew JString;

auto* text = jnew JString;
auto* style = jnew JRunArray<JFont>;
assert( style != nullptr );

const bool ok = GetSelection(text, style);
assert( ok );
Expand Down Expand Up @@ -1457,8 +1455,6 @@ JXTEBase::TEUpdateClipboard
const
{
auto* data = jnew JXTextSelection(GetDisplay(), text, &style);
assert( data != nullptr );

if (!GetSelectionManager()->SetData(kJXClipboardName, data))
{
JGetUserNotification()->ReportError(JGetString("UnableToCopy::JXTEBase"));
Expand Down Expand Up @@ -2771,7 +2767,7 @@ JXTEBase::GetPSPrintFileName()
{
if (itsPSPrintName == nullptr)
{
auto* me = const_cast<JXTEBase*>(this);
auto* me = const_cast<JXTEBase*>(this);
me->itsPSPrintName = jnew JString;
}

Expand Down Expand Up @@ -2898,7 +2894,7 @@ JXTEBase::GetPTPrintFileName()
{
if (itsPTPrintName == nullptr)
{
auto* me = const_cast<JXTEBase*>(this);
auto* me = const_cast<JXTEBase*>(this);
me->itsPTPrintName = jnew JString;
}

Expand Down Expand Up @@ -2970,8 +2966,6 @@ JXTEBase::AskForLine()
JIndex lineIndex = GetLineForChar(GetInsertionIndex().charIndex);

auto* dlog = jnew JXGoToLineDialog(lineIndex, GetLineCount());
assert( dlog != nullptr );

if (dlog->DoDialog())
{
bool physicalLineIndexFlag;
Expand Down
5 changes: 2 additions & 3 deletions libjx/code/JXTextSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ JXTextSelection::SetData
else if (style != nullptr && itsStyle == nullptr)
{
itsStyle = jnew JRunArray<JFont>(*style);
assert( itsStyle != nullptr );
}
else
{
Expand Down Expand Up @@ -282,7 +281,7 @@ JXTextSelection::ConvertData
{
*returnType = requestType;
*dataLength = itsText->GetByteCount();
*data = jnew unsigned char[ *dataLength ];
*data = jnew_allow_null unsigned char[ *dataLength ];
if (*data != nullptr)
{
memcpy(*data, itsText->GetRawBytes(), *dataLength);
Expand All @@ -301,7 +300,7 @@ JXTextSelection::ConvertData
const std::string s = dataStream.str();
*returnType = itsStyledText0XAtom;
*dataLength = s.length();
*data = jnew unsigned char[ *dataLength ];
*data = jnew_allow_null unsigned char[ *dataLength ];
if (*data != nullptr)
{
memcpy(*data, s.data(), *dataLength);
Expand Down
4 changes: 1 addition & 3 deletions libjx/code/JXWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,6 @@ JXWidget::CreateDragPainter
assert( visible );

itsDragPainter = jnew JXDragPainter(GetDisplay(), GetWindow(), clipRect);
assert( itsDragPainter != nullptr );

itsDragPainter->SetOrigin(itsBoundsG.left, itsBoundsG.top);
itsDragPainter->ResetClipRect(); // do this last so clipRect matches with new origin
return itsDragPainter;
Expand Down Expand Up @@ -1379,7 +1377,7 @@ JXWidget::GetSelectionData
void
JXWidget::DNDFinish
(
const bool isDrop,
const bool isDrop,
const JXContainer* target
)
{
Expand Down
6 changes: 2 additions & 4 deletions tutorial/14-DragAndDrop/DNDData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ DNDData::SetData
if (itsPoints == nullptr)
{
itsPoints = jnew JArray<JPoint>;
assert(itsPoints != nullptr);
}

// if the data had been set previously, we want to remove all of
Expand Down Expand Up @@ -132,7 +131,7 @@ DNDData::ConvertData
// The following code gives X the data in the form that it needs.
*returnType = itsLinesXAtom;
*dataLength = itsBuffer->GetByteCount();
*data = jnew unsigned char[ *dataLength ];
*data = jnew_allow_null unsigned char[ *dataLength ];
if (*data != nullptr)
{
memcpy(*data, itsBuffer->GetRawBytes(), *dataLength);
Expand Down Expand Up @@ -197,7 +196,6 @@ DNDData::CreateBuffer()
}

// Create our buffer with the character pointer.
th->itsBuffer = jnew JString(os.str());
assert( th->itsBuffer != nullptr );
th->itsBuffer = jnew JString(os.str());
}
}
3 changes: 1 addition & 2 deletions tutorial/14-DragAndDrop/DNDWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ DNDWidget::DNDWidget
// See JCollection.h, JList.h, and JArray.h for functionality

itsPoints = jnew JArray<JPoint>;
assert( itsPoints != nullptr );

// We need to register the drag X Atom with the display. We will need
// to keep a copy of the atom to check in WillAcceptDrop.
itsLinesXAtom = GetDisplay()->RegisterXAtom(DNDData::GetDNDAtomName());
itsLinesXAtom = GetDisplay()->RegisterXAtom(DNDData::GetDNDAtomName());
}

/******************************************************************************
Expand Down

0 comments on commit 3f10b6a

Please sign in to comment.