source: tags/arb-6.0/WINDOW/AW_cb_struct.cxx

Last change on this file was 11493, checked in by westram, 10 years ago
  • fix doxygen issues for WINDOW (see [11492])
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : AW_cb_struct.cxx                                  //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#include "aw_root.hxx"
12#include "aw_window.hxx"
13#include "aw_window_Xm.hxx"
14#include "aw_msg.hxx"
15
16#if defined(DEBUG)
17// #define TRACE_CALLBACKS
18#endif // DEBUG
19
20AW_cb_struct_guard AW_cb::guard_before = NULL;
21AW_cb_struct_guard AW_cb::guard_after  = NULL;
22AW_postcb_cb       AW_cb::postcb       = NULL;
23
24
25AW_cb::AW_cb(AW_window *awi, AW_CB g, AW_CL cd1i, AW_CL cd2i, const char *help_texti, class AW_cb *nexti)
26    : cb(makeWindowCallback(g, cd1i, cd2i))
27{
28    aw         = awi;
29    help_text  = help_texti;
30    this->next = nexti;
31
32    id = NULL;
33}
34
35AW_cb::AW_cb(AW_window *awi, const WindowCallback& wcb, const char *help_texti, class AW_cb *nexti)
36    : cb(wcb)
37{
38    aw         = awi;
39    help_text  = help_texti;
40    this->next = nexti;
41
42    id = NULL;
43}
44
45
46bool AW_cb::contains(AW_CB g) {
47    return (AW_CB(cb.callee()) == g) || (next && next->contains(g));
48}
49
50bool AW_cb::is_equal(const AW_cb& other) const {
51    bool equal = cb == other.cb;
52    if (equal) {
53        if (AW_CB(cb.callee()) == AW_POPUP) {
54            equal = aw->get_root() == other.aw->get_root();
55        }
56        else {
57            equal = aw == other.aw;
58            if (!equal) {
59                equal = aw->get_root() == other.aw->get_root();
60#if defined(DEBUG) && 0
61                if (equal) {
62                    fprintf(stderr,
63                            "callback '%s' instantiated twice with different windows (w1='%s' w2='%s') -- assuming the callbacks are equal\n",
64                            id, aw->get_window_id(), other.aw->get_window_id());
65                }
66#endif // DEBUG
67            }
68        }
69    }
70    return equal;
71}
72
73
74void AW_cb::run_callbacks() {
75    if (next) next->run_callbacks();                // callback the whole list
76
77    AW_CB f = AW_CB(cb.callee());
78    aw_assert(f);
79
80    AW_root *root = aw->get_root();
81    if (root->disable_callbacks) {
82        // some functions (namely aw_message, aw_input, aw_string_selection and aw_file_selection)
83        // have to disable most callbacks, because they are often called from inside these callbacks
84        // (e.g. because some exceptional condition occurred which needs user interaction) and if
85        // callbacks weren't disabled, a recursive deadlock occurs.
86
87        // the following callbacks are allowed even if disable_callbacks is true
88
89        bool isModalCallback = (f == AW_CB(message_cb) ||
90                                f == AW_CB(input_history_cb) ||
91                                f == AW_CB(input_cb)         ||
92                                f == AW_CB(file_selection_cb));
93
94        bool isPopdown = (f == AW_CB(AW_POPDOWN));
95        bool isHelp    = (f == AW_CB(AW_help_popup));
96        bool allow     = isModalCallback || isHelp || isPopdown;
97
98        bool isInfoResizeExpose = false;
99
100        if (!allow) {
101            isInfoResizeExpose = aw->is_expose_callback(AW_INFO_AREA, f) || aw->is_resize_callback(AW_INFO_AREA, f);
102            allow              = isInfoResizeExpose;
103        }
104
105        if (!allow) {
106            // do not change position of modal dialog, when one of the following callbacks happens - just raise it
107            // (other callbacks like pressing a button, will position the modal dialog under mouse)
108            bool onlyRaise =
109                aw->is_expose_callback(AW_MIDDLE_AREA, f) ||
110                aw->is_focus_callback(f) ||
111                root->is_focus_callback((AW_RCB)f) ||
112                aw->is_resize_callback(AW_MIDDLE_AREA, f);
113
114            if (root->current_modal_window) { 
115                AW_window *awmodal = root->current_modal_window;
116
117                AW_PosRecalc prev = awmodal->get_recalc_pos_atShow();
118                if (onlyRaise) awmodal->recalc_pos_atShow(AW_KEEP_POS);
119                awmodal->activate();
120                awmodal->recalc_pos_atShow(prev);
121            }
122            else {
123                aw_message("Internal error (callback suppressed when no modal dialog active)");
124                aw_assert(0);
125            }
126#if defined(TRACE_CALLBACKS)
127            printf("suppressing callback %p\n", f);
128#endif // TRACE_CALLBACKS
129            return; // suppress the callback!
130        }
131#if defined(TRACE_CALLBACKS)
132        else {
133            if (isModalCallback) printf("allowed modal callback %p\n", f);
134            else if (isPopdown) printf("allowed AW_POPDOWN\n");
135            else if (isHelp) printf("allowed AW_help_popup\n");
136            else if (isInfoResizeExpose) printf("allowed expose/resize infoarea\n");
137            else printf("allowed other (unknown) callback %p\n", f);
138        }
139#endif // TRACE_CALLBACKS
140    }
141    else {
142#if defined(TRACE_CALLBACKS)
143        printf("Callbacks are allowed (executing %p)\n", f);
144#endif // TRACE_CALLBACKS
145    }
146
147    useraction_init();
148    cb(aw);
149    useraction_done(aw);
150}
Note: See TracBrowser for help on using the repository browser.