Added 'Go to page' control. Contributed by Hartmut Reh.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10658 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -29,6 +29,8 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
@@ -255,6 +257,20 @@ void PreviewView::ShowLastPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewView::ShowFindPage(int page) {
|
||||||
|
page --;
|
||||||
|
|
||||||
|
if (page < 0) {
|
||||||
|
page = 0;
|
||||||
|
} else if (page > (NumberOfPages()-1)) {
|
||||||
|
page = NumberOfPages()-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fPage = (int32)page;
|
||||||
|
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
bool PreviewView::CanZoomIn() const {
|
bool PreviewView::CanZoomIn() const {
|
||||||
return fZoom < 4;
|
return fZoom < 4;
|
||||||
}
|
}
|
||||||
@@ -351,11 +367,26 @@ PreviewWindow::PreviewWindow(BFile* jobFile)
|
|||||||
fLast->ResizeTo(width, height);
|
fLast->ResizeTo(width, height);
|
||||||
left = fLast->Frame().right + kPageTextDistance;
|
left = fLast->Frame().right + kPageTextDistance;
|
||||||
|
|
||||||
|
// page number text
|
||||||
|
fPageNumber = new BTextControl(BRect(left, top+3, left+10, top+10), "FindPage", "", "", new BMessage(MSG_FIND_PAGE));
|
||||||
|
fPageNumber->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_RIGHT);
|
||||||
|
int num;
|
||||||
|
for (num = 0; num <= 255; num++) {
|
||||||
|
fPageNumber->TextView()->DisallowChar(num);
|
||||||
|
}
|
||||||
|
for (num = 0; num <= 9; num++) {
|
||||||
|
fPageNumber->TextView()->AllowChar('0' + num);
|
||||||
|
}
|
||||||
|
fPageNumber->TextView()-> SetMaxBytes(5);
|
||||||
|
AddChild(fPageNumber);
|
||||||
|
fPageNumber->ResizeTo(be_plain_font->StringWidth("999999") + 10, height);
|
||||||
|
left = fPageNumber->Frame().right + 5;
|
||||||
|
|
||||||
|
// number of pages text
|
||||||
fPageText = new BStringView(BRect(left, top, left + 100, top + 15), "pageText", "");
|
fPageText = new BStringView(BRect(left, top, left + 100, top + 15), "pageText", "");
|
||||||
fPageText->SetAlignment(B_ALIGN_CENTER);
|
|
||||||
AddChild(fPageText);
|
AddChild(fPageText);
|
||||||
// estimate max. width
|
// estimate max. width
|
||||||
float pageTextWidth = fPageText->StringWidth("Page 99999 of 99999 Pages");
|
float pageTextWidth = fPageText->StringWidth("of 99999 Pages");
|
||||||
// estimate height
|
// estimate height
|
||||||
BFont font;
|
BFont font;
|
||||||
fPageText->GetFont(&font);
|
fPageText->GetFont(&font);
|
||||||
@@ -431,17 +462,19 @@ void PreviewWindow::UpdateControls() {
|
|||||||
fZoomIn->SetEnabled(fPreview->CanZoomIn());
|
fZoomIn->SetEnabled(fPreview->CanZoomIn());
|
||||||
fZoomOut->SetEnabled(fPreview->CanZoomOut());
|
fZoomOut->SetEnabled(fPreview->CanZoomOut());
|
||||||
|
|
||||||
BString text("Page ");
|
BString page;
|
||||||
text << fPreview->CurrentPage()
|
page << fPreview->CurrentPage();
|
||||||
<< " of "
|
fPageNumber->SetText(page.String());
|
||||||
|
|
||||||
|
BString text;
|
||||||
|
text << "of "
|
||||||
<< fPreview->NumberOfPages();
|
<< fPreview->NumberOfPages();
|
||||||
if (fPreview->NumberOfPages() == 1) {
|
if (fPreview->NumberOfPages() == 1) {
|
||||||
text << " Page";
|
text << " Page";
|
||||||
} else {
|
} else {
|
||||||
text << " Pages";
|
text << " Pages";
|
||||||
}
|
}
|
||||||
fPageText->SetText(text.String());
|
fPageText->SetText(text.String());}
|
||||||
}
|
|
||||||
|
|
||||||
void PreviewWindow::MessageReceived(BMessage* m) {
|
void PreviewWindow::MessageReceived(BMessage* m) {
|
||||||
switch (m->what) {
|
switch (m->what) {
|
||||||
@@ -457,6 +490,9 @@ void PreviewWindow::MessageReceived(BMessage* m) {
|
|||||||
case MSG_LAST_PAGE:
|
case MSG_LAST_PAGE:
|
||||||
fPreview->ShowLastPage();
|
fPreview->ShowLastPage();
|
||||||
break;
|
break;
|
||||||
|
case MSG_FIND_PAGE:
|
||||||
|
fPreview->ShowFindPage(atoi(fPageNumber->Text())) ;
|
||||||
|
break;
|
||||||
case MSG_ZOOM_IN:
|
case MSG_ZOOM_IN:
|
||||||
fPreview->ZoomIn();
|
fPreview->ZoomIn();
|
||||||
ResizeToPage();
|
ResizeToPage();
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public:
|
|||||||
void ShowPrevPage();
|
void ShowPrevPage();
|
||||||
void ShowFirstPage();
|
void ShowFirstPage();
|
||||||
void ShowLastPage();
|
void ShowLastPage();
|
||||||
|
void ShowFindPage(int page);
|
||||||
|
|
||||||
bool CanZoomIn() const;
|
bool CanZoomIn() const;
|
||||||
bool CanZoomOut() const;
|
bool CanZoomOut() const;
|
||||||
@@ -99,9 +100,10 @@ class PreviewWindow : public BlockingWindow {
|
|||||||
BButton *fLast;
|
BButton *fLast;
|
||||||
BButton *fZoomIn;
|
BButton *fZoomIn;
|
||||||
BButton *fZoomOut;
|
BButton *fZoomOut;
|
||||||
BStringView* fPageText;
|
BTextControl *fPageNumber;
|
||||||
PreviewView* fPreview;
|
BStringView *fPageText;
|
||||||
BScrollView* fPreviewScroller;
|
PreviewView *fPreview;
|
||||||
|
BScrollView *fPreviewScroller;
|
||||||
float fButtonBarHeight;
|
float fButtonBarHeight;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -109,6 +111,7 @@ class PreviewWindow : public BlockingWindow {
|
|||||||
MSG_NEXT_PAGE = 'pwnp',
|
MSG_NEXT_PAGE = 'pwnp',
|
||||||
MSG_PREV_PAGE = 'pwpp',
|
MSG_PREV_PAGE = 'pwpp',
|
||||||
MSG_LAST_PAGE = 'pwlp',
|
MSG_LAST_PAGE = 'pwlp',
|
||||||
|
MSG_FIND_PAGE = 'pwsp',
|
||||||
MSG_ZOOM_IN = 'pwzi',
|
MSG_ZOOM_IN = 'pwzi',
|
||||||
MSG_ZOOM_OUT = 'pwzo',
|
MSG_ZOOM_OUT = 'pwzo',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user