summaryrefslogtreecommitdiff
path: root/dldialog/src/DLD_TV/dld_tvapp.cc
blob: 75a5e86c2efc34457cecb263c2a1562b79c6f1e8 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/******************************************************************************
**
** $Id: dld_tvapp.cc,v 1.6 1999/01/20 14:40:29 saturn Exp $
**
**	This program is free software; you can redistribute it and/or
**	modify it under the terms of the GNU General Public License
**	as published by the Free Software Foundation; either version
**	2 of the License, or (at your option) any later version.
**
** (C) (C) 1999,2000 Harald Hoyer <DLDialog@parzelle.de> - All rights reserved -
**
******************************************************************************/
#define Uses_TStatusDef
#define Uses_TStatusItem
#define Uses_TStatusLine
#define Uses_TBackground
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TKeys

#include <string.h>
#include <stdio.h>
#include <signal.h>

#include "dld_tvlib.h"
#include "dld_tvapp.h"
#include "dld_dialog.h"

static TStatusItem *statusItem = 0;

#define DLD_cpBackground "\x08"

#define cmDLDQuit 100

class DLD_TVDesktop : public virtual TDeskTop , public virtual TDeskInit 
{
public:
   DLD_TVDesktop( const TRect& bounds );

   static TBackground *initBackground( TRect r );
};

class DLD_TVBackground : public TBackground 
{
public:
   DLD_TVBackground( const TRect& bounds, char aPattern ) :
      TBackground(bounds,aPattern) {
   };

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


TBackground *DLD_TVDesktop::initBackground( TRect r ) 
{
   defaultBkgrnd = '\x20';
   return new DLD_TVBackground( r, defaultBkgrnd);
}

DLD_TVDesktop::DLD_TVDesktop( const TRect& bounds ) :
   TDeskTop(bounds ),
   TDeskInit( &DLD_TVDesktop::initBackground )
{
}


DLD_TVApp::
DLD_TVApp (const string&, int _oldsid, int, char **):
   TProgInit(&DLD_TVApp::initStatusLine, &DLD_TVApp::initMenuBar, 
	     &DLD_TVApp::initDeskTop),
   mainDialog(0),
   running(false),
   oldsid(_oldsid)
{
   /*
    * We don't wanna get stopped
    */
   signal(SIGTSTP, SIG_IGN);
   print_status ("->Starting<-");
}

DLD_TVApp::
~DLD_TVApp ()
{
#ifdef DEBUG
   DLDdbg << "tvapp  ending!" << endl << flush;
#endif
}

DLD_Dialog *DLD_TVApp::
dialog (const string& name, const DLD_Out& _out)
{
   print_status ("->Adding Dialog<-");

   DLD_TVDialog *p =  new DLD_TVDialog (conname(name), this, _out);

   add_child(p);

   if(!mainDialog)
      mainDialog = p;

   return p;
}

int DLD_TVApp::
exec ()
{
   if(!running && mainDialog) {
      print_status ("->Running<-");
      
      running = true;
/*
 * Obsoleted by setsid
 *      menuBar->draw();
 */
      run ();
      running = false;
      
      CI first = childlist.begin();
      CI last  = childlist.end();
      
      while(first != last)
      {
	 delete *first;
	 first = childlist.begin();
	 last  = childlist.end();
      }
      
      print_status ("->Idle<-");   
      mainDialog = 0;
   } 
   else if(!running) {
      DLD_Gui::parse(-1);
   }
     
   return 0;
}

void DLD_TVApp::
idle () 
{
   // DLD_Gui::idle for further parsing input, if any
//   if(running)
   if(!DLD_Gui::parse(100000)) {
      /* Now generate QUIT event */	    
      TEvent te;
      te.what = evCommand;
      te.message.command = cmQuit;
      te.message.infoPtr = 0;
      /*
       * needs fix in tvision to remove TProgram:: and call putEvent
       * directly.
       */
      TProgram::putEvent (te);      
   }

   // The native idle function for TApplications
   TApplication::idle();
}

TStatusLine *DLD_TVApp::
initStatusLine (TRect r)
{
   char *stptr = new char[21];

   sprintf (stptr, "%20s", " ->Starting<-");

   r.a.y = r.b.y - 1;

   return new TStatusLine (r,
			   *new TStatusDef (0, 0xFFFF) +
/*			   *new TStatusItem ("~Alt-X~ to Cancel!", 
			   kbAltX, cmDLDQuit) + */
			   *new TStatusItem (_("SPACE selects - TAB to move -"),
			   0, 0) +
			   *(statusItem = new TStatusItem (stptr, 0, 0)) +
			   *new TStatusItem (0, kbF10, cmMenu) +
			   *new TStatusItem (0, kbAltF3, cmClose) +
			   *new TStatusItem (0, kbF5, cmZoom) +
			   *new TStatusItem (0, kbCtrlF5, cmResize)
      );
}



int DLD_TVApp::
print_status (const string& str)
{
   if ((statusItem != 0) && (statusItem->text != 0))
   {
      strncpy (statusItem->text, str.c_str(), 20);
      statusLine->draw ();
   }

   return 0;
}

void DLD_TVApp::
del_child(DLD_TVDialog *dia)
{
   CI first = childlist.begin();
   CI last = childlist.end();
   while (first != last) {
      if (*first == dia) {
	 // Remove it from the list
	 childlist.erase(first);
	 deskTop->remove(*first);

	 if(dia == mainDialog) {
	    /*
	     * First delete all other dialogs.
	     * This will get us here, but we already removed the mainDialog.
	     */
	    CI first = childlist.begin();
	    CI last  = childlist.end();	    
	    while(first != last)
	    {
	       delete *first;
	       first = childlist.begin();
	       last  = childlist.end();
	    }

	    /* Now generate QUIT event */	    
	    TEvent te;
	    te.what = evCommand;
	    te.message.command = cmQuit;
	    te.message.infoPtr = 0;
	    /*
	     * needs fix in tvision to remove TProgram:: and call putEvent
	     * directly.
	     */
	    TProgram::putEvent (te);
	 }       
	 break;
      }
      first++;
   }
}

int DLD_TVApp::
add_child (DLD_TVDialog * nobj)
{
   Assert(Bad_arg, nobj);

   childlist.push_back(nobj);

   return 0;
}

void DLD_TVApp::
handleEvent( TEvent& event )
{
   TApplication::handleEvent( event );
   if (event.what == evCommand)
   {
      switch (event.message.command)
      {	 
      case cmTile:             //  Tile current file windows
	 deskTop->tile(deskTop->getExtent());
	 break;
	 
      case cmCascade:          //  Cascade current file windows
	 deskTop->cascade(deskTop->getExtent());
	 break;
	 
      case cmDLDQuit:
	 delete mainDialog;
	 break;

      default:                    //  Unknown command
	 return;
	 
      }
      clearEvent (event);
   }
}   


TMenuBar * DLD_TVApp::initMenuBar(TRect r)
{
/*    TSubMenu& sub2 =
      *new TSubMenu( "~F~ile", 0, hcFile ) +
        *new TMenuItem( "E~x~it", cmQuit, kbAltX, hcFExit, "Alt-X" );
*/
    TSubMenu& sub3 =
      *new TSubMenu( "~W~indows", 0, hcWindows ) +
        *new TMenuItem( "~R~esize/move", cmResize, kbCtrlF5, hcWSizeMove, "Ctrl-F5" ) +
        *new TMenuItem( "~Z~oom", cmZoom, kbF5, hcWZoom, "F5" ) +
        *new TMenuItem( "~N~ext", cmNext, kbF6, hcWNext, "F6" ) +
        *new TMenuItem( "~C~lose", cmClose, kbAltF3, hcWClose, "Alt-F3" ) +
        *new TMenuItem( "~T~ile", cmTile, kbNoKey, hcWTile ) +
        *new TMenuItem( "C~a~scade", cmCascade, kbNoKey, hcWCascade );

    r.b.y =  r.a.y + 1;
    return (new TMenuBar( r, sub3) );
//    return (new TMenuBar( r, sub2 + sub3) );
}

TDeskTop *DLD_TVApp::initDeskTop( TRect r )
{
    r.a.y++;
    r.b.y--;
    return new DLD_TVDesktop( r );
/*    TDeskTop::defaultBkgrnd = '\x20';
    return new TDeskTop( r );
*/
}