2 * Copyright 2005-2006, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
9 #include "StatusWindow.h"
12 #include <GroupLayout.h>
13 #include <GroupLayoutBuilder.h>
16 #include <StatusBar.h>
18 #include <StringView.h>
21 #define CANCEL_MSG 'canM'
22 #define HIDE_MSG 'hidM'
25 StatusWindow::StatusWindow(bool oddPages
, bool evenPages
, uint32 firstPage
,
26 uint32 numPages
, uint32 numCopies
, uint32 nup
)
28 BWindow(BRect(200, 200, 250, 250),
31 B_NOT_RESIZABLE
| B_NOT_CLOSABLE
| B_NOT_ZOOMABLE
32 | B_AUTO_UPDATE_SIZE_LIMITS
)
34 // oddPages - if true, only print odd numbered pages
35 // evenPages - if true, only print even numbered pages
36 // firstPage - number of first page
37 // numPages - total number of pages (must be recalculate if odd/even is
39 // numCopies - total number of document copies
42 fStatusBar
= new BStatusBar("statusBar", "Page: ");
45 fHideButton
= new BButton("hideButton", "Hide Status",
46 new BMessage(HIDE_MSG
));
48 fCancelButton
= new BButton("cancelButton", "Cancel",
49 new BMessage(CANCEL_MSG
));
51 SetLayout(new BGroupLayout(B_VERTICAL
));
52 AddChild(BGroupLayoutBuilder(B_HORIZONTAL
, 10)
56 .SetInsets(10, 10, 10, 10)
62 // calculate the real number of pages
65 bool evenFirstPage
= (firstPage
% 2) == 0;
66 bool evenNumPages
= (numPages
% 2) == 0;
68 // recalculate page numbers if even or odd is used
69 if (oddPages
|| evenPages
) {
72 } else if (evenFirstPage
) {
74 fNops
= (numPages
- 1) / 2;
76 fNops
= (numPages
+ 1) / 2;
79 fNops
= (numPages
+ 1) / 2;
81 fNops
= (numPages
- 1) / 2;
88 fNops
= (uint32
)(fNops
/ (float)nup
) + addPage
;
89 // recalculate page numbers nup-pages-up
91 fStatusBar
->SetMaxValue((float)fNops
);
92 // max value of status bar = real number of pages
93 fDelta
= 1.0/numCopies
;
94 // reduce step width of status bar
95 fStatusDelta
= fDelta
;
96 fDocCopies
= numCopies
;
98 fDocumentCopy
= fDocCopies
> 1;
107 StatusWindow::~StatusWindow(void)
113 StatusWindow::ResetStatusBar(void)
116 fStatusBar
->Reset("Page: ");
117 InvalidateLayout(true);
123 StatusWindow::UpdateStatusBar(uint32 page
, uint32 copy
)
130 sprintf(buffer
,"%d", (int)(page
+ 1));
131 BString
string1(buffer
);
133 sprintf(buffer
,"%d",(int)fNops
);
134 BString
string2(buffer
);
135 string1
.Append(BString(" / "));
136 string1
.Append(string2
);
138 BString string3
= BString("Remaining Document Copies: ");
139 if (fDocumentCopy
== true) {
140 sprintf(buffer
, "%d", (int)(fDocCopies
));
141 BString
string4(buffer
);
142 string3
.Append(string4
);
144 string3
= BString("Remaining Page Copies: ");
146 sprintf(buffer
,"%d",(int)(fCopies
- copy
) );
147 BString
string4(buffer
);
148 string3
.Append(string4
);
151 fStatusBar
->Update(fStatusDelta
* 100.0 / fNops
,
152 string1
.String(), string3
.String());
153 if (fStatusBar
->MaxValue() == fStatusBar
->CurrentValue())
154 fCancelButton
->SetEnabled(false);
156 InvalidateLayout(true);
163 StatusWindow::SetPageCopies(uint32 copies
)
166 fStatusDelta
= fDelta
/ (float)fCopies
;
171 // Handling of user interface and other events
173 StatusWindow::MessageReceived(BMessage
*message
)
176 switch(message
->what
) {
177 case CANCEL_MSG
: // 'CancelButton' is pressed...
179 fCancelButton
->SetEnabled(false);
180 fCancelButton
->SetLabel("Job cancelled");
181 InvalidateLayout(true);
184 case HIDE_MSG
: // 'HideButton' is pressed...
189 BWindow::MessageReceived(message
);