| 21 | | : BColorControl(point, B_CELLS_32x8, 6, "ColorControl", message, false) { |
| 22 | | |
| 23 | | } |
| 24 | | |
| 25 | | // Send a message every time the color changes, not just |
| 26 | | // when the mouse button is released |
| 27 | | void RTColorControl::SetValue(int32 color) { |
| | 28 | : BColorControl(point, B_CELLS_32x8, 6, "ColorControl", message, false) |
| | 29 | { |
| | 30 | } |
| | 31 | |
| | 32 | |
| | 33 | /*! |
| | 34 | Send a message every time the color changes, not just |
| | 35 | when the mouse button is released |
| | 36 | */ |
| | 37 | void |
| | 38 | RTColorControl::SetValue(int32 color) |
| | 39 | { |
| 32 | | // A single class for all three prefs views, needs to be |
| 33 | | // customized below to give each control the right message |
| 34 | | ConfigView::ConfigView(BRect rect, const char *name, int mode, Prefs *prefs) : |
| 35 | | BView(rect, name, B_FOLLOW_NONE, B_WILL_DRAW) { |
| 36 | | |
| 37 | | this->mode = mode; |
| 38 | | first_time_attached = true; |
| 39 | | fadecolors = NULL; |
| 40 | | active = idle = frame = NULL; |
| 41 | | iconwidth = NULL; |
| 42 | | |
| 43 | | BRect r(6, 5, 296, 115); |
| 44 | | BBox *bbox = new BBox(r, "BBox"); |
| 45 | | bbox->SetLabel("Bar Colors"); |
| 46 | | AddChild(bbox); |
| 47 | | |
| 48 | | if (mode == NORMAL_WINDOW_MODE) { |
| 49 | | colorcontrol = new RTColorControl(BPoint(10, 20), |
| 50 | | new BMessage(PRV_NORMAL_CHANGE_COLOR)); |
| 51 | | } else if (mode == MINI_WINDOW_MODE) { |
| 52 | | colorcontrol = new RTColorControl(BPoint(10, 20), |
| 53 | | new BMessage(PRV_MINI_CHANGE_COLOR)); |
| | 44 | |
| | 45 | // #pragma mark - |
| | 46 | |
| | 47 | |
| | 48 | /*! |
| | 49 | A single class for all three prefs views, needs to be |
| | 50 | customized below to give each control the right message |
| | 51 | */ |
| | 52 | ConfigView::ConfigView(BRect rect, const char *name, uint32 mode, BMessenger& target, |
| | 53 | Prefs *prefs) |
| | 54 | : BBox(rect, name, B_FOLLOW_NONE, B_WILL_DRAW), |
| | 55 | fMode(mode), |
| | 56 | fTarget(target), |
| | 57 | fPrefs(prefs), |
| | 58 | fFirstTimeAttached(true) |
| | 59 | { |
| | 60 | fFadeCheckBox = NULL; |
| | 61 | fActiveButton = fIdleButton = fFrameButton = NULL; |
| | 62 | fIconWidthControl = NULL; |
| | 63 | |
| | 64 | SetLabel("Bar Colors"); |
| | 65 | |
| | 66 | font_height fontHeight; |
| | 67 | be_bold_font->GetHeight(&fontHeight); |
| | 68 | |
| | 69 | fColorControl = new RTColorControl(BPoint(10, 5.0f + fontHeight.ascent |
| | 70 | + fontHeight.descent), new BMessage(fMode)); |
| | 71 | fColorControl->ResizeToPreferred(); |
| | 72 | AddChild(fColorControl); |
| | 73 | |
| | 74 | rect = fColorControl->Frame(); |
| | 75 | rect.top = rect.bottom + 10.0f; |
| | 76 | rect.bottom = rect.top + 15.0f; |
| | 77 | |
| | 78 | if (mode == PRV_NORMAL_CHANGE_COLOR) { |
| | 79 | // normal mode |
| | 80 | |
| | 81 | fFadeCheckBox = new BCheckBox(rect, "FadeColors", "Fade colors", |
| | 82 | new BMessage(PRV_NORMAL_FADE_COLORS)); |
| | 83 | fFadeCheckBox->ResizeToPreferred(); |
| | 84 | AddChild(fFadeCheckBox); |
| | 85 | |
| | 86 | fColorControl->SetValue(fPrefs->normal_bar_color); |
| | 87 | fFadeCheckBox->SetValue(fPrefs->normal_fade_colors); |
| | 88 | } else if (mode == PRV_MINI_CHANGE_COLOR) { |
| | 89 | // mini mode |
| | 90 | |
| | 91 | fActiveButton = new BRadioButton(rect, "ActiveColor", "Active color", |
| | 92 | new BMessage(PRV_MINI_ACTIVE)); |
| | 93 | fActiveButton->ResizeToPreferred(); |
| | 94 | fActiveButton->SetValue(B_CONTROL_ON); |
| | 95 | AddChild(fActiveButton); |
| | 96 | |
| | 97 | rect.left = fActiveButton->Frame().right + 5.0f; |
| | 98 | fIdleButton = new BRadioButton(rect, "IdleColor", "Idle color", |
| | 99 | new BMessage(PRV_MINI_IDLE)); |
| | 100 | fIdleButton->ResizeToPreferred(); |
| | 101 | AddChild(fIdleButton); |
| | 102 | |
| | 103 | rect.left = fIdleButton->Frame().right + 5.0f; |
| | 104 | fFrameButton = new BRadioButton(rect, "FrameColor", "Frame color", |
| | 105 | new BMessage(PRV_MINI_FRAME)); |
| | 106 | fFrameButton->ResizeToPreferred(); |
| | 107 | AddChild(fFrameButton); |
| | 108 | |
| | 109 | fColorControl->SetValue(fPrefs->mini_active_color); |
| 55 | | colorcontrol = new RTColorControl(BPoint(10, 20), |
| 56 | | new BMessage(PRV_DESKBAR_CHANGE_COLOR)); |
| 57 | | } |
| 58 | | |
| 59 | | bbox->AddChild(colorcontrol); |
| 60 | | r = colorcontrol->Frame(); |
| 61 | | r.top = r.bottom + 10; |
| 62 | | r.bottom = r.top + 15; |
| 63 | | |
| 64 | | if (mode == NORMAL_WINDOW_MODE) { |
| 65 | | r.right = r.left + be_plain_font->StringWidth("Fade colors") + 20; |
| 66 | | fadecolors = new BCheckBox(r, "FadeColors", "Fade colors", |
| 67 | | new BMessage(PRV_NORMAL_FADE_COLORS)); |
| 68 | | bbox->AddChild(fadecolors); |
| | 111 | // deskbar mode |
| | 112 | fActiveButton = new BRadioButton(rect, "ActiveColor", "Active color", |
| | 113 | new BMessage(PRV_DESKBAR_ACTIVE)); |
| | 114 | fActiveButton->ResizeToPreferred(); |
| | 115 | fActiveButton->SetValue(B_CONTROL_ON); |
| | 116 | AddChild(fActiveButton); |
| | 117 | |
| | 118 | rect.left = fActiveButton->Frame().right + 5.0f; |
| | 119 | fIdleButton = new BRadioButton(rect, "IdleColor", "Idle color", |
| | 120 | new BMessage(PRV_DESKBAR_IDLE)); |
| | 121 | fIdleButton->ResizeToPreferred(); |
| | 122 | AddChild(fIdleButton); |
| | 123 | |
| | 124 | rect.left = fIdleButton->Frame().right + 5.0f; |
| | 125 | fFrameButton = new BRadioButton(rect, "FrameColor", "Frame color", |
| | 126 | new BMessage(PRV_DESKBAR_FRAME)); |
| | 127 | fFrameButton->ResizeToPreferred(); |
| | 128 | AddChild(fFrameButton); |
| | 129 | |
| | 130 | rect.left = fColorControl->Frame().left; |
| | 131 | rect.top = fActiveButton->Frame().bottom + 5.0f; |
| | 132 | |
| | 133 | char temp[10]; |
| | 134 | snprintf(temp, sizeof(temp), "%d", fPrefs->deskbar_icon_width); |
| | 135 | fIconWidthControl = new BTextControl(rect, "Width", "Width of icon:", temp, |
| | 136 | new BMessage(PRV_DESKBAR_ICON_WIDTH)); |
| | 137 | AddChild(fIconWidthControl); |
| | 138 | fIconWidthControl->SetDivider(be_plain_font->StringWidth( |
| | 139 | fIconWidthControl->Label()) + 5.0f); |
| | 140 | |
| | 141 | for (int c = 0; c < 256; c++) { |
| | 142 | if (!isdigit(c)) |
| | 143 | fIconWidthControl->TextView()->DisallowChar(c); |
| | 144 | } |
| | 145 | fIconWidthControl->TextView()->SetMaxBytes(2); |
| 70 | | colorcontrol->SetValue(prefs->normal_bar_color); |
| 71 | | fadecolors->SetValue(prefs->normal_fade_colors); |
| 72 | | } else if (mode == MINI_WINDOW_MODE) { |
| 73 | | r.right = r.left + be_plain_font->StringWidth("Active color") + 20; |
| 74 | | active = new BRadioButton(r, "ActiveColor", "Active color", |
| 75 | | new BMessage(PRV_MINI_ACTIVE)); |
| 76 | | bbox->AddChild(active); |
| 77 | | active->SetValue(B_CONTROL_ON); |
| 78 | | |
| 79 | | r.left = r.right + 5; |
| 80 | | r.right = r.left + be_plain_font->StringWidth("Idle color") + 20; |
| 81 | | idle = new BRadioButton(r, "IdleColor", "Idle color", |
| 82 | | new BMessage(PRV_MINI_IDLE)); |
| 83 | | bbox->AddChild(idle); |
| 84 | | |
| 85 | | r.left = r.right + 5; |
| 86 | | r.right = r.left + be_plain_font->StringWidth("Frame color") + 20; |
| 87 | | frame = new BRadioButton(r, "FrameColor", "Frame color", |
| 88 | | new BMessage(PRV_MINI_FRAME)); |
| 89 | | bbox->AddChild(frame); |
| 90 | | |
| 91 | | colorcontrol->SetValue(prefs->mini_active_color); |
| | 147 | float width, height; |
| | 148 | fIconWidthControl->GetPreferredSize(&width, &height); |
| | 149 | fIconWidthControl->ResizeTo(fIconWidthControl->Divider() + 32.0f |
| | 150 | + fIconWidthControl->StringWidth("999"), height); |
| | 151 | |
| | 152 | fColorControl->SetValue(fPrefs->deskbar_active_color); |
| | 153 | } |
| | 154 | } |
| | 155 | |
| | 156 | |
| | 157 | void |
| | 158 | ConfigView::GetPreferredSize(float* _width, float* _height) |
| | 159 | { |
| | 160 | float right, bottom; |
| | 161 | |
| | 162 | if (fMode == PRV_NORMAL_CHANGE_COLOR) { |
| | 163 | // normal mode |
| | 164 | bottom = fFadeCheckBox->Frame().bottom; |
| | 165 | right = fFadeCheckBox->Frame().right; |
| | 166 | } else if (fMode == PRV_MINI_CHANGE_COLOR) { |
| | 167 | // mini mode |
| | 168 | bottom = fIdleButton->Frame().bottom; |
| | 169 | right = fFrameButton->Frame().right; |
| 93 | | bbox->ResizeBy(0, 20); |
| 94 | | |
| 95 | | r.right = r.left + be_plain_font->StringWidth("Active color") + 20; |
| 96 | | active = new BRadioButton(r, "ActiveColor", "Active color", |
| 97 | | new BMessage(PRV_DESKBAR_ACTIVE)); |
| 98 | | bbox->AddChild(active); |
| 99 | | active->SetValue(B_CONTROL_ON); |
| 100 | | |
| 101 | | r.left = r.right + 5; |
| 102 | | r.right = r.left + be_plain_font->StringWidth("Idle color") + 20; |
| 103 | | idle = new BRadioButton(r, "IdleColor", "Idle color", |
| 104 | | new BMessage(PRV_DESKBAR_IDLE)); |
| 105 | | bbox->AddChild(idle); |
| 106 | | |
| 107 | | r.left = r.right + 5; |
| 108 | | r.right = r.left + be_plain_font->StringWidth("Frame color") + 20; |
| 109 | | frame = new BRadioButton(r, "FrameColor", "Frame color", |
| 110 | | new BMessage(PRV_DESKBAR_FRAME)); |
| 111 | | bbox->AddChild(frame); |
| 112 | | |
| 113 | | r.top = active->Frame().bottom + 1; |
| 114 | | r.bottom = r.top + 15; |
| 115 | | r.left = 10; |
| 116 | | r.right = r.left + be_plain_font->StringWidth("Width of icon:") + 5 + 30; |
| 117 | | char temp[10]; |
| 118 | | sprintf(temp, "%d", prefs->deskbar_icon_width); |
| 119 | | iconwidth = new BTextControl(r, "Width", "Width of icon:", temp, |
| 120 | | new BMessage(PRV_DESKBAR_ICON_WIDTH)); |
| 121 | | bbox->AddChild(iconwidth); |
| 122 | | iconwidth->SetDivider(be_plain_font->StringWidth("Width of icon:") + 5); |
| 123 | | //iconwidth->SetModificationMessage(new BMessage(PRV_DESKBAR_ICON_WIDTH)); |
| 124 | | |
| 125 | | for (int x = 0; x < 256; x++) { |
| 126 | | if (x < '0' || x > '9') iconwidth->TextView()->DisallowChar(x); |
| 127 | | } |
| 128 | | iconwidth->TextView()->SetMaxBytes(2); |
| 129 | | |
| 130 | | colorcontrol->SetValue(prefs->deskbar_active_color); |
| 131 | | } |
| 132 | | } |
| 133 | | |
| 134 | | void ConfigView::AttachedToWindow() { |
| | 171 | // deskbar mode |
| | 172 | bottom = fIconWidthControl->Frame().bottom; |
| | 173 | right = fFrameButton->Frame().right; |
| | 174 | } |
| | 175 | |
| | 176 | if (right < fColorControl->Frame().right) |
| | 177 | right = fColorControl->Frame().right; |
| | 178 | if (right < 300) |
| | 179 | right = 300; |
| | 180 | |
| | 181 | if (_width) |
| | 182 | *_width = right + 10.0f; |
| | 183 | if (_height) |
| | 184 | *_height = bottom + 8.0f; |
| | 185 | } |
| | 186 | |
| | 187 | |
| | 188 | void |
| | 189 | ConfigView::AttachedToWindow() |
| | 190 | { |
| 141 | | colorcontrol->SetTarget(messenger); |
| 142 | | if (fadecolors != NULL) fadecolors->SetTarget(messenger); |
| 143 | | if (active != NULL) active->SetTarget(messenger); |
| 144 | | if (idle != NULL) idle->SetTarget(messenger); |
| 145 | | if (frame != NULL) frame->SetTarget(messenger); |
| 146 | | if (iconwidth != NULL) iconwidth->SetTarget(messenger); |
| 147 | | |
| 148 | | first_time_attached = false; |
| 149 | | } |
| 150 | | } |
| 151 | | |
| 152 | | void ConfigView::MessageReceived(BMessage *message) { |
| 153 | | PrefsWindow *prefswindow = (PrefsWindow *)Window(); |
| 154 | | if (prefswindow == NULL) return; |
| 155 | | Prefs *prefs = prefswindow->prefs; |
| 156 | | BMessenger *messenger = prefswindow->messenger; |
| 157 | | |
| | 202 | fColorControl->SetTarget(messenger); |
| | 203 | if (fFadeCheckBox != NULL) |
| | 204 | fFadeCheckBox->SetTarget(messenger); |
| | 205 | if (fActiveButton != NULL) |
| | 206 | fActiveButton->SetTarget(messenger); |
| | 207 | if (fIdleButton != NULL) |
| | 208 | fIdleButton->SetTarget(messenger); |
| | 209 | if (fFrameButton != NULL) |
| | 210 | fFrameButton->SetTarget(messenger); |
| | 211 | if (fIconWidthControl != NULL) |
| | 212 | fIconWidthControl->SetTarget(messenger); |
| | 213 | |
| | 214 | fFirstTimeAttached = false; |
| | 215 | } |
| | 216 | } |
| | 217 | |
| | 218 | |
| | 219 | void |
| | 220 | ConfigView::MessageReceived(BMessage *message) |
| | 221 | { |
| 182 | | int32 color = colorcontrol->Value(); |
| 183 | | if (active->Value()) { |
| 184 | | prefs->mini_active_color = color; |
| 185 | | } else if (idle->Value()) { |
| 186 | | prefs->mini_idle_color = color; |
| 187 | | } else { |
| 188 | | prefs->mini_frame_color = color; |
| 189 | | } |
| 190 | | message->AddInt32("active_color", prefs->mini_active_color); |
| 191 | | message->AddInt32("idle_color", prefs->mini_idle_color); |
| 192 | | message->AddInt32("frame_color", prefs->mini_frame_color); |
| 193 | | messenger->SendMessage(message); |
| | 248 | int32 color = fColorControl->Value(); |
| | 249 | if (fActiveButton->Value()) |
| | 250 | fPrefs->mini_active_color = color; |
| | 251 | else if (fIdleButton->Value()) |
| | 252 | fPrefs->mini_idle_color = color; |
| | 253 | else |
| | 254 | fPrefs->mini_frame_color = color; |
| | 255 | |
| | 256 | message->AddInt32("active_color", fPrefs->mini_active_color); |
| | 257 | message->AddInt32("idle_color", fPrefs->mini_idle_color); |
| | 258 | message->AddInt32("frame_color", fPrefs->mini_frame_color); |
| | 259 | fTarget.SendMessage(message); |
| 209 | | int32 color = colorcontrol->Value(); |
| 210 | | if (active->Value()) { |
| 211 | | prefs->deskbar_active_color = color; |
| 212 | | } else if (idle->Value()) { |
| 213 | | prefs->deskbar_idle_color = color; |
| 214 | | } else { |
| 215 | | prefs->deskbar_frame_color = color; |
| 216 | | } |
| 217 | | message->AddInt32("active_color", prefs->deskbar_active_color); |
| 218 | | message->AddInt32("idle_color", prefs->deskbar_idle_color); |
| 219 | | message->AddInt32("frame_color", prefs->deskbar_frame_color); |
| 220 | | messenger->SendMessage(message); |
| | 275 | int32 color = fColorControl->Value(); |
| | 276 | if (fActiveButton->Value()) |
| | 277 | fPrefs->deskbar_active_color = color; |
| | 278 | else if (fIdleButton->Value()) |
| | 279 | fPrefs->deskbar_idle_color = color; |
| | 280 | else |
| | 281 | fPrefs->deskbar_frame_color = color; |
| | 282 | |
| | 283 | message->AddInt32("active_color", fPrefs->deskbar_active_color); |
| | 284 | message->AddInt32("idle_color", fPrefs->deskbar_idle_color); |
| | 285 | message->AddInt32("frame_color", fPrefs->deskbar_frame_color); |
| | 286 | fTarget.SendMessage(message); |
| 251 | | iconwidth->SetText(temp); |
| 252 | | } |
| 253 | | |
| 254 | | BMessage *message = new BMessage(PRV_DESKBAR_ICON_WIDTH); |
| 255 | | message->AddInt32("width", width); |
| 256 | | prefs->deskbar_icon_width = width; |
| 257 | | messenger->SendMessage(message); |
| 258 | | delete message; |
| 259 | | } |
| 260 | | |
| 261 | | // Only reset our own controls to default |
| 262 | | void ConfigView::ResetDefaults() { |
| 263 | | PrefsWindow *prefswindow = (PrefsWindow *)Window(); |
| 264 | | if (prefswindow == NULL) return; |
| 265 | | Prefs *prefs = prefswindow->prefs; |
| 266 | | BMessenger *messenger = prefswindow->messenger; |
| 267 | | |
| 268 | | if (mode == NORMAL_WINDOW_MODE) { |
| 269 | | colorcontrol->SetValue(DEFAULT_NORMAL_BAR_COLOR); |
| 270 | | fadecolors->SetValue(DEFAULT_NORMAL_FADE_COLORS); |
| 271 | | } else if (mode == MINI_WINDOW_MODE) { |
| 272 | | prefs->mini_active_color = DEFAULT_MINI_ACTIVE_COLOR; |
| 273 | | prefs->mini_idle_color = DEFAULT_MINI_IDLE_COLOR; |
| 274 | | prefs->mini_frame_color = DEFAULT_MINI_FRAME_COLOR; |
| 275 | | if (active->Value()) { |
| 276 | | colorcontrol->SetValue(DEFAULT_MINI_ACTIVE_COLOR); |
| 277 | | } else if (idle->Value()) { |
| 278 | | colorcontrol->SetValue(DEFAULT_MINI_IDLE_COLOR); |
| 279 | | } else { |
| 280 | | colorcontrol->SetValue(DEFAULT_MINI_FRAME_COLOR); |
| 281 | | } |
| | 315 | fIconWidthControl->SetText(temp); |
| | 316 | } |
| | 317 | |
| | 318 | fPrefs->deskbar_icon_width = width; |
| | 319 | |
| | 320 | BMessage message(PRV_DESKBAR_ICON_WIDTH); |
| | 321 | message.AddInt32("width", width); |
| | 322 | fTarget.SendMessage(&message); |
| | 323 | } |
| | 324 | |
| | 325 | |
| | 326 | void |
| | 327 | ConfigView::_ResetDefaults() |
| | 328 | { |
| | 329 | if (fMode == PRV_NORMAL_CHANGE_COLOR) { |
| | 330 | fColorControl->SetValue(DEFAULT_NORMAL_BAR_COLOR); |
| | 331 | fFadeCheckBox->SetValue(DEFAULT_NORMAL_FADE_COLORS); |
| | 332 | } else if (fMode == PRV_MINI_CHANGE_COLOR) { |
| | 333 | fPrefs->mini_active_color = DEFAULT_MINI_ACTIVE_COLOR; |
| | 334 | fPrefs->mini_idle_color = DEFAULT_MINI_IDLE_COLOR; |
| | 335 | fPrefs->mini_frame_color = DEFAULT_MINI_FRAME_COLOR; |
| | 336 | if (fActiveButton->Value()) |
| | 337 | fColorControl->SetValue(DEFAULT_MINI_ACTIVE_COLOR); |
| | 338 | else if (fIdleButton->Value()) |
| | 339 | fColorControl->SetValue(DEFAULT_MINI_IDLE_COLOR); |
| | 340 | else |
| | 341 | fColorControl->SetValue(DEFAULT_MINI_FRAME_COLOR); |
| | 342 | |
| 288 | | prefs->deskbar_active_color = DEFAULT_DESKBAR_ACTIVE_COLOR; |
| 289 | | prefs->deskbar_idle_color = DEFAULT_DESKBAR_IDLE_COLOR; |
| 290 | | prefs->deskbar_frame_color = DEFAULT_DESKBAR_FRAME_COLOR; |
| 291 | | if (active->Value()) { |
| 292 | | colorcontrol->SetValue(DEFAULT_DESKBAR_ACTIVE_COLOR); |
| 293 | | } else if (idle->Value()) { |
| 294 | | colorcontrol->SetValue(DEFAULT_DESKBAR_IDLE_COLOR); |
| 295 | | } else { |
| 296 | | colorcontrol->SetValue(DEFAULT_DESKBAR_FRAME_COLOR); |
| 297 | | } |
| | 349 | fPrefs->deskbar_active_color = DEFAULT_DESKBAR_ACTIVE_COLOR; |
| | 350 | fPrefs->deskbar_idle_color = DEFAULT_DESKBAR_IDLE_COLOR; |
| | 351 | fPrefs->deskbar_frame_color = DEFAULT_DESKBAR_FRAME_COLOR; |
| | 352 | if (fActiveButton->Value()) |
| | 353 | fColorControl->SetValue(DEFAULT_DESKBAR_ACTIVE_COLOR); |
| | 354 | else if (fIdleButton->Value()) |
| | 355 | fColorControl->SetValue(DEFAULT_DESKBAR_IDLE_COLOR); |
| | 356 | else |
| | 357 | fColorControl->SetValue(DEFAULT_DESKBAR_FRAME_COLOR); |
| | 358 | |