File: scroller.c

package info (click to toggle)
twin 0.4.0-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,804 kB
  • ctags: 23,904
  • sloc: ansic: 61,860; cpp: 1,023; makefile: 777; sh: 552; lex: 302; yacc: 231
file content (149 lines) | stat: -rw-r--r-- 3,826 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 *  scroller.c  --  manage autorepeat of virtual screen and window scrolling
 *
 *  Copyright (C) 1993-2000 by Massimiliano Ghilardi
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 */

#include "twin.h"
#include "data.h"
#include "methods.h"
#include "scroller.h"

#include "hw_multi.h"
#include "resize.h"
#include "printk.h"
#include "util.h"


/* FIXME: Fix screen scrolling during Interactive Drag/Resize */

msgport Scroller_MsgPort;
static void ScrollerH(msgport MsgPort);

/*
 * just dummy msgs that we receive when we are called
 * to start/stop scrolling immediately
 */
msg Do_Scroll, Dont_Scroll;

byte InitScroller(void) {
    if ((Scroller_MsgPort=Do(Create,MsgPort)
	 (FnMsgPort, 8, "Scroller", (time_t)0, 401 MilliSECs, (byte)0, ScrollerH)) &&
	(Do_Scroll=Do(Create,Msg)(FnMsg, 0, 0)) &&
	(Dont_Scroll=Do(Create,Msg)(FnMsg, 0, 0))) {

	return TRUE;
    }
    printk("twin: Scroller: %s\n", ErrStr);
    return FALSE;
}

INLINE void ScrollerDeactivate(void) {
    Scroller_MsgPort->PauseDuration.Fraction = 333 MilliSECs + 1;
    Scroller_MsgPort->WakeUp = 0;
}

INLINE void ScrollerAutoRepeat(void) {
    if (Scroller_MsgPort->PauseDuration.Fraction > 333 MilliSECs)
	Scroller_MsgPort->PauseDuration.Fraction = 333 MilliSECs;
    else
	Scroller_MsgPort->PauseDuration.Fraction = 30 MilliSECs;
}

INLINE void ScrollerDelayRepeat(void) {
    Scroller_MsgPort->PauseDuration.Fraction = 333 MilliSECs + 1;
}

static void ScrollerH(msgport MsgPort) {
    msg Msg, saveMsg;
    mouse_state *Mouse;
    screen Screen;
    uldat Attrib, WState;
    dat Limit;
    dat Mouse_delta_x, Mouse_delta_y;
    byte State, FlagDeskScroll, FlagWinScroll, WinScrolled = FALSE;
    window FocusWindow;
    
    while ((Msg=Scroller_MsgPort->FirstMsg)) {
	Remove(Msg);
	if (Msg == Do_Scroll || Msg == Dont_Scroll)
	    saveMsg = Msg;
	else
	    Delete(Msg);
    }

    if (saveMsg == Dont_Scroll || !All->MouseHW) {
	ScrollerDeactivate();
	return;
    }
    
    Mouse = &All->MouseHW->MouseState;

    FocusWindow = (window)All->FirstScreen->FocusW;
    if (FocusWindow && !IS_WINDOW(FocusWindow))
	FocusWindow = (window)0;
    
    if (FocusWindow) {
	Attrib=FocusWindow->Attrib;
	WState=FocusWindow->State;
	FlagWinScroll = (((Attrib & WINDOW_X_BAR) && (WState | X_BAR_SELECT))
			 || ((Attrib & WINDOW_Y_BAR) && (WState | Y_BAR_SELECT)))
	    && !(WState & TAB_SELECT);
    } else
	FlagWinScroll = FALSE;
    
    FlagDeskScroll = (All->SetUp->Flags & SETUP_EDGESCROLL)
	&& (Mouse->keys == HOLD_LEFT || Mouse->keys == HOLD_MIDDLE || Mouse->keys == HOLD_RIGHT);

    State = All->State & STATE_ANY;
    
    if (State != STATE_DEFAULT && State != STATE_SCROLL &&
	State != STATE_DRAG && State != STATE_RESIZE) {
	
	ScrollerDeactivate();
	return;
    }
    
    if (State != STATE_DEFAULT && FlagWinScroll) {
	if ((WinScrolled = ExecScrollFocusWindow()))
	    ScrollerAutoRepeat();
    }
    
    Mouse_delta_x=-Mouse->delta_x;
    Mouse_delta_y=-Mouse->delta_y;
    FlagDeskScroll &= Mouse_delta_x || Mouse_delta_y;

    if (!FlagDeskScroll) {
	if (!WinScrolled) {
	    ScrollerDelayRepeat();
	}
	return;
    }
    
    if (FlagDeskScroll) {
	Screen=All->FirstScreen;

	Limit=All->SetUp->MaxMouseSnap;
	if (Scroller_MsgPort->PauseDuration.Fraction > 333 MilliSECs) {
	    Mouse_delta_x = Sign(Mouse_delta_x);
	    Mouse_delta_y = Sign(Mouse_delta_y);
	}
		
	DragFirstScreen(Mouse_delta_x*Limit, Mouse_delta_y*Limit);
	
	if (!WinScrolled)
	    ScrollerAutoRepeat();

	StdAddEventMouse(MSG_MOUSE, DRAG_MOUSE | Mouse->keys, Mouse->x, Mouse->y);
    } else {
	if (!WinScrolled)
	    ScrollerDelayRepeat();
    }
}