wp->RefreshDisplay(); } wp = (WndProperty*)wf->FindByName(TEXT("prpRightBottom")); if (wp) { DataFieldEnum* dfe; dfe = (DataFieldEnum*)wp->GetDataField(); dfe->Set(1); wp->RefreshDisplay(); } } static CallBackTableEntry_t CallBackTable[]={ ClickNotifyCallbackEntry(OnCloseClicked), ClickNotifyCallbackEntry(OnResetClicked), EndCallBackEntry() }; void dlgOverlaysShowModal(void){ WndProperty *wp; TCHAR filename[MAX_PATH]; LocalPathS(filename, TEXT("dlgOverlays.xml")); wf = dlgLoadFromXML(CallBackTable, filename, TEXT("IDR_XML_OVERLAYS")); if (!wf) return;
namespace dlgBlueFlyConfig { WndForm *wfDlg; PDeviceDescriptor_t pDevice; bool Init = true; const TCHAR* lstPageName [] = { _T("1"), _T("2"), _T("3") }; typedef std::vector<WindowControl*> lstPageWnd_t; lstPageWnd_t lstPageWnd; unsigned CurrentPage = 0; typedef std::map<DataField*, std::tstring> DataField2Parameter_t; DataField2Parameter_t AssocFieldParam; void NextPage(int Step) { if( ((CurrentPage+Step) >= 0) && ((CurrentPage+Step) < lstPageWnd.size()) ) { lstPageWnd[CurrentPage]->Close(); CurrentPage+=Step; lstPageWnd[CurrentPage]->Show(); WindowControl * pWnd = wfDlg->FindByName(_T("cmdNext")); if(pWnd) { pWnd->SetVisible(CurrentPage<(lstPageWnd.size()-1)); } pWnd = wfDlg->FindByName(_T("cmdPrev")); if(pWnd) { pWnd->SetVisible(CurrentPage>0); } TCHAR szTmp[50] = {0}; _stprintf(szTmp, _T("BlueFlyVario %d/%d"), CurrentPage+1, lstPageWnd.size()); wfDlg->SetCaption(szTmp); } } void OnClose(WindowControl * Sender) { (void)Sender; wfDlg->SetModalResult(mrOK); } void OnNextClicked(WindowControl * Sender) { (void)Sender; NextPage(+1); } void OnPrevClicked(WindowControl * Sender) { (void)Sender; NextPage(-1); } void OnParamData(DataField *Sender, DataField::DataAccessKind_t Mode) { if(Init) { return; } DataField2Parameter_t::iterator It; switch(Mode){ case DataField::daGet: break; case DataField::daPut: case DataField::daChange: It = AssocFieldParam.find(Sender); if(It != AssocFieldParam.end()) { CHardwareParameters& Parameters = gHardwareParameters[pDevice]; CHardwareParameter& Param = Parameters.GetParameter(It->second); switch(Param.Type()) { case TYPE_BOOLEAN: Param = Sender->GetAsBoolean(); break; case TYPE_DOUBLE: Param = Sender->GetAsFloat(); break; case TYPE_INT: case TYPE_INTOFFSET: case TYPE_INTLIST: Param = Sender->GetAsInteger(); break; } if(pDevice && pDevice->Com) { Parameters.UpdateDevice(Param, pDevice->Com); } } break; case DataField::daInc: case DataField::daDec: case DataField::daSpecial: break; } } CallBackTableEntry_t CallBackTable[] = { ClickNotifyCallbackEntry(OnClose), ClickNotifyCallbackEntry(OnNextClicked), ClickNotifyCallbackEntry(OnPrevClicked), DataAccessCallbackEntry(OnParamData), EndCallBackEntry() }; void FillProperty(CHardwareParameters::value_type& Val) { if(!wfDlg) return; CHardwareParameter& Param = Val.second; WndProperty* pWnd = (WndProperty*)wfDlg->FindByName(Param.Code().c_str()); if(pWnd) { DataField* pData = pWnd->GetDataField(); if(pData) { AssocFieldParam[pData] = Param.Code(); switch(Param.Type()) { case TYPE_BOOLEAN: pData->Set(Param.ValueBool()); break; case TYPE_DOUBLE: pData->SetMax((double)Param.Max()); pData->SetMin((double)Param.Min()); pData->Set(Param.ValueDouble()); break; case TYPE_INT: case TYPE_INTOFFSET: pData->SetMax((int)Param.Max()); pData->SetMin((int)Param.Min()); pData->Set(Param.ValueInt()); break; case TYPE_INTLIST: pData->SetMax((int)Param.Max()); pData->SetMin((int)Param.Min()); pData->Set(Param.ValueInt()); break; } } pWnd->RefreshDisplay(); } } int Show(DeviceDescriptor_t *d) { int nRet = IdCancel; TCHAR filename[MAX_PATH]; const TCHAR *resName = NULL; pDevice = d; Init = true; if (ScreenLandscape) { LocalPathS(filename, TEXT("dlgBlueFlyConfig.xml")); resName = TEXT("IDR_XML_BLUEFLYCONFIG"); } else { LocalPathS(filename, TEXT("dlgBlueFlyConfig_L.xml")); resName = TEXT("IDR_XML_BLUEFLYCONFIG_L"); } wfDlg = dlgLoadFromXML(CallBackTable, filename, resName); if (wfDlg) { // build list of page WindowConrol* lstPageWnd.clear(); lstPageWnd.reserve(std::distance(std::begin(lstPageName), std::end(lstPageName))); std::transform(std::begin(lstPageName), std::end(lstPageName), std::inserter(lstPageWnd, lstPageWnd.begin()), std::bind(&WndForm::FindByName, wfDlg, _1)); if(!lstPageWnd.empty()) { // Show First Page CurrentPage=0; NextPage(0); // Hide All Next Page std::for_each(++lstPageWnd.begin(), lstPageWnd.end(), std::bind(&WindowControl::Close, _1)); } // Init Enum WndProperty WndProperty* pWnd = (WndProperty*)wfDlg->FindByName(_T("BOM")); if(pWnd) { DataFieldEnum* pData =(DataFieldEnum*)pWnd->GetDataField(); if(pData) { pData->addEnumText(_T("BlueFlyVario")); pData->addEnumText(_T("LK8EX1")); pData->addEnumText(_T("LX")); pData->addEnumText(_T("FlyNet")); } } // Set Value to all WndProperty CHardwareParameters& HardwareParameters = gHardwareParameters[pDevice]; AssocFieldParam.clear(); std::for_each(HardwareParameters.begin(), HardwareParameters.end(), std::ptr_fun(FillProperty)); Init = false; if (wfDlg->ShowModal(true)) { nRet = IdOk; } AssocFieldParam.clear(); lstPageWnd.clear(); delete wfDlg; wfDlg = NULL; pDevice = NULL; } return nRet; } };
namespace DlgBluetooth { WndForm *wfBth = NULL; size_t DrawListIndex = 0; size_t ItemIndex = 0; void OnClose(WndButton* pWnd) { wfBth->SetModalResult(mrOK); } void OnPair(WndButton* pWnd) { CBtHandler* pBtHandler = CBtHandler::Get(); if (pBtHandler) { CBtDevice * SelectedDevice = pBtHandler->GetDevice(ItemIndex); if (SelectedDevice && SelectedDevice->m_src == BDSRC_LOOKUP) { TCHAR szPin[20] = {0}; dlgTextEntryShowModal(szPin, 20, false); if (!pBtHandler->Pair(SelectedDevice->m_ba, SelectedDevice->GetName().c_str(), szPin)) { StartupStore(_T("Bluetooth pairing <%s> : Failed%s"), SelectedDevice->GetName().c_str(), NEWLINE); MessageBoxX(LKGetText(TEXT("_@M1835_")), TEXT("Bluetooth"), mbOk, false); } else { StartupStore(_T("Bluetooth pairing <%s> : success%s"), SelectedDevice->GetName().c_str(), NEWLINE); SelectedDevice->m_src |= BDSRC_REGNAV; } } WndListFrame* BthList = (WndListFrame*) wfBth->FindByName(TEXT("frmBthList")); if (BthList) { BthList->ResetList(); BthList->Redraw(); } } } void OnUnpair(WndButton* pWnd) { CBtHandler* pBtHandler = CBtHandler::Get(); if (pBtHandler) { CBtDevice * SelectedDevice = pBtHandler->GetDevice(ItemIndex); if (SelectedDevice && SelectedDevice->m_src != BDSRC_LOOKUP) { if (!pBtHandler->Unpair(SelectedDevice->m_ba)) { StartupStore(_T("%s[%s] : UnPairing Error%s"), SelectedDevice->GetName().c_str(), SelectedDevice->BTPortName().c_str(), NEWLINE); } else { pBtHandler->RemoveDevice(SelectedDevice->m_ba); } } WndListFrame* BthList = (WndListFrame*) wfBth->FindByName(TEXT("frmBthList")); if (BthList) { BthList->ResetList(); BthList->Redraw(); } } } void OnLookup(WndButton* pWnd) { StartHourglassCursor(); CBtHandler * pBtHandler = CBtHandler::Get(); if (pBtHandler && pBtHandler->StartHW() && pBtHandler->LookupDevices()) { WndListFrame* BthList = (WndListFrame*) wfBth->FindByName(TEXT("frmBthList")); if (BthList) { BthList->ResetList(); BthList->Redraw(); } } StopHourglassCursor(); } void OnPaintListItem(WindowControl * Sender, LKSurface& Surface) { CBtHandler* pBtHandler = CBtHandler::Get(); if (pBtHandler) { CBtDevice * bt = pBtHandler->GetDevice(DrawListIndex); if (bt) { int w1 = Surface.GetTextWidth(TEXT("PAIRED")); int w0 = Sender->GetWidth(); Surface.DrawTextClip(2 * ScreenScale, 2 * ScreenScale, bt->GetName().c_str(), w0 - w1 - ScreenScale * 5); if ((bt->m_src & (BDSRC_REGSVC | BDSRC_REGNAV | BDSRC_REGPIN))) { Surface.DrawTextClip(2 * ScreenScale + w0 - w1, 2 * ScreenScale, _T("Paired"), w1); } } } } void OnListInfo(WindowControl * Sender, WndListFrame::ListInfo_t * ListInfo) { (void) Sender; CBtHandler* pBtHandler = CBtHandler::Get(); if (pBtHandler) { ListInfo->ItemCount = pBtHandler->m_devices.size(); if (ListInfo->DrawIndex != -1) { DrawListIndex = ListInfo->DrawIndex + ListInfo->ScrollIndex; ItemIndex = ListInfo->ItemIndex + ListInfo->ScrollIndex; } } } CallBackTableEntry_t CallBackTable[] = { ClickNotifyCallbackEntry(OnClose), ClickNotifyCallbackEntry(OnPair), ClickNotifyCallbackEntry(OnUnpair), ClickNotifyCallbackEntry(OnLookup), OnPaintCallbackEntry(OnPaintListItem), OnListCallbackEntry(OnListInfo), EndCallBackEntry() }; void Show() { TCHAR filename[MAX_PATH]; const TCHAR *resName = NULL; if (!ScreenLandscape) { LocalPathS(filename, TEXT("dlgBluetooth_L.xml")); resName = TEXT("IDR_XML_BLUETOOTH_L"); } else { LocalPathS(filename, TEXT("dlgBluetooth.xml")); resName = TEXT("IDR_XML_BLUETOOTH"); } wfBth = dlgLoadFromXML(CallBackTable, filename, resName); if (wfBth) { WndListFrame* BthList = (WndListFrame*) wfBth->FindByName(TEXT("frmBthList")); if (BthList) { BthList->SetBorderKind(BORDERLEFT | BORDERTOP | BORDERRIGHT | BORDERBOTTOM); BthList->SetWidth(wfBth->GetWidth() - BthList->GetLeft() - IBLSCALE(4)); // Bug : we need ClientHeight, but Cleint Rect is Calculated by OnPaint // BthList->SetHeight(wfBth->GetHeight() - BthList->GetTop() - 2); if (BthList->ScrollbarWidth == -1) { BthList->ScrollbarWidth = (int) (SCROLLBARWIDTH_INITIAL * ScreenDScale); } WndOwnerDrawFrame* BthListEntry = (WndOwnerDrawFrame*) wfBth->FindByName(TEXT("frmBthListEntry")); if (BthListEntry) { BthListEntry->SetCanFocus(true); BthListEntry->SetWidth(BthList->GetWidth() - BthList->ScrollbarWidth - 5); } BthList->ResetList(); BthList->Redraw(); } if (wfBth->ShowModal()) { CBtHandler * pBtHandler = CBtHandler::Get(); if (pBtHandler) { pBtHandler->ClearDevices(); pBtHandler->FillDevices(); } RefreshComPortList(); } delete wfBth; wfBth = NULL; } } };
namespace DlgIgcFile { WndForm *wfDlg = NULL; typedef std::vector<std::tstring> FileList_t; FileList_t FileList; size_t DrawListIndex = (~0); size_t ItemIndex = (~0); void ScanFile() { FileList.clear(); TCHAR szPath[MAX_PATH] = _T("\0"); TCHAR tmpPath[MAX_PATH]; LocalPath(szPath, _T(LKD_LOGS)); size_t nLen = _tcslen(szPath); if (szPath[nLen - 1] != _T('\\')) { _tcscat(szPath, _T(DIRSEP)); } _tcscpy(tmpPath,szPath); _tcscat(tmpPath, _T("*.igc")); for(lk::filesystem::directory_iterator It(tmpPath); It; ++It) { if(!It.isDirectory()) { FileList.push_back(It.getName()); } } _tcscpy(tmpPath,szPath); _tcscat(tmpPath, _T("*.IGC")); for(lk::filesystem::directory_iterator It(tmpPath); It; ++It) { if(!It.isDirectory()) { FileList.push_back(It.getName()); } } std::sort(FileList.rbegin(), FileList.rend()); // sort in desc order. } void OnClose(WndButton* pWnd) { wfDlg->SetModalResult(mrOK); } void OnSend(WndButton* pWnd) { if(ItemIndex < FileList.size()) { StartHourglassCursor(); //Start Bluetooth if needed... #ifdef UNDER_CE CObexPush Obex; if(Obex.Startup()) { StartupStore(_T("Startup OK \n")); size_t nDevice = Obex.LookupDevice(); StartupStore(_T("LookupDevice OK \n")); if(nDevice == 0) { StopHourglassCursor(); MessageBoxX(_T("No Device"), _T("Error"), mbOk); StartHourglassCursor(); } else { WndProperty* wp = (WndProperty*)wfDlg->FindByName(TEXT("prpDeviceList")); DataFieldEnum* dfe = NULL; if (wp) { dfe = (DataFieldEnum*)wp->GetDataField(); } if(dfe) { dfe->Clear(); dfe->addEnumText(_T("none")); } for(size_t i = 0; i < nDevice; ++i) { TCHAR szDeviceName[100] = {0}; if(!Obex.GetDeviceName(i, szDeviceName, array_size(szDeviceName))) { _stprintf(szDeviceName, _T("Unknown device <%d>"), i); } StartupStore(_T("GetDeviceName <%d><%s> \n"), i, szDeviceName); if(dfe) { dfe->addEnumText(szDeviceName); } } if(wp) { if(dfe) { dfe->SetAsInteger(0); } wp->SetReadOnly(false); wp->RefreshDisplay(); } StopHourglassCursor(); size_t DeviceIndex = 0; if(dfe && wp) { dlgComboPicker(wp); DeviceIndex = dfe->GetAsInteger(); } StartHourglassCursor(); if(DeviceIndex != 0) { DeviceIndex--; TCHAR szFileFullPath[MAX_PATH] = _T("\0"); LocalPath(szFileFullPath, _T(LKD_LOGS)); size_t nLen = _tcslen(szFileFullPath); if (szFileFullPath[nLen - 1] != _T('\\')) { _tcscat(szFileFullPath, _T("\\")); } FileList_t::const_iterator ItFileName = FileList.begin(); std::advance(ItFileName, ItemIndex); _tcscat(szFileFullPath, ItFileName->c_str()); if(!Obex.SendFile(DeviceIndex, szFileFullPath)) { StopHourglassCursor(); MessageBoxX(_T("Send Failed"), _T("Error"), mbOk); StartHourglassCursor(); } else { StopHourglassCursor(); MessageBoxX(_T("File sent!"), _T("Success"), mbOk); StartHourglassCursor(); } } } Obex.Shutdown(); } else { MessageBoxX(_T("Unsupported on this device"), _T("Error"), mbOk); } #else MessageBoxX(_T("Unsupported on this device"), _T("Error"), mbOk); #endif StopHourglassCursor(); } } void OnIgcFileListInfo(WindowControl * Sender, WndListFrame::ListInfo_t * ListInfo) { (void) Sender; ListInfo->ItemCount = FileList.size(); if (ListInfo->DrawIndex != -1) { DrawListIndex = ListInfo->DrawIndex + ListInfo->ScrollIndex; ItemIndex = ListInfo->ItemIndex + ListInfo->ScrollIndex; } } void OnPaintIgcFileListItem(WindowControl * Sender, LKSurface& Surface) { if (DrawListIndex < FileList.size()) { FileList_t::const_iterator ItFileName = FileList.begin(); std::advance(ItFileName, DrawListIndex); int w0 = Sender->GetWidth(); Surface.SetTextColor(RGB_BLACK); Surface.DrawTextClip(2 * ScreenScale, 2 * ScreenScale, ItFileName->c_str(), w0 - ScreenScale * 5); } } CallBackTableEntry_t CallBackTable[] = { ClickNotifyCallbackEntry(OnClose), ClickNotifyCallbackEntry(OnSend), OnListCallbackEntry(OnIgcFileListInfo), OnPaintCallbackEntry(OnPaintIgcFileListItem), EndCallBackEntry() }; }