1e234c034SDarkWyrm /*
2e234c034SDarkWyrm * Copyright (c) 2005-2010, Haiku, Inc.
3e234c034SDarkWyrm * Distributed under the terms of the MIT license.
4e234c034SDarkWyrm *
5e234c034SDarkWyrm * Author:
6e234c034SDarkWyrm * DarkWyrm <darkwyrm@gmail.com>
7e234c034SDarkWyrm */
822c6ae69SDarkWyrm #include "InternalEditors.h"
922c6ae69SDarkWyrm #include "ResourceData.h"
10*09a03cb8SDarkWyrm
1122c6ae69SDarkWyrm #include <Message.h>
12*09a03cb8SDarkWyrm #include <Messenger.h>
1322c6ae69SDarkWyrm #include <String.h>
14*09a03cb8SDarkWyrm
1522c6ae69SDarkWyrm #include <stdlib.h>
1622c6ae69SDarkWyrm
DoubleEditor(const BRect & frame,ResourceData * data,BHandler * owner)1722c6ae69SDarkWyrm DoubleEditor::DoubleEditor(const BRect &frame, ResourceData *data,
1822c6ae69SDarkWyrm BHandler *owner)
1922c6ae69SDarkWyrm : Editor(frame, data, owner)
2022c6ae69SDarkWyrm {
2122c6ae69SDarkWyrm if (data->GetName())
2222c6ae69SDarkWyrm SetTitle(data->GetName());
2322c6ae69SDarkWyrm
2422c6ae69SDarkWyrm fView = new StringEditView(Bounds());
2522c6ae69SDarkWyrm AddChild(fView);
2622c6ae69SDarkWyrm
2722c6ae69SDarkWyrm fView->SetID(data->GetIDString());
2822c6ae69SDarkWyrm fView->SetName(data->GetName());
2922c6ae69SDarkWyrm fView->SetValue(data->GetData());
3022c6ae69SDarkWyrm }
3122c6ae69SDarkWyrm
3222c6ae69SDarkWyrm
3322c6ae69SDarkWyrm void
MessageReceived(BMessage * msg)3422c6ae69SDarkWyrm DoubleEditor::MessageReceived(BMessage *msg)
3522c6ae69SDarkWyrm {
3622c6ae69SDarkWyrm if (msg->what == M_UPDATE_RESOURCE) {
3722c6ae69SDarkWyrm // We have to have an ID, so if the squirrely developer didn't give us
3822c6ae69SDarkWyrm // one, don't do anything
3922c6ae69SDarkWyrm if (fView->GetID()) {
4022c6ae69SDarkWyrm int32 newid = atol(fView->GetID());
4122c6ae69SDarkWyrm GetData()->SetID(newid);
4222c6ae69SDarkWyrm }
4322c6ae69SDarkWyrm
4422c6ae69SDarkWyrm GetData()->SetName(fView->GetName());
4522c6ae69SDarkWyrm GetData()->SetData(fView->GetValue(), strlen(fView->GetValue()));
4622c6ae69SDarkWyrm
4722c6ae69SDarkWyrm BMessage updatemsg(M_UPDATE_RESOURCE);
4822c6ae69SDarkWyrm updatemsg.AddPointer("item", GetData());
4922c6ae69SDarkWyrm BMessenger msgr(GetOwner());
5022c6ae69SDarkWyrm msgr.SendMessage(&updatemsg);
5122c6ae69SDarkWyrm PostMessage(B_QUIT_REQUESTED);
5222c6ae69SDarkWyrm
5322c6ae69SDarkWyrm } else {
5422c6ae69SDarkWyrm Editor::MessageReceived(msg);
5522c6ae69SDarkWyrm }
5622c6ae69SDarkWyrm }
5722c6ae69SDarkWyrm
58