Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[7339b1]: sys_X11.c Maximize Restore History

Download this file

sys_X11.c    525 lines (403 with data), 11.7 kB

  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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/* Panorama_Tools - Generate, Edit and Convert Panoramic Images
Copyright (C) 1998,1999 - Helmut Dersch der@fh-furtwangen.de
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, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this software; see the file COPYING. If not, a copy
can be downloaded from http://www.gnu.org/licenses/gpl.html, or
obtained by writing to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/*------------------------------------------------------------*/
#include "sys_x11.h"
#include <unistd.h>
int ptools_isOK;
//---------------- Callback functions
void pt_widget_destroy( GtkWidget *widget )
{
ptools_isOK = FALSE;
gtk_widget_destroy( widget );
}
void pt_main_destroy (GtkWidget *widget)
{
ptools_isOK = FALSE;
gtk_main_quit();
}
void pt_set_size_source(GtkWidget *widget, gpointer data)
{
GtkWidget **dp;
char text[32];
dp = (GtkWidget**) data;
sprintf( text, "%ld", gTrPtr->src->width );
gtk_entry_set_text( GTK_ENTRY(dp[kSetPerspectivePrefs_Width]), text );
sprintf( text, "%ld", gTrPtr->src->height );
gtk_entry_set_text( GTK_ENTRY(dp[kSetPerspectivePrefs_Height]), text );
}
void filter_main( TrformStr *TrPtr, struct size_Prefs *spref)
{
dispatch ( TrPtr, spref);
}
// Error reporting
void PrintErrorIntern( char* fmt, va_list ap)
{
char message[255];
vsprintf(message, fmt, ap);
gimp_message (message);
}
// Progress report; return false if canceled
int ProgressIntern( int command, char* argument )
{
double percentage;
switch( command )
{
case _initProgress:
gimp_progress_init( argument );
return TRUE;
break;
case _setProgress:
sscanf(argument,"%lf", &percentage);
gimp_progress_update ((gdouble) percentage/100.0);
return TRUE;
break;
case _disposeProgress:
percentage = 1.0;
gimp_progress_update ((gdouble) percentage);
return TRUE;
break;
case _idleProgress:
return TRUE;
}
return TRUE;
}
int infoDlgIntern ( int command, char* argument ) // Display info: same argumenmts as progress
{
if( command != _setProgress)
return Progress( command, argument );
else
return Progress( command, "0.5" );
}
int readPrefs( char* pref, int selector )
{
struct {
char v[sizeof(PREF_VERSION)];
struct correct_Prefs c;
struct remap_Prefs r;
struct perspective_Prefs p;
struct adjust_Prefs a;
struct interp_Prefs i;
struct size_Prefs s;
panControls pc;
} prf;
char *home_dir;
char prefname[512];
long size;
FILE *prfile;
int result = 0;
home_dir = getenv ("HOME");
if (!home_dir)
return -1;
sprintf (prefname, "%s/.gimp/pano13.prf", home_dir);
if( (prfile = fopen( prefname, "rb" )) != NULL )
{
size = fread( &prf, 1, sizeof(prf), prfile);
fclose( prfile );
if( size != sizeof(prf) )
{
result = -1;
}
else
{
switch( selector)
{
case _version:
memcpy( pref, &prf.v, sizeof( PREF_VERSION ) );
break;
case _correct:
if( prf.c.magic != 20 )
result = -1;
else
memcpy( pref, &prf.c, sizeof(struct correct_Prefs));
break;
case _remap:
if( prf.r.magic != 30 )
result = -1;
else
memcpy( pref, &prf.r , sizeof(struct remap_Prefs));
break;
case _perspective:
if( prf.p.magic != 40 )
result = -1;
else
memcpy( pref, &prf.p , sizeof(struct perspective_Prefs));
break;
case _adjust:
if( prf.a.magic != 50 )
result = -1;
else
memcpy( pref, &prf.a , sizeof(struct adjust_Prefs));
break;
case _interpolate:
if( prf.i.magic != 60 )
result = -1;
else
memcpy( pref, &prf.i , sizeof(struct interp_Prefs));
break;
case _sizep:
if( prf.s.magic != 70 )
result = -1;
else
memcpy( pref, &prf.s , sizeof(struct size_Prefs));
break;
case _panright:
case _panleft:
case _panup:
case _pandown:
case _zoomin:
case _zoomout:
case _apply:
case _getPano:
case _increment:
memcpy( pref, &prf.pc , sizeof(panControls));
break;
}// switch
} // sizes match
}
else
result = -1;
return result;
}
void writePrefs( char* prefs, int selector )
{
struct {
char v[sizeof(PREF_VERSION)];
struct correct_Prefs c;
struct remap_Prefs r;
struct perspective_Prefs p;
struct adjust_Prefs a;
struct interp_Prefs i;
struct size_Prefs s;
panControls pc;
} prf;
FILE *prfile;
char *home_dir;
char prefname[512];
home_dir = getenv ("HOME");
if (!home_dir)
return ;
sprintf (prefname, "%s/.gimp/pano13.prf", home_dir);
if( (prfile = fopen( prefname, "rb" )) != NULL )
{
fread( &prf, 1, sizeof(prf), prfile);
fclose( prfile );
}
switch( selector)
{
case _version:
memcpy( &prf.v, prefs, sizeof( PREF_VERSION ) );
break;
case _correct:
memcpy( &prf.c , prefs, sizeof(struct correct_Prefs));
break;
case _remap:
memcpy( &prf.r , prefs, sizeof(struct remap_Prefs));
break;
case _perspective:
memcpy( &prf.p , prefs, sizeof(struct perspective_Prefs));
break;
case _adjust:
memcpy( &prf.a , prefs, sizeof(struct adjust_Prefs));
break;
case _interpolate:
memcpy( &prf.i , prefs, sizeof(struct interp_Prefs));
break;
case _sizep:
memcpy( &prf.s , prefs, sizeof(struct size_Prefs));
break;
case _panright:
case _panleft:
case _panup:
case _pandown:
case _zoomin:
case _zoomout:
case _apply:
case _getPano:
case _increment:
memcpy( &prf.pc , prefs, sizeof(panControls));
break;
}
if( (prfile = fopen( prefname, "wb" )) != NULL )
{
fwrite( &prf, 1, sizeof(prf), prfile);
fclose(prfile);
}
}
void** mymalloc( long numBytes ) // Memory allocation, use Handles
{
char **mem;
mem = (char**)malloc( sizeof(char*) ); // Allocate memory for pointer
if(mem == NULL)
return (void**)NULL;
else
{
(*mem) = (char*) malloc( numBytes ); // Allocate numBytes
if( *mem == NULL )
{
free( mem );
return (void**)NULL;
}
else
return (void**)mem;
}
}
void myfree( void** Hdl ) // free Memory, use Handles
{
free( (char*) *Hdl );
free( (char**) Hdl );
}
void showScript ( fullPath* scriptFile )
{
char cmd[sizeof(fullPath) + 16];
sprintf( cmd, "xedit \"%s\"", scriptFile->name );
system( cmd );
}
void makePathForResult ( fullPath *path )
{
char *home_dir;
home_dir = getenv ("HOME");
if (!home_dir || strlen( home_dir ) > sizeof( fullPath ) - 15 )
home_dir = ".";
sprintf (path->name, "%s/ptool_result", home_dir);
}
void makePathToHost ( fullPath *path )
{
sprintf ( path->name, "gimp");
}
// Fname is appended to host-directory path
void MakeTempName( fullPath *destPath, char *fname )
{
char *home_dir;
home_dir = getenv ("HOME");
if (!home_dir || strlen( home_dir ) > sizeof( fullPath ) - 64 )
home_dir = ".";
sprintf (destPath->name, "%s/.gimp/%s", home_dir,fname);
}
void ptool_save_callback (GtkWidget *widget, gpointer data)
{
GtkWidget *filew;
static wdata wd;
filew = gtk_file_selection_new ("Save corrections as...");
gtk_window_position (GTK_WINDOW (filew), GTK_WIN_POS_MOUSE);
wd.data = data;
wd.widg = filew;
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked", (GtkSignalFunc) pt_save_corr, (gpointer) &wd );
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(filew)->cancel_button),
"clicked", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (GTK_WINDOW (filew)));
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), "Corrections");
gtk_widget_show (filew);
}
void pt_save_corr (GtkWidget *widget, gpointer data)
{
FILE *cf;
cPrefs *c;
char *filename;
c = (cPrefs*) ((wdata*)data)->data;
filename = gtk_file_selection_get_filename ((GtkFileSelection *) ((wdata*)data)->widg );
if (! filename)
return;
if( (cf = fopen( filename, "wb" )) != NULL )
{
fwrite( c, sizeof(cPrefs), 1 , cf);
fclose( cf );
}
gtk_widget_destroy( ((wdata*)data)->widg ) ;
}
void ptool_load_callback (GtkWidget *widget, gpointer data)
{
GtkWidget *filew;
static wdata wd;
filew = gtk_file_selection_new ("Please find corrections file...");
gtk_window_position (GTK_WINDOW (filew), GTK_WIN_POS_MOUSE);
wd.data = data;
wd.widg = filew;
/* Connect the ok_button to file_ok_sel function */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked", (GtkSignalFunc) pt_load_corr, (gpointer) &wd );
/* Connect the cancel_button to destroy the widget */
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(filew)->cancel_button),
"clicked", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (GTK_WINDOW (filew)));
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), "");
gtk_widget_show (filew);
}
void pt_load_corr (GtkWidget *widget, gpointer data)
{
FILE *cf;
cPrefs *c, cP;
char *filename;
long size;
c = (cPrefs*) ((wdata*)data)->data;
filename = gtk_file_selection_get_filename ((GtkFileSelection *) ((wdata*)data)->widg );
if (! filename)
return;
if( (cf = fopen( filename, "rb" )) != NULL )
{
size = fread( &cP, 1, sizeof(cPrefs), cf);
fclose( cf );
if( size == sizeof(cPrefs) )
{
memcpy((char*) c, (char*)&cP, sizeof(struct correct_Prefs));
}
}
gtk_widget_destroy( ((wdata*)data)->widg );
}
// Set file as specified by dialog
// data is *fullPath
void pt_find_file( GtkWidget *widget, gpointer data )
{
GtkWidget *filew;
static wdata wd;
filew = gtk_file_selection_new ("Find/Set file...");
gtk_window_position (GTK_WINDOW (filew), GTK_WIN_POS_MOUSE);
wd.data = data;
wd.widg = filew;
/* Connect the ok_button to file_ok_sel function */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked", (GtkSignalFunc) pt_set_file, (gpointer)&wd );
/* Connect the cancel_button to destroy the widget */
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(filew)->cancel_button),
"clicked", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (GTK_WINDOW (filew)));
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), "");
gtk_widget_show (filew);
}
void pt_set_file (GtkWidget *widget, gpointer data)
{
fullPath *a;
char* filename;
a = (fullPath*) ((wdata*)data)->data;
filename = gtk_file_selection_get_filename ((GtkFileSelection *) ((wdata*)data)->widg );
if (! filename )
return;
if( strlen(filename) > sizeof( fullPath )-1)
{
PrintError("Path too long");
gtk_widget_destroy( ((wdata*)data)->widg );
return;
}
strcpy( a->name, filename );
gtk_widget_destroy( ((wdata*)data)->widg );
}
void ConvFileName( fullPath *fspec,char *string)
{
strcpy( string, fspec->name );
}
//--------------- Unused Functions -------------------------------
int FindFile( fullPath *fspec ) { return 0;};
int SaveFileAs( fullPath *path, char *prompt, char *name ) { return 0;};