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
This commit is contained in:
Jonas Sundström 2009-08-13 21:00:53 +00:00
parent 38ec40dcbe
commit f99cf5726b
6 changed files with 65 additions and 159 deletions

View File

@ -6,7 +6,6 @@ Application ZipOMatic-Z :
ZipOMaticActivity.cpp
ZipOMaticMisc.cpp
ZipOMaticSettings.cpp
ZipOMaticView.cpp
ZipOMaticWindow.cpp
ZipperThread.cpp

View File

@ -128,7 +128,7 @@ ZipOMatic::QuitRequested (void)
BWindow* window;
ZippoWindow* zippo;
ZippoWindow* lastFoundZippo;
ZippoWindow* lastFoundZippo = NULL;
int32 zippoCount = 0;
for (int32 i = 0;; i++) {

View File

@ -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();
}

View File

@ -1,27 +0,0 @@
#ifndef __ZIPPO_VIEW_H__
#define __ZIPPO_VIEW_H__
#include <Box.h>
#include <Button.h>
#include <StringView.h>
#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__

View File

@ -12,37 +12,63 @@
#include <stdio.h>
#include <stdlib.h>
#include <Alert.h>
#include <Application.h>
#include <Directory.h>
#include <File.h>
#include <FindDirectory.h>
#include <InterfaceKit.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <Path.h>
#include <Roster.h>
#include <SeparatorView.h>
#include <String.h>
#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.
}

View File

@ -2,13 +2,11 @@
#define _ZIPOMATIC_WINDOW_H
#include <Bitmap.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Button.h>
#include <StringView.h>
#include <Window.h>
#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;