mirror of
https://github.com/autc04/Retro68.git
synced 2025-03-22 10:37:48 +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.cc
|
||||
ToolLauncher.cc
|
||||
Window.h
|
||||
StatusDisplay.h
|
||||
StatusDisplay.cc
|
||||
AboutBox.h
|
||||
AboutBox.cc
|
||||
ConnectionProvider.h
|
||||
CarbonFileCompat.h
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include "AppLauncher.h"
|
||||
#include "StatusDisplay.h"
|
||||
#include "AboutBox.h"
|
||||
|
||||
#include <ServerProtocol.h>
|
||||
#include <Processes.h>
|
||||
@ -48,6 +49,7 @@
|
||||
#include "OpenTptConnectionProvider.h"
|
||||
#endif
|
||||
|
||||
#include "SystemInfo.h"
|
||||
|
||||
#include "CarbonFileCompat.h"
|
||||
|
||||
@ -82,8 +84,8 @@ bool portsAvailable[] = { false, false, false, false };
|
||||
#else
|
||||
bool portsAvailable[] = { true, true, false, false };
|
||||
#endif
|
||||
Boolean hasIconUtils = true;
|
||||
Boolean hasColorQD = true;
|
||||
bool hasIconUtils = true;
|
||||
bool hasColorQD = true;
|
||||
|
||||
struct Prefs
|
||||
{
|
||||
@ -126,64 +128,6 @@ bool gQuitting = false;
|
||||
WindowRef aboutWindow = nullptr;
|
||||
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
|
||||
#define EnableItem EnableMenuItem
|
||||
@ -246,7 +190,7 @@ void DoMenuCommand(long menuCommand)
|
||||
if(menuID == kMenuApple)
|
||||
{
|
||||
if(menuItem == kItemAbout)
|
||||
ShowAboutBox();
|
||||
AboutBox::ShowAboutBox();
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
else
|
||||
{
|
||||
@ -777,10 +721,9 @@ int main()
|
||||
case inGoAway:
|
||||
if(TrackGoAway(win, e.where))
|
||||
{
|
||||
if(win == aboutWindow)
|
||||
if(Window *winObject = reinterpret_cast<Window*>(GetWRefCon(win)))
|
||||
{
|
||||
DisposeWindow(win);
|
||||
aboutWindow = nullptr;
|
||||
delete winObject;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -806,10 +749,11 @@ int main()
|
||||
}
|
||||
break;
|
||||
case updateEvt:
|
||||
if(statusDisplay && (WindowRef)e.message == statusDisplay->GetWindow())
|
||||
statusDisplay->Update();
|
||||
else if(aboutWindow && (WindowRef)e.message == aboutWindow)
|
||||
UpdateAboutWindow();
|
||||
win = reinterpret_cast<WindowRef>(e.message);
|
||||
if(Window *winObject = reinterpret_cast<Window*>(GetWRefCon(win)))
|
||||
{
|
||||
winObject->Update();
|
||||
}
|
||||
break;
|
||||
case kHighLevelEvent:
|
||||
if(hasAppleEvents)
|
||||
|
@ -2,12 +2,12 @@
|
||||
#include <Quickdraw.h>
|
||||
#include <Windows.h>
|
||||
#include <string.h>
|
||||
#include "SystemInfo.h"
|
||||
|
||||
const short tableTop = 50;
|
||||
const short tableLineHeight = 20;
|
||||
const short tableBaseline = 15;
|
||||
|
||||
extern Boolean hasColorQD;
|
||||
|
||||
enum class StatusDisplay::Stat : short
|
||||
{
|
||||
@ -25,6 +25,7 @@ StatusDisplay::StatusDisplay()
|
||||
statusWindow = hasColorQD ?
|
||||
GetNewCWindow(129, NULL, (WindowPtr) -1)
|
||||
: GetNewWindow(129, NULL, (WindowPtr) -1);
|
||||
SetWRefCon(statusWindow, reinterpret_cast<long>(static_cast<Window*>(this)));
|
||||
|
||||
#if TARGET_API_MAC_CARBON
|
||||
Rect bounds;
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <Windows.h>
|
||||
#include <TextUtils.h>
|
||||
|
||||
#include "Window.h"
|
||||
|
||||
enum class AppStatus
|
||||
{
|
||||
empty = 0,
|
||||
@ -13,7 +15,7 @@ enum class AppStatus
|
||||
uploading
|
||||
};
|
||||
|
||||
class StatusDisplay
|
||||
class StatusDisplay : public Window
|
||||
{
|
||||
WindowPtr statusWindow;
|
||||
Str255 statusString = "\p";
|
||||
@ -46,7 +48,7 @@ public:
|
||||
~StatusDisplay();
|
||||
|
||||
WindowPtr GetWindow() { return statusWindow; }
|
||||
void Update();
|
||||
virtual void Update() override;
|
||||
|
||||
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…
x
Reference in New Issue
Block a user