Initial checkin of a resource editor similar in style to QuickRes -- Resourcer's code is too difficult to maintain and the others on BeBits are either not good or the author could not be contacted.
This is currently a work-in-progress - right now it can only view resources and attributes. Haiku target builds but R5 is broken because of a linking issue that will hopefully be resolved shortly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19734 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -22,6 +22,7 @@ SubInclude HAIKU_TOP src apps poorman ;
|
|||||||
SubInclude HAIKU_TOP src apps powerstatus ;
|
SubInclude HAIKU_TOP src apps powerstatus ;
|
||||||
SubInclude HAIKU_TOP src apps processcontroller ;
|
SubInclude HAIKU_TOP src apps processcontroller ;
|
||||||
SubInclude HAIKU_TOP src apps pulse ;
|
SubInclude HAIKU_TOP src apps pulse ;
|
||||||
|
SubInclude HAIKU_TOP src apps resedit ;
|
||||||
SubInclude HAIKU_TOP src apps showimage ;
|
SubInclude HAIKU_TOP src apps showimage ;
|
||||||
SubInclude HAIKU_TOP src apps soundrecorder ;
|
SubInclude HAIKU_TOP src apps soundrecorder ;
|
||||||
SubInclude HAIKU_TOP src apps stylededit ;
|
SubInclude HAIKU_TOP src apps stylededit ;
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#include "App.h"
|
||||||
|
#include "ResWindow.h"
|
||||||
|
#include <Entry.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
App app;
|
||||||
|
app.Run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
App::App(void)
|
||||||
|
: BApplication("application/x-vnd.Haiku-ResEdit"),
|
||||||
|
fWindowCount(0)
|
||||||
|
{
|
||||||
|
fOpenPanel = new BFilePanel();
|
||||||
|
fSavePanel = new BFilePanel(B_SAVE_PANEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
App::~App(void)
|
||||||
|
{
|
||||||
|
delete fOpenPanel;
|
||||||
|
delete fSavePanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
App::ReadyToRun(void)
|
||||||
|
{
|
||||||
|
if (fWindowCount < 1) {
|
||||||
|
ResWindow *win = new ResWindow(BRect(50,100,600,400));
|
||||||
|
win->Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
App::MessageReceived(BMessage *msg)
|
||||||
|
{
|
||||||
|
switch(msg->what) {
|
||||||
|
case M_REGISTER_WINDOW: {
|
||||||
|
fWindowCount++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case M_UNREGISTER_WINDOW: {
|
||||||
|
fWindowCount--;
|
||||||
|
if (fWindowCount == 0)
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case M_SHOW_OPEN_PANEL: {
|
||||||
|
// Don't do anything if it's already open
|
||||||
|
if (fOpenPanel->IsShowing())
|
||||||
|
break;
|
||||||
|
fOpenPanel->Show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
BApplication::MessageReceived(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
App::RefsReceived(BMessage *msg)
|
||||||
|
{
|
||||||
|
entry_ref ref;
|
||||||
|
int32 i=0;
|
||||||
|
while (msg->FindRef("refs",i,&ref) == B_OK) {
|
||||||
|
ResWindow *win = new ResWindow(BRect(50,100,600,400),&ref);
|
||||||
|
win->Show();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
App::QuitRequested(void)
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < CountWindows(); i++) {
|
||||||
|
BWindow *win = WindowAt(i);
|
||||||
|
if (fOpenPanel->Window() == win || fSavePanel->Window() == win)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!win->QuitRequested())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef APP_H
|
||||||
|
#define APP_H
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include <FilePanel.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
M_REGISTER_WINDOW = 'regw',
|
||||||
|
M_UNREGISTER_WINDOW,
|
||||||
|
M_SHOW_OPEN_PANEL,
|
||||||
|
M_SHOW_SAVE_PANEL
|
||||||
|
};
|
||||||
|
|
||||||
|
class App : public BApplication
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
App(void);
|
||||||
|
~App(void);
|
||||||
|
void MessageReceived(BMessage *msg);
|
||||||
|
void RefsReceived(BMessage *msg);
|
||||||
|
void ReadyToRun(void);
|
||||||
|
bool QuitRequested(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32 fWindowCount;
|
||||||
|
BFilePanel *fOpenPanel, *fSavePanel;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef EDITOR_H
|
||||||
|
#define EDITOR_H
|
||||||
|
|
||||||
|
class Editor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Editor(void);
|
||||||
|
virtual ~Editor(void);
|
||||||
|
virtual BView * GetConfigView(void);
|
||||||
|
virtual void LoadData(unsigned char *data, const size_t &length);
|
||||||
|
virtual unsigned char * SaveData(size_t *data);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
SubDir HAIKU_TOP src apps resedit ;
|
||||||
|
|
||||||
|
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||||
|
|
||||||
|
UsePrivateHeaders shared interface ;
|
||||||
|
|
||||||
|
Application ResEdit :
|
||||||
|
App.cpp
|
||||||
|
PreviewColumn.cpp
|
||||||
|
ResourceData.cpp
|
||||||
|
ResourceRoster.cpp
|
||||||
|
ResView.cpp
|
||||||
|
ResWindow.cpp
|
||||||
|
: be tracker translation
|
||||||
|
;
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#include "PreviewColumn.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
PreviewColumn::PreviewColumn(const char *title, float width,
|
||||||
|
float minWidth, float maxWidth)
|
||||||
|
: BTitledColumn(title, width, minWidth, maxWidth)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PreviewColumn::DrawField(BField* field, BRect rect, BView* parent)
|
||||||
|
{
|
||||||
|
BIntegerField *intField = dynamic_cast<BIntegerField*>(field);
|
||||||
|
BStringField *strField = dynamic_cast<BStringField*>(field);
|
||||||
|
BBitmapField *bmpField = dynamic_cast<BBitmapField*>(field);
|
||||||
|
|
||||||
|
if (intField) {
|
||||||
|
float width = rect.Width() - 16;
|
||||||
|
BString string;
|
||||||
|
string << intField->Value();
|
||||||
|
parent->TruncateString(&string, B_TRUNCATE_MIDDLE, width + 2);
|
||||||
|
DrawString(string.String(), parent, rect);
|
||||||
|
} else if (strField) {
|
||||||
|
float width = rect.Width() - 16;
|
||||||
|
if (width != strField->Width()) {
|
||||||
|
BString out_string(strField->String());
|
||||||
|
|
||||||
|
parent->TruncateString(&out_string, B_TRUNCATE_END, width + 2);
|
||||||
|
strField->SetClippedString(out_string.String());
|
||||||
|
strField->SetWidth(width);
|
||||||
|
}
|
||||||
|
DrawString(strField->ClippedString(), parent, rect);
|
||||||
|
} else if (bmpField) {
|
||||||
|
const BBitmap *bitmap = bmpField->Bitmap();
|
||||||
|
|
||||||
|
if (bitmap != NULL) {
|
||||||
|
// Scale the bitmap down to completely fit within the field's height
|
||||||
|
BRect drawrect(bitmap->Bounds().OffsetToCopy(rect.LeftTop()));
|
||||||
|
if (drawrect.Height() > rect.Height()) {
|
||||||
|
drawrect = rect;
|
||||||
|
drawrect.right = drawrect.left +
|
||||||
|
(bitmap->Bounds().Width() *
|
||||||
|
(rect.Height() / bitmap->Bounds().Height()));
|
||||||
|
}
|
||||||
|
|
||||||
|
parent->SetDrawingMode(B_OP_ALPHA);
|
||||||
|
parent->DrawBitmap(bitmap, bitmap->Bounds(), drawrect);
|
||||||
|
parent->SetDrawingMode(B_OP_COPY);
|
||||||
|
|
||||||
|
BString out;
|
||||||
|
out << bitmap->Bounds().IntegerWidth() << " x "
|
||||||
|
<< bitmap->Bounds().IntegerHeight() << " x "
|
||||||
|
<< (int32(bitmap->BytesPerRow() / bitmap->Bounds().Width()) * 8);
|
||||||
|
|
||||||
|
BRect stringrect = rect;
|
||||||
|
stringrect.right -= 10;
|
||||||
|
stringrect.left = stringrect.right - parent->StringWidth(out.String());
|
||||||
|
if (stringrect.left < drawrect.right + 5)
|
||||||
|
stringrect.left = drawrect.right + 5;
|
||||||
|
|
||||||
|
parent->TruncateString(&out, B_TRUNCATE_END, stringrect.Width());
|
||||||
|
DrawString(out.String(), parent, stringrect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef PREVIEW_COLUMN_H
|
||||||
|
#define PREVIEW_COLUMN_H
|
||||||
|
|
||||||
|
#include <ColumnTypes.h>
|
||||||
|
|
||||||
|
class PreviewColumn : public BTitledColumn
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PreviewColumn(const char *title, float width,
|
||||||
|
float minWidth, float maxWidth);
|
||||||
|
void DrawField(BField* field, BRect rect, BView* parent);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#include "ResView.h"
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include <ScrollView.h>
|
||||||
|
#include <MenuBar.h>
|
||||||
|
#include <Menu.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ColumnTypes.h>
|
||||||
|
|
||||||
|
#include "App.h"
|
||||||
|
#include "ResourceData.h"
|
||||||
|
#include "ResWindow.h"
|
||||||
|
#include "PreviewColumn.h"
|
||||||
|
|
||||||
|
static int32 sUntitled = 1;
|
||||||
|
|
||||||
|
ResourceRoster gResRoster;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
M_NEW_FILE = 'nwfl',
|
||||||
|
M_OPEN_FILE,
|
||||||
|
M_SAVE_FILE,
|
||||||
|
M_SAVE_FILE_AS,
|
||||||
|
M_QUIT
|
||||||
|
};
|
||||||
|
|
||||||
|
ResView::ResView(const BRect &frame, const char *name, const int32 &resize,
|
||||||
|
const int32 &flags, const entry_ref *ref)
|
||||||
|
: BView(frame, name, resize, flags),
|
||||||
|
fIsDirty(false)
|
||||||
|
{
|
||||||
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
if (ref) {
|
||||||
|
fRef = new entry_ref;
|
||||||
|
*fRef = *ref;
|
||||||
|
fFileName = fRef->name;
|
||||||
|
} else {
|
||||||
|
fRef = NULL;
|
||||||
|
fFileName = "Untitled ";
|
||||||
|
fFileName << sUntitled;
|
||||||
|
sUntitled++;
|
||||||
|
}
|
||||||
|
|
||||||
|
BMenu *menu = new BMenu("File");
|
||||||
|
menu->AddItem(new BMenuItem("New…", new BMessage(M_NEW_FILE), 'N'));
|
||||||
|
menu->AddSeparatorItem();
|
||||||
|
menu->AddItem(new BMenuItem("Open…", new BMessage(M_OPEN_FILE), 'O'));
|
||||||
|
menu->AddItem(new BMenuItem("Quit", new BMessage(M_QUIT), 'Q'));
|
||||||
|
|
||||||
|
BRect r(Bounds());
|
||||||
|
r.bottom = 16;
|
||||||
|
fBar = new BMenuBar(r, "bar");
|
||||||
|
AddChild(fBar);
|
||||||
|
|
||||||
|
fBar->AddItem(menu);
|
||||||
|
|
||||||
|
r = Bounds();
|
||||||
|
r.top = fBar->Frame().bottom + 4;
|
||||||
|
fListView = new BColumnListView(r, "gridview", B_FOLLOW_ALL, B_WILL_DRAW,
|
||||||
|
B_FANCY_BORDER);
|
||||||
|
AddChild(fListView);
|
||||||
|
|
||||||
|
rgb_color white = { 255,255,255,255 };
|
||||||
|
fListView->SetColor(B_COLOR_BACKGROUND, white);
|
||||||
|
fListView->SetColor(B_COLOR_SELECTION, ui_color(B_MENU_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
float width = be_plain_font->StringWidth("00000") + 20;
|
||||||
|
fListView->AddColumn(new BStringColumn("ID",width,width,100,B_TRUNCATE_END),0);
|
||||||
|
|
||||||
|
fListView->AddColumn(new BStringColumn("Type",width,width,100,B_TRUNCATE_END),1);
|
||||||
|
fListView->AddColumn(new BStringColumn("Name",150,50,300,B_TRUNCATE_END),2);
|
||||||
|
fListView->AddColumn(new PreviewColumn("Data",150,50,300),3);
|
||||||
|
|
||||||
|
width = be_plain_font->StringWidth("1000 bytes") + 20;
|
||||||
|
fListView->AddColumn(new BSizeColumn("Size",width,10,100),4);
|
||||||
|
|
||||||
|
if (ref)
|
||||||
|
OpenFile(*ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResView::~ResView(void)
|
||||||
|
{
|
||||||
|
delete fRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ResView::AttachedToWindow(void)
|
||||||
|
{
|
||||||
|
for(int32 i = 0; i < fBar->CountItems(); i++)
|
||||||
|
fBar->SubmenuAt(i)->SetTargetForItems(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ResView::MessageReceived(BMessage *msg)
|
||||||
|
{
|
||||||
|
switch (msg->what) {
|
||||||
|
case M_NEW_FILE: {
|
||||||
|
BRect r(100,100,400,400);
|
||||||
|
if (Window())
|
||||||
|
r = Window()->Frame().OffsetByCopy(10,10);
|
||||||
|
ResWindow *win = new ResWindow(r);
|
||||||
|
win->Show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case M_OPEN_FILE: {
|
||||||
|
be_app->PostMessage(M_SHOW_OPEN_PANEL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case M_QUIT: {
|
||||||
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ResView::OpenFile(const entry_ref &ref)
|
||||||
|
{
|
||||||
|
// Add all the 133t resources and attributes of the file
|
||||||
|
|
||||||
|
BFile file(&ref, B_READ_ONLY);
|
||||||
|
if (fResources.SetTo(&file) != B_OK)
|
||||||
|
return;
|
||||||
|
file.Unset();
|
||||||
|
|
||||||
|
fResources.PreloadResourceType();
|
||||||
|
|
||||||
|
int32 index = 0;
|
||||||
|
ResourceData data;
|
||||||
|
BRow *row;
|
||||||
|
while (data.SetFromResource(index, fResources)) {
|
||||||
|
row = new BRow();
|
||||||
|
row->SetField(new BStringField(data.GetIDString()),0);
|
||||||
|
row->SetField(new BStringField(data.GetTypeString()),1);
|
||||||
|
row->SetField(new BStringField(data.GetName()),2);
|
||||||
|
BField *field = gResRoster.MakeFieldForType(data.GetType(),
|
||||||
|
data.GetData(),
|
||||||
|
data.GetLength());
|
||||||
|
if (field)
|
||||||
|
row->SetField(field,3);
|
||||||
|
row->SetField(new BSizeField(data.GetLength()),4);
|
||||||
|
fListView->AddRow(row);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//debugger("");
|
||||||
|
BNode node;
|
||||||
|
if (node.SetTo(&ref) == B_OK) {
|
||||||
|
char attrName[B_ATTR_NAME_LENGTH];
|
||||||
|
node.RewindAttrs();
|
||||||
|
while (node.GetNextAttrName(attrName) == B_OK) {
|
||||||
|
if (data.SetFromAttribute(attrName, node)) {
|
||||||
|
row = new BRow();
|
||||||
|
row->SetField(new BStringField(data.GetIDString()),0);
|
||||||
|
row->SetField(new BStringField(data.GetTypeString()),1);
|
||||||
|
row->SetField(new BStringField(data.GetName()),2);
|
||||||
|
BField *field = gResRoster.MakeFieldForType(data.GetType(),
|
||||||
|
data.GetData(),
|
||||||
|
data.GetLength());
|
||||||
|
if (field)
|
||||||
|
row->SetField(field,3);
|
||||||
|
row->SetField(new BSizeField(data.GetLength()),4);
|
||||||
|
fListView->AddRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const void *
|
||||||
|
ResView::LoadResource(const type_code &type, const int32 &id, size_t *out_size)
|
||||||
|
{
|
||||||
|
return fResources.LoadResource(type, id, out_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const void *
|
||||||
|
ResView::LoadResource(const type_code &type, const char *name, size_t *out_size)
|
||||||
|
{
|
||||||
|
return fResources.LoadResource(type, name, out_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
ResView::AddResource(const type_code &type, const int32 &id, const void *data,
|
||||||
|
const size_t &data_size, const char *name)
|
||||||
|
{
|
||||||
|
return fResources.AddResource(type, id, data, data_size, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ResView::HasResource(const type_code &type, const int32 &id)
|
||||||
|
{
|
||||||
|
return fResources.HasResource(type, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ResView::HasResource(const type_code &type, const char *name)
|
||||||
|
{
|
||||||
|
return fResources.HasResource(type, name);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef RESVIEW_H
|
||||||
|
#define RESVIEW_H
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
#include <ColumnListView.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <ListItem.h>
|
||||||
|
#include <Resources.h>
|
||||||
|
#include "ResourceRoster.h"
|
||||||
|
|
||||||
|
class ResView : public BView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ResView(const BRect &frame, const char *name,
|
||||||
|
const int32 &resize, const int32 &flags,
|
||||||
|
const entry_ref *ref = NULL);
|
||||||
|
~ResView(void);
|
||||||
|
void AttachedToWindow(void);
|
||||||
|
void MessageReceived(BMessage *msg);
|
||||||
|
|
||||||
|
const char * Filename(void) const { return fFileName.String(); }
|
||||||
|
bool IsDirty(void) const { return fIsDirty; }
|
||||||
|
|
||||||
|
void OpenFile(const entry_ref &ref);
|
||||||
|
|
||||||
|
// BResources mirror API
|
||||||
|
const void * LoadResource(const type_code &type, const int32 &id,
|
||||||
|
size_t *out_size);
|
||||||
|
const void * LoadResource(const type_code &type, const char *name,
|
||||||
|
size_t *out_size);
|
||||||
|
status_t AddResource(const type_code &type, const int32 &id,
|
||||||
|
const void *data, const size_t &data_size,
|
||||||
|
const char *name = NULL);
|
||||||
|
bool HasResource(const type_code &type, const int32 &id);
|
||||||
|
bool HasResource(const type_code &type, const char *name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BColumnListView *fListView;
|
||||||
|
entry_ref *fRef;
|
||||||
|
BString fFileName;
|
||||||
|
BMenuBar *fBar;
|
||||||
|
bool fIsDirty;
|
||||||
|
|
||||||
|
BResources fResources;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern ResourceRoster gResRoster;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#include "ResWindow.h"
|
||||||
|
#include "ResView.h"
|
||||||
|
#include "App.h"
|
||||||
|
|
||||||
|
ResWindow::ResWindow(const BRect &rect, const entry_ref *ref)
|
||||||
|
: BWindow(rect,"", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||||
|
{
|
||||||
|
be_app->PostMessage(M_REGISTER_WINDOW);
|
||||||
|
|
||||||
|
ResView *child = new ResView(Bounds(), "resview", B_FOLLOW_ALL, B_WILL_DRAW, ref);
|
||||||
|
AddChild(child);
|
||||||
|
|
||||||
|
SetTitle(child->Filename());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResWindow::~ResWindow(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ResWindow::QuitRequested(void)
|
||||||
|
{
|
||||||
|
be_app->PostMessage(M_UNREGISTER_WINDOW);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef RESWIN_H
|
||||||
|
#define RESWIN_H
|
||||||
|
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
class ResWindow : public BWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ResWindow(const BRect &rect,
|
||||||
|
const entry_ref *ref=NULL);
|
||||||
|
~ResWindow(void);
|
||||||
|
bool QuitRequested(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#include "ResourceData.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
ResourceData::ResourceData(void)
|
||||||
|
: fType(0),
|
||||||
|
fTypeString("Invalid"),
|
||||||
|
fID(-1),
|
||||||
|
fIDString("Invalid"),
|
||||||
|
fName(""),
|
||||||
|
fData(NULL),
|
||||||
|
fLength(0),
|
||||||
|
fFree(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourceData::ResourceData(const type_code &code, const int32 &id,
|
||||||
|
const char *name, char *data,
|
||||||
|
const size_t &length)
|
||||||
|
: fType(code),
|
||||||
|
fID(id),
|
||||||
|
fName(name),
|
||||||
|
fData(data),
|
||||||
|
fLength(length),
|
||||||
|
fFree(false)
|
||||||
|
{
|
||||||
|
fIDString = "";
|
||||||
|
fIDString << fID;
|
||||||
|
MakeTypeString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourceData::ResourceData(const ResourceData &data)
|
||||||
|
{
|
||||||
|
*this = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourceData::~ResourceData(void)
|
||||||
|
{
|
||||||
|
if (fFree)
|
||||||
|
free(fData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourceData &
|
||||||
|
ResourceData::operator=(const ResourceData &data)
|
||||||
|
{
|
||||||
|
fType = data.fType;
|
||||||
|
fTypeString = data.fTypeString;
|
||||||
|
fID = data.fID;
|
||||||
|
fIDString = data.fIDString;
|
||||||
|
fName = data.fName;
|
||||||
|
fLength = data.fLength;
|
||||||
|
fFree = data.fFree;
|
||||||
|
|
||||||
|
// This is an attribute, so we need to allocate and free the data
|
||||||
|
if (fFree) {
|
||||||
|
fData = data.fData;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ResourceData::SetFromResource(const int32 &index, BResources &res)
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
if (!res.GetResourceInfo(index, (type_code*)&fType, &fID,
|
||||||
|
(const char **)&name, &fLength)) {
|
||||||
|
*this = ResourceData();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fName = name;
|
||||||
|
MakeTypeString();
|
||||||
|
fIDString = "";
|
||||||
|
fIDString << fID;
|
||||||
|
fFree = false;
|
||||||
|
fData = (char *)res.LoadResource(fType,fID,&fLength);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ResourceData::SetFromAttribute(const char *name, BNode &node)
|
||||||
|
{
|
||||||
|
attr_info info;
|
||||||
|
if (node.GetAttrInfo(name, &info) != B_OK) {
|
||||||
|
*this = ResourceData();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fType = info.type;
|
||||||
|
fID = -1;
|
||||||
|
fIDString = "(attr)";
|
||||||
|
fName = name;
|
||||||
|
fLength = info.size;
|
||||||
|
fFree = true;
|
||||||
|
|
||||||
|
MakeTypeString();
|
||||||
|
|
||||||
|
fData = (char *)malloc(fLength);
|
||||||
|
if (fData) {
|
||||||
|
ssize_t size = node.ReadAttr(name, info.type, 0, (void*)fData, fLength);
|
||||||
|
if (size >= 0) {
|
||||||
|
fLength = (size_t) size;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*this = ResourceData();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ResourceData::SetTo(const type_code &code, const int32 &id,
|
||||||
|
const char *name, char *data, const size_t &length)
|
||||||
|
{
|
||||||
|
fType = code;
|
||||||
|
fID = id;
|
||||||
|
fName = name;
|
||||||
|
fData = data;
|
||||||
|
fLength = length;
|
||||||
|
|
||||||
|
MakeTypeString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ResourceData::MakeTypeString(void)
|
||||||
|
{
|
||||||
|
char typestring[7];
|
||||||
|
char *typeptr = (char *) &fType;
|
||||||
|
typestring[0] = '\'';
|
||||||
|
typestring[1] = typeptr[3];
|
||||||
|
typestring[2] = typeptr[2];
|
||||||
|
typestring[3] = typeptr[1];
|
||||||
|
typestring[4] = typeptr[0];
|
||||||
|
typestring[5] = '\'';
|
||||||
|
typestring[6] = '\0';
|
||||||
|
fTypeString = typestring;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef RESOURCE_DATA_H
|
||||||
|
#define RESOURCE_DATA_H
|
||||||
|
|
||||||
|
#include <Resources.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <Node.h>
|
||||||
|
#include <fs_attr.h>
|
||||||
|
|
||||||
|
class ResourceData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ResourceData(void);
|
||||||
|
ResourceData(const type_code &code, const int32 &id,
|
||||||
|
const char *name, char *data,
|
||||||
|
const size_t &length);
|
||||||
|
ResourceData(const ResourceData &data);
|
||||||
|
~ResourceData(void);
|
||||||
|
void SetTo(const type_code &code, const int32 &id,
|
||||||
|
const char *name, char *data, const size_t &length);
|
||||||
|
ResourceData & operator=(const ResourceData &data);
|
||||||
|
|
||||||
|
bool SetFromResource(const int32 &index, BResources &res);
|
||||||
|
bool SetFromAttribute(const char *name, BNode &node);
|
||||||
|
|
||||||
|
type_code GetType(void) const { return fType; }
|
||||||
|
const char * GetTypeString(void) const { return fTypeString.String(); }
|
||||||
|
int32 GetID(void) const { return fID; }
|
||||||
|
const char * GetIDString(void) const { return fIDString.String(); }
|
||||||
|
const char * GetName(void) const { return fName.String(); }
|
||||||
|
char * GetData(void) { return fData; }
|
||||||
|
size_t GetLength(void) const { return fLength; }
|
||||||
|
|
||||||
|
bool IsAttribute(void) const { return fFree; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void MakeTypeString(void);
|
||||||
|
|
||||||
|
int32 fType;
|
||||||
|
BString fTypeString;
|
||||||
|
int32 fID;
|
||||||
|
BString fIDString;
|
||||||
|
BString fName;
|
||||||
|
char *fData;
|
||||||
|
size_t fLength;
|
||||||
|
bool fFree;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#include "ResourceRoster.h"
|
||||||
|
#include <Roster.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <image.h>
|
||||||
|
#include <Application.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
|
||||||
|
// For the MakeFieldForType temp code
|
||||||
|
#include <TranslatorFormats.h>
|
||||||
|
#include <TranslationUtils.h>
|
||||||
|
#include <DataIO.h>
|
||||||
|
#include <Mime.h>
|
||||||
|
#include <TypeConstants.h>
|
||||||
|
|
||||||
|
class EditorInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EditorInfo(const image_id &id, const char *name,
|
||||||
|
create_editor *allocator);
|
||||||
|
~EditorInfo(void);
|
||||||
|
|
||||||
|
status_t ID(void) const { return fID; }
|
||||||
|
const char * Name(void) const { return fName.String(); }
|
||||||
|
Editor * Instantiate(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
image_id fID;
|
||||||
|
BString fName;
|
||||||
|
create_editor * fAllocator;
|
||||||
|
};
|
||||||
|
|
||||||
|
EditorInfo::EditorInfo(const image_id &id, const char *name,
|
||||||
|
create_editor *allocator)
|
||||||
|
: fID(id),
|
||||||
|
fName(name),
|
||||||
|
fAllocator(allocator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EditorInfo::~EditorInfo(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Editor *
|
||||||
|
EditorInfo::Instantiate(void)
|
||||||
|
{
|
||||||
|
return fAllocator();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourceRoster::ResourceRoster(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourceRoster::~ResourceRoster(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BField *
|
||||||
|
ResourceRoster::MakeFieldForType(const int32 &type, const char *data,
|
||||||
|
const size_t &length)
|
||||||
|
{
|
||||||
|
// temporary code until editors are done
|
||||||
|
switch (type) {
|
||||||
|
case B_MIME_STRING_TYPE:
|
||||||
|
return new BStringField(data);
|
||||||
|
case B_GIF_FORMAT:
|
||||||
|
case B_PPM_FORMAT:
|
||||||
|
case B_TGA_FORMAT:
|
||||||
|
case B_BMP_FORMAT:
|
||||||
|
case B_TIFF_FORMAT:
|
||||||
|
case B_PNG_FORMAT:
|
||||||
|
case B_JPEG_FORMAT: {
|
||||||
|
BMemoryIO memio(data,length);
|
||||||
|
BBitmap *bitmap = BTranslationUtils::GetBitmap(&memio);
|
||||||
|
if (bitmap) {
|
||||||
|
// XXX WARNING! WARNING! Known memory leak
|
||||||
|
// This is temp code, so it's OK for the moment
|
||||||
|
BBitmapField *field = new BBitmapField(bitmap);
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ResourceRoster::LoadEditors(void)
|
||||||
|
{
|
||||||
|
app_info info;
|
||||||
|
be_app->GetAppInfo(&info);
|
||||||
|
|
||||||
|
BDirectory dir;
|
||||||
|
BEntry entry(&info.ref);
|
||||||
|
entry.GetParent(&dir);
|
||||||
|
entry.SetTo(&dir, "addons");
|
||||||
|
dir.SetTo(&entry);
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
dir.Rewind();
|
||||||
|
while (dir.GetNextRef(&ref) == B_OK) {
|
||||||
|
BPath path(&ref);
|
||||||
|
|
||||||
|
image_id addon = load_add_on(path.Path());
|
||||||
|
if (addon < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char *temp;
|
||||||
|
if (get_image_symbol(addon,"description",B_SYMBOL_TYPE_DATA,(void **)(&temp)) != B_OK) {
|
||||||
|
unload_add_on(addon);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
create_editor *createFunc;
|
||||||
|
if (get_image_symbol(addon,"instantiate_editor",B_SYMBOL_TYPE_TEXT,(void **)(&createFunc)) != B_OK) {
|
||||||
|
delete temp;
|
||||||
|
unload_add_on(addon);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createFunc && temp)
|
||||||
|
fList.AddItem(new EditorInfo(addon, temp, createFunc));
|
||||||
|
|
||||||
|
delete temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Author:
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef RESROSTER_H
|
||||||
|
#define RESROSTER_H
|
||||||
|
|
||||||
|
#include <List.h>
|
||||||
|
#include <ColumnTypes.h>
|
||||||
|
#include <ColumnListView.h>
|
||||||
|
|
||||||
|
class Editor;
|
||||||
|
|
||||||
|
class ResourceRoster
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ResourceRoster(void);
|
||||||
|
~ResourceRoster(void);
|
||||||
|
BField * MakeFieldForType(const int32 &type, const char *data,
|
||||||
|
const size_t &length);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void LoadEditors(void);
|
||||||
|
|
||||||
|
BList fList;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Editor* create_editor(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user