Files
Work/guitar/tabdlg.cpp
2024-08-07 09:16:27 -04:00

157 lines
4.8 KiB
C++

#include <guitar/tabdlg.hpp>
#include <guitar/guitar.hpp>
#include <common/puredwrd.hpp>
TabDialog::TabDialog(void)
: mCurrEntryIndex(0)
{
mInitHandler.setCallback(this,&TabDialog::initHandler);
mCreateHandler.setCallback(this,&TabDialog::createHandler);
mCloseHandler.setCallback(this,&TabDialog::closeHandler);
mDestroyHandler.setCallback(this,&TabDialog::destroyHandler);
mCommandHandler.setCallback(this,&TabDialog::commandHandler);
insertHandler(VectorHandler::InitDialogHandler,&mInitHandler);
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
insertHandler(VectorHandler::CloseHandler,&mCloseHandler);
insertHandler(VectorHandler::CommandHandler,&mCommandHandler);
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
}
TabDialog::TabDialog(const TabDialog &someTabDialog)
{ // private implementation
*this=someTabDialog;
}
TabDialog::~TabDialog()
{
removeHandler(VectorHandler::InitDialogHandler,&mInitHandler);
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
removeHandler(VectorHandler::CloseHandler,&mCloseHandler);
removeHandler(VectorHandler::CommandHandler,&mCommandHandler);
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
}
TabDialog &TabDialog::operator=(const TabDialog &someTabDialog)
{ // private implementation
return *this;
}
bool TabDialog::perform(GUIWindow &parentWindow,TabEntries &entries,int currEntryIndex)
{
mTabEntries=SmartPointer<TabEntries>(&entries);
mCurrEntryIndex=currEntryIndex;
return ::DialogBoxParam(processInstance(),(LPSTR)"TABDIALOG",(HWND)parentWindow,DWindow::DlgProc,(LPARAM)(DWindow*)this);
}
CallbackData::ReturnType TabDialog::initHandler(CallbackData &someCallbackData)
{
Block<PureDWORD> stops;
mTabEntryList=::new OwnerDrawListAltColor(*this,getItem(TABENTRY_LIST),TABENTRY_LIST);
mTabEntryList.disposition(PointerDisposition::Delete);
stops.insert(&PureDWORD(15));
stops.insert(&PureDWORD(35));
stops.insert(&PureDWORD(50));
mTabEntryList->setTabStops(stops);
setTypes();
TabEntry &entry=(*mTabEntries)[mCurrEntryIndex];
if(entry.hasSeparator())sendMessage(TABENTRY_SEPARATOR,BM_SETCHECK,1,0L);
for(int index=0;index<entry.size();index++)
{
String strLine;
FrettedNote &frettedNote=entry[index];
strLine+=String(" ")+String().fromInt(frettedNote.getString()+1)+String("\t");
strLine+=String().fromInt(frettedNote.getFret())+String("\t");
strLine+=((Note&)frettedNote).toString();
mTabEntryList->insertString(strLine);
}
if(!entry.getComment().isNull())setText(TABENTRY_COMMENTS,entry.getComment());
mTabEntryList->setCurrent(0);
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType TabDialog::createHandler(CallbackData &someCallbackData)
{
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType TabDialog::closeHandler(CallbackData &someCallbackData)
{
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType TabDialog::destroyHandler(CallbackData &someCallbackData)
{
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType TabDialog::commandHandler(CallbackData &someCallbackData)
{
switch(someCallbackData.wmCommandID())
{
case IDCANCEL :
endDialog(false);
break;
case IDOK :
handleOk();
endDialog(true);
break;
}
return (CallbackData::ReturnType)FALSE;
}
void TabDialog::setTypes()
{
Array<String> notes;
sendMessage(TABENTRY_NOTETYPE,CB_RESETCONTENT,0,0L);
notes=NoteType::enumerate();
int currSel=-1;
TabEntry &entry=(*mTabEntries)[mCurrEntryIndex];
for(int index=0;index<notes.size();index++)
{
sendMessage(TABENTRY_NOTETYPE,CB_ADDSTRING,0,(LPARAM)(LPSTR)notes[index].str());
if(notes[index].equals(entry.getNoteType().toString()))currSel=index;
}
if(-1==currSel)
{
int itemCount;
sendMessage(TABENTRY_NOTETYPE,CB_ADDSTRING,0,(LPARAM)(LPSTR)entry.getNoteType().toString());
itemCount=sendMessage(TABENTRY_NOTETYPE,CB_GETCOUNT,0,0L);
sendMessage(TABENTRY_NOTETYPE,CB_SETCURSEL,itemCount-1,0L);
}
else sendMessage(TABENTRY_NOTETYPE,CB_SETCURSEL,currSel,0L);
}
void TabDialog::handleOk(void)
{
LRESULT currSel;
String selText;
String comments;
bool applyRemainder;
bool separator;
currSel=sendMessage(TABENTRY_NOTETYPE,CB_GETCURSEL,0,0L);
sendMessage(TABENTRY_NOTETYPE,CB_GETLBTEXT,currSel,(LPARAM)selText.str());
applyRemainder=sendMessage(TABENTRY_REMAINDER,BM_GETCHECK,0,0L);
separator=sendMessage(TABENTRY_SEPARATOR,BM_GETCHECK,0,0L);
NoteType noteType(NoteType().fromString(selText));
comments=getText(TABENTRY_COMMENTS);
comments.removeTokens("\"");
TabEntry &entry=(*mTabEntries)[mCurrEntryIndex];
entry.setComment(comments);
entry.hasSeparator(separator);
if(applyRemainder)
{
for(int index=mCurrEntryIndex;index<mTabEntries->size();index++)
{
TabEntry &entry=(*mTabEntries)[index];
entry.setNoteType(noteType);
}
}
else
{
TabEntry &entry=(*mTabEntries)[mCurrEntryIndex];
entry.setNoteType(noteType);
}
}