WebPositive: Now that it lives in the tree, get rid of the copied shared code.

This commit is contained in:
Stephan Aßmus
2013-06-16 14:06:16 +02:00
parent 3d319aec26
commit 2fd5f1736a
19 changed files with 18 additions and 4710 deletions
-1
View File
@@ -47,7 +47,6 @@
#include "DownloadWindow.h"
#include "SettingsMessage.h"
#include "SettingsWindow.h"
#include "svn_revision.h"
#include "NetworkCookieJar.h"
#include "WebKitInfo.h"
#include "WebPage.h"
+4 -4
View File
@@ -462,19 +462,19 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
}
// Back, Forward, Stop & Home buttons
fBackButton = new IconButton("Back", 0, NULL, new BMessage(GO_BACK));
fBackButton = new BIconButton("Back", NULL, new BMessage(GO_BACK));
fBackButton->SetIcon(201);
fBackButton->TrimIcon();
fForwardButton = new IconButton("Forward", 0, NULL, new BMessage(GO_FORWARD));
fForwardButton = new BIconButton("Forward", NULL, new BMessage(GO_FORWARD));
fForwardButton->SetIcon(202);
fForwardButton->TrimIcon();
fStopButton = new IconButton("Stop", 0, NULL, new BMessage(STOP));
fStopButton = new BIconButton("Stop", NULL, new BMessage(STOP));
fStopButton->SetIcon(204);
fStopButton->TrimIcon();
fHomeButton = new IconButton("Home", 0, NULL, new BMessage(HOME));
fHomeButton = new BIconButton("Home", NULL, new BMessage(HOME));
fHomeButton->SetIcon(206);
fHomeButton->TrimIcon();
if (!fAppSettings->GetValue(kSettingsKeyShowHomeButton, true))
+10 -5
View File
@@ -47,11 +47,16 @@ class BStatusBar;
class BStringView;
class BTextControl;
class BWebView;
class IconButton;
class SettingsMessage;
class TabManager;
class URLInputGroup;
namespace BPrivate {
class BIconButton;
}
using BPrivate::BIconButton;
enum {
INTERFACE_ELEMENT_MENU = 1 << 0,
INTERFACE_ELEMENT_TABS = 1 << 1,
@@ -214,10 +219,10 @@ private:
BMenuItem* fBackMenuItem;
BMenuItem* fForwardMenuItem;
IconButton* fBackButton;
IconButton* fForwardButton;
IconButton* fStopButton;
IconButton* fHomeButton;
BIconButton* fBackButton;
BIconButton* fForwardButton;
BIconButton* fStopButton;
BIconButton* fHomeButton;
URLInputGroup* fURLInputGroup;
BStringView* fStatusText;
BStatusBar* fLoadingProgressBar;
+4 -9
View File
@@ -26,11 +26,8 @@ local sources =
# support
BaseURL.cpp
BitmapButton.cpp
DateTime.cpp
FontSelectionView.cpp
IconButton.cpp
SettingsMessage.cpp
StringForSize.cpp
# tabview
TabContainerView.cpp
@@ -46,7 +43,6 @@ local sources =
DownloadWindow.cpp
SettingsKeys.cpp
SettingsWindow.cpp
svn_revision.cpp
URLInputGroup.cpp
;
@@ -54,12 +50,11 @@ Includes [ FGristFiles $(sources) ] : $(HAIKU_WEBKIT_HEADERS_DEPENDENCY) ;
# Dependency needed to trigger downloading/unzipping the package before
# compiling the files.
# SVN revision
#local svnRevisionFile = [ FGristFiles svn_revision ] ;
#MakeLocate $(svnRevisionFile) : $(LOCATE_TARGET) ;
#CreateSVNRevisionFile $(svnRevisionFile) ;
# private OS headers
UseLibraryHeaders icon ;
UsePrivateHeaders shared tracker ;
SubDirHdrs $(HAIKU_TOP) src kits tracker ;
UsePrivateHeaders shared ;
Application WebPositive :
$(sources)
-178
View File
@@ -1,178 +0,0 @@
/*
* Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef _AUTO_LOCKER_H
#define _AUTO_LOCKER_H
#include <stddef.h>
namespace BPrivate {
// AutoLockerStandardLocking
template<typename Lockable>
class AutoLockerStandardLocking {
public:
inline bool Lock(Lockable* lockable)
{
return lockable->Lock();
}
inline void Unlock(Lockable* lockable)
{
lockable->Unlock();
}
};
// AutoLockerReadLocking
template<typename Lockable>
class AutoLockerReadLocking {
public:
inline bool Lock(Lockable* lockable)
{
return lockable->ReadLock();
}
inline void Unlock(Lockable* lockable)
{
lockable->ReadUnlock();
}
};
// AutoLockerWriteLocking
template<typename Lockable>
class AutoLockerWriteLocking {
public:
inline bool Lock(Lockable* lockable)
{
return lockable->WriteLock();
}
inline void Unlock(Lockable* lockable)
{
lockable->WriteUnlock();
}
};
// AutoLocker
template<typename Lockable,
typename Locking = AutoLockerStandardLocking<Lockable> >
class AutoLocker {
private:
typedef AutoLocker<Lockable, Locking> ThisClass;
public:
inline AutoLocker()
:
fLockable(NULL),
fLocked(false)
{
}
inline AutoLocker(const Locking& locking)
:
fLockable(NULL),
fLocking(locking),
fLocked(false)
{
}
inline AutoLocker(Lockable* lockable, bool alreadyLocked = false,
bool lockIfNotLocked = true)
:
fLockable(lockable),
fLocked(fLockable && alreadyLocked)
{
if (!alreadyLocked && lockIfNotLocked)
Lock();
}
inline AutoLocker(Lockable& lockable, bool alreadyLocked = false,
bool lockIfNotLocked = true)
:
fLockable(&lockable),
fLocked(fLockable && alreadyLocked)
{
if (!alreadyLocked && lockIfNotLocked)
Lock();
}
inline ~AutoLocker()
{
Unlock();
}
inline void SetTo(Lockable* lockable, bool alreadyLocked,
bool lockIfNotLocked = true)
{
Unlock();
fLockable = lockable;
fLocked = (lockable && alreadyLocked);
if (!alreadyLocked && lockIfNotLocked)
Lock();
}
inline void SetTo(Lockable& lockable, bool alreadyLocked,
bool lockIfNotLocked = true)
{
SetTo(&lockable, alreadyLocked, lockIfNotLocked);
}
inline void Unset()
{
Unlock();
Detach();
}
inline bool Lock()
{
if (fLockable && !fLocked)
fLocked = fLocking.Lock(fLockable);
return fLocked;
}
inline void Unlock()
{
if (fLockable && fLocked) {
fLocking.Unlock(fLockable);
fLocked = false;
}
}
inline void Detach()
{
fLockable = NULL;
fLocked = false;
}
inline AutoLocker<Lockable, Locking>& operator=(Lockable* lockable)
{
SetTo(lockable);
return *this;
}
inline AutoLocker<Lockable, Locking>& operator=(Lockable& lockable)
{
SetTo(&lockable);
return *this;
}
inline bool IsLocked() const { return fLocked; }
inline operator bool() const { return fLocked; }
protected:
Lockable* fLockable;
Locking fLocking;
bool fLocked;
};
} // namespace BPrivate
using BPrivate::AutoLocker;
using BPrivate::AutoLockerReadLocking;
using BPrivate::AutoLockerWriteLocking;
#endif // _AUTO_LOCKER_H
File diff suppressed because it is too large Load Diff
-225
View File
@@ -1,225 +0,0 @@
/*
* Copyright 2007-2010, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _DATE_TIME_H_
#define _DATE_TIME_H_
#include <String.h>
class BMessage;
namespace BPrivate {
enum time_type {
B_GMT_TIME,
B_LOCAL_TIME
};
enum diff_type {
B_HOURS_DIFF,
B_MINUTES_DIFF,
B_SECONDS_DIFF,
B_MILLISECONDS_DIFF,
B_MICROSECONDS_DIFF
};
class BTime {
public:
BTime();
BTime(const BTime& other);
BTime(int32 hour, int32 minute, int32 second,
int32 microsecond = 0);
BTime(const BMessage* archive);
~BTime();
status_t Archive(BMessage* into) const;
bool IsValid() const;
bool IsValid(const BTime& time) const;
bool IsValid(int32 hour, int32 minute, int32 second,
int32 microsecond = 0) const;
static BTime CurrentTime(time_type type);
BTime Time() const;
bool SetTime(const BTime& time);
bool SetTime(int32 hour, int32 minute, int32 second,
int32 microsecond = 0);
BTime& AddHours(int32 hours);
BTime& AddMinutes(int32 minutes);
BTime& AddSeconds(int32 seconds);
BTime& AddMilliseconds(int32 milliseconds);
BTime& AddMicroseconds(int32 microseconds);
int32 Hour() const;
int32 Minute() const;
int32 Second() const;
int32 Millisecond() const;
int32 Microsecond() const;
bigtime_t Difference(const BTime& time,
diff_type type) const;
bool operator!=(const BTime& time) const;
bool operator==(const BTime& time) const;
bool operator<(const BTime& time) const;
bool operator<=(const BTime& time) const;
bool operator>(const BTime& time) const;
bool operator>=(const BTime& time) const;
private:
bigtime_t _Microseconds() const;
BTime& _AddMicroseconds(bigtime_t microseconds);
bool _SetTime(bigtime_t hour, bigtime_t minute,
bigtime_t second, bigtime_t microsecond);
private:
bigtime_t fMicroseconds;
};
class BDate {
public:
BDate();
BDate(const BDate& other);
BDate(int32 year, int32 month, int32 day);
BDate(const BMessage* archive);
~BDate();
status_t Archive(BMessage* into) const;
bool IsValid() const;
bool IsValid(const BDate& date) const;
bool IsValid(int32 year, int32 month,
int32 day) const;
static BDate CurrentDate(time_type type);
BDate Date() const;
bool SetDate(const BDate& date);
bool SetDate(int32 year, int32 month, int32 day);
void GetDate(int32* year, int32* month, int32* day);
void AddDays(int32 days);
void AddYears(int32 years);
void AddMonths(int32 months);
int32 Day() const;
int32 Year() const;
int32 Month() const;
int32 Difference(const BDate& date) const;
int32 DayOfWeek() const;
int32 DayOfYear() const;
int32 WeekNumber() const;
bool IsLeapYear(int32 year) const;
int32 DaysInYear() const;
int32 DaysInMonth() const;
BString ShortDayName() const;
static BString ShortDayName(int32 day);
BString ShortMonthName() const;
static BString ShortMonthName(int32 month);
BString LongDayName() const;
static BString LongDayName(int32 day);
BString LongMonthName() const;
static BString LongMonthName(int32 month);
int32 DateToJulianDay() const;
static BDate JulianDayToDate(int32 julianDay);
bool operator!=(const BDate& date) const;
bool operator==(const BDate& date) const;
bool operator<(const BDate& date) const;
bool operator<=(const BDate& date) const;
bool operator>(const BDate& date) const;
bool operator>=(const BDate& date) const;
private:
int32 _DaysInMonth(int32 year, int32 month) const;
bool _SetDate(int32 year, int32 month, int32 day);
int32 _DateToJulianDay(int32 year, int32 month,
int32 day) const;
private:
int32 fDay;
int32 fYear;
int32 fMonth;
};
class BDateTime {
public:
BDateTime();
BDateTime(const BDate &date, const BTime &time);
BDateTime(const BMessage* archive);
~BDateTime();
status_t Archive(BMessage* into) const;
bool IsValid() const;
static BDateTime CurrentDateTime(time_type type);
void SetDateTime(const BDate &date, const BTime &time);
BDate& Date();
const BDate& Date() const;
void SetDate(const BDate &date);
BTime& Time();
const BTime& Time() const;
void SetTime(const BTime &time);
int32 Time_t() const;
void SetTime_t(uint32 seconds);
bool operator!=(const BDateTime& dateTime) const;
bool operator==(const BDateTime& dateTime) const;
bool operator<(const BDateTime& dateTime) const;
bool operator<=(const BDateTime& dateTime) const;
bool operator>(const BDateTime& dateTime) const;
bool operator>=(const BDateTime& dateTime) const;
private:
BDate fDate;
BTime fTime;
};
} // namespace BPrivate
using BPrivate::time_type;
using BPrivate::B_GMT_TIME;
using BPrivate::B_LOCAL_TIME;
using BPrivate::diff_type;
using BPrivate::B_HOURS_DIFF;
using BPrivate::B_MINUTES_DIFF;
using BPrivate::B_SECONDS_DIFF;
using BPrivate::B_MILLISECONDS_DIFF;
using BPrivate::B_MICROSECONDS_DIFF;
using BPrivate::BTime;
using BPrivate::BDate;
using BPrivate::BDateTime;
#endif // _DATE_TIME_H_
-481
View File
@@ -1,481 +0,0 @@
// HashMap.h
//
// Copyright (c) 2004-2007, Ingo Weinhold ([email protected])
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of a copyright holder shall
// not be used in advertising or otherwise to promote the sale, use or other
// dealings in this Software without prior written authorization of the
// copyright holder.
#ifndef HASH_MAP_H
#define HASH_MAP_H
#include <Locker.h>
#include "AutoLocker.h"
#include "OpenHashTable.h"
namespace BPrivate {
// HashMapElement
template<typename Key, typename Value>
class HashMapElement : public OpenHashElement {
private:
typedef HashMapElement<Key, Value> Element;
public:
HashMapElement() : OpenHashElement(), fKey(), fValue()
{
fNext = -1;
}
inline uint32 Hash() const
{
return fKey.GetHashCode();
}
inline bool operator==(const OpenHashElement &_element) const
{
const Element &element = static_cast<const Element&>(_element);
return (fKey == element.fKey);
}
inline void Adopt(Element &element)
{
fKey = element.fKey;
fValue = element.fValue;
}
Key fKey;
Value fValue;
};
// HashMap
template<typename Key, typename Value>
class HashMap {
public:
class Entry {
public:
Entry() {}
Entry(const Key& key, Value value) : key(key), value(value) {}
Key key;
Value value;
};
class Iterator {
private:
typedef HashMapElement<Key, Value> Element;
public:
Iterator(const Iterator& other)
:
fMap(other.fMap),
fIndex(other.fIndex),
fElement(other.fElement),
fLastElement(other.fElement)
{
}
bool HasNext() const
{
return fElement;
}
Entry Next()
{
if (!fElement)
return Entry();
Entry result(fElement->fKey, fElement->fValue);
_FindNext();
return result;
}
Value* NextValue()
{
if (fElement == NULL)
return NULL;
Value* value = &fElement->fValue;
_FindNext();
return value;
}
Entry Remove()
{
if (!fLastElement)
return Entry();
Entry result(fLastElement->fKey, fLastElement->fValue);
fMap->fTable.Remove(fLastElement, true);
fLastElement = NULL;
return result;
}
Iterator& operator=(const Iterator& other)
{
fMap = other.fMap;
fIndex = other.fIndex;
fElement = other.fElement;
fLastElement = other.fLastElement;
return *this;
}
private:
Iterator(const HashMap<Key, Value>* map)
:
fMap(const_cast<HashMap<Key, Value>*>(map)),
fIndex(0),
fElement(NULL),
fLastElement(NULL)
{
// find first
_FindNext();
}
void _FindNext()
{
fLastElement = fElement;
if (fElement && fElement->fNext >= 0) {
fElement = fMap->fTable.ElementAt(fElement->fNext);
return;
}
fElement = NULL;
int32 arraySize = fMap->fTable.ArraySize();
for (; !fElement && fIndex < arraySize; fIndex++)
fElement = fMap->fTable.FindFirst(fIndex);
}
private:
friend class HashMap<Key, Value>;
HashMap<Key, Value>* fMap;
int32 fIndex;
Element* fElement;
Element* fLastElement;
};
HashMap();
~HashMap();
status_t InitCheck() const;
status_t Put(const Key& key, Value value);
Value Remove(const Key& key);
void Clear();
Value Get(const Key& key) const;
bool Get(const Key& key, Value*& _value) const;
bool ContainsKey(const Key& key) const;
int32 Size() const;
Iterator GetIterator() const;
protected:
typedef HashMapElement<Key, Value> Element;
friend class Iterator;
private:
Element *_FindElement(const Key& key) const;
protected:
OpenHashElementArray<Element> fElementArray;
OpenHashTable<Element, OpenHashElementArray<Element> > fTable;
};
// SynchronizedHashMap
template<typename Key, typename Value>
class SynchronizedHashMap : public BLocker {
public:
typedef struct HashMap<Key, Value>::Entry Entry;
typedef struct HashMap<Key, Value>::Iterator Iterator;
SynchronizedHashMap() : BLocker("synchronized hash map") {}
~SynchronizedHashMap() { Lock(); }
status_t InitCheck() const
{
return fMap.InitCheck();
}
status_t Put(const Key& key, Value value)
{
MapLocker locker(this);
if (!locker.IsLocked())
return B_ERROR;
return fMap.Put(key, value);
}
Value Remove(const Key& key)
{
MapLocker locker(this);
if (!locker.IsLocked())
return Value();
return fMap.Remove(key);
}
void Clear()
{
MapLocker locker(this);
return fMap.Clear();
}
Value Get(const Key& key) const
{
const BLocker* lock = this;
MapLocker locker(const_cast<BLocker*>(lock));
if (!locker.IsLocked())
return Value();
return fMap.Get(key);
}
bool ContainsKey(const Key& key) const
{
const BLocker* lock = this;
MapLocker locker(const_cast<BLocker*>(lock));
if (!locker.IsLocked())
return false;
return fMap.ContainsKey(key);
}
int32 Size() const
{
const BLocker* lock = this;
MapLocker locker(const_cast<BLocker*>(lock));
return fMap.Size();
}
Iterator GetIterator()
{
return fMap.GetIterator();
}
// for debugging only
const HashMap<Key, Value>& GetUnsynchronizedMap() const { return fMap; }
HashMap<Key, Value>& GetUnsynchronizedMap() { return fMap; }
protected:
typedef AutoLocker<BLocker> MapLocker;
HashMap<Key, Value> fMap;
};
// HashKey32
template<typename Value>
struct HashKey32 {
HashKey32() {}
HashKey32(const Value& value) : value(value) {}
uint32 GetHashCode() const
{
return (uint32)value;
}
HashKey32<Value> operator=(const HashKey32<Value>& other)
{
value = other.value;
return *this;
}
bool operator==(const HashKey32<Value>& other) const
{
return (value == other.value);
}
bool operator!=(const HashKey32<Value>& other) const
{
return (value != other.value);
}
Value value;
};
// HashKey64
template<typename Value>
struct HashKey64 {
HashKey64() {}
HashKey64(const Value& value) : value(value) {}
uint32 GetHashCode() const
{
uint64 v = (uint64)value;
return (uint32)(v >> 32) ^ (uint32)v;
}
HashKey64<Value> operator=(const HashKey64<Value>& other)
{
value = other.value;
return *this;
}
bool operator==(const HashKey64<Value>& other) const
{
return (value == other.value);
}
bool operator!=(const HashKey64<Value>& other) const
{
return (value != other.value);
}
Value value;
};
// HashMap
// constructor
template<typename Key, typename Value>
HashMap<Key, Value>::HashMap()
:
fElementArray(1000),
fTable(1000, &fElementArray)
{
}
// destructor
template<typename Key, typename Value>
HashMap<Key, Value>::~HashMap()
{
}
// InitCheck
template<typename Key, typename Value>
status_t
HashMap<Key, Value>::InitCheck() const
{
return (fTable.InitCheck() && fElementArray.InitCheck()
? B_OK : B_NO_MEMORY);
}
// Put
template<typename Key, typename Value>
status_t
HashMap<Key, Value>::Put(const Key& key, Value value)
{
Element* element = _FindElement(key);
if (element) {
// already contains the key: just set the new value
element->fValue = value;
return B_OK;
}
// does not contain the key yet: add an element
element = fTable.Add(key.GetHashCode());
if (!element)
return B_NO_MEMORY;
element->fKey = key;
element->fValue = value;
return B_OK;
}
// Remove
template<typename Key, typename Value>
Value
HashMap<Key, Value>::Remove(const Key& key)
{
Value value = Value();
if (Element* element = _FindElement(key)) {
value = element->fValue;
fTable.Remove(element);
}
return value;
}
// Clear
template<typename Key, typename Value>
void
HashMap<Key, Value>::Clear()
{
fTable.RemoveAll();
}
// Get
template<typename Key, typename Value>
Value
HashMap<Key, Value>::Get(const Key& key) const
{
if (Element* element = _FindElement(key))
return element->fValue;
return Value();
}
// Get
template<typename Key, typename Value>
bool
HashMap<Key, Value>::Get(const Key& key, Value*& _value) const
{
if (Element* element = _FindElement(key)) {
_value = &element->fValue;
return true;
}
return false;
}
// ContainsKey
template<typename Key, typename Value>
bool
HashMap<Key, Value>::ContainsKey(const Key& key) const
{
return _FindElement(key);
}
// Size
template<typename Key, typename Value>
int32
HashMap<Key, Value>::Size() const
{
return fTable.CountElements();
}
// GetIterator
template<typename Key, typename Value>
struct HashMap<Key, Value>::Iterator
HashMap<Key, Value>::GetIterator() const
{
return Iterator(this);
}
// _FindElement
template<typename Key, typename Value>
struct HashMap<Key, Value>::Element *
HashMap<Key, Value>::_FindElement(const Key& key) const
{
Element* element = fTable.FindFirst(key.GetHashCode());
while (element && element->fKey != key) {
if (element->fNext >= 0)
element = fTable.ElementAt(element->fNext);
else
element = NULL;
}
return element;
}
} // namespace BPrivate
using BPrivate::HashMap;
using BPrivate::HashKey32;
using BPrivate::HashKey64;
using BPrivate::SynchronizedHashMap;
#endif // HASH_MAP_H
-342
View File
@@ -1,342 +0,0 @@
// HashSet.h
//
// Copyright (c) 2004, Ingo Weinhold ([email protected])
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of a copyright holder shall
// not be used in advertising or otherwise to promote the sale, use or other
// dealings in this Software without prior written authorization of the
// copyright holder.
#ifndef HASH_SET_H
#define HASH_SET_H
#include <Locker.h>
#include "AutoLocker.h"
#include "OpenHashTable.h"
namespace BPrivate {
// HashSetElement
template<typename Key>
class HashSetElement : public OpenHashElement {
private:
typedef HashSetElement<Key> Element;
public:
HashSetElement() : OpenHashElement(), fKey()
{
fNext = -1;
}
inline uint32 Hash() const
{
return fKey.GetHashCode();
}
inline bool operator==(const OpenHashElement &_element) const
{
const Element &element = static_cast<const Element&>(_element);
return (fKey == element.fKey);
}
inline void Adopt(Element &element)
{
fKey = element.fKey;
}
Key fKey;
};
// HashSet
template<typename Key>
class HashSet {
public:
class Iterator {
private:
typedef HashSetElement<Key> Element;
public:
Iterator(const Iterator& other)
: fSet(other.fSet),
fIndex(other.fIndex),
fElement(other.fElement),
fLastElement(other.fElement)
{
}
bool HasNext() const
{
return fElement;
}
Key Next()
{
if (!fElement)
return Key();
Key result(fElement->fKey);
_FindNext();
return result;
}
bool Remove()
{
if (!fLastElement)
return false;
fSet->fTable.Remove(fLastElement);
fLastElement = NULL;
return true;
}
Iterator& operator=(const Iterator& other)
{
fSet = other.fSet;
fIndex = other.fIndex;
fElement = other.fElement;
fLastElement = other.fLastElement;
return *this;
}
private:
Iterator(HashSet<Key>* map)
: fSet(map),
fIndex(0),
fElement(NULL),
fLastElement(NULL)
{
// find first
_FindNext();
}
void _FindNext()
{
fLastElement = fElement;
if (fElement && fElement->fNext >= 0) {
fElement = fSet->fTable.ElementAt(fElement->fNext);
return;
}
fElement = NULL;
int32 arraySize = fSet->fTable.ArraySize();
for (; !fElement && fIndex < arraySize; fIndex++)
fElement = fSet->fTable.FindFirst(fIndex);
}
private:
friend class HashSet<Key>;
HashSet<Key>* fSet;
int32 fIndex;
Element* fElement;
Element* fLastElement;
};
HashSet();
~HashSet();
status_t InitCheck() const;
status_t Add(const Key& key);
bool Remove(const Key& key);
void Clear();
bool Contains(const Key& key) const;
int32 Size() const;
bool IsEmpty() const { return Size() == 0; }
Iterator GetIterator();
protected:
typedef HashSetElement<Key> Element;
friend class Iterator;
private:
Element *_FindElement(const Key& key) const;
protected:
OpenHashElementArray<Element> fElementArray;
OpenHashTable<Element, OpenHashElementArray<Element> > fTable;
};
// SynchronizedHashSet
template<typename Key>
class SynchronizedHashSet : public BLocker {
public:
typedef struct HashSet<Key>::Iterator Iterator;
SynchronizedHashSet() : BLocker("synchronized hash set") {}
~SynchronizedHashSet() { Lock(); }
status_t InitCheck() const
{
return fSet.InitCheck();
}
status_t Add(const Key& key)
{
MapLocker locker(this);
if (!locker.IsLocked())
return B_ERROR;
return fSet.Add(key);
}
bool Remove(const Key& key)
{
MapLocker locker(this);
if (!locker.IsLocked())
return false;
return fSet.Remove(key);
}
bool Contains(const Key& key) const
{
const BLocker* lock = this;
MapLocker locker(const_cast<BLocker*>(lock));
if (!locker.IsLocked())
return false;
return fSet.Contains(key);
}
int32 Size() const
{
const BLocker* lock = this;
MapLocker locker(const_cast<BLocker*>(lock));
return fSet.Size();
}
Iterator GetIterator()
{
return fSet.GetIterator();
}
// for debugging only
const HashSet<Key>& GetUnsynchronizedSet() const { return fSet; }
HashSet<Key>& GetUnsynchronizedSet() { return fSet; }
protected:
typedef AutoLocker<BLocker> MapLocker;
HashSet<Key> fSet;
};
// HashSet
// constructor
template<typename Key>
HashSet<Key>::HashSet()
: fElementArray(1000),
fTable(1000, &fElementArray)
{
}
// destructor
template<typename Key>
HashSet<Key>::~HashSet()
{
}
// InitCheck
template<typename Key>
status_t
HashSet<Key>::InitCheck() const
{
return (fTable.InitCheck() && fElementArray.InitCheck()
? B_OK : B_NO_MEMORY);
}
// Add
template<typename Key>
status_t
HashSet<Key>::Add(const Key& key)
{
if (Contains(key))
return B_OK;
Element* element = fTable.Add(key.GetHashCode());
if (!element)
return B_NO_MEMORY;
element->fKey = key;
return B_OK;
}
// Remove
template<typename Key>
bool
HashSet<Key>::Remove(const Key& key)
{
if (Element* element = _FindElement(key)) {
fTable.Remove(element);
return true;
}
return false;
}
// Clear
template<typename Key>
void
HashSet<Key>::Clear()
{
fTable.RemoveAll();
}
// Contains
template<typename Key>
bool
HashSet<Key>::Contains(const Key& key) const
{
return _FindElement(key);
}
// Size
template<typename Key>
int32
HashSet<Key>::Size() const
{
return fTable.CountElements();
}
// GetIterator
template<typename Key>
struct HashSet<Key>::Iterator
HashSet<Key>::GetIterator()
{
return Iterator(this);
}
// _FindElement
template<typename Key>
struct HashSet<Key>::Element *
HashSet<Key>::_FindElement(const Key& key) const
{
Element* element = fTable.FindFirst(key.GetHashCode());
while (element && element->fKey != key) {
if (element->fNext >= 0)
element = fTable.ElementAt(element->fNext);
else
element = NULL;
}
return element;
}
} // namespace BPrivate
using BPrivate::HashSet;
using BPrivate::SynchronizedHashSet;
#endif // HASH_SET_H
-929
View File
@@ -1,929 +0,0 @@
/*
* Copyright 2006-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
// NOTE: this file is a duplicate of the version in Icon-O-Matic/generic
// it should be placed into a common folder for generic useful stuff
#include "IconButton.h"
#include <new>
#include <stdio.h>
#include <Application.h>
#include <Bitmap.h>
#include <Control.h>
#include <ControlLook.h>
#include <Entry.h>
#include <Looper.h>
#include <Message.h>
#include <Mime.h>
#include <Path.h>
#include <Region.h>
#include <Resources.h>
#include <Roster.h>
#include <TranslationUtils.h>
#include <Window.h>
#include "IconUtils.h"
using std::nothrow;
// constructor
IconButton::IconButton(const char* name, uint32 id, const char* label,
BMessage* message, BHandler* target)
: BView(name, B_WILL_DRAW),
BInvoker(message, target),
fButtonState(STATE_ENABLED),
fID(id),
fNormalBitmap(NULL),
fDisabledBitmap(NULL),
fClickedBitmap(NULL),
fDisabledClickedBitmap(NULL),
fLabel(label),
fTargetCache(target)
{
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetViewColor(B_TRANSPARENT_32_BIT);
}
// destructor
IconButton::~IconButton()
{
_DeleteBitmaps();
}
// MessageReceived
void
IconButton::MessageReceived(BMessage* message)
{
switch (message->what) {
default:
BView::MessageReceived(message);
break;
}
}
// AttachedToWindow
void
IconButton::AttachedToWindow()
{
rgb_color background = B_TRANSPARENT_COLOR;
if (BView* parent = Parent()) {
background = parent->ViewColor();
if (background == B_TRANSPARENT_COLOR)
background = parent->LowColor();
}
if (background == B_TRANSPARENT_COLOR)
background = ui_color(B_PANEL_BACKGROUND_COLOR);
SetLowColor(background);
SetTarget(fTargetCache);
if (!Target())
SetTarget(Window());
}
// Draw
void
IconButton::Draw(BRect area)
{
rgb_color background = LowColor();
BRect r(Bounds());
if (be_control_look != NULL) {
uint32 flags = 0;
BBitmap* bitmap = fNormalBitmap;
if (!IsEnabled()) {
flags |= BControlLook::B_DISABLED;
bitmap = fDisabledBitmap;
}
if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED))
flags |= BControlLook::B_ACTIVATED;
if (DrawBorder()) {
be_control_look->DrawButtonFrame(this, r, area, background,
background, flags);
be_control_look->DrawButtonBackground(this, r, area, background,
flags);
} else {
SetHighColor(background);
FillRect(r);
}
if (bitmap && bitmap->IsValid()) {
float x = r.left + floorf((r.Width()
- bitmap->Bounds().Width()) / 2.0 + 0.5);
float y = r.top + floorf((r.Height()
- bitmap->Bounds().Height()) / 2.0 + 0.5);
BPoint point(x, y);
if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED))
point += BPoint(1.0, 1.0);
if (bitmap->ColorSpace() == B_RGBA32
|| bitmap->ColorSpace() == B_RGBA32_BIG) {
SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
}
DrawBitmap(bitmap, point);
}
return;
}
rgb_color lightShadow, shadow, darkShadow, light;
BBitmap* bitmap = fNormalBitmap;
// adjust colors and bitmap according to flags
if (IsEnabled()) {
lightShadow = tint_color(background, B_DARKEN_1_TINT);
shadow = tint_color(background, B_DARKEN_2_TINT);
darkShadow = tint_color(background, B_DARKEN_4_TINT);
light = tint_color(background, B_LIGHTEN_MAX_TINT);
SetHighColor(0, 0, 0, 255);
} else {
lightShadow = tint_color(background, 1.11);
shadow = tint_color(background, B_DARKEN_1_TINT);
darkShadow = tint_color(background, B_DARKEN_2_TINT);
light = tint_color(background, B_LIGHTEN_2_TINT);
bitmap = fDisabledBitmap;
SetHighColor(tint_color(background, B_DISABLED_LABEL_TINT));
}
if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED)) {
if (IsEnabled()) {
// background = tint_color(background, B_DARKEN_2_TINT);
// background = tint_color(background, B_LIGHTEN_1_TINT);
background = tint_color(background, B_DARKEN_1_TINT);
bitmap = fClickedBitmap;
} else {
// background = tint_color(background, B_DARKEN_1_TINT);
// background = tint_color(background, (B_NO_TINT + B_LIGHTEN_1_TINT) / 2.0);
background = tint_color(background, (B_NO_TINT + B_DARKEN_1_TINT) / 2.0);
bitmap = fDisabledClickedBitmap;
}
// background
SetLowColor(background);
r.InsetBy(2.0, 2.0);
StrokeLine(r.LeftBottom(), r.LeftTop(), B_SOLID_LOW);
StrokeLine(r.LeftTop(), r.RightTop(), B_SOLID_LOW);
r.InsetBy(-2.0, -2.0);
}
// draw frame only if tracking
if (DrawBorder()) {
if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED))
DrawPressedBorder(r, background, shadow, darkShadow, lightShadow, light);
else
DrawNormalBorder(r, background, shadow, darkShadow, lightShadow, light);
r.InsetBy(2.0, 2.0);
} else
_DrawFrame(r, background, background, background, background);
float width = Bounds().Width();
float height = Bounds().Height();
// bitmap
BRegion originalClippingRegion;
if (bitmap && bitmap->IsValid()) {
float x = floorf((width - bitmap->Bounds().Width()) / 2.0 + 0.5);
float y = floorf((height - bitmap->Bounds().Height()) / 2.0 + 0.5);
BPoint point(x, y);
if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED))
point += BPoint(1.0, 1.0);
if (bitmap->ColorSpace() == B_RGBA32 || bitmap->ColorSpace() == B_RGBA32_BIG) {
FillRect(r, B_SOLID_LOW);
SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
}
DrawBitmap(bitmap, point);
// constrain clipping region
BRegion region= originalClippingRegion;
GetClippingRegion(&region);
region.Exclude(bitmap->Bounds().OffsetByCopy(point));
ConstrainClippingRegion(&region);
}
// background
SetDrawingMode(B_OP_COPY);
FillRect(r, B_SOLID_LOW);
ConstrainClippingRegion(NULL);
// label
if (fLabel.CountChars() > 0) {
SetDrawingMode(B_OP_COPY);
font_height fh;
GetFontHeight(&fh);
float y = Bounds().bottom - 4.0;
y -= fh.descent;
float x = (width - StringWidth(fLabel.String())) / 2.0;
DrawString(fLabel.String(), BPoint(x, y));
}
}
// MouseDown
void
IconButton::MouseDown(BPoint where)
{
if (!IsValid())
return;
if (_HasFlags(STATE_ENABLED)/* && !_HasFlags(STATE_FORCE_PRESSED)*/) {
if (Bounds().Contains(where)) {
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
_AddFlags(STATE_PRESSED | STATE_TRACKING);
} else {
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
}
}
}
// MouseUp
void
IconButton::MouseUp(BPoint where)
{
if (!IsValid())
return;
// if (!_HasFlags(STATE_FORCE_PRESSED)) {
if (_HasFlags(STATE_ENABLED) && _HasFlags(STATE_PRESSED) && Bounds().Contains(where))
Invoke();
else if (Bounds().Contains(where))
_AddFlags(STATE_INSIDE);
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
// }
}
// MouseMoved
void
IconButton::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
{
if (!IsValid())
return;
uint32 buttons = 0;
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
// catch a mouse up event that we might have missed
if (!buttons && _HasFlags(STATE_PRESSED)) {
MouseUp(where);
return;
}
if (buttons && !_HasFlags(STATE_TRACKING))
return;
if ((transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW)
&& _HasFlags(STATE_ENABLED))
_AddFlags(STATE_INSIDE);
else
_ClearFlags(STATE_INSIDE);
if (_HasFlags(STATE_TRACKING)) {
if (Bounds().Contains(where))
_AddFlags(STATE_PRESSED);
else
_ClearFlags(STATE_PRESSED);
}
}
#define MIN_SPACE 15.0
// GetPreferredSize
void
IconButton::GetPreferredSize(float* width, float* height)
{
float minWidth = 0.0;
float minHeight = 0.0;
if (IsValid()) {
minWidth += fNormalBitmap->Bounds().IntegerWidth() + 1.0;
minHeight += fNormalBitmap->Bounds().IntegerHeight() + 1.0;
}
if (minWidth < MIN_SPACE)
minWidth = MIN_SPACE;
if (minHeight < MIN_SPACE)
minHeight = MIN_SPACE;
float hPadding = max_c(6.0, ceilf(minHeight / 4.0));
float vPadding = max_c(6.0, ceilf(minWidth / 4.0));
if (fLabel.CountChars() > 0) {
font_height fh;
GetFontHeight(&fh);
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
minWidth += StringWidth(fLabel.String()) + vPadding;
}
if (width)
*width = minWidth + hPadding;
if (height)
*height = minHeight + vPadding;
}
// MinSize
BSize
IconButton::MinSize()
{
BSize size;
GetPreferredSize(&size.width, &size.height);
return size;
}
// MaxSize
BSize
IconButton::MaxSize()
{
return MinSize();
}
// Invoke
status_t
IconButton::Invoke(BMessage* message)
{
if (!message)
message = Message();
if (message) {
BMessage clone(*message);
clone.AddInt64("be:when", system_time());
clone.AddPointer("be:source", (BView*)this);
clone.AddInt32("be:value", Value());
clone.AddInt32("id", ID());
return BInvoker::Invoke(&clone);
}
return BInvoker::Invoke(message);
}
// SetPressed
void
IconButton::SetPressed(bool pressed)
{
if (pressed)
_AddFlags(STATE_FORCE_PRESSED);
else
_ClearFlags(STATE_FORCE_PRESSED);
}
// IsPressed
bool
IconButton::IsPressed() const
{
return _HasFlags(STATE_FORCE_PRESSED);
}
status_t
IconButton::SetIcon(int32 resourceID)
{
app_info info;
status_t status = be_app->GetAppInfo(&info);
if (status != B_OK)
return status;
BResources resources(&info.ref);
status = resources.InitCheck();
if (status != B_OK)
return status;
size_t size;
const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, resourceID,
&size);
if (data != NULL) {
BBitmap bitmap(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_RGBA32);
status = bitmap.InitCheck();
if (status != B_OK)
return status;
status = BIconUtils::GetVectorIcon(reinterpret_cast<const uint8*>(data),
size, &bitmap);
if (status != B_OK)
return status;
return SetIcon(&bitmap);
}
// const void* data = resources.LoadResource(B_BITMAP_TYPE, resourceID, &size);
return B_ERROR;
}
// SetIcon
status_t
IconButton::SetIcon(const char* pathToBitmap)
{
if (pathToBitmap == NULL)
return B_BAD_VALUE;
status_t status = B_BAD_VALUE;
BBitmap* fileBitmap = NULL;
// try to load bitmap from either relative or absolute path
BEntry entry(pathToBitmap, true);
if (!entry.Exists()) {
app_info info;
status = be_app->GetAppInfo(&info);
if (status == B_OK) {
BEntry app_entry(&info.ref, true);
BPath path;
app_entry.GetPath(&path);
status = path.InitCheck();
if (status == B_OK) {
status = path.GetParent(&path);
if (status == B_OK) {
status = path.Append(pathToBitmap, true);
if (status == B_OK)
fileBitmap = BTranslationUtils::GetBitmap(path.Path());
else
printf("IconButton::SetIcon() - path.Append() failed: %s\n", strerror(status));
} else
printf("IconButton::SetIcon() - path.GetParent() failed: %s\n", strerror(status));
} else
printf("IconButton::SetIcon() - path.InitCheck() failed: %s\n", strerror(status));
} else
printf("IconButton::SetIcon() - be_app->GetAppInfo() failed: %s\n", strerror(status));
} else
fileBitmap = BTranslationUtils::GetBitmap(pathToBitmap);
if (fileBitmap) {
status = _MakeBitmaps(fileBitmap);
delete fileBitmap;
} else
status = B_ERROR;
return status;
}
// SetIcon
status_t
IconButton::SetIcon(const BBitmap* bitmap)
{
if (bitmap && bitmap->ColorSpace() == B_CMAP8) {
status_t status = bitmap->InitCheck();
if (status >= B_OK) {
if (BBitmap* rgb32Bitmap = _ConvertToRGB32(bitmap)) {
status = _MakeBitmaps(rgb32Bitmap);
delete rgb32Bitmap;
} else
status = B_NO_MEMORY;
}
return status;
} else
return _MakeBitmaps(bitmap);
}
// SetIcon
status_t
IconButton::SetIcon(const BMimeType* fileType, bool small)
{
status_t status = fileType ? fileType->InitCheck() : B_BAD_VALUE;
if (status >= B_OK) {
BBitmap* mimeBitmap = new(nothrow) BBitmap(BRect(0.0, 0.0, 15.0, 15.0), B_CMAP8);
if (mimeBitmap && mimeBitmap->IsValid()) {
status = fileType->GetIcon(mimeBitmap, small ? B_MINI_ICON : B_LARGE_ICON);
if (status >= B_OK) {
if (BBitmap* bitmap = _ConvertToRGB32(mimeBitmap)) {
status = _MakeBitmaps(bitmap);
delete bitmap;
} else
printf("IconButton::SetIcon() - B_RGB32 bitmap is not valid\n");
} else
printf("IconButton::SetIcon() - fileType->GetIcon() failed: %s\n", strerror(status));
} else
printf("IconButton::SetIcon() - B_CMAP8 bitmap is not valid\n");
delete mimeBitmap;
} else
printf("IconButton::SetIcon() - fileType is not valid: %s\n", strerror(status));
return status;
}
// SetIcon
status_t
IconButton::SetIcon(const unsigned char* bitsFromQuickRes,
uint32 width, uint32 height, color_space format, bool convertToBW)
{
status_t status = B_BAD_VALUE;
if (bitsFromQuickRes && width > 0 && height > 0) {
BBitmap* quickResBitmap = new(nothrow) BBitmap(BRect(0.0, 0.0, width - 1.0, height - 1.0), format);
status = quickResBitmap ? quickResBitmap->InitCheck() : B_ERROR;
if (status >= B_OK) {
// It doesn't look right to copy BitsLength() bytes, but bitmaps
// exported from QuickRes still contain their padding, so it is alright.
memcpy(quickResBitmap->Bits(), bitsFromQuickRes, quickResBitmap->BitsLength());
if (format != B_RGB32 && format != B_RGBA32 && format != B_RGB32_BIG && format != B_RGBA32_BIG) {
// colorspace needs conversion
BBitmap* bitmap = new(nothrow) BBitmap(quickResBitmap->Bounds(), B_RGB32, true);
if (bitmap && bitmap->IsValid()) {
BView* helper = new BView(bitmap->Bounds(), "helper",
B_FOLLOW_NONE, B_WILL_DRAW);
if (bitmap->Lock()) {
bitmap->AddChild(helper);
helper->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
helper->FillRect(helper->Bounds());
helper->SetDrawingMode(B_OP_OVER);
helper->DrawBitmap(quickResBitmap, BPoint(0.0, 0.0));
helper->Sync();
bitmap->Unlock();
}
status = _MakeBitmaps(bitmap);
} else
printf("IconButton::SetIcon() - B_RGB32 bitmap is not valid\n");
delete bitmap;
} else {
// native colorspace (32 bits)
if (convertToBW) {
// convert to gray scale icon
uint8* bits = (uint8*)quickResBitmap->Bits();
uint32 bpr = quickResBitmap->BytesPerRow();
for (uint32 y = 0; y < height; y++) {
uint8* handle = bits;
uint8 gray;
for (uint32 x = 0; x < width; x++) {
gray = uint8((116 * handle[0] + 600 * handle[1] + 308 * handle[2]) / 1024);
handle[0] = gray;
handle[1] = gray;
handle[2] = gray;
handle += 4;
}
bits += bpr;
}
}
status = _MakeBitmaps(quickResBitmap);
}
} else
printf("IconButton::SetIcon() - error allocating bitmap: %s\n", strerror(status));
delete quickResBitmap;
}
return status;
}
// ClearIcon
void
IconButton::ClearIcon()
{
_DeleteBitmaps();
_Update();
}
void
IconButton::TrimIcon(bool keepAspect)
{
if (fNormalBitmap == NULL)
return;
uint8* bits = (uint8*)fNormalBitmap->Bits();
uint32 bpr = fNormalBitmap->BytesPerRow();
uint32 width = fNormalBitmap->Bounds().IntegerWidth() + 1;
uint32 height = fNormalBitmap->Bounds().IntegerHeight() + 1;
BRect trimmed(LONG_MAX, LONG_MAX, LONG_MIN, LONG_MIN);
for (uint32 y = 0; y < height; y++) {
uint8* b = bits + 3;
bool rowHasAlpha = false;
for (uint32 x = 0; x < width; x++) {
if (*b) {
rowHasAlpha = true;
if (x < trimmed.left)
trimmed.left = x;
if (x > trimmed.right)
trimmed.right = x;
}
b += 4;
}
if (rowHasAlpha) {
if (y < trimmed.top)
trimmed.top = y;
if (y > trimmed.bottom)
trimmed.bottom = y;
}
bits += bpr;
}
if (!trimmed.IsValid())
return;
if (keepAspect) {
float minInset = trimmed.left;
minInset = min_c(minInset, trimmed.top);
minInset = min_c(minInset, fNormalBitmap->Bounds().right - trimmed.right);
minInset = min_c(minInset, fNormalBitmap->Bounds().bottom - trimmed.bottom);
trimmed = fNormalBitmap->Bounds().InsetByCopy(minInset, minInset);
}
trimmed = trimmed & fNormalBitmap->Bounds();
BBitmap trimmedBitmap(trimmed.OffsetToCopy(B_ORIGIN),
B_BITMAP_NO_SERVER_LINK, B_RGBA32);
bits = (uint8*)fNormalBitmap->Bits();
bits += 4 * (int32)trimmed.left + bpr * (int32)trimmed.top;
uint8* dst = (uint8*)trimmedBitmap.Bits();
uint32 trimmedWidth = trimmedBitmap.Bounds().IntegerWidth() + 1;
uint32 trimmedHeight = trimmedBitmap.Bounds().IntegerHeight() + 1;
uint32 trimmedBPR = trimmedBitmap.BytesPerRow();
for (uint32 y = 0; y < trimmedHeight; y++) {
memcpy(dst, bits, trimmedWidth * 4);
dst += trimmedBPR;
bits += bpr;
}
SetIcon(&trimmedBitmap);
}
// Bitmap
BBitmap*
IconButton::Bitmap() const
{
BBitmap* bitmap = NULL;
if (fNormalBitmap && fNormalBitmap->IsValid()) {
bitmap = new(nothrow) BBitmap(fNormalBitmap);
if (bitmap->IsValid()) {
// TODO: remove this functionality when we use real transparent bitmaps
uint8* bits = (uint8*)bitmap->Bits();
uint32 bpr = bitmap->BytesPerRow();
uint32 width = bitmap->Bounds().IntegerWidth() + 1;
uint32 height = bitmap->Bounds().IntegerHeight() + 1;
color_space format = bitmap->ColorSpace();
if (format == B_CMAP8) {
// replace gray with magic transparent index
} else if (format == B_RGB32) {
for (uint32 y = 0; y < height; y++) {
uint8* bitsHandle = bits;
for (uint32 x = 0; x < width; x++) {
if (bitsHandle[0] == 216
&& bitsHandle[1] == 216
&& bitsHandle[2] == 216) {
bitsHandle[3] = 0; // make this pixel completely transparent
}
bitsHandle += 4;
}
bits += bpr;
}
}
} else {
delete bitmap;
bitmap = NULL;
}
}
return bitmap;
}
// DrawBorder
bool
IconButton::DrawBorder() const
{
return ((IsEnabled() && (_HasFlags(STATE_INSIDE)
|| _HasFlags(STATE_TRACKING))) || _HasFlags(STATE_FORCE_PRESSED));
}
// DrawNormalBorder
void
IconButton::DrawNormalBorder(BRect r, rgb_color background,
rgb_color shadow, rgb_color darkShadow,
rgb_color lightShadow, rgb_color light)
{
_DrawFrame(r, shadow, darkShadow, light, lightShadow);
}
// DrawPressedBorder
void
IconButton::DrawPressedBorder(BRect r, rgb_color background,
rgb_color shadow, rgb_color darkShadow,
rgb_color lightShadow, rgb_color light)
{
_DrawFrame(r, shadow, light, darkShadow, background);
}
// IsValid
bool
IconButton::IsValid() const
{
return (fNormalBitmap && fDisabledBitmap && fClickedBitmap
&& fDisabledClickedBitmap
&& fNormalBitmap->IsValid()
&& fDisabledBitmap->IsValid()
&& fClickedBitmap->IsValid()
&& fDisabledClickedBitmap->IsValid());
}
// Value
int32
IconButton::Value() const
{
return _HasFlags(STATE_PRESSED) ? B_CONTROL_ON : B_CONTROL_OFF;
}
// SetValue
void
IconButton::SetValue(int32 value)
{
if (value)
_AddFlags(STATE_PRESSED);
else
_ClearFlags(STATE_PRESSED);
}
// IsEnabled
bool
IconButton::IsEnabled() const
{
return _HasFlags(STATE_ENABLED) ? B_CONTROL_ON : B_CONTROL_OFF;
}
// SetEnabled
void
IconButton::SetEnabled(bool enabled)
{
if (enabled)
_AddFlags(STATE_ENABLED);
else
_ClearFlags(STATE_ENABLED | STATE_TRACKING | STATE_INSIDE);
}
// _ConvertToRGB32
BBitmap*
IconButton::_ConvertToRGB32(const BBitmap* bitmap) const
{
BBitmap* convertedBitmap = new(nothrow) BBitmap(bitmap->Bounds(),
B_BITMAP_ACCEPTS_VIEWS, B_RGBA32);
if (convertedBitmap && convertedBitmap->IsValid()) {
memset(convertedBitmap->Bits(), 0, convertedBitmap->BitsLength());
BView* helper = new BView(bitmap->Bounds(), "helper",
B_FOLLOW_NONE, B_WILL_DRAW);
if (convertedBitmap->Lock()) {
convertedBitmap->AddChild(helper);
helper->SetDrawingMode(B_OP_OVER);
helper->DrawBitmap(bitmap, BPoint(0.0, 0.0));
helper->Sync();
convertedBitmap->Unlock();
}
} else {
delete convertedBitmap;
convertedBitmap = NULL;
}
return convertedBitmap;
}
// _MakeBitmaps
status_t
IconButton::_MakeBitmaps(const BBitmap* bitmap)
{
status_t status = bitmap ? bitmap->InitCheck() : B_BAD_VALUE;
if (status >= B_OK) {
// make our own versions of the bitmap
BRect b(bitmap->Bounds());
_DeleteBitmaps();
color_space format = bitmap->ColorSpace();
fNormalBitmap = new(nothrow) BBitmap(b, format);
fDisabledBitmap = new(nothrow) BBitmap(b, format);
fClickedBitmap = new(nothrow) BBitmap(b, format);
fDisabledClickedBitmap = new(nothrow) BBitmap(b, format);
if (IsValid()) {
// copy bitmaps from file bitmap
uint8* nBits = (uint8*)fNormalBitmap->Bits();
uint8* dBits = (uint8*)fDisabledBitmap->Bits();
uint8* cBits = (uint8*)fClickedBitmap->Bits();
uint8* dcBits = (uint8*)fDisabledClickedBitmap->Bits();
uint8* fBits = (uint8*)bitmap->Bits();
int32 nbpr = fNormalBitmap->BytesPerRow();
int32 fbpr = bitmap->BytesPerRow();
int32 pixels = b.IntegerWidth() + 1;
int32 lines = b.IntegerHeight() + 1;
// nontransparent version:
if (format == B_RGB32 || format == B_RGB32_BIG) {
// iterate over color components
for (int32 y = 0; y < lines; y++) {
for (int32 x = 0; x < pixels; x++) {
int32 nOffset = 4 * x;
int32 fOffset = 4 * x;
nBits[nOffset + 0] = fBits[fOffset + 0];
nBits[nOffset + 1] = fBits[fOffset + 1];
nBits[nOffset + 2] = fBits[fOffset + 2];
nBits[nOffset + 3] = 255;
// clicked bits are darker (lame method...)
cBits[nOffset + 0] = (uint8)((float)nBits[nOffset + 0] * 0.8);
cBits[nOffset + 1] = (uint8)((float)nBits[nOffset + 1] * 0.8);
cBits[nOffset + 2] = (uint8)((float)nBits[nOffset + 2] * 0.8);
cBits[nOffset + 3] = 255;
// disabled bits have less contrast (lame method...)
uint8 grey = 216;
float dist = (nBits[nOffset + 0] - grey) * 0.4;
dBits[nOffset + 0] = (uint8)(grey + dist);
dist = (nBits[nOffset + 1] - grey) * 0.4;
dBits[nOffset + 1] = (uint8)(grey + dist);
dist = (nBits[nOffset + 2] - grey) * 0.4;
dBits[nOffset + 2] = (uint8)(grey + dist);
dBits[nOffset + 3] = 255;
// disabled bits have less contrast (lame method...)
grey = 188;
dist = (nBits[nOffset + 0] - grey) * 0.4;
dcBits[nOffset + 0] = (uint8)(grey + dist);
dist = (nBits[nOffset + 1] - grey) * 0.4;
dcBits[nOffset + 1] = (uint8)(grey + dist);
dist = (nBits[nOffset + 2] - grey) * 0.4;
dcBits[nOffset + 2] = (uint8)(grey + dist);
dcBits[nOffset + 3] = 255;
}
nBits += nbpr;
dBits += nbpr;
cBits += nbpr;
dcBits += nbpr;
fBits += fbpr;
}
// transparent version:
} else if (format == B_RGBA32 || format == B_RGBA32_BIG) {
// iterate over color components
for (int32 y = 0; y < lines; y++) {
for (int32 x = 0; x < pixels; x++) {
int32 nOffset = 4 * x;
int32 fOffset = 4 * x;
nBits[nOffset + 0] = fBits[fOffset + 0];
nBits[nOffset + 1] = fBits[fOffset + 1];
nBits[nOffset + 2] = fBits[fOffset + 2];
nBits[nOffset + 3] = fBits[fOffset + 3];
// clicked bits are darker (lame method...)
cBits[nOffset + 0] = (uint8)(nBits[nOffset + 0] * 0.8);
cBits[nOffset + 1] = (uint8)(nBits[nOffset + 1] * 0.8);
cBits[nOffset + 2] = (uint8)(nBits[nOffset + 2] * 0.8);
cBits[nOffset + 3] = fBits[fOffset + 3];
// disabled bits have less opacity
uint8 grey = ((uint16)nBits[nOffset + 0] * 10
+ nBits[nOffset + 1] * 60
+ nBits[nOffset + 2] * 30) / 100;
float dist = (nBits[nOffset + 0] - grey) * 0.3;
dBits[nOffset + 0] = (uint8)(grey + dist);
dist = (nBits[nOffset + 1] - grey) * 0.3;
dBits[nOffset + 1] = (uint8)(grey + dist);
dist = (nBits[nOffset + 2] - grey) * 0.3;
dBits[nOffset + 2] = (uint8)(grey + dist);
dBits[nOffset + 3] = (uint8)(fBits[fOffset + 3] * 0.3);
// disabled bits have less contrast (lame method...)
dcBits[nOffset + 0] = (uint8)(dBits[nOffset + 0] * 0.8);
dcBits[nOffset + 1] = (uint8)(dBits[nOffset + 1] * 0.8);
dcBits[nOffset + 2] = (uint8)(dBits[nOffset + 2] * 0.8);
dcBits[nOffset + 3] = (uint8)(fBits[fOffset + 3] * 0.3);
}
nBits += nbpr;
dBits += nbpr;
cBits += nbpr;
dcBits += nbpr;
fBits += fbpr;
}
// unsupported format
} else {
printf("IconButton::_MakeBitmaps() - bitmap has unsupported colorspace\n");
status = B_MISMATCHED_VALUES;
_DeleteBitmaps();
}
} else {
printf("IconButton::_MakeBitmaps() - error allocating local bitmaps\n");
status = B_NO_MEMORY;
_DeleteBitmaps();
}
} else
printf("IconButton::_MakeBitmaps() - bitmap is not valid\n");
return status;
}
// _DeleteBitmaps
void
IconButton::_DeleteBitmaps()
{
delete fNormalBitmap;
fNormalBitmap = NULL;
delete fDisabledBitmap;
fDisabledBitmap = NULL;
delete fClickedBitmap;
fClickedBitmap = NULL;
delete fDisabledClickedBitmap;
fDisabledClickedBitmap = NULL;
}
// _Update
void
IconButton::_Update()
{
if (LockLooper()) {
Invalidate();
UnlockLooper();
}
}
// _AddFlags
void
IconButton::_AddFlags(uint32 flags)
{
if (!(fButtonState & flags)) {
fButtonState |= flags;
_Update();
}
}
// _ClearFlags
void
IconButton::_ClearFlags(uint32 flags)
{
if (fButtonState & flags) {
fButtonState &= ~flags;
_Update();
}
}
// _HasFlags
bool
IconButton::_HasFlags(uint32 flags) const
{
return (fButtonState & flags);
}
// _DrawFrame
void
IconButton::_DrawFrame(BRect r, rgb_color col1, rgb_color col2,
rgb_color col3, rgb_color col4)
{
BeginLineArray(8);
AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), col1);
AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), col1);
AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), col2);
AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), col2);
r.InsetBy(1.0, 1.0);
AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), col3);
AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), col3);
AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), col4);
AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), col4);
EndLineArray();
}
-134
View File
@@ -1,134 +0,0 @@
/*
* Copyright 2006-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
/** gui class that loads an image from disk and shows it
as clickable button */
// TODO: inherit from BControl?
// NOTE: this file is a duplicate of the version in Icon-O-Matic/generic
// it should be placed into a common folder for generic useful stuff
#ifndef ICON_BUTTON_H
#define ICON_BUTTON_H
#include <Invoker.h>
#include <String.h>
#include <View.h>
class BBitmap;
class BMimeType;
class IconButton : public BView, public BInvoker {
public:
IconButton(const char* name,
uint32 id,
const char* label = NULL,
BMessage* message = NULL,
BHandler* target = NULL);
virtual ~IconButton();
// BView interface
virtual void MessageReceived(BMessage* message);
virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* message);
virtual void GetPreferredSize(float* width,
float* height);
virtual BSize MinSize();
virtual BSize MaxSize();
// BInvoker interface
virtual status_t Invoke(BMessage* message = NULL);
// IconButton
bool IsValid() const;
virtual int32 Value() const;
virtual void SetValue(int32 value);
bool IsEnabled() const;
void SetEnabled(bool enable);
void SetPressed(bool pressed);
bool IsPressed() const;
uint32 ID() const
{ return fID; }
status_t SetIcon(int32 resourceID);
status_t SetIcon(const char* pathToBitmap);
status_t SetIcon(const BBitmap* bitmap);
status_t SetIcon(const BMimeType* fileType,
bool small = true);
status_t SetIcon(const unsigned char* bitsFromQuickRes,
uint32 width, uint32 height,
color_space format,
bool convertToBW = false);
void ClearIcon();
void TrimIcon(bool keepAspect = true);
BBitmap* Bitmap() const;
// caller has to delete the returned bitmap
virtual bool DrawBorder() const;
virtual void DrawNormalBorder(BRect r,
rgb_color background,
rgb_color shadow,
rgb_color darkShadow,
rgb_color lightShadow,
rgb_color light);
virtual void DrawPressedBorder(BRect r,
rgb_color background,
rgb_color shadow,
rgb_color darkShadow,
rgb_color lightShadow,
rgb_color light);
protected:
enum {
STATE_NONE = 0x0000,
STATE_TRACKING = 0x0001,
STATE_PRESSED = 0x0002,
STATE_ENABLED = 0x0004,
STATE_INSIDE = 0x0008,
STATE_FORCE_PRESSED = 0x0010,
};
void _AddFlags(uint32 flags);
void _ClearFlags(uint32 flags);
bool _HasFlags(uint32 flags) const;
void _DrawFrame(BRect frame,
rgb_color col1,
rgb_color col2,
rgb_color col3,
rgb_color col4);
// private:
BBitmap* _ConvertToRGB32(const BBitmap* bitmap) const;
status_t _MakeBitmaps(const BBitmap* bitmap);
void _DeleteBitmaps();
void _SendMessage() const;
void _Update();
uint32 fButtonState;
int32 fID;
BBitmap* fNormalBitmap;
BBitmap* fDisabledBitmap;
BBitmap* fClickedBitmap;
BBitmap* fDisabledClickedBitmap;
BString fLabel;
BHandler* fTargetCache;
};
#endif // ICON_BUTTON_H
-80
View File
@@ -1,80 +0,0 @@
/*
* Copyright 2006-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ICON_UTILS_H
#define _ICON_UTILS_H
#include <Mime.h>
class BBitmap;
class BNode;
// This class is a little different from many other classes.
// You don't create an instance of it; you just call its various
// static member functions for utility-like operations.
class BIconUtils {
BIconUtils();
~BIconUtils();
BIconUtils(const BIconUtils&);
BIconUtils& operator=(const BIconUtils&);
public:
// Utility function to import an icon from the node that
// has either of the provided attribute names. Which icon type
// is preferred (vector, small or large B_CMAP8 icon) depends
// on the colorspace of the provided bitmap. If the colorspace
// is B_CMAP8, B_CMAP8 icons are preferred. In that case, the
// bitmap size must also match the provided icon_size "size"!
static status_t GetIcon(BNode* node,
const char* vectorIconAttrName,
const char* smallIconAttrName,
const char* largeIconAttrName,
icon_size size, BBitmap* result);
// Utility functions to import a vector icon in "flat icon"
// format from a BNode attribute or from a flat buffer in
// memory into the preallocated BBitmap "result".
// The colorspace of result needs to be B_RGBA32 or at
// least B_RGB32 (though that makes less sense). The icon
// will be scaled from it's "native" size of 64x64 to the
// size of the bitmap, the scale is derived from the bitmap
// width, the bitmap should have square dimension, or the
// icon will be cut off at the bottom (or have room left).
static status_t GetVectorIcon(BNode* node,
const char* attrName, BBitmap* result);
static status_t GetVectorIcon(const uint8* buffer,
size_t size, BBitmap* result);
// Utility function to import an "old" BeOS icon in B_CMAP8
// colorspace from either the small icon attribute or the
// large icon attribute as given in "smallIconAttrName" and
// "largeIconAttrName". Which icon is loaded depends on
// the given "size".
static status_t GetCMAP8Icon(BNode* node,
const char* smallIconAttrName,
const char* largeIconAttrName,
icon_size size, BBitmap* icon);
// Utility functions to convert from old icon colorspace
// into colorspace of BBitmap "result" (should be B_RGBA32
// to make any sense).
static status_t ConvertFromCMAP8(BBitmap* source,
BBitmap* result);
static status_t ConvertToCMAP8(BBitmap* source,
BBitmap* result);
static status_t ConvertFromCMAP8(const uint8* data,
uint32 width, uint32 height,
uint32 bytesPerRow, BBitmap* result);
static status_t ConvertToCMAP8(const uint8* data,
uint32 width, uint32 height,
uint32 bytesPerRow, BBitmap* result);
};
#endif // _ICON_UTILS_H
-168
View File
@@ -1,168 +0,0 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
// NavMenu is a hierarchical menu of volumes, folders, files and queries
// displays icons, uses the SlowMenu API for full interruptability
#ifndef NAV_MENU_H
#define NAV_MENU_H
#include <Messenger.h>
#include <StorageDefs.h>
#include <Entry.h>
#include "SlowMenu.h"
template<class T> class BObjectList;
class BMenuItem;
namespace BPrivate {
class Model;
class BContainerWindow;
class ModelMenuItem;
class EntryListBase;
class TrackingHookData {
public:
TrackingHookData()
:
fTrackingHook(NULL),
fDragMessage(NULL)
{
}
bool (*fTrackingHook)(BMenu *, void *);
BMessenger fTarget;
const BMessage *fDragMessage;
};
class BNavMenu : public BSlowMenu {
public:
BNavMenu(const char* title, uint32 message, const BHandler *,
BWindow *parentWindow = NULL, const BObjectList<BString> *list = NULL);
BNavMenu(const char* title, uint32 message, const BMessenger &,
BWindow *parentWindow = NULL, const BObjectList<BString> *list = NULL);
// parentWindow, if specified, will be closed if nav menu item invoked
// with option held down
virtual ~BNavMenu();
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
void SetNavDir(const entry_ref *);
void ForceRebuild();
bool NeedsToRebuild() const;
// will cause menu to get rebuilt next time it is shown
virtual void ResetTargets();
void SetTarget(const BMessenger &);
BMessenger Target();
void SetTypesList(const BObjectList<BString> *list);
const BObjectList<BString> *TypesList() const;
void AddNavDir(const Model *model, uint32 what, BHandler *target,
bool populateSubmenu);
void AddNavParentDir(const char *name, const Model *model, uint32 what, BHandler *target);
void AddNavParentDir(const Model *model, uint32 what, BHandler *target);
void SetShowParent(bool show);
static int32 GetMaxMenuWidth();
static int CompareFolderNamesFirstOne(const BMenuItem *, const BMenuItem *);
static int CompareOne(const BMenuItem *, const BMenuItem *);
static ModelMenuItem *NewModelItem(Model *, const BMessage *, const BMessenger &,
bool suppressFolderHierarchy=false, BContainerWindow * = NULL,
const BObjectList<BString> *typeslist = NULL,
TrackingHookData *hook = NULL);
TrackingHookData *InitTrackingHook(bool (*hookfunction)(BMenu *, void *),
const BMessenger *target, const BMessage *dragMessage);
protected:
virtual bool StartBuildingItemList();
virtual bool AddNextItem();
virtual void DoneBuildingItemList();
virtual void ClearMenuBuildingState();
void BuildVolumeMenu();
void AddOneItem(Model *);
void AddRootItemsIfNeeded();
void AddTrashItem();
static void SetTrackingHookDeep(BMenu *, bool (*)(BMenu *, void *), void *);
entry_ref fNavDir;
BMessage fMessage;
BMessenger fMessenger;
BWindow *fParentWindow;
// menu building state
uint8 fFlags;
BObjectList<BMenuItem> *fItemList;
EntryListBase *fContainer;
bool fIteratingDesktop;
const BObjectList<BString> *fTypesList;
TrackingHookData fTrackingHook;
};
// Spring Loaded Folder convenience routines
// used in both Tracker and Deskbar
#ifndef _IMPEXP_TRACKER
# define _IMPEXP_TRACKER
#endif
_IMPEXP_TRACKER bool SpringLoadedFolderCompareMessages(const BMessage *incoming,
const BMessage *dragmessage);
_IMPEXP_TRACKER void SpringLoadedFolderSetMenuStates(const BMenu *menu,
const BObjectList<BString> *typeslist);
_IMPEXP_TRACKER void SpringLoadedFolderAddUniqueTypeToList(entry_ref *ref,
BObjectList<BString> *typeslist);
_IMPEXP_TRACKER void SpringLoadedFolderCacheDragData(const BMessage *incoming,
BMessage **, BObjectList<BString> **typeslist);
} // namespace BPrivate
using namespace BPrivate;
#endif // NAV_MENU_H
@@ -1,514 +0,0 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
// bonefish:
// * removed need for exceptions
// * fixed warnings
// * implemented rehashing
// * added RemoveAll()
// TODO:
// * shrinking of element vectors
// Hash table with open addresssing
#ifndef __OPEN_HASH_TABLE__
#define __OPEN_HASH_TABLE__
#include <stdlib.h>
#include <new>
// don't include <Debug.h>
#ifndef ASSERT
# define ASSERT(E) (void)0
#endif
#ifndef TRESPASS
# define TRESPASS() (void)0
#endif
namespace BPrivate {
template <class Element>
class ElementVector {
// element vector for OpenHashTable needs to implement this
// interface
public:
Element &At(int32 index);
Element *Add();
int32 IndexOf(const Element &) const;
void Remove(int32 index);
};
class OpenHashElement {
public:
uint32 Hash() const;
bool operator==(const OpenHashElement &) const;
void Adopt(OpenHashElement &);
// low overhead copy, original element is in undefined state
// after call (calls Adopt on BString members, etc.)
int32 fNext;
};
const uint32 kPrimes [] = {
509, 1021, 2039, 4093, 8191, 16381, 32749, 65521, 131071, 262139,
524287, 1048573, 2097143, 4194301, 8388593, 16777213, 33554393, 67108859,
134217689, 268435399, 536870909, 1073741789, 2147483647, 0
};
template <class Element, class ElementVec = ElementVector<Element> >
class OpenHashTable {
public:
OpenHashTable(int32 minSize, ElementVec *elementVector = 0,
float maxLoadFactor = 0.8);
// it is up to the subclass of OpenHashTable to supply
// elementVector
~OpenHashTable();
bool InitCheck() const;
void SetElementVector(ElementVec *elementVector);
Element *FindFirst(uint32 elementHash) const;
Element *Add(uint32 elementHash);
void Remove(Element *element, bool dontRehash = false);
void RemoveAll();
// when calling Add, any outstanding element pointer may become
// invalid; to deal with this, get the element index and restore
// it after the add
int32 ElementIndex(const Element *) const;
Element *ElementAt(int32 index) const;
int32 ArraySize() const;
int32 VectorSize() const;
int32 CountElements() const;
protected:
static int32 OptimalSize(int32 minSize);
private:
bool _RehashIfNeeded();
bool _Rehash();
int32 fArraySize;
int32 fInitialSize;
int32 fElementCount;
int32 *fHashArray;
ElementVec *fElementVector;
float fMaxLoadFactor;
};
template <class Element>
class OpenHashElementArray : public ElementVector<Element> {
// this is a straightforward implementation of an element vector
// deleting is handled by linking deleted elements into a free list
// the vector never shrinks
public:
OpenHashElementArray(int32 initialSize);
~OpenHashElementArray();
bool InitCheck() const;
Element &At(int32 index);
const Element &At(int32 index) const;
Element *Add(const Element &);
Element *Add();
void Remove(int32 index);
int32 IndexOf(const Element &) const;
int32 Size() const;
private:
Element *fData;
int32 fSize;
int32 fNextFree;
int32 fNextDeleted;
};
//-----------------------------------
template<class Element, class ElementVec>
OpenHashTable<Element, ElementVec>::OpenHashTable(int32 minSize,
ElementVec *elementVector, float maxLoadFactor)
: fArraySize(OptimalSize(minSize)),
fInitialSize(fArraySize),
fElementCount(0),
fElementVector(elementVector),
fMaxLoadFactor(maxLoadFactor)
{
// sanity check the maximal load factor
if (fMaxLoadFactor < 0.5)
fMaxLoadFactor = 0.5;
// allocate and init the array
fHashArray = (int32*)calloc(fArraySize, sizeof(int32));
if (fHashArray) {
for (int32 index = 0; index < fArraySize; index++)
fHashArray[index] = -1;
}
}
template<class Element, class ElementVec>
OpenHashTable<Element, ElementVec>::~OpenHashTable()
{
RemoveAll();
free(fHashArray);
}
template<class Element, class ElementVec>
bool
OpenHashTable<Element, ElementVec>::InitCheck() const
{
return (fHashArray && fElementVector);
}
template<class Element, class ElementVec>
int32
OpenHashTable<Element, ElementVec>::OptimalSize(int32 minSize)
{
for (int32 index = 0; ; index++)
if (!kPrimes[index] || kPrimes[index] >= (uint32)minSize)
return (int32)kPrimes[index];
return 0;
}
template<class Element, class ElementVec>
Element *
OpenHashTable<Element, ElementVec>::FindFirst(uint32 hash) const
{
ASSERT(fElementVector);
hash %= fArraySize;
if (fHashArray[hash] < 0)
return 0;
return &fElementVector->At(fHashArray[hash]);
}
template<class Element, class ElementVec>
int32
OpenHashTable<Element, ElementVec>::ElementIndex(const Element *element) const
{
return fElementVector->IndexOf(*element);
}
template<class Element, class ElementVec>
Element *
OpenHashTable<Element, ElementVec>::ElementAt(int32 index) const
{
return &fElementVector->At(index);
}
template<class Element, class ElementVec>
int32
OpenHashTable<Element, ElementVec>::ArraySize() const
{
return fArraySize;
}
template<class Element, class ElementVec>
int32
OpenHashTable<Element, ElementVec>::VectorSize() const
{
return fElementVector->Size();
}
template<class Element, class ElementVec>
int32
OpenHashTable<Element, ElementVec>::CountElements() const
{
return fElementCount;
}
template<class Element, class ElementVec>
Element *
OpenHashTable<Element, ElementVec>::Add(uint32 hash)
{
ASSERT(fElementVector);
_RehashIfNeeded();
hash %= fArraySize;
Element *result = fElementVector->Add();
if (result) {
result->fNext = fHashArray[hash];
fHashArray[hash] = fElementVector->IndexOf(*result);
fElementCount++;
}
return result;
}
template<class Element, class ElementVec>
void
OpenHashTable<Element, ElementVec>::Remove(Element *element, bool dontRehash)
{
if (!dontRehash)
_RehashIfNeeded();
uint32 hash = element->Hash() % fArraySize;
int32 next = fHashArray[hash];
ASSERT(next >= 0);
if (&fElementVector->At(next) == element) {
fHashArray[hash] = element->fNext;
fElementVector->Remove(next);
fElementCount--;
return;
}
for (int32 index = next; index >= 0; ) {
// look for an existing match in table
next = fElementVector->At(index).fNext;
if (next < 0) {
TRESPASS();
return;
}
if (&fElementVector->At(next) == element) {
fElementVector->At(index).fNext = element->fNext;
fElementVector->Remove(next);
fElementCount--;
return;
}
index = next;
}
}
template<class Element, class ElementVec>
void
OpenHashTable<Element, ElementVec>::RemoveAll()
{
for (int32 i = 0; fElementCount > 0 && i < fArraySize; i++) {
int32 index = fHashArray[i];
while (index >= 0) {
Element* element = &fElementVector->At(index);
int32 next = element->fNext;
fElementVector->Remove(index);
fElementCount--;
index = next;
}
fHashArray[i] = -1;
}
_RehashIfNeeded();
}
template<class Element, class ElementVec>
void
OpenHashTable<Element, ElementVec>::SetElementVector(ElementVec *elementVector)
{
fElementVector = elementVector;
}
// _RehashIfNeeded
template<class Element, class ElementVec>
bool
OpenHashTable<Element, ElementVec>::_RehashIfNeeded()
{
// The load factor range [fMaxLoadFactor / 3, fMaxLoadFactor] is fine,
// I think. After rehashing the load factor will be about
// fMaxLoadFactor * 2 / 3, respectively fMaxLoadFactor / 2.
float loadFactor = (float)fElementCount / (float)fArraySize;
if (loadFactor > fMaxLoadFactor
|| (fArraySize > fInitialSize && loadFactor < fMaxLoadFactor / 3)) {
return _Rehash();
}
return true;
}
// _Rehash
template<class Element, class ElementVec>
bool
OpenHashTable<Element, ElementVec>::_Rehash()
{
bool result = true;
int32 newSize = int32(fElementCount * 1.73 * fMaxLoadFactor);
newSize = (fInitialSize > newSize ? fInitialSize : newSize);
if (newSize != fArraySize) {
// allocate a new array
int32 *newHashArray = (int32*)calloc(newSize, sizeof(int32));
if (newHashArray) {
// init the new hash array
for (int32 index = 0; index < newSize; index++)
newHashArray[index] = -1;
// iterate through all elements and put them into the new
// hash array
for (int i = 0; i < fArraySize; i++) {
int32 index = fHashArray[i];
while (index >= 0) {
// insert the element in the new array
Element &element = fElementVector->At(index);
int32 next = element.fNext;
uint32 hash = (element.Hash() % newSize);
element.fNext = newHashArray[hash];
newHashArray[hash] = index;
// next element in old list
index = next;
}
}
// delete the old array and set the new one
free(fHashArray);
fHashArray = newHashArray;
fArraySize = newSize;
} else
result = false;
}
return result;
}
template<class Element>
OpenHashElementArray<Element>::OpenHashElementArray(int32 initialSize)
: fSize(initialSize),
fNextFree(0),
fNextDeleted(-1)
{
fData = (Element*)calloc((size_t)initialSize, sizeof(Element));
}
template<class Element>
OpenHashElementArray<Element>::~OpenHashElementArray()
{
free(fData);
}
template<class Element>
bool
OpenHashElementArray<Element>::InitCheck() const
{
return fData;
}
template<class Element>
Element &
OpenHashElementArray<Element>::At(int32 index)
{
ASSERT(index < fSize);
return fData[index];
}
template<class Element>
const Element &
OpenHashElementArray<Element>::At(int32 index) const
{
ASSERT(index < fSize);
return fData[index];
}
template<class Element>
int32
OpenHashElementArray<Element>::IndexOf(const Element &element) const
{
int32 result = &element - fData;
if (result < 0 || result > fSize)
return -1;
return result;
}
template<class Element>
int32
OpenHashElementArray<Element>::Size() const
{
return fSize;
}
template<class Element>
Element *
OpenHashElementArray<Element>::Add(const Element &newElement)
{
Element *element = Add();
if (element)
element.Adopt(newElement);
return element;
}
#if DEBUG
const int32 kGrowChunk = 10;
#else
const int32 kGrowChunk = 1024;
#endif
template<class Element>
Element *
OpenHashElementArray<Element>::Add()
{
int32 index = fNextFree;
if (fNextDeleted >= 0) {
index = fNextDeleted;
fNextDeleted = At(index).fNext;
} else if (fNextFree >= fSize - 1) {
int32 newSize = fSize + kGrowChunk;
/*
Element *newData = (Element *)calloc((size_t)newSize , sizeof(Element));
if (!newData)
return NULL;
memcpy(newData, fData, fSize * sizeof(Element));
free(fData);
*/
Element *newData = (Element*)realloc(fData,
(size_t)newSize * sizeof(Element));
if (!newData)
return NULL;
fData = newData;
fSize = newSize;
index = fNextFree;
fNextFree++;
} else
fNextFree++;
new (&At(index)) Element;
// call placement new to initialize the element properly
ASSERT(At(index).fNext == -1);
return &At(index);
}
template<class Element>
void
OpenHashElementArray<Element>::Remove(int32 index)
{
// delete by chaining empty elements in a single linked
// list, reusing the next field
ASSERT(index < fSize);
At(index).~Element();
// call the destructor explicitly to destroy the element
// properly
At(index).fNext = fNextDeleted;
fNextDeleted = index;
}
} // namespace BPrivate
using BPrivate::OpenHashTable;
#endif // __OPEN_HASH_TABLE__
-76
View File
@@ -1,76 +0,0 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
#ifndef __SLOW_MENU__
#define __SLOW_MENU__
#include <Menu.h>
#include <MenuItem.h>
#include <Debug.h>
// SlowMenu is a convenience class that makes it easier to
// use the AddDynamicItem callback to implement a menu that can
// checks periodically between creating new items and quits
// early if needed
namespace BPrivate {
class BSlowMenu : public BMenu {
public:
BSlowMenu(const char *title, menu_layout layout = B_ITEMS_IN_COLUMN);
protected:
virtual bool StartBuildingItemList();
// set up state to start building the item list
// returns false if setup failed
virtual bool AddNextItem() = 0;
// returns false if done
virtual void DoneBuildingItemList() = 0;
// default version adds items from itemList to menu and deletes
// the list; override to sort items first, etc.
virtual void ClearMenuBuildingState() = 0;
protected:
virtual bool AddDynamicItem(add_state state);
// this is the callback from BMenu, you shouldn't need to override this
bool fMenuBuilt;
};
} // namespace BPrivate
using namespace BPrivate;
#endif /* __SLOW_MENU__ */
@@ -1,43 +0,0 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "StringForSize.h"
#include <stdio.h>
namespace BPrivate {
const char*
string_for_size(double size, char* string, size_t stringSize)
{
double kib = size / 1024.0;
if (kib < 1.0) {
snprintf(string, stringSize, "%d bytes", (int)size);
return string;
}
double mib = kib / 1024.0;
if (mib < 1.0) {
snprintf(string, stringSize, "%3.2f KiB", kib);
return string;
}
double gib = mib / 1024.0;
if (gib < 1.0) {
snprintf(string, stringSize, "%3.2f MiB", mib);
return string;
}
double tib = gib / 1024.0;
if (tib < 1.0) {
snprintf(string, stringSize, "%3.2f GiB", gib);
return string;
}
snprintf(string, stringSize, "%.2f TiB", tib);
return string;
}
} // namespace BPrivate
@@ -1,23 +0,0 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef STRING_FOR_SIZE_H
#define STRING_FOR_SIZE_H
#include <SupportDefs.h>
namespace BPrivate {
const char* string_for_size(double size, char* string, size_t stringSize);
} // namespace BPrivate
using BPrivate::string_for_size;
#endif // COLOR_QUANTIZER_H
-10
View File
@@ -1,10 +0,0 @@
/*
* Copyright 2006-2009, Ingo Weinhold <ingo_weinhold@gmx.de>
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "svn_revision.h"
const int32 kSVNRevision = 0;
// #include "svn_revision"
;
-15
View File
@@ -1,15 +0,0 @@
/*
* Copyright 2006-2009, Ingo Weinhold <ingo_weinhold@gmx.de>
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef SVN_REVISION_H
#define SVN_REVISION_H
#include <SupportDefs.h>
extern const int32 kSVNRevision;
#endif // SVN_REVISION_H