home *** CD-ROM | disk | FTP | other *** search
- /*
- bordimo.c 5/20/89
-
- % Border Request handler function for use by mouse borders & maybe others.
- By JMD
-
- Also contains outline draw routines.
-
- OWL 1.2
- Copyright (c) 1989, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 5/23/89 jmd added "border features"
- 7/06/89 ted Fixed sizing in graphics mode by making bbox use char coords.
- and cleaned up various other stuff.
- 8/02/89 jdc added mvpnt.x, mvpnt.y initialization for resize
- 8/04/89 jmd added BD_TOP feature
- 8/08/89 jmd made request messages into functions
- 12/20/89 ted Added support for border mousethru feature.
- 3/28/90 jmd ansi-fied
- 6/22/90 ted added "void" to no-parameter function per ansii.
- 8/03/90 jmd added aux messages
- 12/11/90 jdc fixed sizing below 1, 1 bug
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "bordobj.h"
- #include "bordod.h"
-
- #include "scancode.h" /* for mouse pseudo-scancodes */
-
- enum action_flag {
- ACT_NO, ACT_MOVE, ACT_SIZEUL, ACT_SIZEUR, ACT_SIZELR, ACT_SIZELL
- };
-
- OSTATIC objreq_func (bdreq_mouse);
- OSTATIC int OWLPRIV bord_mouse(border_od *bdd, mev_struct *mev, unsigned features);
-
- /* -------------------------------------------------------------------------- */
-
- void bord_MouseInit(void)
- {
- bdreq_mousefptr = bdreq_mouse;
- }
-
- static int bdreq_mouse(VOID *objdata, int msg, VOID *indata, VOID *outdata)
- /*
- Standard handler for border mouse messages. Handles topping, moving and
- resizing depending on which border features are turned on.
- Returns 0 if unable to do anything, 1 if if it does something,
- or a scancode (set by the window's aux function) to be returned
- via kb_Read.
- */
- {
- mev_struct *mev;
- border_od *bdd;
- unsigned features;
- int ret;
-
- oak_notused(outdata);
-
- mev = (mev_struct *) indata;
- bdd = (border_od *) objdata;
- features = bord_getxdfeature(bordod_GetSelf(bdd));
-
- switch(msg) {
- case BDM_STARTMOUSE:
- case BDM_ENDMOUSE: /* Mouse left the border. */
- /* Ignore mouse if button pressed when mouse first enters */
- /* (we don't care if mouse is exiting, but what the poot). */
-
- bdd->debounced = mev_IsButtonDown(mev);
- if (!(features & BD_MOUSETHRU)) {
- mev_ClearEvent(mev);
- }
- break;
-
- case BDM_MOUSE:
- if (!mev_IsEventClear(mev)) {
- ret = bord_mouse(bdd, mev, features);
- if ((ret != 0) || !(features & BD_MOUSETHRU)) {
- mev_ClearEvent(mev);
- }
-
- if (ret != 0 && ret != 1) {
- return(ret);
- }
- }
- break;
- }
-
- return(1);
- }
- /* -------------------------------------------------------------------------- */
-
- static int OWLPRIV bord_mouse(border_od *bdd, mev_struct *mev, unsigned features)
- /*
- Mouse proccessing for borders.
-
- returns 0 if unable to do anything,
- 1 if if it does something
- or a scancode (set by the window's aux function) to be returned
- via kb_Read
- */
- {
- win_type win;
- opoint mvpnt, szpnt;
- opcoord mx, my, offx, offy;
- enum action_flag action = ACT_NO;
- boolean oldrawn = FALSE; /* flag for outline window currently drawn */
- boolean olmoved = FALSE; /* flag for outline window actually changed */
- opbox olbox;
- ocbox bbox;
- int ret, evcode = MOU_IGNORE;
-
- if (mev_IsButtonDown(mev)) {
- if (bdd->debounced) {
- return(0);
- }
- }
- else {
- bdd->debounced = FALSE;
- return(0);
- }
-
- win = bdd->win;
-
- /* send an aux message to the window */
- ret = obj_DoAux(win, WINA_BORDERCLICK, (VOID *) mev, (VOID *) &evcode);
- if (evcode != MOU_IGNORE) {
- /* return a scancode via kb_Read() */
- return(evcode);
- }
- if (ret == 0) {
- /* ignore mouse click */
- return(0);
- }
-
- /* If enabled, move the window to the top */
- if (features & BD_TOP) {
- win_Top(win);
- /* Not setting didsomething because we might already be topped */
- }
-
- /* Get the border corners */
- bord_GetBox(win, &bbox);
-
- /* Find offset of mouse from upper corner of window */
- offx = mev_GetX(mev);
- offy = mev_GetY(mev);
-
- /* Assume a MOVE action, then test for others */
- action = (features & BD_MOVE) ? ACT_MOVE : ACT_NO;
-
- if (features & BD_RESIZE) {
- if (mev_GetRow(mev) == bbox.toprow && mev_GetCol(mev) == bbox.leftcol) {
- /* Resize window: Upper Left Corner */
- action = ACT_SIZEUL;
- }
- else if (mev_GetRow(mev) == bbox.toprow && mev_GetCol(mev) == bbox.rightcol) {
- /* Resize window: Upper Right Corner */
- action = ACT_SIZEUR;
- offx -= win_GetPixWidth(win);
- }
- else if (mev_GetRow(mev) == bbox.botrow && mev_GetCol(mev) == bbox.rightcol) {
- /* Resize window: Lower Right */
- action = ACT_SIZELR;
- offx -= win_GetPixWidth(win);
- offy -= win_GetPixHeight(win);
- }
- else if (mev_GetRow(mev) == bbox.botrow && mev_GetCol(mev) == bbox.leftcol) {
- /* Resize window: Lower Left */
- action = ACT_SIZELL;
- offy -= win_GetPixHeight(win);
- }
- }
- if (action == ACT_NO) {
- return(0);
- }
-
- /* Do the action */
- for(;;) {
- /* Size or Move while the mouse is dragged */
-
- /* Get next mouse event in local mev struct */
- if (win_ReadEvent(win, mev) == MOU_EVENT) {
- if (oldrawn) {
- /* erase the last drawn box */
- bord_EraseOutline(win, &olbox);
- oldrawn = FALSE;
- }
- if (!mev_IsButtonDown(mev)) {
- break; /* break out of loop */
- }
- else {
- /* figure out how far we've moved */
- mx = mev_GetX(mev) - offx;
- my = mev_GetY(mev) - offy;
- mvpnt.x = win_GetXmin(win);
- mvpnt.y = win_GetYmin(win);
-
- switch (action) {
- case ACT_MOVE:
- mvpnt.x += mx;
- mvpnt.y += my;
- break;
-
- case ACT_SIZEUL:
- if (win_GetPixWidth(win) > 1 || mx < 0) {
- mvpnt.x += mx;
- if ((szpnt.x = win_GetPixWidth(win) - mx) < 1) {
- mvpnt.x += szpnt.x - 1;
- }
- }
- if (win_GetPixHeight(win) > 1 || my < 0) {
- mvpnt.y += my;
- if ((szpnt.y = win_GetPixHeight(win) - my) < 1) {
- mvpnt.y += szpnt.y - 1;
- }
- }
- break;
-
- case ACT_SIZEUR:
- szpnt.x = mev_GetX(mev);
- if (win_GetPixHeight(win) > 1 || my < 0) {
- mvpnt.y += my;
- if ((szpnt.y = win_GetPixHeight(win) - my) < 1) {
- mvpnt.y += szpnt.y - 1;
- }
- }
- break;
-
- case ACT_SIZELR:
- szpnt.x = mx;
- szpnt.y = my;
- break;
-
- case ACT_SIZELL:
- if (win_GetPixWidth(win) > 1 || mx < 0) {
- mvpnt.x += mx;
- if ((szpnt.x = win_GetPixWidth(win) - mx) < 1) {
- mvpnt.x += szpnt.x - 1;
- }
- }
- szpnt.y = my;
- break;
- }
- szpnt.x = int_max(szpnt.x, 1);
- szpnt.y = int_max(szpnt.y, 1);
-
- /* Adjust size and position for SIZE */
- if (features & BD_OUTLINE) {
- bord_GetPixBox(win, &olbox);
- opbox_trans(&olbox, mvpnt.x, mvpnt.y);
- if (action != ACT_MOVE) { /* Size action */
- olbox.xmax += szpnt.x - win_GetPixWidth(win);
- olbox.ymax += szpnt.y - win_GetPixHeight(win);
- }
- bord_DrawOutline(win, &olbox);
- oldrawn = TRUE;
- olmoved = TRUE; /* keep quick click from having effect */
- }
- else {
- /* move the window */
- win_SetPixPosition(win, mvpnt.x, mvpnt.y);
-
- if (action != ACT_MOVE) { /* Size action */
- /* resize the window */
- win_SetPixSize(win, szpnt.x, szpnt.y);
- }
- }
- }
- }
- }
- if (olmoved) {
- /* move the window for real */
- win_SetPixPosition(win, mvpnt.x, mvpnt.y);
-
- if (action != ACT_MOVE) { /* Size action */
- /* resize the window for real */
- win_SetPixSize(win, szpnt.x, szpnt.y);
- }
- }
-
- return(1);
- }
- /* -------------------------------------------------------------------------- */
-
-