Source

oberchatten / ServerVersionUnit.cpp

Full commit
//---------------------------------------------------------------------------
#ifdef HAVE_CONFIG_H
# include "overchat_config.h"
#endif //HAVE_CONFIG_H

#include <vcl.h>
#include <time.h>
#include <stdio.h>

#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif //HAVE_LIMITS_H

#ifdef HDRSTOP
# pragma hdrstop
#endif //HDRSTOP

#include "daybothreads.h"
#include "blake.h" // OverChat's main library
#include "General.h" // For CentreMyForm()
#include "ShadowUnit.h" // TShadowForm
#include "InfoBoxUnit.h" // INFOBOX_ICONS_RESHANDLE
#include "Options.h" // Options
#include "ServerVersionUnit.h" // TServerVersionDlg (this)
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TServerVersionDlg *ServerVersionDlg = NULL; // Global disabled
using namespace Oberchatten;

#ifdef OVERCHAT_RCS_STAMPS
static const char *rcsid =
  "$Id: ServerVersionUnit.cpp,v 0.3 2006/03/04 13:40:00 ddrp Exp $";
#endif /*OVERCHAT_RCS_STAMPS*/
//---------------------------------------------------------------------------
__fastcall TServerVersionDlg::TServerVersionDlg(
  TComponent *Owner
)
        : TForm(Owner),
          iconVer(1),
          shadow(NULL),
          inDenyChk(false)
{
  #ifdef OVERCHAT_RCS_STAMPS
    blake_Unused(rcsid);
  #endif /*OVERCHAT_RCS_STAMPS*/

  daybothreads_CreateLock(&this->moveHandlingLock);
}
//---------------------------------------------------------------------------
__fastcall TServerVersionDlg::~TServerVersionDlg()
{
  daybothreads_DestroyLock(&this->moveHandlingLock);
}
//---------------------------------------------------------------------------
void __fastcall TServerVersionDlg::OnMove(TWMMove &Message)
{
  if ( this->shadow ) {
    this->LockOnMove(true);
    this->UpdateShadow();
    this->LockOnMove(false);
  }
}
//---------------------------------------------------------------------------
void __fastcall TServerVersionDlg::FormCreate(TObject *Sender)
{
  this->SetIcon();
  if ( Options.GetOptionBool(Oberchatten::oShadows) )
    this->shadow = new TShadowForm(this);
}
//---------------------------------------------------------------------------
void __fastcall TServerVersionDlg::FormDestroy(TObject *Sender)
{
  if ( this->shadow ) {
    delete this->shadow;
    this->shadow = NULL;
  }
  this->SetIcon(NULL);
}
//---------------------------------------------------------------------------
void TServerVersionDlg::LockOnMove(bool Locking)
{
  if ( Locking )
    daybothreads_EnterLock(&this->moveHandlingLock);
  else
    daybothreads_LeaveLock(&this->moveHandlingLock);
}
//---------------------------------------------------------------------------
void TServerVersionDlg::UpdateShadow()
{
  if ( this->shadow ) {
    this->shadow->Follow();
    if ( !this->shadow->Visible ) this->shadow->Show();
  }
}
//---------------------------------------------------------------------------
unsigned int TServerVersionDlg::IconVersion(
  unsigned int NewIconVersion
)
{
  if ( NewIconVersion ) // Changing?
    this->iconVer = NewIconVersion; // Assign new

  // Correct the icon to one we support
  if ( this->iconVer >= 6 )
    this->iconVer = 6;
  else if ( this->iconVer >= 4 )
    this->iconVer = 4;
  else if ( this->iconVer >= 1 )
    this->iconVer = 3;

  return this->iconVer;
}
//---------------------------------------------------------------------------
bool TServerVersionDlg::SetServerExFlags(
  const blake_word16_t Flags
)
{
  if ( !this->inDenyChk ) {
    this->inDenyChk = true;
    this->DebugChk->Checked = (bool)(Flags & OVERCHAT_VEREX_DEBUG);
    this->PrivateChk->Checked = (bool)(Flags & OVERCHAT_VEREX_PRIVATE);
    this->SpecialChk->Checked = (bool)(Flags & OVERCHAT_VEREX_SPECIAL);
    this->PreReleaseChk->Checked = (bool)(Flags & OVERCHAT_VEREX_PRERELEASE);
    this->BetaChk->Checked = (bool)(Flags & OVERCHAT_VEREX_BETA);
    this->PreEmptChk->Checked = (bool)(Flags & OVERCHAT_VEREX_PREEMPT);
    this->inDenyChk = false;
  }

  if ( Flags & OVERCHAT_VEREX_UNDEFINED_6 ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_7 ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_8 ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_9 ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_A ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_B ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_C ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_D ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_E ) return false;
  if ( Flags & OVERCHAT_VEREX_UNDEFINED_F ) return false;
  return true;
}
//---------------------------------------------------------------------------
void __fastcall TServerVersionDlg::FormShow(TObject *Sender)
{
  CentreMyForm(this, Screen);
  this->UpdateShadow();
}
//---------------------------------------------------------------------------
void __fastcall TServerVersionDlg::DenyChk(TObject *Sender)
{
  if ( !inDenyChk ) {
    TCheckBox *pcb;

    inDenyChk = true;
    pcb = dynamic_cast<TCheckBox*>(Sender);
    if ( pcb ) {
      pcb->Checked = !pcb->Checked;
    }
    inDenyChk = false;
  }
}
//---------------------------------------------------------------------------
void TServerVersionDlg::SetIcon(bool Setting)
{
  if ( Setting ) {
    AnsiString resname("IDB_INFOICONS_INFORMATION_");
    resname += (AnsiString)this->IconVersion();

    this->IconImage->Picture->Bitmap->LoadFromResourceName(
      (int)INFOBOX_ICONS_RESHANDLE,
      resname
    );

    // Reduce memory requirements
    this->IconImage->Picture->Bitmap->FreeImage();
  }
  else
    this->IconImage->Picture->Assign(NULL); // Clear it

  return;
}
//---------------------------------------------------------------------------