source: trunk/ICeCoffEE/ICeCoffEE/ICeCoffEETextEdit.c@ 106

Last change on this file since 106 was 106, checked in by Nicholas Riley, 19 years ago

ICeCoffEE 1.3.2b1

File size: 8.5 KB
Line 
1/*
2 * ICeCoffEETextEdit.c
3 * ICeCoffEE APE
4 *
5 * Created by Nicholas Riley on Sun Jan 26 2003.
6 * Copyright (c) 2003 Nicholas Riley. All rights reserved.
7 *
8 */
9
10// based on ICeTEe.c by Michael Schürig
11
12#include "ICeCoffEETextEdit.h"
13#include "ICeCoffEEConfig.h"
14#include "ICeCoffEEShared.h"
15#include <ApplicationEnhancer/ApplicationEnhancer.h>
16
17//=============================================================================
18// Global Variables
19//-----------------------------------------------------------------------------
20TEClickProcPtr gTEClick = NULL;
21
22//=============================================================================
23// Private function prototypes
24//-----------------------------------------------------------------------------
25void ICCF_LaunchURLFromTEClick(TEHandle teH, short oldSelStart, short oldSelEnd, iccfURLAction action);
26OSStatus ICCF_DoCommandClick(TEHandle teH, long selStart, long selEnd, iccfURLAction action);
27
28//=============================================================================
29// ICCF_LaunchURLFromTEClick : TEClick addition.
30//-----------------------------------------------------------------------------
31void ICCF_LaunchURLFromTEClick(TEHandle teH, short oldSelStart, short oldSelEnd, iccfURLAction action)
32{
33 OSStatus err;
34 ICapeprintf("ICCF_LaunchURLFromTEClick entered\n");
35 if (ICCF_enabled && ICCF_prefs.commandClickEnabled) {
36 if ( !( (oldSelStart <= (**teH).selStart) && ((**teH).selStart <= oldSelEnd)
37 && (oldSelStart <= (**teH).selEnd) && ((**teH).selEnd <= oldSelEnd) ) ) {
38 oldSelStart = (**teH).selStart;
39 oldSelEnd = (**teH).selEnd;
40 }
41 err = ICCF_DoCommandClick(teH, oldSelStart, oldSelEnd, action);
42 if (err != noErr && err != userCanceledErr) {
43 ICapeprintf("ICCF_DoCommandClick failed: %ld\n", err);
44 if (ICCF_prefs.errorSoundEnabled) SysBeep(10);
45 if (ICCF_prefs.errorDialogEnabled) {
46 CFStringRef alertTitle = ICCF_CopyLocalizedString(CFSTR("AlertTitle"));
47 CFStringRef alertMessageTemplate = ICCF_CopyLocalizedString(CFSTR("AlertMessage%@"));
48 CFStringRef errStr = ICCF_CopyErrString(err, CFSTR("ICCF_DoCommandClick"));
49 CFStringRef alertMessage = CFStringCreateWithFormat(NULL, NULL, alertMessageTemplate, errStr);
50 CFStringRef disableButton = ICCF_CopyLocalizedString(CFSTR("AlertDisableButton"));
51 AlertStdCFStringAlertParamRec paramRec = { kStdCFStringAlertVersionOne, true, false, NULL, disableButton, NULL, kStdOkItemIndex, 0, kWindowDefaultPosition, kNilOptions };
52
53 DialogRef alertRef = NULL;
54 DialogItemIndex itemHit = kStdOkItemIndex;
55 err = CreateStandardAlert(kAlertNoteAlert, alertTitle, alertMessage, &paramRec, &alertRef);
56
57 if (err != noErr) { // last resort: should be apeprintf, not ICapeprintf
58 apeprintf("ICCF_DoCommandClick failed, couldn't create alert (%ld): %@\n", err, errStr);
59 } else {
60 err = RunStandardAlert(alertRef, NULL, &itemHit);
61 if (err != noErr) { // last resort: should be apeprintf, not ICapeprintf
62 apeprintf("ICCF_DoCommandClick failed, couldn't run alert (%ld): %@\n", err, errStr);
63 }
64 }
65
66 if (alertTitle != NULL) CFRelease(alertTitle);
67 if (alertMessageTemplate != NULL) CFRelease(alertMessageTemplate);
68 if (alertMessage != NULL) CFRelease(alertMessage);
69 if (disableButton != NULL) CFRelease(disableButton);
70 if (errStr != NULL) CFRelease(errStr);
71
72 if (itemHit == kStdCancelItemIndex) {
73 alertTitle = ICCF_CopyLocalizedString(CFSTR("DisableAlertTitle"));
74 alertMessage = ICCF_CopyLocalizedString(CFSTR("DisableAlertMessage"));
75 disableButton = ICCF_CopyLocalizedString(CFSTR("DisableAlertDisableButton"));
76 CFStringRef dontDisableButton = ICCF_CopyLocalizedString(CFSTR("DisableAlertDontDisableButton"));
77
78 AlertStdCFStringAlertParamRec disableParamRec = { kStdCFStringAlertVersionOne, true, false, disableButton, dontDisableButton, NULL, kStdOkItemIndex, kStdCancelItemIndex, kWindowDefaultPosition, kNilOptions };
79
80 itemHit = kStdCancelItemIndex;
81 err = CreateStandardAlert(kAlertNoteAlert, alertTitle, alertMessage, &disableParamRec, &alertRef);
82
83 if (err != noErr) { // last resort: should be apeprintf, not ICapeprintf
84 apeprintf("ICCF_DoCommandClick couldn't create alert (%ld)\n", err);
85 } else {
86 err = RunStandardAlert(alertRef, NULL, &itemHit);
87 if (err != noErr) { // last resort: should be apeprintf, not ICapeprintf
88 apeprintf("ICCF_DoCommandClick couldn't run alert (%ld)\n", err);
89 }
90 }
91 if (alertTitle != NULL) CFRelease(alertTitle);
92 if (alertMessage != NULL) CFRelease(alertMessage);
93 if (disableButton != NULL) CFRelease(disableButton);
94 if (dontDisableButton != NULL) CFRelease(dontDisableButton);
95
96 if (itemHit == kStdOkItemIndex) ICCF_enabled = false;
97 }
98 }
99 }
100 }
101 ICapeprintf("ICCF_LaunchURLFromTEClick exit\n");
102}
103
104//=============================================================================
105// ICCF_DoCommandClick : Handle the click.
106//-----------------------------------------------------------------------------
107OSStatus ICCF_DoCommandClick(TEHandle teH, long selStart, long selEnd, iccfURLAction action)
108{
109 ICInstance inst = NULL;
110 OSStatus err = noErr, err2;
111 ICapeprintf("ICCF_DoCommandClick entered\n");
112 if (inst == NULL) {
113 if ( (err = ICStart(&inst, kICCFCreator)) != noErr)
114 return err;
115 }
116 Handle textH;
117 SInt8 s;
118 ConstStringPtr hint;
119 Boolean needsSlashes;
120 textH = (Handle)TEGetText(teH);
121 s = HGetState(textH);
122 HLock(textH);
123 hint = ICCF_GetHint(inst, *textH, GetHandleSize(textH), &selStart, &selEnd, &needsSlashes);
124 ICapeprintf("ICCF_DoCommandClick: %sneedsSlashes\n", needsSlashes ? "" : "doesn't ");
125 if (hint != NULL) {
126 CGrafPtr thePort = teH[0]->inPort;
127 if (!QDIsPortBuffered(thePort)) thePort = NULL;
128 TESetSelect(selStart, selEnd, teH);
129 if (thePort != NULL) QDFlushPortBuffer(thePort, NULL);
130
131 Handle urlH = NewHandle(0);
132 if (urlH == NULL) {
133 err = MemError();
134 } else {
135 err = ICParseURL(inst, hint, *textH, GetHandleSize(textH), &selStart, &selEnd, urlH);
136 if (err == noErr) {
137 if (needsSlashes) ICCF_AddSlashes(urlH, hint);
138 err = ICCF_DoURLAction(inst, hint, *urlH, 0, GetHandleSize(urlH), action);
139 }
140 DisposeHandle(urlH);
141 }
142
143 if (err == noErr) {
144 SInt32 junk;
145 SInt16 i = ICCF_prefs.textBlinkCount;
146 SInt32 blinkDelay = kICBlinkDelayUsecs / 10000; // XXX incorrect, fix
147 TESetSelect(selStart, selEnd, teH);
148 if (thePort != NULL) QDFlushPortBuffer(thePort, NULL);
149 while (i--) {
150 Delay(blinkDelay, &junk);
151 TEDeactivate(teH);
152 if (thePort != NULL) QDFlushPortBuffer(thePort, NULL);
153 Delay(blinkDelay, &junk);
154 TEActivate(teH);
155 if (thePort != NULL) QDFlushPortBuffer(thePort, NULL);
156 }
157 }
158 }
159 HSetState(textH, s);
160 err2 = ICStop(inst);
161 if (err == noErr)
162 err = err2;
163 ICapeprintf("ICCF_DoCommandClick exit\n");
164 return(err);
165}
166
167void ICCF_TEClick(Point pt, Boolean fExtend, TEHandle teH) {
168 short oldSelStart, oldSelEnd;
169
170 ICapeprintf("ICCF_TEClick entered\n");
171
172 // Save old selection
173 oldSelStart = (**teH).selStart;
174 oldSelEnd = (**teH).selEnd;
175 // Get modifier keys
176 UInt32 modifiers = GetCurrentEventKeyModifiers();
177 // Call the original TEClick()
178 gTEClick(pt, fExtend, teH);
179 // Do our thing
180 if (modifiers & cmdKey) {
181 iccfURLAction action;
182 action.presentMenu = (modifiers & optionKey) != 0;
183 action.launchInBackground = (modifiers & shiftKey) != 0;
184 ICCF_LaunchURLFromTEClick(teH, oldSelStart, oldSelEnd, action);
185 }
186 ICapeprintf("ICCF_TEClick exited\n");
187}
Note: See TracBrowser for help on using the repository browser.