tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / interface / OptionControl.cpp
blobf7e4fa8ebe4637ddcc093482f6fbd35222494b60
1 /*
2 * Copyright 2003-2006, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Stefano Ceccherini (burton666@libero.it)
7 * Jerome Duval
9 * Description: An abstract base class for option controls.
12 #include <OptionControl.h>
14 #include <cstring>
17 /*! \brief Creates and initializes a BOptionControl.
18 \param frame The control's frame rectangle.
19 \param name The control's name.
20 \param label The label displayed by the control.
21 \param message The message which the control will send when operated.
22 \param resize Resize mask, passed to the base class's constructor.
23 \param flags View flags, passed to the base class's constructor.
25 BOptionControl::BOptionControl(BRect frame, const char *name, const char *label,
26 BMessage *message, uint32 resize, uint32 flags)
28 BControl(frame, name, label, message, resize, flags)
33 BOptionControl::BOptionControl(const char *name, const char *label,
34 BMessage *message, uint32 flags)
36 BControl(name, label, message, flags)
41 /*! \brief Destructor
42 It does nothing.
44 BOptionControl::~BOptionControl()
49 /*! \brief Overrides the base version to take special actions.
50 \param message The received message.
51 Calls SetValue() if receives a B_OPTION_CONTROL_VALUE message
52 which contains a "be:value" int32
54 void
55 BOptionControl::MessageReceived(BMessage *message)
57 switch (message->what) {
58 case B_OPTION_CONTROL_VALUE:
60 int32 value;
61 if (message->FindInt32("be:value", &value) == B_OK) {
62 SetValue(value);
63 Invoke();
65 break;
67 default:
68 BControl::MessageReceived(message);
69 break;
74 /*! \brief Adds an "option" after the last one.
75 \param name The name of the option.
76 \param value The value of the option.
77 \return \c B_OK if the option was added succesfully,
78 an error code otherwise.
80 status_t
81 BOptionControl::AddOption(const char *name, int32 value)
83 int32 numOptions = CountOptions();
84 return AddOptionAt(name, value, numOptions);
88 /*! \brief Select the option which has the given value.
89 \param value The value of the option.
90 \return \c B_OK if there was an option with that value,
91 and it was correctly selected, an error code otherwise.
92 It works like SetValue(value);
94 status_t
95 BOptionControl::SelectOptionFor(int32 value)
97 // XXX: I wonder why this method was created in the first place,
98 // since you can obtain the same result simply by calling SetValue().
99 // The only difference I can see is that this method iterates over
100 // all the options contained in the control, and then selects the right one.
101 int32 numOptions = CountOptions();
102 for (int32 c = 0; c < numOptions; c++) {
103 const char *name = NULL;
104 int32 optionValue;
105 if (GetOptionAt(c, &name, &optionValue) && optionValue == value) {
106 SetValue(optionValue);
107 return B_OK;
111 return B_ERROR;
115 /*! \brief Select the option which has the given name.
116 \param name The name of the option.
117 \return \c B_OK if there was an option with that name,
118 and it was correctly selected, an error code otherwise.
120 status_t
121 BOptionControl::SelectOptionFor(const char *name)
123 int32 numOptions = CountOptions();
124 for (int32 c = 0; c < numOptions; c++) {
125 const char *optionName = NULL;
126 int32 optionValue;
127 if (GetOptionAt(c, &optionName, &optionValue)
128 && !strcmp(name, optionName)) {
129 SetValue(optionValue);
130 return B_OK;
133 return B_ERROR;
137 // Protected
138 /*! \brief Creates a BMessage which contains the given value.
139 \param The value to be added to the message.
140 \return A pointer to a BMessage, NULL if something went wrong.
142 BMessage *
143 BOptionControl::MakeValueMessage(int32 value)
145 BMessage *message = new BMessage(B_OPTION_CONTROL_VALUE);
146 if (message->AddInt32("be:value", value) != B_OK) {
147 delete message;
148 message = NULL;
151 return message;
155 // Private unimplemented
156 BOptionControl::BOptionControl()
158 BControl(BRect(), "", "", NULL, 0, 0)
163 BOptionControl::BOptionControl(const BOptionControl & clone)
165 BControl(BRect(), "", "", NULL, 0, 0)
170 BOptionControl &
171 BOptionControl::operator=(const BOptionControl & clone)
173 return *this;
177 // FBC
178 status_t BOptionControl::_Reserved_OptionControl_0(void *, ...) { return B_ERROR; }
179 status_t BOptionControl::_Reserved_OptionControl_1(void *, ...) { return B_ERROR; }
180 status_t BOptionControl::_Reserved_OptionControl_2(void *, ...) { return B_ERROR; }
181 status_t BOptionControl::_Reserved_OptionControl_3(void *, ...) { return B_ERROR; }
182 status_t BOptionControl::_Reserved_OptionControl_4(void *, ...) { return B_ERROR; }
183 status_t BOptionControl::_Reserved_OptionControl_5(void *, ...) { return B_ERROR; }
184 status_t BOptionControl::_Reserved_OptionControl_6(void *, ...) { return B_ERROR; }
185 status_t BOptionControl::_Reserved_OptionControl_7(void *, ...) { return B_ERROR; }
186 status_t BOptionControl::_Reserved_OptionControl_8(void *, ...) { return B_ERROR; }
187 status_t BOptionControl::_Reserved_OptionControl_9(void *, ...) { return B_ERROR; }
188 status_t BOptionControl::_Reserved_OptionControl_10(void *, ...) { return B_ERROR; }
189 status_t BOptionControl::_Reserved_OptionControl_11(void *, ...) { return B_ERROR; }