1/* 2 * Copyright 2002-2006, Stephan A��mus <superstippi@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 * 5 */ 6 7#include "ColorPickerPanel.h" 8 9#include <stdio.h> 10 11#include <Autolock.h> 12#include <Application.h> 13#include <Locker.h> 14 15#include <Box.h> 16#include <Button.h> 17#include <Catalog.h> 18#include <ControlLook.h> 19#include <GroupView.h> 20#include <LayoutBuilder.h> 21#include <Locale.h> 22#include <SeparatorView.h> 23 24#include "support_ui.h" 25 26#include "ColorPickerView.h" 27 28 29#undef B_TRANSLATION_CONTEXT 30#define B_TRANSLATION_CONTEXT "Icon-O-Matic-ColorPicker" 31 32 33enum { 34 MSG_CANCEL = 'cncl', 35 MSG_DONE = 'done', 36}; 37 38 39ColorPickerPanel::ColorPickerPanel(BRect frame, rgb_color color, 40 SelectedColorMode mode, 41 BWindow* window, 42 BMessage* message, BHandler* target) 43 : Panel(frame, "Pick a color", 44 B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL, 45 B_ASYNCHRONOUS_CONTROLS | 46 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_CLOSABLE 47 | B_AUTO_UPDATE_SIZE_LIMITS), 48 fWindow(window), 49 fMessage(message), 50 fTarget(target) 51{ 52 SetTitle(B_TRANSLATE("Pick a color")); 53 54 fColorPickerView = new ColorPickerView("color picker", color, mode); 55 56 SetLayout(new BGroupLayout(B_VERTICAL)); 57 58 BButton* defaultButton = new BButton("ok button", 59 B_TRANSLATE("OK"), 60 new BMessage(MSG_DONE)); 61 BButton* cancelButton = new BButton("cancel button", 62 B_TRANSLATE("Cancel"), 63 new BMessage(MSG_CANCEL)); 64 65 BView* topView = new BGroupView(B_VERTICAL); 66 67 const float inset = be_control_look->DefaultLabelSpacing(); 68 69 BLayoutBuilder::Group<>(topView, B_VERTICAL, 0.0f) 70 .Add(fColorPickerView) 71 .Add(new BSeparatorView(B_HORIZONTAL)) 72 .AddGroup(B_HORIZONTAL) 73 .AddGlue() 74 .Add(cancelButton) 75 .Add(defaultButton) 76 .SetInsets(inset, inset, inset, inset) 77 .End() 78 ; 79 80 SetDefaultButton(defaultButton); 81 82 if (fWindow != NULL) 83 AddToSubset(fWindow); 84 else 85 SetFeel(B_FLOATING_APP_WINDOW_FEEL); 86 87 AddChild(topView); 88} 89 90 91ColorPickerPanel::~ColorPickerPanel() 92{ 93 delete fMessage; 94} 95 96 97void 98ColorPickerPanel::Cancel() 99{ 100 PostMessage(MSG_CANCEL); 101} 102 103 104void 105ColorPickerPanel::MessageReceived(BMessage* message) 106{ 107 switch (message->what) { 108 case MSG_CANCEL: 109 case MSG_DONE: 110 { 111 BMessage msg('PSTE'); 112 BLooper* looper = fTarget ? fTarget->Looper() : be_app; 113 if (fMessage) 114 msg = *fMessage; 115 if (message->what == MSG_DONE) 116 store_color_in_message(&msg, fColorPickerView->Color()); 117 msg.AddRect("panel frame", Frame()); 118 msg.AddInt32("panel mode", fColorPickerView->Mode()); 119 msg.AddBool("begin", true); 120 looper->PostMessage(&msg, fTarget); 121 PostMessage(B_QUIT_REQUESTED); 122 break; 123 } 124 default: 125 Panel::MessageReceived(message); 126 break; 127 } 128} 129 130 131// #pragma mark - 132 133 134void 135ColorPickerPanel::SetColor(rgb_color color) 136{ 137 fColorPickerView->SetColor(color); 138} 139 140 141void 142ColorPickerPanel::SetMessage(BMessage* message) 143{ 144 if (message != fMessage) { 145 delete fMessage; 146 fMessage = message; 147 } 148} 149 150 151void 152ColorPickerPanel::SetTarget(BHandler* target) 153{ 154 fTarget = target; 155} 156 157