⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oggcontrols.cpp

📁 OggPlay for Symbian 是symbian上的一个媒体播放程序的源码。它支持ogg,wav等等多媒体格式。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{
  delete iData;

  if (iFont && iOwnedByControl)
      CCoeEnv::Static()->ScreenDevice()->ReleaseFont(iFont);
}

void
COggListBox::SetPosition(TInt ax, TInt ay, TInt aw, TInt ah)
{
  COggControl::SetPosition(ax, ay, aw, ah);
  iLinesVisible= ih/iLineHeight;
}

void
COggListBox::SetText(CDesCArray* aText)
{
  iText= aText;
}

void
COggListBox::SetFont(CFont* aFont, TBool aOwnedByControl)
{
  iFont= aFont;
  iRedraw= ETrue;
  iOwnedByControl = aOwnedByControl;

  iFontHeight = iFont->HeightInPixels();
  iFontAscent = iFont->AscentInPixels();

#if defined(SERIES60)
  if (iFont->TypeUid() == KCFbsFontUid)
  {
	  CFbsFont* fbsFont = (CFbsFont *) iFont;
	  if (fbsFont->IsOpenFont())
	  {
	    TOpenFontMetrics fontMetrics;
		if (fbsFont->GetFontMetrics(fontMetrics))
		{
		  iFontHeight = fontMetrics.MaxHeight() + fontMetrics.MaxDepth() + 1;
		  iFontAscent = fontMetrics.MaxHeight();
		}
	  }
  }
#endif

  iLinePadding = iFontHeight/6;
  iLineHeight = iFontHeight + 2*iLinePadding;

  iLinesVisible = ih/iLineHeight;
  iOffset= iScroll*iLineHeight;
  UpdateScrollBar();
}

void
COggListBox::SetFontColor(TRgb aColor)
{
  iFontColor= aColor;
  iRedraw= ETrue;
}

void
COggListBox::SetFontColorSelected(TRgb aColor)
{
  iFontColorSelected= aColor;
  iRedraw= ETrue;
}

void
COggListBox::SetBarColorSelected(TRgb aColor)
{
  iBarColorSelected= aColor;
  iUseBarSelected=ETrue;
  iRedraw= ETrue;
}

CColumnListBoxData*
COggListBox::GetColumnListBoxData()
{
  return iData;
}

void
COggListBox::Redraw(TBool doRedraw)
{
  UpdateScrollBar();
  COggControl::Redraw(doRedraw);
}

void
COggListBox::ClearText()
{
  iText->Reset();
  iRedraw= ETrue;
  UpdateScrollBar();
}

void
COggListBox::AppendText(const TDesC& aText)
{
  iText->AppendL(aText);
  iRedraw= ETrue;
  UpdateScrollBar();
}

TInt
COggListBox::CountText()
{
  if (!iText) return 0;
  else return iText->Count();
}

CDesCArray*
COggListBox::GetTextArray()
{
  return iText;
}

void
COggListBox::ScrollBy(TInt nLines)
{
  SetTopIndex(iTop+nLines);
}

TInt
COggListBox::CurrentItemIndex()
{
  return iSelected;
}

TInt
COggListBox::NofVisibleLines()
{
  return iLinesVisible;
}

TInt 
COggListBox::SetCurrentItemIndex(TInt idx)
{
#if defined(UIQ)
  // UIQ_?
  if (idx<0) idx = 1;
#else
  if (idx<0) idx=0; // FIXIT Quest : Newer a listbox without an valid selection
#endif
  else if (idx>=iText->Count()) idx= iText->Count()-1;
  if (idx!=iSelected) {
    iSelected= idx;
    iRedraw= ETrue;
    if (idx<iTop) SetTopIndex(idx);
    else if (idx>=iTop+iLinesVisible) SetTopIndex(idx-iLinesVisible+1);
    if (iObserver) iObserver->OggControlEvent(this,1,idx);
  }
  return idx;
}

void
COggListBox::SetTopIndex(TInt idx)
{
  if (idx<0) idx=0;
  if (idx!=iTop) {
    iCycle= KListboxcycles;
    iScroll= (iTop-idx);
    iOffset= iScroll*iLineHeight;
    iTop= idx;
    iRedraw= ETrue;
    UpdateScrollBar();
    if (iObserver) iObserver->OggControlEvent(this,0,idx);
  }
}

void
COggListBox::SetVertScrollBar(COggScrollBar* aScrollBar)
{
  iScrollBar= aScrollBar;
  UpdateScrollBar();
}

void
COggListBox::UpdateScrollBar()
{
  if (iScrollBar && iText) {
    TInt max(iText->Count()-iLinesVisible);
    if (max<0) max=0;
    iScrollBar->SetMaxValue(max);
    iScrollBar->SetValue(iTop);
    iScrollBar->SetPage(iLinesVisible);
  }
}

TInt
COggListBox::GetLineFromPos(TInt aPos)
{
  return (aPos/iLineHeight)+iTop;
}

TInt
COggListBox::GetColumnFromPos(TInt aPos)
{
  if (!iData) return 0;
  for (TInt j=0; j<iData->LastColumn(); j++) {
    if (aPos>=0 && aPos<iData->ColumnWidthPixel(j)) {
      return j;
    }
    aPos-= iData->ColumnWidthPixel(j);
  }
  return -1;
}

void
COggListBox::Draw(CBitmapContext& aBitmapContext)
{
  if (!iFont) return;
  if (!iData) return;
  if (!iText) return;
  DrawFocus(aBitmapContext);

  aBitmapContext.UseFont(iFont);
  aBitmapContext.SetPenSize(TSize(1,1));

  TInt y= iy - iLineHeight;
  TInt x;
  TInt len,idx;

  for (TInt i=iTop+iOffset/iLineHeight-1; i<iText->Count(); i++) {

    if (i<0) {
      y+= iLineHeight;
      continue;
    }

    TPtrC p((*iText)[i]);
    x= ix;

    if (i==iSelected) {
			if(iUseBarSelected) {
				aBitmapContext.SetBrushColor(iBarColorSelected);
				aBitmapContext.SetBrushStyle(CGraphicsContext::ESolidBrush);
				aBitmapContext.SetPenColor(iBarColorSelected);
				TRect lineRect(TPoint(x, y-iOffset%iLineHeight), TSize(iw, iLineHeight));

				aBitmapContext.DrawRect(lineRect);
				aBitmapContext.SetBrushStyle(CGraphicsContext::ENullBrush);
			}
			aBitmapContext.SetPenColor(iFontColorSelected);
    } else
      aBitmapContext.SetPenColor(iFontColor);

    for (TInt j=0; j<iData->LastColumn(); j++) {

      len= p.Locate(KColumnListSeparator);

      if (iData->ColumnIsGraphics(j) && iData->IconArray())
	  {
			TLex lex(p.Left(len));
			if (lex.Val(idx)==KErrNone)
			{
			#ifdef PLAYLIST_SUPPORT
				// Patch for V1 skins (they don't have a play list icon)
				if (iData->IconArray()->Count() == idx)
					idx = EFileName; // Use the file icon instead
			#endif

				if ((idx == ETitle) || (idx == EFileName) || (idx == EPlayList))
				{
					// These items can be stopped, paused or playing
					TLex lex(p.Right(1));

					TInt playState(0);
					lex.Val(playState);
					if (playState)
						idx = playState;
				}

				CGulIcon* icn= (*iData->IconArray())[idx];
				TSize s(icn->Bitmap()->SizeInPixels());
				TPoint pt(x+iData->ColumnWidthPixel(j)/2-s.iWidth/2,y+iLineHeight/2-s.iHeight/2-iOffset%iLineHeight);
				aBitmapContext.BitBltMasked(pt,icn->Bitmap(), TRect(TPoint(0,0),s), icn->Mask(), ETrue);
			}
      }
      else
	  {
			TRect lineRect(TPoint(x, y+iLinePadding-iOffset%iLineHeight), TSize(iData->ColumnWidthPixel(j), iFontHeight));
			aBitmapContext.DrawText(p.Left(len), lineRect, iFontAscent, iData->ColumnAlignment(j));
      }

      p.Set(p.Mid(len+1));
      x+= iData->ColumnWidthPixel(j);
	  
	  //FIXME: On S60, ColumnHorizontalGap returns 1080049501 !!?
#if !defined(SERIES60)
	  x+= iData->ColumnHorizontalGap(j);
#else
	  x+=2;
#endif
    }

    y+= iLineHeight;
    if (y>iy+ih) break;
  }
}

void
COggListBox::Cycle()
{
  if (iCycle>0) {
    iCycle--;
    iOffset -= (iScroll*iLineHeight)/KListboxcycles;
    iRedraw= ETrue;
  } else {
    if (iOffset!=0) {
      iOffset= 0;
      iRedraw= ETrue;
    }
  }
}

void
COggListBox::PointerEvent(const TPointerEvent& p)
{
  COggControl::PointerEvent(p);
  if (p.iType==TPointerEvent::EButton1Down /*|| p.iType==TPointerEvent::EDrag*/) {
    TInt idx= GetLineFromPos(p.iPosition.iY-iy);
    SetCurrentItemIndex(idx);
    if (iObserver) iObserver->OggControlEvent(this,2,idx);
    iRedraw= ETrue;
  } 
}

void
COggListBox::ControlEvent(TInt anEventType, TInt aValue)
{
  COggControl::ControlEvent(anEventType, aValue);
  if (anEventType==0) SetTopIndex(aValue);
}

TBool COggListBox::ReadArguments(TOggParser& p)
{
  TBool success= COggControl::ReadArguments(p);
  if (success && p.iToken==_L("Font")) {
    p.Debug(_L("Setting font."));
    CFont* aFont= p.ReadFont();
    success= aFont!=0;
    if (success) SetFont(aFont, ETrue);
  }
  if (success && p.iToken==_L("FontColor")) {
    p.Debug(_L("Setting font color."));
    TRgb col(0,0,0);
    success= p.ReadColor(col);
    if (success) SetFontColor(col);
  }
  if (success && p.iToken==_L("FontColorSelected")) {
    p.Debug(_L("Setting selected font color."));
    TRgb col(255,0,0);
    success= p.ReadColor(col);
    if (success) SetFontColorSelected(col);
  }
  if (success && p.iToken==_L("BarColorSelected")) {
    p.Debug(_L("Setting selected bar color."));
    TRgb col(255,0,0);
    success= p.ReadColor(col);
    if (success) SetBarColorSelected(col);
  }
  return success;
}


// COggCanvas
COggCanvas::COggCanvas() :
  iControls(10)
{
}

COggCanvas::~COggCanvas()
{
  DestroyBitmap();
  if(iBackground) {
    iBackground->Reset();
    delete iBackground;
  }
}

TInt COggCanvas::LoadBackgroundBitmapL(const TFileName& aFileName, TInt iIdx)
{
  if(iBackground) 
    {
    iBackground->Reset();
    delete iBackground;
    }

  iBackground = new(ELeave) CFbsBitmap;
  TInt err = KErrNone;
  TInt scaleFactor = 1;

#if defined (SERIES60)
  TSize screenSize = CCoeEnv::Static()->ScreenDevice()->SizeInPixels();
  if (screenSize == TSize(352, 416))
  {
	  // Double resolution screen, so scale the skin if necessary
	  CFbsBitmap* bgBitmap = new(ELeave) CFbsBitmap;
	  err = bgBitmap->Load(aFileName, iIdx);
	  if (err == KErrNone)
	  {
		  TSize bgBitmapSize = bgBitmap->SizeInPixels();
		  scaleFactor = screenSize.iWidth / bgBitmapSize.iWidth;
		  if (scaleFactor == 1)
		  {
			// Use the bitmap as it is
			TRAP(err, iBackground->Duplicate(bgBitmap->Handle()));
		  }
		  else
		  {
			// Scale the bitmap to the correct size
			TRAP(err, ScaleBitmapL(iBackground, bgBitmap, scaleFactor));
		  }
	  }

	  delete bgBitmap;
  }
  else
	err = iBackground->Load(aFileName,iIdx);
#else
  err= iBackground->Load(aFileName,iIdx);
#endif

  if (err!=KErrNone)
  {
    TBuf<256> buf;
    CEikonEnv::Static()->ReadResource(buf, R_OGG_ERROR_21);
    buf.AppendNum(err);
#if defined(UIQ)
    User::InfoPrint(buf);
#else
    // UIQ_?
    COggMsgEnv::OggErrorMsgL( buf, _L(" ") );
#endif
    delete iBackground;
    iBackground= 0;
    User::Leave(err);
  }

  EnableDragEvents();
  DrawControl();

  return scaleFactor;
}

void
COggCanvas::Refresh()
{
  TBool redrawRequired = EFalse;
  TInt i;
  for (i=0; i<iControls.Count(); i++) 
  {
    if (iControls[i]->iRedraw)
	{
		redrawRequired = ETrue;
		break;
    }
  }

  if (redrawRequired)
  {
    DrawControl(*iBitmapContext, *iBitmapDevice);

	Window().Invalidate();
	ActivateGc();
	Window().BeginRedraw();
	CWindowGc& gc=SystemGc();

#if defined(SERIES90)
	// Series 90 has a problem redrawing parts of the screen, so redraw everything
	TRect rect = TRect(iBitmap->SizeInPixels());
	gc.BitBlt(rect.iTl, iBitmap, rect);
#else
	for (i=0; i<iControls.Count(); i++)
	{
		if (iControls[i]->iRedraw)
		{
		TRect rect = iControls[i]->Rect();
		gc.BitBlt(rect.iTl, iBitmap, rect);

		iControls[i]->iRedraw = EFalse;
		}
	}
#endif

	Window().EndRedraw();
	DeactivateGc();
  }
}

void
COggCanvas::Invalidate()
{
  DrawNow();
}

COggControl*
COggCanvas::GetControl(TInt i)
{
  return iControls[i];
}

void
COggCanvas::AddControl(COggControl* c)
{
  iControls.AppendL(c);
//  RDebug::Print(_L("Adding control - now %d"),iControls.Count());
}

void COggCanvas::ClearControls()
{
  iControls.ResetAndDestroy();
 
}

void COggCanvas::DrawControl()
{
  if (iBitmap)
  {
    iBitmapContext->SetClippingRect(Rect());
    if (iBackground) {
      iBitmapContext->BitBlt(TPoint(0,0),iBackground);
    } else {
      iBitmapContext->SetBrushColor(KRgbWhite);
      iBitmapContext->Clear(Rect());
    }

    // DrawControl will draw relative to its Position().
    // when drawing to the bitmap gc, Position() should be (0,0)
    TPoint	position = iPosition;
    iPosition = TPoint(0,0);
    for (int i=0; i<iControls.Count(); i++) iControls[i]->iRedraw= ETrue;
    DrawControl(*iBitmapContext, *iBitmapDevice);
    for (int j=0; j<iControls.Count(); j++) iControls[j]->iRedraw= EFalse;
    iPosition = position;
  }
}

void COggCanvas::SizeChanged()
{
  DestroyBitmap();
  TRAPD(err, CreateBitmapL(Size()));
  if (err)
    DestroyBitmap();
  else
    DrawControl();
}

void COggCanvas::DestroyBitmap()
{
  delete iBitmapContext;
  iBitmapContext = NULL;
  delete iBitmapDevice;
  iBitmapDevice = NULL;
  if(iBitmap) {
    iBitmap->Reset();
    delete iBitmap;
    iBitmap = NULL;
  }
}

void COggCanvas::CreateBitmapL(const TSize& aSize)
{
  iBitmap = new (ELeave) CFbsBitmap;
  iBitmap->Create(aSize, iEikonEnv->ScreenDevice()->DisplayMode());
  
  iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
  iBitmapDevice->CreateContext(iBitmapContext);
}

void COggCanvas::Draw(const TRect& aRect) const
{
  CWindowGc& gc=SystemGc();
  
  if (iBitmap) {
    gc.BitBlt(aRect.iTl, iBitmap, TRect(aRect.iTl - Position(), aRect.Size()));
  } else {
    CWsScreenDevice* screenDevice = iCoeEnv->ScreenDevice();
    DrawControl(gc, *screenDevice);
  }
}

void COggCanvas::DrawControl(CBitmapContext& aBitmapContext, CBitmapDevice& /*aBitmapDevice*/) const
{
  // clear backgrounds
  for (int i=0; i<iControls.Count(); i++) {
    COggControl* c= iControls[i];
    if (c->iRedraw) {
      aBitmapContext.SetClippingRect(Rect());
      if (iBackground) 
        aBitmapContext.BitBlt(TPoint(c->ix,c->iy),iBackground,TRect(TPoint(c->ix,c->iy),TSize(c->iw,c->ih)));
      else {
	aBitmapContext.SetBrushColor(KRgbWhite);
	aBitmapContext.Clear(TRect(TPoint(c->ix,c->iy),TSize(c->iw,c->ih)));
      }
    }
  }

  // redraw controls
  for (int k=0; k<iControls.Count(); k++) {
    COggControl* c= iControls[k];
    if (c->iRedraw && c->IsVisible()) {
      aBitmapContext.SetClippingRect(c->Rect());
      c->Draw(aBitmapContext);
    }
  }
}

TKeyResponse COggCanvas::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/)
{
  return EKeyWasNotConsumed;
}

void COggCanvas::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
  if (iGrabbed) iGrabbed->PointerEvent(aPointerEvent);

  if (!iGrabbed && aPointerEvent.iType==TPointerEvent::EButton1Down) {
    for (int i=0; i<iControls.Count(); i++) {
      COggControl* c= iControls[i];
      if (c->IsVisible() && !c->IsDimmed() && c->Rect().Contains(aPointerEvent.iPosition)) {
	iGrabbed= c;
	c->PointerEvent(aPointerEvent);
	return;
      }
    }
  }

  if (aPointerEvent.iType==TPointerEvent::EButton1Up) iGrabbed= 0;
}

void COggCanvas::CycleHighFrequencyControls()
{
  for (int i=0; i<iControls.Count(); i++)
  {
    COggControl* control = iControls[i];
    if (control->HighFrequency())
		control->Cycle();
  }
}

void COggCanvas::CycleLowFrequencyControls()
{
  for (int i=0; i<iControls.Count(); i++)
  {
    COggControl* control = iControls[i];
    if (!control->HighFrequency())
		control->Cycle();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -