27 #include <sbIPropertyArray.h>
28 #include <sbIPropertyManager.h>
29 #include <nsITreeView.h>
32 #include <nsNetUtil.h>
33 #include <nsServiceManagerUtils.h>
34 #include <nsUnicharUtils.h>
53 mClickHandlers(nsnull)
55 mType.AssignLiteral(
"image");
62 delete mClickHandlers;
68 mImages =
new nsClassHashtable<nsCStringHashKey, nsCString>();
69 NS_ENSURE_TRUE(mImages, NS_ERROR_OUT_OF_MEMORY);
70 mLabels =
new nsClassHashtable<nsCStringHashKey, nsString>();
71 NS_ENSURE_TRUE(mLabels, NS_ERROR_OUT_OF_MEMORY);
72 mClickHandlers =
new nsTHashtable<nsISupportsHashKey>();
73 NS_ENSURE_TRUE(mClickHandlers, NS_ERROR_OUT_OF_MEMORY);
76 mClickHandlers->Init();
79 NS_ENSURE_SUCCESS(rv, rv);
93 mClickHandlers = aClickHandlers;
94 aClickHandlers = nsnull;
97 NS_ENSURE_SUCCESS(rv, rv);
161 sbImageLabelLinkPropertyInfo::GetUrlProperty(nsAString& _retval)
169 sbImageLabelLinkPropertyInfo::GetPreventNavigation(
const nsAString& aImageValue,
170 const nsAString& aUrlValue,
173 NS_ENSURE_ARG_POINTER(_retval);
175 *_retval = aImageValue.IsEmpty() || aUrlValue.IsEmpty();
184 sbImageLabelLinkPropertyInfo::AddImage(
const nsACString & aKey,
185 const nsACString & aImageUrl)
187 NS_ENSURE_TRUE(mImages, NS_ERROR_NOT_INITIALIZED);
189 if (mImages->Get(aKey, nsnull)) {
190 NS_WARNING(
"found an existing image key");
194 PRBool success = mImages->Put(aKey,
new nsCString(aImageUrl));
195 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
201 sbImageLabelLinkPropertyInfo::AddLabel(
const nsACString & aKey,
202 const nsAString & aLabel)
204 NS_ENSURE_TRUE(mLabels, NS_ERROR_NOT_INITIALIZED);
206 if (mLabels->Get(aKey, nsnull)) {
207 NS_WARNING(
"found an existing label key");
211 nsString
value(aLabel);
213 if (StringBeginsWith(aLabel, NS_LITERAL_STRING(
"&")) &&
214 StringEndsWith(aLabel, NS_LITERAL_STRING(
";")))
220 PRBool success = mLabels->Put(aKey,
new nsString(
value));
221 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
231 NS_ENSURE_TRUE(mImages, NS_ERROR_NOT_INITIALIZED);
233 NS_LossyConvertUTF16toASCII
key(aValue);
237 if (mImages->Get(key, &result)) {
238 CopyASCIItoUTF16(*result, _retval);
242 if (mImages->Get(nsCString(), &result)) {
243 CopyASCIItoUTF16(*result, _retval);
255 if(aValue.IsEmpty()) {
256 _retval.AssignLiteral(
"image label noLink");
260 _retval.AssignLiteral(
"image label link");
268 const nsAString& aPart,
275 NS_ENSURE_ARG_POINTER(_retval);
276 *_retval = aPart.EqualsLiteral(
"image") ||
277 aPart.EqualsLiteral(
"text");
285 PRBool *_retval NS_OUTPARAM)
287 NS_ENSURE_ARG_POINTER(aItem);
288 NS_ENSURE_ARG_POINTER(_retval);
293 if (!mClickHandlers) {
298 nsCOMPtr<nsIMutableArray>
handlers =
299 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1");
300 NS_ENSURE_TRUE(handlers, NS_ERROR_OUT_OF_MEMORY);
303 nsCOMPtr<nsISimpleEnumerator> enumerator;
304 rv = handlers->Enumerate(getter_AddRefs(enumerator));
305 NS_ENSURE_SUCCESS(rv, rv);
309 while (NS_SUCCEEDED(rv = enumerator->HasMoreElements(&hasMore)) && hasMore) {
310 nsCOMPtr<nsISupports> supports;
311 rv = enumerator->GetNext(getter_AddRefs(supports));
312 NS_ENSURE_SUCCESS(rv, rv);
313 nsCOMPtr<sbIClickablePropertyCallback>
callback =
314 do_QueryInterface(supports);
316 NS_WARNING(
"found a onClick callback that is "
317 "not a sbIClickablePropertyCallback");
320 rv = callback->OnClick(
this,
325 if (NS_SUCCEEDED(rv) && result) {
339 NS_ENSURE_TRUE(mLabels, NS_ERROR_NOT_INITIALIZED);
341 NS_LossyConvertUTF16toASCII
key(aValue);
345 if (mLabels->Get(key, &result)) {
346 _retval.Assign(*result);
350 if (mLabels->Get(nsCString(), &result)) {
351 _retval.Assign(*result);
NS_IMETHOD SetRemoteReadable(PRBool aRemoteReadable)
NS_IMPL_ISUPPORTS_INHERITED1(sbImageLabelLinkPropertyInfo, sbImageLinkPropertyInfo, sbIImageLabelLinkPropertyInfo) sbImageLabelLinkPropertyInfo
nsTHashtable< nsISupportsHashKey > InterfaceSet_t
NS_IMETHOD SetLocalizationKey(const nsAString &aLocalizationKey)
NS_IMETHOD GetImageSrc(const nsAString &aValue, nsAString &_retval)
NS_IMETHOD Format(const nsAString &aValue, nsAString &_retval)
The property information consists of image and label.
NS_IMETHOD SetPropertyID(const nsAString &aPropertyID)
NS_IMETHOD SetUserViewable(PRBool aUserViewable)
nsString mLocalizationKey
NS_IMETHOD SetUserEditable(PRBool aUserEditable)
nsresult sbCopyHashtableToArray(class nsTHashtable< T > &aSource, nsIMutableArray *aDest)
NS_IMETHOD OnClick(sbIMediaItem *aItem, nsISupports *aEvent, nsISupports *aContext, PRBool *_retval)
StringArrayEnumerator prototype hasMore
nsClassHashtable< nsCStringHashKey, nsString > LabelMap_t
NS_IMETHOD SetUrlPropertyID(const nsAString &aUrlPropertyID)
nsClassHashtable< nsCStringHashKey, nsCString > ImageMap_t
NS_IMETHOD HitTest(const nsAString &aCurrentValue, const nsAString &aPart, PRUint32 aBoxWidth, PRUint32 aBoxHeight, PRUint32 aMouseX, PRUint32 aMouseY, PRBool *_retval)
NS_IMETHOD SetDisplayName(const nsAString &aDisplayName)
NS_IMETHOD GetCellProperties(const nsAString &aValue, nsAString &_retval)
virtual ~sbImageLabelLinkPropertyInfo()
NS_IMETHOD SetRemoteWritable(PRBool aRemoteWritable)