home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
pwrgu2.zip
/
POWERGU2.EXE
/
CANVAS
/
COMPLEX
/
XCANVAS.CPP
< prev
next >
Wrap
Text File
|
1995-08-21
|
9KB
|
248 lines
//************************************************************
// Canvas - Complex Canvas Example
//
// Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
// All Rights Reserved.
//************************************************************
#include <icolor.hpp>
#include <iscroll.hpp>
#include <istring.hpp>
#include "xcanvas.hpp"
#include "xcanvas.h"
//==================== ComplexCanvasWindow =====================
ComplexCanvasWindow :: ComplexCanvasWindow ( )
: frame( "Multiple Canvas Window" ),
clientCanvas( 1, &frame, &frame ),
headingText( 2, &clientCanvas, &clientCanvas ),
topSeparator( 3, &clientCanvas, &clientCanvas ),
level1( 4, &clientCanvas, &clientCanvas ),
horizSplit( 5, &level1, &level1 ),
vertSplit( 6, &horizSplit, &horizSplit ),
sizedBmp1( 7, &vertSplit, &vertSplit, ID_FLAMINGO_BMP ),
sizedBmp2( 8, &vertSplit, &vertSplit, ID_BUTTERFL_BMP ),
bmpScroller( 9, &horizSplit, &horizSplit,
IRectangle(),
IViewPort::classDefaultStyle
& ~IViewPort::asNeededHorizontalScrollBar
& ~IViewPort::asNeededVerticalScrollBar
| IViewPort::alwaysHorizontalScrollBar
| IViewPort::alwaysVerticalScrollBar
| IViewPort::noViewWindowFill ),
actualSizeBmp( 10, &bmpScroller, &bmpScroller, ID_OS2_BMP ),
centerSeparator( 11, &level1, &level1 ),
dlgScroller( 11, &level1 ),
level2( 12, &dlgScroller, &dlgScroller ),
prompt( 13, &level2, &level2 ),
entry( 14, &level2, &level2 ),
choice1( 15, &level2, &level2 ),
choice2( 16, &level2, &level2 ),
listHeading( 17, &level2, &level2 ),
list( 18, &level2, &level2 ),
rightSeparator( 19, &level2, &level2 ),
colorButtons( 20, &level2 ),
pushButtons( 21, &level2 )
{
headingText
.setText( "This window combines several canvases." );
topSeparator
.setColor( IStaticText::fill, IColor::black )
.setMinimumSize( ISize( 1, 1 ));
centerSeparator
.setColor( IStaticText::fill, IColor::black )
.setMinimumSize( ISize( 1, 1 ));
// Set up split canvases.
horizSplit
.setOrientation( ISplitCanvas::horizontalSplit )
.setSplitWindowPercentage( &vertSplit, 33 )
.setSplitWindowPercentage( &bmpScroller, 67 );
horizSplit.setMinimumSize( ISize() );
// Set up the dialog portion of the window.
dlgScroller.setMinimumSize( ISize() );
prompt.setText( "Enter some data below." );
entry
.setLimit( 15 )
.enableTabStop()
.enableGroup();
choice1
.setText( "~First" )
.enableTabStop()
.enableGroup();
choice2
.setText( "~Second" );
listHeading
.setText( "Below is a list box." );
list
.enableTabStop()
.enableGroup()
.setMinimumSize( ISize( 50, 50 ));
rightSeparator
.setColor( IStaticText::fill, IColor::black )
.setMinimumSize( ISize( 1, 1 ));
ISize defaultCellSize = IMultiCellCanvas::defaultCell();
clientCanvas
.addToCell( &headingText, 1, 2 )
.addToCell( &topSeparator, 1, 3 )
.addToCell( &level1, 1, 4 );
clientCanvas
.setColumnWidth( 1, 1, true )
.setRowHeight( 4, 1, true );
level1
.addToCell( &horizSplit, 1, 1, 2 )
.addToCell( ¢erSeparator, 3, 1 )
.addToCell( &dlgScroller, 4, 1, 2 );
level1
.setColumnWidth( 2, 1, true ) // Use 1:2 ratio.
.setColumnWidth( 5, 2, true )
.setRowHeight( 1, 1, true );
level2
.addToCell( &prompt, 2, 2, 5 )
.addToCell( &entry, 2, 4, 5 )
.addToCell( &choice1, 3, 6 )
.addToCell( &choice2, 5, 6 )
.addToCell( &listHeading, 2, 8, 5 )
.addToCell( &list, 2, 10, 5 )
.addToCell( &rightSeparator, 8, 1, 1, 11 )
.addToCell( &colorButtons, 9, 1, 1, 11 );
level2
.setColumnWidth( 4, 1, true )
.setColumnWidth( 6, 1, true )
.setRowHeight( 10, 1, true )
.setRowHeight( 11, defaultCellSize.height() );
pushButtons.setMargin( defaultCellSize / 2 );
frame
.setClient( &clientCanvas )
.addExtension( &pushButtons, IFrameWindow::belowClient,
(unsigned long)
pushButtons.minimumSize().height() )
.setFocus()
.show();
}
//======================= ColorButtons ========================
ColorButtons :: ColorButtons ( unsigned long id,
IWindow* parentAndOwner )
: ISetCanvas( id, parentAndOwner, parentAndOwner ),
red( 1, this, this, ID_SCREEN_ICON ),
green( 2, this, this, ID_SCREEN_ICON ),
blue( 3, this, this, ID_SCREEN_ICON ),
cyan( 4, this, this, ID_SCREEN_ICON ),
pink( 5, this, this, ID_SCREEN_ICON )
{
(*this)
.setPackType( ISetCanvas::expanded )
.setDeckOrientation( ISetCanvas::vertical );
ISize colorSize( 40, 40 );
red
.setColor( IButton::background, IColor::red )
.enableTabStop()
.enableGroup()
.setMinimumSize( colorSize );
green
.setColor( IButton::background, IColor::green )
.setMinimumSize( colorSize );
blue
.setColor( IButton::background, IColor::blue )
.setMinimumSize( colorSize );
cyan
.setColor( IButton::background, IColor::cyan )
.setMinimumSize( colorSize );
pink
.setColor( IButton::background, IColor::pink )
.setMinimumSize( colorSize );
}
//============= ViewPortWithGrowableMinSizeChild ===============
ViewPortWithGrowableMinSizeChild::
ViewPortWithGrowableMinSizeChild ( unsigned long windowId,
IWindow* parentAndOwner )
: IViewPort( windowId, parentAndOwner, parentAndOwner,
IRectangle(),
IViewPort::classDefaultStyle
| IViewPort::noViewWindowFill )
{ }
ViewPortWithGrowableMinSizeChild
&ViewPortWithGrowableMinSizeChild::setLayoutDistorted
( unsigned long flagsOn,
unsigned long flagsOff )
{
if ( flagsOn & IWindow::childMinimumSizeChanged )
{
unsigned long newFlagsOn =
flagsOn & (unsigned long)(~IWindow::childMinimumSizeChanged);
newFlagsOn |= IWindow::layoutChanged;
newFlagsOn |= IWindow::immediateUpdate;
ICanvas::setLayoutDistorted( newFlagsOn, flagsOff );
}
else
{
IViewPort::setLayoutDistorted( flagsOn, flagsOff );
}
return *this;
}
ViewPortWithGrowableMinSizeChild
&ViewPortWithGrowableMinSizeChild::layout ( )
{
if ( this->isLayoutDistorted( IWindow::layoutChanged ))
{
IWindow* child = IWindow::windowWithHandle( this->viewWindow() );
if ( child )
{
ISize viewPortSize = this->size();
ISize minChildSize = child->minimumSize();
ISize childSize = child->size();
ISize newChildSize = viewPortSize; // Grow to view port size.
if ( viewPortSize.width() < minChildSize.width() )
{ // Don't shrink child smaller than its minimum size.
newChildSize.setWidth( minChildSize.width() );
} // (Let the view port scroll it.)
else if ( viewPortSize.height() < minChildSize.height() )
{ // Allow room for vertical scroll bar if needed.
newChildSize.setWidth( viewPortSize.width() -
this->verticalScrollBar()->size().width() );
if ( newChildSize.width() < minChildSize.width() )
{ // Don't shrink child smaller than its minimum size.
newChildSize.setWidth( minChildSize.width() );
} // (Let the view port scroll it.)
}
if ( viewPortSize.height() < minChildSize.height() )
{ // Don't shrink child smaller than its minimum size.
newChildSize.setHeight( minChildSize.height() );
} // (Let the view port scroll it.)
else if ( viewPortSize.width() < minChildSize.width() )
{ // Allow room for horizontal scroll bar if needed.
newChildSize.setHeight( viewPortSize.height() -
this->horizontalScrollBar()->size().height() );
if ( newChildSize.height() < minChildSize.height() )
{ // Don't shrink child smaller than its minimum size.
newChildSize.setHeight( minChildSize.height() );
} // (Let the view port scroll it.)
}
if ( newChildSize != childSize )
{ // Need to resize the child window.
child->sizeTo( newChildSize );
}
}
IViewPort::layout();
}
return *this;
}