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

📄 customdrawtableviewdemomain.cpp

📁 DevExpress.ExpressQuantumGrid控件组
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  String ATextToDraw = AViewInfo->Text;
  TRect ARec = AViewInfo->Bounds;
  ACanvas->Canvas->Font->Assign(FFonts[(int)vtDetail][(int)cdaGroupCell]);
  switch (FCustomDrawingStyle[(int)vtDetail][(int)cdaGroupCell]) {
    case cdsBkImage: {
      ACanvas->Brush->Bitmap = NULL;
      ACanvas->Brush->Assign(FGridBrushDetailGroupCell);
      ACanvas->FillRect(ARec, NULL);
    }; break;
    case cdsGradient: {
      bool AIsVertical = (FColorScheme[(int)vtDetail][(int)cdaGroupCell] == csGrey) || (FColorScheme[(int)vtDetail][(int)cdaGroupCell] == csGold);
      DrawGradient(ACanvas->Canvas, ARec, ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaGroupCell]][1], ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaGroupCell]][0], 40, AIsVertical);
    }; break;
  };
  ADone = !(TCustomDrawingStyles() << cdsDefaultDrawing).Contains(FCustomDrawingStyle[(int)vtDetail][(int)cdaGroupCell]);
  if(ADone) {
    SetBkMode(ACanvas->Canvas->Handle, TRANSPARENT);
    ARec.Left = ARec.Left + (AViewInfo->RecordViewInfo->ExpandButtonBounds.Right - AViewInfo->RecordViewInfo->ExpandButtonBounds.Left) + 10;
    ARec.Top++;
    ACanvas->DrawTexT(ATextToDraw, ARec, 0, true);
  };
}
//---------------------------------------------------------------------------

void __fastcall TCustomDrawTableViewDemoMainForm::tvOrdersCustomDrawColumnHeader(
      TcxGridTableView *Sender, TcxCanvas *ACanvas,
      TcxGridColumnHeaderViewInfo *AViewInfo, bool &ADone)
{
  String ATextToDraw = AViewInfo->Text;
  TRect ARec = AViewInfo->Bounds;
  ACanvas->Canvas->Font->Assign(FFonts[(int)vtDetail][(int)cdaColumnHeader]);
  switch(FCustomDrawingStyle[(int)vtDetail][(int)cdaColumnHeader]) {
    case cdsBkImage: {
      ACanvas->Brush->Bitmap = NULL;
      ACanvas->Brush->Assign(FGridBrushDetailColumnHeader);
      ACanvas->Canvas->FillRect(ARec);
    }; break;
    case cdsGradient: {
      bool AIsVertical = (FColorScheme[(int)vtDetail][(int)cdaColumnHeader] == csGrey) ||
        (FColorScheme[(int)vtDetail][(int)cdaColumnHeader] == csGold);
      DrawGradient(ACanvas->Canvas, ARec, ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaColumnHeader]][1],
        ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaColumnHeader]][0], 40, AIsVertical);
    }; break;
    case cdsDependsOnData: {
      ACanvas->Canvas->Brush->Style = bsSolid;
      ACanvas->Canvas->Brush->Color = clBlueLight;
      ACanvas->Canvas->FillRect(ARec);
    }; break;
  };

  SetBkMode(ACanvas->Canvas->Handle, TRANSPARENT);
  ACanvas->Canvas->TextOut(AViewInfo->Bounds.Left, AViewInfo->Bounds.Top, ATextToDraw);

  ADone = FCustomDrawingStyle[(int)vtDetail][(int)cdaColumnHeader] != cdsDefaultDrawing;
}
//---------------------------------------------------------------------------

void __fastcall TCustomDrawTableViewDemoMainForm::tvOrdersCustomDrawFooterCell(
      TcxGridTableView *Sender, TcxCanvas *ACanvas,
      TcxGridColumnHeaderViewInfo *AViewInfo, bool &ADone)
{
  String ATextToDraw = AViewInfo->Text;
  TRect ARec = AViewInfo->Bounds;
  ACanvas->Canvas->Font->Assign(FFonts[(int)vtDetail][(int)cdaFooterCell]);
  switch (FCustomDrawingStyle[(int)vtDetail][(int)cdaFooterCell]) {
    case cdsBkImage: {
      ACanvas->Brush->Bitmap = NULL;
      ACanvas->Brush->Assign(FGridBrushDetailFooterCell);
      ACanvas->Canvas->FillRect(ARec);
    }; break;
    case cdsGradient: {
      bool AIsVertical = (FColorScheme[(int)vtDetail][(int)cdaFooterCell] == csGrey) ||
        (FColorScheme[(int)vtDetail][(int)cdaFooterCell] == csGold);
      DrawGradient(ACanvas->Canvas, ARec, ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaFooterCell]][1],
        ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaFooterCell]][0], 40, AIsVertical);
    }; break;
  };

  SetBkMode(ACanvas->Canvas->Handle, TRANSPARENT);
  ACanvas->Canvas->TextOut(AViewInfo->Bounds.Left, AViewInfo->Bounds.Top, ATextToDraw);

  ADone = FCustomDrawingStyle[(int)vtDetail][(int)cdaFooterCell] != cdsDefaultDrawing;
}
//---------------------------------------------------------------------------

void __fastcall TCustomDrawTableViewDemoMainForm::tvOrdersCustomDrawPartBackground(
      TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
      TcxCustomGridCellViewInfo *AViewInfo, bool &ADone)
{
  TRect ARec = AViewInfo->Bounds;
  ACanvas->Canvas->Font->Assign(FFonts[(int)vtDetail][(int)cdaPartBackGround]);
  switch (FCustomDrawingStyle[(int)vtDetail][(int)cdaPartBackGround]) {
    case cdsBkImage: {
      ACanvas->Brush->Bitmap = NULL;
      ACanvas->Brush->Assign(FGridBrushDetailPartBackground);
      ACanvas->Canvas->FillRect(ARec);
    }; break;
    case cdsGradient: {
      bool AIsVertical = (FColorScheme[(int)vtDetail][(int)cdaPartBackGround] == csGrey) ||
        (FColorScheme[(int)vtDetail][(int)cdaPartBackGround] == csGold);
      DrawGradient(ACanvas->Canvas, ARec, ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaPartBackGround]][1],
        ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaPartBackGround]][0], 40, AIsVertical);
    }; break;
  };

  ADone = FCustomDrawingStyle[(int)vtDetail][(int)cdaPartBackGround] != cdsDefaultDrawing;
}
//---------------------------------------------------------------------------

void __fastcall TCustomDrawTableViewDemoMainForm::FormCreate(
      TObject *Sender)
{
  InitFonts();

  FSkyBitmap = new Graphics::TBitmap();

  LoadImageFromRes(FSkyBitmap, "SKY");

  FEgyptBitmap = new Graphics::TBitmap();
  LoadImageFromRes(FEgyptBitmap, "EGYPT");

  FMyFaceBitmap = new Graphics::TBitmap();
  LoadImageFromRes(FMyFaceBitmap, "MYFACE");

  FTileBitmap = new Graphics::TBitmap();
  LoadImageFromRes(FTileBitmap, "TILE");

  FBitMap = new Graphics::TBitmap();
  SetCustomDrawingStyles();
}
//---------------------------------------------------------------------------

void __fastcall TCustomDrawTableViewDemoMainForm::FormDestroy(
      TObject *Sender)
{
  for(int i=0; i < 2; i++)
    for(int j=0; j < 6; j++)
      delete FFonts[i][j];
  delete FBitMap;
  delete FEgyptBitmap;
  delete FMyFaceBitmap;
  delete FTileBitmap;
  delete FSkyBitmap;

  delete FGridBrushMasterCell;
  delete FGridBrushMasterFooterCell;
  delete FGridBrushMasterColumnHeader;
  delete FGridBrushMasterPartBackground;
  delete FGridBrushMasterIndicatorCell;

  delete FGridBrushDetailCell;
  delete FGridBrushDetailFooterCell;
  delete FGridBrushDetailColumnHeader;
  delete FGridBrushDetailPartBackground;
  delete FGridBrushDetailIndicatorCell;
}
//---------------------------------------------------------------------------

void __fastcall TCustomDrawTableViewDemoMainForm::tvOrdersCustomDrawIndicatorCell(
      TcxGridTableView *Sender, TcxCanvas *ACanvas,
      TcxCustomGridIndicatorItemViewInfo *AViewInfo, bool &ADone)
{
  TRect ARec;
  TcxIndicatorKind AIndicatorKind;

  ARec = AViewInfo->Bounds;
  ACanvas->Canvas->Font->Assign(FFonts[(int)vtDetail][(int)cdaIndicatorCell]);

  if (!dynamic_cast<TcxGridIndicatorRowItemViewInfo*>(AViewInfo))
    AIndicatorKind = ikNone;
  else
    AIndicatorKind = ((TcxGridIndicatorRowItemViewInfo*)AViewInfo)->IndicatorKind;

  switch (FCustomDrawingStyle[(int)vtDetail][(int)cdaIndicatorCell]) {
    case cdsBkImage: {
      ACanvas->Brush->Bitmap = NULL;
      ACanvas->Brush->Assign(FGridBrushMasterIndicatorCell);
      ACanvas->FillRect(ARec, NULL);
    }; break;
    case cdsGradient:  {
      bool AIsVertical = (FColorScheme[(int)vtDetail][(int)cdaIndicatorCell] == csGrey) || (FColorScheme[(int)vtDetail][(int)cdaIndicatorCell] == csGold);
      DrawGradient(ACanvas->Canvas, ARec, ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaGroupCell]][1], ColorScheme[(int)FColorScheme[(int)vtDetail][(int)cdaIndicatorCell]][0], 40, AIsVertical);
    }; break;
  }
  if (AIndicatorKind != ikNone) {
    int X = div((ARec.Left + ARec.Right - imIndicatorImages->Width), 2).quot;
    int Y = div((ARec.Top + ARec.Bottom - imIndicatorImages->Height), 2).quot;
    imIndicatorImages->Draw(ACanvas->Canvas, X, Y, IndicatorImageIndex[vtDetail], true);
  };

  ADone = !(TCustomDrawingStyles() << cdsDefaultDrawing).Contains(FCustomDrawingStyle[(int)vtDetail][(int)cdaIndicatorCell]);
}
//---------------------------------------------------------------------------

void __fastcall TCustomDrawTableViewDemoMainForm::tvCarsCustomDrawIndicatorCell(
      TcxGridTableView *Sender, TcxCanvas *ACanvas,
      TcxCustomGridIndicatorItemViewInfo *AViewInfo, bool &ADone)
{
  TRect ARec;
  TcxIndicatorKind AIndicatorKind;

  ARec = AViewInfo->Bounds;
  ACanvas->Canvas->Font->Assign(FFonts[(int)vtMaster][(int)cdaIndicatorCell]);

  if (!dynamic_cast<TcxGridIndicatorRowItemViewInfo*>(AViewInfo))
    AIndicatorKind = ikNone;
  else
    AIndicatorKind = ((TcxGridIndicatorRowItemViewInfo*)AViewInfo)->IndicatorKind;

  switch (FCustomDrawingStyle[(int)vtMaster][(int)cdaIndicatorCell]) {
    case cdsBkImage: {
      ACanvas->Brush->Bitmap = NULL;
      ACanvas->Brush->Assign(FGridBrushMasterIndicatorCell);
      ACanvas->FillRect(ARec, NULL);
    }; break;
    case cdsGradient:  {
      bool AIsVertical = (FColorScheme[(int)vtMaster][(int)cdaIndicatorCell] == csGrey) || (FColorScheme[(int)vtMaster][(int)cdaIndicatorCell] == csGold);
      DrawGradient(ACanvas->Canvas, ARec, ColorScheme[(int)FColorScheme[(int)vtMaster][(int)cdaGroupCell]][1], ColorScheme[(int)FColorScheme[(int)vtMaster][(int)cdaIndicatorCell]][0], 40, AIsVertical);
    }; break;
  }
  if (AIndicatorKind != ikNone) {
    int X = div((ARec.Left + ARec.Right - imIndicatorImages->Width), 2).quot;
    int Y = div((ARec.Top + ARec.Bottom - imIndicatorImages->Height), 2).quot;
    imIndicatorImages->Draw(ACanvas->Canvas, X, Y, IndicatorImageIndex[vtMaster], true);
  };

  ADone = !(TCustomDrawingStyles() << cdsDefaultDrawing).Contains(FCustomDrawingStyle[(int)vtMaster][(int)cdaIndicatorCell]);
}
//---------------------------------------------------------------------------

void __fastcall TCustomDrawTableViewDemoMainForm::miNativeStyleClick(
      TObject *Sender)
{
  LookAndFeelController->NativeStyle = !LookAndFeelController->NativeStyle;
  ((TMenuItem*)Sender)->Checked = LookAndFeelController->NativeStyle;
}
//---------------------------------------------------------------------------


void __fastcall TCustomDrawTableViewDemoMainForm::miLookAndFeelKindClick(
      TObject *Sender)
{
  LookAndFeelController->Kind = (TcxLookAndFeelKind)((TMenuItem*)Sender)->MenuIndex;
  ((TMenuItem*)Sender)->Checked = true;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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