Scroll down to see the controls drawn outside of ClientRect()!! Is it possible?
| Fri, 2005-12-02 13:43 | |
|
Hi
I want to draw some controls like CEikEdwin, CEikLabel, CEikSecreted etc.(there may be more than one control of a type). But the controls which are not drawn inside ClientRect(i.e the visible area of the mobile) are not shown. Can a scroll bar be put and we can scroll down to see the controls? or if any other way to do this. Any suggestions are appreciable. regards Satyajit |
|






Forum posts: 41
I am explaining my problem once again. I am drawing controls dynamically. The new controls are drawn just vertically below the previous control. So after 6/7 controls the new control is drawn out side of the ClientRect(); i.e. visible area, but it is drawn. So the control is not shown. how can i show these controls?
Please help me. it is urgent..
thanx
Satyajit
Forum posts: 41
I have drawn alternative Label and edwin controls dynamically. just changing the "noofctrl" to any integer that no of controls are drawn my code is as follows
The .cpp file
#include <eiklabel.h>
#include <eikedwin.h>
#include <barsread.h>
#include <badesca.h>
#include <eiktxlbm.h>
#include <test.rsg>
#include "testAppview1.h"
// Standard construction sequence
CtestAppview1* CtestAppview1::NewL(const TRect& aRect)
  {
  CtestAppview1* self = CtestAppview1::NewLC(aRect);
  CleanupStack::Pop(self);
  return self;
  }
CtestAppview1* CtestAppview1::NewLC(const TRect& aRect)
  {
  CtestAppview1* self = new (ELeave) CtestAppview1;
  CleanupStack::PushL(self);
  self->ConstructL(aRect);
  return self;
  }
CtestAppview1::CtestAppview1()
  {
// no implementation required
  }
CtestAppview1::~CtestAppview1()
  {
  for(TInt i=0;i<noofctrl;i++)
  {
  if(iCtrl[i])
  {
  delete iCtrl[i];
  iCtrl[i]=NULL;
  }
  }
// no implementation required
  }
void CtestAppview1::ConstructL(const TRect& aRect)
  {
  // Create a window for this application view1
  CreateWindowL();
  noofctrl=2;
  ycord = 5;
for(TInt i=0;i<noofctrl;i++)
{
if(i%2==0)
InitializeLabel(&iCtrl[i]);
else
InitializeEdwin(&iCtrl[i]);
}
iCtrl[1]->SetFocus(ETrue);
  // Set the windows size
  SetRect(aRect);
  // Activate the window, which makes it ready to be drawn
  ActivateL();
  }
// Draw this application's view1 to the screen
void CtestAppview1::Draw(const TRect& aRect) const
  {
  CWindowGc& gc = SystemGc();
  // TODO: Add your drawing code here
  // example code...
  gc.SetPenStyle( CGraphicsContext::ENullPen );
  gc.SetBrushColor( KRgbGray );
  gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
  gc.DrawRect( aRect );
  }
void CtestAppview1::SizeChanged()
  {
  // TODO: Add here control resize code etc.
  }
TInt CtestAppview1::CountComponentControls() const
  {
  return noofctrl; // return nbr of controls inside this container
  }
CCoeControl* CtestAppview1::ComponentControl(TInt aIndex) const
  {
  if(aIndex >= 0 && aIndex < noofctrl)
  return iCtrl[aIndex];
  else
  return NULL;
  }
TKeyResponse CtestAppview1::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
for(TInt i=1;i<noofctrl;i+=2)
{
if(iCtrl[i]->IsFocused())
{
if(aKeyEvent.iCode == EKeyDownArrow)
{
if((i+2)<noofctrl)
{
iCtrl[i]->SetFocus(EFalse);
iCtrl[i+2]->SetFocus(ETrue);
}
}
if(aKeyEvent.iCode == EKeyUpArrow)
{
if((i-2)>0)
{
iCtrl[i]->SetFocus(EFalse);
iCtrl[i-2]->SetFocus(ETrue);
}
}
return iCtrl[i]->OfferKeyEventL(aKeyEvent,aType);
}
}
  return EKeyWasNotConsumed;
}
void CtestAppview1::InitializeLabel(CCoeControl** iLabel)
{
  *iLabel = new (ELeave) CEikLabel;
  (*iLabel)->SetContainerWindowL( *this );
  ((CEikLabel*)*iLabel)->SetTextL( _L("Label") );
  (*iLabel)->SetExtent( TPoint(10,ycord), (*iLabel)->MinimumSize() );
  ycord+=(*iLabel)->Size().iHeight+5;
}
void CtestAppview1::InitializeEdwin(CCoeControl** iText)
{
TResourceReader reader;
  iCoeEnv->CreateResourceReaderLC(reader, R_EDWIN);
*iText = new (ELeave) CEikEdwin;
(*iText)->SetContainerWindowL( *this );
  (*iText)->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy();Â // Resource reader
(*iText)->SetExtent(TPoint(10,ycord), (*iText)->MinimumSize());
ycord+=(*iText)->Size().iHeight+5;
}
the .h file
#ifndef __TEST_APPVIEW1_H__
#define __TEST_APPVIEW1_H__
#include <coecntrl.h>
class CtestAppview1 : public CCoeControl
  {
public:
  static CtestAppview1* NewL(const TRect& aRect);
  static CtestAppview1* NewLC(const TRect& aRect);
~CtestAppview1();
public:Â // from CCoeControl
  void Draw(const TRect& aRect) const;
Â
private: // Functions from base classes
  void SizeChanged();
  TInt CountComponentControls() const;
  CCoeControl* ComponentControl(TInt aIndex) const;
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
void InitializeLabel(CCoeControl** iLabel);
void InitializeEdwin(CCoeControl** iText);
public:
  void ConstructL(const TRect& aRect);
  CtestAppview1();
private:
  CCoeControl* iCtrl[10];
  TInt noofctrl,ycord;
  };
#endif // __TEST_APPview1_H__
the problem is after the 3rd text box is drawn the next controls are drawn outside of the ClientRect and is not visible.
how to make those controls visible. Is some scrollbar can put to view those?
Is there any other way?
and also is there any easier way to draw dynamic controls?
Please help me
it is most urgent
thanx
Satyajit
Forum posts: 54
Hi Satyajit,
How i am also Facing the Same Problem if u have any solution for that please let me Know
Thanks in Advance
Forum posts: 21
let's consider u hv 10 ctrls of size 100 each. putting all ctrls in place size of container is sizeY = 1000.
call SetSize(TSize(Size().iWidth, sizeY) ) on container;
Now according to on which ctrl focus is, call SetPosition( TPoint(0, requiredPosition) ) on container
where requiredPosition veries to -100, -200, -300....
saur
Forum posts: 51
You need to add a layout into view, then add the new label or editor into the layout control
Forum posts: 54
Hi mickeyfirst,
i am Very sorry For Telling this,
i did not get what u have said,(i did not Under standing the adding the Layout to the View)
could u plz explain me in detail
Praveen
Forum posts: 12
suraab's comment should be suitable !