forked from mooseman/D-Flat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lists.c
125 lines (117 loc) · 3.19 KB
/
lists.c
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
/* --------------- lists.c -------------- */
#include "dflat.h"
/* ----- set focus to the next sibling ----- */
void SetNextFocus()
{
if (inFocus != NULL) {
WINDOW wnd1 = inFocus, pwnd;
while (TRUE) {
pwnd = GetParent(wnd1);
if (NextWindow(wnd1) != NULL)
wnd1 = NextWindow(wnd1);
else if (pwnd != NULL)
wnd1 = FirstWindow(pwnd);
if (wnd1 == NULL || wnd1 == inFocus) {
wnd1 = pwnd;
break;
}
if (GetClass(wnd1) == STATUSBAR || GetClass(wnd1) == MENUBAR)
continue;
if (isVisible(wnd1))
break;
}
if (wnd1 != NULL) {
while (wnd1->childfocus != NULL)
wnd1 = wnd1->childfocus;
if (wnd1->condition != ISCLOSING)
SendMessage(wnd1, SETFOCUS, TRUE, 0);
}
}
}
/* ----- set focus to the previous sibling ----- */
void SetPrevFocus()
{
if (inFocus != NULL) {
WINDOW wnd1 = inFocus, pwnd;
while (TRUE) {
pwnd = GetParent(wnd1);
if (PrevWindow(wnd1) != NULL)
wnd1 = PrevWindow(wnd1);
else if (pwnd != NULL)
wnd1 = LastWindow(pwnd);
if (wnd1 == NULL || wnd1 == inFocus) {
wnd1 = pwnd;
break;
}
if (GetClass(wnd1) == STATUSBAR)
continue;
if (isVisible(wnd1))
break;
}
if (wnd1 != NULL) {
while (wnd1->childfocus != NULL)
wnd1 = wnd1->childfocus;
if (wnd1->condition != ISCLOSING)
SendMessage(wnd1, SETFOCUS, TRUE, 0);
}
}
}
/* ------- move a window to the end of its parents list ----- */
void ReFocus(WINDOW wnd)
{
if (GetParent(wnd) != NULL) {
RemoveWindow(wnd);
AppendWindow(wnd);
ReFocus(GetParent(wnd));
}
}
/* ---- remove a window from the linked list ---- */
void RemoveWindow(WINDOW wnd)
{
if (wnd != NULL) {
WINDOW pwnd = GetParent(wnd);
if (PrevWindow(wnd) != NULL)
NextWindow(PrevWindow(wnd)) = NextWindow(wnd);
if (NextWindow(wnd) != NULL)
PrevWindow(NextWindow(wnd)) = PrevWindow(wnd);
if (pwnd != NULL) {
if (wnd == FirstWindow(pwnd))
FirstWindow(pwnd) = NextWindow(wnd);
if (wnd == LastWindow(pwnd))
LastWindow(pwnd) = PrevWindow(wnd);
}
}
}
/* ---- append a window to the linked list ---- */
void AppendWindow(WINDOW wnd)
{
if (wnd != NULL) {
WINDOW pwnd = GetParent(wnd);
if (pwnd != NULL) {
if (FirstWindow(pwnd) == NULL)
FirstWindow(pwnd) = wnd;
if (LastWindow(pwnd) != NULL)
NextWindow(LastWindow(pwnd)) = wnd;
PrevWindow(wnd) = LastWindow(pwnd);
LastWindow(pwnd) = wnd;
}
NextWindow(wnd) = NULL;
}
}
/* ----- if document windows and statusbar or menubar get the focus,
pass it on ------- */
void SkipApplicationControls(void)
{
BOOL EmptyAppl = FALSE;
int ct = 0;
while (!EmptyAppl && inFocus != NULL) {
CLASS cl = GetClass(inFocus);
if (cl == MENUBAR || cl == STATUSBAR) {
SetPrevFocus();
EmptyAppl = (cl == MENUBAR && ct++);
}
else
break;
}
}