File: fd_pallette.c

package info (click to toggle)
libforms1 1.0-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,648 kB
  • ctags: 14,351
  • sloc: ansic: 90,441; makefile: 9,902; sh: 8
file content (184 lines) | stat: -rw-r--r-- 4,126 bytes parent folder | download | duplicates (3)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 *
 * This file is part of XForms.
 *
 * XForms is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1, or
 * (at your option) any later version.
 *
 * XForms 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with XForms; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 *
 */


/* 
 * $Id: fd_pallette.c,v 1.0 2002/05/08 05:27:39 zhao Release $
 *.
 *  This file is part of XForms package
 *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
 *  All rights reserved.
 *.
 *
 *  handles the object pallette
 */
#include "forms.h"
#include <stdlib.h>
#include "pallette.h"
#include "fd_main.h"

static FD_pmain *pmain;

typedef struct
{
    FL_OBJECT *ob;		/* the object (radio button) handle */
    int cls;			/* the obj class it represents      */
}
Entry;

static Entry *entries;
static int nentries;

static void
init_entry_table(FL_FORM * form)
{
    FL_OBJECT *ob;
    int i;

    if (!entries)
	entries = fl_calloc(1, sizeof(*entries) * MAXCLASS);

    /* we obtain the class by looking at the callback function */
    for (i = 0, ob = form->first; i < MAXCLASS && ob; ob = ob->next, i++)
    {
	if (ob->object_callback)
	{
	    entries[nentries].ob = ob;
	    entries[nentries].cls = ob->argument;
	    nentries++;
	}
    }

    if (i >= MAXCLASS)
	fprintf(stderr, "fd_pallette - Internal Error: MAXCLASS too small ?\n");
}

static FL_FORM *
create_all(void)
{
    FD_buttform *bf;
    FD_staticform *sf;
    FD_valuatorform *vf;
    FD_choiceform *cf;
    FD_miscform *mf;

    if (pmain)
	return pmain->pmain;

    pmain = create_form_pmain();
    bf = create_form_buttform();
    sf = create_form_staticform();
    vf = create_form_valuatorform();
    cf = create_form_choiceform();
    mf = create_form_miscform();

    fl_addto_tabfolder(pmain->folder, " Static ", sf->staticform);
    init_entry_table(sf->staticform);
    fl_addto_tabfolder(pmain->folder, " Button ", bf->buttform);
    init_entry_table(bf->buttform);
    fl_addto_tabfolder(pmain->folder, " Valuator ", vf->valuatorform);
    init_entry_table(vf->valuatorform);
    fl_addto_tabfolder(pmain->folder, " Choice ", cf->choiceform);
    init_entry_table(cf->choiceform);
    fl_addto_tabfolder(pmain->folder, " Misc. ", mf->miscform);
    init_entry_table(mf->miscform);

    return pmain->pmain;
}

void
dismiss_pallete(FL_OBJECT * ob, long data)
{
    fl_hide_form(ob->form);
    reset_pallette_menu_status();
}

void
hide_pallette(void)
{
    FL_FORM *form = create_all();

    if (form->visible)
	fl_hide_form(form);
}

void
show_pallette(void)
{
    FL_FORM *form = create_all();
    static int first = 1;

    if (first)
    {
	fl_set_form_position(form, -form->w - 50, 20);
	first = 0;
    }

    select_pallette_entry(cur_class);

    fl_show_form(form, FL_PLACE_POSITION, FL_TRANSIENT, "Pallette");
}

/* all pallette entries are radio buttons */
void
pallette_entry_callback(FL_OBJECT * ob, long data)
{
    if (pmain->vdata && ((FL_OBJECT *) pmain->vdata)->form != ob->form)
	fl_set_button(pmain->vdata, 0);

    pmain->vdata = ob;
    pmain->ldata = data;

    /* selects the object in the object browser */
    select_object_by_class(data);
}

void
reset_pallette(void)
{
    if (pmain && pmain->vdata)
    {
	fl_set_button(pmain->vdata, 0);
	pmain->vdata = 0;
    }
}

/* this function will be called if object browser is selected */
void
select_pallette_entry(int cls)
{
    int i;

    if (!entries || cls < 0)
	return;

    for (i = 0; i < nentries; i++)
    {
	if (entries[i].cls == cls)
	{
	    fl_set_folder(pmain->folder, entries[i].ob->form);
	    fl_set_button(entries[i].ob, 1);
	    break;
	}
    }
}

#include "pallette.c"