forked from boardhead/aged
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PScrollingWindow.cxx
79 lines (60 loc) · 1.92 KB
/
PScrollingWindow.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//==============================================================================
// File: PScrollingWindow.cxx
//
// Copyright (c) 2017, Phil Harvey, Queen's University
//==============================================================================
#include "PScrollingWindow.h"
PScrollingWindow::PScrollingWindow(ImageData *data)
: PWindow(data)
{
for (int i=0; i<kNumScrollBars; ++i) {
mScrollBar[i] = NULL;
}
}
PScrollingWindow::~PScrollingWindow()
{
for (int i=0; i<kNumScrollBars; ++i) {
delete mScrollBar[i];
}
}
// --------------------------------------------------------------------------------
// New ScrollBar
//
// Create new scroll bar in window
//
void PScrollingWindow::NewScrollBar(EScrollBar bar, char *name, Arg *wargs, int n)
{
delete mScrollBar[bar];
mScrollBar[bar] = new PScrollBar(GetMainPane(),bar,name,wargs,n);
mScrollBar[bar]->SetHandler(this); // default to this as the scroll handler
}
void PScrollingWindow::SetScrollValue(EScrollBar bar, int value, int do_callback)
{
Arg wargs[1];
if (!GetScrollBar(bar)) return;
if (value < 0) value = 0;
if (value > kScrollMax) value = kScrollMax;
XtSetArg(wargs[0], XmNvalue, value);
XtSetValues(GetScrollBar(bar)->GetWidget(),wargs,1);
if (do_callback) {
GetScrollBar(bar)->GetHandler()->ScrollValueChanged(bar,value);
}
}
int PScrollingWindow::GetScrollValue(EScrollBar bar)
{
Arg wargs[1];
int value;
if (!GetScrollBar(bar)) return(0);
XtSetArg(wargs[0], XmNvalue, &value);
XtGetValues(GetScrollBar(bar)->GetWidget(),wargs,1);
return(value);
}
// SetScrollHandler - set handler for existing scrollbars
void PScrollingWindow::SetScrollHandler(PScrollHandler *hand)
{
for (int i=0; i<kNumScrollBars; ++i) {
if (mScrollBar[i]) {
mScrollBar[i]->SetHandler(hand);
}
}
}