home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: CenterWindow 2.2 (27 Apr 1996) **
- **
- ** © 1996 Timo C. Nentwig
- ** all rights reserved !
- **
- ** ======================================
- **
- ** Language:
- ** ¯¯¯¯¯¯¯¯
- **
- ** Program is compiled by SAS/C
- **
- **
- ** Purpose:
- ** ¯¯¯¯¯¯¯
- **
- ** Center the active window
- ** by hotkey.
- **
- ** Put window under window -> Parent
- ** by hotkey.
- **
- ** Requirements:
- ** ¯¯¯¯¯¯¯¯¯¯¯¯
- **
- ** AmigaOS v37+
- **
- ** Bugs:
- ** ¯¯¯¯
- **
- **
- **
- ** ToDo:
- ** ¯¯¯¯
- **
- **
- **
- ** Notes:
- ** ¯¯¯¯¯
- **
- **
- ** ======================================
- **
- ** History:
- ** ¯¯¯¯¯¯¯
- **
- ** 01 Apr 1996 - 1.0 : initial release
- ** 26 Apr 1996 - 2.0 : completely overworked (name changed)
- ** now works by hotkey
- ** 27 Apr 1996 - 2.1 : HOTKEY -> CENTERKEY
- ** add: PARENTKEY -> put window under window -> parent
- **
- ** 27 Apr 1996 - 2.2 : PARENTKEY: Care if win -> Parent has WFLG_DRAGBAR
- ** add: Tooltype FULLHEIGHT
- **
- */
-
- /// #include
-
- #include <dos/dos.h>
- #include <exec/types.h>
- #include <intuition/intuition.h>
- #include <intuition/intuitionbase.h>
-
- #include <libraries/commodities.h>
-
- #include <proto/commodities.h>
- #include <proto/exec.h>
- #include <proto/intuition.h>
-
- #include <stdio.h>
- #include <strings.h>
-
- ///
- /// #define
-
- #define EVT_CENTERKEY 1L
- #define EVT_PARENTKEY 2L
-
- #define PRG_VERSION "2.2"
- #define PRG_TITLE "CenterWin"
- #define PRG_AUTHOR "Timo C. Nentwig"
- #define PRG_YEAR "1996"
-
- ///
- /// Prototypes
-
- VOID ProcessMsg (VOID);
- BOOL AttachFilter (STRPTR onkey, ULONG user_event);
-
- ///
-
- struct IntuitionBase *IntuitionBase;
- struct Library *CxBase;
- struct MsgPort *broker_mp;
- CxObj *broker;
- ULONG cxsigflag;
- BOOL fullheight;
-
- /// main ()
-
- VOID
- main (UWORD argc, STRPTR *argv)
- {
-
- if (IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 37))
- {
-
- if (CxBase = OpenLibrary ("commodities.library", 37))
- {
-
- if (broker_mp = CreateMsgPort())
- {
-
- STRPTR *ttypes;
- STRPTR centerkey;
- STRPTR parentkey;
- struct NewBroker newbroker =
- {
-
- NB_VERSION,
- PRG_TITLE,
- PRG_TITLE" "PRG_VERSION" © "PRG_YEAR" by "PRG_AUTHOR,
- "Center window by hotkey",
- NBU_UNIQUE | NBU_NOTIFY,
- 0, 0, 0, 0
-
- };
-
- newbroker.nb_Port = broker_mp;
- cxsigflag = 1L << broker_mp->mp_SigBit;
-
- ttypes = ArgArrayInit (argc, argv);
- newbroker.nb_Pri = (BYTE) ArgInt (ttypes, "CX_PRIORITY", 0);
- centerkey = ArgString (ttypes, "CENTERKEY", "F1");
- parentkey = ArgString (ttypes, "PARENTKEY", "F2");
-
- if (stricmp (ArgString (ttypes, "FULLWIDTH", "NO"), "NO") == 0)
- fullheight = FALSE;
- else
- fullheight = TRUE;
-
- if (broker = CxBroker (&newbroker, NULL))
- {
-
- CxMsg *msg;
-
- if (AttachFilter (centerkey, EVT_CENTERKEY) &&
- AttachFilter (parentkey, EVT_PARENTKEY))
- {
-
- ActivateCxObj (broker, 1L);
- ProcessMsg();
-
- }
-
- DeleteCxObjAll (broker);
-
- while (msg = (CxMsg *) GetMsg (broker_mp)) // Empty the port of all CxMsgs
- ReplyMsg ((struct Message *) msg);
-
- }
-
- DeletePort(broker_mp);
-
- }
-
- ArgArrayDone();
- CloseLibrary (CxBase);
-
- }
- else
- {
-
- printf ("ERROR: Couldn't open commodities.library v37+\n");
-
- }
-
- CloseLibrary ((struct Library *) IntuitionBase);
-
- }
- else
- {
-
- printf ("ERROR: Couldn't open intuition.library v37+\n");
-
- }
-
- }
-
- ///
- /// ProcessMsg ()
-
- /*
- * FROM /rkm/libs/commodities/hotkey.c
- *
- * FUNCTION Process commodity messages.
- *
- * NOTE
- *
- * EXAMPLE ProcessMsg ();
- *
- */
-
-
- VOID
- ProcessMsg (VOID)
- {
-
- CxMsg *msg;
- ULONG sigrcvd;
- ULONG msgid;
- ULONG msgtype;
- LONG returnvalue = 1L;
-
- while (returnvalue)
- {
-
- sigrcvd = Wait (SIGBREAKF_CTRL_C | cxsigflag);
-
- while (msg = (CxMsg *) GetMsg (broker_mp))
- {
-
- msgid = CxMsgID (msg);
- msgtype = CxMsgType (msg);
- ReplyMsg ((struct Message *) msg);
-
- switch (msgtype)
- {
-
- case CXM_IEVENT:
-
- switch (msgid)
- {
-
- case EVT_CENTERKEY:
-
- {
-
- struct Window *win = IntuitionBase -> ActiveWindow;
- UWORD plus;
-
- if (fullheight) // accept titlebar
- plus = win -> Parent -> WScreen -> Font -> ta_YSize + 3;
- else
- plus = 0;
-
- MoveWindow (win, (((win -> WScreen -> Width - win -> Width ) / 2) - win -> LeftEdge),
- ((((win -> WScreen -> Height - plus) - win -> Height) / 2) - win -> TopEdge));
-
- }
- break;
-
- case EVT_PARENTKEY:
-
- {
-
- struct Window *win = IntuitionBase -> ActiveWindow;
- UWORD plus;
-
- if (win -> Parent -> Flags &= WFLG_DRAGBAR) // parent has a dragbar
- plus = win -> Parent -> WScreen -> Font -> ta_YSize + 3;
- else
- plus = 0;
-
-
- if (win -> Parent)
- {
-
- MoveWindow (win, win -> Parent -> LeftEdge - win -> LeftEdge,
- (win -> Parent -> TopEdge - win -> TopEdge) + plus);
-
- }
- else
- {
- // put to 0,0
- MoveWindow (win, 0 - win -> LeftEdge,
- 0 - win -> TopEdge);
-
- }
-
- }
- break;
-
- }
- break;
-
- case CXM_COMMAND:
-
- switch (msgid)
- {
-
- case CXCMD_DISABLE:
-
- ActivateCxObj (broker, 0L);
- break;
-
- case CXCMD_ENABLE:
-
- ActivateCxObj (broker, 1L);
- break;
-
- case CXCMD_KILL:
-
- returnvalue = 0L;
- break;
-
- case CXCMD_UNIQUE:
-
- returnvalue = 0L;
- break;
-
- }
- break;
-
- }
-
- }
-
- if (sigrcvd & SIGBREAKF_CTRL_C)
- returnvalue = 0L;
-
- }
-
- }
-
- ///
- /// AttachFilter ()
-
- /*
- * FROM /CloseWB/CloseWB.c
- *
- * FUNCTION Attach a filter.
- *
- * NOTE
- *
- * EXAMPLE AttachFilter (hotkey, EVT_HOTKEY);
- *
- */
-
-
- BOOL
- AttachFilter (STRPTR onkey, ULONG user_event)
- {
-
- CxObj *filter;
- CxObj *sender;
- CxObj *translator;
-
-
- if (filter = CxFilter (onkey))
- {
-
- AttachCxObj (broker, filter);
-
- if (sender = CxSender (broker_mp, user_event))
- {
-
- AttachCxObj (filter, sender);
-
- if (translator = CxTranslate (NULL))
- {
-
- AttachCxObj (filter, translator);
-
- if ( ! (CxObjError (filter)))
- return (TRUE);
-
- }
-
- }
-
- }
-
- return (FALSE);
-
- }
-
- ///
-