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

216 lines
6.1 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 <fstream.h>
#include <mdiwin/main.hpp>
#include <mdiwin/filehelp.hpp>
#include <mdiwin/bitmap.hpp>
#include <mdiwin/slidesel.hpp>
#include <mdiwin/mdiwin.h>
SlideSelect::SlideSelect(HWND hParent)
: mhParent(hParent)
{
}
SlideSelect::~SlideSelect()
{
}
WORD SlideSelect::selectSlides(Block<String> &pathFileNames)
{
HINSTANCE hInstance;
int retCode;
pathFileNames.remove();
mPathFileNames.remove();
#if defined(__FLAT__)
hInstance=(HINSTANCE)::GetWindowLong(mhParent,GWL_HINSTANCE);
#else
hInstance=(HINSTANCE)::GetWindowWord(mhParent,GWW_HINSTANCE);
#endif
retCode=::DialogBoxParam(hInstance,(LPSTR)"SlideShow",mhParent,(DLGPROC)DWindow::DialogProcedure,(LONG)((DWindow*)this));
if(retCode)retCode=(int)mPathFileNames.size();
if(retCode)copyList(pathFileNames);
return retCode;
}
int SlideSelect::DlgProc(UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG :
Main::smhBitmap.associate(IDOK,
String(STRING_BITMAPOKFOCUSUP,Main::processInstance()),
String(STRING_BITMAPOKNOFUP,Main::processInstance()),
String(STRING_BITMAPOKFOCUSDN,Main::processInstance()),
OwnerDraw::NOFOCUS);
Main::smhBitmap.associate(IDCANCEL,
String(STRING_BITMAPCAFOCUSUP,Main::processInstance()),
String(STRING_BITMAPCANOFUP,Main::processInstance()),
String(STRING_BITMAPCAFOCUSDN,Main::processInstance()),
OwnerDraw::NOFOCUS);
::SendDlgItemMessage(GetHandle(),SS_BITMAP,BM_SETCHECK,TRUE,0L);
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 SS_BITMAP :
handleBitmapEvent();
return FALSE;
case SS_PROJECT :
handleProjectEvent();
return FALSE;
case SS_LIST :
handleListBoxEvent(lParam);
return FALSE;
case SS_SELECT :
handleSelectEvent(lParam);
return FALSE;
case IDOK :
retrieveItemList();
freeBitmaps();
::EndDialog(GetHandle(),TRUE);
return TRUE;
case IDCANCEL :
freeBitmaps();
::EndDialog(GetHandle(),FALSE);
return TRUE;
}
}
return FALSE;
}
void SlideSelect::freeBitmaps(void)const
{
Main::smhBitmap.freeButton(IDOK);
Main::smhBitmap.freeButton(IDCANCEL);
return;
}
void SlideSelect::copyList(Block<String> &pathFileNames)
{
size_t listSize((int)mPathFileNames.size());
for(int index=0;index<listSize;index++)
pathFileNames.insert(&mPathFileNames[index]);
}
void SlideSelect::retrieveItemList(void)
{
LRESULT listSize(::SendDlgItemMessage(GetHandle(),SS_LIST,LB_GETCOUNT,0,0L));
String tempString;
for(int index=0;index<listSize;index++)
{
::SendDlgItemMessage(GetHandle(),SS_LIST,LB_GETTEXT,index,(LONG)(LPSTR)tempString);
mPathFileNames.insert(&tempString);
}
return;
}
void SlideSelect::handleSelectEvent(LPARAM lParam)
{
String bmpExtensionString(STRING_ASTERISKDOTBMP,Main::processInstance());
String prjExtensionString(STRING_ASTERISKDOTPRJ,Main::processInstance());
String pathFileNameString;
LRESULT bitmapExtension;
if(BN_CLICKED==HIWORD(lParam))
{
bitmapExtension=::SendDlgItemMessage(GetHandle(),SS_BITMAP,BM_GETCHECK,0,0L);
::SendDlgItemMessage(GetHandle(),SS_SELECT,BM_SETCHECK,TRUE,0L);
SelectFile selector(GetHandle(),SelectFile::Read);
selector.SetFileSpec(bitmapExtension?bmpExtensionString:prjExtensionString);
if(selector.GetFileName(pathFileNameString,String::MaxString))
handleFileSelection(pathFileNameString);
::SendDlgItemMessage(GetHandle(),SS_SELECT,BM_SETCHECK,FALSE,0L);
}
return;
}
void SlideSelect::handleListBoxEvent(LPARAM lParam)const
{
LRESULT selItem;
if(HIWORD(lParam)==LBN_DBLCLK)
{
if(LB_ERR!=(selItem=::SendDlgItemMessage(GetHandle(),SS_LIST,LB_GETCURSEL,0,0L)))
::SendDlgItemMessage(GetHandle(),SS_LIST,LB_DELETESTRING,(WORD)selItem,0L);
}
}
void SlideSelect::handleBitmapEvent(void)const
{
LRESULT itemSelected;
itemSelected=::SendDlgItemMessage(GetHandle(),SS_BITMAP,BM_GETCHECK,0,0L);
if(itemSelected)return;
::SendDlgItemMessage(GetHandle(),SS_BITMAP,BM_SETCHECK,!itemSelected,0L);
::SendDlgItemMessage(GetHandle(),SS_PROJECT,BM_SETCHECK,(WORD)itemSelected,0L);
}
void SlideSelect::handleProjectEvent(void)const
{
LRESULT itemSelected;
itemSelected=::SendDlgItemMessage(GetHandle(),SS_PROJECT,BM_GETCHECK,0,0L);
if(itemSelected)return;
::SendDlgItemMessage(GetHandle(),SS_PROJECT,BM_SETCHECK,!itemSelected,0L);
::SendDlgItemMessage(GetHandle(),SS_BITMAP,BM_SETCHECK,(WORD)itemSelected,0L);
}
void SlideSelect::handleFileSelection(String &pathFileNameString)
{
Bitmap selectedBitmap;
if(selectedBitmap.isValidBitmap(pathFileNameString))
{
::SendDlgItemMessage(GetHandle(),SS_LIST,LB_ADDSTRING,0,(LPARAM)(LPCSTR)pathFileNameString);
return;
}
parseProjectFile(pathFileNameString);
}
void SlideSelect::parseProjectFile(String &pathFileNameString)
{
String projectIDString(STRING_PROJECTIDSTRING,Main::processInstance());
String crlfString(STRING_CRLF,Main::processInstance());
String errorUnknownFileType(STRING_UNKNOWNFILETYPE,Main::processInstance());
String errorItemsNotPresent(STRING_UNKNOWNREFERENCE,Main::processInstance());
ifstream inputStream(pathFileNameString);
Bitmap selectedBitmap;
int errorCount(0);
String tempString;
inputStream.get(tempString,String::MaxString-1,*crlfString);
if(!(tempString==projectIDString))
{
::MessageBox(GetHandle(),(LPSTR)errorUnknownFileType,(LPSTR)pathFileNameString,MB_OK);
return;
}
waitCursor(TRUE);
::SendMessage(::GetDlgItem(GetHandle(),SS_LIST),WM_SETREDRAW,FALSE,0L);
while(!inputStream.bad()&&!inputStream.fail())
{
inputStream >> tempString;
if(tempString.isNull())continue;
if(selectedBitmap.isValidBitmap(tempString))
::SendDlgItemMessage(GetHandle(),SS_LIST,LB_ADDSTRING,0,(LPARAM)(LPCSTR)tempString);
else errorCount++;
}
waitCursor(FALSE);
::SendMessage(::GetDlgItem(GetHandle(),SS_LIST),WM_SETREDRAW,TRUE,0L);
if(errorCount)
::MessageBox(GetHandle(),(LPSTR)errorItemsNotPresent,(LPSTR)"Error loading project",MB_OK);
}