diff --git a/src/prefs/appearance/APRView.cpp b/src/prefs/appearance/APRView.cpp index 0228a46a9d..76b493aa00 100644 --- a/src/prefs/appearance/APRView.cpp +++ b/src/prefs/appearance/APRView.cpp @@ -44,6 +44,7 @@ #include #include #include "ColorWhichItem.h" +#include "ServerConfig.h" //#define DEBUG_COLORSET @@ -575,7 +576,7 @@ void APRView::SaveSettings(void) // Save the current GUI color settings to the GUI colors file in the // path specified in defs.h - BString path(SETTINGS_DIR); + BString path(SERVER_SETTINGS_DIR); path+=COLOR_SETTINGS_NAME; #ifdef DEBUG_COLORSET printf("SaveSettings: %s\n",path.String()); @@ -599,15 +600,15 @@ printf("Loading settings from disk\n"); settings.MakeEmpty(); BDirectory dir,newdir; - if(dir.SetTo(SETTINGS_DIR)==B_ENTRY_NOT_FOUND) + if(dir.SetTo(SERVER_SETTINGS_DIR)==B_ENTRY_NOT_FOUND) { #ifdef DEBUG_COLORSET -printf("Color set folder not found. Creating %s\n",SETTINGS_DIR); +printf("Color set folder not found. Creating %s\n",SERVER_SETTINGS_DIR); #endif - create_directory(SETTINGS_DIR,0777); + create_directory(SERVER_SETTINGS_DIR,0777); } - BString path(SETTINGS_DIR); + BString path(SERVER_SETTINGS_DIR); path+=COLOR_SETTINGS_NAME; BFile file(path.String(),B_READ_ONLY); diff --git a/src/prefs/appearance/APRWindow.cpp b/src/prefs/appearance/APRWindow.cpp index d6dea4f9d9..70a1247ad3 100644 --- a/src/prefs/appearance/APRWindow.cpp +++ b/src/prefs/appearance/APRWindow.cpp @@ -2,6 +2,7 @@ #include "APRWindow.h" #include "APRView.h" #include "DecView.h" +#include "CurView.h" #include "defs.h" APRWindow::APRWindow(BRect frame) @@ -20,6 +21,10 @@ APRWindow::APRWindow(BRect frame) tab=new BTab(decorators); tabview->AddTab(decorators,tab); + cursors=new CurView(Bounds(),"Cursors",B_FOLLOW_ALL, B_WILL_DRAW); + tab=new BTab(cursors); + tabview->AddTab(cursors,tab); + AddChild(tabview); decorators->SetColors(colors->settings); } diff --git a/src/prefs/appearance/APRWindow.h b/src/prefs/appearance/APRWindow.h index 43fb5c6f86..209a4f1a7c 100644 --- a/src/prefs/appearance/APRWindow.h +++ b/src/prefs/appearance/APRWindow.h @@ -8,6 +8,7 @@ class APRView; class DecView; +class CurView; class APRWindow : public BWindow { @@ -19,6 +20,7 @@ public: BTabView *tabview; APRView *colors; DecView *decorators; + CurView *cursors; }; #endif diff --git a/src/prefs/appearance/CurView.cpp b/src/prefs/appearance/CurView.cpp new file mode 100644 index 0000000000..84f8e67fdd --- /dev/null +++ b/src/prefs/appearance/CurView.cpp @@ -0,0 +1,679 @@ +//------------------------------------------------------------------------------ +// 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: CurView.cpp +// Author: DarkWyrm +// Description: cursor handler for the app +// +//------------------------------------------------------------------------------ +#include +#include +#include +#include +#include +#include +#include +#include "CursorWhichItem.h" +#include "CurView.h" +#include +#include "defs.h" +#include "ServerConfig.h" +#include + +//#define DEBUG_CURSORSET + +#define SAVE_CURSORSET 'svcu' +#define DELETE_CURSORSET 'dlcu' +#define LOAD_CURSORSET 'ldcu' + +CurView::CurView(const BRect &frame, const char *name, int32 resize, int32 flags) + :BView(frame,name,resize,flags), settings(B_SIMPLE_DATA) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + BMenuBar *mb=new BMenuBar(BRect(0,0,Bounds().Width(),16),"menubar"); + + settings_menu=new BMenu("Settings"); + settings_menu->AddItem(new BMenuItem("Save Cursor Set",new BMessage(SAVE_CURSORSET),'S')); + settings_menu->AddSeparatorItem(); + settings_menu->AddItem(new BMenuItem("Delete Cursor Set",new BMessage(DELETE_CURSORSET))); + mb->AddItem(settings_menu); + + cursorset_menu=LoadCursorSets(); + if(cursorset_menu) + mb->AddItem(cursorset_menu); + else + { + // We should *never* be here, but just in case.... + cursorset_menu=new BMenu("Cursor Sets"); + mb->AddItem(cursorset_menu); + } + AddChild(mb); + + BRect wellrect(0,0,20,20); + wellrect.OffsetTo(10,25); + wellrect.right=wellrect.left+50; + cursorset_label=new BStringView(wellrect,"cursorset_label","Cursor Set: "); + AddChild(cursorset_label); + cursorset_name=""; + + + // Set up list of cursor attributes + BRect rect(10,60,200,160); + attrlist=new BListView(rect,"AttributeList"); + + 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)); + + attrlist->AddItem(new CursorWhichItem(B_CURSOR_DEFAULT)); + attrlist->AddItem(new CursorWhichItem(B_CURSOR_TEXT)); + attrlist->AddItem(new CursorWhichItem(B_CURSOR_MOVE)); + attrlist->AddItem(new CursorWhichItem(B_CURSOR_DRAG)); + attrlist->AddItem(new CursorWhichItem(B_CURSOR_RESIZE)); + attrlist->AddItem(new CursorWhichItem(B_CURSOR_RESIZE_NWSE)); + attrlist->AddItem(new CursorWhichItem(B_CURSOR_RESIZE_NESW)); + attrlist->AddItem(new CursorWhichItem(B_CURSOR_RESIZE_NS)); + attrlist->AddItem(new CursorWhichItem(B_CURSOR_RESIZE_EW)); + + BRect cvrect; + + cvrect.Set(0,0,50,25); + cvrect.OffsetBy(scrollview->Frame().right+20, + scrollview->Frame().bottom-cvrect.Height()); + + defaults=new BButton(cvrect,"DefaultsButton","Defaults", + new BMessage(DEFAULT_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP, + B_WILL_DRAW | B_NAVIGABLE); + AddChild(defaults); + + 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); + revert->SetEnabled(false); + + 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); + apply->SetEnabled(false); + + BEntry entry(COLOR_SET_DIR); + entry_ref ref; + entry.GetRef(&ref); + savepanel=new BFilePanel(B_SAVE_PANEL, NULL, + &ref, 0, false); + + attribute=B_PANEL_BACKGROUND_COLOR; + attrstring="Background"; + LoadSettings(); + +} + +CurView::~CurView(void) +{ + delete savepanel; +} + +void CurView::AllAttached(void) +{ + attrlist->Select(0); + attrlist->SetTarget(this); + apply->SetTarget(this); + defaults->SetTarget(this); + revert->SetTarget(this); + settings_menu->SetTargetForItems(this); + cursorset_menu->SetTargetForItems(this); + + BMessenger msgr(this); + savepanel->SetTarget(msgr); +} + +void CurView::MessageReceived(BMessage *msg) +{ + if(msg->WasDropped()) + { + } + + switch(msg->what) + { +/* case DELETE_CURSORSET: + { + // Construct the path and delete + BString path(COLOR_SET_DIR); + path+=cursorset_name; + + BString printstring("Remove "); + printstring+=cursorset_name; + 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) + { +#ifdef DEBUG_CURSORSET +printf("MSG: Delete Request - couldn't delete file %s\n",path.String()); +#endif + } + else + { + BMenuItem *item=cursorset_menu->FindItem(cursorset_name.String()); + if(item!=NULL) + { + if(cursorset_menu->RemoveItem(item)) + delete item; + } + } + } + break; + } + case LOAD_CURSORSET: + { + BString name; + if(msg->FindString("name",&name)!=B_OK) + { +#ifdef DEBUG_CURSORSET +printf("MSG: Load Request - couldn't find file name\n"); +#endif + break; + } + LoadCursorSet(name); + break; + } + case SAVE_CURSORSET: + { + savepanel->Show(); + break; + } + case B_SAVE_REQUESTED: + { + BString name; + if(msg->FindString("name",&name)!=B_OK) + { +#ifdef DEBUG_CURSORSET +printf("MSG: Save Request - couldn't find file name\n"); +#endif + break; + } + SaveCursorSet(name); + break; + } + case ATTRIBUTE_CHOSEN: + { + break; + } + case APPLY_SETTINGS: + { + SaveSettings(); + NotifyServer(); + break; + } + case TRY_SETTINGS: + { + // 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: + { + if(prev_set_name=="Default") + SetDefaults(); + + LoadCursorSet(prev_set_name); + break; + } + case DEFAULT_SETTINGS: + { + break; + } +*/ default: + BView::MessageReceived(msg); + break; + } +} + +BMenu *CurView::LoadCursorSets(void) +{ +#ifdef DEBUG_CURSORSET +printf("Loading cursor sets from disk\n"); +#endif + // This function populates the member menu *cursorset_menu with the cursor + // set files located in the cursor set directory. To ensure that there are + // no entries pointing to invalid cursor sets, they are validated before + // a menu item is added. + BDirectory dir; + BEntry entry; + BPath path; + BString name; + + BMenu *menu=new BMenu("Cursor 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 cursor sets. " + "You will be able to change system cursors, but be unable to save them to a cursor set. " + "Please contact OpenBeOS about Appearance Preferences::CurView::" + "LoadCursorSets::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: + { + printf("CurView::LoadCursorSets(): Invalid cursorset folder path.\n"); + break; + } + case B_NO_MEMORY: + { + printf("CurView::LoadCursorSets(): No memory left. We're probably going to crash now. \n"); + break; + } + case B_BUSY: + { + printf("CurView::LoadCursorSets(): Busy node " CURSOR_SET_DIR "\n"); + break; + } + case B_FILE_ERROR: + { + BAlert *a=new BAlert("OpenBeOS","Couldn't open the folder for cursor 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 cursors, but be unable to save them to a cursor 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 cursor 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;iAddString("name",name); + menu->AddItem(new BMenuItem(name.String(),msg)); + } + + return menu; +} + +void CurView::LoadCursorSet(const BString &name) +{ +/* + // Load the current GUI cursor settings from a cursor set file. + +#ifdef DEBUG_CURSORSET +printf("LoadCursorSet: %s\n",name.String()); +#endif + + BDirectory dir,newdir; + if(dir.SetTo(CURSOR_SET_DIR)==B_ENTRY_NOT_FOUND) + { +#ifdef DEBUG_CURSORSET +printf("Cursor set folder not found. Creating %s\n",COLOR_SET_DIR); +#endif + create_directory(COLOR_SET_DIR,0777); + } + + BString path(COLOR_SET_DIR); + path+=name.String(); + BFile file(path.String(),B_READ_ONLY); + + if(file.InitCheck()!=B_OK) + { +#ifdef DEBUG_CURSORSET +printf("Couldn't open file %s for read\n",path.String()); +#endif + return; + } + if(settings.Unflatten(&file)==B_OK) + { +#ifdef DEBUG_CURSORSET +settings.PrintToStream(); +#endif + BString internal_name; + settings.FindString("name",&internal_name); +// BString namestr("Cursor Set: "); +// namestr+=internal_name.String(); +// cursorset_label->SetText(namestr.String()); + SetCursorSetName(internal_name.String()); + return; + } +#ifdef DEBUG_CURSORSET +printf("Error unflattening file %s\n",name.String()); +#endif +*/ +} + +void CurView::SaveCursorSet(const BString &name) +{ +/* + // Save the current cursor attributes as a flattened BMessage in the + // cursor set folder + BString path(COLOR_SET_DIR); + path+=name.String(); + +#ifdef DEBUG_CURSORSET +printf("SaveCursorSet: %s\n",path.String()); +#endif + + if(settings.ReplaceString("name",name.String())!=B_OK) + { +#ifdef DEBUG_CURSORSET +printf("SaveCursorSet: Couldn't replace set name in settings\n"); +#endif + } + + BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE); + + if(file.InitCheck()!=B_OK) + { +#ifdef DEBUG_CURSORSET +printf("SaveCursorSet: Couldn't open settings file for write\n"); +#endif + } + + if(settings.Flatten(&file)!=B_OK) + { +#ifdef DEBUG_CURSORSET +printf("SaveCursorSet: Couldn't flatten settings to file\n"); +#endif + return; + } + + BMessage *msg=new BMessage(LOAD_CURSORSET); + msg->AddString("name",name.String()); + + if(cursorset_menu->AddItem(new BMenuItem(name.String(),msg))==false) + { +#ifdef DEBUG_CURSORSET +printf("SaveCursorSet: Error in adding item to menu\n"); +#endif + } + SetCursorSetName(name.String()); +*/ +} + +void CurView::SetCursorSetName(const char *name) +{ + if(!name) + return; + BString namestr("Cursor Set: "); + cursorset_name=name; + namestr+=name; + cursorset_label->SetText(namestr.String()); + cursorset_label->Invalidate(); +} + +void CurView::SaveSettings(void) +{ + // Save the current GUI cursor settings to the GUI cursors file in the + // path specified in defs.h + + BString path(SERVER_SETTINGS_DIR); + path+=CURSOR_SETTINGS_NAME; +#ifdef DEBUG_CURSORSET +printf("SaveSettings: %s\n",path.String()); +#endif + BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE); + + settings.Flatten(&file); + prev_set_name=cursorset_name; + revert->SetEnabled(false); + revert->SetEnabled(false); +} + +void CurView::LoadSettings(void) +{ +/* // Load the current GUI cursor settings from disk. This is done instead of + // getting them from the server at this point for testing purposes. Comment + // out the #define LOAD_SETTINGS_FROM_DISK line to use the server query code +#ifdef DEBUG_CURSORSET +printf("Loading settings from disk\n"); +#endif + settings.MakeEmpty(); + + BDirectory dir,newdir; + if(dir.SetTo(SERVER_SETTINGS_DIR)==B_ENTRY_NOT_FOUND) + { +#ifdef DEBUG_CURSORSET +printf("Cursor set folder not found. Creating %s\n",SERVER_SETTINGS_DIR); +#endif + 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) + { +#ifdef DEBUG_CURSORSET +printf("Couldn't open file %s for read\n",path.String()); +#endif + SetDefaults(); + SaveSettings(); + return; + } + if(settings.Unflatten(&file)==B_OK) + { + settings.FindString("name",&cursorset_name); + SetCursorSetName(cursorset_name.String()); + prev_set_name=cursorset_name; + picker->SetValue(GetCursorFromMessage(&settings,attrstring.String())); +#ifdef DEBUG_CURSORSET +settings.PrintToStream(); +#endif + return; + } +#ifdef DEBUG_CURSORSET +printf("Error unflattening SystemCursors file %s\n",path.String()); +#endif + + // If we get this far, we have encountered an error, so reset the settings + // to the defaults + SetDefaults(); + SaveSettings(); +*/ +} + +void CurView::SetDefaults(void) +{ +/* +#ifdef DEBUG_CURSORSET +printf("Initializing cursor settings to defaults\n"); +#endif + settings.MakeEmpty(); + settings.AddString("name","Default"); + cursorset_name="Default"; + + ColorWhichItem whichitem(B_PANEL_BACKGROUND_COLOR); + rgb_color col={216,216,216,255}; + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_PANEL_TEXT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,255,255,255); + whichitem.SetAttribute((color_which)B_DOCUMENT_BACKGROUND_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_DOCUMENT_TEXT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,245,245,245); + whichitem.SetAttribute((color_which)B_CONTROL_BACKGROUND_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_CONTROL_TEXT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_CONTROL_BORDER_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,115,120,184); + whichitem.SetAttribute((color_which)B_CONTROL_HIGHLIGHT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,170,50,184); + whichitem.SetAttribute((color_which)B_NAVIGATION_BASE_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_NAVIGATION_PULSE_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,255,255,255); + whichitem.SetAttribute((color_which)B_SHINE_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_SHADOW_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_MENU_SELECTED_BORDER_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,255,255,0); + whichitem.SetAttribute((color_which)B_TOOLTIP_BACKGROUND_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_TOOLTIP_TEXT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,255,0); + whichitem.SetAttribute((color_which)B_SUCCESS_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,255,0,0); + whichitem.SetAttribute((color_which)B_FAILURE_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,51,102,160); + whichitem.SetAttribute((color_which)B_MENU_SELECTED_BACKGROUND_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + whichitem.SetAttribute(B_PANEL_BACKGROUND_COLOR); + SetRGBColor(&col,216,216,216); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,216,216,216,0); + whichitem.SetAttribute(B_MENU_BACKGROUND_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute(B_MENU_ITEM_TEXT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,255,255,255); + whichitem.SetAttribute(B_MENU_SELECTED_ITEM_TEXT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,255,203,0); + whichitem.SetAttribute(B_WINDOW_TAB_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,0,0,0); + whichitem.SetAttribute((color_which)B_WINDOW_TAB_TEXT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,232,232,232); + whichitem.SetAttribute((color_which)B_INACTIVE_WINDOW_TAB_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + + SetRGBColor(&col,80,80,80); + whichitem.SetAttribute((color_which)B_INACTIVE_WINDOW_TAB_TEXT_COLOR); + settings.AddData(whichitem.Text(),(type_code)'RGBC',&col,sizeof(rgb_color)); + +// BString labelstr("Color Set: "); +// labelstr+=cursorset_name; +// cursorset_label->SetText(labelstr.String()); + SetCursorSetName("Default"); +*/ +} + +void CurView::NotifyServer(void) +{ +} + +rgb_color CurView::GetColorFromMessage(BMessage *msg, const char *name, int32 index=0) +{ +/* + // Simple function to do the dirty work of getting an rgb_color from + // a message + rgb_color *col,rcolor={0,0,0,0}; + ssize_t size; + + if(!msg || !name) + return rcolor; + + if(msg->FindData(name,(type_code)'RGBC',index,(const void**)&col,&size)==B_OK) + rcolor=*col; + return rcolor; +*/ +} diff --git a/src/prefs/appearance/CurView.h b/src/prefs/appearance/CurView.h new file mode 100644 index 0000000000..91bcdb440c --- /dev/null +++ b/src/prefs/appearance/CurView.h @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// 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: CurView.cpp +// Author: DarkWyrm +// Description: System cursor handler +// +//------------------------------------------------------------------------------ +#ifndef CUR_VIEW_H_ +#define CUR_VIEW_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class APRWindow; + +class CurView : public BView +{ +public: + CurView(const BRect &frame, const char *name, int32 resize, int32 flags); + ~CurView(void); + void AllAttached(void); + void MessageReceived(BMessage *msg); + void SaveSettings(void); + void LoadSettings(void); + void SetDefaults(void); + void NotifyServer(void); + rgb_color GetColorFromMessage(BMessage *msg, const char *name, int32 index=0); +protected: + friend APRWindow; + BMenu *LoadCursorSets(void); + void SaveCursorSet(const BString &name); + void LoadCursorSet(const BString &name); + void SetCursorSetName(const char *name); + + BButton *apply,*revert,*defaults; + BListView *attrlist; + color_which attribute; + BMessage settings; + BString attrstring; + BScrollView *scrollview; + BStringView *cursorset_label; + BMenu *cursorset_menu,*settings_menu; + BFilePanel *savepanel; + BString cursorset_name; + BString prev_set_name; +}; + +#endif diff --git a/src/prefs/appearance/CursorWhichItem.cpp b/src/prefs/appearance/CursorWhichItem.cpp new file mode 100644 index 0000000000..82984bf653 --- /dev/null +++ b/src/prefs/appearance/CursorWhichItem.cpp @@ -0,0 +1,99 @@ +#include "CursorWhichItem.h" +#include + +CursorWhichItem::CursorWhichItem(cursor_which which) + : BStringItem(NULL,0,false) +{ + SetAttribute(which); +} + +CursorWhichItem::~CursorWhichItem(void) +{ + // Empty, but exists for just-in-case +} + +void CursorWhichItem::SetAttribute(cursor_which which) +{ + switch(which) + { + // cases not existing in R5 which exist in OpenBeOS + case B_CURSOR_DEFAULT: + { + attribute=which; + SetText("Default"); + break; + } + case B_CURSOR_TEXT: + { + attribute=which; + SetText("Text"); + break; + } + case B_CURSOR_MOVE: + { + attribute=which; + SetText("Move"); + break; + } + case B_CURSOR_DRAG: + { + attribute=which; + SetText("Drag"); + break; + } + case B_CURSOR_RESIZE: + { + attribute=which; + SetText("Resize"); + break; + } + case B_CURSOR_RESIZE_NWSE: + { + attribute=which; + SetText("Diagonal Resize NW-SE"); + break; + } + case B_CURSOR_RESIZE_NESW: + { + attribute=which; + SetText("Diagonal Resize NE-SW"); + break; + } + case B_CURSOR_RESIZE_NS: + { + attribute=which; + SetText("Vertical Resize"); + break; + } + case B_CURSOR_RESIZE_EW: + { + attribute=which; + SetText("Horizontal Resize"); + break; + } + case B_CURSOR_OTHER: + { + attribute=which; + SetText("Other"); + break; + } + case B_CURSOR_INVALID: + { + break; + } + default: + { + printf("unknown code '%c%c%c%c'\n",(char)((which & 0xFF000000) >> 24), + (char)((which & 0x00FF0000) >> 16), + (char)((which & 0x0000FF00) >> 8), + (char)((which & 0x000000FF)) ); + break; + } + } +} + +cursor_which CursorWhichItem::GetAttribute(void) +{ + return attribute; +} + diff --git a/src/prefs/appearance/CursorWhichItem.h b/src/prefs/appearance/CursorWhichItem.h new file mode 100644 index 0000000000..f9bc7ba52c --- /dev/null +++ b/src/prefs/appearance/CursorWhichItem.h @@ -0,0 +1,20 @@ +#ifndef COLORWHICH_ITEM_H +#define COLORWHICH_ITEM_H + +#include +#include + +#include + +class CursorWhichItem : public BStringItem +{ +public: + CursorWhichItem(cursor_which which); + ~CursorWhichItem(void); + void SetAttribute(cursor_which which); + cursor_which GetAttribute(void); +private: + cursor_which attribute; +}; + +#endif \ No newline at end of file diff --git a/src/prefs/appearance/DecView.cpp b/src/prefs/appearance/DecView.cpp index 29eb18ffff..5ee3529012 100644 --- a/src/prefs/appearance/DecView.cpp +++ b/src/prefs/appearance/DecView.cpp @@ -38,6 +38,7 @@ #include #include #include +#include "ServerConfig.h" #include "RGBColor.h" #include "defs.h" #include "PreviewDriver.h" @@ -178,7 +179,7 @@ void DecView::SaveSettings(void) if(!item) return; - BString path(SETTINGS_DIR); + BString path(SERVER_SETTINGS_DIR); path+="DecoratorSettings"; printf("%s\n",path.String()); BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE); @@ -193,10 +194,10 @@ void DecView::LoadSettings(void) settings.MakeEmpty(); BDirectory dir,newdir; - if(dir.SetTo(SETTINGS_DIR)==B_ENTRY_NOT_FOUND) - create_directory(SETTINGS_DIR,0777); + if(dir.SetTo(SERVER_SETTINGS_DIR)==B_ENTRY_NOT_FOUND) + create_directory(SERVER_SETTINGS_DIR,0777); - BString path(SETTINGS_DIR); + BString path(SERVER_SETTINGS_DIR); path+="DecoratorSettings"; BFile file(path.String(),B_READ_ONLY); diff --git a/src/prefs/appearance/SysCursorAPI.cpp b/src/prefs/appearance/SysCursorAPI.cpp new file mode 100644 index 0000000000..89afbec859 --- /dev/null +++ b/src/prefs/appearance/SysCursorAPI.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include "SysCursorAPI.h" + +// TODO: tweak the BBitmap and BCursor headers + +void set_syscursor(cursor_which which, const BCursor *cursor) +{ +/* port_id server=find_port(SERVER_PORT_NAME); + if(fServerFrom!=B_NAME_NOT_FOUND) + { + PortLink link(server); + link.SetOpCode(AS_SET_SYSCURSOR_BCURSOR); + link.Attach(which); + link.Attach(cursor->m_serverToken); + link.Flush(); + } +*/ +} + +void set_syscursor(cursor_which which, const BBitmap *bitmap) +{ +/* port_id server=find_port(SERVER_PORT_NAME); + if(fServerFrom!=B_NAME_NOT_FOUND) + { + PortLink link(server); + link.SetOpCode(AS_SET_SYSCURSOR_BBITMAP); + link.Attach(which); + link.Attach(cursor->fToken); + link.Flush(); + } +*/ +} + +cursor_which get_syscursor(void) +{ + port_id server=find_port(SERVER_PORT_NAME); + if(server!=B_NAME_NOT_FOUND) + { + PortMessage pmsg; + + PortLink link(server); + link.SetOpCode(AS_GET_SYSCURSOR); + link.FlushWithReply(&pmsg); + + cursor_which which; + pmsg.Read(&which); + return which; + } + return B_CURSOR_INVALID; +} + +void setcursor(cursor_which which) +{ + port_id server=find_port(SERVER_PORT_NAME); + if(server!=B_NAME_NOT_FOUND) + { + PortLink link(server); + link.SetOpCode(AS_SET_CURSOR_SYSTEM); + link.Flush(); + } +} diff --git a/src/prefs/appearance/SysCursorAPI.h b/src/prefs/appearance/SysCursorAPI.h new file mode 100644 index 0000000000..7c69decc2a --- /dev/null +++ b/src/prefs/appearance/SysCursorAPI.h @@ -0,0 +1,15 @@ +#ifndef SYSCURSOR_API_H_ +#define SYSCURSOR_API_H_ + +#include +#include +#include + +void set_syscursor(cursor_which which, const BCursor *cursor); +void set_syscursor(cursor_which which, const BBitmap *bitmap); + +cursor_which get_syscursor(void); + +void setcursor(cursor_which which); + +#endif diff --git a/src/prefs/appearance/defs.h b/src/prefs/appearance/defs.h index 559903e107..e1ad19ccb1 100644 --- a/src/prefs/appearance/defs.h +++ b/src/prefs/appearance/defs.h @@ -2,10 +2,13 @@ #define DEFS_H_ // If these paths are changed, ensure that they all end in a '/' character +/* #define SETTINGS_DIR "/boot/home/config/settings/app_server/" #define COLOR_SET_DIR "/boot/home/config/settings/color_sets/" +#define CURSOR_SET_DIR "/boot/home/config/settings/cursor_sets/" #define DECORATORS_DIR "/boot/home/config/add-ons/decorators/" #define COLOR_SETTINGS_NAME "system_colors" +*/ #define APPLY_SETTINGS 'aply' #define REVERT_SETTINGS 'rvrt'