Skip to content

Commit

Permalink
Customize window tab's Zoom button
Browse files Browse the repository at this point in the history
You never need the whole screen width; that only makes all the
textboxes extremely wide. You want to see as many rows of the
transaction list as possible.
So, instead of going full-screen, only maximize the height when
clicking the Zoom button in the window tab.

We save the un-Zoomed size/position of the window and return to
its position and height when clicking Zoom again. We keep the
width of the max-Zoomed state, because you probably want to keep it,
if you changed it while being max-Zoomed.

We save the Zoom state and restore it on the next launch.
  • Loading branch information
humdingerb committed Sep 29, 2024
1 parent db8a2e3 commit f4e9d9e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/DateBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,9 @@ DateBox::Validate(const bool& alert)
gDefaultLocale.DateToString(fCurrentDate, date);
SetText(date.String());
}

bool valid = fCurrentDate > GetCurrentDate();
MarkAsInvalid(valid);

return true;
}
50 changes: 44 additions & 6 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <Resources.h>
#include <Roster.h>
#include <StringFormat.h>
#include <Screen.h>
#include <Url.h>

#include <stdlib.h>
Expand Down Expand Up @@ -98,7 +99,9 @@ LedgerFileFilter::IsValid(const entry_ref* ref, const BEntry* entry)

MainWindow::MainWindow(BRect frame, BPath lastFile)
: BWindow(frame, NULL, B_DOCUMENT_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS),
fLastFile(lastFile.Path())
fLastFile(lastFile.Path()),
fFrameBeforeZoom(frame),
fIsZoomed(false)
{
BString title = B_TRANSLATE_SYSTEM_NAME("CapitalBe");
title << ": " << lastFile.Leaf();
Expand All @@ -107,9 +110,8 @@ MainWindow::MainWindow(BRect frame, BPath lastFile)
if (gPreferences.FindColor("negativecolor", &gNegativeColor) != B_OK)
gNegativeColor = ui_color(B_FAILURE_COLOR);

BRect winFrame = frame;
int32 selectAcc = 0;
_GetFileSettings(&winFrame, &selectAcc);
_GetFileSettings(&fFrameBeforeZoom, &selectAcc);

AddShortcut(B_HOME, B_COMMAND_KEY, new BMessage(M_FIRST_TRANSACTION));
AddShortcut(B_END, B_COMMAND_KEY, new BMessage(M_LAST_TRANSACTION));
Expand Down Expand Up @@ -262,8 +264,15 @@ MainWindow::MainWindow(BRect frame, BPath lastFile)

clearFilter->SetTarget(FindView("registerview")->FindView("filterview"));

MoveTo(winFrame.LeftTop());
ResizeTo(winFrame.Width(), winFrame.Height());
MoveTo(fFrameBeforeZoom.LeftTop());
ResizeTo(fFrameBeforeZoom.Width(), fFrameBeforeZoom.Height());

// If file was zoomed when closing last, zoom it again at launch
if (fIsZoomed) {
fIsZoomed = false;
BWindow::Zoom();
}

HandleScheduledTransactions();
BMessage message(M_RUN_SCHEDULED_TRANSACTIONS);
fRunner = new BMessageRunner(this, &message, 30 * 1000 * 1000); // Every 30 seconds
Expand Down Expand Up @@ -718,13 +727,36 @@ MainWindow::MessageReceived(BMessage* msg)
}


void
MainWindow::Zoom(BPoint /*origin*/, float /*width*/, float /*height*/)
{
BRect frame = Frame();
if (!fIsZoomed) {
fIsZoomed = true;
fFrameBeforeZoom = frame;
BScreen screen(this);
BRect screenFrame(screen.Frame());

MoveTo(BPoint(fFrameBeforeZoom.left, 0));
ResizeTo(fFrameBeforeZoom.Width(), screenFrame.Height());
MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN);
} else {
fIsZoomed = false;
MoveTo(BPoint(frame.left, fFrameBeforeZoom.top));
ResizeTo(frame.Width(), fFrameBeforeZoom.Height());
}
}


void
MainWindow::_GetFileSettings(BRect* winFrame, int32* selectAcc)
{
BNode node(fLastFile);
if (node.InitCheck() != B_OK)
return;

node.ReadAttr("window_zoom", B_BOOL_TYPE, 0, &fIsZoomed, sizeof(bool));

ssize_t bytesRead;
BRect frame;
bytesRead = node.ReadAttr("window_frame", B_RECT_TYPE, 0, &frame, sizeof(BRect));
Expand All @@ -749,7 +781,13 @@ MainWindow::_SetFileSettings()
if (accList != NULL)
select = accList->CurrentSelection();

BRect frame(Frame());
BRect frame;
if (fIsZoomed)
frame = fFrameBeforeZoom;
else
frame = Frame();

node.WriteAttr("window_zoom", B_BOOL_TYPE, 0, &fIsZoomed, sizeof(bool));
node.WriteAttr("window_frame", B_RECT_TYPE, 0, &frame, sizeof(BRect));
node.WriteAttr("select_account", B_INT32_TYPE, 0, &select, sizeof(int32));
}
Expand Down
8 changes: 6 additions & 2 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ class MainWindow : public BWindow, public Observer {
MainWindow(BRect frame, BPath lastFile);
~MainWindow();

bool QuitRequested();
void MessageReceived(BMessage* msg);
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* msg);
virtual void Zoom(BPoint origin, float width, float height);

void HandleNotify(const uint64& value, const BMessage* msg);
void OpenAbout();
Expand All @@ -111,6 +112,9 @@ class MainWindow : public BWindow, public Observer {
BString fLastFile;
BMenuItem* fAccountClosedItem;
BMessageRunner* fRunner;

BRect fFrameBeforeZoom;
bool fIsZoomed;
};

#endif
1 change: 1 addition & 0 deletions src/TransactionItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ TransactionItem::DrawItem(BView* owner, BRect frame, bool complete)
clip = cliprect;
owner->ConstrainClippingRegion(&clip);
locale.DateToString(fDate, string);

owner->DrawString(string.String(), BPoint(xpos, ypos - fontFactor));
owner->ConstrainClippingRegion(NULL);

Expand Down

0 comments on commit f4e9d9e

Please sign in to comment.