From f99cf5726bdf16a249ddf90fdeb8feef6c36ce20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sundstr=C3=B6m?= Date: Thu, 13 Aug 2009 21:00:53 +0000 Subject: [PATCH] Using the new layout facilities the window resizes madly while zipping. Fun fun fun. Advice welcome. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32331 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/tracker/zipomatic/Jamfile | 1 - src/add-ons/tracker/zipomatic/ZipOMatic.cpp | 2 +- .../tracker/zipomatic/ZipOMaticView.cpp | 82 ---------------- src/add-ons/tracker/zipomatic/ZipOMaticView.h | 27 ----- .../tracker/zipomatic/ZipOMaticWindow.cpp | 98 +++++++++++-------- .../tracker/zipomatic/ZipOMaticWindow.h | 14 +-- 6 files changed, 65 insertions(+), 159 deletions(-) delete mode 100644 src/add-ons/tracker/zipomatic/ZipOMaticView.cpp delete mode 100644 src/add-ons/tracker/zipomatic/ZipOMaticView.h diff --git a/src/add-ons/tracker/zipomatic/Jamfile b/src/add-ons/tracker/zipomatic/Jamfile index 242eec92a9..a4381dd7fd 100644 --- a/src/add-ons/tracker/zipomatic/Jamfile +++ b/src/add-ons/tracker/zipomatic/Jamfile @@ -6,7 +6,6 @@ Application ZipOMatic-Z : ZipOMaticActivity.cpp ZipOMaticMisc.cpp ZipOMaticSettings.cpp - ZipOMaticView.cpp ZipOMaticWindow.cpp ZipperThread.cpp diff --git a/src/add-ons/tracker/zipomatic/ZipOMatic.cpp b/src/add-ons/tracker/zipomatic/ZipOMatic.cpp index 9a5af4a95a..95d5843833 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMatic.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMatic.cpp @@ -128,7 +128,7 @@ ZipOMatic::QuitRequested (void) BWindow* window; ZippoWindow* zippo; - ZippoWindow* lastFoundZippo; + ZippoWindow* lastFoundZippo = NULL; int32 zippoCount = 0; for (int32 i = 0;; i++) { diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticView.cpp b/src/add-ons/tracker/zipomatic/ZipOMaticView.cpp deleted file mode 100644 index edc045576b..0000000000 --- a/src/add-ons/tracker/zipomatic/ZipOMaticView.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// license: public domain -// authors: Jonas Sundström, jonas@kirilla.com - - -#include "ZipOMaticView.h" - - -ZippoView::ZippoView(BRect rect) - : - BBox(rect, "zipomatic_view", B_FOLLOW_ALL, - B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER), - fStopButton(NULL) -{ - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - fStopButton = new BButton( - BRect(rect.right-82, rect.bottom-32, rect.right-12, rect.bottom-12), - "stop_button", "Stop", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT); - fStopButton->SetEnabled(false); - AddChild(fStopButton); - - BRect activity_rect(rect.left+14, rect.top+15, rect.right-15, rect.top+31); - fActivityView = new Activity(activity_rect, "activity_view", - B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS); - AddChild(fActivityView); - - BRect archive_rect(rect.left+14, rect.top+30, rect.right-15, rect.top+47); - fArchiveNameView = new BStringView(archive_rect, "archive_text", " ", - B_FOLLOW_LEFT_RIGHT); - AddChild(fArchiveNameView); - - BRect ouput_rect(rect.left+14, rect.top+47, rect.right-15, rect.top+66); - fZipOutputView = new BStringView(ouput_rect, "output_text", - "Drop files to zip.", B_FOLLOW_LEFT_RIGHT); - AddChild(fZipOutputView); -} - - -void ZippoView::Draw(BRect rect) -{ - BBox::Draw(rect); - - const rgb_color grey_accent = {128,128,128,255}; - const rgb_color darker_grey = {108,108,108,255}; - const rgb_color plain_white = {255,255,255,255}; - const rgb_color black = {0, 0, 0, 255}; - - // "preflet" bottom, right grey accent lines - SetHighColor(grey_accent); - - StrokeLine(BPoint(Bounds().right, Bounds().top), - BPoint(Bounds().right, Bounds().bottom)); - - StrokeLine(BPoint(Bounds().left, Bounds().bottom), - BPoint(Bounds().right, Bounds().bottom)); - - // divider - SetHighColor(darker_grey); - StrokeLine(BPoint(Bounds().left+15, Bounds().top+71), - BPoint(Bounds().right-16, Bounds().top+71)); - - SetHighColor(plain_white); - StrokeLine(BPoint(Bounds().left+15, Bounds().top+72), - BPoint(Bounds().right-16, Bounds().top+72)); - - SetHighColor(black); -} - - -void -ZippoView::FrameMoved(BPoint point) -{ - Invalidate(); -} - - -void -ZippoView::FrameResized(float width, float height) -{ - Invalidate(); -} - diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticView.h b/src/add-ons/tracker/zipomatic/ZipOMaticView.h deleted file mode 100644 index ac394a9e10..0000000000 --- a/src/add-ons/tracker/zipomatic/ZipOMaticView.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __ZIPPO_VIEW_H__ -#define __ZIPPO_VIEW_H__ - -#include -#include -#include - -#include "ZipOMaticActivity.h" - - -class ZippoView : public BBox -{ -public: - ZippoView(BRect frame); - - virtual void Draw(BRect frame); - virtual void FrameMoved(BPoint point); - virtual void FrameResized(float width, float height); - - BButton* fStopButton; - Activity* fActivityView; - BStringView* fArchiveNameView; - BStringView* fZipOutputView; -}; - -#endif // __ZIPPO_VIEW_H__ - diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticWindow.cpp b/src/add-ons/tracker/zipomatic/ZipOMaticWindow.cpp index 49acb85a55..887f31e355 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticWindow.cpp +++ b/src/add-ons/tracker/zipomatic/ZipOMaticWindow.cpp @@ -12,37 +12,63 @@ #include #include +#include #include #include #include #include -#include +#include +#include #include #include +#include #include #include "ZipOMatic.h" #include "ZipOMaticActivity.h" #include "ZipOMaticMisc.h" -#include "ZipOMaticView.h" #include "ZipperThread.h" ZippoWindow::ZippoWindow(BRect frame, BMessage* refs) : - BWindow(frame, "Zip-O-Matic", B_TITLED_WINDOW, B_NOT_V_RESIZABLE), - fView(NULL), + BWindow(frame, "Zip-O-Matic", B_TITLED_WINDOW, B_NOT_V_RESIZABLE + | B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE), fThread(NULL), fWindowGotRefs(false), fZippingWasStopped(false), fWindowInvoker(new BInvoker(new BMessage(ZIPPO_QUIT_OR_CONTINUE), NULL, this)) { - fView = new ZippoView(Bounds()); - AddChild(fView); - - SetSizeLimits(Bounds().Width(), 15000, Bounds().Height(), - Bounds().Height()); + fActivityView = new Activity(BRect(0, 0, 171, 17), "activity", + B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS); + fActivityView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 17)); + fActivityView->SetExplicitMinSize(BSize(171, 17)); + + fArchiveNameView = new BStringView("archive_text", ""); + fArchiveNameView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, + B_ALIGN_VERTICAL_UNSET)); + + fZipOutputView = new BStringView("output_text", "Drop files to zip."); + fZipOutputView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, + B_ALIGN_VERTICAL_UNSET)); + + fStopButton = new BButton("stop", "Stop", new BMessage(B_QUIT_REQUESTED)); + fStopButton->SetEnabled(false); + fStopButton->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, + B_ALIGN_VERTICAL_UNSET)); + + BSeparatorView* separator = new BSeparatorView(B_HORIZONTAL); + + SetLayout(new BGroupLayout(B_VERTICAL)); + AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) + .Add(fActivityView) + .Add(fArchiveNameView) + .Add(fZipOutputView) + .Add(separator) + .Add(fStopButton) + .SetInsets(14, 14, 14, 14) + ); if (refs != NULL) { @@ -77,13 +103,13 @@ ZippoWindow::MessageReceived(BMessage* message) case ZIPPO_THREAD_EXIT: fThread = NULL; - fView->fActivityView->Stop(); - fView->fStopButton->SetEnabled(false); - fView->fArchiveNameView->SetText(" "); + fActivityView->Stop(); + fStopButton->SetEnabled(false); + fArchiveNameView->SetText(" "); if (fZippingWasStopped) - fView->fZipOutputView->SetText("Stopped"); + fZipOutputView->SetText("Stopped"); else - fView->fZipOutputView->SetText("Archive created OK"); + fZipOutputView->SetText("Archive created OK"); _CloseWindowOrKeepOpen(); break; @@ -91,17 +117,17 @@ ZippoWindow::MessageReceived(BMessage* message) case ZIPPO_THREAD_EXIT_ERROR: // TODO: figure out why this case does not happen when it should fThread = NULL; - fView->fActivityView->Stop(); - fView->fStopButton->SetEnabled(false); - fView->fArchiveNameView->SetText(""); - fView->fZipOutputView->SetText("Error creating archive"); + fActivityView->Stop(); + fStopButton->SetEnabled(false); + fArchiveNameView->SetText(""); + fZipOutputView->SetText("Error creating archive"); break; case ZIPPO_TASK_DESCRIPTION: { BString string; if (message->FindString("archive_filename", &string) == B_OK) - fView->fArchiveNameView->SetText(string.String()); + fArchiveNameView->SetText(string.String()); break; } @@ -109,7 +135,7 @@ ZippoWindow::MessageReceived(BMessage* message) { BString string; if (message->FindString("zip_output", &string) == B_OK) - fView->fZipOutputView->SetText(string.String()); + fZipOutputView->SetText(string.String()); break; } @@ -123,7 +149,7 @@ ZippoWindow::MessageReceived(BMessage* message) if (fThread != NULL) fThread->ResumeExternalZip(); - fView->fActivityView->Start(); + fActivityView->Start(); } } break; @@ -146,7 +172,7 @@ ZippoWindow::QuitRequested() return true; } else { fThread->SuspendExternalZip(); - fView->fActivityView->Pause(); + fActivityView->Pause(); BAlert* alert = new BAlert("Stop or Continue", "Are you sure you want to stop creating this archive?", "Stop", @@ -161,8 +187,8 @@ ZippoWindow::QuitRequested() void ZippoWindow::_StartZipping(BMessage* message) { - fView->fStopButton->SetEnabled(true); - fView->fActivityView->Start(); + fStopButton->SetEnabled(true); + fActivityView->Start(); fThread = new ZipperThread(message, this); fThread->Start(); @@ -176,8 +202,8 @@ ZippoWindow::StopZipping() { fZippingWasStopped = true; - fView->fStopButton->SetEnabled(false); - fView->fActivityView->Stop(); + fStopButton->SetEnabled(false); + fActivityView->Stop(); fThread->InterruptExternalZip(); fThread->Quit(); @@ -186,8 +212,8 @@ ZippoWindow::StopZipping() fThread->WaitForThread(&status); fThread = NULL; - fView->fArchiveNameView->SetText(" "); - fView->fZipOutputView->SetText("Stopped"); + fArchiveNameView->SetText(" "); + fZipOutputView->SetText("Stopped"); _CloseWindowOrKeepOpen(); } @@ -214,19 +240,7 @@ ZippoWindow::_CloseWindowOrKeepOpen() void ZippoWindow::Zoom(BPoint origin, float width, float height) { - if (IsZipping()) { - float archiveNameWidth = - fView->StringWidth(fView->fArchiveNameView->Text()); - float zipOutputWidth = - fView->StringWidth(fView->fZipOutputView->Text()); - - if (zipOutputWidth > archiveNameWidth) - ResizeTo(zipOutputWidth, Bounds().Height()); - else - ResizeTo(archiveNameWidth, Bounds().Height()); - - } else { - ResizeTo(230,110); - } + // TODO: Think about removing this method when + // zipomatic's new layout code works right. } diff --git a/src/add-ons/tracker/zipomatic/ZipOMaticWindow.h b/src/add-ons/tracker/zipomatic/ZipOMaticWindow.h index 18c9f14af0..03898bc269 100644 --- a/src/add-ons/tracker/zipomatic/ZipOMaticWindow.h +++ b/src/add-ons/tracker/zipomatic/ZipOMaticWindow.h @@ -2,13 +2,11 @@ #define _ZIPOMATIC_WINDOW_H -#include -#include -#include -#include +#include +#include #include -#include "ZipOMaticView.h" +#include "ZipOMaticActivity.h" #include "ZipperThread.h" @@ -30,7 +28,11 @@ private: void _StartZipping(BMessage* message); void _CloseWindowOrKeepOpen(); - ZippoView* fView; + Activity* fActivityView; + BStringView* fArchiveNameView; + BStringView* fZipOutputView; + BButton* fStopButton; + ZipperThread* fThread; bool fWindowGotRefs;