viewmol-2.4.1/ 0040755 0002727 0002727 00000000000 10145666545 011362 5 ustar jrh jrh viewmol-2.4.1/source/ 0040755 0002727 0002727 00000000000 10145666463 012661 5 ustar jrh jrh viewmol-2.4.1/source/Makefile 0100644 0002727 0002727 00000032023 10114362246 014302 0 ustar jrh jrh #*******************************************************************************
# *
# Viewmol *
# *
# M A K E F I L E *
# *
# Copyright (c) Joerg-R. Hill, October 2003 *
# *
#*******************************************************************************
#
# $Id: Makefile,v 1.6 2003/11/07 12:53:50 jrh Exp $
# $Log: Makefile,v $
# Revision 1.6 2003/11/07 12:53:50 jrh
# Release 2.4
#
# Revision 1.5 2000/12/10 15:36:51 jrh
# Release 2.3
#
# Revision 1.4 1999/05/24 01:24:15 jrh
# Release 2.2.1
#
# Revision 1.3 1999/02/07 21:42:47 jrh
# Release 2.2
#
# Revision 1.1 1996/12/10 18:39:05 jrh
# Initial revision
#
# Do not edit this file - to set machine specific options edit getmachine!
#
BAGGER =
CC = $(COMPILER) -c $(CFLAGS) -I$(INCLUDE) $(OPT) $(BAGGER)
CCNOP = $(COMPILER) -c $(CFLAGS) -I$(INCLUDE) $(BAGGER)
OBJ = annotate.o atommodule.o balanceform.o basisform.o bondform.o \
bondorder.o build.o calcmo.o cellform.o coledit.o confform.o \
cylinder.o device.o distort.o draw.o drawel.o drawform.o drawop.o \
drawsp.o elementmodule.o ellipse.o energylevelmodule.o feedback.o \
fileselect.o getmem.o getrc.o hardcopy.o historymodule.o hpgl.o \
inert.o infoform.o init.o input.o insint.o intern.o labelmodule.o \
lightmodule.o makemenu.o maketics.o manual.o marcub.o matrix.o \
messgb.o miller.o mkconn.o mkunitc.o mo.o modifygeo.o moform.o \
moleculemodule.o mouseaction.o mousecb.o normod.o optiform.o \
osname.o postscript.o printform.o pseform.o quaternion.o ray.o \
raytrace.o readgrid.o redraw.o resource.o runprog.o runscript.o \
save.o saveform.o shadow.o specform.o spectrummodule.o TabBook.o \
thermo.o thermoform.o viewmol.o viewmolmodule.o waveform.o \
window.o xfont.o zoom.o $(SCANDIR)
ALLOBJ = $(OBJ) tm.o bio.o readgamess.o readgauss.o readmopac.o readpdb.o \
readframe.o eof.o scandir.o
all : viewmol tm bio readgamess readgauss readmopac readpdb translations;
annotate.o : ../annotate.c ../viewmol.h ; $(CC) ../annotate.c
atommodule.o : ../atommodule.c ../viewmol.h ../modules.h ; $(CC) ../atommodule.c
balanceform.o : ../balanceform.c ../viewmol.h ; $(CC) ../balanceform.c
basisform.o : ../basisform.c ../viewmol.h ; $(CC) ../basisform.c
bio.o : ../bio.c ; $(CCNOP) ../bio.c
bondform.o : ../bondform.c ../viewmol.h ; $(CC) ../bondform.c
bondorder.o : ../bondorder.c ../viewmol.h ; $(CC) ../bondorder.c
build.o : ../build.c ../viewmol.h ../isotopes.h ; $(CC) ../build.c
calcmo.o : ../calcmo.c ../viewmol.h ; $(CC) ../calcmo.c
cellform.o : ../cellform.c ../viewmol.h ../dialog.h ; $(CC) ../cellform.c
coledit.o : ../coledit.c ../viewmol.h ../dialog.h ; $(CC) ../coledit.c
confform.o : ../confform.c ../viewmol.h ../dialog.h ; $(CC) ../confform.c
cylinder.o : ../cylinder.c ; $(CC) ../cylinder.c
device.o : ../device.c ; $(CC) ../device.c
distort.o : ../distort.c ../viewmol.h ; $(CC) ../distort.c
draw.o : ../draw.c ../viewmol.h ; $(CC) ../draw.c
drawel.o : ../drawel.c ../viewmol.h ; $(CC) ../drawel.c
drawform.o : ../drawform.c ../viewmol.h ; $(CC) ../drawform.c
drawop.o : ../drawop.c ../viewmol.h ; $(CC) ../drawop.c
drawsp.o : ../drawsp.c ../viewmol.h ; $(CC) ../drawsp.c
elementmodule.o : ../elementmodule.c ../viewmol.h ../modules.h ; $(CC) ../elementmodule.c
ellipse.o : ../ellipse.c ; $(CC) ../ellipse.c
energylevelmodule.o : ../energylevelmodule.c ../viewmol.h ../modules.h ; $(CC) ../energylevelmodule.c
eof.o : ../eof.c ; $(CC) ../eof.c
feedback.o : ../feedback.c ../viewmol.h ; $(CC) ../feedback.c
fileselect.o : ../fileselect.c ; $(CC) ../fileselect.c
getmem.o : ../getmem.c ; $(CC) ../getmem.c
getrc.o : ../getrc.c ../viewmol.h ../isotopes.h ; $(CC) ../getrc.c
hardcopy.o : ../hardcopy.c ; $(CC) ../hardcopy.c
historymodule.o : ../historymodule.c ../viewmol.h ../modules.h ; $(CC) ../historymodule.c
hpgl.o : ../hpgl.c ; $(CC) ../hpgl.c
inert.o : ../inert.c ../viewmol.h ; $(CC) ../inert.c
infoform.o : ../infoform.c ../dialog.h ; $(CC) ../infoform.c
init.o : ../init.c ../viewmol.h ../menudef.h ; $(CC) -DINIT ../init.c
input.o : ../input.c ../viewmol.h ; $(CC) ../input.c
insint.o : ../insint.c ../viewmol.h ; $(CC) ../insint.c
intern.o : ../intern.c ../viewmol.h ; $(CC) ../intern.c
labelmodule.o : ../labelmodule.c ../viewmol.h ../modules.h ; $(CC) ../labelmodule.c
lightmodule.o : ../lightmodule.c ../viewmol.h ../modules.h ; $(CC) ../lightmodule.c
makemenu.o : ../makemenu.c ; $(CC) ../makemenu.c
maketics.o : ../maketics.c ; $(CC) ../maketics.c
manual.o : ../manual.c ../viewmol.h ; $(CC) ../manual.c
marcub.o : ../marcub.c ../marcub.h ; $(CC) ../marcub.c
matrix.o : ../matrix.c ; $(CC) ../matrix.c
messgb.o : ../messgb.c ../messgb.h ; $(CC) ../messgb.c
miller.o : ../miller.c ../viewmol.h ; $(CC) ../miller.c
mkconn.o : ../mkconn.c ../viewmol.h ; $(CC) ../mkconn.c
mkunitc.o : ../mkunitc.c ../viewmol.h ; $(CC) ../mkunitc.c
mo.o : ../mo.c ../viewmol.h ; $(CC) ../mo.c
modifygeo.o : ../modifygeo.c ../viewmol.h ; $(CC) ../modifygeo.c
moform.o : ../moform.c ../viewmol.h ; $(CC) ../moform.c
moleculemodule.o : ../moleculemodule.c ../viewmol.h ../modules.h ; $(CC) ../moleculemodule.c
mouseaction.o : ../mouseaction.c ../viewmol.h ; $(CC) ../mouseaction.c
mousecb.o : ../mousecb.c ../viewmol.h ; $(CC) ../mousecb.c
normod.o : ../normod.c ../viewmol.h ; $(CC) ../normod.c
optiform.o : ../optiform.c ../viewmol.h ; $(CC) ../optiform.c
osname.o : ../osname.c ; $(CC) ../osname.c
postscript.o : ../postscript.c ../viewmol.h ; $(CC) ../postscript.c
printform.o : ../printform.c ../viewmol.h ../menu.h ; $(CC) ../printform.c
pseform.o : ../pseform.c ../viewmol.h ; $(CC) ../pseform.c
quaternion.o : ../quaternion.c ; $(CC) ../quaternion.c
ray.o : ../ray.c ../viewmol.h ; $(CC) ../ray.c
raytrace.o : ../raytrace.c ../viewmol.h ; $(CC) ../raytrace.c
readframe.o : ../readframe.c ; $(CC) ../readframe.c
readgrid.o : ../readgrid.c ../viewmol.h ; $(CC) ../readgrid.c
readgamess.o : ../readgamess.c ; $(CC) ../readgamess.c
readgauss.o : ../readgauss.c ../isotopes.h ; $(CC) ../readgauss.c
readmopac.o : ../readmopac.c ; $(CC) ../readmopac.c
readpdb.o : ../readpdb.c ; $(CC) ../readpdb.c
redraw.o : ../redraw.c ../viewmol.h ; $(CC) ../redraw.c
resource.o : ../resource.c ; $(CC) ../resource.c
runprog.o : ../runprog.c ; $(CC) ../runprog.c
runscript.o : ../runscript.c ../viewmol.h ../dialog.h ; $(CC) ../runscript.c
save.o : ../save.c ../viewmol.h ; $(CC) ../save.c
saveform.o : ../saveform.c ../viewmol.h ; $(CC) ../saveform.c
scandir.o : ../scandir.c ; $(CC) ../scandir.c
shadow.o : ../shadow.c ../viewmol.h ; $(CC) ../shadow.c
specform.o : ../specform.c ; $(CC) ../specform.c
spectrummodule.o : ../spectrummodule.c ../viewmol.h ../modules.h ; $(CC) ../spectrummodule.c
TabBook.o : ../TabBook.c ; $(CC) -DMOTIF ../TabBook.c
thermo.o : ../thermo.c ../viewmol.h ; $(CC) ../thermo.c
thermoform.o : ../thermoform.c ../viewmol.h ; $(CC) ../thermoform.c
tm.o : ../tm.c ; $(CC) ../tm.c
viewmol.o : ../viewmol.c ../viewmol.h ../fallbacks.h ; $(CC) ../viewmol.c
viewmolmodule.o : ../viewmolmodule.c ; $(CC) ../viewmolmodule.c
waveform.o : ../waveform.c ../viewmol.h ; $(CC) ../waveform.c
window.o : ../window.c ../viewmol.h ; $(CC) ../window.c
xdnd.o : ../xdnd.c ../xdnd.h ; $(CC) ../xdnd.c
xfont.o : ../xfont.c ; $(CC) ../xfont.c
zoom.o : ../zoom.c ../viewmol.h ; $(CC) ../zoom.c
viewmol : ; /bin/sh getmachine viewmol
viewmol_: $(OBJ) ; $(COMPILER) -o viewmol $(BAGGER) $(LDFLAGS) $(OBJ) $(LIBRARY) $(LIBS)
tm : ; /bin/sh getmachine tm
tm_ : tm.o readframe.o getmem.o ; $(COMPILER) -o tm $(LDFLAGS) tm.o readframe.o getmem.o -lm
bio : ; /bin/sh getmachine bio
bio_ : bio.o readframe.o getmem.o ; $(COMPILER) -o bio $(LDFLAGS) bio.o readframe.o getmem.o
readgamess: ; /bin/sh getmachine readgamess
readgamess_: readgamess.o eof.o getmem.o ; $(COMPILER) -o readgamess $(LDFLAGS) readgamess.o eof.o getmem.o -lm
readgauss: ; /bin/sh getmachine readgauss
readgauss_: readgauss.o eof.o getmem.o ; $(COMPILER) -o readgauss $(LDFLAGS) readgauss.o eof.o getmem.o
readmopac: ; /bin/sh getmachine readmopac
readmopac_: readmopac.o eof.o getmem.o ; $(COMPILER) -o readmopac $(LDFLAGS) readmopac.o eof.o getmem.o
readpdb: ; /bin/sh getmachine readpdb
readpdb_: readpdb.o eof.o ; $(COMPILER) -o readpdb $(LDFLAGS) readpdb.o eof.o
translations: ; /bin/sh makeTranslations
htmldoc: ; cd ../doc; latex2html -address "Jörg-Rüdiger Hill `date`" -white -no_navigation -html_version "4.0,unicode" -t Viewmol -noinfo viewmol.tex
tar : ; tar -cvf viewmol.tar `echo $(ALLOBJ) | sed "s/\.o/\.c/g"` \
Makefile *.h readgulp readdmol* readmol readpqs writecar writemol \
writetm writegauss.py viewmolrc getmachine checkres README* \
bugs scripts locale makeTranslations `find doc -type f -print | grep -v RCS` ; \
gzip -9 viewmol.tar; mv viewmol.tar.gz viewmol.tgz
distribution: ; tar -cvzf viewmol.tgz `echo $(ALLOBJ) | sed "s/\.o/\.c/g"` \
Makefile *.h readgulp readdmol* readmol readpqs writecar writemol \
writetm writegauss.py viewmolrc getmachine Xdefaults.* \
doc/html doc/viewmol.pdf doc/viewmol.html
snapshot: ; tar -cvf viewmol-`date +'%Y%m%d'`.tar `echo $(ALLOBJ) | sed "s/\.o/\.c/g"` \
Makefile *.h readgulp readdmol readdmol.awk readmol readpqs writecar \
writemol writetm writegauss.py viewmolrc getmachine locale; \
gzip -9 viewmol-`date +'%Y%m%d'`.tar; \
mv viewmol-`date +'%Y%m%d'`.tar.gz viewmol-`date +'%Y%m%d'`.tgz; \
cd web; ./updateWeb
clean : ; /bin/sh getmachine clean
clean_ : ; rm -f $(ALLOBJ) *.il
viewmol-2.4.1/source/TabBook.c 0100644 0002727 0002727 00000104004 07752700021 014327 0 ustar jrh jrh /*******************************************************************************
* *
* Viewmol *
* *
* T A B B O O K . C *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: TabBook.c,v 1.2 2003/11/07 11:20:49 jrh Exp $
* $Log: TabBook.c,v $
* Revision 1.2 2003/11/07 11:20:49 jrh
* Release 2.4
*
* Revision 1.1 2000/12/10 15:40:30 jrh
* Initial revision
*
*/
/*
TabBook.h - TabBook widget (Like Motif Notebook)
See TabBook documentation
Copyright 1996 COMPUTER GENERATION, INC.,
The software is provided "as is", without warranty of any kind, express
or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose and noninfringement.
In no event shall Computer Generation, inc. nor the author be liable for
any claim, damages or other liability, whether in an action of contract,
tort or otherwise, arising from, out of or in connection with the
software or the use or other dealings in the software.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation.
Author:
Gary Aviv
Computer Generation, Inc.,
gary@compgen.com
*/
/*
;+
TabBook.c - TabBook widget (Like Motif Notebook)
MODULE NAME: $RCSfile: TabBook.c,v $
AUTHOR: $Author: jrh $
FUNCTIONS: Boolean XcgTabBookSetActivePage(Widget w, int page, int option );
int XcgTabBookGetActivePage(Widget w );
Widget XcgTabBookGetActivePageWidget(Widget w);
USAGE: See Actual Functions For Description
;-
*/
/* Revision History:
$Log: TabBook.c,v $
Revision 1.2 2003/11/07 11:20:49 jrh
Release 2.4
Revision 1.1 2000/12/10 15:40:30 jrh
Initial revision
Revision 1.3 1997/05/30 12:28:24 gary
Guard against realizing with no children
Revision 1.2 1997/04/25 16:40:04 gary
Chenged default of XcgNanchorChild from XcgANCHOR_NORTHWEST to XcgANCHOR_NORTH
Revision 1.1 1997/04/10 18:16:25 jeff
Initial revision
$log
Guard against realizing with no children
$log
*/
#define VERSION "$Revision: 1.2 $"
#include
#include
#include
#include
#include
#ifdef MOTIF
#include
#include
#include
#include
#else
#include
#include
#endif
/*
#include
#include
#include
*/
#include "TabBookP.h"
/* debugging */
#define TRACE_ON(a) fprintf a
#define TRACE_OFF(a)
#define CheckWidgetClass(routine) \
if (XtClass(w) != xcgTabBookWidgetClass) \
wrong_widget(routine)
/* Private Definitions */
static void ResizeAllManagers( TabBookWidget cw );
static void FrameInsideArea(TabBookWidget cw, Boolean erase);
static void draw_tab_bottom(TabBookWidget cw , Widget child, Boolean active);
static void draw_tab_for_button(TabBookWidget cw , Widget child);
static void create_GC(TabBookWidget cw );
static void InsertChild(Widget w);
static void ExposeMeth(Widget w, XEvent *event, Region region );
static void ClassInitialize(), ClassPartInitialize(), Initialize();
static void Resize(Widget w);
static Boolean ConstraintSetValues(Widget current, Widget request, Widget new,
ArgList args,Cardinal *num_args);
static Boolean SetValues(Widget current, Widget request, Widget new,
ArgList args,Cardinal *num_args);
static XtGeometryResult GeometryManager(Widget w,XtWidgetGeometry *request,
XtWidgetGeometry *reply);
XtGeometryResult TabBookPreferredGeometry(Widget widget,
XtWidgetGeometry *request, XtWidgetGeometry *reply);
static void ChangeManaged(Widget w);
/*static void Realize(Widget w, XtValueMask * valueMask,
XSetWindowAttributes * attributes ); */
static void DoLayout(TabBookWidget cw);
static void unmanage_all_Pages(TabBookWidget cw );
static void activate_cb(Widget w, XtPointer fieldp ,XtPointer cb_data);
static Widget find_nth_button(TabBookWidget cw , int page);
static void wrong_widget(char * routine);
#define offset(field) XtOffsetOf(TabBookRec, field)
static XtResource resources[] =
{
{XcgNautoManage, XcgCAutoManage, XtRBoolean , sizeof(Boolean),
offset(tabBook.auto_manage), XtRImmediate, (XtPointer) True},
{XcgNactivePage, XcgCActivePage, XtRInt , sizeof(int),
offset(tabBook.active_page), XtRImmediate, (XtPointer) 1},
{ XcgNnewPageCallback, XcgCNewPageCallback, XmRCallback,sizeof(XtCallbackList),
offset(tabBook.newPageCallback), XmRCallback, NULL },
};
#undef offset
#define offset(field) XtOffsetOf(TabBookConstraintRec, field)
static XtResource constraint_resources[] =
{
{XcgNresizeChild, XcgCResizeChild, XtRInt , sizeof(int),
offset(tabBook.resize_child), XtRImmediate, (XtPointer) XcgRESIZE_NONE},
{XcgNanchorChild, XcgCAnchorChild, XtRInt , sizeof(int),
offset(tabBook.anchor_child), XtRImmediate, (XtPointer) XcgANCHOR_NORTH},
};
#undef offset
TabBookClassRec tabBookClassRec = {
{ /* core_class fields */
#ifdef MOTIF
/* superclass */ (WidgetClass) &xmBulletinBoardClassRec,
#else
(WidgetClass) &constraintClassRec,
#endif
/* class_name */ "TabBook",
/* widget_size */ sizeof(TabBookRec),
/* class_initialize */ ClassInitialize,
/* class_part_init */ ClassPartInitialize,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize, /* Realize, */
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ (XtResourceList)resources,
/* num_resources */ (Cardinal)XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave*/ TRUE,
/* visible_interest */ FALSE,
/* destroy */ NULL,
/* resize */ Resize,
/* expose */ ExposeMeth,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ NULL,
/* query_geometry */ TabBookPreferredGeometry,
/* display_accelerator*/ XtInheritDisplayAccelerator,
/* extension */ NULL
},
{ /* composite_class fields */
/* geometry_manager */ GeometryManager,
/* change_managed */ ChangeManaged,
/* insert_child */ InsertChild, /* XtInheritInsertChild,*/
/* delete_child */ XtInheritDeleteChild,
/* extension */ NULL
},
{ /* constraint_class fields */
/* subresourses */ (XtResourceList)constraint_resources,
/* subresource_count */ (Cardinal)XtNumber(constraint_resources),
/* constraint_size */ sizeof(TabBookConstraintRec),
/* initialize */ NULL, /*ConstraintInitialize,*/
/* destroy */ NULL,
/* set_values */ ConstraintSetValues,
/* extension */ NULL
},
#ifdef MOTIF
{ /*** xmManager-Class ***/
/* translations */ XtInheritTranslations,
/* syn_resources */ NULL,
/* num_syn_resources */ 0,
/* syn_constraint_resources */ NULL,
/* num_syn_constraint_resources */ 0,
/* parent_process */ XmInheritParentProcess,
/* extension */ NULL
},
{ /* Bulletin Board */
/* always_install_accelerators */ False,
/* geo_matrix_create */ XmInheritGeoMatrixCreate, /*NULL,*/
/* focus_moved_proc */ XmInheritFocusMovedProc,
/* extension */ NULL
},
#endif
{ /* TabBook_class fields */
/* dummy */ 0
}
};
WidgetClass xcgTabBookWidgetClass = (WidgetClass)&tabBookClassRec;
/****************************************************************
*
* Private Procedures
*
****************************************************************/
static void ClassInitialize()
{
}
static void ClassPartInitialize(class)
WidgetClass class;
{
}
/* ARGSUSED */
static void Initialize(Widget request, Widget new, ArgList args, Cardinal num_args)
{
TabBookWidget cw = (TabBookWidget)new;
Pixel select_color ;
cw->tabBook.managed_before = False;
cw->tabBook.old_active_page = 0;
cw->tabBook.total_managers = 0;
cw->tabBook.total_buttons = 0;
cw->tabBook.cur_height = 0;
cw->tabBook.cur_width = 0;
cw->tabBook.layout_completed = False;
cw->tabBook.active_manager = NULL;
cw->tabBook.active_tab = NULL;
cw->tabBook. y_margin = 2; /* reserved margin around each pushbutton ... */
cw->tabBook. x_margin = 2; /* Used to draw Tab around it */
cw->tabBook. x_spacing = 2; /* x space between each button */
cw->tabBook. x_angle = 4; /* space on the right to draw andled line */
cw->tabBook.border = cw->tabBook.x_margin + 2 ; /* border around TabBook inside area */
cw->tabBook.clip = NULL;
/* compute all the colors we will need */
cw->tabBook.drawBackground_color = cw->core.background_pixel;
XmGetColors(XtScreen(cw), cw->core.colormap,
cw->tabBook.drawBackground_color,
&cw->tabBook.drawForeground_color,
&cw->tabBook.top_shadow_color,
&cw->tabBook.bot_shadow_color,
&select_color );
create_GC(cw );
/* create the clip window in which all manager children will be
re-parented */
cw->tabBook.clip = XtVaCreateManagedWidget("TabBookClip",
xmBulletinBoardWidgetClass, new,
XmNmarginHeight,0, XmNmarginWidth,0, NULL);
}
/*
Creates the various graphic contexts we will need
*/
static void create_GC(TabBookWidget cw )
{
XtGCMask valuemask;
XGCValues myXGCV;
valuemask = GCForeground | GCBackground | GCLineWidth | GCFillStyle ;
myXGCV.foreground = cw->tabBook.drawForeground_color;
myXGCV.background = cw->tabBook.drawBackground_color;
myXGCV.fill_style = FillSolid;
myXGCV.line_width = cw->tabBook.x_margin ;
/* | GCJoinStyle ;
myXGCV.join_style = JoinRound; */
if (cw->tabBook.drawForeground_GC )
XtReleaseGC((Widget) cw, cw->tabBook.drawForeground_GC );
cw->tabBook.drawForeground_GC = XtGetGC((Widget)cw, valuemask, &myXGCV);
myXGCV.foreground = cw->tabBook.drawBackground_color;
if (cw->tabBook.drawBackground_GC )
XtReleaseGC((Widget) cw, cw->tabBook.drawBackground_GC );
cw->tabBook.drawBackground_GC = XtGetGC((Widget)cw, valuemask, &myXGCV);
myXGCV.foreground = cw->tabBook.bot_shadow_color;
if (cw->tabBook.bot_shadow_GC )
XtReleaseGC((Widget) cw, cw->tabBook.bot_shadow_GC );
cw->tabBook.bot_shadow_GC = XtGetGC((Widget)cw, valuemask, &myXGCV);
myXGCV.foreground = cw->tabBook.top_shadow_color;
if (cw->tabBook.top_shadow_GC )
XtReleaseGC((Widget) cw, cw->tabBook.top_shadow_GC );
cw->tabBook.top_shadow_GC = XtGetGC((Widget)cw, valuemask, &myXGCV);
}
static void Resize(Widget w)
{
TabBookWidget cw = (TabBookWidget)w;
/* Position x, y;
Dimension width, height; */
Boolean bigger;
TRACE_OFF((stderr,"Resize Old=%dx%d New=%dx%d \n",cw->tabBook.cur_width,cw->tabBook.cur_height,cw->core.width,cw->core.height ));
if (cw->tabBook.cur_height )
FrameInsideArea(cw, True ); /* erase old frame */
if (cw->core.height <= cw->tabBook.cur_height
&& cw->core.width <= cw->tabBook.cur_width )
bigger = False;
else
bigger = True;
cw->tabBook.cur_height = cw->core.height;
cw->tabBook.cur_width = cw->core.width;
/* new frame will be drawn when expose is next called unless it
got smaller */
if (bigger == False)
FrameInsideArea(cw, False); /* redraw new frame */
/* now resize all manager children */
ResizeAllManagers( cw );
}
/*
Resize all managers to fit (or to enlarge out) in the TabBook
inside area
*/
static void ResizeAllManagers( TabBookWidget cw )
{
XmBulletinBoardRec * clip = (XmBulletinBoardRec *) cw->tabBook.clip;
WidgetList widget_list = clip->composite.children;
Cardinal num_children = clip->composite.num_children;
Cardinal n = 0;
Dimension border = 2 * cw->tabBook.border;
Dimension inside_width = cw->tabBook.cur_width - border;
Dimension inside_height = cw->tabBook.cur_height -
cw->tabBook.button_bot - border;
XtResizeWidget(cw->tabBook.clip, inside_width,
inside_height ,
clip->core.border_width) ;
XtMoveWidget(cw->tabBook.clip, cw->tabBook.border ,
cw->tabBook.button_bot + cw->tabBook.border);
#define _TOP 0
#define _BOTTOM (inside_height - child->core.height)
#define _RIGHT (inside_width - child->core.width)
#define _LEFT 0
#define _CENTER_VERT (inside_height - child->core.height)/2
#define _CENTER_HORIZ (inside_width - child->core.width)/2
for (n=0; n < num_children; n++)
{
Widget child = widget_list[n];
if ( XtIsSubclass(child, xmManagerWidgetClass ) )
{
TabBookConstraints cw_c = (TabBookConstraints)
child->core.constraints;
switch (cw_c->tabBook.resize_child)
{
case XcgRESIZE_NONE:
break;
case XcgRESIZE_BOTH:
XtResizeWidget(child, inside_width,inside_height,
child->core.border_width) ;
break;
case XcgRESIZE_HORIZONTAL:
XtResizeWidget(child, inside_width,
child->core.height,
child->core.border_width) ;
break;
case XcgRESIZE_VERTICAL:
XtResizeWidget(child, child->core.width,
inside_height,
child->core.border_width) ;
break;
}
switch (cw_c->tabBook.anchor_child)
{
case XcgANCHOR_CENTER:
XtMoveWidget(child, _CENTER_HORIZ, _CENTER_VERT);
break;
case XcgANCHOR_NORTH:
XtMoveWidget(child, _CENTER_HORIZ, _TOP);
break;
case XcgANCHOR_EAST:
XtMoveWidget(child, _RIGHT, _CENTER_VERT);
break;
case XcgANCHOR_SOUTH:
XtMoveWidget(child, _CENTER_HORIZ, _BOTTOM);
break;
case XcgANCHOR_WEST:
XtMoveWidget(child, _LEFT, _CENTER_VERT);
break;
case XcgANCHOR_NORTHEAST:
XtMoveWidget(child, _RIGHT, _TOP);
break;
case XcgANCHOR_NORTHWEST:
XtMoveWidget(child, _LEFT, _TOP);
break;
case XcgANCHOR_SOUTHEAST:
XtMoveWidget(child, _RIGHT,_BOTTOM);
break;
case XcgANCHOR_SOUTHWEST:
XtMoveWidget(child, _LEFT,_BOTTOM);
break;
}
}
}
}
static XtGeometryResult GeometryManager(Widget w,XtWidgetGeometry *request,
XtWidgetGeometry *reply)
{
TabBookWidget cw = (TabBookWidget) XtParent(w);
TRACE_OFF((stderr,"GeometryManager request=%dx%d\n",
request->width, request->height ));
/* only honor changes in width or height */
if (request->request_mode & ~(CWWidth | CWHeight | XtCWQueryOnly))
return XtGeometryNo;
if (request->request_mode & CWWidth )
reply->width = request->width;
else
reply->width = w->core.width;
if (request->request_mode & CWHeight )
reply->height = request->height;
else
reply->height = w->core.height;
if (reply->height == request->height
&& reply->width == request->width)
return XtGeometryNo;
if (request->request_mode & XtCWQueryOnly)
return XtGeometryYes;
if (XtClass(w) == xmPushButtonWidgetClass )
{
reply->request_mode = CWWidth | CWHeight;
XClearArea(XtDisplay(cw), XtWindow(cw), 0, 0,
cw->tabBook.cur_width, cw->tabBook.button_bot , True);
w->core.width = reply->width;
w->core.height = reply->height;
DoLayout(cw);
}
return(XtGeometryYes);
}
/* ARGSUSED */
static Boolean SetValues(Widget current, Widget request, Widget new,
ArgList args,Cardinal *num_args)
{
TabBookWidget cw_new = (TabBookWidget) new;
TabBookWidget cw_cur = (TabBookWidget) current;
if (cw_new->tabBook.active_page != cw_cur->tabBook.active_page )
{
if (cw_new->tabBook.layout_completed )
{
Widget button = find_nth_button(cw_new, cw_new->tabBook.active_page );
/* emulate user pressing this button */
if (button && XtIsRealized(new))
activate_cb(button, NULL, NULL);
}
}
return FALSE;
}
static Boolean ConstraintSetValues(Widget current, Widget request, Widget new,
ArgList args,Cardinal *num_args)
{
/* TabBookWidget cw_new = (TabBookWidget) new->core.parent ;
TabBookWidget cw_cur = (TabBookWidget) current->core.parent ;
TabBookConstraints cw_c = (TabBookConstraints) new->core.constraints; */
return( FALSE );
}
static void ChangeManaged(Widget w)
{
TabBookWidget cw = (TabBookWidget)w;
TRACE_OFF((stderr,"Change Managed\n"));
DoLayout(cw);
/* first time, unmanage all but active manager */
if (!cw->tabBook.managed_before)
{
if (cw->tabBook.auto_manage )
unmanage_all_Pages(cw); /* Unmanage all pages except active one */
if (cw->tabBook.newPageCallback )
{
XcgTabBookCallbackData rcb_data;
memset(&rcb_data, 0, sizeof(rcb_data));
rcb_data.reason = XcgNewPage; /* reason for callback */
rcb_data.prev_active_page = 0; /* 0 when initially called */
rcb_data.active_page = cw->tabBook.active_page; /* new active page */
XtCallCallbackList((Widget)cw, cw->tabBook.newPageCallback,
(XtPointer) &rcb_data);
}
}
cw->tabBook.managed_before = True;
}
XtGeometryResult TabBookPreferredGeometry(Widget widget,
XtWidgetGeometry *request, XtWidgetGeometry *reply)
{
TabBookWidget cw = (TabBookWidget)widget;
/* Dimension width, height */;
TRACE_OFF((stderr,"Query Geometry\n"));
if (! cw->tabBook.layout_completed)
DoLayout(cw);
request->request_mode &= CWWidth | CWHeight;
reply->request_mode = CWWidth | CWHeight;
reply->width = cw->tabBook.cur_width ;
reply->height = cw->tabBook.cur_height ;
/* called with NULL request */
if (! request->request_mode )
{
if (reply->width != cw->core.width
|| reply->height != cw->core.height)
return XtGeometryNo; /* current and desired size the same */
else
return XtGeometryAlmost; /* this is our desired size */
}
/* called with non-NULL request */
if ( request->width == reply->width &&
request->height == reply->height)
return XtGeometryYes; /* requested change is correct */
if (reply->width != cw->core.width
|| reply->height != cw->core.height)
return XtGeometryNo; /* we want to stay the size we are now */
return XtGeometryAlmost; /* this is our desired size */
}
/*
Layout the children
*/
static void DoLayout(TabBookWidget cw)
{
XmBulletinBoardRec * clip = (XmBulletinBoardRec *) cw->tabBook.clip;
WidgetList widget_list = cw->composite.children;
Cardinal num_children = cw->composite.num_children;
Cardinal n = 0;
XtWidgetGeometry size;
Dimension max_x, max_y, low_button_y ;
XtGeometryResult GResult ;
Dimension width_return, height_return;
int max_button_height = 0;
max_x = max_y = 0;
/* place all the buttons side by side */
for (n=0; n < num_children; n++)
{
Widget child = widget_list[n];
if ( XtClass(child) == xmPushButtonWidgetClass)
{
XtQueryGeometry(child, NULL, &size);
if (max_x) /* all but first button, space from its left neighbor */
max_x += cw->tabBook.x_spacing;
max_x += cw->tabBook.x_margin ;
XtMoveWidget(child, max_x, cw->tabBook.y_margin );
max_x += size.width + cw->tabBook.x_margin + cw->tabBook.x_angle ;
if (max_button_height < size.height)
max_button_height = size.height;
if (max_y < size.height)
max_y = size.height; /* max height */
continue;
}
}
cw->tabBook.button_bot = low_button_y = max_y + cw->tabBook.y_margin ;
low_button_y += cw->tabBook.border; /* allow space for inside border */
/* Set all buttons to the same height, the max height */
for (n=0; n < num_children; n++)
{
Widget child = widget_list[n];
if ( XtClass(child) == xmPushButtonWidgetClass)
{
XtResizeWidget(child, child->core.width,
max_button_height, child->core.border_width) ;
}
}
/* now position all manager ancestors below buttons, all at x=0,
y=low_button_y (plus margin) and expand the TabBook width and
height to accomodate all these managers */
widget_list = clip->composite.children;
num_children = clip->composite.num_children;
for (n=0; n < num_children; n++)
{
Widget child = widget_list[n];
if ( XtIsSubclass(child, xmManagerWidgetClass ) )
{
XtQueryGeometry(child, NULL, &size);
size.height += low_button_y ;
if (max_y < size.height)
max_y = size.height; /* max height */
size.width += cw->tabBook.border;
if (max_x < size.width)
max_x = size.width; /* max width */
}
}
cw->tabBook.cur_width = max_x + cw->tabBook.border ;
cw->tabBook.cur_height = max_y + cw->tabBook.border ; /* space for right border */
cw->tabBook.layout_completed = True;
if (cw->core.height != cw->tabBook.cur_height
|| cw->core.width != cw->tabBook.cur_width)
{
GResult = XtMakeResizeRequest((Widget)cw, cw->tabBook.cur_width, cw->tabBook.cur_height,
&width_return, &height_return);
cw->tabBook.cur_height = cw->core.height;
cw->tabBook.cur_width = cw->core.width;
}
ResizeAllManagers( cw );
}
/*
Use standard method to chain Realize request. Use this opportunity
to position child widgets.
*/
#if 0
static void Realize(Widget w, XtValueMask * valueMask,
XSetWindowAttributes * attributes )
{
/* TabBookWidget new = (TabBookWidget) w; */
TRACE_OFF((stderr,"Realize\n"));
(*(&coreClassRec)->core_class.realize)(w, valueMask, attributes );
}
#endif
/*
Draw (or erase) the shadow around the inside area of the TabBook
*/
static void FrameInsideArea(TabBookWidget cw, Boolean erase)
{
Dimension left_x, top_y, p_width, p_height, thickness;
XPoint points[4];
GC gc1, gc2;
if (!XtIsRealized((Widget)cw))
return;
if (erase)
gc1 = gc2 = cw->tabBook.drawBackground_GC ;
else
{
gc1 = cw->tabBook.top_shadow_GC ;
gc2 = cw->tabBook.bot_shadow_GC ;
}
/* draw shadow around inside area */
thickness = cw->tabBook.x_margin ;
left_x = 0 + thickness/2 ;
top_y = cw->tabBook.button_bot + thickness/2 ;
p_width = cw->tabBook.cur_width ;
p_height = cw->tabBook.cur_height - cw->tabBook.button_bot ;
/* note that lines are drawn centered on their (x,y) pixel. we
want to specify the outside pixel to contain the line so we
have to add in the thickness/2
*/
points[0].x = left_x ;
points[0].y = top_y + p_height; /* lower left */
points[1].x = 0;
points[1].y = - p_height; /* upper left */
points[2].x = p_width - thickness;
points[2].y = 0; /* upper right */
/* draw left and top edges */
XDrawLines(XtDisplay(cw), XtWindow(cw), gc1 ,
points, 3, CoordModePrevious);
points[0].x = left_x + p_width - thickness;
points[0].y = top_y ; /* upper right */
points[1].x = 0;
points[1].y = p_height - thickness; /* lower right*/
points[2].x = - p_width;
points[2].y = 0; /* lower left */
/* draw right and bottom edge */
XDrawLines(XtDisplay(cw), XtWindow(cw), gc2 ,
points, 3, CoordModePrevious);
}
/*
Draw shadows around tab buttons and the inside area
*/
static void draw_frames(TabBookWidget cw )
{
WidgetList widget_list = cw->composite.children;
Cardinal num_children = cw->composite.num_children;
Cardinal n = 0;
/* draw shadow around each button */
for (n=0; n < num_children; n++)
{
Widget child = widget_list[n];
if ( XtClass(child) == xmPushButtonWidgetClass)
{
draw_tab_for_button(cw, child);
}
}
FrameInsideArea(cw, False);
/* activate the current page's tab */
draw_tab_bottom(cw , cw->tabBook.active_tab, True);
}
static void ExposeMeth(Widget w, XEvent *xevent, Region region)
{
TabBookWidget cw = (TabBookWidget) w;
XExposeEvent * event = (XExposeEvent *) xevent;
/* WidgetList widget_list = cw->composite.children;
Cardinal num_children = cw->composite.num_children;
Cardinal n = 0; */
TRACE_OFF((stderr,"Expose %d \n", event->count));
if (!XtIsRealized(w))
return;
if (event->count != 0)
return;
draw_frames(cw);
}
/*
Draw the Tab looking border around the child widget which is a push button
*/
static void draw_tab_for_button(TabBookWidget cw , Widget child)
{
/* XtWidgetGeometry size;*/
Dimension left_x, top_y, p_width, p_height, thickness;
XPoint points[4];
if (!child)
return;
if (!XtIsRealized((Widget)cw))
return;
thickness = cw->tabBook.x_margin ;
left_x = child->core.x - cw->tabBook.x_margin + thickness/2 ;
top_y = child->core.y - cw->tabBook.y_margin + thickness/2 ;
p_width = child->core.width + 2*(cw->tabBook.x_margin) ;
p_height = cw->tabBook.button_bot - child->core.y +1;
/* note that lines are drawn centered on their (x,y) pixel. we
want to specify the outside pixel to contain the line so we
have to add in the thickness/2
*/
points[0].x = left_x ;
points[0].y = top_y + p_height; /* lower left */
points[1].x = 0;
points[1].y = - p_height; /* upper left */
points[2].x = p_width - thickness;
points[2].y = 0; /* upper right */
/* draw left and top edges */
XDrawLines(XtDisplay(cw), XtWindow(cw), cw->tabBook.top_shadow_GC ,
points, 3, CoordModePrevious);
points[0].x = left_x + p_width - thickness;
points[0].y = top_y ; /* upper right */
points[1].x = cw->tabBook.x_angle ;
points[1].y = cw->tabBook.x_angle ; /* angle out */
points[2].x = 0;
points[2].y = p_height - cw->tabBook.x_angle ; /* lower right */
/* draw right edge */
XDrawLines(XtDisplay(cw), XtWindow(cw), cw->tabBook.bot_shadow_GC ,
points, 3, CoordModePrevious);
}
/*
We draw the bottom line of the Tab to either activate or deactivate the
page
*/
static void draw_tab_bottom(TabBookWidget cw , Widget child, Boolean active)
{
/* XtWidgetGeometry size; */
Dimension left_x, top_y, p_width, p_height, thickness;
XPoint points[4];
if (!XtIsRealized((Widget)cw) || child == (Widget) 0)
return;
thickness = cw->tabBook.x_margin ;
left_x = child->core.x - cw->tabBook.x_margin + 1 + thickness/2 ;
top_y = child->core.y - cw->tabBook.y_margin + thickness/2 ;
p_width = child->core.width + 2*(cw->tabBook.x_margin) ;
p_height = cw->tabBook.button_bot - child->core.y + 1 + thickness/2 ;
points[0].x = left_x ;
points[0].y = top_y + p_height; /* lower left */
points[1].x = p_width ;
points[1].y = 0; /* lower right */
XDrawLines(XtDisplay(cw), XtWindow(cw),
active ? cw->tabBook.drawBackground_GC : cw->tabBook.top_shadow_GC ,
points, 2, CoordModePrevious);
}
/*
Return page number (1,2,..) coressponding to this child's
tab page
*/
static int find_page(TabBookWidget cw , Widget tab)
{
int page=1;
WidgetList widget_list = cw->composite.children;
Cardinal num_children = cw->composite.num_children;
Cardinal n = 0;
for (n=0; n < num_children; n++ )
{
Widget child = widget_list[n];
if (tab == child)
return page;
if ( XtClass(child) == xmPushButtonWidgetClass)
page++;
}
return 0; /* error */
}
/*
Return page Widget of n'th manager
*/
static Widget find_nth_manager(TabBookWidget cw , int page)
{
XmBulletinBoardRec * clip = (XmBulletinBoardRec *) cw->tabBook.clip;
WidgetList widget_list = clip->composite.children;
Cardinal num_children = clip->composite.num_children;
Cardinal n = 0;
int page_count ;
for (page_count=0, n=0; n < num_children; n++ )
{
Widget child = widget_list[n];
if ( XtIsSubclass(child, xmManagerWidgetClass ) )
{
page_count++;
if (page == page_count)
return child;
}
}
return NULL; /* error */
}
/*
Return page Widget of n'th button
*/
static Widget find_nth_button(TabBookWidget cw , int page)
{
WidgetList widget_list = cw->composite.children;
Cardinal num_children = cw->composite.num_children;
Cardinal n = 0;
int page_count ;
for (page_count=0, n=0; n < num_children; n++ )
{
Widget child = widget_list[n];
if ( XtClass(child) == xmPushButtonWidgetClass)
{
page_count++;
if (page == page_count)
return child;
}
}
return NULL; /* error */
}
/*
Unmanage all pages except active one
*/
static void unmanage_all_Pages(TabBookWidget cw )
{
XmBulletinBoardRec * clip = (XmBulletinBoardRec *) cw->tabBook.clip;
WidgetList widget_list = clip->composite.children;
Cardinal num_children = clip->composite.num_children;
Cardinal n = 0;
for (n=0; n < num_children; n++ )
{
Widget child = widget_list[n];
if ( XtIsSubclass(child, xmManagerWidgetClass ) )
{
if (cw->tabBook.active_manager == child )
XtManageChild(child);
else
XtUnmanageChild(child);
}
}
}
/*
Tab PushButton callback - activate this tab and deactivate
the formerly activated tab
*/
static void activate_cb(Widget w, XtPointer ctx ,XtPointer cb_data)
{
TabBookWidget cw = (TabBookWidget) XtParent(w);
XcgTabBookCallbackData rcb_data;
XmPushButtonCallbackStruct * but_cb_data =
(XmPushButtonCallbackStruct * ) cb_data;
int option;
if (cw->tabBook.active_tab == w)
return; /* pressed the already active tab button */
if (ctx) /* callback called internally rather from button event */
option = *(int *) ctx;
else
option = 0;
rcb_data.reason = XcgNewPage; /* reason for callback */
if (but_cb_data)
rcb_data.event = but_cb_data->event; /* button event */
else
rcb_data.event = NULL; /* not a real event, emulated */
rcb_data.prev_active_page = cw->tabBook.active_page ; /* 0 when initially called */
rcb_data.active_page = find_page(cw, w); /* new active page */
rcb_data.button = w; /* the button widget which was
pressed (emulated or actual*/
rcb_data.ret_veto = False;
rcb_data.future1 = 0;
rcb_data.future2 = NULL;
/* callback not called if we are here as a result of user
calling XcgTabBookSetActivePage with option set to
XcgTabBook_OPT_NO_CB */
if (cw->tabBook.newPageCallback && !(option & XcgTabBook_OPT_NO_CB) )
XtCallCallbackList((Widget)cw, cw->tabBook.newPageCallback,
(XtPointer) &rcb_data);
if (rcb_data.ret_veto )
return;
draw_tab_bottom(cw , cw->tabBook.active_tab, False);
draw_tab_bottom(cw , w, True);
cw->tabBook.active_tab = w;
cw->tabBook.old_active_page = cw->tabBook.active_page ;
if (cw->tabBook.auto_manage && cw->tabBook.active_manager )
XtUnmanageChild(cw->tabBook.active_manager);
cw->tabBook.active_page = rcb_data.active_page ;
cw->tabBook.active_manager = find_nth_manager(cw, cw->tabBook.active_page );
if (cw->tabBook.auto_manage && cw->tabBook.active_manager )
XtManageChild(cw->tabBook.active_manager);
}
/*
If child is push button, change its resources to meet our needs
*/
static void InsertChild(Widget w)
{
TabBookWidget cw = (TabBookWidget) XtParent(w);
TRACE_OFF((stderr,"Insert Child\n"));
if ( XtClass(w) == xmPushButtonWidgetClass)
{
cw->tabBook.total_buttons ++;
XtVaSetValues(w, XmNfillOnArm, False,
XmNshadowThickness, 0,
NULL);
XtAddCallback(w, XmNactivateCallback,
(XtCallbackProc) activate_cb, NULL);
if (cw->tabBook.active_page == cw->tabBook.total_buttons)
cw->tabBook.active_tab = w;
}
else if ( XtIsSubclass(w, xmManagerWidgetClass ) )
{
if (cw->tabBook.clip == NULL)
/* first child inserted is our own clipping widget */
goto inherit_insert;
cw->tabBook.total_managers ++;
if (cw->tabBook.active_page == cw->tabBook.total_managers)
cw->tabBook.active_manager = w;
w->core.parent = cw->tabBook.clip ; /* reparent */
}
else
{
XtAppError(XtWidgetToApplicationContext((Widget)cw),
"TabBook: Only Buttons and manager widgets may be children of TabBook");
}
inherit_insert:
/* call insert child of superclass, which we know is at least a
composite widget */
(*((CompositeWidgetClass)(tabBookClassRec.core_class.superclass))->
composite_class.insert_child) (w) ;
}
/* a routine to halt execution and force
a core dump for debugging analysis
when a public routine is called with the wrong class of widget
*/
static void wrong_widget(char * routine)
{
int mypid = getpid();
TRACE_OFF((stderr, "Wrong class of widget passed to %s\n", routine));
fflush(stderr);
kill(mypid, SIGABRT);
}
/* ---------------- Widget API ---------------------------- */
/*
;+
XcgTabBookSetActivePage -- The active page is changed
Func: The active page is changed to the passed page number. Page
numbers begin with 1. If this results in a new active page,
the result is as if the user pressed the corresponding tab button.
It is also equivalent to setting the resource
C-Call: Boolean XcgTabBookSetActivePage(Widget w, int page, int option )
Input: w - TabBook widget
page - The new active page number (1,2,...)
option - bitmapped
XcgTabBook_OPT_NO_CB - don't call NewPage callback
Return: True - page has been changed
False - non-existent page number
;-
*/
Boolean XcgTabBookSetActivePage(Widget w, int page, int option )
{
# define ROUTINE "XcgTabBookSetActivePage"
TabBookWidget cw = (TabBookWidget) w;
CheckWidgetClass(ROUTINE); /* make sure we are called with a TabBook widget */
if (cw->tabBook.layout_completed && cw->tabBook.active_page != page )
{
Widget button = find_nth_button(cw, page );
/* emulate user pressing this button */
if (button)
{
activate_cb(button, &option, NULL);
return True;
}
else
return False;
}
cw->tabBook.active_page = page ;
return True;
# undef ROUTINE
}
/*
;+
XcgTabBookGetActivePage -- The active page is returned
Func: The current active page is returned.
C-Call: int XcgTabBookGetActivePage(Widget w)
Input: w - TabBook widget
Return: The current active page number (1,2,...)
A zero means the widget has not been managed at least once
;-
*/
int XcgTabBookGetActivePage(Widget w)
{
# define ROUTINE "XcgTabBookGetActivePage"
TabBookWidget cw = (TabBookWidget) w;
CheckWidgetClass(ROUTINE); /* make sure we are called with a TabBook widget */
return cw->tabBook.active_page ;
# undef ROUTINE
}
/*
;+
XcgTabBookGetActivePageWidget -- The manager widget child of the active page is returned
Func: The manager widget child of the active page is returned.
C-Call: Widget XcgTabBookGetActivePageWidget(Widget w)
Input: w - TabBook widget
Return: The manager Widget representing the active page.
A NULL means the widget has not been managed at least once
;-
*/
Widget XcgTabBookGetActivePageWidget(Widget w)
{
# define ROUTINE "XcgTabBookGetActivePageWidget"
TabBookWidget cw = (TabBookWidget) w;
CheckWidgetClass(ROUTINE); /* make sure we are called with a TabBook widget */
return find_nth_manager(cw, cw->tabBook.active_page );
# undef ROUTINE
}
viewmol-2.4.1/source/TabBook.h 0100644 0002727 0002727 00000010504 07752712707 014353 0 ustar jrh jrh /*******************************************************************************
* *
* Viewmol *
* *
* T A B B O O K . H *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: TabBook.h,v 1.2 2003/11/07 12:53:27 jrh Exp $
* $Log: TabBook.h,v $
* Revision 1.2 2003/11/07 12:53:27 jrh
* Release 2.4
*
* Revision 1.1 2000/12/10 15:40:37 jrh
* Initial revision
*
*/
/*
TabBook.h - Public definitions for TabBook widget
See TabBook documentation
Copyright 1996 COMPUTER GENERATION, INC.,
The software is provided "as is", without warranty of any kind, express
or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose and noninfringement.
In no event shall Computer Generation, inc. nor the author be liable for
any claim, damages or other liability, whether in an action of contract,
tort or otherwise, arising from, out of or in connection with the
software or the use or other dealings in the software.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation.
Author:
Gary Aviv
Computer Generation, Inc.,
gary@compgen.com
*/
/* Revision History:
$Log: TabBook.h,v $
Revision 1.2 2003/11/07 12:53:27 jrh
Release 2.4
Revision 1.1 2000/12/10 15:40:37 jrh
Initial revision
Revision 1.1 1997/05/01 22:20:51 eric
Initial revision
$log
Initial
$log
*/
#ifndef _XcgTabBook_h
#define _XcgTabBook_h
/***********************************************************************
*
* TabBook Widget
*
***********************************************************************/
/*
New resource names/classes
*/
#define XcgNautoManage "autoManage"
#define XcgCAutoManage "AutoManage"
#define XcgNactivePage "activePage"
#define XcgCActivePage "ActivePage"
#define XcgNnewPageCallback "newPageCallback,"
#define XcgCNewPageCallback "NewPageCallback,"
/*
Constraint resource names/classes
*/
#define XcgNresizeChild "resizeChild"
#define XcgCResizeChild "ResizeChild"
#define XcgRESIZE_NONE 0
#define XcgRESIZE_VERTICAL 1
#define XcgRESIZE_HORIZONTAL 2
#define XcgRESIZE_BOTH (XcgRESIZE_VERTICAL | XcgRESIZE_HORIZONTAL)
#define XcgNanchorChild "anchorChild"
#define XcgCAnchorChild "AnchorChild"
#define XcgANCHOR_CENTER 0
#define XcgANCHOR_EAST 1
#define XcgANCHOR_NORTH 2
#define XcgANCHOR_NORTHEAST 3
#define XcgANCHOR_NORTHWEST 4
#define XcgANCHOR_SOUTH 5
#define XcgANCHOR_SOUTHEAST 6
#define XcgANCHOR_SOUTHWEST 7
#define XcgANCHOR_WEST 8
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
typedef struct _TabBookClassRec *TabBookWidgetClass;
typedef struct _TabBookRec *TabBookWidget;
extern WidgetClass xcgTabBookWidgetClass;
#define XcgTabBook_OPT_NO_CB 1
Boolean XcgTabBookSetActivePage(Widget w, int page, int option );
int XcgTabBookGetActivePage(Widget w );
Widget XcgTabBookGetActivePageWidget(Widget w);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
/*
* Callback reasons. Try to stay out of range of the Motif XmCR_* reasons.
*/
typedef enum _XcgTabBookgReasonType {
XcgNewPage = 202 /* New page is active */
} XcgTabBookReasonType;
/*
** Struct passed to application when called back
*/
typedef struct _XcgTabBookCallbackData
{
XcgTabBookReasonType reason; /* reason for callback */
XEvent *event; /* button event, NULL if emulated */
int prev_active_page; /* 0 when initially called */
int active_page; /* new active page */
Widget button; /* the button widget which was
pressed (emulated or actual*/
Boolean ret_veto; /* caller may set to True to stop page change */
int future1;
void * future2;
} XcgTabBookCallbackData;
#endif /* _XcgTabBook_h */
viewmol-2.4.1/source/TabBookP.h 0100644 0002727 0002727 00000007056 07752712720 014476 0 ustar jrh jrh /*******************************************************************************
* *
* Viewmol *
* *
* T A B B O O K P . H *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: TabBookP.h,v 1.2 2003/11/07 12:53:36 jrh Exp $
* $Log: TabBookP.h,v $
* Revision 1.2 2003/11/07 12:53:36 jrh
* Release 2.4
*
* Revision 1.1 2000/12/10 15:40:50 jrh
* Initial revision
*
*/
/* TabBook widget private definitions */
#ifndef _XcgTabBookP_h
#define _XcgTabBookP_h
#include "TabBook.h"
#include
#ifdef MOTIF
#include
# if XmVersion >= 1002 /* If motif version >= 1.2 */
# include
# endif
#include
#include
#endif
#define XtInheritLayout ((Boolean (*)())_XtInherit)
typedef struct {
int dummy;
} TabBookClassPart;
typedef struct _TabBookClassRec {
CoreClassPart core_class;
CompositeClassPart composite_class;
ConstraintClassPart constraint_class;
#ifdef MOTIF
XmManagerClassPart manager_class;
XmBulletinBoardClassPart bulletin_class;
#endif
TabBookClassPart tabBook_class;
} TabBookClassRec;
extern TabBookClassRec tabBookClassRec;
typedef struct _TabBookPart
{
int y_margin ; /* reserved margin around each pushbutton ... */
int x_margin ; /* Used to draw Tab around it */
int x_spacing; /* x space between each button */
int x_angle; /* space on the right to draw andled line */
int border; /* border around entire TabBook */
Dimension button_bot; /* largest button goes this far */
Dimension cur_width;
Dimension cur_height;
Boolean layout_completed; /* layout was done at least once */
Boolean managed_before; /* manged was done at least once */
Boolean auto_manage; /* manager children are automatically mapped when appropriate */
Widget active_tab; /* the current page's tab Button */
Widget active_manager; /* the current page's manager widget */
int active_page; /* 1,2,.. */
int total_buttons;
int total_managers;
int old_active_page; /* 1,2,.. 0 means none, i.e. init */
GC drawBackground_GC ; /* the drawing area background */
Pixel drawBackground_color; /* ... and its color */
GC drawForeground_GC ; /* the drawing area foreground */
Pixel drawForeground_color; /* ... and its color */
GC bot_shadow_GC; /* for drawing lines, bottom shadow */
Pixel bot_shadow_color; /* ... and its color */
GC top_shadow_GC; /* for drawing lines, top shadow */
Pixel top_shadow_color; /* ... and its color */
XtCallbackList newPageCallback;
Widget clip; /* clip the manager children */
} TabBookPart;
typedef struct _TabBookRec {
CorePart core;
CompositePart composite;
ConstraintPart constraint;
#ifdef MOTIF
XmManagerPart manager;
XmBulletinBoardPart bulletin_board;
#endif
TabBookPart tabBook;
} TabBookRec;
typedef struct _TabBookConstraintPart
{
int resize_child; /* constraint resources */
int anchor_child;
} TabBookConstraintPart;
typedef struct _TabBookConstraintRec {
TabBookConstraintPart tabBook;
} TabBookConstraintRec, *TabBookConstraints;
#endif /* _XcgTabBookP_h */
viewmol-2.4.1/source/annotate.c 0100644 0002727 0002727 00000025475 07752675131 014652 0 ustar jrh jrh /*******************************************************************************
* *
* Viewmol *
* *
* A N N O T A T E . C *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: annotate.c,v 1.5 2003/11/07 10:56:25 jrh Exp $
* $Log: annotate.c,v $
* Revision 1.5 2003/11/07 10:56:25 jrh
* Release 2.4
*
* Revision 1.4 2000/12/10 15:01:05 jrh
* Release 2.3
*
* Revision 1.3 1999/05/24 01:24:31 jrh
* Release 2.2.1
*
* Revision 1.2 1999/02/07 21:43:52 jrh
* Release 2.2
*
* Revision 1.1 1998/01/26 00:33:05 jrh
* Initial revision
*
*/
#include
#include
#include
#include
#include
#include
#include "viewmol.h"
void modifyAnnotation(int, int, int);
void getAnnotation(Widget, caddr_t, caddr_t);
int makeAnnotation(int, int, float, float, float, int, const GLfloat *, int,
int, char *);
void deleteAnnotation(int *);
void moveAnnotation(int, double, double);
void setAnnotation(Widget, caddr_t, XmDrawingAreaCallbackStruct *);
int TextGetBaseline(Widget);
extern void redraw(int);
extern void pixelToWorld(int, double *, double *);
extern void setCursor(Widget, unsigned int);
extern int StringWidth(XFontStruct *, char *);
extern int StringHeight(XFontStruct *);
extern void *getmem(size_t, size_t);
extern void *expmem(void *, size_t, size_t);
extern void fremem(void **);
extern char *getStringResource(Widget, char *);
extern void getScreenCoordinates(double, double, double, double *, double *,
double *);
extern void modifyGeometry(int, char *);
extern PyLabelSpecObject *label_new(void);
extern struct WINDOW windows[];
extern struct MOLECULE *molecules;
extern struct ANNOTATION *annotation;
extern int nAnnotations, annotate, imol;
extern Pixel stdcol[9];
void modifyAnnotation(int which, int x, int y)
{
XmFontListEntry entry;
XmFontList fontlist;
XmFontType ret;
XFontStruct *font;
Widget text;
Dimension width, height;
Pixel bg;
int l, xs;
char str[MAXLENLINE], def[]="variable";
register char *p;
if ((which != (-1)) || annotate)
{
if ((p=getStringResource(windows[VIEWER].widget, "font")) == NULL) p=def;
entry=XmFontListEntryLoad(XtDisplay(windows[VIEWER].widget), p, XmFONT_IS_FONT, "TAG");
fontlist=XmFontListAppendEntry(NULL, entry);
font=(XFontStruct *)XmFontListEntryGetFont(entry, &ret);
XmFontListEntryFree(&entry);
XtVaGetValues(windows[VIEWER].widget, XtNbackground, &bg, NULL);
text=XtVaCreateWidget("annotation", xmTextWidgetClass, windows[VIEWER].widget,
XmNfontList, fontlist,
XmNshadowThickness, 0,
XmNmarginWidth, 3,
XmNmarginHeight, 0,
XmNcolumns, 10,
XmNresizeWidth, True,
XtNbackground, bg,
NULL);
/* Lesstif does not yet have XmTextGetBaseline implemented */
/* height=XmTextGetBaseline(text); */
height=TextGetBaseline(text);
if (which == (-1)) XtVaSetValues(text, XmNx, x-3, XmNy, y-height-1, NULL);
if (which != (-1))
{
annotation[which].widget=text;
XtVaGetValues(windows[VIEWER].widget, XmNwidth, &width, XmNheight, &height, NULL);
XtVaSetValues(annotation[which].widget, XmNx, (Position)(0.5*(annotation[which].x+1.0)*(double)width),
XmNy, height-(Position)(0.5*(annotation[which].y+1.0)*(double)height+TextGetBaseline(annotation[which].widget)),
NULL);
/* moveAnnotation(which, 2.0*(double)x/(double)width, 2.0*(double)y/(double)height); */
xs=(int)(0.5*(annotation[which].x+1.0)*(double)width);
l=xs;
p=annotation[which].text;
while (*p && (l < x))
{
strncpy(str, annotation[which].text, p-annotation[which].text+1);
str[p-annotation[which].text+1]='\0';
p++;
l=xs+StringWidth(windows[VIEWER].font, str);
}
if (annotation[which].text[0])
{
XtVaSetValues(annotation[which].widget, XmNvalue, annotation[which].text,
XmNcursorPosition, (XmTextPosition)(p-annotation[which].text-1),
XmNcolumns, (int)strlen(annotation[which].text),
NULL);
annotation[which].flags&=~DRAWANN;
}
}
XtManageChild(text);
XtAddCallback(text, XmNactivateCallback, (XtCallbackProc)getAnnotation, (XmAnyCallbackStruct *)which);
XmProcessTraversal(text, XmTRAVERSE_CURRENT);
}
setCursor(windows[VIEWER].widget, XC_top_left_arrow);
annotate=FALSE;
}
void getAnnotation(Widget w, caddr_t which, caddr_t call_data)
{
Dimension h;
Position x, y;
const GLfloat black[4] = {0.0, 0.0, 0.0, 0.0};
double xpix, ypix;
int i, active;
char *text;
active=(int)which;
text=XmTextGetString(w);
if (*text != '\0')
{
XtVaGetValues(w, XmNx, &x, XmNy, &y, NULL);
pixelToWorld(VIEWER, &xpix, &ypix);
/* h=XmTextGetBaseline(w); */
h=TextGetBaseline(w);
if (active == (-1))
{
x+=3;
y+=h;
i=makeAnnotation((-1), COORDINATES, (float)(windows[VIEWER].left+x*xpix),
(float)(windows[VIEWER].top-y*ypix), 0.0,
stdcol[BLACK], black, EDITABLE | MOVEABLE, (-1), text);
}
else
{
if (annotation[active].flags & GEOMETRY)
{
molecules[imol].internals[annotation[active].userdata].type=
(-molecules[imol].internals[annotation[active].userdata].type);
if (strcmp(annotation[active].text, text))
modifyGeometry(annotation[active].userdata, text);
deleteAnnotation(&active);
}
else
{
strcpy(annotation[active].text, text);
annotation[active].flags|=DRAWANN;
}
active=(-1);
}
}
else
deleteAnnotation(&active);
XtFree(text);
XtDestroyWidget(w);
}
int makeAnnotation(int which, int type, float x, float y, float z, int color,
const GLfloat color_rgb[4], int flags, int userdata, char *text)
{
PyLabelSpecObject *newLabel;
Dimension width, height;
double xpix, ypix;
register int i;
if (which == (-1))
{
nAnnotations++;
if (annotation == NULL)
annotation=(struct ANNOTATION *)getmem(1, sizeof(struct ANNOTATION));
else
annotation=(struct ANNOTATION *)expmem((void *)annotation, nAnnotations,
sizeof(struct ANNOTATION));
which=nAnnotations-1;
}
if ((newLabel=label_new()) != NULL)
{
newLabel->labelID=which;
annotation[which].pyObject=newLabel;
}
annotation[which].widget=NULL;
if (text != NULL)
strncpy(annotation[which].text, text, MAXLENLINE-1);
XtVaGetValues(windows[VIEWER].widget, XtNwidth, &width, XtNheight, &height, NULL);
pixelToWorld(VIEWER, &xpix, &ypix);
if (type == CENTERED)
{
i=StringHeight(windows[VIEWER].font);
annotation[which].x=((windows[VIEWER].left+windows[VIEWER].right
-xpix*(double)StringWidth(windows[VIEWER].font,
annotation[which].text)))/((double)width*xpix);
annotation[which].y=2.0*(windows[VIEWER].top-2.*(double)y*ypix*(double)i)/((double)height*ypix);
annotation[which].z=0.0;
}
else
{
/* x and y are in pixels */
annotation[which].x=2.0*x/((double)width*xpix);
annotation[which].y=2.0*y/((double)height*ypix);
annotation[which].z=z;
}
annotation[which].color=color;
annotation[which].color_rgb[0]=color_rgb[0];
annotation[which].color_rgb[1]=color_rgb[1];
annotation[which].color_rgb[2]=color_rgb[2];
annotation[which].color_rgb[3]=color_rgb[3];
annotation[which].flags=flags | DRAWANN;
annotation[which].userdata=userdata;
return(which);
}
void deleteAnnotation(int *which)
{
register int i;
if (*which != (-1))
{
Py_DECREF(annotation[*which].pyObject);
if (annotation[*which].widget)
{
XtDestroyWidget(annotation[*which].widget);
annotation[*which].widget=NULL;
}
}
if (*which > (-1) && *which != nAnnotations-1)
{
for (i=(*which)+1; ilabelID=i-1;
annotation[i-1].widget=annotation[i].widget;
annotation[i-1].x=annotation[i].x;
annotation[i-1].y=annotation[i].y;
annotation[i-1].z=annotation[i].z;
annotation[i-1].color=annotation[i].color;
annotation[i-1].color_rgb[0]=annotation[i].color_rgb[0];
annotation[i-1].color_rgb[1]=annotation[i].color_rgb[1];
annotation[i-1].color_rgb[2]=annotation[i].color_rgb[2];
annotation[i-1].color_rgb[3]=annotation[i].color_rgb[3];
annotation[i-1].flags=annotation[i].flags;
annotation[i-1].userdata=annotation[i].userdata;
strcpy(annotation[i-1].text, annotation[i].text);
}
}
if (*which != (-1))
{
nAnnotations--;
if (nAnnotations)
annotation=(struct ANNOTATION *)expmem((void *)annotation, nAnnotations,
sizeof(struct ANNOTATION));
else
fremem((void *)&annotation);
*which=(-1);
}
}
void scaleAnnotation(float scale)
{
register int i;
for (i=0; iascent+margin+1);
}
viewmol-2.4.1/source/atommodule.c 0100644 0002727 0002727 00000024374 07752675212 015204 0 ustar jrh jrh /*******************************************************************************
* *
* Viewmol *
* *
* A T O M M O D U L E . C *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: atommodule.c,v 1.2 2003/11/07 10:57:14 jrh Exp $
* $Log: atommodule.c,v $
* Revision 1.2 2003/11/07 10:57:14 jrh
* Release 2.4
*
* Revision 1.1 2000/12/10 15:01:16 jrh
* Initial revision
*
*/
#include
#include
#include
#include
#include "viewmol.h"
#define PyAtom_API_pointers 1
#define PyAtomSpec_Type_NUM 0
PyAtomSpecObject *atom_new(void);
static PyObject *atom_getElement(PyObject *, PyObject *);
static PyObject *atom_coordinates(PyObject *, PyObject *);
static PyObject *atom_radius(PyObject *, PyObject *);
static PyObject *atom_radiusScaleFactor(PyObject *, PyObject *);
static PyObject *atom_neutronScatteringFactor(PyObject *, PyObject *);
static PyObject *atom_name(PyObject *, PyObject *);
static PyObject *atom_replace(PyObject *, PyObject *);
static PyObject *atom_delete(PyObject *, PyObject *);
static PyObject *atom_getattr(PyAtomSpecObject *, char *);
static void atom_dealloc(PyAtomSpecObject *);
extern PyElementSpecObject *element_new(void);
extern void buildMolecule(struct MOLECULE *, int, int, int);
extern int checkInterrupt(void);
extern void makeINSIntensity(void);
extern struct MOLECULE *molecules;
extern struct ELEMENT *elements;
extern int nmolecule, ne, element;
static char PyAtomSpec_Type__doc__[] =
"Atom specification";
statichere PyTypeObject PyAtomSpec_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"AtomSpec", /*tp_name*/
sizeof(PyAtomSpecObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)atom_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)atom_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
/* Space for future expansion */
0L,0L,
/* Documentation string */
PyAtomSpec_Type__doc__
};
static PyMethodDef atom_methods[] = {
{"getElement", atom_getElement, 1},
{"coordinates", atom_coordinates, 1},
{"radius", atom_radius, 1},
{"radiusScaleFactor", atom_radiusScaleFactor, 1},
{"neutronScatteringFactor", atom_neutronScatteringFactor, 1},
{"name", atom_name, 1},
{"replace", atom_replace, 1},
{"delete", atom_delete, 1},
{NULL, NULL}
};
PyAtomSpecObject *atom_new(void)
{
PyAtomSpecObject *self;
self=PyObject_NEW(PyAtomSpecObject, &PyAtomSpec_Type);
if (self == NULL)
{
PyErr_NoMemory();
return(NULL);
}
self->moleculeID=0;
self->atomID=0;
return(self);
}
static PyObject *atom_getElement(PyObject *self, PyObject *args)
{
PyAtomSpecObject *s;
PyElementSpecObject *element;
int imol, iatom;
register int i;
if (checkInterrupt()) return(NULL);
if (!self)
{
Py_INCREF(Py_None);
return(Py_None);
}
s=(PyAtomSpecObject *)self;
imol=s->moleculeID;
iatom=s->atomID;
element=element_new();
if (element == NULL) return(NULL);
for (i=0; ielementID=i;
return((PyObject *)element);
}
}
for (i=0; ielementID=i;
return((PyObject *)element);
}
}
return(NULL);
}
static PyObject *atom_coordinates(PyObject *self, PyObject *args)
{
PyAtomSpecObject *s;
PyObject *tuple;
int imol, iatom;
double x=1.0e302, y=1.0e302, z=1.0e302;
if (checkInterrupt()) return(NULL);
if (!self)
{
Py_INCREF(Py_None);
return(Py_None);
}
s=(PyAtomSpecObject *)self;
imol=s->moleculeID;
iatom=s->atomID;
if (!PyArg_ParseTuple(args, "|ddd", &x, &y, &z)) return(NULL);
if (x < 1.0e300 && y < 1.0e300 && z < 1.0e300) /* set */
{
molecules[imol].atoms[iatom].x=x;
molecules[imol].atoms[iatom].y=y;
molecules[imol].atoms[iatom].z=z;
}
else
{
if ((tuple=PyTuple_New(4))) /* get */
{
PyTuple_SetItem(tuple, 0, PyFloat_FromDouble(molecules[imol].atoms[iatom].x));
PyTuple_SetItem(tuple, 1, PyFloat_FromDouble(molecules[imol].atoms[iatom].y));
PyTuple_SetItem(tuple, 2, PyFloat_FromDouble(molecules[imol].atoms[iatom].z));
PyTuple_SetItem(tuple, 3, PyString_FromString(molecules[imol].atoms[iatom].name));
return(tuple);
}
}
Py_INCREF(Py_None);
return(Py_None);
}
static PyObject *atom_radius(PyObject *self, PyObject *args)
{
PyAtomSpecObject *s;
double radius=-1.0e0;
int imol, iatom;
if (checkInterrupt()) return(NULL);
if (!self)
{
Py_INCREF(Py_None);
return(Py_None);
}
s=(PyAtomSpecObject *)self;
imol=s->moleculeID;
iatom=s->atomID;
if (!PyArg_ParseTuple(args, "|d", &radius)) return(NULL);
if (radius != -1.0e0) /* set */
{
if (radius >= 0.0)
molecules[imol].atoms[iatom].rad=radius;
else
{
PyErr_SetString(PyExc_ValueError, "Value out of range");
return(NULL);
}
}
else /* get */
return(PyFloat_FromDouble(molecules[imol].atoms[iatom].rad));
Py_INCREF(Py_None);
return(Py_None);
}
static PyObject *atom_radiusScaleFactor(PyObject *self, PyObject *args)
{
PyAtomSpecObject *s;
double radScale=-1.0e0;
int imol, iatom;
if (checkInterrupt()) return(NULL);
if (!self)
{
Py_INCREF(Py_None);
return(Py_None);
}
s=(PyAtomSpecObject *)self;
imol=s->moleculeID;
iatom=s->atomID;
if (!PyArg_ParseTuple(args, "|d", &radScale)) return(NULL);
if (radScale != -1.0e0) /* set */
{
if (radScale >= 0.0)
molecules[imol].atoms[iatom].radScale=radScale;
else
{
PyErr_SetString(PyExc_ValueError, "Value out of range");
return(NULL);
}
}
else /* get */
return(PyFloat_FromDouble(molecules[imol].atoms[iatom].radScale));
Py_INCREF(Py_None);
return(Py_None);
}
static PyObject *atom_neutronScatteringFactor(PyObject *self, PyObject *args)
{
PyAtomSpecObject *s;
double factor=-1.0e0;
int imol, iatom;
if (checkInterrupt()) return(NULL);
if (!self)
{
Py_INCREF(Py_None);
return(Py_None);
}
s=(PyAtomSpecObject *)self;
imol=s->moleculeID;
iatom=s->atomID;
if (!PyArg_ParseTuple(args, "|d", &factor)) return(NULL);
if (factor != -1.0e0) /* set */
{
if (factor >= 0.0)
{
molecules[imol].atoms[iatom].neutronScatterfac=factor;
makeINSIntensity();
}
else
{
PyErr_SetString(PyExc_ValueError, "Value out of range");
return(NULL);
}
}
else /* get */
return(PyFloat_FromDouble(molecules[imol].atoms[iatom].neutronScatterfac));
Py_INCREF(Py_None);
return(Py_None);
}
static PyObject *atom_name(PyObject *self, PyObject *args)
{
PyAtomSpecObject *s;
int imol, iatom;
char *n=NULL, name[MAXLENLINE];
if (checkInterrupt()) return(NULL);
if (!self)
{
Py_INCREF(Py_None);
return(Py_None);
}
s=(PyAtomSpecObject *)self;
imol=s->moleculeID;
iatom=s->atomID;
if (!PyArg_ParseTuple(args, "|s", &n)) return(NULL);
if (n != NULL) /* set */
{
if (strlen(n) > 8)
{
PyErr_SetString(PyExc_ValueError, "Name is too long");
return(NULL);
}
else
strncpy(molecules[imol].atoms[iatom].name, n, 8);
}
else /* get */
{
sprintf(name, "%s%d", molecules[imol].atoms[iatom].name, iatom+1);
return(PyString_FromString(name));
}
Py_INCREF(Py_None);
return(Py_None);
}
static PyObject *atom_replace(PyObject *self, PyObject *args)
{
PyAtomSpecObject *s;
int imol, iatom, i, found;
char *symbol;
if (checkInterrupt()) return(NULL);
if (!self)
{
Py_INCREF(Py_None);
return(Py_None);
}
s=(PyAtomSpecObject *)self;
imol=s->moleculeID;
iatom=s->atomID;
if (!PyArg_ParseTuple(args, "s", &symbol)) return(NULL);
symbol[0]=toupper(symbol[0]);
symbol[1]=tolower(symbol[1]);
found=FALSE;
for (i=0; imoleculeID;
iatom=s->atomID;
buildMolecule(&molecules[imol], iatom, DELETE_ATOM, FALSE);
}
Py_INCREF(Py_None);
return(Py_None);
}
static void atom_dealloc(PyAtomSpecObject *self)
{
if (!self) return;
PyMem_DEL(self);
}
static PyObject *atom_getattr(PyAtomSpecObject *self, char *name)
{
return(Py_FindMethod(atom_methods, (PyObject *)self, name));
}
void initAtomModule(void)
{
PyObject *module, *dict;
static void *PyAtom_API[PyAtom_API_pointers];
PyAtomSpec_Type.ob_type=&PyType_Type;
module=Py_InitModule("atom", atom_methods);
dict=PyModule_GetDict(module);
PyAtom_API[PyAtomSpec_Type_NUM]=(void *)&PyAtomSpec_Type;
PyDict_SetItemString(dict, "_C_API", PyCObject_FromVoidPtr((void *)PyAtom_API, NULL));
}
viewmol-2.4.1/source/balanceform.c 0100644 0002727 0002727 00000020702 07752675227 015304 0 ustar jrh jrh /*******************************************************************************
* *
* Viewmol *
* *
* B A L A N C E F O R M . C *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: balanceform.c,v 1.2 2003/11/07 10:57:27 jrh Exp $
* $Log: balanceform.c,v $
* Revision 1.2 2003/11/07 10:57:27 jrh
* Release 2.4
*
* Revision 1.1 2000/12/10 15:01:29 jrh
* Initial revision
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "viewmol.h"
#include "dialog.h"
void balanceExit(Widget, caddr_t, XmPushButtonCallbackStruct *);
void GetInt(Widget, caddr_t, XmPushButtonCallbackStruct *);
int checkReaction(void);
extern void MapBox(Widget, caddr_t, XmToggleButtonCallbackStruct *);
extern Widget CreatePushButtonRow(Widget, struct PushButtonRow *, int);
extern Widget initShell(Widget, char *, Widget *, Widget *);
extern void getSumFormula(struct MOLECULE *, char *, int);
extern XmString makeIndexedString(char *);
extern void *getmem(size_t, size_t);
extern void *expmem(void *, size_t, size_t);
extern void fremem(void **);
extern void ringBell(void);
extern XtAppContext app;
extern struct WINDOW windows[];
extern struct MOLECULE *molecules;
extern Widget topShell;
extern int nmolecule, ne;
static Widget dialog, *stoichioNumber;
static int *balancedReactions=NULL, nmolecule_saved=0, cont;
static char **balancedReactants=NULL, *reactants=NULL;
void balanceDialog(Widget widget, caddr_t dummy, XmAnyCallbackStruct *data)
{
XEvent event;
Widget form, board, form1, label=NULL, sep;
static struct PushButtonRow buttons[] = {
{ "ok", balanceExit, (XtPointer)TRUE, NULL },
{ "cancel", balanceExit, (XtPointer)FALSE, NULL },
};
XmString name;
size_t mnc;
int found;
char formula[MAXLENLINE], last[MAXLENLINE], *p;
register int i, j, k;
/* This function creates the dialog for manually balancing reactions */
if (balancedReactions)
{
mnc=0;
k=0;
for (i=0; i 0)
k++;
}
}
if (nmolecule_saved == k) return;
fremem((void **)&balancedReactions);
fremem((void **)&balancedReactants);
fremem((void **)&reactants);
balancedReactions=(int *)getmem((size_t)nmolecule, sizeof(int));
balancedReactants=(char **)getmem((size_t)nmolecule, sizeof(char *));
reactants=(char *)getmem(mnc, sizeof(char));
}
else
{
mnc=0;
for (i=0; ina; j++)
{
found=FALSE;
for (k=0; katoms[j].element->symbol))
{
found=TRUE;
count[k]+=mol->stoichioNumber;
}
}
if (!found)
{
strcpy(&elements[4*nelem], mol->atoms[j].element->symbol);
count[nelem]=mol->stoichioNumber;
nelem++;
}
}
}
found=TRUE;
for (i=0; i