2007-02-08 18:54:37 +01:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2009-04-01 04:31:38 +02:00
|
|
|
* Copyright (c) 2006-2009, Tomasz Sowa
|
2007-02-08 18:54:37 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-01-22 12:12:01 +01:00
|
|
|
#include "compileconfig.h"
|
|
|
|
#include "winmain.h"
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\file mainwin.cpp
|
2007-06-24 22:11:14 +02:00
|
|
|
\brief There's defined the entry point to the application in this file
|
2007-01-22 12:12:01 +01:00
|
|
|
*/
|
|
|
|
|
2007-02-08 18:54:37 +01:00
|
|
|
#include <string>
|
2009-09-08 03:24:56 +02:00
|
|
|
#include <ttmath/ttmath.h>
|
2007-02-08 18:54:37 +01:00
|
|
|
|
2007-01-22 12:12:01 +01:00
|
|
|
|
|
|
|
/*!
|
2008-10-13 06:17:57 +02:00
|
|
|
the application starts here
|
2007-01-22 12:12:01 +01:00
|
|
|
*/
|
|
|
|
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
|
|
|
|
{
|
|
|
|
GetPrgRes()->SetInstance(hInstance);
|
2007-11-04 22:56:55 +01:00
|
|
|
|
|
|
|
// we're using GetLanguages() simultaneously in two threads, this is to be sure
|
|
|
|
// that everything is initialized before the second thread is started
|
|
|
|
GetPrgRes()->GetLanguages()->InitAll();
|
2007-01-22 12:12:01 +01:00
|
|
|
GetPrgRes()->GetLanguages()->SetCurrentLanguage(Languages::en);
|
2008-10-13 06:17:57 +02:00
|
|
|
//GetPrgRes()->GetConvert()->Init();
|
2007-01-22 12:12:01 +01:00
|
|
|
GetPrgRes()->SetNameOfConfigurationFile();
|
|
|
|
GetPrgRes()->ReadFromFile();
|
2007-09-18 22:08:47 +02:00
|
|
|
|
2007-01-22 12:12:01 +01:00
|
|
|
INITCOMMONCONTROLSEX common_ctrl;
|
|
|
|
common_ctrl.dwSize = sizeof(common_ctrl);
|
|
|
|
common_ctrl.dwICC = ICC_WIN95_CLASSES;
|
|
|
|
|
|
|
|
if( !InitCommonControlsEx(&common_ctrl) )
|
|
|
|
return ShowError( Languages::cant_init_common_controls );
|
|
|
|
|
|
|
|
if( !GetPrgRes()->GetThreadController()->Init() )
|
|
|
|
return ShowError( Languages::cant_init_calculations );
|
|
|
|
|
2009-03-28 19:26:20 +01:00
|
|
|
unsigned int thread_id;
|
2007-01-22 12:12:01 +01:00
|
|
|
uintptr_t thread_handle;
|
|
|
|
if( (thread_handle = _beginthreadex(0,0,CalculationsProcedure, 0, 0, &thread_id)) == 0 )
|
|
|
|
return ShowError( Languages::cant_create_thread );
|
|
|
|
|
2009-10-16 04:12:10 +02:00
|
|
|
bool maximized_from_file = GetPrgRes()->GetMaximized();
|
2007-01-22 12:12:01 +01:00
|
|
|
CreateDialog( hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), 0, MainWindowProc);
|
|
|
|
|
|
|
|
if( !GetPrgRes()->GetMainWindow() )
|
|
|
|
return ShowError( Languages::cant_create_main_window );
|
|
|
|
|
2009-10-16 04:12:10 +02:00
|
|
|
if( maximized_from_file )
|
|
|
|
{
|
|
|
|
GetPrgRes()->SetMaximized(true);
|
|
|
|
ShowWindow(GetPrgRes()->GetMainWindow(), SW_SHOWMAXIMIZED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetPrgRes()->SetMaximized(false);
|
|
|
|
ShowWindow(GetPrgRes()->GetMainWindow(), SW_SHOWNORMAL);
|
|
|
|
}
|
|
|
|
|
2009-10-14 00:41:00 +02:00
|
|
|
if( !CreatePadWindow() )
|
|
|
|
return ShowError( Languages::cant_create_pad );
|
|
|
|
|
2007-01-22 12:12:01 +01:00
|
|
|
// there's the main loop of messages here
|
|
|
|
MainMessagesLoop();
|
|
|
|
|
2009-04-01 04:31:38 +02:00
|
|
|
// there can be another variables/functions saved by other instantion of TTCalc
|
|
|
|
// we're reading them now
|
|
|
|
GetPrgRes()->ReadVariablesFunctionsFromFile();
|
|
|
|
|
2007-01-22 12:12:01 +01:00
|
|
|
GetPrgRes()->SaveToFile();
|
2009-10-16 04:12:10 +02:00
|
|
|
DestroyPadWindow();
|
2007-01-22 12:12:01 +01:00
|
|
|
CloseHandle( (HANDLE)thread_handle );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
it displays a message box with an error
|
|
|
|
(it's only used during initiation)
|
|
|
|
*/
|
|
|
|
int ShowError( Languages::GuiMsg error_code )
|
|
|
|
{
|
|
|
|
MessageBox(0, GetPrgRes()->GetLanguages()->GuiMessage( error_code ),
|
|
|
|
GetPrgRes()->GetLanguages()->GuiMessage( Languages::message_box_error_caption ),
|
|
|
|
MB_ICONERROR);
|
|
|
|
|
|
|
|
return static_cast<int>( error_code );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-08 18:54:37 +01:00
|
|
|
|
2007-08-05 22:31:46 +02:00
|
|
|
|
2007-01-22 12:12:01 +01:00
|
|
|
/*!
|
|
|
|
the main loop of messages
|
|
|
|
*/
|
|
|
|
void MainMessagesLoop()
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
while( GetMessage(&msg,0,0,0) )
|
|
|
|
{
|
2007-08-05 22:31:46 +02:00
|
|
|
bool sent = false;
|
|
|
|
|
|
|
|
// if there's CTRL+C or CTRL+V pressed we're trying to copy
|
|
|
|
// a result from the output edit or trying to paste something from the clipboard
|
|
|
|
if( msg.message==WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0xff00)!=0 )
|
|
|
|
{
|
|
|
|
if( msg.wParam == 'C' )
|
|
|
|
{
|
|
|
|
if( MainWindowFunctions::CopyResult() )
|
|
|
|
sent = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( msg.wParam == 'V' )
|
|
|
|
{
|
|
|
|
if( MainWindowFunctions::Paste() )
|
|
|
|
sent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 12:12:01 +01:00
|
|
|
|
2007-03-08 20:15:55 +01:00
|
|
|
// we give our own special function for navigating from the keyboard
|
|
|
|
// if our function returns false then we use a standard navigation
|
|
|
|
// from the system
|
2007-08-05 22:31:46 +02:00
|
|
|
if( !sent && msg.message == WM_KEYDOWN &&
|
added: a user can change the names of variables or functions now
changed: the program uses TTMath 0.8.0 now
added: functions: from TTMath 0.8.0:
DegToDeg(deg, min, sec), DegToRad(deg), DegToRad(deg, min, sec),
RadToDeg(rad), Ceil(x), Floor(x), Sqrt(x), Sinh(x), Cosh(x),
Tanh(x) /Tgh(x)/, Coth(x) /Ctgh(x)/
added: a help
changed: from TTMath 0.8.0:
renamed: CTan() into Cot() or Ctg()
renamed: ACTan() into ACot() or ACtg()
Factorial() has a history log now (it can remember last
10 calculated values)
added: a directory 'help' with files of the help
added: a directory 'setup' with files needed to make an installer
(we're using InnoSetup Compiler to make it)
fixed: the vertical size of the main window when a user uses a different size
of the window caption (especially under the Windows XP Luna)
fixed: on Windows 9x: the program hung when a user clicks on a control
on the first tab (the procedure SetNextFocus(...) has been completely
rewritten and the flag WS_EX_CONTROLPARENT on the tab dialogs has
gone away)
fixed: when started navigating from the keyboard the program showed a wrong
variable or a funtion in the edit dialog
git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@28 e52654a7-88a9-db11-a3e9-0013d4bc506e
2007-04-02 02:17:26 +02:00
|
|
|
( msg.wParam == VK_TAB ||
|
2007-03-08 20:15:55 +01:00
|
|
|
msg.wParam == VK_DOWN || msg.wParam == VK_UP ||
|
|
|
|
msg.wParam == VK_LEFT || msg.wParam == VK_DOWN ) )
|
|
|
|
|
2007-02-08 18:54:37 +01:00
|
|
|
{
|
2007-03-08 20:15:55 +01:00
|
|
|
if( MainWindowFunctions::SetNextFocus(msg.wParam) )
|
2007-08-05 22:31:46 +02:00
|
|
|
sent = true;
|
2007-02-08 18:54:37 +01:00
|
|
|
}
|
|
|
|
|
2007-03-08 20:15:55 +01:00
|
|
|
|
2007-01-22 12:12:01 +01:00
|
|
|
// firt we try to send our message to dialogs
|
|
|
|
// (the dialogs on the tab control)
|
2007-08-05 22:31:46 +02:00
|
|
|
if( !sent )
|
2007-01-22 12:12:01 +01:00
|
|
|
{
|
2007-08-05 22:31:46 +02:00
|
|
|
for(unsigned int i=0 ; i<GetPrgRes()->HowManyTabWindows() && !sent ; ++i)
|
2007-02-08 18:54:37 +01:00
|
|
|
{
|
|
|
|
if( IsDialogMessage(GetPrgRes()->GetTabWindow(i), &msg) )
|
2007-08-05 22:31:46 +02:00
|
|
|
sent = true;
|
2007-02-08 18:54:37 +01:00
|
|
|
}
|
2007-01-22 12:12:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// if it's not a message to any of our dialogs we send it
|
|
|
|
// to the main window (it's a dialog as well)
|
2007-08-05 22:31:46 +02:00
|
|
|
if( !sent )
|
2007-01-22 12:12:01 +01:00
|
|
|
{
|
|
|
|
if( !IsDialogMessage(GetPrgRes()->GetMainWindow(), &msg) )
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
the window-procedure for the main window
|
|
|
|
*/
|
|
|
|
BOOL CALLBACK MainWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2009-10-14 00:41:00 +02:00
|
|
|
static Messages<BOOL> messages;
|
2007-01-22 12:12:01 +01:00
|
|
|
|
|
|
|
if( messages.Empty() )
|
|
|
|
// initiation
|
|
|
|
MainWindowFunctions::CreateMainMessagesTable(messages);
|
|
|
|
|
|
|
|
// in the Messages class we're using the std::map
|
|
|
|
// so that we have the logarythmic time to find the special function to call
|
|
|
|
return messages.Call(message, hWnd, message, wParam, lParam);
|
|
|
|
}
|
2009-09-08 03:24:56 +02:00
|
|
|
|
|
|
|
|