-
Notifications
You must be signed in to change notification settings - Fork 0
/
ext_window_class.c
162 lines (147 loc) · 5.47 KB
/
ext_window_class.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* AmiSoundED - Sound Editor
* Copyright (C) 2008-2009 Fredrik Wikstrom <fredrik@a500.org>
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <intuition/sysiclass.h>
#include <classes/window.h>
#include <gadgets/button.h>
#include <proto/exec.h>
#include <proto/utility.h>
#include <proto/intuition.h>
#include <proto/window.h>
#include "ext_window_class.h"
typedef struct {
struct Window *Window;
int32 HasSnapshot;
Object *SnapshotButton;
Object *SnapshotImage;
APTR DrawInfo;
} ExtWindow;
static uint32 ExtWindow_Dispatch (Class *cl, Object *o, Msg msg);
Class * InitExtWindowClass () {
Class *cl;
cl = MakeClass("extwindow.class", NULL, WINDOW_GetClass(), sizeof(ExtWindow), 0);
if (cl) {
cl->cl_Dispatcher.h_Entry = ExtWindow_Dispatch;
}
return cl;
}
static void ParseTaglist (struct TagItem *taglist, ExtWindow *extwin);
static void FreeSnapshotButton (ExtWindow *extwin, struct Window *window);
static uint32 ExtWindow_Dispatch (Class *cl, Object *o, Msg msg) {
uint32 ret;
struct Window *window;
ExtWindow *extwin;
switch (msg->MethodID) {
case OM_NEW:
{
ExtWindow tmp = {0};
ParseTaglist(((struct opSet *)msg)->ops_AttrList, &tmp);
ret = IDoSuperMethodA(cl, o, msg);
if (o = (Object *)ret) {
extwin = INST_DATA(cl, o);
CopyMem(&tmp, extwin, sizeof(ExtWindow));
}
}
break;
case WM_OPEN:
extwin = INST_DATA(cl, o);
ret = IDoSuperMethodA(cl, o, msg);
if (!extwin->Window && (window = (struct Window *)ret)) {
extwin->Window = window;
if (extwin->HasSnapshot) {
extwin->DrawInfo = GetScreenDrawInfo(window->WScreen);
extwin->SnapshotImage = NewObject(NULL, "sysiclass",
SYSIA_DrawInfo, extwin->DrawInfo,
SYSIA_Which, SNAPSHOTIMAGE,
TAG_END);
if (extwin->SnapshotImage) {
extwin->SnapshotButton = NewObject(NULL, "buttongclass",
GA_ID, GID_SNAPSHOT,
GA_RelVerify, TRUE,
//GA_SysGadget, TRUE,
GA_Image, extwin->SnapshotImage,
GA_Titlebar, TRUE,
GA_TopBorder, TRUE,
GA_RelRight, 0,
TAG_END);
if (extwin->SnapshotButton) {
AddGadget(window, (struct Gadget *)extwin->SnapshotButton, 0);
RefreshGList((struct Gadget *)extwin->SnapshotButton, window,
NULL, 1);
break;
}
}
FreeSnapshotButton(extwin, window);
}
}
break;
case WM_HANDLEINPUT:
ret = IDoSuperMethodA(cl, o, msg);
switch (ret & WMHI_CLASSMASK) {
case WMHI_GADGETUP:
extwin = INST_DATA(cl, o);
switch (ret & WMHI_GADGETMASK) {
case GID_SNAPSHOT:
if (extwin->SnapshotButton) ret = WMHI_SNAPSHOT;
break;
}
break;
}
break;
case WM_ICONIFY:
case WM_CLOSE:
case OM_DISPOSE:
extwin = INST_DATA(cl, o);
if (window = extwin->Window) {
extwin->Window = NULL;
if (extwin->HasSnapshot) {
FreeSnapshotButton(extwin, window);
}
}
// fall through
default:
ret = IDoSuperMethodA(cl, o, msg);
break;
}
return ret;
}
static void ParseTaglist (struct TagItem *taglist, ExtWindow *extwin) {
struct TagItem *tstate, *ti;
tstate = taglist;
while (ti = NextTagItem(&tstate)) {
switch (ti->ti_Tag) {
case WINDOW_SnapshotGadget:
extwin->HasSnapshot = ti->ti_Data;
ti->ti_Tag = TAG_IGNORE;
break;
}
}
}
static void FreeSnapshotButton (ExtWindow *extwin, struct Window *window) {
if (extwin->SnapshotButton) {
RemoveGadget(window, (struct Gadget *)extwin->SnapshotButton);
DisposeObject(extwin->SnapshotButton);
extwin->SnapshotButton = NULL;
}
DisposeObject(extwin->SnapshotImage);
extwin->SnapshotImage = NULL;
FreeScreenDrawInfo(window->WScreen, extwin->DrawInfo);
extwin->DrawInfo = NULL;
}