xref: /haiku/src/apps/resedit/NumberEditors.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright (c) 2005-2010, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Author:
6  *		DarkWyrm <darkwyrm@gmail.com>
7  */
8 #include "InternalEditors.h"
9 #include "ResourceData.h"
10 
11 #include <Message.h>
12 #include <Messenger.h>
13 #include <String.h>
14 
15 #include <stdlib.h>
16 
17 DoubleEditor::DoubleEditor(const BRect &frame, ResourceData *data,
18 							BHandler *owner)
19   :	Editor(frame, data, owner)
20 {
21 	if (data->GetName())
22 		SetTitle(data->GetName());
23 
24 	fView = new StringEditView(Bounds());
25 	AddChild(fView);
26 
27 	fView->SetID(data->GetIDString());
28 	fView->SetName(data->GetName());
29 	fView->SetValue(data->GetData());
30 }
31 
32 
33 void
34 DoubleEditor::MessageReceived(BMessage *msg)
35 {
36 	if (msg->what == M_UPDATE_RESOURCE) {
37 		// We have to have an ID, so if the squirrely developer didn't give us
38 		// one, don't do anything
39 		if (fView->GetID()) {
40 			int32 newid = atol(fView->GetID());
41 			GetData()->SetID(newid);
42 		}
43 
44 		GetData()->SetName(fView->GetName());
45 		GetData()->SetData(fView->GetValue(), strlen(fView->GetValue()));
46 
47 		BMessage updatemsg(M_UPDATE_RESOURCE);
48 		updatemsg.AddPointer("item", GetData());
49 		BMessenger msgr(GetOwner());
50 		msgr.SendMessage(&updatemsg);
51 		PostMessage(B_QUIT_REQUESTED);
52 
53 	} else {
54 		Editor::MessageReceived(msg);
55 	}
56 }
57 
58