OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [libcdl/] [dialog.cxx] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//{{{  Banner                           
2
 
3
//============================================================================
4
//
5
//     dialog.cxx
6
//
7
//     Implementation of the CdlDialog class
8
//
9
//============================================================================
10
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
11
// -------------------------------------------                              
12
// This file is part of the eCos host tools.                                
13
// Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.            
14
//
15
// This program is free software; you can redistribute it and/or modify     
16
// it under the terms of the GNU General Public License as published by     
17
// the Free Software Foundation; either version 2 or (at your option) any   
18
// later version.                                                           
19
//
20
// This program is distributed in the hope that it will be useful, but      
21
// WITHOUT ANY WARRANTY; without even the implied warranty of               
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
23
// General Public License for more details.                                 
24
//
25
// You should have received a copy of the GNU General Public License        
26
// along with this program; if not, write to the                            
27
// Free Software Foundation, Inc., 51 Franklin Street,                      
28
// Fifth Floor, Boston, MA  02110-1301, USA.                                
29
// -------------------------------------------                              
30
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
31
//============================================================================
32
//#####DESCRIPTIONBEGIN####
33
//
34
// Author(s):   bartv
35
// Contact(s):  bartv
36
// Date:        1999/03/01
37
// Version:     0.01
38
//
39
//####DESCRIPTIONEND####
40
//============================================================================
41
 
42
//}}}
43
//{{{  #include's                       
44
 
45
// ----------------------------------------------------------------------------
46
#include "cdlconfig.h"
47
 
48
// Get the infrastructure types, assertions, tracing and similar
49
// facilities.
50
#include <cyg/infra/cyg_ass.h>
51
#include <cyg/infra/cyg_trac.h>
52
 
53
// <cdlcore.hxx> defines everything implemented in this module.
54
// It implicitly supplies <string>, <vector> and <map> because
55
// the class definitions rely on these headers.
56
#include <cdlcore.hxx>
57
 
58
//}}}
59
 
60
//{{{  Class statics                    
61
 
62
// ----------------------------------------------------------------------------
63
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlDialogBody);
64
 
65
// The application code can specify whether or not it supports custom
66
// dialogs. This affects the internals of e.g.
67
// CdlValuable::get_widget_hint(). For now err on the side of caution.
68
 
69
bool CdlDialogBody::dialogs_enabled     = false;
70
 
71
void
72
CdlDialogBody::disable_dialogs()
73
{
74
    CYG_REPORT_FUNCNAME("CdlDialog::disable_dialogs");
75
    dialogs_enabled = false;
76
    CYG_REPORT_RETURN();
77
}
78
 
79
void
80
CdlDialogBody::enable_dialogs()
81
{
82
    CYG_REPORT_FUNCNAME("CdlDialog::enable_dialogs");
83
    dialogs_enabled = true;
84
    CYG_REPORT_RETURN();
85
}
86
 
87
bool
88
CdlDialogBody::dialogs_are_enabled()
89
{
90
    CYG_REPORT_FUNCNAMETYPE("CdlDialog::dialogs_are_enabled", "result %d");
91
    bool result = dialogs_enabled;
92
    CYG_REPORT_RETVAL(result);
93
    return result;
94
}
95
 
96
//}}}
97
//{{{  Constructor                      
98
 
99
// ----------------------------------------------------------------------------
100
// Constructor. The real work is actually done in the parse routine.
101
//
102
// There is no data associated with a custom dialog object.
103
CdlDialogBody::CdlDialogBody(std::string name_arg)
104
    : CdlNodeBody(name_arg),
105
      CdlUserVisibleBody(),
106
      CdlParentableBody()
107
{
108
    CYG_REPORT_FUNCNAME("CdlDialogBody:: constructor");
109
    CYG_REPORT_FUNCARG1XV(this);
110
 
111
    cdldialogbody_cookie = CdlDialogBody_Magic;
112
    CYGDBG_MEMLEAK_CONSTRUCTOR();
113
 
114
    CYG_POSTCONDITION_THISC();
115
    CYG_REPORT_RETURN();
116
}
117
 
118
//}}}
119
//{{{  Destructor                       
120
 
121
// ----------------------------------------------------------------------------
122
// The real work is done in the base classes.
123
 
124
CdlDialogBody::~CdlDialogBody()
125
{
126
    CYG_REPORT_FUNCNAME("CdlDialogBody:: destructor");
127
    CYG_REPORT_FUNCARG1XV(this);
128
    CYG_PRECONDITION_THISC();
129
 
130
    cdldialogbody_cookie = CdlDialogBody_Invalid;
131
    CYGDBG_MEMLEAK_DESTRUCTOR();
132
 
133
    CYG_REPORT_RETURN();
134
}
135
 
136
//}}}
137
//{{{  parse_dialog()                   
138
 
139
// ----------------------------------------------------------------------------
140
// Parsing a dialog definition.
141
int
142
CdlDialogBody::parse_dialog(CdlInterpreter interp, int argc, const char* argv[])
143
{
144
    CYG_REPORT_FUNCNAMETYPE("CdlDialog::parse_dialog", "result %d");
145
    CYG_REPORT_FUNCARG1("argc %d", argc);
146
    CYG_PRECONDITION_CLASSC(interp);
147
 
148
    std::string diag_argv0      = CdlParse::get_tcl_cmd_name(argv[0]);
149
 
150
    CdlLoadable  loadable       = interp->get_loadable();
151
    CdlContainer parent         = interp->get_container();
152
    CdlToplevel  toplevel       = interp->get_toplevel();
153
    CYG_ASSERT_CLASSC(loadable);        // There should always be a loadable during parsing
154
    CYG_ASSERT_CLASSC(parent);
155
    CYG_ASSERT_CLASSC(toplevel);
156
 
157
    // The new dialog should be created and added to the loadable
158
    // early on. If there is a parsing error it will get cleaned up
159
    // automatically as a consequence of the loadable destructor.
160
    // However it is necessary to validate the name first. Errors
161
    // should be reported via CdlParse::report_error(), which
162
    // may result in an exception.
163
    CdlDialog    new_dialog     = 0;
164
    CdlNode      old_node       = 0;
165
    std::vector<CdlInterpreterCommandEntry>* old_commands = 0;
166
    int          result         = TCL_OK;
167
 
168
    // Currently there are no command-line options. This may change in future.
169
    if (3 != argc) {
170
        CdlParse::report_error(interp, "", std::string("Incorrect number of arguments to `") + diag_argv0 +
171
                               "'\nExpecting name and properties list.");
172
    } else if (!Tcl_CommandComplete(CDL_TCL_CONST_CAST(char*, argv[2]))) {
173
        CdlParse::report_error(interp, "", std::string("Invalid property list for cdl_dialog `") + argv[1] + "'.");
174
    } else if (0 != toplevel->lookup(argv[1])) {
175
        CdlParse::report_error(interp, "", std::string("Dialog `") + argv[1] + "' cannot be loaded.\n" +
176
                               "The name is already in use.");
177
    } else {
178
 
179
        try {
180
            new_dialog = new CdlDialogBody(argv[1]);
181
            toplevel->add_node(loadable, parent, new_dialog);
182
 
183
            // Push the dialog as the current base object early on.
184
            // This aids diagnostics.
185
            old_node = interp->push_node(new_dialog);
186
 
187
            std::string tcl_result;
188
            std::vector<CdlInterpreterCommandEntry>  new_commands;
189
            static CdlInterpreterCommandEntry commands[] =
190
            {
191
                CdlInterpreterCommandEntry("init_proc",          &CdlWizardBody::parse_init_proc    ),
192
                CdlInterpreterCommandEntry("update_proc",        &CdlDialogBody::parse_update_proc  ),
193
                CdlInterpreterCommandEntry("display_proc",       &CdlDialogBody::parse_display_proc ),
194
                CdlInterpreterCommandEntry("confirm_proc",       &CdlWizardBody::parse_confirm_proc ),
195
                CdlInterpreterCommandEntry("cancel_proc",        &CdlWizardBody::parse_cancel_proc  ),
196
                CdlInterpreterCommandEntry("",                   0                                  ),
197
            };
198
            int i;
199
            for (i = 0; 0 != commands[i].command; i++) {
200
                new_commands.push_back(commands[i]);
201
            }
202
            CdlParentableBody::add_property_parsers(new_commands);
203
            CdlUserVisibleBody::add_property_parsers(new_commands);
204
            CdlNodeBody::add_property_parsers(new_commands);
205
 
206
            // Now evaluate the body. If an error occurs then typically
207
            // this will be reported via CdlParse::report_error(),
208
            // but any exceptions will have been intercepted and
209
            // turned into a Tcl error.
210
            old_commands = interp->push_commands(new_commands);
211
            result = interp->eval(argv[2], tcl_result);
212
            interp->pop_commands(old_commands);
213
            old_commands = 0;
214
            interp->pop_node(old_node);
215
            old_node = 0;
216
 
217
            if (TCL_OK == result) {
218
                // Even if there were errors, they were not fatal. There may
219
                // now be a number of properties for this option, and some
220
                // validation should take place. Start with the base classes.
221
                new_dialog->CdlNodeBody::check_properties(interp);
222
                new_dialog->CdlUserVisibleBody::check_properties(interp);
223
                new_dialog->CdlParentableBody::check_properties(interp);
224
 
225
                // The init_proc and update_proc properties are optional.
226
                // The display_proc, confirm_proc and cancel_proc properties
227
                // are compulsory.
228
                if (new_dialog->count_properties(CdlPropertyId_InitProc) > 1) {
229
                    CdlParse::report_error(interp, "", "A dialog should have only one `init_proc' property.");
230
                }
231
                if (new_dialog->count_properties(CdlPropertyId_UpdateProc) > 1) {
232
                    CdlParse::report_error(interp, "", "A dialog should have only one `update_proc' property.");
233
                }
234
                if (new_dialog->count_properties(CdlPropertyId_DisplayProc) != 1) {
235
                    CdlParse::report_error(interp, "", "A dialog should have one `display_proc' property.");
236
                }
237
                if (new_dialog->count_properties(CdlPropertyId_ConfirmProc) != 1) {
238
                    CdlParse::report_error(interp, "", "A dialog should have one `confirm_proc' property.");
239
                }
240
                if (new_dialog->count_properties(CdlPropertyId_CancelProc) != 1) {
241
                    CdlParse::report_error(interp, "", "A dialog should have one `cancel_proc' property.");
242
                }
243
            }
244
 
245
        } catch(...) {
246
            if (0 != new_dialog) {
247
                delete new_dialog;
248
            }
249
            if (0 != old_node) {
250
                interp->pop_node(old_node);
251
            }
252
            if (0 != old_commands) {
253
                interp->pop_commands(old_commands);
254
            }
255
            throw;
256
        }
257
    }
258
 
259
    CYG_REPORT_RETVAL(result);
260
    return result;
261
}
262
 
263
 
264
// ----------------------------------------------------------------------------
265
// Syntax: display_proc <tclcode>
266
int
267
CdlDialogBody::parse_display_proc(CdlInterpreter interp, int argc, const char* argv[])
268
{
269
    CYG_REPORT_FUNCNAMETYPE("parse_display_proc", "result %d");
270
 
271
    int result = CdlParse::parse_tclcode_property(interp, argc, argv, CdlPropertyId_DisplayProc, 0, 0);
272
 
273
    CYG_REPORT_RETVAL(result);
274
    return result;
275
}
276
 
277
// ----------------------------------------------------------------------------
278
// Syntax: update_proc <tclcode>
279
int
280
CdlDialogBody::parse_update_proc(CdlInterpreter interp, int argc, const char* argv[])
281
{
282
    CYG_REPORT_FUNCNAMETYPE("parse_update_proc", "result %d");
283
 
284
    int result = CdlParse::parse_tclcode_property(interp, argc, argv, CdlPropertyId_UpdateProc, 0, 0);
285
 
286
    CYG_REPORT_RETVAL(result);
287
    return result;
288
}
289
 
290
//}}}
291
//{{{  Persistence                      
292
 
293
// ----------------------------------------------------------------------------
294
// For now there is no information in a custom dialog that should end
295
// up in a save file, but it is still desirable to override the base
296
// class member function.
297
 
298
void
299
CdlDialogBody::save(CdlInterpreter interp, Tcl_Channel chan, int indentation, bool minimal)
300
{
301
    CYG_REPORT_FUNCNAME("CdlDialog::save");
302
    CYG_REPORT_FUNCARG5XV(this, interp, chan, indentation, minimal);
303
    CYG_PRECONDITION_THISC();
304
 
305
    CYG_UNUSED_PARAM(CdlInterpreter, interp);
306
    CYG_UNUSED_PARAM(Tcl_Channel, chan);
307
    CYG_UNUSED_PARAM(int, indentation);
308
    CYG_UNUSED_PARAM(bool, minimal);
309
 
310
    CYG_REPORT_RETURN();
311
}
312
 
313
//}}}
314
//{{{  Data access                      
315
 
316
// ----------------------------------------------------------------------------
317
bool
318
CdlDialogBody::has_init_proc() const
319
{
320
    CYG_REPORT_FUNCNAMETYPE("CdlDialog::has_init_proc", "result %d");
321
    CYG_REPORT_FUNCARG1XV(this);
322
    CYG_PRECONDITION_THISC();
323
 
324
    bool result = has_property(CdlPropertyId_InitProc);
325
    CYG_REPORT_RETVAL(result);
326
    return result;
327
}
328
 
329
bool
330
CdlDialogBody::has_update_proc() const
331
{
332
    CYG_REPORT_FUNCNAMETYPE("CdlDialog::has_update_proc", "result %d");
333
    CYG_REPORT_FUNCARG1XV(this);
334
    CYG_PRECONDITION_THISC();
335
 
336
    bool result = has_property(CdlPropertyId_UpdateProc);
337
    CYG_REPORT_RETVAL(result);
338
    return result;
339
}
340
 
341
const cdl_tcl_code&
342
CdlDialogBody::get_init_proc() const
343
{
344
    CYG_REPORT_FUNCNAME("CdlDialog::get_init_proc");
345
    CYG_REPORT_FUNCARG1XV(this);
346
    CYG_PRECONDITION_THISC();
347
 
348
    static cdl_tcl_code null_result = "";
349
    cdl_tcl_code& result = null_result;
350
    CdlProperty prop = get_property(CdlPropertyId_InitProc);
351
    if (0 != prop) {
352
        CdlProperty_TclCode tclprop = dynamic_cast<CdlProperty_TclCode>(prop);
353
        CYG_ASSERT_CLASSC(tclprop);
354
        result = tclprop->get_code();
355
    }
356
 
357
    CYG_REPORT_RETURN();
358
    return result;
359
}
360
 
361
const cdl_tcl_code&
362
CdlDialogBody::get_update_proc() const
363
{
364
    CYG_REPORT_FUNCNAME("CdlDialog::get_update_proc");
365
    CYG_REPORT_FUNCARG1XV(this);
366
    CYG_PRECONDITION_THISC();
367
 
368
    static cdl_tcl_code null_result = "";
369
    cdl_tcl_code& result = null_result;
370
    CdlProperty prop = get_property(CdlPropertyId_UpdateProc);
371
    if (0 != prop) {
372
        CdlProperty_TclCode tclprop = dynamic_cast<CdlProperty_TclCode>(prop);
373
        CYG_ASSERT_CLASSC(tclprop);
374
        result = tclprop->get_code();
375
    }
376
 
377
    CYG_REPORT_RETURN();
378
    return result;
379
}
380
 
381
const cdl_tcl_code&
382
CdlDialogBody::get_display_proc() const
383
{
384
    CYG_REPORT_FUNCNAME("CdlDialog::get_display_proc");
385
    CYG_REPORT_FUNCARG1XV(this);
386
    CYG_PRECONDITION_THISC();
387
 
388
    CdlProperty prop = get_property(CdlPropertyId_DisplayProc);
389
    CYG_ASSERT_CLASSC(prop);
390
    CdlProperty_TclCode tclprop = dynamic_cast<CdlProperty_TclCode>(prop);
391
    CYG_ASSERT_CLASSC(tclprop);
392
 
393
    const cdl_tcl_code& result = tclprop->get_code();
394
 
395
    CYG_REPORT_RETURN();
396
    return result;
397
}
398
 
399
const cdl_tcl_code&
400
CdlDialogBody::get_confirm_proc() const
401
{
402
    CYG_REPORT_FUNCNAME("CdlDialog::get_display_proc");
403
    CYG_REPORT_FUNCARG1XV(this);
404
    CYG_PRECONDITION_THISC();
405
 
406
    CdlProperty prop = get_property(CdlPropertyId_ConfirmProc);
407
    CYG_ASSERT_CLASSC(prop);
408
    CdlProperty_TclCode tclprop = dynamic_cast<CdlProperty_TclCode>(prop);
409
    CYG_ASSERT_CLASSC(tclprop);
410
 
411
    const cdl_tcl_code& result = tclprop->get_code();
412
 
413
    CYG_REPORT_RETURN();
414
    return result;
415
}
416
 
417
const cdl_tcl_code&
418
CdlDialogBody::get_cancel_proc() const
419
{
420
    CYG_REPORT_FUNCNAME("CdlDialog::get_display_proc");
421
    CYG_REPORT_FUNCARG1XV(this);
422
    CYG_PRECONDITION_THISC();
423
 
424
    CdlProperty prop = get_property(CdlPropertyId_CancelProc);
425
    CYG_ASSERT_CLASSC(prop);
426
    CdlProperty_TclCode tclprop = dynamic_cast<CdlProperty_TclCode>(prop);
427
    CYG_ASSERT_CLASSC(tclprop);
428
 
429
    const cdl_tcl_code& result = tclprop->get_code();
430
 
431
    CYG_REPORT_RETURN();
432
    return result;
433
}
434
 
435
//}}}
436
//{{{  check_this()                     
437
 
438
// ----------------------------------------------------------------------------
439
// check_this(). There is very little data associated with a dialog itself.
440
// most of the checks happen in the base class.
441
 
442
bool
443
CdlDialogBody::check_this(cyg_assert_class_zeal zeal) const
444
{
445
    if (CdlDialogBody_Magic != cdldialogbody_cookie) {
446
        return false;
447
    }
448
    CYGDBG_MEMLEAK_CHECKTHIS();
449
    return CdlUserVisibleBody::check_this(zeal);
450
}
451
 
452
//}}}
453
//{{{  misc                             
454
 
455
// ----------------------------------------------------------------------------
456
std::string
457
CdlDialogBody::get_class_name() const
458
{
459
    CYG_REPORT_FUNCNAME("CdlDialog::get_class_name");
460
    CYG_PRECONDITION_THISC();
461
    CYG_REPORT_RETURN();
462
    return "dialog";
463
}
464
 
465
//}}}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.