Laxkit  0.0.7.1
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
Laxkit::Scroller Class Reference

A vertical or horizontal scroll bar, with optional zooming handles, and togglable arrow positions. More...

Inheritance diagram for Laxkit::Scroller:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 Scroller (anXWindow *parnt, const char *nname, const char *ntitle, unsigned long nstyle, int nx, int ny, int nw, int nh, int brder, anXWindow *prev, unsigned long nowner, const char *mes, PanController *npan, long nmins=0, long nmaxs=0, long nps=0, long nes=0, long ncp=-1, long ncpe=-1)
 Constructor. Creates a new panner if npan==NULL.
virtual ~Scroller ()
 Empty default destructor.
virtual int Event (const EventData *e, const char *mes)
virtual void Refresh ()
 Essentially clears the window, then drawtrack(), then drawtrackbox().
virtual int Idle (int id=0)
virtual int MoveResize (int nx, int ny, int nw, int nh)
 Calls anXWindow::MoveResize, then redoarrows.
virtual int Resize (int nw, int nh)
 Calls anXWindow::Resize, then redoarrows.
virtual int RBDown (int mx, int my, unsigned int state, int count, const LaxMouse *d)
 Right clicking on the arrows causes pageup/down at the next idle or on RBUp.
virtual int RBUp (int mx, int my, unsigned int state, const LaxMouse *d)
 Right clicking on the arrows causes pageup/down.
virtual int LBDown (int mx, int my, unsigned int state, int count, const LaxMouse *d)
 LBDown.
virtual int LBUp (int mx, int my, unsigned int state, const LaxMouse *d)
virtual int WheelUp (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Wheel up. Move 1 element, shift or control moves 1 page, shift+control moves 5 pages.
virtual int WheelDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Wheel down. Move 1 element, shift moves 1 page, shift+control moves 5 pages.
virtual int MouseMove (int mx, int my, unsigned int state, const LaxMouse *d)
 Mouse Move.
virtual int CharInput (unsigned int ch, const char *buffer, int len, unsigned int state, const LaxKeyboard *d)
 Control-, and control-. toggle the arrow style.
virtual void drawarrows ()
 Draw the arrows in their proper place based on a1off, a2off, and ah.
virtual void drawtrack ()
 Draw the track, including arrows. Default is draw a line, then call drawarrows.
virtual void drawtrackbox ()
 Draw the track box including the zoom handles if required.
virtual long SetPageSize (long nps)
 Sets pagesize (meaning curposend-curpos+1), returns actual new pagesize.
virtual long GetPageSize ()
 Return end-start.
virtual long GetCurPos (long *poss=NULL, long *pose=NULL)
 Just returns panner->GetCurPos(poss,pose);.
virtual long GetCurPosEnd ()
 Returns the panner->end.
virtual long SetCurPos (long newcurpos)
 Sets current position, keeping the old page size. Returns actual new curpos.
virtual long SetCurPos (long start, long end)
 Sets current position and end position, assigning new page size.
virtual long SetSize (long nmins, long nmaxs, long ncurpos, long ncurposend, long nps, long nes)
 Set lots of attributes.
virtual long SetSize (long nmins, long nmaxs, long nps=0)
 Calling this one assumes you want definite pagesize, not pagesize=curposend-curpos.
virtual int getpos (int mx, int my)
 Return which of the various elements the mouse is in.
virtual int send ()
virtual void send (long change, int pagesizechange=0)
 Send a control message. If change==0, then nothing is sent.
virtual long PageDown (int numpages=1)
 Shift the bar numpages up.
virtual long PageUp (int numpages=1)
 Shift the bar numpages down.
virtual long OneDown ()
 Move the track up one unit.
virtual long OneUp ()
 Move the track down one element unit.
virtual LaxFiles::Attributedump_out_atts (LaxFiles::Attribute *att, int what, anObject *context)
virtual void dump_in_atts (LaxFiles::Attribute *att, int flag, anObject *context)
- Public Member Functions inherited from Laxkit::PanUser
 PanUser (PanController *npan=NULL)
 Create with a new panner.
virtual ~PanUser ()
 Removes this from panner tellstack. Delete panner if necessary.
virtual PanControllercreateNewPanner (PanController *pan=NULL)
 Create a new panner that is a copy of pan if given.
virtual void UseThisPanner (PanController *npanner)
 Replace the current panner with npanner, which can be NULL to mean make a new one.
- Public Member Functions inherited from Laxkit::anXWindow
 anXWindow (anXWindow *parnt, const char *nname, const char *ntitle, unsigned long nstyle, int xx, int yy, int ww, int hh, int brder, anXWindow *prev, unsigned long nowner, const char *nsend)
 Constructor.
virtual ~anXWindow ()
 anXWindow destructor. Its X window should have been XDestroy'd before here.
virtual const charwhattype ()
virtual const charWindowTitle (int which=0)
 Return basically the name of the window.
virtual void WindowTitle (const char *newtitle)
 Change the title of the window. This text would usually be displayed in the bar provided by a window manager.
virtual const chartooltip (int mouseid=0)
 By default, return win_tooltip.
virtual const chartooltip (const char *newtooltip)
 Replace the current tooltip, return the current tooltip (after replacing).
virtual anXWindowfindChildWindowByTitle (const char *title)
 Find the first immediate child window that has win_title==title.
virtual anXWindowfindChildWindowByName (const char *name)
 Find the first immediate child window that has win_name==name.
virtual int Grayed ()
 Return whether this window is grayed.
virtual int Grayed (int g)
 Set the gray state of this window. Returns Grayed(void).
virtual int preinit ()
virtual int init ()
 Empty placeholeder. Just returns 0.
virtual int close ()
 Called by anXApp from anXApp::destroywindow() when a window is to be destroyed.
virtual DisplayerMakeCurrent ()
virtual int Needtodraw ()
 Default is to return needtodraw.
virtual void Needtodraw (int nntd)
 If 0, then the window does not need refreshing. Otherwise it does.
virtual int deletenow ()
 Return whether the window is allowed to be deleted.
virtual int setWinStyle (unsigned int stylebit, int newvalue)
 Control various window related basic styling of win_style.
virtual int getWinStyle (unsigned int stylebit)
 Currently, simply return win_style&stylebit.
virtual void installColors (WindowColors *newcolors)
 Dec_count old and inc_count new.
virtual ShortcutHandlerGetShortcuts ()
 Return a ShortcutHandler that contains stacks of bound shortcuts and possible window actions.
virtual int PerformAction (int action_number)
virtual int ExposeChange (ScreenEventData *e)
 Default behavior on Expose events is to call Needtodraw(1).
virtual int DeviceChange (const DeviceEventData *e)
virtual int KeyUp (unsigned int ch, unsigned int state, const LaxKeyboard *kb)
 Called when a key is released.
virtual int ButtonDown (int button, int x, int y, unsigned int state, int count, const LaxMouse *m)
virtual int ButtonUp (int button, int x, int y, unsigned int state, const LaxMouse *m)
virtual int MBDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Default is just to return 1.
virtual int MBUp (int x, int y, unsigned int state, const LaxMouse *d)
 Default is just to return 1.
virtual int FocusOn (const FocusChangeData *e)
 Increment win_active, and highlights the window's border, if the event refers to this window.
virtual int FocusOff (const FocusChangeData *e)
 Decrements win_active, and de-highlights the window's border if win_active==0, if event is a real focus off.
virtual void contentChanged ()
 Windows may call this when their contents change.
virtual void selectionChanged ()
 Windows may call this when their selections change.
virtual anXWindowGetController ()
 Return the window most relevant for tab control loops.
virtual int SelectNextControl (const LaxDevice *d)
 Transfer focus to nextcontrol.
virtual int SelectPrevControl (const LaxDevice *d)
 Transfer the focus to prevcontrol.
virtual void ControlActivation (int on)
 Do special activation or not when controls are activated by tabbing.
virtual int AddPrevControl (anXWindow *prev)
virtual int AddNextControl (anXWindow *next)
virtual int ConnectControl (anXWindow *towhat, int after=1)
 Connect towhat to this. Used for tab loops.
virtual int CloseControlLoop ()
 Close a tab loop.
virtual void SetOwner (anXWindow *nowner, const char *mes=NULL, unsigned int send_mask=0)
 Set the new owner and control message.
virtual void SetOwner (unsigned long nowner_id, const char *mes=NULL, unsigned int send_mask=0)
virtual void dump_out (FILE *f, int indent, int what, anObject *context)
 Simple dumping function.
- Public Member Functions inherited from Laxkit::Tagged
virtual int HasTag (const char *tag, int casematters)
 Return whether the tag exists.
virtual int NumberOfTags ()
 Return the number of tags, strangely enough.
virtual const charGetTag (int i)
 Return const pointer to the tag text for tag number i, where i==0 is the first tag.
virtual charGetAllTags ()
 Return a new char[] with a space separated list of all the tags.
virtual int InsertTags (const char *tags, int casematters)
 Insert tags from a string such as 'tag1 tag2 tag3 "tag with spaces" tag4'.
virtual int InsertTag (const char *tag, int casematters)
 Insert tag if it doesn't exist already.
virtual int RemoveTag (const char *tag)
 The tag must be an exact match.
virtual int RemoveTag (int i)
 Remove tag number i. i must be in range [0..NumberOfTags()-1].
virtual void FlushTags ()
- Public Member Functions inherited from LaxFiles::DumpUtility
virtual void dump_in (FILE *f, int indent, int what, Laxkit::anObject *loadcontext, Attribute **att)
 Read in a file segment as an Attribute, and pass parsing duties to dump_in_atts.
virtual ~DumpUtility ()
 Empty virtual destructor.
- Public Member Functions inherited from Laxkit::aDrawable
 aDrawable (Drawable d=0)
virtual int DrawableType ()
virtual int ValidDrawable ()

Public Attributes

unsigned long bordercolor
unsigned long wholecolor
unsigned long trackcolor
- Public Attributes inherited from Laxkit::PanUser
PanControllerpanner
- Public Attributes inherited from Laxkit::anXWindow
WindowColorswin_colors
anXAppapp
charwin_name
 An arbitrary string to be used as an id.
charwin_title
 The title of the window.
anXWindowwin_parent
int win_screen
unsigned long win_style
int win_x
int win_y
int win_w
int win_h
unsigned int win_border
int win_pointer_shape
 Identifier for a stock mouse shape.
char win_on
 Nonzero if the window is mapped.
char win_active
 Should be positive when the window has a keyboard focus, 0 otherwise.
unsigned long win_owner
 Who gets control messages from this window.
unsigned int win_owner_send_mask
charwin_sendthis
 The type of message that gets sent to owner.
anXWindownextcontrol
anXWindowprevcontrol
- Public Attributes inherited from Laxkit::Tagged
int sorttags

Protected Member Functions

virtual void redoarrows ()
 Sets ah,zh,toff based on a presumed changed in win_w/win_h.
- Protected Member Functions inherited from Laxkit::anXWindow
virtual int deletekid (anXWindow *w)
 Purges child anXWindows from window's child stack.
virtual void SwapBuffers ()
 Swap buffers. This should be called from Refresh() if VIEWPORT_BACK_BUFFER is set in win_style.
virtual void SetupBackBuffer ()
 Initialize the backbuffer.

Protected Attributes

ButtonDownInfo buttondown
int zh
 The height of an individual zoom handle.
int ah
 The height of an individual arrow.
int minboxlen
int toff
 The offset from the left (or top) to the track.
int a1off
 The offset from the left (or top) to the first arrow.
int a2off
 The offset from the left (or top) to the second arrow.
int omx
int omy
int tid
int idlemx
int idlemy
- Protected Attributes inherited from Laxkit::anXWindow
charwin_tooltip
 Convenience variable to hold the window's tooltip, if any.
int needtodraw
RefPtrStack< anXWindow_kids
 Stack of children of the window.
- Protected Attributes inherited from Laxkit::Tagged
PtrStack< charlist_of_tags

Detailed Description

A vertical or horizontal scroll bar, with optional zooming handles, and togglable arrow positions.

Todo:

*** all this assumes max>min, should allow min>max?? flip(pos) { return max-(pos-min); }

*** watch out for ALLOW_SMALL

This uses a PanController to keep track of the space being scrolled through. This is particularly convenient when the scroller is part of a pair, and they have zoom handles, as the PanController helps to synchronize them.

Control-left-click or typing any of '.' ',' '<' or '>' toggles the arrow style, which can be one arrow at each end (SC_ASPLIT), both arrows on top or left (SC_ATOP), or both arrows at the bottom or right (SC_ABOTTOM). Or one can have no arrows at all (SC_NOARROWS).

When there is a change in the scroll bar handle position, a SimpleMessage is filled thus:

    mevent->info1 = amount of change, basically curpos-oldcurpos;
    mevent->info2 = start position;
    mevent->info3 = end position; 
    mevent->info4 = pagesizechange; <– 1 if zoom handle was changed
 

Style Defines:

#define SC_XSCROLL (1<<16)
#define SC_YSCROLL (1<<17)
#define SC_ASPLIT (1<<18)
#define SC_ATOP (1<<19)
#define SC_ABOTTOM (1<<20)
#define SC_NOARROWS (1<<21)
#define SC_ZOOM (1<<22)
#define SC_PAGE_IS_PERCENT (1<<23)
#define SC_ELEMENT_IS_PERCENT (1<<24)
#define SC_ALLOW_SMALL (1<<25) <--- ***not imp yet
 |— a   
 | ^
 |— b 
 | |  c  (c-a)= toff, where track box begins
 | |
 | z  c  
 | z  d (d-c)+1= zh, the height of a zoom handle
 | +  e  
 | +
 | m  ]<– minboxlen is the minimum size of the trackbox (not including zoom handles)
 | m  ]
 | +
 | +    
 | z  f (g-f)+1= zh
 | z  g (g-c+1)=  the track box height
 | |
 | |
 | |
 |— h  (h-c)= th, the height or length of the track
 | v     
 |— i
  bw,bh is the width,height of track box, xscroll or yscroll
  
Todo:
implement 2 point zooming by dragging tracker with 2 devices

Constructor & Destructor Documentation

Laxkit::Scroller::Scroller ( anXWindow parnt,
const char nname,
const char ntitle,
unsigned long  nwstyle,
int  nx,
int  ny,
int  nw,
int  nh,
int  brder,
anXWindow prev,
unsigned long  nowner,
const char mes,
PanController npan,
long  nmins = 0,
long  nmaxs = 0,
long  nps = 0,
long  nes = 0,
long  ncp = -1,
long  ncpe = -1 
)

Constructor. Creates a new panner if npan==NULL.

If npan is not NULL, then all the parameters after npan are ignored, so it's a good thing the constructor is overloaded.

Parameters:
nminsMinimum value
nmaxsMaximum value
npsPage size
nesElement size
ncpCurpos
ncpeCurpos end. Use -1 if you do not need an actual range for the curpos.

References Laxkit::anXWindow::installColors(), redoarrows(), Laxkit::PanController::SetStuff(), and zh.


Member Function Documentation

int Laxkit::Scroller::CharInput ( unsigned int  ch,
const char buffer,
int  len,
unsigned int  state,
const LaxKeyboard d 
)
virtual

Control-, and control-. toggle the arrow style.

Todo:
***: somehow there should be a mechanism to not grab the focus even if the mouse is clicked here.

Reimplemented from Laxkit::anXWindow.

References redoarrows().

void Laxkit::Scroller::dump_in_atts ( LaxFiles::Attribute att,
int  flag,
anObject context 
)
virtual
Attribute * Laxkit::Scroller::dump_out_atts ( LaxFiles::Attribute att,
int  what,
anObject context 
)
virtual

Append to att if att!=NULL, else return a new Attribute whose name is whattype().

Default is to add attributes for "text", and whatever anXWindow adds.

Reimplemented from Laxkit::anXWindow.

References Laxkit::PanController::elementsize, GetCurPos(), Laxkit::PanController::maxsel, Laxkit::PanController::minsel, Laxkit::PanController::pagesize, and LaxFiles::Attribute::push().

int Laxkit::Scroller::getpos ( int  mx,
int  my 
)
virtual

Return which of the various elements the mouse is in.

  purpose here is to find where the mouse was when pressed
  1 left/up arrow
  2 right/down arrow
  3 on tracker
  4 pgleft/up
  5 pgright/down
  6 left/up zoom handle
  7 right/down zoom handle
 

References a1off, a2off, ah, Laxkit::PanController::GetMagToBox(), Laxkit::PanController::GetMagToWhole(), toff, and zh.

Referenced by LBDown(), RBDown(), and RBUp().

int Laxkit::Scroller::Idle ( int  id = 0)
virtual
Todo:
put in shift/control on idling too.. maybe have call to WheelUp/WheelDown
Todo:
this does not properly distinguish between left and right clicks...

Reimplemented from Laxkit::anXWindow.

References Laxkit::ButtonDownInfo::any(), Laxkit::ButtonDownInfo::getextrainfo(), OneDown(), OneUp(), PageDown(), PageUp(), Laxkit::anXApp::removetimer(), and Laxkit::ButtonDownInfo::whichdown().

int Laxkit::Scroller::MouseMove ( int  mx,
int  my,
unsigned int  state,
const LaxMouse d 
)
virtual
long Laxkit::Scroller::OneDown ( )
virtual

Move the track up one unit.

Returns 1 if movement occurs.

References Laxkit::PanController::OneUp().

Referenced by Idle(), and WheelDown().

long Laxkit::Scroller::OneUp ( )
virtual

Move the track down one element unit.

Returns amount of change.

References Laxkit::PanController::OneDown().

Referenced by Idle(), and WheelUp().

long Laxkit::Scroller::PageDown ( int  numpages = 1)
virtual

Shift the bar numpages up.

This does not send an event. It is assumed that the application calls this, and already knows that it is calling and so does not need to be notified of changes.

Returns amount of change.

References Laxkit::PanController::PageUp().

Referenced by Idle(), RBUp(), and WheelDown().

long Laxkit::Scroller::PageUp ( int  numpages = 1)
virtual

Shift the bar numpages down.

This does not send an event. It is assumed that the application calls this, and already knows that it is calling and so does not need to be notified of changes.

Returns amount of change.

References Laxkit::PanController::PageDown().

Referenced by Idle(), RBUp(), and WheelUp().

int Laxkit::Scroller::RBUp ( int  mx,
int  my,
unsigned int  state,
const LaxMouse d 
)
virtual

Right clicking on the arrows causes pageup/down.

Control-Right click changes the arrow styles.

Reimplemented from Laxkit::anXWindow.

References Laxkit::ButtonDownInfo::any(), Laxkit::ButtonDownInfo::getinfo(), getpos(), Laxkit::ButtonDownInfo::isdown(), PageDown(), PageUp(), Laxkit::anXApp::removetimer(), and Laxkit::ButtonDownInfo::up().

void Laxkit::Scroller::redoarrows ( )
protectedvirtual

Sets ah,zh,toff based on a presumed changed in win_w/win_h.

zoom height is 2/3 of the window height (for x scrollers, for instance)

References a1off, a2off, ah, toff, and zh.

Referenced by CharInput(), MoveResize(), Resize(), and Scroller().

void Laxkit::Scroller::send ( long  change,
int  pagesizechange = 0 
)
virtual

Send a control message. If change==0, then nothing is sent.

Fills a SimpleMessage thus:

  info1 = amount of change, basically curpos-oldcurpos;
    info2 = start position;
    info3 = end position; 
    info4 = pagesizechange; 
 

pagesizechange should be nonzero if there has been some zooming action.

References Laxkit::PanController::GetCurPos(), Laxkit::anXApp::SendMessage(), Laxkit::anXWindow::win_owner, Laxkit::anXWindow::win_sendthis, and Laxkit::anXWindow::WindowTitle().

long Laxkit::Scroller::SetCurPos ( long  newcurpos)
virtual

Sets current position, keeping the old page size. Returns actual new curpos.

Returns difference between old and new pos.

References Laxkit::PanController::SetCurPos().

Referenced by Laxkit::MultiLineEdit::makeinwindow(), and Laxkit::MultiLineEdit::ShiftScreen().

long Laxkit::Scroller::SetCurPos ( long  start,
long  end 
)
virtual

Sets current position and end position, assigning new page size.

Returns difference between new curpos and old curpos.

References Laxkit::PanController::SetCurPos().

long Laxkit::Scroller::SetSize ( long  nmins,
long  nmaxs,
long  ncurpos,
long  ncurposend,
long  nps,
long  nes 
)
virtual

Set lots of attributes.

nps and nes are interpreted however the panner interprets them. That is, whether they are percent of the selbox or absolute space units.

Returns whatever panner->SetStuff returns, currently just 1 if stuff was set else 0.

Parameters:
nminsNew minimum number
nmaxsNew maximum number
ncurposNew current position
ncurposendNew current end position
npsNew page size (could be percent, depends on panner settings)
nesNew element size (could be percent, depends on panner settings)

References Laxkit::PanController::SetStuff().

Referenced by Laxkit::MultiLineEdit::Getmostwide().

long Laxkit::Scroller::SetSize ( long  nmins,
long  nmaxs,
long  nps = 0 
)
virtual

Calling this one assumes you want definite pagesize, not pagesize=curposend-curpos.

Returns curpos.

Parameters:
nminsNew minimum size
nmaxsNew maximym size
npsNew size for curposend-curpos+1.

References Laxkit::PanController::SetSize().


The documentation for this class was generated from the following files:

Mon Feb 17 2014 11:53:00, Laxkit