Change to have a more consistent coding style, eliminated unused / unessecary code, added MIT license notice, prevented image window from closing when a save panel is open, prevented the user from opening multiple save panels for a single image window, etc.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4214 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageApp
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageApp.cpp
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Alert.h>
|
||||
@@ -10,7 +34,7 @@
|
||||
#include "ShowImageApp.h"
|
||||
#include "ShowImageWindow.h"
|
||||
|
||||
int main(int, char**)
|
||||
int main(int, char **)
|
||||
{
|
||||
ShowImageApp theApp;
|
||||
theApp.Run();
|
||||
@@ -23,20 +47,22 @@ ShowImageApp::ShowImageApp()
|
||||
: BApplication(APP_SIG)
|
||||
{
|
||||
fbpulseStarted = false;
|
||||
m_pOpenPanel = new BFilePanel(B_OPEN_PANEL);
|
||||
fpopenPanel = new BFilePanel(B_OPEN_PANEL);
|
||||
}
|
||||
|
||||
void ShowImageApp::AboutRequested()
|
||||
void
|
||||
ShowImageApp::AboutRequested()
|
||||
{
|
||||
BAlert* pAlert = new BAlert("About ShowImage",
|
||||
"OBOS ShowImage\n\nby Fernando F. Oliveira and Michael Wilber", "OK");
|
||||
pAlert->Go();
|
||||
}
|
||||
|
||||
void ShowImageApp::ReadyToRun()
|
||||
void
|
||||
ShowImageApp::ReadyToRun()
|
||||
{
|
||||
if (CountWindows() == WINDOWS_TO_IGNORE)
|
||||
m_pOpenPanel->Show();
|
||||
fpopenPanel->Show();
|
||||
else
|
||||
// If image windows are already open
|
||||
// (paths supplied on the command line)
|
||||
@@ -66,30 +92,33 @@ ShowImageApp::Pulse()
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
|
||||
void ShowImageApp::ArgvReceived(int32 argc, char** argv)
|
||||
void
|
||||
ShowImageApp::ArgvReceived(int32 argc, char **argv)
|
||||
{
|
||||
BMessage* message = 0;
|
||||
for (int32 i=1; i<argc; i++) {
|
||||
BMessage *pmsg = NULL;
|
||||
for (int32 i = 1; i < argc; i++) {
|
||||
entry_ref ref;
|
||||
status_t err = get_ref_for_path(argv[i], &ref);
|
||||
if (err == B_OK) {
|
||||
if (! message) {
|
||||
message = new BMessage;
|
||||
message->what = B_REFS_RECEIVED;
|
||||
if (!pmsg) {
|
||||
pmsg = new BMessage;
|
||||
pmsg->what = B_REFS_RECEIVED;
|
||||
}
|
||||
message->AddRef("refs", &ref);
|
||||
pmsg->AddRef("refs", &ref);
|
||||
}
|
||||
}
|
||||
if (message)
|
||||
RefsReceived(message);
|
||||
if (pmsg)
|
||||
RefsReceived(pmsg);
|
||||
}
|
||||
|
||||
void ShowImageApp::MessageReceived(BMessage* message)
|
||||
void
|
||||
ShowImageApp::MessageReceived(BMessage *pmsg)
|
||||
{
|
||||
switch (message->what) {
|
||||
switch (pmsg->what) {
|
||||
case MSG_FILE_OPEN:
|
||||
m_pOpenPanel->Show();
|
||||
fpopenPanel->Show();
|
||||
break;
|
||||
|
||||
case MSG_WINDOW_QUIT:
|
||||
break;
|
||||
|
||||
@@ -100,34 +129,35 @@ void ShowImageApp::MessageReceived(BMessage* message)
|
||||
break;
|
||||
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
BApplication::MessageReceived(pmsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ShowImageApp::RefsReceived(BMessage* message)
|
||||
void
|
||||
ShowImageApp::RefsReceived(BMessage *pmsg)
|
||||
{
|
||||
uint32 type;
|
||||
int32 count;
|
||||
entry_ref ref;
|
||||
|
||||
message->GetInfo("refs", &type, &count);
|
||||
if (type != B_REF_TYPE)
|
||||
status_t ret = pmsg->GetInfo("refs", &type, &count);
|
||||
if (ret != B_OK || type != B_REF_TYPE)
|
||||
return;
|
||||
|
||||
for (int32 i = --count; i >= 0; --i) {
|
||||
if (message->FindRef("refs", i, &ref) == B_OK) {
|
||||
|
||||
entry_ref ref;
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
if (pmsg->FindRef("refs", i, &ref) == B_OK)
|
||||
Open(&ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShowImageApp::Open(const entry_ref* ref)
|
||||
void
|
||||
ShowImageApp::Open(const entry_ref *pref)
|
||||
{
|
||||
if (ShowImageWindow::NewWindow(ref) != B_OK) {
|
||||
if (ShowImageWindow::NewWindow(pref) != B_OK) {
|
||||
char errStr[B_FILE_NAME_LENGTH + 50];
|
||||
sprintf(errStr, "Couldn't open file: %s",
|
||||
(ref && ref->name) ? ref->name : "???");
|
||||
(pref && pref->name) ? pref->name : "???");
|
||||
|
||||
BAlert* pAlert = new BAlert("file i/o error", errStr, "OK");
|
||||
pAlert->Go();
|
||||
}
|
||||
|
||||
@@ -1,31 +1,53 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageApp
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageApp.h
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef _ShowImageApp_h
|
||||
#define _ShowImageApp_h
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
class ShowImageApp : public BApplication
|
||||
{
|
||||
class ShowImageApp : public BApplication {
|
||||
public:
|
||||
ShowImageApp();
|
||||
|
||||
public:
|
||||
virtual void AboutRequested();
|
||||
virtual void ArgvReceived(int32 argc, char** argv);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void ArgvReceived(int32 argc, char **argv);
|
||||
virtual void MessageReceived(BMessage *pmsg);
|
||||
virtual void ReadyToRun();
|
||||
virtual void Pulse();
|
||||
virtual void RefsReceived(BMessage* message);
|
||||
virtual void RefsReceived(BMessage *pmsg);
|
||||
|
||||
private:
|
||||
void StartPulse();
|
||||
void Open(const entry_ref* ref);
|
||||
|
||||
private:
|
||||
BFilePanel* m_pOpenPanel;
|
||||
void Open(const entry_ref *pref);
|
||||
|
||||
BFilePanel *fpopenPanel;
|
||||
bool fbpulseStarted;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,31 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageConstants
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageConstants.cpp
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "ShowImageConstants.h"
|
||||
|
||||
extern const char* APP_SIG = "application/x-vnd.FFO-ShowImage";
|
||||
extern const char *APP_SIG = "application/x-vnd.FFO-ShowImage";
|
||||
|
||||
@@ -1,6 +1,30 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageConstants
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageConstants.h
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef _ShowImageConstants_
|
||||
#define _ShowImageConstants_
|
||||
@@ -18,7 +42,7 @@ const uint32 MSG_CLEAR_SELECT = 'mCSL';
|
||||
const uint32 MSG_SELECT_ALL = 'mSAL';
|
||||
const uint32 MSG_DITHER_IMAGE = 'mDIM';
|
||||
|
||||
extern const char* APP_SIG;
|
||||
extern const char *APP_SIG;
|
||||
|
||||
|
||||
#endif /* _ShowImageConstants_ */
|
||||
|
||||
@@ -1,20 +1,47 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageStatusView
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageStatusView.cpp
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "ShowImageStatusView.h"
|
||||
|
||||
ShowImageStatusView::ShowImageStatusView(BRect r, const char* name, uint32 resizingMode, uint32 flags)
|
||||
: BView(r, name, resizingMode, flags)
|
||||
ShowImageStatusView::ShowImageStatusView(BRect rect, const char* name,
|
||||
uint32 resizingMode, uint32 flags)
|
||||
: BView(rect, name, resizingMode, flags)
|
||||
{
|
||||
}
|
||||
|
||||
void ShowImageStatusView::Draw(BRect updateRect)
|
||||
void
|
||||
ShowImageStatusView::Draw(BRect updateRect)
|
||||
{
|
||||
DrawString( fstrText.String(), BPoint( 3, 11) );
|
||||
DrawString(fstrText.String(), BPoint(3, 11));
|
||||
}
|
||||
|
||||
void ShowImageStatusView::SetText(BString &strText)
|
||||
void
|
||||
ShowImageStatusView::SetText(BString &strText)
|
||||
{
|
||||
fstrText = strText;
|
||||
Invalidate();
|
||||
|
||||
@@ -1,6 +1,30 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageStatusView
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageStatusView.h
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef _ShowImageStatusView_h
|
||||
#define _ShowImageStatusView_h
|
||||
@@ -8,10 +32,10 @@
|
||||
#include <View.h>
|
||||
#include <String.h>
|
||||
|
||||
class ShowImageStatusView : public BView
|
||||
{
|
||||
class ShowImageStatusView : public BView {
|
||||
public:
|
||||
ShowImageStatusView(BRect r, const char* name, uint32 resizingMode, uint32 flags);
|
||||
ShowImageStatusView(BRect rect, const char *name, uint32 resizingMode,
|
||||
uint32 flags);
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
|
||||
@@ -1,6 +1,30 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageView
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageView.cpp
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Bitmap.h>
|
||||
@@ -14,84 +38,90 @@
|
||||
#include "ShowImageConstants.h"
|
||||
#include "ShowImageView.h"
|
||||
|
||||
ShowImageView::ShowImageView(BRect r, const char* name, uint32 resizingMode, uint32 flags)
|
||||
: BView(r, name, resizingMode, flags), m_pBitmap(NULL)
|
||||
ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
||||
uint32 flags)
|
||||
: BView(rect, name, resizingMode, flags)
|
||||
{
|
||||
SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
|
||||
fpbitmap = NULL;
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
}
|
||||
|
||||
ShowImageView::~ShowImageView()
|
||||
{
|
||||
delete m_pBitmap;
|
||||
m_pBitmap = NULL;
|
||||
delete fpbitmap;
|
||||
fpbitmap = NULL;
|
||||
}
|
||||
|
||||
void ShowImageView::SetBitmap(BBitmap* pBitmap)
|
||||
void
|
||||
ShowImageView::SetBitmap(BBitmap *pbitmap)
|
||||
{
|
||||
m_pBitmap = pBitmap;
|
||||
fpbitmap = pbitmap;
|
||||
}
|
||||
|
||||
BBitmap *
|
||||
ShowImageView::GetBitmap()
|
||||
{
|
||||
return m_pBitmap;
|
||||
return fpbitmap;
|
||||
}
|
||||
|
||||
void ShowImageView::AttachedToWindow()
|
||||
void
|
||||
ShowImageView::AttachedToWindow()
|
||||
{
|
||||
FixupScrollBars();
|
||||
}
|
||||
|
||||
void ShowImageView::Draw(BRect updateRect)
|
||||
void
|
||||
ShowImageView::Draw(BRect updateRect)
|
||||
{
|
||||
if ( m_pBitmap )
|
||||
{
|
||||
DrawBitmap( m_pBitmap, updateRect, updateRect );
|
||||
}
|
||||
if (fpbitmap)
|
||||
DrawBitmap(fpbitmap, updateRect, updateRect);
|
||||
}
|
||||
|
||||
void ShowImageView::FrameResized(float /* width */, float /* height */)
|
||||
void
|
||||
ShowImageView::FrameResized(float /* width */, float /* height */)
|
||||
{
|
||||
FixupScrollBars();
|
||||
}
|
||||
|
||||
void ShowImageView::MessageReceived(BMessage* msg)
|
||||
void
|
||||
ShowImageView::MessageReceived(BMessage *pmsg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
switch (pmsg->what) {
|
||||
default:
|
||||
BView::MessageReceived(msg);
|
||||
BView::MessageReceived(pmsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ShowImageView::FixupScrollBars()
|
||||
void
|
||||
ShowImageView::FixupScrollBars()
|
||||
{
|
||||
if (! m_pBitmap)
|
||||
if (!fpbitmap)
|
||||
return;
|
||||
|
||||
BRect vBds = Bounds(), bBds = m_pBitmap->Bounds();
|
||||
BRect vBds = Bounds(), bBds = fpbitmap->Bounds();
|
||||
float prop;
|
||||
float range;
|
||||
|
||||
BScrollBar* sb = ScrollBar(B_HORIZONTAL);
|
||||
if (sb) {
|
||||
BScrollBar *psb = ScrollBar(B_HORIZONTAL);
|
||||
if (psb) {
|
||||
range = bBds.Width() - vBds.Width();
|
||||
if (range < 0) range = 0;
|
||||
prop = vBds.Width() / bBds.Width();
|
||||
if (prop > 1.0f) prop = 1.0f;
|
||||
sb->SetRange(0, range);
|
||||
sb->SetProportion(prop);
|
||||
sb->SetSteps(10, 100);
|
||||
psb->SetRange(0, range);
|
||||
psb->SetProportion(prop);
|
||||
psb->SetSteps(10, 100);
|
||||
}
|
||||
sb = ScrollBar(B_VERTICAL);
|
||||
if (sb) {
|
||||
psb = ScrollBar(B_VERTICAL);
|
||||
if (psb) {
|
||||
range = bBds.Height() - vBds.Height();
|
||||
if (range < 0) range = 0;
|
||||
prop = vBds.Height() / bBds.Height();
|
||||
if (prop > 1.0f) prop = 1.0f;
|
||||
sb->SetRange(0, range);
|
||||
sb->SetProportion(prop);
|
||||
sb->SetSteps(10, 100);
|
||||
psb->SetRange(0, range);
|
||||
psb->SetProportion(prop);
|
||||
psb->SetSteps(10, 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,54 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageView
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageView.h
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef _ShowImageView_h
|
||||
#define _ShowImageView_h
|
||||
|
||||
#include <View.h>
|
||||
|
||||
class ShowImageView : public BView
|
||||
{
|
||||
class ShowImageView : public BView {
|
||||
public:
|
||||
ShowImageView(BRect r, const char* name, uint32 resizingMode, uint32 flags);
|
||||
ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
||||
uint32 flags);
|
||||
~ShowImageView();
|
||||
|
||||
void SetBitmap(BBitmap* pBitmap);
|
||||
void SetBitmap(BBitmap *pbitmap);
|
||||
BBitmap *GetBitmap();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void MessageReceived(BMessage *pmsg);
|
||||
|
||||
void FixupScrollBars();
|
||||
|
||||
BMenuBar* pBar;
|
||||
|
||||
private:
|
||||
|
||||
BBitmap* m_pBitmap;
|
||||
BBitmap *fpbitmap;
|
||||
};
|
||||
|
||||
#endif /* _ShowImageView_h */
|
||||
|
||||
@@ -1,6 +1,30 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageWindow
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageWindow.cpp
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <algobase.h>
|
||||
#include <stdio.h>
|
||||
@@ -24,314 +48,290 @@
|
||||
#include "ShowImageView.h"
|
||||
#include "ShowImageStatusView.h"
|
||||
|
||||
status_t ShowImageWindow::NewWindow(const entry_ref* ref)
|
||||
status_t
|
||||
ShowImageWindow::NewWindow(const entry_ref *pref)
|
||||
{
|
||||
// Get identify string (image type)
|
||||
BString strId = "Unknown";
|
||||
BString strId = "Unknown image type";
|
||||
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
||||
if (!proster)
|
||||
return B_ERROR;
|
||||
BFile file(ref, B_READ_ONLY);
|
||||
BFile file(pref, B_READ_ONLY);
|
||||
translator_info info;
|
||||
if (proster->Identify(&file, NULL, &info) == B_OK)
|
||||
strId = info.name;
|
||||
|
||||
// Translate image data and create a new ShowImage window
|
||||
file.Seek(0, SEEK_SET);
|
||||
BBitmap* pBitmap = BTranslationUtils::GetBitmap(&file);
|
||||
if (pBitmap) {
|
||||
ShowImageWindow* pWin = new ShowImageWindow(ref, pBitmap, strId);
|
||||
return pWin->InitCheck();
|
||||
BBitmap* pbitmap = BTranslationUtils::GetBitmap(&file);
|
||||
if (pbitmap) {
|
||||
ShowImageWindow* pwin = new ShowImageWindow(pref, pbitmap, strId);
|
||||
return pwin->InitCheck();
|
||||
}
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
ShowImageWindow::ShowImageWindow(const entry_ref* ref, BBitmap* pBitmap, BString &strId)
|
||||
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0),
|
||||
m_pReferences(0)
|
||||
ShowImageWindow::ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap,
|
||||
BString &strId)
|
||||
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
|
||||
{
|
||||
fpsavePanel = NULL;
|
||||
fpref = NULL;
|
||||
|
||||
// create menu bar
|
||||
pBar = new BMenuBar( BRect(0,0, Bounds().right, 20), "menu_bar");
|
||||
LoadMenus(pBar);
|
||||
AddChild(pBar);
|
||||
fpbar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar");
|
||||
LoadMenus(fpbar);
|
||||
AddChild(fpbar);
|
||||
|
||||
BRect viewFrame = Bounds();
|
||||
viewFrame.top = pBar->Bounds().bottom+1;
|
||||
viewFrame.top = fpbar->Bounds().bottom + 1;
|
||||
viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
|
||||
viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;
|
||||
|
||||
// create the image view
|
||||
m_PrivateView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
||||
m_PrivateView->SetBitmap(pBitmap);
|
||||
fpimageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
||||
fpimageView->SetBitmap(pbitmap);
|
||||
|
||||
// wrap a scroll view around the view
|
||||
BScrollView* pScrollView = new BScrollView("image_scroller", m_PrivateView, B_FOLLOW_ALL,
|
||||
0, false, false, B_PLAIN_BORDER);
|
||||
|
||||
AddChild(pScrollView);
|
||||
|
||||
BScrollBar *hor_scroll;
|
||||
|
||||
BRect rect;
|
||||
BScrollView *pscrollView = new BScrollView("image_scroller", fpimageView,
|
||||
B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
|
||||
AddChild(pscrollView);
|
||||
|
||||
const int32 kstatusWidth = 190;
|
||||
BRect rect;
|
||||
rect = Bounds();
|
||||
rect.top = viewFrame.bottom + 1;
|
||||
rect.left = viewFrame.left + kstatusWidth;
|
||||
rect.right = viewFrame.right;
|
||||
|
||||
hor_scroll = new BScrollBar( rect, "hor_scroll", m_PrivateView, 0,150, B_HORIZONTAL );
|
||||
AddChild( hor_scroll );
|
||||
|
||||
ShowImageStatusView * status_bar;
|
||||
rect.left = viewFrame.left + kstatusWidth;
|
||||
rect.right = viewFrame.right;
|
||||
BScrollBar *phscroll;
|
||||
phscroll = new BScrollBar(rect, "hscroll", fpimageView, 0, 150,
|
||||
B_HORIZONTAL);
|
||||
AddChild(phscroll);
|
||||
|
||||
rect.left = 0;
|
||||
rect.right = kstatusWidth - 1;
|
||||
|
||||
status_bar = new ShowImageStatusView( rect, "status_bar", B_FOLLOW_BOTTOM, B_WILL_DRAW );
|
||||
status_bar->SetViewColor( ui_color( B_MENU_BACKGROUND_COLOR ) );
|
||||
status_bar->SetText(strId);
|
||||
|
||||
AddChild( status_bar );
|
||||
|
||||
BScrollBar *vert_scroll;
|
||||
rect.right = kstatusWidth - 1;
|
||||
ShowImageStatusView *pstatusView;
|
||||
pstatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
|
||||
B_WILL_DRAW);
|
||||
pstatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
|
||||
pstatusView->SetText(strId);
|
||||
AddChild(pstatusView);
|
||||
|
||||
rect = Bounds();
|
||||
rect.top = viewFrame.top;
|
||||
rect.left = viewFrame.right + 1;
|
||||
rect.bottom = viewFrame.bottom;
|
||||
BScrollBar *pvscroll;
|
||||
pvscroll = new BScrollBar(rect, "vscroll", fpimageView, 0, 150, B_VERTICAL);
|
||||
AddChild(pvscroll);
|
||||
|
||||
vert_scroll = new BScrollBar( rect, "vert_scroll", m_PrivateView, 0,150, B_VERTICAL );
|
||||
AddChild( vert_scroll );
|
||||
|
||||
WindowRedimension( pBitmap );
|
||||
WindowRedimension(pbitmap);
|
||||
|
||||
// finish creating window
|
||||
SetRef(ref);
|
||||
SetRef(pref);
|
||||
UpdateTitle();
|
||||
|
||||
m_PrivateView->pBar = pBar;
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
ShowImageWindow::~ShowImageWindow()
|
||||
{
|
||||
delete m_pReferences;
|
||||
delete fpref;
|
||||
}
|
||||
|
||||
void ShowImageWindow::WindowActivated(bool active)
|
||||
status_t
|
||||
ShowImageWindow::InitCheck()
|
||||
{
|
||||
// WindowRedimension( pBitmap );
|
||||
}
|
||||
|
||||
status_t ShowImageWindow::InitCheck()
|
||||
{
|
||||
if (! m_pReferences) {
|
||||
if (!fpref || !fpimageView)
|
||||
return B_ERROR;
|
||||
} else {
|
||||
else
|
||||
return B_OK;
|
||||
}
|
||||
}
|
||||
|
||||
void ShowImageWindow::SetRef(const entry_ref* ref)
|
||||
void
|
||||
ShowImageWindow::SetRef(const entry_ref *pref)
|
||||
{
|
||||
if (! m_pReferences) {
|
||||
m_pReferences = new entry_ref(*ref);
|
||||
} else {
|
||||
*m_pReferences = *ref;
|
||||
}
|
||||
if (!fpref)
|
||||
fpref = new entry_ref(*pref);
|
||||
else
|
||||
*fpref = *pref;
|
||||
}
|
||||
|
||||
void ShowImageWindow::UpdateTitle()
|
||||
void
|
||||
ShowImageWindow::UpdateTitle()
|
||||
{
|
||||
BEntry entry(m_pReferences);
|
||||
BEntry entry(fpref);
|
||||
if (entry.InitCheck() == B_OK) {
|
||||
BPath path;
|
||||
entry.GetPath(&path);
|
||||
if (path.InitCheck() == B_OK) {
|
||||
if (path.InitCheck() == B_OK)
|
||||
SetTitle(path.Path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShowImageWindow::LoadMenus(BMenuBar* pBar)
|
||||
void
|
||||
ShowImageWindow::LoadMenus(BMenuBar *pbar)
|
||||
{
|
||||
BMenu* pMenu = new BMenu("File");
|
||||
|
||||
AddItemMenu( pMenu, "Open", MSG_FILE_OPEN, 'O', 0, 'A', true );
|
||||
pMenu->AddSeparatorItem();
|
||||
|
||||
BMenu* pMenuSaveAs = new BMenu( "Save As...", B_ITEMS_IN_COLUMN );
|
||||
BTranslationUtils::AddTranslationItems(pMenuSaveAs, B_TRANSLATOR_BITMAP);
|
||||
BMenu *pmenu = new BMenu("File");
|
||||
AddItemMenu(pmenu, "Open", MSG_FILE_OPEN, 'O', 0, 'A', true);
|
||||
pmenu->AddSeparatorItem();
|
||||
BMenu *pmenuSaveAs = new BMenu("Save As...", B_ITEMS_IN_COLUMN);
|
||||
BTranslationUtils::AddTranslationItems(pmenuSaveAs, B_TRANSLATOR_BITMAP);
|
||||
// Fill Save As submenu with all types that can be converted
|
||||
// to from the Be bitmap image format
|
||||
pMenu->AddItem( pMenuSaveAs );
|
||||
pmenu->AddItem(pmenuSaveAs);
|
||||
AddItemMenu(pmenu, "Close", MSG_CLOSE, 'W', 0, 'W', true);
|
||||
pmenu->AddSeparatorItem();
|
||||
AddItemMenu(pmenu, "About ShowImage...", B_ABOUT_REQUESTED, 0, 0, 'A', true);
|
||||
pmenu->AddSeparatorItem();
|
||||
AddItemMenu(pmenu, "Quit", B_QUIT_REQUESTED, 'Q', 0, 'A', true);
|
||||
pbar->AddItem(pmenu);
|
||||
|
||||
AddItemMenu( pMenu, "Close", MSG_CLOSE, 'W', 0, 'W', true);
|
||||
pMenu->AddSeparatorItem();
|
||||
AddItemMenu( pMenu, "About ShowImage...", B_ABOUT_REQUESTED, 0, 0, 'A', true);
|
||||
pMenu->AddSeparatorItem();
|
||||
AddItemMenu( pMenu, "Quit", B_QUIT_REQUESTED, 'Q', 0, 'A', true);
|
||||
pmenu = new BMenu("Edit");
|
||||
AddItemMenu(pmenu, "Undo", B_UNDO, 'Z', 0, 'W', false);
|
||||
pmenu->AddSeparatorItem();
|
||||
AddItemMenu(pmenu, "Cut", B_CUT, 'X', 0, 'W', false);
|
||||
AddItemMenu(pmenu, "Copy", B_COPY, 'C', 0, 'W', false);
|
||||
AddItemMenu(pmenu, "Paste", B_PASTE, 'V', 0, 'W', false);
|
||||
AddItemMenu(pmenu, "Clear", MSG_CLEAR_SELECT, 0, 0, 'W', false);
|
||||
pmenu->AddSeparatorItem();
|
||||
AddItemMenu(pmenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', false);
|
||||
pbar->AddItem(pmenu);
|
||||
|
||||
pBar->AddItem(pMenu);
|
||||
|
||||
pMenu = new BMenu("Edit");
|
||||
|
||||
AddItemMenu( pMenu, "Undo", B_UNDO, 'Z', 0, 'W', false);
|
||||
pMenu->AddSeparatorItem();
|
||||
AddItemMenu( pMenu, "Cut", B_CUT, 'X', 0, 'W', false);
|
||||
AddItemMenu( pMenu, "Copy", B_COPY, 'C', 0, 'W', false);
|
||||
AddItemMenu( pMenu, "Paste", B_PASTE, 'V', 0, 'W', false);
|
||||
AddItemMenu( pMenu, "Clear", MSG_CLEAR_SELECT, 0, 0, 'W', false);
|
||||
pMenu->AddSeparatorItem();
|
||||
AddItemMenu( pMenu, "Select All", MSG_SELECT_ALL, 'A', 0, 'W', true);
|
||||
|
||||
pBar->AddItem(pMenu);
|
||||
|
||||
pMenu = new BMenu("Image");
|
||||
AddItemMenu( pMenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
|
||||
pBar->AddItem(pMenu);
|
||||
pmenu = new BMenu("Image");
|
||||
AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
|
||||
pbar->AddItem(pmenu);
|
||||
}
|
||||
|
||||
BMenuItem * ShowImageWindow::AddItemMenu( BMenu *pMenu, char *Caption, long unsigned int msg,
|
||||
char shortcut, uint32 modifier, char target, bool enabled ) {
|
||||
|
||||
BMenuItem* pItem;
|
||||
BMenuItem *
|
||||
ShowImageWindow::AddItemMenu(BMenu *pmenu, char *caption, long unsigned int msg,
|
||||
char shortcut, uint32 modifier, char target, bool benabled)
|
||||
{
|
||||
BMenuItem* pitem;
|
||||
pitem = new BMenuItem(caption, new BMessage(msg), shortcut);
|
||||
|
||||
pItem = new BMenuItem( Caption, new BMessage(msg), shortcut );
|
||||
|
||||
if ( target == 'A' )
|
||||
pItem->SetTarget(be_app);
|
||||
if (target == 'A')
|
||||
pitem->SetTarget(be_app);
|
||||
|
||||
pItem->SetEnabled( enabled );
|
||||
pMenu->AddItem(pItem);
|
||||
pitem->SetEnabled(benabled);
|
||||
pmenu->AddItem(pitem);
|
||||
|
||||
return( pItem );
|
||||
return pitem;
|
||||
}
|
||||
|
||||
void ShowImageWindow::WindowRedimension( BBitmap *pBitmap )
|
||||
void
|
||||
ShowImageWindow::WindowRedimension(BBitmap *pbitmap)
|
||||
{
|
||||
// set the window's min & max size limits
|
||||
// based on document's data bounds
|
||||
float maxWidth = pBitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH;
|
||||
float maxHeight = pBitmap->Bounds().Height()
|
||||
+ pBar->Frame().Height()
|
||||
+ B_H_SCROLL_BAR_HEIGHT + 1;
|
||||
float maxWidth = pbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH;
|
||||
float maxHeight = pbitmap->Bounds().Height() + fpbar->Frame().Height() +
|
||||
B_H_SCROLL_BAR_HEIGHT + 1;
|
||||
float minWidth = min(maxWidth, 100.0f);
|
||||
float minHeight = min(maxHeight, 100.0f);
|
||||
|
||||
// adjust the window's current size based on new min/max values
|
||||
float curWidth = Bounds().Width();
|
||||
float curHeight = Bounds().Height();
|
||||
if (curWidth < minWidth) {
|
||||
if (curWidth < minWidth)
|
||||
curWidth = minWidth;
|
||||
} else if (curWidth > maxWidth) {
|
||||
else if (curWidth > maxWidth)
|
||||
curWidth = maxWidth;
|
||||
}
|
||||
if (curHeight < minHeight) {
|
||||
|
||||
if (curHeight < minHeight)
|
||||
curHeight = minHeight;
|
||||
} else if (curHeight > maxHeight) {
|
||||
else if (curHeight > maxHeight)
|
||||
curHeight = maxHeight;
|
||||
}
|
||||
if ( minWidth < 250 ) {
|
||||
|
||||
if (minWidth < 250)
|
||||
minWidth = 250;
|
||||
}
|
||||
|
||||
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
|
||||
ResizeTo(curWidth, curHeight);
|
||||
}
|
||||
|
||||
void ShowImageWindow::FrameResized( float new_width, float new_height )
|
||||
void
|
||||
ShowImageWindow::FrameResized(float width, float height)
|
||||
{
|
||||
}
|
||||
|
||||
void ShowImageWindow::MessageReceived(BMessage* message)
|
||||
void
|
||||
ShowImageWindow::MessageReceived(BMessage *pmsg)
|
||||
{
|
||||
BAlert* pAlert;
|
||||
|
||||
switch (message->what) {
|
||||
switch (pmsg->what) {
|
||||
case MSG_OUTPUT_TYPE:
|
||||
// User clicked Save As then choose an output format
|
||||
SaveAs(message);
|
||||
if (!fpsavePanel)
|
||||
// If user doesn't already have a save panel open
|
||||
SaveAs(pmsg);
|
||||
break;
|
||||
|
||||
case MSG_SAVE_PANEL:
|
||||
// User specified where to save the output image
|
||||
SaveToFile(message);
|
||||
SaveToFile(pmsg);
|
||||
break;
|
||||
|
||||
case MSG_CLOSE:
|
||||
Quit();
|
||||
if (CanQuit())
|
||||
Quit();
|
||||
break;
|
||||
|
||||
case B_CANCEL:
|
||||
delete fpsavePanel;
|
||||
fpsavePanel = NULL;
|
||||
break;
|
||||
|
||||
case B_UNDO :
|
||||
pAlert = new BAlert( "Edit/Undo",
|
||||
"Edit/Undo not implemented yet", "OK");
|
||||
pAlert->Go();
|
||||
break;
|
||||
case B_CUT :
|
||||
pAlert = new BAlert( "Edit/Cut",
|
||||
"Edit/Cut not implemented yet", "OK");
|
||||
pAlert->Go();
|
||||
break;
|
||||
case B_COPY :
|
||||
pAlert = new BAlert( "Edit/Copy",
|
||||
"Edit/Copy not implemented yet", "OK");
|
||||
pAlert->Go();
|
||||
break;
|
||||
case B_PASTE :
|
||||
pAlert = new BAlert( "Edit/Paste",
|
||||
"Edit/Paste not implemented yet", "OK");
|
||||
pAlert->Go();
|
||||
break;
|
||||
case MSG_CLEAR_SELECT :
|
||||
pAlert = new BAlert( "Edit/Clear Select",
|
||||
"Edit/Clear Select not implemented yet", "OK");
|
||||
pAlert->Go();
|
||||
break;
|
||||
case MSG_SELECT_ALL :
|
||||
pAlert = new BAlert( "Edit/Select All",
|
||||
"Edit/Select All not implemented yet", "OK");
|
||||
pAlert->Go();
|
||||
break;
|
||||
case MSG_DITHER_IMAGE :
|
||||
BMenuItem * pMenuDither;
|
||||
pMenuDither = pBar->FindItem( message->what );
|
||||
pMenuDither->SetMarked( ! pMenuDither->IsMarked() );
|
||||
|
||||
break;
|
||||
case B_UNDO:
|
||||
break;
|
||||
case B_CUT:
|
||||
break;
|
||||
case B_COPY:
|
||||
break;
|
||||
case B_PASTE:
|
||||
break;
|
||||
case MSG_CLEAR_SELECT:
|
||||
break;
|
||||
case MSG_SELECT_ALL:
|
||||
break;
|
||||
|
||||
case MSG_DITHER_IMAGE:
|
||||
BMenuItem *pmenuDither;
|
||||
pmenuDither = fpbar->FindItem(pmsg->what);
|
||||
pmenuDither->SetMarked(!pmenuDither->IsMarked());
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
default:
|
||||
BWindow::MessageReceived(pmsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ShowImageWindow::SaveAs(BMessage *pmsg)
|
||||
{
|
||||
// Handle SaveAs menu choice by setting the
|
||||
// translator and desired output format
|
||||
// and giving the user a save panel
|
||||
|
||||
if (pmsg->FindInt32("be:translator",
|
||||
reinterpret_cast<int32 *>(&foutTranslator)) != B_OK)
|
||||
// Read the translator and output type the user chose
|
||||
translator_id outTranslator;
|
||||
uint32 outType;
|
||||
if (pmsg->FindInt32(TRANSLATOR_FLD,
|
||||
reinterpret_cast<int32 *>(&outTranslator)) != B_OK)
|
||||
return;
|
||||
if (pmsg->FindInt32("be:type",
|
||||
reinterpret_cast<int32 *>(&foutType)) != B_OK)
|
||||
if (pmsg->FindInt32(TYPE_FLD,
|
||||
reinterpret_cast<int32 *>(&outType)) != B_OK)
|
||||
return;
|
||||
|
||||
// Add the chosen translator and output type to the
|
||||
// message that the save panel will send back
|
||||
BMessage *ppanelMsg = new BMessage(MSG_SAVE_PANEL);
|
||||
ppanelMsg->AddInt32(TRANSLATOR_FLD, outTranslator);
|
||||
ppanelMsg->AddInt32(TYPE_FLD, outType);
|
||||
|
||||
if (!fpsavePanel) {
|
||||
fpsavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0,
|
||||
false, new BMessage(MSG_SAVE_PANEL));
|
||||
if (!fpsavePanel)
|
||||
return;
|
||||
}
|
||||
|
||||
// Create save panel and show it
|
||||
fpsavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0,
|
||||
false, ppanelMsg);
|
||||
if (!fpsavePanel)
|
||||
return;
|
||||
fpsavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE);
|
||||
fpsavePanel->Show();
|
||||
}
|
||||
@@ -339,11 +339,7 @@ ShowImageWindow::SaveAs(BMessage *pmsg)
|
||||
void
|
||||
ShowImageWindow::SaveToFile(BMessage *pmsg)
|
||||
{
|
||||
// After the user has chosen which format
|
||||
// to output to and where to save the file,
|
||||
// this function is called to save the currently
|
||||
// open image to a file in the desired format.
|
||||
|
||||
// Read in where the file should be saved
|
||||
entry_ref dirref;
|
||||
if (pmsg->FindRef("directory", &dirref) != B_OK)
|
||||
return;
|
||||
@@ -351,15 +347,28 @@ ShowImageWindow::SaveToFile(BMessage *pmsg)
|
||||
if (pmsg->FindString("name", &filename) != B_OK)
|
||||
return;
|
||||
|
||||
// Read in the translator and type to be used
|
||||
// to save the output image
|
||||
translator_id outTranslator;
|
||||
uint32 outType;
|
||||
if (pmsg->FindInt32(TRANSLATOR_FLD,
|
||||
reinterpret_cast<int32 *>(&outTranslator)) != B_OK)
|
||||
return;
|
||||
if (pmsg->FindInt32(TYPE_FLD,
|
||||
reinterpret_cast<int32 *>(&outType)) != B_OK)
|
||||
return;
|
||||
|
||||
// Create the output file
|
||||
BDirectory dir(&dirref);
|
||||
BFile file(&dir, filename, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||
if (file.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
BBitmapStream stream(m_PrivateView->GetBitmap());
|
||||
// Translate the image and write it out to the output file
|
||||
BBitmapStream stream(fpimageView->GetBitmap());
|
||||
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
||||
if (proster->Translate(foutTranslator, &stream, NULL,
|
||||
&file, foutType) != B_OK) {
|
||||
if (proster->Translate(outTranslator, &stream, NULL,
|
||||
&file, outType) != B_OK) {
|
||||
BAlert *palert = new BAlert(NULL, "Error writing image file.", "Ok");
|
||||
palert->Go();
|
||||
}
|
||||
@@ -370,6 +379,22 @@ ShowImageWindow::SaveToFile(BMessage *pmsg)
|
||||
// detach so it doesn't get deleted
|
||||
}
|
||||
|
||||
bool
|
||||
ShowImageWindow::CanQuit()
|
||||
{
|
||||
if (fpsavePanel)
|
||||
// Don't allow this window to be closed if a save panel is open
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ShowImageWindow::QuitRequested()
|
||||
{
|
||||
return CanQuit();
|
||||
}
|
||||
|
||||
void
|
||||
ShowImageWindow::Quit()
|
||||
{
|
||||
@@ -378,4 +403,3 @@ ShowImageWindow::Quit()
|
||||
BWindow::Quit();
|
||||
}
|
||||
|
||||
// BMenu* pMenuDither = ;
|
||||
|
||||
@@ -1,6 +1,30 @@
|
||||
/*
|
||||
OBOS ShowImage 0.1 - 17/02/2002 - 22:22 - Fernando Francisco de Oliveira
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
// ShowImageWindow
|
||||
// Written by Fernando Francisco de Oliveira, Michael Wilber
|
||||
//
|
||||
// ShowImageWindow.h
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef _ShowImageWindow_h
|
||||
#define _ShowImageWindow_h
|
||||
@@ -12,46 +36,46 @@
|
||||
|
||||
class ShowImageView;
|
||||
|
||||
class ShowImageWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
static status_t NewWindow(const entry_ref* ref);
|
||||
// BMessage field names used in Save messages
|
||||
#define TRANSLATOR_FLD "be:translator"
|
||||
#define TYPE_FLD "be:type"
|
||||
|
||||
ShowImageWindow(const entry_ref* ref, BBitmap* pBitmap, BString &strId);
|
||||
class ShowImageWindow : public BWindow {
|
||||
public:
|
||||
static status_t NewWindow(const entry_ref *pref);
|
||||
|
||||
ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap, BString &strId);
|
||||
virtual ~ShowImageWindow();
|
||||
|
||||
virtual void WindowActivated(bool active);
|
||||
virtual void FrameResized( float new_width, float new_height );
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void MessageReceived(BMessage *pmsg);
|
||||
virtual bool QuitRequested();
|
||||
virtual void Quit();
|
||||
|
||||
status_t InitCheck();
|
||||
ShowImageView* GetShowImageView() const { return m_PrivateView; }
|
||||
ShowImageView *GetShowImageView() const { return fpimageView; }
|
||||
|
||||
void SetRef(const entry_ref* ref);
|
||||
void SetRef(const entry_ref *pref);
|
||||
void UpdateTitle();
|
||||
void LoadMenus(BMenuBar* pBar);
|
||||
void WindowRedimension( BBitmap *pBitmap );
|
||||
void LoadMenus(BMenuBar *pbar);
|
||||
void WindowRedimension(BBitmap *pbitmap);
|
||||
|
||||
BMenuBar* pBar;
|
||||
private:
|
||||
BMenuItem * AddItemMenu( BMenu *pMenu, char *Caption, long unsigned int msg,
|
||||
char shortcut, uint32 modifier, char target, bool enabled );
|
||||
BMenuItem *AddItemMenu(BMenu *pmenu, char *caption,
|
||||
long unsigned int msg, char shortcut, uint32 modifier,
|
||||
char target, bool enabled);
|
||||
|
||||
void SaveAs(BMessage *pmsg);
|
||||
// Handle Save As submenu choice
|
||||
void SaveToFile(BMessage *pmsg);
|
||||
// Handle save file panel message
|
||||
// Handle save file panel message
|
||||
bool CanQuit();
|
||||
// returns true if the window can be closed safely, false if not
|
||||
|
||||
BFilePanel *fpsavePanel;
|
||||
translator_id foutTranslator;
|
||||
uint32 foutType;
|
||||
|
||||
entry_ref* m_pReferences;
|
||||
ShowImageView* m_PrivateView;
|
||||
|
||||
static BLocker s_winListLocker;
|
||||
static BList s_winList;
|
||||
BMenuBar *fpbar;
|
||||
entry_ref *fpref;
|
||||
ShowImageView *fpimageView;
|
||||
};
|
||||
|
||||
#endif /* _ShowImageWindow_h */
|
||||
|
||||
Reference in New Issue
Block a user