×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    29

    Custom Control in a Dialog

    I cannot seem to successfully display a custom compound control within a dialog.

    The code is copied from "Symbian OS: Creating
    Custom Controls v1.0", and adapted so that it will compile.

    The background gets grayed out, but nothing is displayed except the softkey buttons. What is wrong with that code.

    S60 3rd Edition MR.

    Relevant code

    called with
    Code:
    CSpecialCharDialog* dlg = new (ELeave) CSpecialCharDialog();
    dlg->ExecuteLD(R_BLINKER_DIALOG);
    Dialog code
    Code:
    SEikControlInfo 
    CSpecialCharDialog::CreateCustomControlL (TInt  aControlType)
    {
    	SEikControlInfo controlInfo;
    	controlInfo.iTrailerTextId = 0;
    	controlInfo.iFlags = 0;
    	
    	switch (aControlType)
    	{
    	case KBlinkTextType:
    	{
    		CBlinkText *txt = new (ELeave) CBlinkText();
    		controlInfo.iControl = txt;
    	}break;
    	default:
            return CEikDialog::CreateCustomControlL(aControlType);
    	}
        return controlInfo;
    }
    control code
    Code:
    void CBlinkText::ConstructFromResourceL(TResourceReader& aReader) 
    { 
    	iLabel = new (ELeave) CEikLabel(); 
    	iLabel->SetContainerWindowL(*this); 
    	iTicker = CPeriodic::NewL(CActive::EPriorityIdle); 
    	TPtrC label = aReader.ReadTPtrC16(); 
    	iLabel->SetTextL(label); 
    	const TInt interval = aReader.ReadInt32(); 
    	Start(interval); 
    	iLabel->MakeVisible(ETrue);
    	iLabel->ActivateL();
    	ActivateL();
    }
    .rh file
    Code:
    STRUCT BLINKTEXT 
    { 
    	LTEXT txt; 
    	LONG period = 2000000; 
    }
    .rss file
    Code:
    RESOURCE DIALOG r_blinker_dialog 
    { 
    	flags = EEikDialogFlagWait;  
    	title = "Blinker"; 
    	buttons = R_AVKON_SOFTKEYS_OK_CANCEL; 
    	items =  
        { 
    		DLG_LINE 
    		{ 
    			type = KBlinkTextType; 
    			id = KBlinkLabelId;
    			control = BLINKTEXT 
    			{ 
    				txt="hello world"; 
    				period=1000000; 
    			}; 
    		} 
        }; 
    }
    hrh file
    Code:
    enum 
    {
    	KCtSpecialKeyControl = KAknCtLastControlId ,
    	KBlinkTextType
    }; 
    
    enum
    {
    	KCtSpecialKeyControlId = 0x10,
    	KBlinkLabelId
    };

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    29

    Re: Custom Control in a Dialog

    OK so the control should be window owning. If someone from documentation stumbles across this thread, please update the "Symbian OS: Creating Custom Controls" document.

    But now the control is displayed in top left corner of screen, not exactly what I want. How can the extend be set correctly?

    Code:
    void CBlinkText::ConstructFromResourceL(TResourceReader& aReader) 
    { 
    	CreateWindowL();
    	iLabel = new (ELeave) CEikLabel(); 
    	iLabel->SetContainerWindowL(*this); 
    	iTicker = CPeriodic::NewL(CActive::EPriorityIdle); 
    	TPtrC label = aReader.ReadTPtrC16(); 
    	iLabel->SetTextL(label); 
    	const TInt interval = aReader.ReadInt32(); 
    	Start(interval); 
    	iLabel->MakeVisible(ETrue);
    	iLabel->ActivateL();
    	ActivateL();
    }
    Last edited by wernerkriel; 2007-11-12 at 07:25.

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,673

    Re: Custom Control in a Dialog

    You should set the size and the position of the control. check CCoeControl::SetRect/SetSize/SetPosition/SetExtent/SetExtentToWholeScreen. If you do not set anything, the default is 0 for everything - as usually in case of a C-class. And 0,0 is the top-left corner obviously.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    29

    Re: Custom Control in a Dialog

    Thanks wizard, but that only works partially, Setting the rectangle calls SizeChanged(). Position() returns correct position, but then for some reason SizeChanged() is called again, now Position() returns (0,0), Size() is correct. When Draw() is called the TRect parameter has position of (0,0).

    It seems to me custom controls is not really supported, or broken.

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,673

    Re: Custom Control in a Dialog

    Could you post the new snippet (where you invoke SetAnything), including your SizeChanged method?

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    29

    Re: Custom Control in a Dialog

    Hi
    Code:
    CBlinkText::ConstructFromResourceL(TResourceReader& aReader)
    {
    	...
    	...
    	SetRect(TRect(0,40,352,420));
    	iLabel->MakeVisible(ETrue);
    	iLabel->ActivateL()
    }
    Code:
    void 
    CBlinkText::SizeChanged() 
    { 
    	iLabel->SetExtent(Position(),Size()); 
    }

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,673

    Re: Custom Control in a Dialog

    The top-left corner of a window-owning control is always 0,0 (since these coordinates are relative to the window), that is the cause I think. Although it is not mentioned in Position, it is mentioned in Rect, which is the next method in the SDK Help.
    Your code apparently fills the rectangle, with the contained label. I do not see the problem with that. CEikLabel draws its content to the top-left corner I guess. You can try what happens if you use SetLabelAlignment.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    29

    Re: Custom Control in a Dialog

    Thanks for the effort Wizard.

    I've noticed the label is placed twice when it is moved that far down, one is placed in the top left of the screen, the other is placed where it should be. There is another white area, right below the topmost label and above the correct position.

    Both the labels appear grayed out, as if they are in the background. And nothing is flashing, although the debugger catches the timer callback function.

Similar Threads

  1. Custom Listbox in Dialog
    By enjo13 in forum Symbian
    Replies: 0
    Last Post: 2007-05-04, 01:35
  2. Custom control in CAknDialog
    By Diamond in forum Symbian User Interface
    Replies: 5
    Last Post: 2007-02-27, 12:14
  3. Replies: 1
    Last Post: 2006-06-26, 07:14
  4. custom control - clipping problem
    By boumitran in forum Symbian User Interface
    Replies: 0
    Last Post: 2006-05-17, 06:23
  5. yucca help, question about custom control in dialog
    By mobileworm in forum Symbian User Interface
    Replies: 0
    Last Post: 2005-10-05, 17:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×