File: application.cc

package info (click to toggle)
vdk2 2.4.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,524 kB
  • ctags: 4,975
  • sloc: cpp: 26,944; sh: 10,580; ansic: 9,220; makefile: 602; perl: 113
file content (208 lines) | stat: -rwxr-xr-x 4,328 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
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
/*
 * ===========================
 * VDK Visual Development Kit
 * Version 0.4
 * October 1998
 * ===========================
 *
 * 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 "vdk/application.h"
#include "vdk/forms.h"
#include "vdk/vdkfeatures.h"
#include <assert.h>
#include <unistd.h>
#include <config.h>

#ifdef VDKDEBUG
extern int objectC,objectD,formC,formD,childRemoved,objRemoved;
 
#endif
//static char buff[128];
/*
at idle callback:
execute garbage collection
*/
int VDKApplication::GcCallback(gpointer app)
{
g_return_val_if_fail(app != NULL , FALSE);
VDKApplication* theApp = reinterpret_cast<VDKApplication*>((VDKApplication*) app);
g_return_val_if_fail(theApp != NULL,FALSE);
if (theApp->MainForm)
  theApp->MainForm->CollectGarbage();
return TRUE;
}

/*
  constructor
  executing:
  <app> -rc <rc file>
  will result in rc file loading
  and parsing
  */
VDKApplication::VDKApplication(int* argc, char** argv, char* rcf,
			       bool have_locale)
{
// load rc file
if(rcf)
  rcfile = rcf;
if( ! rcfile.isNull()  && ! access((char*) rcfile,F_OK) )
  gtk_rc_add_default_file ((char*) rcfile);
if(have_locale)
  {
#ifdef VDKDEBUG
    char* i18n = NULL;
    i18n = gtk_set_locale();
    printf("\nLocale set to: %s",i18n ? i18n : "none");
    fflush(stdout);
#else
    gtk_set_locale();
#endif

  }
gtk_init (argc, &argv);

#ifdef VDKDEBUG
int depth = gdk_visual_get_best_depth();
printf("\nbpp:%d",depth);
fflush(stdout);
#endif
// gdk_rgb_init (); deprecated in GDK 2.0
MainForm = NULL;
idleTag = gcTag = 0;
}
/*
  destructor:
  delete main form that in turn
  deletes all childs and
  all objects
  */
VDKApplication::~VDKApplication()
{
if(MainForm) delete MainForm;
#ifdef VDKDEBUG
printf("\nobjects constructed:%d\nobjects destroyed:%d",objectC,objectD);
printf("\nforms constructed:%d\nforms destroyed:%d",formC,formD);
printf("\nchilds removed:%d\nobjs removed:%d\n\n",
       childRemoved,
       objRemoved);
fflush(stdout);
#endif
}
/*
runs app:
calls:
Setup() thet should be overridden by user
initiates event loop
*/
void
VDKApplication::Run(void)
{
  Setup();
  g_return_if_fail(MainForm != NULL);
  gtk_main();
}
/*
call it before Run()
 */
void
VDKApplication::SetResourceFile(char* rcf)
{
gtk_rc_parse (rcf);
}
/*
set idle call back
*/
void VDKApplication::SetIdleCallback(GtkFunction idlecb, gpointer data)
{
if( (idlecb == NULL) ||
    (data == NULL) )
  {
    if(idleTag)
      gtk_idle_remove(idleTag);
    return;
  }
else if(idleTag)
  gtk_idle_remove(idleTag);
 idleTag = gtk_idle_add(idlecb , data);
}
/*
set garbage collection
*/
void VDKApplication::SetGarbageCollection(unsigned int tick)
{
 gcTag = gtk_timeout_add(tick,(GtkFunction) VDKApplication::GcCallback,
		reinterpret_cast<gpointer>(this));
}
/*
 */
void VDKApplication::RemoveGarbageCollection()
{
if(gcTag)
  gtk_timeout_remove(gcTag);
}
/*
quit application
*/
void
VDKApplication::Terminate(void)
{
MainForm->CloseChilds();
gtk_main_quit ();
}

/*
 */
GtkWidget*
VDKApplication::MainWindow()
{
  return MainForm->Window();
}

/*
  new version in msgdialog.cc
 */
/*
gint
VDKApplication::MessageBox(char* caption,
 			   char* text,
	 		   int mode,
 			   char *oktext,
	 		   char *canceltext,
			   unsigned int wait)
{
  int answer;
  if(MainForm)
    {
      MessageBoxWindow* dialog =
	new MessageBoxWindow(MainForm,
			     caption,
			     text,
			     mode,
			     oktext,
			     canceltext,
			     &answer,
			     wait);
      dialog->Setup();
      dialog->ShowModal(GTK_WIN_POS_CENTER);
    }
  return answer;
}
*/