File: progcompo.cc

package info (click to toggle)
vdk2 2.4.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,520 kB
  • ctags: 4,975
  • sloc: cpp: 26,947; sh: 10,677; ansic: 9,220; makefile: 601; perl: 113
file content (105 lines) | stat: -rw-r--r-- 2,892 bytes parent folder | download | duplicates (8)
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
/*
 * ===========================
 * VDK Visual Develeopment Kit
 * Version 2.0.0
 * february 2001
 * ===========================
 *
 * Copyright (C) 1998, Mario Motta
 * Developed by Mario Motta <mmotta@guest.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
#include "progcompo.h"
/*
 */
DEFINE_SIGNAL_MAP(ProgressComponent,VDKBox)
  ON_SIGNAL(timer,timer_tick_signal,OnTimer),
  ON_SIGNAL(start,clicked_signal,Start),
  ON_SIGNAL(stop,clicked_signal,Stop),
  ON_SIGNAL(stop,realize_signal,OnRealize),
  ON_SIGNAL(start,realize_signal,OnRealize)
END_SIGNAL_MAP
  
const int maxTime = 20;    
static int timeElapsed = 0;
static char buff[64];
/*
 */
void
ProgressComponent::Setup()
{
  timer = new VDKTimer(Owner(),1000,false);
  timer->Parent(this);
  VDKBox* vbox = new VDKBox(Owner(),v_box);
  vbox->Add( bar = new VDKProgressBar(Owner(),0,20)); 
  bar->BarStyle = GTK_PROGRESS_DISCRETE;
  bar->BlockCount = 20;
  bar->NormalBackground = clWhite;
  bar->PrelightBackground = VDKRgb("dodger blue");
  vbox->Add( label = new VDKLabel(Owner(),""));
  vbox->Add(new VDKSeparator(Owner()));
  Add(vbox,l_justify,false,false);  
  VDKBox* hbox = new VDKBox(Owner(),h_box);
  hbox->Add(start = new VDKCustomButton(Owner(),"Start"));
  hbox->Add(stop  = new VDKCustomButton(Owner(),"Stop"));
  start->Parent(this);
  stop->Parent(this);
  Add(hbox,l_justify,false,false);
  timeElapsed = 0;
}
/*
 */ 
bool ProgressComponent::OnTimer(VDKObject*)
{
  timeElapsed++;
  bar->Value = double(timeElapsed);
  sprintf(buff,"Time elapsed: %.0f - Remaining:%.0f",bar->Position(),maxTime - bar->Value);
  label->Caption = buff;
  if(timeElapsed >= maxTime)
    {
      timeElapsed = 0;
      timer->Stop();
      bar->Value = 0.0;
    }
  return true;
}  
 
/*
 */
bool ProgressComponent::Start(VDKObject*)
{
  sprintf(buff,"Time elapsed: %.0f - Remaining:%.0f", bar->Position(), maxTime - bar->Value);
  label->Caption = buff;
  timer->Start();
  return true;
}
/*
 */ 
bool ProgressComponent::Stop(VDKObject*)
{
  timer->Stop();
  return true;
}  
/*
 */
bool ProgressComponent::OnRealize(VDKObject* sender) 
{
  printf("\nOnRealize");
  fflush(stdout);
  sender->Cursor = curHandPtr;
  return true;
}