mirror of
https://github.com/autc04/Retro68.git
synced 2024-09-30 01:57:08 +00:00
LaunchAPPLServer: refactor a bit
This commit is contained in:
parent
e39e0a09c5
commit
3928a55b91
78
LaunchAPPL/Server/AboutBox.cc
Normal file
78
LaunchAPPL/Server/AboutBox.cc
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "AboutBox.h"
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <TextEdit.h>
|
||||||
|
#include <Resources.h>
|
||||||
|
|
||||||
|
#include "SystemInfo.h"
|
||||||
|
|
||||||
|
AboutBox* AboutBox::aboutBox = nullptr;
|
||||||
|
|
||||||
|
void AboutBox::ShowAboutBox()
|
||||||
|
{
|
||||||
|
if(aboutBox)
|
||||||
|
SelectWindow(aboutBox->window);
|
||||||
|
else
|
||||||
|
aboutBox = new AboutBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
AboutBox::AboutBox()
|
||||||
|
{
|
||||||
|
window = hasColorQD ?
|
||||||
|
GetNewCWindow(128, NULL, (WindowPtr) -1)
|
||||||
|
: GetNewWindow(128, NULL, (WindowPtr) -1);
|
||||||
|
|
||||||
|
SetWRefCon(window, reinterpret_cast<long>(static_cast<Window*>(this)));
|
||||||
|
|
||||||
|
#if TARGET_API_MAC_CARBON
|
||||||
|
Rect screenBounds = (*GetMainDevice())->gdRect;
|
||||||
|
Rect portBounds;
|
||||||
|
GetWindowPortBounds(window,&portBounds);
|
||||||
|
#else
|
||||||
|
const Rect& screenBounds = qd.screenBits.bounds;
|
||||||
|
const Rect& portBounds = window->portRect;
|
||||||
|
#endif
|
||||||
|
MacMoveWindow(window,
|
||||||
|
screenBounds.right/2 - portBounds.right/2,
|
||||||
|
screenBounds.bottom/2 - portBounds.bottom/2,
|
||||||
|
false);
|
||||||
|
|
||||||
|
ShowWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
AboutBox::~AboutBox()
|
||||||
|
{
|
||||||
|
DisposeWindow(window);
|
||||||
|
if(aboutBox == this)
|
||||||
|
aboutBox = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AboutBox::Update()
|
||||||
|
{
|
||||||
|
SetPortWindowPort(window);
|
||||||
|
BeginUpdate(window);
|
||||||
|
|
||||||
|
Rect portRect;
|
||||||
|
GetWindowPortBounds(window,&portRect);
|
||||||
|
EraseRect(&portRect);
|
||||||
|
|
||||||
|
Rect r;
|
||||||
|
SetRect(&r, portRect.right/2 - 16, 10, portRect.right/2 + 16, 42);
|
||||||
|
|
||||||
|
if(hasIconUtils)
|
||||||
|
PlotIconID(&r, kAlignAbsoluteCenter, kTransformNone, 128);
|
||||||
|
else
|
||||||
|
PlotIcon(&r, GetResource('ICN#', 128));
|
||||||
|
|
||||||
|
r = portRect;
|
||||||
|
r.left += 10;
|
||||||
|
r.top += 52;
|
||||||
|
r.bottom -= 10;
|
||||||
|
r.right -= 10;
|
||||||
|
|
||||||
|
Handle h = GetResource('TEXT', 128);
|
||||||
|
HLock(h);
|
||||||
|
TETextBox(*h, GetHandleSize(h), &r, teJustLeft);
|
||||||
|
HUnlock(h);
|
||||||
|
|
||||||
|
EndUpdate(window);
|
||||||
|
}
|
19
LaunchAPPL/Server/AboutBox.h
Normal file
19
LaunchAPPL/Server/AboutBox.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Window.h"
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
class AboutBox : public Window
|
||||||
|
{
|
||||||
|
WindowRef window;
|
||||||
|
|
||||||
|
static AboutBox* aboutBox;
|
||||||
|
|
||||||
|
AboutBox();
|
||||||
|
public:
|
||||||
|
~AboutBox();
|
||||||
|
|
||||||
|
virtual void Update();
|
||||||
|
|
||||||
|
static void ShowAboutBox();
|
||||||
|
};
|
@ -36,8 +36,11 @@ add_application(LaunchAPPLServer
|
|||||||
AppLauncher.h
|
AppLauncher.h
|
||||||
AppLauncher.cc
|
AppLauncher.cc
|
||||||
ToolLauncher.cc
|
ToolLauncher.cc
|
||||||
|
Window.h
|
||||||
StatusDisplay.h
|
StatusDisplay.h
|
||||||
StatusDisplay.cc
|
StatusDisplay.cc
|
||||||
|
AboutBox.h
|
||||||
|
AboutBox.cc
|
||||||
ConnectionProvider.h
|
ConnectionProvider.h
|
||||||
CarbonFileCompat.h
|
CarbonFileCompat.h
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include "AppLauncher.h"
|
#include "AppLauncher.h"
|
||||||
#include "StatusDisplay.h"
|
#include "StatusDisplay.h"
|
||||||
|
#include "AboutBox.h"
|
||||||
|
|
||||||
#include <ServerProtocol.h>
|
#include <ServerProtocol.h>
|
||||||
#include <Processes.h>
|
#include <Processes.h>
|
||||||
@ -48,6 +49,7 @@
|
|||||||
#include "OpenTptConnectionProvider.h"
|
#include "OpenTptConnectionProvider.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "SystemInfo.h"
|
||||||
|
|
||||||
#include "CarbonFileCompat.h"
|
#include "CarbonFileCompat.h"
|
||||||
|
|
||||||
@ -82,8 +84,8 @@ bool portsAvailable[] = { false, false, false, false };
|
|||||||
#else
|
#else
|
||||||
bool portsAvailable[] = { true, true, false, false };
|
bool portsAvailable[] = { true, true, false, false };
|
||||||
#endif
|
#endif
|
||||||
Boolean hasIconUtils = true;
|
bool hasIconUtils = true;
|
||||||
Boolean hasColorQD = true;
|
bool hasColorQD = true;
|
||||||
|
|
||||||
struct Prefs
|
struct Prefs
|
||||||
{
|
{
|
||||||
@ -126,64 +128,6 @@ bool gQuitting = false;
|
|||||||
WindowRef aboutWindow = nullptr;
|
WindowRef aboutWindow = nullptr;
|
||||||
void ConnectionChanged();
|
void ConnectionChanged();
|
||||||
|
|
||||||
void ShowAboutBox()
|
|
||||||
{
|
|
||||||
if(aboutWindow)
|
|
||||||
{
|
|
||||||
SelectWindow(aboutWindow);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WindowRef w = hasColorQD ?
|
|
||||||
GetNewCWindow(128, NULL, (WindowPtr) -1)
|
|
||||||
: GetNewWindow(128, NULL, (WindowPtr) -1);
|
|
||||||
aboutWindow = w;
|
|
||||||
#if TARGET_API_MAC_CARBON
|
|
||||||
Rect screenBounds = (*GetMainDevice())->gdRect;
|
|
||||||
Rect portBounds;
|
|
||||||
GetWindowPortBounds(w,&portBounds);
|
|
||||||
#else
|
|
||||||
const Rect& screenBounds = qd.screenBits.bounds;
|
|
||||||
const Rect& portBounds = w->portRect;
|
|
||||||
#endif
|
|
||||||
MacMoveWindow(w,
|
|
||||||
screenBounds.right/2 - portBounds.right/2,
|
|
||||||
screenBounds.bottom/2 - portBounds.bottom/2,
|
|
||||||
false);
|
|
||||||
|
|
||||||
ShowWindow(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateAboutWindow()
|
|
||||||
{
|
|
||||||
SetPortWindowPort(aboutWindow);
|
|
||||||
BeginUpdate(aboutWindow);
|
|
||||||
|
|
||||||
Rect portRect;
|
|
||||||
GetWindowPortBounds(aboutWindow,&portRect);
|
|
||||||
EraseRect(&portRect);
|
|
||||||
|
|
||||||
Rect r;
|
|
||||||
SetRect(&r, portRect.right/2 - 16, 10, portRect.right/2 + 16, 42);
|
|
||||||
|
|
||||||
if(hasIconUtils)
|
|
||||||
PlotIconID(&r, kAlignAbsoluteCenter, kTransformNone, 128);
|
|
||||||
else
|
|
||||||
PlotIcon(&r, GetResource('ICN#', 128));
|
|
||||||
|
|
||||||
r = portRect;
|
|
||||||
r.left += 10;
|
|
||||||
r.top += 52;
|
|
||||||
r.bottom -= 10;
|
|
||||||
r.right -= 10;
|
|
||||||
|
|
||||||
Handle h = GetResource('TEXT', 128);
|
|
||||||
HLock(h);
|
|
||||||
TETextBox(*h, GetHandleSize(h), &r, teJustLeft);
|
|
||||||
HUnlock(h);
|
|
||||||
|
|
||||||
EndUpdate(aboutWindow);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if TARGET_API_MAC_CARBON
|
#if TARGET_API_MAC_CARBON
|
||||||
#define EnableItem EnableMenuItem
|
#define EnableItem EnableMenuItem
|
||||||
@ -246,7 +190,7 @@ void DoMenuCommand(long menuCommand)
|
|||||||
if(menuID == kMenuApple)
|
if(menuID == kMenuApple)
|
||||||
{
|
{
|
||||||
if(menuItem == kItemAbout)
|
if(menuItem == kItemAbout)
|
||||||
ShowAboutBox();
|
AboutBox::ShowAboutBox();
|
||||||
#if !TARGET_API_MAC_CARBON
|
#if !TARGET_API_MAC_CARBON
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -777,10 +721,9 @@ int main()
|
|||||||
case inGoAway:
|
case inGoAway:
|
||||||
if(TrackGoAway(win, e.where))
|
if(TrackGoAway(win, e.where))
|
||||||
{
|
{
|
||||||
if(win == aboutWindow)
|
if(Window *winObject = reinterpret_cast<Window*>(GetWRefCon(win)))
|
||||||
{
|
{
|
||||||
DisposeWindow(win);
|
delete winObject;
|
||||||
aboutWindow = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -806,10 +749,11 @@ int main()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case updateEvt:
|
case updateEvt:
|
||||||
if(statusDisplay && (WindowRef)e.message == statusDisplay->GetWindow())
|
win = reinterpret_cast<WindowRef>(e.message);
|
||||||
statusDisplay->Update();
|
if(Window *winObject = reinterpret_cast<Window*>(GetWRefCon(win)))
|
||||||
else if(aboutWindow && (WindowRef)e.message == aboutWindow)
|
{
|
||||||
UpdateAboutWindow();
|
winObject->Update();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case kHighLevelEvent:
|
case kHighLevelEvent:
|
||||||
if(hasAppleEvents)
|
if(hasAppleEvents)
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
#include <Quickdraw.h>
|
#include <Quickdraw.h>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "SystemInfo.h"
|
||||||
|
|
||||||
const short tableTop = 50;
|
const short tableTop = 50;
|
||||||
const short tableLineHeight = 20;
|
const short tableLineHeight = 20;
|
||||||
const short tableBaseline = 15;
|
const short tableBaseline = 15;
|
||||||
|
|
||||||
extern Boolean hasColorQD;
|
|
||||||
|
|
||||||
enum class StatusDisplay::Stat : short
|
enum class StatusDisplay::Stat : short
|
||||||
{
|
{
|
||||||
@ -25,6 +25,7 @@ StatusDisplay::StatusDisplay()
|
|||||||
statusWindow = hasColorQD ?
|
statusWindow = hasColorQD ?
|
||||||
GetNewCWindow(129, NULL, (WindowPtr) -1)
|
GetNewCWindow(129, NULL, (WindowPtr) -1)
|
||||||
: GetNewWindow(129, NULL, (WindowPtr) -1);
|
: GetNewWindow(129, NULL, (WindowPtr) -1);
|
||||||
|
SetWRefCon(statusWindow, reinterpret_cast<long>(static_cast<Window*>(this)));
|
||||||
|
|
||||||
#if TARGET_API_MAC_CARBON
|
#if TARGET_API_MAC_CARBON
|
||||||
Rect bounds;
|
Rect bounds;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <TextUtils.h>
|
#include <TextUtils.h>
|
||||||
|
|
||||||
|
#include "Window.h"
|
||||||
|
|
||||||
enum class AppStatus
|
enum class AppStatus
|
||||||
{
|
{
|
||||||
empty = 0,
|
empty = 0,
|
||||||
@ -13,7 +15,7 @@ enum class AppStatus
|
|||||||
uploading
|
uploading
|
||||||
};
|
};
|
||||||
|
|
||||||
class StatusDisplay
|
class StatusDisplay : public Window
|
||||||
{
|
{
|
||||||
WindowPtr statusWindow;
|
WindowPtr statusWindow;
|
||||||
Str255 statusString = "\p";
|
Str255 statusString = "\p";
|
||||||
@ -46,7 +48,7 @@ public:
|
|||||||
~StatusDisplay();
|
~StatusDisplay();
|
||||||
|
|
||||||
WindowPtr GetWindow() { return statusWindow; }
|
WindowPtr GetWindow() { return statusWindow; }
|
||||||
void Update();
|
virtual void Update() override;
|
||||||
|
|
||||||
void Idle();
|
void Idle();
|
||||||
|
|
||||||
|
4
LaunchAPPL/Server/SystemInfo.h
Normal file
4
LaunchAPPL/Server/SystemInfo.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
extern bool hasColorQD;
|
||||||
|
extern bool hasIconUtils;
|
8
LaunchAPPL/Server/Window.h
Normal file
8
LaunchAPPL/Server/Window.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Window
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~Window() {}
|
||||||
|
virtual void Update() = 0;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user