| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 | //---------------------------------------------------------------------------#include <vcl.h>#pragma hdrstop#include <FileCtrl.hpp>#include <VCLCommon.h>#include <Common.h>#include <CoreMain.h>#include <TextsWin.h>#include "Log.h"#include "Glyphs.h"#include "NonVisual.h"#include "WinConfiguration.h"#include "Tools.h"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma link "LogMemo"#pragma link "TB2Dock"#pragma link "TB2Item"#pragma link "TB2Toolbar"#pragma link "TBX"#pragma link "TBXStatusBars"#ifndef NO_RESOURCES#pragma resource "*.dfm"#endifTLogForm *LogForm = NULL;//---------------------------------------------------------------------------TLogForm * __fastcall CreateLogForm(TLogMemo *ALogMemo){  DebugAssert(!LogForm);  Configuration->Usage->Inc(L"LogWindowDisplays");  TLogForm * aLogForm = new TLogForm(Application);  try  {    aLogForm->LogMemo = ALogMemo;    aLogForm->Show();  }  catch (...)  {    delete aLogForm;    throw;  }  LogForm = aLogForm;  return aLogForm;}//---------------------------------------------------------------------------TLogForm * __fastcall RequireLogForm(TLogMemo *ALogMemo){  if (!LogForm)  {    CreateLogForm(ALogMemo);  }  return LogForm;}//---------------------------------------------------------------------------void __fastcall SwitchLogFormSessionLog(){  if (LogForm != NULL)  {    LogForm->SwitchSessionLog();  }}//---------------------------------------------------------------------------void __fastcall FreeLogForm(){  if (LogForm)  {    TLogForm * PLogForm = LogForm;    LogForm = NULL;    // would also free form see TLogForm::FormClose()    // we can't free form directly (cause exception when form is closed by    // button on toolbar, beacuse it destroys the button too)    PLogForm->Close();  }}//---------------------------------------------------------------------------__fastcall TLogForm::TLogForm(TComponent* Owner)        : TForm(Owner){  FLogMemo = NULL;  FSessionLog = NULL;  ShowWindow(Handle, SW_SHOWNA);  UseSystemSettings(this);  UseDesktopFont(StatusBar);  FixFormIcons(this);}//---------------------------------------------------------------------------__fastcall TLogForm::~TLogForm(){  // deassociate us from session log state change handler  SessionLog = NULL;  LogForm = NULL;  LogMemo = NULL;}//---------------------------------------------------------------------------void __fastcall TLogForm::SetLogMemo(TLogMemo * value){  if (LogMemo != value)  {    TLogMemo * OldLogMemo = LogMemo;    FLogMemo = value;    if (OldLogMemo)    {      DebugAssert((OldLogMemo->Parent == this) && (OldLogMemo->OnChange == LogMemoChange));      OldLogMemo->OnChange = NULL;      if (SessionLog == OldLogMemo->SessionLog) SessionLog = NULL;      OldLogMemo->Parent = NULL;    }    if (LogMemo)    {      LogMemo->Align = alClient;      SwitchSessionLog();      LogMemo->Parent = this;      // setting Parent usually calls OnChange many times (pending changes are      // inserted to TLogMemo), so we set OnChange handler after Parent.      LogMemo->OnChange = LogMemoChange;      LogMemoChange(LogMemo);    }  }}//---------------------------------------------------------------------------void __fastcall TLogForm::LogMemoChange(TObject * /*Sender*/){  DebugAssert(LogMemo);  Application->ProcessMessages();  if (!ComponentState.Contains(csDestroying))  {    UpdateActions();  }}//---------------------------------------------------------------------------void __fastcall TLogForm::FormClose(TObject * /*Sender*/, TCloseAction & Action){  DebugAssert(Configuration);  // If log window feature is turned off (log window is being closed  // by turning off this feature e.g. in Preferences Window), really close it  // If log window feature is turned on (log window is being closed by  // close command if this window) we only disable log window feature  // (this function will be than called again, see case 1)  LogMemo = NULL;  if (!Configuration->Logging || (WinConfiguration->LogView != lvWindow) ||      Application->Terminated)  {    Action = caFree;  }  else  {    WinConfiguration->LogView = lvNone;    Action = caNone;  }  WinConfiguration->LogWindowParams = StoreForm(this);}//---------------------------------------------------------------------------void __fastcall TLogForm::SetSessionLog(TSessionLog * value){  if (FSessionLog != value)  {    if (SessionLog)    {      DebugAssert(SessionLog->OnStateChange == SessionLogStateChange);      SessionLog->OnStateChange = NULL;    }    FSessionLog = value;    if (SessionLog)    {      DebugAssert(SessionLog->OnStateChange == NULL);      SessionLog->OnStateChange = SessionLogStateChange;    }    UpdateControls();  }}//---------------------------------------------------------------------------void __fastcall TLogForm::SessionLogStateChange(TObject * /*Sender*/){  UpdateControls();}//---------------------------------------------------------------------------void __fastcall TLogForm::UpdateControls(){  TTBXStatusPanel * Panel = StatusBar->Panels->Items[0];  if (SessionLog)  {    if (SessionLog->LoggingToFile)    {      Panel->TextTruncation = twPathEllipsis;      Panel->Caption = SessionLog->CurrentFileName;    }    else    {      Panel->TextTruncation = twEndEllipsis;      Panel->Caption = LoadStr(LOG_NOLOGFILE);    }    Caption = FMTLOAD(LOG_CAPTION, (SessionLog->SessionName));  }  else  {    Panel->TextTruncation = twEndEllipsis;    Panel->Caption = LoadStr(LOG_NOLOG);    Caption = LoadStr(LOG_NOLOGCAPTION);  }}//---------------------------------------------------------------------------void __fastcall TLogForm::CreateParams(TCreateParams & Params){  if (!FFormRestored)  {    FFormRestored = True;    DebugAssert(Configuration);    RestoreForm(WinConfiguration->LogWindowParams, this);  }  TForm::CreateParams(Params);  Params.WndParent = GetDesktopWindow();}//---------------------------------------------------------------------------void __fastcall TLogForm::SwitchSessionLog(){  SessionLog = LogMemo->SessionLog;}
 |