#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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; applyHistory(); ::GetClassName(*this,strClass,String::MaxString); ::SetClassLong(*this,GCL_HICON,(LONG)::LoadIcon(processInstance(),"APPICON")); enableMenuItems(false); mOwnerDrawGraph=new OwnerDrawGraph(*this,getItem(DB_GRAPH),DB_GRAPH); mOwnerDrawGraph.disposition(PointerDisposition::Delete); setCaption(String(STRING_APPNAME)+String(" ")+String(STRING_VERSION)); Block logStopArray; Block 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); ::EnableWindow(getItem(DB_NITROX),false); ::EnableWindow(getItem(DB_O2),false); 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_OPENDEVICE : handleFileOpenDevice(); break; case APPMENU_FILE_OPENLOG : handleFileOpenLog(); 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_FILE_SAVEGRAPH : handleSaveGraph(); break; case APPMENU_FILE_SAVE : handleFileSaveLog(); break; case APPMENU_FILE_NEW : handleFileNew(); 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 APPMENU_HELP_INTERFACES : handleHelpInterfaces(); break; case DB_PROFILES : if(CBN_SELCHANGE==someCallbackData.wmCommandCommand()) handleProfileChange(); break; case DB_GRAPH : handleGraph(); break; } if(someCallbackData.wParam()>=StartDynamicID)handleFileOpen(someCallbackData); return (CallbackData::ReturnType)FALSE; } void DiveDlg::handleGraph() { GDIPoint cursorPos; if(!mOwnerDrawGraph->hasData())return; cursorPos.x(0); cursorPos.y(0); PureMenu popupMenu(PureMenu::PopupMenu); popupMenu.insertMenu(0,PureMenu::ItemString,APPMENU_FILE_SAVEGRAPH,"&Save Bitmap..."); popupMenu.trackPopupMenu(*this,cursorPos,PureMenu::CenterAlign|PureMenu::TopAlign); } void DiveDlg::handleSaveGraph() { OpenDialog openDialog; String strPathFileName; String strSaveAs; sendMessage(DB_PROFILES,WM_GETTEXT,String::MaxString,(LPARAM)(LPSTR)strSaveAs.str()); strSaveAs+=".bmp"; if(!openDialog.getSaveFileName(".bmp","Save Bitmap",strSaveAs,strPathFileName))return; mOwnerDrawGraph->saveBitmap(strPathFileName); } void DiveDlg::handleCancel() { endDialog(false); } void DiveDlg::handleOk() { endDialog(true); } void DiveDlg::handleSerialSettings() { SerialDlg serialDlg; serialDlg.perform(*this); } void DiveDlg::handleFileOpen(CallbackData &someCallbackData) { PureMenu pureMenu(getMenu()); PureMenu fileMenu; String menuItemString; pureMenu.getSubMenu(0,fileMenu); menuItemString=fileMenu.menuItemString(someCallbackData.wParam(),PureMenu::ByCommand); if(menuItemString.isNull())return; menuItemString=menuItemString.betweenString(')',0); menuItemString.trimLeft(); if(menuItemString.strstr(".log"))handleFileOpenLog(menuItemString); else if(menuItemString.strstr(".dat"))handleFileOpenRaw(menuItemString); else ::MessageBox(*this,"Unknown data format","Error",MB_OK); } void DiveDlg::handleFileOpenDevice() { AppReg appReg; LRESULT result; if(mDiveProfile.isOkay()) { result=::MessageBox(*this,"Merge into currently loaded log?","Confirm",MB_YESNOCANCEL); if(IDCANCEL==result)return; if(IDNO==result)mDiveProfile.clear(); } if(!mDiveProfile.openDevice(appReg.getPort(),*this))return; enableMenuItems(true,IDYES==result?false:true); setCaption(String(STRING_APPNAME)+String(" ")+String(STRING_VERSION)+String(" (Device:")+appReg.getPort()+String(")")); setData(mDiveProfile); } void DiveDlg::handleImport() { String strPathFileName; OpenDialog openDialog; if(!openDialog.getOpenFileName(*this,"*.dat","Open File","*.dat",strPathFileName))return; handleFileOpenRaw(strPathFileName); } void DiveDlg::handleFileOpenLog(void) { OpenDialog openDialog; String strPathFileName; if(!openDialog.getOpenFileName(*this,"*.log","Open Log","*.log",strPathFileName))return; handleFileOpenLog(strPathFileName); } void DiveDlg::handleFileOpenLog(const String &strPathFileName) { AppReg appReg; LRESULT result; if(mDiveProfile.isOkay()) { result=::MessageBox(*this,"Merge into currently loaded log?","Confirm",MB_YESNOCANCEL); if(IDCANCEL==result)return; if(IDNO==result)mDiveProfile.clear(); } if(!mDiveProfile.openLog(strPathFileName)) { ::MessageBox(*this,"Not a valid log file","Error",MB_OK); return; } appReg.insertHistory(strPathFileName); setCaption(String(STRING_APPNAME)+String(" ")+String(STRING_VERSION)+String(" (")+strPathFileName+String(")")); enableMenuItems(true,false); setData(mDiveProfile); } void DiveDlg::handleFileOpenRaw(const String &strPathFileName) { AppReg appReg; LRESULT result; if(mDiveProfile.isOkay()) { result=::MessageBox(*this,"Merge into currently loaded log?","Confirm",MB_YESNOCANCEL); if(IDCANCEL==result)return; if(IDNO==result)mDiveProfile.clear(); } if(!mDiveProfile.openRaw(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(")")); enableMenuItems(true,IDYES==result?false:true); setData(mDiveProfile); appReg.insertHistory(strPathFileName); } void DiveDlg::clearData() { mDiveProfile.clear(); sendMessage(DB_PROFILES,CB_RESETCONTENT,0,0L); setText(DB_COMPUTER,""); setText(DB_BATTERY,""); setText(DB_STANDARD,""); sendMessage(DB_NITROX,BM_SETCHECK,0,0L); sendMessage(DB_O2,BM_SETCHECK,0,0L); mLogList->resetContent(); mProfileList->resetContent(); mOwnerDrawGraph->clearData(); mOwnerDrawGraph->invalidate(); } 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); sendMessage(DB_NITROX,WM_ENABLE,FALSE,0); sendMessage(DB_O2,WM_ENABLE,FALSE,0); for(index=0;indexaddString(str); } for(index=0;indexresetContent(); DiveProfile &diveProfile=((Block&)profiles)[index]; for(index=0;indexaddString(str); } sendMessage(DB_PFMAXDEPTH,WM_SETTEXT,0,(LONG)(LPSTR)String().fromInt(diveProfile.getMaxDepth())); sendMessage(DB_PFBOTTOMTIME,WM_SETTEXT,0,(LONG)(LPSTR)String().fromInt(diveProfile.getBottomTime())); 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::handleFileSaveLog(void) { OpenDialog openDialog; String strPathFileName; if(!openDialog.getSaveFileName(".log","Save Log","",strPathFileName))return; if(!mDiveProfile.saveLog(strPathFileName)) { ::MessageBox(*this,"Error saving file.","Error",MB_OK); return; } } void DiveDlg::handleFileNew() { if(IDCANCEL==::MessageBox(*this,"Clear contents?","Confirm",MB_OKCANCEL))return; clearData(); } void DiveDlg::handleHelpAbout() { SplashScreen splashScreen("SPLASH",String(STRING_SPLASHURL),String(STRING_APPNAME)); splashScreen.perform(); } void DiveDlg::handleHelpHelp() { String strCommand; Process process; if(!getBrowser(strCommand))return; process.createProcess(strCommand,String(" ")+String(STRING_HOST)+String(STRING_HELPPAGE),false); } void DiveDlg::handleHelpRegister() { String strCommand; Process process; if(!getBrowser(strCommand))return; process.createProcess(strCommand,String(" ")+String(STRING_HOST)+String(STRING_REGISTERPAGE),false); } void DiveDlg::handleHelpHome() { String strCommand; Process process; if(!getBrowser(strCommand))return; process.createProcess(strCommand,String(" ")+String(STRING_HOST)+String(STRING_HOMEPAGE),false); } void DiveDlg::handleHelpInterfaces(void) { String strCommand; Process process; if(!getBrowser(strCommand))return; process.createProcess(strCommand,String(" ")+String(STRING_LINKURL),false); } void DiveDlg::enableMenuItems(bool enable,bool enableSaveRaw) { PureMenu windowMenu(::GetMenu(*this)); windowMenu.getSubMenu(0,windowMenu); if(enable) { windowMenu.getSubMenu(0,windowMenu); windowMenu.enableMenuItem(APPMENU_FILE_SAVEWORKSHEET,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled)); if(!enableSaveRaw)windowMenu.enableMenuItem(APPMENU_FILE_SAVERAW,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemDisabled|PureMenu::ItemGrayed)); else windowMenu.enableMenuItem(APPMENU_FILE_SAVERAW,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled)); windowMenu.enableMenuItem(APPMENU_FILE_SAVETEXT,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled)); windowMenu.enableMenuItem(APPMENU_FILE_SAVE,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled)); windowMenu.enableMenuItem(APPMENU_FILE_NEW,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemEnabled)); } else { 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)); windowMenu.enableMenuItem(APPMENU_FILE_SAVE,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemDisabled|PureMenu::ItemGrayed)); windowMenu.enableMenuItem(APPMENU_FILE_NEW,PureMenu::ByCommand,PureMenu::InsertFlags(PureMenu::ItemDisabled|PureMenu::ItemGrayed)); } } bool DiveDlg::getBrowser(String &strBrowser) { RegKey regKey(RegKey::LocalMachine); String strCommand; int argPos; if(!regKey.openKey(String(STRING_BROWSERKEY))) { if(!regKey.openKey(String(STRING_BROWSERKEYALT))) { ::MessageBox(*this,"Unable to launch browser.","Error",MB_OK); return false; } } if(!regKey.enumValue(0,String(STRING_BROWSERCOMMAND),strCommand)||strCommand.isNull()||!strCommand.length()) { ::MessageBox(*this,"Unable to launch browser.","Error",MB_OK); return false; } strCommand.removeTokens("'\""); if(-1!=(argPos=strCommand.strpos("-")))strCommand=strCommand.substr(0,argPos-1); strBrowser=strCommand; return true; } void DiveDlg::applyHistory(void) { AppReg appReg; Block nameList; PureMenu fileMenu; String strItem; PureMenu pureMenu(getMenu()); appReg.getHistory(nameList); if(!nameList.size())return; pureMenu.getSubMenu(0,fileMenu); fileMenu.appendSeparator(); for(int itemIndex=0;itemIndex