Source

gdt / SpriteEd / edwin.cpp

Full commit
/* This class controls an editor window (sprite editing) */

#include <Owl\MDIChild.H>
#include <Assert.H>
#include "Stds\DLStdInc.H"
#include "Stds\MoreLmts.H"
#pragma hdrstop

#include "CoppsRes.H" // Technical resource definitions
#include "EdWin.H"
//---------------------------------------------------------------------------
NATIVEBOOLTYPE TEdWin::_expressClose = FALSE;
int TEdWin::_numChildren = 0;
//---------------------------------------------------------------------------
TEdWin::TEdWin(TMDIClient& parent, int ChildNum)
:	TMDIChild(parent),
	_childNum(ChildNum),
   _spriteData(NULL) // Sprite data has not yet been allocated
{
	++_numChildren; // Another child created
   SetupCaption("");
}
//---------------------------------------------------------------------------
TEdWin::~TEdWin()
{
	--_numChildren; // Another child destroyed

   if (_spriteData) /* A sprite was allocated? */
   	free(_spriteData); /* Free the sprite */
}
//---------------------------------------------------------------------------
NATIVEBOOLTYPE TEdWin::CanClose()
{
	return _expressClose
   	|| MessageBox("Close this window?",
      	"Query",
         MB_YESNO | MB_ICONQUESTION) == IDYES;
}
//---------------------------------------------------------------------------
void TEdWin::SetExpressClose(NATIVEBOOLTYPE tf)
{
	_expressClose = tf;
}
//---------------------------------------------------------------------------
int TEdWin::GetNumChildren()
{
	return _numChildren;
}
//---------------------------------------------------------------------------
void TEdWin::SetupCaption(const char* FileName)
{
	char deftext[] = " Sprite #";
   char defname[] = "Untitled";
   char blank[] = "";
   char* buff; // Will be allocated later
   char* usestr;
   char* usename;
   char strofnum[18]; /* For number conversion */

   assert(FileName); /* Must send pointer, even if it's to a blank string */
   if (FileName[0] == '\0') /* No string sent? */
   {
   	usestr = deftext; // Use default text
      usename = defname;
   }
   else // String sent
   {
   	usestr = blank; // Add nothing on the end
      usename = (char*)FileName; // Case const to r/w (just don't use the pointer to modify it!
   }

   buff = new char[strlen(usename)+strlen(deftext)+sizeof(strofnum)];

   strcpy(buff, usename);
   strcat(buff, usestr);
   itoa(_childNum, strofnum, 10);
   strcat(buff, strofnum); /* Add the number to the caption */

   SetCaption(buff); /* Implement the caption (display) */

   // Cleaup
   delete[] buff;
}
//---------------------------------------------------------------------------