Article View: comp.windows.interviews
Article #1480Re: StringBrowser and Scrollers
From: John Vlissides
Date: Sat, 15 Jun 1991 19:23
Date: Sat, 15 Jun 1991 19:23
246 lines
7239 bytes
7239 bytes
> If anyone has managed to get horizontal scrollers working
> with a stringbrowser (and preferably both types of scroller),
> I would appreciate some help (or even code)
Here's a patch that adds this feature (and fixes an obscure bug):
*** /interviews/dist/3.0-beta/iv/src/lib/IV-look/strbrowser.c Thu Mar 14 17:06:18 1991
--- iv/src/lib/IV-look/strbrowser.c Wed Jun 5 19:16:06 1991
***************
*** 172,177 ****
--- 172,178 ----
}
void StringBrowser::Insert (const char* s, int index) {
+ display->Draw(output, canvas);
register Perspective* p = perspective;
char* copy = new char[strlen(s)+1];
***************
*** 181,186 ****
--- 182,188 ----
p->height += lineheight;
p->cury += lineheight;
p->Update();
+
if (index < strcount-1) {
display->InsertLinesAfter(index-1, 1);
}
***************
*** 189,194 ****
--- 191,197 ----
void StringBrowser::Remove (int index) {
if (0 <= index && index < strcount) {
+ display->Draw(output, canvas);
register Perspective* p = perspective;
Unselect(index);
***************
*** 226,231 ****
--- 229,235 ----
void StringBrowser::Select (int index) {
if (index < strcount && !Selected(index)) {
BufInsert(String(index), selcount, selbuf, selbufsize, selcount);
+ display->Draw(output, canvas);
display->Style(index, 0, index, columns, highlight);
}
}
***************
*** 235,240 ****
--- 239,245 ----
if (index < strcount && (selindex = SelectionIndex(index)) >= 0) {
BufRemove(selindex, selbuf, selcount);
+ display->Draw(output, canvas);
display->Style(index, 0, index, columns, Plain);
}
}
***************
*** 377,384 ****
void StringBrowser::Adjust (Perspective& np) {
register Perspective* p = perspective;
! float scale = float(np.height) / float(p->height);
! ScrollTo(0, p->y0 + int((np.cury - np.y0) / scale));
}
static Cursor* handCursor;
--- 382,391 ----
void StringBrowser::Adjust (Perspective& np) {
register Perspective* p = perspective;
! float scale = (np.height == 0) ? 1 : float(p->height) / float(np.height);
! int x = p->x0 + int((np.curx - np.x0) * scale);
! int y = p->y0 + int((np.cury - np.y0) * scale);
! ScrollTo(x, y);
}
static Cursor* handCursor;
***************
*** 449,454 ****
--- 456,462 ----
}
void StringBrowser::Redraw (IntCoord l, IntCoord b, IntCoord r, IntCoord t) {
+ display->Draw(output, canvas);
display->Redraw(l, b, r, t);
}
***************
*** 462,467 ****
--- 470,476 ----
for (int i = 0; i < strcount; ++i) {
BufInsert(strbuf[i], selcount, selbuf, selbufsize, selcount);
}
+ display->Draw(output, canvas);
display->Style(0, 0, strcount, 0, highlight);
}
***************
*** 473,483 ****
void StringBrowser::UnselectAll () {
selcount = 0;
display->Style(0, 0, strcount, 0, Plain);
}
! void StringBrowser::ScrollBy (int, int dy) {
! ScrollTo(0, perspective->cury + dy);
}
void StringBrowser::ScrollBy (int lines) {
--- 482,494 ----
void StringBrowser::UnselectAll () {
selcount = 0;
+ display->Draw(output, canvas);
display->Style(0, 0, strcount, 0, Plain);
}
! void StringBrowser::ScrollBy (int dx, int dy) {
! register Perspective* p = perspective;
! ScrollTo(p->curx + dx, p->cury + dy);
}
void StringBrowser::ScrollBy (int lines) {
***************
*** 486,499 ****
void StringBrowser::ScrollTo (int x, int y) {
register Perspective* p = perspective;
int maxy = p->height - p->curheight;
int miny = min(maxy, 1-lineheight);
p->cury = max(miny, min(y, maxy));
p->Update();
int topmargin = p->height - p->curheight - p->cury;
int line = topmargin / lineheight;
! display->Scroll(line, x, ymax);
}
void StringBrowser::ScrollTo (int index) {
--- 497,516 ----
void StringBrowser::ScrollTo (int x, int y) {
register Perspective* p = perspective;
+ int minx = 0;
+ int maxx = max(minx, p->width - p->curwidth/2);
int maxy = p->height - p->curheight;
int miny = min(maxy, 1-lineheight);
+ p->curx = max(minx, min(x, maxx));
p->cury = max(miny, min(y, maxy));
p->Update();
+
int topmargin = p->height - p->curheight - p->cury;
int line = topmargin / lineheight;
!
! display->Draw(output, canvas);
! display->Scroll(line, -p->curx, ymax);
}
void StringBrowser::ScrollTo (int index) {
***************
*** 509,521 ****
}
}
! void StringBrowser::ScrollToView (IntCoord, IntCoord y) {
! register Perspective* p = perspective;
!
! if (y > ymax) {
! ScrollTo(0, p->y0 + p->cury - (ymax-y));
! } else if (y < 0) {
! ScrollTo(0, p->y0 + p->cury - (-y));
}
}
--- 526,536 ----
}
}
! void StringBrowser::ScrollToView (IntCoord x, IntCoord y) {
! IntCoord dx = x < 0 ? x : x > xmax ? x - xmax : 0;
! IntCoord dy = y < 0 ? y : y > ymax ? y - ymax : 0;
! if (dx != 0 || dy != 0) {
! ScrollTo(perspective->curx + dx, perspective->cury + dy);
}
}
***************
*** 636,649 ****
void StringBrowser::GrabScroll (Event& e) {
int y = e.y;
- int x = e.x;
Cursor* origCursor = GetCursor();
SetCursor(handCursor);
do {
! ScrollBy(x - e.x, y - e.y);
y = e.y;
- x = e.x;
Poll(e);
} while (e.middlemouse);
--- 651,662 ----
void StringBrowser::GrabScroll (Event& e) {
int y = e.y;
Cursor* origCursor = GetCursor();
SetCursor(handCursor);
do {
! ScrollBy(0, y - e.y);
y = e.y;
Poll(e);
} while (e.middlemouse);
***************
*** 653,662 ****
void StringBrowser::RateScroll (Event& e) {
Cursor* origCursor = GetCursor();
int y = e.y;
- int x = e.x;
do {
! ScrollBy(e.x - x, e.y - y);
if (e.y - y < 0) {
SetCursor(dnCursor);
} else {
--- 666,674 ----
void StringBrowser::RateScroll (Event& e) {
Cursor* origCursor = GetCursor();
int y = e.y;
do {
! ScrollBy(0, e.y - y);
if (e.y - y < 0) {
SetCursor(dnCursor);
} else {
--
John Vlissides
Computer Systems Lab
Stanford University
vlis@interviews.stanford.edu
Technical Details
Message-ID:
<VLIS.91Jun15152352@lurch.stanford.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!stanford.edu!leland.Stanford.EDU!portia!vlisReferences:
<1627@ucl-cs.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!stanford.edu!leland.Stanford.EDU!portia!vlis From: vlis@lurch.stanford.edu (John Vlissides) Newsgroups: comp.windows.interviews Subject: Re: StringBrowser and Scrollers Message-ID: <VLIS.91Jun15152352@lurch.stanford.edu> Date: 15 Jun 91 19:23:52 GMT References: <1627@ucl-cs.uucp> Sender: news@leland.Stanford.EDU (Mr News) Organization: stanford university Lines: 246 In-Reply-To: J.Cowan@cs.ucl.ac.uk's message of 14 Jun 91 14:50:02 GMT