summaryrefslogtreecommitdiff
path: root/tvision/examples/demo/mousedlg.cc
blob: 93e1a8370fc57ac6b8dce9d25a672207b8b1d28f (plain)
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
/*---------------------------------------------------------*/
/*                                                         */
/*   Mousedlg.cpp : Member functions of following classes: */
/*                     TClickTester                        */
/*                     TMouseDialog                        */
/*                                                         */
/*---------------------------------------------------------*/
/*
 *      Turbo Vision - Version 2.0
 *
 *      Copyright (c) 1994 by Borland International
 *      All Rights Reserved.
 *
 */
/*
 * Modified by Sergio Sigala <ssigala@globalnet.it>
 * Modified to compile with gcc v3.x by Salvador E. Tropea, with the help of
 * Andris Pavenis.
 */
 
// SET: moved the standard headers before tv.h
#define Uses_string
#define Uses_stdlib
#define Uses_ctype

#define Uses_TRect
#define Uses_TStaticText
#define Uses_TEvent
#define Uses_TDrawBuffer
#define Uses_TDialog
#define Uses_TLabel
#define Uses_TScrollBar
#define Uses_TCheckBoxes
#define Uses_TButton
#define Uses_TSItem
#define Uses_TEventQueue
#define Uses_TPalette
#define Uses_iomanip
#include <tv.h>

#include "mousedlg.h"


#define cpMousePalette "\x07\x08"


//
// TClickTester functions
//

TClickTester::TClickTester(TRect& r, char *aText) :
    TStaticText(r, aText)
{
    clicked = 0;
}


TPalette& TClickTester::getPalette() const
{
    static TPalette palette( cpMousePalette, sizeof(cpMousePalette)-1 );
    return palette;
}


void TClickTester::handleEvent(TEvent& event)
{
    TStaticText::handleEvent(event);

    if (event.what == evMouseDown)
        {
        //if (event.mouse.eventFlags & meDoubleClick) SET:
        if (event.mouse.doubleClick)
            {
            clicked = (short)((clicked) ? 0 : 1);
            drawView();
            }
        clearEvent(event);
        }
}


void TClickTester::draw()
{
    TDrawBuffer buf;
    char c;

    if (clicked)
        c = getColor(2);
    else
        c = getColor(1);

    buf.moveChar(0, ' ', c, (short)size.x);
    buf.moveStr(0, text, c);
    writeLine(0, 0, (short)size.x, 1, buf);
}


//
// TMouseDialog functions
//

TMouseDialog::TMouseDialog() :
    TWindowInit( &TMouseDialog::initFrame )
    , TDialog( TRect(0, 0, 34, 12), "Mouse options" )
{
    TRect r(3, 4, 30, 5);

    options |= ofCentered;

    mouseScrollBar = new TScrollBar(r);
    mouseScrollBar->setParams(1, 1, 20, 20, 1);
    mouseScrollBar->options |= ofSelectable;
    mouseScrollBar->setValue(TEventQueue::doubleDelay);
    insert(mouseScrollBar);

    r = TRect(2, 2, 21, 3);
    insert(new TLabel(r, "~M~ouse double click", mouseScrollBar));

    r = TRect(3, 3, 30, 4);
    insert(new TClickTester(r, "Fast       Medium      Slow"));

    r = TRect(3, 6, 30, 7);
    insert(new TCheckBoxes(r, new TSItem("~R~everse mouse buttons", NULL)));
    oldDelay = TEventQueue::doubleDelay;

    r = TRect(9, 9, 19, 11);
    insert(new TButton(r, "O~K~", cmOK, bfDefault));

    r = TRect(21, 9, 31, 11);
    insert(new TButton(r, "Cancel", cmCancel, bfNormal));

    selectNext( (Boolean) 0);
}


void TMouseDialog::handleEvent(TEvent& event)
{
    TDialog::handleEvent(event);
    switch(event.what)
        {
        case evCommand:
            if(event.message.command == cmCancel)
                TEventQueue::doubleDelay = oldDelay;
            break;

        case evBroadcast:
            if(event.message.command == cmScrollBarChanged)
                {
                TEventQueue::doubleDelay = (short)mouseScrollBar->value;
                clearEvent(event);
                }
            break;
        }
}