1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "StrUtils.hpp"
#include "LabelVertical.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TLabelVertical *)
{
new TLabelVertical(NULL);
}
//---------------------------------------------------------------------------
__fastcall TLabelVertical::TLabelVertical(TComponent* Owner)
: TLabel(Owner)
{
LaForm = (TForm *)Owner;
}
//---------------------------------------------------------------------------
void __fastcall TLabelVertical::SetVertical(bool AVertical)
// SetVertical modifie la variable FVertical qui est la valeur
// renvoyee par la propriete
{
if (AVertical != FVertical)
{
FVertical = AVertical;
Invalidate();
AdjustBounds();
}
}
//---------------------------------------------------------------------------
void __fastcall TLabelVertical::SetWordWrap(bool AWordWrap)
// SetWordWrap modifie la variable FWordWrap qui est la valeur
// renvoyee par la propriete
{
if (AWordWrap != FWordWrap)
{
FWordWrap = AWordWrap;
Invalidate();
AdjustBounds();
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall TLabelVertical::GetLabelText()
// on recupere le Caption du TLabel
// redefinition de la fonction GetLabelText
// ici on met un test si c'est une ecriture Verticale ou WordWrapVertical
// si FVertical ---> sous programme 1
// si FWordWrapVertical ---> sous programme 2
{
if (FVertical == false && FWordWrap == false)
{
// on lit la longueur du Caption
Size = GetTextLen();
// on recupere le Caption
char *capt = new char[Size+1];
GetTextBuf(capt,Size+1);
// on reecrit la chaine du Caption en ecrivant
// \n entre chaque lettre
tempd = "";
for (i=0;i<Size;i++)
{
tempd += capt[i];
}
// on ecrit le Caption
//SetTextBuf(tempd);
delete capt;
return tempd;
}
if (FVertical == true && FWordWrap == false)
{
// on lit la longueur du Caption
Size = GetTextLen();
// on recupere le Caption
char *capt = new char[Size+1];
GetTextBuf(capt,Size+1);
// on reecrit la chaine du Caption en ecrivant
// \n entre chaque lettre
tempd = "";
for (i=0;i<Size;i++)
{
tempd += capt[i];
tempd += '\n';
}
// on ecrit le Caption
//SetTextBuf(tempd);
delete capt;
return tempd;
}
//---------------------------------------------------------------------------
if (FVertical == true && FWordWrap == true)
{
//int yy = GetClientWidth;
int zz = Canvas->TextHeight(Caption);// <---- voir s'il faut laisser Canvas
int yy = Canvas->TextWidth(Caption);// <---- voir s'il faut laisser Canvas
int Gauche = Left;
int Haut = Top;
int Droite = Width;
int Bas = Height;
String x;
TRect TheRect;
Size = GetTextLen();
// on recupere le Caption
char *capt = new char[Size+1];
GetTextBuf(capt,Size+1);
tempd = "";
//String text1 = "essai d'ecriture de texte sur plusieurs colonnes";
//text1 = text1 + " ";
//int lngtxt = text1.Length();
int lngtxt1;
int htlabel = Height;
int nbcar = htlabel / zz;
int k = 0;
int rst = nbcar;
int bcl = 0;
AnsiString c = "";
AnsiString tempd ="";
for (int i = 0; i <= Size; i++)
{
tempd += capt[i];
x = capt[i];// <---- a refaire
if (x == " " || x == '\0')
{
lngtxt1 = tempd.Length();
if (bcl != 0 && rst < lngtxt1)
{
k = k + 1;
rst = nbcar;
bcl = 0;
}
if (bcl == 0 && rst > lngtxt1)
{
rst = nbcar;
bcl = 0;
}
for (int j = 1; j <= lngtxt1; j++)
{
c = tempd[j];
// c = MidStr(d, j + 1, 1);// <---- a refaire
// ici on fait l'affichage
// Gauche, Haut, Droite, Bas
TheRect = Rect(Gauche + (k * 15), Haut + ((j + bcl) * (zz - 2)),
Droite + (k * 15), Bas + ((j + bcl) * (zz - 2)));
LaForm->Canvas->TextRect(TheRect, Gauche + (k * 15),
Haut + ((j + bcl) * (zz - 2)), c);
}
bcl = bcl + lngtxt1;
rst = rst - lngtxt1;
// tempd = "";
}
}
// tempd = "";
//return tempd;
}
// delete capt;
//return tempd;
}
//---------------------------------------------------------------------------
namespace Labelvertical
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TLabelVertical)};
RegisterComponents("Perso", classes, 0);
}
}
//--------------------------------------------------------------------------- |
Partager