Jack Jansen | c982ef2 | 2001-02-15 22:56:41 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * WETabs.c |
| 3 | * |
| 4 | * WASTE TABS PACKAGE |
| 5 | * Routines for installing/removing tab hooks; accessors |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "WETabs.h" |
| 11 | #include "WETabHooks.h" |
| 12 | |
| 13 | #ifndef __ERRORS__ |
| 14 | #include <Errors.h> |
| 15 | #endif |
| 16 | |
| 17 | /* static UPP's */ |
| 18 | static WEDrawTextUPP _weTabDrawTextProc = nil; |
| 19 | static WEPixelToCharUPP _weTabPixelToCharProc = nil; |
| 20 | static WECharToPixelUPP _weTabCharToPixelProc = nil; |
| 21 | static WELineBreakUPP _weTabLineBreakProc = nil; |
| 22 | |
| 23 | pascal OSErr WEInstallTabHooks(WEReference we) |
| 24 | { |
| 25 | OSErr err; |
| 26 | |
| 27 | /* if first time, create routine descriptors */ |
| 28 | if (_weTabDrawTextProc == nil) |
| 29 | { |
| 30 | _weTabDrawTextProc = NewWEDrawTextProc(_WETabDrawText); |
| 31 | _weTabPixelToCharProc = NewWEPixelToCharProc(_WETabPixelToChar); |
| 32 | _weTabCharToPixelProc = NewWECharToPixelProc(_WETabCharToPixel); |
| 33 | _weTabLineBreakProc = NewWELineBreakProc(_WETabLineBreak); |
| 34 | } |
| 35 | |
| 36 | if ((err = WESetInfo( weDrawTextHook, &_weTabDrawTextProc, we )) != noErr) |
| 37 | { |
| 38 | goto cleanup; |
| 39 | } |
| 40 | if ((err = WESetInfo( wePixelToCharHook, &_weTabPixelToCharProc, we )) != noErr) |
| 41 | { |
| 42 | goto cleanup; |
| 43 | } |
| 44 | if ((err = WESetInfo( weCharToPixelHook, &_weTabCharToPixelProc, we )) != noErr) |
| 45 | { |
| 46 | goto cleanup; |
| 47 | } |
| 48 | if ((err = WESetInfo( weLineBreakHook, &_weTabLineBreakProc, we )) != noErr) |
| 49 | { |
| 50 | goto cleanup; |
| 51 | } |
| 52 | |
| 53 | cleanup: |
| 54 | return err; |
| 55 | } |
| 56 | |
| 57 | pascal OSErr WERemoveTabHooks(WEReference we) |
| 58 | { |
| 59 | UniversalProcPtr nullHook = nil; |
| 60 | OSErr err; |
| 61 | |
| 62 | if ((err = WESetInfo( weDrawTextHook, &nullHook, we )) != noErr) |
| 63 | { |
| 64 | goto cleanup; |
| 65 | } |
| 66 | if ((err = WESetInfo( wePixelToCharHook, &nullHook, we )) != noErr) |
| 67 | { |
| 68 | goto cleanup; |
| 69 | } |
| 70 | if ((err = WESetInfo( weCharToPixelHook, &nullHook, we )) != noErr) |
| 71 | { |
| 72 | goto cleanup; |
| 73 | } |
| 74 | if ((err = WESetInfo( weLineBreakHook, &nullHook, we )) != noErr) |
| 75 | { |
| 76 | goto cleanup; |
| 77 | } |
| 78 | |
| 79 | cleanup: |
| 80 | return err; |
| 81 | } |
| 82 | |
| 83 | pascal Boolean WEIsTabHooks(WEReference we) |
| 84 | { |
| 85 | WEPixelToCharUPP hook = nil; |
| 86 | |
| 87 | /* return true if our tab hooks are installed */ |
| 88 | |
| 89 | return ( _weTabPixelToCharProc != nil ) && |
| 90 | ( WEGetInfo( wePixelToCharHook, &hook, we ) == noErr) && |
| 91 | ( _weTabPixelToCharProc == hook ); |
| 92 | } |
| 93 | |
| 94 | pascal SInt16 WEGetTabSize(WEReference we) |
| 95 | { |
| 96 | SInt32 result; |
| 97 | |
| 98 | if (WEGetUserInfo( kTabSizeTag, &result, we ) != noErr) |
| 99 | { |
| 100 | result = kDefaultTabSize; |
| 101 | } |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | pascal OSErr WESetTabSize(SInt16 tabSize, WEReference we) |
| 106 | { |
| 107 | // make sure tabSize is a reasonable size |
| 108 | if ((tabSize < kMinTabSize) || (tabSize > kMaxTabSize)) |
| 109 | { |
| 110 | return paramErr; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | return WESetUserInfo( kTabSizeTag, tabSize, we ); |
| 115 | } |
| 116 | } |