#include #include Factor::Factor(GUIWindow &parent,const String &strCaption) : mhParent(parent), mWidthFactor(0.00), mWidthIncremental(0.00), mWidthOperation(None), mHeightFactor(0.00), mHeightIncremental(0.00), mHeightOperation(None), mhInstance(parent.processInstance()) { mInitHandler.setCallback(this,&Factor::initHandler); mCommandHandler.setCallback(this,&Factor::commandHandler); insertHandler(VectorHandler::CommandHandler,&mCommandHandler); insertHandler(VectorHandler::InitDialogHandler,&mInitHandler); mCaption=strCaption; } Factor::~Factor() { removeHandler(VectorHandler::CommandHandler,&mCommandHandler); removeHandler(VectorHandler::InitDialogHandler,&mInitHandler); } bool Factor::showFactor(double &widthFactor,double &heightFactor,double &widthIncremental,Operation &widthOperation,double &heightIncremental,Operation &heightOperation) { bool returnCode; mFactorType=Incremental; returnCode=::DialogBoxParam(mhInstance,(LPSTR)"Factor",mhParent,(DLGPROC)DWindow::DlgProc,(LONG)((DWindow*)this)); if(!returnCode)return false; widthFactor=mWidthFactor; widthIncremental=mWidthIncremental; widthOperation=mWidthOperation; heightFactor=mHeightFactor; heightIncremental=mHeightIncremental; heightOperation=mHeightOperation; return true; } bool Factor::showFactor(double &widthFactor,double &heightFactor) { bool returnCode; mFactorType=NonIncremental; returnCode=::DialogBoxParam(mhInstance,(LPSTR)"Factor",mhParent,(DLGPROC)DWindow::DlgProc,(LONG)((DWindow*)this)); if(!returnCode)return false; widthFactor=mWidthFactor; heightFactor=mHeightFactor; return true; } void Factor::initializeStrings(void) { mWidthStringIndex=0; mHeightStringIndex=0; mWidthStrings.insert(&String("+=")); mWidthStrings.insert(&String("-=")); mWidthStrings.insert(&String("\\=")); mWidthStrings.insert(&String("*=")); mHeightStrings.insert(&mWidthStrings[0]); mHeightStrings.insert(&mWidthStrings[1]); mHeightStrings.insert(&mWidthStrings[2]); mHeightStrings.insert(&mWidthStrings[3]); } void Factor::currentOperation(WORD stringIndex,Operation &operation)const { switch(stringIndex) { case 0 : operation=Add; break; case 1 : operation=Subtract; break; case 2 : operation=Divide; break; case 3 : operation=Multiply; break; } } CallbackData::ReturnType Factor::initHandler(CallbackData &callbackData) { mWidthStrings.remove(); mHeightStrings.remove(); if(Incremental==mFactorType) { Rect cRect; windowRect(cRect); moveWindow(Rect(cRect.left(),cRect.top(),407,148),true); initializeStrings(); currentOperation(mWidthStringIndex,mWidthOperation); currentOperation(mHeightStringIndex,mHeightOperation); setText(FACTOR_WOPSTRING,mWidthStrings[mWidthStringIndex]); setText(FACTOR_HOPSTRING,mHeightStrings[mHeightStringIndex]); } setCaption(mCaption); return true; } CallbackData::ReturnType Factor::commandHandler(CallbackData &callbackData) { switch(callbackData.wmCommandID()) { case FACTOR_WIDTHOP : handleWidth(callbackData); break; case FACTOR_HEIGHTOP : handleHeight(callbackData); break; case IDOK : handleOk(callbackData); break; case IDCANCEL : handleCancel(); break; } return true; } void Factor::handleWidth(CallbackData &callbackData) { LRESULT checkState; if(!(BN_CLICKED==HIWORD(callbackData.lParam())))return; if(!mWidthStrings.size())return; if(++mWidthStringIndex>=mWidthStrings.size())mWidthStringIndex=0; checkState=sendMessage(FACTOR_WIDTHOP,BM_GETCHECK,0,0L); sendMessage(FACTOR_WIDTHOP,BM_SETCHECK,!checkState,0L); setText(FACTOR_WOPSTRING,mWidthStrings[mWidthStringIndex]); sendMessage(FACTOR_WIDTHOP,BM_SETCHECK,!(!checkState),0L); currentOperation(mWidthStringIndex,mWidthOperation); } void Factor::handleHeight(CallbackData &callbackData) { LRESULT checkState; if(!(BN_CLICKED==HIWORD(callbackData.lParam())))return; if(!mHeightStrings.size())return; if(++mHeightStringIndex>=mHeightStrings.size())mHeightStringIndex=0; checkState=sendMessage(FACTOR_HEIGHTOP,BM_GETCHECK,0,0L); sendMessage(FACTOR_HEIGHTOP,BM_SETCHECK,!checkState,0L); setText(FACTOR_HOPSTRING,mHeightStrings[mHeightStringIndex]); sendMessage(FACTOR_HEIGHTOP,BM_SETCHECK,!(!checkState),0L); currentOperation(mHeightStringIndex,mHeightOperation); } void Factor::handleOk(CallbackData &callackData) { String itemText; getText(FACTOR_WIDTH,itemText); mWidthFactor=itemText.toDouble(); getText(FACTOR_HEIGHT,itemText); mHeightFactor=itemText.toDouble(); getText(FACTOR_WIDTHINCR,itemText); mWidthIncremental=itemText.toDouble(); getText(FACTOR_HEIGHTINCR,itemText); mHeightIncremental=itemText.toDouble(); endDialog(true); } void Factor::handleCancel() { endDialog(false); }