home *** CD-ROM | disk | FTP | other *** search
- /*
- bdmouse2.c 4/09/90
-
- % mouseable border with vertical and horizontal scroll bars and lights
- % supports a prompt and title
-
- OWL 1.2
- Copyright (c) 1990 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 4/09/90 pmcm wrapped a horizontal variant of bd_sidebar around bd_mouse
- 4/15/90 pmcm added inpos check to mouse handler to prevent scrolling overshoot
- 4/17/90 ted added textfree dependent coord rounding for pmwin borders
- 10/11/90 pmcm changed scroll bar chars for VMS
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "strdecl.h"
- #include "scancode.h" /* for mouse pseudo-scancodes */
-
- #include "bordobj.h"
- #include "bordod.h"
- #include "bdmou2od.h"
-
- #define HSCROLL_BAR "\262\262\262"
-
- #ifdef OAK_VMS
- # define H_BAR "\303\304\264"
- #else
- # define H_BAR "\260\260\260"
- #endif
-
- #ifdef BORDER_CHARS
- # define leftlight(bdmou2dd) ((bdmou2dd->left) ? "\x11" : &bdmou2dd->back)
- # define rightlight(bdmou2dd) ((bdmou2dd->right) ? "\x10" : &bdmou2dd->back)
- # define LEFTCORNER "\xC3\xC0\xC0"
- # define RIGHTCORNER "\xB4\xD9\xD9"
- #else
- # define leftlight(bdmou2dd) ((bdmou2dd->left) ? "*" : &bdmou2dd->back)
- # define rightlight(bdmou2dd) ((bdmou2dd->right) ? "*" : &bdmou2dd->back)
- # define LEFTCORNER "+++"
- # define RIGHTCORNER "+++"
- #endif
-
- OSTATIC void OWLPRIV hbar_mouse(bdmouse2_od *, mev_struct *);
- OSTATIC void OWLPRIV light_scroll(bdmouse2_od *, opoint *, boolean *, mev_struct *);
- /* -------------------------------------------------------------------------- */
-
- int bd_mouse2(VOID *objdata, int msg, VOID *indata, VOID *outdata)
-
- /*
- This is a simple single lined border.
- With an title and prompt line.
- The title is pointed to by the border data pointer.
- Example:
- +-----Title-----+
- | <--- Scroll Lights
- | I
- | X <--- Elevator for Vertical scroll bar
- | I
- | <--- Scroll Lights
- +Prompt---------+
- + ----X------ + <--- Horizontal scroll bar & lights
-
- Clicking the mouse on the scroll lights scrolls the border's contents.
- Dragging the mouse on an edge moves the window.
- Dragging the mouse on a corner resizes the window.
-
- */
- {
- bdmouse2_od *bdmou2od;
- ocbox cbox;
- ptd_struct *ptd;
- win_type win;
- mev_struct *mev;
- byte attr;
-
- bdmou2od = (bdmouse2_od *)objdata;
-
- if(!(msg == OBJM_GETDATASIZE || msg == OBJM_OPEN)) {
- win = bdmou2od->mou1.prompt.bdd.win;
- }
-
- switch(msg) {
- case OBJM_GETDATASIZE:
- ((ogds_struct *) outdata)->odsize = sizeof(bdmouse2_od);
- ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
- ((ogds_struct *) outdata)->id = ID_BDMOUSE2;
- break;
-
- case OBJM_OPEN:
- if (!bd_mouse(&bdmou2od->mou1, msg, indata, outdata)) {
- return(FALSE);
- }
-
- bdmou2od->back = '\304';
-
- /* This bord must be charsize */
- win_SetCharSize(bdmou2od->mou1.prompt.bdd.win, TRUE);
- bord_SetSides(bdmou2od->mou1.prompt.bdd.win, -1, -1, 2, 1);
-
- bdmou2od->elleft = 1;
- bdmou2od->elright = win_GetWidth(bdmou2od->mou1.prompt.bdd.win) - 2;
-
- bord_GetHzBar(bdmou2od->mou1.prompt.bdd.win,
- &bdmou2od->elleft, &bdmou2od->elright, &bdmou2od->left, &bdmou2od->right);
-
- break;
-
- case BDM_SCROLL:
- /* Adjust the left and right lights and the scroll bar */
-
- cbox.toprow = win_GetHeight(win) + 1;
- cbox.botrow = cbox.toprow;
- cbox.leftcol = 0;
- cbox.rightcol = win_GetWidth(win) - 1;
-
- bdmou2od->elleft = cbox.leftcol + 1;
- bdmou2od->elright = cbox.rightcol - 1;
- bord_GetHzBar(win, &bdmou2od->elleft, &bdmou2od->elright,
- &bdmou2od->left, &bdmou2od->right);
-
- win_PaintBox(win, &cbox);
-
- /* pass it up */
- bd_mouse(&bdmou2od->mou1, msg, indata, outdata);
-
- break;
-
- case BDM_RESIZE:
- /* our window has changed size, reset the scroll lights */
- bdmou2od->elleft = 1;
- bdmou2od->elright = win_GetWidth(win) - 2;
- bord_GetHzBar(win, &bdmou2od->elleft, &bdmou2od->elright,
- &bdmou2od->left, &bdmou2od->right);
- bd_mouse(&bdmou2od->mou1, msg, indata, outdata);
- break;
-
- case BDM_SHADOW:
- case BDM_DRAW:
- ptd = (ptd_struct *)indata;
- attr = (msg == BDM_DRAW) ? bord_GetAttr(win) : win_GetShadowAttr(win);
-
- /* Draw the scroll bar */
-
- cbox.toprow = win_GetHeight(win) + 1;
- cbox.botrow = cbox.toprow;
- cbox.leftcol = 1;
- cbox.rightcol = win_GetWidth(win) - 2;
-
- if (cbox.rightcol >= cbox.leftcol) {
- ptd_DrawCharLine(ptd, H_BAR, &cbox, attr);
-
- cbox.leftcol = bdmou2od->elleft;
- cbox.rightcol = bdmou2od->elright;
- ptd_DrawCharLine(ptd, HSCROLL_BAR, &cbox, attr);
- }
-
- /* Draw the scroll lights */
-
- cbox.leftcol = 0;
- cbox.rightcol = win_GetWidth(win) - 1;
-
- if (cbox.leftcol < cbox.rightcol) {
- /* Leftlight */
- ptd_DrawString(ptd, cbox.toprow, cbox.leftcol,
- leftlight(bdmou2od), attr, 1); /* Rightlight */
- ptd_DrawString(ptd, cbox.toprow, cbox.rightcol,
- rightlight(bdmou2od), attr, 1);
- }
- else {
- /* fill in char under absent scroll light(s) */
- ptd_DrawString(ptd, cbox.toprow, cbox.leftcol,
- &bdmou2od->back, attr, 1);
- }
-
- bd_mouse(&bdmou2od->mou1, msg, indata, outdata);
-
- /* Draw the bottom corners after we pass it up */
-
- cbox.leftcol = -1;
- cbox.rightcol = -1;
- cbox.toprow = win_GetHeight(win);
- ptd_DrawCharLine(ptd, LEFTCORNER, &cbox, attr);
- cbox.leftcol = win_GetWidth(win);
- cbox.rightcol = cbox.leftcol;
- ptd_DrawCharLine(ptd, RIGHTCORNER, &cbox, attr);
-
- break;
-
- case BDM_STARTMOUSE:
- case BDM_ENDMOUSE:
- return(bd_mouse(&bdmou2od->mou1, msg, indata, outdata));
-
- case BDM_MOUSE:
- /* If mouse clicked on left or right light, then scroll. */
- /* If mouse clicked on elevator, scroll in that fashion */
-
- mev = (mev_struct *) indata;
-
- if (mev_GetRow(mev) == win_GetHeight(win) + 1 &&
- mev_GetCol(mev) >= 0 &&
- mev_GetCol(mev) <= win_GetWidth(win) - 1) {
-
- hbar_mouse(bdmou2od, mev);
-
- /* Don't offer to make this border's window the current window */
- mev_ClearEvent(mev);
- }
- else {
- /* pass message up to super class */
- return(bd_mouse(&bdmou2od->mou1, msg, indata, outdata));
- }
-
- break;
-
- case OBJM_CLOSE:
- /* No break; fall through to default */
-
- default:
- bd_mouse(&bdmou2od->mou1, msg, indata, outdata);
- break;
- }
- return(1);
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV hbar_mouse(bdmouse2_od *bdmou2od, mev_struct *mev)
-
- /*
- Mouse processing for horizontal scroll bar of bd_mouse2.
- */
-
- {
- win_type win;
- opoint mvpnt;
- boolean *actdirp;
- opcoord prevx, tempx;
- int elevw, barw;
- inposdata_struct inpos;
-
- if (mev_IsButtonDown(mev)) {
- if (bdmou2od->mou1.prompt.bdd.debounced) {
- return;
- }
- }
- else {
- bdmou2od->mou1.prompt.bdd.debounced = FALSE;
- return;
- }
- win = bdmou2od->mou1.prompt.bdd.win;
-
- if (mev_GetCol(mev) == 0) {
- /* Left arrow */
- if (bdmou2od->left) {
- actdirp = &bdmou2od->left;
- mvpnt.y = 0;
- mvpnt.x = -win_GetFontWidth(win);
-
- light_scroll(bdmou2od, &mvpnt, actdirp, mev);
- }
- }
- else if (mev_GetCol(mev) == win_GetWidth(win) - 1) {
- /* Right arrow */
- if (bdmou2od->right) {
- actdirp = &bdmou2od->right;
- mvpnt.y = 0;
- mvpnt.x = win_GetFontWidth(win);
-
- light_scroll(bdmou2od, &mvpnt, actdirp, mev);
- }
- }
- else if (mev_GetCol(mev) > 0 &&
- mev_GetCol(mev) < win_GetWidth(win) - 1 ) {
-
- /* Hbar */
- if ((barw = (win_GetWidth(win) - 2)) >= 2) {
-
- inpos.win = win;
-
- prevx = mev_GetX(mev);
- mvpnt.y = 0;
-
- /* scaling factor is ratio of scroll bar width to elevator width */
- elevw = bdmou2od->elright - bdmou2od->elleft + 1;
-
- for (;;) {
- win_Do(win, WINM_GETINPOS, NULL, &inpos);
-
- mvpnt.x = (mev_GetX(mev) - prevx) * barw / elevw;
-
- if (mvpnt.x < 0) {
- /* Don't scroll left too much */
- tempx = inpos.inbox.xmin;
- if (mvpnt.x < tempx) {
- mvpnt.x = tempx;
- }
- if (mvpnt.x > 0) {
- mvpnt.x = 0;
- }
- else {
- /* Round down to character boundary */
- if (!disp_TextFree()) {
- opcoord_GridRound(&mvpnt.x, &mvpnt.y, win_GetFont(win));
- }
- }
- }
- else {
- /* Don't scroll right too much */
- tempx = inpos.inbox.xmax - win_GetPixWidth(win);
- if (mvpnt.x > tempx) {
- mvpnt.x = tempx;
- }
- if (mvpnt.x < 0) {
- mvpnt.x = 0;
- }
- else {
- /* Round up to character boundary */
- if (!disp_TextFree()) {
- mvpnt.x += win_GetFontWidth(win) - 1;
- opcoord_GridRound(&mvpnt.x, &mvpnt.y, win_GetFont(win));
- }
- }
- }
-
- if (mvpnt.x != 0) {
- /* Scroll window contents */
- win_Do(win, WINM_SCROLLREQ, &mvpnt, NULL);
- }
-
- if (win_ReadEvent(win, mev) == MOU_EVENT) {
- if (!mev_IsButtonDown(mev)) {
- break;
- }
- /* else: ignore keystrokes */
- }
- }
- }
- }
- bdmou2od->mou1.prompt.bdd.debounced = mev_IsButtonDown(mev);
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV light_scroll(bdmouse2_od *bdmou2od, opoint *mvpnt, boolean *actdirp, mev_struct *mev)
- {
- win_type win;
- unsigned holdtime;
-
- win = bdmou2od->mou1.prompt.bdd.win;
-
- holdtime = 30; /* Initial delay value = 1/3 second */
-
- for (;;) {
- /* Scroll window contents */
- /* Note that the SCROLLREQ is expected to call BDM_SCROLL */
- /* to reset the lights flags which we test to see if */
- /* scrolling is all done */
- win_Do(win, WINM_SCROLLREQ, mvpnt, NULL);
-
- /* Break if dir is all used up now */
- if (!(*actdirp)) {
- bdmou2od->mou1.prompt.bdd.debounced = TRUE;
- break;
- }
- /* Break if mouse is no longer held down. Ignore keyhits */
- if (win_MouseHoldDownTime(win, mev, holdtime) != MOU_HOLDDOWN) {
- break;
- }
- holdtime = 5;
- }
- }
- /* -------------------------------------------------------------------------- */
-
-