Files
haiku-beta6/src/prefs/appearance/APRView.cpp
T

727 lines
19 KiB
C++
Raw Normal View History

2003-04-04 02:22:23 +00:00
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: APRView.cpp
// Author: DarkWyrm <[email protected]>
// Description: color handler for the app
//
// Handles all the grunt work. Color settings are stored in a BMessage to
// allow for easy transition to and from disk. The messy details are in the
// hard-coded strings to translate the enumerated color_which defines to
// strings and such, but even those should be easy to maintain.
//------------------------------------------------------------------------------
2002-07-09 12:24:59 +00:00
#include <OS.h>
#include <Directory.h>
#include <Alert.h>
2003-04-04 02:22:23 +00:00
#include <storage/Path.h>
#include <Entry.h>
2002-07-09 12:24:59 +00:00
#include <File.h>
2002-08-20 14:13:13 +00:00
#include <Screen.h> // for settings Desktop color
2002-07-09 12:24:59 +00:00
#include <stdio.h>
#include "APRView.h"
2003-02-07 18:56:09 +00:00
#include <PortLink.h>
2003-10-08 00:22:18 +00:00
#include <PortMessage.h>
#include "defs.h"
#include "ColorWell.h"
2003-02-07 19:03:19 +00:00
#include <ColorUtils.h>
2003-04-04 02:22:23 +00:00
#include <InterfaceDefs.h>
2003-10-08 00:22:18 +00:00
#include <ServerProtocol.h>
2003-04-04 02:22:23 +00:00
#include "ColorWhichItem.h"
#include "ServerConfig.h"
//#define DEBUG_COLORSET
2003-10-05 21:54:24 +00:00
#ifdef DEBUG_COLORSET
#define STRACE(a) printf a
#else
#define STRACE(A) /* nothing */
#endif
//#define SAVE_COLORSET 'svcs'
//#define DELETE_COLORSET 'dlcs'
//#define LOAD_COLORSET 'ldcs'
#define COLOR_DROPPED 'cldp'
APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags)
2003-10-05 21:54:24 +00:00
:BView(frame,name,resize,flags)
2002-07-09 12:24:59 +00:00
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
2003-10-05 21:54:24 +00:00
currentset=new ColorSet;
prevset=NULL;
/*
// This disabled code block is being saved for a color set app
BMenuBar *mb=new BMenuBar(BRect(0,0,Bounds().Width(),16),"menubar");
settings_menu=new BMenu("Settings");
settings_menu->AddItem(new BMenuItem("Save Color Set",new BMessage(SAVE_COLORSET),'S'));
settings_menu->AddSeparatorItem();
settings_menu->AddItem(new BMenuItem("Delete Color Set",new BMessage(DELETE_COLORSET)));
mb->AddItem(settings_menu);
colorset_menu=LoadColorSets();
if(colorset_menu)
mb->AddItem(colorset_menu);
else
{
// We should *never* be here, but just in case....
colorset_menu=new BMenu("Color Sets");
mb->AddItem(colorset_menu);
}
AddChild(mb);
*/
2002-07-09 12:24:59 +00:00
// Set up list of color attributes
BRect rect(10,10,200,175);
attrlist=new BListView(rect,"AttributeList");
2002-07-09 12:24:59 +00:00
scrollview=new BScrollView("ScrollView",attrlist, B_FOLLOW_LEFT |
B_FOLLOW_TOP, 0, false, true);
AddChild(scrollview);
scrollview->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
attrlist->SetSelectionMessage(new BMessage(ATTRIBUTE_CHOSEN));
2003-04-04 02:22:23 +00:00
attrlist->AddItem(new ColorWhichItem(B_PANEL_BACKGROUND_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_PANEL_TEXT_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_DOCUMENT_BACKGROUND_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_DOCUMENT_TEXT_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_CONTROL_BACKGROUND_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_CONTROL_TEXT_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_CONTROL_BORDER_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_CONTROL_HIGHLIGHT_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_NAVIGATION_BASE_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_NAVIGATION_PULSE_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_SHINE_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_SHADOW_COLOR));
2003-04-04 02:22:23 +00:00
attrlist->AddItem(new ColorWhichItem(B_MENU_BACKGROUND_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_MENU_SELECTED_BACKGROUND_COLOR));
2003-04-04 02:22:23 +00:00
attrlist->AddItem(new ColorWhichItem(B_MENU_ITEM_TEXT_COLOR));
attrlist->AddItem(new ColorWhichItem(B_MENU_SELECTED_ITEM_TEXT_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_MENU_SELECTED_BORDER_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_TOOLTIP_BACKGROUND_COLOR));
2002-07-09 12:24:59 +00:00
attrlist->AddItem(new ColorWhichItem((color_which)B_SUCCESS_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_FAILURE_COLOR));
2003-04-04 02:22:23 +00:00
attrlist->AddItem(new ColorWhichItem(B_WINDOW_TAB_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_WINDOW_TAB_TEXT_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_INACTIVE_WINDOW_TAB_COLOR));
attrlist->AddItem(new ColorWhichItem((color_which)B_INACTIVE_WINDOW_TAB_TEXT_COLOR));
2003-04-04 02:22:23 +00:00
BRect wellrect(0,0,50,50);
wellrect.OffsetTo(rect.right + 42,25);
colorwell=new ColorWell(wellrect,new BMessage(COLOR_DROPPED),true);
AddChild(colorwell);
picker=new BColorControl(BPoint(10,scrollview->Frame().bottom+20),B_CELLS_32x8,5.0,"Picker",
2002-07-09 12:24:59 +00:00
new BMessage(UPDATE_COLOR));
AddChild(picker);
BRect cvrect;
2002-07-09 12:24:59 +00:00
cvrect=picker->Frame();
cvrect.right=cvrect.left+60;
cvrect.bottom=cvrect.top+30;
// 40 is 10 pixel space between buttons and other objects, such as the edge or another button
cvrect.OffsetTo( (Bounds().Width()-((cvrect.Width()*3)+40))/2,picker->Frame().bottom+10);
2002-07-09 12:24:59 +00:00
defaults=new BButton(cvrect,"DefaultsButton","Defaults",
new BMessage(DEFAULT_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
AddChild(defaults);
2003-10-05 21:54:24 +00:00
defaults->SetEnabled(false);
2002-07-09 12:24:59 +00:00
cvrect.OffsetBy(70,0);
revert=new BButton(cvrect,"RevertButton","Revert",
new BMessage(REVERT_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
AddChild(revert);
2003-07-07 19:53:47 +00:00
revert->SetEnabled(false);
2002-07-09 12:24:59 +00:00
cvrect.OffsetBy(70,0);
apply=new BButton(cvrect,"ApplyButton","Apply",
new BMessage(APPLY_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
AddChild(apply);
2003-07-07 19:53:47 +00:00
apply->SetEnabled(false);
BEntry entry(COLOR_SET_DIR);
entry_ref ref;
entry.GetRef(&ref);
2002-07-09 12:24:59 +00:00
attribute=B_PANEL_BACKGROUND_COLOR;
2003-10-08 00:22:18 +00:00
attrstring="Panel Background";
2002-07-09 12:24:59 +00:00
LoadSettings();
}
APRView::~APRView(void)
{
2003-10-05 21:54:24 +00:00
if(currentset)
delete currentset;
if(prevset)
delete prevset;
2002-07-09 12:24:59 +00:00
}
void APRView::AllAttached(void)
2002-07-09 12:24:59 +00:00
{
picker->SetTarget(this);
attrlist->Select(0);
2002-07-09 12:24:59 +00:00
attrlist->SetTarget(this);
apply->SetTarget(this);
defaults->SetTarget(this);
revert->SetTarget(this);
colorwell->SetTarget(this);
BMessenger msgr(this);
2003-10-05 21:54:24 +00:00
picker->SetValue(currentset->StringToColor(attrstring.String()).GetColor32());
2002-07-09 12:24:59 +00:00
}
void APRView::MessageReceived(BMessage *msg)
{
if(msg->WasDropped())
{
rgb_color *col;
ssize_t size;
if(msg->FindData("RGBColor",(type_code)'RGBC',(const void**)&col,&size)==B_OK)
{
picker->SetValue(*col);
colorwell->SetColor(*col);
2003-10-08 00:22:18 +00:00
colorwell->Invalidate();
}
}
2002-07-09 12:24:59 +00:00
switch(msg->what)
{
/*
// More code being saved for a color set app
case DELETE_COLORSET:
2002-08-20 13:26:20 +00:00
{
2003-10-08 00:22:18 +00:00
// We can't delete the Default set
if(currentset->name.Compare("Default")==0)
break;
2002-08-20 13:26:20 +00:00
// Construct the path and delete
BString path(COLOR_SET_DIR);
2003-10-05 21:54:24 +00:00
path+=currentset->name;
2002-08-20 13:26:20 +00:00
BString printstring("Remove ");
2003-10-05 21:54:24 +00:00
printstring+=currentset->name;
2002-08-20 13:26:20 +00:00
printstring+=" from disk permenantly?";
BAlert *a=new BAlert("OpenBeOS",printstring.String(),"Yes", "No");
if(a->Go()==0)
{
int stat=remove(path.String());
if(stat!=0)
{
2003-10-05 21:54:24 +00:00
STRACE(("MSG: Delete Request - couldn't delete file %s\n",path.String()));
2002-08-20 13:26:20 +00:00
}
else
{
2003-10-05 21:54:24 +00:00
BMenuItem *item=colorset_menu->FindItem(currentset->name.String());
2002-08-20 13:26:20 +00:00
if(item!=NULL)
{
if(colorset_menu->RemoveItem(item))
delete item;
}
}
}
break;
}
case LOAD_COLORSET:
{
BString name;
if(msg->FindString("name",&name)!=B_OK)
{
2003-10-05 21:54:24 +00:00
STRACE(("MSG: Load Request - couldn't find file name\n"));
break;
}
LoadColorSet(name);
break;
}
case SAVE_COLORSET:
{
2003-10-08 00:22:18 +00:00
// Saving the Default set is rather dumb
if(currentset->name.Compare("Default")==0)
break;
savepanel->Show();
break;
}
case B_SAVE_REQUESTED:
{
BString name;
if(msg->FindString("name",&name)!=B_OK)
{
2003-10-05 21:54:24 +00:00
STRACE(("MSG: Save Request - couldn't find file name\n"));
break;
}
2003-10-08 00:22:18 +00:00
if(name.ICompare("Default")==0)
{
BAlert *a=new BAlert("OpenBeOS","The name 'Default' is reserved. Please choose another.","OK");
a->Go();
savepanel->Show();
break;
}
SaveColorSet(name);
break;
}
// end disabled colorset code
*/
case UPDATE_COLOR:
2002-07-09 12:24:59 +00:00
{
// Received from the color picker when its color changes
2003-10-05 21:54:24 +00:00
if(!prevset)
{
prevset=new ColorSet;
*prevset=*currentset;
}
2002-07-09 12:24:59 +00:00
rgb_color col=picker->ValueAsColor();
colorwell->SetColor(col);
colorwell->Invalidate();
2002-07-09 12:24:59 +00:00
// Update current attribute in the settings
2003-10-05 21:54:24 +00:00
if(currentset->SetColor(attrstring.String(),col)!=B_OK)
{
STRACE(("Couldn't set color for attribute %s\n",attrstring.String()));
}
2003-07-07 19:53:47 +00:00
2003-10-05 21:54:24 +00:00
if(!apply->IsEnabled())
2003-07-07 19:53:47 +00:00
apply->SetEnabled(true);
2003-10-05 21:54:24 +00:00
if(!defaults->IsEnabled())
defaults->SetEnabled(true);
if(!revert->IsEnabled())
2003-07-07 19:53:47 +00:00
revert->SetEnabled(true);
Window()->PostMessage(SET_UI_COLORS);
2002-07-09 12:24:59 +00:00
break;
}
case ATTRIBUTE_CHOSEN:
{
// Received when the user chooses a GUI attribute from the list
2003-04-04 02:22:23 +00:00
ColorWhichItem *whichitem=(ColorWhichItem*)attrlist->ItemAt(attrlist->CurrentSelection());
if(!whichitem)
break;
2003-07-07 19:53:47 +00:00
attrstring=whichitem->Text();
2003-10-08 00:22:18 +00:00
UpdateControlsFromAttr(whichitem->Text());
2002-07-09 12:24:59 +00:00
break;
}
case APPLY_SETTINGS:
{
2003-10-05 21:54:24 +00:00
if(prevset)
{
delete prevset;
prevset=NULL;
revert->SetEnabled(false);
}
if(currentset->name=="Default")
defaults->SetEnabled(false);
apply->SetEnabled(false);
2002-07-09 12:24:59 +00:00
SaveSettings();
NotifyServer();
break;
}
case TRY_SETTINGS:
2002-07-09 12:24:59 +00:00
{
// Tell server to apply settings here without saving them.
// Theoretically, the user can set this temporarily and keep it
// until the next boot.
NotifyServer();
break;
}
case REVERT_SETTINGS:
2002-07-09 12:24:59 +00:00
{
2003-10-05 21:54:24 +00:00
delete currentset;
currentset=prevset;
prevset=NULL;
rgb_color col=picker->ValueAsColor();
colorwell->SetColor(col);
colorwell->Invalidate();
2003-07-07 19:53:47 +00:00
2003-10-05 21:54:24 +00:00
// Update current attribute in the settings
currentset->SetColor(attrstring.String(),col);
if(!apply->IsEnabled())
apply->SetEnabled(false);
if((currentset->name!="Default"))
defaults->SetEnabled(true);
else
defaults->SetEnabled(false);
revert->SetEnabled(false);
Window()->PostMessage(SET_UI_COLORS);
2002-07-09 12:24:59 +00:00
break;
}
case DEFAULT_SETTINGS:
{
2003-10-05 21:54:24 +00:00
if(!prevset)
{
prevset=new ColorSet;
*prevset=*currentset;
revert->SetEnabled(true);
apply->SetEnabled(true);
}
2002-07-09 12:24:59 +00:00
SetDefaults();
2003-10-08 00:22:18 +00:00
UpdateControlsFromAttr(attrstring.String());
if(Window())
Window()->PostMessage(SET_UI_COLORS);
2002-07-09 12:24:59 +00:00
break;
}
default:
BView::MessageReceived(msg);
break;
}
}
/*
// This section is commented out because Appearance doesn't manage color sets. That
// task is better left to another application.
BMenu *APRView::LoadColorSets(void)
{
2003-10-05 21:54:24 +00:00
STRACE(("Loading color sets from disk\n"));
// This function populates the member menu *colorset_menu with the color
// set files located in the color set directory. To ensure that there are
// no entries pointing to invalid color sets, they are validated before
// a menu item is added.
BDirectory dir;
BEntry entry;
BPath path;
BString name;
BMenu *menu=new BMenu("Color Sets");
status_t dirstat=dir.SetTo(COLOR_SET_DIR);
if(dirstat!=B_OK)
{
// We couldn't set the directory, so more than likely it just
// doesn't exist. Create it and return an empty menu.
switch(dirstat)
{
case B_NAME_TOO_LONG:
{
BAlert *a=new BAlert("OpenBeOS","Couldn't open the folder for color sets. "
"You will be able to change system colors, but be unable to save them to a color set. "
"Please contact OpenBeOS about Appearance Preferences::APRView::"
"LoadColorSets::B_NAME_TOO_LONG for a bugfix", "OK",
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
a->Go();
break;
}
case B_ENTRY_NOT_FOUND:
{
create_directory(COLOR_SET_DIR,0777);
break;
}
case B_BAD_VALUE:
{
2003-10-05 21:54:24 +00:00
STRACE(("APRView::LoadColorSets(): Invalid colorset folder path.\n"));
break;
}
case B_NO_MEMORY:
{
2003-10-05 21:54:24 +00:00
STRACE(("APRView::LoadColorSets(): No memory left. We're probably going to crash now. \n"));
break;
}
case B_BUSY:
{
2003-10-05 21:54:24 +00:00
STRACE(("APRView::LoadColorSets(): Busy node " COLOR_SET_DIR "\n"));
break;
}
case B_FILE_ERROR:
{
BAlert *a=new BAlert("OpenBeOS","Couldn't open the folder for color sets "
"because of a file error. Perhaps there is a file (instead of a folder) at " COLOR_SET_DIR
"? You will be able to change system colors, but be unable to save them to a color set. ",
"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
a->Go();
break;
}
case B_NO_MORE_FDS:
{
BAlert *a=new BAlert("OpenBeOS","Couldn't open the folder for color sets "
"because there are too many open files. Please close some files and restart "
" this application.", "OK",
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
a->Go();
if(Window())
Window()->PostMessage(B_QUIT_REQUESTED);
break;
}
}
return menu;
}
int32 count=dir.CountEntries();
BMessage *msg;
for(int32 i=0;i<count;i++)
{
dir.GetNextEntry(&entry);
entry.GetPath(&path);
name=path.Path();
name.Remove(0,name.FindLast('/')+1);
msg=new BMessage(LOAD_COLORSET);
msg->AddString("name",name);
menu->AddItem(new BMenuItem(name.String(),msg));
}
return menu;
}
*/
void APRView::LoadColorSet(const BString &name)
{
// Load the current GUI color settings from a color set file.
2003-10-05 21:54:24 +00:00
STRACE(("LoadColorSet: %s\n",name.String()));
BDirectory dir,newdir;
if(dir.SetTo(COLOR_SET_DIR)==B_ENTRY_NOT_FOUND)
{
2003-10-05 21:54:24 +00:00
STRACE(("Color set folder not found. Creating %s\n",COLOR_SET_DIR));
create_directory(COLOR_SET_DIR,0777);
}
2003-10-05 21:54:24 +00:00
BString path(COLOR_SET_DIR);
path+=name.String();
BFile file(path.String(),B_READ_ONLY);
2003-10-05 21:54:24 +00:00
if(file.InitCheck()!=B_OK)
{
2003-10-05 21:54:24 +00:00
STRACE(("Couldn't open file %s for read\n",path.String()));
return;
}
2003-10-05 21:54:24 +00:00
BMessage settings;
if(settings.Unflatten(&file)!=B_OK)
{
2003-10-05 21:54:24 +00:00
STRACE(("Error unflattening file %s\n",name.String()));
return;
}
2003-10-05 21:54:24 +00:00
currentset->ConvertFromMessage(&settings);
// SetColorSetName(currentset->name.String());
2003-10-05 21:54:24 +00:00
2003-10-08 00:22:18 +00:00
UpdateControlsFromAttr(attrstring.String());
}
/*
// More code being saved for a color set app
void APRView::SaveColorSet(const BString &name)
{
// Save the current color attributes as a flattened BMessage in the
// color set folder
BString path(COLOR_SET_DIR);
path+=name.String();
2003-10-05 21:54:24 +00:00
STRACE(("SaveColorSet: %s\n",path.String()));
BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE);
if(file.InitCheck()!=B_OK)
{
2003-10-05 21:54:24 +00:00
STRACE(("SaveColorSet: Couldn't open settings file for write\n"));
return;
}
2003-10-05 21:54:24 +00:00
BMessage settings;
2003-10-08 00:22:18 +00:00
currentset->name=name;
2003-10-05 21:54:24 +00:00
currentset->ConvertToMessage(&settings);
2003-10-08 00:22:18 +00:00
if(settings.Flatten(&file)!=B_OK)
{
2003-10-05 21:54:24 +00:00
STRACE(("SaveColorSet: Couldn't flatten settings to file\n"));
return;
}
BMessage *msg=new BMessage(LOAD_COLORSET);
msg->AddString("name",name.String());
if(colorset_menu->AddItem(new BMenuItem(name.String(),msg))==false)
{
2003-10-05 21:54:24 +00:00
STRACE(("SaveColorSet: Error in adding item to menu\n"));
}
SetColorSetName(name.String());
2003-10-08 00:22:18 +00:00
// If we saved the color set after Applying it, the name won't be updated on disk, so
// save again to disk if this has happened.
if(prevset==NULL)
SaveSettings();
}
// More code being saved for a color set app
void APRView::SetColorSetName(const char *name)
{
if(!name)
return;
BString namestr("Color Set: ");
2003-10-05 21:54:24 +00:00
currentset->name.SetTo(name);
namestr+=name;
colorwell_label->SetText(namestr.String());
colorwell_label->ResizeToPreferred();
colorwell_label->Invalidate();
}
*/
2002-07-09 12:24:59 +00:00
void APRView::SaveSettings(void)
{
// Save the current GUI color settings to the GUI colors file in the
// path specified in defs.h
BString path(SERVER_SETTINGS_DIR);
path+=COLOR_SETTINGS_NAME;
2003-10-05 21:54:24 +00:00
STRACE(("SaveSettings: %s\n",path.String()));
2002-07-09 12:24:59 +00:00
BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE);
2003-10-05 21:54:24 +00:00
BMessage settings;
currentset->ConvertToMessage(&settings);
2002-07-09 12:24:59 +00:00
settings.Flatten(&file);
}
void APRView::LoadSettings(void)
{
// Load the current GUI color settings from disk. This is done instead of
2003-10-05 21:54:24 +00:00
// getting them from the server at this point for testing purposes.
#ifndef RUN_WITHOUT_APP_SERVER
2003-10-08 00:22:18 +00:00
// Query the server for the current settings
port_id port=find_port(SERVER_PORT_NAME);
if(port!=B_NAME_NOT_FOUND)
{
2003-10-08 00:22:18 +00:00
STRACE(("Retrieving settings from app_server\n"));
BPortLink link(port);
int32 code;
2003-10-08 00:22:18 +00:00
link.StartMessage(AS_GET_UI_COLORS);
link.Flush();
link.GetNextMessage(code);
link.Read<ColorSet>(currentset);
}
2003-10-08 00:22:18 +00:00
else
{
#endif
2003-10-08 00:22:18 +00:00
STRACE(("Loading settings from disk\n"));
2003-10-05 21:54:24 +00:00
2003-10-08 00:22:18 +00:00
BDirectory dir,newdir;
if(dir.SetTo(SERVER_SETTINGS_DIR)==B_ENTRY_NOT_FOUND)
{
STRACE(("Color set folder not found. Creating %s\n",SERVER_SETTINGS_DIR));
create_directory(SERVER_SETTINGS_DIR,0777);
}
BString path(SERVER_SETTINGS_DIR);
path+=COLOR_SETTINGS_NAME;
BFile file(path.String(),B_READ_ONLY);
if(file.InitCheck()!=B_OK)
{
STRACE(("Couldn't open file %s for read\n",path.String()));
SetDefaults();
SaveSettings();
return;
}
BMessage settings;
if(settings.Unflatten(&file)!=B_OK)
{
STRACE(("Error unflattening SystemColors file %s\n",path.String()));
SetDefaults();
SaveSettings();
}
currentset->ConvertFromMessage(&settings);
#ifndef RUN_WITHOUT_APP_SERVER
}
2003-10-05 21:54:24 +00:00
// SetColorSetName(currentset->name.String());
#endif
2002-07-09 12:24:59 +00:00
2003-10-08 00:22:18 +00:00
UpdateControlsFromAttr(attrstring.String());
2003-10-05 21:54:24 +00:00
2003-10-08 00:22:18 +00:00
if(currentset->name.Compare("Default")!=0)
2003-10-05 21:54:24 +00:00
defaults->SetEnabled(true);
2002-07-09 12:24:59 +00:00
}
void APRView::SetDefaults(void)
{
2003-10-05 21:54:24 +00:00
STRACE(("Initializing color settings to defaults\n"));
defaults->SetEnabled(false);
currentset->name.SetTo("Default");
2003-04-04 02:22:23 +00:00
2003-10-05 21:54:24 +00:00
currentset->SetToDefaults();
2002-07-09 12:24:59 +00:00
}
void APRView::NotifyServer(void)
{
#ifndef RUN_WITHOUT_APP_SERVER
2002-07-09 12:24:59 +00:00
// Send a message to the app_server with the settings which we have.
2002-08-20 14:13:13 +00:00
2003-10-18 23:58:59 +00:00
port_id port=find_port(SERVER_PORT_NAME);
if(port!=B_NAME_NOT_FOUND)
2002-08-20 14:13:13 +00:00
{
2003-10-18 23:58:59 +00:00
STRACE(("Notifying app_server\n"));
BPortLink link(port);
2003-10-18 23:58:59 +00:00
link.StartMessage(AS_SET_UI_COLORS);
2003-10-18 23:58:59 +00:00
link.Attach<ColorSet>(*currentset);
link.Flush();
2002-08-20 14:13:13 +00:00
}
2003-10-18 23:58:59 +00:00
// We also need to send the message to the window so that the Decorators tab updates itself
if(Window())
Window()->PostMessage(SET_UI_COLORS);
#endif
2002-07-09 12:24:59 +00:00
}
2003-10-08 00:22:18 +00:00
void APRView::UpdateControlsFromAttr(const char *string)
{
if(!string)
return;
STRACE(("Update color for %s\n",string));
picker->SetValue(currentset->StringToColor(string).GetColor32());
colorwell->SetColor(picker->ValueAsColor());
colorwell->Invalidate();
}