//----------------------------------------------------------------------------//
//    module: FGuiOptions.cpp                                                 //
//                                                                            //
//    Options dialog for Gui specific settings - directly saves to registry   //
//                                                                            //
//    copyright (c) 2003 by Lars Haendel                                      //
//    home: www.newty.de                                                      //
//                                                                            //
//    This program is free software and can be used under the terms of the    //
//    GNU licence. See header file for further information and disclaimer.    //
//                                                                            //
//----------------------------------------------------------------------------//


#include <vcl.h>
#pragma hdrstop

#include "FGuiOptions.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

#include <Registry.hpp>       // due to:  TRegistry
#include <htmlhelp>           //          HTML help

#include "defines.h"          //          ComChar, global comment character
#include "FMain.h"            //          SZ_REGISTRY_KEY and globals




TFGuiOptions *FGuiOptions;
//----------------------------------------------------------------------------------------------------------------------
// constructor
__fastcall TFGuiOptions::TFGuiOptions(TComponent* Owner) : TForm(Owner){}


//----------------------------------------------------------------------------------------------------------------------
// show form
void __fastcall TFGuiOptions::FormShow(TObject *Sender)
{
   ActComChar();                                      // initialize drop down list ...
   CbDisableWarnings ->Checked = f_DisableWarnings;   // ... and check boxes
   CbDisableQuestions->Checked = f_DisableQuestions;

   ActiveControl = BtOk;                              // set focus on button 'Ok'
}


//----------------------------------------------------------------------------------------------------------------------
// button 'Ok' clicked: close dialog
void __fastcall TFGuiOptions::BtOkClick(TObject *Sender){ Close(); }


//----------------------------------------------------------------------------------------------------------------------
// initialize drop down list according to project comment character
void TFGuiOptions::ActComChar()
{
   // set comment character in drop down list. Hard coded, thus be sure to have the correct order of the comment
   // characters in property 'Items' - not really good style, I know, but it should do :-|
   if(ComChar=='#') DlComChar->ItemIndex = 0;
   if(ComChar=='*') DlComChar->ItemIndex = 1;
   if(ComChar=='%') DlComChar->ItemIndex = 2;
}


//----------------------------------------------------------------------------------------------------------------------
// comment character changed: write trough to global and registry
void __fastcall TFGuiOptions::DlComCharChange(TObject *Sender)
{
   ComChar = DlComChar->Text[1];                     // set global(!) comment character

   // open registry key creating it if it does not exist, note: only used for writing
   TRegistry* registry = new TRegistry;
   registry->OpenKey(SZ_REGISTRY_KEY, true);
   registry->WriteString(SZ_COM_CHAR, ComChar);                       // write to registry
   registry->CloseKey();                                              // close key
   delete registry;
}


//----------------------------------------------------------------------------------------------------------------------
// flag changed: write trough to f_DisableWarnings and registry
void __fastcall TFGuiOptions::CbDisableWarningsClick(TObject *Sender)
{
   f_DisableWarnings = CbDisableWarnings->Checked;                    // write trough

   // open registry key creating it if it does not exist, note: only used for writing
   TRegistry* registry = new TRegistry;
   registry->OpenKey(SZ_REGISTRY_KEY, true);
   registry->WriteBool(SZ_DISABLE_WARNINGS, f_DisableWarnings);       // write to registry
   registry->CloseKey();                                              // close key
   delete registry;
}


//----------------------------------------------------------------------------------------------------------------------
// flag changed: write trough to f_DisableQuestions and registry
void __fastcall TFGuiOptions::CbDisableQuestionsClick(TObject *Sender)
{
   f_DisableQuestions = CbDisableQuestions->Checked;                  // write trough

   // open registry key creating it if it does not exist, note: only used for writing
   TRegistry* registry = new TRegistry;
   registry->OpenKey(SZ_REGISTRY_KEY, true);
   registry->WriteBool(SZ_DISABLE_QUESTIONS, f_DisableQuestions);     // write to registry
   registry->CloseKey();                                              // close key
   delete registry;
}


//----------------------------------------------------------------------------------------------------------------------
// close all help windows
void __fastcall TFGuiOptions::FormClose(TObject*, TCloseAction&){ /* HtmlHelp(0, 0, HH_CLOSE_ALL, 0); */}