forked from ff6347/mpolauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPOLnchPenObserver.cpp
252 lines (178 loc) · 5.81 KB
/
MPOLnchPenObserver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//========================================================================================
//
// $File: //depot/indesign_6.0/highprofile/source/sdksamples/wlistboxcomposite/MPOLnchPenObserver.cpp $
//
// Owner: Adobe Developer Technologies
//
// $Author: pmbuilder $
//
// $DateTime: 2008/08/19 04:03:07 $
//
// $Revision: #1 $
//
// $Change: 643572 $
//
// Copyright 1997-2008 Adobe Systems Incorporated. All rights reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
// with the terms of the Adobe license agreement accompanying it. If you have received
// this file from a source other than Adobe, then your use, modification, or
// distribution of it requires the prior written permission of Adobe.
//
//========================================================================================
#include "VCPlugInHeaders.h"
// Implementation includes
#include "widgetid.h"
// Interface includes
#include "ISubject.h"
#include "ITriStateControlData.h"
// Implem includes
#include "CAlert.h"
#include "CObserver.h"
#include "MPOLnchID.h"
// Interface includes
#include "IControlView.h"
#include "ITreeViewController.h"
#include "IWidgetParent.h"
#include "IPanelControlData.h"
#include "ITextControlData.h"
// Implem includes
#include "CAlert.h"
#include "CObserver.h"
#include "MPOLnchID.h"
// Implem includes
#include "K2Vector.tpp" // For NodeIDList to compile
#include "MPOLnchNodeID.h"
// Scripting includes
#include "IScriptRunner.h"
#include "IScriptUtils.h"
// file handling
#include "FileUtils.h"
#include "StreamUtil.h"
#include "IPMStream.h"
#include "MPOLnchHelper.h"
/**
Observes the "pen" buttons in the widget list.
@ingroup wlistboxcomposite
*/
class MPOLnchPenObserver : public CObserver
{
public:
/**
Constructor for WLBListBoxObserver class.
@param interface ptr from boss object on which this interface is aggregated.
*/
MPOLnchPenObserver(IPMUnknown *boss);
/**
Destructor.
*/
~MPOLnchPenObserver();
/**
AutoAttach is only called for registered observers
of widgets. This method is called by the application
core when the widget is shown.
*/
virtual void AutoAttach();
/**
AutoDetach is only called for registered observers
of widgets. Called when widget hidden.
*/
virtual void AutoDetach();
/**
Update when there's been a change on the pen widget.
@param theChange this is specified by the agent of change; it can be the class ID of the agent,
or it may be some specialised message ID.
@param theSubject this provides a reference to the object which has changed; in this case, the button
widget boss object that is being observed.
@param protocol the protocol along which the change occurred.
@param changedBy this can be used to provide additional information about the change or a reference
to the boss object that caused the change.
*/
virtual void Update(const ClassID& theChange, ISubject* theSubject, const PMIID &protocol, void* changedBy);
//PMString ReadAllAsText(IPMStream *s);
};
CREATE_PMINTERFACE(MPOLnchPenObserver, kMPOLnchPenObserverImpl)
MPOLnchPenObserver::MPOLnchPenObserver(IPMUnknown* boss)
: CObserver(boss)
{
}
MPOLnchPenObserver::~MPOLnchPenObserver()
{
}
void MPOLnchPenObserver::AutoAttach()
{
InterfacePtr<ISubject> subject(this, UseDefaultIID());
if (subject != nil)
{
subject->AttachObserver(this, IID_ITRISTATECONTROLDATA);
}
}
void MPOLnchPenObserver::AutoDetach()
{
InterfacePtr<ISubject> subject(this, UseDefaultIID());
if (subject != nil)
{
subject->DetachObserver(this,IID_ITRISTATECONTROLDATA);
}
}
void MPOLnchPenObserver::Update
(
const ClassID& theChange,
ISubject* theSubject,
const PMIID &protocol,
void* changedBy
)
{
if(theChange == kTrueStateMessage) {
// Then the button has been activated.
do {
InterfacePtr<ITriStateControlData> data(this, IID_ITRISTATECONTROLDATA);
// now look for the parent of the widget
InterfacePtr<IWidgetParent> widgetParent(this, IID_IWIDGETPARENT);
if(widgetParent == nil){
CAlert::InformationAlert("widgetParent is nil");
break;
}
//found it
// Query the parent for the panel
InterfacePtr<IPanelControlData> panelData((IPanelControlData*)widgetParent->QueryParentFor(IID_IPANELCONTROLDATA));
if(panelData == nil) {
CAlert::InformationAlert("panelData is nil");
break;
}
// found it
// look for the TextWidget that holds the name
IControlView* nameView = panelData->FindWidget(kMPOLnchTextWidgetID);
InterfacePtr<ITextControlData> textControlData( nameView, UseDefaultIID() );
if( (textControlData== nil)) {
break;
CAlert::InformationAlert("textControlData is nil");
}
// Thats great. found it
// get the name of the node. The associated PMString
PMString nodeName(textControlData->GetString());
// Show it only for debug
//nodeName.SetTranslatable(kFalse); // only for debug- not real code
//CAlert::InformationAlert(nodeName);
MPOLnchHelper helper;
// look for the internal resource files
IDFile helpFile = helper.GetInternalResourceFolder();
//PMString pre("help_");
PMString fn(nodeName);
PMString exth(".txt");
FileUtils::AppendPath(&helpFile, fn + exth);
if (FileUtils::DoesFileExist(helpFile)) {
InterfacePtr<IPMStream> s(StreamUtil::CreateFileStreamRead(helpFile));
//CAlert::InformationAlert(helper.ReadAllAsText(s));
CAlert::ModalAlert(helper.ReadAllAsText(s),
kOKString,
kNullString,
kNullString,
1, // pass in 1, 2, or 3 to make that button the default button or 0 for no default
CAlert::eWarningIcon);
}else {
CAlert::InformationAlert(helper.MissingHelpFileStr(nodeName));
}
} while(0);
}
}