Beispiel #1
0
void CMsgHandlerDlg::OnCbtnMsgHandlerApply() 
{

    BOOL bValidateSelection = FALSE;
    UpdateData(TRUE);
    m_omButtonApply.EnableWindow(FALSE);
    m_omButtonOK.EnableWindow(FALSE);
    // Get document pointer
    CFunctionEditorDoc* pDoc = CGlobalObj::ouGetObj(m_eBus).podGetFunctionEditorDoc();
    if (NULL != pDoc)
    {
        SBUS_SPECIFIC_INFO sBusSpecInfo;
        pDoc->bGetBusSpecificInfo(sBusSpecInfo);
        // Validate user selections
        bValidateSelection = bValidateUserSelection(pDoc); 
        if (bValidateSelection == TRUE)
        {
            CString omFunc = CGlobalObj::omGetBusSpecMsgHndlrName(m_eBus);;
            // Add to function editor
            CString omSelectedText = _T("");

            omSelectedText = BUS_FN_HDR; // Start comment section: init
            omSelectedText.Replace(_T("PLACE_HODLER_FOR_BUSNAME"), 
                             sBusSpecInfo.m_omBusName); // Replace the bus name

            omFunc += m_omStrSelectedItemText;
            omSelectedText.Replace( _T("PLACE_HODLER_FOR_FUNCTIONNAME"),
                omFunc );
            pDoc->m_omSourceCodeTextList.AddTail( omSelectedText );
            // Form the function prototype
            omSelectedText  = m_omStrSelectedItemText;
            int nIndex = -1;
            

            // Get the type and set the parameter type
            BOOL bIsMsgSpecificHandler = FALSE;
            //Find out whether the Msg handler is DatabaseMsgName type or ID type
            CString omMsgHandlerType = CGlobalObj::ouGetObj(m_eBus).m_omMsgStructName;
            nIndex = omSelectedText.Find(defSTR_MSG_SPECIFIC_HANDLER);
            
            if( nIndex != -1 )
            {
                bIsMsgSpecificHandler = TRUE;
                // For database message type is equal same as msg name
                omMsgHandlerType = omSelectedText.Mid( nIndex +
                                                     defMESSAGE_NAME_INDEX );
            }
            CString omStrParamtype;
            
            if (bIsMsgSpecificHandler == TRUE && (m_eBus == CAN))
            {
                omStrParamtype = omMsgHandlerType;
            }
            else// For Msg ID, Range and generic messages the type is sTCANDATA
            {
                omStrParamtype = CGlobalObj::ouGetObj(m_eBus).m_omMsgStructName;
            }
            CString omFormatString = m_eBus == CAN ? defDEFAULT_MSG_HANDLER_CODE_CAN : defDEFAULT_MSG_HANDLER_CODE;
            omSelectedText.Format(  omFormatString,
                                    CGlobalObj::omGetBusSpecMsgHndlrName(sBusSpecInfo.m_eBus),
                                    omSelectedText,   // Fun name
                                    omStrParamtype ); // Parameter type

            pDoc->m_omSourceCodeTextList.AddTail( omSelectedText );

            CString omStrPrototype = omSelectedText;
            // Add to tree view
            CFnsTreeView* pomTreeView = CGlobalObj::ouGetObj(m_eBus).podGetFuncsTreeViewPtr();
            if(pomTreeView != NULL )
            {
                // Add the prototype to the tree view
                CTreeCtrl& omTree = pomTreeView->GetTreeCtrl();
                HTREEITEM hItem = omTree.GetSelectedItem();
                HTREEITEM hNew = 
                    omTree.InsertItem( omSelectedText, hItem);
                omTree.SetItemImage( hNew, 5, 5 );
                omTree.SelectItem( hNew );
                // Form the body of the function
                omSelectedText = "{";
                pDoc->m_omSourceCodeTextList.AddTail( omSelectedText );
                if (CGlobalObj::ouGetObj(m_eBus).m_omMsgStructName.IsEmpty())
                {
                    ASSERT(FALSE);
                }
                omSelectedText = defTODO;
                pDoc->m_omSourceCodeTextList.AddTail( omSelectedText );

                // Form the function footer
                omSelectedText = BUS_FN_FOOTER;
                omSelectedText.Replace(_T("PLACE_HODLER_FOR_BUSNAME"), sBusSpecInfo.m_omBusName);
                omSelectedText.Replace( _T("PLACE_HODLER_FOR_FUNCTIONNAME"),
                    omFunc );

                pDoc->m_omSourceCodeTextList.AddTail( omSelectedText );

                CStringArray* pMsgArray = 
                    pDoc->omStrGetMessageHandlerPrototypes();
                if ( pMsgArray != NULL )
                {
                    pMsgArray->Add( omStrPrototype );
                }
                pDoc->UpdateAllViews( NULL );
                pDoc->SetModifiedFlag( TRUE );
            }
        }
    }
    m_omStrSelectedItemText = _T("");
    BOOL bButtonChecked  = FALSE;
    bButtonChecked =  IsDlgButtonChecked(IDC_RBTN_MSG_NAME);
    if(bButtonChecked != FALSE )
    {
         m_omListMsgName.SetCurSel(-1);
    }
}