352 lines
11 KiB
C++
352 lines
11 KiB
C++
#include <aladin/divedlg.hpp>
|
|
#include <aladin/aladinrc.hpp>
|
|
#include <aladin/aladin.hpp>
|
|
#include <aladin/serdlg.hpp>
|
|
#include <aladin/graph.hpp>
|
|
#include <aladin/appreg.hpp>
|
|
#include <aladin/splash.hpp>
|
|
#include <common/odlstalt.hpp>
|
|
#include <common/block.hpp>
|
|
#include <common/puredwrd.hpp>
|
|
#include <common/opendlg.hpp>
|
|
#include <common/puremenu.hpp>
|
|
#include <common/regkey.hpp>
|
|
#include <common/process.hpp>
|
|
|
|
DiveDlg::DiveDlg(void)
|
|
{
|
|
mInitHandler.setCallback(this,&DiveDlg::initHandler);
|
|
mCreateHandler.setCallback(this,&DiveDlg::createHandler);
|
|
mCloseHandler.setCallback(this,&DiveDlg::closeHandler);
|
|
mDestroyHandler.setCallback(this,&DiveDlg::destroyHandler);
|
|
mCommandHandler.setCallback(this,&DiveDlg::commandHandler);
|
|
insertHandler(VectorHandler::InitDialogHandler,&mInitHandler);
|
|
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
|
insertHandler(VectorHandler::CloseHandler,&mCloseHandler);
|
|
insertHandler(VectorHandler::CommandHandler,&mCommandHandler);
|
|
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
|
}
|
|
|
|
DiveDlg::DiveDlg(const DiveDlg &someDiveDlg)
|
|
{ // private implementation
|
|
*this=someDiveDlg;
|
|
}
|
|
|
|
DiveDlg::~DiveDlg()
|
|
{
|
|
removeHandler(VectorHandler::InitDialogHandler,&mInitHandler);
|
|
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
|
removeHandler(VectorHandler::CloseHandler,&mCloseHandler);
|
|
removeHandler(VectorHandler::CommandHandler,&mCommandHandler);
|
|
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
|
}
|
|
|
|
DiveDlg &DiveDlg::operator=(const DiveDlg &someDiveDlg)
|
|
{
|
|
return *this;
|
|
}
|
|
|
|
bool DiveDlg::perform(void)
|
|
{
|
|
return ::DialogBoxParam(processInstance(),(LPSTR)"DIVEBOOK",(HWND)0,DWindow::DlgProc,(LPARAM)(DWindow*)this);
|
|
}
|
|
|
|
CallbackData::ReturnType DiveDlg::initHandler(CallbackData &someCallbackData)
|
|
{
|
|
String strClass;
|
|
|
|
::GetClassName(*this,strClass,String::MaxString);
|
|
::SetClassLong(*this,GCL_HICON,(LONG)::LoadIcon(processInstance(),"APPICON"));
|
|
PureMenu windowMenu(::GetMenu(*this));
|
|
windowMenu.getSubMenu(0,windowMenu);
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVEWORKSHEET,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemDisabled|PureMenu::ItemGrayed));
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVERAW,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemDisabled|PureMenu::ItemGrayed));
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVETEXT,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemDisabled|PureMenu::ItemGrayed));
|
|
mOwnerDrawGraph=new OwnerDrawGraph(*this,getItem(DB_GRAPH),DB_GRAPH);
|
|
mOwnerDrawGraph.disposition(PointerDisposition::Delete);
|
|
setCaption(String(STRING_APPNAME)+String(" ")+String(STRING_VERSION));
|
|
Block<PureDWORD> logStopArray;
|
|
Block<PureDWORD> profileStopArray;
|
|
mLogList=new OwnerDrawListAltColor(*this,getItem(DB_LOGLIST),DB_LOGLIST);
|
|
mLogList.disposition(PointerDisposition::Delete);
|
|
mProfileList=new OwnerDrawListAltColor(*this,getItem(DB_PFLIST),DB_PFLIST);
|
|
mProfileList.disposition(PointerDisposition::Delete);
|
|
logStopArray.insert(&PureDWORD(50));
|
|
logStopArray.insert(&PureDWORD(70));
|
|
logStopArray.insert(&PureDWORD(92));
|
|
logStopArray.insert(&PureDWORD(112));
|
|
logStopArray.insert(&PureDWORD(130));
|
|
mLogList->setTabStops(logStopArray);
|
|
profileStopArray.insert(&PureDWORD(5));
|
|
profileStopArray.insert(&PureDWORD(25));
|
|
profileStopArray.insert(&PureDWORD(50));
|
|
mProfileList->setTabStops(profileStopArray);
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType DiveDlg::createHandler(CallbackData &someCallbackData)
|
|
{
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType DiveDlg::closeHandler(CallbackData &someCallbackData)
|
|
{
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType DiveDlg::destroyHandler(CallbackData &someCallbackData)
|
|
{
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType DiveDlg::commandHandler(CallbackData &someCallbackData)
|
|
{
|
|
switch(someCallbackData.wmCommandID())
|
|
{
|
|
case APPMENU_FILE_EXIT :
|
|
case IDCANCEL :
|
|
handleCancel();
|
|
break;
|
|
case APPMENU_FILE_OPEN :
|
|
handleFileOpen();
|
|
break;
|
|
case APPMENU_FILE_IMPORT :
|
|
handleImport();
|
|
break;
|
|
case APPMENU_FILE_SAVEWORKSHEET :
|
|
handleSaveAsWorksheet();
|
|
break;
|
|
case APPMENU_FILE_SAVERAW :
|
|
handleSaveAsRaw();
|
|
break;
|
|
case APPMENU_FILE_SAVETEXT :
|
|
handleSaveAsText();
|
|
break;
|
|
case APPMENU_SETTINGS_SERIAL :
|
|
handleSerialSettings();
|
|
break;
|
|
case APPMENU_HELP_ABOUT :
|
|
handleHelpAbout();
|
|
break;
|
|
case APPMENU_HELP_REGISTER :
|
|
handleHelpRegister();
|
|
break;
|
|
case APPMENU_HELP_HELP :
|
|
handleHelpHelp();
|
|
break;
|
|
case APPMENU_HELP_HOME :
|
|
handleHelpHome();
|
|
break;
|
|
case DB_PROFILES :
|
|
if(CBN_SELCHANGE==someCallbackData.wmCommandCommand())
|
|
handleProfileChange();
|
|
break;
|
|
}
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
void DiveDlg::handleCancel()
|
|
{
|
|
endDialog(false);
|
|
}
|
|
|
|
void DiveDlg::handleOk()
|
|
{
|
|
endDialog(true);
|
|
}
|
|
|
|
void DiveDlg::handleSerialSettings()
|
|
{
|
|
SerialDlg serialDlg;
|
|
serialDlg.perform(*this);
|
|
}
|
|
|
|
void DiveDlg::handleFileOpen()
|
|
{
|
|
PureMenu windowMenu(::GetMenu(*this));
|
|
AppReg appReg;
|
|
|
|
if(!mDiveProfile.openDevice(appReg.getPort(),*this))return;
|
|
// if(mDiveProfile.isOkay())
|
|
// {
|
|
// ::MessageBox(*this,"Merge into currently loaded log?","Confirm",MB_YESNOCANCEL);
|
|
// }
|
|
windowMenu.getSubMenu(0,windowMenu);
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVEWORKSHEET,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled));
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVERAW,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled));
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVETEXT,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled));
|
|
setCaption(String(STRING_APPNAME)+String(" ")+String(STRING_VERSION)+String(" (Device:")+appReg.getPort()+String(")"));
|
|
setData(mDiveProfile);
|
|
}
|
|
|
|
void DiveDlg::handleImport()
|
|
{
|
|
PureMenu windowMenu(::GetMenu(*this));
|
|
OpenDialog openDialog;
|
|
String strPathFileName;
|
|
LRESULT result;
|
|
|
|
if(!openDialog.getOpenFileName(*this,"*.dat","Open File","*.dat",strPathFileName))return;
|
|
if(mDiveProfile.isOkay())
|
|
{
|
|
result=::MessageBox(*this,"Merge into currently loaded log?","Confirm",MB_YESNOCANCEL);
|
|
}
|
|
if(!mDiveProfile.openFile(strPathFileName))
|
|
{
|
|
::MessageBox(*this,"File is not in Aladin data format","Error",MB_OK);
|
|
return;
|
|
}
|
|
setCaption(String(STRING_APPNAME)+String(" ")+String(STRING_VERSION)+String(" (")+strPathFileName+String(")"));
|
|
windowMenu.getSubMenu(0,windowMenu);
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVEWORKSHEET,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled));
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVERAW,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled));
|
|
windowMenu.enableMenuItem(APPMENU_FILE_SAVETEXT,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled));
|
|
setData(mDiveProfile);
|
|
}
|
|
|
|
void DiveDlg::setData(Aladin &diveInfo)
|
|
{
|
|
const Information &information=diveInfo.getInformation();
|
|
const CurrentStatus &status=diveInfo.getStatus();
|
|
const LogBook &logBook=diveInfo.getLogBook();
|
|
const Profiles &profiles=diveInfo.getProfile();
|
|
int index;
|
|
|
|
mLogList->resetContent();
|
|
mProfileList->resetContent();
|
|
sendMessage(DB_PROFILES,CB_RESETCONTENT,0,0L);
|
|
setText(DB_COMPUTER,information.getComputerTypeString());
|
|
setText(DB_BATTERY,String().fromDouble(status.getRemainingBattery()));
|
|
setText(DB_STANDARD,information.getStandardString());
|
|
sendMessage(DB_NITROX,BM_SETCHECK,information.isNitrox(),0L);
|
|
sendMessage(DB_O2,BM_SETCHECK,information.isO2(),0L);
|
|
for(index=0;index<logBook.size();index++)
|
|
{
|
|
const DiveLog &diveLog=((LogBook&)logBook)[index];
|
|
String str=diveLog.getEntryTime().toString()+String("\t");
|
|
str+=String().fromInt(diveLog.getMaxDepth())+String("\t");
|
|
str+=String().fromInt(diveLog.getBottomTime())+String("\t");
|
|
str+=diveLog.getSurfaceTime().toString()+String("\t");
|
|
str+=String().fromInt(diveLog.getWaterTemperature());
|
|
mLogList->addString(str);
|
|
}
|
|
for(index=0;index<profiles.size();index++)
|
|
{
|
|
String str=String("Profile_")+String().fromInt(index+1);
|
|
sendMessage(DB_PROFILES,CB_INSERTSTRING,-1,(LPARAM)str.str());
|
|
}
|
|
sendMessage(DB_PROFILES,CB_SETCURSEL,0,0L);
|
|
handleProfileChange();
|
|
}
|
|
|
|
void DiveDlg::handleProfileChange()
|
|
{
|
|
const Profiles &profiles=mDiveProfile.getProfile();
|
|
int index=sendMessage(DB_PROFILES,CB_GETCURSEL,0,0L);
|
|
mProfileList->resetContent();
|
|
DiveProfile &diveProfile=((Block<DiveProfile>&)profiles)[index];
|
|
for(index=0;index<diveProfile.size();index++)
|
|
{
|
|
ProfileData &profileData=diveProfile[index];
|
|
String str=String("\t")+String().fromInt(profileData.getStageTime())+String("\t")+String().fromInt(profileData.getDepth());
|
|
mProfileList->addString(str);
|
|
}
|
|
mOwnerDrawGraph->setData(diveProfile);
|
|
mOwnerDrawGraph->invalidate();
|
|
}
|
|
|
|
void DiveDlg::handleSaveAsWorksheet()
|
|
{
|
|
OpenDialog openDialog;
|
|
String strPathFileName;
|
|
|
|
if(!openDialog.getSaveFileName(".123","Save As Lotus Worksheet","",strPathFileName))return;
|
|
if(!mDiveProfile.saveWorksheet(strPathFileName))
|
|
{
|
|
::MessageBox(*this,"Error saving file.","Error",MB_OK);
|
|
return;
|
|
}
|
|
}
|
|
|
|
void DiveDlg::handleSaveAsRaw()
|
|
{
|
|
OpenDialog openDialog;
|
|
String strPathFileName;
|
|
|
|
if(!openDialog.getSaveFileName(".dat","Save As Raw Data","",strPathFileName))return;
|
|
if(!mDiveProfile.saveRaw(strPathFileName))
|
|
{
|
|
::MessageBox(*this,"Error saving file.","Error",MB_OK);
|
|
return;
|
|
}
|
|
}
|
|
|
|
void DiveDlg::handleSaveAsText()
|
|
{
|
|
OpenDialog openDialog;
|
|
String strPathFileName;
|
|
|
|
if(!openDialog.getSaveFileName(".txt","Save As Text","",strPathFileName))return;
|
|
if(!mDiveProfile.saveText(strPathFileName))
|
|
{
|
|
::MessageBox(*this,"Error saving file.","Error",MB_OK);
|
|
return;
|
|
}
|
|
}
|
|
|
|
void DiveDlg::handleHelpAbout()
|
|
{
|
|
SplashScreen splashScreen("SPLASH",String(STRING_SPLASHURL),String(STRING_APPNAME));
|
|
splashScreen.perform();
|
|
}
|
|
|
|
void DiveDlg::handleHelpHelp()
|
|
{
|
|
RegKey regKey(RegKey::LocalMachine);
|
|
String strCommand;
|
|
Process process;
|
|
|
|
if(!regKey.openKey(String(STRING_BROWSERKEY)))return;
|
|
if(!regKey.enumValue(0,String(STRING_BROWSERCOMMAND),strCommand)||strCommand.isNull())
|
|
{
|
|
::MessageBox(*this,"Cannot locate default browser","Help->Home",MB_OK);
|
|
return;
|
|
}
|
|
strCommand.removeTokens("'\"");
|
|
process.createProcess(strCommand,String(" ")+String(STRING_HOST)+String(STRING_HELPPAGE),false);
|
|
}
|
|
|
|
void DiveDlg::handleHelpRegister()
|
|
{
|
|
RegKey regKey(RegKey::LocalMachine);
|
|
String strCommand;
|
|
Process process;
|
|
|
|
if(!regKey.openKey(String(STRING_BROWSERKEY)))return;
|
|
if(!regKey.enumValue(0,String(STRING_BROWSERCOMMAND),strCommand)||strCommand.isNull())
|
|
{
|
|
::MessageBox(*this,"Cannot locate default browser","Help->Home",MB_OK);
|
|
return;
|
|
}
|
|
strCommand.removeTokens("'\"");
|
|
process.createProcess(strCommand,String(" ")+String(STRING_HOST)+String(STRING_REGISTERPAGE),false);
|
|
}
|
|
|
|
void DiveDlg::handleHelpHome()
|
|
{
|
|
RegKey regKey(RegKey::LocalMachine);
|
|
String strCommand;
|
|
Process process;
|
|
|
|
if(!regKey.openKey(String(STRING_BROWSERKEY)))return;
|
|
if(!regKey.enumValue(0,String(STRING_BROWSERCOMMAND),strCommand)||strCommand.isNull())
|
|
{
|
|
::MessageBox(*this,"Cannot locate default browser","Help->Home",MB_OK);
|
|
return;
|
|
}
|
|
strCommand.removeTokens("'\"");
|
|
process.createProcess(strCommand,String(" ")+String(STRING_HOST)+String(STRING_HOMEPAGE),false);
|
|
}
|
|
|
|
|