Problem using TScroller if unit !=1

I develop a program under Windows95 using Borland C++ 5.00 and OWL5.0.
The scroll box (thumb) desn't scroll the whole range if the unit parameter (e.g. YUnit) of TScroller differs from 1, but the arrows at the end of the scrollbar work correctly. Furthermore if the range parameter (YRange) is a little value (e.g. 6) the scrollbar doesn't appear. See the sample program of BC++ 5.00 in the examples\owl\classes\scroller directory.
Does anybody know a solution for my problem? Thanks.
moczarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

moczarAuthor Commented:
Edited text of question
0
pangofilCommented:
You have to make your window scrollable :

put in your constructor follow :

{
...

Attr.tyle |= WS_HSCROLL | WS_VSCROLL ;
Sceoller = TScroller ( ... ) ;

...
}


It works fro me in 100% of cases.

Hope it helps
0
moczarAuthor Commented:
This is a code fragment of the Borland OWL sample program (examples\owl\classes\scroller\scrollex.cpp). It generates the described error for me.

const int XUnits = 7;
const int YUnits = 16;
const int XRange = 80;
const int YRange = 6; //60; was originally

// class TScrollWindow
class TScrollWindow : public TWindow {
  public:
    TScrollWindow(TWindow* parent = 0, const char* title = 0);
    void Paint(TDC& dc, bool, TRect&);
};

// Constructor for a TScrollWindow, sets scroll styles and
// constructs the Scroller object.

TScrollWindow::TScrollWindow(TWindow* parent, const char* title)
:
  TWindow(parent, title)
{
  Attr.Style |= WS_VSCROLL | WS_HSCROLL;
  Scroller = new TScroller(this, XUnits, YUnits, XRange, YRange);
}


0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

jasoncCommented:
You cannot just change ranges like that and expect it to work properly.  Keep in mind that TScroller does not care what is in the window.  YOU are responsible for resetting the scrollers range and units every time the user resizes the window, etc.  If you set the range to 6 it's going to let you hit the down arrow 5 times and that's it. If you don't get all the way to the bottom of what you're trying to display it's your own fault.

0
moczarAuthor Commented:
Thank you for the answer. But it is not the content of the window  I have problems with. I have problem with the scrollbar itself.

Problem 1.: If the YRange is a small value (e.g. 6) the scrollbar doesn't appear. Why?

Problem 2.: If the YRange is a bigger value (e.g.60) the scrollbar appears and the arrows at its end work correctly, that is you can hit the down arrow 59 times. However if you don't scroll the window with the arrows but with the thumb (the scroll rectangle) it scrolls less, about 47 steps. In other words, the arrows at the end of it work properly, but dragging the thumb rectangle and pulling it from one end of the scrollbar to the other doesn't provide as big scrolling as the arrows did. Why?

0
NickRepinCommented:
There are errors in implementation of TScroller in OWL (namely in TScroller::SetPageSize()).
It is not work correctly if XUnit (YUnit)!=1.

Problem1:
If you set YRange=6, YUnit=8, TScroller set range value for window's scroll bar as 6, page size as 8. It is standard Windows behavior with these values to hide scroll bar.

Problem2:
There are two class members in TScroller,  XTotalUnits and YTotalUnits. You need to set them also. But as I said TScroller will not work correctly even in this case.

I had to write my own NScroller (descendant from TScroller) to fix this problem and to use variable-length thumb.

 May be better way for you to set  XUnit=YUnit=1, but use XLine & YLine instead.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
moczarAuthor Commented:
Thank you for your answer.
The 'XUnit==YUnit=1 XLine,YLine' solution didn't conduce me to fix the Problem2. Would you describe me more detailed how to fix this problem using a descendant from TScroller, please!
Thank you.
0
NickRepinCommented:
I used window with MM_ISOTROPIC map mode and various set of SetWindowExt&SetViewPortExt to display bitmap with different zoom value (5...3000%). But in following code I have stripped lines that handle zoom job.
I suppose your window has MM_TEXT map mode (1 device unit = 1 logical unit).

You can compare NScroller code with
TScroller source (BC5\SOURCE\OWL\scroller.cpp).

Write me if you have any questions.

//---------------------------------------------------------------------------
// NScroller class
//---------------------------------------------------------------------------
class NScroller : public TScroller
{
   public:
      NScroller(TWindow* win) : TScroller(win,1,1,0,0) { }
      void SetPageSize();
      void SetSBarRange() { }   // Override parent's function!
      void SetRange(long xRange,long yRange);
};
//---------------------------------------------------------------------------
void NScroller::SetPageSize()
{
   if(Window && Window->GetHandle()) {
      TPoint p(Window->GetClientRect().Size());
      if(p.x<1) p.x=1;
      if(p.y<1) p.y=1;

      // Number of bitmap's pixels to scroll when user press arrow
      // on scroll bar
      XLine=YLine=1;

      // Range to scroll, must be less then XTotalUnits (bitmap's width)
      XRange=XTotalUnits+1-p.x;
      YRange=YTotalUnits+1-p.y;

      // Page size equal width (height) of  window's client area
      XPage=p.x;
      YPage=p.y;

      Window->SetScrollPage(SB_HORZ,XPage,true);
      Window->SetScrollPage(SB_VERT,YPage,true);
      ScrollTo(XPos,YPos);
   }
}
//---------------------------------------------------------------------------
void NScroller::SetRange(long xRange,long yRange)
{
   XTotalUnits=xRange-1;
   YTotalUnits=yRange-1;
   if(Window && Window->GetHandle()) {
      int curMin,curMax;
      Window->GetScrollRange(SB_HORZ,curMin,curMax);
      int newMax=max(0,min(int(XTotalUnits),SHRT_MAX));
      if(newMax!=curMax || curMin!=0)
         Window->SetScrollRange(SB_HORZ,0,newMax,false);
      Window->GetScrollRange(SB_VERT,curMin,curMax);
      newMax=max(0,min(int(YTotalUnits),SHRT_MAX));
      if(newMax!=curMax || curMin!=0)
         Window->SetScrollRange(SB_VERT,0,newMax,false);
   }
   SetPageSize();
}

//---------------------------------------------------------------------------
// NView (bitmap's window) class functions
//---------------------------------------------------------------------------
NView::NView(...) : TMDIChild(parent)
{
   Attr.Style|=WS_VSCROLL|WS_HSCROLL;
   Scroller=new NScroller(this);
}
//---------------------------------------------------------------------------
bool NView::SetDib(TDib* newdib)
{

   // This function loads image into window
   // ...
   // Setting scroller range
   if(newdib==0)
      Scroller->SetRange(0,0);   // Hide scroll bar
   else
      Scroller->SetRange(dib->Width(),dib->Height());

   Invalidate();
   UpdateWindow();
}
//---------------------------------------------------------------------------
void NView::Paint(...)
{
   // ...
}
//---------------------------------------------------------------------------

0
moczarAuthor Commented:
Thank you very much, it works fine.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.