source: tags/ms_r16q3/AWT/AWT_modules.cxx

Last change on this file was 14451, checked in by westram, 8 years ago
  • use typed callbacks (partial binding)
    • move untyped code into namespace UNTYPED
    • added template wrappers (doing the type checks)
    • added template-helper-struct disallow_type
  • revealed wrong enum-types used in awt_create_collect_buttons
File size: 3.4 KB
Line 
1// ============================================================= //
2//                                                               //
3//   File      : AWT_modules.cxx                                 //
4//   Purpose   :                                                 //
5//                                                               //
6//   Coded by Ralf Westram (coder@reallysoft.de) in April 2012   //
7//   Institute of Microbiology (Technical University Munich)     //
8//   http://www.arb-home.de/                                     //
9//                                                               //
10// ============================================================= //
11
12#include "awt_modules.hxx"
13#include <aw_window.hxx>
14
15#define awt_assert(cond) arb_assert(cond)
16
17void UNTYPED::awt_create_order_buttons(AW_window *aws, awt_orderfun reorder_cb, AW_CL cl) {
18    // generates order buttons at current pos and binds them to 'reorder_cb'
19    // 'cl' is forwarded to reorder_cb
20
21    SmartPtr<AW_at_storage> auto_at(AW_at_storage::make(aws, AW_AT_AUTO));
22
23    aws->auto_space(1, 1);
24    aws->at_newline();
25
26    int x, y; aws->get_at_position(&x, &y);
27
28    aws->callback(makeWindowCallback(reorder_cb, ARM_TOP, cl)); aws->create_button("moveTop", "#moveTop.xpm", 0);
29
30    aws->at_newline();
31    int yoff = aws->get_at_yposition()-y;
32    awt_assert(yoff>0);
33
34    aws->at(x, y+1*yoff); aws->callback(makeWindowCallback(reorder_cb, ARM_UP,     cl)); aws->create_button("moveUp",     "#moveUp.xpm",     0);
35    aws->at(x, y+2*yoff); aws->callback(makeWindowCallback(reorder_cb, ARM_DOWN,   cl)); aws->create_button("moveDown",   "#moveDown.xpm",   0);
36    aws->at(x, y+3*yoff); aws->callback(makeWindowCallback(reorder_cb, ARM_BOTTOM, cl)); aws->create_button("moveBottom", "#moveBottom.xpm", 0);
37
38    aws->restore_at_from(*auto_at);
39}
40
41inline const char *bitmap_name(bool rightwards, bool all) {
42    if (all) return rightwards ? "#moveAllRight.xpm" : "#moveAllLeft.xpm"; // uses_pix_res("moveAllRight.xpm", "moveAllLeft.xpm");
43    return rightwards ? "#moveRight.xpm" : "#moveLeft.xpm";                // uses_pix_res("moveRight.xpm", "moveLeft.xpm"); see ../SOURCE_TOOLS/check_resources.pl@uses_pix_res
44}
45
46void UNTYPED::awt_create_collect_buttons(AW_window *aws, bool collect_rightwards, awt_collectfun collect_cb, AW_CL cl) {
47    // generates collect buttons at current pos and binds them to 'collect_cb'
48    // 'cl' is forwarded to 'collect_cb'
49    // 'collect_rightwards' affects the direction of the buttons
50
51    SmartPtr<AW_at_storage> auto_at(AW_at_storage::make(aws, AW_AT_AUTO));
52
53    aws->auto_space(1, 1);
54    aws->button_length(0);
55    aws->at_newline();
56
57    int x, y; aws->get_at_position(&x, &y);
58
59    bool       collect = collect_rightwards;
60    const bool all     = true;
61
62    aws->callback(makeWindowCallback(collect_cb, ACM_FILL, cl)); aws->create_button("ADDALL", bitmap_name(collect, all), 0);
63
64    aws->at_newline();
65    int yoff = aws->get_at_yposition()-y;
66    awt_assert(yoff>0);
67
68    aws->at(x, y+1*yoff); aws->callback(makeWindowCallback(collect_cb, ACM_ADD,    cl)); aws->create_button("ADD",    bitmap_name(collect,  !all), 0);
69    aws->at(x, y+2*yoff); aws->callback(makeWindowCallback(collect_cb, ACM_REMOVE, cl)); aws->create_button("REMOVE", bitmap_name(!collect, !all), 0);
70    aws->at(x, y+3*yoff); aws->callback(makeWindowCallback(collect_cb, ACM_EMPTY,  cl)); aws->create_button("CLEAR",  bitmap_name(!collect, all),  0);
71
72    aws->restore_at_from(*auto_at);
73}
Note: See TracBrowser for help on using the repository browser.