~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/xt_frame.c

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2004-08-29 10:53:42 UTC
  • Revision ID: james.westby@ubuntu.com-20040829105342-qgmnry37eadfkoxx
Tags: upstream-1.1.3
ImportĀ upstreamĀ versionĀ 1.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * xt_frame.c,
 
3
 *
 
4
 * Copyright (C) 1997 Rasca Gmelch, Berlin
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 *
 
20
 *
 
21
 * This file contains routines for setting up and handling the selection
 
22
 * rectangle. Both Xt and GTK2 versions are in here now.
 
23
 *
 
24
 */
 
25
 
 
26
#include "../config.h" //autoconf output
 
27
#include <stdio.h>
 
28
#include <X11/Intrinsic.h>
 
29
#include <X11/StringDefs.h>
 
30
#include <X11/Shell.h>
 
31
#include "Xw/Toggle.h"
 
32
#include "Xw/Label.h"
 
33
#include "frame.h"
 
34
#include "xt_frame.h"
 
35
#include "app_data.h"
 
36
#include "job.h"
 
37
 
 
38
/*
 
39
 * some globals
 
40
 */
 
41
static Widget
 
42
top, left, right, bottom, blind = None;
 
43
extern XRectangle XVC_frame_rectangle;
 
44
extern int XVC_frame_lock;
 
45
extern Widget toplevel;
 
46
 
 
47
 
 
48
/*
 
49
 * XVIDCAP API STUFF
 
50
 *
 
51
 * XVC_CREATEFRAME SETS UP THE FRAME ... THE REST IS DONE BY THE GUI CALLBACKS
 
52
 * CAN BE FOUND IN CONTROL.H ... OR XT_CONTROL.C
 
53
 *
 
54
 */
 
55
 
 
56
 
 
57
/*
 
58
 * CALLBACKS
 
59
 *
 
60
 */
 
61
 
 
62
/*
 
63
 * event handler
 
64
 * handle the capture frame, e.g. move, unmap, etc.
 
65
 */
 
66
void
 
67
MoveFrameEH(Widget parent, XtPointer xtp, XEvent *ev, Boolean *boo) {
 
68
    Position x, y;
 
69
    Dimension pheight;
 
70
    #ifdef DEBUG
 
71
    printf("MoveFrameEH() event type = %d\n", ev->type);
 
72
    #endif
 
73
    if (ev->type == ConfigureNotify) {
 
74
        if (!XVC_frame_lock) {
 
75
            /* ignore it
 
76
             */
 
77
            return;
 
78
        }
 
79
        XtVaGetValues(parent,
 
80
        XtNx, &x,
 
81
        XtNy, &y,
 
82
        XtNheight, &pheight,
 
83
        NULL);
 
84
        y += pheight + FRAME_OFFSET;
 
85
        ChangeFrame(x, y, XVC_frame_rectangle.width, XVC_frame_rectangle.height, FALSE);
 
86
    } else if ( ev->type == UnmapNotify ) {
 
87
        XtUnmanageChild(top);
 
88
        XtUnmanageChild(bottom);
 
89
        XtUnmanageChild(left);
 
90
        XtUnmanageChild(right);
 
91
        if (blind)
 
92
            XtUnmanageChild(blind);
 
93
    } else if ( ev->type == MapNotify ) {
 
94
        XtManageChild(top);
 
95
        XtManageChild(bottom);
 
96
        XtManageChild(left);
 
97
        XtManageChild(right);
 
98
        if (blind)
 
99
            XtManageChild(blind);
 
100
    } else if ( ev->type == FocusIn ) {
 
101
        XRaiseWindow(XtDisplay(top), XtWindow(top));
 
102
        XRaiseWindow(XtDisplay(top), XtWindow(bottom));
 
103
        XRaiseWindow(XtDisplay(top), XtWindow(left));
 
104
        XRaiseWindow(XtDisplay(top), XtWindow(right));
 
105
        if (blind)
 
106
            XRaiseWindow(XtDisplay(top), XtWindow(blind));
 
107
    }
 
108
}
 
109
 
 
110
 
 
111
 
 
112
/*
 
113
 * HELPER FUNCTIONS
 
114
 *
 
115
 */
 
116
 
 
117
/*
 
118
 * change the position and the dimension of the capture frame
 
119
 */
 
120
void
 
121
ChangeFrame(int x, int y, int width, int height, Boolean reposition_control) {
 
122
    int frame_width = FRAME_WIDTH;
 
123
    int max_width, max_height;
 
124
    Window topwin, ignore;
 
125
    int pwidth, pheight, px, py, pborder_width, pdepth;
 
126
    Display *dpy;
 
127
    
 
128
    Job *job = job_ptr();
 
129
    
 
130
    if ( ! (job->flags & FLG_NOGUI ) ) {
 
131
        dpy = XtDisplay(toplevel);
 
132
        max_width = WidthOfScreen(XtScreen(top));
 
133
        max_height= HeightOfScreen(XtScreen(top));
 
134
    } else {
 
135
        dpy = XOpenDisplay(NULL);
 
136
        max_width = WidthOfScreen(DefaultScreenOfDisplay(dpy));
 
137
        max_height = HeightOfScreen(DefaultScreenOfDisplay(dpy));
 
138
    } 
 
139
    
 
140
    /* we have to adjust it to viewable areas
 
141
     */
 
142
    #ifdef DEBUG
 
143
    printf("ChangeFrame() screen = %dx%d selection=%dx%d\n",
 
144
    max_width, max_height, width, height);
 
145
    #endif
 
146
    if (x < 0)
 
147
        x = 0;
 
148
    if (width > max_width)
 
149
        width = max_width;
 
150
    if (x + width > max_width)
 
151
        x = max_width - width;
 
152
    
 
153
    if (height > max_height)
 
154
        height = max_height;
 
155
    if (y + height > max_height)
 
156
        y = max_height - height;
 
157
    if (y < 0)
 
158
        y = 0;
 
159
    
 
160
    if ( ! ( job->flags & FLG_NOGUI ) ) {
 
161
        XtVaSetValues(top,
 
162
        XtNx, x - frame_width,
 
163
        XtNy, y - frame_width,
 
164
        XtNwidth, width + 2 * frame_width,
 
165
        XtNheight, frame_width,
 
166
        NULL);
 
167
        XtVaSetValues(bottom,
 
168
        XtNx, x - frame_width,
 
169
        XtNy, y + height,
 
170
        XtNwidth, width + 2 * frame_width,
 
171
        XtNheight, frame_width,
 
172
        NULL);
 
173
        XtVaSetValues(left,
 
174
        XtNx, x - frame_width,
 
175
        XtNy, y - frame_width,
 
176
        XtNwidth, frame_width,
 
177
        XtNheight, height + 2 * frame_width,
 
178
        NULL);
 
179
        XtVaSetValues(right,
 
180
        XtNx, x + width,
 
181
        XtNy, y - frame_width,
 
182
        XtNwidth, frame_width,
 
183
        XtNheight, height + 2 * frame_width,
 
184
        NULL);
 
185
        if (blind)
 
186
            XtVaSetValues(blind,
 
187
            XtNx, x,
 
188
            XtNy, y,
 
189
            XtNwidth, width,
 
190
            XtNheight, height,
 
191
            NULL);
 
192
    }
 
193
    XVC_frame_rectangle.x = x;
 
194
    XVC_frame_rectangle.y = y;
 
195
    XVC_frame_rectangle.width = width;
 
196
    XVC_frame_rectangle.height= height;
 
197
    
 
198
    if (!IsFrameLocked() && ( ! (job->flags & FLG_NOGUI)) && reposition_control ) {
 
199
        topwin = XtWindow( toplevel );
 
200
        XGetGeometry(dpy, topwin, &ignore, &px, &py, &pwidth, &pheight, &pborder_width,
 
201
        &pdepth);
 
202
        pwidth += FRAME_OFFSET;
 
203
        pheight += FRAME_OFFSET;
 
204
        
 
205
        if ( ( y - pheight - 30 ) >= 0 ) {
 
206
            // FIXME: find out how to determine the title bar height, if possible
 
207
            // don*t know real title bar height ...
 
208
            // If I knew, I perhaps didn*t absolutely need to unlock the frame
 
209
            // if a position is given ...
 
210
            XtVaSetValues(toplevel, XtNx, x, XtNy, ( y - pheight - 30 ), NULL);
 
211
        } else {
 
212
            if ( ( y + pheight + height ) < max_height ) {
 
213
                XtVaSetValues(toplevel, XtNx, x, XtNy, ( y + height + FRAME_OFFSET ), NULL);
 
214
            } else {
 
215
                if ( x > pwidth ) {
 
216
                    XtVaSetValues(toplevel, XtNx, ( x - pwidth), XtNy, y, NULL);
 
217
                } else {
 
218
                    if ( ( x + width + pwidth ) < max_width ) {
 
219
                        XtVaSetValues(toplevel, XtNx, ( x + width + FRAME_OFFSET ), XtNy, y, NULL);
 
220
                    }
 
221
                    // ansonsten lass das GUI wo es ist ...
 
222
                }
 
223
            }
 
224
        }
 
225
    }
 
226
    if ( job->flags & FLG_NOGUI ) {
 
227
        XCloseDisplay(dpy);
 
228
    } 
 
229
    
 
230
}
 
231
 
 
232
/*
 
233
 * create the video frame
 
234
 */
 
235
void
 
236
CreateFrame(Widget parent, int width, int height, int flags) {
 
237
    Position x, y;
 
238
    Dimension pwidth, pheight;
 
239
    XVC_frame_lock = 1;
 
240
    
 
241
    #ifdef DEBUG
 
242
    printf("CreateFrame() %d %d\n", width, height);
 
243
    #endif
 
244
    XtVaGetValues(parent, XtNx, &x, XtNy, &y, XtNwidth, &pwidth, XtNheight, &pheight, NULL);
 
245
    if (x < 0)
 
246
        x = 0;
 
247
    y += pheight + FRAME_OFFSET;
 
248
    if (y < 0)
 
249
        y = 0;
 
250
    XVC_frame_rectangle.width = width;
 
251
    XVC_frame_rectangle.height= height;
 
252
    XVC_frame_rectangle.x = x;
 
253
    XVC_frame_rectangle.y = y;
 
254
    
 
255
    if ( ! ( flags & FLG_NOGUI ) ) {
 
256
        top = XtVaCreatePopupShell("top", overrideShellWidgetClass, parent,
 
257
        XtNx, x-FRAME_WIDTH,
 
258
        XtNy, y-FRAME_WIDTH,
 
259
        XtNwidth, width+2*FRAME_WIDTH,
 
260
        XtNheight, FRAME_WIDTH,
 
261
        NULL);
 
262
        bottom = XtVaCreatePopupShell("bottom", overrideShellWidgetClass, parent,
 
263
        XtNx, x-FRAME_WIDTH,
 
264
        XtNy, y+height,
 
265
        XtNwidth, width+2*FRAME_WIDTH,
 
266
        XtNheight, FRAME_WIDTH,
 
267
        NULL);
 
268
        left= XtVaCreatePopupShell("left", overrideShellWidgetClass, parent,
 
269
        XtNx, x-FRAME_WIDTH,
 
270
        XtNy, y-FRAME_WIDTH,
 
271
        XtNwidth, FRAME_WIDTH,
 
272
        XtNheight, height+2*FRAME_WIDTH,
 
273
        NULL);
 
274
        right= XtVaCreatePopupShell("right", overrideShellWidgetClass, parent,
 
275
        XtNx, x+width,
 
276
        XtNy, y-FRAME_WIDTH,
 
277
        XtNwidth, FRAME_WIDTH,
 
278
        XtNheight, height+2*FRAME_WIDTH,
 
279
        NULL);
 
280
        if (flags & FLG_USE_V4L) {
 
281
            blind = XtVaCreatePopupShell("blind", overrideShellWidgetClass, parent,
 
282
            XtNx, x+FRAME_WIDTH,
 
283
            XtNy, y+FRAME_WIDTH,
 
284
            XtNwidth, width,
 
285
            XtNheight, height,
 
286
            NULL);
 
287
            XtVaCreateManagedWidget("text", xwLabelWidgetClass, blind,
 
288
            XtNlabel, "Source: Video4Linux", NULL);
 
289
            XtPopup(blind, XtGrabNone);
 
290
        }
 
291
        
 
292
        XtPopup(top, XtGrabNone);
 
293
        XtPopup(bottom, XtGrabNone);
 
294
        XtPopup(left, XtGrabNone);
 
295
        XtPopup(right, XtGrabNone);
 
296
        XtAddEventHandler(parent,
 
297
        StructureNotifyMask|FocusChangeMask|ExposureMask,
 
298
        False, MoveFrameEH, NULL);
 
299
    }
 
300
}
 
301
 
 
302