summaryrefslogtreecommitdiff
path: root/rhtvision/examples/inplis/inplist.cpp
blob: 2ad5cd5025ea18b119d06f3d65c94ab183748566 (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
156
157
158
159
160
161
162
163
164
165
166
167
/*

  Created by L. Borobia 92-11-30

  File: INPLIST.CPP

  A little example, how to execute an inputline in a
  focused item from a listbox.

*/

#include "stdio.h"
#include "string.h"
#include "inplist.h"

TExecInputLine::TExecInputLine(const TRect& bounds, int aMaxLen)
               :TInputLine(bounds, aMaxLen)
 {
 }

void TExecInputLine::set(void *rec)
 {
   setData(rec);
 }

void TExecInputLine::get(void *rec)
 {
   getData(rec);
 }

ushort TExecInputLine::execute()
 {
  TEvent e;
  Boolean leavemodal = False;
  do
   {
    getEvent(e);
    if (e.what == evKeyDown)
     {
      switch (e.keyDown.keyCode)
        {
          case kbDown:
          case kbUp:
          case kbEsc:
          case kbEnter:
          case kbPgDn:
          case kbPgUp:
          case kbCtrlPgDn:
          case kbCtrlPgUp:
            leavemodal = True;
           break;
          default:
            leavemodal = False;
           break;
       }
    }
    if (e.what == evMouseDown && e.mouse.buttons == mbLeftButton)
     {
      TPoint p = makeLocal(e.mouse.where);
      if (mouseInView(p) == False)
        leavemodal = True;
     }
    handleEvent(e);
   } while (leavemodal == False);
  return e.keyDown.keyCode;
}


TInputBox::TInputBox(const TRect& bounds, ushort aNumCols, TScrollBar *aScrollBar)
          :TListBox(bounds,aNumCols,aScrollBar)

 {
 }

void TInputBox::getText(char *dest, int item, short maxLen)
 {
  ListBoxItem *v;
  char s[MAXVALUELEN+MAXLABELLEN];
  if (list() != 0 )
    {
     v = (ListBoxItem *)(list()->at(item));
     sprintf(s, "%.*s = %.*s", MAXLABELLEN,v->label, MAXVALUELEN, v->value);
     strncpy( dest, s, maxLen );
     dest[maxLen] = '\0';
    }
   else
    *dest = EOS;
 }

ushort TInputBox::inputData( )
 {
  ListBoxItem *v;
  TExecInputLine *te;
  TRect r = getExtent();
  ushort control=0;
  if (list() != 0 )
   {
    v  = (ListBoxItem *)(list()->at(focused));
    r  = TRect(strlen(v->label)+5, focused-topItem+1,r.b.x-r.a.x,focused-topItem+2);
    te = new TExecInputLine(r,MAXVALUELEN);
    te->set(v->value);
    control = owner->execView((TView *)te);
    if (control != kbEsc)
       te->get(v->value);
    CLY_destroy((TView *)te);
   }
  return control;
 }


void TInputBox::handleEvent(TEvent& event)
 {
  TEvent e = event;
  ushort item;
  TListBox::handleEvent(event);
  item = focused;
  if ( event.what == evKeyDown )
   {
      if (event.keyDown.charScan.charCode >=  32)
       {
        putEvent(event);
        if (inputData() == kbUp)
             item--;
           else
             item++;
        drawView();
        focusItemNum(item);
       }
       else
        if ( event.keyDown.keyCode == kbRight ||
             event.keyDown.keyCode == kbLeft  ||
             event.keyDown.keyCode == kbEnter
            )
         {
          if (inputData() == kbUp)
             item--;
           else
             item++;
          drawView();
          focusItemNum(item);
         }
    }
   else
    if (e.what == evMouseDown &&
         e.mouse.buttons == mbLeftButton)
     {
      inputData();
      drawView();
     }
 }


TInputDialog::TInputDialog(const TRect& r, const char *aTitle, TCollection *aList)
                  : TWindowInit( &TInputDialog::initFrame )
                  , TDialog(r, aTitle)
                   
 {
   options   |= ofCentered;
   TRect r1   = getExtent();
   r1.grow(-1,-1);
   vScrollBar = new TScrollBar(TRect(r1.b.x-1,r1.a.y,r1.b.x,r1.b.y));
   inputBox   = new TInputBox(r1,1,vScrollBar);
   inputBox->newList(aList);
   insert(inputBox);
   insert(vScrollBar);
 }