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:
Matthew Wilber
2003-08-02 20:04:53 +00:00
parent f5eabf0502
commit cdb89ebbeb
10 changed files with 590 additions and 340 deletions
+62 -32
View File
@@ -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 <stdio.h>
#include <Alert.h> #include <Alert.h>
@@ -10,7 +34,7 @@
#include "ShowImageApp.h" #include "ShowImageApp.h"
#include "ShowImageWindow.h" #include "ShowImageWindow.h"
int main(int, char**) int main(int, char **)
{ {
ShowImageApp theApp; ShowImageApp theApp;
theApp.Run(); theApp.Run();
@@ -23,20 +47,22 @@ ShowImageApp::ShowImageApp()
: BApplication(APP_SIG) : BApplication(APP_SIG)
{ {
fbpulseStarted = false; 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", BAlert* pAlert = new BAlert("About ShowImage",
"OBOS ShowImage\n\nby Fernando F. Oliveira and Michael Wilber", "OK"); "OBOS ShowImage\n\nby Fernando F. Oliveira and Michael Wilber", "OK");
pAlert->Go(); pAlert->Go();
} }
void ShowImageApp::ReadyToRun() void
ShowImageApp::ReadyToRun()
{ {
if (CountWindows() == WINDOWS_TO_IGNORE) if (CountWindows() == WINDOWS_TO_IGNORE)
m_pOpenPanel->Show(); fpopenPanel->Show();
else else
// If image windows are already open // If image windows are already open
// (paths supplied on the command line) // (paths supplied on the command line)
@@ -66,30 +92,33 @@ ShowImageApp::Pulse()
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
void ShowImageApp::ArgvReceived(int32 argc, char** argv) void
ShowImageApp::ArgvReceived(int32 argc, char **argv)
{ {
BMessage* message = 0; BMessage *pmsg = NULL;
for (int32 i=1; i<argc; i++) { for (int32 i = 1; i < argc; i++) {
entry_ref ref; entry_ref ref;
status_t err = get_ref_for_path(argv[i], &ref); status_t err = get_ref_for_path(argv[i], &ref);
if (err == B_OK) { if (err == B_OK) {
if (! message) { if (!pmsg) {
message = new BMessage; pmsg = new BMessage;
message->what = B_REFS_RECEIVED; pmsg->what = B_REFS_RECEIVED;
} }
message->AddRef("refs", &ref); pmsg->AddRef("refs", &ref);
} }
} }
if (message) if (pmsg)
RefsReceived(message); RefsReceived(pmsg);
} }
void ShowImageApp::MessageReceived(BMessage* message) void
ShowImageApp::MessageReceived(BMessage *pmsg)
{ {
switch (message->what) { switch (pmsg->what) {
case MSG_FILE_OPEN: case MSG_FILE_OPEN:
m_pOpenPanel->Show(); fpopenPanel->Show();
break; break;
case MSG_WINDOW_QUIT: case MSG_WINDOW_QUIT:
break; break;
@@ -100,34 +129,35 @@ void ShowImageApp::MessageReceived(BMessage* message)
break; break;
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(pmsg);
break; break;
} }
} }
void ShowImageApp::RefsReceived(BMessage* message) void
ShowImageApp::RefsReceived(BMessage *pmsg)
{ {
uint32 type; uint32 type;
int32 count; int32 count;
entry_ref ref; status_t ret = pmsg->GetInfo("refs", &type, &count);
if (ret != B_OK || type != B_REF_TYPE)
message->GetInfo("refs", &type, &count);
if (type != B_REF_TYPE)
return; return;
for (int32 i = --count; i >= 0; --i) { entry_ref ref;
if (message->FindRef("refs", i, &ref) == B_OK) { for (int32 i = 0; i < count; i++) {
if (pmsg->FindRef("refs", i, &ref) == B_OK)
Open(&ref); 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]; char errStr[B_FILE_NAME_LENGTH + 50];
sprintf(errStr, "Couldn't open file: %s", 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"); BAlert* pAlert = new BAlert("file i/o error", errStr, "OK");
pAlert->Go(); pAlert->Go();
} }
+33 -11
View File
@@ -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 #ifndef _ShowImageApp_h
#define _ShowImageApp_h #define _ShowImageApp_h
#include <Application.h> #include <Application.h>
class ShowImageApp : public BApplication class ShowImageApp : public BApplication {
{
public: public:
ShowImageApp(); ShowImageApp();
public: public:
virtual void AboutRequested(); virtual void AboutRequested();
virtual void ArgvReceived(int32 argc, char** argv); virtual void ArgvReceived(int32 argc, char **argv);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage *pmsg);
virtual void ReadyToRun(); virtual void ReadyToRun();
virtual void Pulse(); virtual void Pulse();
virtual void RefsReceived(BMessage* message); virtual void RefsReceived(BMessage *pmsg);
private: private:
void StartPulse(); void StartPulse();
void Open(const entry_ref* ref); void Open(const entry_ref *pref);
private: BFilePanel *fpopenPanel;
BFilePanel* m_pOpenPanel;
bool fbpulseStarted; bool fbpulseStarted;
}; };
+28 -4
View File
@@ -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" #include "ShowImageConstants.h"
extern const char* APP_SIG = "application/x-vnd.FFO-ShowImage"; extern const char *APP_SIG = "application/x-vnd.FFO-ShowImage";
+28 -4
View File
@@ -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_ #ifndef _ShowImageConstants_
#define _ShowImageConstants_ #define _ShowImageConstants_
@@ -18,7 +42,7 @@ const uint32 MSG_CLEAR_SELECT = 'mCSL';
const uint32 MSG_SELECT_ALL = 'mSAL'; const uint32 MSG_SELECT_ALL = 'mSAL';
const uint32 MSG_DITHER_IMAGE = 'mDIM'; const uint32 MSG_DITHER_IMAGE = 'mDIM';
extern const char* APP_SIG; extern const char *APP_SIG;
#endif /* _ShowImageConstants_ */ #endif /* _ShowImageConstants_ */
+35 -8
View File
@@ -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" #include "ShowImageStatusView.h"
ShowImageStatusView::ShowImageStatusView(BRect r, const char* name, uint32 resizingMode, uint32 flags) ShowImageStatusView::ShowImageStatusView(BRect rect, const char* name,
: BView(r, name, resizingMode, flags) 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; fstrText = strText;
Invalidate(); Invalidate();
+30 -6
View File
@@ -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 #ifndef _ShowImageStatusView_h
#define _ShowImageStatusView_h #define _ShowImageStatusView_h
@@ -8,10 +32,10 @@
#include <View.h> #include <View.h>
#include <String.h> #include <String.h>
class ShowImageStatusView : public BView class ShowImageStatusView : public BView {
{
public: 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); virtual void Draw(BRect updateRect);
+64 -34
View File
@@ -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 <stdio.h>
#include <Bitmap.h> #include <Bitmap.h>
@@ -14,84 +38,90 @@
#include "ShowImageConstants.h" #include "ShowImageConstants.h"
#include "ShowImageView.h" #include "ShowImageView.h"
ShowImageView::ShowImageView(BRect r, const char* name, uint32 resizingMode, uint32 flags) ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
: BView(r, name, resizingMode, flags), m_pBitmap(NULL) 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() ShowImageView::~ShowImageView()
{ {
delete m_pBitmap; delete fpbitmap;
m_pBitmap = NULL; fpbitmap = NULL;
} }
void ShowImageView::SetBitmap(BBitmap* pBitmap) void
ShowImageView::SetBitmap(BBitmap *pbitmap)
{ {
m_pBitmap = pBitmap; fpbitmap = pbitmap;
} }
BBitmap * BBitmap *
ShowImageView::GetBitmap() ShowImageView::GetBitmap()
{ {
return m_pBitmap; return fpbitmap;
} }
void ShowImageView::AttachedToWindow() void
ShowImageView::AttachedToWindow()
{ {
FixupScrollBars(); FixupScrollBars();
} }
void ShowImageView::Draw(BRect updateRect) void
ShowImageView::Draw(BRect updateRect)
{ {
if ( m_pBitmap ) if (fpbitmap)
{ DrawBitmap(fpbitmap, updateRect, updateRect);
DrawBitmap( m_pBitmap, updateRect, updateRect );
}
} }
void ShowImageView::FrameResized(float /* width */, float /* height */) void
ShowImageView::FrameResized(float /* width */, float /* height */)
{ {
FixupScrollBars(); FixupScrollBars();
} }
void ShowImageView::MessageReceived(BMessage* msg) void
ShowImageView::MessageReceived(BMessage *pmsg)
{ {
switch (msg->what) { switch (pmsg->what) {
default: default:
BView::MessageReceived(msg); BView::MessageReceived(pmsg);
break; break;
} }
} }
void ShowImageView::FixupScrollBars() void
ShowImageView::FixupScrollBars()
{ {
if (! m_pBitmap) if (!fpbitmap)
return; return;
BRect vBds = Bounds(), bBds = m_pBitmap->Bounds(); BRect vBds = Bounds(), bBds = fpbitmap->Bounds();
float prop; float prop;
float range; float range;
BScrollBar* sb = ScrollBar(B_HORIZONTAL); BScrollBar *psb = ScrollBar(B_HORIZONTAL);
if (sb) { if (psb) {
range = bBds.Width() - vBds.Width(); range = bBds.Width() - vBds.Width();
if (range < 0) range = 0; if (range < 0) range = 0;
prop = vBds.Width() / bBds.Width(); prop = vBds.Width() / bBds.Width();
if (prop > 1.0f) prop = 1.0f; if (prop > 1.0f) prop = 1.0f;
sb->SetRange(0, range); psb->SetRange(0, range);
sb->SetProportion(prop); psb->SetProportion(prop);
sb->SetSteps(10, 100); psb->SetSteps(10, 100);
} }
sb = ScrollBar(B_VERTICAL); psb = ScrollBar(B_VERTICAL);
if (sb) { if (psb) {
range = bBds.Height() - vBds.Height(); range = bBds.Height() - vBds.Height();
if (range < 0) range = 0; if (range < 0) range = 0;
prop = vBds.Height() / bBds.Height(); prop = vBds.Height() / bBds.Height();
if (prop > 1.0f) prop = 1.0f; if (prop > 1.0f) prop = 1.0f;
sb->SetRange(0, range); psb->SetRange(0, range);
sb->SetProportion(prop); psb->SetProportion(prop);
sb->SetSteps(10, 100); psb->SetSteps(10, 100);
} }
} }
+33 -12
View File
@@ -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 #ifndef _ShowImageView_h
#define _ShowImageView_h #define _ShowImageView_h
#include <View.h> #include <View.h>
class ShowImageView : public BView class ShowImageView : public BView {
{
public: public:
ShowImageView(BRect r, const char* name, uint32 resizingMode, uint32 flags); ShowImageView(BRect rect, const char *name, uint32 resizingMode,
uint32 flags);
~ShowImageView(); ~ShowImageView();
void SetBitmap(BBitmap* pBitmap); void SetBitmap(BBitmap *pbitmap);
BBitmap *GetBitmap(); BBitmap *GetBitmap();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void FrameResized(float width, float height); virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage *pmsg);
void FixupScrollBars(); void FixupScrollBars();
BMenuBar* pBar;
private: private:
BBitmap *fpbitmap;
BBitmap* m_pBitmap;
}; };
#endif /* _ShowImageView_h */ #endif /* _ShowImageView_h */
+209 -185
View File
@@ -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 <algobase.h>
#include <stdio.h> #include <stdio.h>
@@ -24,289 +48,262 @@
#include "ShowImageView.h" #include "ShowImageView.h"
#include "ShowImageStatusView.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) // Get identify string (image type)
BString strId = "Unknown"; BString strId = "Unknown image type";
BTranslatorRoster *proster = BTranslatorRoster::Default(); BTranslatorRoster *proster = BTranslatorRoster::Default();
if (!proster) if (!proster)
return B_ERROR; return B_ERROR;
BFile file(ref, B_READ_ONLY); BFile file(pref, B_READ_ONLY);
translator_info info; translator_info info;
if (proster->Identify(&file, NULL, &info) == B_OK) if (proster->Identify(&file, NULL, &info) == B_OK)
strId = info.name; strId = info.name;
// Translate image data and create a new ShowImage window // Translate image data and create a new ShowImage window
file.Seek(0, SEEK_SET); file.Seek(0, SEEK_SET);
BBitmap* pBitmap = BTranslationUtils::GetBitmap(&file); BBitmap* pbitmap = BTranslationUtils::GetBitmap(&file);
if (pBitmap) { if (pbitmap) {
ShowImageWindow* pWin = new ShowImageWindow(ref, pBitmap, strId); ShowImageWindow* pwin = new ShowImageWindow(pref, pbitmap, strId);
return pWin->InitCheck(); return pwin->InitCheck();
} }
return B_ERROR; return B_ERROR;
} }
ShowImageWindow::ShowImageWindow(const entry_ref* ref, BBitmap* pBitmap, BString &strId) ShowImageWindow::ShowImageWindow(const entry_ref *pref, BBitmap *pbitmap,
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0), BString &strId)
m_pReferences(0) : BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
{ {
fpsavePanel = NULL; fpsavePanel = NULL;
fpref = NULL;
// create menu bar // create menu bar
pBar = new BMenuBar( BRect(0,0, Bounds().right, 20), "menu_bar"); fpbar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar");
LoadMenus(pBar); LoadMenus(fpbar);
AddChild(pBar); AddChild(fpbar);
BRect viewFrame = Bounds(); BRect viewFrame = Bounds();
viewFrame.top = pBar->Bounds().bottom+1; viewFrame.top = fpbar->Bounds().bottom + 1;
viewFrame.right -= B_V_SCROLL_BAR_WIDTH; viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT; viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;
// create the image view // create the image view
m_PrivateView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL, fpimageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED); B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED);
m_PrivateView->SetBitmap(pBitmap); fpimageView->SetBitmap(pbitmap);
// wrap a scroll view around the view // wrap a scroll view around the view
BScrollView* pScrollView = new BScrollView("image_scroller", m_PrivateView, B_FOLLOW_ALL, BScrollView *pscrollView = new BScrollView("image_scroller", fpimageView,
0, false, false, B_PLAIN_BORDER); B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
AddChild(pscrollView);
AddChild(pScrollView);
BScrollBar *hor_scroll;
BRect rect;
const int32 kstatusWidth = 190; const int32 kstatusWidth = 190;
BRect rect;
rect = Bounds(); rect = Bounds();
rect.top = viewFrame.bottom + 1; rect.top = viewFrame.bottom + 1;
rect.left = viewFrame.left + kstatusWidth; rect.left = viewFrame.left + kstatusWidth;
rect.right = viewFrame.right; rect.right = viewFrame.right;
BScrollBar *phscroll;
hor_scroll = new BScrollBar( rect, "hor_scroll", m_PrivateView, 0,150, B_HORIZONTAL ); phscroll = new BScrollBar(rect, "hscroll", fpimageView, 0, 150,
AddChild( hor_scroll ); B_HORIZONTAL);
AddChild(phscroll);
ShowImageStatusView * status_bar;
rect.left = 0; rect.left = 0;
rect.right = kstatusWidth - 1; rect.right = kstatusWidth - 1;
ShowImageStatusView *pstatusView;
status_bar = new ShowImageStatusView( rect, "status_bar", B_FOLLOW_BOTTOM, B_WILL_DRAW ); pstatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
status_bar->SetViewColor( ui_color( B_MENU_BACKGROUND_COLOR ) ); B_WILL_DRAW);
status_bar->SetText(strId); pstatusView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
pstatusView->SetText(strId);
AddChild( status_bar ); AddChild(pstatusView);
BScrollBar *vert_scroll;
rect = Bounds(); rect = Bounds();
rect.top = viewFrame.top; rect.top = viewFrame.top;
rect.left = viewFrame.right + 1; rect.left = viewFrame.right + 1;
rect.bottom = viewFrame.bottom; 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 ); WindowRedimension(pbitmap);
AddChild( vert_scroll );
WindowRedimension( pBitmap );
// finish creating window // finish creating window
SetRef(ref); SetRef(pref);
UpdateTitle(); UpdateTitle();
m_PrivateView->pBar = pBar;
Show(); Show();
} }
ShowImageWindow::~ShowImageWindow() ShowImageWindow::~ShowImageWindow()
{ {
delete m_pReferences; delete fpref;
} }
void ShowImageWindow::WindowActivated(bool active) status_t
ShowImageWindow::InitCheck()
{ {
// WindowRedimension( pBitmap ); if (!fpref || !fpimageView)
}
status_t ShowImageWindow::InitCheck()
{
if (! m_pReferences) {
return B_ERROR; return B_ERROR;
} else { else
return B_OK; return B_OK;
}
} }
void ShowImageWindow::SetRef(const entry_ref* ref) void
ShowImageWindow::SetRef(const entry_ref *pref)
{ {
if (! m_pReferences) { if (!fpref)
m_pReferences = new entry_ref(*ref); fpref = new entry_ref(*pref);
} else { else
*m_pReferences = *ref; *fpref = *pref;
}
} }
void ShowImageWindow::UpdateTitle() void
ShowImageWindow::UpdateTitle()
{ {
BEntry entry(m_pReferences); BEntry entry(fpref);
if (entry.InitCheck() == B_OK) { if (entry.InitCheck() == B_OK) {
BPath path; BPath path;
entry.GetPath(&path); entry.GetPath(&path);
if (path.InitCheck() == B_OK) { if (path.InitCheck() == B_OK)
SetTitle(path.Path()); SetTitle(path.Path());
} }
}
} }
void ShowImageWindow::LoadMenus(BMenuBar* pBar) void
ShowImageWindow::LoadMenus(BMenuBar *pbar)
{ {
BMenu* pMenu = new BMenu("File"); BMenu *pmenu = new BMenu("File");
AddItemMenu(pmenu, "Open", MSG_FILE_OPEN, 'O', 0, 'A', true);
AddItemMenu( pMenu, "Open", MSG_FILE_OPEN, 'O', 0, 'A', true ); pmenu->AddSeparatorItem();
pMenu->AddSeparatorItem(); BMenu *pmenuSaveAs = new BMenu("Save As...", B_ITEMS_IN_COLUMN);
BTranslationUtils::AddTranslationItems(pmenuSaveAs, B_TRANSLATOR_BITMAP);
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 // Fill Save As submenu with all types that can be converted
// to from the Be bitmap image format // 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 = new BMenu("Edit");
pMenu->AddSeparatorItem(); AddItemMenu(pmenu, "Undo", B_UNDO, 'Z', 0, 'W', false);
AddItemMenu( pMenu, "About ShowImage...", B_ABOUT_REQUESTED, 0, 0, 'A', true); pmenu->AddSeparatorItem();
pMenu->AddSeparatorItem(); AddItemMenu(pmenu, "Cut", B_CUT, 'X', 0, 'W', false);
AddItemMenu( pMenu, "Quit", B_QUIT_REQUESTED, 'Q', 0, 'A', true); 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("Image");
AddItemMenu(pmenu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true);
pMenu = new BMenu("Edit"); pbar->AddItem(pmenu);
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);
} }
BMenuItem * ShowImageWindow::AddItemMenu( BMenu *pMenu, char *Caption, long unsigned int msg, BMenuItem *
char shortcut, uint32 modifier, char target, bool enabled ) { 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);
BMenuItem* pItem; if (target == 'A')
pitem->SetTarget(be_app);
pItem = new BMenuItem( Caption, new BMessage(msg), shortcut ); pitem->SetEnabled(benabled);
pmenu->AddItem(pitem);
if ( target == 'A' ) return pitem;
pItem->SetTarget(be_app);
pItem->SetEnabled( enabled );
pMenu->AddItem(pItem);
return( pItem );
} }
void ShowImageWindow::WindowRedimension( BBitmap *pBitmap ) void
ShowImageWindow::WindowRedimension(BBitmap *pbitmap)
{ {
// set the window's min & max size limits // set the window's min & max size limits
// based on document's data bounds // based on document's data bounds
float maxWidth = pBitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH; float maxWidth = pbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH;
float maxHeight = pBitmap->Bounds().Height() float maxHeight = pbitmap->Bounds().Height() + fpbar->Frame().Height() +
+ pBar->Frame().Height() B_H_SCROLL_BAR_HEIGHT + 1;
+ B_H_SCROLL_BAR_HEIGHT + 1;
float minWidth = min(maxWidth, 100.0f); float minWidth = min(maxWidth, 100.0f);
float minHeight = min(maxHeight, 100.0f); float minHeight = min(maxHeight, 100.0f);
// adjust the window's current size based on new min/max values // adjust the window's current size based on new min/max values
float curWidth = Bounds().Width(); float curWidth = Bounds().Width();
float curHeight = Bounds().Height(); float curHeight = Bounds().Height();
if (curWidth < minWidth) { if (curWidth < minWidth)
curWidth = minWidth; curWidth = minWidth;
} else if (curWidth > maxWidth) { else if (curWidth > maxWidth)
curWidth = maxWidth; curWidth = maxWidth;
}
if (curHeight < minHeight) { if (curHeight < minHeight)
curHeight = minHeight; curHeight = minHeight;
} else if (curHeight > maxHeight) { else if (curHeight > maxHeight)
curHeight = maxHeight; curHeight = maxHeight;
}
if ( minWidth < 250 ) { if (minWidth < 250)
minWidth = 250; minWidth = 250;
}
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight); SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
ResizeTo(curWidth, curHeight); 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 (pmsg->what) {
switch (message->what) {
case MSG_OUTPUT_TYPE: case MSG_OUTPUT_TYPE:
// User clicked Save As then choose an output format // 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; break;
case MSG_SAVE_PANEL: case MSG_SAVE_PANEL:
// User specified where to save the output image // User specified where to save the output image
SaveToFile(message); SaveToFile(pmsg);
break; break;
case MSG_CLOSE: case MSG_CLOSE:
if (CanQuit())
Quit(); Quit();
break; break;
case B_UNDO : case B_CANCEL:
pAlert = new BAlert( "Edit/Undo", delete fpsavePanel;
"Edit/Undo not implemented yet", "OK"); fpsavePanel = NULL;
pAlert->Go();
break; 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() );
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; break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(pmsg);
break; break;
} }
} }
@@ -314,24 +311,27 @@ void ShowImageWindow::MessageReceived(BMessage* message)
void void
ShowImageWindow::SaveAs(BMessage *pmsg) ShowImageWindow::SaveAs(BMessage *pmsg)
{ {
// Handle SaveAs menu choice by setting the // Read the translator and output type the user chose
// translator and desired output format translator_id outTranslator;
// and giving the user a save panel uint32 outType;
if (pmsg->FindInt32(TRANSLATOR_FLD,
if (pmsg->FindInt32("be:translator", reinterpret_cast<int32 *>(&outTranslator)) != B_OK)
reinterpret_cast<int32 *>(&foutTranslator)) != B_OK)
return; return;
if (pmsg->FindInt32("be:type", if (pmsg->FindInt32(TYPE_FLD,
reinterpret_cast<int32 *>(&foutType)) != B_OK) reinterpret_cast<int32 *>(&outType)) != B_OK)
return; return;
if (!fpsavePanel) { // 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);
// Create save panel and show it
fpsavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0, fpsavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0,
false, new BMessage(MSG_SAVE_PANEL)); false, ppanelMsg);
if (!fpsavePanel) if (!fpsavePanel)
return; return;
}
fpsavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE); fpsavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE);
fpsavePanel->Show(); fpsavePanel->Show();
} }
@@ -339,11 +339,7 @@ ShowImageWindow::SaveAs(BMessage *pmsg)
void void
ShowImageWindow::SaveToFile(BMessage *pmsg) ShowImageWindow::SaveToFile(BMessage *pmsg)
{ {
// After the user has chosen which format // Read in where the file should be saved
// 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.
entry_ref dirref; entry_ref dirref;
if (pmsg->FindRef("directory", &dirref) != B_OK) if (pmsg->FindRef("directory", &dirref) != B_OK)
return; return;
@@ -351,15 +347,28 @@ ShowImageWindow::SaveToFile(BMessage *pmsg)
if (pmsg->FindString("name", &filename) != B_OK) if (pmsg->FindString("name", &filename) != B_OK)
return; 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); BDirectory dir(&dirref);
BFile file(&dir, filename, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); BFile file(&dir, filename, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if (file.InitCheck() != B_OK) if (file.InitCheck() != B_OK)
return; 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(); BTranslatorRoster *proster = BTranslatorRoster::Default();
if (proster->Translate(foutTranslator, &stream, NULL, if (proster->Translate(outTranslator, &stream, NULL,
&file, foutType) != B_OK) { &file, outType) != B_OK) {
BAlert *palert = new BAlert(NULL, "Error writing image file.", "Ok"); BAlert *palert = new BAlert(NULL, "Error writing image file.", "Ok");
palert->Go(); palert->Go();
} }
@@ -370,6 +379,22 @@ ShowImageWindow::SaveToFile(BMessage *pmsg)
// detach so it doesn't get deleted // 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 void
ShowImageWindow::Quit() ShowImageWindow::Quit()
{ {
@@ -378,4 +403,3 @@ ShowImageWindow::Quit()
BWindow::Quit(); BWindow::Quit();
} }
// BMenu* pMenuDither = ;
+50 -26
View File
@@ -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 #ifndef _ShowImageWindow_h
#define _ShowImageWindow_h #define _ShowImageWindow_h
@@ -12,46 +36,46 @@
class ShowImageView; class ShowImageView;
class ShowImageWindow : public BWindow // BMessage field names used in Save messages
{ #define TRANSLATOR_FLD "be:translator"
public: #define TYPE_FLD "be:type"
static status_t NewWindow(const entry_ref* ref);
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 ~ShowImageWindow();
virtual void WindowActivated(bool active); virtual void FrameResized(float width, float height);
virtual void FrameResized( float new_width, float new_height ); virtual void MessageReceived(BMessage *pmsg);
virtual void MessageReceived(BMessage* message); virtual bool QuitRequested();
virtual void Quit(); virtual void Quit();
status_t InitCheck(); 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 UpdateTitle();
void LoadMenus(BMenuBar* pBar); void LoadMenus(BMenuBar *pbar);
void WindowRedimension( BBitmap *pBitmap ); void WindowRedimension(BBitmap *pbitmap);
BMenuBar* pBar;
private: private:
BMenuItem * AddItemMenu( BMenu *pMenu, char *Caption, long unsigned int msg, BMenuItem *AddItemMenu(BMenu *pmenu, char *caption,
char shortcut, uint32 modifier, char target, bool enabled ); long unsigned int msg, char shortcut, uint32 modifier,
char target, bool enabled);
void SaveAs(BMessage *pmsg); void SaveAs(BMessage *pmsg);
// Handle Save As submenu choice // Handle Save As submenu choice
void SaveToFile(BMessage *pmsg); 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; BFilePanel *fpsavePanel;
translator_id foutTranslator; BMenuBar *fpbar;
uint32 foutType; entry_ref *fpref;
ShowImageView *fpimageView;
entry_ref* m_pReferences;
ShowImageView* m_PrivateView;
static BLocker s_winListLocker;
static BList s_winList;
}; };
#endif /* _ShowImageWindow_h */ #endif /* _ShowImageWindow_h */