From 4399fd6025580cec46444f51bf45d898e1829c19 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Wed, 15 Jun 2005 19:04:52 +0000 Subject: [PATCH] Serious cleanup of the app git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13160 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/appearance/APRMain.cpp | 30 +- src/prefs/appearance/APRMain.h | 10 +- src/prefs/appearance/APRView.cpp | 577 ++++--------------------- src/prefs/appearance/APRView.h | 49 ++- src/prefs/appearance/APRWindow.cpp | 97 +---- src/prefs/appearance/APRWindow.h | 15 +- src/prefs/appearance/DecView.cpp | 505 +++++----------------- src/prefs/appearance/DecView.h | 43 +- src/prefs/appearance/Jamfile | 19 +- src/prefs/appearance/PreviewDriver.cpp | 240 ---------- src/prefs/appearance/PreviewDriver.h | 313 -------------- 11 files changed, 261 insertions(+), 1637 deletions(-) delete mode 100644 src/prefs/appearance/PreviewDriver.cpp delete mode 100644 src/prefs/appearance/PreviewDriver.h diff --git a/src/prefs/appearance/APRMain.cpp b/src/prefs/appearance/APRMain.cpp index f9874efbba..1372ea4d42 100644 --- a/src/prefs/appearance/APRMain.cpp +++ b/src/prefs/appearance/APRMain.cpp @@ -26,40 +26,20 @@ // //------------------------------------------------------------------------------ #include "APRMain.h" +#include "APRWindow.h" #include #include "defs.h" -#include "FontServer.h" -#include "ServerConfig.h" -APRApplication::APRApplication() - :BApplication(APPEARANCE_APP_SIGNATURE) +APRApplication::APRApplication(void) + : BApplication(APPEARANCE_APP_SIGNATURE) { - fontserver=new FontServer(); - fontserver->ScanDirectory("/boot/beos/etc/fonts/ttfonts/"); - fontserver->ScanDirectory("/boot/beos/etc/fonts/PS-Type1/"); - if(!fontserver->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY,DEFAULT_PLAIN_FONT_STYLE,DEFAULT_PLAIN_FONT_SIZE)) - printf("Couldn't set plain to %s, %s %d pt\n",DEFAULT_PLAIN_FONT_FAMILY, - DEFAULT_PLAIN_FONT_STYLE,DEFAULT_PLAIN_FONT_SIZE); - if(!fontserver->SetSystemBold(DEFAULT_BOLD_FONT_FAMILY,DEFAULT_BOLD_FONT_STYLE,DEFAULT_BOLD_FONT_SIZE)) - printf("Couldn't set bold to %s, %s %d pt\n",DEFAULT_BOLD_FONT_FAMILY, - DEFAULT_BOLD_FONT_STYLE,DEFAULT_BOLD_FONT_SIZE); - if(!fontserver->SetSystemFixed(DEFAULT_FIXED_FONT_FAMILY,DEFAULT_FIXED_FONT_STYLE,DEFAULT_FIXED_FONT_SIZE)) - printf("Couldn't set fixed to %s, %s %d pt\n",DEFAULT_FIXED_FONT_FAMILY, - DEFAULT_FIXED_FONT_STYLE,DEFAULT_FIXED_FONT_SIZE); - - BRect rect; - - // This is just the size and location of the window when Show() is called - rect.Set(100,100,540,410); - aprwin=new APRWindow(rect); - aprwin->Show(); + fWindow=new APRWindow( BRect(100,100,540,410) ); + fWindow->Show(); } int main(int, char**) { APRApplication myApplication; - - // This function doesn't return until the application quits myApplication.Run(); return(0); diff --git a/src/prefs/appearance/APRMain.h b/src/prefs/appearance/APRMain.h index 004dbbeab0..9a268b53b4 100644 --- a/src/prefs/appearance/APRMain.h +++ b/src/prefs/appearance/APRMain.h @@ -29,13 +29,17 @@ #define APR_WORLD_H #include -#include "APRWindow.h" + +class APRWindow; class APRApplication : public BApplication { public: - APRApplication(); - APRWindow *aprwin; + APRApplication(void); + +private: + + APRWindow *fWindow; }; #endif diff --git a/src/prefs/appearance/APRView.cpp b/src/prefs/appearance/APRView.cpp index ef60dc3089..3f44fec469 100644 --- a/src/prefs/appearance/APRView.cpp +++ b/src/prefs/appearance/APRView.cpp @@ -34,18 +34,19 @@ #include #include #include -#include // for settings Desktop color #include -#include "APRView.h" #include -#include +#include +#include + +#include "APRView.h" #include "defs.h" #include "ColorWell.h" #include -#include -#include #include "ColorWhichItem.h" +#include "ColorSet.h" + #include "ServerConfig.h" //#define DEBUG_COLORSET @@ -56,43 +57,22 @@ #define STRACE(A) /* nothing */ #endif -//#define SAVE_COLORSET 'svcs' -//#define DELETE_COLORSET 'dlcs' -//#define LOAD_COLORSET 'ldcs' #define COLOR_DROPPED 'cldp' +// Declarations for private functions in InterfaceDefs.cpp +namespace BPrivate +{ + void get_system_colors(ColorSet *colors); + void set_system_colors(const ColorSet &colors); +} + APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags) :BView(frame,name,resize,flags) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - 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); -*/ - // Set up list of color attributes - BRect rect(10,10,200,175); + BRect rect(10,10,200,150); attrlist=new BListView(rect,"AttributeList"); scrollview=new BScrollView("ScrollView",attrlist, B_FOLLOW_LEFT | @@ -130,41 +110,54 @@ APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags BRect wellrect(0,0,50,50); - wellrect.OffsetTo(rect.right + 42,25); + wellrect.OffsetTo( rect.right + 42, rect.top + + (scrollview->Bounds().Height() - wellrect.Height())/2 ); colorwell=new ColorWell(wellrect,new BMessage(COLOR_DROPPED),true); AddChild(colorwell); - + + // Center the list and color well + + rect = scrollview->Frame(); + rect.right = wellrect.right; + rect.OffsetTo( (Bounds().Width()-rect.Width())/2,rect.top); + + scrollview->MoveTo(rect.left, rect.top); + colorwell->MoveTo(rect.right - colorwell->Bounds().Width(), colorwell->Frame().top); + picker=new BColorControl(BPoint(10,scrollview->Frame().bottom+20),B_CELLS_32x8,5.0,"Picker", new BMessage(UPDATE_COLOR)); AddChild(picker); + picker->MoveTo( (Bounds().Width() - picker->Frame().Width())/2, + scrollview->Frame().bottom + 20 ); + BRect cvrect; 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); + // 40 is a 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); defaults=new BButton(cvrect,"DefaultsButton","Defaults", - new BMessage(DEFAULT_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP, - B_WILL_DRAW | B_NAVIGABLE); + new BMessage(DEFAULT_SETTINGS), + B_FOLLOW_LEFT |B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); AddChild(defaults); - defaults->SetEnabled(false); 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); + 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); + 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); @@ -174,18 +167,14 @@ APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags attribute=B_PANEL_BACKGROUND_COLOR; attrstring="Panel Background"; + LoadSettings(); + + // Save values for when we need to revert + prevset=currentset; } -APRView::~APRView(void) -{ - if(currentset) - delete currentset; - if(prevset) - delete prevset; -} - -void APRView::AllAttached(void) +void APRView::AttachedToWindow(void) { picker->SetTarget(this); attrlist->Select(0); @@ -195,8 +184,7 @@ void APRView::AllAttached(void) revert->SetTarget(this); colorwell->SetTarget(this); - BMessenger msgr(this); - picker->SetValue(currentset->StringToColor(attrstring.String()).GetColor32()); + picker->SetValue(currentset.StringToColor(attrstring.String())); } void APRView::MessageReceived(BMessage *msg) @@ -215,91 +203,9 @@ void APRView::MessageReceived(BMessage *msg) switch(msg->what) { -/* - // More code being saved for a color set app - - case DELETE_COLORSET: - { - // We can't delete the Default set - if(currentset->name.Compare("Default")==0) - break; - - // Construct the path and delete - BString path(COLOR_SET_DIR); - path+=currentset->name; - - BString printstring("Remove "); - printstring+=currentset->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) - { - STRACE(("MSG: Delete Request - couldn't delete file %s\n",path.String())); - } - else - { - BMenuItem *item=colorset_menu->FindItem(currentset->name.String()); - if(item!=NULL) - { - if(colorset_menu->RemoveItem(item)) - delete item; - } - } - } - break; - } - case LOAD_COLORSET: - { - BString name; - if(msg->FindString("name",&name)!=B_OK) - { - STRACE(("MSG: Load Request - couldn't find file name\n")); - break; - } - LoadColorSet(name); - break; - } - case SAVE_COLORSET: - { - // 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) - { - STRACE(("MSG: Save Request - couldn't find file name\n")); - break; - } - 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: { // Received from the color picker when its color changes - if(!prevset) - { - prevset=new ColorSet; - *prevset=*currentset; - } rgb_color col=picker->ValueAsColor(); @@ -307,92 +213,60 @@ void APRView::MessageReceived(BMessage *msg) colorwell->Invalidate(); // Update current attribute in the settings - if(currentset->SetColor(attrstring.String(),col)!=B_OK) - { - STRACE(("Couldn't set color for attribute %s\n",attrstring.String())); - } + currentset.SetColor(attrstring.String(),col); - if(!apply->IsEnabled()) - apply->SetEnabled(true); - if(!defaults->IsEnabled()) - defaults->SetEnabled(true); - if(!revert->IsEnabled()) - revert->SetEnabled(true); + apply->SetEnabled(true); + revert->SetEnabled(true); - Window()->PostMessage(SET_UI_COLORS); break; } case ATTRIBUTE_CHOSEN: { // Received when the user chooses a GUI attribute from the list - ColorWhichItem *whichitem=(ColorWhichItem*)attrlist->ItemAt(attrlist->CurrentSelection()); + + ColorWhichItem *whichitem = (ColorWhichItem*)attrlist->ItemAt( attrlist->CurrentSelection() ); + if(!whichitem) break; + attrstring=whichitem->Text(); UpdateControlsFromAttr(whichitem->Text()); break; } case APPLY_SETTINGS: { - if(prevset) - { - delete prevset; - prevset=NULL; - revert->SetEnabled(false); - } - if(currentset->name=="Default") - defaults->SetEnabled(false); apply->SetEnabled(false); - 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(); + BPrivate::set_system_colors(currentset); + + BString path(SERVER_SETTINGS_DIR); + path += COLOR_SETTINGS_NAME; + + SaveColorSet( path.String(), currentset); break; } case REVERT_SETTINGS: { - delete currentset; currentset=prevset; - prevset=NULL; - - rgb_color col=picker->ValueAsColor(); - - colorwell->SetColor(col); - colorwell->Invalidate(); - - // Update current attribute in the settings - currentset->SetColor(attrstring.String(),col); + UpdateControlsFromAttr(attrstring.String()); + // Save settings on disk if 'Apply' has been used if(!apply->IsEnabled()) - apply->SetEnabled(false); - if((currentset->name!="Default")) - defaults->SetEnabled(true); - else - defaults->SetEnabled(false); + { + BString path(SERVER_SETTINGS_DIR); + path += COLOR_SETTINGS_NAME; + SaveColorSet( path.String(), currentset); + } + apply->SetEnabled(false); revert->SetEnabled(false); - Window()->PostMessage(SET_UI_COLORS); break; } case DEFAULT_SETTINGS: { - if(!prevset) - { - prevset=new ColorSet; - *prevset=*currentset; - revert->SetEnabled(true); - apply->SetEnabled(true); - } - SetDefaults(); + currentset.SetToDefaults(); + apply->SetEnabled(true); + UpdateControlsFromAttr(attrstring.String()); - if(Window()) - Window()->PostMessage(SET_UI_COLORS); break; } default: @@ -401,317 +275,18 @@ void APRView::MessageReceived(BMessage *msg) } } -/* - -// This section is commented out because Appearance doesn't manage color sets. That -// task is better left to another application. - -BMenu *APRView::LoadColorSets(void) -{ - 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: - { - STRACE(("APRView::LoadColorSets(): Invalid colorset folder path.\n")); - break; - } - case B_NO_MEMORY: - { - STRACE(("APRView::LoadColorSets(): No memory left. We're probably going to crash now. \n")); - break; - } - case B_BUSY: - { - 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;iAddString("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. - - STRACE(("LoadColorSet: %s\n",name.String())); - - BDirectory dir,newdir; - if(dir.SetTo(COLOR_SET_DIR)==B_ENTRY_NOT_FOUND) - { - STRACE(("Color set folder not found. Creating %s\n",COLOR_SET_DIR)); - 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) - { - STRACE(("Couldn't open file %s for read\n",path.String())); - return; - } - BMessage settings; - - if(settings.Unflatten(&file)!=B_OK) - { - STRACE(("Error unflattening file %s\n",name.String())); - return; - } - currentset->ConvertFromMessage(&settings); -// SetColorSetName(currentset->name.String()); - - 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(); - - - STRACE(("SaveColorSet: %s\n",path.String())); - - - BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE); - - if(file.InitCheck()!=B_OK) - { - STRACE(("SaveColorSet: Couldn't open settings file for write\n")); - return; - } - - BMessage settings; - currentset->name=name; - currentset->ConvertToMessage(&settings); - - if(settings.Flatten(&file)!=B_OK) - { - 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) - { - STRACE(("SaveColorSet: Error in adding item to menu\n")); - } - SetColorSetName(name.String()); - - // 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: "); - currentset->name.SetTo(name); - namestr+=name; - colorwell_label->SetText(namestr.String()); - colorwell_label->ResizeToPreferred(); - colorwell_label->Invalidate(); -} -*/ -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; - - STRACE(("SaveSettings: %s\n",path.String())); - - BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE); - - BMessage settings; - - currentset->ConvertToMessage(&settings); - settings.Flatten(&file); -} - void APRView::LoadSettings(void) { // Load the current GUI color settings from disk. This is done instead of // getting them from the server at this point for testing purposes. - -#ifndef RUN_WITHOUT_APP_SERVER + // Query the server for the current settings - port_id port=find_port(SERVER_PORT_NAME); - if(port!=B_NAME_NOT_FOUND) - { - STRACE(("Retrieving settings from app_server\n")); - BPrivate::PortLink link(port); - int32 code; + //BPrivate::get_system_colors(¤tset); + + // TODO: remove this and enable the get_system_colors() call + LoadColorSet("/boot/home/config/settings/app_server/system_colors",¤tset); - link.StartMessage(AS_GET_UI_COLORS); - link.Flush(); - link.GetNextMessage(code); - link.Read(currentset); - } - else - { -#endif - STRACE(("Loading settings from disk\n")); - - 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 - } - -// SetColorSetName(currentset->name.String()); -#endif - UpdateControlsFromAttr(attrstring.String()); - - if(currentset->name.Compare("Default")!=0) - defaults->SetEnabled(true); -} - -void APRView::SetDefaults(void) -{ - STRACE(("Initializing color settings to defaults\n")); - defaults->SetEnabled(false); - currentset->name.SetTo("Default"); - - currentset->SetToDefaults(); -} - -void APRView::NotifyServer(void) -{ -#ifndef RUN_WITHOUT_APP_SERVER - // Send a message to the app_server with the settings which we have. - - port_id port=find_port(SERVER_PORT_NAME); - - if(port!=B_NAME_NOT_FOUND) - { - STRACE(("Notifying app_server\n")); - BPrivate::PortLink link(port); - - link.StartMessage(AS_SET_UI_COLORS); - link.Attach(*currentset); - link.Flush(); - } - - // 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 } void APRView::UpdateControlsFromAttr(const char *string) @@ -720,7 +295,7 @@ void APRView::UpdateControlsFromAttr(const char *string) return; STRACE(("Update color for %s\n",string)); - picker->SetValue(currentset->StringToColor(string).GetColor32()); + picker->SetValue(currentset.StringToColor(string)); colorwell->SetColor(picker->ValueAsColor()); colorwell->Invalidate(); } diff --git a/src/prefs/appearance/APRView.h b/src/prefs/appearance/APRView.h index d6db193799..98c764dc5e 100644 --- a/src/prefs/appearance/APRView.h +++ b/src/prefs/appearance/APRView.h @@ -41,36 +41,43 @@ #include #include #include -#include +#include "ColorSet.h" + class ColorWell; class APRWindow; class APRView : public BView { public: - APRView(const BRect &frame, const char *name, int32 resize, int32 flags); - ~APRView(void); - void AllAttached(void); - void MessageReceived(BMessage *msg); - void SaveSettings(void); - void LoadSettings(void); - void SetDefaults(void); - void NotifyServer(void); + APRView(const BRect &frame, const char *name, int32 resize, + int32 flags); + void AttachedToWindow(void); + void MessageReceived(BMessage *msg); + + void LoadSettings(void); protected: - friend APRWindow; - void UpdateControlsFromAttr(const char *string); -// BMenu *LoadColorSets(void); - void LoadColorSet(const BString &name); - BColorControl *picker; - BButton *apply,*revert,*defaults; - BListView *attrlist; - color_which attribute; - BString attrstring; - BScrollView *scrollview; - ColorWell *colorwell; + + void UpdateControlsFromAttr(const char *string); - ColorSet *currentset,*prevset; + BColorControl *picker; + + BButton *apply; + BButton *revert; + BButton *defaults; + + BListView *attrlist; + + color_which attribute; + + BString attrstring; + + BScrollView *scrollview; + + ColorWell *colorwell; + + ColorSet currentset; + ColorSet prevset; }; #endif diff --git a/src/prefs/appearance/APRWindow.cpp b/src/prefs/appearance/APRWindow.cpp index a532eb9ec3..f2e0fcc5f9 100644 --- a/src/prefs/appearance/APRWindow.cpp +++ b/src/prefs/appearance/APRWindow.cpp @@ -32,67 +32,24 @@ #include "CurView.h" #include "MenuView.h" #include "defs.h" -#include -#include +#include APRWindow::APRWindow(BRect frame) : BWindow(frame, "Appearance", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES ) { - BView *topview=new BView(Bounds(),"topview",B_FOLLOW_ALL,B_WILL_DRAW); - topview->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - AddChild(topview); + BTabView *tabview = new BTabView(Bounds(),"tabview"); - BRect r(10,10,110,Bounds().Height()-10); - - listview=new BListView(r,"prefslist"); - topview->AddChild(listview); - listview->SetSelectionMessage(new BMessage(PREFS_CHOSEN)); + BRect r(Bounds()); + r.bottom -= 20; - - r.Set(100,100,385,445); - r.OffsetTo(listview->Bounds().Width()+20,0); - r.right=Bounds().right; + DecView *decview=new DecView(r,"Decorators",B_FOLLOW_ALL, B_WILL_DRAW); + tabview->AddTab(decview); - listview->AddItem(new BStringItem("Colors")); - colors=new APRView(r,"Colors",B_FOLLOW_ALL, B_WILL_DRAW); - topview->AddChild(colors); - viewlist.AddItem(colors); - colors->Hide(); + APRView *colorview=new APRView(r,"Colors",B_FOLLOW_ALL, B_WILL_DRAW); + tabview->AddTab(colorview); - // TODO: Finish CurView -/* listview->AddItem(new BStringItem("Cursors")); - cursors=new CurView(r,"Cursors",B_FOLLOW_ALL, B_WILL_DRAW); - topview->AddChild(cursors); - viewlist.AddItem(cursors); - cursors->Hide(); -*/ - - listview->AddItem(new BStringItem("Decorators")); - decorators=new DecView(r,"Decorator",B_FOLLOW_ALL, B_WILL_DRAW); - topview->AddChild(decorators); - decorators->Hide(); - viewlist.AddItem(decorators); - decorators->SetColors(*colors->currentset); - - // This code works properly IIRC, but will remain disabled for now. - - // One of the cool things about Appearance is that eventually we will probably - // integrate all appearance-related preference panels into this to reduce the number - // of preference applications and to make the entire preferences area more organized. - // This is the route that Zeta took with theirs, but ours will not be a hack -- it will - // be done right. B^> - - // This won't amount to much -- we won't bother with the scrollbar prefs app and just - // set sensible defaults. It should just be menu and fonts, so not much work, either. - -// listview->AddItem(new BStringItem("Menu")); -// MenuView *menuview=new MenuView(r,"Menu",B_FOLLOW_ALL, B_WILL_DRAW); -// topview->AddChild(menuview); -// viewlist.AddItem(menuview); -// menuview->Hide(); - - listview->Select(1); + AddChild(tabview); } bool APRWindow::QuitRequested() @@ -100,39 +57,3 @@ bool APRWindow::QuitRequested() be_app->PostMessage(B_QUIT_REQUESTED); return(true); } - -void APRWindow::MessageReceived(BMessage *msg) -{ - switch(msg->what) - { - case SET_UI_COLORS: - { - decorators->SetColors(*colors->currentset); - break; - } - case PREFS_CHOSEN: - { - int32 selectionindex=listview->CurrentSelection(); - if(selectionindex==-1) - break; - - // Hide any visible preference views - for(int32 i=0; iCountItems(); i++) - { - BView *v=(BView*)viewlist.ItemAt(i); - - if(!v) - continue; - - if(!v->IsHidden()) - v->Hide(); - } - BView *visible=(BView*)viewlist.ItemAt(selectionindex); - visible->Show(); - break; - } - default: - BWindow::MessageReceived(msg); - break; - } -} diff --git a/src/prefs/appearance/APRWindow.h b/src/prefs/appearance/APRWindow.h index fc62fdde0b..23e23cc022 100644 --- a/src/prefs/appearance/APRWindow.h +++ b/src/prefs/appearance/APRWindow.h @@ -31,23 +31,12 @@ #include #include #include -#include - -class APRView; -class DecView; -class CurView; class APRWindow : public BWindow { public: - APRWindow(BRect frame); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *msg); - BListView *listview; - APRView *colors; - DecView *decorators; - CurView *cursors; - BList viewlist; + APRWindow(BRect frame); + bool QuitRequested(void); }; #endif diff --git a/src/prefs/appearance/DecView.cpp b/src/prefs/appearance/DecView.cpp index cd1e2a18e2..e6ac64c882 100644 --- a/src/prefs/appearance/DecView.cpp +++ b/src/prefs/appearance/DecView.cpp @@ -28,21 +28,17 @@ // settings directory. //------------------------------------------------------------------------------ #include -#include -#include -#include -#include -#include "DecView.h" -#include -#include -#include +#include #include +#include +#include #include +#include +#include + #include "ServerConfig.h" -#include "RGBColor.h" +#include "DecView.h" #include "defs.h" -#include "PreviewDriver.h" -#include "Decorator.h" //#define DEBUG_DECORATOR @@ -52,98 +48,89 @@ #define STRACE(a) /* nothing */ #endif +namespace BPrivate +{ + int32 count_decorators(void); + status_t set_decorator(const int32 &index); + int32 get_decorator(void); + status_t get_decorator_name(const int32 &index, BString &name); + status_t get_decorator_preview(const int32 &index, BBitmap *bitmap); +} + +class DecoratorItem : public BStringItem +{ +public: + DecoratorItem(const char *text, const int32 &index); + int32 GetIndex(void) const { return fIndex; } + +private: + int32 fIndex; + +}; + +DecoratorItem::DecoratorItem(const char *text, const int32 &index) + : BStringItem(text), + fIndex(index) +{ +} DecView::DecView(BRect frame, const char *name, int32 resize, int32 flags) :BView(frame,name,resize,flags) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - BRect cvrect(0,0,50,25); - - cvrect.OffsetTo(Bounds().right-60,10); - - apply=new BButton(cvrect,"ApplyButton","Apply", - new BMessage(APPLY_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP, - B_WILL_DRAW | B_NAVIGABLE); + BRect r; + + r.left = r.top = 10; + + r.right = Bounds().Width()/2 - 10; + r.bottom = Bounds().bottom * .75; + + + // TODO: This will eventually be just a BView which draws a BBitmap, but for now + // we will use a placeholder + preview = new BView(r, "preview", B_FOLLOW_NONE, B_WILL_DRAW); + preview->SetViewColor(100,140,255); + AddChild(preview); + + r.left = r.right + 20; + r.right = Bounds().right - 10 - B_V_SCROLL_BAR_WIDTH; + + + declist = new BListView(r, "listview"); + declist->SetSelectionMessage( new BMessage(DECORATOR_CHOSEN) ); + + BScrollView *scrollView = new BScrollView("scrollview", declist, B_FOLLOW_NONE, + 0,false,true); + AddChild(scrollView); + + apply = new BButton( BRect(0,0,1,1), "apply", "Apply", new BMessage(APPLY_SETTINGS), + B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + apply->ResizeToPreferred(); + apply->MoveTo( Bounds().Width() - 10 - apply->Bounds().Width(), + Bounds().Height() - 10 - apply->Bounds().Height() ); AddChild(apply); - - // set up app_server emulation - driver=new PreviewDriver(); - if(!driver->Initialize()) + + // Now that we have all the controls in place, populate the list + int32 decCount = BPrivate::count_decorators(); + + for(int32 i=0; iView(); - AddChild(preview); - - BRect temp(driver->View()->Bounds()); + BString string; - preview->MoveTo(apply->Frame().left-temp.Width()-20,apply->Frame().top); - } - - // Set up list of color attributes - float top=preview->Frame().bottom+15; - - cvrect.Set(10,top,Bounds().right-10-B_V_SCROLL_BAR_WIDTH, top+125); - declist=new BListView(cvrect,"DecoratorList"); - - scrollview=new BScrollView("ScrollView",declist, B_FOLLOW_LEFT | - B_FOLLOW_TOP, 0, false, true); - AddChild(scrollview); - scrollview->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - declist->SetSelectionMessage(new BMessage(DECORATOR_CHOSEN)); - - - // Finish setup - ldata.SetHighColor(RGBColor(51,102,160)); - pat_solid_high=0xFFFFFFFFFFFFFFFFLL; - driver->FillRect(preview_bounds,&ldata); - - decorator=NULL; - decorator_id=-1; - GetDecorators(); - LoadSettings(); - - BString path(ConvertIndexToPath(0L)); - - if(LoadDecorator(path.String())) - { - driver->FillRect(preview_bounds,&ldata); - if(decorator) - { - BStringItem *item=(BStringItem*)declist->ItemAt(declist->CurrentSelection()); - path=(item)?item->Text():path="Title"; - decorator->SetDriver(driver); - decorator->SetTitle(path.String()); - decorator->SetColors(colorset); - } + if( BPrivate::get_decorator_name( i, string ) == B_OK ) + declist->AddItem( new DecoratorItem( string.String(), i ) ); } } -DecView::~DecView(void) -{ - driver->Shutdown(); - delete driver; - if(decorator!=NULL) - delete decorator; -} - -void DecView::AllAttached(void) +void DecView::AttachedToWindow(void) { declist->SetTarget(this); apply->SetTarget(this); - LoadSettings(); - - BRegion clip; - if(decorator) - { - decorator->GetFootprint(&clip); - driver->View()->ConstrainClippingRegion(&clip); - decorator->Draw(); - } + + int32 currentDec = BPrivate::get_decorator(); + if(currentDec>=0) + declist->Select(currentDec); } void DecView::MessageReceived(BMessage *msg) @@ -153,44 +140,20 @@ void DecView::MessageReceived(BMessage *msg) case APPLY_SETTINGS: { SaveSettings(); - NotifyServer(); + + int32 selection = declist->CurrentSelection(); + if(selection >=0 ) + BPrivate::set_decorator(selection); + break; } + case DECORATOR_CHOSEN: { - - STRACE(("MSG: Decorator Chosen - #%ld\n",declist->CurrentSelection())); - bool success=false; - - BString path( ConvertIndexToPath(declist->CurrentSelection()) ); - - STRACE(("MSG: Decorator path: %s\n",path.String())); - - success=LoadDecorator(path.String()); - - if(!success) - { - STRACE(("MSG: Decorator NOT Chosen - couldn't load decorator\n")); - break; - } - - driver->FillRect(preview_bounds,&ldata); - if(decorator) - { - BStringItem *item=(BStringItem*)declist->ItemAt(declist->CurrentSelection()); - path=(item)?item->Text():path="Title"; - decorator->SetDriver(driver); - decorator->SetFocus(true); - decorator->SetTitle(path.String()); - decorator->SetColors(colorset); - - BRegion clip; - decorator->GetFootprint(&clip); - driver->View()->ConstrainClippingRegion(&clip); - decorator->Draw(); - } + // TODO: update the preview here break; } + default: BView::MessageReceived(msg); break; @@ -199,303 +162,59 @@ void DecView::MessageReceived(BMessage *msg) void DecView::SaveSettings(void) { - BStringItem *item=(BStringItem*)declist->ItemAt(declist->CurrentSelection()); + BStringItem *item=(DecoratorItem*)declist->ItemAt(declist->CurrentSelection()); if(!item) return; BString path(SERVER_SETTINGS_DIR); - path+="DecoratorSettings"; + path+="decorator_settings"; STRACE(("%s\n",path.String())); BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE); - settings.MakeEmpty(); + BMessage settings; settings.AddString("decorator",item->Text()); settings.Flatten(&file); } void DecView::LoadSettings(void) { - settings.MakeEmpty(); + BMessage settings; BDirectory dir,newdir; if(dir.SetTo(SERVER_SETTINGS_DIR)==B_ENTRY_NOT_FOUND) create_directory(SERVER_SETTINGS_DIR,0777); BString path(SERVER_SETTINGS_DIR); - path+="DecoratorSettings"; + path+="decorator_settings"; BFile file(path.String(),B_READ_ONLY); - if(file.InitCheck()==B_OK) + if(file.InitCheck()!=B_OK) { - if(settings.Unflatten(&file)==B_OK) + STRACE(("Error opening settings file %s\n",path.String())); + return; + } + + if(settings.Unflatten(&file)!=B_OK) + { + STRACE(("Error unflattening settings file %s\n",path.String())); + return; + } + + BString itemtext; + if(settings.FindString("decorator",&itemtext)!=B_OK) + { + STRACE(("Couldn't find decorator name in settings file %s\n",path.String())); + return; + } + + for(int32 i=0;iCountItems();i++) + { + BStringItem *item=(BStringItem*)declist->ItemAt(i); + if(item && itemtext.Compare(item->Text())==0) { - BString itemtext; - if(settings.FindString("decorator",&itemtext)==B_OK) - { - for(int32 i=0;iCountItems();i++) - { - BStringItem *item=(BStringItem*)declist->ItemAt(i); - if(item && itemtext.Compare(item->Text())==0) - { - declist->Select(i); - return; - } - } - } - - // We got this far, so something must have gone wrong. Select the first item - declist->Select(0L); - + declist->Select(i); return; } - STRACE(("Error unflattening settings file %s\n",path.String())); } -} - -void DecView::NotifyServer(void) -{ - // Send a message to the app_server to tell it which decorator we have selected. - BStringItem *item=(BStringItem*)declist->ItemAt(declist->CurrentSelection()); - if(!item) - return; - - port_id serverport=find_port(SERVER_PORT_NAME); - if(serverport==B_NAME_NOT_FOUND) - return; - - - BPrivate::PortLink pl(serverport); - pl.StartMessage(AS_SET_DECORATOR); - pl.AttachString(item->Text()); - pl.Flush(); -} - -void DecView::GetDecorators(void) -{ - - STRACE(("DecView::GetDecorators()\n")); - - BDirectory dir; - BEntry entry; - BPath path; - BString name; - BStringItem *item; - - status_t dirstat=dir.SetTo(DECORATORS_DIR); - if(dirstat!=B_OK) - 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: - { - STRACE(("DecView::GetDecorators: Couldn't open the folder for decorators - path string too long.\n")); - break; - } - case B_ENTRY_NOT_FOUND: - { - STRACE(("Couldn't open the folder for decorators - entry not found\n")); - break; - } - case B_BAD_VALUE: - { - STRACE(("DecView::GetDecorators: Couldn't open the folder for decorators - bad path\n")); - break; - } - case B_NO_MEMORY: - { - STRACE(("DecView::GetDecorators: No memory left. We're probably going to crash now\n")); - break; - } - case B_BUSY: - { - STRACE(("DecView::GetDecorators: Couldn't open the folder for decorators - node busy\n")); - break; - } - case B_FILE_ERROR: - { - STRACE(("DecView::GetDecorators: Couldn't open the folder for decorators - general file error\n")); - break; - } - case B_NO_MORE_FDS: - { - STRACE(("DecView::GetDecorators: Couldn't open the folder for decorators - no more file descriptors\n")); - break; - } - } - return; - } - - int32 count=dir.CountEntries(); - - for(int32 i=0;iAddItem(item); - } - -} - -bool DecView::LoadDecorator(const char *path) -{ - if(!path) - return false; - create_decorator *pcreatefunc=NULL; -// get_decorator_version *pversionfunc=NULL; - status_t stat; - image_id addon; - - addon=load_add_on(path); - -/* stat=get_image_symbol(addon, "get_decorator_version", B_SYMBOL_TYPE_TEXT, (void**)&pversionfunc); - if(stat!=B_OK) - { - unload_add_on(addon); - -STRACE(("LoadDecorator(%s): Couldn't get version symbol\n",path)); - - return false; - } -*/ - // As of now, we do nothing with decorator versions, but the possibility exists - // that the API will change even though I cannot forsee any reason to do so. If - // we *did* do anything with decorator versions, the assignment to a global would - // go here. - - stat=get_image_symbol(addon, "instantiate_decorator", B_SYMBOL_TYPE_TEXT, (void**)&pcreatefunc); - if(stat!=B_OK) - { - unload_add_on(addon); - - STRACE(("LoadDecorator(%s): Couldn't get allocation symbol\n",path)); - - return false; - } - if(decorator!=NULL) - { - - STRACE(("LoadDecorator(): Deleting old decorator\n")); - - delete decorator; - decorator=NULL; - - // NEVER, *EVER*, call unload_add_on() if there is _any_ possibility, - // no matter remote, that memory might still be in use when it is called. - // It wll lead to unpredictable crashes which have almost nothing to - // do with the *real* cause. -// unload_add_on(decorator_id); - } - decorator_id=addon; - decorator=pcreatefunc(BRect(25,25,125,125),B_TITLED_WINDOW_LOOK, - B_NORMAL_WINDOW_FEEL,0); - decorator->SetDriver(driver); - decorator->SetFocus(true); -// decorator->Draw(); - return true; -} - -BString DecView::ConvertIndexToPath(int32 index) -{ - BStringItem *item=(BStringItem*)declist->ItemAt(index); - if(!item) - { - - STRACE(("ConvertIndexToPath(): Couldn't get item for index %ld\n",index)); - - return NULL; - } - BString path(DECORATORS_DIR); - path+=item->Text(); - - STRACE(("ConvertIndexToPath(): returned %s\n",path.String())); - - return BString(path.String()); -} - -void DecView::SetColors(const ColorSet &set) -{ - - STRACE(("DecView::SetColors\n")); - - colorset=set; - if(decorator) - { - driver->FillRect(preview_bounds,&ldata); - decorator->SetColors(colorset); - decorator->Draw(); - } - else - { - STRACE(("DecView::SetColors: NULL decorator\n")); - } -} - -bool DecView::UnpackSettings(ColorSet *set, const BMessage &msg) -{ - if(!set) - { - STRACE(("UnpackSettings(): NULL parameter\n")); - return false; - } - rgb_color *col; - ssize_t size; - - if(msg.FindData("Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->panel_background=*col; - if(msg.FindData("Panel Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->panel_text=*col; - if(msg.FindData("Document Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->document_background=*col; - if(msg.FindData("Document Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->document_text=*col; - if(msg.FindData("Control Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->control_background=*col; - if(msg.FindData("Control Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->control_text=*col; - if(msg.FindData("Control Highlight",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->control_highlight=*col; - if(msg.FindData("Control Border",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->control_border=*col; - if(msg.FindData("Tooltip Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->tooltip_background=*col; - if(msg.FindData("Tooltip Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->tooltip_text=*col; - if(msg.FindData("Menu Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->menu_background=*col; - if(msg.FindData("Selected Menu Item Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->menu_selected_background=*col; - if(msg.FindData("Navigation Base",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->keyboard_navigation_base=*col; - if(msg.FindData("Navigation Pulse",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->keyboard_navigation_pulse=*col; - if(msg.FindData("Menu Item Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->menu_text=*col; - if(msg.FindData("Selected Menu Item Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->menu_selected_text=*col; - if(msg.FindData("Selected Menu Item Border",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->menu_selected_border=*col; - if(msg.FindData("Success",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->success=*col; - if(msg.FindData("Failure",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->failure=*col; - if(msg.FindData("Shine",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->shine=*col; - if(msg.FindData("Shadow",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->shadow=*col; - if(msg.FindData("Window Tab",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->window_tab=*col; - if(msg.FindData("Window Tab Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->window_tab_text=*col; - if(msg.FindData("Inactive Window Tab",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->inactive_window_tab=*col; - if(msg.FindData("Inactive Window Tab Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - set->inactive_window_tab_text=*col; - return true; + } diff --git a/src/prefs/appearance/DecView.h b/src/prefs/appearance/DecView.h index 9dd91c6345..00fe0d9c91 100644 --- a/src/prefs/appearance/DecView.h +++ b/src/prefs/appearance/DecView.h @@ -28,46 +28,25 @@ #define DEC_VIEW_H_ #include -#include -#include #include #include -#include -#include #include -#include "ColorSet.h" -#include "LayerData.h" -class PreviewDriver; -class Decorator; class DecView : public BView { public: - DecView(BRect frame, const char *name, int32 resize, int32 flags); - ~DecView(void); - void AllAttached(void); - void MessageReceived(BMessage *msg); - void SaveSettings(void); - void LoadSettings(void); - void NotifyServer(void); - void GetDecorators(void); - void SetColors(const ColorSet &set); - bool LoadDecorator(const char *path); - BString ConvertIndexToPath(int32 index); + DecView(BRect frame, const char *name, int32 resize, int32 flags); + + void AttachedToWindow(void); + void MessageReceived(BMessage *msg); + + void SaveSettings(void); + void LoadSettings(void); + protected: - bool UnpackSettings(ColorSet *set, const BMessage &msg); - BButton *apply; - BListView *declist; - BMessage settings; - BScrollView *scrollview; - PreviewDriver *driver; - BView *preview; - Decorator *decorator; - image_id decorator_id; - BString decpath; - LayerData ldata; - uint64 pat_solid_high; - ColorSet colorset; + BButton *apply; + BListView *declist; + BView *preview; }; #endif diff --git a/src/prefs/appearance/Jamfile b/src/prefs/appearance/Jamfile index 339bab15bf..608506f851 100644 --- a/src/prefs/appearance/Jamfile +++ b/src/prefs/appearance/Jamfile @@ -1,22 +1,25 @@ SubDir OBOS_TOP src prefs appearance ; -UseFreeTypeHeaders ; UsePrivateHeaders app [ FDirName servers app ] ; Preference Appearance : APRMain.cpp APRView.cpp APRWindow.cpp - CurView.cpp DecView.cpp - FontMenu.cpp - MenuView.cpp - PreviewDriver.cpp - SysCursorAPI.cpp ColorWell.cpp ColorWhichItem.cpp - CursorWhichItem.cpp - : libopenbeos.so libbe.so libtranslation.so libappserver.so + + # These are currently disabled while everything else is being worked on + #CurView.cpp + #CursorWhichItem.cpp + #SysCursorAPI.cpp + + # These exist for post-R1, so they are disabled for now + #FontMenu.cpp + #MenuView.cpp + + : libbe.so libopenbeos.so libtranslation.so libappserver.so : Appearance.rdef ; diff --git a/src/prefs/appearance/PreviewDriver.cpp b/src/prefs/appearance/PreviewDriver.cpp deleted file mode 100644 index f4ab88ead2..0000000000 --- a/src/prefs/appearance/PreviewDriver.cpp +++ /dev/null @@ -1,240 +0,0 @@ -//------------------------------------------------------------------------------ -// 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: PreviewDriver.cpp -// Author: DarkWyrm -// Description: Class to display decorators from regular BApplications -// -//------------------------------------------------------------------------------ - -/* - PreviewDriver: - Module based on app_server's ViewDriver for the purpose of Decorator previews. - - The concept is to have a view draw a bitmap, which is a "frame buffer" - of sorts, utilize a second view to write to it. This cuts out - the most problems with having a crapload of code to get just right without - having to write a bunch of unit tests - - Components: 3 classes, VDView, VDWindow, and ViewDriver - - PreviewDriver - a wrapper class which mostly posts messages to the VDWindow - PDView - doesn't do all that much except display the rendered bitmap -*/ - -//#define DEBUG_DRIVER_MODULE -//#define DEBUG_SERVER_EMU - -//#define DISABLE_SERVER_EMU - -#include -#include -#include -#include -#include -#include -#include -#include -#include "PortLink.h" -#include "PatternHandler.h" -#include "PreviewDriver.h" -#include "LayerData.h" -#include "ColorSet.h" -#include -#include FT_FREETYPE_H - -BRect preview_bounds(0,0,150,150);; - -PVView::PVView(const BRect &bounds) - : BView(bounds,"previewdriver_view",B_FOLLOW_NONE, B_WILL_DRAW) -{ - viewbmp=new BBitmap(bounds,B_RGB32,true); -} - -PVView::~PVView(void) -{ - delete viewbmp; -} - -void PVView::AttachedToWindow(void) -{ - win=Window(); -} - -void PVView::DetachedFromWindow(void) -{ - win=NULL; -} - -void PVView::Draw(BRect rect) -{ - if(viewbmp) - { - DrawBitmapAsync(viewbmp,rect,rect); - Sync(); - } -} - -PreviewDriver::PreviewDriver(void) -{ - fView=new PVView(preview_bounds); - fDrawView=new BView(preview_bounds,"drawview",B_FOLLOW_ALL, 0); -} - -PreviewDriver::~PreviewDriver(void) -{ - delete fView; - delete fDrawView; -} - -bool PreviewDriver::Initialize(void) -{ - fView->viewbmp->Lock(); - fView->viewbmp->AddChild(fDrawView); - fView->viewbmp->Unlock(); - return true; -} - -void PreviewDriver::Shutdown(void) -{ - fView->viewbmp->Lock(); - fView->viewbmp->RemoveChild(fDrawView); - fView->viewbmp->Unlock(); -} - -void PreviewDriver::InvertRect(const BRect &r) -{ - fView->viewbmp->Lock(); - fDrawView->InvertRect(r); - fDrawView->Sync(); - fView->Invalidate(r); - fView->viewbmp->Unlock(); -} - -void PreviewDriver::StrokeLineArray(const int32 &numlines, const LineArrayData *linedata, - const DrawData *d) -{ - if(!linedata || !d) - return; - - fView->viewbmp->Lock(); - fDrawView->SetHighColor(d->HighColor().GetColor32()); - fDrawView->SetLowColor(d->LowColor().GetColor32()); - fDrawView->SetPenSize(d->PenSize()); - fDrawView->BeginLineArray(numlines); - for(int32 i=0; iAddLine(data->pt1,data->pt2,data->color); - } - fDrawView->EndLineArray(); - fDrawView->Sync(); - fView->Invalidate(); - fView->viewbmp->Unlock(); -} - -bool PreviewDriver::Lock(bigtime_t timeout=B_INFINITE_TIMEOUT) -{ - return true; -} - -void PreviewDriver::Unlock(void) -{ -} - -float -PreviewDriver::StringWidth(const char *string, int32 length, const DrawData *d) -{ - SetDrawData(d,true); - fView->viewbmp->Lock(); - float value=fDrawView->StringWidth(string,length); - fView->viewbmp->Unlock(); - - return value; -} - -float -PreviewDriver::StringWidth(const char *string,int32 length, const ServerFont &font) -{ - DrawData d; - d.SetFont(font); - return StringWidth(string,length,&d); -} - -void -PreviewDriver::SetDrawData(const DrawData *d, bool set_font_data) -{ - if(!d) - return; - - fView->viewbmp->Lock(); - - BRegion reg=*d->ClippingRegion(); - fDrawView->ConstrainClippingRegion(®); - - fDrawView->SetPenSize(d->PenSize()); - fDrawView->SetDrawingMode(d->GetDrawingMode()); - - fDrawView->SetHighColor(d->HighColor().GetColor32()); - fDrawView->SetLowColor(d->LowColor().GetColor32()); - - fDrawView->SetScale(d->Scale()); - fDrawView->MovePenTo(d->PenLocation()); - - if(set_font_data) - { - BFont font; - const ServerFont *sf=&(d->Font()); - - if(!sf) - return; - - font.SetFamilyAndStyle(sf->GetFamily(),sf->GetStyle()); - font.SetFlags(sf->Flags()); - font.SetEncoding(sf->Encoding()); - font.SetSize(sf->Size()); - font.SetRotation(sf->Rotation()); - font.SetShear(sf->Shear()); - font.SetSpacing(sf->Spacing()); - fDrawView->SetFont(&font); - } - - fView->viewbmp->Unlock(); -} - -float -PreviewDriver::StringHeight(const char *string,int32 length, - const DrawData *d) -{ - SetDrawData(d,true); - - fView->viewbmp->Lock(); - - font_height fh; - - fDrawView->GetFontHeight(&fh); - - float value=fh.ascent+fh.descent+fh.leading; - - fView->viewbmp->Unlock(); - - return value; -} diff --git a/src/prefs/appearance/PreviewDriver.h b/src/prefs/appearance/PreviewDriver.h deleted file mode 100644 index 6ada1c01e3..0000000000 --- a/src/prefs/appearance/PreviewDriver.h +++ /dev/null @@ -1,313 +0,0 @@ -//------------------------------------------------------------------------------ -// 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: PreviewDriver.cpp -// Author: DarkWyrm -// Description: Class to display decorators from regular BApplications -// -//------------------------------------------------------------------------------ -#ifndef _PREVIEWDRIVER_H_ -#define _PREVIEWDRIVER_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "DisplayDriver.h" - -class BBitmap; -class PortLink; -class ServerCursor; -class ColorSet; - -class PVView : public BView -{ -public: - PVView(const BRect &bounds); - ~PVView(void); - void AttachedToWindow(void); - void DetachedFromWindow(void); - void Draw(BRect rect); - - BBitmap *viewbmp; - BWindow *win; -}; - -class PreviewDriver : public DisplayDriver -{ - public: - PreviewDriver(); - virtual ~PreviewDriver(); - - // when implementing, be sure to call the inherited version - virtual bool Initialize(); - virtual void Shutdown(); - - // clipping for all drawing functions - virtual void ConstrainClippingRegion(BRegion* region) {} - - // Graphics calls implemented in DisplayDriver - virtual void CopyRegion( /*const*/ BRegion* region, - int32 xOffset, - int32 yOffset) {} - - virtual void CopyRegionList( BList* list, - BList* pList, - int32 rCount, - BRegion* clipReg) {} - - virtual void InvertRect( const BRect &r); - - virtual void DrawBitmap( ServerBitmap *bitmap, - const BRect &source, - const BRect &dest, - const DrawData *d) {} - - virtual void FillArc( const BRect &r, - const float &angle, - const float &span, - const DrawData *d) {} - - virtual void FillBezier( BPoint *pts, - const DrawData *d) {} - - virtual void FillEllipse( const BRect &r, - const DrawData *d) {} - - virtual void FillPolygon( BPoint *ptlist, - int32 numpts, - const BRect &bounds, - const DrawData *d) {} - - virtual void FillRect( const BRect &r, - const RGBColor &color) {} - - virtual void FillRect( const BRect &r, - const DrawData *d) {} - - virtual void FillRegion( BRegion &r, - const DrawData *d) {} - - virtual void FillRoundRect( const BRect &r, - const float &xrad, - const float &yrad, - const DrawData *d) {} - - virtual void FillShape( const BRect &bounds, - const int32 &opcount, - const int32 *oplist, - const int32 &ptcount, - const BPoint *ptlist, - const DrawData *d) {} - - virtual void FillTriangle( BPoint *pts, - const BRect &bounds, - const DrawData *d) {} - - virtual void StrokeArc( const BRect &r, - const float &angle, - const float &span, - const DrawData *d) {} - - virtual void StrokeBezier( BPoint *pts, - const DrawData *d) {} - - virtual void StrokeEllipse( const BRect &r, - const DrawData *d) {} - - // this version used by Decorator - virtual void StrokeLine( const BPoint &start, - const BPoint &end, - const RGBColor &color) {} - - virtual void StrokeLine( const BPoint &start, - const BPoint &end, - DrawData *d) {} - - virtual void StrokeLineArray(const int32 &numlines, - const LineArrayData *data, - const DrawData *d); - - // this version used by Decorator - virtual void StrokePoint( const BPoint &pt, - const RGBColor &color) {} - - virtual void StrokePoint( const BPoint &pt, - DrawData *d) {} - - virtual void StrokePolygon( BPoint *ptlist, - int32 numpts, - const BRect &bounds, - const DrawData *d, - bool is_closed=true) {} - - // this version used by Decorator - virtual void StrokeRect( const BRect &r, - const RGBColor &color) {} - - virtual void StrokeRect( const BRect &r, - const DrawData *d) {} - - virtual void StrokeRegion( BRegion &r, - const DrawData *d) {} - - virtual void StrokeRoundRect(const BRect &r, - const float &xrad, - const float &yrad, - const DrawData *d) {} - - virtual void StrokeShape( const BRect &bounds, - const int32 &opcount, - const int32 *oplist, - const int32 &ptcount, - const BPoint *ptlist, - const DrawData *d) {} - - virtual void StrokeTriangle( BPoint *pts, - const BRect &bounds, - const DrawData *d) {} - - // Font-related calls - - // DrawData is NOT const because this call updates the pen position in the passed DrawData - virtual void DrawString( const char *string, - const int32 &length, - const BPoint &pt, - DrawData *d) {} - - virtual void DrawString( const char *string, - const int32 &length, - const BPoint &pt, - const RGBColor &color, - escapement_delta *delta=NULL) {} - - virtual float StringWidth( const char *string, - int32 length, - const DrawData *d); - - virtual float StringWidth( const char *string, - int32 length, - const ServerFont &font); - - virtual float StringHeight( const char *string, - int32 length, - const DrawData *d); - - virtual void GetBoundingBoxes(const char *string, - int32 count, - font_metric_mode mode, - escapement_delta *delta, - BRect *rectarray, - const DrawData *d) {} - - virtual void GetEscapements( const char *string, - int32 charcount, - escapement_delta *delta, - escapement_delta *escapements, - escapement_delta *offsets, - const DrawData *d) {} - - virtual void GetEdges( const char *string, - int32 charcount, - edge_info *edgearray, - const DrawData *d) {} - - virtual void GetHasGlyphs( const char *string, - int32 charcount, - bool *hasarray) {} - - virtual void GetTruncatedStrings(const char **instrings, - const int32 &stringcount, - const uint32 &mode, - const float &maxwidth, - char **outstrings) {} - - virtual void HideCursor() {} - virtual bool IsCursorHidden() { return false; } - virtual void MoveCursorTo( const float &x, - const float &y) {} - virtual void ShowCursor() {} - virtual void ObscureCursor() {} - virtual void SetCursor(ServerCursor *cursor) {} - virtual BPoint GetCursorPosition() { return BPoint(0,0); } - virtual bool IsCursorObscured(bool state) { return false; } - - - // Virtual methods which need to be implemented by each subclass - - // These two will rarely be implemented by subclasses, - // but it still needs to be possible - virtual bool Lock(bigtime_t timeout = B_INFINITE_TIMEOUT); - virtual void Unlock(); - - // display mode access - virtual status_t SetMode(const display_mode &mode) { return B_OK; } - virtual void GetMode(display_mode &mode) {} - const display_mode* DisplayMode() - { return &fDisplayMode; } - - virtual bool DumpToFile(const char *path) { return false; } - virtual ServerBitmap* DumpToBitmap() { return NULL; } - - virtual status_t SetDPMSMode(const uint32 &state) { return B_ERROR; } - virtual uint32 DPMSMode() { return 0; } - virtual uint32 DPMSCapabilities() { return 0; } - virtual status_t GetDeviceInfo(accelerant_device_info *info) { return B_ERROR; } - - virtual status_t GetModeList(display_mode **mode_list, - uint32 *count) { return B_ERROR; } - - virtual status_t GetPixelClockLimits(display_mode *mode, - uint32 *low, - uint32 *high) { return B_ERROR; } - - virtual status_t GetTimingConstraints(display_timing_constraints *dtc) { return B_ERROR; } - virtual status_t ProposeMode(display_mode *candidate, - const display_mode *low, - const display_mode *high) { return B_ERROR; } - - virtual status_t WaitForRetrace(bigtime_t timeout = B_INFINITE_TIMEOUT) { return B_ERROR; } - - // This is only for the PreviewDriver - BView * View(void) { return (BView*)fView; }; - - protected: - void SetDrawData(const DrawData *d, - bool set_font_data); - - display_mode fDisplayMode; - - BBitmap *fFramebuffer; - BView *fDrawView; - - // Region used to track of invalid areas for the - // Begin/EndLineArray functions - BRegion fArrayRegion; - PVView *fView; -}; - -extern BRect preview_bounds; - -#endif