📄 commands1.cpp
字号:
void CAppSpecificListView::HandleListBoxEventL(
//
// List box event occured - its reporting back what that might be.
//
CQikListBox* aListBox,
TQikListBoxEvent aEventType,
TInt aItemIndex,
TInt aSlotId)
{
switch (aEventType)
{
case EEventItemConfirmed:
case EEventItemTapped:
{
MQikListBoxData* lbData=aListBox->Model().RetrieveDataL(aItemIndex);
CleanupClosePushL(*lbData); // its retrieved in an 'Open' state
iEikonEnv->InfoMsg(lbData->Text(EQikListBoxSlotText1));
CleanupStack::PopAndDestroy(lbData); // closes the item
break;
}
default:
break;
}
}
const TInt KCommand1Items=7;
void CAppSpecificListView::UpdateList1CommandAvailability()
//
// We can adjust the availabilty of commands based on our internal state. In this
// example we make the Add/Delete commands available dependant on the number of entries
// that exist.
//
// NOTE:
// Rather than explictly Dim or Hide we make the command unavailable. The device specific
// configuration will map that onto the current device preference of dimmed or invisibile
// commands.
//
{
// if we have less than 4 items in the list box we disable the delete menu option
CQikCommandManager& cm=CQikCommandManager::Static();
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId1);
TBool avail=EFalse;
if (listbox->ItemCount()>=4)
avail=ETrue;
cm.SetAvailable(*this,EAppCmdDelete3,avail);
// if we have less than max items in the list box we enable the add menu option
avail=EFalse;
if (listbox->ItemCount()<KCommand1Items)
avail=ETrue;
cm.SetAvailable(*this,EAppCmdAdd2,avail);
}
void CAppSpecificListView::AddSingleItemToList1L()
//
// Add a single item to the list box
//
{
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId1);
MQikListBoxModel& model(listbox->Model());
model.ModelBeginUpdateLC();
// In our example application we restrict the number of items by dimming the create
// menu option if the list contains KCommand1Items. Therefore the resource read to
// form the entry content is guaranteed to be sensible.
TBuf<KMaxListItemText>bb;
MQikListBoxData* lbData=model.NewDataLC(MQikListBoxModel::EDataNormal);
iEikonEnv->ReadResourceL(bb,R_STR_LIST_ALT_CONTENT_1+listbox->ItemCount()-1);
lbData->AddTextL(bb,EQikListBoxSlotText1);
CleanupStack::PopAndDestroy(lbData);
// we should maintain the list in sorted order, so whilst we have an open model
// sort the list items
TLinearOrder<MQikListBoxData> compare(CAppSpecificListView::SortComparisonFunction);
model.Sort(compare);
model.ModelEndUpdateL();
// now ensure only those commands that are legal given our internal state are
// presented to the user to choose between
UpdateList1CommandAvailability();
}
void CAppSpecificListView::DeleteItemFromList1L()
//
// Delete the currently highlighted record.
//
{
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId1);
listbox->RemoveItemL(listbox->CurrentItemIndex());
// our command set is dependant on number of records so update now record count changed.
UpdateList1CommandAvailability();
}
void CAppSpecificListView::AddItemsToList1L()
//
// We are a single line list box. Add each of the items to the listbox for display
//
{
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId1);
MQikListBoxModel& model(listbox->Model());
model.ModelBeginUpdateLC();
TBuf<KMaxListItemText>bb;
for (TInt i=0;i<KCommand1Items;i++)
{
MQikListBoxData* lbData=model.NewDataLC(MQikListBoxModel::EDataNormal);
iEikonEnv->ReadResourceL(bb,R_STR_LIST_CONTENT_1+i);
lbData->AddTextL(bb,EQikListBoxSlotText1);
CleanupStack::PopAndDestroy(lbData);
}
model.ModelEndUpdateL();
// now ensure only those commands that are legal given our internal state are
// presented to the user to choose between
UpdateList1CommandAvailability();
}
void CAppSpecificListView::AddItemsToList2L()
//
// We are a single line list box. Add each of the items to the listbox for display
//
{
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId2);
MQikListBoxModel& model(listbox->Model());
model.ModelBeginUpdateLC();
TBuf<KMaxListItemText>bb;
for (TInt i=0;i<KCommand1Items;i++)
{
MQikListBoxData* lbData=model.NewDataLC(MQikListBoxModel::EDataNormal);
iEikonEnv->ReadResourceL(bb,R_STR_LIST_ALT_CONTENT_1+i);
lbData->AddTextL(bb,EQikListBoxSlotText1);
CleanupStack::PopAndDestroy(lbData);
}
model.ModelEndUpdateL();
}
CQikCommand* CAppSpecificListView::DynInitOrDeleteCommandL(
//
// As commands are added to the view we get the opportunity to perform some actions.
// In this case we want to ensure the Radio buttons and SortOrder check item are correct.
//
CQikCommand* aCommand,
const CCoeControl& aControlAddingCommands)
{
TBool val=EFalse;
switch (aCommand->Id())
{
// determine which of the radio buttons should be checked
case EAppCmdSortType1:
if (iEngine->ListViewSortType()==ESortType1)
val=ETrue;
aCommand->SetChecked(val);
break;
case EAppCmdSortType2:
if (iEngine->ListViewSortType()==ESortType2)
val=ETrue;
aCommand->SetChecked(val);
break;
case EAppCmdSortType3:
if (iEngine->ListViewSortType()==ESortType3)
val=ETrue;
aCommand->SetChecked(val);
break;
// determine whether the single check box type menu option should be checked
case EAppCmdSortOrder:
if (iEngine->ListViewSortOrder()==ESortOrderAscending)
val=ETrue;
aCommand->SetChecked(val);
break;
default:
break;
}
return(aCommand);
}
void CAppSpecificListView::ViewConstructL()
{
ViewConstructFromResourceL(R_LIST_VIEW_CONFIGURATIONS);
// determine zoom level last used (we dont currently load/save when apps exit)
CQikViewBase::SetZoomFactorL(CQikAppUi::ZoomFactorL(iEngine->ListViewZoomState(),*iEikonEnv));
// we want to HandleListBoxEventL() - so observe the listboxes
LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId1)->SetListBoxObserver(this);
// set the line below app name to be "List title"
TBuf<64>bb;
iEikonEnv->ReadResourceL(bb,R_STR_LIST_TITLE);
ViewContext()->AddTextL(1,bb);
AddItemsToList1L();
AddItemsToList2L();
// we should ensure the list view sorted order is the same as the engine
// and UI are currently reporting
SortList1L();
}
void CAppSpecificListView::ViewDeactivated()
//
// The view is being de-activated.
//
{
}
void CAppSpecificListView::ViewActivatedL(
//
// The view is being activated.
//
const TVwsViewId& aPrevViewId,
const TUid aCustomMessageId,
const TDesC8& aCustomMessage)
{
}
void CAppSpecificListView::TabActivatedL(TInt aTabId)
//
// Called from the framework when a tab is activated.
//
{
CQikCommandManager& cm=CQikCommandManager::Static();
if (aTabId==EAppSpecificListViewPageId1)
{ // Page 1 adds a Create and erase command
cm.InsertIntoCommandListL(*this,*this,R_ALTERNATE_COMMANDS);
// remove any sort commands added if we tabbed to page 2
// these are harmless if the command has not been added when called.
cm.DeleteCommand(*this,EAppCmdSortAltType1);
cm.DeleteCommand(*this,EAppCmdSortAltType2);
UpdateList1CommandAvailability();
}
else
{
// remove any create + erase commands added in page 1
cm.DeleteFromCommandList(*this,R_ALTERNATE_COMMANDS);
// manually add a couple of sort commands
TBuf<64>bb;
CQikCommand* q=CQikCommand::NewLC(EAppCmdSortAltType1);
q->SetType(EQikCommandTypeScreen);
q->SetPriority(EAppCmdSortType1Priority);
q->SetGroupId(EAppCmdSortGroup);
q->SetIcon(KMbmFile,EMbmCommands1Icon0,EMbmCommands1Icon0mask);
iEikonEnv->ReadResourceL(bb,R_STR_SORT_TYPE1);
q->SetTextL(bb);
q->SetHandler(this); // we implement MQikCommandHandler
cm.InsertCommandL(*this,q);
CleanupStack::Pop(q);
q=CQikCommand::NewLC(EAppCmdSortAltType2);
q->SetType(EQikCommandTypeScreen);
q->SetPriority(EAppCmdSortType1Priority);
q->SetGroupId(EAppCmdSortGroup);
q->SetIcon(KMbmFile,EMbmCommands1Icon1,EMbmCommands1Icon1mask);
iEikonEnv->ReadResourceL(bb,R_STR_SORT_TYPE2);
q->SetTextL(bb);
q->SetHandler(this); // we implement MQikCommandHandler
cm.InsertCommandL(*this,q);
CleanupStack::Pop(q);
}
// let base class perform its work
CQikMultiPageViewBase::TabActivatedL(aTabId);
}
//////////////////////////////////////////////////////////////////////////////
CAppSpecificUi::~CAppSpecificUi()
{
delete(iEngine);
}
CAppEngine* CAppSpecificUi::AppEngine() const
{
return(iEngine);
}
void CAppSpecificUi::ConstructL()
//
// Normal primary entry point to a Symbian App
//
{
CQikAppUi::ConstructL();
iEngine=new(ELeave)CAppEngine(EQikCmdZoomLevel2);
CAppSpecificListView* q=new(ELeave)CAppSpecificListView(*this,iEngine);
CleanupStack::PushL(q);
q->ConstructL();
AddViewL(*q); // takes ownership
CleanupStack::Pop(q);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificDocument : public CQikDocument
{
protected:
CQikAppUi* CreateAppUiL();
public:
CAppSpecificDocument(CQikApplication& aApp);
static CAppSpecificDocument* NewL(CQikApplication& aApp);
protected:
};
CAppSpecificDocument::CAppSpecificDocument(CQikApplication& aApp) :
CQikDocument(aApp)
{
__DECLARE_NAME(_S("CAppSpecificDocument"));
}
CAppSpecificDocument* CAppSpecificDocument::NewL(CQikApplication& aApp)
{
return(new(ELeave)CAppSpecificDocument(aApp));
}
CQikAppUi* CAppSpecificDocument::CreateAppUiL()
{
return(new(ELeave)CAppSpecificUi);
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificApplication : public CQikApplication
{
protected:
TUid AppDllUid() const;
CApaDocument* CreateDocumentL();
};
TUid CAppSpecificApplication::AppDllUid() const
{
return(KAppSpecificUid);
}
CApaDocument* CAppSpecificApplication::CreateDocumentL()
{
return(CAppSpecificDocument::NewL(*this));
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application start up code
LOCAL_C CApaApplication* NewApplication()
{
return(new CAppSpecificApplication);
}
GLDEF_C TInt E32Main()
{
return(EikStart::RunApplication(NewApplication));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -