home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD2.mdf
/
c
/
library
/
starview
/
examples
/
output
/
fontdemo.cxx
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-31
|
18KB
|
563 lines
/*******************************************************************
* FONTDEMO.CXX
* (c) 1992 STAR DIVISION
*******************************************************************/
#include <sv.hxx>
#include "fontdemo.hrc"
// --- class MyApp -------------------------------------------------
class MyApp : public Application
{
public:
virtual void Main( int, char*[] );
};
// --- class ShowFont ----------------------------------------------
class ShowFont : public Control
{
public:
ShowFont( Window* pParent, ResId& rResId );
virtual void Paint( const Rectangle& );
Font ChangeFont( const Font& rFont );
};
// --- class FontDialog --------------------------------------------
class FontDialog : public ModalDialog
{
protected:
FixedText aNameText;
ListBox aNameBox;
FixedText aSizeText;
ListBox aSizeBox;
AutoCheckBox aItalic;
AutoCheckBox aBold;
AutoCheckBox aStrikeout;
AutoCheckBox aUnderline;
AutoCheckBox aShadow;
AutoCheckBox aOutline;
AutoCheckBox aTransparent;
GroupBox aStyleGroup;
FixedText aColorText;
DropDownListBox aColorBox;
FixedText aFillText;
DropDownListBox aFillBox;
FixedText aLineAngleText;
DropDownComboBox aLineAngleBox;
FixedText aCharAngleText;
DropDownComboBox aCharAngleBox;
ShowFont aShowFont;
DefPushButton aOkButton;
Font aFont;
public:
FontDialog( Window* pWindow,
ResId& rResId );
void FontChangeHdl( ListBox* pBox );
void SizeChangeHdl( ListBox* pBox );
void ColorSelectHdl( DropDownListBox* pBox );
void FillSelectHdl( DropDownListBox* pBox );
void AttrHdl( AutoCheckBox* pBox );
void LineSelectHdl( DropDownComboBox* pBox );
void LineModifyHdl( DropDownComboBox* pBox );
void CharSelectHdl( DropDownComboBox* pBox );
void CharModifyHdl( DropDownComboBox* pBox );
void OkHdl( PushButton* pOkButton );
Font GetNewFont() const { return aFont; }
};
// --- class AppWin ------------------------------------------------
class AppWin : public WorkWindow
{
private:
FontDialog aFontDialog;
PushButton aFontButton;
public:
AppWin();
virtual void Paint( const Rectangle& );
void FontHdl( PushButton* );
};
// --- ShowFont::ShowFont() ----------------------------------------
ShowFont::ShowFont( Window* pParent, ResId& rResId ) :
Control( pParent, rResId )
{
}
// --- ShowFont::Paint() -------------------------------------------
void ShowFont::Paint( const Rectangle& )
{
USHORT x,y;
Size aTextSize( GetTextSize( GetText() ) );
Size aWindowSize( GetOutputSize() );
if ( GetFont().GetLineOrientation() != 0 )
{
x = aWindowSize.Width()/2;
y = aWindowSize.Height()/2;
DrawText( Point( x, y ), "Rotation" );
}
else
{
x = aWindowSize.Width()/2 - aTextSize.Width()/2;
y = aWindowSize.Height()/2 - aTextSize.Height()/2;
DrawText( Point( x, y ), GetText() );
}
}
// --- ShowFont::ChangeFont() --------------------------------------
Font ShowFont::ChangeFont( const Font& rFont )
{
Invalidate();
return Control::ChangeFont( rFont );
}
// --- FontDialog::FontDialog() ------------------------------------
FontDialog::FontDialog( Window* pWindow, ResId& rResId ) :
ModalDialog( pWindow, rResId.Lock() ),
aNameText( this, ResId( FD_NAMETEXT ) ),
aNameBox( this, ResId( FD_NAMEBOX ) ),
aSizeText( this, ResId( FD_SIZETEXT ) ),
aSizeBox( this, ResId( FD_SIZEBOX ) ),
aItalic( this, ResId( FD_ITALIC ) ),
aBold( this, ResId( FD_BOLD ) ),
aStrikeout( this, ResId( FD_STRIKEOUT ) ),
aUnderline( this, ResId( FD_UNDERLINE ) ),
aShadow( this, ResId( FD_SHADOW ) ),
aOutline( this, ResId( FD_OUTLINE ) ),
aTransparent( this, ResId( FD_TRANSPARENT ) ),
aStyleGroup( this, ResId( FD_STYLEGROUP ) ),
aColorText( this, ResId( FD_COLORTEXT ) ),
aColorBox( this, ResId( FD_COLORBOX ) ),
aFillText( this, ResId( FD_FILLINTEXT ) ),
aFillBox( this, ResId( FD_FILLINBOX ) ),
aLineAngleText( this, ResId( FD_LINEANGLETEXT ) ),
aLineAngleBox( this, ResId( FD_LINEANGLEBOX ) ),
aCharAngleText( this, ResId( FD_CHARANGLETEXT ) ),
aCharAngleBox( this, ResId( FD_CHARANGLEBOX ) ),
aShowFont( this, ResId( FD_SHOWFONT ) ),
aOkButton( this, ResId( FD_OK ) )
{
rResId.Unlock();
int n = GetDevFontCount();
for ( int i = 0; i < n; i++ )
aNameBox.InsertEntry( GetDevFont( i ).GetName() );
aNameBox.SetCurEntryPos( 0 );
aNameBox.ChangeHighlightHdl(
LINK( this, FontDialog::FontChangeHdl ) );
aSizeBox.ChangeHighlightHdl(
LINK( this, FontDialog::SizeChangeHdl ) );
aItalic.ChangeClickHdl( LINK( this, FontDialog::AttrHdl ) );
aBold.ChangeClickHdl( LINK( this, FontDialog::AttrHdl ) );
aStrikeout.ChangeClickHdl( LINK( this, FontDialog::AttrHdl ) );
aUnderline.ChangeClickHdl( LINK( this, FontDialog::AttrHdl ) );
aShadow.ChangeClickHdl( LINK( this, FontDialog::AttrHdl ) );
aOutline.ChangeClickHdl( LINK( this, FontDialog::AttrHdl ) );
aTransparent.ChangeClickHdl(
LINK( this, FontDialog::AttrHdl ) );
aColorBox.ChangeSelectHdl(
LINK( this, FontDialog::ColorSelectHdl ) );
aFillBox.ChangeSelectHdl(
LINK( this, FontDialog::FillSelectHdl ) );
aLineAngleBox.ChangeModifyHdl(
LINK( this, FontDialog::LineModifyHdl ) );
aLineAngleBox.ChangeSelectHdl(
LINK( this, FontDialog::LineSelectHdl ) );
aCharAngleBox.ChangeModifyHdl(
LINK( this, FontDialog::CharModifyHdl ) );
aCharAngleBox.ChangeSelectHdl(
LINK( this, FontDialog::CharSelectHdl ) );
aOkButton.ChangeClickHdl( LINK( this, FontDialog::OkHdl ) );
FontChangeHdl( &aNameBox );
}
// --- FontDialog::FontChangeHdl() ---------------------------------
void FontDialog::FontChangeHdl( ListBox* pBox )
{
aFont.ChangeName( pBox->GetCurEntry() );
aSizeBox.ChangeUpdateMode( FALSE );
aSizeBox.Clear();
int n = GetDevFontSizeCount( aFont );
for ( int i = 0; i < n; i++ )
aSizeBox.InsertEntry( GetDevFontSize( aFont, i ).Height() );
aSizeBox.SetCurEntryPos( 0 );
aSizeBox.ChangeUpdateMode( TRUE );
aSizeBox.Invalidate();
SizeChangeHdl( &aSizeBox );
}
// --- FontDialog::SizeChangeHdl() ---------------------------------
void FontDialog::SizeChangeHdl( ListBox* pBox )
{
aFont.ChangeSize( Size( 0, pBox->GetCurEntry() ) );
aShowFont.ChangeFont( aFont );
}
// --- FontDialog::ColorSelectHdl() --------------------------------
void FontDialog::ColorSelectHdl( DropDownListBox* pBox )
{
switch ( pBox->GetCurEntryPos() )
{
case 0:
aFont.ChangeColor( Color( COL_BLACK ) );
break;
case 1:
aFont.ChangeColor( Color( COL_RED ) );
break;
case 2:
aFont.ChangeColor( Color( COL_GREEN ) );
break;
case 3:
aFont.ChangeColor( Color( COL_BLUE ) );
break;
case 4:
aFont.ChangeColor( Color( COL_LIGHTRED ) );
break;
case 5:
aFont.ChangeColor( Color( COL_LIGHTGREEN ) );
break;
case 6:
aFont.ChangeColor( Color( COL_LIGHTBLUE ) );
break;
case 7:
aFont.ChangeColor( Color( COL_YELLOW ) );
break;
case 8:
aFont.ChangeColor( Color( COL_WHITE ) );
break;
}
aShowFont.ChangeFont( aFont );
}
// --- FontDialog::FillSelectHdl() ---------------------------------
void FontDialog::FillSelectHdl( DropDownListBox* pBox )
{
switch ( pBox->GetCurEntryPos() )
{
case 0:
aFont.ChangeFillColor( Color( COL_BLACK ) );
break;
case 1:
aFont.ChangeFillColor( Color( COL_RED ) );
break;
case 2:
aFont.ChangeFillColor( Color( COL_GREEN ) );
break;
case 3:
aFont.ChangeFillColor( Color( COL_BLUE ) );
break;
case 4:
aFont.ChangeFillColor( Color( COL_LIGHTRED ) );
break;
case 5:
aFont.ChangeFillColor( Color( COL_LIGHTGREEN ) );
break;
case 6:
aFont.ChangeFillColor( Color( COL_LIGHTBLUE ) );
break;
case 7:
aFont.ChangeFillColor( Color( COL_YELLOW ) );
break;
case 8:
aFont.ChangeFillColor( Color( COL_WHITE ) );
break;
}
aShowFont.ChangeFont( aFont );
}
// --- FontDialog::AttrHdl() ---------------------------------------
void FontDialog::AttrHdl( AutoCheckBox* )
{
if ( aBold.IsChecked() )
aFont.ChangeWeight( FontWeight( WEIGHT_BOLD ) );
else
aFont.ChangeWeight( FontWeight( WEIGHT_NORMAL ) );
aFont.ChangeItalic( aItalic.IsChecked() );
aFont.ChangeStrikeout( aStrikeout.IsChecked() );
aFont.ChangeUnderline( aUnderline.IsChecked() );
aFont.ChangeShadow( aShadow.IsChecked());
aFont.ChangeOutline( aOutline.IsChecked() );
aFont.ChangeTransparent( aTransparent.IsChecked() );
aShowFont.ChangeFont( aFont );
}
// --- FontDialog::LineSelectHdl() ---------------------------------
void FontDialog::LineSelectHdl( DropDownComboBox* pBox )
{
aFont.ChangeLineOrientation( (short)pBox->GetCurEntry() );
aShowFont.ChangeFont( aFont );
}
// --- FontDialog::LineModifyHdl() ---------------------------------
void FontDialog::LineModifyHdl( DropDownComboBox* pBox )
{
aFont.ChangeLineOrientation( pBox->GetText() );
aShowFont.ChangeFont( aFont );
}
// --- FontDialog::CharSelectHdl() ---------------------------------
void FontDialog::CharSelectHdl( DropDownComboBox* pBox )
{
aFont.ChangeCharOrientation( pBox->GetCurEntry() );
aShowFont.ChangeFont( aFont );
}
// --- FontDialog::CharModifyHdl() ---------------------------------
void FontDialog::CharModifyHdl( DropDownComboBox* pBox )
{
aFont.ChangeCharOrientation( pBox->GetText() );
aShowFont.ChangeFont( aFont );
}
// --- FontDialog::OkHdl() -----------------------------------------
void FontDialog::OkHdl( PushButton* )
{
EndDialog( TRUE );
}
// --- AppWin::AppWin() --------------------------------------------
AppWin::AppWin() :
WorkWindow( NULL, WB_APP | WB_MOVEABLE |
WB_MINABLE | WB_CLOSEABLE ),
aFontDialog( this, ResId( FONTDIALOG ) ),
aFontButton( this )
{
aFontButton.SetText( "Change Font..." );
aFontButton.ChangePosPixel( Point( 300, 10 ) );
aFontButton.ChangeSizePixel( Size( 150, 30 ) );
aFontButton.ChangeClickHdl( LINK( this, AppWin::FontHdl ) );
aFontButton.Show();
ChangeOutputSizePixel( Size( 500, 400 ) );
SetText( "Font Demo" );
Show();
}
// --- AppWin::Paint() ---------------------------------------------
void AppWin::Paint( const Rectangle& )
{
Font aTempFont;
aTempFont.ChangePitch( PITCH_FIXED );
aTempFont.ChangeSize( Size( 0, 14 ) );
ChangeFont( aTempFont );
Font aNewFont = aFontDialog.GetNewFont();
FontMetric aMetric = GetFontMetric( aNewFont );
DrawText( Point( 10, 10 ), String( "FontName : " ) +
String( aMetric.GetName() ) );
String aTempStr;
switch ( aMetric.GetFamily() )
{
case FAMILY_SWISS:
aTempStr = "Swiss";
break;
case FAMILY_MODERN:
aTempStr = "Modern";
break;
case FAMILY_DECORATIVE:
aTempStr = "Decorative";
break;
case FAMILY_ROMAN:
aTempStr = "Roman";
break;
case FAMILY_SCRIPT:
aTempStr = "Script";
break;
case FAMILY_SYSTEM:
aTempStr = "System";
break;
default:
aTempStr = "DontKnow";
break;
}
DrawText( Point( 10, 30 ), String( "Family : " ) +
aTempStr );
DrawText( Point( 10, 50 ), String( "FontSize : " ) +
String( aMetric.GetSize().
Width() ) +
String( ';' ) +
String( aMetric.GetSize().
Height() ) );
switch ( aMetric.GetPitch() )
{
case PITCH_FIXED:
aTempStr = "Fixed";
break;
case PITCH_VARIABLE:
aTempStr = "Variable";
break;
default:
aTempStr = "DontKnow";
break;
}
DrawText( Point( 10, 70 ), String( "Pitch : " ) +
aTempStr );
switch ( aMetric.GetCharSet() )
{
case CHARSET_ANSI:
aTempStr = "Ansi";
break;
case CHARSET_IBMPC:
aTempStr = "IBM-PC";
break;
case CHARSET_MAC:
aTempStr = "Mac";
break;
case CHARSET_SYMBOL:
aTempStr = "Symbol";
break;
default:
aTempStr = "DontKnow";
break;
}
DrawText( Point( 10, 90 ), String( "CharSet : " ) +
aTempStr );
switch ( aMetric.GetType() )
{
case TYPE_RASTER:
aTempStr = "Raster";
break;
case TYPE_VECTOR:
aTempStr = "Vector";
break;
case TYPE_SCALABLE:
aTempStr = "Scalable";
break;
default:
aTempStr = "DontKnow";
break;
}
DrawText( Point( 10, 110 ), String( "FontType : " ) +
aTempStr );
switch ( aMetric.GetWeight() )
{
case WEIGHT_LIGHT:
aTempStr = "Light";
break;
case WEIGHT_NORMAL:
aTempStr = "Normal";
break;
case WEIGHT_BOLD:
aTempStr = "Bold";
break;
default:
aTempStr = "DontKnow";
break;
}
DrawText( Point( 10, 130 ), String( "Weight : " ) +
aTempStr );
DrawText( Point( 10, 150 ), String( "Italic : " ) +
((aMetric.IsItalic()) ?
"TRUE" : "FALSE") );
DrawText( Point( 10, 170 ), String( "Underline : " ) +
((aMetric.IsUnderline()) ?
"TRUE" : "FALSE") );
DrawText( Point( 10, 190 ), String( "Strikeout : " ) +
((aMetric.IsStrikeout()) ?
"TRUE" : "FALSE") );
DrawText( Point( 10, 210 ), String( "Shadow : " ) +
((aMetric.IsShadow()) ?
"TRUE" : "FALSE") );
DrawText( Point( 10, 230 ), String( "Outline : " ) +
((aMetric.IsOutline()) ?
"TRUE" : "FALSE") );
DrawText( Point( 10, 250 ), String( "Transparent : " ) +
((aMetric.IsTransparent()) ?
"TRUE" : "FALSE") );
DrawText( Point( 10, 270 ), String( "IsDeviceFont : " ) +
((aMetric.IsDeviceFont()) ?
"TRUE" : "FALSE") );
DrawText( Point( 10, 290 ), String( "Ascent : " ) +
String( aMetric.GetAscent() ) );
DrawText( Point( 10, 310 ), String( "Descent : " ) +
String( aMetric.GetDescent() ) );
DrawText( Point( 10, 330 ), String( "Leading : " ) +
String( aMetric.GetLeading() ) );
if ( aMetric.GetLineOrientation() != LINEORIENTATION_DONTKNOW )
DrawText( Point( 10, 350 ),
String( "LineOrientation: " ) +
String( aMetric.GetLineOrientation() ) );
else
DrawText( Point( 10, 350 ),
String( "LineOrientation: DontKnow" ) );
if ( aMetric.GetCharOrientation() != CHARORIENTATION_DONTKNOW )
DrawText( Point( 10, 370 ),
String( "CharOrientation: " ) +
String( aMetric.GetCharOrientation() ) );
else
DrawText( Point( 10, 370 ),
String( "CharOrientation: DontKnow" ) );
ChangeFont( aNewFont );
DrawText( Point( 300, 200 ), "Test" );
}
// --- AppWin::FontHdl() -------------------------------------------
void AppWin::FontHdl( PushButton* )
{
if ( aFontDialog.Execute() )
Invalidate();
}
// --- MyApp::Main() -----------------------------------------------
void MyApp::Main( int, char*[] )
{
AppWin aAppWin;
Execute();
}
// --- aMyApp ------------------------------------------------------
MyApp aMyApp;
#ifdef MAC
Application* pApp = &aMyApp;
#endif