Files
Work/mdiwin/FACTOR.CPP
2024-08-07 09:16:27 -04:00

184 lines
5.7 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <math.h>
#include <string.h>
#include <mdiwin/windowsx.hpp>
#include <mdiwin/string.hpp>
#include <mdiwin/main.hpp>
#include <mdiwin/factor.hpp>
#include <mdiwin/mdiwin.h>
Factor::Factor(HWND hParent,const char *caption)
: mhParent(hParent), mWidthFactor(0.00), mWidthIncremental(0.00),
mWidthOperation(None), mHeightFactor(0.00), mHeightIncremental(0.00),
mHeightOperation(None), mhInstance(Main::processInstance(hParent))
{
::strcpy(mCaption,caption);
}
Factor::~Factor()
{
}
WORD Factor::showFactor(double &widthFactor,double &heightFactor,
double &widthIncremental,Operation &widthOperation,
double &heightIncremental,Operation &heightOperation)
{
WORD returnCode;
mFactorType=Incremental;
returnCode=::DialogBoxParam(mhInstance,(LPSTR)"Factor",mhParent,(DLGPROC)DWindow::DialogProcedure,(LONG)((DWindow*)this));
if(!returnCode)return FALSE;
widthFactor=mWidthFactor;
widthIncremental=mWidthIncremental;
widthOperation=mWidthOperation;
heightFactor=mHeightFactor;
heightIncremental=mHeightIncremental;
heightOperation=mHeightOperation;
return TRUE;
}
WORD Factor::showFactor(double &widthFactor,double &heightFactor)
{
WORD returnCode;
mFactorType=NonIncremental;
returnCode=::DialogBoxParam(mhInstance,(LPSTR)"Factor",mhParent,(DLGPROC)DWindow::DialogProcedure,(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;
}
}
int Factor::DlgProc(UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG :
{
mWidthStrings.remove();
mHeightStrings.remove();
if(Incremental==mFactorType)
{
RECT clientRect;
::GetWindowRect(GetHandle(),(RECT FAR *)&clientRect);
::MoveWindow(GetHandle(),clientRect.left,clientRect.top,407,148,TRUE);
initializeStrings();
currentOperation(mWidthStringIndex,mWidthOperation);
currentOperation(mHeightStringIndex,mHeightOperation);
::SetDlgItemText(GetHandle(),FACTOR_WOPSTRING,(LPSTR)mWidthStrings[mWidthStringIndex]);
::SetDlgItemText(GetHandle(),FACTOR_HOPSTRING,(LPSTR)mHeightStrings[mHeightStringIndex]);
}
::SetWindowText(GetHandle(),(LPSTR)mCaption);
Main::smhBitmap.associate(IDOK,
String(STRING_BITMAPOKFOCUSUP,mhInstance),
String(STRING_BITMAPOKNOFUP,mhInstance),
String(STRING_BITMAPOKFOCUSDN,mhInstance),OwnerDraw::NOFOCUS);
Main::smhBitmap.associate(IDCANCEL,
String(STRING_BITMAPCAFOCUSUP,mhInstance),
String(STRING_BITMAPCANOFUP,mhInstance),
String(STRING_BITMAPCAFOCUSDN,mhInstance),OwnerDraw::NOFOCUS);
}
return TRUE;
case WM_DRAWITEM :
switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
{
case IDOK :
Main::smhBitmap.handleOwnerButton(IDOK,lParam);
break;
case IDCANCEL :
Main::smhBitmap.handleOwnerButton(IDCANCEL,lParam);
break;
}
return TRUE;
case WM_COMMAND :
switch(GET_WM_COMMAND_ID(wParam,lParam))
{
case FACTOR_WIDTHOP :
{
LRESULT checkState;
if(BN_CLICKED==HIWORD(lParam))
{
if(!mWidthStrings.size())break;
if(++mWidthStringIndex>=mWidthStrings.size())mWidthStringIndex=0;
checkState=::SendDlgItemMessage(GetHandle(),FACTOR_WIDTHOP,BM_GETCHECK,0,0L);
::SendDlgItemMessage(GetHandle(),FACTOR_WIDTHOP,BM_SETCHECK,!checkState,0L);
::SetDlgItemText(GetHandle(),FACTOR_WOPSTRING,(LPSTR)mWidthStrings[mWidthStringIndex]);
::SendDlgItemMessage(GetHandle(),FACTOR_WIDTHOP,BM_SETCHECK,!(!checkState),0L);
currentOperation(mWidthStringIndex,mWidthOperation);
}
}
break;
case FACTOR_HEIGHTOP :
{
LRESULT checkState;
if(BN_CLICKED==HIWORD(wParam))
{
if(!mHeightStrings.size())break;
if(++mHeightStringIndex>=mHeightStrings.size())mHeightStringIndex=0;
checkState=::SendDlgItemMessage(GetHandle(),FACTOR_HEIGHTOP,BM_GETCHECK,0,0L);
::SendDlgItemMessage(GetHandle(),FACTOR_HEIGHTOP,BM_SETCHECK,!checkState,0L);
::SetDlgItemText(GetHandle(),FACTOR_HOPSTRING,(LPSTR)mHeightStrings[mHeightStringIndex]);
::SendDlgItemMessage(GetHandle(),FACTOR_HEIGHTOP,BM_SETCHECK,!(!checkState),0L);
currentOperation(mHeightStringIndex,mHeightOperation);
}
}
break;
case IDOK :
{
char buffer[50];
::GetDlgItemText(GetHandle(),FACTOR_WIDTH,(LPSTR)buffer,sizeof(buffer)-1);
mWidthFactor=::atof(buffer);
::GetDlgItemText(GetHandle(),FACTOR_HEIGHT,(LPSTR)buffer,sizeof(buffer)-1);
mHeightFactor=::atof(buffer);
::GetDlgItemText(GetHandle(),FACTOR_WIDTHINCR,(LPSTR)buffer,sizeof(buffer)-1);
mWidthIncremental=::atof(buffer);
::GetDlgItemText(GetHandle(),FACTOR_HEIGHTINCR,(LPSTR)buffer,sizeof(buffer)-1);
mHeightIncremental=::atof(buffer);
}
Main::smhBitmap.freeButton(IDOK);
Main::smhBitmap.freeButton(IDCANCEL);
::EndDialog(GetHandle(),TRUE);
return TRUE;
case IDCANCEL :
Main::smhBitmap.freeButton(IDOK);
Main::smhBitmap.freeButton(IDCANCEL);
::EndDialog(GetHandle(),FALSE);
return TRUE;
}
}
return FALSE;
}