diff -Nru rasmol-2.7.5/debian/changelog rasmol-2.7.5/debian/changelog --- rasmol-2.7.5/debian/changelog 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/debian/changelog 2011-04-26 15:13:57.000000000 +0000 @@ -1,3 +1,28 @@ +rasmol (2.7.5-3) unstable; urgency=low + + * Andreas Tille added upstream-metadata.yaml with bibliographic information. + * Start maintaining rasmol with '3.0 (quilt)' source format with changes + to upstream sources as patches generated from the git repository with gdp. + * Add a 'debian/README.source' file. + * Fix GTK deprecation warning in GtkSpinButtons (patch 06_spinbuttons). + * Fix segfault in image exporting with GTK (patch 07_gtkexport). + * Split older changes to upstream sources to separate patches with gdp and + add DEP-3 in 'debian/metapatches': + - 01_writemsg: Use WriteMsg() consistently for text output. + - 02_x11shortcuts: Fix null pointer ref on File menu keyboard + shortcuts in x11win.c. + - 03_gtk_redraw: Fix screen update in GTK UI. + - 04_imakefile: Debian changes to Imakefile. + - 05_intwidth: Use C99 exact-width ints in typedefs. + - 08_manfix: Rasmol man page fixes. + - 09_uncompress_quote: Quote args to decompression programs when + loading files. + * control: + - Build-Depend on new (versionless) libneartree-dev. + - Remove duplicate Section in rasmol binary package. + + -- Teemu Ikonen Tue, 26 Apr 2011 17:11:48 +0200 + rasmol (2.7.5-2) unstable; urgency=low * gtkwin.c: diff -Nru rasmol-2.7.5/debian/control rasmol-2.7.5/debian/control --- rasmol-2.7.5/debian/control 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/debian/control 2011-04-26 15:13:57.000000000 +0000 @@ -8,12 +8,11 @@ Homepage: http://rasmol.org Build-Depends: debhelper (>= 7.0.0), xutils-dev, libx11-dev, libxext-dev, libxi-dev, x11proto-core-dev, libvte-dev, libgtk2.0-dev (>= 2.12.0), - libcbf-dev, libcvector2-dev, libcqrlib2-dev, libcneartree3-dev + libcbf-dev, libcvector2-dev, libcqrlib2-dev, libcneartree-dev Standards-Version: 3.9.1 Package: rasmol Architecture: any -Section: science Depends: ${shlibs:Depends}, ${misc:Depends} Suggests: rasmol-doc Description: Visualize biological macromolecules diff -Nru rasmol-2.7.5/debian/metapatches/01_writemsg rasmol-2.7.5/debian/metapatches/01_writemsg --- rasmol-2.7.5/debian/metapatches/01_writemsg 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/01_writemsg 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,3 @@ +From: Teemu Ikonen +Subject: Use WriteMsg() consistently for text output. +X-git-branch: p/writemsg diff -Nru rasmol-2.7.5/debian/metapatches/02_x11shortcuts rasmol-2.7.5/debian/metapatches/02_x11shortcuts --- rasmol-2.7.5/debian/metapatches/02_x11shortcuts 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/02_x11shortcuts 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,3 @@ +From: Teemu Ikonen +Subject: Fix null pointer ref on File menu keyboard shortcuts in x11win.c. +X-git-branch: p/x11shortcuts diff -Nru rasmol-2.7.5/debian/metapatches/03_gtk_redraw rasmol-2.7.5/debian/metapatches/03_gtk_redraw --- rasmol-2.7.5/debian/metapatches/03_gtk_redraw 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/03_gtk_redraw 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,3 @@ +From: Teemu Ikonen +Subject: Fix screen update in GTK UI. +X-git-branch: p/gtk_redraw diff -Nru rasmol-2.7.5/debian/metapatches/04_imakefile rasmol-2.7.5/debian/metapatches/04_imakefile --- rasmol-2.7.5/debian/metapatches/04_imakefile 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/04_imakefile 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,3 @@ +From: Teemu Ikonen +Subject: Debian changes to Imakefile. +X-git-branch: p/imakefile diff -Nru rasmol-2.7.5/debian/metapatches/05_intwidth rasmol-2.7.5/debian/metapatches/05_intwidth --- rasmol-2.7.5/debian/metapatches/05_intwidth 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/05_intwidth 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,3 @@ +From: Teemu Ikonen +Subject: rasmol.h: Use C99 exact-width ints in typedefs. +X-git-branch: p/intwidth diff -Nru rasmol-2.7.5/debian/metapatches/06_spinbuttons rasmol-2.7.5/debian/metapatches/06_spinbuttons --- rasmol-2.7.5/debian/metapatches/06_spinbuttons 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/06_spinbuttons 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,9 @@ +From: Teemu Ikonen +Subject: Set zero page size to GtkSpinButtons in export dialog. +X-git-branch: p/spinbuttons + + Fixes deprecation warning from GTK. + + Also re-save the sizechooser.glade file in glade, causing + some reordering in the XML file. + diff -Nru rasmol-2.7.5/debian/metapatches/07_gtkexport rasmol-2.7.5/debian/metapatches/07_gtkexport --- rasmol-2.7.5/debian/metapatches/07_gtkexport 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/07_gtkexport 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,15 @@ +From: Teemu Ikonen +Subject: Fix segfault in image export with GTK. +X-git-branch: p/gtkexport + + File->Export segfaulted when the exported image size was different + from the image buffer size currently on the screen. + + The fix is to not try to render to user supplied buffer in + render_buffer(), but to copy FBuffer to the supplied buffer after + resizing. + + Also fixed the temporary image buffer allocation in export_cb() to use + sizeof(Pixel) instead of 4. + + Also, replace int with uintptr_t when casting pointers to ints. diff -Nru rasmol-2.7.5/debian/metapatches/08_manfix rasmol-2.7.5/debian/metapatches/08_manfix --- rasmol-2.7.5/debian/metapatches/08_manfix 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/08_manfix 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,3 @@ +From: Teemu Ikonen +Subject: Rasmol man page fixes. +X-git-branch: p/manfix diff -Nru rasmol-2.7.5/debian/metapatches/09_uncompress_quote rasmol-2.7.5/debian/metapatches/09_uncompress_quote --- rasmol-2.7.5/debian/metapatches/09_uncompress_quote 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/metapatches/09_uncompress_quote 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,3 @@ +From: Teemu Ikonen +Subject: Quote args to 'uncompress' command when loading files. +X-git-branch: p/uncompress_quote diff -Nru rasmol-2.7.5/debian/patches/01_writemsg.patch rasmol-2.7.5/debian/patches/01_writemsg.patch --- rasmol-2.7.5/debian/patches/01_writemsg.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/01_writemsg.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,664 @@ +From: Teemu Ikonen +Subject: Use WriteMsg() consistently for text output. +X-git-branch: p/writemsg + + src/rasmac.c | 7 + + src/rasmol.c | 6 + + src/rasmol.h | 2 + + src/rastxt.c | 6 + + src/raswin.c | 7 + + src/render.c | 449 +++++++++++++++++++++++++++--------------------------- + src/txt/rasmol.h | 1 + + 7 files changed, 256 insertions(+), 222 deletions(-) + +diff --git a/src/rasmac.c b/src/rasmac.c +index 5a22e9c..64eb8ee 100755 +--- a/src/rasmac.c ++++ b/src/rasmac.c +@@ -671,6 +671,13 @@ void WriteChar( int ch ) + } + + ++void WriteMsg( char *ptr ) ++{ ++ WriteString(ptr); ++ WriteChar ('\n'); ++} ++ ++ + void WriteString( char *ptr ) + { + while( *ptr ) +diff --git a/src/rasmol.c b/src/rasmol.c +index 9d6ad7b..8fd4b7e 100755 +--- a/src/rasmol.c ++++ b/src/rasmol.c +@@ -400,6 +400,12 @@ static int LexState; + static int HandleEvents( int ); + extern int ProcessCommand( void ); + ++void WriteMsg( char *ptr ) ++{ ++ WriteString(ptr); ++ WriteChar('\n'); ++} ++ + #ifndef GTKWIN + void WriteChar( int ch ) + { +diff --git a/src/rasmol.h b/src/rasmol.h +index bfc037c..f226f45 100755 +--- a/src/rasmol.h ++++ b/src/rasmol.h +@@ -284,8 +284,10 @@ typedef short Pixel; + #define AdvPickCoord 7 + + ++#define MSG_MAX 256 + void WriteChar( int ); + void WriteString( char* ); ++void WriteMsg( char* ); + void RasMolFatalExit( char* ); + void AdviseUpdate( int ); + void RefreshScreen( void ); +diff --git a/src/rastxt.c b/src/rastxt.c +index b73e977..6d7c547 100755 +--- a/src/rastxt.c ++++ b/src/rastxt.c +@@ -144,6 +144,12 @@ static int FileFormat; + static int ProfCount; + + ++void WriteMsg( char *ptr ) ++{ ++ WriteString(ptr); ++ WriteChar ('\n'); ++} ++ + + void WriteChar( int ch ) + { putc(ch,OutFp); +diff --git a/src/raswin.c b/src/raswin.c +index 3e86d13..1ee1902 100755 +--- a/src/raswin.c ++++ b/src/raswin.c +@@ -619,6 +619,13 @@ void WriteChar( int ch ) + } + + ++void WriteMsg( char *ptr ) ++{ ++ WriteString(ptr); ++ WriteChar ('\n'); ++} ++ ++ + void WriteString( char *ptr ) + { + while( *ptr ) +diff --git a/src/render.c b/src/render.c +index 6fb1ba9..21bd43c 100755 +--- a/src/render.c ++++ b/src/render.c +@@ -2013,43 +2013,43 @@ void SetPickMode( int mode ) + } + + +-static void DescribeAtom( AtomRef *ptr, int flag ) ++static int DescribeAtom(char *dest, AtomRef *ptr, int flag ) + { + register char *str; + register int i,ch; +- char buffer[40]; ++ char *cur; + ++ cur = dest; + str = Residue[ptr->grp->refno]; + for( i=0; i<3; i++ ) +- if( str[i]!=' ' ) +- WriteChar(str[i]); ++ if( str[i]!=' ' ) ++ *(cur++) = str[i]; + +- sprintf(buffer,"%d",ptr->grp->serno); +- WriteString(buffer); ++ cur += sprintf(cur,"%d",ptr->grp->serno); + + ch = ptr->chn->ident; +- if( ch != ' ' ) +- { if( isdigit(ch) ) +- WriteChar(':'); +- WriteChar(ch); ++ if( ch != ' ' ) { ++ if( isdigit(ch) ) ++ *(cur++) = ':'; ++ *(cur++) = ch; + } + +- WriteChar('.'); ++ *(cur++) = '.'; + str = ElemDesc[ptr->atm->refno]; + for( i=0; str[i] && i<12; i++ ) +- if( str[i]!=' ' ) +- WriteChar(str[i]); +- +- if (ptr->atm->model) +- { +- sprintf(buffer,"/%d",ptr->atm->model); +- WriteString(buffer); ++ if( str[i]!=' ' ) ++ *(cur++) = str[i]; ++ ++ if (ptr->atm->model) { ++ cur += sprintf(cur, "/%d", ptr->atm->model); + } + +- if( flag ) +- { sprintf(buffer," (%ld)",ptr->atm->serno); +- WriteString(buffer); ++ if( flag ) { ++ cur += sprintf(cur, " (%ld)", ptr->atm->serno); + } ++ ++ *(cur++) = 0; ++ return (cur - dest - 1); + } + + +@@ -2060,10 +2060,14 @@ int PickAtoms( int shift, int xpos, int ypos ) + register double temp; + register char *str; + register size_t len; +- + char buffer[80]; + AtomRef ref; ++ char msg[MSG_MAX]; ++ char *cur; ++#define MsgString(mstr) cur += sprintf(cur, (mstr)) ++#define MsgChar(c) *(cur++) = (c) + ++ cur = msg; + if( PickMode == PickNone ) + return False; + +@@ -2072,92 +2076,92 @@ int PickAtoms( int shift, int xpos, int ypos ) + if( !QAtom ) + return False; + +- if( PickMode==PickCentr && shift ) +- SetPickMode(PickOrign); +- +- if( PickMode==PickAtom ) +- { SelectAtom( shift, QAtom, QGroup ); +- return True; +- } else if( PickMode == PickGroup ) +- { SelectGroup( shift, QGroup ); +- return True; +- } else if( PickMode == PickChain ) +- { SelectChain( shift, QChain ); +- return True; +- } else if( PickMode == PickIdent || PickMode == PickCoord ) +- { InvalidateCmndLine(); +- +- WriteString("Atom: "); ++ if( PickMode==PickCentr && shift ) ++ SetPickMode(PickOrign); ++ ++ if( PickMode==PickAtom ) { ++ SelectAtom( shift, QAtom, QGroup ); ++ return True; ++ } else if( PickMode == PickGroup ) { ++ SelectGroup( shift, QGroup ); ++ return True; ++ } else if( PickMode == PickChain ) { ++ SelectChain( shift, QChain ); ++ return True; ++ } else if( PickMode == PickIdent || PickMode == PickCoord ) { ++ InvalidateCmndLine(); ++ MsgString("Atom: "); + str = ElemDesc[QAtom->refno]; +- if( str[0]!=' ' ) WriteChar(str[0]); +- WriteChar(str[1]); WriteChar(str[2]); ++ if( str[0]!=' ' ) ++ MsgChar(str[0]); ++ MsgChar(str[1]); ++ MsgChar(str[2]); + { int iii; +- for (iii = 3; str[iii] && iii < 12; iii++) { +- if( str[iii]!=' ' ) WriteChar(str[iii]); +- } ++ for (iii = 3; str[iii] && iii < 12; iii++) { ++ if( str[iii]!=' ' ) ++ MsgChar(str[iii]); ++ } + } + + if( !(QAtom->altl == ' ')) { +- WriteChar(';'); +- WriteChar(QAtom->altl); ++ MsgChar(';'); ++ MsgChar(QAtom->altl); + } + +- sprintf(buffer," %ld ",QAtom->serno); +- WriteString(buffer); ++ cur += sprintf(cur, " %ld ", QAtom->serno); + + if (!(QGroup->serno == -9999)) { +- str = Residue[QGroup->refno]; +- if( QAtom->flag&HeteroFlag ) +- { WriteString("Hetero: "); +- } else WriteString("Group: "); +- +- if( str[0]!=' ' ) WriteChar(str[0]); +- WriteChar(str[1]); WriteChar(str[2]); +- +- sprintf(buffer," %d",QGroup->serno); +- WriteString(buffer); +- if (!(QGroup->insert == ' ') && !(QGroup->insert=='\0')) +- WriteChar(QGroup->insert); ++ str = Residue[QGroup->refno]; ++ if( QAtom->flag&HeteroFlag ) { ++ MsgString("Hetero: "); ++ } else ++ MsgString("Group: "); ++ ++ if( str[0]!=' ' ) ++ MsgChar(str[0]); ++ MsgChar(str[1]); ++ MsgChar(str[2]); ++ ++ cur += sprintf(cur, " %d", QGroup->serno); ++ if (!(QGroup->insert == ' ') && !(QGroup->insert=='\0')) ++ MsgChar(QGroup->insert); + } + +- if( QChain->ident!=' ' ) +- { WriteString(" Chain: "); +- WriteChar(QChain->ident); ++ if( QChain->ident!=' ' ) { ++ MsgString(" Chain: "); ++ MsgChar(QChain->ident); + } + + if( QAtom->model) { +- sprintf(buffer," Model: %d",QAtom->model); +- WriteString(buffer); ++ cur += sprintf(cur, " Model: %d", QAtom->model); + } +- WriteChar('\n'); + if (PickMode == PickCoord || shift != 0 ) { +- register double x, y, z; +- +- x = (double)(QAtom->xorg + QAtom->fxorg + OrigCX)/250.0 +- +(double)(QAtom->xtrl)/10000.0; +- y = (double)(QAtom->yorg + QAtom->fyorg + OrigCY)/250.0 +- +(double)(QAtom->ytrl)/10000.0; +- z = (double)(QAtom->zorg + QAtom->fzorg + OrigCZ)/250.0 +- +(double)(QAtom->ztrl)/10000.0; +- ++ MsgChar('\n'); ++ register double x, y, z; ++ ++ x = (double)(QAtom->xorg + QAtom->fxorg + OrigCX)/250.0 ++ +(double)(QAtom->xtrl)/10000.0; ++ y = (double)(QAtom->yorg + QAtom->fyorg + OrigCY)/250.0 ++ +(double)(QAtom->ytrl)/10000.0; ++ z = (double)(QAtom->zorg + QAtom->fzorg + OrigCZ)/250.0 ++ +(double)(QAtom->ztrl)/10000.0; + #ifdef INVERT +- sprintf(buffer, " Coordinates: %9.3f %9.3f %9.3f\n",x,-y,-z); ++ cur += sprintf(cur, " Coordinates: %9.3f %9.3f %9.3f",x,-y,-z); + #else +- sprintf(buffer, " Coordinates: %9.3f %9.3f %9.3f\n",x,y,-z); ++ cur += sprintf(cur, " Coordinates: %9.3f %9.3f %9.3f",x,y,-z); + #endif +- WriteString(buffer); + } + +- } else if( PickMode == PickLabel ) +- { if( !QAtom->label ) +- { if( *LabelFormat!='\0' ) +- { len = strlen(LabelFormat); +- label = CreateLabel(LabelFormat,len); +- } else if( MainGroupCount > 1 ) +- { strcpy(buffer,"%n%r"); ++ } else if( PickMode == PickLabel ) { ++ if( !QAtom->label ) { ++ if( *LabelFormat!='\0' ) { ++ len = strlen(LabelFormat); ++ label = CreateLabel(LabelFormat,len); ++ } else if( MainGroupCount > 1 ) { ++ strcpy(buffer,"%n%r"); + str = buffer+4; +- if( Info.chaincount > 1 ) +- { if( isdigit(QChain->ident) ) ++ if( Info.chaincount > 1 ) { ++ if( isdigit(QChain->ident) ) + *str++ = ':'; + *str++ = '%'; + *str++ = 'c'; +@@ -2166,96 +2170,98 @@ int PickAtoms( int shift, int xpos, int ypos ) + + len = (str-buffer) + 3; + label = CreateLabel(buffer,(int)len); +- } else label = CreateLabel("%e%i%A",6); +- +- QAtom->label = label; +- label->refcount++; + } else +- { DeleteLabel( (Label*)QAtom->label ); +- QAtom->label = (void*)0; +- } +- ReDrawFlag |= RFRefresh; ++ label = CreateLabel("%e%i%A",6); ++ QAtom->label = label; ++ label->refcount++; ++ } else { ++ DeleteLabel( (Label*)QAtom->label ); ++ QAtom->label = (void*)0; ++ } ++ ReDrawFlag |= RFRefresh; + +- } else if( PickMode == PickCentr ) +- { CentreTransform(QAtom->xorg + QAtom->fxorg, +- QAtom->yorg + QAtom->fyorg, +- QAtom->zorg + QAtom->fzorg, XlateCen); ++ } else if( PickMode == PickCentr ) { ++ CentreTransform(QAtom->xorg + QAtom->fxorg, ++ QAtom->yorg + QAtom->fyorg, ++ QAtom->zorg + QAtom->fzorg, XlateCen); + +- ref.chn = QChain; +- ref.grp = QGroup; +- ref.atm = QAtom; ++ ref.chn = QChain; ++ ref.grp = QGroup; ++ ref.atm = QAtom; + +- InvalidateCmndLine(); +- WriteString("Rotating about "); +- DescribeAtom(&ref,True); +- WriteChar('\n'); ++ InvalidateCmndLine(); ++ MsgString("Rotating about "); ++ cur += DescribeAtom(cur, &ref,True); + +- } else if( PickMode == PickOrign ) +- { CentreTransform(QAtom->xorg + QAtom->fxorg, +- QAtom->yorg + QAtom->fyorg, +- QAtom->zorg + QAtom->fzorg, False); ++ } else if( PickMode == PickOrign ) { ++ CentreTransform(QAtom->xorg + QAtom->fxorg, ++ QAtom->yorg + QAtom->fyorg, ++ QAtom->zorg + QAtom->fzorg, False); + + ref.chn = QChain; + ref.grp = QGroup; + ref.atm = QAtom; + + InvalidateCmndLine(); +- WriteString("Rotating about "); +- DescribeAtom(&ref,True); +- WriteChar('\n'); ++ MsgString("Rotating about "); ++ cur += DescribeAtom(cur, &ref,True); + +- } else if( PickMode == PickMonit ) +- { /* State Machine Implementation */ ++ } else if( PickMode == PickMonit ) { ++ /* State Machine Implementation */ + +- if( PickCount == 0 ) +- { PickHist[0].atm = QAtom; ++ if( PickCount == 0 ) { ++ PickHist[0].atm = QAtom; + PickCount = 1; +- } else if( PickCount == 1 ) +- { if( !shift ) +- { if( PickHist[0].atm != QAtom ) +- { AddMonitors(PickHist[0].atm,QAtom); ++ } else if( PickCount == 1 ) { ++ if( !shift ) { ++ if( PickHist[0].atm != QAtom ) { ++ AddMonitors(PickHist[0].atm,QAtom); + ReDrawFlag |= RFRefresh; +- } +- PickCount = 2; +- } else PickHist[0].atm = QAtom; ++ } ++ PickCount = 2; ++ } else ++ PickHist[0].atm = QAtom; + } else /* PickCount == 2 */ +- if( !shift ) +- { PickHist[0].atm = QAtom; ++ if( !shift ) { ++ PickHist[0].atm = QAtom; + PickCount = 1; +- } else if( PickHist[0].atm != QAtom ) +- { AddMonitors(PickHist[0].atm,QAtom); ++ } else if( PickHist[0].atm != QAtom ) { ++ AddMonitors(PickHist[0].atm,QAtom); + ReDrawFlag |= RFRefresh; + } +- } else if (PickMode == PickBond) /* [GSG 11/16/95] */ +- { if( PickCount ) +- { if( shift ) +- { PickCount--; +- } else if( PickCount == 2 ) +- PickCount = 0; +- } +- +- ptr = PickHist+PickCount; +- ptr->chn = QChain; +- ptr->grp = QGroup; +- ptr->atm = QAtom; +- PickCount++; ++ } else if (PickMode == PickBond) { /* [GSG 11/16/95] */ ++ if( PickCount ) { ++ if( shift ) { ++ PickCount--; ++ } else if( PickCount == 2 ) ++ PickCount = 0; ++ } + +- if( CommandActive ) +- WriteChar('\n'); +- CommandActive = False; ++ ptr = PickHist+PickCount; ++ ptr->chn = QChain; ++ ptr->grp = QGroup; ++ ptr->atm = QAtom; ++ PickCount++; + +- WriteString("Atom #"); +- WriteChar(PickCount+'0'); +- WriteString(": "); +- DescribeAtom(ptr,True); ++ if( CommandActive ) + WriteChar('\n'); +- +- if( PickCount == 2 ) +- SetBondAxis(PickHist[0].atm, PickHist[1].atm); +- } else /* Distance, Angle or Torsion! */ +- { if( PickCount ) +- { if( shift ) +- { PickCount--; ++ CommandActive = False; ++ ++ MsgString("Atom #"); ++ MsgChar(PickCount+'0'); ++ MsgString(": "); ++ cur += DescribeAtom(cur, ptr,True); ++ MsgChar('\n'); ++ MsgChar(0); ++ WriteMsg(msg); ++ cur = msg; ++ ++ if( PickCount == 2 ) ++ SetBondAxis(PickHist[0].atm, PickHist[1].atm); ++ } else { /* Distance, Angle or Torsion! */ ++ if( PickCount ) { ++ if( shift ) { ++ PickCount--; + } else if( PickCount == PickMode ) + PickCount = 0; + } +@@ -2267,77 +2273,76 @@ int PickAtoms( int shift, int xpos, int ypos ) + PickCount++; + + InvalidateCmndLine(); +- WriteString("Atom #"); +- WriteChar(PickCount+'0'); +- WriteString(": "); +- DescribeAtom(ptr,True); +- WriteChar('\n'); +- +- if( PickCount == PickMode ) +- { /* [GSG 11/29/95] */ +- if ( PickMode != PickMonit ) +- DeleteMonitors(); +- if( PickMode == PickDist ) +- { temp = (double)CalcDistance(PickHist[0].atm, +- PickHist[1].atm); +- +- WriteString("Distance "); +- DescribeAtom(PickHist,False); +- WriteChar('-'); +- DescribeAtom(PickHist+1,False); +- sprintf(buffer,": %.2f\n\n",temp); +- WriteString(buffer); +- /* [GSG 11/21/95] */ +- AddMonitors(PickHist[0].atm, QAtom); +- ReDrawFlag |= RFRefresh; +- +- } else if( PickMode == PickAngle ) +- { temp = (double)CalcAngle(PickHist[0].atm, +- PickHist[1].atm, +- PickHist[2].atm); +- +- WriteString("Angle "); +- DescribeAtom(PickHist,False); +- WriteChar('-'); +- DescribeAtom(PickHist+1,False); +- WriteChar('-'); +- DescribeAtom(PickHist+2,False); +- sprintf(buffer,": %.2f\n\n",temp); +- WriteString(buffer); +- +- /* [GSG 11/21/95] */ +- AddMonitors2(PickHist[0].atm, PickHist[2].atm, +- PickHist[1].atm, (RAtom __far *)NULL, +- (Long) (rint(temp*100)), 128, PickAngle); +- ReDrawFlag |= RFRefresh; +- +- +- } else /* PickMode == PickTorsn */ +- { temp = (double)CalcTorsion(PickHist[0].atm, +- PickHist[1].atm, +- PickHist[2].atm, +- PickHist[3].atm); +- +- WriteString("Torsion "); +- DescribeAtom(PickHist,False); +- WriteChar('-'); +- DescribeAtom(PickHist+1,False); +- WriteChar('-'); +- DescribeAtom(PickHist+2,False); +- WriteChar('-'); +- DescribeAtom(PickHist+3,False); +- sprintf(buffer,": %.2f\n\n",temp); +- WriteString(buffer); +- WriteString(buffer); +- +- /* [GSG 11/21/95] */ +- AddMonitors2(PickHist[0].atm, PickHist[3].atm, +- PickHist[1].atm, PickHist[2].atm, +- (Long) (rint(temp*100)), 128, PickTorsn); +- ReDrawFlag |= RFRefresh; ++ MsgString("Atom #"); ++ MsgChar(PickCount+'0'); ++ MsgString(": "); ++ cur += DescribeAtom(cur, ptr,True); ++ ++ if( PickCount == PickMode ) { ++ /* [GSG 11/29/95] */ ++ if ( PickMode != PickMonit ) ++ DeleteMonitors(); ++ if( PickMode == PickDist ) { ++ temp = (double)CalcDistance(PickHist[0].atm, PickHist[1].atm); ++ ++ MsgChar('\n'); ++ MsgString("Distance "); ++ cur += DescribeAtom(cur, PickHist, False); ++ MsgChar('-'); ++ cur += DescribeAtom(cur, PickHist+1, False); ++ cur += sprintf(cur, ": %.2f", temp); ++ /* [GSG 11/21/95] */ ++ AddMonitors(PickHist[0].atm, QAtom); ++ ReDrawFlag |= RFRefresh; ++ ++ } else if( PickMode == PickAngle ) { ++ temp = (double)CalcAngle(PickHist[0].atm, ++ PickHist[1].atm, ++ PickHist[2].atm); ++ ++ MsgChar('\n'); ++ MsgString("Angle "); ++ cur += DescribeAtom(cur, PickHist, False); ++ MsgChar('-'); ++ cur += DescribeAtom(cur, PickHist+1, False); ++ MsgChar('-'); ++ cur += DescribeAtom(cur, PickHist+2, False); ++ cur += sprintf(cur, ": %.2f", temp); ++ ++ /* [GSG 11/21/95] */ ++ AddMonitors2(PickHist[0].atm, PickHist[2].atm, ++ PickHist[1].atm, (RAtom __far *)NULL, ++ (Long) (rint(temp*100)), 128, PickAngle); ++ ReDrawFlag |= RFRefresh; ++ } else { /* PickMode == PickTorsn */ ++ temp = (double)CalcTorsion(PickHist[0].atm, ++ PickHist[1].atm, ++ PickHist[2].atm, ++ PickHist[3].atm); ++ ++ MsgChar('\n'); ++ MsgString("Torsion "); ++ cur += DescribeAtom(cur, PickHist, False); ++ MsgChar('-'); ++ cur += DescribeAtom(cur, PickHist+1, False); ++ MsgChar('-'); ++ cur += DescribeAtom(cur, PickHist+2, False); ++ MsgChar('-'); ++ cur += DescribeAtom(cur, PickHist+3, False); ++ cur += sprintf(cur, ": %.2f", temp); ++ ++ /* [GSG 11/21/95] */ ++ AddMonitors2(PickHist[0].atm, PickHist[3].atm, ++ PickHist[1].atm, PickHist[2].atm, ++ (Long) (rint(temp*100)), 128, PickTorsn); ++ ReDrawFlag |= RFRefresh; + } + } + } ++ if(cur > msg) { ++ MsgChar(0); ++ WriteMsg(msg); ++ } + return True; + } + +diff --git a/src/txt/rasmol.h b/src/txt/rasmol.h +index 3014e39..e4ae3aa 100755 +--- a/src/txt/rasmol.h ++++ b/src/txt/rasmol.h +@@ -213,6 +213,7 @@ typedef short Pixel; + + void WriteChar( int ); + void WriteString( char* ); ++void WriteMsg( char* ); + void RasMolFatalExit( char* ); + void AdviseUpdate( int ); + void RefreshScreen( void ); diff -Nru rasmol-2.7.5/debian/patches/02_x11shortcuts.patch rasmol-2.7.5/debian/patches/02_x11shortcuts.patch --- rasmol-2.7.5/debian/patches/02_x11shortcuts.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/02_x11shortcuts.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,82 @@ +From: Teemu Ikonen +Subject: Fix null pointer ref on File menu keyboard shortcuts in x11win.c. +X-git-branch: p/x11shortcuts + + src/x11win.c | 55 ++++++++++++++++++++++++++++--------------------------- + 1 files changed, 28 insertions(+), 27 deletions(-) + +diff --git a/src/x11win.c b/src/x11win.c +index 7284260..1e4368e 100644 +--- a/src/x11win.c ++++ b/src/x11win.c +@@ -287,6 +287,7 @@ typedef struct _MenuItem { + int value; + } MenuItem; + ++static int zero = 0; + + static MenuItem FilMenu[21] = { + { &MsgStrs[StrMOpen] /* "Open..." */, 0x11, &MsgAuxl[StrMOpen], +@@ -301,35 +302,35 @@ static MenuItem FilMenu[21] = { + &MsgLens[StrMExit], NULL, 0 }, + { &MsgStrs[StrMEmpty] /* "" */, 0x08, &MsgAuxl[StrMEmpty], + &MsgLens[StrMEmpty], NULL, 0 }, +- { &(MolNStr[0]), 0x01, 0, +- &MolNLen[0], &MoleculeIndex, 0 }, +- { &(MolNStr[1]), 0x01, 0, +- &MolNLen[1], &MoleculeIndex, 1 }, +- { &(MolNStr[2]), 0x01, 0, +- &MolNLen[2], &MoleculeIndex, 2 }, +- { &(MolNStr[3]), 0x01, 0, +- &MolNLen[3], &MoleculeIndex, 3 }, +- { &(MolNStr[4]), 0x01, 0, ++ { &(MolNStr[0]), 0x01, &zero, ++ &MolNLen[0], &MoleculeIndex, 0 }, ++ { &(MolNStr[1]), 0x01, &zero, ++ &MolNLen[1], &MoleculeIndex, 1 }, ++ { &(MolNStr[2]), 0x01, &zero, ++ &MolNLen[2], &MoleculeIndex, 2 }, ++ { &(MolNStr[3]), 0x01, &zero, ++ &MolNLen[3], &MoleculeIndex, 3 }, ++ { &(MolNStr[4]), 0x01, &zero, + &MolNLen[4], &MoleculeIndex, 4 }, +- { &(MolNStr[5]), 0x01, 0, +- &MolNLen[5], &MoleculeIndex, 5 }, +- { &(MolNStr[6]), 0x01, 0, +- &MolNLen[6], &MoleculeIndex, 6 }, +- { &(MolNStr[7]), 0x01, 0, +- &MolNLen[7], &MoleculeIndex, 7 }, +- { &(MolNStr[8]), 0x01, 0, +- &MolNLen[8], &MoleculeIndex, 8 }, +- { &(MolNStr[9]), 0x01, 0, ++ { &(MolNStr[5]), 0x01, &zero, ++ &MolNLen[5], &MoleculeIndex, 5 }, ++ { &(MolNStr[6]), 0x01, &zero, ++ &MolNLen[6], &MoleculeIndex, 6 }, ++ { &(MolNStr[7]), 0x01, &zero, ++ &MolNLen[7], &MoleculeIndex, 7 }, ++ { &(MolNStr[8]), 0x01, &zero, ++ &MolNLen[8], &MoleculeIndex, 8 }, ++ { &(MolNStr[9]), 0x01, &zero, + &MolNLen[9], &MoleculeIndex, 9 }, +- { &(MolNStr[10]), 0x01, 0, +- &MolNLen[10], &MoleculeIndex, 10 }, +- { &(MolNStr[11]), 0x01, 0, +- &MolNLen[11], &MoleculeIndex, 11 }, +- { &(MolNStr[12]), 0x01, 0, +- &MolNLen[12], &MoleculeIndex, 12 }, +- { &(MolNStr[13]), 0x01, 0, +- &MolNLen[13], &MoleculeIndex, 13 }, +- { &(MolNStr[14]), 0x01, 0, ++ { &(MolNStr[10]), 0x01, &zero, ++ &MolNLen[10], &MoleculeIndex, 10 }, ++ { &(MolNStr[11]), 0x01, &zero, ++ &MolNLen[11], &MoleculeIndex, 11 }, ++ { &(MolNStr[12]), 0x01, &zero, ++ &MolNLen[12], &MoleculeIndex, 12 }, ++ { &(MolNStr[13]), 0x01, &zero, ++ &MolNLen[13], &MoleculeIndex, 13 }, ++ { &(MolNStr[14]), 0x01, &zero, + &MolNLen[14], &MoleculeIndex, 14 }}; + + static MenuItem DisMenu[9] = { diff -Nru rasmol-2.7.5/debian/patches/03_gtk_redraw.patch rasmol-2.7.5/debian/patches/03_gtk_redraw.patch --- rasmol-2.7.5/debian/patches/03_gtk_redraw.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/03_gtk_redraw.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,87 @@ +From: Teemu Ikonen +Subject: Fix screen update in GTK UI. +X-git-branch: p/gtk_redraw + + src/gtkwin.c | 39 ++++++++++++++++++++------------------- + 1 files changed, 20 insertions(+), 19 deletions(-) + +diff --git a/src/gtkwin.c b/src/gtkwin.c +index ce0e02f..8e1b11f 100755 +--- a/src/gtkwin.c ++++ b/src/gtkwin.c +@@ -1299,7 +1299,6 @@ void UpdateScrollBars( void ) + g_signal_handler_block(G_OBJECT(vscrollbar), vscr_handler); + gtk_range_set_value(GTK_RANGE(vscrollbar), new); + g_signal_handler_unblock(G_OBJECT(vscrollbar), vscr_handler); +- ReDrawFlag |= (1<button == 3 && event->type == GDK_BUTTON_RELEASE && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) { +- do_popup_menu (canvas, event); ++ if (!dragging && event->button == 3 && event->type == GDK_BUTTON_RELEASE ++ && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) { ++ do_popup_menu (canvas, event); + } else { +- stat = GetStatus(event->state); +- ProcessMouseUp(event->x,event->y,stat); +- } ++ stat = GetStatus(event->state); ++ ProcessMouseUp(event->x,event->y,stat); ++ } ++ if( ReDrawFlag ) { ++ RefreshScreen(); ++ } ++ dragging = FALSE; + +- dragging = FALSE; +- + return TRUE; + } + +@@ -1568,7 +1569,7 @@ int OpenDisplay(void) + #ifdef THIRTYTWOBIT + static ByteTest test; + #endif +- register int i,num; ++ int i; + static char VersionStr[50]; + GError *gerr = NULL; + +@@ -1681,15 +1682,15 @@ int OpenDisplay(void) + + int CreateImage( void ) + { +- register long size; +- register Pixel *ptr; +- +- if( FBuffer ) +- _ffree(FBuffer); +- size = (long)XRange*YRange*sizeof(Pixel); +- FBuffer = (Pixel*)_fmalloc( size+32 ); +- +- return((FBuffer!=(Pixel*)NULL)?True : False); ++ long size; ++ ++ if(FBuffer) { ++ _ffree(FBuffer); ++ } ++ size = (long)XRange*YRange*sizeof(Pixel); ++ FBuffer = (Pixel*)_fmalloc( size+32 ); ++ ++ return((FBuffer!=(Pixel*)NULL)?True : False); + } + + diff -Nru rasmol-2.7.5/debian/patches/04_imakefile.patch rasmol-2.7.5/debian/patches/04_imakefile.patch --- rasmol-2.7.5/debian/patches/04_imakefile.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/04_imakefile.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,82 @@ +From: Teemu Ikonen +Subject: Debian changes to Imakefile. +X-git-branch: p/imakefile + + src/Imakefile | 28 ++++++++++++++-------------- + 1 files changed, 14 insertions(+), 14 deletions(-) + +diff --git a/src/Imakefile b/src/Imakefile +index 03be00e..a7047c9 100755 +--- a/src/Imakefile ++++ b/src/Imakefile +@@ -1,8 +1,8 @@ +-#define NEARTREE_LOCAL +-#define CQRLIB_LOCAL +-#define CVECTOR_LOCAL +-#define XFORMSLIB_LOCAL +-#define CBFLIB_LOCAL ++# #define NEARTREE_LOCAL ++# #define CQRLIB_LOCAL ++# #define CVECTOR_LOCAL ++# #define XFORMSLIB_LOCAL ++# #define CBFLIB_LOCAL + ########################################################################### + # RasMol 2.7.5 # + # # +@@ -124,7 +124,7 @@ DEPTHDEF = -DTHIRTYTWOBIT + LOCALEDEF = + #endif + +-PKGDIR = $(HOME) ++PKGDIR = /usr + + #ifndef GTKWIN + #define X11WIN +@@ -197,7 +197,7 @@ CBFLIB_OBJDEP = $(CBFLIB_DIR)/lib/libcbf.a + ifeq ($(strip $(CBFLIB_DIR)),) + CBFLIB_DIR = $(PKGDIR) + endif +-CBFLIB_INCLUDE_DIR = $(CBFLIB_DIR)/include/cbflib ++CBFLIB_INCLUDE_DIR = $(CBFLIB_DIR)/include/cbf + CBFLIB_LDLIB = -L$(CBFLIB_DIR)/lib -lcbf + CBFLIB_OBJDEP = + #define NO_CBFLIB_BUILD +@@ -276,7 +276,7 @@ NEARTREE_OBJDEP = + + # RasMol's on-line help direcory + # e.g. /usr/local/lib/rasmol/rasmol.hlp +-RASMOLDIR = $(USRLIBDIR)/rasmol/ ++RASMOLDIR = /usr/share/rasmol/ + + + #ifndef USE_XFORMSLIB +@@ -332,23 +332,23 @@ LDLIBS = -lm -lXi $(XLIB) $(EXTRA_LIBRARIES) $(XFORMSLIB) $(GTKLIBS) \ + # + + #ifdef HPArchitecture +-CCOPTIONS = -Ae +-CDEBUGFLAGS = +O2 +Onolimit ++#CCOPTIONS = -Ae ++#CDEBUGFLAGS = -O2 # -Onolimit + + #ifdef HPUX_PARISC_32 +-CCOPTIONS = -Ae +DA2.0 +DS2.0 ++#CCOPTIONS = -Ae -DA2.0 -DS2.0 + #endif + + #ifdef HPUX_PARISC_64 +-CCOPTIONS = -Ae +DA2.0W +DS2.0 -D_LONGLONG ++#CCOPTIONS = -Ae -DA2.0W -DS2.0 -D_LONGLONG + #endif + + #ifdef HPUX_IA64_32 +-CCOPTIONS = -Ae +DD32 +DSmckinley ++#CCOPTIONS = -Ae -DD32 -DSmckinley + #endif + + #ifdef HPUX_IA64_64 +-CCOPTIONS = -Ae +DD64 +DSmckinley -D_LONGLONG ++#CCOPTIONS = -Ae -DD64 -DSmckinley -D_LONGLONG + #endif + #endif + diff -Nru rasmol-2.7.5/debian/patches/05_intwidth.patch rasmol-2.7.5/debian/patches/05_intwidth.patch --- rasmol-2.7.5/debian/patches/05_intwidth.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/05_intwidth.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,64 @@ +From: Teemu Ikonen +Subject: rasmol.h: Use C99 exact-width ints in typedefs. +X-git-branch: p/intwidth + + src/rasmol.h | 19 ++++++++----------- + 1 files changed, 8 insertions(+), 11 deletions(-) + +diff --git a/src/rasmol.h b/src/rasmol.h +index bfc037c..ff40939 100755 +--- a/src/rasmol.h ++++ b/src/rasmol.h +@@ -78,6 +78,7 @@ + /* rasmol.h + */ + ++#include + + /*===========================*/ + /* User Definable Options! */ +@@ -202,7 +203,7 @@ + + typedef double Real; + #ifndef APPLEMAC +-typedef unsigned char Byte; ++typedef uint8_t Byte; + #endif + + #ifdef __STDC__ +@@ -211,21 +212,18 @@ typedef signed char Char; + typedef char Char; + #endif + +-#ifdef _LONGLONG +-typedef unsigned int Card; +-typedef int Long; +-#else +-typedef unsigned long Card; ++typedef uint32_t Card; ++/* Long has to be defined as long, instead of int32_t because of ++ multiple printf and scanf calls using %ld in the format. */ + typedef long Long; +-#endif + + #ifdef EIGHTBIT +-typedef unsigned char Pixel; ++typedef uint8_t Pixel; + #else + #ifdef THIRTYTWOBIT +-typedef Long Pixel; ++typedef int32_t Pixel; + #else +-typedef short Pixel; ++typedef int16_t Pixel; + #endif + #endif + +@@ -249,7 +247,6 @@ typedef short Pixel; + #define ToUpper(x) (islower((x))?toupper((x)):(x)) + #endif + +- + #if !defined(IBMPC) || defined(_WIN32) + #ifdef APPLEMAC + #define _fmalloc NewPtrSys diff -Nru rasmol-2.7.5/debian/patches/06_spinbuttons.patch rasmol-2.7.5/debian/patches/06_spinbuttons.patch --- rasmol-2.7.5/debian/patches/06_spinbuttons.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/06_spinbuttons.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,120 @@ +From: Teemu Ikonen +Subject: Set zero page size to GtkSpinButtons in export dialog. +X-git-branch: p/spinbuttons + + Fixes deprecation warning from GTK. + + Also re-save the sizechooser.glade file in glade, causing + some reordering in the XML file. + + + src/sizechooser.glade | 29 +++++++++++++++++++---------- + 1 files changed, 19 insertions(+), 10 deletions(-) + +diff --git a/src/sizechooser.glade b/src/sizechooser.glade +index 77b3d99..da8bdbe 100644 +--- a/src/sizechooser.glade ++++ b/src/sizechooser.glade +@@ -1,7 +1,7 @@ +- +- +- ++ + ++ ++ + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + +@@ -15,20 +15,25 @@ + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + ++ Current size + True + True ++ False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK +- Current size + True + True + ++ ++ 0 ++ + + + ++ 640 x 480 + True + True ++ False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK +- 640 x 480 + True + size_current + +@@ -39,10 +44,11 @@ + + + ++ 1024 x 768 + True + True ++ False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK +- 1024 x 768 + True + size_current + +@@ -52,10 +58,11 @@ + + + ++ 1600 x 1200 + True + True ++ False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK +- 1600 x 1200 + True + size_current + +@@ -69,16 +76,18 @@ + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + ++ Custom: + True + True ++ False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK +- Custom: + True + size_current + + + False + False ++ 0 + + + +@@ -87,7 +96,7 @@ + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 +- 1920 1 65536 1 100 10 ++ 1920 1 65536 1 100 0 + True + True + +@@ -114,7 +123,7 @@ + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 +- 1440 1 65536 1 100 10 ++ 1440 1 65536 1 100 0 + True + + diff -Nru rasmol-2.7.5/debian/patches/07_gtkexport.patch rasmol-2.7.5/debian/patches/07_gtkexport.patch --- rasmol-2.7.5/debian/patches/07_gtkexport.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/07_gtkexport.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,491 @@ +From: Teemu Ikonen +Subject: Fix segfault in image export with GTK. +X-git-branch: p/gtkexport + + File->Export segfaulted when the exported image size was different + from the image buffer size currently on the screen. + + The fix is to not try to render to user supplied buffer in + render_buffer(), but to copy FBuffer to the supplied buffer after + resizing. + + Also fixed the temporary image buffer allocation in export_cb() to use + sizeof(Pixel) instead of 4. + + Also, replace int with uintptr_t when casting pointers to ints. + + src/gtkwin.c | 425 +++++++++++++++++++++++++++++++--------------------------- + 1 files changed, 226 insertions(+), 199 deletions(-) + +diff --git a/src/gtkwin.c b/src/gtkwin.c +index ce0e02f..8772345 100755 +--- a/src/gtkwin.c ++++ b/src/gtkwin.c +@@ -155,7 +155,7 @@ enum { + RES_150, + RES_300 + }; +-int print_resolution = RES_CURRENT; ++uintptr_t print_resolution = RES_CURRENT; + GtkPrintSettings *print_settings = NULL; + GtkPageSetup *print_pagesetup = NULL; + +@@ -392,109 +392,116 @@ void save_cb(GtkAction *action, gpointer user_data) + gtk_widget_destroy (dialog); + } + ++ + /* Render the current image to a given memory buffer with a given size */ +-void render_buffer(Pixel *buf, int xsize, int ysize) +-{ +- Pixel *old_fbuffer; +- int old_xrange, old_yrange, old_hrange, old_wrange, old_range, old_interactive, dx; +- +- old_fbuffer = FBuffer; +- old_xrange = XRange; +- old_yrange = YRange; +- FBuffer = buf; +- XRange = xsize; +- YRange = ysize; +- +- if( (dx = XRange%4) ) +- XRange += 4-dx; +- +- old_hrange = HRange; +- old_wrange = WRange; +- old_range = Range; +- HRange = YRange>>1; +- WRange = XRange>>1; +- Range = MinFun(XRange,YRange); +- +- ReDrawFlag |= RFReSize; +- old_interactive = Interactive; +- Interactive = False; +- RefreshScreen(); // *buf now contains the image +- Interactive = old_interactive; +- +- FBuffer = old_fbuffer; +- XRange = old_xrange; +- YRange = old_yrange; +- HRange = old_hrange; +- WRange = old_wrange; +- Range = old_range; +- +- ReDrawFlag |= RFReSize; +- RefreshScreen(); +- ReDrawFlag = NextReDrawFlag; ++void render_buffer(Pixel * buf, int xsize, int ysize) ++{ ++ int old_xrange, old_yrange, old_hrange, old_wrange, old_range, ++ old_interactive, dx; ++ ++ old_xrange = XRange; ++ old_yrange = YRange; ++ XRange = xsize; ++ YRange = ysize; ++ if ((dx = XRange % 4)) ++ XRange += 4 - dx; ++ ++ old_hrange = HRange; ++ old_wrange = WRange; ++ old_range = Range; ++ HRange = YRange >> 1; ++ WRange = XRange >> 1; ++ Range = MinFun(XRange, YRange); ++ ++ ReDrawFlag |= RFReSize; ++ old_interactive = Interactive; ++ Interactive = False; ++ RefreshScreen(); // FBuffer now contains the image ++ memcpy(buf, FBuffer, sizeof(Pixel) * xsize * ysize); ++ ++ Interactive = old_interactive; ++ ++ XRange = old_xrange; ++ YRange = old_yrange; ++ HRange = old_hrange; ++ WRange = old_wrange; ++ Range = old_range; ++ ++ ReDrawFlag |= RFReSize; ++ RefreshScreen(); ++ ReDrawFlag = NextReDrawFlag; + } + ++ + gboolean sizespin_cb(GtkSpinButton button, gpointer data) + { +- GtkLabel *header = NULL; +- char header_str[128]; +- +- if(gtk_toggle_button_get_active( +- GTK_TOGGLE_BUTTON(gtk_builder_get_object(sizebuilder, "size_custom")))) +- { +- export_x = gtk_spin_button_get_value_as_int( +- GTK_SPIN_BUTTON(gtk_builder_get_object(sizebuilder, "custom_x"))); +- export_y = gtk_spin_button_get_value_as_int( +- GTK_SPIN_BUTTON(gtk_builder_get_object(sizebuilder, "custom_y"))); +- +- header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); +- snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); +- gtk_label_set_text(header, header_str); +- } +- +- return FALSE; ++ GtkLabel *header = NULL; ++ char header_str[128]; ++ ++ if (gtk_toggle_button_get_active ++ (GTK_TOGGLE_BUTTON ++ (gtk_builder_get_object(sizebuilder, "size_custom")))) { ++ export_x = ++ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON ++ (gtk_builder_get_object ++ (sizebuilder, "custom_x"))); ++ export_y = ++ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON ++ (gtk_builder_get_object ++ (sizebuilder, "custom_y"))); ++ ++ header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); ++ snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); ++ gtk_label_set_text(header, header_str); ++ } ++ ++ return FALSE; + } + +-gboolean sizeradio_cb(GtkButton *button, gpointer data) ++ ++gboolean sizeradio_cb(GtkButton * button, gpointer data) + { +- int radioid; +- GtkLabel *header = NULL; +- char header_str[128]; +- +- radioid = (int) data; +- +- export_x = XRange; +- export_y = YRange; +- +- switch(radioid) { +- case RADIO_CURRENT: +- break; +- case RADIO_640: +- export_x = 640; +- export_y = 480; +- break; +- case RADIO_1024: +- export_x = 1024; +- export_y = 768; +- break; +- case RADIO_1600: +- export_x = 1600; +- export_y = 1200; +- break; +- case RADIO_CUSTOM: +- export_x = gtk_spin_button_get_value_as_int( +- GTK_SPIN_BUTTON(gtk_builder_get_object(sizebuilder, "custom_x"))); +- export_y = gtk_spin_button_get_value_as_int( +- GTK_SPIN_BUTTON(gtk_builder_get_object(sizebuilder, "custom_y"))); +- break; +- default: +- ; +- } +- +- header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); +- snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); +- gtk_label_set_text(header, header_str); +- +- return FALSE; ++ GtkLabel *header = NULL; ++ char header_str[128]; ++ uintptr_t radioid = (uintptr_t) data; ++ ++ export_x = XRange; ++ export_y = YRange; ++ ++ switch (radioid) { ++ case RADIO_CURRENT: ++ break; ++ case RADIO_640: ++ export_x = 640; ++ export_y = 480; ++ break; ++ case RADIO_1024: ++ export_x = 1024; ++ export_y = 768; ++ break; ++ case RADIO_1600: ++ export_x = 1600; ++ export_y = 1200; ++ break; ++ case RADIO_CUSTOM: ++ export_x = ++ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON ++ (gtk_builder_get_object ++ (sizebuilder, "custom_x"))); ++ export_y = ++ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON ++ (gtk_builder_get_object ++ (sizebuilder, "custom_y"))); ++ break; ++ default: ++ ; ++ } ++ ++ header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); ++ snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); ++ gtk_label_set_text(header, header_str); ++ ++ return FALSE; + } + + +@@ -560,101 +567,117 @@ void build_exportdialog(void) + + } + +-void export_cb(GtkAction *action, gpointer user_data) ++ ++void export_cb(GtkAction * action, gpointer user_data) + { +- static char *fname = NULL; ++ static char *fname = NULL; + +- if(!exportdialog) { +- build_exportdialog(); +- } +- if(fname) { +- gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (exportdialog), fname); +- gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER (exportdialog)); +- } +- if(gtk_toggle_button_get_active( +- GTK_TOGGLE_BUTTON(gtk_builder_get_object(sizebuilder, "size_current")))) +- { +- GtkLabel *header = NULL; +- char header_str[128]; +- +- export_x = XRange; +- export_y = YRange; +- header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); +- snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); +- gtk_label_set_text(header, header_str); +- } +- while(TRUE) { +- GtkWidget *question; +- GdkPixbuf *pbuf; +- GError *err = NULL; +- gboolean success = TRUE; +- guint format = 0; +- gchar *formatname = NULL; +- GSList *tmplist = NULL; +- guchar *tmpbuf; +- +- if (gtk_dialog_run (GTK_DIALOG (exportdialog)) != GTK_RESPONSE_ACCEPT) { +- break; +- } +- +- if(fname) { +- g_free (fname); +- } +- fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (exportdialog)); +- if(g_file_test(fname, G_FILE_TEST_EXISTS)) { +- gint resp; +- question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), +- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, +- GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, +- "A file named \"%s\" already exists. Do you want to replace it?", +- fname); +- resp = gtk_dialog_run(GTK_DIALOG(question)); +- gtk_widget_destroy (question); +- if(resp != GTK_RESPONSE_YES) { +- continue; +- } +- } +- +- format = egg_file_format_chooser_get_format ( +- EGG_FILE_FORMAT_CHOOSER(format_chooser), fname); +- if(!format) { +- char *tmp; +- question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), +- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, +- GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, +- "Could not recognise format of output file \"%s\", please choose another format.", +- ((tmp = rindex(fname, '/')) != NULL) ? (tmp+1) : (fname)); +- gtk_dialog_run(GTK_DIALOG(question)); +- gtk_widget_destroy (question); +- continue; +- } +- formatname = (gchar *) egg_file_format_chooser_get_format_data( +- EGG_FILE_FORMAT_CHOOSER(format_chooser), format); +- +- tmpbuf = g_new(guchar, 4*export_x*export_y); +- render_buffer((Pixel *) tmpbuf, export_x, export_y); +- pbuf = gdk_pixbuf_new_from_data(tmpbuf, +- GDK_COLORSPACE_RGB, +- TRUE, 8, +- export_x, export_y, 4*export_x, +- NULL, NULL); +- success = gdk_pixbuf_save(pbuf, fname, formatname, &err, NULL); +- +- if(!success && (err != NULL) ) { +- question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), +- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, +- GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Error saving image: %s", +- err->message); +- gtk_dialog_run(GTK_DIALOG(question)); +- gtk_widget_destroy (question); +- } +- g_object_unref(pbuf); +- g_free(tmpbuf); +- break; +- } +- gtk_widget_hide (exportdialog); ++ if (!exportdialog) { ++ build_exportdialog(); ++ } ++ if (fname) { ++ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(exportdialog), fname); ++ gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(exportdialog)); ++ } ++ if (gtk_toggle_button_get_active ++ (GTK_TOGGLE_BUTTON ++ (gtk_builder_get_object(sizebuilder, "size_current")))) { ++ GtkLabel *header = NULL; ++ char header_str[128]; ++ ++ export_x = XRange; ++ export_y = YRange; ++ header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); ++ snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); ++ gtk_label_set_text(header, header_str); ++ } ++ while (TRUE) { ++ GtkWidget *question; ++ GdkPixbuf *pbuf; ++ GError *err = NULL; ++ gboolean success = TRUE; ++ guint format = 0; ++ gchar *formatname = NULL; ++ GSList *tmplist = NULL; ++ Pixel *tmpbuf; ++ ++ if (gtk_dialog_run(GTK_DIALOG(exportdialog)) != GTK_RESPONSE_ACCEPT) { ++ break; ++ } ++ ++ if (fname) { ++ g_free(fname); ++ } ++ fname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(exportdialog)); ++ if (g_file_test(fname, G_FILE_TEST_EXISTS)) { ++ gint resp; ++ question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), ++ GTK_DIALOG_MODAL | ++ GTK_DIALOG_DESTROY_WITH_PARENT, ++ GTK_MESSAGE_QUESTION, ++ GTK_BUTTONS_YES_NO, ++ "A file named \"%s\" already exists. Do you want to replace it?", ++ fname); ++ resp = gtk_dialog_run(GTK_DIALOG(question)); ++ gtk_widget_destroy(question); ++ if (resp != GTK_RESPONSE_YES) { ++ continue; ++ } ++ } ++ ++ format = ++ egg_file_format_chooser_get_format(EGG_FILE_FORMAT_CHOOSER ++ (format_chooser), fname); ++ if (!format) { ++ char *tmp; ++ question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), ++ GTK_DIALOG_MODAL | ++ GTK_DIALOG_DESTROY_WITH_PARENT, ++ GTK_MESSAGE_WARNING, ++ GTK_BUTTONS_OK, ++ "Could not recognise format of output file \"%s\", please choose another format.", ++ ((tmp = ++ rindex(fname, ++ '/')) != ++ NULL) ? (tmp + 1) : (fname)); ++ gtk_dialog_run(GTK_DIALOG(question)); ++ gtk_widget_destroy(question); ++ continue; ++ } ++ formatname = ++ (gchar *) ++ egg_file_format_chooser_get_format_data(EGG_FILE_FORMAT_CHOOSER ++ (format_chooser), format); ++ ++ tmpbuf = g_new(Pixel, export_x * export_y); ++ render_buffer(tmpbuf, export_x, export_y); ++ pbuf = gdk_pixbuf_new_from_data((guchar *) tmpbuf, ++ GDK_COLORSPACE_RGB, ++ TRUE, 8, ++ export_x, export_y, ++ sizeof(Pixel) * export_x, ++ NULL, NULL); ++ success = gdk_pixbuf_save(pbuf, fname, formatname, &err, NULL); ++ ++ if (!success && (err != NULL)) { ++ question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), ++ GTK_DIALOG_MODAL | ++ GTK_DIALOG_DESTROY_WITH_PARENT, ++ GTK_MESSAGE_WARNING, ++ GTK_BUTTONS_OK, ++ "Error saving image: %s", ++ err->message); ++ gtk_dialog_run(GTK_DIALOG(question)); ++ gtk_widget_destroy(question); ++ } ++ g_object_unref(pbuf); ++ g_free(tmpbuf); ++ break; ++ } ++ gtk_widget_hide(exportdialog); + } + ++ + void pagesetup_cb(GtkAction *action, gpointer user_data) + { + if (print_pagesetup == NULL) { +@@ -735,21 +758,25 @@ void print_draw(GtkPrintOperation *printop, GtkPrintContext *context, + g_free(tmpbuf); + } + +-void print_get_res_cb(GtkPrintOperation *print, GtkWidget *widget, gpointer rb) ++ ++void print_get_res_cb(GtkPrintOperation * print, GtkWidget * widget, ++ gpointer rb) + { +- GSList *el; +- +- el = gtk_radio_button_get_group(*((GtkRadioButton **)rb)); +- while(el != NULL) { +- if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(el->data))) { +- print_resolution = (int) g_object_get_data(G_OBJECT(el->data), "res"); +- return; +- } else +- el = el->next; +- } +- return; ++ GSList *el; ++ ++ el = gtk_radio_button_get_group(*((GtkRadioButton **) rb)); ++ while (el != NULL) { ++ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(el->data))) { ++ print_resolution = ++ (uintptr_t) g_object_get_data(G_OBJECT(el->data), "res"); ++ return; ++ } else ++ el = el->next; ++ } ++ return; + } + ++ + GObject *print_build_reswidget_cb(GtkPrintOperation *operation, gpointer radio_p) + { + GtkBuilder *b = NULL; diff -Nru rasmol-2.7.5/debian/patches/08_manfix.patch rasmol-2.7.5/debian/patches/08_manfix.patch --- rasmol-2.7.5/debian/patches/08_manfix.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/08_manfix.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,30 @@ +From: Teemu Ikonen +Subject: Rasmol man page fixes. +X-git-branch: p/manfix + + doc/rasmol.1 | 8 ++++---- + 1 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/doc/rasmol.1 b/doc/rasmol.1 +index 85df72c..7aa392c 100644 +--- a/doc/rasmol.1 ++++ b/doc/rasmol.1 +@@ -1,4 +1,3 @@ +-.PU + .TH RASMOL 1 "July 2009" + .SH NAME + rasmol \- Molecular Graphics Visualisation Tool v2.7.5 +@@ -4115,9 +4114,10 @@ codes of each of the amino acids. + + .TP + .B Booleans +-A boolean parameter is a truth value. Valid boolean values are 'true' and +-'false', and their synonyms 'on' and 'off'. Boolean parameters are commonly +-used by RasMol to either enable or disable a representation or option. ++A boolean parameter is a truth value. Valid boolean values are 'true' ++and 'false', and their synonyms 'on' and 'off'. Boolean parameters are ++commonly used by RasMol to either enable or disable a representation or ++option. + + .SH FILE FORMATS + diff -Nru rasmol-2.7.5/debian/patches/09_uncompress_quote.patch rasmol-2.7.5/debian/patches/09_uncompress_quote.patch --- rasmol-2.7.5/debian/patches/09_uncompress_quote.patch 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/09_uncompress_quote.patch 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,25 @@ +From: Teemu Ikonen +Subject: Quote args to 'uncompress' command when loading files. +X-git-branch: p/uncompress_quote + + src/command.c | 4 ++-- + 1 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/command.c b/src/command.c +index 51ca288..c688c68 100755 +--- a/src/command.c ++++ b/src/command.c +@@ -669,11 +669,11 @@ static int FetchFileOne( int format, int info, char *name ) + + if( done == 0x9d ) + { /* Should #include and trap "" SIGPIPE */ +- sprintf(buffer,"trap \"\" 13; uncompress -c %s 2> /dev/null\n", ++ sprintf(buffer,"trap \"\" 13; uncompress -c '%s' 2> /dev/null\n", + DataFileName); + } else if( done == 0x8b ) + { /* Should #include and trap "" SIGPIPE */ +- sprintf(buffer,"trap \"\" 13; gzip -cdq %s 2> /dev/null\n", ++ sprintf(buffer,"trap \"\" 13; gzip -cdq '%s' 2> /dev/null\n", + DataFileName); + } else /* bad magic number! */ + { InvalidateCmndLine(); diff -Nru rasmol-2.7.5/debian/patches/series rasmol-2.7.5/debian/patches/series --- rasmol-2.7.5/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/patches/series 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,9 @@ +01_writemsg.patch +02_x11shortcuts.patch +03_gtk_redraw.patch +04_imakefile.patch +05_intwidth.patch +06_spinbuttons.patch +07_gtkexport.patch +08_manfix.patch +09_uncompress_quote.patch diff -Nru rasmol-2.7.5/debian/README.source rasmol-2.7.5/debian/README.source --- rasmol-2.7.5/debian/README.source 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/README.source 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,44 @@ +Notes on this Debian source package +=================================== + +Source package format +--------------------- + +These Debianized sources are in the standard '3.0 (quilt)' dpkg source format. +The patches in 'debian/patches' are generated from the git repository of the +package (see the Vcs-Git field in debian/control) by diffing the 'upstream' +branch with the corresponding patch branch ('p/*'). + +Making a change to the package sources does not require working with the git +repository. The package can be changed in a normal way by either adding a new +patch to 'debian/patches' or by changing the sources directly and letting +dpkg-source build the additional patch during source package creation. + +Working with the packaging git repository +----------------------------------------- + +If you want to incorporate your patch to the git repository of this package, +here are some hints. Some scripts to automate the patch and series file +generation and other tasks can be found at http://gitorious.org/gdp + +The 'master' branch of the git repository always contains the complete patched +sources, ready to be built by 'debuild' or a similar command. + +Commits modifying the upstream sources should go directly to the master branch, +but should also be cherry picked to a specific patch branch, in order to be +included in a separate patch file in the final source package. Note that the +patch branches do not form a patch stack, all of them should be branched from +unmodified upstream sources. + +The patches to be generated and the order of patch application are determined +by DEP-3 header information files in 'debian/metapatches'. The patches are +created and applied in lexicographic ordering of the patch header files, so if +a specific ordering of the patch files is needed, these files should be named +like 'NN_name', where NN is a number, to force the ordering. The header field +'X-git-branch' in the metapatch file points to the git branch used to generate +the patch file. + +Upstream modifying commits not included in any of the patch branches +will be placed by dpkg-source to the catchall patch +'debian/patches/debian-changes-{version}', but having this patch in +a released version is discouraged. diff -Nru rasmol-2.7.5/debian/source/format rasmol-2.7.5/debian/source/format --- rasmol-2.7.5/debian/source/format 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/source/format 2011-05-01 00:49:40.000000000 +0000 @@ -0,0 +1 @@ +3.0 (quilt) diff -Nru rasmol-2.7.5/debian/upstream-metadata.yaml rasmol-2.7.5/debian/upstream-metadata.yaml --- rasmol-2.7.5/debian/upstream-metadata.yaml 1970-01-01 00:00:00.000000000 +0000 +++ rasmol-2.7.5/debian/upstream-metadata.yaml 2011-04-26 15:13:57.000000000 +0000 @@ -0,0 +1,10 @@ +Contact: Herbert J. Bernstein +Name: RasMol +Reference: + author: Roger Sayle and E. James Milner-White + title: RasMol: Biomolecular graphics for all + journal: Trends in Biochemical Sciences (TIBS) + volume: 20 + number: 9 + pages: 374 + year: 1995 diff -Nru rasmol-2.7.5/doc/rasmol.1 rasmol-2.7.5/doc/rasmol.1 --- rasmol-2.7.5/doc/rasmol.1 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/doc/rasmol.1 2009-07-21 22:36:43.000000000 +0000 @@ -1,3 +1,4 @@ +.PU .TH RASMOL 1 "July 2009" .SH NAME rasmol \- Molecular Graphics Visualisation Tool v2.7.5 @@ -4114,10 +4115,9 @@ .TP .B Booleans -A boolean parameter is a truth value. Valid boolean values are 'true' -and 'false', and their synonyms 'on' and 'off'. Boolean parameters are -commonly used by RasMol to either enable or disable a representation or -option. +A boolean parameter is a truth value. Valid boolean values are 'true' and +'false', and their synonyms 'on' and 'off'. Boolean parameters are commonly +used by RasMol to either enable or disable a representation or option. .SH FILE FORMATS diff -Nru rasmol-2.7.5/src/command.c rasmol-2.7.5/src/command.c --- rasmol-2.7.5/src/command.c 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/command.c 2009-07-21 22:35:48.000000000 +0000 @@ -669,11 +669,11 @@ if( done == 0x9d ) { /* Should #include and trap "" SIGPIPE */ - sprintf(buffer,"trap \"\" 13; uncompress -c '%s' 2> /dev/null\n", + sprintf(buffer,"trap \"\" 13; uncompress -c %s 2> /dev/null\n", DataFileName); } else if( done == 0x8b ) { /* Should #include and trap "" SIGPIPE */ - sprintf(buffer,"trap \"\" 13; gzip -cdq '%s' 2> /dev/null\n", + sprintf(buffer,"trap \"\" 13; gzip -cdq %s 2> /dev/null\n", DataFileName); } else /* bad magic number! */ { InvalidateCmndLine(); diff -Nru rasmol-2.7.5/src/gtkwin.c rasmol-2.7.5/src/gtkwin.c --- rasmol-2.7.5/src/gtkwin.c 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/gtkwin.c 2009-07-21 22:35:48.000000000 +0000 @@ -1299,6 +1299,7 @@ g_signal_handler_block(G_OBJECT(vscrollbar), vscr_handler); gtk_range_set_value(GTK_RANGE(vscrollbar), new); g_signal_handler_unblock(G_OBJECT(vscrollbar), vscr_handler); + ReDrawFlag |= (1<button == 3 && event->type == GDK_BUTTON_RELEASE - && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) { - do_popup_menu (canvas, event); + if (!dragging && event->button == 3 && event->type == GDK_BUTTON_RELEASE && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) { + do_popup_menu (canvas, event); } else { - stat = GetStatus(event->state); - ProcessMouseUp(event->x,event->y,stat); - } - if( ReDrawFlag ) { - RefreshScreen(); - } - dragging = FALSE; + stat = GetStatus(event->state); + ProcessMouseUp(event->x,event->y,stat); + } + dragging = FALSE; + return TRUE; } @@ -1569,7 +1568,7 @@ #ifdef THIRTYTWOBIT static ByteTest test; #endif - int i; + register int i,num; static char VersionStr[50]; GError *gerr = NULL; @@ -1682,15 +1681,15 @@ int CreateImage( void ) { - long size; - - if(FBuffer) { - _ffree(FBuffer); - } - size = (long)XRange*YRange*sizeof(Pixel); - FBuffer = (Pixel*)_fmalloc( size+32 ); - - return((FBuffer!=(Pixel*)NULL)?True : False); + register long size; + register Pixel *ptr; + + if( FBuffer ) + _ffree(FBuffer); + size = (long)XRange*YRange*sizeof(Pixel); + FBuffer = (Pixel*)_fmalloc( size+32 ); + + return((FBuffer!=(Pixel*)NULL)?True : False); } diff -Nru rasmol-2.7.5/src/gtkwin.c.indent rasmol-2.7.5/src/gtkwin.c.indent --- rasmol-2.7.5/src/gtkwin.c.indent 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/gtkwin.c.indent 1970-01-01 00:00:00.000000000 +0000 @@ -1,1854 +0,0 @@ -/*************************************************************************** - * RasMol 2.7.5 * - * * - * RasMol * - * Molecular Graphics Visualisation Tool * - * 13 June 2009 * - * * - * Based on RasMol 2.6 by Roger Sayle * - * Biomolecular Structures Group, Glaxo Wellcome Research & Development, * - * Stevenage, Hertfordshire, UK * - * Version 2.6, August 1995, Version 2.6.4, December 1998 * - * Copyright (C) Roger Sayle 1992-1999 * - * * - * and Based on Mods by * - *Author Version, Date Copyright * - *Arne Mueller RasMol 2.6x1 May 98 (C) Arne Mueller 1998 * - *Gary Grossman and RasMol 2.5-ucb Nov 95 (C) UC Regents/ModularCHEM * - *Marco Molinaro RasMol 2.6-ucb Nov 96 Consortium 1995, 1996 * - * * - *Philippe Valadon RasTop 1.3 Aug 00 (C) Philippe Valadon 2000 * - * * - *Herbert J. RasMol 2.7.0 Mar 99 (C) Herbert J. Bernstein * - *Bernstein RasMol 2.7.1 Jun 99 1998-2008 * - * RasMol 2.7.1.1 Jan 01 * - * RasMol 2.7.2 Aug 00 * - * RasMol 2.7.2.1 Apr 01 * - * RasMol 2.7.2.1.1 Jan 04 * - * RasMol 2.7.3 Feb 05 * - * RasMol 2.7.3.1 Apr 06 * - * RasMol 2.7.4 Nov 07 * - * RasMol 2.7.4.1 Jan 08 * - * RasMol 2.7.4.2 Mar 08 * - * RasMol 2.7.5 May 09 * - * * - * RasMol 2.7.5 incorporates changes by T. Ikonen, G. McQuillan, N. Darakev* - * and L. Andrews (via the neartree package). Work on RasMol 2.7.5 * - * supported in part by grant 1R15GM078077-01 from the National Institute * - * of General Medical Sciences (NIGMS), U.S. National Institutes of Health * - * and by grant ER63601-1021466-0009501 from the Office of Biological & * - * Environmental Research (BER), Office of Science, U. S. Department of * - * Energy. RasMol 2.7.4 incorporated changes by G. Todorov, Nan Jia, * - * N. Darakev, P. Kamburov, G. McQuillan, and J. Jemilawon. Work on RasMol * - * 2.7.4 supported in part by grant 1R15GM078077-01 from the NIGMS/NIH and * - * grant ER63601-1021466-0009501 from BER/DOE. RasMol 2.7.3 incorporates * - * changes by Clarice Chigbo, Ricky Chachra, and Mamoru Yamanishi. Work * - * on RasMol 2.7.3 supported in part by grants DBI-0203064, DBI-0315281 * - * and EF-0312612 from the U.S. National Science Foundation and grant * - * DE-FG02-03ER63601 from BER/DOE. The content is solely the responsibility* - * of the authors and does not necessarily represent the official views of * - * the funding organizations. * - * * - * The code for use of RasMol under GTK in RasMol 2.7.4.2 and 2.7.5 was * - * written by Teemu Ikonen. * - * * - * and Incorporating Translations by * - * Author Item Language * - * Isabel Servan Martinez, * - * Jose Miguel Fernandez Fernandez 2.6 Manual Spanish * - * Jose Miguel Fernandez Fernandez 2.7.1 Manual Spanish * - * Fernando Gabriel Ranea 2.7.1 menus and messages Spanish * - * Jean-Pierre Demailly 2.7.1 menus and messages French * - * Giuseppe Martini, Giovanni Paolella, 2.7.1 menus and messages * - * A. Davassi, M. Masullo, C. Liotto 2.7.1 help file Italian * - * G. Pozhvanov 2.7.3 menus and messages Russian * - * G. Todorov 2.7.3 menus and messages Bulgarian* - * Nan Jia, G. Todorov 2.7.3 menus and messages Chinese * - * Mamoru Yamanishi, Katajima Hajime 2.7.3 menus and messages Japanese * - * * - * This Release by * - * Herbert J. Bernstein, Bernstein + Sons, 5 Brewster Ln, Bellport, NY, USA* - * yaya@bernstein-plus-sons.com * - * Copyright(C) Herbert J. Bernstein 1998-2008 * - * * - * READ THE FILE NOTICE FOR RASMOL LICENSES * - *Please read the file NOTICE for important notices which apply to this * - *package and for license terms (GPL or RASLIC). * - ***************************************************************************/ -/* gtkwin.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define GRAPHICS -#include "rasmol.h" -#include "graphics.h" -#include "bitmaps.h" -#include "command.h" -#include "cmndline.h" -#include "molecule.h" -#include "abstree.h" -#include "render.h" -#include "multiple.h" -#include "transfor.h" -#include "vector.h" -#include "wbrotate.h" -#include "langsel.h" -#include "gtkwin.h" -#include "gtkui.h" -#include "eggfileformatchooser.h" - - -#define RASGTK_MINWIDTH 300 -#define RASGTK_MINHEIGHT 300 - -typedef union { - Long longword; - Byte bytes[4]; -} ByteTest; - - -#ifdef THIRTYTWOBIT -static int SwapBytes; -#endif - -extern int ProcessCommand(void); - -/* Widgets and containers */ -GtkWidget *mainwin; -GtkWidget *mainvbox; -GtkWidget *menubar; -GtkWidget *mainvpane; -GtkWidget *ctable; -GtkWidget *canvasarea; -GtkWidget *vscrollbar; -GtkWidget *hscrollbar; -GtkWidget *termhbox; -GtkWidget *vte; - -/* Export dialog and extras */ -enum { - RADIO_CURRENT, - RADIO_640, - RADIO_1024, - RADIO_1600, - RADIO_CUSTOM -}; -GtkWidget *exportdialog = NULL; -GtkWidget *format_chooser = NULL; -GtkBuilder *sizebuilder = NULL; -GSList *sizeradios = NULL; -int export_x, export_y; - -/* printing */ -enum { - RES_CURRENT, - RES_150, - RES_300 -}; -int print_resolution = RES_CURRENT; -GtkPrintSettings *print_settings = NULL; -GtkPageSetup *print_pagesetup = NULL; - -/* other global junk */ -gulong vscr_handler; -gulong hscr_handler; -gulong menu_handler; -GtkActionGroup *action_group; -GtkUIManager *ui_manager; -GtkAccelGroup *accel_group; -guint merge_id; -gboolean dragging = FALSE; - -#define ADDSIGNAL(A,B) g_signal_connect(gtk_ui_manager_get_action(ui_manager,\ -(A)),"activate", G_CALLBACK(handlemenu_cb), (gpointer) &(B)); - -/* Magic numbers for menus */ -#define FILEMENU (0<<8) -#define DISMENU (1<<8) -#define COLMENU (2<<8) -#define OPTMENU (3<<8) -#define SETMENU (4<<8) -/* #define EXPMENU (5<<8) */ -#define HELPMENU (6<<8) - -/* Magic numbers for menu items */ -/* for normal menu entries, the values need to be allocated */ -static const int m_f_open = (FILEMENU + 1); -static const int m_f_saveas = (FILEMENU + 2); -static const int m_f_close = (FILEMENU + 3); - -#define m_ofiles (FILEMENU + 7) - -static const int m_d_wireframe = (DISMENU + 1); -static const int m_d_backbone = (DISMENU + 2); -static const int m_d_sticks = (DISMENU + 3); -static const int m_d_spheres = (DISMENU + 4); -static const int m_d_ballstick = (DISMENU + 5); -static const int m_d_ribbons = (DISMENU + 6); -static const int m_d_strands = (DISMENU + 7); -static const int m_d_cartoons = (DISMENU + 8); -static const int m_d_molsurf = (DISMENU + 9); - -static const int m_c_monochrome = (COLMENU + 1); -static const int m_c_cpk = (COLMENU + 2); -static const int m_c_shapely = (COLMENU + 3); -static const int m_c_group = (COLMENU + 4); -static const int m_c_chain = (COLMENU + 5); -static const int m_c_temperature = (COLMENU + 6); -static const int m_c_structure = (COLMENU + 7); -static const int m_c_user = (COLMENU + 8); -static const int m_c_model = (COLMENU + 9); -static const int m_c_alt = (COLMENU + 10); - -/* for other menu entries, the values need to be allocated */ -static const int m_o_slab = (OPTMENU + 1); -static const int m_o_hydrogens = (OPTMENU + 2); -static const int m_o_heteros = (OPTMENU + 3); -static const int m_o_specular = (OPTMENU + 4); -static const int m_o_shadows = (OPTMENU + 5); -static const int m_o_stereo = (OPTMENU + 6); -static const int m_o_labels = (OPTMENU + 7); - -/* for radio buttons the numbers need to be constants */ -#define m_s_poff (SETMENU + 1) -#define m_s_pident (SETMENU + 2) -#define m_s_pdist (SETMENU + 3) -#define m_s_pmon (SETMENU + 4) -#define m_s_pangle (SETMENU + 5) -#define m_s_ptorsion (SETMENU + 6) -#define m_s_plabel (SETMENU + 7) -#define m_s_pcentre (SETMENU + 8) -#define m_s_pcoord (SETMENU + 9) -#define m_s_pbond (SETMENU + 10) -#define m_s_rbond (SETMENU + 11) -#define m_s_rmol (SETMENU + 12) -#define m_s_rall (SETMENU + 13) - -/* -static const int m_e_gif = (EXPMENU + 1); -static const int m_e_eps = (EXPMENU + 2); -static const int m_e_ppm = (EXPMENU + 3); -static const int m_e_iris = (EXPMENU + 4); -static const int m_e_rast = (EXPMENU + 5); -static const int m_e_bmp = (EXPMENU + 6); -static const int m_e_pict = (EXPMENU + 7); -*/ - -/* static const int m_h_about = (HELPMENU + 1); */ -static const int m_h_manual = (HELPMENU + 2); -static const int m_h_register = (HELPMENU + 3); -static const int m_h_donate = (HELPMENU + 4); - - -gboolean handlemenu_cb(GtkAction * action, gpointer user_data) -{ - int menu; - - menu = *((int *) user_data); - HandleMenu(menu); - /* Handle the strange tristate toggle on stereo mode */ - if (menu == m_o_stereo) { - gtk_toggle_action_set_active((GtkToggleAction *) action, UseStereo); - } - if (ReDrawFlag) { - RefreshScreen(); - ReDrawFlag = NextReDrawFlag; - } - return FALSE; -} - -void radio_cb(GtkRadioAction * action, GtkRadioAction * current, - gpointer user_data) -{ - gint value; - - value = gtk_radio_action_get_current_value(action); - HandleMenu(value); - if (ReDrawFlag) { - RefreshScreen(); - ReDrawFlag = NextReDrawFlag; - } -} - -void open_cb(GtkAction * action, gpointer user_data) -{ - static char *prevname = NULL; - GtkWidget *opendialog = NULL; - GtkRecentManager *rman = NULL; - GtkFileFilter *filter = NULL; - - opendialog = gtk_file_chooser_dialog_new("Open File", - GTK_WINDOW(mainwin), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, - GTK_RESPONSE_ACCEPT, NULL); - - filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, "Molecular structures"); - gtk_file_filter_add_pattern(filter, "*.pdb"); - gtk_file_filter_add_pattern(filter, "*.PDB"); - gtk_file_filter_add_pattern(filter, "*.mol"); - gtk_file_filter_add_pattern(filter, "*.MOL"); - gtk_file_filter_add_pattern(filter, "*.mol2"); - gtk_file_filter_add_pattern(filter, "*.xyz"); - gtk_file_filter_add_pattern(filter, "*.XYZ"); - gtk_file_filter_add_pattern(filter, "*.mop"); - gtk_file_filter_add_pattern(filter, "*.MOP"); - gtk_file_filter_add_pattern(filter, "*.mopcrt"); - gtk_file_filter_add_pattern(filter, "*.MOPCRT"); - gtk_file_filter_add_pattern(filter, "*.mopint"); - gtk_file_filter_add_pattern(filter, "*.MOPINT"); - gtk_file_filter_add_pattern(filter, "*.mopout"); - gtk_file_filter_add_pattern(filter, "*.MOPOUT"); - gtk_file_filter_add_pattern(filter, "*.alc"); - gtk_file_filter_add_pattern(filter, "*.ALC"); - gtk_file_filter_add_pattern(filter, "*.crd"); - gtk_file_filter_add_pattern(filter, "*.cor"); - gtk_file_filter_add_pattern(filter, "*.cif"); - gtk_file_filter_add_pattern(filter, "*.CIF"); - gtk_file_filter_add_pattern(filter, "*.mmcif"); - gtk_file_filter_add_pattern(filter, "*.mmCIF"); - gtk_file_filter_add_pattern(filter, "*.MMCIF"); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(opendialog), filter); - filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, "All files"); - gtk_file_filter_add_pattern(filter, "*"); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(opendialog), filter); - - if (prevname) { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(opendialog), prevname); - } - if (gtk_dialog_run(GTK_DIALOG(opendialog)) == GTK_RESPONSE_ACCEPT) { - if (prevname) - g_free(prevname); - prevname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(opendialog)); - strcpy(DataFileName, prevname); - if (FetchFile(FormatPDB, False, prevname)) { - char tmp[PATH_MAX + 10]; - - strcpy(tmp, "file://"); - if (realpath(prevname, tmp + 7)) { - rman = gtk_recent_manager_get_default(); - gtk_recent_manager_add_item(rman, tmp); - } - DefaultRepresentation(); - RefreshScreen(); - } else { - ; - } - } - - gtk_widget_destroy(opendialog); -} - -void save_cb(GtkAction * action, gpointer user_data) -{ - static char *prevname = NULL; - GtkWidget *dialog; - GtkWidget *question; - - dialog = gtk_file_chooser_dialog_new("Save to a PDB file", - GTK_WINDOW(mainwin), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); - if (prevname) { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), prevname); - gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(dialog)); - } - while (TRUE) { - if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) { - break; - } else { - if (prevname) - g_free(prevname); - prevname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - if (g_file_test(prevname, G_FILE_TEST_EXISTS)) { - gint resp; - question = - gtk_message_dialog_new(GTK_WINDOW(dialog), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "A file named \"%s\" already exists. Do you want to replace it?", - prevname); - resp = gtk_dialog_run(GTK_DIALOG(question)); - gtk_widget_destroy(question); - if (resp != GTK_RESPONSE_YES) { - continue; - } - } - SavePDBMolecule(prevname); - break; - } - } - gtk_widget_destroy(dialog); -} - -/* Render the current image to a given memory buffer with a given size */ -void render_buffer(Pixel * buf, int xsize, int ysize) -{ - Pixel *old_fbuffer; - int old_xrange, old_yrange, old_hrange, old_wrange, old_range, - old_interactive, dx; - - old_fbuffer = FBuffer; - old_xrange = XRange; - old_yrange = YRange; - FBuffer = buf; - XRange = xsize; - YRange = ysize; - - if ((dx = XRange % 4)) - XRange += 4 - dx; - - old_hrange = HRange; - old_wrange = WRange; - old_range = Range; - HRange = YRange >> 1; - WRange = XRange >> 1; - Range = MinFun(XRange, YRange); - - ReDrawFlag |= RFReSize; - old_interactive = Interactive; - Interactive = False; - RefreshScreen(); // *buf now contains the image - Interactive = old_interactive; - - FBuffer = old_fbuffer; - XRange = old_xrange; - YRange = old_yrange; - HRange = old_hrange; - WRange = old_wrange; - Range = old_range; - - ReDrawFlag |= RFReSize; - RefreshScreen(); - ReDrawFlag = NextReDrawFlag; -} - -gboolean sizespin_cb(GtkSpinButton button, gpointer data) -{ - GtkLabel *header = NULL; - char header_str[128]; - - if (gtk_toggle_button_get_active - (GTK_TOGGLE_BUTTON - (gtk_builder_get_object(sizebuilder, "size_custom")))) { - export_x = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON - (gtk_builder_get_object - (sizebuilder, "custom_x"))); - export_y = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON - (gtk_builder_get_object - (sizebuilder, "custom_y"))); - - header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); - snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); - gtk_label_set_text(header, header_str); - } - - return FALSE; -} - -gboolean sizeradio_cb(GtkButton * button, gpointer data) -{ - int radioid; - GtkLabel *header = NULL; - char header_str[128]; - - radioid = (int) data; - - export_x = XRange; - export_y = YRange; - - switch (radioid) { - case RADIO_CURRENT: - break; - case RADIO_640: - export_x = 640; - export_y = 480; - break; - case RADIO_1024: - export_x = 1024; - export_y = 768; - break; - case RADIO_1600: - export_x = 1600; - export_y = 1200; - break; - case RADIO_CUSTOM: - export_x = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON - (gtk_builder_get_object - (sizebuilder, "custom_x"))); - export_y = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON - (gtk_builder_get_object - (sizebuilder, "custom_y"))); - break; - default: - ; - } - - header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); - snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); - gtk_label_set_text(header, header_str); - - return FALSE; -} - - -#define SZ_RADIO_ADD(NAME, VAL) \ -rbut = GTK_RADIO_BUTTON(gtk_builder_get_object(sizebuilder, (NAME))); \ -g_signal_connect(G_OBJECT(rbut), "clicked", G_CALLBACK(sizeradio_cb), \ -((gpointer) (VAL))); - -void build_exportdialog(void) -{ - GError *err = NULL; - GtkRadioButton *rbut = NULL; - GtkWidget *size_chooser = NULL; - GtkWidget *extrabox = NULL; - int icoformat; - - exportdialog = gtk_file_chooser_dialog_new("Export image to a file", - GTK_WINDOW(mainwin), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, - GTK_RESPONSE_ACCEPT, NULL); - - format_chooser = egg_file_format_chooser_new(); - egg_file_format_chooser_add_pixbuf_formats(EGG_FILE_FORMAT_CHOOSER - (format_chooser), 0, NULL); - icoformat = - egg_file_format_chooser_get_format(EGG_FILE_FORMAT_CHOOSER - (format_chooser), "a.ico"); - egg_file_format_chooser_remove_format(EGG_FILE_FORMAT_CHOOSER - (format_chooser), icoformat); - - sizebuilder = gtk_builder_new(); - g_assert(sizebuilder); - if (!gtk_builder_add_from_string(sizebuilder, sizechooser_str, -1, &err)) { - g_message("building size chooser failed: s", err->message); - g_error_free(err); - exit(EXIT_FAILURE); - } - - SZ_RADIO_ADD("size_current", RADIO_CURRENT) - SZ_RADIO_ADD("size_640", RADIO_640) - SZ_RADIO_ADD("size_1024", RADIO_1024) - SZ_RADIO_ADD("size_1600", RADIO_1600) - SZ_RADIO_ADD("size_custom", RADIO_CUSTOM) - - g_signal_connect(gtk_builder_get_object(sizebuilder, "custom_x"), - "value-changed", G_CALLBACK(sizespin_cb), NULL); - g_signal_connect(gtk_builder_get_object(sizebuilder, "custom_y"), - "value-changed", G_CALLBACK(sizespin_cb), NULL); - - size_chooser = - GTK_WIDGET(gtk_builder_get_object(sizebuilder, "size_expander")); - - extrabox = gtk_vbox_new(FALSE, 0); - g_assert(extrabox); - gtk_box_pack_start(GTK_BOX(extrabox), format_chooser, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(extrabox), size_chooser, TRUE, TRUE, 10); - gtk_widget_show_all(extrabox); - - gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(exportdialog), - GTK_WIDGET(extrabox)); - - gtk_dialog_set_default_response(GTK_DIALOG(exportdialog), - GTK_RESPONSE_ACCEPT); - -} - -void export_cb(GtkAction * action, gpointer user_data) -{ - static char *fname = NULL; - - if (!exportdialog) { - build_exportdialog(); - } - if (fname) { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(exportdialog), fname); - gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(exportdialog)); - } - if (gtk_toggle_button_get_active - (GTK_TOGGLE_BUTTON - (gtk_builder_get_object(sizebuilder, "size_current")))) { - GtkLabel *header = NULL; - char header_str[128]; - - export_x = XRange; - export_y = YRange; - header = GTK_LABEL(gtk_builder_get_object(sizebuilder, "size_header")); - snprintf(header_str, 127, "Size: %d x %d", export_x, export_y); - gtk_label_set_text(header, header_str); - } - while (TRUE) { - GtkWidget *question; - GdkPixbuf *pbuf; - GError *err = NULL; - gboolean success = TRUE; - guint format = 0; - gchar *formatname = NULL; - GSList *tmplist = NULL; - guchar *tmpbuf; - - if (gtk_dialog_run(GTK_DIALOG(exportdialog)) != GTK_RESPONSE_ACCEPT) { - break; - } - - if (fname) { - g_free(fname); - } - fname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(exportdialog)); - if (g_file_test(fname, G_FILE_TEST_EXISTS)) { - gint resp; - question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "A file named \"%s\" already exists. Do you want to replace it?", - fname); - resp = gtk_dialog_run(GTK_DIALOG(question)); - gtk_widget_destroy(question); - if (resp != GTK_RESPONSE_YES) { - continue; - } - } - - format = - egg_file_format_chooser_get_format(EGG_FILE_FORMAT_CHOOSER - (format_chooser), fname); - if (!format) { - char *tmp; - question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - "Could not recognise format of output file \"%s\", please choose another format.", - ((tmp = - rindex(fname, - '/')) != - NULL) ? (tmp + 1) : (fname)); - gtk_dialog_run(GTK_DIALOG(question)); - gtk_widget_destroy(question); - continue; - } - formatname = - (gchar *) - egg_file_format_chooser_get_format_data(EGG_FILE_FORMAT_CHOOSER - (format_chooser), format); - - tmpbuf = g_new(guchar, 4 * export_x * export_y); - render_buffer((Pixel *) tmpbuf, export_x, export_y); - pbuf = gdk_pixbuf_new_from_data(tmpbuf, - GDK_COLORSPACE_RGB, - TRUE, 8, - export_x, export_y, 4 * export_x, - NULL, NULL); - success = gdk_pixbuf_save(pbuf, fname, formatname, &err, NULL); - - if (!success && (err != NULL)) { - question = gtk_message_dialog_new(GTK_WINDOW(exportdialog), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - "Error saving image: %s", - err->message); - gtk_dialog_run(GTK_DIALOG(question)); - gtk_widget_destroy(question); - } - g_object_unref(pbuf); - g_free(tmpbuf); - break; - } - gtk_widget_hide(exportdialog); -} - -void pagesetup_cb(GtkAction * action, gpointer user_data) -{ - if (print_pagesetup == NULL) { - print_pagesetup = gtk_page_setup_new(); - } - print_pagesetup = - gtk_print_run_page_setup_dialog(GTK_WINDOW(mainwin), print_pagesetup, - print_settings); -} - - -/* Shuffle bytes from gdk_draw_rgb_32_image format to cairo rgb format */ -void rgb_convert(guint8 * buf, int len) -{ - int i; - guint8 r, g, b; - - for (i = 0; i < 4 * len; i += 4) { - r = buf[i + 0]; - g = buf[i + 1]; - b = buf[i + 2]; - buf[i + 0] = b; - buf[i + 1] = g; - buf[i + 2] = r; - buf[i + 3] = 0xff; - } -} - - -void print_draw(GtkPrintOperation * printop, GtkPrintContext * context, - gint pageno, gpointer user_data) -{ - cairo_t *cr; - cairo_surface_t *sur; - cairo_pattern_t *pat; - cairo_matrix_t mat; - gdouble width, height; - guchar *tmpbuf; - int print_x, print_y; - gdouble scale; - - width = gtk_print_context_get_width(context); // in mm - height = gtk_print_context_get_height(context); - - switch (print_resolution) { - case RES_150: - print_x = (int) (150.0 / 25.4 * width); - print_y = (int) (150.0 / 25.5 * height); - break; - case RES_300: - print_x = (int) (300.0 / 25.4 * width); - print_y = (int) (300.0 / 25.4 * height); - break; - default: - print_x = XRange; - print_y = YRange; - break; - } - - print_x &= ~3; - print_y &= ~3; - - tmpbuf = g_new(guchar, 4 * print_x * print_y); - render_buffer((Pixel *) tmpbuf, print_x, print_y); - rgb_convert((guint8 *) tmpbuf, print_x * print_y); - - cr = gtk_print_context_get_cairo_context(context); - sur = cairo_image_surface_create_for_data((unsigned char *) tmpbuf, - CAIRO_FORMAT_RGB24, print_x, - print_y, 4 * print_x); - pat = cairo_pattern_create_for_surface(sur); - scale = ((gdouble) print_x) / width; - cairo_matrix_init_scale(&mat, scale, scale); - cairo_pattern_set_matrix(pat, &mat); - cairo_set_source(cr, pat); - cairo_rectangle(cr, 0, 0, width, height); - cairo_fill(cr); - - cairo_pattern_destroy(pat); - cairo_surface_destroy(sur); - g_free(tmpbuf); -} - -void print_get_res_cb(GtkPrintOperation * print, GtkWidget * widget, - gpointer rb) -{ - GSList *el; - - el = gtk_radio_button_get_group(*((GtkRadioButton **) rb)); - while (el != NULL) { - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(el->data))) { - print_resolution = - (int) g_object_get_data(G_OBJECT(el->data), "res"); - return; - } else - el = el->next; - } - return; -} - -GObject *print_build_reswidget_cb(GtkPrintOperation * operation, - gpointer radio_p) -{ - GtkBuilder *b = NULL; - GObject *widget = NULL; - GError *err = NULL; - GObject *r = NULL; - - b = gtk_builder_new(); - if (!gtk_builder_add_from_string(b, print_resolution_str, -1, &err)) { - g_message("building size chooser failed: s", err->message); - g_error_free(err); - exit(EXIT_FAILURE); - } - r = gtk_builder_get_object(b, "res_radio1"); - g_object_set_data(r, "res", (gpointer) RES_CURRENT); - if (print_resolution == RES_CURRENT) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(r), TRUE); - r = gtk_builder_get_object(b, "res_radio2"); - g_object_set_data(r, "res", (gpointer) RES_150); - if (print_resolution == RES_150) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(r), TRUE); - r = gtk_builder_get_object(b, "res_radio3"); - g_object_set_data(r, "res", (gpointer) RES_300); - if (print_resolution == RES_300) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(r), TRUE); - *((GObject **) radio_p) = r; - - widget = gtk_builder_get_object(b, "resframe"); - g_assert(widget != NULL); - - return widget; -} - -void print_cb(GtkAction * action, gpointer user_data) -{ - GtkPrintOperation *print; - GtkPrintOperationResult res; - GtkToggleButton *radio = NULL; - - print = gtk_print_operation_new(); - gtk_print_operation_set_n_pages(print, 1); - gtk_print_operation_set_custom_tab_label(print, "Resolution"); - gtk_print_operation_set_unit(print, GTK_UNIT_MM); - - g_signal_connect(print, "draw_page", G_CALLBACK(print_draw), NULL); - g_signal_connect(print, "create-custom-widget", - G_CALLBACK(print_build_reswidget_cb), &radio); - g_signal_connect(print, "custom-widget-apply", - G_CALLBACK(print_get_res_cb), &radio); - - if (print_pagesetup != NULL) - gtk_print_operation_set_default_page_setup(print, print_pagesetup); - if (print_settings != NULL) - gtk_print_operation_set_print_settings(print, print_settings); - - res = gtk_print_operation_run(print, - GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, - GTK_WINDOW(mainwin), NULL); - - if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { - if (print_settings != NULL) - g_object_unref(print_settings); - print_settings = - g_object_ref(gtk_print_operation_get_print_settings(print)); - } - - g_object_unref(print); -} - - -void DisplayAboutDLG(void) -{ - -} - -void about_cb(GtkAction * action, gpointer user_data) -{ - gchar *authors[] = { "Roger Sayle", NULL }; - gtk_show_about_dialog(GTK_WINDOW(mainwin), - "authors", authors, - "comments", "Molecular Renderer", - "copyright", "Copyright (C)\n\ -Roger Sayle 1992-1999\n\ -Herbert J. Bernstein 1998-2008\n\ -", "license", "GPL", "logo-icon-name", "/usr/share/pixmaps/rasmol.xpm", "version", VERSION, "website", "http://rasmol.org/", NULL); -} - -void build_window(void) -{ - GList *vlist; - GtkAction *a; - gint x, y; - - vlist = gtk_container_get_children(GTK_CONTAINER(mainvbox)); - while (vlist) { - g_object_ref(vlist->data); - gtk_container_remove(GTK_CONTAINER(mainvbox), GTK_WIDGET(vlist->data)); - vlist = vlist->next; - } - - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/ViewMenu/Menus"); - if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(a))) { - gtk_box_pack_start(GTK_BOX(mainvbox), menubar, FALSE, FALSE, 0); - } - - vlist = gtk_container_get_children(GTK_CONTAINER(ctable)); - while (vlist) { - g_object_ref(vlist->data); - gtk_container_remove(GTK_CONTAINER(ctable), GTK_WIDGET(vlist->data)); - vlist = vlist->next; - } - gtk_table_attach(GTK_TABLE(ctable), canvasarea, 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/ViewMenu/Scrolls"); - if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(a))) { - gtk_table_attach(GTK_TABLE(ctable), vscrollbar, 1, 2, 0, 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); - gtk_table_attach(GTK_TABLE(ctable), hscrollbar, 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); - } - - vlist = gtk_container_get_children(GTK_CONTAINER(mainvpane)); - while (vlist) { - g_object_ref(vlist->data); - gtk_container_remove(GTK_CONTAINER(mainvpane), - GTK_WIDGET(vlist->data)); - vlist = vlist->next; - } - - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/ViewMenu/Command"); - if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(a))) { - gtk_window_get_size(GTK_WINDOW(mainwin), &x, &y); - gtk_paned_set_position(GTK_PANED(mainvpane), y - 200); - gtk_paned_pack1(GTK_PANED(mainvpane), ctable, TRUE, TRUE); - gtk_paned_pack2(GTK_PANED(mainvpane), termhbox, FALSE, TRUE); - gtk_box_pack_start(GTK_BOX(mainvbox), mainvpane, TRUE, TRUE, 0); - } else { - gtk_box_pack_start(GTK_BOX(mainvbox), ctable, TRUE, TRUE, 0); - } - gtk_adjustment_value_changed(VTE_TERMINAL(vte)->adjustment); - gtk_widget_show_all(mainvbox); - - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/ViewMenu/Fullscreen"); - if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(a))) { - gtk_window_fullscreen(GTK_WINDOW(mainwin)); - } else { - gtk_window_unfullscreen(GTK_WINDOW(mainwin)); - } -} - - -void view_cb(GtkAction * action, gpointer user_data) -{ - build_window(); -} - - -void set_ui_elements(int mask) -{ - GtkAction *a; - - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/ViewMenu/Command"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(a), mask & UI_COMMAND); - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/ViewMenu/Scrolls"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(a), mask & UI_SCROLLS); - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/ViewMenu/Menus"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(a), mask & UI_MENUS); - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/ViewMenu/Fullscreen"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(a), mask & UI_FULLSCREEN); - build_window(); -} - - -void setfont_cb(GtkAction * action, gpointer user_data) -{ - static char *fontname = NULL; - GtkWidget *d; - gint result; - - d = gtk_font_selection_dialog_new("Command prompt font"); - if (fontname) - gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(d), - fontname); - - result = gtk_dialog_run(GTK_DIALOG(d)); - if (result == GTK_RESPONSE_OK) { - fontname = - gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG - (d)); - vte_terminal_set_font_from_string(VTE_TERMINAL(vte), fontname); - } - gtk_widget_destroy(d); -} - -void recent_cb(GtkAction * recent, gpointer user_data) -{ - gchar *uri; - - uri = gtk_recent_chooser_get_current_uri(GTK_RECENT_CHOOSER(recent)); - if (strncmp(uri, "file:", 5) == 0) { - strcpy(DataFileName, uri + 5); - FetchFile(FormatPDB, False, uri + 5); - DefaultRepresentation(); - RefreshScreen(); - } -} - -static const GtkActionEntry menuentries[] = { - {"FileMenu", NULL, "_File"}, - {"Open", GTK_STOCK_OPEN, "_Open...", "O", "Open a file", - G_CALLBACK(open_cb)}, - {"SaveAs", GTK_STOCK_SAVE_AS, "_Save As...", "S", "Save a file", - G_CALLBACK(save_cb)}, - {"Export", GTK_STOCK_CONVERT, "_Export...", "X", - "Export current image", G_CALLBACK(export_cb)}, - {"Close", GTK_STOCK_CLOSE, "_Close", "W", - "Close the selected molecule", NULL}, - {"PageSetup", NULL, "Page Set_up...", "", "Set the page parameters", - G_CALLBACK(pagesetup_cb)}, - {"Print", GTK_STOCK_PRINT, "_Print...", "P", - "Print the current image", G_CALLBACK(print_cb)}, - {"Exit", GTK_STOCK_QUIT, "E_xit", "Q", "Exit the program", - RasMolExit}, - {"ViewMenu", NULL, "_View"}, - {"Setfont", NULL, "Set command font...", "", "", G_CALLBACK(setfont_cb)}, - {"DispMenu", NULL, "_Display"}, - {"Wireframe", NULL, "_Wireframe", "", "", NULL}, - {"Backbone", NULL, "_Backbone", "", "", NULL}, - {"Sticks", NULL, "S_ticks", "", "", NULL}, - {"Spheres", NULL, "_Spacefill", "", "", NULL}, - {"Ballstick", NULL, "B_all & stick", "", "", NULL}, - {"Ribbons", NULL, "_Ribbons", "", "", NULL}, - {"Strands", NULL, "Stran_ds", "", "", NULL}, - {"Cartoons", NULL, "_Cartoons", "", "", NULL}, - {"MolSurf", NULL, "_Molecular Surface", "", "", NULL}, - {"ColMenu", NULL, "_Colours"}, - {"Monochrome", NULL, "_Monochrome", "", "", NULL}, - {"CPK", NULL, "_CPK", "", "", NULL}, - {"Shapely", NULL, "_Shapely", "", "", NULL}, - {"Group", NULL, "_Group", "", "", NULL}, - {"Chain", NULL, "C_hain", "", "", NULL}, - {"Temperature", NULL, "_Temperature", "", "", NULL}, - {"Structure", NULL, "St_ructure", "", "", NULL}, - {"User", NULL, "_User", "", "", NULL}, - {"Model", NULL, "Mo_del", "", "", NULL}, - {"Alt", NULL, "_Alt", "", "", NULL}, - {"OptMenu", NULL, "_Options"}, - {"SetMenu", NULL, "_Settings"}, - {"HelpMenu", NULL, "_Help"}, - {"Manual", GTK_STOCK_HELP, "_User Manual", "F1", "", NULL}, - {"Register", NULL, "_Register", "", "", NULL}, - {"Donate", NULL, "_Donate", "", "", NULL}, - {"About", GTK_STOCK_ABOUT, "_About", "", "", G_CALLBACK(about_cb)}, -}; - -static const GtkToggleActionEntry view_toggles[] = { - {"Command", NULL, "_Command prompt", "F7", "", NULL, FALSE}, - {"Scrolls", NULL, "_Scrollbars", "F8", "", NULL, FALSE}, - {"Menus", NULL, "_Menubar", "F9", "", NULL, TRUE}, - {"Fullscreen", NULL, "_Full Screen", "F11", "", NULL, FALSE}, -}; - -static const GtkToggleActionEntry opt_toggles[] = { - {"Slab", NULL, "_Slab Mode", "", "", NULL, FALSE}, - {"Hydrogens", NULL, "Hy_drogens", "", "", NULL, FALSE}, - {"Heteros", NULL, "He_tero Atoms", "", "", NULL, FALSE}, - {"Specular", NULL, "Spe_cular", "", "", NULL, FALSE}, - {"Shadows", NULL, "S_hadows", "", "", NULL, FALSE}, - {"Stereo", NULL, "Stere_o", "", "", NULL, FALSE}, - {"Labels", NULL, "_Labels", "", "", NULL, FALSE} -}; - -static const GtkRadioActionEntry pick_radios[] = { - {"POff", NULL, "Pick _Off", "", "", m_s_poff}, - {"PIdent", NULL, "Pick _Ident", "", "", m_s_pident}, - {"PDistance", NULL, "Pick _Distance", "", "", m_s_pdist}, - {"PMonitor", NULL, "_Pick Monitor", "", "", m_s_pmon}, - {"PAngle", NULL, "Pick _Angle", "", "", m_s_pangle}, - {"PTorsion", NULL, "Pick _Torsion", "", "", m_s_ptorsion}, - {"PLabel", NULL, "Pick _Label", "", "", m_s_plabel}, - {"PCentre", NULL, "Pick _Centre", "", "", m_s_pcentre}, - {"PCoord", NULL, "Pick C_oord", "", "", m_s_pcoord}, - {"PBond", NULL, "Pick _Bond", "", "", m_s_pbond}, -}; - -static const GtkRadioActionEntry rot_radios[] = { - {"RBond", NULL, "_Rotate Bond ", "", "", m_s_rbond}, - {"RMol", NULL, "Rotate _Mol ", "", "", m_s_rmol}, - {"RAll", NULL, "Rotate _All ", "", "", m_s_rall}, -}; - -GtkActionGroup *ofiles_group; - -void EnableRotBondMenu(int rot_enable) -{ - GtkAction *a; - - a = gtk_ui_manager_get_action(ui_manager, "/MainMenu/SetMenu/RBond"); - if (rot_enable) { - gtk_action_set_sensitive(a, TRUE); - } else { - if (gtk_toggle_action_get_active((GtkToggleAction *) a)) - gtk_toggle_action_set_active((GtkToggleAction *) - gtk_ui_manager_get_action(ui_manager, - "/MainMenu/SetMenu/RMol"), - TRUE); - gtk_action_set_sensitive(a, FALSE); - } -} - -void set_gtk_open_file(int index) -{ - GList *alist; - GtkRadioAction *radact; - - alist = gtk_action_group_list_actions(ofiles_group); - if (alist && alist->data) { - radact = (GtkRadioAction *) alist->data; - g_signal_handlers_block_by_func(radact, radio_cb, NULL); - gtk_radio_action_set_current_value(radact, m_ofiles + index); - g_signal_handlers_unblock_by_func(radact, radio_cb, NULL); - } - g_list_free(alist); -} - - -void UpdateGtkMoleculeList(void) -{ - int i; - char itemname[4]; - char itlabel[2 * MAX_MOLNAME + 1]; - GList *alist, *ahead; - GSList *group = NULL; - GtkRadioAction *rad; - GError *err = NULL; - GRegex *re = NULL; - - gtk_ui_manager_remove_ui(ui_manager, merge_id); - merge_id = gtk_ui_manager_new_merge_id(ui_manager); - - alist = gtk_action_group_list_actions(ofiles_group); - ahead = alist; - while (alist) { - gtk_action_group_remove_action(ofiles_group, - (GtkAction *) alist->data); - alist = alist->next; - } - g_list_free(ahead); - - itlabel[2 * MAX_MOLNAME] = '\0'; - re = g_regex_new("[_]", 0, 0, &err); - for (i = 0; i < NumMolecules; i++) { - gchar *rep; - // GTK menu labels use the underscore for accelerator, replace w. __ - rep = g_regex_replace_literal(re, MolNStr[i], -1, 0, "__", 0, &err); - strncpy((itlabel + 1), rep, 2 * MAX_MOLNAME); - g_free(rep); - itlabel[0] = '_'; - snprintf(itemname, 3, "%d", i); - rad = gtk_radio_action_new(itemname, itlabel, NULL, NULL, - (m_ofiles + i)); - gtk_radio_action_set_group(rad, group); - group = gtk_radio_action_get_group(rad); - if (i == MoleculeIndex) - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(rad), TRUE); - gtk_action_group_add_action(ofiles_group, (GtkAction *) rad); - g_object_unref(rad); - } - g_regex_unref(re); - - alist = gtk_action_group_list_actions(ofiles_group); - if (alist) { - g_signal_connect(alist->data, "changed", G_CALLBACK(radio_cb), NULL); - } - g_list_free(alist); - - for (i = 0; i < NumMolecules; i++) { - snprintf(itemname, 3, "%d", i); - gtk_ui_manager_add_ui(ui_manager, merge_id, - "/MainMenu/FileMenu/OFiles", itemname, - itemname, GTK_UI_MANAGER_MENUITEM, FALSE); - gtk_ui_manager_add_ui(ui_manager, merge_id, "/popup/OFiles", - itemname, itemname, - GTK_UI_MANAGER_MENUITEM, FALSE); - } - - gtk_ui_manager_ensure_update(ui_manager); -} - - -GtkWidget *build_gtkmenu(void) -{ - GError *error; - GtkAction *recentaction = NULL; - GtkRecentFilter *filter = NULL; - int i; - - action_group = gtk_action_group_new("MenuActions"); - gtk_action_group_add_actions(action_group, menuentries, - G_N_ELEMENTS(menuentries), NULL); - - recentaction = gtk_recent_action_new("Recent", "Open _Recent", - "Open a recently opened file", NULL); - filter = gtk_recent_filter_new(); - gtk_recent_filter_add_application(filter, "RasMol"); - gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(recentaction), filter); - gtk_recent_chooser_set_local_only(GTK_RECENT_CHOOSER(recentaction), TRUE); - gtk_recent_chooser_set_sort_type(GTK_RECENT_CHOOSER(recentaction), - GTK_RECENT_SORT_MRU); - gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER(recentaction), 30); - g_signal_connect(GTK_RECENT_CHOOSER(recentaction), "item-activated", - G_CALLBACK(recent_cb), NULL); - gtk_action_group_add_action(action_group, recentaction); - - gtk_action_group_add_toggle_actions(action_group, view_toggles, - G_N_ELEMENTS(view_toggles), NULL); - gtk_action_group_add_toggle_actions(action_group, opt_toggles, - G_N_ELEMENTS(opt_toggles), NULL); - gtk_action_group_add_radio_actions(action_group, pick_radios, - G_N_ELEMENTS(pick_radios), m_s_pident, - G_CALLBACK(radio_cb), NULL); - gtk_action_group_add_radio_actions(action_group, rot_radios, - G_N_ELEMENTS(rot_radios), m_s_rmol, - G_CALLBACK(radio_cb), NULL); - - ui_manager = gtk_ui_manager_new(); - gtk_ui_manager_insert_action_group(ui_manager, action_group, 0); - - accel_group = gtk_ui_manager_get_accel_group(ui_manager); - gtk_window_add_accel_group(GTK_WINDOW(mainwin), accel_group); - - error = NULL; - if (!gtk_ui_manager_add_ui_from_string(ui_manager, actionmenu_str, - -1, &error)) { - g_message("building menus failed: s", error->message); - g_error_free(error); - exit(EXIT_FAILURE); - } - - EnableRotBondMenu(False); - - ADDSIGNAL("/MainMenu/FileMenu/Close", m_f_close); - ADDSIGNAL("/MainMenu/DispMenu/Wireframe", m_d_wireframe); - ADDSIGNAL("/MainMenu/DispMenu/Backbone", m_d_backbone); - ADDSIGNAL("/MainMenu/DispMenu/Sticks", m_d_sticks); - ADDSIGNAL("/MainMenu/DispMenu/Spheres", m_d_spheres); - ADDSIGNAL("/MainMenu/DispMenu/Ballstick", m_d_ballstick); - ADDSIGNAL("/MainMenu/DispMenu/Ribbons", m_d_ribbons); - ADDSIGNAL("/MainMenu/DispMenu/Strands", m_d_strands); - ADDSIGNAL("/MainMenu/DispMenu/Cartoons", m_d_cartoons); - ADDSIGNAL("/MainMenu/DispMenu/MolSurf", m_d_molsurf); - ADDSIGNAL("/MainMenu/ColMenu/Monochrome", m_c_monochrome); - ADDSIGNAL("/MainMenu/ColMenu/CPK", m_c_cpk); - ADDSIGNAL("/MainMenu/ColMenu/Shapely", m_c_shapely); - ADDSIGNAL("/MainMenu/ColMenu/Group", m_c_group); - ADDSIGNAL("/MainMenu/ColMenu/Chain", m_c_chain); - ADDSIGNAL("/MainMenu/ColMenu/Temperature", m_c_temperature); - ADDSIGNAL("/MainMenu/ColMenu/Structure", m_c_structure); - ADDSIGNAL("/MainMenu/ColMenu/User", m_c_user); - ADDSIGNAL("/MainMenu/ColMenu/Model", m_c_model); - ADDSIGNAL("/MainMenu/ColMenu/Alt", m_c_alt); - ADDSIGNAL("/MainMenu/OptMenu/Slab", m_o_slab); - ADDSIGNAL("/MainMenu/OptMenu/Hydrogens", m_o_hydrogens); - ADDSIGNAL("/MainMenu/OptMenu/Heteros", m_o_heteros); - ADDSIGNAL("/MainMenu/OptMenu/Specular", m_o_specular); - ADDSIGNAL("/MainMenu/OptMenu/Shadows", m_o_shadows); - ADDSIGNAL("/MainMenu/OptMenu/Stereo", m_o_stereo); - ADDSIGNAL("/MainMenu/OptMenu/Labels", m_o_labels); - ADDSIGNAL("/MainMenu/HelpMenu/Manual", m_h_manual); - ADDSIGNAL("/MainMenu/HelpMenu/Register", m_h_register); - ADDSIGNAL("/MainMenu/HelpMenu/Donate", m_h_donate); - - g_signal_connect(gtk_ui_manager_get_action - (ui_manager, "/MainMenu/ViewMenu/Command"), "activate", - G_CALLBACK(view_cb), NULL); - g_signal_connect(gtk_ui_manager_get_action - (ui_manager, "/MainMenu/ViewMenu/Scrolls"), "activate", - G_CALLBACK(view_cb), NULL); - g_signal_connect(gtk_ui_manager_get_action - (ui_manager, "/MainMenu/ViewMenu/Menus"), "activate", - G_CALLBACK(view_cb), NULL); - g_signal_connect(gtk_ui_manager_get_action - (ui_manager, "/MainMenu/ViewMenu/Fullscreen"), "activate", - G_CALLBACK(view_cb), NULL); - - /* merge id for filemenu additions */ - merge_id = gtk_ui_manager_new_merge_id(ui_manager); - ofiles_group = gtk_action_group_new("OFileActions"); - gtk_ui_manager_insert_action_group(ui_manager, ofiles_group, 1); - - menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu"); - - return menubar; -} - - -static void do_popup_menu(GtkWidget * widget, GdkEventButton * event) -{ - GtkWidget *menu; - int button, event_time; - - menu = gtk_ui_manager_get_widget(ui_manager, "/popup"); - g_signal_connect(menu, "deactivate", G_CALLBACK(gtk_widget_hide), NULL); - - if (event) { - button = event->button; - event_time = event->time; - } else { - button = 0; - event_time = gtk_get_current_event_time(); - } - - gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, event_time); -} - - -void AllocateColourMap(void) -{ - GdkColor Col; - static ByteTest buf; - register Byte temp; - register int i; - - for (i = 0; i < LutSize; i++) - if (ULut[i]) { - /* This is the correct byteorder for gdk_draw_rgb_32_image */ - Col.pixel = - (RLut[i] << 24) | (GLut[i] << 16) | (BLut[i] << 8) | 0xFF; - if (SwapBytes) { - buf.longword = (Long) Col.pixel; - temp = buf.bytes[0]; - buf.bytes[0] = buf.bytes[3]; - buf.bytes[3] = temp; - - temp = buf.bytes[1]; - buf.bytes[1] = buf.bytes[2]; - buf.bytes[2] = temp; - Lut[i] = buf.longword; - } else - Lut[i] = (Long) Col.pixel; - } -} - - -int FetchEvent(int wait) -{ - return 0; -} - -void UpdateScrollBars(void) -{ - gdouble new, old; - - if (RotMode == RotAll) { - new = WorldDialValue[YScrlDial]; - } else { - new = DialValue[YScrlDial]; - } - old = gtk_range_get_value(GTK_RANGE(vscrollbar)); - - if (new != old) { - g_signal_handler_block(G_OBJECT(vscrollbar), vscr_handler); - gtk_range_set_value(GTK_RANGE(vscrollbar), new); - g_signal_handler_unblock(G_OBJECT(vscrollbar), vscr_handler); - } - - if ((RotMode == RotBond) && BondSelected) { - new = BondSelected->BRotValue; - } else { - if (RotMode == RotAll) { - new = WorldDialValue[XScrlDial]; - } else { - new = DialValue[XScrlDial]; - } - } - old = gtk_range_get_value(GTK_RANGE(hscrollbar)); - - if (new != old) { - g_signal_handler_block(G_OBJECT(hscrollbar), hscr_handler); - gtk_range_set_value(GTK_RANGE(hscrollbar), new); - g_signal_handler_unblock(G_OBJECT(hscrollbar), hscr_handler); - } - -} - -void EnableMenus(int flag) -{ - DisableMenu = !flag; -} - -int LookUpColour(char *name, int *red, int *grn, int *blu) -{ - return False; -} - - -void ReDrawWindow(void) -{ - build_window(); -} - - -void TransferImage(void) -{ - gdk_draw_rgb_32_image(canvasarea->window, - canvasarea->style->fg_gc[GTK_STATE_NORMAL], - 0, 0, XRange, YRange, - GDK_RGB_DITHER_NONE, (guchar *) FBuffer, XRange * 4); -} - -void SetMouseCaptureStatus(int bool) -{ - MouseCaptureStatus = bool; -} - - -static int GetStatus(int mask) -{ - register int status; - - status = 0; - if (mask & GDK_BUTTON1_MASK) - status |= MMLft; - if (mask & GDK_BUTTON2_MASK) - status |= MMMid; - if (mask & GDK_BUTTON3_MASK) - status |= MMRgt; - if (mask & GDK_CONTROL_MASK) - status |= MMCtl; - if (mask & GDK_SHIFT_MASK) - status |= MMSft; - return status; -} - - -gboolean expose_cb(GtkWidget * widget, GdkEventExpose * event, - gpointer user_data) -{ - TransferImage(); - return FALSE; -} - - -gboolean configure_cb(GtkWidget * widget, GdkEventConfigure * event, - gpointer user_data) -{ - int dx; - - XRange = event->width; - YRange = event->height; - ZRange = 20000; - - if ((dx = XRange % 4)) - XRange += 4 - dx; - - HRange = YRange >> 1; - WRange = XRange >> 1; - Range = MinFun(XRange, YRange); - - gtk_widget_set_size_request(widget, XRange, YRange); - - ReDrawFlag |= RFReSize; - RefreshScreen(); - ReDrawFlag = NextReDrawFlag; - - return FALSE; -} - - -void vscroll_cb(GtkRange * range, gpointer user_data) -{ - WorldDialValue[YScrlDial] = gtk_range_get_value(range); - ReDrawFlag |= (1 << YScrlDial); - RefreshScreen(); - ReDrawFlag = NextReDrawFlag; -} - -void hscroll_cb(GtkRange * range, gpointer user_data) -{ - gdouble val; - - val = gtk_range_get_value(range); - if ((RotMode == RotBond) && BondSelected) { - BondSelected->BRotValue = val; - ReDrawFlag |= RFRotBond; - } else { - WorldDialValue[XScrlDial] = val; - ReDrawFlag |= (1 << XScrlDial); - } - RefreshScreen(); - ReDrawFlag = NextReDrawFlag; -} - -static gboolean popup_cb(GtkWidget * widget) -{ - do_popup_menu(widget, NULL); - return TRUE; -} - -gboolean motion_cb(GtkWidget * canvas, GdkEventMotion * event, - gpointer user_data) -{ - int stat, x, y, xorig, yorig; - GdkModifierType mask; - - dragging = TRUE; - stat = GetStatus(event->state); - ProcessMouseMove(event->x, event->y, stat); - if (ReDrawFlag) { - RefreshScreen(); - ReDrawFlag = NextReDrawFlag; - } - xorig = event->x; - yorig = event->y; - gdk_window_get_pointer(canvas->window, &x, &y, &mask); - - return FALSE; -} - -gboolean button_press_cb(GtkWidget * canvas, GdkEventButton * event, - gpointer user_data) -{ - int stat; - - HeldButton = -1; - stat = GetStatus(event->state); - ProcessMouseDown(event->x, event->y, stat); - return FALSE; -} - -gboolean button_release_cb(GtkWidget * canvas, GdkEventButton * event, - gpointer user_data) -{ - int stat; - - if (!dragging && event->button == 3 && event->type == GDK_BUTTON_RELEASE - && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) { - do_popup_menu(canvas, event); - } else { - stat = GetStatus(event->state); - ProcessMouseUp(event->x, event->y, stat); - } - if (ReDrawFlag) { - RefreshScreen(); - } - dragging = FALSE; - - return TRUE; -} - - -void do_char(char c) -{ - if (ProcessCharacter(c)) { - if (ProcessCommand()) - RasMolExit(); - if (!CommandActive) { - ResetCommandLine(0); - RefreshScreen(); - ReDrawFlag = NextReDrawFlag; - } - } -} - - -void termin_cb(VteTerminal * vte, gchar * str, guint len, gpointer user_data) -{ - int i; - gchar buf; - static char prev = 0; - - /* Map xterm escape sequences to ASCII control chars */ - for (i = 0; i < len; i++) { - buf = str[i]; - switch (prev) { - case '\0': - if (buf != 0x1b) { - do_char(buf); - prev = '\0'; - } else { - prev = 0x1b; - } - break; - case 0x1b: - if ((buf != '[') && (buf != 'O')) { - do_char(buf); - prev = '\0'; - } else { - prev = buf; - } - break; - case '[': - case 'O': - switch (buf) { - /* Arrow keys */ - case ('A'): - do_char(0x10); - break; - case ('B'): - do_char(0x0e); - break; - case ('C'): - do_char(0x06); - break; - case ('D'): - do_char(0x02); - break; - /* Delete */ - case ('3'): - do_char(0x04); - i++; - break; - /* Ignore the rest */ - default: - i = len; - } - prev = '\0'; - } - } -} - - -void WriteChar(int ch) -{ - char buf[3]; - - switch (ch) { - case ('\n'): - buf[0] = '\n'; - buf[1] = '\r'; - buf[2] = '\0'; - vte_terminal_feed(VTE_TERMINAL(vte), buf, 2); - break; - default: - buf[0] = ch; - buf[1] = '\0'; - vte_terminal_feed(VTE_TERMINAL(vte), buf, 1); - } -} - - -void WriteString(char *ptr) -{ - while (*ptr) - WriteChar(*ptr++); -} - - -int OpenDisplay(void) -{ -#ifdef THIRTYTWOBIT - static ByteTest test; -#endif - int i; - static char VersionStr[50]; - GError *gerr = NULL; - - sprintf(VersionStr, "RasMol Version %s", VERSION); - - for (i = 0; i < 11; i++) - DialValue[i] = 0.0; - - RLut[0] = 0; - GLut[0] = 0; - BLut[0] = 0; - ULut[0] = True; - RLut[1] = 100; - GLut[1] = 100; - BLut[1] = 100; - ULut[1] = True; - RLut[2] = 150; - GLut[2] = 150; - BLut[2] = 150; - ULut[2] = True; - RLut[3] = 200; - GLut[3] = 200; - BLut[3] = 200; - ULut[3] = True; - RLut[4] = 255; - GLut[4] = 255; - BLut[4] = 255; - ULut[4] = True; - - XRange = DefaultWide; - YRange = DefaultHigh; - if (InitWidth >= RASGTK_MINWIDTH) - XRange = InitWidth; - if (InitHeight >= RASGTK_MINHEIGHT) - YRange = InitHeight; - WRange = XRange >> 1; - HRange = YRange >> 1; - Range = MinFun(XRange, YRange); - - if (!Interactive) - return (False); - - g_set_application_name("RasMol"); - mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_widget_add_events(mainwin, GDK_KEY_PRESS_MASK); - g_signal_connect(mainwin, "delete-event", G_CALLBACK(RasMolExit), NULL); - - menubar = build_gtkmenu(); - - mainvbox = gtk_vbox_new(FALSE, 0); - - ctable = gtk_table_new(2, 2, FALSE); - - canvasarea = gtk_drawing_area_new(); - gtk_widget_add_events(canvasarea, GDK_POINTER_MOTION_HINT_MASK); - gtk_widget_add_events(canvasarea, GDK_BUTTON_PRESS_MASK); - gtk_widget_add_events(canvasarea, GDK_BUTTON_RELEASE_MASK); - gtk_widget_add_events(canvasarea, GDK_BUTTON_MOTION_MASK); - g_signal_connect(G_OBJECT(canvasarea), "expose-event", - G_CALLBACK(expose_cb), NULL); - g_signal_connect(G_OBJECT(canvasarea), "configure-event", - G_CALLBACK(configure_cb), NULL); - g_signal_connect(G_OBJECT(canvasarea), "motion-notify-event", - G_CALLBACK(motion_cb), NULL); - g_signal_connect(G_OBJECT(canvasarea), "button-press-event", - G_CALLBACK(button_press_cb), NULL); - g_signal_connect(G_OBJECT(canvasarea), "button-release-event", - G_CALLBACK(button_release_cb), NULL); - g_signal_connect(G_OBJECT(canvasarea), "popup-menu", - G_CALLBACK(popup_cb), NULL); - - vscrollbar = gtk_vscrollbar_new(NULL); - gtk_range_set_update_policy(GTK_RANGE(vscrollbar), GTK_UPDATE_CONTINUOUS); - gtk_range_set_range(GTK_RANGE(vscrollbar), -1.0, 1.0); - gtk_range_set_increments(GTK_RANGE(vscrollbar), 0.01, 0.1); - vscr_handler = g_signal_connect(G_OBJECT(vscrollbar), "value-changed", - G_CALLBACK(vscroll_cb), NULL); - - hscrollbar = gtk_hscrollbar_new(NULL); - gtk_range_set_update_policy(GTK_RANGE(hscrollbar), GTK_UPDATE_CONTINUOUS); - gtk_range_set_range(GTK_RANGE(hscrollbar), -1.0, 1.0); - gtk_range_set_increments(GTK_RANGE(hscrollbar), 0.01, 0.1); - hscr_handler = g_signal_connect(G_OBJECT(hscrollbar), "value-changed", - G_CALLBACK(hscroll_cb), NULL); - - vte = vte_terminal_new(); - g_assert(vte); - vte_terminal_set_size(VTE_TERMINAL(vte), 80, 10); - vte_terminal_set_font_from_string(VTE_TERMINAL(vte), "Monospace 10"); - vte_terminal_set_scroll_on_output(VTE_TERMINAL(vte), TRUE); - vte_terminal_set_backspace_binding(VTE_TERMINAL(vte), - VTE_ERASE_ASCII_BACKSPACE); - vte_terminal_set_delete_binding(VTE_TERMINAL(vte), - VTE_ERASE_DELETE_SEQUENCE); - g_signal_connect(G_OBJECT(vte), "commit", G_CALLBACK(termin_cb), NULL); - - termhbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(termhbox), vte, TRUE, TRUE, 0); - - GtkWidget *termscroll; - termscroll = gtk_vscrollbar_new(VTE_TERMINAL(vte)->adjustment); - gtk_box_pack_start(GTK_BOX(termhbox), termscroll, FALSE, FALSE, 0); - - mainvpane = gtk_vpaned_new(); - - build_window(); - - GdkGeometry geo; - geo.min_width = RASGTK_MINWIDTH; - geo.min_height = RASGTK_MINHEIGHT; - gtk_window_set_geometry_hints(GTK_WINDOW(mainwin), GTK_WIDGET(mainvbox), - &geo, GDK_HINT_MIN_SIZE); - gtk_window_set_default_icon(gdk_pixbuf_from_pixdata(&rasmol_icon, - TRUE, &gerr)); - - gtk_container_add(GTK_CONTAINER(mainwin), mainvbox); - gtk_widget_set_size_request(mainwin, XRange, YRange); - gtk_widget_show_all(mainwin); - - test.longword = (Long) 0x000000ff; - SwapBytes = test.bytes[0]; - - return True; -} - - -int CreateImage(void) -{ - long size; - - if (FBuffer) { - _ffree(FBuffer); - } - size = (long) XRange *YRange * sizeof(Pixel); - FBuffer = (Pixel *) _fmalloc(size + 32); - - return ((FBuffer != (Pixel *) NULL) ? True : False); -} - - -void ClearImage(void) -{ - -} - - -int PrintImage(void) -{ - return False; -} - - -int ClipboardImage(void) -{ - return False; -} - - -void SetCanvasTitle(char *ptr) -{ - if (Interactive) { - gtk_window_set_title(GTK_WINDOW(mainwin), ptr); - } -} - - -void SetMouseUpdateStatus(int bool) -{ - MouseUpdateStatus = bool; -} - - -void BeginWait(void) -{ - -} - - -void EndWait(void) -{ - -} - - -void CloseDisplay(void) -{ - -} - - -void RasMolExit(void) -{ - gtk_main_quit(); - exit(0); -} - - -void RasMolFatalExit(char *msg) -{ - putc('\n', stdout); - fputs(msg, stdout); - putc('\n', stdout); - gtk_main_quit(); - exit(1); -} diff -Nru rasmol-2.7.5/src/Imakefile rasmol-2.7.5/src/Imakefile --- rasmol-2.7.5/src/Imakefile 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/Imakefile 2009-07-21 22:35:48.000000000 +0000 @@ -1,8 +1,8 @@ -# #define NEARTREE_LOCAL -# #define CQRLIB_LOCAL -# #define CVECTOR_LOCAL -# #define XFORMSLIB_LOCAL -# #define CBFLIB_LOCAL +#define NEARTREE_LOCAL +#define CQRLIB_LOCAL +#define CVECTOR_LOCAL +#define XFORMSLIB_LOCAL +#define CBFLIB_LOCAL ########################################################################### # RasMol 2.7.5 # # # @@ -124,7 +124,7 @@ LOCALEDEF = #endif -PKGDIR = /usr +PKGDIR = $(HOME) #ifndef GTKWIN #define X11WIN @@ -197,7 +197,7 @@ ifeq ($(strip $(CBFLIB_DIR)),) CBFLIB_DIR = $(PKGDIR) endif -CBFLIB_INCLUDE_DIR = $(CBFLIB_DIR)/include/cbf +CBFLIB_INCLUDE_DIR = $(CBFLIB_DIR)/include/cbflib CBFLIB_LDLIB = -L$(CBFLIB_DIR)/lib -lcbf CBFLIB_OBJDEP = #define NO_CBFLIB_BUILD @@ -276,7 +276,7 @@ # RasMol's on-line help direcory # e.g. /usr/local/lib/rasmol/rasmol.hlp -RASMOLDIR = /usr/share/rasmol/ +RASMOLDIR = $(USRLIBDIR)/rasmol/ #ifndef USE_XFORMSLIB @@ -332,23 +332,23 @@ # #ifdef HPArchitecture -#CCOPTIONS = -Ae -#CDEBUGFLAGS = -O2 # -Onolimit +CCOPTIONS = -Ae +CDEBUGFLAGS = +O2 +Onolimit #ifdef HPUX_PARISC_32 -#CCOPTIONS = -Ae -DA2.0 -DS2.0 +CCOPTIONS = -Ae +DA2.0 +DS2.0 #endif #ifdef HPUX_PARISC_64 -#CCOPTIONS = -Ae -DA2.0W -DS2.0 -D_LONGLONG +CCOPTIONS = -Ae +DA2.0W +DS2.0 -D_LONGLONG #endif #ifdef HPUX_IA64_32 -#CCOPTIONS = -Ae -DD32 -DSmckinley +CCOPTIONS = -Ae +DD32 +DSmckinley #endif #ifdef HPUX_IA64_64 -#CCOPTIONS = -Ae -DD64 -DSmckinley -D_LONGLONG +CCOPTIONS = -Ae +DD64 +DSmckinley -D_LONGLONG #endif #endif diff -Nru rasmol-2.7.5/src/rasmac.c rasmol-2.7.5/src/rasmac.c --- rasmol-2.7.5/src/rasmac.c 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/rasmac.c 2009-07-21 22:35:48.000000000 +0000 @@ -671,13 +671,6 @@ } -void WriteMsg( char *ptr ) -{ - WriteString(ptr); - WriteChar ('\n'); -} - - void WriteString( char *ptr ) { while( *ptr ) diff -Nru rasmol-2.7.5/src/rasmol.c rasmol-2.7.5/src/rasmol.c --- rasmol-2.7.5/src/rasmol.c 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/rasmol.c 2009-07-21 22:35:48.000000000 +0000 @@ -400,12 +400,6 @@ static int HandleEvents( int ); extern int ProcessCommand( void ); -void WriteMsg( char *ptr ) -{ - WriteString(ptr); - WriteChar('\n'); -} - #ifndef GTKWIN void WriteChar( int ch ) { diff -Nru rasmol-2.7.5/src/rasmol.h rasmol-2.7.5/src/rasmol.h --- rasmol-2.7.5/src/rasmol.h 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/rasmol.h 2009-07-21 22:35:48.000000000 +0000 @@ -78,7 +78,6 @@ /* rasmol.h */ -#include /*===========================*/ /* User Definable Options! */ @@ -203,7 +202,7 @@ typedef double Real; #ifndef APPLEMAC -typedef uint8_t Byte; +typedef unsigned char Byte; #endif #ifdef __STDC__ @@ -212,18 +211,21 @@ typedef char Char; #endif -typedef uint32_t Card; -/* Long has to be defined as long, instead of int32_t because of - multiple printf and scanf calls using %ld in the format. */ +#ifdef _LONGLONG +typedef unsigned int Card; +typedef int Long; +#else +typedef unsigned long Card; typedef long Long; +#endif #ifdef EIGHTBIT -typedef uint8_t Pixel; +typedef unsigned char Pixel; #else #ifdef THIRTYTWOBIT -typedef int32_t Pixel; +typedef Long Pixel; #else -typedef int16_t Pixel; +typedef short Pixel; #endif #endif @@ -247,6 +249,7 @@ #define ToUpper(x) (islower((x))?toupper((x)):(x)) #endif + #if !defined(IBMPC) || defined(_WIN32) #ifdef APPLEMAC #define _fmalloc NewPtrSys @@ -281,10 +284,8 @@ #define AdvPickCoord 7 -#define MSG_MAX 256 void WriteChar( int ); void WriteString( char* ); -void WriteMsg( char* ); void RasMolFatalExit( char* ); void AdviseUpdate( int ); void RefreshScreen( void ); diff -Nru rasmol-2.7.5/src/rastxt.c rasmol-2.7.5/src/rastxt.c --- rasmol-2.7.5/src/rastxt.c 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/rastxt.c 2009-07-21 22:35:48.000000000 +0000 @@ -144,12 +144,6 @@ static int ProfCount; -void WriteMsg( char *ptr ) -{ - WriteString(ptr); - WriteChar ('\n'); -} - void WriteChar( int ch ) { putc(ch,OutFp); diff -Nru rasmol-2.7.5/src/raswin.c rasmol-2.7.5/src/raswin.c --- rasmol-2.7.5/src/raswin.c 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/raswin.c 2009-07-21 22:35:48.000000000 +0000 @@ -619,13 +619,6 @@ } -void WriteMsg( char *ptr ) -{ - WriteString(ptr); - WriteChar ('\n'); -} - - void WriteString( char *ptr ) { while( *ptr ) diff -Nru rasmol-2.7.5/src/render.c rasmol-2.7.5/src/render.c --- rasmol-2.7.5/src/render.c 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/render.c 2009-07-21 22:35:48.000000000 +0000 @@ -2013,43 +2013,43 @@ } -static int DescribeAtom(char *dest, AtomRef *ptr, int flag ) +static void DescribeAtom( AtomRef *ptr, int flag ) { register char *str; register int i,ch; - char *cur; + char buffer[40]; - cur = dest; str = Residue[ptr->grp->refno]; for( i=0; i<3; i++ ) - if( str[i]!=' ' ) - *(cur++) = str[i]; + if( str[i]!=' ' ) + WriteChar(str[i]); - cur += sprintf(cur,"%d",ptr->grp->serno); + sprintf(buffer,"%d",ptr->grp->serno); + WriteString(buffer); ch = ptr->chn->ident; - if( ch != ' ' ) { - if( isdigit(ch) ) - *(cur++) = ':'; - *(cur++) = ch; + if( ch != ' ' ) + { if( isdigit(ch) ) + WriteChar(':'); + WriteChar(ch); } - *(cur++) = '.'; + WriteChar('.'); str = ElemDesc[ptr->atm->refno]; for( i=0; str[i] && i<12; i++ ) - if( str[i]!=' ' ) - *(cur++) = str[i]; - - if (ptr->atm->model) { - cur += sprintf(cur, "/%d", ptr->atm->model); + if( str[i]!=' ' ) + WriteChar(str[i]); + + if (ptr->atm->model) + { + sprintf(buffer,"/%d",ptr->atm->model); + WriteString(buffer); } - if( flag ) { - cur += sprintf(cur, " (%ld)", ptr->atm->serno); + if( flag ) + { sprintf(buffer," (%ld)",ptr->atm->serno); + WriteString(buffer); } - - *(cur++) = 0; - return (cur - dest - 1); } @@ -2060,14 +2060,10 @@ register double temp; register char *str; register size_t len; + char buffer[80]; AtomRef ref; - char msg[MSG_MAX]; - char *cur; -#define MsgString(mstr) cur += sprintf(cur, (mstr)) -#define MsgChar(c) *(cur++) = (c) - cur = msg; if( PickMode == PickNone ) return False; @@ -2076,92 +2072,92 @@ if( !QAtom ) return False; - if( PickMode==PickCentr && shift ) - SetPickMode(PickOrign); + if( PickMode==PickCentr && shift ) + SetPickMode(PickOrign); - if( PickMode==PickAtom ) { - SelectAtom( shift, QAtom, QGroup ); - return True; - } else if( PickMode == PickGroup ) { - SelectGroup( shift, QGroup ); - return True; - } else if( PickMode == PickChain ) { - SelectChain( shift, QChain ); - return True; - } else if( PickMode == PickIdent || PickMode == PickCoord ) { - InvalidateCmndLine(); - MsgString("Atom: "); + if( PickMode==PickAtom ) + { SelectAtom( shift, QAtom, QGroup ); + return True; + } else if( PickMode == PickGroup ) + { SelectGroup( shift, QGroup ); + return True; + } else if( PickMode == PickChain ) + { SelectChain( shift, QChain ); + return True; + } else if( PickMode == PickIdent || PickMode == PickCoord ) + { InvalidateCmndLine(); + + WriteString("Atom: "); str = ElemDesc[QAtom->refno]; - if( str[0]!=' ' ) - MsgChar(str[0]); - MsgChar(str[1]); - MsgChar(str[2]); + if( str[0]!=' ' ) WriteChar(str[0]); + WriteChar(str[1]); WriteChar(str[2]); { int iii; - for (iii = 3; str[iii] && iii < 12; iii++) { - if( str[iii]!=' ' ) - MsgChar(str[iii]); - } + for (iii = 3; str[iii] && iii < 12; iii++) { + if( str[iii]!=' ' ) WriteChar(str[iii]); + } } if( !(QAtom->altl == ' ')) { - MsgChar(';'); - MsgChar(QAtom->altl); + WriteChar(';'); + WriteChar(QAtom->altl); } - cur += sprintf(cur, " %ld ", QAtom->serno); + sprintf(buffer," %ld ",QAtom->serno); + WriteString(buffer); if (!(QGroup->serno == -9999)) { - str = Residue[QGroup->refno]; - if( QAtom->flag&HeteroFlag ) { - MsgString("Hetero: "); - } else - MsgString("Group: "); - - if( str[0]!=' ' ) - MsgChar(str[0]); - MsgChar(str[1]); - MsgChar(str[2]); - - cur += sprintf(cur, " %d", QGroup->serno); - if (!(QGroup->insert == ' ') && !(QGroup->insert=='\0')) - MsgChar(QGroup->insert); - } - - if( QChain->ident!=' ' ) { - MsgString(" Chain: "); - MsgChar(QChain->ident); + str = Residue[QGroup->refno]; + if( QAtom->flag&HeteroFlag ) + { WriteString("Hetero: "); + } else WriteString("Group: "); + + if( str[0]!=' ' ) WriteChar(str[0]); + WriteChar(str[1]); WriteChar(str[2]); + + sprintf(buffer," %d",QGroup->serno); + WriteString(buffer); + if (!(QGroup->insert == ' ') && !(QGroup->insert=='\0')) + WriteChar(QGroup->insert); + } + + if( QChain->ident!=' ' ) + { WriteString(" Chain: "); + WriteChar(QChain->ident); } if( QAtom->model) { - cur += sprintf(cur, " Model: %d", QAtom->model); + sprintf(buffer," Model: %d",QAtom->model); + WriteString(buffer); } + WriteChar('\n'); if (PickMode == PickCoord || shift != 0 ) { - MsgChar('\n'); - register double x, y, z; + register double x, y, z; + + x = (double)(QAtom->xorg + QAtom->fxorg + OrigCX)/250.0 + +(double)(QAtom->xtrl)/10000.0; + y = (double)(QAtom->yorg + QAtom->fyorg + OrigCY)/250.0 + +(double)(QAtom->ytrl)/10000.0; + z = (double)(QAtom->zorg + QAtom->fzorg + OrigCZ)/250.0 + +(double)(QAtom->ztrl)/10000.0; - x = (double)(QAtom->xorg + QAtom->fxorg + OrigCX)/250.0 - +(double)(QAtom->xtrl)/10000.0; - y = (double)(QAtom->yorg + QAtom->fyorg + OrigCY)/250.0 - +(double)(QAtom->ytrl)/10000.0; - z = (double)(QAtom->zorg + QAtom->fzorg + OrigCZ)/250.0 - +(double)(QAtom->ztrl)/10000.0; #ifdef INVERT - cur += sprintf(cur, " Coordinates: %9.3f %9.3f %9.3f",x,-y,-z); + sprintf(buffer, " Coordinates: %9.3f %9.3f %9.3f\n",x,-y,-z); #else - cur += sprintf(cur, " Coordinates: %9.3f %9.3f %9.3f",x,y,-z); + sprintf(buffer, " Coordinates: %9.3f %9.3f %9.3f\n",x,y,-z); #endif + WriteString(buffer); } - } else if( PickMode == PickLabel ) { - if( !QAtom->label ) { - if( *LabelFormat!='\0' ) { - len = strlen(LabelFormat); - label = CreateLabel(LabelFormat,len); - } else if( MainGroupCount > 1 ) { - strcpy(buffer,"%n%r"); + } else if( PickMode == PickLabel ) + { if( !QAtom->label ) + { if( *LabelFormat!='\0' ) + { len = strlen(LabelFormat); + label = CreateLabel(LabelFormat,len); + } else if( MainGroupCount > 1 ) + { strcpy(buffer,"%n%r"); str = buffer+4; - if( Info.chaincount > 1 ) { - if( isdigit(QChain->ident) ) + if( Info.chaincount > 1 ) + { if( isdigit(QChain->ident) ) *str++ = ':'; *str++ = '%'; *str++ = 'c'; @@ -2170,98 +2166,96 @@ len = (str-buffer) + 3; label = CreateLabel(buffer,(int)len); - } else - label = CreateLabel("%e%i%A",6); - QAtom->label = label; - label->refcount++; - } else { - DeleteLabel( (Label*)QAtom->label ); - QAtom->label = (void*)0; - } - ReDrawFlag |= RFRefresh; + } else label = CreateLabel("%e%i%A",6); - } else if( PickMode == PickCentr ) { - CentreTransform(QAtom->xorg + QAtom->fxorg, - QAtom->yorg + QAtom->fyorg, - QAtom->zorg + QAtom->fzorg, XlateCen); - - ref.chn = QChain; - ref.grp = QGroup; - ref.atm = QAtom; + QAtom->label = label; + label->refcount++; + } else + { DeleteLabel( (Label*)QAtom->label ); + QAtom->label = (void*)0; + } + ReDrawFlag |= RFRefresh; - InvalidateCmndLine(); - MsgString("Rotating about "); - cur += DescribeAtom(cur, &ref,True); + } else if( PickMode == PickCentr ) + { CentreTransform(QAtom->xorg + QAtom->fxorg, + QAtom->yorg + QAtom->fyorg, + QAtom->zorg + QAtom->fzorg, XlateCen); + + ref.chn = QChain; + ref.grp = QGroup; + ref.atm = QAtom; + + InvalidateCmndLine(); + WriteString("Rotating about "); + DescribeAtom(&ref,True); + WriteChar('\n'); - } else if( PickMode == PickOrign ) { - CentreTransform(QAtom->xorg + QAtom->fxorg, - QAtom->yorg + QAtom->fyorg, - QAtom->zorg + QAtom->fzorg, False); + } else if( PickMode == PickOrign ) + { CentreTransform(QAtom->xorg + QAtom->fxorg, + QAtom->yorg + QAtom->fyorg, + QAtom->zorg + QAtom->fzorg, False); ref.chn = QChain; ref.grp = QGroup; ref.atm = QAtom; InvalidateCmndLine(); - MsgString("Rotating about "); - cur += DescribeAtom(cur, &ref,True); + WriteString("Rotating about "); + DescribeAtom(&ref,True); + WriteChar('\n'); - } else if( PickMode == PickMonit ) { - /* State Machine Implementation */ + } else if( PickMode == PickMonit ) + { /* State Machine Implementation */ - if( PickCount == 0 ) { - PickHist[0].atm = QAtom; + if( PickCount == 0 ) + { PickHist[0].atm = QAtom; PickCount = 1; - } else if( PickCount == 1 ) { - if( !shift ) { - if( PickHist[0].atm != QAtom ) { - AddMonitors(PickHist[0].atm,QAtom); + } else if( PickCount == 1 ) + { if( !shift ) + { if( PickHist[0].atm != QAtom ) + { AddMonitors(PickHist[0].atm,QAtom); ReDrawFlag |= RFRefresh; - } - PickCount = 2; - } else - PickHist[0].atm = QAtom; + } + PickCount = 2; + } else PickHist[0].atm = QAtom; } else /* PickCount == 2 */ - if( !shift ) { - PickHist[0].atm = QAtom; + if( !shift ) + { PickHist[0].atm = QAtom; PickCount = 1; - } else if( PickHist[0].atm != QAtom ) { - AddMonitors(PickHist[0].atm,QAtom); + } else if( PickHist[0].atm != QAtom ) + { AddMonitors(PickHist[0].atm,QAtom); ReDrawFlag |= RFRefresh; } - } else if (PickMode == PickBond) { /* [GSG 11/16/95] */ - if( PickCount ) { - if( shift ) { - PickCount--; - } else if( PickCount == 2 ) - PickCount = 0; - } - - ptr = PickHist+PickCount; - ptr->chn = QChain; - ptr->grp = QGroup; - ptr->atm = QAtom; - PickCount++; + } else if (PickMode == PickBond) /* [GSG 11/16/95] */ + { if( PickCount ) + { if( shift ) + { PickCount--; + } else if( PickCount == 2 ) + PickCount = 0; + } - if( CommandActive ) + ptr = PickHist+PickCount; + ptr->chn = QChain; + ptr->grp = QGroup; + ptr->atm = QAtom; + PickCount++; + + if( CommandActive ) + WriteChar('\n'); + CommandActive = False; + + WriteString("Atom #"); + WriteChar(PickCount+'0'); + WriteString(": "); + DescribeAtom(ptr,True); WriteChar('\n'); - CommandActive = False; - MsgString("Atom #"); - MsgChar(PickCount+'0'); - MsgString(": "); - cur += DescribeAtom(cur, ptr,True); - MsgChar('\n'); - MsgChar(0); - WriteMsg(msg); - cur = msg; - - if( PickCount == 2 ) - SetBondAxis(PickHist[0].atm, PickHist[1].atm); - } else { /* Distance, Angle or Torsion! */ - if( PickCount ) { - if( shift ) { - PickCount--; + if( PickCount == 2 ) + SetBondAxis(PickHist[0].atm, PickHist[1].atm); + } else /* Distance, Angle or Torsion! */ + { if( PickCount ) + { if( shift ) + { PickCount--; } else if( PickCount == PickMode ) PickCount = 0; } @@ -2273,76 +2267,77 @@ PickCount++; InvalidateCmndLine(); - MsgString("Atom #"); - MsgChar(PickCount+'0'); - MsgString(": "); - cur += DescribeAtom(cur, ptr,True); - - if( PickCount == PickMode ) { - /* [GSG 11/29/95] */ - if ( PickMode != PickMonit ) - DeleteMonitors(); - if( PickMode == PickDist ) { - temp = (double)CalcDistance(PickHist[0].atm, PickHist[1].atm); - - MsgChar('\n'); - MsgString("Distance "); - cur += DescribeAtom(cur, PickHist, False); - MsgChar('-'); - cur += DescribeAtom(cur, PickHist+1, False); - cur += sprintf(cur, ": %.2f", temp); - /* [GSG 11/21/95] */ - AddMonitors(PickHist[0].atm, QAtom); - ReDrawFlag |= RFRefresh; - - } else if( PickMode == PickAngle ) { - temp = (double)CalcAngle(PickHist[0].atm, - PickHist[1].atm, - PickHist[2].atm); - - MsgChar('\n'); - MsgString("Angle "); - cur += DescribeAtom(cur, PickHist, False); - MsgChar('-'); - cur += DescribeAtom(cur, PickHist+1, False); - MsgChar('-'); - cur += DescribeAtom(cur, PickHist+2, False); - cur += sprintf(cur, ": %.2f", temp); - - /* [GSG 11/21/95] */ - AddMonitors2(PickHist[0].atm, PickHist[2].atm, - PickHist[1].atm, (RAtom __far *)NULL, - (Long) (rint(temp*100)), 128, PickAngle); - ReDrawFlag |= RFRefresh; - } else { /* PickMode == PickTorsn */ - temp = (double)CalcTorsion(PickHist[0].atm, - PickHist[1].atm, - PickHist[2].atm, - PickHist[3].atm); - - MsgChar('\n'); - MsgString("Torsion "); - cur += DescribeAtom(cur, PickHist, False); - MsgChar('-'); - cur += DescribeAtom(cur, PickHist+1, False); - MsgChar('-'); - cur += DescribeAtom(cur, PickHist+2, False); - MsgChar('-'); - cur += DescribeAtom(cur, PickHist+3, False); - cur += sprintf(cur, ": %.2f", temp); - - /* [GSG 11/21/95] */ - AddMonitors2(PickHist[0].atm, PickHist[3].atm, - PickHist[1].atm, PickHist[2].atm, - (Long) (rint(temp*100)), 128, PickTorsn); - ReDrawFlag |= RFRefresh; + WriteString("Atom #"); + WriteChar(PickCount+'0'); + WriteString(": "); + DescribeAtom(ptr,True); + WriteChar('\n'); + + if( PickCount == PickMode ) + { /* [GSG 11/29/95] */ + if ( PickMode != PickMonit ) + DeleteMonitors(); + if( PickMode == PickDist ) + { temp = (double)CalcDistance(PickHist[0].atm, + PickHist[1].atm); + + WriteString("Distance "); + DescribeAtom(PickHist,False); + WriteChar('-'); + DescribeAtom(PickHist+1,False); + sprintf(buffer,": %.2f\n\n",temp); + WriteString(buffer); + /* [GSG 11/21/95] */ + AddMonitors(PickHist[0].atm, QAtom); + ReDrawFlag |= RFRefresh; + + } else if( PickMode == PickAngle ) + { temp = (double)CalcAngle(PickHist[0].atm, + PickHist[1].atm, + PickHist[2].atm); + + WriteString("Angle "); + DescribeAtom(PickHist,False); + WriteChar('-'); + DescribeAtom(PickHist+1,False); + WriteChar('-'); + DescribeAtom(PickHist+2,False); + sprintf(buffer,": %.2f\n\n",temp); + WriteString(buffer); + + /* [GSG 11/21/95] */ + AddMonitors2(PickHist[0].atm, PickHist[2].atm, + PickHist[1].atm, (RAtom __far *)NULL, + (Long) (rint(temp*100)), 128, PickAngle); + ReDrawFlag |= RFRefresh; + + + } else /* PickMode == PickTorsn */ + { temp = (double)CalcTorsion(PickHist[0].atm, + PickHist[1].atm, + PickHist[2].atm, + PickHist[3].atm); + + WriteString("Torsion "); + DescribeAtom(PickHist,False); + WriteChar('-'); + DescribeAtom(PickHist+1,False); + WriteChar('-'); + DescribeAtom(PickHist+2,False); + WriteChar('-'); + DescribeAtom(PickHist+3,False); + sprintf(buffer,": %.2f\n\n",temp); + WriteString(buffer); + WriteString(buffer); + + /* [GSG 11/21/95] */ + AddMonitors2(PickHist[0].atm, PickHist[3].atm, + PickHist[1].atm, PickHist[2].atm, + (Long) (rint(temp*100)), 128, PickTorsn); + ReDrawFlag |= RFRefresh; } } } - if(cur > msg) { - MsgChar(0); - WriteMsg(msg); - } return True; } diff -Nru rasmol-2.7.5/src/txt/rasmol.h rasmol-2.7.5/src/txt/rasmol.h --- rasmol-2.7.5/src/txt/rasmol.h 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/txt/rasmol.h 2009-07-21 22:35:45.000000000 +0000 @@ -213,7 +213,6 @@ void WriteChar( int ); void WriteString( char* ); -void WriteMsg( char* ); void RasMolFatalExit( char* ); void AdviseUpdate( int ); void RefreshScreen( void ); diff -Nru rasmol-2.7.5/src/x11win.c rasmol-2.7.5/src/x11win.c --- rasmol-2.7.5/src/x11win.c 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/x11win.c 2009-07-21 22:35:48.000000000 +0000 @@ -287,7 +287,6 @@ int value; } MenuItem; -static int zero = 0; static MenuItem FilMenu[21] = { { &MsgStrs[StrMOpen] /* "Open..." */, 0x11, &MsgAuxl[StrMOpen], @@ -302,35 +301,35 @@ &MsgLens[StrMExit], NULL, 0 }, { &MsgStrs[StrMEmpty] /* "" */, 0x08, &MsgAuxl[StrMEmpty], &MsgLens[StrMEmpty], NULL, 0 }, - { &(MolNStr[0]), 0x01, &zero, - &MolNLen[0], &MoleculeIndex, 0 }, - { &(MolNStr[1]), 0x01, &zero, - &MolNLen[1], &MoleculeIndex, 1 }, - { &(MolNStr[2]), 0x01, &zero, - &MolNLen[2], &MoleculeIndex, 2 }, - { &(MolNStr[3]), 0x01, &zero, - &MolNLen[3], &MoleculeIndex, 3 }, - { &(MolNStr[4]), 0x01, &zero, + { &(MolNStr[0]), 0x01, 0, + &MolNLen[0], &MoleculeIndex, 0 }, + { &(MolNStr[1]), 0x01, 0, + &MolNLen[1], &MoleculeIndex, 1 }, + { &(MolNStr[2]), 0x01, 0, + &MolNLen[2], &MoleculeIndex, 2 }, + { &(MolNStr[3]), 0x01, 0, + &MolNLen[3], &MoleculeIndex, 3 }, + { &(MolNStr[4]), 0x01, 0, &MolNLen[4], &MoleculeIndex, 4 }, - { &(MolNStr[5]), 0x01, &zero, - &MolNLen[5], &MoleculeIndex, 5 }, - { &(MolNStr[6]), 0x01, &zero, - &MolNLen[6], &MoleculeIndex, 6 }, - { &(MolNStr[7]), 0x01, &zero, - &MolNLen[7], &MoleculeIndex, 7 }, - { &(MolNStr[8]), 0x01, &zero, - &MolNLen[8], &MoleculeIndex, 8 }, - { &(MolNStr[9]), 0x01, &zero, + { &(MolNStr[5]), 0x01, 0, + &MolNLen[5], &MoleculeIndex, 5 }, + { &(MolNStr[6]), 0x01, 0, + &MolNLen[6], &MoleculeIndex, 6 }, + { &(MolNStr[7]), 0x01, 0, + &MolNLen[7], &MoleculeIndex, 7 }, + { &(MolNStr[8]), 0x01, 0, + &MolNLen[8], &MoleculeIndex, 8 }, + { &(MolNStr[9]), 0x01, 0, &MolNLen[9], &MoleculeIndex, 9 }, - { &(MolNStr[10]), 0x01, &zero, - &MolNLen[10], &MoleculeIndex, 10 }, - { &(MolNStr[11]), 0x01, &zero, - &MolNLen[11], &MoleculeIndex, 11 }, - { &(MolNStr[12]), 0x01, &zero, - &MolNLen[12], &MoleculeIndex, 12 }, - { &(MolNStr[13]), 0x01, &zero, - &MolNLen[13], &MoleculeIndex, 13 }, - { &(MolNStr[14]), 0x01, &zero, + { &(MolNStr[10]), 0x01, 0, + &MolNLen[10], &MoleculeIndex, 10 }, + { &(MolNStr[11]), 0x01, 0, + &MolNLen[11], &MoleculeIndex, 11 }, + { &(MolNStr[12]), 0x01, 0, + &MolNLen[12], &MoleculeIndex, 12 }, + { &(MolNStr[13]), 0x01, 0, + &MolNLen[13], &MoleculeIndex, 13 }, + { &(MolNStr[14]), 0x01, 0, &MolNLen[14], &MoleculeIndex, 14 }}; static MenuItem DisMenu[9] = { diff -Nru rasmol-2.7.5/src/x11win.c.indented.manually rasmol-2.7.5/src/x11win.c.indented.manually --- rasmol-2.7.5/src/x11win.c.indented.manually 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/x11win.c.indented.manually 1970-01-01 00:00:00.000000000 +0000 @@ -1,4149 +0,0 @@ -/*************************************************************************** - * RasMol 2.7.5 * - * * - * RasMol * - * Molecular Graphics Visualisation Tool * - * 13 June 2009 * - * * - * Based on RasMol 2.6 by Roger Sayle * - * Biomolecular Structures Group, Glaxo Wellcome Research & Development, * - * Stevenage, Hertfordshire, UK * - * Version 2.6, August 1995, Version 2.6.4, December 1998 * - * Copyright (C) Roger Sayle 1992-1999 * - * * - * and Based on Mods by * - *Author Version, Date Copyright * - *Arne Mueller RasMol 2.6x1 May 98 (C) Arne Mueller 1998 * - *Gary Grossman and RasMol 2.5-ucb Nov 95 (C) UC Regents/ModularCHEM * - *Marco Molinaro RasMol 2.6-ucb Nov 96 Consortium 1995, 1996 * - * * - *Philippe Valadon RasTop 1.3 Aug 00 (C) Philippe Valadon 2000 * - * * - *Herbert J. RasMol 2.7.0 Mar 99 (C) Herbert J. Bernstein * - *Bernstein RasMol 2.7.1 Jun 99 1998-2008 * - * RasMol 2.7.1.1 Jan 01 * - * RasMol 2.7.2 Aug 00 * - * RasMol 2.7.2.1 Apr 01 * - * RasMol 2.7.2.1.1 Jan 04 * - * RasMol 2.7.3 Feb 05 * - * RasMol 2.7.3.1 Apr 06 * - * RasMol 2.7.4 Nov 07 * - * RasMol 2.7.4.1 Jan 08 * - * RasMol 2.7.4.2 Mar 08 * - * RasMol 2.7.5 May 09 * - * * - * RasMol 2.7.5 incorporates changes by T. Ikonen, G. McQuillan, N. Darakev* - * and L. Andrews (via the neartree package). Work on RasMol 2.7.5 * - * supported in part by grant 1R15GM078077-01 from the National Institute * - * of General Medical Sciences (NIGMS), U.S. National Institutes of Health * - * and by grant ER63601-1021466-0009501 from the Office of Biological & * - * Environmental Research (BER), Office of Science, U. S. Department of * - * Energy. RasMol 2.7.4 incorporated changes by G. Todorov, Nan Jia, * - * N. Darakev, P. Kamburov, G. McQuillan, and J. Jemilawon. Work on RasMol * - * 2.7.4 supported in part by grant 1R15GM078077-01 from the NIGMS/NIH and * - * grant ER63601-1021466-0009501 from BER/DOE. RasMol 2.7.3 incorporates * - * changes by Clarice Chigbo, Ricky Chachra, and Mamoru Yamanishi. Work * - * on RasMol 2.7.3 supported in part by grants DBI-0203064, DBI-0315281 * - * and EF-0312612 from the U.S. National Science Foundation and grant * - * DE-FG02-03ER63601 from BER/DOE. The content is solely the responsibility* - * of the authors and does not necessarily represent the official views of * - * the funding organizations. * - * * - * The code for use of RasMol under GTK in RasMol 2.7.4.2 and 2.7.5 was * - * written by Teemu Ikonen. * - * * - * and Incorporating Translations by * - * Author Item Language * - * Isabel Servan Martinez, * - * Jose Miguel Fernandez Fernandez 2.6 Manual Spanish * - * Jose Miguel Fernandez Fernandez 2.7.1 Manual Spanish * - * Fernando Gabriel Ranea 2.7.1 menus and messages Spanish * - * Jean-Pierre Demailly 2.7.1 menus and messages French * - * Giuseppe Martini, Giovanni Paolella, 2.7.1 menus and messages * - * A. Davassi, M. Masullo, C. Liotto 2.7.1 help file Italian * - * G. Pozhvanov 2.7.3 menus and messages Russian * - * G. Todorov 2.7.3 menus and messages Bulgarian* - * Nan Jia, G. Todorov 2.7.3 menus and messages Chinese * - * Mamoru Yamanishi, Katajima Hajime 2.7.3 menus and messages Japanese * - * * - * This Release by * - * Herbert J. Bernstein, Bernstein + Sons, 5 Brewster Ln, Bellport, NY, USA* - * yaya@bernstein-plus-sons.com * - * Copyright(C) Herbert J. Bernstein 1998-2008 * - * * - * READ THE FILE NOTICE FOR RASMOL LICENSES * - *Please read the file NOTICE for important notices which apply to this * - *package and for license terms (GPL or RASLIC). * - ***************************************************************************/ -/* x11win.c - $Log$ - Revision 1.13 2008/06/28 14:25:26 yaya - Make more IPC errors non-fatal. -- HJB - - Revision 1.12 2008/06/28 14:06:37 yaya - Fix unused variable warning in command.c - Start changes for loading models in infile.c - Make handling of IPC errors non-fatal in x11win.c -- HJB - - Revision 1.11 2008/06/18 20:04:53 yaya - Start in infrastructure for animation - Start on WPDB code -- HJB - - Revision 1.10 2008/03/22 18:42:56 yaya - Post release cleanup and credit to Ikonen in file headers. -- HJB - - Revision 1.9 2008/03/17 03:01:32 yaya - Update to agree with 2.7.4.2 release and T. Ikonen GTK mods -- HJB - - Revision 1.6 2008/03/17 01:32:41 yaya - Add gtk mods by tpikonen, and intergate with 2.7.4.2 mods -- HJB - - Revision 1.5 2008/03/16 22:38:10 yaya - Update stable release to 2.7.4.2; Update rasmol_install and rasmol_run - scripts to handle Japanese and Chiness (using cxterm), changing - Japanese for unix back to EUCJP; and align command line options - to set initial window size and position to agree between unix and - windows -- HJB - - Revision 1.8 2008/03/16 22:25:22 yaya - Align comments with production version; Update rasmol_install and - rasmol_run shell scripts for Japanese and Chinese; Align logic for - positioning and sizing initial window with windows version -- HJB - - Revision 1.7 2008/03/08 21:41:03 yaya - Updates to switch Japanese in unix to EUC_CN, and to reorganize - languagues directory for split between mswin and unix. -- HJB - - Revision 1.6 2008/03/08 15:26:50 yaya - Fixes to get Chinese working under MacOSX for RasMol 2.7.4 - Based on suggested fixes by Mamoru Yamanishi. -- HJB - - Revision 1.4 2008/01/28 03:29:38 yaya - Update CVS to RasMol_2.7.4.1 -- HJB - - Revision 1.5 2007/11/19 03:28:40 yaya - Update to credits for 2.7.4 in manual and headers - Mask code added -- HJB - - Revision 1.4 2007/03/13 21:48:19 todorovg - Fixed a few typo errors that were causing xforms to crash - - Revision 1.3 2007/03/13 21:09:28 todorovg - fixed bug when you run rasmol in chinese and japanese; added catch for fontset to print an error and not give segfault - - Revision 1.2 2007/03/05 22:27:26 todorovg - Fixed japanese - - Revision 1.10 2007/02/26 18:40:31 todorovg - fixed menu click bug - - Revision 1.9 2006/12/29 04:07:37 yaya - Update x11win.c and rasmol.c to add links to list of browsers - and to kill About dialog when the menu bar is selected - Update rasmol_install.sh to allow recompilation of fonts - on install to handle openwin and other old systems that - can't handle byte-swapped bdf files, and add enviroment - variable RASMOL_NOSPAWN to suppress spawn in intermediate - xterm from rasmol_run.sh. -- HJB - - Revision 1.8 2006/12/24 03:48:28 yaya - Clean up conditionals for MITSHM if it is not defined - Fix choice of license files for install -- HJB - - Revision 1.7 2006/12/23 23:18:01 yaya - Detect remote X server that does not share memory - Add new rasmol_install.sh and rasmol_run.sh scripts -- HJB - - Revision 1.6 2006/12/11 02:45:39 yaya - Migrate some of the language switching tables to mac and mswin version - and update the icons for mswin and X11 versions. -- HJB - - Revision 1.5 2006/12/10 03:32:45 yaya - Additional updates for linux build with Russian, cleaning - up X11 font selection for CP1251 and recovering when fonts - are missing. -- HJB - - Revision 1.4 2006/12/03 02:53:10 yaya - Clean up compilation warnings in outfile.c - Mods for about screen under Linux -- HJB - - Revision 1.3 2006/11/28 03:12:48 yaya - Changes for Russian and About dialog in unix - This is a variant tried under Mac OS X. Changes - for Linux still needed. note that more work is - needed on font selection. -- HJB - - Revision 1.2 2006/09/17 10:53:56 yaya - Clean up headers and start on code for X11 -- HJB - - Revision 1.1.1.1 2006/09/16 18:46:03 yaya - Start of RasMol Russian Translation Project based on translations - by Gregory A. Pozhvanov of Saint Petersburg State University -- HJB - - Revision 1.2 2006/06/19 22:06:41 todorovg - Rasmol 2.7.3.1 - - Revision 1.1.1.1 2006/06/19 22:05:14 todorovg - Initial Rasmol 2.7.3 Import - - Revision 1.1 2004/05/07 19:46:16 yaya - Initial revision - - Revision 1.3 2004/02/15 00:24:00 yaya - *** empty log message *** - - Revision 1.2 2003/12/13 19:26:11 yaya - *** empty log message *** - - Revision 1.1 2003/12/12 21:10:38 yaya - Initial revision - - Revision 1.3 2001/02/07 20:30:31 yaya - *** empty log message *** - - Revision 1.2 2001/02/06 21:58:18 yaya - *** empty log message *** - - Revision 1.1 2001/01/31 02:13:45 yaya - Initial revision - - Revision 1.8 2000/08/27 00:54:54 yaya - create rotation bond database - - Revision 1.7 2000/08/26 18:12:50 yaya - Updates to header comments in all files - - Revision 1.6 2000/08/21 21:07:56 yaya - semi-final ucb mods - - Revision 1.5 2000/08/18 16:40:56 yaya - *** empty log message *** - - Revision 1.4 2000/08/13 20:56:35 yaya - Conversion from toolbar to menus - - Revision 1.3 2000/08/12 21:10:41 yaya - Minimal X windows mods - - */ - - -#ifndef sun386 -#include -#endif -#include -#include -#include -#include - -#ifdef VMS -#include -#endif - -#include -#include -#include -#include -#include - -#ifdef X_LOCALE -#include -#define SetLocale _Xsetlocale -#else -#include -#define SetLocale setlocale -#endif - -#define GRAPHICS -#include "rasmol.h" -#include "bitmaps.h" -#include "command.h" -#include "cmndline.h" -#include "molecule.h" -#include "abstree.h" -#include "render.h" -#include "multiple.h" -#include "transfor.h" -#include "vector.h" -#include "wbrotate.h" -#include "langsel.h" -#include "graphics.h" - - -/* Menu Definitions */ -#define mbEnable 0x01 -#define mbOption 0x02 -#define mbSepBar 0x08 -#define mbAccel 0x10 - - -typedef struct _MenuItem { - char **text; - int flags; - int *pos; - int *len; - int *enable; - int value; -} MenuItem; - -static int zero = 0; - -static MenuItem FilMenu[21] = { - { &MsgStrs[StrMOpen] /* "Open..." */, 0x11, &MsgAuxl[StrMOpen], - &MsgLens[StrMOpen], NULL, 0 }, - { &MsgStrs[StrMSaveAs] /*" Save As..."*/, 0x11, &MsgAuxl[StrMSaveAs], - &MsgLens[StrMSaveAs], NULL, 0 }, - { &MsgStrs[StrMClose] /* "Close" */, 0x11, &MsgAuxl[StrMClose], - &MsgLens[StrMClose], NULL, 0 }, - { &MsgStrs[StrMEmpty] /* "" */, 0x08, &MsgAuxl[StrMEmpty], - &MsgLens[StrMEmpty], NULL, 0 }, - { &MsgStrs[StrMExit] /* "Exit" */, 0x11, &MsgAuxl[StrMExit], - &MsgLens[StrMExit], NULL, 0 }, - { &MsgStrs[StrMEmpty] /* "" */, 0x08, &MsgAuxl[StrMEmpty], - &MsgLens[StrMEmpty], NULL, 0 }, - { &(MolNStr[0]), 0x01, &zero, - &MolNLen[0], &MoleculeIndex, 0 }, - { &(MolNStr[1]), 0x01, &zero, - &MolNLen[1], &MoleculeIndex, 1 }, - { &(MolNStr[2]), 0x01, &zero, - &MolNLen[2], &MoleculeIndex, 2 }, - { &(MolNStr[3]), 0x01, &zero, - &MolNLen[3], &MoleculeIndex, 3 }, - { &(MolNStr[4]), 0x01, &zero, - &MolNLen[4], &MoleculeIndex, 4 }, - { &(MolNStr[5]), 0x01, &zero, - &MolNLen[5], &MoleculeIndex, 5 }, - { &(MolNStr[6]), 0x01, &zero, - &MolNLen[6], &MoleculeIndex, 6 }, - { &(MolNStr[7]), 0x01, &zero, - &MolNLen[7], &MoleculeIndex, 7 }, - { &(MolNStr[8]), 0x01, &zero, - &MolNLen[8], &MoleculeIndex, 8 }, - { &(MolNStr[9]), 0x01, &zero, - &MolNLen[9], &MoleculeIndex, 9 }, - { &(MolNStr[10]), 0x01, &zero, - &MolNLen[10], &MoleculeIndex, 10 }, - { &(MolNStr[11]), 0x01, &zero, - &MolNLen[11], &MoleculeIndex, 11 }, - { &(MolNStr[12]), 0x01, &zero, - &MolNLen[12], &MoleculeIndex, 12 }, - { &(MolNStr[13]), 0x01, &zero, - &MolNLen[13], &MoleculeIndex, 13 }, - { &(MolNStr[14]), 0x01, &zero, - &MolNLen[14], &MoleculeIndex, 14 } -}; - -static MenuItem DisMenu[9] = { - { &MsgStrs[StrMWirefr] /* "Wireframe" */, 0x11, &MsgAuxl[StrMWirefr], - &MsgLens[StrMWirefr], NULL, 0 }, - { &MsgStrs[StrMBackbn] /* "Backbone" */, 0x11, &MsgAuxl[StrMBackbn], - &MsgLens[StrMBackbn], NULL, 0 }, - { &MsgStrs[StrMSticks] /* "Sticks" */, 0x11, &MsgAuxl[StrMSticks], - &MsgLens[StrMSticks], NULL, 0 }, - { &MsgStrs[StrMSpacefl]/* "Spacefill" */, 0x11, &MsgAuxl[StrMSpacefl], - &MsgLens[StrMSpacefl], NULL, 0 }, - { &MsgStrs[StrMBallStk]/* "Ball & Stick" */, 0x11, &MsgAuxl[StrMBallStk], - &MsgLens[StrMBallStk], NULL, 0 }, - { &MsgStrs[StrMRibbons]/* "Ribbons" */, 0x11, &MsgAuxl[StrMRibbons], - &MsgLens[StrMRibbons], NULL, 0 }, - { &MsgStrs[StrMStrands]/* "Strands" */, 0x11, &MsgAuxl[StrMStrands], - &MsgLens[StrMStrands], NULL, 0 }, - { &MsgStrs[StrMCartoon]/* "Cartoons" */, 0x11, &MsgAuxl[StrMCartoon], - &MsgLens[StrMCartoon], NULL, 0 }, - { &MsgStrs[StrMMolSurf]/* "Molecular Surface" */, 0x11, &MsgAuxl[StrMMolSurf], - &MsgLens[StrMMolSurf], NULL, 0 } -}; - -static MenuItem ColMenu[10] = { - { &MsgStrs[StrMMonochr]/* "Monochrome" */, 0x11, &MsgAuxl[StrMMonochr], - &MsgLens[StrMMonochr], NULL, 0 }, - { &MsgStrs[StrMCPK] /* "CPK" */, 0x11, &MsgAuxl[StrMCPK], - &MsgLens[StrMCPK], NULL, 0 }, - { &MsgStrs[StrMShapely]/*" Shapely" */, 0x11, &MsgAuxl[StrMShapely], - &MsgLens[StrMShapely], NULL, 0 }, - { &MsgStrs[StrMGroup] /* "Group" */, 0x11, &MsgAuxl[StrMGroup], - &MsgLens[StrMGroup], NULL, 0 }, - { &MsgStrs[StrMChain] /* "Chain" */, 0x11, &MsgAuxl[StrMChain], - &MsgLens[StrMChain], NULL, 0 }, - { &MsgStrs[StrMTemp] /* "Temperature" */, 0x11, &MsgAuxl[StrMTemp], - &MsgLens[StrMTemp], NULL, 0 }, - { &MsgStrs[StrMStruct] /* "Structure" */, 0x11, &MsgAuxl[StrMStruct], - &MsgLens[StrMStruct], NULL, 0 }, - { &MsgStrs[StrMUser] /* "User" */, 0x11, &MsgAuxl[StrMUser], - &MsgLens[StrMUser], NULL, 0 }, - { &MsgStrs[StrMModel] /* "Model" */, 0x11, &MsgAuxl[StrMModel], - &MsgLens[StrMModel], NULL, 0 }, - { &MsgStrs[StrMAlt] /* "Alt" */, 0x11, &MsgAuxl[StrMAlt], - &MsgLens[StrMAlt], NULL, 0 } -}; - -static MenuItem OptMenu[7] = { - { &MsgStrs[StrMSlab] /* "Slab Mode" */, 0x13, &MsgAuxl[StrMSlab], - &MsgLens[StrMSlab], &UseSlabPlane, True }, - { &MsgStrs[StrMHydr] /* "Hydrogens" */, 0x13, &MsgAuxl[StrMHydr], - &MsgLens[StrMHydr], &Hydrogens, True }, - { &MsgStrs[StrMHet] /* "Hetero Atoms" */, 0x13, &MsgAuxl[StrMHet], - &MsgLens[StrMHet], &HetaGroups, True }, - { &MsgStrs[StrMSpec] /* "Specular" */, 0x13, &MsgAuxl[StrMSpec], - &MsgLens[StrMSpec], &FakeSpecular, True }, - { &MsgStrs[StrMShad] /* "Shadows" */, 0x13, &MsgAuxl[StrMShad], - &MsgLens[StrMShad], &UseShadow, True }, - { &MsgStrs[StrMStereo] /* "Stereo" */, 0x13, &MsgAuxl[StrMStereo], - &MsgLens[StrMStereo], &UseStereo, True }, - { &MsgStrs[StrMLabel] /* "Labels" */, 0x13, &MsgAuxl[StrMLabel], - &MsgLens[StrMLabel], &LabelOptFlag, True } -}; - -static MenuItem SetMenu[13] = { - { &MsgStrs[StrMPOff] /* "Pick Off" */, 0x13, &MsgAuxl[StrMPOff], - &MsgLens[StrMPOff], &PickMode, PickNone }, - { &MsgStrs[StrMPIdent] /* "Pick Ident" */, 0x13, &MsgAuxl[StrMPIdent], - &MsgLens[StrMPIdent], &PickMode, PickIdent }, - { &MsgStrs[StrMPDist] /* "Pick Distance"*/, 0x13, &MsgAuxl[StrMPDist], - &MsgLens[StrMPDist], &PickMode, PickDist }, - { &MsgStrs[StrMPMon] /* "Pick Monitor" */, 0x13, &MsgAuxl[StrMPMon], - &MsgLens[StrMPMon], &PickMode, PickMonit }, - { &MsgStrs[StrMPAng] /* "Pick Angle" */, 0x13, &MsgAuxl[StrMPAng], - &MsgLens[StrMPAng], &PickMode, PickAngle }, - { &MsgStrs[StrMPTrsn] /* "Pick Torsion" */, 0x13, &MsgAuxl[StrMPTrsn], - &MsgLens[StrMPTrsn], &PickMode, PickTorsn }, - { &MsgStrs[StrMPLabl] /* "Pick Label" */, 0x13, &MsgAuxl[StrMPLabl], - &MsgLens[StrMPLabl], &PickMode, PickLabel }, - { &MsgStrs[StrMPCent] /* "Pick Centre" */, 0x13, &MsgAuxl[StrMPCent], - &MsgLens[StrMPCent], &PickMode, PickOrign }, - { &MsgStrs[StrMPCoord] /* "Pick Coord" */, 0x13, &MsgAuxl[StrMPCoord], - &MsgLens[StrMPCoord], &PickMode, PickCoord }, - { &MsgStrs[StrMPBond] /* "Pick Bond" */, 0x13, &MsgAuxl[StrMPBond], - &MsgLens[StrMPBond], &PickMode, PickBond }, - { &MsgStrs[StrMRBond] /* "Rotate Bond" */, 0x13, &MsgAuxl[StrMRBond], - &MsgLens[StrMRBond], &RotMode, RotBond }, - { &MsgStrs[StrMRMol] /* "Rotate Mol" */, 0x13, &MsgAuxl[StrMRMol], - &MsgLens[StrMRMol], &RotMode, RotMol }, - { &MsgStrs[StrMRAll] /* "Rotate All" */, 0x13, &MsgAuxl[StrMRAll], - &MsgLens[StrMRAll], &RotMode, RotAll } -}; - -static MenuItem ExpMenu[15] = { - { &MsgStrs[StrMBMP] /* "BMP..." */, 0x11, &MsgAuxl[StrMBMP], - &MsgLens[StrMBMP], NULL, 0 }, - { &MsgStrs[StrMGIF] /* "GIF..." */, 0x11, &MsgAuxl[StrMGIF], - &MsgLens[StrMGIF], NULL, 0 }, - { &MsgStrs[StrMIRGB] /* "IRIS RGB..." */, 0x11, &MsgAuxl[StrMIRGB], - &MsgLens[StrMIRGB], NULL, 0 }, - { &MsgStrs[StrMPPM] /* "PPM..." */, 0x11, &MsgAuxl[StrMPPM], - &MsgLens[StrMPPM], NULL, 0 }, - { &MsgStrs[StrMSRast] /* "Sun Raster..." */, 0x11, &MsgAuxl[StrMSRast], - &MsgLens[StrMSRast], NULL, 0 }, - { &MsgStrs[StrMPostscr] /* "PostScript..." */, 0x11, &MsgAuxl[StrMPostscr], - &MsgLens[StrMPostscr], NULL, 0 }, - { &MsgStrs[StrMPICT] /* "PICT..." */, 0x11, &MsgAuxl[StrMPICT], - &MsgLens[StrMPICT], NULL, 0 }, - { &MsgStrs[StrMVECPS] /* "Vector PS ..." */, 0x11, &MsgAuxl[StrMVECPS], - &MsgLens[StrMVECPS], NULL, 0 }, - { &MsgStrs[StrMMSCR] /* "Molscript ..." */, 0x11, &MsgAuxl[StrMMSCR], - &MsgLens[StrMMSCR], NULL, 0 }, - { &MsgStrs[StrMKine] /* "Kinemage ..." */, 0x11, &MsgAuxl[StrMKine], - &MsgLens[StrMKine], NULL, 0 }, - { &MsgStrs[StrMPOVRAY] /*"POVRay 3 ..." */, 0x11, &MsgAuxl[StrMPOVRAY], - &MsgLens[StrMPOVRAY], NULL, 0 }, - { &MsgStrs[StrMVRML] /* "VRML ..." */, 0x11, &MsgAuxl[StrMVRML], - &MsgLens[StrMVRML], NULL, 0 }, - { &MsgStrs[StrMRPP] /* "Ramachandran ..." */, 0x11, &MsgAuxl[StrMRPP], - &MsgLens[StrMRPP], NULL, 0 }, - { &MsgStrs[StrMR3D] /* "Raster3D ..." */, 0x11, &MsgAuxl[StrMR3D], - &MsgLens[StrMR3D], NULL, 0 }, - { &MsgStrs[StrMSCR] /* "RasMol Script ..."*/, 0x11, &MsgAuxl[StrMSCR], - &MsgLens[StrMSCR], NULL, 0 } -}; - -static MenuItem HelMenu[4] = { - { &MsgStrs[StrMAbout] /* "About RasMol..."*/, 0x11, &MsgAuxl[StrMAbout], - &MsgLens[StrMAbout], NULL, 0 }, - { &MsgStrs[StrMUserM] /* "User Manual..." */, 0x11, &MsgAuxl[StrMUserM], - &MsgLens[StrMUserM], NULL, 0 }, - { &MsgStrs[StrRegister] /* "Register ..."*/, 0x11, &MsgAuxl[StrRegister], - &MsgLens[StrRegister], NULL, 0 }, - { &MsgStrs[StrDonate] /* "Donate..."*/, 0x11, &MsgAuxl[StrDonate], - &MsgLens[StrDonate], NULL, 0 } -}; - - -typedef struct _BarItem { - MenuItem *menu; - char **text; - int count; - int flags; - int *pos; - int *len; - int *increment; -} BarItem; - -#define MenuBarMax 7 -static BarItem MenuBar[MenuBarMax] = { - { FilMenu, &MsgStrs[StrMFile] /* "File" */, 5, 0x01, &MsgAuxl[StrMFile], - &MsgLens[StrMFile], &NumMolecules}, - { DisMenu, &MsgStrs[StrMDisplay] /* "Display" */, 9, 0x01, &MsgAuxl[StrMDisplay], - &MsgLens[StrMDisplay], NULL }, - { ColMenu, &MsgStrs[StrMColour] /* "Colours" */, 10, 0x01, &MsgAuxl[StrMColour], - &MsgLens[StrMColour], NULL }, - { OptMenu, &MsgStrs[StrMOpt] /* "Options" */, 7, 0x01, &MsgAuxl[StrMOpt], - &MsgLens[StrMOpt], NULL }, - { SetMenu, &MsgStrs[StrMSettings] /* "Settings" */,13, 0x01, &MsgAuxl[StrMSettings], - &MsgLens[StrMSettings], NULL }, - { ExpMenu, &MsgStrs[StrMExport] /* "Export" */, 15, 0x01, &MsgAuxl[StrMExport], - &MsgLens[StrMExport], NULL }, - { HelMenu, &MsgStrs[StrMHelp] /* "Help" */, 4, 0x01, &MsgAuxl[StrMHelp], - &MsgLens[StrMHelp], NULL } -}; - - -static int MenuFocus; -static int ItemFocus; -static int MenuItemSelect; -static int MenuBarSelect; -static int MenuBarCount; -static int PopUpWide; -static int PopUpHigh; -static int PopUpFlag; -static int ItemFlag; - - -#ifdef DIALBOX -#include - -static char *DialLabel[] = { - "ROTATE X", "ROTATE Y", "ROTATE Z", " ZOOM ", - "TRANS X ", "TRANS Y ", "TRANS Z ", " SLAB " -}; - -static int *DialMap; -static int ESVDialMap[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; -static int SGIDialMap[8] = { 3, 7, 2, 6, 1, 5, 0, 4 }; - -static Real DialRes[8]; -static int DialPrev[8]; -static int DialMode; - -static int UseDialLEDs; -static XDevice *Dials; -static int DialEvent; -static int UseDials; -#endif - - -#ifdef MITSHM -#include -#include -#include -#include - -XShmSegmentInfo xshminfo; -int SharedMemOption; -int SharedMemFlag; -#else -#define SharedMemOption False -#endif - -#define XScrlSkip 8 -#define YScrlSkip 8 - -typedef union { - Long longword; - Byte bytes[4]; -} ByteTest; - - -static int MenuHigh; -static int FontHigh; -static char *lastlocale; -static Cursor cross; -static Cursor arrow; -static Cursor hglass; -static Pixmap Scrl; -static Pixmap tilepix; -static Pixmap uppix, dnpix; -static Pixmap lfpix, rgpix; -static XFontStruct *MenuFont = NULL; -static XFontSet MenuFontSet = NULL; -static short XFascent; -static short XFdescent; -static XSetWindowAttributes attr; -static Window XScrlWin, YScrlWin; -static XWMHints hints; -static Colormap lmap; -static XImage *image; -static GC gcon; - -#ifdef EIGHTBIT -static unsigned long Ident[256]; -static int IdentCount; -#endif - -static int XHeldButton; -static int XHeldStep; - -static Byte Intensity[LutSize]; -static Pixel WhiteCol; -static Pixel BlackCol; - -#ifdef THIRTYTWOBIT -static int SwapBytes; -#endif - -static int MaxWidth, MaxHeight; -static int MinWidth, MinHeight; -static int MainWide, MainHigh; -static int ScrlX, NewScrlX; -static int ScrlY, NewScrlY; - - -/* WM_PROTOCOLS */ -static char TkInterp[10]; -static Atom AppNameAtom; -static Atom DelWinXAtom; -static Atom ProtoXAtom; -static Atom InterpAtom; -static Atom CommAtom; - - -/*=======================*/ -/* Function Prototypes */ -/*=======================*/ - -extern int ProcessCommand(void); -static int HandleMenuLoop(void); -static int HandleIPCError(Display *dpy, XErrorEvent *ptr); -#ifdef MITSHM -static int HandleShmError(Display *dpy, XErrorEvent *ptr); -#endif - - -void FatalGraphicsError(char *ptr) -{ - char buffer[80]; - - sprintf(buffer, "Graphics Error: %s!", ptr); - RasMolFatalExit(buffer); -} - - -void AllocateColourMap(void) -{ -#ifdef EIGHTBIT - static XColor Col; - register int i, j; - - if (Monochrome) { - for (i = 0; i < LutSize; i++) - Intensity[i] = (Byte) ((int) (20*RLut[i] + 32*GLut[i] + 12*BLut[i]) >> 6); - return; - } - - if (LocalMap) { - XSetWindowColormap(dpy, MainWin, cmap); - XSetWindowColormap(dpy, CanvWin, cmap); - XUninstallColormap(dpy, lmap); - XFreeColormap(dpy, lmap); - LocalMap = False; - } else { - if (IdentCount) - XFreeColors(dpy, cmap, Ident, IdentCount, (long) 0); - } - IdentCount = 0; - - - for (i = 0; i < LutSize; i++) { - if (ULut[i]) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - Col.flags = DoRed | DoGreen | DoBlue; - if (!XAllocColor(dpy, cmap, &Col)) - break; - Ident[IdentCount++] = Col.pixel; - Lut[i] = (Pixel) Col.pixel; - } - } - - if (i < LutSize) { - lmap = XCopyColormapAndFree(dpy, cmap); - LocalMap = True; - - for (j = 0; j < 5; j++) { - Col.red = RLut[j] << 8 | RLut[j]; - Col.green = GLut[j] << 8 | GLut[j]; - Col.blue = BLut[j] << 8 | BLut[j]; - XAllocColor(dpy, cmap, &Col); - Lut[i] = (Pixel) Col.pixel; - } - - for (j = i; j < LutSize; j++) { - if (ULut[j]) { - Col.red = RLut[j] << 8 | RLut[j]; - Col.green = GLut[j] << 8 | GLut[j]; - Col.blue = BLut[j] << 8 | BLut[j]; - XAllocColor(dpy, lmap, &Col); - Lut[j] = (Pixel) Col.pixel; - } - } - XSetWindowColormap(dpy, MainWin, lmap); - XSetWindowColormap(dpy, CanvWin, lmap); - XInstallColormap(dpy, lmap); - } -#else /* EIGHTBIT */ -#ifdef THIRTYTWOBIT - static XColor Col; - static ByteTest buf; - register Byte temp; - register int i; - - for (i = 0; i < LutSize; i++) { - if (ULut[i]) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - XAllocColor(dpy, cmap, &Col); - if (SwapBytes) { - buf.longword = (Long) Col.pixel; - temp = buf.bytes[0]; - buf.bytes[0] = buf.bytes[3]; - buf.bytes[3] = temp; - temp = buf.bytes[1]; - buf.bytes[1] = buf.bytes[2]; - buf.bytes[2] = temp; - Lut[i] = buf.longword; - } else - Lut[i] = (Long) Col.pixel; - } - } -#else /* THIRTYTWOBIT */ - static XColor Col; - register int i; - - for (i = 0; i < LutSize; i++) - if (ULut[i]) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - XAllocColor(dpy, cmap, &Col); - Lut[i] = (Pixel) Col.pixel; - } -#endif /* THIRTYTWOBIT */ -#endif /* EIGHTBIT */ - XSetWindowBackground(dpy, CanvWin, (unsigned long) Lut[5]); -} - - -static void OpenCanvas(int x, int y) -{ - register unsigned long mask; - - mask = CWEventMask; - attr.event_mask = - ExposureMask | ButtonPressMask | ButtonMotionMask | ButtonReleaseMask; - attr.cursor = cross; - mask |= CWCursor; - attr.background_pixel = Lut[0]; - mask |= CWBackPixel; - - CanvWin = XCreateWindow(dpy, MainWin, 14, MenuHigh + 14, x, y, 0, - CopyFromParent, InputOutput, vis, mask, &attr); -} - - -static XFontSet RasLoadQueryFontSet(Display *disp, const char *fontset_name) -{ - XFontSet MenuFontSet; - int missing_charset_count; - char **missing_charset_list; - char *def_string; - char buffer[255]; - - MenuFontSet = XCreateFontSet(disp, fontset_name, - &missing_charset_list, &missing_charset_count, - &def_string); - - if (missing_charset_count) { - if (strlen(fontset_name) < 200) - sprintf(buffer, "Missing charsets in MenuFontSet (%s) creation.\n", - fontset_name); - else - strcpy(buffer, "Missing charsets in MenuFontSet creation.\n"); - WriteString(buffer); - for (; missing_charset_count--;) { - sprintf(buffer, " missing %d: %s\n", - missing_charset_count, - missing_charset_list[missing_charset_count]); - WriteString(buffer); - } - XFreeStringList(missing_charset_list); - } - return MenuFontSet; -} - - -static int RasOpenFonts(void) -{ - static char fontname[255]; - register int i; - XFontSetExtents *extent; - char *menufonts; - XRectangle dummy; - XRectangle bound; - - if (Language != TermLanguage) { - if (MenuFont && MenuFont->fid) - XUnloadFont(dpy, MenuFont->fid); - MenuFont = 0; - if (MenuFontSet) - XFreeFontSet(dpy, MenuFontSet); - MenuFontSet = NULL; - } - - if (!MenuFont || !(MenuFont->fid)) { - for (i = 0; i < NUMLANGS; i++) { - if (langfonts[i].lang == Language) { - int kl; - if ((menufonts = getenv(langfonts[i].menufontvar))) { - char *strend; - while ((strend = strchr(menufonts, ':'))) { - /* fprintf(stderr,"menufonts: %s\n",menufonts); */ - strncpy(fontname, menufonts, - strend - menufonts < - 255 ? strend - menufonts : 254); - fontname[strend - menufonts < - 255 ? strend - menufonts : 254] = '\0'; - menufonts = strend + 1; - if ((MenuFont = XLoadQueryFont(dpy, fontname))) - break; - } - if (!MenuFont && (kl = strlen(menufonts)) > 0) { - /* fprintf(stderr,"menufonts: %s\n",menufonts); */ - strncpy(fontname, menufonts, kl < 255 ? kl : 254); - fontname[kl < 255 ? kl : 254] = '\0'; - if ((MenuFont = XLoadQueryFont(dpy, fontname))) - break; - } - if (MenuFont) - break; - } - if ((menufonts = langfonts[i].menufontlist)) { - char *strend; - while ((strend = strchr(menufonts, ':'))) { - /* fprintf(stderr,"menufonts: %s\n",menufonts); */ - strncpy(fontname, menufonts, - strend - menufonts < 255 ? strend - menufonts : 254); - fontname[strend - menufonts < - 255 ? strend - menufonts : 254] = '\0'; - menufonts = strend + 1; - if ((MenuFont = XLoadQueryFont(dpy, fontname))) - break; - } - if (!MenuFont && (kl = strlen(menufonts)) > 0) { - /* fprintf(stderr,"menufonts: %s\n",menufonts); */ - strncpy(fontname, menufonts, kl < 255 ? kl : 254); - fontname[kl < 255 ? kl : 254] = '\0'; - if ((MenuFont = XLoadQueryFont(dpy, fontname))) - break; - } - if (MenuFont) - break; - } - } - } - } - - /* if (MenuFont) fprintf(stderr,"Selected menufont %s\n",fontname); */ - - if (!cross) - cross = XCreateFontCursor(dpy, XC_tcross); - if (!arrow) - arrow = XCreateFontCursor(dpy, XC_top_left_arrow); - - if (Language == Chinese) { - strncat(fontname, ",-*-helvetica-bold-o-normal-*-14-*-iso8859-1", - 254 - strlen(fontname)); - SetLocale(LC_ALL, "zh_CN.GB2312"); - lastlocale = "chinese"; - MenuFontSet = RasLoadQueryFontSet(dpy, fontname); - if (!MenuFontSet) - return 1; - extent = XExtentsOfFontSet(MenuFontSet); - XFascent = extent->max_logical_extent.height; - XFdescent = extent->max_logical_extent.height * 1.0 / 10.0; - FontHigh = extent->max_logical_extent.height + 6; - XmbTextExtents(MenuFontSet, MsgStrs[StrWarranty], - strlen(MsgStrs[StrWarranty]), &dummy, &bound); - if (bound.height > FontHigh) - FontHigh = bound.height; - if (-dummy.y > XFascent) - XFascent = dummy.y; - if (-dummy.y + dummy.height > XFdescent) - XFdescent = -dummy.y + dummy.height; - if (XFdescent > 4) - XFdescent = 4; - MenuHigh = FontHigh + 6; - if (!MenuFont) - return 1; - return 0; - - } else if (Language == Japanese) { - strncat(fontname, ",-*-helvetica-bold-o-normal-*-14-*-iso8859-1", - 254 - strlen(fontname)); - SetLocale(LC_ALL, "ja_JP.eucjp"); - lastlocale = "japanese"; - MenuFontSet = RasLoadQueryFontSet(dpy, fontname); - if (!MenuFontSet) - return 1; - extent = XExtentsOfFontSet(MenuFontSet); - XFascent = extent->max_logical_extent.height; - XFdescent = extent->max_logical_extent.height * 2.0 / 10.0; - FontHigh = extent->max_logical_extent.height + 6; - XmbTextExtents(MenuFontSet, MsgStrs[StrWarranty], - strlen(MsgStrs[StrWarranty]), &dummy, &bound); - if (bound.height > FontHigh) - FontHigh = bound.height; - if (-dummy.y > XFascent) - XFascent = dummy.y; - if (-dummy.y + dummy.height > XFdescent) - XFdescent = -dummy.y + dummy.height; - if (XFdescent > 4) - XFdescent = 4; - MenuHigh = FontHigh + 6; - if (!MenuFont) - return 1; - return 0; - } else { - if (Language == English) { - SetLocale(LC_ALL, "en_US"); - lastlocale = "english"; - } else if (Language == Spanish) { - SetLocale(LC_ALL, "es_ES"); - lastlocale = "spanish"; - } else if (Language == Italian) { - SetLocale(LC_ALL, "it_IT"); - lastlocale = "italian"; - } else if (Language == French) { - SetLocale(LC_ALL, "fr_FR"); - lastlocale = "french"; - } else if (Language == Russian) { - SetLocale(LC_ALL, "ru_RU"); - lastlocale = "russian"; - } else if (Language == Bulgarian) { - SetLocale(LC_ALL, "bg_BG"); - lastlocale = "bulgarian"; - } - - if (!MenuFont) - return 1; - - FontHigh = - MenuFont->max_bounds.descent + MenuFont->max_bounds.ascent + 1; - } - MenuHigh = FontHigh + 6; - XFascent = MenuFont->ascent; - XFdescent = MenuFont->descent; - return 0; -} - - -static void OpenCursors(void) -{ - Pixmap source, mask; - XColor black, white; - - white.red = 65535; - black.red = 0; - white.green = 65535; - black.green = 0; - white.blue = 65535; - black.blue = 0; - - white.flags = DoRed | DoGreen | DoBlue; - black.flags = DoRed | DoGreen | DoBlue; - - source = XCreateBitmapFromData(dpy, MainWin, (char *) HGlassData, 16, 16); - mask = XCreateBitmapFromData(dpy, MainWin, (char *) HGlassMask, 16, 16); - hglass = XCreatePixmapCursor(dpy, source, mask, &black, &white, 7, 7); -} - - -static void OpenColourMap(void) -{ - static XColor Col; - register int i; - -#ifdef EIGHTBIT - if (!Monochrome) { - Col.flags = DoRed | DoGreen | DoBlue; - - for (i = 0; i < 5; i++) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - if (!XAllocColor(dpy, cmap, &Col)) { - cmap = XCopyColormapAndFree(dpy, cmap); - XAllocColor(dpy, cmap, &Col); - } - Lut[i] = (Pixel) Col.pixel; - } - Lut[5] = Lut[0]; - } else { /* Black & White */ - Lut[0] = BlackCol; - Lut[1] = BlackCol; - Lut[2] = WhiteCol; - Lut[3] = BlackCol; - Lut[4] = WhiteCol; - - Intensity[5] = 0; - Lut[5] = 5; - } - - LocalMap = False; - IdentCount = 0; -#else - Col.flags = DoRed | DoGreen | DoBlue; - - for (i = 0; i < 5; i++) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - XAllocColor(dpy, cmap, &Col); - Lut[i] = (Pixel) Col.pixel; - } - Lut[5] = Lut[0]; -#endif -} - - -static int RegisterInterpName(char *name) -{ - static unsigned char *registry; - static unsigned long len, left; - static char buffer[32]; - static int format; - static Atom type; - - register int result; - register char *ptr; - register int (*handler) (); - - registry = NULL; - handler = XSetErrorHandler(HandleIPCError); - result = XGetWindowProperty(dpy, RootWindow(dpy, 0), InterpAtom, - 0, 100000, False, XA_STRING, &type, - &format, &len, &left, ®istry); - XSync(dpy, False); - XSetErrorHandler(handler); - - if ((result != Success) || (format != 8) || (type != XA_STRING)) { - if ((type != None) && registry) - XFree((char *) registry); - - sprintf(buffer, "%x %s", (int) MainWin, name); - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, RootWindow(dpy, 0), InterpAtom, XA_STRING, - 8, PropModeReplace, (unsigned char *) buffer, - (int) strlen(buffer) + 1); - XSync(dpy, False); - XSetErrorHandler(handler); - - return (True); - } - - ptr = (char *) registry; - while (*ptr) { /* Skip Window ID */ - while (*ptr++ != ' ') - if (!*ptr) - break; - - /* Compare Interp Name */ - if (!strcmp(ptr, name)) { - XFree((char *) registry); - return False; - } - - while (*ptr++); - } - - XFree((char *) registry); - sprintf(buffer, "%x %s", (int) MainWin, name); - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, RootWindow(dpy, 0), InterpAtom, XA_STRING, - 8, PropModeAppend, (unsigned char *) buffer, - (int) strlen(buffer) + 1); - XSync(dpy, False); - XSetErrorHandler(handler); - return (True); -} - - -static void DeRegisterInterpName(char *name) -{ - static unsigned char *registry; - static unsigned long len, left; - static int format; - static Atom type; - - register char *src, *dst; - register int result; - register int (*handler) (); - - /* Avoid compiler warnings */ - src = (char *) 0; - - registry = NULL; - handler = XSetErrorHandler(HandleIPCError); - result = XGetWindowProperty(dpy, RootWindow(dpy, 0), InterpAtom, - 0, 100000, False, XA_STRING, &type, - &format, &len, &left, ®istry); - XSync(dpy, False); - XSetErrorHandler(handler); - if (type == None) - return; - - if ((result != Success) || (format != 8) || (type != XA_STRING)) { - handler = XSetErrorHandler(HandleIPCError); - XDeleteProperty(dpy, RootWindow(dpy, 0), InterpAtom); - XSync(dpy, False); - XSetErrorHandler(handler); - if (registry) - XFree((char *) registry); - return; - } - - dst = (char *) registry; - while (*dst) { /* Skip Window ID */ - src = dst; - while (*src++ != ' ') - if (!*src) - break; - - /* Compare Interp Name */ - if (strcmp(src, name)) { - while (*dst++); - } else - break; - } - - if (*dst) { /* Skip Interp Name */ - while (*src++); - - /* Shuffle Registry */ - while (*src) - while ((*dst++ = *src++)); - *dst = 0; - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, RootWindow(dpy, 0), InterpAtom, XA_STRING, - 8, PropModeReplace, registry, - (int) (dst - (char *) registry)); - XSync(dpy, False); - XSetErrorHandler(handler); - } - XFree((char *) registry); -} - - -static void OpenIPCComms(void) -{ - auto char buffer[16]; - register int i; - register int (*handler) (); - - CommAtom = XInternAtom(dpy, "Comm", False); - InterpAtom = XInternAtom(dpy, "InterpRegistry", False); - AppNameAtom = XInternAtom(dpy, "TK_APPLICATION", False); - DelWinXAtom = XInternAtom(dpy, "WM_DELETE_WINDOW", False); - XSync(dpy, False); - /* XSetWMProtocols(dpy,MainWin,&DelWinXAtom,True); */ - if ((ProtoXAtom = XInternAtom(dpy, "WM_PROTOCOLS", False))) { - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, MainWin, ProtoXAtom, XA_ATOM, 32, - PropModeReplace, (Byte *) & DelWinXAtom, True); - XSync(dpy, False); - XSetErrorHandler(handler); - } - i = 0; - XSync(dpy, False); - if (!RegisterInterpName("rasmol")) { - strcpy(TkInterp, "rasmol #0"); - for (i = 1; i < 10; i++) { - TkInterp[8] = i + '0'; - if (RegisterInterpName(TkInterp)) - break; - } - - if (i < 10) { /* Tk4.0 and later! */ - strcpy(buffer, "{rasmol #0}"); - buffer[9] = i + '0'; - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, MainWin, AppNameAtom, XA_STRING, - 8, PropModeReplace, (Byte *) buffer, 12); - XSync(dpy, False); - XSetErrorHandler(handler); - } else - *TkInterp = 0; - } else { - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, MainWin, AppNameAtom, XA_STRING, - 8, PropModeReplace, (Byte *) "rasmol", 7); - XSync(dpy, False); - XSetErrorHandler(handler); - strcpy(TkInterp, "rasmol"); - } - XUngrabServer(dpy); -} - - -static void DrawUpCircle(Drawable wdw, int x1, int y1, int x2, int y2) -{ - int width, height; - - width = x2 - x1 + 1; - height = y2 - y1 + 1; - -/* XSetForeground(dpy,gcon,(unsigned long)Lut[2]); - XFillArc(dpy,wdw,gcon,x1-1,y1-1,width+2,height+2,0,360*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[3]); - XFillArc(dpy,wdw,gcon,x1,y1,width,height,-45*64,180*64); - XFillArc(dpy,wdw,gcon,x1+1,y1+1,width-2,height-2,-45*64,180*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[1]); - XFillArc(dpy,wdw,gcon,x1,y1,width,height,135*64,180*64); - XFillArc(dpy,wdw,gcon,x1+1,y1+1,width-2,height-2,135*64,180*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[3]); - XFillArc(dpy,wdw,gcon,x1+2,y1+2,width-4,height-4,0,360*64); - */ - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillArc(dpy, wdw, gcon, x1 - 1, y1 - 1, width + 2, height + 2, 0, - 360 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XFillArc(dpy, wdw, gcon, x1, y1, width, height, 135 * 64, 360 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillArc(dpy, wdw, gcon, x1 + width / 10, y1, width - width / 10, - height - height / 10, 135 * 64, 360 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XFillArc(dpy, wdw, gcon, x1 + width / 9, y1, width - width / 9, - height - height / 9, 135 * 64, 360 * 64); -} - - -static void DrawUpPieSlice(Drawable wdw, int x1, int y1, int x2, int y2) -{ - int width, height; - - width = x2 - x1 + 1; - height = y2 - y1 + 1; - -/* XSetForeground(dpy,gcon,(unsigned long)Lut[2]); - XFillArc(dpy,wdw,gcon,x1-1,y1-1,width+2,height+2,135*64,90*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[1]); - XFillArc(dpy,wdw,gcon,x1,y1,width,height,135*64,90*64); - XFillArc(dpy,wdw,gcon,x1+1,y1+1,width-2,height-2,135*64,90*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[3]); - XFillArc(dpy,wdw,gcon,x1+2,y1+2,width-4,height-4,135*64,90*64); - */ - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillArc(dpy, wdw, gcon, x1 - 1, y1 - 1, width + 2, height + 2, 155 * 64, - 50 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XFillArc(dpy, wdw, gcon, x1, y1, width, height, 155 * 64, 50 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillArc(dpy, wdw, gcon, x1 + width / 10, y1, width - width / 10, - height - height / 10, 150 * 64, 60 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XFillArc(dpy, wdw, gcon, x1 + width / 9, y1, width - width / 9, - height - height / 9, 145 * 64, 70 * 64); - -} - - -static void DrawUpLine(Drawable wdw, int x1, int y1, int x2, int y2, int wid) -{ - XGCValues lineattr[4]; - - XGetGCValues(dpy, gcon, - GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle, - lineattr); - XSetLineAttributes(dpy, gcon, wid, LineSolid, CapRound, JoinRound); - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y2); - XSetLineAttributes(dpy, gcon, wid - 1, LineSolid, CapRound, JoinRound); - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XDrawLine(dpy, wdw, gcon, x1 + 1, y1 - 1, x2 + 1, y2 - 1); - XSetLineAttributes(dpy, gcon, wid - 2, LineSolid, CapRound, JoinRound); - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y2); - XChangeGC(dpy, gcon, GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle, - lineattr); -} - - -static void DrawUpBox(Drawable wdw, int x1, int y1, int x2, int y2) -{ - register int lx, ly, ux, uy; - - lx = x1 + 1; - ly = y1 + 1; - ux = x2 - 1; - uy = y2 - 1; - - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y1); /* top bar */ - XDrawLine(dpy, wdw, gcon, lx, ly, ux, ly); /* top bar */ - XDrawLine(dpy, wdw, gcon, x2, y1, x2, y2); /* right bar */ - XDrawLine(dpy, wdw, gcon, ux, ly, ux, uy); /* right bar */ - - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XDrawLine(dpy, wdw, gcon, x1, y2, x2, y2); /* bottom bar */ - XDrawLine(dpy, wdw, gcon, lx, uy, ux, uy); /* bottom bar */ - XDrawLine(dpy, wdw, gcon, x1, y1, x1, y2); /* left bar */ - XDrawLine(dpy, wdw, gcon, lx, ly, lx, uy); /* left bar */ -} - - -static void DrawDnBox(Drawable wdw, int x1, int y1, int x2, int y2) -{ - register int lx, ly, ux, uy; - - lx = x1 + 1; - ly = y1 + 1; - ux = x2 - 1; - uy = y2 - 1; - - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y1); /* top bar */ - XDrawLine(dpy, wdw, gcon, lx, ly, ux, ly); /* top bar */ - XDrawLine(dpy, wdw, gcon, x2, y1, x2, y2); /* right bar */ - XDrawLine(dpy, wdw, gcon, ux, ly, ux, uy); /* right bar */ - - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XDrawLine(dpy, wdw, gcon, x1, y2, x2, y2); /* bottom bar */ - XDrawLine(dpy, wdw, gcon, lx, uy, ux, uy); /* bottom bar */ - XDrawLine(dpy, wdw, gcon, x1, y1, x1, y2); /* left bar */ - XDrawLine(dpy, wdw, gcon, lx, ly, lx, uy); /* left bar */ -} - - -static void DrawNoBox(Drawable wdw, int x1, int y1, int x2, int y2) -{ - register int lx, ly, ux, uy; - - lx = x1 + 1; - ly = y1 + 1; - ux = x2 - 1; - uy = y2 - 1; - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y1); - XDrawLine(dpy, wdw, gcon, x2, y1, x2, y2); - XDrawLine(dpy, wdw, gcon, x2, y2, x1, y2); - XDrawLine(dpy, wdw, gcon, x1, y2, x1, y1); - - XDrawLine(dpy, wdw, gcon, lx, ly, ux, ly); - XDrawLine(dpy, wdw, gcon, ux, ly, ux, uy); - XDrawLine(dpy, wdw, gcon, ux, uy, lx, uy); - XDrawLine(dpy, wdw, gcon, lx, uy, lx, ly); -} - - -static void OpenMenuBar(void) -{ - register unsigned long mask; - - mask = CWEventMask; - attr.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask; - MenuWin = XCreateWindow(dpy, MainWin, 2, 2, XRange + 49, FontHigh + 5, 0, - CopyFromParent, InputOnly, vis, mask, &attr); - - /* Create Unmapped PopUp Window! */ - mask = CWEventMask; - attr.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | - KeyPressMask | VisibilityChangeMask; - attr.background_pixel = Lut[2]; - attr.border_pixel = Lut[2]; - attr.override_redirect = True; - attr.save_under = True; - attr.colormap = cmap; - mask |= CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder | - CWColormap; - - PopUpWin = XCreateWindow(dpy, RootWin, 0, 0, 100, 100, 0, - PixDepth, InputOutput, vis, mask, &attr); - MenuFocus = False; - PopUpFlag = False; -} - - -static void OpenScrollBars(void) -{ - register unsigned long mask; - - Scrl = XCreatePixmap(dpy, MainWin, 16, 16, PixDepth); - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillRectangle(dpy, Scrl, gcon, 0, 0, 15, 15); - XSetForeground(dpy, gcon, (unsigned long) Lut[0]); - XDrawRectangle(dpy, Scrl, gcon, 0, 0, 15, 15); - DrawUpBox(Scrl, 1, 1, 14, 14); - - tilepix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) ScrlTile, 8, 8, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - - mask = CWEventMask; - attr.event_mask = ExposureMask | ButtonPressMask | ButtonMotionMask - | ButtonReleaseMask; - attr.background_pixmap = tilepix; - mask |= CWBackPixmap; - - XScrlWin = - XCreateWindow(dpy, MainWin, 14, YRange + MenuHigh + 24, XRange, 16, 0, - CopyFromParent, InputOutput, vis, mask, &attr); - lfpix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) LfArrow, 16, 16, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - rgpix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) RgArrow, 16, 16, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - - YScrlWin = - XCreateWindow(dpy, MainWin, XRange + 24, MenuHigh + 14, 16, YRange, 0, - CopyFromParent, InputOutput, vis, mask, &attr); - uppix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) UpArrow, 16, 16, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - dnpix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) DnArrow, 16, 16, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - - ScrlX = (XRange / 2) - 8; - ScrlY = (YRange / 2) - 8; -} - - -static void DrawXScroll(void) -{ - XCopyArea(dpy, rgpix, XScrlWin, gcon, 0, 0, 16, 16, XRange - 16, 0); - XCopyArea(dpy, Scrl, XScrlWin, gcon, 0, 0, 16, 16, ScrlX, 0); - XCopyArea(dpy, lfpix, XScrlWin, gcon, 0, 0, 16, 16, 0, 0); -} - - -static void DrawYScroll(void) -{ - XCopyArea(dpy, dnpix, YScrlWin, gcon, 0, 0, 16, 16, 0, YRange - 16); - XCopyArea(dpy, Scrl, YScrlWin, gcon, 0, 0, 16, 16, 0, ScrlY); - XCopyArea(dpy, uppix, YScrlWin, gcon, 0, 0, 16, 16, 0, 0); -} - - -void UpdateScrollBars(void) -{ - register int temp; - - if (RotMode == RotAll) { - temp = (WorldDialValue[YScrlDial] + 1.0) * (YRange - 48); - } else { - temp = (DialValue[YScrlDial] + 1.0) * (YRange - 48); - } - NewScrlY = (temp >> 1) + 16; - - if (NewScrlY != ScrlY) { - XClearArea(dpy, YScrlWin, 0, ScrlY, 16, 16, False); - XCopyArea(dpy, Scrl, YScrlWin, gcon, 0, 0, 16, 16, 0, NewScrlY); - ReDrawFlag |= (1 << YScrlDial); - ScrlY = NewScrlY; - } - - if ((RotMode == RotBond) && BondSelected) { - temp = ((BondSelected->BRotValue) + 1.0) * (XRange - 48); - } else { - if (RotMode == RotAll) { - temp = (WorldDialValue[XScrlDial] + 1.0) * (XRange - 48); - } else { - temp = (DialValue[XScrlDial] + 1.0) * (XRange - 48); - } - } - NewScrlX = (temp >> 1) + 16; - - if (NewScrlX != ScrlX) { - XClearArea(dpy, XScrlWin, ScrlX, 0, 16, 16, False); - XCopyArea(dpy, Scrl, XScrlWin, gcon, 0, 0, 16, 16, NewScrlX, 0); - ReDrawFlag |= (1 << XScrlDial); - ScrlX = NewScrlX; - } - XFlush(dpy); -} - - -#ifdef DIALBOX -static void SetDialLabel(int num, char *ptr) -{ - static XStringFeedbackControl ctrl; - static KeySym text[8]; - register int length; - - length = 0; - while (*ptr) - text[length++] = *ptr++; - - ctrl.id = num; - ctrl.num_keysyms = length; - ctrl.class = ValuatorClass; - ctrl.syms_to_display = text; - XChangeFeedbackControl(dpy, Dials, DvString, (XFeedbackControl *) & ctrl); -} - - -static void GetDialState(void) -{ - register XValuatorState *ptr; - register XDeviceState *stat; - register int i, j, max; - - stat = XQueryDeviceState(dpy, Dials); - ptr = (XValuatorState *) stat->data; - for (i = 0; i < stat->num_classes; i++) { - if (ptr->class == ValuatorClass) { - if (ptr->mode & 0x01) { - DialMode = Absolute; - max = MinFun(ptr->num_valuators, 8); - for (j = 0; j < max; j++) - DialPrev[j] = ptr->valuators[j]; - } else - DialMode = Relative; - break; - } else - ptr = (XValuatorState *) (((char *) ptr) + ptr->length); - } - XFreeDeviceState(stat); -} - - -static void OpenDialsBox(void) -{ - register XValuatorInfo *valptr; - register XFeedbackState *list; - register XFeedbackState *feed; - register XDeviceInfo *devlist; - register XDeviceInfo *ptr; - register Atom devtype; - register int i, j, max; - - static XEventClass dclass; - static int count; - - UseDials = False; - /* Avoid X Server's without the extension */ - if (!XQueryExtension(dpy, "XInputExtension", &count, &count, &count)) - return; - - devlist = XListInputDevices(dpy, &count); - devtype = XInternAtom(dpy, XI_KNOB_BOX, True); - if ((devtype == None) || !devlist) - return; - - ptr = devlist; - for (i = 0; i < count; i++) - if ((ptr->use == IsXExtensionDevice) && (ptr->type == devtype)) { - valptr = (XValuatorInfo *) ptr->inputclassinfo; - for (j = 0; j < ptr->num_classes; j++) { - if (valptr->class == ValuatorClass) - if ((Dials = XOpenDevice(dpy, ptr->id))) { - UseDials = True; - break; - } - valptr = (XValuatorInfo *) (((char *) valptr) + - valptr->length); - } - if (UseDials) - break; - } else - ptr++; - /* XFreeDeviceList(devlist); */ - - if (UseDials) { /* Determine Dial Mapping! */ - if (!strcmp(ServerVendor(dpy), "Silicon Graphics")) { - DialMap = SGIDialMap; - } else - DialMap = ESVDialMap; - - DialMode = valptr->mode; - max = MinFun(valptr->num_axes, 8); - for (i = 0; i < max; i++) - DialRes[i] = (Real) valptr->axes[i].resolution; - GetDialState(); - } else - return; - - UseDialLEDs = 0; - feed = list = XGetFeedbackControl(dpy, Dials, &count); - for (i = 0; i < count; i++) { - if (feed->class == StringFeedbackClass) - UseDialLEDs++; - feed = (XFeedbackState *) (((char *) feed) + feed->length); - } - XFreeFeedbackList(list); - - if (UseDialLEDs >= 8) { - for (i = 0; i < 8; i++) - SetDialLabel(i, DialLabel[DialMap[i]]); - } else - UseDialLEDs = False; - - DeviceMotionNotify(Dials, DialEvent, dclass); - XSelectExtensionEvent(dpy, MainWin, &dclass, 1); - XSelectExtensionEvent(dpy, MenuWin, &dclass, 1); - XSelectExtensionEvent(dpy, CanvWin, &dclass, 1); - XSelectExtensionEvent(dpy, XScrlWin, &dclass, 1); - XSelectExtensionEvent(dpy, YScrlWin, &dclass, 1); -} - - -static void HandleDialEvent(XDeviceMotionEvent *ptr) -{ - register double temp; - register int count; - register int value; - register int index; - register int num; - - /* Limit Number of Dials */ - count = 8 - ptr->first_axis; - if (count > (int) ptr->axes_count) - count = (int) ptr->axes_count; - - for (index = 0; index < count; index++) { - num = ptr->first_axis + index; - if (DialMode == Absolute) { - value = ptr->axis_data[index] - DialPrev[num]; - DialPrev[num] = ptr->axis_data[index]; - } else - value = ptr->axis_data[index]; - - if (value) { - temp = (Real) value / DialRes[num]; - num = DialMap[num]; - if (num == YScrlDial || num == XScrlDial) { - if ((RotMode == RotBond) && BondSelected && num == XScrlDial) { - temp += BondSelected->BRotValue; - ReDrawFlag |= RFRotBond; - } else { - if (RotMode == RotAll) { - temp += WorldDialValue[num]; - ReDrawFlag |= (1 << num); - } else { - temp += DialValue[num]; - ReDrawFlag |= (1 << num); - } - } - } else { - temp += DialValue[num]; - ReDrawFlag |= (1 << num); - } - - if (num < 3) { - while (temp < -1.0) - temp += 2.0; - while (temp > 1.0) - temp -= 2.0; - } else { - if (temp < -1.0) - temp = -1.0; - if (temp > 1.0) - temp = 1.0; - } - if (num == YScrlDial || num == XScrlDial) { - if ((RotMode == RotBond) && BondSelected && num == XScrlDial) { - BondSelected->BRotValue = temp; - ReDrawFlag |= RFRotBond; - } else { - if (RotMode == RotAll) { - WorldDialValue[num] = temp; - } else { - DialValue[num] = temp; - } - } - } else { - DialValue[num] = temp; - } - - if (num == YScrlDial) { - value = (temp + 1.0) * (YRange - 48); - NewScrlY = (value >> 1) + 16; - } - - if (num == XScrlDial) { - value = (temp + 1.0) * (XRange - 48); - NewScrlX = (value >> 1) + 16; - } - } - } -} -#endif - - -static void DrawMainWin(void) -{ - register int temp; - - DrawUpBox(MainWin, 0, 0, MainWide, MainHigh); - DrawUpBox(MainWin, 0, 0, MainWide - 2, FontHigh + 7); - - temp = YRange + MenuHigh; - DrawDnBox(MainWin, 12, MenuHigh + 12, XRange + 16, temp + 16); - DrawDnBox(MainWin, XRange + 22, MenuHigh + 12, XRange + 41, temp + 16); - DrawDnBox(MainWin, 12, temp + 22, XRange + 16, temp + 41); -} - - -/*====================*/ -/* Menu Bar Display */ -/*====================*/ - -static void DisplayMenuBarText(BarItem * ptr, int x, int y) -{ - register unsigned long col; - register int under, pos, wide; - int slen; - - if (ptr->flags & mbEnable && !DisableMenu) { - col = Lut[0]; - } else - col = Lut[1]; - XSetForeground(dpy, gcon, col); - - if (ptr->len) { - slen = *(ptr->len); - } else { - slen = strlen(*(ptr->text)); - } - if (MenuFontSet) { - XmbDrawString(dpy, MainWin, MenuFontSet, gcon, x, y, *(ptr->text), - slen); - under = y + XFdescent; - } else { - XDrawString(dpy, MainWin, gcon, x, y, *(ptr->text), slen); - under = y + MenuFont->descent; - } - - if (!isascii(*(*(ptr->text) + *(ptr->pos)))) - return; - - pos = x; - if (*(ptr->pos) > 0) - pos += XTextWidth(MenuFont, *(ptr->text), *(ptr->pos)); - - if (MenuFontSet) { - if (*(ptr->pos) > 0) - pos += XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->pos)); - wide = -XmbTextEscapement(MenuFontSet, *(ptr->text) + *(ptr->pos) + 1, - slen - *(ptr->pos) - 1) - + XmbTextEscapement(MenuFontSet, *(ptr->text) + *(ptr->pos), - slen - *(ptr->pos)); - } else { - wide = -XTextWidth(MenuFont, *(ptr->text) + *(ptr->pos) + 1, - slen - *(ptr->pos) - 1) - + XTextWidth(MenuFont, *(ptr->text) + *(ptr->pos), - slen - *(ptr->pos)); - } - - if (wide > 3) - wide--; - if (wide > 6) - wide--; - - XDrawLine(dpy, MainWin, gcon, pos, under, pos + wide, under); -} - - -static void DrawMenuBar(void) -{ - register BarItem *ptr; - register int wide; - register int x, y; - register int i; - - if (Language != TermLanguage) { - if (RasOpenFonts()) { - Language = TermLanguage; - RasOpenFonts(); - } - TermLanguage = Language; - } - - x = 6; - if (MenuFontSet) { - y = XFascent + 4; - } else { - y = MenuFont->ascent + 4; - XSetFont(dpy, gcon, MenuFont->fid); - } - - for (i = 0; i < MenuBarMax; i++) { - ptr = MenuBar + i; - if (MenuFontSet) { - wide = XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->len)); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - if (x + wide + 24 > MainWide) - break; - - /* Right Justify "Help" */ - if (i == MenuBarMax - 1) - x = MainWide - (wide + 24); - DisplayMenuBarText(ptr, x + 8, y); - - if (MenuFocus && (i == MenuBarSelect)) { - DrawUpBox(MainWin, x, 2, x + wide + 16, FontHigh + 5); - } else - DrawNoBox(MainWin, x, 2, x + wide + 16, FontHigh + 5); - x += wide + 24; - } - MenuBarCount = i; - XFlush(dpy); -} - - -/*=======================*/ -/* Pop-up Menu Display */ -/*=======================*/ -static void DisplayPopUpText(MenuItem * ptr, int x, int y) -{ - register unsigned long col; - register int pos, wide; - register int under; - int slen; - - col = (ptr->flags & mbEnable) ? Lut[0] : Lut[1]; - XSetForeground(dpy, gcon, col); - - if (ptr->enable && (*(ptr->enable) == ptr->value)) { - if (MenuFontSet) { - XDrawLine(dpy, PopUpWin, gcon, x - 9, y + XFdescent - FontHigh / 2, - x - 7, y + XFdescent - 2); - XDrawLine(dpy, PopUpWin, gcon, x - 7, y + XFdescent - 2, - x - 3, y + XFdescent - FontHigh + 2); - } else { - XDrawLine(dpy, PopUpWin, gcon, x - 9, - y + MenuFont->descent - FontHigh / 2, x - 7, - y + MenuFont->descent - 2); - XDrawLine(dpy, PopUpWin, gcon, x - 7, y + MenuFont->descent - 2, - x - 3, y + MenuFont->descent - FontHigh + 2); - } - } - if (ptr->len) { - slen = *(ptr->len); - } else { - slen = strlen(*(ptr->text)); - } - if (MenuFontSet) { - XmbDrawString(dpy, PopUpWin, MenuFontSet, gcon, - x, y, *(ptr->text), slen); - if ((ptr->flags & mbAccel) && isascii(*(*(ptr->text) + *(ptr->pos)))) { - under = y + XFdescent; - pos = x; - if (*(ptr->pos) > 0) - pos += - XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->pos)); - wide = - -XmbTextEscapement(MenuFontSet, *(ptr->text) + *(ptr->pos) + 1, - slen - *(ptr->pos) - 1) - + XmbTextEscapement(MenuFontSet, *(ptr->text) + *(ptr->pos), - slen - *(ptr->pos)); - - if (wide > 3) - wide--; - if (wide > 6) - wide--; - - XDrawLine(dpy, PopUpWin, gcon, pos, under, pos + wide, under); - } - } else { - XDrawString(dpy, PopUpWin, gcon, x, y, *(ptr->text), slen); - if ((ptr->flags & mbAccel) && isascii(*(*(ptr->text) + *(ptr->pos)))) { - under = y + MenuFont->descent; - pos = x; - if (*(ptr->pos) > 0) - pos += XTextWidth(MenuFont, *(ptr->text), *(ptr->pos)); - wide = - -XTextWidth(MenuFont, *(ptr->text) + *(ptr->pos) + 1, - slen - *(ptr->pos) - 1) - + XTextWidth(MenuFont, *(ptr->text) + *(ptr->pos), - slen - *(ptr->pos)); - - if (wide > 3) - wide--; - if (wide > 6) - wide--; - - XDrawLine(dpy, PopUpWin, gcon, pos, under, pos + wide, under); - } - } -} - - -static void DrawPopUpMenu(void) -{ - register MenuItem *ptr; - register int count; - register int x, y; - register int i; - - DrawUpBox(PopUpWin, 0, 0, PopUpWide, PopUpHigh); - - if (MenuBarSelect < 0) - MenuBarSelect = 0; - if (MenuBarSelect >= MenuBarMax) - MenuBarSelect = MenuBarMax - 1; - - ptr = MenuBar[MenuBarSelect].menu; - count = MenuBar[MenuBarSelect].count; - if (MenuBar[MenuBarSelect].increment && - *(MenuBar[MenuBarSelect].increment)) { - count += 1 + *(MenuBar[MenuBarSelect].increment); - } - - y = 2; - x = 2; - for (i = 0; i < count; i++) { - if (!(ptr->flags & mbSepBar)) { - DisplayPopUpText(ptr, x + 12, y + XFascent + 2); - if (ItemFlag && (i == MenuItemSelect)) { - DrawUpBox(PopUpWin, 2, y, PopUpWide - 2, y + FontHigh + 3); - } else - DrawNoBox(PopUpWin, 2, y, PopUpWide - 2, y + FontHigh + 3); - y += FontHigh + 4; - } else { - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XDrawLine(dpy, PopUpWin, gcon, 2, y, PopUpWide - 2, y); - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XDrawLine(dpy, PopUpWin, gcon, 2, y + 1, PopUpWide - 2, y + 1); - y += 2; - } - ptr++; - } - /* XSync(dpy,False); */ - XFlush(dpy); -} - - -static void DisplayPopUpMenu(int i, int x) -{ - register int wide, count; - register MenuItem *ptr; - static int xpos, ypos; - static Window win; - XRectangle bound; - XRectangle dummy; - - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - UnDisplayAboutDLG(); - } - MenuBarSelect = i; - DrawMenuBar(); - - ptr = MenuBar[i].menu; - count = MenuBar[i].count; - if (MenuBar[i].increment && *(MenuBar[i].increment)) { - count += 1 + *(MenuBar[i].increment); - } - - PopUpHigh = 4; - PopUpWide = 8; - for (i = 0; i < count; i++) { - if (!(ptr->flags & mbSepBar)) { - if (MenuFontSet) { - wide = - XmbTextExtents(MenuFontSet, *(ptr->text), *(ptr->len), - &dummy, &bound); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - if (wide + 28 > PopUpWide) - PopUpWide = wide + 28; - PopUpHigh += FontHigh + 4; - } else - PopUpHigh += 2; - ptr++; - } - /* Determine pop-up menu position! */ - XTranslateCoordinates(dpy, MainWin, RootWin, x, FontHigh + 6, - &xpos, &ypos, &win); - - if (ypos + PopUpHigh > MaxHeight) - ypos -= (PopUpHigh + FontHigh + 6); - if (xpos + PopUpWide > MaxWidth) - xpos = MaxWidth - PopUpWide; - if (xpos < 0) - xpos = 0; - - XUnmapWindow(dpy, PopUpWin); - XMoveResizeWindow(dpy, PopUpWin, xpos, ypos, PopUpWide + 1, PopUpHigh + 1); - XRaiseWindow(dpy, PopUpWin); - XMapWindow(dpy, PopUpWin); - PopUpFlag = True; - DrawPopUpMenu(); -} - - -static void DisplayAboutDLGText(DLGItem * ptr, int x, int y, int center) -{ - register unsigned long col; - register int wide; - int slen; - - col = Lut[0]; - XSetForeground(dpy, gcon, col); - - slen = strlen(*(ptr->text)); - - if (center) { - - if (MenuFontSet) { - wide = XmbTextEscapement(MenuFontSet, *(ptr->text), slen); - XmbDrawString(dpy, PopUpWin, MenuFontSet, gcon, - x + (ptr->x + (ptr->width)/2) * DLGScale - wide/2, - y + (ptr->y) * DLGScale, *(ptr->text), slen); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), slen); - XDrawString(dpy, PopUpWin, gcon, - x + (ptr->x + (ptr->width) / 2) * DLGScale - wide / 2, - y + (ptr->y) * DLGScale, *(ptr->text), slen); - } - } else { - if (MenuFontSet) { - XmbDrawString(dpy, PopUpWin, MenuFontSet, gcon, - x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale, *(ptr->text), slen); - } else { - XDrawString(dpy, PopUpWin, gcon, - x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale, *(ptr->text), slen); - } - } -} - - -void DrawAboutDLG(void) -{ - register DLGItem *ptr; - register int count; - register int x, y; - register int i; - - DrawUpBox(PopUpWin, 0, 0, PopUpWide, PopUpHigh); - - ptr = AboutDLG; - count = AboutDLGCount; - - y = 2 + FontHigh; - x = 2; - for (i = 0; i < count; i++) { - switch (ptr->DLGtype) { - case DLGICON:{ - int box1[4], box2[4], box3[4]; - - DrawUpBox(PopUpWin, - x+(ptr->x)*DLGScale-4, - y+(ptr->y)*DLGScale-4-(ptr->height)*DLGScale, - x+(ptr->x)*DLGScale+4+(ptr->width)*DLGScale, - y+(ptr->y)*DLGScale+4); - - box1[0] = x + (ptr->x) * DLGScale; - box1[1] = box2[1] = - y + (ptr->y)*DLGScale - (ptr->height) * 9 * DLGScale/200; - box1[2] = box2[2] = box3[2] = (ptr->width / 2 - 1) * DLGScale; - box1[3] = box2[3] = box3[3] = - (ptr->height/2-1)*DLGScale - (ptr->height)*9*DLGScale/200; - - box2[0] = - x + (ptr->x)*DLGScale + (ptr->width)*DLGScale - box2[2]; - - box3[0] = x + (box1[0] + box2[0] - 1) / 2; - box3[1] = box1[1] - 178*(box2[0]-box1[0]+1)/200-(ptr->height)*9*DLGScale/200; - - DrawUpCircle(PopUpWin, - box2[0], - box2[1] - box2[3], - box2[0] + box2[2], - box2[1]); - - DrawUpLine(PopUpWin, - box2[0] + box2[2] / 2 + (box3[0] - box2[0]) / 4, - box2[1] - box2[2] / 2 + (box3[1] - box2[1]) / 4, - box2[0] + box2[2] / 2 + 3 * (box3[0] - box2[0]) / 4, - box2[1] - box2[3] / 2 + 3 * (box3[1] - box2[1]) / 4, - 6); - - DrawUpCircle(PopUpWin, box3[0], box3[1] - box3[3], - box3[0] + box3[2], box3[1]); - - DrawUpLine(PopUpWin, - box3[0] + box3[2] / 2 + (box1[0] - box3[0]) / 4, - box3[1] - box3[2] / 2 + (box1[1] - box3[1]) / 4, - box3[0] + box3[2] / 2 + 3 * (box1[0] - box3[0]) / 4, - box3[1] - box3[3] / 2 + 3 * (box1[1] - box3[1]) / 4, - 6); - - DrawUpCircle(PopUpWin, box1[0], box1[1] - box1[3], - box1[0] + box1[2], box1[1]); - - DrawUpLine(PopUpWin, - box1[0] + box1[2] / 2 + (box2[0] - box1[0]) / 4, - box1[1] - box1[2] / 2 + (box2[1] - box1[1]) / 4, - box1[0] + box1[2] / 2 + 3 * (box2[0] - box1[0]) / 4, - box1[1] - box1[3] / 2 + 3 * (box2[1] - box1[1]) / 4, - 6); - - DrawUpPieSlice(PopUpWin, box2[0], box2[1] - box2[3], - box2[0] + box2[2], box2[1]); - break; - } - case DLGCTEXT: -#ifdef USE_UNAME - if (ptr->Identifier == IDD_HARDWARE && !uname(&AboutDLGUNAME)) { - int klen; - - klen = 0; - strncpy(unamebuffer, AboutDLGUNAME.sysname, 81); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - if (79 - klen > strlen(AboutDLGUNAME.nodename)) { - unamebuffer[klen] = ' '; - strncpy(unamebuffer + klen + 1, AboutDLGUNAME.nodename, - 81 - klen); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - } - /* if (79-klen > strlen(AboutDLGUNAME.release)) { - unamebuffer[klen] = ' '; - strncpy(unamebuffer+klen+1,AboutDLGUNAME.release,81-klen); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - } */ - if (79 - klen > strlen(AboutDLGUNAME.version)) { - unamebuffer[klen] = ' '; - strncpy(unamebuffer + klen + 1, AboutDLGUNAME.version, - 81 - klen); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - } - if (79 - klen > strlen(AboutDLGUNAME.machine)) { - unamebuffer[klen] = ' '; - strncpy(unamebuffer + klen + 1, AboutDLGUNAME.machine, - 81 - klen); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - } - } -#endif - DisplayAboutDLGText(ptr, x, y, True); - /* WriteString("\n");WriteString(*(ptr->text) ); */ - break; - case DLGPUSHBUTTON: - DisplayAboutDLGText(ptr, x, - y - ((ptr->height) * DLGScale + 4 - - FontHigh) / 2, True); - if (ptr->status) { - DrawDnBox(PopUpWin, x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale - ((ptr->height) * DLGScale), - x + (ptr->x) * DLGScale + (ptr->width) * DLGScale, - y + (ptr->y) * DLGScale); - break; - } else { - DrawUpBox(PopUpWin, x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale - ((ptr->height) * DLGScale), - x + (ptr->x) * DLGScale + (ptr->width) * DLGScale, - y + (ptr->y) * DLGScale); - break; - } - case DLGCHECKBOX: - DisplayAboutDLGText(ptr, x + (ptr->height) * DLGScale + 2, y, - False); - if (ptr->status) { - DrawDnBox(PopUpWin, x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale - (ptr->height) * DLGScale, - x + (ptr->x) * DLGScale + (ptr->height) * DLGScale, - y + (ptr->y) * DLGScale); - break; - } else { - DrawUpBox(PopUpWin, x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale - (ptr->height) * DLGScale, - x + (ptr->x) * DLGScale + (ptr->height) * DLGScale, - y + (ptr->y) * DLGScale); - break; - } - } - ptr++; - - } - /* WriteString("\n\n"); */ - XFlush(dpy); -} - - -void DisplayAboutDLG(void) -{ - - static int xpos, ypos; - static Window win; - - MenuBarSelect = AboutDLGMItem; - DrawMenuBar(); - - if (AboutDLG[AboutDLGNOSHOWindex].DLGtype == DLGCHECKBOX - && AboutDLG[AboutDLGNOSHOWindex].Identifier == IDD_NOSHOW) { - if (getraid(filaid, 1025, fillang, 81) - && DetermineApplicationIdentifier(macaid, 1025) - && !strncasecmp(filaid, macaid, 1024)) { - AboutDLG[AboutDLGNOSHOWindex].status = 1; - } else { - AboutDLG[AboutDLGNOSHOWindex].status = 0; - } - } - - ItemFlag = False; - - PopUpHigh = AboutDLGHeight * DLGScale + 4; - PopUpWide = AboutDLGWidth * DLGScale + 4; - /* Determine pop-up menu position! */ - XTranslateCoordinates(dpy, MainWin, RootWin, AboutDLGXpos, FontHigh + 6, - &xpos, &ypos, &win); - - if (ypos + PopUpHigh > MaxHeight) - ypos -= (PopUpHigh + FontHigh + 6); - if (xpos + PopUpWide > MaxWidth) - xpos = MaxWidth - PopUpWide; - if (xpos < 0) - xpos = 0; - - XUnmapWindow(dpy, PopUpWin); - XMoveResizeWindow(dpy, PopUpWin, xpos, ypos, PopUpWide + 1, PopUpHigh + 1); - XRaiseWindow(dpy, PopUpWin); - XMapWindow(dpy, PopUpWin); - PopUpFlag = True; - DrawAboutDLG(); - ItemFocus = True; -} - - -void UnDisplayAboutDLG(void) -{ - - MenuBarSelect = 0; - DrawMenuBar(); - - ItemFlag = False; - - if (AboutDLG[AboutDLGNOSHOWindex].DLGtype == DLGCHECKBOX - && AboutDLG[AboutDLGNOSHOWindex].Identifier == IDD_NOSHOW) { - if (AboutDLG[AboutDLGNOSHOWindex].status && - DetermineApplicationIdentifier(macaid, 1025)) { - setraid(macaid, lang2str(Language)); - } else { - setraid("", lang2str(Language)); - } - } else { - FatalGraphicsError("Improperly structured AboutDLG in graphics.h"); - } - - XUnmapWindow(dpy, PopUpWin); - PopUpFlag = False; -} - - -/*==============================*/ -/* Pop-Up Menu Event Handling */ -/*==============================*/ - -static void HandleItemClick(int xpos, int ypos) -{ - register MenuItem *ptr; - register DLGItem *qtr; - register int count, i; - register int xo, yo; - - /* Ignore by not setting ItemFocus! */ - if ((xpos < 0) || (xpos > PopUpWide)) - return; - if ((ypos < 0) || (ypos > PopUpHigh)) - return; - ItemFocus = True; - - if (MenuBarSelect == AboutDLGMItem) { - MenuItemSelect = -1; - qtr = AboutDLG; - count = AboutDLGCount; - yo = 2 + FontHigh; - xo = 2; - for (i = 0; i < count; i++) { - if (qtr->DLGtype == DLGPUSHBUTTON ) { - if (xpos >= xo+(qtr->x)*DLGScale - && xpos <= xo+(qtr->x)*DLGScale+(qtr->width)*DLGScale - && ypos >= yo+(qtr->y)*DLGScale-(qtr->height)*DLGScale - && ypos <= yo+(qtr->y)*DLGScale) { - MenuItemSelect = i; - ItemFlag = True; - return; - } - } else if (qtr->DLGtype == DLGCHECKBOX) { - if (xpos >= xo+(qtr->x)*DLGScale - && xpos <= xo+(qtr->x)*DLGScale+(qtr->height)*DLGScale - && ypos >= yo+(qtr->y)*DLGScale-(qtr->height)*DLGScale - && ypos <= yo+(qtr->y)*DLGScale) { - MenuItemSelect = i; - ItemFlag = True; - return; - } - } - qtr++; - } - ItemFlag = False; - return; - - } else { - - ptr = MenuBar[MenuBarSelect].menu; - count = MenuBar[MenuBarSelect].count; - if (MenuBar[MenuBarSelect].increment && - *(MenuBar[MenuBarSelect].increment)) { - count += 1 + *(MenuBar[MenuBarSelect].increment); - } - - yo = 2; - for (i = 0; i < count; i++) { - if (!(ptr->flags & mbSepBar)) { - if ((ypos >= yo) && (ypos <= yo + FontHigh + 3)) { - if (ptr->flags & mbEnable) { - if (!ItemFlag || (MenuItemSelect != i)) { /* Avoid Flickering */ - MenuItemSelect = i; - ItemFlag = True; - DrawPopUpMenu(); - } - return; - } else - break; - } - yo += FontHigh + 4; - } else - yo += 2; - ptr++; - } - } - - if (ItemFlag) { - ItemFlag = False; - if (MenuBarSelect == AboutDLGMItem) { - DrawAboutDLG(); - } else { - DrawPopUpMenu(); - } - } -} - - -static void HandleItemMove(int xpos, int ypos) -{ - register MenuItem *ptr; - register DLGItem *qtr; - register int count, i; - - static int xo, yo; - - if (MenuBarSelect == AboutDLGMItem) { - if ((xpos >= 0) && (xpos <= PopUpWide) - && (ypos >= 0) && (ypos <= PopUpHigh)) { - qtr = AboutDLG; - count = AboutDLGCount; - yo = 2 + FontHigh; - xo = 2; - for (i = 0; i < count; i++) { - if (qtr->DLGtype == DLGPUSHBUTTON) { - if (xpos >= xo + (qtr->x) * DLGScale - && xpos <= xo+(qtr->x)*DLGScale+(qtr->width)*DLGScale - && ypos >= yo+(qtr->y)*DLGScale-(qtr->height)*DLGScale - && ypos <= yo+(qtr->y)*DLGScale) { - MenuItemSelect = i; - ItemFlag = True; - return; - } - } else if (qtr->DLGtype == DLGCHECKBOX) { - if (xpos >= xo + (qtr->x) * DLGScale - && xpos <= xo+(qtr->x)*DLGScale+(qtr->height)*DLGScale - && ypos >= yo+(qtr->y)*DLGScale-(qtr->height)*DLGScale - && ypos <= yo+(qtr->y)*DLGScale) { - MenuItemSelect = i; - ItemFlag = True; - return; - } - } - qtr++; - } - } - - } else { - - if ((xpos >= 0) && (xpos <= PopUpWide)) { - ptr = MenuBar[MenuBarSelect].menu; - count = MenuBar[MenuBarSelect].count; - if (MenuBar[MenuBarSelect].increment && - *(MenuBar[MenuBarSelect].increment)) { - count += 1 + *(MenuBar[MenuBarSelect].increment); - } - - yo = 2; - for (i = 0; i < count; i++) { - if (!(ptr->flags & mbSepBar)) { - if ((ypos >= yo) && (ypos <= yo + FontHigh + 3)) { - if (!ItemFlag || (MenuItemSelect != i)) { /* Avoid Flicker! */ - MenuItemSelect = i; - ItemFlag = True; - DrawPopUpMenu(); - } - ItemFocus = True; - return; - } - yo += FontHigh + 4; - } else - yo += 2; - ptr++; - } - } - - } - - if (ItemFlag) { /* Avoid Flicker! */ - ItemFlag = False; - if (MenuBarSelect == AboutDLGMItem) { - DrawAboutDLG(); - } else { - DrawPopUpMenu(); - } - } -} - - -static int HandleItemKey(int key) -{ - register MenuItem *ptr; - register int count; - register int item; - register int ch; - register int i; - - key = ToUpper(key); - item = MenuItemSelect; - ptr = &MenuBar[MenuBarSelect].menu[item]; - count = MenuBar[MenuBarSelect].count; - if (MenuBar[MenuBarSelect].increment && - *(MenuBar[MenuBarSelect].increment)) { - count += 1 + *(MenuBar[MenuBarSelect].increment); - } - for (i = 0; i < count; i++) { - if ((ptr->flags & (mbEnable | mbAccel)) - && isascii(*(*(ptr->text) + *(ptr->pos))) - && !(ptr->flags & mbSepBar)) { - ch = (*(ptr->text))[*(ptr->pos)]; - if (ToUpper(ch) == key) - return ((MenuBarSelect << 8) + item + 1); - } - - /* Advance to next item! */ - if (item == count - 1) { - ptr = MenuBar[MenuBarSelect].menu; - item = 0; - } else { - item++; - ptr++; - } - } - return 0; -} - - -static void SelectFirstItem(int menu) -{ - register MenuItem *ptr; - register int count; - register int i; - - count = MenuBar[menu].count; - if (MenuBar[menu].increment && *(MenuBar[menu].increment)) { - count += 1 + *(MenuBar[menu].increment); - } - ptr = MenuBar[menu].menu; - - ItemFlag = False; - for (i = 0; i < count; i++) - if ((ptr->flags & mbEnable) && !(ptr->flags & mbSepBar)) { - MenuItemSelect = i; - ItemFlag = True; - break; - } else - ptr++; -} - - -static void SelectPrevItem(void) -{ - register BarItem *ptr; - register int flags; - register int item; - register int i; - - if (!ItemFlag || MenuBarSelect == AboutDLGMItem) - return; - - item = MenuItemSelect; - ptr = MenuBar + MenuBarSelect; - for (i = 0; i < ptr->count; i++) { - if (!item) { - item = ptr->count - 1; - } else - item--; - - flags = ptr->menu[item].flags; - if ((flags & mbEnable) && !(flags & mbSepBar)) - break; - } - - if (item != MenuItemSelect) { - MenuItemSelect = item; - DrawPopUpMenu(); - } -} - - -static void SelectNextItem(void) -{ - register BarItem *ptr; - register int flags; - register int item; - register int i; - - if (!ItemFlag || MenuBarSelect == AboutDLGMItem) - return; - - item = MenuItemSelect; - ptr = MenuBar + MenuBarSelect; - for (i = 0; i < ptr->count; i++) { - if (item == ptr->count - 1) { - item = 0; - } else - item++; - - flags = ptr->menu[item].flags; - if ((flags & mbEnable) && !(flags & mbSepBar)) - break; - } - - if (item != MenuItemSelect) { - MenuItemSelect = item; - DrawPopUpMenu(); - } -} - - - -/*===========================*/ -/* Menu Bar Event Handling */ -/*===========================*/ - -static void SelectMenu(int menu) -{ - register BarItem *ptr; - register int wide; - register int i, x; - - if (!PopUpFlag) { - MenuBarSelect = menu; - DrawMenuBar(); - return; - } - - if (menu != MenuBarMax - 1) { - x = 6; - for (i = 0; i < menu; i++) { - ptr = MenuBar + i; - if (MenuFontSet) { - wide = - XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->len)); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - x += wide + 24; - } - } else { - ptr = MenuBar + menu; - if (MenuFontSet) { - wide = XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->len)); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - x = MainWide - (wide + 24); - } - - SelectFirstItem(menu); - DisplayPopUpMenu(menu, x); - ItemFocus = False; -} - - -static int HandleMenuClick(int pos) -{ - register BarItem *ptr; - register int wide; - register int x, i; - - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) - UnDisplayAboutDLG(); - x = 6; - for (i = 0; i < MenuBarCount; i++) { - ptr = MenuBar + i; - if (MenuFontSet) { - wide = XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->len)); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - if (i == MenuBarMax - 1) - x = MainWide - (wide + 24); - - if ((pos >= x) && (pos <= x + wide + 16)) { - if (!PopUpFlag || (MenuBarSelect != i)) { - ItemFlag = False; - DisplayPopUpMenu(i, x); - } else if (ItemFlag) { - ItemFlag = False; - DrawPopUpMenu(); - } - ItemFocus = True; - return True; - } else - x += wide + 24; - } - return False; -} - - -static int HandleMenuKey(char key) -{ - register int i; - - key = ToUpper(key); - for (i = 0; i < MenuBarCount; i++) - if (ToUpper((*(MenuBar[i].text))[*(MenuBar[i].pos)]) == key) { - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - UnDisplayAboutDLG(); - } - if (!PopUpFlag || (MenuBarSelect != i)) { - PopUpFlag = True; - SelectMenu(i); - } - return True; - } - return False; -} - - -void EnableMenus(int flag) -{ - DisableMenu = !flag; - if (Interactive) { - DrawMenuBar(); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - } - -} - - -static void ReSizeWindow(int wide, int high) -{ - register Real xpos; - register Real ypos; - register int dx; - - xpos = (XRange > 48) ? (Real) (ScrlX - 16) / (XRange - 48) : 0.0; - ypos = (YRange > 48) ? (Real) (ScrlY - 16) / (YRange - 48) : 0.0; - - YRange = high - (MenuHigh + 53); - XRange = wide - 53; - ZRange = 20000; - - if ((dx = XRange % 4)) - XRange += 4 - dx; - - MainHigh = YRange + (MenuHigh + 53); - HRange = YRange >> 1; - MainWide = XRange + 53; - WRange = XRange >> 1; - Range = MinFun(XRange, YRange); - - XResizeWindow(dpy, CanvWin, XRange, YRange); - XResizeWindow(dpy, MenuWin, XRange + 49, FontHigh + 5); - XMoveResizeWindow(dpy, XScrlWin, 14, YRange + MenuHigh + 24, XRange, 16); - XMoveResizeWindow(dpy, YScrlWin, XRange + 24, MenuHigh + 14, 16, YRange); - - NewScrlX = ScrlX = (xpos * (XRange - 48)) + 16; - NewScrlY = ScrlY = (ypos * (YRange - 48)) + 16; - - XClearWindow(dpy, MainWin); - XClearWindow(dpy, CanvWin); - - DrawXScroll(); - DrawYScroll(); - DrawMainWin(); - DrawMenuBar(); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - int xpos, ypos; - Window win; - - XTranslateCoordinates(dpy, MainWin, RootWin, AboutDLGXpos, - FontHigh + 6, &xpos, &ypos, &win); - - if (ypos + PopUpHigh > MaxHeight) - ypos -= (PopUpHigh + FontHigh + 6); - if (xpos + PopUpWide > MaxWidth) - xpos = MaxWidth - PopUpWide; - if (xpos < 0) - xpos = 0; - XMoveResizeWindow(dpy, PopUpWin, xpos, ypos, PopUpWide + 1, - PopUpHigh + 1); - XClearWindow(dpy, PopUpWin); - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - - ReDrawFlag |= RFReSize; - XSync(dpy, True); -} - -void ReDrawWindow(void) -{ - if (Interactive) - ReSizeWindow(MainWide, MainHigh); -} - - -int FatalXError(Display * ptr) -{ - /* Avoid Compiler Warnings! */ - UnusedArgument(ptr); - - dpy = (Display *) NULL; - RasMolFatalExit("*** Fatal X11 I/O Error! ***"); - return 0; -} - - -int OpenDisplay(void) -{ -#ifdef THIRTYTWOBIT - static ByteTest test; -#endif - register unsigned long mask; - register int i, num; - register char *ptr; - - static XVisualInfo visinfo; - static XClassHint xclass; - static XSizeHints size; - static int temp; - static char VersionStr[50]; - int xpos, ypos, rxpos, rypos; - Window win; - - sprintf(VersionStr, "RasMol Version %s", VERSION); - - image = (XImage *) NULL; - - MouseCaptureStatus = False; - MouseUpdateStatus = False; - UseHourGlass = True; - DisableMenu = False; - Monochrome = False; - XHeldButton = -1; - - for (i = 0; i < 11; i++) - DialValue[i] = 0.0; - - CQRMSet(DialQRot, 0.0, 0.0, 0.0, 0.0); - - RLut[0]=0; GLut[0]=0; BLut[0]=0; ULut[0]=True; - RLut[1]=100; GLut[1]=100; BLut[1]=100; ULut[1]=True; - RLut[2]=150; GLut[2]=150; BLut[2]=150; ULut[2]=True; - RLut[3]=200; GLut[3]=200; BLut[3]=200; ULut[3]=True; - RLut[4]=255; GLut[4]=255; BLut[4]=255; ULut[4]=True; - - XRange = DefaultWide; - YRange = DefaultHigh; - - if (InitWidth >= 48) - XRange = InitWidth; - if (InitHeight >= 48) - YRange = InitHeight; - - WRange = XRange >> 1; - HRange = YRange >> 1; - Range = MinFun(XRange, YRange); - - xpos = InitXPos - 14; - ypos = InitYPos - MenuHigh - 14; - if (xpos < 0) - xpos = 0; - if (ypos < 0) - ypos = 0; - - if (!Interactive) - return (False); - if ((dpy = XOpenDisplay(NULL)) == NULL) - return 0; - - num = DefaultScreen(dpy); - RootWin = RootWindow(dpy, num); - XSetIOErrorHandler(FatalXError); - -#ifdef EIGHTBIT - if (!(XMatchVisualInfo(dpy, num, 8, PseudoColor, &visinfo) || - XMatchVisualInfo(dpy, num, 8, GrayScale, &visinfo))) { - /* Attempt to use Monochrome Mode! */ - if (!(XMatchVisualInfo(dpy, num, 1, StaticColor, &visinfo) || - XMatchVisualInfo(dpy, num, 1, StaticGray, &visinfo))) { - XCloseDisplay(dpy); - return 0; - } - Monochrome = True; - PixDepth = 1; - } else - PixDepth = 8; -#else -#ifdef THIRTYTWOBIT - if (XMatchVisualInfo(dpy, num, 32, TrueColor, &visinfo) || - XMatchVisualInfo(dpy, num, 32, DirectColor, &visinfo)) { - PixDepth = 32; - } else if (XMatchVisualInfo(dpy, num, 24, TrueColor, &visinfo) || - XMatchVisualInfo(dpy, num, 24, DirectColor, &visinfo)) { - PixDepth = 24; - } else { /* No suitable display! */ - XCloseDisplay(dpy); - return (0); - } -#else /* SIXTEENBIT */ - if (XMatchVisualInfo(dpy, num, 16, TrueColor, &visinfo) || - XMatchVisualInfo(dpy, num, 16, DirectColor, &visinfo)) { - PixDepth = 16; - } else if (XMatchVisualInfo(dpy, num, 15, TrueColor, &visinfo) || - XMatchVisualInfo(dpy, num, 15, DirectColor, &visinfo)) { - PixDepth = 15; - } else { /* No suitable display! */ - XCloseDisplay(dpy); - return 0; - } -#endif -#endif - - if (!Monochrome) { - vis = visinfo.visual; - if (vis != DefaultVisual(dpy, num)) { - cmap = XCreateColormap(dpy, RootWin, vis, AllocNone); - } else - cmap = DefaultColormap(dpy, num); - } else { /* Black & White */ - /* PixDepth = DefaultDepth(dpy,num); */ - cmap = DefaultColormap(dpy, num); - vis = visinfo.visual; - - BlackCol = (Pixel) (BlackPixel(dpy, num) & 1); - WhiteCol = (Pixel) (WhitePixel(dpy, num) & 1); - } - - if (RasOpenFonts()) { - if (Language != Russian) { - SwitchLang(English); - if (RasOpenFonts()) - FatalGraphicsError("Unable to find suitable font"); - } else { - FatalGraphicsError("Unable to find suitable font"); - } - } - - OpenColourMap(); - - MaxHeight = DisplayHeight(dpy, num); - MinHeight = MenuHigh + 101; - MaxWidth = DisplayWidth(dpy, num); - MinWidth = 101; - - MainHigh = YRange + MenuHigh + 53; - MainWide = XRange + 53; - - mask = CWEventMask; - attr.event_mask = ExposureMask | KeyPressMask | StructureNotifyMask - | EnterWindowMask | LeaveWindowMask | PropertyChangeMask; - attr.background_pixel = Lut[2]; - attr.border_pixel = Lut[2]; - attr.colormap = cmap; - attr.cursor = arrow; - mask |= CWBackPixel; - mask |= CWBorderPixel; - mask |= CWColormap; - mask |= CWCursor; - - MainWin = XCreateWindow(dpy, RootWin, 0, 0, MainWide, MainHigh, 2, - PixDepth, InputOutput, vis, mask, &attr); - - gcon = XCreateGC(dpy, MainWin, 0L, NULL); - /* DefaultGC(dpy,num) */ - - XSetGraphicsExposures(dpy, gcon, False); - icon = XCreateBitmapFromData(dpy, MainWin, (char *) icon_bits, - icon_width, icon_height); - - size.flags = PMinSize | PMaxSize; - size.min_width = MinWidth; - size.max_width = MaxWidth; - size.min_height = MinHeight; - size.max_height = MaxHeight; - XSetStandardProperties(dpy, MainWin, VersionStr, - "RasMol", icon, NULL, 0, &size); - - xclass.res_name = "rasmol"; - xclass.res_class = "RasMol"; - XSetClassHint(dpy, MainWin, &xclass); - - hints.icon_pixmap = icon; - hints.flags = IconPixmapHint; - XSetWMHints(dpy, MainWin, &hints); - - OpenCanvas(XRange, YRange); - OpenScrollBars(); - OpenMenuBar(); - OpenCursors(); - OpenIPCComms(); - -#ifdef DIALBOX - OpenDialsBox(); -#endif - -#ifdef MITSHM - ptr = DisplayString(dpy); - if (!ptr || (*ptr == ':') || !strncmp(ptr, "localhost:", 10) || - !strncmp(ptr, "unix:", 5) || !strncmp(ptr, "local:", 6)) { - SharedMemOption = XQueryExtension(dpy, "MIT-SHM", &temp, &temp, &temp); - if (Monochrome && (PixDepth != 1)) - SharedMemOption = False; - } else - SharedMemOption = False; - SharedMemFlag = False; -#endif - -#ifdef THIRTYTWOBIT - /* Determine Byte Ordering */ - test.longword = (Long) 0x000000ff; - if (ImageByteOrder(dpy) == MSBFirst) { - SwapBytes = test.bytes[0]; - } else - SwapBytes = test.bytes[3]; -#endif - - XMapSubwindows(dpy, MainWin); - XMapWindow(dpy, MainWin); - - DrawXScroll(); - DrawYScroll(); - DrawMainWin(); - DrawMenuBar(); - - XClearWindow(dpy, CanvWin); - XSync(dpy, False); - - XTranslateCoordinates(dpy, MainWin, RootWin, xpos, ypos, - &rxpos, &rypos, &win); - XMoveResizeWindow(dpy, MainWin, rxpos, rypos, MainWide, MainHigh); - ReDrawWindow(); - - - num = 1 << ConnectionNumber(dpy); - return (num); -} - -#ifdef MITSHM -static int HandleShmError(Display * dpy, XErrorEvent * ptr) -{ - /* Avoid Compiler Warnings! */ - UnusedArgument(dpy); - UnusedArgument(ptr); - SharedMemOption = False; - return 0; -} -#endif - - -int CreateImage(void) -{ - register long size, temp; - register int format; - register Pixel *ptr; -#ifdef MITSHM - register int (*handler) (); -#endif - - if (!Interactive) { - if (FBuffer) - _ffree(FBuffer); - size = (long) XRange *YRange * sizeof(Pixel); - FBuffer = (Pixel *) _fmalloc(size + 32); - return ((FBuffer != (Pixel *) NULL) ? True : False); - } - - format = Monochrome ? XYPixmap : ZPixmap; - - if (image) { /* Monochrome Mode Frame Buffer! */ - if (FBuffer && (FBuffer != (Pixel *) image->data)) - _ffree(FBuffer); -#ifdef MITSHM - if (SharedMemFlag) { - XShmDetach(dpy, &xshminfo); - image->data = (char *) NULL; - shmdt(xshminfo.shmaddr); - } -#endif - XDestroyImage(image); - image = (XImage *) NULL; - } - - if (Monochrome) { /* Monochrome Mode Frame Buffer! */ - size = (long) XRange *YRange * sizeof(Pixel); - FBuffer = (Pixel *) _fmalloc(size + 32); - if (FBuffer == (Pixel *) NULL) - return False; - - /* Bit per Pixel ScanLines! */ - temp = ((XRange + 31) >> 5) << 2; - size = (long) temp *YRange + 32; - } else - size = (long) XRange *YRange * sizeof(Pixel) + 32; - -#ifdef MITSHM - if (SharedMemOption) { - SharedMemFlag = False; - image = XShmCreateImage(dpy, vis, PixDepth, format, - NULL, &xshminfo, XRange, YRange); - - if (image) { - temp = (Long) image->bytes_per_line * image->height; - if (temp > size) - size = temp; - xshminfo.shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777); - if (xshminfo.shmid != -1) { - xshminfo.shmaddr = (char *) shmat(xshminfo.shmid, 0, 0); - if (xshminfo.shmaddr != (char *) -1) { - image->data = xshminfo.shmaddr; - if (!Monochrome) - FBuffer = (Pixel *) image->data; - xshminfo.readOnly = True; - handler = XSetErrorHandler(HandleShmError); - SharedMemFlag = XShmAttach(dpy, &xshminfo); - XSync(dpy, False); - XSetErrorHandler(handler); - if (!SharedMemOption) - SharedMemFlag = False; - } - /* Always Destroy Shared Memory Ident */ - shmctl(xshminfo.shmid, IPC_RMID, 0); - } - - if (SharedMemFlag) { - if (Monochrome) { - if (BlackCol) { - memset((void *) image->data, 255, size); - } else - memset((void *) image->data, 255, size); - } - return True; - } else { - XDestroyImage(image); - image = (XImage *) NULL; - SharedMemOption = False; - } - } - } -#endif - - /* Allocate Frame Buffer! */ - ptr = (Pixel *) _fmalloc(size); - if (ptr == (Pixel *) NULL) - return False; - - if (!Monochrome) - FBuffer = ptr; - image = XCreateImage(dpy, vis, PixDepth, format, 0, (char *) ptr, - XRange, YRange, sizeof(Pixel) << 3, 0); - return ((image == (XImage *) NULL) ? False : True); -} - - -static void DitherImage(void) -{ - register Card bits; - register Card *dst; - register Pixel *src; - register int xmax, ymax; - register int count, x, y; - register int error; - - register Card bmask, wmask; - register Card bhigh, whigh; - register int wlen; - register int blen; - register int len; - - /* Avoid compiler warnings */ - bits = bmask = wmask = (Card) 0; - - src = (Pixel *) FBuffer; - dst = (Card *) image->data; - - wlen = XRange >> 5; - blen = XRange & 31; - if (blen) { - wmask = WhiteCol << (blen - 1); - bmask = BlackCol << (blen - 1); - len = wlen + 1; - } else - len = wlen; - - whigh = WhiteCol << 31; - bhigh = BlackCol << 31; - - /* Allow Compiler Optimisation */ - xmax = XRange; - ymax = YRange; - - error = 0; - for (y = 0; y < ymax; y++) { - for (x = 0; x < wlen; x++) { - for (count = 0; count < 32; count++) { - error += Intensity[*src++]; - bits <<= 1; - if (error >= 128) { - error -= 255; - bits |= WhiteCol; - } else - bits |= BlackCol; - } - *dst++ = bits; - } - - if (blen) { - for (count = 0; count < blen; count++) { - error += Intensity[*src++]; - bits <<= 1; - if (error >= 128) { - error -= 255; - bits |= WhiteCol; - } else - bits |= BlackCol; - } - *dst++ = bits; - - /* Asymmetric Loop Unrolling! */ - if (++y == ymax) - break; - src += xmax; - dst += wlen; - - bits = 0; - for (count = 0; count < blen; count++) { - error += Intensity[*(--src)]; - bits >>= 1; - if (error >= 128) { - error -= 255; - bits |= wmask; - } else - bits |= bmask; - } - *(--dst) = bits; - } else { /* Asymmetric Loop Unrolling! */ - if (++y == ymax) - break; - src += xmax; - dst += len; - } - - for (x = wlen - 1; x >= 0; x--) { - for (count = 0; count < 32; count++) { - error += Intensity[*(--src)]; - bits >>= 1; - if (error >= 128) { - error -= 255; - bits |= whigh; - } else - bits |= bhigh; - } - *(--dst) = bits; - } - src += xmax; - dst += len; - } -} - - -void TransferImage(void) -{ - if (Monochrome) - DitherImage(); - -#ifdef MITSHM - if (SharedMemFlag) { - XShmPutImage(dpy, CanvWin, gcon, image, 0,0,0,0, XRange,YRange,False); - XSync(dpy, False); - } else { - XPutImage(dpy, CanvWin, gcon, image, 0, 0, 0, 0, XRange, YRange); - XFlush(dpy); - } -#else - XPutImage(dpy, CanvWin, gcon, image, 0, 0, 0, 0, XRange, YRange); - XFlush(dpy); -#endif -} - - -void ClearImage(void) -{ - XClearWindow(dpy, CanvWin); - XFlush(dpy); -} - - -int PrintImage(void) -{ - return False; -} - - -int ClipboardImage(void) -{ - return False; -} - - -void SetCanvasTitle(char *ptr) -{ - if (Interactive) { - XStoreName(dpy, MainWin, ptr); - } -} - - -static int HandleIPCError(Display * dpy, XErrorEvent * ptr) -{ - /* Avoid Compiler Warnings! */ - UnusedArgument(dpy); - UnusedArgument(ptr); - return 0; -} - - -static void HandleIPCCommand(void) -{ - static unsigned long len, left; - static unsigned char *command; - static Window source; - static int serial; - static int format; - static Atom type; - char buffer[32]; - - register size_t rlen; - register int result; - register int (*handler) (); - register char *cmnd; - register char *ptr; - - command = NULL; - result = XGetWindowProperty(dpy, MainWin, CommAtom, 0, 1024, True, - XA_STRING, &type, &format, &len, &left, - &command); - if ((result != Success) || (type != XA_STRING) || (format != 8)) { - if (command) - XFree((char *) command); - return; - } - - result = 0; - ptr = (char *) command; - if (!*ptr) { /* Tcl/Tk4.0 and later */ - - ptr++; - while (ptr < (char *) command + len) { - if ((ptr[0] == 'c') && (ptr[1] == '\0')) { - ptr += 2; - cmnd = (char *) NULL; - source = serial = 0; - while ((ptr < (char *) command + len) && (*ptr == '-')) { - if ((ptr[1] == 'r') && (ptr[2] == ' ')) { - sscanf(ptr + 3, "%x %d\n", (int *) &source, &serial); - } else if ((ptr[1] == 's') && (ptr[2] == ' ')) - cmnd = ptr + 3; - while (*ptr) - ptr++; - ptr++; - } - - if (!cmnd) - continue; - result = ExecuteIPCCommand(cmnd); - if (!source || !serial) - continue; - - buffer[0] = '\0'; - buffer[1] = 'r'; - buffer[2] = '\0'; - buffer[3] = '-'; - buffer[4] = 'r'; - buffer[5] = ' '; - buffer[6] = result ? '1' : '0'; - buffer[7] = '\0'; - sprintf(buffer + 8, "-s %d", serial); - rlen = strlen(buffer + 8) + 9; - - /* Return Tcl/Tk v4.0 result! */ - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, source, CommAtom, XA_STRING, 8, - PropModeAppend, (unsigned char *) buffer, - rlen); - XSync(dpy, False); - XSetErrorHandler(handler); - } else { /* Unrecognised command! */ - while (*ptr) - ptr++; - ptr++; - } - } - - } else - while (*ptr) { /* Tcl/Tk3.0 and later */ - if (*ptr == 'C') { - sscanf(ptr + 1, "%x %x\n", (int *) &source, &serial); - while (*ptr && (*ptr != '|')) - ptr++; - if (*ptr == '|') { - result = ExecuteIPCCommand(ptr + 1); - } else - result = 0; - - sprintf(buffer, "R %x 0 %d", serial, result); - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, source, CommAtom, XA_STRING, 8, - PropModeAppend, (unsigned char *) buffer, - (int) strlen(buffer) + 1); - XSync(dpy, False); - XSetErrorHandler(handler); - } - - /* Next Command! */ - while (*ptr++); - } - XFree((char *) command); - - if ((result == IPC_Quit) || (result == IPC_Exit)) - RasMolExit(); -} - - -void SetMouseUpdateStatus(int bool) -{ - if (MouseUpdateStatus != bool) { /* Enable/Disable Pointer Motion Events! */ - attr.event_mask = ExposureMask | ButtonPressMask | ButtonMotionMask - | ButtonReleaseMask; - if (bool) - attr.event_mask |= PointerMotionMask; - XChangeWindowAttributes(dpy, CanvWin, CWEventMask, &attr); - } - MouseUpdateStatus = bool; -} - - -void SetMouseCaptureStatus(int bool) -{ - MouseCaptureStatus = bool; -} - - -static int GetStatus(int mask) -{ - register int status; - - status = 0; - if (mask & Button1Mask) - status |= MMLft; - if (mask & Button2Mask) - status |= MMMid; - if (mask & Button3Mask) - status |= MMRgt; - if (mask & ControlMask) - status |= MMCtl; - if (mask & ShiftMask) - status |= MMSft; - return status; -} - - -static int CropRange(int val, int min, int max) -{ - if (val < min) - return min; - if (val > max) - return max; - return val; -} - - -static void DoneEvents(void) -{ - register Real temp; - register int index; - - if (XHeldButton == YScrlDial) { - index = NewScrlY + XHeldStep; -#ifdef ORIG - if (YScrlDial < 3) { - if (index < 16) { - index += YRange - 48; - } else if (index > YRange - 32) - index -= YRange - 48; - NewScrlY = index; - } else - NewScrlY = CropRange(index, 16, YRange - 32); -#else - if (index < 16) { - index += YRange - 48; - } else if (index > YRange - 32) - index -= YRange - 48; - NewScrlY = index; -#endif - } - - if (NewScrlY != ScrlY) { - XClearArea(dpy, YScrlWin, 0, ScrlY, 16, 16, False); - XCopyArea(dpy, Scrl, YScrlWin, gcon, 0, 0, 16, 16, 0, NewScrlY); - - temp = ((Real) (NewScrlY - 16)) / (YRange - 48); - if (RotMode == RotAll) { - WorldDialValue[YScrlDial] = 2.0 * temp - 1.0; - } else { - DialValue[YScrlDial] = 2.0 * temp - 1.0; - } - ReDrawFlag |= (1 << YScrlDial); - ScrlY = NewScrlY; - } - - if (XHeldButton == XScrlDial) { - index = NewScrlX + XHeldStep; -#ifdef ORIG - if (XScrlDial < 3) { - if (index < 16) { - index += XRange - 48; - } else if (index > XRange - 32) - index -= XRange - 48; - NewScrlX = index; - } else - NewScrlX = CropRange(index, 16, XRange - 32); -#else - if (index < 16) { - index += XRange - 48; - } else if (index > XRange - 32) - index -= XRange - 48; - NewScrlX = index; -#endif - } - - if (NewScrlX != ScrlX) { - XClearArea(dpy, XScrlWin, ScrlX, 0, 16, 16, False); - XCopyArea(dpy, Scrl, XScrlWin, gcon, 0, 0, 16, 16, NewScrlX, 0); - - temp = ((Real) (NewScrlX - 16)) / (XRange - 48); - if ((RotMode == RotBond) && BondSelected) { - BondSelected->BRotValue = 2.0 * temp - 1.0; - ReDrawFlag |= RFRotBond; - } else { - if (RotMode == RotAll) { - WorldDialValue[XScrlDial] = 2.0 * temp - 1.0; - ReDrawFlag |= (1 << XScrlDial); - } else { - DialValue[XScrlDial] = 2.0 * temp - 1.0; - ReDrawFlag |= (1 << XScrlDial); - } - } - ScrlX = NewScrlX; - } - /* XSync(dpy,False); */ - XFlush(dpy); -} - - -static int ProcessEvent(XEvent * event) -{ - register int result; - register int index; - register int stat; - - result = 0; - - switch (event->type) { - case (ButtonPress): - { - XButtonPressedEvent *ptr; - - XHeldButton = -1; - ptr = (XButtonPressedEvent *) event; - - if (ptr->window == CanvWin) { - stat = GetStatus(ptr->state); - ProcessMouseDown(ptr->x, ptr->y, stat); - } else if (ptr->window == MenuWin) { - if (!DisableMenu) - if (HandleMenuClick(ptr->x)) - result = HandleMenuLoop(); - } else if (ptr->window == XScrlWin) { - ReDrawFlag |= RFRotateY; - if (ptr->x < 16) { - XHeldButton = XScrlDial; - XHeldStep = -XScrlSkip; - } else if (ptr->x >= XRange - 16) { - XHeldButton = XScrlDial; - XHeldStep = XScrlSkip; - } else { - index = ptr->x - 8; -#ifdef ORIG - if (XScrlDial < 3) { - if (index > XRange - 32) { - index -= XRange - 48; - } else if (index < 16) - index += XRange - 48; - NewScrlX = index; - } else - NewScrlX = CropRange(index, 16, XRange - 32); -#else - if (index > XRange - 32) { - index -= XRange - 48; - } else if (index < 16) - index += XRange - 48; - NewScrlX = index; -#endif - } - - } else if (ptr->window == YScrlWin) { - ReDrawFlag |= RFRotateX; - if (ptr->y < 16) { - XHeldButton = YScrlDial; - XHeldStep = -YScrlSkip; - } else if (ptr->y >= YRange - 16) { - XHeldButton = YScrlDial; - XHeldStep = YScrlSkip; - } else { - index = ptr->y - 8; -#ifdef ORIG - if (YScrlDial < 3) { - if (index > YRange - 32) { - index -= YRange - 48; - } else if (index < 16) - index += YRange - 48; - NewScrlY = index; - } else - NewScrlY = CropRange(index, 16, YRange - 32); -#else - if (index > YRange - 32) { - index -= YRange - 48; - } else if (index < 16) - index += YRange - 48; - NewScrlY = index; -#endif - } - - } - } - break; - - case (MotionNotify): - { - XMotionEvent *ptr; - - ptr = (XMotionEvent *) event; - if (ptr->window == PopUpWin && MenuBarSelect == AboutDLGMItem) { - HandleItemMove(ptr->x, ptr->y); - } else if (ptr->window == CanvWin) { - stat = GetStatus(ptr->state); - ProcessMouseMove(ptr->x, ptr->y, stat); - } else if (XHeldButton == -1) { - if (ptr->window == XScrlWin) { - index = ptr->x - 8; - NewScrlX = CropRange(index, 16, XRange - 32); - } else { /* if( ptr->window==YScrlWin ) */ - index = ptr->y - 8; - NewScrlY = CropRange(index, 16, YRange - 32); - } - } - } - break; - - case (CirculateNotify): - { - XCirculateEvent *ptr; - - ptr = (XCirculateEvent *) event; - if (ptr->window == MainWin && ptr->place == PlaceOnTop - && PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - } - break; - - case (VisibilityNotify): - { - XVisibilityEvent *ptr; - - ptr = (XVisibilityEvent *) event; - if (ptr->window == PopUpWin && ptr->state != VisibilityUnobscured - && PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - } - break; - - - case (ButtonRelease): - { - XButtonReleasedEvent *ptr; - - if (XHeldButton != -1) { /* Three button emulation fix! */ - DoneEvents(); - XHeldButton = -1; - } - - ptr = (XButtonReleasedEvent *) event; - - if (ptr->window == PopUpWin && MenuBarSelect == AboutDLGMItem) { - HandleItemClick(ptr->x, ptr->y); - result = (MenuBarSelect << 8) + MenuItemSelect + 1; - } else if (ptr->window == CanvWin) - if (ptr->window == CanvWin) { - stat = GetStatus(ptr->state); - ProcessMouseUp(ptr->x, ptr->y, stat); - } - } - break; - - case (KeyPress): - { - XKeyPressedEvent *ptr; - static KeySym symbol; - static char keychar; - - keychar = '\0'; - ptr = (XKeyPressedEvent *) event; - index = XLookupString(ptr, &keychar, 1, &symbol, NULL); - switch (symbol) { - case (XK_Begin): - case (XK_Home): - ProcessCharacter(0x01); - break; - case (XK_Right): - ProcessCharacter(0x06); - break; - case (XK_Left): - ProcessCharacter(0x02); - break; - case (XK_End): - ProcessCharacter(0x05); - break; - case (XK_Up): - case (XK_Prior): - ProcessCharacter(0x10); - break; - case (XK_Down): - case (XK_Next): - ProcessCharacter(0x0e); - break; - - case (XK_F10): - if (!DisableMenu) { - SelectMenu(0); - result = HandleMenuLoop(); - } - break; - - default: - if (index == 1) { - if (!(ptr->state & Mod1Mask)) { - if (ProcessCharacter(keychar)) { - if (ProcessCommand()) - RasMolExit(); - - if (!CommandActive) - ResetCommandLine(0); - } - } else if (!DisableMenu) - if (HandleMenuKey(keychar)) - result = HandleMenuLoop(); - } - } - } - break; - - - case (Expose): - { - XExposeEvent *ptr; - - ptr = (XExposeEvent *) event; - if (ptr->window == CanvWin) { - if (image) { -#ifdef MITSHM - if (SharedMemFlag) { - XShmPutImage(dpy, CanvWin, gcon, image, - ptr->x, ptr->y, ptr->x, ptr->y, - ptr->width, ptr->height, False); - XSync(dpy, False); - } else -#endif - XPutImage(dpy, CanvWin, gcon, image, - ptr->x, ptr->y, ptr->x, ptr->y, - ptr->width, ptr->height); - } else - XClearWindow(dpy, CanvWin); - } else if (ptr->window == MainWin) { - DrawMainWin(); - DrawMenuBar(); - } else if (ptr->window == XScrlWin) { - DrawXScroll(); - } else if (ptr->window == YScrlWin) { - DrawYScroll(); - } - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - XFlush(dpy); - } - break; - - case (EnterNotify): - { - XCrossingEvent *ptr; - - ptr = (XCrossingEvent *) event; - if (ptr->detail != NotifyInferior) { - if (LocalMap) - XInstallColormap(dpy, lmap); - } -#ifdef DIALBOX - if (UseDials) - GetDialState(); -#endif - } - break; - - case (LeaveNotify): - if (LocalMap) { - XCrossingEvent *ptr; - - ptr = (XCrossingEvent *) event; - if (ptr->detail != NotifyInferior) - XUninstallColormap(dpy, lmap); - } - break; - - case (ConfigureNotify): - { - XConfigureEvent *ptr; - register int wide, high; - - ptr = (XConfigureEvent *) event; - if (ptr->window == MainWin) { - high = CropRange(ptr->height, MinHeight, MaxHeight); - wide = CropRange(ptr->width, MinWidth, MaxWidth); - - if ((wide != MainWide) || (high != MainHigh)) - ReSizeWindow(wide, high); - XFlush(dpy); - } - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - int xpos, ypos; - Window win; - - XTranslateCoordinates(dpy, MainWin, RootWin, AboutDLGXpos, - FontHigh + 6, &xpos, &ypos, &win); - - if (ypos + PopUpHigh > MaxHeight) - ypos -= (PopUpHigh + FontHigh + 6); - if (xpos + PopUpWide > MaxWidth) - xpos = MaxWidth - PopUpWide; - if (xpos < 0) - xpos = 0; - - XMoveWindow(dpy, PopUpWin, xpos, ypos); - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - XFlush(dpy); - } - } - break; - - case (ClientMessage): - { - XClientMessageEvent *ptr; - - ptr = (XClientMessageEvent *) event; - if ((ptr->message_type == ProtoXAtom) && - (ptr->data.l[0] == DelWinXAtom)) - RasMolExit(); - } - break; - - case (PropertyNotify): - { - XPropertyEvent *ptr; - - ptr = (XPropertyEvent *) event; - if ((ptr->atom == CommAtom) && (ptr->state == PropertyNewValue)) - HandleIPCCommand(); - } - break; - - case (MapNotify): - DrawXScroll(); - DrawYScroll(); - DrawMainWin(); - DrawMenuBar(); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - break; - - default: -#ifdef DIALBOX - if (event->type == DialEvent) - HandleDialEvent((XDeviceMotionEvent *) event); -#endif - break; - } - return result; -} - - - -/*=========================*/ -/* Modal Dialog Handling */ -/*=========================*/ - -static int HandleMenuLoop(void) -{ - register unsigned int mask; - register int result; - register int done; - auto XEvent event; - - /* Passive Pointer Grab */ - mask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask; - XGrabPointer(dpy, MenuWin, False, mask, - GrabModeAsync, GrabModeAsync, None, None, CurrentTime); - - XHeldButton = -1; - MenuFocus = True; - DrawMenuBar(); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - - result = 0; - done = False; - while (!done) { - XNextEvent(dpy, &event); - switch (event.type) { - case (Expose): - { - XExposeEvent *ptr; - - ptr = (XExposeEvent *) & event; - if (ptr->window == PopUpWin) { - if (MenuBarSelect == AboutDLGMItem) - DrawAboutDLG(); - else - DrawPopUpMenu(); - } else - ProcessEvent(&event); - } - break; - - - case (ButtonPress): - { - XButtonPressedEvent *ptr; - - ptr = (XButtonPressedEvent *) & event; - /* All Events Relative to MenuWin */ - if ((ptr->y >= 0) && (ptr->y <= FontHigh + 5)) { - HandleMenuClick(ptr->x); - } else if (PopUpFlag) { - int xpos, ypos; - Window win; - XTranslateCoordinates(dpy, MenuWin, PopUpWin, ptr->x, - ptr->y, &xpos, &ypos, &win); - HandleItemClick(xpos, ypos); - } else - done = True; - } - break; - - case (MotionNotify): - if (ItemFocus) { - XMotionEvent *ptr; - - ptr = (XMotionEvent *) & event; - /* All Events Relative to MenuWin */ - if ((ptr->y >= 0) && (ptr->y <= FontHigh + 5)) { - HandleMenuClick(ptr->x); - } else if (PopUpFlag) { - int xpos, ypos; - Window win; - XTranslateCoordinates(dpy, MenuWin, PopUpWin, ptr->x, - ptr->y, &xpos, &ypos, &win); - HandleItemMove(xpos, ypos); - } - } - break; - - case (ButtonRelease): - { - XButtonReleasedEvent *ptr; - - ptr = (XButtonReleasedEvent *) &event; - /* All Events Relative to MenuWin */ - if ((ptr->y >= 0) && (ptr->y <= FontHigh + 5)) { - if (HandleMenuClick(ptr->x)) { - SelectFirstItem(MenuBarSelect); - DrawPopUpMenu(); - } else - done = True; - } else if (PopUpFlag) { - if (ItemFocus || MenuBarSelect == AboutDLGMItem) { - int xpos, ypos; - Window win; - - XTranslateCoordinates(dpy, MenuWin, PopUpWin, ptr->x, - ptr->y, &xpos, &ypos, &win); - HandleItemClick(xpos, ypos); - } - if (ItemFlag) - result = (MenuBarSelect << 8) + MenuItemSelect + 1; - done = True; - } else - done = False; - ItemFocus = False; - } - break; - - case (KeyPress): - if (!ItemFocus) { - XKeyPressedEvent *ptr; - static KeySym symbol; - static char keychar; - register int index; - - ptr = (XKeyPressedEvent *) & event; - index = XLookupString(ptr, &keychar, 1, &symbol, NULL); - switch (symbol) { - case (XK_Right): - index = MenuBarSelect + 1; - if (index < MenuBarCount) { - SelectMenu(index); - } else - SelectMenu(0); - break; - - case (XK_Left): - if (MenuBarSelect) { - SelectMenu(MenuBarSelect - 1); - } else - SelectMenu(MenuBarCount - 1); - break; - - case (XK_Up): - if (!PopUpFlag) { - PopUpFlag = True; - SelectMenu(MenuBarSelect); - } else - SelectPrevItem(); - break; - - case (XK_Down): - if (!PopUpFlag) { - PopUpFlag = True; - SelectMenu(MenuBarSelect); - } else - SelectNextItem(); - break; - - case (XK_KP_Enter): - case (XK_Linefeed): - case (XK_Return): - if (PopUpFlag && ItemFlag) - result = (MenuBarSelect << 8) + MenuItemSelect + 1; - done = True; - break; - - default: - if ((index == 1) && (keychar >= ' ')) { - if (!(ptr->state & Mod1Mask)) { - if (PopUpFlag) { - result = HandleItemKey(keychar); - if (result) - done = True; - } else - HandleMenuKey(keychar); - } else - HandleMenuKey(keychar); - } - } - } - break; - - default: - ProcessEvent(&event); - } - } - - /* Passive Grab Release */ - XUngrabPointer(dpy, CurrentTime); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - UnDisplayAboutDLG(); - } - XUnmapWindow(dpy, PopUpWin); - PopUpFlag = False; - MenuFocus = False; - DrawMenuBar(); - return result; -} - - -int FetchEvent(int wait) -{ - register int result; - auto XEvent event; - - NewScrlX = ScrlX; - NewScrlY = ScrlY; - - if (XHeldButton != -1) - wait = False; - while (XPending(dpy) || (wait && !ReDrawFlag)) { - XNextEvent(dpy, &event); - result = ProcessEvent(&event); - if (result) - return result; - } - DoneEvents(); - return 0; -} - - -int LookUpColour(char *name, int *red, int *grn, int *blu) -{ - static XColor exact, close; - register Colormap map; - - map = (LocalMap) ? lmap : cmap; - if (XLookupColor(dpy, map, name, &exact, &close)) { - *red = exact.red >> 8; - *grn = exact.green >> 8; - *blu = exact.blue >> 8; - return True; - } - return False; -} - - -void BeginWait(void) -{ - if (UseHourGlass) { - XDefineCursor(dpy, CanvWin, hglass); - XDefineCursor(dpy, MainWin, hglass); - XFlush(dpy); - } -} - - -void EndWait(void) -{ - if (UseHourGlass) { - XDefineCursor(dpy, CanvWin, cross); - XDefineCursor(dpy, MainWin, arrow); - XFlush(dpy); - } -} - - -void CloseDisplay(void) -{ -#ifdef DIALBOX - register int num; -#endif - - /* FatalXError! */ - if (!dpy) - return; - - if (image) { -#ifdef MITSHM - if (SharedMemFlag) { - XShmDetach(dpy, &xshminfo); - image->data = (char *) NULL; - shmdt(xshminfo.shmaddr); - } -#endif - XDestroyImage(image); - } - - if (*TkInterp) { - XGrabServer(dpy); - DeRegisterInterpName(TkInterp); - XUngrabServer(dpy); - } -#ifdef DIALBOX - if (UseDials) { - if (UseDialLEDs) - for (num = 0; num < 8; num++) - SetDialLabel(num, ""); - XCloseDevice(dpy, Dials); - } -#endif - XCloseDisplay(dpy); -} diff -Nru rasmol-2.7.5/src/x11win.c.indent_-kr_-l79_-nut rasmol-2.7.5/src/x11win.c.indent_-kr_-l79_-nut --- rasmol-2.7.5/src/x11win.c.indent_-kr_-l79_-nut 2011-05-01 00:49:39.000000000 +0000 +++ rasmol-2.7.5/src/x11win.c.indent_-kr_-l79_-nut 1970-01-01 00:00:00.000000000 +0000 @@ -1,4191 +0,0 @@ -/*************************************************************************** - * RasMol 2.7.5 * - * * - * RasMol * - * Molecular Graphics Visualisation Tool * - * 13 June 2009 * - * * - * Based on RasMol 2.6 by Roger Sayle * - * Biomolecular Structures Group, Glaxo Wellcome Research & Development, * - * Stevenage, Hertfordshire, UK * - * Version 2.6, August 1995, Version 2.6.4, December 1998 * - * Copyright (C) Roger Sayle 1992-1999 * - * * - * and Based on Mods by * - *Author Version, Date Copyright * - *Arne Mueller RasMol 2.6x1 May 98 (C) Arne Mueller 1998 * - *Gary Grossman and RasMol 2.5-ucb Nov 95 (C) UC Regents/ModularCHEM * - *Marco Molinaro RasMol 2.6-ucb Nov 96 Consortium 1995, 1996 * - * * - *Philippe Valadon RasTop 1.3 Aug 00 (C) Philippe Valadon 2000 * - * * - *Herbert J. RasMol 2.7.0 Mar 99 (C) Herbert J. Bernstein * - *Bernstein RasMol 2.7.1 Jun 99 1998-2008 * - * RasMol 2.7.1.1 Jan 01 * - * RasMol 2.7.2 Aug 00 * - * RasMol 2.7.2.1 Apr 01 * - * RasMol 2.7.2.1.1 Jan 04 * - * RasMol 2.7.3 Feb 05 * - * RasMol 2.7.3.1 Apr 06 * - * RasMol 2.7.4 Nov 07 * - * RasMol 2.7.4.1 Jan 08 * - * RasMol 2.7.4.2 Mar 08 * - * RasMol 2.7.5 May 09 * - * * - * RasMol 2.7.5 incorporates changes by T. Ikonen, G. McQuillan, N. Darakev* - * and L. Andrews (via the neartree package). Work on RasMol 2.7.5 * - * supported in part by grant 1R15GM078077-01 from the National Institute * - * of General Medical Sciences (NIGMS), U.S. National Institutes of Health * - * and by grant ER63601-1021466-0009501 from the Office of Biological & * - * Environmental Research (BER), Office of Science, U. S. Department of * - * Energy. RasMol 2.7.4 incorporated changes by G. Todorov, Nan Jia, * - * N. Darakev, P. Kamburov, G. McQuillan, and J. Jemilawon. Work on RasMol * - * 2.7.4 supported in part by grant 1R15GM078077-01 from the NIGMS/NIH and * - * grant ER63601-1021466-0009501 from BER/DOE. RasMol 2.7.3 incorporates * - * changes by Clarice Chigbo, Ricky Chachra, and Mamoru Yamanishi. Work * - * on RasMol 2.7.3 supported in part by grants DBI-0203064, DBI-0315281 * - * and EF-0312612 from the U.S. National Science Foundation and grant * - * DE-FG02-03ER63601 from BER/DOE. The content is solely the responsibility* - * of the authors and does not necessarily represent the official views of * - * the funding organizations. * - * * - * The code for use of RasMol under GTK in RasMol 2.7.4.2 and 2.7.5 was * - * written by Teemu Ikonen. * - * * - * and Incorporating Translations by * - * Author Item Language * - * Isabel Servan Martinez, * - * Jose Miguel Fernandez Fernandez 2.6 Manual Spanish * - * Jose Miguel Fernandez Fernandez 2.7.1 Manual Spanish * - * Fernando Gabriel Ranea 2.7.1 menus and messages Spanish * - * Jean-Pierre Demailly 2.7.1 menus and messages French * - * Giuseppe Martini, Giovanni Paolella, 2.7.1 menus and messages * - * A. Davassi, M. Masullo, C. Liotto 2.7.1 help file Italian * - * G. Pozhvanov 2.7.3 menus and messages Russian * - * G. Todorov 2.7.3 menus and messages Bulgarian* - * Nan Jia, G. Todorov 2.7.3 menus and messages Chinese * - * Mamoru Yamanishi, Katajima Hajime 2.7.3 menus and messages Japanese * - * * - * This Release by * - * Herbert J. Bernstein, Bernstein + Sons, 5 Brewster Ln, Bellport, NY, USA* - * yaya@bernstein-plus-sons.com * - * Copyright(C) Herbert J. Bernstein 1998-2008 * - * * - * READ THE FILE NOTICE FOR RASMOL LICENSES * - *Please read the file NOTICE for important notices which apply to this * - *package and for license terms (GPL or RASLIC). * - ***************************************************************************/ -/* x11win.c - $Log$ - Revision 1.13 2008/06/28 14:25:26 yaya - Make more IPC errors non-fatal. -- HJB - - Revision 1.12 2008/06/28 14:06:37 yaya - Fix unused variable warning in command.c - Start changes for loading models in infile.c - Make handling of IPC errors non-fatal in x11win.c -- HJB - - Revision 1.11 2008/06/18 20:04:53 yaya - Start in infrastructure for animation - Start on WPDB code -- HJB - - Revision 1.10 2008/03/22 18:42:56 yaya - Post release cleanup and credit to Ikonen in file headers. -- HJB - - Revision 1.9 2008/03/17 03:01:32 yaya - Update to agree with 2.7.4.2 release and T. Ikonen GTK mods -- HJB - - Revision 1.6 2008/03/17 01:32:41 yaya - Add gtk mods by tpikonen, and intergate with 2.7.4.2 mods -- HJB - - Revision 1.5 2008/03/16 22:38:10 yaya - Update stable release to 2.7.4.2; Update rasmol_install and rasmol_run - scripts to handle Japanese and Chiness (using cxterm), changing - Japanese for unix back to EUCJP; and align command line options - to set initial window size and position to agree between unix and - windows -- HJB - - Revision 1.8 2008/03/16 22:25:22 yaya - Align comments with production version; Update rasmol_install and - rasmol_run shell scripts for Japanese and Chinese; Align logic for - positioning and sizing initial window with windows version -- HJB - - Revision 1.7 2008/03/08 21:41:03 yaya - Updates to switch Japanese in unix to EUC_CN, and to reorganize - languagues directory for split between mswin and unix. -- HJB - - Revision 1.6 2008/03/08 15:26:50 yaya - Fixes to get Chinese working under MacOSX for RasMol 2.7.4 - Based on suggested fixes by Mamoru Yamanishi. -- HJB - - Revision 1.4 2008/01/28 03:29:38 yaya - Update CVS to RasMol_2.7.4.1 -- HJB - - Revision 1.5 2007/11/19 03:28:40 yaya - Update to credits for 2.7.4 in manual and headers - Mask code added -- HJB - - Revision 1.4 2007/03/13 21:48:19 todorovg - Fixed a few typo errors that were causing xforms to crash - - Revision 1.3 2007/03/13 21:09:28 todorovg - fixed bug when you run rasmol in chinese and japanese; added catch for fontset to print an error and not give segfault - - Revision 1.2 2007/03/05 22:27:26 todorovg - Fixed japanese - - Revision 1.10 2007/02/26 18:40:31 todorovg - fixed menu click bug - - Revision 1.9 2006/12/29 04:07:37 yaya - Update x11win.c and rasmol.c to add links to list of browsers - and to kill About dialog when the menu bar is selected - Update rasmol_install.sh to allow recompilation of fonts - on install to handle openwin and other old systems that - can't handle byte-swapped bdf files, and add enviroment - variable RASMOL_NOSPAWN to suppress spawn in intermediate - xterm from rasmol_run.sh. -- HJB - - Revision 1.8 2006/12/24 03:48:28 yaya - Clean up conditionals for MITSHM if it is not defined - Fix choice of license files for install -- HJB - - Revision 1.7 2006/12/23 23:18:01 yaya - Detect remote X server that does not share memory - Add new rasmol_install.sh and rasmol_run.sh scripts -- HJB - - Revision 1.6 2006/12/11 02:45:39 yaya - Migrate some of the language switching tables to mac and mswin version - and update the icons for mswin and X11 versions. -- HJB - - Revision 1.5 2006/12/10 03:32:45 yaya - Additional updates for linux build with Russian, cleaning - up X11 font selection for CP1251 and recovering when fonts - are missing. -- HJB - - Revision 1.4 2006/12/03 02:53:10 yaya - Clean up compilation warnings in outfile.c - Mods for about screen under Linux -- HJB - - Revision 1.3 2006/11/28 03:12:48 yaya - Changes for Russian and About dialog in unix - This is a variant tried under Mac OS X. Changes - for Linux still needed. note that more work is - needed on font selection. -- HJB - - Revision 1.2 2006/09/17 10:53:56 yaya - Clean up headers and start on code for X11 -- HJB - - Revision 1.1.1.1 2006/09/16 18:46:03 yaya - Start of RasMol Russian Translation Project based on translations - by Gregory A. Pozhvanov of Saint Petersburg State University -- HJB - - Revision 1.2 2006/06/19 22:06:41 todorovg - Rasmol 2.7.3.1 - - Revision 1.1.1.1 2006/06/19 22:05:14 todorovg - Initial Rasmol 2.7.3 Import - - Revision 1.1 2004/05/07 19:46:16 yaya - Initial revision - - Revision 1.3 2004/02/15 00:24:00 yaya - *** empty log message *** - - Revision 1.2 2003/12/13 19:26:11 yaya - *** empty log message *** - - Revision 1.1 2003/12/12 21:10:38 yaya - Initial revision - - Revision 1.3 2001/02/07 20:30:31 yaya - *** empty log message *** - - Revision 1.2 2001/02/06 21:58:18 yaya - *** empty log message *** - - Revision 1.1 2001/01/31 02:13:45 yaya - Initial revision - - Revision 1.8 2000/08/27 00:54:54 yaya - create rotation bond database - - Revision 1.7 2000/08/26 18:12:50 yaya - Updates to header comments in all files - - Revision 1.6 2000/08/21 21:07:56 yaya - semi-final ucb mods - - Revision 1.5 2000/08/18 16:40:56 yaya - *** empty log message *** - - Revision 1.4 2000/08/13 20:56:35 yaya - Conversion from toolbar to menus - - Revision 1.3 2000/08/12 21:10:41 yaya - Minimal X windows mods - - */ - - -#ifndef sun386 -#include -#endif -#include -#include -#include -#include - -#ifdef VMS -#include -#endif - -#include -#include -#include -#include -#include - -#ifdef X_LOCALE -#include -#define SetLocale _Xsetlocale -#else -#include -#define SetLocale setlocale -#endif - -#define GRAPHICS -#include "rasmol.h" -#include "bitmaps.h" -#include "command.h" -#include "cmndline.h" -#include "molecule.h" -#include "abstree.h" -#include "render.h" -#include "multiple.h" -#include "transfor.h" -#include "vector.h" -#include "wbrotate.h" -#include "langsel.h" -#include "graphics.h" - - -/* Menu Definitions */ -#define mbEnable 0x01 -#define mbOption 0x02 -#define mbSepBar 0x08 -#define mbAccel 0x10 - - -typedef struct _MenuItem { - char **text; - int flags; - int *pos; - int *len; - int *enable; - int value; -} MenuItem; - -static int zero = 0; - -static MenuItem FilMenu[21] = { - {&MsgStrs[StrMOpen] /* "Open..." */ , 0x11, &MsgAuxl[StrMOpen], - &MsgLens[StrMOpen], NULL, 0}, - {&MsgStrs[StrMSaveAs] /*" Save As..." */ , 0x11, &MsgAuxl[StrMSaveAs], - &MsgLens[StrMSaveAs], NULL, 0}, - {&MsgStrs[StrMClose] /* "Close" */ , 0x11, &MsgAuxl[StrMClose], - &MsgLens[StrMClose], NULL, 0}, - {&MsgStrs[StrMEmpty] /* "" */ , 0x08, &MsgAuxl[StrMEmpty], - &MsgLens[StrMEmpty], NULL, 0}, - {&MsgStrs[StrMExit] /* "Exit" */ , 0x11, &MsgAuxl[StrMExit], - &MsgLens[StrMExit], NULL, 0}, - {&MsgStrs[StrMEmpty] /* "" */ , 0x08, &MsgAuxl[StrMEmpty], - &MsgLens[StrMEmpty], NULL, 0}, - {&(MolNStr[0]), 0x01, &zero, - &MolNLen[0], &MoleculeIndex, 0}, - {&(MolNStr[1]), 0x01, &zero, - &MolNLen[1], &MoleculeIndex, 1}, - {&(MolNStr[2]), 0x01, &zero, - &MolNLen[2], &MoleculeIndex, 2}, - {&(MolNStr[3]), 0x01, &zero, - &MolNLen[3], &MoleculeIndex, 3}, - {&(MolNStr[4]), 0x01, &zero, - &MolNLen[4], &MoleculeIndex, 4}, - {&(MolNStr[5]), 0x01, &zero, - &MolNLen[5], &MoleculeIndex, 5}, - {&(MolNStr[6]), 0x01, &zero, - &MolNLen[6], &MoleculeIndex, 6}, - {&(MolNStr[7]), 0x01, &zero, - &MolNLen[7], &MoleculeIndex, 7}, - {&(MolNStr[8]), 0x01, &zero, - &MolNLen[8], &MoleculeIndex, 8}, - {&(MolNStr[9]), 0x01, &zero, - &MolNLen[9], &MoleculeIndex, 9}, - {&(MolNStr[10]), 0x01, &zero, - &MolNLen[10], &MoleculeIndex, 10}, - {&(MolNStr[11]), 0x01, &zero, - &MolNLen[11], &MoleculeIndex, 11}, - {&(MolNStr[12]), 0x01, &zero, - &MolNLen[12], &MoleculeIndex, 12}, - {&(MolNStr[13]), 0x01, &zero, - &MolNLen[13], &MoleculeIndex, 13}, - {&(MolNStr[14]), 0x01, &zero, - &MolNLen[14], &MoleculeIndex, 14} -}; - -static MenuItem DisMenu[9] = { - {&MsgStrs[StrMWirefr] /* "Wireframe" */ , 0x11, &MsgAuxl[StrMWirefr], - &MsgLens[StrMWirefr], NULL, 0}, - {&MsgStrs[StrMBackbn] /* "Backbone" */ , 0x11, &MsgAuxl[StrMBackbn], - &MsgLens[StrMBackbn], NULL, 0}, - {&MsgStrs[StrMSticks] /* "Sticks" */ , 0x11, &MsgAuxl[StrMSticks], - &MsgLens[StrMSticks], NULL, 0}, - {&MsgStrs[StrMSpacefl] /* "Spacefill" */ , 0x11, &MsgAuxl[StrMSpacefl], - &MsgLens[StrMSpacefl], NULL, 0}, - {&MsgStrs[StrMBallStk] /* "Ball & Stick" */ , 0x11, &MsgAuxl[StrMBallStk], - &MsgLens[StrMBallStk], NULL, 0}, - {&MsgStrs[StrMRibbons] /* "Ribbons" */ , 0x11, &MsgAuxl[StrMRibbons], - &MsgLens[StrMRibbons], NULL, 0}, - {&MsgStrs[StrMStrands] /* "Strands" */ , 0x11, &MsgAuxl[StrMStrands], - &MsgLens[StrMStrands], NULL, 0}, - {&MsgStrs[StrMCartoon] /* "Cartoons" */ , 0x11, &MsgAuxl[StrMCartoon], - &MsgLens[StrMCartoon], NULL, 0}, - {&MsgStrs[StrMMolSurf] /* "Molecular Surface" */ , 0x11, - &MsgAuxl[StrMMolSurf], - &MsgLens[StrMMolSurf], NULL, 0} -}; - -static MenuItem ColMenu[10] = { - {&MsgStrs[StrMMonochr] /* "Monochrome" */ , 0x11, &MsgAuxl[StrMMonochr], - &MsgLens[StrMMonochr], NULL, 0}, - {&MsgStrs[StrMCPK] /* "CPK" */ , 0x11, &MsgAuxl[StrMCPK], - &MsgLens[StrMCPK], NULL, 0}, - {&MsgStrs[StrMShapely] /*" Shapely" */ , 0x11, &MsgAuxl[StrMShapely], - &MsgLens[StrMShapely], NULL, 0}, - {&MsgStrs[StrMGroup] /* "Group" */ , 0x11, &MsgAuxl[StrMGroup], - &MsgLens[StrMGroup], NULL, 0}, - {&MsgStrs[StrMChain] /* "Chain" */ , 0x11, &MsgAuxl[StrMChain], - &MsgLens[StrMChain], NULL, 0}, - {&MsgStrs[StrMTemp] /* "Temperature" */ , 0x11, &MsgAuxl[StrMTemp], - &MsgLens[StrMTemp], NULL, 0}, - {&MsgStrs[StrMStruct] /* "Structure" */ , 0x11, &MsgAuxl[StrMStruct], - &MsgLens[StrMStruct], NULL, 0}, - {&MsgStrs[StrMUser] /* "User" */ , 0x11, &MsgAuxl[StrMUser], - &MsgLens[StrMUser], NULL, 0}, - {&MsgStrs[StrMModel] /* "Model" */ , 0x11, &MsgAuxl[StrMModel], - &MsgLens[StrMModel], NULL, 0}, - {&MsgStrs[StrMAlt] /* "Alt" */ , 0x11, &MsgAuxl[StrMAlt], - &MsgLens[StrMAlt], NULL, 0} -}; - -static MenuItem OptMenu[7] = { - {&MsgStrs[StrMSlab] /* "Slab Mode" */ , 0x13, &MsgAuxl[StrMSlab], - &MsgLens[StrMSlab], &UseSlabPlane, True}, - {&MsgStrs[StrMHydr] /* "Hydrogens" */ , 0x13, &MsgAuxl[StrMHydr], - &MsgLens[StrMHydr], &Hydrogens, True}, - {&MsgStrs[StrMHet] /* "Hetero Atoms" */ , 0x13, &MsgAuxl[StrMHet], - &MsgLens[StrMHet], &HetaGroups, True}, - {&MsgStrs[StrMSpec] /* "Specular" */ , 0x13, &MsgAuxl[StrMSpec], - &MsgLens[StrMSpec], &FakeSpecular, True}, - {&MsgStrs[StrMShad] /* "Shadows" */ , 0x13, &MsgAuxl[StrMShad], - &MsgLens[StrMShad], &UseShadow, True}, - {&MsgStrs[StrMStereo] /* "Stereo" */ , 0x13, &MsgAuxl[StrMStereo], - &MsgLens[StrMStereo], &UseStereo, True}, - {&MsgStrs[StrMLabel] /* "Labels" */ , 0x13, &MsgAuxl[StrMLabel], - &MsgLens[StrMLabel], &LabelOptFlag, True} -}; - -static MenuItem SetMenu[13] = { - {&MsgStrs[StrMPOff] /* "Pick Off" */ , 0x13, &MsgAuxl[StrMPOff], - &MsgLens[StrMPOff], &PickMode, PickNone}, - {&MsgStrs[StrMPIdent] /* "Pick Ident" */ , 0x13, &MsgAuxl[StrMPIdent], - &MsgLens[StrMPIdent], &PickMode, PickIdent}, - {&MsgStrs[StrMPDist] /* "Pick Distance" */ , 0x13, &MsgAuxl[StrMPDist], - &MsgLens[StrMPDist], &PickMode, PickDist}, - {&MsgStrs[StrMPMon] /* "Pick Monitor" */ , 0x13, &MsgAuxl[StrMPMon], - &MsgLens[StrMPMon], &PickMode, PickMonit}, - {&MsgStrs[StrMPAng] /* "Pick Angle" */ , 0x13, &MsgAuxl[StrMPAng], - &MsgLens[StrMPAng], &PickMode, PickAngle}, - {&MsgStrs[StrMPTrsn] /* "Pick Torsion" */ , 0x13, &MsgAuxl[StrMPTrsn], - &MsgLens[StrMPTrsn], &PickMode, PickTorsn}, - {&MsgStrs[StrMPLabl] /* "Pick Label" */ , 0x13, &MsgAuxl[StrMPLabl], - &MsgLens[StrMPLabl], &PickMode, PickLabel}, - {&MsgStrs[StrMPCent] /* "Pick Centre" */ , 0x13, &MsgAuxl[StrMPCent], - &MsgLens[StrMPCent], &PickMode, PickOrign}, - {&MsgStrs[StrMPCoord] /* "Pick Coord" */ , 0x13, &MsgAuxl[StrMPCoord], - &MsgLens[StrMPCoord], &PickMode, PickCoord}, - {&MsgStrs[StrMPBond] /* "Pick Bond" */ , 0x13, &MsgAuxl[StrMPBond], - &MsgLens[StrMPBond], &PickMode, PickBond}, - {&MsgStrs[StrMRBond] /* "Rotate Bond" */ , 0x13, &MsgAuxl[StrMRBond], - &MsgLens[StrMRBond], &RotMode, RotBond}, - {&MsgStrs[StrMRMol] /* "Rotate Mol" */ , 0x13, &MsgAuxl[StrMRMol], - &MsgLens[StrMRMol], &RotMode, RotMol}, - {&MsgStrs[StrMRAll] /* "Rotate All" */ , 0x13, &MsgAuxl[StrMRAll], - &MsgLens[StrMRAll], &RotMode, RotAll} -}; - -static MenuItem ExpMenu[15] = { - {&MsgStrs[StrMBMP] /* "BMP..." */ , 0x11, &MsgAuxl[StrMBMP], - &MsgLens[StrMBMP], NULL, 0}, - {&MsgStrs[StrMGIF] /* "GIF..." */ , 0x11, &MsgAuxl[StrMGIF], - &MsgLens[StrMGIF], NULL, 0}, - {&MsgStrs[StrMIRGB] /* "IRIS RGB..." */ , 0x11, &MsgAuxl[StrMIRGB], - &MsgLens[StrMIRGB], NULL, 0}, - {&MsgStrs[StrMPPM] /* "PPM..." */ , 0x11, &MsgAuxl[StrMPPM], - &MsgLens[StrMPPM], NULL, 0}, - {&MsgStrs[StrMSRast] /* "Sun Raster..." */ , 0x11, &MsgAuxl[StrMSRast], - &MsgLens[StrMSRast], NULL, 0}, - {&MsgStrs[StrMPostscr] /* "PostScript..." */ , 0x11, - &MsgAuxl[StrMPostscr], - &MsgLens[StrMPostscr], NULL, 0}, - {&MsgStrs[StrMPICT] /* "PICT..." */ , 0x11, &MsgAuxl[StrMPICT], - &MsgLens[StrMPICT], NULL, 0}, - {&MsgStrs[StrMVECPS] /* "Vector PS ..." */ , 0x11, &MsgAuxl[StrMVECPS], - &MsgLens[StrMVECPS], NULL, 0}, - {&MsgStrs[StrMMSCR] /* "Molscript ..." */ , 0x11, &MsgAuxl[StrMMSCR], - &MsgLens[StrMMSCR], NULL, 0}, - {&MsgStrs[StrMKine] /* "Kinemage ..." */ , 0x11, &MsgAuxl[StrMKine], - &MsgLens[StrMKine], NULL, 0}, - {&MsgStrs[StrMPOVRAY] /*"POVRay 3 ..." */ , 0x11, - &MsgAuxl[StrMPOVRAY], - &MsgLens[StrMPOVRAY], NULL, 0}, - {&MsgStrs[StrMVRML] /* "VRML ..." */ , 0x11, &MsgAuxl[StrMVRML], - &MsgLens[StrMVRML], NULL, 0}, - {&MsgStrs[StrMRPP] /* "Ramachandran ..." */ , 0x11, &MsgAuxl[StrMRPP], - &MsgLens[StrMRPP], NULL, 0}, - {&MsgStrs[StrMR3D] /* "Raster3D ..." */ , 0x11, &MsgAuxl[StrMR3D], - &MsgLens[StrMR3D], NULL, 0}, - {&MsgStrs[StrMSCR] /* "RasMol Script ..." */ , 0x11, &MsgAuxl[StrMSCR], - &MsgLens[StrMSCR], NULL, 0} -}; - -static MenuItem HelMenu[4] = { - {&MsgStrs[StrMAbout] /* "About RasMol..." */ , 0x11, &MsgAuxl[StrMAbout], - &MsgLens[StrMAbout], NULL, 0}, - {&MsgStrs[StrMUserM] /* "User Manual..." */ , 0x11, &MsgAuxl[StrMUserM], - &MsgLens[StrMUserM], NULL, 0}, - {&MsgStrs[StrRegister] /* "Register ..." */ , 0x11, &MsgAuxl[StrRegister], - &MsgLens[StrRegister], NULL, 0}, - {&MsgStrs[StrDonate] /* "Donate..." */ , 0x11, &MsgAuxl[StrDonate], - &MsgLens[StrDonate], NULL, 0} -}; - - -typedef struct _BarItem { - MenuItem *menu; - char **text; - int count; - int flags; - int *pos; - int *len; - int *increment; -} BarItem; - -#define MenuBarMax 7 -static BarItem MenuBar[MenuBarMax] = { - {FilMenu, &MsgStrs[StrMFile] /* "File" */ , 5, 0x01, - &MsgAuxl[StrMFile], - &MsgLens[StrMFile], &NumMolecules}, - {DisMenu, &MsgStrs[StrMDisplay] /* "Display" */ , 9, 0x01, - &MsgAuxl[StrMDisplay], - &MsgLens[StrMDisplay], NULL}, - {ColMenu, &MsgStrs[StrMColour] /* "Colours" */ , 10, 0x01, - &MsgAuxl[StrMColour], - &MsgLens[StrMColour], NULL}, - {OptMenu, &MsgStrs[StrMOpt] /* "Options" */ , 7, 0x01, &MsgAuxl[StrMOpt], - &MsgLens[StrMOpt], NULL}, - {SetMenu, &MsgStrs[StrMSettings] /* "Settings" */ , 13, 0x01, - &MsgAuxl[StrMSettings], - &MsgLens[StrMSettings], NULL}, - {ExpMenu, &MsgStrs[StrMExport] /* "Export" */ , 15, 0x01, - &MsgAuxl[StrMExport], - &MsgLens[StrMExport], NULL}, - {HelMenu, &MsgStrs[StrMHelp] /* "Help" */ , 4, 0x01, - &MsgAuxl[StrMHelp], - &MsgLens[StrMHelp], NULL} -}; - - -static int MenuFocus; -static int ItemFocus; -static int MenuItemSelect; -static int MenuBarSelect; -static int MenuBarCount; -static int PopUpWide; -static int PopUpHigh; -static int PopUpFlag; -static int ItemFlag; - - -#ifdef DIALBOX -#include - -static char *DialLabel[] = { - "ROTATE X", "ROTATE Y", "ROTATE Z", " ZOOM ", - "TRANS X ", "TRANS Y ", "TRANS Z ", " SLAB " -}; - -static int *DialMap; -static int ESVDialMap[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; -static int SGIDialMap[8] = { 3, 7, 2, 6, 1, 5, 0, 4 }; - -static Real DialRes[8]; -static int DialPrev[8]; -static int DialMode; - -static int UseDialLEDs; -static XDevice *Dials; -static int DialEvent; -static int UseDials; -#endif - - -#ifdef MITSHM -#include -#include -#include -#include - -XShmSegmentInfo xshminfo; -int SharedMemOption; -int SharedMemFlag; -#else -#define SharedMemOption False -#endif - -#define XScrlSkip 8 -#define YScrlSkip 8 - -typedef union { - Long longword; - Byte bytes[4]; -} ByteTest; - - -static int MenuHigh; -static int FontHigh; -static char *lastlocale; -static Cursor cross; -static Cursor arrow; -static Cursor hglass; -static Pixmap Scrl; -static Pixmap tilepix; -static Pixmap uppix, dnpix; -static Pixmap lfpix, rgpix; -static XFontStruct *MenuFont = NULL; -static XFontSet MenuFontSet = NULL; -static short XFascent; -static short XFdescent; -static XSetWindowAttributes attr; -static Window XScrlWin, YScrlWin; -static XWMHints hints; -static Colormap lmap; -static XImage *image; -static GC gcon; - -#ifdef EIGHTBIT -static unsigned long Ident[256]; -static int IdentCount; -#endif - -static int XHeldButton; -static int XHeldStep; - -static Byte Intensity[LutSize]; -static Pixel WhiteCol; -static Pixel BlackCol; - -#ifdef THIRTYTWOBIT -static int SwapBytes; -#endif - -static int MaxWidth, MaxHeight; -static int MinWidth, MinHeight; -static int MainWide, MainHigh; -static int ScrlX, NewScrlX; -static int ScrlY, NewScrlY; - - -/* WM_PROTOCOLS */ -static char TkInterp[10]; -static Atom AppNameAtom; -static Atom DelWinXAtom; -static Atom ProtoXAtom; -static Atom InterpAtom; -static Atom CommAtom; - - -/*=======================*/ -/* Function Prototypes */ -/*=======================*/ - -extern int ProcessCommand(void); -static int HandleMenuLoop(void); -static int HandleIPCError(Display * dpy, XErrorEvent * ptr); -#ifdef MITSHM -static int HandleShmError(Display * dpy, XErrorEvent * ptr); -#endif - - -void FatalGraphicsError(char *ptr) -{ - char buffer[80]; - - sprintf(buffer, "Graphics Error: %s!", ptr); - RasMolFatalExit(buffer); -} - - -void AllocateColourMap(void) -{ -#ifdef EIGHTBIT - static XColor Col; - register int i, j; - - if (Monochrome) { - for (i = 0; i < LutSize; i++) - Intensity[i] = - (Byte) ((int) (20 * RLut[i] + 32 * GLut[i] + 12 * BLut[i]) >> - 6); - return; - } - - if (LocalMap) { - XSetWindowColormap(dpy, MainWin, cmap); - XSetWindowColormap(dpy, CanvWin, cmap); - XUninstallColormap(dpy, lmap); - XFreeColormap(dpy, lmap); - LocalMap = False; - } else { - if (IdentCount) - XFreeColors(dpy, cmap, Ident, IdentCount, (long) 0); - } - IdentCount = 0; - - - for (i = 0; i < LutSize; i++) { - if (ULut[i]) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - Col.flags = DoRed | DoGreen | DoBlue; - if (!XAllocColor(dpy, cmap, &Col)) - break; - Ident[IdentCount++] = Col.pixel; - Lut[i] = (Pixel) Col.pixel; - } - } - - if (i < LutSize) { - lmap = XCopyColormapAndFree(dpy, cmap); - LocalMap = True; - - for (j = 0; j < 5; j++) { - Col.red = RLut[j] << 8 | RLut[j]; - Col.green = GLut[j] << 8 | GLut[j]; - Col.blue = BLut[j] << 8 | BLut[j]; - XAllocColor(dpy, cmap, &Col); - Lut[i] = (Pixel) Col.pixel; - } - - for (j = i; j < LutSize; j++) { - if (ULut[j]) { - Col.red = RLut[j] << 8 | RLut[j]; - Col.green = GLut[j] << 8 | GLut[j]; - Col.blue = BLut[j] << 8 | BLut[j]; - XAllocColor(dpy, lmap, &Col); - Lut[j] = (Pixel) Col.pixel; - } - } - XSetWindowColormap(dpy, MainWin, lmap); - XSetWindowColormap(dpy, CanvWin, lmap); - XInstallColormap(dpy, lmap); - } -#else /* EIGHTBIT */ -#ifdef THIRTYTWOBIT - static XColor Col; - static ByteTest buf; - register Byte temp; - register int i; - - for (i = 0; i < LutSize; i++) { - if (ULut[i]) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - XAllocColor(dpy, cmap, &Col); - if (SwapBytes) { - buf.longword = (Long) Col.pixel; - temp = buf.bytes[0]; - buf.bytes[0] = buf.bytes[3]; - buf.bytes[3] = temp; - temp = buf.bytes[1]; - buf.bytes[1] = buf.bytes[2]; - buf.bytes[2] = temp; - Lut[i] = buf.longword; - } else - Lut[i] = (Long) Col.pixel; - } - } -#else /* THIRTYTWOBIT */ - static XColor Col; - register int i; - - for (i = 0; i < LutSize; i++) - if (ULut[i]) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - XAllocColor(dpy, cmap, &Col); - Lut[i] = (Pixel) Col.pixel; - } -#endif /* THIRTYTWOBIT */ -#endif /* EIGHTBIT */ - XSetWindowBackground(dpy, CanvWin, (unsigned long) Lut[5]); -} - - -static void OpenCanvas(int x, int y) -{ - register unsigned long mask; - - mask = CWEventMask; - attr.event_mask = - ExposureMask | ButtonPressMask | ButtonMotionMask | ButtonReleaseMask; - attr.cursor = cross; - mask |= CWCursor; - attr.background_pixel = Lut[0]; - mask |= CWBackPixel; - - CanvWin = XCreateWindow(dpy, MainWin, 14, MenuHigh + 14, x, y, 0, - CopyFromParent, InputOutput, vis, mask, &attr); -} - - -static XFontSet RasLoadQueryFontSet(Display * disp, const char *fontset_name) -{ - XFontSet MenuFontSet; - int missing_charset_count; - char **missing_charset_list; - char *def_string; - char buffer[255]; - - MenuFontSet = XCreateFontSet(disp, fontset_name, - &missing_charset_list, &missing_charset_count, - &def_string); - - if (missing_charset_count) { - if (strlen(fontset_name) < 200) - sprintf(buffer, "Missing charsets in MenuFontSet (%s) creation.\n", - fontset_name); - else - strcpy(buffer, "Missing charsets in MenuFontSet creation.\n"); - WriteString(buffer); - for (; missing_charset_count--;) { - sprintf(buffer, " missing %d: %s\n", - missing_charset_count, - missing_charset_list[missing_charset_count]); - WriteString(buffer); - } - XFreeStringList(missing_charset_list); - } - return MenuFontSet; -} - - -static int RasOpenFonts(void) -{ - static char fontname[255]; - register int i; - XFontSetExtents *extent; - char *menufonts; - XRectangle dummy; - XRectangle bound; - - if (Language != TermLanguage) { - if (MenuFont && MenuFont->fid) - XUnloadFont(dpy, MenuFont->fid); - MenuFont = 0; - if (MenuFontSet) - XFreeFontSet(dpy, MenuFontSet); - MenuFontSet = NULL; - } - - if (!MenuFont || !(MenuFont->fid)) { - for (i = 0; i < NUMLANGS; i++) { - if (langfonts[i].lang == Language) { - int kl; - if ((menufonts = getenv(langfonts[i].menufontvar))) { - char *strend; - while ((strend = strchr(menufonts, ':'))) { - /* fprintf(stderr,"menufonts: %s\n",menufonts); */ - strncpy(fontname, menufonts, - strend - menufonts < - 255 ? strend - menufonts : 254); - fontname[strend - menufonts < - 255 ? strend - menufonts : 254] = '\0'; - menufonts = strend + 1; - if ((MenuFont = XLoadQueryFont(dpy, fontname))) - break; - } - if (!MenuFont && (kl = strlen(menufonts)) > 0) { - /* fprintf(stderr,"menufonts: %s\n",menufonts); */ - strncpy(fontname, menufonts, kl < 255 ? kl : 254); - fontname[kl < 255 ? kl : 254] = '\0'; - if ((MenuFont = XLoadQueryFont(dpy, fontname))) - break; - } - if (MenuFont) - break; - } - if ((menufonts = langfonts[i].menufontlist)) { - char *strend; - while ((strend = strchr(menufonts, ':'))) { - /* fprintf(stderr,"menufonts: %s\n",menufonts); */ - strncpy(fontname, menufonts, - strend - menufonts < - 255 ? strend - menufonts : 254); - fontname[strend - menufonts < - 255 ? strend - menufonts : 254] = '\0'; - menufonts = strend + 1; - if ((MenuFont = XLoadQueryFont(dpy, fontname))) - break; - } - if (!MenuFont && (kl = strlen(menufonts)) > 0) { - /* fprintf(stderr,"menufonts: %s\n",menufonts); */ - strncpy(fontname, menufonts, kl < 255 ? kl : 254); - fontname[kl < 255 ? kl : 254] = '\0'; - if ((MenuFont = XLoadQueryFont(dpy, fontname))) - break; - } - if (MenuFont) - break; - } - } - } - } - - /* if (MenuFont) fprintf(stderr,"Selected menufont %s\n",fontname); */ - - if (!cross) - cross = XCreateFontCursor(dpy, XC_tcross); - if (!arrow) - arrow = XCreateFontCursor(dpy, XC_top_left_arrow); - - if (Language == Chinese) { - strncat(fontname, ",-*-helvetica-bold-o-normal-*-14-*-iso8859-1", - 254 - strlen(fontname)); - SetLocale(LC_ALL, "zh_CN.GB2312"); - lastlocale = "chinese"; - MenuFontSet = RasLoadQueryFontSet(dpy, fontname); - if (!MenuFontSet) - return 1; - extent = XExtentsOfFontSet(MenuFontSet); - XFascent = extent->max_logical_extent.height; - XFdescent = extent->max_logical_extent.height * 1.0 / 10.0; - FontHigh = extent->max_logical_extent.height + 6; - XmbTextExtents(MenuFontSet, MsgStrs[StrWarranty], - strlen(MsgStrs[StrWarranty]), &dummy, &bound); - if (bound.height > FontHigh) - FontHigh = bound.height; - if (-dummy.y > XFascent) - XFascent = dummy.y; - if (-dummy.y + dummy.height > XFdescent) - XFdescent = -dummy.y + dummy.height; - if (XFdescent > 4) - XFdescent = 4; - MenuHigh = FontHigh + 6; - if (!MenuFont) - return 1; - return 0; - - } else if (Language == Japanese) { - strncat(fontname, ",-*-helvetica-bold-o-normal-*-14-*-iso8859-1", - 254 - strlen(fontname)); - SetLocale(LC_ALL, "ja_JP.eucjp"); - lastlocale = "japanese"; - MenuFontSet = RasLoadQueryFontSet(dpy, fontname); - if (!MenuFontSet) - return 1; - extent = XExtentsOfFontSet(MenuFontSet); - XFascent = extent->max_logical_extent.height; - XFdescent = extent->max_logical_extent.height * 2.0 / 10.0; - FontHigh = extent->max_logical_extent.height + 6; - XmbTextExtents(MenuFontSet, MsgStrs[StrWarranty], - strlen(MsgStrs[StrWarranty]), &dummy, &bound); - if (bound.height > FontHigh) - FontHigh = bound.height; - if (-dummy.y > XFascent) - XFascent = dummy.y; - if (-dummy.y + dummy.height > XFdescent) - XFdescent = -dummy.y + dummy.height; - if (XFdescent > 4) - XFdescent = 4; - MenuHigh = FontHigh + 6; - if (!MenuFont) - return 1; - return 0; - } else { - if (Language == English) { - SetLocale(LC_ALL, "en_US"); - lastlocale = "english"; - } else if (Language == Spanish) { - SetLocale(LC_ALL, "es_ES"); - lastlocale = "spanish"; - } else if (Language == Italian) { - SetLocale(LC_ALL, "it_IT"); - lastlocale = "italian"; - } else if (Language == French) { - SetLocale(LC_ALL, "fr_FR"); - lastlocale = "french"; - } else if (Language == Russian) { - SetLocale(LC_ALL, "ru_RU"); - lastlocale = "russian"; - } else if (Language == Bulgarian) { - SetLocale(LC_ALL, "bg_BG"); - lastlocale = "bulgarian"; - } - - if (!MenuFont) - return 1; - - FontHigh = - MenuFont->max_bounds.descent + MenuFont->max_bounds.ascent + 1; - } - MenuHigh = FontHigh + 6; - XFascent = MenuFont->ascent; - XFdescent = MenuFont->descent; - return 0; -} - - -static void OpenCursors(void) -{ - Pixmap source, mask; - XColor black, white; - - white.red = 65535; - black.red = 0; - white.green = 65535; - black.green = 0; - white.blue = 65535; - black.blue = 0; - - white.flags = DoRed | DoGreen | DoBlue; - black.flags = DoRed | DoGreen | DoBlue; - - source = XCreateBitmapFromData(dpy, MainWin, (char *) HGlassData, 16, 16); - mask = XCreateBitmapFromData(dpy, MainWin, (char *) HGlassMask, 16, 16); - hglass = XCreatePixmapCursor(dpy, source, mask, &black, &white, 7, 7); -} - - -static void OpenColourMap(void) -{ - static XColor Col; - register int i; - -#ifdef EIGHTBIT - if (!Monochrome) { - Col.flags = DoRed | DoGreen | DoBlue; - - for (i = 0; i < 5; i++) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - if (!XAllocColor(dpy, cmap, &Col)) { - cmap = XCopyColormapAndFree(dpy, cmap); - XAllocColor(dpy, cmap, &Col); - } - Lut[i] = (Pixel) Col.pixel; - } - Lut[5] = Lut[0]; - } else { /* Black & White */ - Lut[0] = BlackCol; - Lut[1] = BlackCol; - Lut[2] = WhiteCol; - Lut[3] = BlackCol; - Lut[4] = WhiteCol; - - Intensity[5] = 0; - Lut[5] = 5; - } - - LocalMap = False; - IdentCount = 0; -#else - Col.flags = DoRed | DoGreen | DoBlue; - - for (i = 0; i < 5; i++) { - Col.red = RLut[i] << 8 | RLut[i]; - Col.green = GLut[i] << 8 | GLut[i]; - Col.blue = BLut[i] << 8 | BLut[i]; - XAllocColor(dpy, cmap, &Col); - Lut[i] = (Pixel) Col.pixel; - } - Lut[5] = Lut[0]; -#endif -} - - -static int RegisterInterpName(char *name) -{ - static unsigned char *registry; - static unsigned long len, left; - static char buffer[32]; - static int format; - static Atom type; - - register int result; - register char *ptr; - register int (*handler) (); - - registry = NULL; - handler = XSetErrorHandler(HandleIPCError); - result = XGetWindowProperty(dpy, RootWindow(dpy, 0), InterpAtom, - 0, 100000, False, XA_STRING, &type, - &format, &len, &left, ®istry); - XSync(dpy, False); - XSetErrorHandler(handler); - - if ((result != Success) || (format != 8) || (type != XA_STRING)) { - if ((type != None) && registry) - XFree((char *) registry); - - sprintf(buffer, "%x %s", (int) MainWin, name); - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, RootWindow(dpy, 0), InterpAtom, XA_STRING, - 8, PropModeReplace, (unsigned char *) buffer, - (int) strlen(buffer) + 1); - XSync(dpy, False); - XSetErrorHandler(handler); - - return (True); - } - - ptr = (char *) registry; - while (*ptr) { /* Skip Window ID */ - while (*ptr++ != ' ') - if (!*ptr) - break; - - /* Compare Interp Name */ - if (!strcmp(ptr, name)) { - XFree((char *) registry); - return False; - } - - while (*ptr++); - } - - XFree((char *) registry); - sprintf(buffer, "%x %s", (int) MainWin, name); - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, RootWindow(dpy, 0), InterpAtom, XA_STRING, - 8, PropModeAppend, (unsigned char *) buffer, - (int) strlen(buffer) + 1); - XSync(dpy, False); - XSetErrorHandler(handler); - return (True); -} - - -static void DeRegisterInterpName(char *name) -{ - static unsigned char *registry; - static unsigned long len, left; - static int format; - static Atom type; - - register char *src, *dst; - register int result; - register int (*handler) (); - - /* Avoid compiler warnings */ - src = (char *) 0; - - registry = NULL; - handler = XSetErrorHandler(HandleIPCError); - result = XGetWindowProperty(dpy, RootWindow(dpy, 0), InterpAtom, - 0, 100000, False, XA_STRING, &type, - &format, &len, &left, ®istry); - XSync(dpy, False); - XSetErrorHandler(handler); - if (type == None) - return; - - if ((result != Success) || (format != 8) || (type != XA_STRING)) { - handler = XSetErrorHandler(HandleIPCError); - XDeleteProperty(dpy, RootWindow(dpy, 0), InterpAtom); - XSync(dpy, False); - XSetErrorHandler(handler); - if (registry) - XFree((char *) registry); - return; - } - - dst = (char *) registry; - while (*dst) { /* Skip Window ID */ - src = dst; - while (*src++ != ' ') - if (!*src) - break; - - /* Compare Interp Name */ - if (strcmp(src, name)) { - while (*dst++); - } else - break; - } - - if (*dst) { /* Skip Interp Name */ - while (*src++); - - /* Shuffle Registry */ - while (*src) - while ((*dst++ = *src++)); - *dst = 0; - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, RootWindow(dpy, 0), InterpAtom, XA_STRING, - 8, PropModeReplace, registry, - (int) (dst - (char *) registry)); - XSync(dpy, False); - XSetErrorHandler(handler); - } - XFree((char *) registry); -} - - -static void OpenIPCComms(void) -{ - auto char buffer[16]; - register int i; - register int (*handler) (); - - CommAtom = XInternAtom(dpy, "Comm", False); - InterpAtom = XInternAtom(dpy, "InterpRegistry", False); - AppNameAtom = XInternAtom(dpy, "TK_APPLICATION", False); - DelWinXAtom = XInternAtom(dpy, "WM_DELETE_WINDOW", False); - XSync(dpy, False); - /* XSetWMProtocols(dpy,MainWin,&DelWinXAtom,True); */ - if ((ProtoXAtom = XInternAtom(dpy, "WM_PROTOCOLS", False))) { - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, MainWin, ProtoXAtom, XA_ATOM, 32, - PropModeReplace, (Byte *) & DelWinXAtom, True); - XSync(dpy, False); - XSetErrorHandler(handler); - } - i = 0; - XSync(dpy, False); - if (!RegisterInterpName("rasmol")) { - strcpy(TkInterp, "rasmol #0"); - for (i = 1; i < 10; i++) { - TkInterp[8] = i + '0'; - if (RegisterInterpName(TkInterp)) - break; - } - - if (i < 10) { /* Tk4.0 and later! */ - strcpy(buffer, "{rasmol #0}"); - buffer[9] = i + '0'; - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, MainWin, AppNameAtom, XA_STRING, - 8, PropModeReplace, (Byte *) buffer, 12); - XSync(dpy, False); - XSetErrorHandler(handler); - } else - *TkInterp = 0; - } else { - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, MainWin, AppNameAtom, XA_STRING, - 8, PropModeReplace, (Byte *) "rasmol", 7); - XSync(dpy, False); - XSetErrorHandler(handler); - strcpy(TkInterp, "rasmol"); - } - XUngrabServer(dpy); -} - - -static void DrawUpCircle(Drawable wdw, int x1, int y1, int x2, int y2) -{ - int width, height; - - width = x2 - x1 + 1; - height = y2 - y1 + 1; - -/* XSetForeground(dpy,gcon,(unsigned long)Lut[2]); - XFillArc(dpy,wdw,gcon,x1-1,y1-1,width+2,height+2,0,360*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[3]); - XFillArc(dpy,wdw,gcon,x1,y1,width,height,-45*64,180*64); - XFillArc(dpy,wdw,gcon,x1+1,y1+1,width-2,height-2,-45*64,180*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[1]); - XFillArc(dpy,wdw,gcon,x1,y1,width,height,135*64,180*64); - XFillArc(dpy,wdw,gcon,x1+1,y1+1,width-2,height-2,135*64,180*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[3]); - XFillArc(dpy,wdw,gcon,x1+2,y1+2,width-4,height-4,0,360*64); - */ - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillArc(dpy, wdw, gcon, x1 - 1, y1 - 1, width + 2, height + 2, 0, - 360 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XFillArc(dpy, wdw, gcon, x1, y1, width, height, 135 * 64, 360 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillArc(dpy, wdw, gcon, x1 + width / 10, y1, width - width / 10, - height - height / 10, 135 * 64, 360 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XFillArc(dpy, wdw, gcon, x1 + width / 9, y1, width - width / 9, - height - height / 9, 135 * 64, 360 * 64); -} - - -static void DrawUpPieSlice(Drawable wdw, int x1, int y1, int x2, int y2) -{ - int width, height; - - width = x2 - x1 + 1; - height = y2 - y1 + 1; - -/* XSetForeground(dpy,gcon,(unsigned long)Lut[2]); - XFillArc(dpy,wdw,gcon,x1-1,y1-1,width+2,height+2,135*64,90*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[1]); - XFillArc(dpy,wdw,gcon,x1,y1,width,height,135*64,90*64); - XFillArc(dpy,wdw,gcon,x1+1,y1+1,width-2,height-2,135*64,90*64); - - XSetForeground(dpy,gcon,(unsigned long)Lut[3]); - XFillArc(dpy,wdw,gcon,x1+2,y1+2,width-4,height-4,135*64,90*64); - */ - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillArc(dpy, wdw, gcon, x1 - 1, y1 - 1, width + 2, height + 2, 155 * 64, - 50 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XFillArc(dpy, wdw, gcon, x1, y1, width, height, 155 * 64, 50 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillArc(dpy, wdw, gcon, x1 + width / 10, y1, width - width / 10, - height - height / 10, 150 * 64, 60 * 64); - - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XFillArc(dpy, wdw, gcon, x1 + width / 9, y1, width - width / 9, - height - height / 9, 145 * 64, 70 * 64); - -} - - -static void DrawUpLine(Drawable wdw, int x1, int y1, int x2, int y2, int wid) -{ - XGCValues lineattr[4]; - - XGetGCValues(dpy, gcon, - GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle, - lineattr); - XSetLineAttributes(dpy, gcon, wid, LineSolid, CapRound, JoinRound); - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y2); - XSetLineAttributes(dpy, gcon, wid - 1, LineSolid, CapRound, JoinRound); - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XDrawLine(dpy, wdw, gcon, x1 + 1, y1 - 1, x2 + 1, y2 - 1); - XSetLineAttributes(dpy, gcon, wid - 2, LineSolid, CapRound, JoinRound); - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y2); - XChangeGC(dpy, gcon, GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle, - lineattr); -} - - -static void DrawUpBox(Drawable wdw, int x1, int y1, int x2, int y2) -{ - register int lx, ly, ux, uy; - - lx = x1 + 1; - ly = y1 + 1; - ux = x2 - 1; - uy = y2 - 1; - - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y1); /* top bar */ - XDrawLine(dpy, wdw, gcon, lx, ly, ux, ly); /* top bar */ - XDrawLine(dpy, wdw, gcon, x2, y1, x2, y2); /* right bar */ - XDrawLine(dpy, wdw, gcon, ux, ly, ux, uy); /* right bar */ - - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XDrawLine(dpy, wdw, gcon, x1, y2, x2, y2); /* bottom bar */ - XDrawLine(dpy, wdw, gcon, lx, uy, ux, uy); /* bottom bar */ - XDrawLine(dpy, wdw, gcon, x1, y1, x1, y2); /* left bar */ - XDrawLine(dpy, wdw, gcon, lx, ly, lx, uy); /* left bar */ -} - - -static void DrawDnBox(Drawable wdw, int x1, int y1, int x2, int y2) -{ - register int lx, ly, ux, uy; - - lx = x1 + 1; - ly = y1 + 1; - ux = x2 - 1; - uy = y2 - 1; - - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y1); /* top bar */ - XDrawLine(dpy, wdw, gcon, lx, ly, ux, ly); /* top bar */ - XDrawLine(dpy, wdw, gcon, x2, y1, x2, y2); /* right bar */ - XDrawLine(dpy, wdw, gcon, ux, ly, ux, uy); /* right bar */ - - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XDrawLine(dpy, wdw, gcon, x1, y2, x2, y2); /* bottom bar */ - XDrawLine(dpy, wdw, gcon, lx, uy, ux, uy); /* bottom bar */ - XDrawLine(dpy, wdw, gcon, x1, y1, x1, y2); /* left bar */ - XDrawLine(dpy, wdw, gcon, lx, ly, lx, uy); /* left bar */ -} - - -static void DrawNoBox(Drawable wdw, int x1, int y1, int x2, int y2) -{ - register int lx, ly, ux, uy; - - lx = x1 + 1; - ly = y1 + 1; - ux = x2 - 1; - uy = y2 - 1; - - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - - XDrawLine(dpy, wdw, gcon, x1, y1, x2, y1); - XDrawLine(dpy, wdw, gcon, x2, y1, x2, y2); - XDrawLine(dpy, wdw, gcon, x2, y2, x1, y2); - XDrawLine(dpy, wdw, gcon, x1, y2, x1, y1); - - XDrawLine(dpy, wdw, gcon, lx, ly, ux, ly); - XDrawLine(dpy, wdw, gcon, ux, ly, ux, uy); - XDrawLine(dpy, wdw, gcon, ux, uy, lx, uy); - XDrawLine(dpy, wdw, gcon, lx, uy, lx, ly); -} - - -static void OpenMenuBar(void) -{ - register unsigned long mask; - - mask = CWEventMask; - attr.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask; - MenuWin = XCreateWindow(dpy, MainWin, 2, 2, XRange + 49, FontHigh + 5, 0, - CopyFromParent, InputOnly, vis, mask, &attr); - - /* Create Unmapped PopUp Window! */ - mask = CWEventMask; - attr.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | - KeyPressMask | VisibilityChangeMask; - attr.background_pixel = Lut[2]; - attr.border_pixel = Lut[2]; - attr.override_redirect = True; - attr.save_under = True; - attr.colormap = cmap; - mask |= CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder | - CWColormap; - - PopUpWin = XCreateWindow(dpy, RootWin, 0, 0, 100, 100, 0, - PixDepth, InputOutput, vis, mask, &attr); - MenuFocus = False; - PopUpFlag = False; -} - - -static void OpenScrollBars(void) -{ - register unsigned long mask; - - Scrl = XCreatePixmap(dpy, MainWin, 16, 16, PixDepth); - XSetForeground(dpy, gcon, (unsigned long) Lut[2]); - XFillRectangle(dpy, Scrl, gcon, 0, 0, 15, 15); - XSetForeground(dpy, gcon, (unsigned long) Lut[0]); - XDrawRectangle(dpy, Scrl, gcon, 0, 0, 15, 15); - DrawUpBox(Scrl, 1, 1, 14, 14); - - tilepix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) ScrlTile, 8, 8, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - - mask = CWEventMask; - attr.event_mask = ExposureMask | ButtonPressMask | ButtonMotionMask - | ButtonReleaseMask; - attr.background_pixmap = tilepix; - mask |= CWBackPixmap; - - XScrlWin = - XCreateWindow(dpy, MainWin, 14, YRange + MenuHigh + 24, XRange, 16, 0, - CopyFromParent, InputOutput, vis, mask, &attr); - lfpix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) LfArrow, 16, 16, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - rgpix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) RgArrow, 16, 16, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - - YScrlWin = - XCreateWindow(dpy, MainWin, XRange + 24, MenuHigh + 14, 16, YRange, 0, - CopyFromParent, InputOutput, vis, mask, &attr); - uppix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) UpArrow, 16, 16, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - dnpix = - XCreatePixmapFromBitmapData(dpy, MainWin, (char *) DnArrow, 16, 16, - (unsigned long) Lut[0], - (unsigned long) Lut[2], PixDepth); - - ScrlX = (XRange / 2) - 8; - ScrlY = (YRange / 2) - 8; -} - - -static void DrawXScroll(void) -{ - XCopyArea(dpy, rgpix, XScrlWin, gcon, 0, 0, 16, 16, XRange - 16, 0); - XCopyArea(dpy, Scrl, XScrlWin, gcon, 0, 0, 16, 16, ScrlX, 0); - XCopyArea(dpy, lfpix, XScrlWin, gcon, 0, 0, 16, 16, 0, 0); -} - - -static void DrawYScroll(void) -{ - XCopyArea(dpy, dnpix, YScrlWin, gcon, 0, 0, 16, 16, 0, YRange - 16); - XCopyArea(dpy, Scrl, YScrlWin, gcon, 0, 0, 16, 16, 0, ScrlY); - XCopyArea(dpy, uppix, YScrlWin, gcon, 0, 0, 16, 16, 0, 0); -} - - -void UpdateScrollBars(void) -{ - register int temp; - - if (RotMode == RotAll) { - temp = (WorldDialValue[YScrlDial] + 1.0) * (YRange - 48); - } else { - temp = (DialValue[YScrlDial] + 1.0) * (YRange - 48); - } - NewScrlY = (temp >> 1) + 16; - - if (NewScrlY != ScrlY) { - XClearArea(dpy, YScrlWin, 0, ScrlY, 16, 16, False); - XCopyArea(dpy, Scrl, YScrlWin, gcon, 0, 0, 16, 16, 0, NewScrlY); - ReDrawFlag |= (1 << YScrlDial); - ScrlY = NewScrlY; - } - - if ((RotMode == RotBond) && BondSelected) { - temp = ((BondSelected->BRotValue) + 1.0) * (XRange - 48); - } else { - if (RotMode == RotAll) { - temp = (WorldDialValue[XScrlDial] + 1.0) * (XRange - 48); - } else { - temp = (DialValue[XScrlDial] + 1.0) * (XRange - 48); - } - } - NewScrlX = (temp >> 1) + 16; - - if (NewScrlX != ScrlX) { - XClearArea(dpy, XScrlWin, ScrlX, 0, 16, 16, False); - XCopyArea(dpy, Scrl, XScrlWin, gcon, 0, 0, 16, 16, NewScrlX, 0); - ReDrawFlag |= (1 << XScrlDial); - ScrlX = NewScrlX; - } - XFlush(dpy); -} - - -#ifdef DIALBOX -static void SetDialLabel(int num, char *ptr) -{ - static XStringFeedbackControl ctrl; - static KeySym text[8]; - register int length; - - length = 0; - while (*ptr) - text[length++] = *ptr++; - - ctrl.id = num; - ctrl.num_keysyms = length; - ctrl.class = ValuatorClass; - ctrl.syms_to_display = text; - XChangeFeedbackControl(dpy, Dials, DvString, (XFeedbackControl *) & ctrl); -} - - -static void GetDialState(void) -{ - register XValuatorState *ptr; - register XDeviceState *stat; - register int i, j, max; - - stat = XQueryDeviceState(dpy, Dials); - ptr = (XValuatorState *) stat->data; - for (i = 0; i < stat->num_classes; i++) { - if (ptr->class == ValuatorClass) { - if (ptr->mode & 0x01) { - DialMode = Absolute; - max = MinFun(ptr->num_valuators, 8); - for (j = 0; j < max; j++) - DialPrev[j] = ptr->valuators[j]; - } else - DialMode = Relative; - break; - } else - ptr = (XValuatorState *) (((char *) ptr) + ptr->length); - } - XFreeDeviceState(stat); -} - - -static void OpenDialsBox(void) -{ - register XValuatorInfo *valptr; - register XFeedbackState *list; - register XFeedbackState *feed; - register XDeviceInfo *devlist; - register XDeviceInfo *ptr; - register Atom devtype; - register int i, j, max; - - static XEventClass dclass; - static int count; - - UseDials = False; - /* Avoid X Server's without the extension */ - if (!XQueryExtension(dpy, "XInputExtension", &count, &count, &count)) - return; - - devlist = XListInputDevices(dpy, &count); - devtype = XInternAtom(dpy, XI_KNOB_BOX, True); - if ((devtype == None) || !devlist) - return; - - ptr = devlist; - for (i = 0; i < count; i++) - if ((ptr->use == IsXExtensionDevice) && (ptr->type == devtype)) { - valptr = (XValuatorInfo *) ptr->inputclassinfo; - for (j = 0; j < ptr->num_classes; j++) { - if (valptr->class == ValuatorClass) - if ((Dials = XOpenDevice(dpy, ptr->id))) { - UseDials = True; - break; - } - valptr = (XValuatorInfo *) (((char *) valptr) + - valptr->length); - } - if (UseDials) - break; - } else - ptr++; - /* XFreeDeviceList(devlist); */ - - if (UseDials) { /* Determine Dial Mapping! */ - if (!strcmp(ServerVendor(dpy), "Silicon Graphics")) { - DialMap = SGIDialMap; - } else - DialMap = ESVDialMap; - - DialMode = valptr->mode; - max = MinFun(valptr->num_axes, 8); - for (i = 0; i < max; i++) - DialRes[i] = (Real) valptr->axes[i].resolution; - GetDialState(); - } else - return; - - UseDialLEDs = 0; - feed = list = XGetFeedbackControl(dpy, Dials, &count); - for (i = 0; i < count; i++) { - if (feed->class == StringFeedbackClass) - UseDialLEDs++; - feed = (XFeedbackState *) (((char *) feed) + feed->length); - } - XFreeFeedbackList(list); - - if (UseDialLEDs >= 8) { - for (i = 0; i < 8; i++) - SetDialLabel(i, DialLabel[DialMap[i]]); - } else - UseDialLEDs = False; - - DeviceMotionNotify(Dials, DialEvent, dclass); - XSelectExtensionEvent(dpy, MainWin, &dclass, 1); - XSelectExtensionEvent(dpy, MenuWin, &dclass, 1); - XSelectExtensionEvent(dpy, CanvWin, &dclass, 1); - XSelectExtensionEvent(dpy, XScrlWin, &dclass, 1); - XSelectExtensionEvent(dpy, YScrlWin, &dclass, 1); -} - - -static void HandleDialEvent(XDeviceMotionEvent * ptr) -{ - register double temp; - register int count; - register int value; - register int index; - register int num; - - /* Limit Number of Dials */ - count = 8 - ptr->first_axis; - if (count > (int) ptr->axes_count) - count = (int) ptr->axes_count; - - for (index = 0; index < count; index++) { - num = ptr->first_axis + index; - if (DialMode == Absolute) { - value = ptr->axis_data[index] - DialPrev[num]; - DialPrev[num] = ptr->axis_data[index]; - } else - value = ptr->axis_data[index]; - - if (value) { - temp = (Real) value / DialRes[num]; - num = DialMap[num]; - if (num == YScrlDial || num == XScrlDial) { - if ((RotMode == RotBond) && BondSelected && num == XScrlDial) { - temp += BondSelected->BRotValue; - ReDrawFlag |= RFRotBond; - } else { - if (RotMode == RotAll) { - temp += WorldDialValue[num]; - ReDrawFlag |= (1 << num); - } else { - temp += DialValue[num]; - ReDrawFlag |= (1 << num); - } - } - } else { - temp += DialValue[num]; - ReDrawFlag |= (1 << num); - } - - if (num < 3) { - while (temp < -1.0) - temp += 2.0; - while (temp > 1.0) - temp -= 2.0; - } else { - if (temp < -1.0) - temp = -1.0; - if (temp > 1.0) - temp = 1.0; - } - if (num == YScrlDial || num == XScrlDial) { - if ((RotMode == RotBond) && BondSelected && num == XScrlDial) { - BondSelected->BRotValue = temp; - ReDrawFlag |= RFRotBond; - } else { - if (RotMode == RotAll) { - WorldDialValue[num] = temp; - } else { - DialValue[num] = temp; - } - } - } else { - DialValue[num] = temp; - } - - if (num == YScrlDial) { - value = (temp + 1.0) * (YRange - 48); - NewScrlY = (value >> 1) + 16; - } - - if (num == XScrlDial) { - value = (temp + 1.0) * (XRange - 48); - NewScrlX = (value >> 1) + 16; - } - } - } -} -#endif - - -static void DrawMainWin(void) -{ - register int temp; - - DrawUpBox(MainWin, 0, 0, MainWide, MainHigh); - DrawUpBox(MainWin, 0, 0, MainWide - 2, FontHigh + 7); - - temp = YRange + MenuHigh; - DrawDnBox(MainWin, 12, MenuHigh + 12, XRange + 16, temp + 16); - DrawDnBox(MainWin, XRange + 22, MenuHigh + 12, XRange + 41, temp + 16); - DrawDnBox(MainWin, 12, temp + 22, XRange + 16, temp + 41); -} - - -/*====================*/ -/* Menu Bar Display */ -/*====================*/ - -static void DisplayMenuBarText(BarItem * ptr, int x, int y) -{ - register unsigned long col; - register int under, pos, wide; - int slen; - - if (ptr->flags & mbEnable && !DisableMenu) { - col = Lut[0]; - } else - col = Lut[1]; - XSetForeground(dpy, gcon, col); - - if (ptr->len) { - slen = *(ptr->len); - } else { - slen = strlen(*(ptr->text)); - } - if (MenuFontSet) { - XmbDrawString(dpy, MainWin, MenuFontSet, gcon, x, y, *(ptr->text), - slen); - under = y + XFdescent; - } else { - XDrawString(dpy, MainWin, gcon, x, y, *(ptr->text), slen); - under = y + MenuFont->descent; - } - - if (!isascii(*(*(ptr->text) + *(ptr->pos)))) - return; - - pos = x; - if (*(ptr->pos) > 0) - pos += XTextWidth(MenuFont, *(ptr->text), *(ptr->pos)); - - if (MenuFontSet) { - if (*(ptr->pos) > 0) - pos += XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->pos)); - wide = -XmbTextEscapement(MenuFontSet, *(ptr->text) + *(ptr->pos) + 1, - slen - *(ptr->pos) - 1) - + XmbTextEscapement(MenuFontSet, *(ptr->text) + *(ptr->pos), - slen - *(ptr->pos)); - } else { - wide = -XTextWidth(MenuFont, *(ptr->text) + *(ptr->pos) + 1, - slen - *(ptr->pos) - 1) - + XTextWidth(MenuFont, *(ptr->text) + *(ptr->pos), - slen - *(ptr->pos)); - } - - if (wide > 3) - wide--; - if (wide > 6) - wide--; - - XDrawLine(dpy, MainWin, gcon, pos, under, pos + wide, under); -} - - -static void DrawMenuBar(void) -{ - register BarItem *ptr; - register int wide; - register int x, y; - register int i; - - if (Language != TermLanguage) { - if (RasOpenFonts()) { - Language = TermLanguage; - RasOpenFonts(); - } - TermLanguage = Language; - } - - x = 6; - if (MenuFontSet) { - y = XFascent + 4; - } else { - y = MenuFont->ascent + 4; - XSetFont(dpy, gcon, MenuFont->fid); - } - - for (i = 0; i < MenuBarMax; i++) { - ptr = MenuBar + i; - if (MenuFontSet) { - wide = XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->len)); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - if (x + wide + 24 > MainWide) - break; - - /* Right Justify "Help" */ - if (i == MenuBarMax - 1) - x = MainWide - (wide + 24); - DisplayMenuBarText(ptr, x + 8, y); - - if (MenuFocus && (i == MenuBarSelect)) { - DrawUpBox(MainWin, x, 2, x + wide + 16, FontHigh + 5); - } else - DrawNoBox(MainWin, x, 2, x + wide + 16, FontHigh + 5); - x += wide + 24; - } - MenuBarCount = i; - XFlush(dpy); -} - - -/*=======================*/ -/* Pop-up Menu Display */ -/*=======================*/ -static void DisplayPopUpText(MenuItem * ptr, int x, int y) -{ - register unsigned long col; - register int pos, wide; - register int under; - int slen; - - col = (ptr->flags & mbEnable) ? Lut[0] : Lut[1]; - XSetForeground(dpy, gcon, col); - - if (ptr->enable && (*(ptr->enable) == ptr->value)) { - if (MenuFontSet) { - XDrawLine(dpy, PopUpWin, gcon, x - 9, y + XFdescent - FontHigh / 2, - x - 7, y + XFdescent - 2); - XDrawLine(dpy, PopUpWin, gcon, x - 7, y + XFdescent - 2, - x - 3, y + XFdescent - FontHigh + 2); - } else { - XDrawLine(dpy, PopUpWin, gcon, x - 9, - y + MenuFont->descent - FontHigh / 2, x - 7, - y + MenuFont->descent - 2); - XDrawLine(dpy, PopUpWin, gcon, x - 7, y + MenuFont->descent - 2, - x - 3, y + MenuFont->descent - FontHigh + 2); - } - } - if (ptr->len) { - slen = *(ptr->len); - } else { - slen = strlen(*(ptr->text)); - } - if (MenuFontSet) { - XmbDrawString(dpy, PopUpWin, MenuFontSet, gcon, - x, y, *(ptr->text), slen); - if ((ptr->flags & mbAccel) && isascii(*(*(ptr->text) + *(ptr->pos)))) { - under = y + XFdescent; - pos = x; - if (*(ptr->pos) > 0) - pos += - XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->pos)); - wide = - -XmbTextEscapement(MenuFontSet, *(ptr->text) + *(ptr->pos) + 1, - slen - *(ptr->pos) - 1) - + XmbTextEscapement(MenuFontSet, *(ptr->text) + *(ptr->pos), - slen - *(ptr->pos)); - - if (wide > 3) - wide--; - if (wide > 6) - wide--; - - XDrawLine(dpy, PopUpWin, gcon, pos, under, pos + wide, under); - } - } else { - XDrawString(dpy, PopUpWin, gcon, x, y, *(ptr->text), slen); - if ((ptr->flags & mbAccel) && isascii(*(*(ptr->text) + *(ptr->pos)))) { - under = y + MenuFont->descent; - pos = x; - if (*(ptr->pos) > 0) - pos += XTextWidth(MenuFont, *(ptr->text), *(ptr->pos)); - wide = - -XTextWidth(MenuFont, *(ptr->text) + *(ptr->pos) + 1, - slen - *(ptr->pos) - 1) - + XTextWidth(MenuFont, *(ptr->text) + *(ptr->pos), - slen - *(ptr->pos)); - - if (wide > 3) - wide--; - if (wide > 6) - wide--; - - XDrawLine(dpy, PopUpWin, gcon, pos, under, pos + wide, under); - } - } -} - - -static void DrawPopUpMenu(void) -{ - register MenuItem *ptr; - register int count; - register int x, y; - register int i; - - DrawUpBox(PopUpWin, 0, 0, PopUpWide, PopUpHigh); - - if (MenuBarSelect < 0) - MenuBarSelect = 0; - if (MenuBarSelect >= MenuBarMax) - MenuBarSelect = MenuBarMax - 1; - - ptr = MenuBar[MenuBarSelect].menu; - count = MenuBar[MenuBarSelect].count; - if (MenuBar[MenuBarSelect].increment && - *(MenuBar[MenuBarSelect].increment)) { - count += 1 + *(MenuBar[MenuBarSelect].increment); - } - - y = 2; - x = 2; - for (i = 0; i < count; i++) { - if (!(ptr->flags & mbSepBar)) { - DisplayPopUpText(ptr, x + 12, y + XFascent + 2); - if (ItemFlag && (i == MenuItemSelect)) { - DrawUpBox(PopUpWin, 2, y, PopUpWide - 2, y + FontHigh + 3); - } else - DrawNoBox(PopUpWin, 2, y, PopUpWide - 2, y + FontHigh + 3); - y += FontHigh + 4; - } else { - XSetForeground(dpy, gcon, (unsigned long) Lut[1]); - XDrawLine(dpy, PopUpWin, gcon, 2, y, PopUpWide - 2, y); - XSetForeground(dpy, gcon, (unsigned long) Lut[3]); - XDrawLine(dpy, PopUpWin, gcon, 2, y + 1, PopUpWide - 2, y + 1); - y += 2; - } - ptr++; - } - /* XSync(dpy,False); */ - XFlush(dpy); -} - - -static void DisplayPopUpMenu(int i, int x) -{ - register int wide, count; - register MenuItem *ptr; - static int xpos, ypos; - static Window win; - XRectangle bound; - XRectangle dummy; - - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - UnDisplayAboutDLG(); - } - MenuBarSelect = i; - DrawMenuBar(); - - ptr = MenuBar[i].menu; - count = MenuBar[i].count; - if (MenuBar[i].increment && *(MenuBar[i].increment)) { - count += 1 + *(MenuBar[i].increment); - } - - PopUpHigh = 4; - PopUpWide = 8; - for (i = 0; i < count; i++) { - if (!(ptr->flags & mbSepBar)) { - if (MenuFontSet) { - wide = - XmbTextExtents(MenuFontSet, *(ptr->text), *(ptr->len), - &dummy, &bound); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - if (wide + 28 > PopUpWide) - PopUpWide = wide + 28; - PopUpHigh += FontHigh + 4; - } else - PopUpHigh += 2; - ptr++; - } - /* Determine pop-up menu position! */ - XTranslateCoordinates(dpy, MainWin, RootWin, x, FontHigh + 6, - &xpos, &ypos, &win); - - if (ypos + PopUpHigh > MaxHeight) - ypos -= (PopUpHigh + FontHigh + 6); - if (xpos + PopUpWide > MaxWidth) - xpos = MaxWidth - PopUpWide; - if (xpos < 0) - xpos = 0; - - XUnmapWindow(dpy, PopUpWin); - XMoveResizeWindow(dpy, PopUpWin, xpos, ypos, PopUpWide + 1, PopUpHigh + 1); - XRaiseWindow(dpy, PopUpWin); - XMapWindow(dpy, PopUpWin); - PopUpFlag = True; - DrawPopUpMenu(); -} - - -static void DisplayAboutDLGText(DLGItem * ptr, int x, int y, int center) -{ - register unsigned long col; - register int wide; - int slen; - - col = Lut[0]; - XSetForeground(dpy, gcon, col); - - slen = strlen(*(ptr->text)); - - if (center) { - - if (MenuFontSet) { - wide = XmbTextEscapement(MenuFontSet, *(ptr->text), slen); - XmbDrawString(dpy, PopUpWin, MenuFontSet, gcon, - x + (ptr->x + (ptr->width) / 2) * DLGScale - - wide / 2, y + (ptr->y) * DLGScale, *(ptr->text), - slen); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), slen); - XDrawString(dpy, PopUpWin, gcon, - x + (ptr->x + (ptr->width) / 2) * DLGScale - wide / 2, - y + (ptr->y) * DLGScale, *(ptr->text), slen); - } - } else { - if (MenuFontSet) { - XmbDrawString(dpy, PopUpWin, MenuFontSet, gcon, - x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale, *(ptr->text), slen); - } else { - XDrawString(dpy, PopUpWin, gcon, - x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale, *(ptr->text), slen); - } - } -} - - -void DrawAboutDLG(void) -{ - register DLGItem *ptr; - register int count; - register int x, y; - register int i; - - DrawUpBox(PopUpWin, 0, 0, PopUpWide, PopUpHigh); - - ptr = AboutDLG; - count = AboutDLGCount; - - y = 2 + FontHigh; - x = 2; - for (i = 0; i < count; i++) { - switch (ptr->DLGtype) { - case DLGICON:{ - int box1[4], box2[4], box3[4]; - - DrawUpBox(PopUpWin, - x + (ptr->x) * DLGScale - 4, - y + (ptr->y) * DLGScale - 4 - - (ptr->height) * DLGScale, - x + (ptr->x) * DLGScale + 4 + - (ptr->width) * DLGScale, - y + (ptr->y) * DLGScale + 4); - - box1[0] = x + (ptr->x) * DLGScale; - box1[1] = box2[1] = - y + (ptr->y) * DLGScale - - (ptr->height) * 9 * DLGScale / 200; - box1[2] = box2[2] = box3[2] = (ptr->width / 2 - 1) * DLGScale; - box1[3] = box2[3] = box3[3] = - (ptr->height / 2 - 1) * DLGScale - - (ptr->height) * 9 * DLGScale / 200; - - box2[0] = - x + (ptr->x) * DLGScale + (ptr->width) * DLGScale - - box2[2]; - - box3[0] = x + (box1[0] + box2[0] - 1) / 2; - box3[1] = - box1[1] - 178 * (box2[0] - box1[0] + 1) / 200 - - (ptr->height) * 9 * DLGScale / 200; - - DrawUpCircle(PopUpWin, - box2[0], - box2[1] - box2[3], box2[0] + box2[2], box2[1]); - - DrawUpLine(PopUpWin, - box2[0] + box2[2] / 2 + (box3[0] - box2[0]) / 4, - box2[1] - box2[2] / 2 + (box3[1] - box2[1]) / 4, - box2[0] + box2[2] / 2 + 3 * (box3[0] - box2[0]) / 4, - box2[1] - box2[3] / 2 + 3 * (box3[1] - box2[1]) / 4, - 6); - - DrawUpCircle(PopUpWin, box3[0], box3[1] - box3[3], - box3[0] + box3[2], box3[1]); - - DrawUpLine(PopUpWin, - box3[0] + box3[2] / 2 + (box1[0] - box3[0]) / 4, - box3[1] - box3[2] / 2 + (box1[1] - box3[1]) / 4, - box3[0] + box3[2] / 2 + 3 * (box1[0] - box3[0]) / 4, - box3[1] - box3[3] / 2 + 3 * (box1[1] - box3[1]) / 4, - 6); - - DrawUpCircle(PopUpWin, box1[0], box1[1] - box1[3], - box1[0] + box1[2], box1[1]); - - DrawUpLine(PopUpWin, - box1[0] + box1[2] / 2 + (box2[0] - box1[0]) / 4, - box1[1] - box1[2] / 2 + (box2[1] - box1[1]) / 4, - box1[0] + box1[2] / 2 + 3 * (box2[0] - box1[0]) / 4, - box1[1] - box1[3] / 2 + 3 * (box2[1] - box1[1]) / 4, - 6); - - DrawUpPieSlice(PopUpWin, box2[0], box2[1] - box2[3], - box2[0] + box2[2], box2[1]); - break; - } - case DLGCTEXT: -#ifdef USE_UNAME - if (ptr->Identifier == IDD_HARDWARE && !uname(&AboutDLGUNAME)) { - int klen; - - klen = 0; - strncpy(unamebuffer, AboutDLGUNAME.sysname, 81); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - if (79 - klen > strlen(AboutDLGUNAME.nodename)) { - unamebuffer[klen] = ' '; - strncpy(unamebuffer + klen + 1, AboutDLGUNAME.nodename, - 81 - klen); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - } - /* if (79-klen > strlen(AboutDLGUNAME.release)) { - unamebuffer[klen] = ' '; - strncpy(unamebuffer+klen+1,AboutDLGUNAME.release,81-klen); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - } */ - if (79 - klen > strlen(AboutDLGUNAME.version)) { - unamebuffer[klen] = ' '; - strncpy(unamebuffer + klen + 1, AboutDLGUNAME.version, - 81 - klen); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - } - if (79 - klen > strlen(AboutDLGUNAME.machine)) { - unamebuffer[klen] = ' '; - strncpy(unamebuffer + klen + 1, AboutDLGUNAME.machine, - 81 - klen); - unamebuffer[80] = '\0'; - klen = strlen(unamebuffer); - } - } -#endif - DisplayAboutDLGText(ptr, x, y, True); - /* WriteString("\n");WriteString(*(ptr->text) ); */ - break; - case DLGPUSHBUTTON: - DisplayAboutDLGText(ptr, x, - y - ((ptr->height) * DLGScale + 4 - - FontHigh) / 2, True); - if (ptr->status) { - DrawDnBox(PopUpWin, x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale - ((ptr->height) * DLGScale), - x + (ptr->x) * DLGScale + (ptr->width) * DLGScale, - y + (ptr->y) * DLGScale); - break; - } else { - DrawUpBox(PopUpWin, x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale - ((ptr->height) * DLGScale), - x + (ptr->x) * DLGScale + (ptr->width) * DLGScale, - y + (ptr->y) * DLGScale); - break; - } - case DLGCHECKBOX: - DisplayAboutDLGText(ptr, x + (ptr->height) * DLGScale + 2, y, - False); - if (ptr->status) { - DrawDnBox(PopUpWin, x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale - (ptr->height) * DLGScale, - x + (ptr->x) * DLGScale + (ptr->height) * DLGScale, - y + (ptr->y) * DLGScale); - break; - } else { - DrawUpBox(PopUpWin, x + (ptr->x) * DLGScale, - y + (ptr->y) * DLGScale - (ptr->height) * DLGScale, - x + (ptr->x) * DLGScale + (ptr->height) * DLGScale, - y + (ptr->y) * DLGScale); - break; - } - } - ptr++; - - } - /* WriteString("\n\n"); */ - XFlush(dpy); -} - - -void DisplayAboutDLG(void) -{ - - static int xpos, ypos; - static Window win; - - MenuBarSelect = AboutDLGMItem; - DrawMenuBar(); - - if (AboutDLG[AboutDLGNOSHOWindex].DLGtype == DLGCHECKBOX - && AboutDLG[AboutDLGNOSHOWindex].Identifier == IDD_NOSHOW) { - if (getraid(filaid, 1025, fillang, 81) - && DetermineApplicationIdentifier(macaid, 1025) - && !strncasecmp(filaid, macaid, 1024)) { - AboutDLG[AboutDLGNOSHOWindex].status = 1; - } else { - AboutDLG[AboutDLGNOSHOWindex].status = 0; - } - } - - ItemFlag = False; - - PopUpHigh = AboutDLGHeight * DLGScale + 4; - PopUpWide = AboutDLGWidth * DLGScale + 4; - /* Determine pop-up menu position! */ - XTranslateCoordinates(dpy, MainWin, RootWin, AboutDLGXpos, FontHigh + 6, - &xpos, &ypos, &win); - - if (ypos + PopUpHigh > MaxHeight) - ypos -= (PopUpHigh + FontHigh + 6); - if (xpos + PopUpWide > MaxWidth) - xpos = MaxWidth - PopUpWide; - if (xpos < 0) - xpos = 0; - - XUnmapWindow(dpy, PopUpWin); - XMoveResizeWindow(dpy, PopUpWin, xpos, ypos, PopUpWide + 1, PopUpHigh + 1); - XRaiseWindow(dpy, PopUpWin); - XMapWindow(dpy, PopUpWin); - PopUpFlag = True; - DrawAboutDLG(); - ItemFocus = True; -} - - -void UnDisplayAboutDLG(void) -{ - - MenuBarSelect = 0; - DrawMenuBar(); - - ItemFlag = False; - - if (AboutDLG[AboutDLGNOSHOWindex].DLGtype == DLGCHECKBOX - && AboutDLG[AboutDLGNOSHOWindex].Identifier == IDD_NOSHOW) { - if (AboutDLG[AboutDLGNOSHOWindex].status && - DetermineApplicationIdentifier(macaid, 1025)) { - setraid(macaid, lang2str(Language)); - } else { - setraid("", lang2str(Language)); - } - } else { - FatalGraphicsError("Improperly structured AboutDLG in graphics.h"); - } - - XUnmapWindow(dpy, PopUpWin); - PopUpFlag = False; -} - - -/*==============================*/ -/* Pop-Up Menu Event Handling */ -/*==============================*/ - -static void HandleItemClick(int xpos, int ypos) -{ - register MenuItem *ptr; - register DLGItem *qtr; - register int count, i; - register int xo, yo; - - /* Ignore by not setting ItemFocus! */ - if ((xpos < 0) || (xpos > PopUpWide)) - return; - if ((ypos < 0) || (ypos > PopUpHigh)) - return; - ItemFocus = True; - - if (MenuBarSelect == AboutDLGMItem) { - MenuItemSelect = -1; - qtr = AboutDLG; - count = AboutDLGCount; - yo = 2 + FontHigh; - xo = 2; - for (i = 0; i < count; i++) { - if (qtr->DLGtype == DLGPUSHBUTTON) { - if (xpos >= xo + (qtr->x) * DLGScale - && xpos <= - xo + (qtr->x) * DLGScale + (qtr->width) * DLGScale - && ypos >= - yo + (qtr->y) * DLGScale - (qtr->height) * DLGScale - && ypos <= yo + (qtr->y) * DLGScale) { - MenuItemSelect = i; - ItemFlag = True; - return; - } - } else if (qtr->DLGtype == DLGCHECKBOX) { - if (xpos >= xo + (qtr->x) * DLGScale - && xpos <= - xo + (qtr->x) * DLGScale + (qtr->height) * DLGScale - && ypos >= - yo + (qtr->y) * DLGScale - (qtr->height) * DLGScale - && ypos <= yo + (qtr->y) * DLGScale) { - MenuItemSelect = i; - ItemFlag = True; - return; - } - } - qtr++; - } - ItemFlag = False; - return; - - } else { - - ptr = MenuBar[MenuBarSelect].menu; - count = MenuBar[MenuBarSelect].count; - if (MenuBar[MenuBarSelect].increment && - *(MenuBar[MenuBarSelect].increment)) { - count += 1 + *(MenuBar[MenuBarSelect].increment); - } - - yo = 2; - for (i = 0; i < count; i++) { - if (!(ptr->flags & mbSepBar)) { - if ((ypos >= yo) && (ypos <= yo + FontHigh + 3)) { - if (ptr->flags & mbEnable) { - if (!ItemFlag || (MenuItemSelect != i)) { /* Avoid Flickering */ - MenuItemSelect = i; - ItemFlag = True; - DrawPopUpMenu(); - } - return; - } else - break; - } - yo += FontHigh + 4; - } else - yo += 2; - ptr++; - } - } - - if (ItemFlag) { - ItemFlag = False; - if (MenuBarSelect == AboutDLGMItem) { - DrawAboutDLG(); - } else { - DrawPopUpMenu(); - } - } -} - - -static void HandleItemMove(int xpos, int ypos) -{ - register MenuItem *ptr; - register DLGItem *qtr; - register int count, i; - - static int xo, yo; - - if (MenuBarSelect == AboutDLGMItem) { - if ((xpos >= 0) && (xpos <= PopUpWide) - && (ypos >= 0) && (ypos <= PopUpHigh)) { - qtr = AboutDLG; - count = AboutDLGCount; - yo = 2 + FontHigh; - xo = 2; - for (i = 0; i < count; i++) { - if (qtr->DLGtype == DLGPUSHBUTTON) { - if (xpos >= xo + (qtr->x) * DLGScale - && xpos <= - xo + (qtr->x) * DLGScale + (qtr->width) * DLGScale - && ypos >= - yo + (qtr->y) * DLGScale - (qtr->height) * DLGScale - && ypos <= yo + (qtr->y) * DLGScale) { - MenuItemSelect = i; - ItemFlag = True; - return; - } - } else if (qtr->DLGtype == DLGCHECKBOX) { - if (xpos >= xo + (qtr->x) * DLGScale - && xpos <= - xo + (qtr->x) * DLGScale + (qtr->height) * DLGScale - && ypos >= - yo + (qtr->y) * DLGScale - (qtr->height) * DLGScale - && ypos <= yo + (qtr->y) * DLGScale) { - MenuItemSelect = i; - ItemFlag = True; - return; - } - } - qtr++; - } - } - - } else { - - if ((xpos >= 0) && (xpos <= PopUpWide)) { - ptr = MenuBar[MenuBarSelect].menu; - count = MenuBar[MenuBarSelect].count; - if (MenuBar[MenuBarSelect].increment && - *(MenuBar[MenuBarSelect].increment)) { - count += 1 + *(MenuBar[MenuBarSelect].increment); - } - - yo = 2; - for (i = 0; i < count; i++) { - if (!(ptr->flags & mbSepBar)) { - if ((ypos >= yo) && (ypos <= yo + FontHigh + 3)) { - if (!ItemFlag || (MenuItemSelect != i)) { /* Avoid Flicker! */ - MenuItemSelect = i; - ItemFlag = True; - DrawPopUpMenu(); - } - ItemFocus = True; - return; - } - yo += FontHigh + 4; - } else - yo += 2; - ptr++; - } - } - - } - - if (ItemFlag) { /* Avoid Flicker! */ - ItemFlag = False; - if (MenuBarSelect == AboutDLGMItem) { - DrawAboutDLG(); - } else { - DrawPopUpMenu(); - } - } -} - - -static int HandleItemKey(int key) -{ - register MenuItem *ptr; - register int count; - register int item; - register int ch; - register int i; - - key = ToUpper(key); - item = MenuItemSelect; - ptr = &MenuBar[MenuBarSelect].menu[item]; - count = MenuBar[MenuBarSelect].count; - if (MenuBar[MenuBarSelect].increment && - *(MenuBar[MenuBarSelect].increment)) { - count += 1 + *(MenuBar[MenuBarSelect].increment); - } - for (i = 0; i < count; i++) { - if ((ptr->flags & (mbEnable | mbAccel)) - && isascii(*(*(ptr->text) + *(ptr->pos))) - && !(ptr->flags & mbSepBar)) { - ch = (*(ptr->text))[*(ptr->pos)]; - if (ToUpper(ch) == key) - return ((MenuBarSelect << 8) + item + 1); - } - - /* Advance to next item! */ - if (item == count - 1) { - ptr = MenuBar[MenuBarSelect].menu; - item = 0; - } else { - item++; - ptr++; - } - } - return 0; -} - - -static void SelectFirstItem(int menu) -{ - register MenuItem *ptr; - register int count; - register int i; - - count = MenuBar[menu].count; - if (MenuBar[menu].increment && *(MenuBar[menu].increment)) { - count += 1 + *(MenuBar[menu].increment); - } - ptr = MenuBar[menu].menu; - - ItemFlag = False; - for (i = 0; i < count; i++) - if ((ptr->flags & mbEnable) && !(ptr->flags & mbSepBar)) { - MenuItemSelect = i; - ItemFlag = True; - break; - } else - ptr++; -} - - -static void SelectPrevItem(void) -{ - register BarItem *ptr; - register int flags; - register int item; - register int i; - - if (!ItemFlag || MenuBarSelect == AboutDLGMItem) - return; - - item = MenuItemSelect; - ptr = MenuBar + MenuBarSelect; - for (i = 0; i < ptr->count; i++) { - if (!item) { - item = ptr->count - 1; - } else - item--; - - flags = ptr->menu[item].flags; - if ((flags & mbEnable) && !(flags & mbSepBar)) - break; - } - - if (item != MenuItemSelect) { - MenuItemSelect = item; - DrawPopUpMenu(); - } -} - - -static void SelectNextItem(void) -{ - register BarItem *ptr; - register int flags; - register int item; - register int i; - - if (!ItemFlag || MenuBarSelect == AboutDLGMItem) - return; - - item = MenuItemSelect; - ptr = MenuBar + MenuBarSelect; - for (i = 0; i < ptr->count; i++) { - if (item == ptr->count - 1) { - item = 0; - } else - item++; - - flags = ptr->menu[item].flags; - if ((flags & mbEnable) && !(flags & mbSepBar)) - break; - } - - if (item != MenuItemSelect) { - MenuItemSelect = item; - DrawPopUpMenu(); - } -} - - - -/*===========================*/ -/* Menu Bar Event Handling */ -/*===========================*/ - -static void SelectMenu(int menu) -{ - register BarItem *ptr; - register int wide; - register int i, x; - - if (!PopUpFlag) { - MenuBarSelect = menu; - DrawMenuBar(); - return; - } - - if (menu != MenuBarMax - 1) { - x = 6; - for (i = 0; i < menu; i++) { - ptr = MenuBar + i; - if (MenuFontSet) { - wide = - XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->len)); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - x += wide + 24; - } - } else { - ptr = MenuBar + menu; - if (MenuFontSet) { - wide = XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->len)); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - x = MainWide - (wide + 24); - } - - SelectFirstItem(menu); - DisplayPopUpMenu(menu, x); - ItemFocus = False; -} - - -static int HandleMenuClick(int pos) -{ - register BarItem *ptr; - register int wide; - register int x, i; - - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) - UnDisplayAboutDLG(); - x = 6; - for (i = 0; i < MenuBarCount; i++) { - ptr = MenuBar + i; - if (MenuFontSet) { - wide = XmbTextEscapement(MenuFontSet, *(ptr->text), *(ptr->len)); - } else { - wide = XTextWidth(MenuFont, *(ptr->text), *(ptr->len)); - } - if (i == MenuBarMax - 1) - x = MainWide - (wide + 24); - - if ((pos >= x) && (pos <= x + wide + 16)) { - if (!PopUpFlag || (MenuBarSelect != i)) { - ItemFlag = False; - DisplayPopUpMenu(i, x); - } else if (ItemFlag) { - ItemFlag = False; - DrawPopUpMenu(); - } - ItemFocus = True; - return True; - } else - x += wide + 24; - } - return False; -} - - -static int HandleMenuKey(char key) -{ - register int i; - - key = ToUpper(key); - for (i = 0; i < MenuBarCount; i++) - if (ToUpper((*(MenuBar[i].text))[*(MenuBar[i].pos)]) == key) { - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - UnDisplayAboutDLG(); - } - if (!PopUpFlag || (MenuBarSelect != i)) { - PopUpFlag = True; - SelectMenu(i); - } - return True; - } - return False; -} - - -void EnableMenus(int flag) -{ - DisableMenu = !flag; - if (Interactive) { - DrawMenuBar(); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - } - -} - - -static void ReSizeWindow(int wide, int high) -{ - register Real xpos; - register Real ypos; - register int dx; - - xpos = (XRange > 48) ? (Real) (ScrlX - 16) / (XRange - 48) : 0.0; - ypos = (YRange > 48) ? (Real) (ScrlY - 16) / (YRange - 48) : 0.0; - - YRange = high - (MenuHigh + 53); - XRange = wide - 53; - ZRange = 20000; - - if ((dx = XRange % 4)) - XRange += 4 - dx; - - MainHigh = YRange + (MenuHigh + 53); - HRange = YRange >> 1; - MainWide = XRange + 53; - WRange = XRange >> 1; - Range = MinFun(XRange, YRange); - - XResizeWindow(dpy, CanvWin, XRange, YRange); - XResizeWindow(dpy, MenuWin, XRange + 49, FontHigh + 5); - XMoveResizeWindow(dpy, XScrlWin, 14, YRange + MenuHigh + 24, XRange, 16); - XMoveResizeWindow(dpy, YScrlWin, XRange + 24, MenuHigh + 14, 16, YRange); - - NewScrlX = ScrlX = (xpos * (XRange - 48)) + 16; - NewScrlY = ScrlY = (ypos * (YRange - 48)) + 16; - - XClearWindow(dpy, MainWin); - XClearWindow(dpy, CanvWin); - - DrawXScroll(); - DrawYScroll(); - DrawMainWin(); - DrawMenuBar(); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - int xpos, ypos; - Window win; - - XTranslateCoordinates(dpy, MainWin, RootWin, AboutDLGXpos, - FontHigh + 6, &xpos, &ypos, &win); - - if (ypos + PopUpHigh > MaxHeight) - ypos -= (PopUpHigh + FontHigh + 6); - if (xpos + PopUpWide > MaxWidth) - xpos = MaxWidth - PopUpWide; - if (xpos < 0) - xpos = 0; - XMoveResizeWindow(dpy, PopUpWin, xpos, ypos, PopUpWide + 1, - PopUpHigh + 1); - XClearWindow(dpy, PopUpWin); - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - - ReDrawFlag |= RFReSize; - XSync(dpy, True); -} - -void ReDrawWindow(void) -{ - if (Interactive) - ReSizeWindow(MainWide, MainHigh); -} - - -int FatalXError(Display * ptr) -{ - /* Avoid Compiler Warnings! */ - UnusedArgument(ptr); - - dpy = (Display *) NULL; - RasMolFatalExit("*** Fatal X11 I/O Error! ***"); - return 0; -} - - -int OpenDisplay(void) -{ -#ifdef THIRTYTWOBIT - static ByteTest test; -#endif - register unsigned long mask; - register int i, num; - register char *ptr; - - static XVisualInfo visinfo; - static XClassHint xclass; - static XSizeHints size; - static int temp; - static char VersionStr[50]; - int xpos, ypos, rxpos, rypos; - Window win; - - sprintf(VersionStr, "RasMol Version %s", VERSION); - - image = (XImage *) NULL; - - MouseCaptureStatus = False; - MouseUpdateStatus = False; - UseHourGlass = True; - DisableMenu = False; - Monochrome = False; - XHeldButton = -1; - - for (i = 0; i < 11; i++) - DialValue[i] = 0.0; - - CQRMSet(DialQRot, 0.0, 0.0, 0.0, 0.0); - - RLut[0] = 0; - GLut[0] = 0; - BLut[0] = 0; - ULut[0] = True; - RLut[1] = 100; - GLut[1] = 100; - BLut[1] = 100; - ULut[1] = True; - RLut[2] = 150; - GLut[2] = 150; - BLut[2] = 150; - ULut[2] = True; - RLut[3] = 200; - GLut[3] = 200; - BLut[3] = 200; - ULut[3] = True; - RLut[4] = 255; - GLut[4] = 255; - BLut[4] = 255; - ULut[4] = True; - - XRange = DefaultWide; - YRange = DefaultHigh; - - if (InitWidth >= 48) - XRange = InitWidth; - if (InitHeight >= 48) - YRange = InitHeight; - - WRange = XRange >> 1; - HRange = YRange >> 1; - Range = MinFun(XRange, YRange); - - xpos = InitXPos - 14; - ypos = InitYPos - MenuHigh - 14; - if (xpos < 0) - xpos = 0; - if (ypos < 0) - ypos = 0; - - if (!Interactive) - return (False); - if ((dpy = XOpenDisplay(NULL)) == NULL) - return 0; - - num = DefaultScreen(dpy); - RootWin = RootWindow(dpy, num); - XSetIOErrorHandler(FatalXError); - -#ifdef EIGHTBIT - if (!(XMatchVisualInfo(dpy, num, 8, PseudoColor, &visinfo) || - XMatchVisualInfo(dpy, num, 8, GrayScale, &visinfo))) { - /* Attempt to use Monochrome Mode! */ - if (!(XMatchVisualInfo(dpy, num, 1, StaticColor, &visinfo) || - XMatchVisualInfo(dpy, num, 1, StaticGray, &visinfo))) { - XCloseDisplay(dpy); - return 0; - } - Monochrome = True; - PixDepth = 1; - } else - PixDepth = 8; -#else -#ifdef THIRTYTWOBIT - if (XMatchVisualInfo(dpy, num, 32, TrueColor, &visinfo) || - XMatchVisualInfo(dpy, num, 32, DirectColor, &visinfo)) { - PixDepth = 32; - } else if (XMatchVisualInfo(dpy, num, 24, TrueColor, &visinfo) || - XMatchVisualInfo(dpy, num, 24, DirectColor, &visinfo)) { - PixDepth = 24; - } else { /* No suitable display! */ - XCloseDisplay(dpy); - return (0); - } -#else /* SIXTEENBIT */ - if (XMatchVisualInfo(dpy, num, 16, TrueColor, &visinfo) || - XMatchVisualInfo(dpy, num, 16, DirectColor, &visinfo)) { - PixDepth = 16; - } else if (XMatchVisualInfo(dpy, num, 15, TrueColor, &visinfo) || - XMatchVisualInfo(dpy, num, 15, DirectColor, &visinfo)) { - PixDepth = 15; - } else { /* No suitable display! */ - XCloseDisplay(dpy); - return 0; - } -#endif -#endif - - if (!Monochrome) { - vis = visinfo.visual; - if (vis != DefaultVisual(dpy, num)) { - cmap = XCreateColormap(dpy, RootWin, vis, AllocNone); - } else - cmap = DefaultColormap(dpy, num); - } else { /* Black & White */ - /* PixDepth = DefaultDepth(dpy,num); */ - cmap = DefaultColormap(dpy, num); - vis = visinfo.visual; - - BlackCol = (Pixel) (BlackPixel(dpy, num) & 1); - WhiteCol = (Pixel) (WhitePixel(dpy, num) & 1); - } - - if (RasOpenFonts()) { - if (Language != Russian) { - SwitchLang(English); - if (RasOpenFonts()) - FatalGraphicsError("Unable to find suitable font"); - } else { - FatalGraphicsError("Unable to find suitable font"); - } - } - - OpenColourMap(); - - MaxHeight = DisplayHeight(dpy, num); - MinHeight = MenuHigh + 101; - MaxWidth = DisplayWidth(dpy, num); - MinWidth = 101; - - MainHigh = YRange + MenuHigh + 53; - MainWide = XRange + 53; - - mask = CWEventMask; - attr.event_mask = ExposureMask | KeyPressMask | StructureNotifyMask - | EnterWindowMask | LeaveWindowMask | PropertyChangeMask; - attr.background_pixel = Lut[2]; - attr.border_pixel = Lut[2]; - attr.colormap = cmap; - attr.cursor = arrow; - mask |= CWBackPixel; - mask |= CWBorderPixel; - mask |= CWColormap; - mask |= CWCursor; - - MainWin = XCreateWindow(dpy, RootWin, 0, 0, MainWide, MainHigh, 2, - PixDepth, InputOutput, vis, mask, &attr); - - gcon = XCreateGC(dpy, MainWin, 0L, NULL); - /* DefaultGC(dpy,num) */ - - XSetGraphicsExposures(dpy, gcon, False); - icon = XCreateBitmapFromData(dpy, MainWin, (char *) icon_bits, - icon_width, icon_height); - - size.flags = PMinSize | PMaxSize; - size.min_width = MinWidth; - size.max_width = MaxWidth; - size.min_height = MinHeight; - size.max_height = MaxHeight; - XSetStandardProperties(dpy, MainWin, VersionStr, - "RasMol", icon, NULL, 0, &size); - - xclass.res_name = "rasmol"; - xclass.res_class = "RasMol"; - XSetClassHint(dpy, MainWin, &xclass); - - hints.icon_pixmap = icon; - hints.flags = IconPixmapHint; - XSetWMHints(dpy, MainWin, &hints); - - OpenCanvas(XRange, YRange); - OpenScrollBars(); - OpenMenuBar(); - OpenCursors(); - OpenIPCComms(); - -#ifdef DIALBOX - OpenDialsBox(); -#endif - -#ifdef MITSHM - ptr = DisplayString(dpy); - if (!ptr || (*ptr == ':') || !strncmp(ptr, "localhost:", 10) || - !strncmp(ptr, "unix:", 5) || !strncmp(ptr, "local:", 6)) { - SharedMemOption = XQueryExtension(dpy, "MIT-SHM", &temp, &temp, &temp); - if (Monochrome && (PixDepth != 1)) - SharedMemOption = False; - } else - SharedMemOption = False; - SharedMemFlag = False; -#endif - -#ifdef THIRTYTWOBIT - /* Determine Byte Ordering */ - test.longword = (Long) 0x000000ff; - if (ImageByteOrder(dpy) == MSBFirst) { - SwapBytes = test.bytes[0]; - } else - SwapBytes = test.bytes[3]; -#endif - - XMapSubwindows(dpy, MainWin); - XMapWindow(dpy, MainWin); - - DrawXScroll(); - DrawYScroll(); - DrawMainWin(); - DrawMenuBar(); - - XClearWindow(dpy, CanvWin); - XSync(dpy, False); - - XTranslateCoordinates(dpy, MainWin, RootWin, xpos, ypos, - &rxpos, &rypos, &win); - XMoveResizeWindow(dpy, MainWin, rxpos, rypos, MainWide, MainHigh); - ReDrawWindow(); - - - num = 1 << ConnectionNumber(dpy); - return (num); -} - -#ifdef MITSHM -static int HandleShmError(Display * dpy, XErrorEvent * ptr) -{ - /* Avoid Compiler Warnings! */ - UnusedArgument(dpy); - UnusedArgument(ptr); - SharedMemOption = False; - return 0; -} -#endif - - -int CreateImage(void) -{ - register long size, temp; - register int format; - register Pixel *ptr; -#ifdef MITSHM - register int (*handler) (); -#endif - - if (!Interactive) { - if (FBuffer) - _ffree(FBuffer); - size = (long) XRange *YRange * sizeof(Pixel); - FBuffer = (Pixel *) _fmalloc(size + 32); - return ((FBuffer != (Pixel *) NULL) ? True : False); - } - - format = Monochrome ? XYPixmap : ZPixmap; - - if (image) { /* Monochrome Mode Frame Buffer! */ - if (FBuffer && (FBuffer != (Pixel *) image->data)) - _ffree(FBuffer); -#ifdef MITSHM - if (SharedMemFlag) { - XShmDetach(dpy, &xshminfo); - image->data = (char *) NULL; - shmdt(xshminfo.shmaddr); - } -#endif - XDestroyImage(image); - image = (XImage *) NULL; - } - - if (Monochrome) { /* Monochrome Mode Frame Buffer! */ - size = (long) XRange *YRange * sizeof(Pixel); - FBuffer = (Pixel *) _fmalloc(size + 32); - if (FBuffer == (Pixel *) NULL) - return False; - - /* Bit per Pixel ScanLines! */ - temp = ((XRange + 31) >> 5) << 2; - size = (long) temp *YRange + 32; - } else - size = (long) XRange *YRange * sizeof(Pixel) + 32; - -#ifdef MITSHM - if (SharedMemOption) { - SharedMemFlag = False; - image = XShmCreateImage(dpy, vis, PixDepth, format, - NULL, &xshminfo, XRange, YRange); - - if (image) { - temp = (Long) image->bytes_per_line * image->height; - if (temp > size) - size = temp; - xshminfo.shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777); - if (xshminfo.shmid != -1) { - xshminfo.shmaddr = (char *) shmat(xshminfo.shmid, 0, 0); - if (xshminfo.shmaddr != (char *) -1) { - image->data = xshminfo.shmaddr; - if (!Monochrome) - FBuffer = (Pixel *) image->data; - xshminfo.readOnly = True; - handler = XSetErrorHandler(HandleShmError); - SharedMemFlag = XShmAttach(dpy, &xshminfo); - XSync(dpy, False); - XSetErrorHandler(handler); - if (!SharedMemOption) - SharedMemFlag = False; - } - /* Always Destroy Shared Memory Ident */ - shmctl(xshminfo.shmid, IPC_RMID, 0); - } - - if (SharedMemFlag) { - if (Monochrome) { - if (BlackCol) { - memset((void *) image->data, 255, size); - } else - memset((void *) image->data, 255, size); - } - return True; - } else { - XDestroyImage(image); - image = (XImage *) NULL; - SharedMemOption = False; - } - } - } -#endif - - /* Allocate Frame Buffer! */ - ptr = (Pixel *) _fmalloc(size); - if (ptr == (Pixel *) NULL) - return False; - - if (!Monochrome) - FBuffer = ptr; - image = XCreateImage(dpy, vis, PixDepth, format, 0, (char *) ptr, - XRange, YRange, sizeof(Pixel) << 3, 0); - return ((image == (XImage *) NULL) ? False : True); -} - - -static void DitherImage(void) -{ - register Card bits; - register Card *dst; - register Pixel *src; - register int xmax, ymax; - register int count, x, y; - register int error; - - register Card bmask, wmask; - register Card bhigh, whigh; - register int wlen; - register int blen; - register int len; - - /* Avoid compiler warnings */ - bits = bmask = wmask = (Card) 0; - - src = (Pixel *) FBuffer; - dst = (Card *) image->data; - - wlen = XRange >> 5; - blen = XRange & 31; - if (blen) { - wmask = WhiteCol << (blen - 1); - bmask = BlackCol << (blen - 1); - len = wlen + 1; - } else - len = wlen; - - whigh = WhiteCol << 31; - bhigh = BlackCol << 31; - - /* Allow Compiler Optimisation */ - xmax = XRange; - ymax = YRange; - - error = 0; - for (y = 0; y < ymax; y++) { - for (x = 0; x < wlen; x++) { - for (count = 0; count < 32; count++) { - error += Intensity[*src++]; - bits <<= 1; - if (error >= 128) { - error -= 255; - bits |= WhiteCol; - } else - bits |= BlackCol; - } - *dst++ = bits; - } - - if (blen) { - for (count = 0; count < blen; count++) { - error += Intensity[*src++]; - bits <<= 1; - if (error >= 128) { - error -= 255; - bits |= WhiteCol; - } else - bits |= BlackCol; - } - *dst++ = bits; - - /* Asymmetric Loop Unrolling! */ - if (++y == ymax) - break; - src += xmax; - dst += wlen; - - bits = 0; - for (count = 0; count < blen; count++) { - error += Intensity[*(--src)]; - bits >>= 1; - if (error >= 128) { - error -= 255; - bits |= wmask; - } else - bits |= bmask; - } - *(--dst) = bits; - } else { /* Asymmetric Loop Unrolling! */ - if (++y == ymax) - break; - src += xmax; - dst += len; - } - - for (x = wlen - 1; x >= 0; x--) { - for (count = 0; count < 32; count++) { - error += Intensity[*(--src)]; - bits >>= 1; - if (error >= 128) { - error -= 255; - bits |= whigh; - } else - bits |= bhigh; - } - *(--dst) = bits; - } - src += xmax; - dst += len; - } -} - - -void TransferImage(void) -{ - if (Monochrome) - DitherImage(); - -#ifdef MITSHM - if (SharedMemFlag) { - XShmPutImage(dpy, CanvWin, gcon, image, 0, 0, 0, 0, XRange, YRange, - False); - XSync(dpy, False); - } else { - XPutImage(dpy, CanvWin, gcon, image, 0, 0, 0, 0, XRange, YRange); - XFlush(dpy); - } -#else - XPutImage(dpy, CanvWin, gcon, image, 0, 0, 0, 0, XRange, YRange); - XFlush(dpy); -#endif -} - - -void ClearImage(void) -{ - XClearWindow(dpy, CanvWin); - XFlush(dpy); -} - - -int PrintImage(void) -{ - return False; -} - - -int ClipboardImage(void) -{ - return False; -} - - -void SetCanvasTitle(char *ptr) -{ - if (Interactive) { - XStoreName(dpy, MainWin, ptr); - } -} - - -static int HandleIPCError(Display * dpy, XErrorEvent * ptr) -{ - /* Avoid Compiler Warnings! */ - UnusedArgument(dpy); - UnusedArgument(ptr); - return 0; -} - - -static void HandleIPCCommand(void) -{ - static unsigned long len, left; - static unsigned char *command; - static Window source; - static int serial; - static int format; - static Atom type; - char buffer[32]; - - register size_t rlen; - register int result; - register int (*handler) (); - register char *cmnd; - register char *ptr; - - command = NULL; - result = XGetWindowProperty(dpy, MainWin, CommAtom, 0, 1024, True, - XA_STRING, &type, &format, &len, &left, - &command); - if ((result != Success) || (type != XA_STRING) || (format != 8)) { - if (command) - XFree((char *) command); - return; - } - - result = 0; - ptr = (char *) command; - if (!*ptr) { /* Tcl/Tk4.0 and later */ - - ptr++; - while (ptr < (char *) command + len) { - if ((ptr[0] == 'c') && (ptr[1] == '\0')) { - ptr += 2; - cmnd = (char *) NULL; - source = serial = 0; - while ((ptr < (char *) command + len) && (*ptr == '-')) { - if ((ptr[1] == 'r') && (ptr[2] == ' ')) { - sscanf(ptr + 3, "%x %d\n", (int *) &source, &serial); - } else if ((ptr[1] == 's') && (ptr[2] == ' ')) - cmnd = ptr + 3; - while (*ptr) - ptr++; - ptr++; - } - - if (!cmnd) - continue; - result = ExecuteIPCCommand(cmnd); - if (!source || !serial) - continue; - - buffer[0] = '\0'; - buffer[1] = 'r'; - buffer[2] = '\0'; - buffer[3] = '-'; - buffer[4] = 'r'; - buffer[5] = ' '; - buffer[6] = result ? '1' : '0'; - buffer[7] = '\0'; - sprintf(buffer + 8, "-s %d", serial); - rlen = strlen(buffer + 8) + 9; - - /* Return Tcl/Tk v4.0 result! */ - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, source, CommAtom, XA_STRING, 8, - PropModeAppend, (unsigned char *) buffer, - rlen); - XSync(dpy, False); - XSetErrorHandler(handler); - } else { /* Unrecognised command! */ - while (*ptr) - ptr++; - ptr++; - } - } - - } else - while (*ptr) { /* Tcl/Tk3.0 and later */ - if (*ptr == 'C') { - sscanf(ptr + 1, "%x %x\n", (int *) &source, &serial); - while (*ptr && (*ptr != '|')) - ptr++; - if (*ptr == '|') { - result = ExecuteIPCCommand(ptr + 1); - } else - result = 0; - - sprintf(buffer, "R %x 0 %d", serial, result); - handler = XSetErrorHandler(HandleIPCError); - XChangeProperty(dpy, source, CommAtom, XA_STRING, 8, - PropModeAppend, (unsigned char *) buffer, - (int) strlen(buffer) + 1); - XSync(dpy, False); - XSetErrorHandler(handler); - } - - /* Next Command! */ - while (*ptr++); - } - XFree((char *) command); - - if ((result == IPC_Quit) || (result == IPC_Exit)) - RasMolExit(); -} - - -void SetMouseUpdateStatus(int bool) -{ - if (MouseUpdateStatus != bool) { /* Enable/Disable Pointer Motion Events! */ - attr.event_mask = ExposureMask | ButtonPressMask | ButtonMotionMask - | ButtonReleaseMask; - if (bool) - attr.event_mask |= PointerMotionMask; - XChangeWindowAttributes(dpy, CanvWin, CWEventMask, &attr); - } - MouseUpdateStatus = bool; -} - - -void SetMouseCaptureStatus(int bool) -{ - MouseCaptureStatus = bool; -} - - -static int GetStatus(int mask) -{ - register int status; - - status = 0; - if (mask & Button1Mask) - status |= MMLft; - if (mask & Button2Mask) - status |= MMMid; - if (mask & Button3Mask) - status |= MMRgt; - if (mask & ControlMask) - status |= MMCtl; - if (mask & ShiftMask) - status |= MMSft; - return status; -} - - -static int CropRange(int val, int min, int max) -{ - if (val < min) - return min; - if (val > max) - return max; - return val; -} - - -static void DoneEvents(void) -{ - register Real temp; - register int index; - - if (XHeldButton == YScrlDial) { - index = NewScrlY + XHeldStep; -#ifdef ORIG - if (YScrlDial < 3) { - if (index < 16) { - index += YRange - 48; - } else if (index > YRange - 32) - index -= YRange - 48; - NewScrlY = index; - } else - NewScrlY = CropRange(index, 16, YRange - 32); -#else - if (index < 16) { - index += YRange - 48; - } else if (index > YRange - 32) - index -= YRange - 48; - NewScrlY = index; -#endif - } - - if (NewScrlY != ScrlY) { - XClearArea(dpy, YScrlWin, 0, ScrlY, 16, 16, False); - XCopyArea(dpy, Scrl, YScrlWin, gcon, 0, 0, 16, 16, 0, NewScrlY); - - temp = ((Real) (NewScrlY - 16)) / (YRange - 48); - if (RotMode == RotAll) { - WorldDialValue[YScrlDial] = 2.0 * temp - 1.0; - } else { - DialValue[YScrlDial] = 2.0 * temp - 1.0; - } - ReDrawFlag |= (1 << YScrlDial); - ScrlY = NewScrlY; - } - - if (XHeldButton == XScrlDial) { - index = NewScrlX + XHeldStep; -#ifdef ORIG - if (XScrlDial < 3) { - if (index < 16) { - index += XRange - 48; - } else if (index > XRange - 32) - index -= XRange - 48; - NewScrlX = index; - } else - NewScrlX = CropRange(index, 16, XRange - 32); -#else - if (index < 16) { - index += XRange - 48; - } else if (index > XRange - 32) - index -= XRange - 48; - NewScrlX = index; -#endif - } - - if (NewScrlX != ScrlX) { - XClearArea(dpy, XScrlWin, ScrlX, 0, 16, 16, False); - XCopyArea(dpy, Scrl, XScrlWin, gcon, 0, 0, 16, 16, NewScrlX, 0); - - temp = ((Real) (NewScrlX - 16)) / (XRange - 48); - if ((RotMode == RotBond) && BondSelected) { - BondSelected->BRotValue = 2.0 * temp - 1.0; - ReDrawFlag |= RFRotBond; - } else { - if (RotMode == RotAll) { - WorldDialValue[XScrlDial] = 2.0 * temp - 1.0; - ReDrawFlag |= (1 << XScrlDial); - } else { - DialValue[XScrlDial] = 2.0 * temp - 1.0; - ReDrawFlag |= (1 << XScrlDial); - } - } - ScrlX = NewScrlX; - } - /* XSync(dpy,False); */ - XFlush(dpy); -} - - -static int ProcessEvent(XEvent * event) -{ - register int result; - register int index; - register int stat; - - result = 0; - - switch (event->type) { - case (ButtonPress): - { - XButtonPressedEvent *ptr; - - XHeldButton = -1; - ptr = (XButtonPressedEvent *) event; - - if (ptr->window == CanvWin) { - stat = GetStatus(ptr->state); - ProcessMouseDown(ptr->x, ptr->y, stat); - } else if (ptr->window == MenuWin) { - if (!DisableMenu) - if (HandleMenuClick(ptr->x)) - result = HandleMenuLoop(); - } else if (ptr->window == XScrlWin) { - ReDrawFlag |= RFRotateY; - if (ptr->x < 16) { - XHeldButton = XScrlDial; - XHeldStep = -XScrlSkip; - } else if (ptr->x >= XRange - 16) { - XHeldButton = XScrlDial; - XHeldStep = XScrlSkip; - } else { - index = ptr->x - 8; -#ifdef ORIG - if (XScrlDial < 3) { - if (index > XRange - 32) { - index -= XRange - 48; - } else if (index < 16) - index += XRange - 48; - NewScrlX = index; - } else - NewScrlX = CropRange(index, 16, XRange - 32); -#else - if (index > XRange - 32) { - index -= XRange - 48; - } else if (index < 16) - index += XRange - 48; - NewScrlX = index; -#endif - } - - } else if (ptr->window == YScrlWin) { - ReDrawFlag |= RFRotateX; - if (ptr->y < 16) { - XHeldButton = YScrlDial; - XHeldStep = -YScrlSkip; - } else if (ptr->y >= YRange - 16) { - XHeldButton = YScrlDial; - XHeldStep = YScrlSkip; - } else { - index = ptr->y - 8; -#ifdef ORIG - if (YScrlDial < 3) { - if (index > YRange - 32) { - index -= YRange - 48; - } else if (index < 16) - index += YRange - 48; - NewScrlY = index; - } else - NewScrlY = CropRange(index, 16, YRange - 32); -#else - if (index > YRange - 32) { - index -= YRange - 48; - } else if (index < 16) - index += YRange - 48; - NewScrlY = index; -#endif - } - - } - } - break; - - case (MotionNotify): - { - XMotionEvent *ptr; - - ptr = (XMotionEvent *) event; - if (ptr->window == PopUpWin && MenuBarSelect == AboutDLGMItem) { - HandleItemMove(ptr->x, ptr->y); - } else if (ptr->window == CanvWin) { - stat = GetStatus(ptr->state); - ProcessMouseMove(ptr->x, ptr->y, stat); - } else if (XHeldButton == -1) { - if (ptr->window == XScrlWin) { - index = ptr->x - 8; - NewScrlX = CropRange(index, 16, XRange - 32); - } else { /* if( ptr->window==YScrlWin ) */ - index = ptr->y - 8; - NewScrlY = CropRange(index, 16, YRange - 32); - } - } - } - break; - - case (CirculateNotify): - { - XCirculateEvent *ptr; - - ptr = (XCirculateEvent *) event; - if (ptr->window == MainWin && ptr->place == PlaceOnTop - && PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - } - break; - - case (VisibilityNotify): - { - XVisibilityEvent *ptr; - - ptr = (XVisibilityEvent *) event; - if (ptr->window == PopUpWin && ptr->state != VisibilityUnobscured - && PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - } - break; - - - case (ButtonRelease): - { - XButtonReleasedEvent *ptr; - - if (XHeldButton != -1) { /* Three button emulation fix! */ - DoneEvents(); - XHeldButton = -1; - } - - ptr = (XButtonReleasedEvent *) event; - - if (ptr->window == PopUpWin && MenuBarSelect == AboutDLGMItem) { - HandleItemClick(ptr->x, ptr->y); - result = (MenuBarSelect << 8) + MenuItemSelect + 1; - } else if (ptr->window == CanvWin) - if (ptr->window == CanvWin) { - stat = GetStatus(ptr->state); - ProcessMouseUp(ptr->x, ptr->y, stat); - } - } - break; - - case (KeyPress): - { - XKeyPressedEvent *ptr; - static KeySym symbol; - static char keychar; - - keychar = '\0'; - ptr = (XKeyPressedEvent *) event; - index = XLookupString(ptr, &keychar, 1, &symbol, NULL); - switch (symbol) { - case (XK_Begin): - case (XK_Home): - ProcessCharacter(0x01); - break; - case (XK_Right): - ProcessCharacter(0x06); - break; - case (XK_Left): - ProcessCharacter(0x02); - break; - case (XK_End): - ProcessCharacter(0x05); - break; - case (XK_Up): - case (XK_Prior): - ProcessCharacter(0x10); - break; - case (XK_Down): - case (XK_Next): - ProcessCharacter(0x0e); - break; - - case (XK_F10): - if (!DisableMenu) { - SelectMenu(0); - result = HandleMenuLoop(); - } - break; - - default: - if (index == 1) { - if (!(ptr->state & Mod1Mask)) { - if (ProcessCharacter(keychar)) { - if (ProcessCommand()) - RasMolExit(); - - if (!CommandActive) - ResetCommandLine(0); - } - } else if (!DisableMenu) - if (HandleMenuKey(keychar)) - result = HandleMenuLoop(); - } - } - } - break; - - - case (Expose): - { - XExposeEvent *ptr; - - ptr = (XExposeEvent *) event; - if (ptr->window == CanvWin) { - if (image) { -#ifdef MITSHM - if (SharedMemFlag) { - XShmPutImage(dpy, CanvWin, gcon, image, - ptr->x, ptr->y, ptr->x, ptr->y, - ptr->width, ptr->height, False); - XSync(dpy, False); - } else -#endif - XPutImage(dpy, CanvWin, gcon, image, - ptr->x, ptr->y, ptr->x, ptr->y, - ptr->width, ptr->height); - } else - XClearWindow(dpy, CanvWin); - } else if (ptr->window == MainWin) { - DrawMainWin(); - DrawMenuBar(); - } else if (ptr->window == XScrlWin) { - DrawXScroll(); - } else if (ptr->window == YScrlWin) { - DrawYScroll(); - } - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - XFlush(dpy); - } - break; - - case (EnterNotify): - { - XCrossingEvent *ptr; - - ptr = (XCrossingEvent *) event; - if (ptr->detail != NotifyInferior) { - if (LocalMap) - XInstallColormap(dpy, lmap); - } -#ifdef DIALBOX - if (UseDials) - GetDialState(); -#endif - } - break; - - case (LeaveNotify): - if (LocalMap) { - XCrossingEvent *ptr; - - ptr = (XCrossingEvent *) event; - if (ptr->detail != NotifyInferior) - XUninstallColormap(dpy, lmap); - } - break; - - case (ConfigureNotify): - { - XConfigureEvent *ptr; - register int wide, high; - - ptr = (XConfigureEvent *) event; - if (ptr->window == MainWin) { - high = CropRange(ptr->height, MinHeight, MaxHeight); - wide = CropRange(ptr->width, MinWidth, MaxWidth); - - if ((wide != MainWide) || (high != MainHigh)) - ReSizeWindow(wide, high); - XFlush(dpy); - } - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - int xpos, ypos; - Window win; - - XTranslateCoordinates(dpy, MainWin, RootWin, AboutDLGXpos, - FontHigh + 6, &xpos, &ypos, &win); - - if (ypos + PopUpHigh > MaxHeight) - ypos -= (PopUpHigh + FontHigh + 6); - if (xpos + PopUpWide > MaxWidth) - xpos = MaxWidth - PopUpWide; - if (xpos < 0) - xpos = 0; - - XMoveWindow(dpy, PopUpWin, xpos, ypos); - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - XFlush(dpy); - } - } - break; - - case (ClientMessage): - { - XClientMessageEvent *ptr; - - ptr = (XClientMessageEvent *) event; - if ((ptr->message_type == ProtoXAtom) && - (ptr->data.l[0] == DelWinXAtom)) - RasMolExit(); - } - break; - - case (PropertyNotify): - { - XPropertyEvent *ptr; - - ptr = (XPropertyEvent *) event; - if ((ptr->atom == CommAtom) && (ptr->state == PropertyNewValue)) - HandleIPCCommand(); - } - break; - - case (MapNotify): - DrawXScroll(); - DrawYScroll(); - DrawMainWin(); - DrawMenuBar(); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - break; - - default: -#ifdef DIALBOX - if (event->type == DialEvent) - HandleDialEvent((XDeviceMotionEvent *) event); -#endif - break; - } - return result; -} - - - -/*=========================*/ -/* Modal Dialog Handling */ -/*=========================*/ - -static int HandleMenuLoop(void) -{ - register unsigned int mask; - register int result; - register int done; - auto XEvent event; - - /* Passive Pointer Grab */ - mask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask; - XGrabPointer(dpy, MenuWin, False, mask, - GrabModeAsync, GrabModeAsync, None, None, CurrentTime); - - XHeldButton = -1; - MenuFocus = True; - DrawMenuBar(); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - XRaiseWindow(dpy, PopUpWin); - DrawAboutDLG(); - } - - result = 0; - done = False; - while (!done) { - XNextEvent(dpy, &event); - switch (event.type) { - case (Expose): - { - XExposeEvent *ptr; - - ptr = (XExposeEvent *) & event; - if (ptr->window == PopUpWin) { - if (MenuBarSelect == AboutDLGMItem) - DrawAboutDLG(); - else - DrawPopUpMenu(); - } else - ProcessEvent(&event); - } - break; - - - case (ButtonPress): - { - XButtonPressedEvent *ptr; - - ptr = (XButtonPressedEvent *) & event; - /* All Events Relative to MenuWin */ - if ((ptr->y >= 0) && (ptr->y <= FontHigh + 5)) { - HandleMenuClick(ptr->x); - } else if (PopUpFlag) { - int xpos, ypos; - Window win; - XTranslateCoordinates(dpy, MenuWin, PopUpWin, ptr->x, - ptr->y, &xpos, &ypos, &win); - HandleItemClick(xpos, ypos); - } else - done = True; - } - break; - - case (MotionNotify): - if (ItemFocus) { - XMotionEvent *ptr; - - ptr = (XMotionEvent *) & event; - /* All Events Relative to MenuWin */ - if ((ptr->y >= 0) && (ptr->y <= FontHigh + 5)) { - HandleMenuClick(ptr->x); - } else if (PopUpFlag) { - int xpos, ypos; - Window win; - XTranslateCoordinates(dpy, MenuWin, PopUpWin, ptr->x, - ptr->y, &xpos, &ypos, &win); - HandleItemMove(xpos, ypos); - } - } - break; - - case (ButtonRelease): - { - XButtonReleasedEvent *ptr; - - ptr = (XButtonReleasedEvent *) & event; - /* All Events Relative to MenuWin */ - if ((ptr->y >= 0) && (ptr->y <= FontHigh + 5)) { - if (HandleMenuClick(ptr->x)) { - SelectFirstItem(MenuBarSelect); - DrawPopUpMenu(); - } else - done = True; - } else if (PopUpFlag) { - if (ItemFocus || MenuBarSelect == AboutDLGMItem) { - int xpos, ypos; - Window win; - - XTranslateCoordinates(dpy, MenuWin, PopUpWin, ptr->x, - ptr->y, &xpos, &ypos, &win); - HandleItemClick(xpos, ypos); - } - if (ItemFlag) - result = (MenuBarSelect << 8) + MenuItemSelect + 1; - done = True; - } else - done = False; - ItemFocus = False; - } - break; - - case (KeyPress): - if (!ItemFocus) { - XKeyPressedEvent *ptr; - static KeySym symbol; - static char keychar; - register int index; - - ptr = (XKeyPressedEvent *) & event; - index = XLookupString(ptr, &keychar, 1, &symbol, NULL); - switch (symbol) { - case (XK_Right): - index = MenuBarSelect + 1; - if (index < MenuBarCount) { - SelectMenu(index); - } else - SelectMenu(0); - break; - - case (XK_Left): - if (MenuBarSelect) { - SelectMenu(MenuBarSelect - 1); - } else - SelectMenu(MenuBarCount - 1); - break; - - case (XK_Up): - if (!PopUpFlag) { - PopUpFlag = True; - SelectMenu(MenuBarSelect); - } else - SelectPrevItem(); - break; - - case (XK_Down): - if (!PopUpFlag) { - PopUpFlag = True; - SelectMenu(MenuBarSelect); - } else - SelectNextItem(); - break; - - case (XK_KP_Enter): - case (XK_Linefeed): - case (XK_Return): - if (PopUpFlag && ItemFlag) - result = (MenuBarSelect << 8) + MenuItemSelect + 1; - done = True; - break; - - default: - if ((index == 1) && (keychar >= ' ')) { - if (!(ptr->state & Mod1Mask)) { - if (PopUpFlag) { - result = HandleItemKey(keychar); - if (result) - done = True; - } else - HandleMenuKey(keychar); - } else - HandleMenuKey(keychar); - } - } - } - break; - - default: - ProcessEvent(&event); - } - } - - /* Passive Grab Release */ - XUngrabPointer(dpy, CurrentTime); - if (PopUpFlag && MenuBarSelect == AboutDLGMItem) { - UnDisplayAboutDLG(); - } - XUnmapWindow(dpy, PopUpWin); - PopUpFlag = False; - MenuFocus = False; - DrawMenuBar(); - return result; -} - - -int FetchEvent(int wait) -{ - register int result; - auto XEvent event; - - NewScrlX = ScrlX; - NewScrlY = ScrlY; - - if (XHeldButton != -1) - wait = False; - while (XPending(dpy) || (wait && !ReDrawFlag)) { - XNextEvent(dpy, &event); - result = ProcessEvent(&event); - if (result) - return result; - } - DoneEvents(); - return 0; -} - - -int LookUpColour(char *name, int *red, int *grn, int *blu) -{ - static XColor exact, close; - register Colormap map; - - map = (LocalMap) ? lmap : cmap; - if (XLookupColor(dpy, map, name, &exact, &close)) { - *red = exact.red >> 8; - *grn = exact.green >> 8; - *blu = exact.blue >> 8; - return True; - } - return False; -} - - -void BeginWait(void) -{ - if (UseHourGlass) { - XDefineCursor(dpy, CanvWin, hglass); - XDefineCursor(dpy, MainWin, hglass); - XFlush(dpy); - } -} - - -void EndWait(void) -{ - if (UseHourGlass) { - XDefineCursor(dpy, CanvWin, cross); - XDefineCursor(dpy, MainWin, arrow); - XFlush(dpy); - } -} - - -void CloseDisplay(void) -{ -#ifdef DIALBOX - register int num; -#endif - - /* FatalXError! */ - if (!dpy) - return; - - if (image) { -#ifdef MITSHM - if (SharedMemFlag) { - XShmDetach(dpy, &xshminfo); - image->data = (char *) NULL; - shmdt(xshminfo.shmaddr); - } -#endif - XDestroyImage(image); - } - - if (*TkInterp) { - XGrabServer(dpy); - DeRegisterInterpName(TkInterp); - XUngrabServer(dpy); - } -#ifdef DIALBOX - if (UseDials) { - if (UseDialLEDs) - for (num = 0; num < 8; num++) - SetDialLabel(num, ""); - XCloseDevice(dpy, Dials); - } -#endif - XCloseDisplay(dpy); -}