Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User Kolayuk's Avatar
    Join Date
    Mar 2010
    Posts
    42
    Здравствуйте, у меня есть кастомный диалог (CAknDialog) с моими контролами, который при наступлении определенного события надо закрыть. Как это сделать? Попробовал TryExitL(EAknSoftkeyOk); - получил панику KERN EXEC 3. Хотя посмотел диалоги в PDK, которые сами закрываются после выбора, там TryExitL используется. Что я делаю неверно? Спасибо.

    Контрол и диалог
    Code:
    /*
     ============================================================================
     Name		: SelectKeyControl.cpp
     Author	  : Usanov-Kornilov Nikolay (aka Kolay)
     Version	 : 1.0
     Copyright   : 
     Contacts:
     kolayuk@mail.ru
     http://kolaysoft.ru
    
     (c) KolaySoft, 2010
    
     Description : CSelectKeyControl implementation
     ============================================================================
     */
    
    #include "SelectKeyControl.h"
    #include <aknsutils.h>
    #include <aknutils.h>
    #include <akniconutils.h>
    #include <MusicBar_ui.mbg>
    #include <BARSREAD.H>
    #include <ButtonContainer.h>
    #include <MusicBar.rsg>
    #include "Main.hrh"
    #include <MusicBarAppUi.h>
    
    
    CSelectKeyDialog::CSelectKeyDialog(TInt& aVal): CAknDialog(), MButtonCB(),iVal(aVal)
    	{
    	// No implementation required
    	}
    
    TInt CSelectKeyDialog::RunDlgLD(TInt& aVal)
        {
    	CSelectKeyDialog* dlg = new (ELeave) CSelectKeyDialog(aVal);
    	return dlg->ExecuteLD(R_SELECT_KEY_DIALOG);
        }
     
    void CSelectKeyDialog::PostLayoutDynInitL()
    	{
    	CSelectKeyControl* control = (CSelectKeyControl*)Control(KMyCustomCtlId);
        control->SetCallBack(this);
        if (iVal!=0) {control->SetVal(iVal);}
        ButtonGroupContainer().MakeVisible(EFalse);
    	TInt scrX=CEikonEnv::Static()->ScreenDevice()->SizeInPixels().iWidth;
    	TInt scrY=CEikonEnv::Static()->ScreenDevice()->SizeInPixels().iHeight;    
    	TRect r=TRect(TPoint(scrX/4,scrY/3),TSize(scrX/2,scrY/3));
    	control->ShrinkRects(r,EDirectionVertical);
    	control->MakeVisible(ETrue);
    	}
    
    SEikControlInfo CSelectKeyDialog::CreateCustomControlL(TInt aControlType)
        {
        SEikControlInfo controlInfo;
        controlInfo.iControl = NULL ;
        controlInfo.iTrailerTextId = 0 ;
        controlInfo.iFlags = 0 ;
     
        switch (aControlType)
            {
            // CMyControl custom control type (defined in multiviews.hrh)
            case KMyCustomCtl:
                {
                controlInfo.iControl = new (ELeave)CSelectKeyControl();
                break;
                }
            default:
                break;
            }
        return controlInfo;
        }
    TBool CSelectKeyDialog::OkToExitL(TInt aButtonID)
    	{
    	CSelectKeyControl* control = (CSelectKeyControl*)Control(KMyCustomCtlId);
    	if (aButtonID=EAknSoftkeyOk)
    		{
    		iVal=control->GetVal();
    		}
    	//TRAPD(err,CEikonEnv::Static()->AppUi()->RemoveFromStack(control));
    	return ETrue; //breakpoint - ok
    	}
    void CSelectKeyDialog::ButtonPressed()
    	{
    	CAknDialog::TryExitL(EAknSoftkeyOk);
    	//iButtonGroupContainer->
    	}
    
    
    
    CSelectKeyControl::CSelectKeyControl(): CCoeControl(), MCoeControlObserver()
    	{
    	// No implementation required
    	}
    
    CSelectKeyControl::~CSelectKeyControl()
    	{
    	for (TInt i=0;i<iHandles.Count();i++)
    		{
    		CEikonEnv::Static()->RootWin().CancelCaptureKeyUpAndDowns(iHandles[i]);
    		}
    	Components().ResetAndDestroy();
    	delete iIcon;
    	}
    
    CSelectKeyControl* CSelectKeyControl::NewLC(CCoeControl* aParent,TInt aResId)
    	{
    	CSelectKeyControl* self = new (ELeave) CSelectKeyControl();
    	CleanupStack::PushL(self);
    	self->ConstructL(aParent,aResId);
    	return self;
    	}
    
    CSelectKeyControl* CSelectKeyControl::NewL(CCoeControl* aParent,TInt aResId)
    	{
    	CSelectKeyControl* self = CSelectKeyControl::NewLC(aParent,aResId);
    	CleanupStack::Pop(); // self;
    	return self;
    	}
    void CSelectKeyControl::SetVal(TInt aVal)
    	{
    	iVal=aVal;
    	TBuf<3> txt;
    	txt.Num(iVal);
    	iLabelKey->SetTextL(txt);
    	DrawNow();
    	}
    TInt CSelectKeyControl::GetVal()
    	{
    	return iVal;
    	}
    void CSelectKeyControl::ConstructL(CCoeControl* aParent,TInt aResId)
    	{
    	TResourceReader reader;
    	CEikonEnv::Static()->CreateResourceReaderLC(reader,aResId);
    	CleanupStack::Pop(1); //reader
    	//ConstructFromResourceL(reader);
    	}
    
    void CSelectKeyControl::LoadPicture()
    	{
    	CFbsBitmap* mask;
    	CFbsBitmap* icon;
    	_LIT(KPath,"\\resource\\apps\\MusicBar_ui.mif");
    	AknIconUtils::CreateIconL(icon,mask,KPath,EMbmMusicbar_uiButton_dlg_bg,EMbmMusicbar_uiButton_dlg_bg_mask);
    	AknIconUtils::SetSize(icon,Size(),EAspectRatioNotPreserved);
    	AknIconUtils::SetSize(mask,Size(),EAspectRatioNotPreserved);
    	iIcon=CGulIcon::NewL(icon,mask);
    	}
    void CSelectKeyControl::Draw(const TRect& aRect) const
    	{
    	CWindowGc& gc=SystemGc();
    	gc.Clear(Rect());
    	gc.BitBltMasked(TPoint(0,0),iIcon->Bitmap(),TRect(TPoint(0,0),iIcon->Bitmap()->SizeInPixels()),iIcon->Mask(),EFalse);
    	}
    
    void CSelectKeyControl::ShrinkRects(TRect aRect,TInt aDir)
    	{
    	SetExtent(aRect.iTl,aRect.Size());
    	CCoeControlArray::TCursor cursor = Components().Begin();
    	CCoeControl* ctrl = NULL;
    	TInt i=0;
    	TRect r;
    	while ((ctrl = cursor.Control<CCoeControl>()) != NULL)
    	    {
    		if (aDir==EDirectionHorizontal)
    			{
    			TInt w=aRect.Size().iWidth/Components().Count();
    			TInt h=aRect.Size().iHeight;
    			r=TRect(i*w,0,(i+1)*w,aRect.Height());
    			}
    		else if (aDir==EDirectionVertical)
    			{
    			TInt w=aRect.Size().iWidth;
    			TInt h=aRect.Size().iHeight/Components().Count();
    			r=TRect(0,h*i,aRect.Width(),h*(i+1));
    			}		
    		ctrl->SetRect(r);
    	    cursor.Next();
    	    i++;
    	    }
    	}
    void CSelectKeyControl::HandleControlEventL(CCoeControl* aControl,enum TCoeEvent aEvent)
    	{
    	if (aControl==iButton&&aEvent==EEventStateChanged)
    		{
    		if (iCallBack){ iCallBack->ButtonPressed();}
    		}		
    	}
    TKeyResponse CSelectKeyControl::OfferKeyEventL(const TKeyEvent& aKeyEvent, enum TEventCode aType)
    	{
    	TBuf<3> txt;
    	iVal=aKeyEvent.iScanCode;
    	txt.Num(aKeyEvent.iScanCode);
    	iLabelKey->SetTextL(txt);
    	DrawNow();
    	return EKeyWasConsumed;
    	}
    
    void CSelectKeyControl::SizeChanged()
    	{
    	if (iIcon)
    		{
    		AknIconUtils::SetSize(iIcon->Bitmap(),Size(),EAspectRatioNotPreserved);
    		AknIconUtils::SetSize(iIcon->Mask(),Size(),EAspectRatioNotPreserved);
    		}
    	if (iButton)
    		{
    		iButton->SetIconScaleMode(EAspectRatioNotPreserved);
    		iButton->SetIconSize(iButton->Size());
    		iButton->SetTextAndIconAlignment(CAknButton::EOverlay);
    		}
        TInt scrX=CEikonEnv::Static()->ScreenDevice()->SizeInPixels().iWidth;
        TInt scrY=CEikonEnv::Static()->ScreenDevice()->SizeInPixels().iHeight;    
        TRect r=TRect(TPoint(scrX/4,scrY/3),TSize(scrX/2,scrY/3));
        if (Position().iY!=r.iTl.iY){ShrinkRects(r,EDirectionVertical);}
    	CCoeControl::SizeChanged();
    	}
    void CSelectKeyControl::SetCallBack(MButtonCB* aCB)
    	{
    	iCallBack=aCB;
    	}
    void CSelectKeyControl::ConstructFromResourceL(TResourceReader& reader)
    	{
    	iVal=0;
    		CreateWindowL();
    		//SetExtentToWholeScreen();
    		LoadPicture();
    		
    		InitComponentArrayL();
    		
    		iLabel = new (ELeave) CEikLabel;
    		iLabel->SetContainerWindowL(*this);
    		TRgb lbc; 
    		MAknsSkinInstance* skin=AknsUtils::SkinInstance();
    		AknsUtils::GetCachedColor(skin,lbc,KAknsIIDQsnTextColors,EAknsCIQsnTextColorsCG6 );
    		iLabel->OverrideColorL(EColorLabelText,lbc);
    		iLabel->SetAlignment(EHCenterVCenter);
    		iLabel->MakeVisible(ETrue);
    		iLabel->SetTextL(reader.ReadTPtrC16());
    		Components().AppendLC(iLabel);
    		CleanupStack::Pop(iLabel);
    		
    		iLabelKey = new (ELeave) CEikLabel;
    		iLabelKey->SetContainerWindowL(*this);
    		AknsUtils::GetCachedColor(skin,lbc,KAknsIIDQsnTextColors,EAknsCIQsnTextColorsCG6 );
    		iLabelKey->OverrideColorL(EColorLabelText,lbc);
    		iLabelKey->SetAlignment(EHCenterVCenter);
    		iLabelKey->MakeVisible(ETrue);
    		iLabelKey->SetTextL(reader.ReadTPtrC());
    		Components().AppendLC(iLabelKey);
    		CleanupStack::Pop(iLabelKey);
    		
    		iButton=CAknButton::NewL();
    		iButton->SetContainerWindowL(*this);
    		TInt res=reader.ReadInt32();
    		iButton->ConstructFromResourceL(res);
    		iButton->SetObserver(this);
    		iButton->SetIconScaleMode(EAspectRatioNotPreserved);
    		iButton->SetIconSize(iButton->Size());
    		iButton->SetTextAndIconAlignment(CAknButton::EOverlay);
    		iButton->MakeVisible(ETrue);
    		Components().AppendLC(iButton,res);
    		CleanupStack::Pop(iButton);
    		
    		MakeVisible(EFalse);
    		ActivateL();
    		for (TInt i=1; i<=255;i++)
    		{
    			iHandles.Append(CEikonEnv::Static()->RootWin().CaptureKeyUpAndDowns(i,0,0));
    		}
    		
    	}
    При нажатии на iButton в контейнер-контроле вызывается CSelectKeyDialog::ButtonPressed() и диалог должен закрываться.
    Last edited by Kolayuk; 2010-12-12 at 17:21.

  2. #2
    Registered User arok666's Avatar
    Join Date
    Nov 2008
    Location
    Russia, Izhevsk
    Posts
    51
    Делал так
    Code:
    MakeVisible(EFalse);
    delete this;

  3. #3
    Nokia Developer Moderator A.A.M.'s Avatar
    Join Date
    Jan 2008
    Location
    Moscow, Russia
    Posts
    3,308

  4. #4
    Registered User Ktulhu's Avatar
    Join Date
    Sep 2009
    Posts
    33
    Возможно в дочерние контролы удаляются раньше, чем завершат работу со своими полями. Например если кнопка обрабатывает HandlePointerEventL потом вызывает callback, в котором диалог удаляется, потом диспатчит HandlePointerEventL или работает со своими полями то это легко приводит к обращению к невалидному адресу.

Similar Threads

  1. номер/значение версии программы в окне диалога "about"
    By Maxfox111 in forum Russian Developer Forum - Форум Российских разработчиков
    Replies: 1
    Last Post: 2009-03-30, 09:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved