From aeff0d150470ad484c315cb66d79c76b804d82b6 Mon Sep 17 00:00:00 2001 From: ehouse Date: Tue, 18 Jan 2005 14:49:23 +0000 Subject: [PATCH] first checked in; works but confirm and rename pending --- symbian/inc/symgmdlg.h | 57 ++++++++++++++++ symbian/src/symgmdlg.cpp | 140 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100755 symbian/inc/symgmdlg.h create mode 100755 symbian/src/symgmdlg.cpp diff --git a/symbian/inc/symgmdlg.h b/symbian/inc/symgmdlg.h new file mode 100755 index 000000000..d42e0c408 --- /dev/null +++ b/symbian/inc/symgmdlg.h @@ -0,0 +1,57 @@ +/* -*-mode: C; fill-column: 78; c-basic-offset: 4;-*- */ +/* + * Copyright 2005 by Eric House (fixin@peak.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _SYMGMDLG_H_ +#define _SYMGMDLG_H_ + +extern "C" { +#include "comtypes.h" +#include "mempool.h" +} + +#include +#include + +#include "symgmmgr.h" + +class CXSavedGamesDlg : public CEikDialog +{ + public: + static TBool DoGamesPicker( MPFORMAL CXWGamesMgr* aGameMgr, + const TGameName* aCurName, TGameName* result ); + + private: + CXSavedGamesDlg( MPFORMAL CXWGamesMgr* aGameMgr, + const TGameName* aCurName, TGameName* result ); + + TBool OkToExitL( TInt aKeyCode ); + void PreLayoutDynInitL(); + + void ResetNames( TInt aPrefIndex ); + TBool ConfirmDelete(); + void EditSelName(); + + CXWGamesMgr* iGameMgr; /* I don't own this */ + const TGameName* iCurName; + TGameName* iResultP; /* ditto */ + MPSLOT +}; + + +#endif diff --git a/symbian/src/symgmdlg.cpp b/symbian/src/symgmdlg.cpp new file mode 100755 index 000000000..c7f4a4baf --- /dev/null +++ b/symbian/src/symgmdlg.cpp @@ -0,0 +1,140 @@ +/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ +/* + * Copyright 2005 by Eric House (fixin@peak.org). + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +#include "symgmdlg.h" +#include "symutil.h" +#include "xwords.hrh" +#include "xwords.rsg" + + +CXSavedGamesDlg::CXSavedGamesDlg( MPFORMAL CXWGamesMgr* aGameMgr, + const TGameName* aCurName, TGameName* result ) + : iGameMgr(aGameMgr), iCurName(aCurName), iResultP(result) +{ + MPASSIGN( this->mpool, mpool ); +} + +void +CXSavedGamesDlg::PreLayoutDynInitL() +{ + ResetNames(-1); +} + +TBool +CXSavedGamesDlg::OkToExitL( TInt aKeyCode ) +{ + TBool canReturn = EFalse; + TInt index; + CEikTextListBox* box; + const CListBoxView::CSelectionIndexArray* indices; + box = static_cast(Control(ESelGameChoice)); + + XP_LOGF( "CXSavedGamesDlg::OkToExitL(%d) called", aKeyCode ); + + switch( aKeyCode ) { + case XW_SGAMES_OPEN_COMMAND: + indices = box->SelectionIndexes(); + if ( indices->Count() > 1 ) { + XP_LOGF( "too many selected" ); + } else { + /* Don't use indices: invalid when multi-select isn't on? */ + // TInt index = indices->At(0); + index = box->CurrentItemIndex(); + XP_LOGF( "the %dth is selected:", index ); + *iResultP = (*iGameMgr->GetNames())[index]; + XP_LOGDESC16( iResultP ); + canReturn = ETrue; + } + break; + + case XW_SGAMES_RENAME_COMMAND: + EditSelName(); + break; + + case XW_SGAMES_DELETE_COMMAND: { + XP_LOGF( "delete" ); + index = box->CurrentItemIndex(); + TDesC16* selName = &(*iGameMgr->GetNames())[index]; + if ( 0 == selName->Compare(*iCurName) ) { + /* Warn user why can't delete */ + } else if ( ConfirmDelete() ) { + if ( iGameMgr->DeleteSelected( index ) ) { + ResetNames( index ); + box->DrawDeferred(); + } + } + } + break; + case EEikBidCancel: + canReturn = ETrue; + } + + return canReturn; +} /* OkToExitL */ + +void +CXSavedGamesDlg::ResetNames( TInt aPrefIndex ) +{ + /* PENDING aPrefIndex is a hint what to select next */ + + CDesC16Array* names = iGameMgr->GetNames(); + TInt index; + + if ( 0 != names->Find( *iCurName, index ) ) { + XP_LOGF( "Unable to find" ); + XP_LOGDESC16( iCurName ); + XP_ASSERT( 0 ); + index = 0; /* safe default if not found */ + } + + CEikTextListBox* box; + box = static_cast(Control(ESelGameChoice)); + + box->Model()->SetItemTextArray( names ); + box->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); + box->HandleItemAdditionL(); + box->SetCurrentItemIndex( index ); +} /* ResetNames */ + +TBool +CXSavedGamesDlg::ConfirmDelete() +{ + return ETrue; +} /* ConfirmDelete */ + +void +CXSavedGamesDlg::EditSelName() +{ +} + +/* static */ TBool +CXSavedGamesDlg::DoGamesPicker( MPFORMAL CXWGamesMgr* aGameMgr, + const TGameName* aCurName, TGameName* result ) +{ + CXSavedGamesDlg* me = new CXSavedGamesDlg( MPPARM(mpool) + aGameMgr, aCurName, result ); + User::LeaveIfNull( me ); + + return me->ExecuteLD( R_XWORDS_SAVEDGAMES_DLG ); +} // DoGamesPicker