Browse Source

fixed: when the program starts the main window was not maximized correctly

(when it should be maximized)
added: pad window is saving its position and size to the config file


git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@212 e52654a7-88a9-db11-a3e9-0013d4bc506e
master
Tomasz Sowa 13 years ago
parent
commit
59d24bf3ae
  1. 8
      src/mainwindow.cpp
  2. 73
      src/pad.cpp
  3. 2
      src/pad.h
  4. 164
      src/programresources.cpp
  5. 28
      src/programresources.h
  6. 13
      src/winmain.cpp

8
src/mainwindow.cpp

@ -590,11 +590,8 @@ HWND hTab = GetDlgItem(hWnd,IDC_TAB);
SendMessage(hWnd,WM_SETICON,ICON_BIG,(LPARAM)program_icon);
GetPrgRes()->SetAlwaysOnTop( GetPrgRes()->GetAlwaysOnTop() );
GetPrgRes()->SetMaximized ( GetPrgRes()->GetMaximized() );
GetPrgRes()->SetView ( GetPrgRes()->GetView() );
ShowWindow(hWnd,SW_SHOW);
SendDlgItemMessage(hWnd,IDC_INPUT_EDIT,EM_SETLIMITTEXT,GetPrgRes()->GetBufferSize()-1,0);
SetMenuLanguage(hWnd);
@ -735,7 +732,8 @@ POINT p;
TabWindowFunctions::SetSizeOfFunctionsList(tab, cx, cy-p.y, borderx, bordery);
TabWindowFunctions::SetSizeOfConvertingLists(tab, cx, cy-p.y, borderx, bordery);
if( fwSizeType != SIZE_MINIMIZED && GetPrgRes()->GetView() != ProgramResources::view_compact )
if( fwSizeType != SIZE_MINIMIZED && fwSizeType != SIZE_MAXIMIZED &&
GetPrgRes()->GetView() != ProgramResources::view_compact )
{
GetWindowRect(hWnd,&r);
GetPrgRes()->SetXSize( r.right - r.left );
@ -903,7 +901,7 @@ return true;
BOOL WmCommand_Pad(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
GetPrgRes()->TurnPad();
GetPrgRes()->ShowPad( !GetPrgRes()->IsPadVisible() );
return true;
}

73
src/pad.cpp

@ -49,6 +49,7 @@ HWND edit;
WNDPROC old_edit_proc;
std::string parse_string;
int precision;
HFONT font;
int base_input;
int base_output;
@ -334,19 +335,59 @@ LRESULT PadCreate(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
0, 0, 100, 100, hwnd, 0, GetPrgRes()->GetInstance(), 0);
if( !edit )
return 0;
old_edit_proc = (WNDPROC)SetWindowLong(edit, GWL_WNDPROC, (LONG)EditSubclass);
return 0;
// 65535 - 64KB
// we're using some kind of messages which operates only on 64KB
SendMessage(edit, EM_SETLIMITTEXT, 65535 - 5, 0);
if( font != 0 )
SendMessage(edit, WM_SETFONT, (WPARAM)font, 0);
return 0;
}
LRESULT PadMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT r;
GetWindowRect(hwnd,&r);
GetPrgRes()->SetPadXPos( r.left );
GetPrgRes()->SetPadYPos( r.top );
return 0;
}
LRESULT PadSize(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// client coordinates
int cx = LOWORD(lParam);
int cy = HIWORD(lParam);
int fwSizeType = int(wParam);
RECT r;
if( fwSizeType == SIZE_MAXIMIZED )
GetPrgRes()->SetPadMaximized(true);
else
if( fwSizeType == SIZE_RESTORED )
GetPrgRes()->SetPadMaximized(false);
MoveWindow(edit, 0, 0, cx, cy, true);
if( fwSizeType != SIZE_MINIMIZED && fwSizeType != SIZE_MAXIMIZED )
{
GetWindowRect(hwnd, &r);
GetPrgRes()->SetPadXSize( r.right - r.left );
GetPrgRes()->SetPadYSize( r.bottom - r.top );
}
return 0;
}
@ -354,7 +395,7 @@ return 0;
LRESULT PadClose(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
GetPrgRes()->TurnPad();
GetPrgRes()->ShowPad( false );
return 0;
}
@ -371,6 +412,7 @@ return 0;
void CreatePadMessagesTable(Messages<LRESULT> & messages)
{
messages.Associate(WM_CREATE, PadCreate);
messages.Associate(WM_MOVE, PadMove);
messages.Associate(WM_SIZE, PadSize);
messages.Associate(WM_CLOSE, PadClose);
messages.Associate(WM_SETFOCUS, PadFocus);
@ -427,26 +469,39 @@ bool CreatePadWindow()
using namespace Pad;
static char ttcalc_pad_class_name[] = "TTCalcPadWindow";
ATOM a = RegisterPadClass(ttcalc_pad_class_name);
if( a == 0 )
return false;
bool pad_maximized_from_file = GetPrgRes()->GetPadMaximized();
// CreateWindow() would change maximizing
font = CreateFont(0, 0, 0, 0, FW_NORMAL, false, false, false,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH, "Ms Shell Dlg");
HWND pad = CreateWindowEx(0, ttcalc_pad_class_name,
"Pad",
WS_OVERLAPPEDWINDOW | WS_POPUPWINDOW ,
100, 100,
600, 450,
GetPrgRes()->GetMainWindow(), 0, GetPrgRes()->GetInstance(), 0);
GetPrgRes()->GetPadXPos(), GetPrgRes()->GetPadYPos(),
GetPrgRes()->GetPadXSize(), GetPrgRes()->GetPadYSize(),
0 /*GetPrgRes()->GetMainWindow()*/, 0, GetPrgRes()->GetInstance(), 0);
GetPrgRes()->SetPadWindow(pad);
GetPrgRes()->SetPadMaximized( pad_maximized_from_file );
GetPrgRes()->ShowPad( GetPrgRes()->IsPadVisible() );
return pad != 0;
return pad!=0 && edit!=0;
}
void DestroyPadWindow()
{
using namespace Pad;
DeleteObject(font);
}

2
src/pad.h

@ -41,7 +41,7 @@
bool CreatePadWindow();
void DestroyPadWindow();
#endif

164
src/programresources.cpp

@ -100,6 +100,50 @@ int ProgramResources::GetYSize()
return y_size;
}
void ProgramResources::SetPadXPos(int x)
{
pad_x_pos = x;
}
void ProgramResources::SetPadYPos(int y)
{
pad_y_pos = y;
}
int ProgramResources::GetPadXPos()
{
return pad_x_pos;
}
int ProgramResources::GetPadYPos()
{
return pad_y_pos;
}
void ProgramResources::SetPadXSize(int x)
{
pad_x_size = x;
}
void ProgramResources::SetPadYSize(int y)
{
pad_y_size = y;
}
int ProgramResources::GetPadXSize()
{
return pad_x_size;
}
int ProgramResources::GetPadYSize()
{
return pad_y_size;
}
void ProgramResources::SetYSizeNormal(int y)
{
y_size_normal = y;
@ -151,11 +195,6 @@ ProgramResources::View ProgramResources::GetView()
void ProgramResources::SetMaximized(bool max)
{
maximized = max;
if( maximized )
ShowWindow(main_window, SW_SHOWMAXIMIZED);
else
ShowWindow(main_window, SW_SHOWNORMAL);
}
@ -164,6 +203,42 @@ bool ProgramResources::GetMaximized()
return maximized;
}
void ProgramResources::SetPadMaximized(bool max)
{
pad_maximized = max;
}
bool ProgramResources::GetPadMaximized()
{
return pad_maximized;
}
void ProgramResources::ShowPad(bool show)
{
show_pad = show;
if( show_pad )
{
if( pad_maximized )
ShowWindow(pad_window, SW_SHOWMAXIMIZED);
else
ShowWindow(pad_window, SW_SHOWNORMAL);
}
else
{
ShowWindow(pad_window, SW_HIDE);
}
}
bool ProgramResources::IsPadVisible()
{
return show_pad;
}
void ProgramResources::SetAlwaysOnTop(bool always)
{
always_on_top = always;
@ -440,26 +515,6 @@ int ProgramResources::GetPrecision()
void ProgramResources::TurnPad()
{
show_pad = !show_pad;
if( show_pad )
{
ShowWindow(pad_window, SW_SHOW);
}
else
{
ShowWindow(pad_window, SW_HIDE);
}
}
bool ProgramResources::IsPadVisible()
{
return show_pad;
}
ProgramResources::ProgramResources()
{
// if you want to change the input buffer you have also to change
@ -496,6 +551,12 @@ ProgramResources::ProgramResources()
x_size = 100;
y_size = 100;
pad_x_pos = 30;
pad_y_pos = 30;
pad_x_size = 600;
pad_y_size = 500;
pad_maximized = false;
y_size_normal = 0;
y_size_compact = 0;
x_size_min = 0;
@ -696,6 +757,35 @@ void ProgramResources::CheckCoordinates()
y_pos = cy - y_size;
}
void ProgramResources::CheckPadCoordinates()
{
if( pad_x_pos < -50 )
pad_x_pos = 0;
if( pad_y_pos < -50 )
pad_y_pos = 0;
if( pad_x_size < 30 )
pad_x_size = 600;
if( pad_y_size < 30 )
pad_y_size = 500;
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
if( pad_x_size > cx+10 )
pad_x_size = cx;
if( pad_y_size > cy+10 )
pad_y_size = cy;
if( pad_x_pos > cx-50 )
pad_x_pos = cx - pad_x_size;
if( pad_y_pos > cy-50 )
pad_y_pos = cy - pad_y_size;
}
void ProgramResources::AddVariablesFunctions( IniParser::Section & temp_variables,
@ -778,7 +868,7 @@ IniParser::Error ProgramResources::ReadFromFile()
IniParser iparser;
IniParser::Section temp_variables, temp_functions;
IniParser::Section::iterator ic;
std::string ini_value[20];
std::string ini_value[30];
iparser.ConvertValueToSmallLetters(false);
iparser.SectionCaseSensitive(false);
@ -803,6 +893,12 @@ std::string ini_value[20];
iparser.Associate( "global|disp.dec.point", &ini_value[14] );
iparser.Associate( "global|disp.remove.zeroes", &ini_value[15] );
iparser.Associate( "global|disp.deg_rad_grad", &ini_value[16] );
iparser.Associate( "global|pad.x", &ini_value[17] );
iparser.Associate( "global|pad.y", &ini_value[18] );
iparser.Associate( "global|pad.size.x", &ini_value[19] );
iparser.Associate( "global|pad.size.y", &ini_value[20] );
iparser.Associate( "global|pad.maximized", &ini_value[21] );
iparser.Associate( "global|pad", &ini_value[22] );
iparser.Associate( "variables", &temp_variables );
iparser.Associate( "functions", &temp_functions );
@ -858,6 +954,14 @@ std::string ini_value[20];
SetDecimalPoint( atoi(ini_value[14].c_str()) );
SetDegRadGrad( atoi(ini_value[16].c_str()) );
pad_x_pos = atoi( ini_value[17].c_str() );
pad_y_pos = atoi( ini_value[18].c_str() );
pad_x_size = atoi( ini_value[19].c_str() );
pad_y_size = atoi( ini_value[20].c_str() );
pad_maximized = bool( atoi(ini_value[21].c_str()) );
show_pad = bool( atoi(ini_value[22].c_str()) );
CheckPadCoordinates();
if( err != IniParser::err_ok )
bad_line = iparser.GetBadLine();
@ -878,11 +982,17 @@ std::ofstream file( configuration_file.c_str() );
file << "always.on.top = " << (int)always_on_top << std::endl;
file << "view = " << (int)view << std::endl;
file << "maximized = " << (int)maximized << std::endl;
file << "x = " << x_pos << std::endl;
file << "y = " << y_pos << std::endl;
file << "size.x = " << x_size << std::endl;
file << "size.y = " << y_size << std::endl;
file << "maximized = " << (int)maximized << std::endl;
file << "pad = " << (int)show_pad << std::endl;
file << "pad.x = " << pad_x_pos << std::endl;
file << "pad.y = " << pad_y_pos << std::endl;
file << "pad.size.x = " << pad_x_size << std::endl;
file << "pad.size.y = " << pad_y_size << std::endl;
file << "pad.maximized = " << (int)pad_maximized << std::endl;
file << "precision = " << precision << std::endl;
file << "disp.input = " << base_input << std::endl;
file << "disp.output = " << base_output << std::endl;

28
src/programresources.h

@ -111,6 +111,19 @@ public:
int GetYSize();
/*!
position of the left top corner of the pad window and its size
*/
void SetPadXPos(int x);
void SetPadYPos(int y);
int GetPadXPos();
int GetPadYPos();
void SetPadXSize(int x);
void SetPadYSize(int y);
int GetPadXSize();
int GetPadYSize();
/*!
size of the main window when 'normal view' is selected
*/
@ -146,6 +159,12 @@ public:
bool GetMaximized();
/*!
maximizing of the pad window
*/
void SetPadMaximized(bool max);
bool GetPadMaximized();
/*!
the main window is always on top or not
*/
@ -347,7 +366,7 @@ public:
/*!
is the pad window is visible then the method hides it (and vice versa)
*/
void TurnPad();
void ShowPad(bool show);
/*!
@ -363,6 +382,7 @@ private:
bool IsDecDigit(int c);
bool SplitFunction(const std::string & input, const char * * name, int * param);
void CheckCoordinates();
void CheckPadCoordinates();
void AddVariablesFunctions(IniParser::Section & temp_variables, IniParser::Section & temp_functions, bool if_not_exist);
@ -399,6 +419,12 @@ private:
int x_size;
int y_size;
int pad_x_pos;
int pad_y_pos;
int pad_x_size;
int pad_y_size;
int pad_maximized;
int base_input;
int base_output;

13
src/winmain.cpp

@ -77,11 +77,23 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
if( (thread_handle = _beginthreadex(0,0,CalculationsProcedure, 0, 0, &thread_id)) == 0 )
return ShowError( Languages::cant_create_thread );
bool maximized_from_file = GetPrgRes()->GetMaximized();
CreateDialog( hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), 0, MainWindowProc);
if( !GetPrgRes()->GetMainWindow() )
return ShowError( Languages::cant_create_main_window );
if( maximized_from_file )
{
GetPrgRes()->SetMaximized(true);
ShowWindow(GetPrgRes()->GetMainWindow(), SW_SHOWMAXIMIZED);
}
else
{
GetPrgRes()->SetMaximized(false);
ShowWindow(GetPrgRes()->GetMainWindow(), SW_SHOWNORMAL);
}
if( !CreatePadWindow() )
return ShowError( Languages::cant_create_pad );
@ -93,6 +105,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
GetPrgRes()->ReadVariablesFunctionsFromFile();
GetPrgRes()->SaveToFile();
DestroyPadWindow();
CloseHandle( (HANDLE)thread_handle );
return 0;

Loading…
Cancel
Save