~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/twm/iconmgr.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * 
 
3
Copyright 1989,1998  The Open Group
 
4
 
 
5
Permission to use, copy, modify, distribute, and sell this software and its
 
6
documentation for any purpose is hereby granted without fee, provided that
 
7
the above copyright notice appear in all copies and that both that
 
8
copyright notice and this permission notice appear in supporting
 
9
documentation.
 
10
 
 
11
The above copyright notice and this permission notice shall be included in
 
12
all copies or substantial portions of the Software.
 
13
 
 
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
17
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
18
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
19
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
20
 
 
21
Except as contained in this notice, the name of The Open Group shall not be
 
22
used in advertising or otherwise to promote the sale, use or other dealings
 
23
in this Software without prior written authorization from The Open Group.
 
24
 * */
 
25
/* $XFree86: xc/programs/twm/iconmgr.c,v 1.6 2001/12/14 20:01:08 dawes Exp $ */
 
26
 
 
27
/***********************************************************************
 
28
 *
 
29
 * $Xorg: iconmgr.c,v 1.4 2001/02/09 02:05:36 xorgcvs Exp $
 
30
 *
 
31
 * Icon Manager routines
 
32
 *
 
33
 * 09-Mar-89 Tom LaStrange              File Created
 
34
 *
 
35
 ***********************************************************************/
 
36
/* $XFree86: xc/programs/twm/iconmgr.c,v 1.6 2001/12/14 20:01:08 dawes Exp $ */
 
37
 
 
38
#include <stdio.h>
 
39
#include "twm.h"
 
40
#include "util.h"
 
41
#include "parse.h"
 
42
#include "screen.h"
 
43
#include "resize.h"
 
44
#include "add_window.h"
 
45
#include "siconify.bm"
 
46
#include <X11/Xos.h>
 
47
#include <X11/Xmu/CharSet.h>
 
48
#ifdef macII
 
49
int strcmp(); /* missing from string.h in AUX 2.0 */
 
50
#endif
 
51
 
 
52
int iconmgr_textx = siconify_width+11;
 
53
WList *Active = NULL;
 
54
WList *DownIconManager = NULL;
 
55
int iconifybox_width = siconify_width;
 
56
int iconifybox_height = siconify_height;
 
57
 
 
58
/***********************************************************************
 
59
 *
 
60
 *  Procedure:
 
61
 *      CreateIconManagers - creat all the icon manager windows
 
62
 *              for this screen.
 
63
 *
 
64
 *  Returned Value:
 
65
 *      none
 
66
 *
 
67
 *  Inputs:
 
68
 *      none
 
69
 *
 
70
 ***********************************************************************
 
71
 */
 
72
 
 
73
void CreateIconManagers()
 
74
{
 
75
    IconMgr *p;
 
76
    int mask;
 
77
    char str[100];
 
78
    char str1[100];
 
79
    Pixel background;
 
80
    char *icon_name;
 
81
 
 
82
    if (Scr->NoIconManagers)
 
83
        return;
 
84
 
 
85
    if (Scr->siconifyPm == None)
 
86
    {
 
87
        Scr->siconifyPm = XCreatePixmapFromBitmapData(dpy, Scr->Root,
 
88
            (char *)siconify_bits, siconify_width, siconify_height, 1, 0, 1);
 
89
    }
 
90
 
 
91
    for (p = &Scr->iconmgr; p != NULL; p = p->next)
 
92
    {
 
93
        mask = XParseGeometry(p->geometry, &JunkX, &JunkY,
 
94
                              (unsigned int *) &p->width, (unsigned int *)&p->height);
 
95
 
 
96
        if (mask & XNegative)
 
97
            JunkX = Scr->MyDisplayWidth - p->width - 
 
98
              (2 * Scr->BorderWidth) + JunkX;
 
99
 
 
100
        if (mask & YNegative)
 
101
            JunkY = Scr->MyDisplayHeight - p->height -
 
102
              (2 * Scr->BorderWidth) + JunkY;
 
103
 
 
104
        background = Scr->IconManagerC.back;
 
105
        GetColorFromList(Scr->IconManagerBL, p->name, (XClassHint *)NULL,
 
106
                         &background);
 
107
 
 
108
        p->w = XCreateSimpleWindow(dpy, Scr->Root,
 
109
            JunkX, JunkY, p->width, p->height, 1,
 
110
            Scr->Black, background);
 
111
 
 
112
        sprintf(str, "%s Icon Manager", p->name);
 
113
        sprintf(str1, "%s Icons", p->name);
 
114
        if (p->icon_name)
 
115
            icon_name = p->icon_name;
 
116
        else
 
117
            icon_name = str1;
 
118
 
 
119
        XSetStandardProperties(dpy, p->w, str, icon_name, None, NULL, 0, NULL);
 
120
 
 
121
        p->twm_win = AddWindow(p->w, TRUE, p);
 
122
        SetMapStateProp (p->twm_win, WithdrawnState);
 
123
    }
 
124
    for (p = &Scr->iconmgr; p != NULL; p = p->next)
 
125
    {
 
126
        GrabButtons(p->twm_win);
 
127
        GrabKeys(p->twm_win);
 
128
    }
 
129
}
 
130
 
 
131
/***********************************************************************
 
132
 *
 
133
 *  Procedure:
 
134
 *      AllocateIconManager - allocate a new icon manager
 
135
 *
 
136
 *  Inputs:
 
137
 *      name    - the name of this icon manager
 
138
 *      icon_name - the name of the associated icon
 
139
 *      geom    - a geometry string to eventually parse
 
140
 *      columns - the number of columns this icon manager has
 
141
 *
 
142
 ***********************************************************************
 
143
 */
 
144
 
 
145
IconMgr *AllocateIconManager(name, icon_name, geom, columns)
 
146
    char *name;
 
147
    char *geom;
 
148
    char *icon_name;
 
149
    int columns;
 
150
{
 
151
    IconMgr *p;
 
152
 
 
153
#ifdef DEBUG_ICONMGR
 
154
    fprintf(stderr, "AllocateIconManager\n");
 
155
    fprintf(stderr, "  name=\"%s\" icon_name=\"%s\", geom=\"%s\", col=%d\n",
 
156
        name, icon_name, geom, columns);
 
157
#endif
 
158
 
 
159
    if (Scr->NoIconManagers)
 
160
        return NULL;
 
161
 
 
162
    p = (IconMgr *)malloc(sizeof(IconMgr));
 
163
    p->name = name;
 
164
    p->icon_name = icon_name;
 
165
    p->geometry = geom;
 
166
    p->columns = columns;
 
167
    p->first = NULL;
 
168
    p->last = NULL;
 
169
    p->active = NULL;
 
170
    p->scr = Scr;
 
171
    p->count = 0;
 
172
    p->x = 0;
 
173
    p->y = 0;
 
174
    p->width = 150;
 
175
    p->height = 10;
 
176
 
 
177
    Scr->iconmgr.lasti->next = p;
 
178
    p->prev = Scr->iconmgr.lasti;
 
179
    Scr->iconmgr.lasti = p;
 
180
    p->next = NULL;
 
181
 
 
182
    return(p);
 
183
}
 
184
 
 
185
/***********************************************************************
 
186
 *
 
187
 *  Procedure:
 
188
 *      MoveIconManager - move the pointer around in an icon manager
 
189
 *
 
190
 *  Inputs:
 
191
 *      dir     - one of the following:
 
192
 *                      F_FORWICONMGR   - forward in the window list
 
193
 *                      F_BACKICONMGR   - backward in the window list
 
194
 *                      F_UPICONMGR     - up one row
 
195
 *                      F_DOWNICONMGR   - down one row
 
196
 *                      F_LEFTICONMGR   - left one column
 
197
 *                      F_RIGHTICONMGR  - right one column
 
198
 *
 
199
 *  Special Considerations:
 
200
 *      none
 
201
 *
 
202
 ***********************************************************************
 
203
 */
 
204
 
 
205
void MoveIconManager(dir)
 
206
    int dir;
 
207
{
 
208
    IconMgr *ip;
 
209
    WList *tmp = NULL;
 
210
    int cur_row, cur_col, new_row, new_col;
 
211
    int row_inc, col_inc;
 
212
    int got_it;
 
213
 
 
214
    if (!Active) return;
 
215
 
 
216
    cur_row = Active->row;
 
217
    cur_col = Active->col;
 
218
    ip = Active->iconmgr;
 
219
 
 
220
    row_inc = 0;
 
221
    col_inc = 0;
 
222
    got_it = FALSE;
 
223
 
 
224
    switch (dir)
 
225
    {
 
226
        case F_FORWICONMGR:
 
227
            if ((tmp = Active->next) == NULL)
 
228
                tmp = ip->first;
 
229
            got_it = TRUE;
 
230
            break;
 
231
 
 
232
        case F_BACKICONMGR:
 
233
            if ((tmp = Active->prev) == NULL)
 
234
                tmp = ip->last;
 
235
            got_it = TRUE;
 
236
            break;
 
237
 
 
238
        case F_UPICONMGR:
 
239
            row_inc = -1;
 
240
            break;
 
241
 
 
242
        case F_DOWNICONMGR:
 
243
            row_inc = 1;
 
244
            break;
 
245
 
 
246
        case F_LEFTICONMGR:
 
247
            col_inc = -1;
 
248
            break;
 
249
 
 
250
        case F_RIGHTICONMGR:
 
251
            col_inc = 1;
 
252
            break;
 
253
    }
 
254
 
 
255
    /* If got_it is FALSE ast this point then we got a left, right,
 
256
     * up, or down, command.  We will enter this loop until we find
 
257
     * a window to warp to.
 
258
     */
 
259
    new_row = cur_row;
 
260
    new_col = cur_col;
 
261
 
 
262
    while (!got_it)
 
263
    {
 
264
        new_row += row_inc;
 
265
        new_col += col_inc;
 
266
        if (new_row < 0)
 
267
            new_row = ip->cur_rows - 1;
 
268
        if (new_col < 0)
 
269
            new_col = ip->cur_columns - 1;
 
270
        if (new_row >= ip->cur_rows)
 
271
            new_row = 0;
 
272
        if (new_col >= ip->cur_columns)
 
273
            new_col = 0;
 
274
            
 
275
        /* Now let's go through the list to see if there is an entry with this
 
276
         * new position
 
277
         */
 
278
        for (tmp = ip->first; tmp != NULL; tmp = tmp->next)
 
279
        {
 
280
            if (tmp->row == new_row && tmp->col == new_col)
 
281
            {
 
282
                got_it = TRUE;
 
283
                break;
 
284
            }
 
285
        }
 
286
    }
 
287
 
 
288
    if (!got_it)
 
289
    {
 
290
        fprintf (stderr, 
 
291
                 "%s:  unable to find window (%d, %d) in icon manager\n", 
 
292
                 ProgramName, new_row, new_col);
 
293
        return;
 
294
    }
 
295
 
 
296
    if (tmp == NULL)
 
297
      return;
 
298
 
 
299
    /* raise the frame so the icon manager is visible */
 
300
    if (ip->twm_win->mapped) {
 
301
        XRaiseWindow(dpy, ip->twm_win->frame);
 
302
        XWarpPointer(dpy, None, tmp->icon, 0,0,0,0, 5, 5);
 
303
    } else {
 
304
        if (tmp->twm->title_height) {
 
305
            int tbx = Scr->TBInfo.titlex;
 
306
            int x = tmp->twm->highlightx;
 
307
            XWarpPointer (dpy, None, tmp->twm->title_w, 0, 0, 0, 0,
 
308
                          tbx + (x - tbx) / 2,
 
309
                          Scr->TitleHeight / 4);
 
310
        } else {
 
311
            XWarpPointer (dpy, None, tmp->twm->w, 0, 0, 0, 0, 5, 5);
 
312
        }
 
313
    }
 
314
}
 
315
 
 
316
/***********************************************************************
 
317
 *
 
318
 *  Procedure:
 
319
 *      JumpIconManager - jump from one icon manager to another,
 
320
 *              possibly even on another screen
 
321
 *
 
322
 *  Inputs:
 
323
 *      dir     - one of the following:
 
324
 *                      F_NEXTICONMGR   - go to the next icon manager 
 
325
 *                      F_PREVICONMGR   - go to the previous one
 
326
 *
 
327
 ***********************************************************************
 
328
 */
 
329
 
 
330
void JumpIconManager(dir)
 
331
    register int dir;
 
332
{
 
333
    IconMgr *ip, *tmp_ip = NULL;
 
334
    int got_it = FALSE;
 
335
    ScreenInfo *sp;
 
336
    int screen;
 
337
 
 
338
    if (!Active) return;
 
339
 
 
340
 
 
341
#define ITER(i) (dir == F_NEXTICONMGR ? (i)->next : (i)->prev)
 
342
#define IPOFSP(sp) (dir == F_NEXTICONMGR ? &(sp->iconmgr) : sp->iconmgr.lasti)
 
343
#define TEST(ip) if ((ip)->count != 0 && (ip)->twm_win->mapped) \
 
344
                 { got_it = TRUE; break; }
 
345
 
 
346
    ip = Active->iconmgr;
 
347
    for (tmp_ip = ITER(ip); tmp_ip; tmp_ip = ITER(tmp_ip)) {
 
348
        TEST (tmp_ip);
 
349
    }
 
350
 
 
351
    if (!got_it) {
 
352
        int origscreen = ip->scr->screen;
 
353
        int inc = (dir == F_NEXTICONMGR ? 1 : -1);
 
354
 
 
355
        for (screen = origscreen + inc; ; screen += inc) {
 
356
            if (screen >= NumScreens)
 
357
              screen = 0;
 
358
            else if (screen < 0)
 
359
              screen = NumScreens - 1;
 
360
 
 
361
            sp = ScreenList[screen];
 
362
            if (sp) {
 
363
                for (tmp_ip = IPOFSP (sp); tmp_ip; tmp_ip = ITER(tmp_ip)) {
 
364
                    TEST (tmp_ip);
 
365
                }
 
366
            }
 
367
            if (got_it || screen == origscreen) break;
 
368
        }
 
369
    }
 
370
 
 
371
#undef ITER
 
372
#undef IPOFSP
 
373
#undef TEST
 
374
 
 
375
    if (!got_it) {
 
376
        Bell(XkbBI_MinorError,0,None);
 
377
        return;
 
378
    }
 
379
 
 
380
    /* raise the frame so it is visible */
 
381
    XRaiseWindow(dpy, tmp_ip->twm_win->frame);
 
382
    if (tmp_ip->active)
 
383
        XWarpPointer(dpy, None, tmp_ip->active->icon, 0,0,0,0, 5, 5);
 
384
    else
 
385
        XWarpPointer(dpy, None, tmp_ip->w, 0,0,0,0, 5, 5);
 
386
}
 
387
 
 
388
/***********************************************************************
 
389
 *
 
390
 *  Procedure:
 
391
 *      AddIconManager - add a window to an icon manager
 
392
 *
 
393
 *  Inputs:
 
394
 *      tmp_win - the TwmWindow structure
 
395
 *
 
396
 ***********************************************************************
 
397
 */
 
398
 
 
399
WList *AddIconManager(tmp_win)
 
400
    TwmWindow *tmp_win;
 
401
{
 
402
    WList *tmp;
 
403
    int h;
 
404
    unsigned long valuemask;            /* mask for create windows */
 
405
    XSetWindowAttributes attributes;    /* attributes for create windows */
 
406
    IconMgr *ip;
 
407
 
 
408
    tmp_win->list = NULL;
 
409
 
 
410
    if (tmp_win->iconmgr || tmp_win->transient || Scr->NoIconManagers)
 
411
        return NULL;
 
412
 
 
413
    if (LookInList(Scr->IconMgrNoShow, tmp_win->full_name, &tmp_win->class))
 
414
        return NULL;
 
415
    if (Scr->IconManagerDontShow &&
 
416
        !LookInList(Scr->IconMgrShow, tmp_win->full_name, &tmp_win->class))
 
417
        return NULL;
 
418
    if ((ip = (IconMgr *)LookInList(Scr->IconMgrs, tmp_win->full_name,
 
419
            &tmp_win->class)) == NULL)
 
420
        ip = &Scr->iconmgr;
 
421
 
 
422
    tmp = (WList *) malloc(sizeof(WList));
 
423
    tmp->iconmgr = ip;
 
424
    tmp->next = NULL;
 
425
    tmp->active = FALSE;
 
426
    tmp->down = FALSE;
 
427
 
 
428
    InsertInIconManager(ip, tmp, tmp_win);
 
429
 
 
430
    tmp->twm = tmp_win;
 
431
 
 
432
    tmp->fore = Scr->IconManagerC.fore;
 
433
    tmp->back = Scr->IconManagerC.back;
 
434
    tmp->highlight = Scr->IconManagerHighlight;
 
435
 
 
436
    GetColorFromList(Scr->IconManagerFL, tmp_win->full_name, &tmp_win->class,
 
437
        &tmp->fore);
 
438
    GetColorFromList(Scr->IconManagerBL, tmp_win->full_name, &tmp_win->class,
 
439
        &tmp->back);
 
440
    GetColorFromList(Scr->IconManagerHighlightL, tmp_win->full_name,
 
441
        &tmp_win->class, &tmp->highlight);
 
442
 
 
443
    h = Scr->IconManagerFont.height + 10;
 
444
    if (h < (siconify_height + 4))
 
445
        h = siconify_height + 4;
 
446
 
 
447
    ip->height = h * ip->count;
 
448
    tmp->me = ip->count;
 
449
    tmp->x = -1;
 
450
    tmp->y = -1;
 
451
    
 
452
    valuemask = (CWBackPixel | CWBorderPixel | CWEventMask | CWCursor);
 
453
    attributes.background_pixel = tmp->back;
 
454
    attributes.border_pixel = tmp->back;
 
455
    attributes.event_mask = (KeyPressMask | ButtonPressMask |
 
456
                             ButtonReleaseMask | ExposureMask |
 
457
                             EnterWindowMask | LeaveWindowMask);
 
458
    attributes.cursor = Scr->IconMgrCursor;
 
459
    tmp->w = XCreateWindow (dpy, ip->w, 0, 0, (unsigned int) 1, 
 
460
                            (unsigned int) h, (unsigned int) 0, 
 
461
                            CopyFromParent, (unsigned int) CopyFromParent,
 
462
                            (Visual *) CopyFromParent, valuemask, &attributes);
 
463
 
 
464
 
 
465
    valuemask = (CWBackPixel | CWBorderPixel | CWEventMask | CWCursor);
 
466
    attributes.background_pixel = tmp->back;
 
467
    attributes.border_pixel = Scr->Black;
 
468
    attributes.event_mask = (ButtonReleaseMask| ButtonPressMask |
 
469
                             ExposureMask);
 
470
    attributes.cursor = Scr->ButtonCursor;
 
471
    tmp->icon = XCreateWindow (dpy, tmp->w, 5, (int) (h - siconify_height)/2,
 
472
                               (unsigned int) siconify_width,
 
473
                               (unsigned int) siconify_height,
 
474
                               (unsigned int) 0, CopyFromParent,
 
475
                               (unsigned int) CopyFromParent,
 
476
                               (Visual *) CopyFromParent,
 
477
                               valuemask, &attributes);
 
478
 
 
479
    ip->count += 1;
 
480
    PackIconManager(ip);
 
481
    XMapWindow(dpy, tmp->w);
 
482
 
 
483
    XSaveContext(dpy, tmp->w, IconManagerContext, (caddr_t) tmp);
 
484
    XSaveContext(dpy, tmp->w, TwmContext, (caddr_t) tmp_win);
 
485
    XSaveContext(dpy, tmp->w, ScreenContext, (caddr_t) Scr);
 
486
    XSaveContext(dpy, tmp->icon, TwmContext, (caddr_t) tmp_win);
 
487
    XSaveContext(dpy, tmp->icon, ScreenContext, (caddr_t) Scr);
 
488
    tmp_win->list = tmp;
 
489
 
 
490
    if (!ip->twm_win->icon)
 
491
    {
 
492
        XMapWindow(dpy, ip->w);
 
493
        XMapWindow(dpy, ip->twm_win->frame);
 
494
    }
 
495
 
 
496
    if (Active == NULL) Active = tmp;
 
497
 
 
498
    return (tmp);
 
499
}
 
500
 
 
501
/***********************************************************************
 
502
 *
 
503
 *  Procedure:
 
504
 *      InsertInIconManager - put an allocated entry into an icon 
 
505
 *              manager
 
506
 *
 
507
 *  Inputs:
 
508
 *      ip      - the icon manager pointer
 
509
 *      tmp     - the entry to insert
 
510
 *
 
511
 ***********************************************************************
 
512
 */
 
513
 
 
514
void InsertInIconManager(ip, tmp, tmp_win)
 
515
    IconMgr *ip;
 
516
    WList *tmp;
 
517
    TwmWindow *tmp_win;
 
518
{
 
519
    WList *tmp1;
 
520
    int added;
 
521
    int (*compar)(const char *, const char *) 
 
522
        = (Scr->CaseSensitive ? strcmp : XmuCompareISOLatin1);
 
523
 
 
524
    added = FALSE;
 
525
    if (ip->first == NULL)
 
526
    {
 
527
        ip->first = tmp;
 
528
        tmp->prev = NULL;
 
529
        ip->last = tmp;
 
530
        added = TRUE;
 
531
    }
 
532
    else if (Scr->SortIconMgr)
 
533
    {
 
534
        for (tmp1 = ip->first; tmp1 != NULL; tmp1 = tmp1->next)
 
535
        {
 
536
            if ((*compar)(tmp_win->icon_name, tmp1->twm->icon_name) < 0)
 
537
            {
 
538
                tmp->next = tmp1;
 
539
                tmp->prev = tmp1->prev;
 
540
                tmp1->prev = tmp;
 
541
                if (tmp->prev == NULL)
 
542
                    ip->first = tmp;
 
543
                else
 
544
                    tmp->prev->next = tmp;
 
545
                added = TRUE;
 
546
                break;
 
547
            }
 
548
        }
 
549
    }
 
550
 
 
551
    if (!added)
 
552
    {
 
553
        ip->last->next = tmp;
 
554
        tmp->prev = ip->last;
 
555
        ip->last = tmp;
 
556
    }
 
557
}
 
558
 
 
559
void RemoveFromIconManager(ip, tmp)
 
560
    IconMgr *ip;
 
561
    WList *tmp;
 
562
{
 
563
    if (tmp->prev == NULL)
 
564
        ip->first = tmp->next;
 
565
    else
 
566
        tmp->prev->next = tmp->next;
 
567
 
 
568
    if (tmp->next == NULL)
 
569
        ip->last = tmp->prev;
 
570
    else
 
571
        tmp->next->prev = tmp->prev;
 
572
}
 
573
 
 
574
/***********************************************************************
 
575
 *
 
576
 *  Procedure:
 
577
 *      RemoveIconManager - remove a window from the icon manager
 
578
 *
 
579
 *  Inputs:
 
580
 *      tmp_win - the TwmWindow structure
 
581
 *
 
582
 ***********************************************************************
 
583
 */
 
584
 
 
585
void RemoveIconManager(tmp_win)
 
586
    TwmWindow *tmp_win;
 
587
{
 
588
    IconMgr *ip;
 
589
    WList *tmp;
 
590
 
 
591
    if (tmp_win->list == NULL)
 
592
        return;
 
593
 
 
594
    tmp = tmp_win->list;
 
595
    tmp_win->list = NULL;
 
596
    ip = tmp->iconmgr;
 
597
 
 
598
    RemoveFromIconManager(ip, tmp);
 
599
    
 
600
    XDeleteContext(dpy, tmp->icon, TwmContext);
 
601
    XDeleteContext(dpy, tmp->icon, ScreenContext);
 
602
    XDestroyWindow(dpy, tmp->icon);
 
603
    XDeleteContext(dpy, tmp->w, IconManagerContext);
 
604
    XDeleteContext(dpy, tmp->w, TwmContext);
 
605
    XDeleteContext(dpy, tmp->w, ScreenContext);
 
606
    XDestroyWindow(dpy, tmp->w);
 
607
    ip->count -= 1;
 
608
    free((char *) tmp);
 
609
 
 
610
    PackIconManager(ip);
 
611
 
 
612
    if (ip->count == 0)
 
613
    {
 
614
        XUnmapWindow(dpy, ip->twm_win->frame);
 
615
    }
 
616
 
 
617
}
 
618
 
 
619
void ActiveIconManager(active)
 
620
    WList *active;
 
621
{
 
622
    active->active = TRUE;
 
623
    Active = active;
 
624
    Active->iconmgr->active = active;
 
625
    DrawIconManagerBorder(active);
 
626
}
 
627
 
 
628
void NotActiveIconManager(active)
 
629
    WList *active;
 
630
{
 
631
    active->active = FALSE;
 
632
    DrawIconManagerBorder(active);
 
633
}
 
634
 
 
635
void DrawIconManagerBorder(tmp)
 
636
    WList *tmp;
 
637
{
 
638
    {
 
639
        XSetForeground(dpy, Scr->NormalGC, tmp->fore);
 
640
            XDrawRectangle(dpy, tmp->w, Scr->NormalGC, 2, 2,
 
641
                tmp->width-5, tmp->height-5);
 
642
 
 
643
        if (tmp->active && Scr->Highlight)
 
644
            XSetForeground(dpy, Scr->NormalGC, tmp->highlight);
 
645
        else
 
646
            XSetForeground(dpy, Scr->NormalGC, tmp->back);
 
647
 
 
648
        XDrawRectangle(dpy, tmp->w, Scr->NormalGC, 0, 0,
 
649
            tmp->width-1, tmp->height-1);
 
650
        XDrawRectangle(dpy, tmp->w, Scr->NormalGC, 1, 1,
 
651
            tmp->width-3, tmp->height-3);
 
652
    }
 
653
}
 
654
 
 
655
/***********************************************************************
 
656
 *
 
657
 *  Procedure:
 
658
 *      SortIconManager - sort the dude
 
659
 *
 
660
 *  Inputs:
 
661
 *      ip      - a pointer to the icon manager struture
 
662
 *
 
663
 ***********************************************************************
 
664
 */
 
665
 
 
666
void SortIconManager(ip)
 
667
    IconMgr *ip;
 
668
{
 
669
    WList *tmp1, *tmp2;
 
670
    int done;
 
671
    int (*compar)(const char *, const char *) 
 
672
        = (Scr->CaseSensitive ? strcmp : XmuCompareISOLatin1);
 
673
 
 
674
    if (ip == NULL)
 
675
        ip = Active->iconmgr;
 
676
 
 
677
    done = FALSE;
 
678
    do
 
679
    {
 
680
        for (tmp1 = ip->first; tmp1 != NULL; tmp1 = tmp1->next)
 
681
        {
 
682
            if ((tmp2 = tmp1->next) == NULL)
 
683
            {
 
684
                done = TRUE;
 
685
                break;
 
686
            }
 
687
            if ((*compar)(tmp1->twm->icon_name, tmp2->twm->icon_name) > 0)
 
688
            {
 
689
                /* take it out and put it back in */
 
690
                RemoveFromIconManager(ip, tmp2);
 
691
                InsertInIconManager(ip, tmp2, tmp2->twm);
 
692
                break;
 
693
            }
 
694
        }
 
695
    }
 
696
    while (!done);
 
697
    PackIconManager(ip);
 
698
}
 
699
 
 
700
/***********************************************************************
 
701
 *
 
702
 *  Procedure:
 
703
 *      PackIconManager - pack the icon manager windows following
 
704
 *              an addition or deletion
 
705
 *
 
706
 *  Inputs:
 
707
 *      ip      - a pointer to the icon manager struture
 
708
 *
 
709
 ***********************************************************************
 
710
 */
 
711
 
 
712
void PackIconManager(ip)
 
713
    IconMgr *ip;
 
714
{
 
715
    int newwidth, i, row, col, maxcol,  colinc, rowinc, wheight, wwidth;
 
716
    int new_x, new_y;
 
717
    int savewidth;
 
718
    WList *tmp;
 
719
 
 
720
    wheight = Scr->IconManagerFont.height + 10;
 
721
    if (wheight < (siconify_height + 4))
 
722
        wheight = siconify_height + 4;
 
723
 
 
724
    wwidth = ip->width / ip->columns;
 
725
 
 
726
    rowinc = wheight;
 
727
    colinc = wwidth;
 
728
 
 
729
    row = 0;
 
730
    col = ip->columns;
 
731
    maxcol = 0;
 
732
    for (i = 0, tmp = ip->first; tmp != NULL; i++, tmp = tmp->next)
 
733
    {
 
734
        tmp->me = i;
 
735
        if (++col >= ip->columns)
 
736
        {
 
737
            col = 0;
 
738
            row += 1;
 
739
        }
 
740
        if (col > maxcol)
 
741
            maxcol = col;
 
742
 
 
743
        new_x = col * colinc;
 
744
        new_y = (row-1) * rowinc;
 
745
 
 
746
        /* if the position or size has not changed, don't touch it */
 
747
        if (tmp->x != new_x || tmp->y != new_y ||
 
748
            tmp->width != wwidth || tmp->height != wheight)
 
749
        {
 
750
            XMoveResizeWindow(dpy, tmp->w, new_x, new_y, wwidth, wheight);
 
751
 
 
752
            tmp->row = row-1;
 
753
            tmp->col = col;
 
754
            tmp->x = new_x;
 
755
            tmp->y = new_y;
 
756
            tmp->width = wwidth;
 
757
            tmp->height = wheight;
 
758
        }
 
759
    }
 
760
    maxcol += 1;
 
761
 
 
762
    ip->cur_rows = row;
 
763
    ip->cur_columns = maxcol;
 
764
    ip->height = row * rowinc;
 
765
    if (ip->height == 0)
 
766
        ip->height = rowinc;
 
767
    newwidth = maxcol * colinc;
 
768
    if (newwidth == 0)
 
769
        newwidth = colinc;
 
770
 
 
771
    XResizeWindow(dpy, ip->w, newwidth, ip->height);
 
772
 
 
773
    savewidth = ip->width;
 
774
    if (ip->twm_win)
 
775
      SetupWindow (ip->twm_win,
 
776
                   ip->twm_win->frame_x, ip->twm_win->frame_y,
 
777
                   newwidth, ip->height + ip->twm_win->title_height, -1);
 
778
    ip->width = savewidth;
 
779
}