| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // TxPrint hook mechanism handling |
|---|
| 34 | // |
|---|
| 35 | // Author: J. van Wijk |
|---|
| 36 | // |
|---|
| 37 | // JvW 19-08-2005 Initial version, split off from TXCON.C |
|---|
| 38 | |
|---|
| 39 | #include <txlib.h> |
|---|
| 40 | #include <txtpriv.h> |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | /*****************************************************************************/ |
|---|
| 44 | // Perform operations on TxPrint HOOK chain |
|---|
| 45 | /*****************************************************************************/ |
|---|
| 46 | BOOL TxPrintHook // RET success |
|---|
| 47 | ( |
|---|
| 48 | TXH_TYPE type, // IN type of handler |
|---|
| 49 | TXH_OPERATION operation, // IN requested operation |
|---|
| 50 | TXH_INFO *hinfo // IN handler info |
|---|
| 51 | ) |
|---|
| 52 | { |
|---|
| 53 | BOOL rc = TRUE; |
|---|
| 54 | TXH_INFO **root; // root of handler chain |
|---|
| 55 | TXH_INFO *this; // existing handler if found |
|---|
| 56 | TXH_INFO *last; // insertion point in chain |
|---|
| 57 | |
|---|
| 58 | ENTER(); |
|---|
| 59 | TRARGS(("type: %s, oper %s, hinfo: %8.8lX\n", |
|---|
| 60 | (type == TXH_T_RAW ) ? "RAW" : "CLEAN", |
|---|
| 61 | (operation == TXH_REGISTER) ? "REGISTER" : "DEREGISTER", hinfo)); |
|---|
| 62 | |
|---|
| 63 | switch (type) |
|---|
| 64 | { |
|---|
| 65 | case TXH_T_RAW: root = &txh_raw; break; |
|---|
| 66 | default: root = &txh_clean; break; |
|---|
| 67 | } |
|---|
| 68 | for (last = NULL, this = *root; |
|---|
| 69 | this != NULL; |
|---|
| 70 | last = this, this = this->next) |
|---|
| 71 | { |
|---|
| 72 | if (this == hinfo) // handler already present |
|---|
| 73 | { |
|---|
| 74 | break; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | switch (operation) |
|---|
| 78 | { |
|---|
| 79 | case TXH_REGISTER: |
|---|
| 80 | if (this == NULL) // new handler |
|---|
| 81 | { |
|---|
| 82 | if (last == NULL) // first handler |
|---|
| 83 | { |
|---|
| 84 | *root = hinfo; |
|---|
| 85 | hinfo->prev = NULL; |
|---|
| 86 | } |
|---|
| 87 | else // another handler |
|---|
| 88 | { |
|---|
| 89 | last->next = hinfo; |
|---|
| 90 | hinfo->prev = last; |
|---|
| 91 | } |
|---|
| 92 | hinfo->next = NULL; |
|---|
| 93 | } |
|---|
| 94 | else // already registred |
|---|
| 95 | { |
|---|
| 96 | rc = FALSE; |
|---|
| 97 | } |
|---|
| 98 | break; |
|---|
| 99 | |
|---|
| 100 | case TXH_DEREGISTER: |
|---|
| 101 | if (this != NULL) // existing handler ? |
|---|
| 102 | { |
|---|
| 103 | if (this == *root) // first in chain |
|---|
| 104 | { |
|---|
| 105 | *root = this->next; |
|---|
| 106 | } |
|---|
| 107 | else |
|---|
| 108 | { |
|---|
| 109 | this->prev->next = this->next; |
|---|
| 110 | } |
|---|
| 111 | if (this->next != NULL) // not last in chain ? |
|---|
| 112 | { |
|---|
| 113 | this->next->prev = this->prev; |
|---|
| 114 | } |
|---|
| 115 | hinfo->prev = NULL; |
|---|
| 116 | hinfo->next = NULL; |
|---|
| 117 | } |
|---|
| 118 | else // not registred |
|---|
| 119 | { |
|---|
| 120 | rc = FALSE; |
|---|
| 121 | } |
|---|
| 122 | break; |
|---|
| 123 | |
|---|
| 124 | default: |
|---|
| 125 | TRACES(("Invalid hook operation: %lu\n", operation)); |
|---|
| 126 | break; |
|---|
| 127 | } |
|---|
| 128 | BRETURN(rc); |
|---|
| 129 | } // end 'TxPrintHook' |
|---|
| 130 | /*---------------------------------------------------------------------------*/ |
|---|