ttcalc/src/programresources.h

293 lines
5.9 KiB
C++

#ifndef headerfileprogramresources
#define headerfileprogramresources
/*!
\file programresources.h
\brief various kinds of objects using by the application
*/
#include <ttmath/ttmathobjects.h>
#include "iniparser.h"
#include "languages.h"
#include "threadcontroller.h"
#include <string>
#include <windows.h>
/*!
you don't have to create an object of this class but instead of it you can
get the pointer to the object by using 'GetPrgRes()'
(there'll be only one object of this type)
you must remember that some of these methods are used by the second thread as well
and when you want to change a state you must do it between calling
StopCalculating() and StartCalculating() in the main thread
for example if you want to change the precision of displaying you can do as follow:
(in the main thread)
GetPrgRes()->GetThreadController()->StopCalculating();
GetPrgRes()->SetPrecision( new_precision );
GetPrgRes()->GetThreadController()->StartCalculating();
methods which are used by the second thread:
GetBuffer(), GetVariables(), GetFunctions(), GetBaseInput(), GetBaseOutput()
GetDisplayAlwaysScientific(), GetDisplayWhenScientific(), GetDisplayRounding()
GetCurrentLanguage(), GetPrecision()
and if you're using methods which begin with Set..... you must call it
between StopCalculating() and StartCalculating()
*/
class ProgramResources
{
public:
/*!
types of the main window's view
view_normal - standard view with all controls on the dialog
view_compact - only the input and output edits are shown
*/
enum View
{
view_normal = 0, view_compact
};
/*!
position of the left top corner of the main window and its size
*/
void SetXPos(int x);
void SetYPos(int y);
int GetXPos();
int GetYPos();
void SetXSize(int x);
void SetYSize(int y);
int GetXSize();
int GetYSize();
/*!
size of the main window when 'normal view' is selected
*/
void SetYSizeNormal(int y);
int GetYSizeNormal();
/*!
size of the main window when 'compact view' is selected
*/
void SetYSizeCompact(int y);
int GetYSizeCompact();
/*!
minimum horizontal size of the main window
*/
void SetXSizeMin(int x);
int GetXSizeMin();
/*!
the kind of the view
*/
void SetView(View v);
View GetView();
/*!
maximizing of the main window
*/
void SetMaximized(bool max);
bool GetMaximized();
/*!
the main window is always on top or not
*/
void SetAlwaysOnTop(bool always);
bool GetAlwaysOnTop();
/*!
rounding of the calculation's result
*/
void SetDisplayRounding(int r);
int GetDisplayRounding();
/*!
displaying always scientific format
*/
void SetDisplayAlwaysScientific(bool a);
bool GetDisplayAlwaysScientific();
/*!
when scientific format will be used
(when the exponent of the result will be greater than w)
*/
void SetDisplayWhenScientific(int w);
int GetDisplayWhenScientific();
/*!
they sets the base of input and output values (2-16)
*/
void SetBaseInput(int i);
int GetBaseInput();
void SetBaseOutput(int i);
int GetBaseOutput();
/*!
the instance of the application
(the same as that one which was passed to the WinMain(...))
*/
void SetInstance(HINSTANCE h);
HINSTANCE GetInstance();
/*!
the main window of the application
*/
void SetMainWindow(HWND h);
HWND GetMainWindow();
/*!
handles to the dialogs which are placed on the tab control
*/
void SetTabWindow(unsigned int id, HWND h);
HWND GetTabWindow(unsigned int id);
unsigned int HowManyTabWindows();
/*!
the precision of our calculations (0-2)
0 - small
1 - medium
2 - big
*/
void SetPrecision(int p);
int GetPrecision();
/*!
the object which is used for synchronizing threads
*/
volatile ThreadController * GetThreadController();
/*!
pointers to variables' table, functions' table, the language's object
and to the characters' buffer
*/
ttmath::Objects * GetVariables();
ttmath::Objects * GetFunctions();
Languages * GetLanguages();
char * GetBuffer();
unsigned int GetBufferSize();
/*!
the constructor and destructor
*/
ProgramResources();
~ProgramResources();
/*!
it returns true if we're using windows nt/2000/xp etc.
*/
bool IsWindowsNt();
/*!
we're reading a particular text-value from windows' registry
if there'll be an error we don't change the output string 'result' and return 'false'
*/
bool ReadTextValueFromRegistry(HKEY main_key, const char * sub_key, const char * value, std::string & result);
/*!
we're trying to set the name of the configuration file of the program
if we run the application on windows 9x the file will be in the same
directory in which the program has been run
when we're using windows nt/2000/xp etc. the configuration file
will be in a special directory for a particular user, for example:
"C:\Documents and Settings\user\applitacion data"
*/
void SetNameOfConfigurationFile();
/*!
reading and writing to a file
*/
IniParser::Error ReadFromFile();
void SaveToFile();
/*!
it returns a number of line where there was an error
during last parsing
*/
int GetBadLine();
private:
bool IsWhiteCharacter(int c);
const char * SkipWhiteCharacters(const char * string);
bool IsDecDigit(int c);
bool SplitFunction(const std::string & input, const char * * name, int * param);
ttmath::Objects variables;
ttmath::Objects functions;
Languages languages;
volatile ThreadController thread_controller;
unsigned int buffer_size;
char * buffer;
HINSTANCE hInstance;
HWND main_window;
HWND tab_window[5];
int precision;
bool always_on_top;
bool maximized;
View view;
std::string configuration_file;
int y_size_normal;
int y_size_compact;
int x_size_min;
int x_pos;
int y_pos;
int x_size;
int y_size;
int base_input;
int base_output;
bool display_always_scientific;
int display_when_scientific;
int display_rounding;
int bad_line;
};
/*!
a global function which returns the pointer to the object of ProgramResource's type
(there's only one object of this type)
*/
ProgramResources * GetPrgRes();
#endif