File: hello2.cc

package info (click to toggle)
vdk2 2.4.0-5.6
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 6,448 kB
  • sloc: cpp: 26,950; sh: 10,942; ansic: 9,220; makefile: 605; perl: 113
file content (179 lines) | stat: -rw-r--r-- 4,337 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
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
               
#include <vdk/vdk.h>
#include "kill.xpm"
extern char * folder_xpm[];
///////////////////////////////////////////
void ExternClicked(GtkWidget*, gpointer gp)
    {
      VDKObject* sender = (VDKObject*) gp;
      printf("\nExternClicked(%p)",sender);
      fflush(stdout);
    }
/////////////////////////////////////
class MyButton: public VDKCustomButton
{

public:
  MyButton(VDKForm* owner, char* label, char* tip):
    VDKCustomButton(owner,label) 
    {
      if(tip)
	SetTip(tip);
      printf("\nMyButton::SignalConnect() to slot:%d",
	     SignalConnect("clicked",&MyButton::Clicked));
      fflush(stdout);
    }
  bool Clicked(VDKObject* sender)
    {
      printf("\nMyButton::Clicked(%p)",sender); 
      fflush(stdout);
      // jump to parent level 
      return false;
    }
  virtual ~MyButton() {} 
DECLARE_SIGNAL_LIST(MyButton);
};
DEFINE_SIGNAL_LIST(MyButton,VDKCustomButton);
///////////////////////////////////////////
class MyCanvas: public VDKCanvas
{
public:
  MyCanvas(VDKForm* owner, int w, int h):
    VDKCanvas(owner,w,h) 
    {
      printf("\nMyCanvas::EventConnect() to slot:%d",
	     EventConnect("button_press_event",&MyCanvas::MouseClick));
      fflush(stdout);
    }
  virtual ~MyCanvas() {}
  bool  MouseClick(VDKObject* sender, GdkEvent* event)
    {
      printf("\nMyCanvas::MouseClick() :%p, type:%d",sender,event->type);
      fflush(stdout);
      // jump to parent level
      return false;
    }

DECLARE_EVENT_LIST(MyCanvas);
};

DEFINE_EVENT_LIST(MyCanvas,VDKCanvas);

/////////////////////////////////////
class MyForm: public VDKForm
{ 
protected:
  static void StaticClicked(GtkWidget*, gpointer gp)
    {
      VDKObject* sender = (VDKObject*) gp;
      printf("\nMyForm::StaticClicked(%p)",sender);
      fflush(stdout);
    }
  bool Clicked(VDKObject* sender)
    {
      printf("\nMyForm::Clicked(%p)",sender);
      fflush(stdout);
      return true;
    }
  MyButton* helloButton;
  VDKCustomButton* closeButton;
  VDKLabel* label;
  MyCanvas* canvas;
public: 
 
  MyForm(VDKApplication* app, gchar* title):
    VDKForm(app,title) {}
  ~MyForm() {}
void Setup() 
{ 
  VDKBox *box = new VDKBox(this);  
  //
  canvas = new MyCanvas(this,200,100);
  canvas->NormalBackground = clIvory;
  box->Add(canvas);
  box->Add(helloButton = new MyButton(
				       this,
				       "Hello",
				       "Says \"hello\""));
  box->Add(closeButton = new VDKCustomButton(this,(const char*) kill_xpm ,"DISMISS"));
  closeButton->SetTip("Closes hello application");
  box->Add(label = new VDKLabel(this," "));  

  Add(box); 
  //SetSize(200,100);    
  // signal connecting
  SignalConnect(closeButton,"clicked" ,&MyForm::Quit);
  // 
  printf("\nMyForm::SignalConnect() to slot:%d",
	 SignalConnect(helloButton,"clicked" ,&MyForm::Clicked));
  fflush(stdout);
  //
  SignalConnect(helloButton,"clicked" ,&MyForm::SayHello);
  // connection with static or "C" callbacks unhandled
  gtk_signal_connect(GTK_OBJECT(helloButton->Widget()),
		     "clicked" , 
		     GTK_SIGNAL_FUNC(MyForm::StaticClicked),
		     (gpointer) helloButton);
  gtk_signal_connect(GTK_OBJECT(helloButton->Widget()),
		     "clicked" , 
		     GTK_SIGNAL_FUNC(ExternClicked),
		     (gpointer) helloButton);
  // event connecting
  printf("\nMyForm::EventConnect(button_press) to slot:%d",
	 EventConnect(canvas,"button_press_event",&MyForm::MouseClick));
  fflush(stdout);
}    
       
bool SayHello(VDKObject* sender) 
{ 
  label->Caption="Hello world !";  
  return true;  
}     
 
bool Quit(VDKObject* sender) 
{ 
  Close();     
  return true;    
} 

bool MouseClick(VDKObject* sender, GdkEvent* event)
{
printf("\nMyForm::MouseClick():%p,type:%d",sender,event->type);
fflush(stdout);
return true;
} 
DECLARE_SIGNAL_LIST(MyForm);
DECLARE_EVENT_LIST(MyForm);
};    
     
DEFINE_SIGNAL_LIST(MyForm,VDKForm); 
DEFINE_EVENT_LIST(MyForm,VDKForm); 

/////////////////////////////////// 
class MyApp: public VDKApplication   
{     
           
public:  
  MyApp(int* argc, char** argv): VDKApplication(argc,argv) {}
  ~MyApp() {}  
  void Setup()  
  { 
    MainForm = new MyForm(this,"Hello world 2");
    MainForm->Setup();
    MainForm->Show(); 
  }
};   

/////////////////////////////////
int main (int argc, char *argv[])    
{
  MyApp app(&argc, argv); 
  app.Run();      
  return 0;  
}