382 lines
8.5 KiB
C++
382 lines
8.5 KiB
C++
/*
|
|
* This file is a part of TTCalc - a mathematical calculator
|
|
* and is distributed under the (new) BSD licence.
|
|
* Author: Tomasz Sowa <t.sowa@slimaczek.pl>
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2006-2007, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
|
* project may be used to endorse or promote products derived
|
|
* from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#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 <vector>
|
|
#include <cstdlib>
|
|
#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 a line where there was an error
|
|
during last parsing
|
|
*/
|
|
int GetBadLine();
|
|
|
|
/*!
|
|
setting and returning the decimal point used during printig values
|
|
0 - '.'
|
|
1 - ','
|
|
*/
|
|
void SetDecimalPoint(int decimal);
|
|
int GetDecimalPoint();
|
|
|
|
|
|
/*!
|
|
setting and returning the state of removing trailing zeroes
|
|
(used during printing values)
|
|
*/
|
|
void SetRemovingZeroes(bool r);
|
|
bool GetRemovingZeroes();
|
|
|
|
|
|
/*!
|
|
these methods set and return the kind of conversion which should be performed
|
|
|
|
0 - none
|
|
1 - ...
|
|
2 - ...
|
|
*/
|
|
void SetConvType(int c);
|
|
int GetConvType();
|
|
|
|
void SetConvUnit(int c, int input, int output);
|
|
bool GetConvUnit(int c, int & input, int & output);
|
|
|
|
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);
|
|
void CheckCoordinates();
|
|
|
|
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[6];
|
|
|
|
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;
|
|
|
|
int decimal_point;
|
|
|
|
bool display_always_scientific;
|
|
int display_when_scientific;
|
|
int display_rounding;
|
|
bool remove_zeroes;
|
|
|
|
int bad_line;
|
|
|
|
int conv_type;
|
|
|
|
struct ConvUnit
|
|
{
|
|
int input, output;
|
|
|
|
ConvUnit()
|
|
{
|
|
input = output = -1;
|
|
}
|
|
};
|
|
|
|
std::vector<ConvUnit> conv_unit;
|
|
|
|
void ConvUnitCheck(int type);
|
|
void ConvUnitCheckAll();
|
|
};
|
|
|
|
|
|
/*!
|
|
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
|