home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- //
- // This file is Copyright 1992,1993 by Warwick W. Allison.
- // This file is part of the gem++ library.
- // You are free to copy and modify these sources, provided you acknowledge
- // the origin by retaining this notice, and adhere to the conditions
- // described in the file COPYING.LIB.
- //
- /////////////////////////////////////////////////////////////////////////////
-
- #include "gemsl.h"
- #include "gemf.h"
- #include "contract.h"
- #include <aesbind.h>
- #include <minmax.h>
-
- class SL_Knob : public GEMobject
- {
- public:
- SL_Knob(GEMform& f, int RSCindex, GEMslider& tell) :
- GEMobject(f, RSCindex),
- Tell(tell)
- { }
-
- virtual GEMfeedback Touch(int x, int y, const GEMevent&)
- {
- int tx,ty;
-
- Tell.GetAbsoluteXY(tx,ty);
-
- int ox,oy,nx,ny;
- ox=tx+X();
- oy=ty+Y();
-
- graf_dragbox(Width(),Height(),ox,oy,
- tx,ty,Tell.Width(),Tell.Height(),&nx,&ny);
-
- if (ox!=nx || oy!=ny) {
- MoveTo(nx-tx,ny-ty);
- Tell.GEMtoDOC();
- Tell.Flush();
- }
-
- return ContinueInteraction;
- }
-
- private:
- GEMslider& Tell;
- };
-
-
- class SL_Left : public GEMobject
- {
- public:
- SL_Left(GEMform& f, int RSCindex, GEMslider& tell) :
- GEMobject(f, RSCindex),
- Tell(tell)
- { }
-
- virtual GEMfeedback Touch(int x, int y, const GEMevent&)
- {
- Tell.ColumnLeft();
- Tell.Flush();
- return ContinueInteraction;
- }
-
- private:
- GEMslider& Tell;
- };
-
-
- class SL_Right : public GEMobject
- {
- public:
- SL_Right(GEMform& f, int RSCindex, GEMslider& tell) :
- GEMobject(f, RSCindex),
- Tell(tell)
- { }
-
- virtual GEMfeedback Touch(int x, int y, const GEMevent&)
- {
- Tell.ColumnRight();
- Tell.Flush();
- return ContinueInteraction;
- }
-
- private:
- GEMslider& Tell;
- };
-
-
- class SL_Up : public GEMobject
- {
- public:
- SL_Up(GEMform& f, int RSCindex, GEMslider& tell) :
- GEMobject(f, RSCindex),
- Tell(tell)
- { }
-
- virtual GEMfeedback Touch(int x, int y, const GEMevent&)
- {
- Tell.LineUp();
- Tell.Flush();
- return ContinueInteraction;
- }
-
- private:
- GEMslider& Tell;
- };
-
-
- class SL_Down : public GEMobject
- {
- public:
- SL_Down(GEMform& f, int RSCindex, GEMslider& tell) :
- GEMobject(f, RSCindex),
- Tell(tell)
- { }
-
- virtual GEMfeedback Touch(int x, int y, const GEMevent&)
- {
- Tell.LineDown();
- Tell.Flush();
- return ContinueInteraction;
- }
-
- private:
- GEMslider& Tell;
- };
-
-
-
- GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack) :
- GEMobject(f,RSCrack),
- K(new SL_Knob(f,RSCknob,*this)),
- U(0),D(0),L(0),R(0),
- visibleLines(K->Height()),visibleColumns(K->Width()),
- totalLines(Height()),totalColumns(Width())
- {
- GEMtoDOC();
- }
-
- GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack, int RSCminus, int RSCplus) :
- GEMobject(f,RSCrack),
- K(new SL_Knob(f,RSCknob,*this)),
- U(0),D(0),L(0),R(0),
- visibleLines(K->Height()),visibleColumns(K->Width()),
- totalLines(Height()),totalColumns(Width())
- {
- GEMtoDOC();
- if (Width()-K->Width() > Height()-K->Height()) {
- // Horizontal
- L=new SL_Left(f,RSCminus,*this);
- R=new SL_Right(f,RSCplus,*this);
- } else {
- // Vertical
- U=new SL_Up(f,RSCminus,*this);
- D=new SL_Down(f,RSCplus,*this);
- }
- }
-
- GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack,
- int RSChplus, int RSChminus,
- int RSCvplus, int RSCvminus) :
- GEMobject(f,RSCrack),
- K(new SL_Knob(f,RSCknob,*this)),
- L(new SL_Left(f,RSChminus,*this)),
- R(new SL_Right(f,RSChplus,*this)),
- U(new SL_Up(f,RSCvminus,*this)),
- D(new SL_Down(f,RSCvplus,*this)),
- visibleLines(K->Height()),visibleColumns(K->Width()),
- totalLines(Height()),totalColumns(Width())
- {
- GEMtoDOC();
- }
-
- GEMslider::~GEMslider()
- {
- delete K;
- if (U) delete U;
- if (D) delete D;
- if (L) delete L;
- if (R) delete R;
- }
-
- GEMfeedback GEMslider::Touch(int x, int y, const GEMevent&)
- {
- if (x<K->X()) PageLeft();
- else if (x>=K->X()+K->Width()) PageRight();
- if (y<K->Y()) PageUp();
- else if (y>=K->Y()+K->Height()) PageDown();
- Flush();
- return ContinueInteraction;
- }
-
- void GEMslider::DOCtoGEM()
- {
- if (totalLines > 0) {
- K->Resize(max(6,Width()*visibleColumns/totalColumns),
- max(6,Height()*visibleLines/totalLines));
- K->MoveTo(
- totalColumns==visibleColumns ? 0
- : actualLeftColumn*(Width()-K->Width())/(totalColumns-visibleColumns),
- totalLines==visibleLines ? 0
- : actualTopLine*(Height()-K->Height())/(totalLines-visibleLines)
- );
- }
- }
-
- void GEMslider::GEMtoDOC()
- {
- if (Height()>K->Height()) {
- actualTopLine = K->Y()*(totalLines-visibleLines)/(Height()-K->Height());
- }
- if (Width()>K->Width()) {
- actualLeftColumn = K->X()*(totalColumns-visibleColumns)/(Width()-K->Width());
- }
- }
-
- void GEMslider::Flush()
- {
- DOCtoGEM();
- Redraw();
- }
-
- void GEMslider::SetVisibleLines( int noOfLines )
- {
- Require(noOfLines >= 0);
- Require(noOfLines <= totalLines);
-
- visibleLines = noOfLines;
-
- if (actualTopLine > totalLines - visibleLines)
- actualTopLine = totalLines - visibleLines;
- }
-
- void GEMslider::SetTotalLines( int noOfLines )
- {
- Require(noOfLines >= 0);
-
- totalLines = noOfLines;
-
- if (noOfLines < visibleLines) {
- visibleLines = totalLines;
- }
-
- if (actualTopLine > totalLines - visibleLines) {
- actualTopLine = totalLines - visibleLines;
- }
- }
-
- void GEMslider::SetTopLine( int noOfLine )
- {
- Require(noOfLine >= 0);
- Require(noOfLine <= totalLines - visibleLines);
-
- if (actualTopLine != noOfLine) {
- actualTopLine = noOfLine;
- }
- }
-
- void GEMslider::SetVisibleColumns( int noOfColumns )
- {
- Require(noOfColumns >= 0);
- Require(noOfColumns <= totalColumns);
-
- if (visibleColumns != noOfColumns) {
- visibleColumns = noOfColumns;
-
- if (actualLeftColumn > totalColumns - visibleColumns)
- actualLeftColumn = totalColumns - visibleColumns;
- }
- }
-
- void GEMslider::SetTotalColumns( int noOfColumns )
- {
- Require(noOfColumns >= 0);
-
- totalColumns = noOfColumns;
-
- if (noOfColumns < visibleColumns) {
- visibleColumns = totalColumns;
- }
-
- if (actualLeftColumn > totalColumns - visibleColumns) {
- actualLeftColumn = totalColumns - visibleColumns;
- }
- }
-
- void GEMslider::SetLeftColumn( int noOfColumn )
- {
- Require(noOfColumn >= 0);
- Require(noOfColumn <= totalColumns - visibleColumns);
-
- if (actualLeftColumn != noOfColumn) {
- actualLeftColumn = noOfColumn;
- }
- }
-
-
- void GEMslider::LineUp()
- {
- if (actualTopLine > 0) {
- actualTopLine--;
- }
- }
-
- void GEMslider::LineDown()
- {
- if (actualTopLine < totalLines - visibleLines) {
- actualTopLine++;
- }
- }
-
- void GEMslider::PageUp()
- {
- if (actualTopLine > 0) {
- actualTopLine = (actualTopLine>=visibleLines)?
- actualTopLine-visibleLines : 0;
- }
- }
-
- void GEMslider::PageDown()
- {
- if (actualTopLine < totalLines - visibleLines) {
- actualTopLine =
- (actualTopLine+visibleLines
- > totalLines-visibleLines)?
- totalLines-visibleLines :
- actualTopLine+visibleLines;
- }
- }
-
-
- void GEMslider::ColumnLeft()
- {
- if (actualLeftColumn > 0) {
- actualLeftColumn--;
- }
- }
-
- void GEMslider::ColumnRight()
- {
- if (actualLeftColumn < totalColumns - visibleColumns) {
- actualLeftColumn++;
- }
- }
-
- void GEMslider::PageLeft()
- {
- if (actualLeftColumn > 0) {
- actualLeftColumn = (actualLeftColumn>=visibleColumns)?
- actualLeftColumn-visibleColumns : 0;
- }
- }
-
- void GEMslider::PageRight()
- {
- if (actualLeftColumn < totalColumns-visibleColumns) {
- actualLeftColumn =
- (actualLeftColumn+visibleColumns
- > totalColumns-visibleColumns) ?
- totalColumns - visibleColumns :
- actualLeftColumn + visibleColumns;
- }
- }
-