diff --git a/src/prefs/screen/AlertView.cpp b/src/prefs/screen/AlertView.cpp index 20024fa1ff..0cac17f031 100644 --- a/src/prefs/screen/AlertView.cpp +++ b/src/prefs/screen/AlertView.cpp @@ -4,27 +4,29 @@ #include "AlertView.h" #include "Bitmaps.h" +#include "Constants.h" +#include "Utility.h" AlertView::AlertView(BRect frame, char *name) : BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW) { - Count = 10; + Count = 8; fBitmap = new BBitmap(BRect(0, 0, 31, 31), B_COLOR_8_BIT); fBitmap->SetBits(BitmapBits, 32 * 32, 0, B_COLOR_8_BIT); } -void AlertView::AttachedToWindow() + +void +AlertView::AttachedToWindow() { - rgb_color greyColor = {216, 216, 216, 255}; SetViewColor(greyColor); } -void AlertView::Draw(BRect updateRect) -{ - rgb_color darkColor = {184, 184, 184, 255}; - rgb_color blackColor = {0, 0, 0, 255}; - + +void +AlertView::Draw(BRect updateRect) +{ SetHighColor(darkColor); FillRect(BRect(0.0, 0.0, 30.0, 100.0)); @@ -39,9 +41,7 @@ void AlertView::Draw(BRect updateRect) SetFont(be_bold_font); - MovePenTo(60.0, 20.0); - - DrawString("Do you wish to keep these settings?"); + DrawString("Do you wish to keep these settings?", BPoint(60.0, 20.0)); MovePenTo(60.0, 37.0); diff --git a/src/prefs/screen/AlertView.h b/src/prefs/screen/AlertView.h index bc28f1fa8d..41c368b832 100644 --- a/src/prefs/screen/AlertView.h +++ b/src/prefs/screen/AlertView.h @@ -8,10 +8,10 @@ class AlertView : public BView { public: - AlertView(BRect frame, char *name); - virtual void AttachedToWindow(); - virtual void Draw(BRect updateRect); - int32 Count; + AlertView(BRect frame, char *name); + virtual void AttachedToWindow(); + virtual void Draw(BRect updateRect); + int32 Count; private: BBitmap *fBitmap; diff --git a/src/prefs/screen/AlertWindow.cpp b/src/prefs/screen/AlertWindow.cpp index 67c868b12a..898bf2f1b1 100644 --- a/src/prefs/screen/AlertWindow.cpp +++ b/src/prefs/screen/AlertWindow.cpp @@ -49,16 +49,20 @@ AlertWindow::AlertWindow(BRect frame) Show(); } -bool AlertWindow::QuitRequested() + +bool +AlertWindow::QuitRequested() { delete fRunner; - + Quit(); - return(true); + return true; } -void AlertWindow::MessageReceived(BMessage *message) + +void +AlertWindow::MessageReceived(BMessage *message) { switch (message->what) { diff --git a/src/prefs/screen/Constants.h b/src/prefs/screen/Constants.h index 6d900f6fc5..ff77e9a208 100644 --- a/src/prefs/screen/Constants.h +++ b/src/prefs/screen/Constants.h @@ -1,6 +1,7 @@ #ifndef CONSTANTS_H #define CONSTANTS_H +//Messages #define WORKSPACE_CHECK_MSG 'wchk' #define BUTTON_DEFAULTS_MSG 'bdef' #define BUTTON_REVERT_MSG 'brev' @@ -22,4 +23,7 @@ #define DIM_COUNT_MSG 'scrf' #define MAKE_INITIAL_MSG 'mkin' -#endif +//Constants +static const char kAppSignature[] = "application/x-vnd.RR-SCRN"; + +#endif //CONSTANTS_H diff --git a/src/prefs/screen/Jamfile b/src/prefs/screen/Jamfile index e94563dcdd..dae8e66cb5 100644 --- a/src/prefs/screen/Jamfile +++ b/src/prefs/screen/Jamfile @@ -2,6 +2,6 @@ SubDir OBOS_TOP src prefs screen ; AddResources Screen : Screen.rsrc ; -Preference Screen : AlertView.cpp AlertWindow.cpp RefreshSlider.cpp RefreshView.cpp RefreshWindow.cpp Screen.cpp ScreenDrawView.cpp ScreenSettings.cpp ScreenView.cpp ScreenWindow.cpp ; +Preference Screen : AlertView.cpp AlertWindow.cpp RefreshSlider.cpp RefreshView.cpp RefreshWindow.cpp Screen.cpp ScreenDrawView.cpp ScreenSettings.cpp ScreenView.cpp ScreenWindow.cpp Utility.cpp ; LinkSharedOSLibs Screen : be root ; diff --git a/src/prefs/screen/RefreshSlider.cpp b/src/prefs/screen/RefreshSlider.cpp index 23c014daca..4201e79229 100644 --- a/src/prefs/screen/RefreshSlider.cpp +++ b/src/prefs/screen/RefreshSlider.cpp @@ -11,41 +11,40 @@ #include "Constants.h" RefreshSlider::RefreshSlider(BRect frame) - : BSlider(frame, "Screen", "Refresh Rate:", new BMessage(SLIDER_INVOKE_MSG), 450, 845) -{ - fStatus = (char*)malloc(64); + : BSlider(frame, "Screen", "Refresh Rate:", new BMessage(SLIDER_INVOKE_MSG), 450, 900), + fStatus(new char[64]) +{ } + RefreshSlider::~RefreshSlider() { - if (fStatus) - free(fStatus); + delete[] fStatus; } -void RefreshSlider::DrawFocusMark() + +void +RefreshSlider::DrawFocusMark() { if (IsFocus()) { - rgb_color blueColor = {0, 0, 229, 255}; + rgb_color blueColor = { 0, 0, 229, 255 }; - BRect Rect; + BRect rect(ThumbFrame()); + BView *view = OffscreenView(); + + rect.InsetBy(2.0, 2.0); + rect.right--; + rect.bottom--; - BView *View; - - Rect = ThumbFrame(); - - View = OffscreenView(); - - Rect.InsetBy(2.0, 2.0); - Rect.right = Rect.right - 1; - Rect.bottom = Rect.bottom - 1; - - View->SetHighColor(blueColor); - View->StrokeRect(Rect); + view->SetHighColor(blueColor); + view->StrokeRect(rect); } } -void RefreshSlider::KeyDown(const char *bytes, int32 numBytes) + +void +RefreshSlider::KeyDown(const char *bytes, int32 numBytes) { switch ( *bytes ) { @@ -72,30 +71,25 @@ void RefreshSlider::KeyDown(const char *bytes, int32 numBytes) } } -char* RefreshSlider::UpdateText() const + +char* +RefreshSlider::UpdateText() const { if (fStatus && Window()->Lock()) { BString String; String << Value(); - - int32 Len = String.Length()+1; - strcpy(fStatus, String.LockBuffer(Len)); - - char Last = fStatus[2]; + String.CopyInto(fStatus, 0, String.Length() + 1); - String.UnlockBuffer(Len); - - String.Truncate(2); - + char Last = fStatus[2]; + + String.Truncate(2); String << "." << Last << " Hz"; - - strcpy(fStatus, String.LockBuffer(Len)); - - String.UnlockBuffer(Len); - - return(fStatus); + + String.CopyInto(fStatus, 0, String.Length() + 1); + + return fStatus; } else { diff --git a/src/prefs/screen/RefreshView.cpp b/src/prefs/screen/RefreshView.cpp index 24647d0018..26b8f00d51 100644 --- a/src/prefs/screen/RefreshView.cpp +++ b/src/prefs/screen/RefreshView.cpp @@ -1,36 +1,39 @@ #include #include "RefreshView.h" +#include "Utility.h" RefreshView::RefreshView(BRect rect, char *name) : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) { - } -void RefreshView::AttachedToWindow() + +void +RefreshView::AttachedToWindow() { - rgb_color greyColor = {216, 216, 216, 255}; SetViewColor(greyColor); } -void RefreshView::Draw(BRect updateRect) + +void +RefreshView::Draw(BRect updateRect) { - rgb_color whiteColor = {255, 255, 255, 255}; - rgb_color darkColor = {128, 128, 128, 255}; - rgb_color blackColor = {0, 0, 0, 255}; + rgb_color darkColor = { 128, 128, 128, 255 }; + BRect bounds(Bounds()); SetHighColor(whiteColor); - StrokeLine(BPoint(Bounds().left, Bounds().top), BPoint(Bounds().right, Bounds().top)); - StrokeLine(BPoint(Bounds().left, Bounds().top), BPoint(Bounds().left, Bounds().bottom)); + StrokeLine(BPoint(bounds.left, bounds.top), BPoint(bounds.right, bounds.top)); + StrokeLine(BPoint(bounds.left, bounds.top), BPoint(bounds.left, bounds.bottom)); SetHighColor(darkColor); - StrokeLine(BPoint(Bounds().left, Bounds().bottom), BPoint(Bounds().right, Bounds().bottom)); - StrokeLine(BPoint(Bounds().right, Bounds().bottom), BPoint(Bounds().right, Bounds().top)); + StrokeLine(BPoint(bounds.left, bounds.bottom), BPoint(bounds.right, bounds.bottom)); + StrokeLine(BPoint(bounds.right, bounds.bottom), BPoint(bounds.right, bounds.top)); SetHighColor(blackColor); + SetLowColor(ViewColor()); DrawString("Type or use the left and right arrow keys.", BPoint(10.0, 23.0)); } diff --git a/src/prefs/screen/RefreshWindow.cpp b/src/prefs/screen/RefreshWindow.cpp index e29e14fc11..04a46193f5 100644 --- a/src/prefs/screen/RefreshWindow.cpp +++ b/src/prefs/screen/RefreshWindow.cpp @@ -13,8 +13,6 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value) : BWindow(frame, "Refresh Rate", B_MODAL_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES) { - int32 Value = value * 10; - frame = Bounds(); fRefreshView = new RefreshView(frame, "RefreshView"); @@ -29,20 +27,18 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value) fRefreshSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fRefreshSlider->SetHashMarkCount(10); - fRefreshSlider->SetLimitLabels("45.0", "84.5"); + fRefreshSlider->SetLimitLabels("45.0", "90.0"); fRefreshSlider->SetKeyIncrementValue(1); - fRefreshSlider->SetValue(Value); + fRefreshSlider->SetValue(value); fRefreshSlider->SetSnoozeAmount(1); fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG)); fRefreshView->AddChild(fRefreshSlider); - BRect ButtonRect; - - ButtonRect.Set(219.0, 97.0, 230.0, 120.0); + BRect ButtonRect(219.0, 97.0, 230.0, 120.0); fDoneButton = new BButton(ButtonRect, "DoneButton", "Done", - new BMessage(BUTTON_DONE_MSG)); + new BMessage(BUTTON_DONE_MSG)); fDoneButton->ResizeToPreferred(); fDoneButton->MakeDefault(true); @@ -52,7 +48,7 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value) ButtonRect.Set(130.0, 97.0, 200.0, 120.0); fCancelButton = new BButton(ButtonRect, "CancelButton", "Cancel", - new BMessage(BUTTON_CANCEL_MSG)); + new BMessage(BUTTON_CANCEL_MSG)); fCancelButton->ResizeToPreferred(); @@ -63,32 +59,25 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value) PostMessage(SLIDER_INVOKE_MSG); } -bool RefreshWindow::QuitRequested() + +void +RefreshWindow::WindowActivated(bool active) { - return(true); + fRefreshSlider->MakeFocus(active); } -void RefreshWindow::WindowActivated(bool active) -{ - if (active == true) - fRefreshSlider->MakeFocus(true); - else - fRefreshSlider->MakeFocus(false); -} -void RefreshWindow::MessageReceived(BMessage* message) +void +RefreshWindow::MessageReceived(BMessage* message) { switch(message->what) { case BUTTON_DONE_MSG: { - BMessenger Messenger("application/x-vnd.RR-SCRN"); - + BMessenger Messenger(kAppSignature); BMessage Message(SET_CUSTOM_REFRESH_MSG); - float Value; - - Value = (float)fRefreshSlider->Value() / 10; + float Value = (float)fRefreshSlider->Value() / 10; Message.AddFloat("refresh", Value); @@ -114,8 +103,7 @@ void RefreshWindow::MessageReceived(BMessage* message) } default: - BWindow::MessageReceived(message); - + BWindow::MessageReceived(message); break; } } diff --git a/src/prefs/screen/RefreshWindow.h b/src/prefs/screen/RefreshWindow.h index fbc3929a72..49ecf09853 100644 --- a/src/prefs/screen/RefreshWindow.h +++ b/src/prefs/screen/RefreshWindow.h @@ -10,10 +10,9 @@ class RefreshWindow : public BWindow { public: - RefreshWindow(BRect frame, int32 value); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *message); - virtual void WindowActivated(bool active); + RefreshWindow(BRect frame, int32 value); + virtual void MessageReceived(BMessage *message); + virtual void WindowActivated(bool active); private: RefreshView *fRefreshView; diff --git a/src/prefs/screen/Screen.cpp b/src/prefs/screen/Screen.cpp index ff48d96c35..bdc3c591ae 100644 --- a/src/prefs/screen/Screen.cpp +++ b/src/prefs/screen/Screen.cpp @@ -1,6 +1,7 @@ -// Screen V0.9 build 1 by Rafael Romo for the OpenBeOS Preferences team. +// Screen V1.00 by Rafael Romo for the OpenBeOS Preferences team. // web.tiscalinet.it/rockman // rockman@tiscalinet.it +// Modified by Stefano Ceccherini ( burton666@freemail.it ) #include #include @@ -14,21 +15,25 @@ #include "Constants.h" ScreenApplication::ScreenApplication() - : BApplication("application/x-vnd.RR-SCRN") + : + BApplication(kAppSignature), + fScreenWindow(new ScreenWindow(new ScreenSettings())) { - fScreenWindow = new ScreenWindow(new ScreenSettings()); } -void ScreenApplication::AboutRequested() + +void +ScreenApplication::AboutRequested() { - BAlert *AboutAlert = new BAlert("About", "Screen by Rafael Romo\nThe OBOS place to configure your monitor", - "Ok", NULL, NULL, - B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_INFO_ALERT); + BAlert *AboutAlert = new BAlert("About", "Screen by Rafael Romo, Stefano Ceccherini\nThe OBOS place to configure your monitor", + "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_INFO_ALERT); AboutAlert->SetShortcut(0, B_OK); AboutAlert->Go(); } -void ScreenApplication::MessageReceived(BMessage* message) + +void +ScreenApplication::MessageReceived(BMessage* message) { switch(message->what) { @@ -41,17 +46,15 @@ void ScreenApplication::MessageReceived(BMessage* message) case SET_CUSTOM_REFRESH_MSG: { - BMessage *Message; - - Message = new BMessage(SET_CUSTOM_REFRESH_MSG); + BMessage message(SET_CUSTOM_REFRESH_MSG); float Value; - message->FindFloat("refresh", &Value); + message.FindFloat("refresh", &Value); - Message->AddFloat("refresh", Value); + message.AddFloat("refresh", Value); - fScreenWindow->PostMessage(Message); + fScreenWindow->PostMessage(&message); break; } @@ -64,17 +67,18 @@ void ScreenApplication::MessageReceived(BMessage* message) } default: - BApplication::MessageReceived(message); - + BApplication::MessageReceived(message); break; } } -int main() + +int +main() { - ScreenApplication MyApplication; + ScreenApplication Application; - MyApplication.Run(); + Application.Run(); return(0); } diff --git a/src/prefs/screen/ScreenApplication.h b/src/prefs/screen/ScreenApplication.h index 7da7692fd8..c5da2326be 100644 --- a/src/prefs/screen/ScreenApplication.h +++ b/src/prefs/screen/ScreenApplication.h @@ -7,9 +7,9 @@ class ScreenApplication : public BApplication { public: - ScreenApplication(); - virtual void MessageReceived(BMessage *message); - virtual void AboutRequested(); + ScreenApplication(); + virtual void MessageReceived(BMessage *message); + virtual void AboutRequested(); private: ScreenWindow *fScreenWindow; diff --git a/src/prefs/screen/ScreenDrawView.cpp b/src/prefs/screen/ScreenDrawView.cpp index babc3a0df6..9a7525e398 100644 --- a/src/prefs/screen/ScreenDrawView.cpp +++ b/src/prefs/screen/ScreenDrawView.cpp @@ -1,46 +1,55 @@ #include #include -#include #include +#include +#include #include -#include +#include #include "ScreenDrawView.h" #include "Constants.h" +#include "Utility.h" ScreenDrawView::ScreenDrawView(BRect rect, char *name) - : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) + : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW), + fScreen(new BScreen(B_MAIN_SCREEN_ID)) + { - fScreen = new BScreen(B_MAIN_SCREEN_ID); - + if (!fScreen->IsValid()) + ; //Debugger() ? + desktopColor = fScreen->DesktopColor(current_workspace()); - display_mode Mode; - - fScreen->GetMode(&Mode); + display_mode mode; + fScreen->GetMode(&mode); - fResolution = Mode.virtual_width; + fResolution = mode.virtual_width; } -void ScreenDrawView::AttachedToWindow() + +void +ScreenDrawView::AttachedToWindow() { - rgb_color greyColor = {216, 216, 216, 255}; + rgb_color greyColor = { 216, 216, 216, 255 }; SetViewColor(greyColor); } -void ScreenDrawView::MouseDown(BPoint point) + +void +ScreenDrawView::MouseDown(BPoint point) { be_roster->Launch("application/x-vnd.Be-BACK"); } -void ScreenDrawView::Draw(BRect updateRect) + +void +ScreenDrawView::Draw(BRect updateRect) { + //FIXME: Make the draw code resolution independent if (fResolution == 1600) { rgb_color darkColor = {160, 160, 160, 255}; - rgb_color blackColor = {0, 0, 0, 255}; - rgb_color redColor = {228, 0, 0, 255}; SetHighColor(darkColor); @@ -65,8 +74,6 @@ void ScreenDrawView::Draw(BRect updateRect) else if(fResolution == 1280) { rgb_color darkColor = {160, 160, 160, 255}; - rgb_color blackColor = {0, 0, 0, 255}; - rgb_color redColor = {228, 0, 0, 255}; SetHighColor(darkColor); @@ -91,8 +98,6 @@ void ScreenDrawView::Draw(BRect updateRect) else if(fResolution == 1152) { rgb_color darkColor = {160, 160, 160, 255}; - rgb_color blackColor = {0, 0, 0, 255}; - rgb_color redColor = {228, 0, 0, 255}; SetHighColor(darkColor); @@ -117,8 +122,6 @@ void ScreenDrawView::Draw(BRect updateRect) else if(fResolution == 1024) { rgb_color darkColor = {160, 160, 160, 255}; - rgb_color blackColor = {0, 0, 0, 255}; - rgb_color redColor = {228, 0, 0, 255}; SetHighColor(darkColor); @@ -143,7 +146,6 @@ void ScreenDrawView::Draw(BRect updateRect) else if(fResolution == 800) { rgb_color darkColor = {160, 160, 160, 255}; - rgb_color blackColor = {0, 0, 0, 255}; rgb_color redColor = {228, 0, 0, 255}; SetHighColor(darkColor); @@ -169,8 +171,6 @@ void ScreenDrawView::Draw(BRect updateRect) else if(fResolution == 640) { rgb_color darkColor = {160, 160, 160, 255}; - rgb_color blackColor = {0, 0, 0, 255}; - rgb_color redColor = {228, 0, 0, 255}; SetHighColor(darkColor); @@ -194,31 +194,18 @@ void ScreenDrawView::Draw(BRect updateRect) } } -void ScreenDrawView::MessageReceived(BMessage* message) + +void +ScreenDrawView::MessageReceived(BMessage* message) { switch(message->what) { case UPDATE_DESKTOP_MSG: { - const char *Resolution; - int32 NextfResolution; - + BString Resolution; message->FindString("resolution", &Resolution); - if (strcmp(Resolution, "640 x 480") == 0) - NextfResolution = 640; - else if (strcmp(Resolution, "800 x 600") == 0) - NextfResolution = 800; - else if (strcmp(Resolution, "1024 x 768") == 0) - NextfResolution = 1024; - else if (strcmp(Resolution, "1152 x 864") == 0) - NextfResolution = 1152; - else if (strcmp(Resolution, "1280 x 1024") == 0) - NextfResolution = 1280; - else if (strcmp(Resolution, "1600 x 1200") == 0) - NextfResolution = 1600; - else - NextfResolution = 640; + int32 NextfResolution = atoi(Resolution.String()); if (fResolution != NextfResolution) { diff --git a/src/prefs/screen/ScreenSettings.cpp b/src/prefs/screen/ScreenSettings.cpp index dbfd972de6..10c58f2965 100644 --- a/src/prefs/screen/ScreenSettings.cpp +++ b/src/prefs/screen/ScreenSettings.cpp @@ -3,37 +3,43 @@ #include "ScreenSettings.h" -const char ScreenSettings::fScreenSettingsFile[] = "RRScreen_Data"; +const char ScreenSettings::fScreenSettingsFile[] = "OBOS_Screen_data"; ScreenSettings::ScreenSettings() { + BScreen screen(B_MAIN_SCREEN_ID); + + if (!screen.IsValid()) + ; //Debugger() ? + BPath path; - if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(fScreenSettingsFile); BFile file(path.Path(), B_READ_ONLY); - if (file.InitCheck() == B_OK && file.Read(&fWindowFrame, sizeof(BRect)) == sizeof(BRect)) + if (file.InitCheck() == B_OK) { - BScreen Screen; - if (Screen.Frame().right >= fWindowFrame.right - && Screen.Frame().bottom >= fWindowFrame.bottom) + file.Read(&fWindowFrame, sizeof(BRect)); + + if (screen.Frame().right >= fWindowFrame.right + && screen.Frame().bottom >= fWindowFrame.bottom) return; } } - BScreen Screen; - fWindowFrame = Screen.Frame(); - fWindowFrame.left = (Screen.Frame().right / 2) - 178; - fWindowFrame.top = (Screen.Frame().right / 2) - 101; + fWindowFrame = screen.Frame(); + fWindowFrame.left = (fWindowFrame.right / 2) - 178; + fWindowFrame.top = (fWindowFrame.right / 2) - 101; fWindowFrame.right = fWindowFrame.left + 356; fWindowFrame.bottom = fWindowFrame.top + 202; } + ScreenSettings::~ScreenSettings() { BPath path; - if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK) + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) return; path.Append(fScreenSettingsFile); @@ -43,7 +49,9 @@ ScreenSettings::~ScreenSettings() file.Write(&fWindowFrame, sizeof(BRect)); } -void ScreenSettings::SetWindowFrame(BRect frame) + +void +ScreenSettings::SetWindowFrame(BRect frame) { fWindowFrame = frame; } diff --git a/src/prefs/screen/ScreenView.cpp b/src/prefs/screen/ScreenView.cpp index 7d97a4a282..80cd09d230 100644 --- a/src/prefs/screen/ScreenView.cpp +++ b/src/prefs/screen/ScreenView.cpp @@ -1,23 +1,25 @@ #include #include "ScreenView.h" +#include "Utility.h" ScreenView::ScreenView(BRect rect, char *name) : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) { } -void ScreenView::AttachedToWindow() + +void +ScreenView::AttachedToWindow() { - rgb_color greyColor = {216, 216, 216, 255}; SetViewColor(greyColor); } -void ScreenView::Draw(BRect updateRect) + +void +ScreenView::Draw(BRect updateRect) { - rgb_color whiteColor = {255, 255, 255, 255}; rgb_color darkColor = {128, 128, 128, 255}; - rgb_color blackColor = {0, 0, 0, 255}; SetHighColor(whiteColor); diff --git a/src/prefs/screen/ScreenWindow.cpp b/src/prefs/screen/ScreenWindow.cpp index 88b06a0463..31ea06f40d 100644 --- a/src/prefs/screen/ScreenWindow.cpp +++ b/src/prefs/screen/ScreenWindow.cpp @@ -1,32 +1,37 @@ -// Note: -// The program has been tested with a 17" Monitor only. -// Do not distribute this program at this state. - -#include +#include #include -#include -#include #include +#include +#include +#include +#include #include #include -#include -#include +#include + +#include #include #include -#include - #include "ScreenWindow.h" #include "ScreenDrawView.h" #include "ScreenView.h" #include "AlertWindow.h" #include "Constants.h" - +#include "Utility.h" + ScreenWindow::ScreenWindow(ScreenSettings *Settings) : BWindow(Settings->WindowFrame(), "Screen", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES) { - BRect frame = Bounds(); + BRect frame(Bounds()); + BScreen screen(B_MAIN_SCREEN_ID); + + if (!screen.IsValid()) { + //What could we do? + //debugger() ? + } + screen.GetModeList(&fSupportedModes, &fTotalModes); fScreenView = new ScreenView(frame, "ScreenView"); @@ -51,14 +56,13 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings) fScreenDrawView = new ScreenDrawView(ScreenDrawViewRect, "ScreenDrawView"); - int32 Count; - BString String; String << count_workspaces(); fWorkspaceCountMenu = new BPopUpMenu(String.String(), true, true); - for (Count = 1; Count <= 32; Count++) + + for (int32 Count = 1; Count <= 32; Count++) { String.Truncate(0); String << Count; @@ -112,12 +116,13 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings) fControlsBox->AddChild(fApplyButton); fResolutionMenu = new BPopUpMenu("640 x 480", true, true); - fResolutionMenu->AddItem(new BMenuItem("640 x 480", new BMessage(POP_RESOLUTION_MSG))); - fResolutionMenu->AddItem(new BMenuItem("800 x 600", new BMessage(POP_RESOLUTION_MSG))); - fResolutionMenu->AddItem(new BMenuItem("1024 x 768", new BMessage(POP_RESOLUTION_MSG))); - fResolutionMenu->AddItem(new BMenuItem("1152 x 864", new BMessage(POP_RESOLUTION_MSG))); - fResolutionMenu->AddItem(new BMenuItem("1280 x 1024", new BMessage(POP_RESOLUTION_MSG))); - fResolutionMenu->AddItem(new BMenuItem("1600 x 1200", new BMessage(POP_RESOLUTION_MSG))); + for (uint32 c = 0; c < fTotalModes; c++) { + BString mode; + mode << (int32)fSupportedModes[c].virtual_width << " x " << (int32)fSupportedModes[c].virtual_height; + if (!fResolutionMenu->FindItem(mode.String())) + fResolutionMenu->AddItem(new BMenuItem(mode.String(), + new BMessage(POP_RESOLUTION_MSG))); + } ControlMenuRect.Set(33.0, 30.0, 171.0, 48.0); @@ -145,8 +150,7 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings) fColorsField->SetDivider(38.0); - fControlsBox->AddChild(fColorsField); - + fControlsBox->AddChild(fColorsField); fRefreshMenu = new BPopUpMenu("60 Hz", true, true); fRefreshMenu->AddItem(new BMenuItem("56 Hz", new BMessage(POP_REFRESH_MSG))); @@ -172,7 +176,7 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings) ButtonRect.Set(10.0, 167, 100.0, 200.0); fDefaultsButton = new BButton(ButtonRect, "DefaultsButton", "Defaults", - new BMessage(BUTTON_DEFAULTS_MSG)); + new BMessage(BUTTON_DEFAULTS_MSG)); fDefaultsButton->AttachedToWindow(); fDefaultsButton->ResizeToPreferred(); @@ -182,48 +186,42 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings) ButtonRect.Set(95.0, 167, 160.0, 200.0); fRevertButton = new BButton(ButtonRect, "RevertButton", "Revert", - new BMessage(BUTTON_REVERT_MSG)); + new BMessage(BUTTON_REVERT_MSG)); fRevertButton->AttachedToWindow(); fRevertButton->ResizeToPreferred(); fRevertButton->SetEnabled(false); fScreenView->AddChild(fRevertButton); - - BScreen *Screen = new BScreen(B_MAIN_SCREEN_ID); - + display_mode mode; - Screen->GetMode(&mode); + screen.GetMode(&mode); fInitialMode = mode; String.Truncate(0); - String << (int32)mode.virtual_width << " x " << (int32)mode.virtual_height; + String << (uint32)mode.virtual_width << " x " << (uint32)mode.virtual_height; Marked = fResolutionMenu->FindItem(String.String()); Marked->SetMarked(true); fInitialResolution = Marked; - if (mode.space == B_CMAP8) - { + if (mode.space == B_CMAP8){ Marked = fColorsMenu->FindItem("8 Bits/Pixel"); Marked->SetMarked(true); - } - if (mode.space == B_RGB15) - { + + } else if (mode.space == B_RGB15) { Marked = fColorsMenu->FindItem("15 Bits/Pixel"); Marked->SetMarked(true); - } - if (mode.space == B_RGB16) - { + + } else if (mode.space == B_RGB16) { Marked = fColorsMenu->FindItem("16 Bits/Pixel"); Marked->SetMarked(true); - } - if (mode.space == B_RGB32) - { + + } else if (mode.space == B_RGB32) { Marked = fColorsMenu->FindItem("32 Bits/Pixel"); Marked->SetMarked(true); } @@ -232,13 +230,13 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings) String.Truncate(0); - int32 total_size = mode.timing.h_total * mode.timing.v_total; + float total_size = mode.timing.h_total * mode.timing.v_total; - fInitialRefreshN = (mode.timing.pixel_clock * 1000) / total_size; + fInitialRefreshN = round((mode.timing.pixel_clock * 1000) / total_size, 1); fCustomRefresh = fInitialRefreshN; - String << (int32)fInitialRefreshN << " Hz"; + String << fInitialRefreshN << " Hz"; Marked = fRefreshMenu->FindItem(String.String()); if (Marked != NULL) @@ -246,16 +244,12 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings) Marked->SetMarked(true); fInitialRefresh = Marked; - } - else - { + } else { BMenuItem *Other = fRefreshMenu->FindItem("Other..."); String.Truncate(0); - float total_sizef = mode.timing.h_total * mode.timing.v_total; - - String << ((int32)mode.timing.pixel_clock * 1000) / total_sizef; + String << fInitialRefreshN; String.Truncate(4); @@ -277,76 +271,75 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings) ScreenWindow::~ScreenWindow() { delete fSettings; + delete[] fSupportedModes; } -bool ScreenWindow::QuitRequested() + +bool +ScreenWindow::QuitRequested() { be_app->PostMessage(B_QUIT_REQUESTED); - return(true); + return BWindow::QuitRequested(); } -void ScreenWindow::FrameMoved(BPoint position) + +void +ScreenWindow::FrameMoved(BPoint position) { fSettings->SetWindowFrame(Frame()); } -void ScreenWindow::ScreenChanged(BRect frame, color_space mode) + +void +ScreenWindow::ScreenChanged(BRect frame, color_space mode) { if (frame.right <= Frame().right && frame.bottom <= Frame().bottom) MoveTo(((frame.right / 2) - 178), ((frame.right / 2) - 101)); } -void ScreenWindow::WorkspaceActivated(int32 ws, bool state) + +void +ScreenWindow::WorkspaceActivated(int32 ws, bool state) { PostMessage(new BMessage(UPDATE_DESKTOP_COLOR_MSG), fScreenDrawView); } -void ScreenWindow::CheckApplyEnabled() + +void +ScreenWindow::CheckApplyEnabled() { int equals = 0; if (fResolutionMenu->FindMarked() == fInitialResolution) - { - equals = equals + 1; - } + equals++; else - { - equals = equals - 1; - } + equals--; if (fColorsMenu->FindMarked() == fInitialColors) - { - equals = equals + 1; - } + equals++; else - { - equals = equals - 1; - } + equals--; if (fRefreshMenu->FindMarked() == fInitialRefresh) - { - equals = equals + 1; - } + equals++; else - { - equals = equals - 1; - } - + equals--; + if(equals != 3) { fApplyButton->SetEnabled(true); fRevertButton->SetEnabled(true); - } - else - { + } else { fApplyButton->SetEnabled(false); fRevertButton->SetEnabled(false); } } -void ScreenWindow::MessageReceived(BMessage* message) + +void +ScreenWindow::MessageReceived(BMessage* message) { switch(message->what) { @@ -372,9 +365,7 @@ void ScreenWindow::MessageReceived(BMessage* message) BMessage *Message = new BMessage(UPDATE_DESKTOP_MSG); - const char *Resolution; - - Resolution = fResolutionMenu->FindMarked()->Label(); + const char *Resolution = fResolutionMenu->FindMarked()->Label(); Message->AddString("resolution", Resolution); @@ -402,12 +393,11 @@ void ScreenWindow::MessageReceived(BMessage* message) case POP_OTHER_REFRESH_MSG: { CheckApplyEnabled(); - - int32 Value; - - Value = (int32)fCustomRefresh; - - fRefreshWindow = new RefreshWindow(BRect((Frame().left + 201.0), (Frame().top + 34.0), (Frame().left + 509.0), (Frame().top + 169.0)), Value); + int32 value = (int32)(fCustomRefresh * 10); + + fRefreshWindow = new RefreshWindow(BRect((Frame().left + 201.0), + (Frame().top + 34.0), (Frame().left + 509.0), + (Frame().top + 169.0)), value); BMenuItem *Other = fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG); @@ -445,19 +435,19 @@ void ScreenWindow::MessageReceived(BMessage* message) if (fInitialRefresh == Other) { - BString String; + BString string; - String << fInitialRefreshN; + string << fInitialRefreshN; - String.Truncate(4); + string.Truncate(4); - String << " Hz/Other..."; + string << " Hz/Other..."; - fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)->SetLabel(String.String()); + fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)->SetLabel(string.String()); - String.Truncate(7); + string.Truncate(7); - fRefreshMenu->Superitem()->SetLabel(String.String()); + fRefreshMenu->Superitem()->SetLabel(string.String()); } break; @@ -465,607 +455,39 @@ void ScreenWindow::MessageReceived(BMessage* message) case BUTTON_APPLY_MSG: { - BScreen *Screen; + BScreen screen(B_MAIN_SCREEN_ID); - Screen = new BScreen(B_MAIN_SCREEN_ID); - - display_mode *modelist; + if (!screen.IsValid()) + break; + display_mode *mode = NULL; + BString string; + int32 height; + int32 width; + float refresh; + + BString menuLabel = fResolutionMenu->FindMarked()->Label(); + int32 space = menuLabel.FindFirst(' '); + menuLabel.MoveInto(string, 0, space); + menuLabel.Remove(0, 3); + width = atoi(string.String()); + height = atoi(menuLabel.String()); + refresh = atof(fRefreshMenu->FindMarked()->Label()); - uint32 count; - - Screen->GetModeList(&modelist, &count); - - uint32 loop = 0; - - count = count - 1; - - if (fResolutionMenu->FindMarked() == fResolutionMenu->FindItem("640 x 480")) - { - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("56 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 0) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 56 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("60 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 2) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 60 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("70 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 3) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 70 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("72 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 3) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 72 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("75 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 4) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 75 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 3) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (uint32) ((mode->timing.h_total * mode->timing.v_total) * fCustomRefresh / 1000); - } - } - else if (fResolutionMenu->FindMarked() == fResolutionMenu->FindItem("800 x 600")) + for(uint32 c = 0; c < fTotalModes; c++) { - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("56 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 6) - mode = modelist; - - modelist++; - } + if ((fSupportedModes[c].virtual_width == width) + && (fSupportedModes[c].virtual_height == height)) - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 56 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("60 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 8) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 60 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("70 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 9) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 70 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("72 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 9) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 72 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("75 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 10) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 75 / 1000; - } - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 8) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (uint32) ((mode->timing.h_total * mode->timing.v_total) * fCustomRefresh / 1000); - } + mode = &fSupportedModes[c]; } - else if (fResolutionMenu->FindMarked() == fResolutionMenu->FindItem("1024 x 768")) - { - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("56 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - if (loop == 11) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 56 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("60 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 13) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 60 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("70 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 14) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 70 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("72 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 14) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 72 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("75 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 15) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 75 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 13) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (uint32) ((mode->timing.h_total * mode->timing.v_total) * fCustomRefresh / 1000); - } - } - else if (fResolutionMenu->FindMarked() == fResolutionMenu->FindItem("1152 x 864")) - { - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("56 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 16) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 56 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("60 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 16) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 60 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("70 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 17) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 70 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("72 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 17) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 72 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("75 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 17) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 75 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 16) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (uint32) ((mode->timing.h_total * mode->timing.v_total) * fCustomRefresh / 1000); - } - } - else if (fResolutionMenu->FindMarked() == fResolutionMenu->FindItem("1280 x 1024")) - { - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("56 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 18) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 56 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("60 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 20) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 60 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("70 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 20) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 70 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("72 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 20) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 72 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("75 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 20) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 75 / 1000; - } - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 19) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (uint32) ((mode->timing.h_total * mode->timing.v_total) * fCustomRefresh / 1000); - } - } - else if (fResolutionMenu->FindMarked() == fResolutionMenu->FindItem("1600 x 1200")) - { - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("56 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 21) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 56 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("60 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 23) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 60 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("70 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 24) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 70 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("72 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 24) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 72 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem("75 Hz")) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 25) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (mode->timing.h_total * mode->timing.v_total) * 75 / 1000; - } - - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) - { - for (loop = 0; loop <= count; loop++) - { - if (mode != NULL) - break; - - if (loop == 22) - mode = modelist; - - modelist++; - } - - mode->timing.pixel_clock = (uint32) ((mode->timing.h_total * mode->timing.v_total) * fCustomRefresh / 1000); - } - } + if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) + mode->timing.pixel_clock = (uint32)((mode->timing.h_total * mode->timing.v_total) * fCustomRefresh / 1000); + else + mode->timing.pixel_clock = (uint32)((mode->timing.h_total * mode->timing.v_total) * refresh / 1000); + + if (fColorsMenu->FindMarked() == fColorsMenu->FindItem("8 Bits/Pixel")) { @@ -1098,32 +520,31 @@ This action cannot be reverted", "Okay", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WAR if (button == 1) break; - int32 count, old; + int32 old = current_workspace(); + int32 totalWorkspaces = count_workspaces(); - old = current_workspace(); - - for (count = 0; count < count_workspaces(); count ++) + for (int32 count = 0; count < totalWorkspaces; count ++) { activate_workspace(count); - Screen->SetMode(mode); + screen.SetMode(mode); } activate_workspace(old); } else - Screen->SetMode(mode); + screen.SetMode(mode); - BRect Rect; - - Rect.Set(100.0, 100.0, 400.0, 193.0); + BRect Rect(100.0, 100.0, 400.0, 193.0); - Rect.left = (Screen->Frame().right / 2) - 150; - Rect.top = (Screen->Frame().bottom / 2) - 42; + Rect.left = (screen.Frame().right / 2) - 150; + Rect.top = (screen.Frame().bottom / 2) - 42; Rect.right = Rect.left + 300.0; Rect.bottom = Rect.top + 93.0; new AlertWindow(Rect); - + + fApplyButton->SetEnabled(false); + break; } @@ -1149,11 +570,8 @@ This action cannot be reverted", "Okay", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WAR fRefreshMenu->Superitem()->SetLabel(String.String()); } - BScreen *Screen; - - Screen = new BScreen(B_MAIN_SCREEN_ID); - - Screen->SetMode(&fInitialMode); + BScreen screen(B_MAIN_SCREEN_ID); + screen.SetMode(&fInitialMode); break; } @@ -1191,13 +609,10 @@ This action cannot be reverted", "Okay", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WAR case MAKE_INITIAL_MSG: { - BScreen *Screen; + BScreen screen(B_MAIN_SCREEN_ID); + display_mode mode; - display_mode mode; - - Screen = new BScreen(B_MAIN_SCREEN_ID); - - Screen->GetMode(&mode); + screen.GetMode(&mode); fInitialRefreshN = fCustomRefresh; fInitialResolution = fResolutionMenu->FindMarked(); @@ -1209,8 +624,7 @@ This action cannot be reverted", "Okay", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WAR } default: - BWindow::MessageReceived(message); - + BWindow::MessageReceived(message); break; } } diff --git a/src/prefs/screen/ScreenWindow.h b/src/prefs/screen/ScreenWindow.h index 2d3bc4498d..252088d0a2 100644 --- a/src/prefs/screen/ScreenWindow.h +++ b/src/prefs/screen/ScreenWindow.h @@ -16,13 +16,13 @@ class ScreenWindow : public BWindow { public: - ScreenWindow(ScreenSettings *Settings); - virtual ~ScreenWindow(); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *message); - virtual void WorkspaceActivated(int32 ws, bool state); - virtual void FrameMoved(BPoint position); - virtual void ScreenChanged(BRect frame, color_space mode); + ScreenWindow(ScreenSettings *Settings); + virtual ~ScreenWindow(); + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage *message); + virtual void WorkspaceActivated(int32 ws, bool state); + virtual void FrameMoved(BPoint position); + virtual void ScreenChanged(BRect frame, color_space mode); private: void CheckApplyEnabled(); @@ -51,6 +51,8 @@ private: BMenuItem *fInitialColors; BMenuItem *fInitialRefresh; display_mode fInitialMode; + display_mode *fSupportedModes; + uint32 fTotalModes; float fCustomRefresh; float fInitialRefreshN; };