Using GPL'ed code is a no-no.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@761 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
#ifndef __HBITMAPVIEW_H__
|
||||
#define __HBITMAPVIEW_H__
|
||||
|
||||
#include <View.h>
|
||||
#include <Bitmap.h>
|
||||
|
||||
class BitmapView :public BView {
|
||||
public:
|
||||
BitmapView(BRect rect,
|
||||
const char* name,
|
||||
uint32 resizing_mode,
|
||||
BBitmap *bitmap,
|
||||
rgb_color bgcolor = ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
virtual ~BitmapView();
|
||||
virtual void Draw(BRect rect);
|
||||
void SetBitmap(BBitmap *bitmap);
|
||||
protected:
|
||||
BBitmap *fBitmap;
|
||||
};
|
||||
#endif
|
||||
@@ -1,118 +0,0 @@
|
||||
//*** LICENSE ***
|
||||
//ColumnListView, its associated classes and source code, and the other components of Santa's Gift Bag are
|
||||
//being made publicly available and free to use in freeware and shareware products with a price under $25
|
||||
//(I believe that shareware should be cheap). For overpriced shareware (hehehe) or commercial products,
|
||||
//please contact me to negotiate a fee for use. After all, I did work hard on this class and invested a lot
|
||||
//of time into it. That being said, DON'T WORRY I don't want much. It totally depends on the sort of project
|
||||
//you're working on and how much you expect to make off it. If someone makes money off my work, I'd like to
|
||||
//get at least a little something. If any of the components of Santa's Gift Bag are is used in a shareware
|
||||
//or commercial product, I get a free copy. The source is made available so that you can improve and extend
|
||||
//it as you need. In general it is best to customize your ColumnListView through inheritance, so that you
|
||||
//can take advantage of enhancements and bug fixes as they become available. Feel free to distribute the
|
||||
//ColumnListView source, including modified versions, but keep this documentation and license with it.
|
||||
|
||||
|
||||
#include "CTextView.h"
|
||||
|
||||
CTextView::CTextView(BRect a_frame,const char* a_name,int32 a_resize_mode,int32 a_flags)
|
||||
: BTextView(a_frame, a_name, BRect(4.0,4.0,a_frame.right-a_frame.left-4.0,a_frame.bottom-a_frame.top-4.0),
|
||||
a_resize_mode,a_flags)
|
||||
{
|
||||
ResetTextRect();
|
||||
m_modified = false;
|
||||
m_modified_disabled = false;
|
||||
}
|
||||
|
||||
|
||||
CTextView::~CTextView()
|
||||
{ }
|
||||
|
||||
|
||||
void CTextView::DetachedFromWindow()
|
||||
{
|
||||
//This is sort of what the destructor should do, but... Derived class's destructors get called before
|
||||
//CTextView's destructor so StoreChange won't get to the derived class's version of it.
|
||||
if(m_modified)
|
||||
{
|
||||
StoreChange();
|
||||
m_modified = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CTextView::FrameResized(float a_width, float a_height)
|
||||
{
|
||||
ResetTextRect();
|
||||
BTextView::FrameResized(a_width,a_height);
|
||||
}
|
||||
|
||||
|
||||
void CTextView::MakeFocus(bool a_focused)
|
||||
{
|
||||
BTextView::MakeFocus(a_focused);
|
||||
if(!a_focused && m_modified)
|
||||
{
|
||||
StoreChange();
|
||||
m_modified = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CTextView::InsertText(const char *a_text, int32 a_length, int32 a_offset,
|
||||
const text_run_array *a_runs)
|
||||
{
|
||||
BTextView::InsertText(a_text, a_length, a_offset, a_runs);
|
||||
if(!m_modified_disabled)
|
||||
Modified();
|
||||
}
|
||||
|
||||
|
||||
void CTextView::Modified()
|
||||
{
|
||||
m_modified = true;
|
||||
}
|
||||
|
||||
|
||||
void CTextView::SetText(const char *text, int32 length, const text_run_array *runs)
|
||||
{
|
||||
m_modified_disabled = true;
|
||||
BTextView::SetText(text,length,runs);
|
||||
m_modified_disabled = false;
|
||||
}
|
||||
|
||||
|
||||
void CTextView::SetText(const char *text, const text_run_array *runs)
|
||||
{
|
||||
m_modified_disabled = true;
|
||||
BTextView::SetText(text,runs);
|
||||
m_modified_disabled = false;
|
||||
}
|
||||
|
||||
|
||||
void CTextView::SetText(BFile *file, int32 offset, int32 length, const text_run_array *runs)
|
||||
{
|
||||
m_modified_disabled = true;
|
||||
BTextView::SetText(file,offset,length,runs);
|
||||
m_modified_disabled = false;
|
||||
}
|
||||
|
||||
|
||||
void CTextView::StoreChange()
|
||||
{ }
|
||||
|
||||
|
||||
void CTextView::ResetTextRect()
|
||||
{
|
||||
BRect textRect = Bounds();
|
||||
textRect.left = 4.0;
|
||||
textRect.top = 4.0;
|
||||
textRect.right -= 4.0;
|
||||
textRect.bottom -= 4.0;
|
||||
SetTextRect(textRect);
|
||||
}
|
||||
|
||||
|
||||
bool CTextView::HasBeenModified()
|
||||
{
|
||||
return m_modified;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
//*** LICENSE ***
|
||||
//ColumnListView, its associated classes and source code, and the other components of Santa's Gift Bag are
|
||||
//being made publicly available and free to use in freeware and shareware products with a price under $25
|
||||
//(I believe that shareware should be cheap). For overpriced shareware (hehehe) or commercial products,
|
||||
//please contact me to negotiate a fee for use. After all, I did work hard on this class and invested a lot
|
||||
//of time into it. That being said, DON'T WORRY I don't want much. It totally depends on the sort of project
|
||||
//you're working on and how much you expect to make off it. If someone makes money off my work, I'd like to
|
||||
//get at least a little something. If any of the components of Santa's Gift Bag are is used in a shareware
|
||||
//or commercial product, I get a free copy. The source is made available so that you can improve and extend
|
||||
//it as you need. In general it is best to customize your ColumnListView through inheritance, so that you
|
||||
//can take advantage of enhancements and bug fixes as they become available. Feel free to distribute the
|
||||
//ColumnListView source, including modified versions, but keep this documentation and license with it.
|
||||
|
||||
//*** DESCRIPTION ***
|
||||
//CTextView class
|
||||
|
||||
//Extends BTextView functionality somewhat. Automates setting up the TextRect and updating it during resizing
|
||||
//so that re-wrapping is live. Also provides a StoreChanges hook function that is called when the CTextView
|
||||
//loses focus or is removed from the window or destroyed. This is useful if the view is of an object that can
|
||||
//exist without the view, so that this more persistent object can be kept up-to-date when the text is modified,
|
||||
//without having to update the other object every time a character is entered.
|
||||
|
||||
|
||||
#ifndef _CTEXT_VIEW_H_
|
||||
#define _CTEXT_VIEW_H_
|
||||
|
||||
|
||||
#include <TextView.h>
|
||||
|
||||
|
||||
class CTextView : public BTextView
|
||||
{
|
||||
public:
|
||||
CTextView(BRect a_frame,const char* a_name,int32 a_resize_mode,int32 a_flags);
|
||||
virtual ~CTextView();
|
||||
|
||||
//BTextView overrides
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void FrameResized(float a_width, float a_height);
|
||||
virtual void MakeFocus(bool a_focused);
|
||||
void SetText(const char *text, int32 length, const text_run_array *runs = NULL);
|
||||
void SetText(const char *text, const text_run_array *runs = NULL);
|
||||
void SetText(BFile *file, int32 offset, int32 length, const text_run_array *runs = NULL);
|
||||
virtual void StoreChange();
|
||||
virtual void Modified();
|
||||
bool HasBeenModified();
|
||||
void ResetTextRect();
|
||||
|
||||
protected:
|
||||
virtual void InsertText(const char *a_text, int32 a_length, int32 a_offset, const text_run_array *a_runs);
|
||||
|
||||
private:
|
||||
bool m_modified;
|
||||
bool m_modified_disabled;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,363 +0,0 @@
|
||||
#include "HAboutWindow.h"
|
||||
#include <Screen.h>
|
||||
#include <String.h>
|
||||
#include <Message.h>
|
||||
#include <Roster.h>
|
||||
#include <Path.h>
|
||||
#include <Application.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Resources.h>
|
||||
#include <Alert.h>
|
||||
#include <ClassInfo.h>
|
||||
|
||||
#include "BitmapView.h"
|
||||
#include "CTextView.h"
|
||||
#include "URLView.h"
|
||||
|
||||
#define ICON_OFFSET 60
|
||||
|
||||
/***********************************************************
|
||||
* Constructor
|
||||
***********************************************************/
|
||||
HAboutWindow::HAboutWindow(const char* app_name,
|
||||
const char* built_date,
|
||||
const char* comment,
|
||||
const char* url,
|
||||
const char* email)
|
||||
:BWindow(BRect(-1,-1,-1,-1),
|
||||
"",
|
||||
B_FLOATING_WINDOW_LOOK,
|
||||
B_MODAL_APP_WINDOW_FEEL,
|
||||
B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
|
||||
{
|
||||
BString window_title = "About ";
|
||||
window_title << app_name;
|
||||
SetTitle(window_title.String());
|
||||
this->AddShortcut('W',0,new BMessage(B_QUIT_REQUESTED));
|
||||
CalcFontHeights();
|
||||
/********** Get max width **********/
|
||||
BString build = "Built date: ";
|
||||
build << built_date;
|
||||
|
||||
float max_width = ICON_OFFSET;
|
||||
BFont font(be_plain_font);
|
||||
font.SetSize(10);
|
||||
|
||||
max_width = font.StringWidth(build.String());
|
||||
BFont boldfont(be_bold_font);
|
||||
boldfont.SetSize(14);
|
||||
if(max_width < boldfont.StringWidth(app_name) )
|
||||
max_width = boldfont.StringWidth(app_name);
|
||||
|
||||
/**************************************/
|
||||
InitGUI();
|
||||
LoadIcon();
|
||||
SetComment(comment);
|
||||
int32 lines = fComment->CountLines();
|
||||
float result = 0;
|
||||
for(register int32 i = 0; i < lines ; i++)
|
||||
{
|
||||
float tmp = fComment->LineWidth(i);
|
||||
if(tmp > result )
|
||||
result = tmp;
|
||||
}
|
||||
if(max_width < result)
|
||||
max_width = result;
|
||||
if(max_width < font.StringWidth(url))
|
||||
max_width = font.StringWidth(url);
|
||||
float width = max_width + ICON_OFFSET + 20;
|
||||
|
||||
int32 isUrlMail = 0;
|
||||
if(url)
|
||||
isUrlMail++;
|
||||
if(email)
|
||||
isUrlMail++;
|
||||
|
||||
float height = fPlainHeight* (2+lines + isUrlMail) + fBoldHeight + 35;
|
||||
|
||||
ResizeTo(width,height);
|
||||
BRect screen_limits = BScreen().Frame();
|
||||
MoveTo(screen_limits.left+floor((screen_limits.Width()-width)/2),
|
||||
screen_limits.top+floor((screen_limits.Height()-height)/2));
|
||||
|
||||
/************** url view ************/
|
||||
float start_pos = fComment->Frame().bottom;
|
||||
|
||||
BRect url_rect(ICON_OFFSET,start_pos,width,start_pos+fPlainHeight);
|
||||
|
||||
HAboutView *bgview = cast_as(FindView("aboutview"),HAboutView);
|
||||
|
||||
if(url)
|
||||
{
|
||||
BString url_string = url;
|
||||
|
||||
int32 index = url_string.FindFirst("http:");
|
||||
if(index != B_ERROR)
|
||||
{
|
||||
url_string = &url[index];
|
||||
}
|
||||
//(new BAlert("",url_string.String(),"OK"))->Go();
|
||||
URLView *urlView = new URLView(url_rect,"url",url,url_string.String());
|
||||
urlView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
urlView->SetFont(&font);
|
||||
bgview->AddChild(urlView);
|
||||
|
||||
url_rect.OffsetBy(0,fPlainHeight+3);
|
||||
}
|
||||
/************** mail view ****************/
|
||||
if(email)
|
||||
{
|
||||
BString mail = email;
|
||||
|
||||
int32 index = mail.FindLast(" ");
|
||||
if(index != B_ERROR)
|
||||
{
|
||||
mail = &email[index+1];
|
||||
}else{
|
||||
index = mail.FindFirst(":");
|
||||
if(index != B_ERROR)
|
||||
{
|
||||
mail = &email[index+1];
|
||||
}
|
||||
}
|
||||
|
||||
BString mail_uri = "mailto:";
|
||||
mail_uri << mail;
|
||||
|
||||
URLView *mailView = new URLView(url_rect,"email",email,mail_uri.String());
|
||||
mailView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
mailView->SetFont(&font);
|
||||
bgview->AddChild(mailView);
|
||||
}
|
||||
|
||||
SetAppName(app_name);
|
||||
SetBuiltDate(built_date);
|
||||
|
||||
LoadVersion();
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* InitGUI
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutWindow::InitGUI()
|
||||
{
|
||||
BRect bitmapRect(0,0,31,31);
|
||||
bitmapRect.OffsetBy(20,5);
|
||||
|
||||
fAboutView = new HAboutView(Bounds());
|
||||
BRect rect(ICON_OFFSET,15,ICON_OFFSET,15+fBoldHeight);
|
||||
fAppName = new BStringView(rect,"name","",B_FOLLOW_NONE);
|
||||
fAboutView->AddChild(fAppName);
|
||||
rect.OffsetBy(0,fBoldHeight);
|
||||
rect.bottom = rect.top + fPlainHeight;
|
||||
fVersion = new BStringView(rect,"ver","",B_FOLLOW_NONE);
|
||||
fAboutView->AddChild(fVersion);
|
||||
rect.OffsetBy(0,fPlainHeight);
|
||||
fBuiltDate = new BStringView(rect,"build","",B_FOLLOW_NONE);
|
||||
fAboutView->AddChild(fBuiltDate);
|
||||
rect.OffsetBy(0,fPlainHeight);
|
||||
fComment = new CTextView(rect,"comment",B_FOLLOW_NONE,B_WILL_DRAW);
|
||||
fAboutView->AddChild(fComment);
|
||||
AddChild(fAboutView);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Load icon from application resource
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutWindow::LoadIcon()
|
||||
{
|
||||
//Extract title bitmap
|
||||
BBitmap *icon = new BBitmap(BRect(0,0,31,31),B_COLOR_8_BIT);
|
||||
app_info info;
|
||||
BPath path;
|
||||
be_app->GetAppInfo(&info);
|
||||
BNodeInfo::GetTrackerIcon(&info.ref,icon,B_LARGE_ICON);
|
||||
fAboutView->SetBitmap(icon);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Load versino from application resource.
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutWindow::LoadVersion()
|
||||
{
|
||||
//Extract version resource
|
||||
BString version = "";
|
||||
BResources* app_version_resource = BApplication::AppResources();
|
||||
if(app_version_resource)
|
||||
{
|
||||
size_t resource_size;
|
||||
const char* app_version_data = (const char*)app_version_resource->LoadResource('APPV',
|
||||
"BEOS:APP_VERSION",&resource_size);
|
||||
if(app_version_data && resource_size > 20)
|
||||
{
|
||||
const char* status[] = {"Development","Alpha","Beta","Gamma",
|
||||
"Golden master","Final"};
|
||||
app_version_info *info = (app_version_info*)app_version_data;
|
||||
uint32 v1 = info->v1;
|
||||
uint32 v2 = info->v2;
|
||||
uint32 v3 = info->v3;
|
||||
version << v1 << "." << v2 << "." << v3;
|
||||
if(info->status != 5)
|
||||
version << " " <<status[info->status];
|
||||
if(info->rel != 0)
|
||||
version << " Release " << info->rel;
|
||||
SetVersion(version.String());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Set applicaiton name
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutWindow::SetAppName(const char* name)
|
||||
{
|
||||
BFont font(be_bold_font);
|
||||
font.SetSize(14);
|
||||
|
||||
BRect rect(0,0,font.StringWidth(name),fBoldHeight);
|
||||
BRect old_rect = fAppName->Bounds();
|
||||
fAppName->SetFont(&font);
|
||||
fAppName->ResizeBy(rect.Width()-old_rect.Width(),rect.Height()-old_rect.Height());
|
||||
fAppName->SetText(name);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Set application built date.
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutWindow::SetBuiltDate(const char* date)
|
||||
{
|
||||
BString title="Built date: ";
|
||||
title << date;
|
||||
|
||||
BFont font(be_plain_font);
|
||||
font.SetSize(10);
|
||||
|
||||
BRect rect(0,0,font.StringWidth(title.String()),fPlainHeight);
|
||||
BRect old_rect = fBuiltDate->Bounds();
|
||||
fBuiltDate->SetFont(&font);
|
||||
fBuiltDate->ResizeBy(rect.Width()-old_rect.Width(),rect.Height()-old_rect.Height());
|
||||
fBuiltDate->SetText(title.String());
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Set comments
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutWindow::SetComment(const char* text)
|
||||
{
|
||||
BFont font(be_plain_font);
|
||||
font.SetSize(10);
|
||||
|
||||
fComment->SetFont(&font);
|
||||
fComment->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
fComment->MakeEditable(false);
|
||||
fComment->MakeFocus(false);
|
||||
fComment->MakeSelectable(false);
|
||||
fComment->SetWordWrap(false);
|
||||
fComment->SetText(text);
|
||||
int32 lines = fComment->CountLines();
|
||||
BRect rect(0,0,font.StringWidth(text)+4,fPlainHeight*lines+4);
|
||||
BRect old_rect = fComment->Bounds();
|
||||
fComment->ResizeBy(rect.Width()-old_rect.Width(),rect.Height()-old_rect.Height());
|
||||
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Set version info
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutWindow::SetVersion(const char* version)
|
||||
{
|
||||
BString title="Version ";
|
||||
title << version;
|
||||
|
||||
BFont font(be_plain_font);
|
||||
font.SetSize(10);
|
||||
|
||||
BRect rect(0,0,font.StringWidth(title.String()),fPlainHeight);
|
||||
BRect old_rect = fVersion->Bounds();
|
||||
fVersion->SetFont(&font);
|
||||
fVersion->ResizeBy(rect.Width()-old_rect.Width(),rect.Height()-old_rect.Height());
|
||||
fVersion->SetText(title.String());
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Calc font height
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutWindow::CalcFontHeights()
|
||||
{
|
||||
BFont plainfont(be_plain_font);
|
||||
plainfont.SetSize(10);
|
||||
|
||||
font_height FontAttributes;
|
||||
plainfont.GetHeight(&FontAttributes);
|
||||
fPlainHeight = ceil(FontAttributes.ascent) + ceil(FontAttributes.descent);
|
||||
|
||||
BFont boldfont(be_bold_font);
|
||||
boldfont.SetSize(14);
|
||||
|
||||
boldfont.GetHeight(&FontAttributes);
|
||||
fBoldHeight = ceil(FontAttributes.ascent) + ceil(FontAttributes.descent);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* HAboutView
|
||||
****************************************************************************/
|
||||
const float kBorderWidth = 32.0f;
|
||||
const rgb_color kDarkBorderColor = {184, 184, 184, 255};
|
||||
|
||||
/***********************************************************
|
||||
* Constructor
|
||||
***********************************************************/
|
||||
HAboutView::HAboutView(BRect rect,BBitmap *icon)
|
||||
:BView(rect,"aboutview",B_FOLLOW_ALL,B_WILL_DRAW)
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
fIcon = icon;
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Destructor
|
||||
***********************************************************/
|
||||
HAboutView::~HAboutView()
|
||||
{
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Draw
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutView::Draw(BRect updateRect)
|
||||
{
|
||||
BRect drawBounds(Bounds());
|
||||
drawBounds.right = kBorderWidth;
|
||||
SetHighColor(kDarkBorderColor);
|
||||
FillRect(drawBounds);
|
||||
|
||||
if(fIcon != NULL)
|
||||
{
|
||||
BRect bitmapRect(0,0,31,31);
|
||||
bitmapRect.OffsetBy(20,5);
|
||||
drawing_mode mode = DrawingMode();
|
||||
SetDrawingMode(B_OP_ALPHA);
|
||||
DrawBitmap(fIcon,bitmapRect);
|
||||
SetDrawingMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Set view bitmap
|
||||
***********************************************************/
|
||||
void
|
||||
HAboutView::SetBitmap(BBitmap *bitmap)
|
||||
{
|
||||
delete fIcon;
|
||||
fIcon = bitmap;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
#ifndef __ABOUTWINDOW_H__
|
||||
#define __ABOUTWINDOW_H__
|
||||
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
#include <Bitmap.h>
|
||||
#include <StringView.h>
|
||||
|
||||
class CTextView;
|
||||
class BitmapView;
|
||||
|
||||
typedef struct {
|
||||
uint32 v1;
|
||||
uint32 v2;
|
||||
uint32 v3;
|
||||
uint32 status;
|
||||
uint32 rel;
|
||||
} app_version_info;
|
||||
|
||||
/**********************************************************************
|
||||
* HAboutView
|
||||
**********************************************************************/
|
||||
class HAboutView : public BView
|
||||
{
|
||||
public:
|
||||
HAboutView(BRect rect,BBitmap *icon = NULL);
|
||||
virtual ~HAboutView();
|
||||
void SetBitmap(BBitmap* bitmap);
|
||||
protected:
|
||||
|
||||
virtual void Draw(BRect);
|
||||
private:
|
||||
BBitmap* fIcon;
|
||||
};
|
||||
/**********************************************************************
|
||||
* HAboutWindow
|
||||
**********************************************************************/
|
||||
class HAboutWindow :public BWindow {
|
||||
public:
|
||||
HAboutWindow(const char* app_name,
|
||||
const char* built_data,
|
||||
const char* comment,
|
||||
const char* url = NULL,
|
||||
const char* mail = NULL);
|
||||
protected:
|
||||
void InitGUI();
|
||||
void SetAppName(const char* app_name);
|
||||
void SetBuiltDate(const char* text);
|
||||
void SetVersion(const char* version);
|
||||
void SetComment(const char* text);
|
||||
void LoadIcon();
|
||||
void LoadVersion();
|
||||
void CalcFontHeights();
|
||||
private:
|
||||
BStringView* fAppName;
|
||||
BStringView* fVersion;
|
||||
BStringView* fBuiltDate;
|
||||
HAboutView* fAboutView;
|
||||
CTextView* fComment;
|
||||
float fBoldHeight;
|
||||
float fPlainHeight;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,107 +0,0 @@
|
||||
#include "IconMenuItem.h"
|
||||
|
||||
#include <Bitmap.h>
|
||||
|
||||
/***********************************************************
|
||||
* Constructor.
|
||||
***********************************************************/
|
||||
IconMenuItem::IconMenuItem(const char* label,BMessage *message,char shortcut,uint32 modifiers,BBitmap *bitmap,bool copy,bool free)
|
||||
:BMenuItem(label,message,shortcut,modifiers)
|
||||
,fBitmap(NULL)
|
||||
,fCopy(copy)
|
||||
{
|
||||
SetBitmap(bitmap,free);
|
||||
fHeightDelta = 0;
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Constructor.
|
||||
***********************************************************/
|
||||
IconMenuItem::IconMenuItem(BMenu *submenu,BMessage *message,char shortcut,uint32 modifiers,BBitmap *bitmap,bool copy,bool free)
|
||||
:BMenuItem(submenu,message)
|
||||
,fBitmap(NULL)
|
||||
,fCopy(copy)
|
||||
{
|
||||
SetBitmap(bitmap,free);
|
||||
fHeightDelta = 0;
|
||||
SetShortcut(shortcut,modifiers);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Destructor.
|
||||
***********************************************************/
|
||||
IconMenuItem::~IconMenuItem()
|
||||
{
|
||||
if(fCopy)
|
||||
delete fBitmap;
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Draw menu icon.
|
||||
***********************************************************/
|
||||
void
|
||||
IconMenuItem::DrawContent()
|
||||
{
|
||||
|
||||
if(fBitmap != NULL)
|
||||
{
|
||||
|
||||
BPoint drawPoint(ContentLocation());
|
||||
// center text and icon.
|
||||
drawing_mode mode = Menu()->DrawingMode();
|
||||
Menu()->SetDrawingMode(B_OP_ALPHA);
|
||||
//Menu()->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
||||
Menu()->SetLowColor( Menu()->ViewColor());
|
||||
//Menu()->SetHighColor(B_TRANSPARENT_32_BIT);
|
||||
if( !IsEnabled() )
|
||||
{
|
||||
Menu()->SetDrawingMode(B_OP_BLEND);
|
||||
Menu()->DrawBitmap(fBitmap,drawPoint);
|
||||
Menu()->SetDrawingMode(B_OP_OVER);
|
||||
}else
|
||||
Menu()->DrawBitmap(fBitmap,drawPoint);
|
||||
// offset to title point.
|
||||
drawPoint.y += ceil( fHeightDelta/2 );
|
||||
drawPoint.x += 20;
|
||||
// Move draw point.
|
||||
Menu()->MovePenTo(drawPoint);
|
||||
Menu()->SetDrawingMode(mode);
|
||||
}
|
||||
|
||||
BMenuItem::DrawContent();
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Extruct content width
|
||||
***********************************************************/
|
||||
void
|
||||
IconMenuItem::GetContentSize(float *width, float *height)
|
||||
{
|
||||
BMenuItem::GetContentSize(width,height);
|
||||
(*width) += 20;
|
||||
fHeightDelta = 16 - (*height);
|
||||
if( (*height) < 16)
|
||||
(*height) = 16;
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Set the other bitmap.
|
||||
***********************************************************/
|
||||
void
|
||||
IconMenuItem::SetBitmap(BBitmap *bitmap,bool free)
|
||||
{
|
||||
if(fCopy)
|
||||
delete fBitmap;
|
||||
|
||||
if(!fCopy)
|
||||
fBitmap = bitmap;
|
||||
else{
|
||||
if(bitmap)
|
||||
{
|
||||
fBitmap = new BBitmap(bitmap);
|
||||
if(free) delete bitmap;
|
||||
}else
|
||||
fBitmap = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*************************************************************
|
||||
* IconMenu
|
||||
*
|
||||
* Toolbar is a usefull UI component.
|
||||
*
|
||||
* @author Atsushi Takamatsu (tak_atsu@tau.bekkoame.ne.jp)
|
||||
**************************************************************/
|
||||
|
||||
#ifndef __ICONMENUITEM_H__
|
||||
#define __ICONMENUITEM_H__
|
||||
|
||||
#include <MenuItem.h>
|
||||
|
||||
class IconMenuItem :public BMenuItem {
|
||||
public:
|
||||
IconMenuItem(const char* label
|
||||
,BMessage *message
|
||||
,char shortcut = 0
|
||||
,uint32 modifiers = 0
|
||||
,BBitmap *bitmap = NULL
|
||||
,bool copyBitmap = true
|
||||
,bool deleteInputBitmap = true);
|
||||
IconMenuItem(BMenu *submenu
|
||||
,BMessage *message
|
||||
,char shortcut = 0
|
||||
,uint32 modifiers = 0
|
||||
,BBitmap *bitmap = NULL
|
||||
,bool copyBitmap = true
|
||||
,bool deleteInputBitmap = true);
|
||||
virtual ~IconMenuItem();
|
||||
void SetBitmap(BBitmap *bitmap,bool freePointer=false);
|
||||
protected:
|
||||
virtual void DrawContent();
|
||||
virtual void GetContentSize(float *width ,float *height);
|
||||
private:
|
||||
BBitmap *fBitmap;
|
||||
bool fCopy;
|
||||
float fHeightDelta;
|
||||
};
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
#include "RectUtils.h"
|
||||
#include <Screen.h>
|
||||
#include <Roster.h>
|
||||
#include <Application.h>
|
||||
#include <fs_attr.h>
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
BRect
|
||||
RectUtils::CenterRect(float width,float height)
|
||||
{
|
||||
BRect frame = BScreen().Frame();
|
||||
BRect rect;
|
||||
|
||||
rect.left = frame.Width()/2.0 - width/2.0;
|
||||
rect.right = rect.left + width;
|
||||
rect.top = frame.Height()/2.0 - height/2.0;
|
||||
rect.bottom = rect.top + height;
|
||||
return rect;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load rect data from the application file attribute.
|
||||
*/
|
||||
bool
|
||||
RectUtils::LoadRectFromApp(const char* name,BRect *rect)
|
||||
{
|
||||
app_info info;
|
||||
be_app->GetAppInfo(&info);
|
||||
BEntry entry(&info.ref);
|
||||
bool rc = false;
|
||||
|
||||
BFile appfile(&entry,B_READ_ONLY);
|
||||
attr_info ainfo;
|
||||
status_t err = appfile.GetAttrInfo(name,&ainfo);
|
||||
if(err == B_OK)
|
||||
{
|
||||
appfile.ReadAttr(name,B_RECT_TYPE,0,rect,sizeof(BRect));
|
||||
rc = true;
|
||||
} else {
|
||||
rc = false;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Save rect data to the application file attribute.
|
||||
*/
|
||||
void
|
||||
RectUtils::SaveRectToApp(const char* name,BRect rect)
|
||||
{
|
||||
app_info info;
|
||||
be_app->GetAppInfo(&info);
|
||||
BEntry entry(&info.ref);
|
||||
|
||||
BFile appfile(&entry,B_WRITE_ONLY);
|
||||
appfile.WriteAttr(name,B_RECT_TYPE,0,&rect,sizeof(BRect));
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef __RECTUTILS_H__
|
||||
#define __RECTUTILS_H__
|
||||
|
||||
#include <Rect.h>
|
||||
|
||||
class RectUtils {
|
||||
public:
|
||||
RectUtils(){};
|
||||
~RectUtils(){};
|
||||
BRect CenterRect(float width,float height);
|
||||
void SaveRectToApp(const char* name,BRect rect);
|
||||
bool LoadRectFromApp(const char* name,BRect *rect);
|
||||
};
|
||||
#endif
|
||||
@@ -1,279 +0,0 @@
|
||||
#include "ResourceUtils.h"
|
||||
#include <Application.h>
|
||||
#include <stdio.h>
|
||||
#include <String.h>
|
||||
|
||||
ResourceUtils::ResourceUtils(BResources *rsrc)
|
||||
:BLocker()
|
||||
,fResource(NULL)
|
||||
{
|
||||
if(rsrc == NULL)
|
||||
fResource = BApplication::AppResources();
|
||||
else
|
||||
fResource = rsrc;
|
||||
}
|
||||
|
||||
ResourceUtils::ResourceUtils(const char *path)
|
||||
:BLocker()
|
||||
,fResource(NULL)
|
||||
{
|
||||
if(path == NULL)
|
||||
fResource = BApplication::AppResources();
|
||||
else{
|
||||
BFile file(path, B_READ_WRITE);
|
||||
BResources *res = new BResources();
|
||||
status_t err;
|
||||
if((err = res->SetTo(&file)) != B_OK)
|
||||
fResource = BApplication::AppResources();
|
||||
else
|
||||
fResource = res;
|
||||
}
|
||||
}
|
||||
|
||||
ResourceUtils::~ResourceUtils()
|
||||
{
|
||||
//if(fResource != BApplication::AppResources())
|
||||
// delete fResource;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load icon by id.
|
||||
*/
|
||||
status_t
|
||||
ResourceUtils::GetIconResource(int32 id, icon_size size, BBitmap *dest)
|
||||
{
|
||||
if (size != B_LARGE_ICON && size != B_MINI_ICON )
|
||||
return B_ERROR;
|
||||
|
||||
size_t len = 0;
|
||||
|
||||
this->Lock();
|
||||
const void *data = fResource->LoadResource(size == B_LARGE_ICON ? 'ICON' : 'MICN',
|
||||
id, &len);
|
||||
this->Unlock();
|
||||
if (data == 0 || len != (size_t)(size == B_LARGE_ICON ? 1024 : 256)) {
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
dest->SetBits(data, (int32)len, 0, B_COLOR_8_BIT);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load icon by name.
|
||||
*/
|
||||
status_t
|
||||
ResourceUtils::GetIconResource(const char* name, icon_size size, BBitmap *dest)
|
||||
{
|
||||
if (size != B_LARGE_ICON && size != B_MINI_ICON )
|
||||
return B_ERROR;
|
||||
|
||||
size_t len = 0;
|
||||
this->Lock();
|
||||
const void *data = fResource->LoadResource(size == B_LARGE_ICON ? 'ICON' : 'MICN',
|
||||
name, &len);
|
||||
this->Unlock();
|
||||
if (data == 0 || len != (size_t)(size == B_LARGE_ICON ? 1024 : 256)) {
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
dest->SetBits(data, (int32)len, 0, B_COLOR_8_BIT);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Load bitmap by id.
|
||||
*/
|
||||
status_t
|
||||
ResourceUtils::GetBitmapResource(type_code type, int32 id, BBitmap **out)
|
||||
{
|
||||
*out = NULL;
|
||||
|
||||
size_t len = 0;
|
||||
|
||||
this->Lock();
|
||||
const void *data = fResource->LoadResource(type, id, &len);
|
||||
this->Unlock();
|
||||
|
||||
if (data == NULL) {
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
BMemoryIO stream(data, len);
|
||||
|
||||
// Try to read as an archived bitmap.
|
||||
stream.Seek(0, SEEK_SET);
|
||||
BMessage archive;
|
||||
status_t err = archive.Unflatten(&stream);
|
||||
if (err != B_OK)
|
||||
return err;
|
||||
|
||||
*out = new BBitmap(&archive);
|
||||
if (!*out)
|
||||
return B_ERROR;
|
||||
|
||||
err = (*out)->InitCheck();
|
||||
if (err != B_OK) {
|
||||
delete *out;
|
||||
*out = NULL;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load bitmap by name.
|
||||
*/
|
||||
status_t
|
||||
ResourceUtils::GetBitmapResource(type_code type, const char* name, BBitmap **out)
|
||||
{
|
||||
*out = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
this->Lock();
|
||||
const void *data = fResource->LoadResource(type, name, &len);
|
||||
this->Unlock();
|
||||
if (data == NULL) {
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
BMemoryIO stream(data, len);
|
||||
|
||||
// Try to read as an archived bitmap.
|
||||
stream.Seek(0, SEEK_SET);
|
||||
BMessage archive;
|
||||
status_t err = archive.Unflatten(&stream);
|
||||
if (err != B_OK)
|
||||
return err;
|
||||
|
||||
*out = new BBitmap(&archive);
|
||||
if (!*out)
|
||||
return B_ERROR;
|
||||
|
||||
err = (*out)->InitCheck();
|
||||
if (err != B_OK) {
|
||||
delete *out;
|
||||
*out = NULL;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load bitmap by name.
|
||||
*/
|
||||
BBitmap*
|
||||
ResourceUtils::GetBitmapResource(type_code type, const char* name)
|
||||
{
|
||||
size_t len = 0;
|
||||
this->Lock();
|
||||
const void *data = fResource->LoadResource(type, name, &len);
|
||||
this->Unlock();
|
||||
if (data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BMemoryIO stream(data, len);
|
||||
|
||||
// Try to read as an archived bitmap.
|
||||
stream.Seek(0, SEEK_SET);
|
||||
BMessage archive;
|
||||
status_t err = archive.Unflatten(&stream);
|
||||
if (err != B_OK)
|
||||
return NULL;
|
||||
|
||||
BBitmap* out = new BBitmap(&archive);
|
||||
if (!out)
|
||||
return NULL;
|
||||
|
||||
err = (out)->InitCheck();
|
||||
if (err != B_OK) {
|
||||
delete out;
|
||||
out = NULL;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get string from resources.
|
||||
*/
|
||||
const char*
|
||||
ResourceUtils::GetString(const char* name)
|
||||
{
|
||||
size_t len = 0;
|
||||
this->Lock();
|
||||
const void* data;
|
||||
if(fResource->HasResource('CSTR',name))
|
||||
{
|
||||
data = fResource->LoadResource('CSTR', name, &len);
|
||||
}else
|
||||
data = name;
|
||||
this->Unlock();
|
||||
return (const char*)data;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get string from resources.
|
||||
*/
|
||||
status_t
|
||||
ResourceUtils::GetString(const char* name,BString &outStr)
|
||||
{
|
||||
size_t len = 0;
|
||||
this->Lock();
|
||||
const void* data;
|
||||
status_t err = B_OK;
|
||||
if(fResource->HasResource('CSTR',name))
|
||||
{
|
||||
data = fResource->LoadResource('CSTR', name, &len);
|
||||
outStr = (const char*)data;
|
||||
}else{
|
||||
err = B_ERROR;
|
||||
outStr = name;
|
||||
}
|
||||
this->Unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set resources.
|
||||
*/
|
||||
void
|
||||
ResourceUtils::SetResource(BResources *rsrc)
|
||||
{
|
||||
fResource = rsrc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set resources.
|
||||
*/
|
||||
void
|
||||
ResourceUtils::SetResource(const char* path)
|
||||
{
|
||||
BFile file(path, B_READ_WRITE);
|
||||
BResources *res = new BResources();
|
||||
status_t err;
|
||||
if((err = res->SetTo(&file)) != B_OK)
|
||||
fResource = BApplication::AppResources();
|
||||
else
|
||||
fResource = res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free fResource. But You must not free when load app resource.
|
||||
*/
|
||||
void
|
||||
ResourceUtils::FreeResource()
|
||||
{
|
||||
delete fResource;
|
||||
}
|
||||
|
||||
/*
|
||||
* Preload resources.
|
||||
*/
|
||||
void
|
||||
ResourceUtils::Preload(type_code type)
|
||||
{
|
||||
fResource->PreloadResourceType(type);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#ifndef __RESOURCEUTILS_H__
|
||||
#define __RESOURCEUTILS_H__
|
||||
|
||||
#include <Resources.h>
|
||||
#include <Bitmap.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <Mime.h>
|
||||
#include <Errors.h>
|
||||
#include <TypeConstants.h>
|
||||
#include <Application.h>
|
||||
#include <Locker.h>
|
||||
|
||||
class ResourceUtils :public BLocker {
|
||||
public:
|
||||
ResourceUtils(BResources *rsrc = NULL);
|
||||
ResourceUtils(const char* path);
|
||||
~ResourceUtils();
|
||||
|
||||
void SetResource(BResources *rsrc);
|
||||
void SetResource(const char* path);
|
||||
|
||||
void Preload(type_code type);
|
||||
void FreeResource();
|
||||
|
||||
status_t GetIconResource(int32 id, icon_size size, BBitmap *dest);
|
||||
status_t GetIconResource(const char* name, icon_size size, BBitmap *dest);
|
||||
status_t GetBitmapResource(type_code type, int32 id, BBitmap **out);
|
||||
status_t GetBitmapResource(type_code type, const char* name, BBitmap **out);
|
||||
BBitmap* GetBitmapResource(type_code type, const char* name);
|
||||
const char* GetString(const char* name);
|
||||
status_t GetString(const char* name,BString &outStr);
|
||||
|
||||
BResources* Resources() {return fResource;}
|
||||
protected:
|
||||
BResources *fResource;
|
||||
};
|
||||
#endif
|
||||
@@ -1,913 +0,0 @@
|
||||
/* URLView 2.0
|
||||
written by William Kakes of Tall Hill Software.
|
||||
|
||||
This class provides an underlined and clickable BStringView
|
||||
that will launch the web browser, e-mail program, or FTP client
|
||||
when clicked on. Other features include hover-highlighting,
|
||||
right-click menus, and drag-and-drop support.
|
||||
|
||||
You are free to use URLView in your own programs (both open-source
|
||||
and closed-source) free of charge, but a mention in your read me
|
||||
file or your program's about box would be appreciated. See
|
||||
http://www.tallhill.com for current contact information.
|
||||
|
||||
URLView is provided as-is, with no warranties of any kind. If
|
||||
you use it, you are on your own.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "URLView.h"
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
#include <fs_attr.h>
|
||||
#include <MenuItem.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Path.h>
|
||||
#include <Roster.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
URLView::URLView( BRect frame, const char *name, const char *label,
|
||||
const char *url, uint32 resizingMode, uint32 flags )
|
||||
: BStringView( frame, name, label, resizingMode, flags ) {
|
||||
|
||||
// Set the instance variables.
|
||||
this->url = new BString( url );
|
||||
|
||||
// Set the default values for the other definable instance variables.
|
||||
this->color = blue;
|
||||
this->clickColor = red;
|
||||
this->hoverColor = dark_blue;
|
||||
this->hoverEnabled = true;
|
||||
this->draggable = true;
|
||||
this->iconSize = 16;
|
||||
this->underlineThickness = 1;
|
||||
|
||||
// Create the cursor to use when over the link.
|
||||
this->linkCursor = new BCursor( url_cursor );
|
||||
|
||||
// The link is not currently selected.
|
||||
selected = false;
|
||||
|
||||
// The URL is currently not hover-colored.
|
||||
hovering = false;
|
||||
|
||||
// The user has not dragged out of the view.
|
||||
draggedOut = false;
|
||||
|
||||
// The user has not yet opened the popup menu.
|
||||
inPopup = false;
|
||||
|
||||
// Initialize the attributes list (there are 14 standard
|
||||
// Person attributes).
|
||||
attributes = new BList( 14 );
|
||||
}
|
||||
|
||||
|
||||
URLView::~URLView() {
|
||||
delete url;
|
||||
delete linkCursor;
|
||||
|
||||
// Delete all the attributes.
|
||||
KeyPair *item;
|
||||
for( int i = 0; (item = (KeyPair *) attributes->ItemAt(i)); i++ ) {
|
||||
delete item->key;
|
||||
delete item->value;
|
||||
delete item;
|
||||
}
|
||||
delete attributes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void URLView::AttachedToWindow() {
|
||||
// When the view is first attached, we want to draw the link
|
||||
// in the normal color. Also, we want to set our background color
|
||||
// to meet that of our parent.
|
||||
SetHighColor( color );
|
||||
if( Parent() != NULL ) {
|
||||
SetLowColor( Parent()->ViewColor() );
|
||||
SetViewColor( Parent()->ViewColor() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::Draw( BRect updateRect ) {
|
||||
BRect rect = Frame();
|
||||
rect.OffsetTo( B_ORIGIN );
|
||||
|
||||
// We want 'g's, etc. to go below the underline. When the BeOS can
|
||||
// do underlining of any font, this code can be removed.
|
||||
font_height height;
|
||||
GetFontHeight( &height );
|
||||
float descent = height.descent / 2;
|
||||
|
||||
// Draw the underline in the requested thickness.
|
||||
FillRect( BRect( (float) rect.left,
|
||||
(float) (rect.bottom - descent - underlineThickness + 1),
|
||||
(float) StringWidth( Text() ),
|
||||
(float) rect.bottom - descent ) );
|
||||
|
||||
// Note: DrawString() draws the text at one pixel above the pen's
|
||||
// current y coordinate.
|
||||
MovePenTo( BPoint( rect.left, rect.bottom - descent -
|
||||
(float) underlineThickness ) );
|
||||
DrawString( Text() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::MessageReceived( BMessage *message ) {
|
||||
// Is this a message from Tracker in response to our drag-and-drop?
|
||||
if( message->what == 'DDCP' ) {
|
||||
// Tracker will send back the name and path of the created file.
|
||||
// We need to read this information.
|
||||
entry_ref ref;
|
||||
message->FindRef( "directory", &ref );
|
||||
BEntry entry( &ref );
|
||||
BPath path( &entry );
|
||||
BString *fullName = new BString( path.Path() );
|
||||
fullName->Append( "/" );
|
||||
fullName->Append( message->FindString( "name" ) );
|
||||
BString *title = new BString( Text() );
|
||||
|
||||
// Set the new file as a bookmark or as a person as appropriate.
|
||||
if( IsEmailLink() ) {
|
||||
CreatePerson( fullName, title );
|
||||
}
|
||||
else CreateBookmark( fullName, title );
|
||||
|
||||
delete fullName;
|
||||
delete title;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::MouseDown( BPoint point ) {
|
||||
// See which mouse buttons were clicked.
|
||||
int32 buttons = Window()->CurrentMessage()->FindInt32( "buttons" );
|
||||
|
||||
// We want to highlight the text if the user clicks on
|
||||
// the URL. We want to be sure to only register a click
|
||||
// if the user clicks on the link text itself and not just
|
||||
// anywhere in the view.
|
||||
if( GetTextRect().Contains( point ) ) {
|
||||
SetHighColor( clickColor );
|
||||
Redraw();
|
||||
|
||||
// Set the link as selected and track the mouse.
|
||||
selected = true;
|
||||
SetMouseEventMask( B_POINTER_EVENTS );
|
||||
|
||||
// Remember where the user clicked.
|
||||
dragOffset = point;
|
||||
|
||||
// Pop up the context menu?
|
||||
if( buttons == B_SECONDARY_MOUSE_BUTTON ) inPopup = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::MouseMoved( BPoint point, uint32 transit,
|
||||
const BMessage *message ) {
|
||||
|
||||
// Make sure the window is the active one.
|
||||
if( !Window()->IsActive() ) return;
|
||||
|
||||
// See which mouse buttons were clicked.
|
||||
int32 buttons = Window()->CurrentMessage()->FindInt32( "buttons" );
|
||||
// Is the user currently dragging the link? (i.e. is a mouse button
|
||||
// currently down?)
|
||||
bool alreadyDragging = (buttons != 0);
|
||||
|
||||
switch( transit ) {
|
||||
case( B_ENTERED_VIEW ):
|
||||
// Should we set the cursor to the link cursor?
|
||||
if( GetTextRect().Contains( point ) && !draggedOut ) {
|
||||
if( !alreadyDragging ) be_app->SetCursor( linkCursor );
|
||||
|
||||
// Did the user leave and re-enter the view while
|
||||
// holding down the mouse button? If so, highlight
|
||||
// the link.
|
||||
if( selected ) {
|
||||
SetHighColor( clickColor );
|
||||
Redraw();
|
||||
}
|
||||
// Should we hover-highlight the link?
|
||||
else if( hoverEnabled && !alreadyDragging ) {
|
||||
if( buttons == 0 ) {
|
||||
SetHighColor( hoverColor );
|
||||
Redraw();
|
||||
hovering = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case( B_EXITED_VIEW ):
|
||||
// We want to restore the link to it normal color and the
|
||||
// mouse cursor to the normal hand. However, we should only
|
||||
// set the color and re-draw if it is needed.
|
||||
if( selected && !draggedOut ) {
|
||||
be_app->SetCursor( B_HAND_CURSOR );
|
||||
SetHighColor( color );
|
||||
Redraw();
|
||||
|
||||
// Is the user drag-and-dropping a bookmark or person?
|
||||
if( draggable ) {
|
||||
draggedOut = true;
|
||||
if( IsEmailLink() ) DoPersonDrag();
|
||||
else DoBookmarkDrag();
|
||||
}
|
||||
}
|
||||
// Is the link currently hover-highlighted? If so, restore
|
||||
// the normal color now.
|
||||
else if( hovering && !alreadyDragging ) {
|
||||
be_app->SetCursor( B_HAND_CURSOR );
|
||||
SetHighColor( color );
|
||||
Redraw();
|
||||
hovering = false;
|
||||
}
|
||||
// Change the cursor back to the hand.
|
||||
else {
|
||||
be_app->SetCursor( B_HAND_CURSOR );
|
||||
}
|
||||
break;
|
||||
|
||||
case( B_INSIDE_VIEW ):
|
||||
// The user could either be moving out of the view or
|
||||
// back into it here, so we must handle both cases.
|
||||
// In the first case, the cursor is now over the link.
|
||||
if( GetTextRect().Contains( point ) && !draggedOut ) {
|
||||
// We only want to change the cursor if not dragging.
|
||||
if( !alreadyDragging ) be_app->SetCursor( linkCursor );
|
||||
if( selected ) {
|
||||
if( draggable ) {
|
||||
// If the user moves the mouse more than ten
|
||||
// pixels, begin the drag.
|
||||
if( (point.x - dragOffset.x) > 10 ||
|
||||
(dragOffset.x - point.x) > 10 ||
|
||||
(point.y - dragOffset.y) > 10 ||
|
||||
(dragOffset.y - point.y) > 10 ) {
|
||||
draggedOut = true;
|
||||
// Draw the appropriate drag object, etc.
|
||||
if( IsEmailLink() ) DoPersonDrag();
|
||||
else DoBookmarkDrag();
|
||||
SetHighColor( color );
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Since the link is not draggable, highlight it
|
||||
// as long as the user holds the button down and
|
||||
// has the mouse cursor over it (like a standard
|
||||
// button).
|
||||
SetHighColor( clickColor );
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
// The link isn't currently selected? If hover-highlighting
|
||||
// is enabled, highlight the link.
|
||||
else if( hoverEnabled && !alreadyDragging ) {
|
||||
SetHighColor( hoverColor );
|
||||
Redraw();
|
||||
hovering = true;
|
||||
}
|
||||
}
|
||||
// In this case, the mouse cursor is not over the link, so we
|
||||
// need to restore the original link color, etc.
|
||||
else if( !draggedOut ) {
|
||||
be_app->SetCursor( B_HAND_CURSOR );
|
||||
if( selected ) {
|
||||
SetHighColor( color );
|
||||
Redraw();
|
||||
|
||||
// Is the user dragging the link?
|
||||
if( draggable ) {
|
||||
draggedOut = true;
|
||||
if( IsEmailLink() ) DoPersonDrag();
|
||||
else DoBookmarkDrag();
|
||||
}
|
||||
}
|
||||
// Is the mouse cursor hovering over the link?
|
||||
else if( hovering ) {
|
||||
SetHighColor( color );
|
||||
Redraw();
|
||||
hovering = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::MouseUp( BPoint point ) {
|
||||
// Do we want to show the right-click menu?
|
||||
if( inPopup && GetTextRect().Contains( point ) ) {
|
||||
BPopUpMenu *popup = CreatePopupMenu();
|
||||
// Work around a current bug in Be's popup menus.
|
||||
point.y = point.y - 6;
|
||||
|
||||
// Display the popup menu.
|
||||
BMenuItem *selected = popup->Go( ConvertToScreen( point ) , false, true );
|
||||
|
||||
// Did the user select an item?
|
||||
if( selected ) {
|
||||
BString label( selected->Label() );
|
||||
// Did the user select the first item? If so, launch the URL.
|
||||
if( label.FindFirst( "Open" ) != B_ERROR ||
|
||||
label.FindFirst( "Send" ) != B_ERROR ||
|
||||
label.FindFirst( "Connect" ) != B_ERROR ) {
|
||||
LaunchURL();
|
||||
}
|
||||
// Did the user select the second item?
|
||||
else if( label.FindFirst( "Copy" ) != B_ERROR ) {
|
||||
CopyToClipboard();
|
||||
}
|
||||
}
|
||||
// If not, restore the normal link color.
|
||||
else {
|
||||
SetHighColor( color );
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
|
||||
// If the link was clicked on (and not dragged), run the program
|
||||
// that should handle the URL.
|
||||
if( selected && GetTextRect().Contains( point ) &&
|
||||
!draggedOut && !inPopup ) {
|
||||
LaunchURL();
|
||||
}
|
||||
selected = false;
|
||||
draggedOut = false;
|
||||
inPopup = false;
|
||||
|
||||
// Should we restore the hovering-highlighted color or the original
|
||||
// link color?
|
||||
if( GetTextRect().Contains( point ) && !draggedOut &&
|
||||
!inPopup && hoverEnabled ) {
|
||||
SetHighColor( hoverColor );
|
||||
}
|
||||
else if( !hovering ) SetHighColor( color );
|
||||
Redraw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void URLView::AddAttribute( const char *name, const char *value ) {
|
||||
// Add an attribute (name and corresponding value) to the object
|
||||
// that will be dragged out (i.e. to fill in Person fields, etc.)
|
||||
KeyPair *newPair = new KeyPair;
|
||||
newPair->key = new BString( name );
|
||||
newPair->value = new BString( value );
|
||||
attributes->AddItem( newPair );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::SetColor( rgb_color color ) {
|
||||
// Set the normal link color.
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
|
||||
void URLView::SetClickColor( rgb_color color ) {
|
||||
// Set the link color used when the link is clicked.
|
||||
clickColor = color;
|
||||
}
|
||||
|
||||
|
||||
void URLView::SetDraggable( bool draggable ) {
|
||||
// Set whether or not this link is draggable.
|
||||
this->draggable = draggable;
|
||||
}
|
||||
|
||||
|
||||
void URLView::SetHoverColor( rgb_color color ) {
|
||||
// Set the link color used when the mouse cursor is over it.
|
||||
hoverColor = color;
|
||||
}
|
||||
|
||||
|
||||
void URLView::SetHoverEnabled( bool hover ) {
|
||||
// Set whether or not to hover-highlight the link.
|
||||
hoverEnabled = hover;
|
||||
}
|
||||
|
||||
|
||||
void URLView::SetIconSize( icon_size iconSize ) {
|
||||
// Set the size of the icon that will be shown when the link is dragged.
|
||||
if( iconSize == B_MINI_ICON ) this->iconSize = 16;
|
||||
else this->iconSize = 32;
|
||||
}
|
||||
|
||||
|
||||
void URLView::SetUnderlineThickness( int thickness ) {
|
||||
// Set the thickness of the underline in pixels.
|
||||
underlineThickness = thickness;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void URLView::CopyToClipboard() {
|
||||
// Copy the URL to the clipboard.
|
||||
BClipboard clipboard( "system" );
|
||||
BMessage *clip = (BMessage *) NULL;
|
||||
// Get the important URL (i.e. trim off "mailto:", etc.).
|
||||
BString newclip = GetImportantURL();
|
||||
|
||||
// Be sure to lock the clipboard first.
|
||||
if( clipboard.Lock() ) {
|
||||
clipboard.Clear();
|
||||
if( (clip = clipboard.Data()) ) {
|
||||
clip->AddData( "text/plain", B_MIME_TYPE, newclip.String(),
|
||||
newclip.Length() + 1 );
|
||||
clipboard.Commit();
|
||||
}
|
||||
clipboard.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::CreateBookmark( const BString *fullName, const BString *title ) {
|
||||
// Read the file defined by the path and the title.
|
||||
BFile *file = new BFile( fullName->String(), B_WRITE_ONLY );
|
||||
|
||||
// Set the file's MIME type to be a bookmark.
|
||||
BNodeInfo *nodeInfo = new BNodeInfo( file );
|
||||
nodeInfo->SetType( "application/x-vnd.Be-bookmark" );
|
||||
delete nodeInfo;
|
||||
delete file;
|
||||
|
||||
// Add all the attributes, both those inherrent to bookmarks and any
|
||||
// the developer may have defined using AddAttribute().
|
||||
DIR *d;
|
||||
int fd;
|
||||
d = fs_open_attr_dir( fullName->String() );
|
||||
if( d ) {
|
||||
fd = open( fullName->String(), O_WRONLY );
|
||||
fs_write_attr( fd, "META:title", B_STRING_TYPE, 0, title->String(), title->Length() + 1 );
|
||||
fs_write_attr( fd, "META:url", B_STRING_TYPE, 0, url->String(), url->Length() + 1 );
|
||||
WriteAttributes( fd );
|
||||
close( fd );
|
||||
fs_close_attr_dir( d );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void URLView::CreatePerson( const BString *fullName, const BString *title ) {
|
||||
// Read the file defined by the path and the title.
|
||||
BFile *file = new BFile( fullName->String(), B_WRITE_ONLY );
|
||||
|
||||
// Set the file's MIME type to be a person.
|
||||
BNodeInfo *nodeInfo = new BNodeInfo( file );
|
||||
nodeInfo->SetType( "application/x-person" );
|
||||
delete nodeInfo;
|
||||
delete file;
|
||||
|
||||
// Add all the attributes, both those inherrent to person files and any
|
||||
// the developer may have defined using AddAttribute().
|
||||
DIR *d;
|
||||
int fd;
|
||||
d = fs_open_attr_dir( fullName->String() );
|
||||
if( d ) {
|
||||
fd = open( fullName->String(), O_WRONLY );
|
||||
fs_write_attr( fd, "META:name", B_STRING_TYPE, 0, title->String(), title->Length() + 1 );
|
||||
BString email = GetImportantURL();
|
||||
fs_write_attr( fd, "META:email", B_STRING_TYPE, 0, email.String(), email.Length() + 1 );
|
||||
WriteAttributes( fd );
|
||||
close( fd );
|
||||
fs_close_attr_dir( d );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
BPopUpMenu * URLView::CreatePopupMenu() {
|
||||
// Create the right-click popup menu.
|
||||
BPopUpMenu *returnMe = new BPopUpMenu( "URLView Popup", false, false );
|
||||
returnMe->SetAsyncAutoDestruct( true );
|
||||
|
||||
entry_ref app;
|
||||
|
||||
// Set the text of the first item according to the link type.
|
||||
if( IsEmailLink() ) {
|
||||
// Find the name of the default e-mail client.
|
||||
if( be_roster->FindApp( "text/x-email", &app ) == B_OK ) {
|
||||
BEntry entry( &app );
|
||||
BString openLabel( "Send e-mail to this address using " );
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
entry.GetName( name );
|
||||
openLabel.Append( name );
|
||||
returnMe->AddItem( new BMenuItem( openLabel.String(), NULL ) );
|
||||
}
|
||||
}
|
||||
else if( IsFTPLink() ) {
|
||||
// Find the name of the default FTP client.
|
||||
if( be_roster->FindApp( "application/x-vnd.Be.URL.ftp", &app ) == B_OK ) {
|
||||
BEntry entry( &app );
|
||||
BString openLabel( "Connect to this server using " );
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
entry.GetName( name );
|
||||
openLabel.Append( name );
|
||||
returnMe->AddItem( new BMenuItem( openLabel.String(), NULL ) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Find the name of the default HTML handler (browser).
|
||||
if( be_roster->FindApp( "text/html", &app ) == B_OK ) {
|
||||
BEntry entry( &app );
|
||||
BString openLabel( "Open this link using " );
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
entry.GetName( name );
|
||||
openLabel.Append( name );
|
||||
returnMe->AddItem( new BMenuItem( openLabel.String(), NULL ) );
|
||||
}
|
||||
}
|
||||
returnMe->AddItem( new BMenuItem( "Copy this link to the clipboard", NULL ) );
|
||||
|
||||
return returnMe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::DoBookmarkDrag() {
|
||||
// Handle all of the bookmark dragging. This includes setting up
|
||||
// the drag message and drawing the dragged bitmap.
|
||||
|
||||
// Set up the drag message to support both BTextView dragging (using
|
||||
// the URL) and file dropping (to Tracker).
|
||||
BMessage *dragMessage = new BMessage( B_MIME_DATA );
|
||||
dragMessage->AddInt32( "be:actions", B_COPY_TARGET );
|
||||
dragMessage->AddString( "be:types", "application/octet-stream" );
|
||||
dragMessage->AddString( "be:filetypes", "application/x-vnd.Be-bookmark" );
|
||||
dragMessage->AddString( "be:type_descriptions", "bookmark" );
|
||||
dragMessage->AddString( "be:clip_name", Text() );
|
||||
dragMessage->AddString( "be:url", url->String() );
|
||||
|
||||
// This allows the user to drag the URL into a standard BTextView.
|
||||
BString link = GetImportantURL();
|
||||
dragMessage->AddData( "text/plain", B_MIME_DATA, link.String(),
|
||||
link.Length() + 1 );
|
||||
|
||||
// Query for the system's icon for bookmarks.
|
||||
BBitmap *bookmarkIcon = new BBitmap( BRect( 0, 0, iconSize - 1,
|
||||
iconSize - 1 ), B_CMAP8 );
|
||||
BMimeType mime( "application/x-vnd.Be-bookmark" );
|
||||
if( iconSize == 16 ) mime.GetIcon( bookmarkIcon, B_MINI_ICON );
|
||||
else mime.GetIcon( bookmarkIcon, B_LARGE_ICON );
|
||||
|
||||
// Find the size of the bitmap to drag. If the text is bigger than the
|
||||
// icon, use that size. Otherwise, use the icon's. Center the icon
|
||||
// vertically in the bitmap.
|
||||
BRect urlRect = GetURLRect();
|
||||
BRect rect = urlRect;
|
||||
rect.right += iconSize + 4;
|
||||
if( (rect.bottom - rect.top) < iconSize ) {
|
||||
int adjustment = (int) ((iconSize - (rect.bottom - rect.top)) / 2) + 1;
|
||||
rect.top -= adjustment;
|
||||
rect.bottom += adjustment;
|
||||
}
|
||||
|
||||
// Make sure the rectangle starts at 0,0.
|
||||
rect.bottom += 0 - rect.top;
|
||||
rect.top = 0;
|
||||
|
||||
// Create the bitmap to draw the dragged image in.
|
||||
BBitmap *dragBitmap = new BBitmap( rect, B_RGBA32, true );
|
||||
BView *dragView = new BView( rect, "Drag View", 0, 0 );
|
||||
dragBitmap->Lock();
|
||||
dragBitmap->AddChild( dragView );
|
||||
|
||||
BRect frameRect = dragView->Frame();
|
||||
|
||||
// Make the background of the dragged image transparent.
|
||||
dragView->SetHighColor( B_TRANSPARENT_COLOR );
|
||||
dragView->FillRect( frameRect );
|
||||
|
||||
// We want 'g's, etc. to go below the underline. When the BeOS can
|
||||
// do underlining of any font, this code can be removed.
|
||||
font_height height;
|
||||
GetFontHeight( &height );
|
||||
float descent = height.descent;
|
||||
|
||||
// Find the vertical center of the view so we can vertically
|
||||
// center everything.
|
||||
int centerPixel = (int) ((frameRect.bottom - frameRect.top) / 2);
|
||||
int textCenter = (int) (descent + underlineThickness) + centerPixel;
|
||||
|
||||
// We want to draw everything only half opaque.
|
||||
dragView->SetDrawingMode( B_OP_ALPHA );
|
||||
dragView->SetHighColor( color.red, color.green, color.blue, 128.0 );
|
||||
dragView->SetBlendingMode( B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE );
|
||||
|
||||
// Center the icon in the view.
|
||||
dragView->MovePenTo( BPoint( frameRect.left,
|
||||
centerPixel - (iconSize / 2) ) );
|
||||
dragView->DrawBitmap( bookmarkIcon );
|
||||
|
||||
// Draw the text in the same font (size, etc.) as the link view.
|
||||
// Note: DrawString() draws the text at one pixel above the pen's
|
||||
// current y coordinate.
|
||||
BFont font;
|
||||
GetFont( &font );
|
||||
dragView->SetFont( &font );
|
||||
dragView->MovePenTo( BPoint( frameRect.left + iconSize + 4, textCenter ) );
|
||||
dragView->DrawString( url->String() );
|
||||
|
||||
// Draw the underline in the requested thickness.
|
||||
dragView->FillRect( BRect( (float) frameRect.left + iconSize + 4,
|
||||
(float) (textCenter + 1),
|
||||
(float) StringWidth( url->String() ) + iconSize + 4,
|
||||
(float) textCenter + underlineThickness ) );
|
||||
|
||||
// Be sure to flush the view buffer so everything is drawn.
|
||||
dragView->Flush();
|
||||
dragBitmap->Unlock();
|
||||
|
||||
// The URL's label is probably not the same size as the URL's
|
||||
// address, which is what we're going to draw. So horizontally
|
||||
// offset the bitmap proportionally to where the user clicked
|
||||
// on the link.
|
||||
float horiz = dragOffset.x / GetTextRect().Width();
|
||||
dragOffset.x = horiz * frameRect.right;
|
||||
|
||||
DragMessage( dragMessage, dragBitmap, B_OP_ALPHA,
|
||||
BPoint( dragOffset.x, (rect.Height() / 2) + 2 ), this );
|
||||
delete dragMessage;
|
||||
|
||||
draggedOut = true;
|
||||
}
|
||||
|
||||
|
||||
void URLView::DoPersonDrag() {
|
||||
// Handle all of the bookmark dragging. This includes setting up
|
||||
// the drag message and drawing the dragged bitmap.
|
||||
|
||||
// Set up the drag message to support both BTextView dragging (using
|
||||
// the e-mail address) and file dropping (to Tracker).
|
||||
BMessage *dragMessage = new BMessage( B_MIME_DATA );
|
||||
dragMessage->AddInt32( "be:actions", B_COPY_TARGET );
|
||||
dragMessage->AddString( "be:types", "application/octet-stream" );
|
||||
dragMessage->AddString( "be:filetypes", "application/x-person" );
|
||||
dragMessage->AddString( "be:type_descriptions", "person" );
|
||||
dragMessage->AddString( "be:clip_name", Text() );
|
||||
|
||||
// This allows the user to drag the e-mail address into a
|
||||
// standard BTextView.
|
||||
BString email = GetImportantURL();
|
||||
dragMessage->AddData( "text/plain", B_MIME_DATA, email.String(),
|
||||
email.Length() + 1 );
|
||||
|
||||
// Query for the system's icon for bookmarks.
|
||||
BBitmap *personIcon = new BBitmap( BRect( 0, 0, iconSize - 1,
|
||||
iconSize - 1 ), B_CMAP8 );
|
||||
BMimeType mime( "application/x-person" );
|
||||
if( iconSize == 16 ) mime.GetIcon( personIcon, B_MINI_ICON );
|
||||
else mime.GetIcon( personIcon, B_LARGE_ICON );
|
||||
|
||||
// Find the size of the bitmap to drag. If the text is bigger than the
|
||||
// icon, use that size. Otherwise, use the icon's. Center the icon
|
||||
// vertically in the bitmap.
|
||||
BRect rect = GetTextRect();
|
||||
rect.right += iconSize + 4;
|
||||
if( (rect.bottom - rect.top) < iconSize ) {
|
||||
int adjustment = (int) ((iconSize - (rect.bottom - rect.top)) / 2) + 1;
|
||||
rect.top -= adjustment;
|
||||
rect.bottom += adjustment;
|
||||
}
|
||||
|
||||
// Make sure the rectangle starts at 0,0.
|
||||
rect.bottom += 0 - rect.top;
|
||||
rect.top = 0;
|
||||
|
||||
// Create the bitmap to draw the dragged image in.
|
||||
BBitmap *dragBitmap = new BBitmap( rect, B_RGBA32, true );
|
||||
BView *dragView = new BView( rect, "Drag View", 0, 0 );
|
||||
dragBitmap->Lock();
|
||||
dragBitmap->AddChild( dragView );
|
||||
|
||||
BRect frameRect = dragView->Frame();
|
||||
|
||||
// Make the background of the dragged image transparent.
|
||||
dragView->SetHighColor( B_TRANSPARENT_COLOR );
|
||||
dragView->FillRect( frameRect );
|
||||
|
||||
// We want 'g's, etc. to go below the underline. When the BeOS can
|
||||
// do underlining of any font, this code can be removed.
|
||||
font_height height;
|
||||
GetFontHeight( &height );
|
||||
float descent = height.descent;
|
||||
|
||||
// Find the vertical center of the view so we can vertically
|
||||
// center everything.
|
||||
int centerPixel = (int) ((frameRect.bottom - frameRect.top) / 2);
|
||||
int textCenter = (int) (descent + underlineThickness) + centerPixel;
|
||||
|
||||
// We want to draw everything only half opaque.
|
||||
dragView->SetDrawingMode( B_OP_ALPHA );
|
||||
dragView->SetHighColor( 0.0, 0.0, 0.0, 128.0 );
|
||||
dragView->SetBlendingMode( B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE );
|
||||
|
||||
// Center the icon in the view.
|
||||
dragView->MovePenTo( BPoint( frameRect.left,
|
||||
centerPixel - (iconSize / 2) ) );
|
||||
dragView->DrawBitmap( personIcon );
|
||||
|
||||
// Draw the text in the same font (size, etc.) as the link view.
|
||||
// Note: DrawString() draws the text at one pixel above the pen's
|
||||
// current y coordinate.
|
||||
BFont font;
|
||||
GetFont( &font );
|
||||
dragView->SetFont( &font );
|
||||
dragView->MovePenTo( BPoint( frameRect.left + iconSize + 4, textCenter ) );
|
||||
dragView->DrawString( Text() );
|
||||
|
||||
// Be sure to flush the view buffer so everything is drawn.
|
||||
dragView->Flush();
|
||||
dragBitmap->Unlock();
|
||||
|
||||
// The Person icon adds some width to the bitmap that we are
|
||||
// going to draw. So horizontally offset the bitmap proportionally
|
||||
// to where the user clicked on the link.
|
||||
float horiz = dragOffset.x / GetTextRect().Width();
|
||||
dragOffset.x = horiz * frameRect.right;
|
||||
|
||||
DragMessage( dragMessage, dragBitmap, B_OP_ALPHA,
|
||||
BPoint( dragOffset.x,
|
||||
(rect.Height() + underlineThickness) / 2 + 2), this );
|
||||
delete dragMessage;
|
||||
|
||||
draggedOut = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BString URLView::GetImportantURL() {
|
||||
// Return the relevant portion of the URL (i.e. strip off "mailto:" from
|
||||
// e-mail address URLs).
|
||||
BString returnMe;
|
||||
|
||||
if( IsEmailLink() ) url->CopyInto( returnMe, 7, url->CountChars() - 6 );
|
||||
else url->CopyInto( returnMe, 0, url->CountChars() );
|
||||
|
||||
return returnMe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BRect URLView::GetTextRect() {
|
||||
// This function will return a BRect that contains only the text
|
||||
// and the underline, so the mouse can change and the link will
|
||||
// be activated only when the mouse is over the text itself, not
|
||||
// just within the view.
|
||||
BRect frame = Frame();
|
||||
frame.OffsetTo( B_ORIGIN );
|
||||
|
||||
// Get the height of the current font.
|
||||
font_height height;
|
||||
GetFontHeight( &height );
|
||||
|
||||
float stringHeight = underlineThickness + height.ascent - 1;
|
||||
|
||||
// Get the rectangle of just the string.
|
||||
return BRect( frame.left, frame.bottom - stringHeight,
|
||||
frame.left + StringWidth( Text() ), frame.bottom - 1 );
|
||||
}
|
||||
|
||||
|
||||
BRect URLView::GetURLRect() {
|
||||
// This function will return a BRect that contains only the text
|
||||
// and the underline, so the mouse can change and the link will
|
||||
// be activated only when the mouse is over the text itself, not
|
||||
// just within the view.
|
||||
BRect frame = Frame();
|
||||
frame.OffsetTo( B_ORIGIN );
|
||||
|
||||
// Get the height of the current font.
|
||||
font_height height;
|
||||
GetFontHeight( &height );
|
||||
|
||||
float stringHeight = underlineThickness + height.ascent - 1;
|
||||
|
||||
// Get the rectangle of just the string.
|
||||
return BRect( frame.left, frame.bottom - stringHeight,
|
||||
frame.left + StringWidth( url->String() ),
|
||||
frame.bottom - 1 );
|
||||
}
|
||||
|
||||
|
||||
bool URLView::IsEmailLink() {
|
||||
// Is this link an e-mail link?
|
||||
return( url->FindFirst( "mailto:" ) == 0 );
|
||||
}
|
||||
|
||||
|
||||
bool URLView::IsFTPLink() {
|
||||
// Is this link an FTP link?
|
||||
return( url->FindFirst( "ftp://" ) == 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::LaunchURL() {
|
||||
// Is the URL a mail link or HTTP?
|
||||
if( IsEmailLink() ) {
|
||||
// Lock the string buffer and pass it to the mail program.
|
||||
char *link = url->LockBuffer( 0 );
|
||||
status_t result = be_roster->Launch( "text/x-email", 1, &link );
|
||||
url->UnlockBuffer();
|
||||
|
||||
if( result == B_ALREADY_RUNNING||result == B_BAD_VALUE)
|
||||
{
|
||||
char app_sig[B_MIME_TYPE_LENGTH];
|
||||
|
||||
BMimeType("text/x-email").GetPreferredApp(app_sig);
|
||||
//result = be_roster->Launch( app_sig, 1, &link );
|
||||
BMessenger messenger(app_sig);
|
||||
BMessage msg(B_ARGV_RECEIVED);
|
||||
msg.AddInt32("argc",2);
|
||||
msg.AddString("argv","app");
|
||||
msg.AddString("argv",link);
|
||||
msg.AddString("cmd","/");
|
||||
BMessage reply;
|
||||
result = messenger.SendMessage(&msg,&reply);
|
||||
}
|
||||
// Make sure the user has an e-mail program.
|
||||
if( result != B_NO_ERROR && result != B_ALREADY_RUNNING ) {
|
||||
BAlert *alert = new BAlert( "E-mail Warning",
|
||||
"There is no e-mail program on your machine that is configured as the default program to send e-mail.",
|
||||
"Ok", NULL, NULL, B_WIDTH_AS_USUAL,
|
||||
B_WARNING_ALERT );
|
||||
alert->Go();
|
||||
}
|
||||
}
|
||||
// Handle an HTTP link.
|
||||
else if( (url->FindFirst( "http://" ) == 0) ||
|
||||
(url->FindFirst( "file://" ) == 0) ) {
|
||||
// Lock the string buffer and pass it to the web browser.
|
||||
char *link = url->LockBuffer( 0 );
|
||||
status_t result = be_roster->Launch( "text/html", 1, &link );
|
||||
url->UnlockBuffer();
|
||||
// Make sure the user has a web browser.
|
||||
if( result != B_NO_ERROR && result != B_ALREADY_RUNNING ) {
|
||||
BAlert *alert = new BAlert( "Web Browser Warning",
|
||||
"There is no web browser on your machine that is configured as the default program to view web pages.",
|
||||
"Ok", NULL, NULL, B_WIDTH_AS_USUAL,
|
||||
B_WARNING_ALERT );
|
||||
alert->Go();
|
||||
}
|
||||
}
|
||||
// Handle an FTP link.
|
||||
else if( IsFTPLink() ) {
|
||||
// Lock the string buffer and pass it to the FTP client.
|
||||
char *link = url->LockBuffer( 0 );
|
||||
status_t result = be_roster->Launch( "application/x-vnd.Be.URL.ftp",
|
||||
1, &link );
|
||||
url->UnlockBuffer();
|
||||
// Make sure the user has an FTP client.
|
||||
if( result != B_NO_ERROR && result != B_ALREADY_RUNNING ) {
|
||||
BAlert *alert = new BAlert( "FTP Warning",
|
||||
"There is no FTP client on your machine that is configured as the default program to connect to an FTP server.",
|
||||
"Ok", NULL, NULL, B_WIDTH_AS_USUAL,
|
||||
B_WARNING_ALERT );
|
||||
alert->Go();
|
||||
}
|
||||
}
|
||||
|
||||
// We don't know how to handle anything else.
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URLView::Redraw() {
|
||||
// Redraw the link without flicker.
|
||||
BRect frame = Frame();
|
||||
frame.OffsetTo( B_ORIGIN );
|
||||
Draw( frame );
|
||||
}
|
||||
|
||||
|
||||
void URLView::WriteAttributes( int fd ) {
|
||||
// Write the developer-defined attributes to the newly-created file.
|
||||
KeyPair *item;
|
||||
for( int i = 0; (item = (KeyPair *) attributes->ItemAt(i)); i++ ) {
|
||||
fs_write_attr( fd, item->key->String(), B_STRING_TYPE, 0, item->value->String(), item->value->Length() + 1 );
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/* URLView 2.0
|
||||
written by William Kakes of Tall Hill Software.
|
||||
|
||||
This class provides an underlined and clickable BStringView
|
||||
that will launch the web browser, e-mail program, or FTP client
|
||||
when clicked on. Other features include hover-highlighting,
|
||||
right-click menus, and drag-and-drop support.
|
||||
|
||||
You are free to use URLView in your own programs (both open-source
|
||||
and closed-source) free of charge, but a mention in your read me
|
||||
file or your program's about box would be appreciated. See
|
||||
http://www.tallhill.com for current contact information.
|
||||
|
||||
URLView is provided as-is, with no warranties of any kind. If
|
||||
you use it, you are on your own.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef TH_URL_VIEW_H
|
||||
#define TH_URL_VIEW_H
|
||||
|
||||
|
||||
|
||||
#include <Cursor.h>
|
||||
#include <List.h>
|
||||
#include <Mime.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
|
||||
|
||||
|
||||
// This is the link's mouse cursor (a replica of NetPositive's link cursor).
|
||||
const uint8 url_cursor[] = { 16, 1, 1, 2,
|
||||
// This is the cursor data.
|
||||
0x00, 0x00, 0x38, 0x00, 0x24, 0x00, 0x24, 0x00,
|
||||
0x13, 0xe0, 0x12, 0x5c, 0x09, 0x2a, 0x08, 0x01,
|
||||
0x3c, 0x21, 0x4c, 0x71, 0x42, 0x71, 0x30, 0xf9,
|
||||
0x0c, 0xf9, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
|
||||
// This is the cursor mask.
|
||||
0x00, 0x00, 0x38, 0x00, 0x3c, 0x00, 0x3c, 0x00,
|
||||
0x1f, 0xe0, 0x1f, 0xfc, 0x0f, 0xfe, 0x0f, 0xff,
|
||||
0x3f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x3f, 0xff,
|
||||
0x0f, 0xff, 0x03, 0xfe, 0x01, 0xf8, 0x00, 0x00,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// The default link color, blue.
|
||||
const rgb_color blue = { 0, 0, 255 };
|
||||
// The default clicked-link color, red.
|
||||
const rgb_color red = { 255, 0, 0 };
|
||||
// The default link hover color, dark blue.
|
||||
const rgb_color dark_blue = { 0, 0, 120 };
|
||||
|
||||
|
||||
|
||||
class URLView : public BStringView {
|
||||
public:
|
||||
URLView( BRect frame, const char *name, const char *label, const char *url,
|
||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW );
|
||||
~URLView();
|
||||
|
||||
|
||||
void AttachedToWindow();
|
||||
void Draw( BRect updateRect );
|
||||
void MessageReceived( BMessage *message );
|
||||
void MouseDown( BPoint point );
|
||||
void MouseMoved( BPoint point, uint32 transit, const BMessage *message );
|
||||
void MouseUp( BPoint point );
|
||||
|
||||
void AddAttribute( const char *name, const char *value );
|
||||
void SetColor( rgb_color color );
|
||||
void SetClickColor( rgb_color color );
|
||||
void SetDraggable( bool draggable );
|
||||
void SetHoverColor( rgb_color color );
|
||||
void SetHoverEnabled( bool hover );
|
||||
void SetIconSize( icon_size iconSize );
|
||||
void SetUnderlineThickness( int thickness );
|
||||
|
||||
|
||||
private:
|
||||
void CopyToClipboard();
|
||||
void CreateBookmark( const BString *fullName, const BString *title );
|
||||
void CreatePerson( const BString *fullName, const BString *title );
|
||||
BPopUpMenu *CreatePopupMenu();
|
||||
void DoBookmarkDrag();
|
||||
void DoPersonDrag();
|
||||
BString GetImportantURL();
|
||||
BRect GetTextRect();
|
||||
BRect GetURLRect();
|
||||
bool IsEmailLink();
|
||||
bool IsFTPLink();
|
||||
void LaunchURL();
|
||||
void Redraw();
|
||||
void WriteAttributes( int fd );
|
||||
|
||||
BString *url;
|
||||
rgb_color color;
|
||||
rgb_color clickColor;
|
||||
rgb_color hoverColor;
|
||||
bool hoverEnabled;
|
||||
bool draggable;
|
||||
int underlineThickness;
|
||||
int iconSize;
|
||||
|
||||
bool selected;
|
||||
bool hovering;
|
||||
bool draggedOut;
|
||||
bool inPopup;
|
||||
const BCursor *linkCursor;
|
||||
BPoint dragOffset;
|
||||
BList *attributes;
|
||||
|
||||
typedef struct kp {
|
||||
BString *key;
|
||||
BString *value;
|
||||
} KeyPair;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TH_URL_VIEW
|
||||
Reference in New Issue
Block a user