]> Git repositories of Nishi - tewi.git/commitdiff
adding gui manager
authorNishi <nishi@nishi.boats>
Thu, 3 Oct 2024 20:04:15 +0000 (20:04 +0000)
committerNishi <nishi@nishi.boats>
Thu, 3 Oct 2024 20:04:15 +0000 (20:04 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@244 8739d7e6-ffea-ec47-b151-bdff447c6205

16 files changed:
Binary/pbtewi.bmp [new file with mode: 0644]
Binary/tewi.bmp [new file with mode: 0644]
Makefile
Platform/bcc.mk
Platform/vc6.mk
Platform/watcom.mk
Platform/win32.mk
Platform/win64.mk
Server/Makefile
Server/gui.c [new file with mode: 0644]
Server/gui.h [new file with mode: 0644]
Server/gui.rc [new file with mode: 0644]
Server/main.c
Server/tewi.rc
Tool/option.c
config.h.tmpl

diff --git a/Binary/pbtewi.bmp b/Binary/pbtewi.bmp
new file mode 100644 (file)
index 0000000..3b709bc
Binary files /dev/null and b/Binary/pbtewi.bmp differ
diff --git a/Binary/tewi.bmp b/Binary/tewi.bmp
new file mode 100644 (file)
index 0000000..21b77a1
Binary files /dev/null and b/Binary/tewi.bmp differ
index 7344a0a6eb3f2a478c3d234b77ca2cd07377438a..88cc56af54805c4ed25b6b28b508224757b521ee 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,7 @@ PLATFORM = generic
 PLATFORM_IDENT = NOT_WINDOWS
 PREFIX = /usr/local
 MODULE = ./Module
+OBJ = o
 
 include Platform/$(PLATFORM).mk
 
@@ -24,7 +25,7 @@ all: ./Server $(MODULE)
        cc -o $@ ./Tool/itworks.c
 
 ./Server:: ./Common ./Tool/option ./Tool/genconf ./Tool/itworks
-       $(MAKE) -C $@ $(FLAGS) EXTOBJS="`./Tool/option objs ../`" EXTLIBS="`./Tool/option libs ../ $(PLATFORM_IDENT)`" EXTCFLAGS="`./Tool/option cflags ../`" EXTLDFLAGS="`./Tool/option ldflags ../`"
+       $(MAKE) -C $@ $(FLAGS) EXTOBJS="`./Tool/option objs ../ $(PLATFORM_IDENT) $(OBJ)`" EXTLIBS="`./Tool/option libs ../ $(PLATFORM_IDENT) $(OBJ)`" EXTCFLAGS="`./Tool/option cflags ../ $(PLATFORM_IDENT) $(OBJ)`" EXTLDFLAGS="`./Tool/option ldflags ../ $(PLATFORM_IDENT) $(OBJ)`"
 
 ./Module:: ./Common
        $(MAKE) -C $@ $(FLAGS)
index 42e6f64a2b5279426693134b1ec4e9ac40bec0d4..ed96a23272d1069cc2cdac3d0a41c40a9fe3ff90 100644 (file)
@@ -14,4 +14,4 @@ EXEC =
 STATIC = lib
 LIBSUF = .dll
 OBJ = obj
-REQOBJS = tewi_bcc.res
+REQOBJS = tewi_bcc.res gui_bcc.res
index bcf8baa18be36d6192eb117aa3b754f728d3f8d7..d080ed43897f2f7e318716d5cf8133b3da4624b6 100644 (file)
@@ -13,4 +13,4 @@ EXEC =
 STATIC = lib
 LIBSUF = .dll
 OBJ = obj
-PREOBJS = tewi_vc6.res
+PREOBJS = tewi_vc6.res gui_vc6.res
index ee4393ef7b657d9d413c26dbb9e0ab526277229a..bf91582aaca5e98963a457c7885a16bfb2358e5c 100644 (file)
@@ -13,4 +13,4 @@ EXEC = .exe
 STATIC = lib
 LIBSUF = .dll
 OBJ = obj
-SERVADD = wrc -bt=nt -i=$(WATCOM)/h/nt -fe=tewi.exe tewi.rc
+SERVADD = wrc -bt=nt -i=$(WATCOM)/h/nt tewi.rc tewi.exe && wrc -bt=nt -i=$(WATCOM)/h/nt gui.rc tewi.exe
index 33682c3d3d5e5f0c216b7a6ff818ee2cea4dcec7..72930211cb77cbd2e42330a168be6d0d6c4ab19c 100644 (file)
@@ -11,4 +11,4 @@ LDFLAGS =
 LIBS =
 EXEC = .exe
 LIBSUF = .dll
-PREOBJS = tewi.res
+PREOBJS = tewi.res gui.res
index f2e5842d7fb637dc0c846083354eb5ea20099a5e..4976bb9c85097851cb97b6f31479ab2204c41713 100644 (file)
@@ -11,4 +11,4 @@ LDFLAGS =
 LIBS = 
 EXEC = .exe
 LIBSUF = .dll
-PREOBJS = tewi.res
+PREOBJS = tewi.res gui.res
index 18aa72ebe935e62a44a760240c9f395435b36e59..3f250f0bb4938b384e5fe91eb2a00e97cc44627a 100644 (file)
@@ -54,5 +54,14 @@ tewi_vc6.res: tewi.rc ../Binary/tewi.ico
 tewi_bcc.res: tewi.rc ../Binary/tewi.ico
        brc32 -r -fo$@ tewi.rc
 
+gui.res: gui.rc gui.h
+       $(WINDRES) gui.rc -O coff -o $@
+
+gui_vc6.res: gui.rc gui.h
+       rc /fo$@ gui.rc
+
+gui_bcc.res: gui.rc gui.h
+       brc32 -r -fo$@ gui.rc
+
 clean:
        rm -f *.o tewi *.exe *.res *.elf *.sfo *.pbp *.self *.pkg *.obj
diff --git a/Server/gui.c b/Server/gui.c
new file mode 100644 (file)
index 0000000..2f7a8e6
--- /dev/null
@@ -0,0 +1,224 @@
+/* $Id$ */
+
+#include "../config.h"
+
+#include "gui.h"
+
+#include <windows.h>
+#include <commctrl.h>
+
+HINSTANCE hInst;
+HBRUSH pbtewi_brush;
+HWND logarea;
+HWND button_start;
+HWND button_stop;
+HWND button_about;
+HWND status;
+BOOL tewi_alive;
+BOOL was_starting;
+BOOL exiting;
+
+#define WINWIDTH(rc) (rc.right - rc.left)
+#define WINHEIGHT(rc) (rc.bottom - rc.top)
+
+#define DIALOG_X(n) (HIWORD(GetDialogBaseUnits()) * n)
+#define DIALOG_Y(n) (LOWORD(GetDialogBaseUnits()) * n)
+
+void ShowBitmapSize(HWND hWnd, HDC hdc, const char* name, int x, int y, int w, int h){
+       HBITMAP hBitmap = LoadBitmap(hInst, name);
+       BITMAP bmp;
+       HDC hmdc;
+       GetObject(hBitmap, sizeof(bmp), &bmp);
+       hmdc = CreateCompatibleDC(hdc);
+       SelectObject(hmdc, hBitmap);
+       if(w == 0 && h == 0){
+               StretchBlt(hdc, x, y, bmp.bmWidth, bmp.bmHeight, hmdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
+       }else{
+               StretchBlt(hdc, x, y, w, h, hmdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
+       }
+       DeleteDC(hmdc);
+       DeleteObject(hBitmap);
+}
+
+void ShowBitmap(HWND hWnd, HDC hdc, const char* name, int x, int y){
+       ShowBitmapSize(hWnd, hdc, name, x, y, 0, 0);
+}
+
+LRESULT CALLBACK VersionDialog(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
+       if(msg == WM_COMMAND){
+               if(LOWORD(wp) == IDOK) EndDialog(hWnd, IDOK);
+       }else if(msg == WM_PAINT){
+               HDC hdc;
+               PAINTSTRUCT ps;
+               RECT size;
+
+               size.left = size.top = 5;
+               size.right = size.bottom = 32 + 5;
+               MapDialogRect(hWnd, &size);
+
+               hdc = BeginPaint(hWnd, &ps);
+               ShowBitmapSize(hWnd, hdc, "TEWILOGO", size.left, size.top, WINWIDTH(size), WINWIDTH(size));
+               EndPaint(hWnd, &ps);
+       }else{
+               return FALSE;
+       }
+       return TRUE;
+}
+
+void StartTewi(void){
+       was_starting = TRUE;
+}
+
+void StopTewi(void){
+       was_starting = TRUE;
+}
+
+LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
+       if(msg == WM_COMMAND){
+               int trig = LOWORD(wp);
+               int ev = HIWORD(wp);
+               if(trig == GUI_BUTTON_ABOUT){
+                       if(ev == BN_CLICKED){
+                               DialogBox(hInst, "VERSIONDLG", hWnd, VersionDialog);
+                       }
+               }else if(trig == GUI_BUTTON_START){
+                       if(ev == BN_CLICKED){
+                               SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Starting Tewi HTTPd");
+                               StartTewi();
+                       }
+               }else if(trig == GUI_BUTTON_STOP){
+                       if(ev == BN_CLICKED){
+                               SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Stopping Tewi HTTPd");
+                               StopTewi();
+                       }
+               }else if(trig == GUI_BUTTON_EXIT){
+                       if(ev == BN_CLICKED){
+                               if(tewi_alive){
+                                       SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Stopping Tewi HTTPd");
+                                       StopTewi();
+                                       exiting = TRUE;
+                               }else{
+                                       SendMessage(hWnd, WM_CLOSE, 0, 0);
+                               }
+                       }
+               }else if(trig == GUI_LOG){
+               }
+       }else if(msg == WM_CLOSE){
+               DestroyWindow(hWnd);
+       }else if(msg == WM_DESTROY){
+               DeleteObject(pbtewi_brush);
+               PostQuitMessage(0);
+       }else if(msg == WM_CREATE){
+               RECT rc, src;
+               GetClientRect(hWnd, &rc);
+
+               InitCommonControls();
+
+               status = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM, NULL, hWnd, GUI_STATUS);
+               SendMessage(status, SB_SIMPLE, 0, 0);
+               SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Welcome to Tewi HTTPd");
+               SendMessage(status, SB_GETRECT, 0, (LPARAM)&src);
+
+               pbtewi_brush = CreateSolidBrush(RGB(0xf7, 0xc9, 0xf3));
+               button_start = CreateWindow("BUTTON", "&Start", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 0, 100, 20, hWnd, (HMENU)GUI_BUTTON_START, hInst, NULL);
+               button_stop = CreateWindow("BUTTON", "S&top", WS_CHILD | WS_VISIBLE | WS_DISABLED | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 1, 100, 20, hWnd, (HMENU)GUI_BUTTON_STOP, hInst, NULL);
+               button_about = CreateWindow("BUTTON", "&About", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 2, 100, 20, hWnd, (HMENU)GUI_BUTTON_ABOUT, hInst, NULL);
+               button_about = CreateWindow("BUTTON", "E&xit", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, WINHEIGHT(rc) - WINHEIGHT(src) - 20, 100, 20, hWnd, (HMENU)GUI_BUTTON_EXIT, hInst, NULL);
+               logarea = CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL, 0, 40, WINWIDTH(rc) - 100, WINHEIGHT(rc) - 40 - WINHEIGHT(src), hWnd, (HMENU)GUI_LOG, hInst, NULL);
+               SetTimer(hWnd, TIMER_WATCH_TEWI, 100, NULL);
+       }else if(msg == WM_TIMER){
+               if(wp == TIMER_WATCH_TEWI){
+                       if(tewi_alive){
+                               if(was_starting){
+                                       was_starting = FALSE;
+                                       SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Started Tewi HTTPd");
+                               }
+                               EnableWindow(button_start, FALSE);
+                               EnableWindow(button_stop, TRUE);
+                       }else{
+                               if(was_starting){
+                                       was_starting = FALSE;
+                                       SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Stopped Tewi HTTPd");
+                               }
+                               EnableWindow(button_start, TRUE);
+                               EnableWindow(button_stop, FALSE);
+                               if(exiting){
+                                       KillTimer(hWnd, TIMER_WATCH_TEWI);
+                                       SendMessage(hWnd, WM_CLOSE, 0, 0);
+                               }
+                       }
+               }
+       }else if(msg == WM_PAINT){
+               HDC hdc;
+               PAINTSTRUCT ps;
+               RECT rc;
+               RECT fill;
+
+               GetClientRect(hWnd, &rc);
+               hdc = BeginPaint(hWnd, &ps);
+               SetRect(&fill, 0, 0, WINWIDTH(rc), 40);
+               FillRect(hdc, &fill, pbtewi_brush);
+               ShowBitmap(hWnd, hdc, "PBTEWI", 0, 0);
+               EndPaint(hWnd, &ps);
+       }else{
+               return DefWindowProc(hWnd, msg, wp, lp);
+       }
+       return 0;
+}
+
+BOOL InitApp(void){
+       WNDCLASS wc;
+       wc.style = CS_HREDRAW | CS_VREDRAW;
+       wc.lpfnWndProc = WndProc;
+       wc.cbClsExtra = 0;
+       wc.cbWndExtra = 0;
+       wc.hInstance = hInst;
+       wc.hIcon = LoadIcon(hInst, "TEWI");
+       wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+       wc.hbrBackground = GetSysColorBrush(COLOR_MENU);
+       wc.lpszMenuName = NULL;
+       wc.lpszClassName = "tewihttpd";
+       return RegisterClass(&wc);
+}
+
+BOOL InitWindow(int nCmdShow){
+       HWND hWnd;
+       RECT deskrc, rc;
+       HWND hDeskWnd = GetDesktopWindow();
+       GetWindowRect(hDeskWnd, &deskrc);
+       hWnd = CreateWindow("tewihttpd", "Tewi HTTPd", (WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME) ^ WS_MAXIMIZEBOX, 0, 0, 600, 200, NULL, 0, hInst, NULL);
+
+       if(!hWnd){
+               return FALSE;
+       }
+       GetWindowRect(hWnd, &rc);
+       SetWindowPos(hWnd, HWND_TOP, (deskrc.right - (rc.right - rc.left)) / 2, (deskrc.bottom - (rc.bottom - rc.top)) / 2, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
+       ShowWindow(hWnd, nCmdShow);
+       UpdateWindow(hWnd);
+       return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow){
+       MSG msg;
+       BOOL bret;
+       hInst = hCurInst;
+       tewi_alive = FALSE;
+       was_starting = FALSE;
+       exiting = FALSE;
+       if(!InitApp()){
+               return FALSE;
+       }
+       if(!InitWindow(nCmdShow)){
+               return FALSE;
+       }
+
+       while((bret = GetMessage(&msg, NULL, 0, 0)) != 0){
+               if(bret == -1) {
+                       break;
+               } else {
+                       TranslateMessage(&msg);
+                       DispatchMessage(&msg);
+               }
+       }
+       return (int)msg.wParam;
+}
diff --git a/Server/gui.h b/Server/gui.h
new file mode 100644 (file)
index 0000000..faf1607
--- /dev/null
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+#ifndef __GUI_H__
+#define __GUI_H__
+
+#define GUI_HELP_ABOUT 100
+#define GUI_BUTTON_START 101
+#define GUI_BUTTON_STOP 102
+#define GUI_BUTTON_ABOUT 103
+#define GUI_STATUS 104
+#define GUI_TEWI_ICON 105
+#define GUI_TEWI_NAME 106
+#define GUI_TEWI_ORIGINAL 107
+#define GUI_TEWI_DATE 108
+#define GUI_LOG 109
+#define GUI_BUTTON_EXIT 104
+
+#define TIMER_WATCH_TEWI 1000
+
+#endif
diff --git a/Server/gui.rc b/Server/gui.rc
new file mode 100644 (file)
index 0000000..11383d1
--- /dev/null
@@ -0,0 +1,18 @@
+/* $Id$ */
+
+#include <windows.h>
+#include "gui.h"
+#include "tw_version.h"
+
+PBTEWI BITMAP "../Binary/pbtewi.bmp"
+TEWILOGO BITMAP "../Binary/tewi.bmp"
+
+VERSIONDLG DIALOG 0, 0, 200, 50
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Version Information"
+{
+       LTEXT "Tewi HTTPd version " TW_VERSION, GUI_TEWI_NAME, 42, 5, 192, 50
+       LTEXT "Original by Nishi <nishi@nishi.boats>", GUI_TEWI_ORIGINAL, 42, 5 + 8, 192, 50
+       LTEXT "Compilation date: " __DATE__ " " __TIME__, GUI_TEWI_DATE, 42, 5 + 8 + 8, 192, 50
+       DEFPUSHBUTTON "&OK", IDOK, 75, 35, 50, 10
+}
index b84a5e68d6386397fa9160971fcded5235a54b86..fcbd0dad091b47fd865adb2493e429007d4fe0ae 100644 (file)
@@ -7,6 +7,7 @@
 #ifdef __BORLANDC__
 
 #pragma resource "tewi_bcc.res"
+#pragma resource "gui_bcc.res"
 
 #endif
 
@@ -30,7 +31,7 @@
 #include "tw_server.h"
 #include "tw_version.h"
 
-#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
 #include <windows.h>
 #endif
 
@@ -524,6 +525,7 @@ void show_png(void) {
 
 #endif
 
+#if !defined(BUILD_GUI) || !(defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__))
 int main(int argc, char** argv) {
        int st;
        logfile = stderr;
@@ -704,6 +706,7 @@ int main(int argc, char** argv) {
 #endif
        return 0;
 }
+#endif
 
 int startup(int argc, char** argv) {
        int i;
index 4bb31087627e943853b86f712e1d4f4728f4d710..7766e8aea827064342b3715f3de418860db0b4d3 100644 (file)
@@ -2,7 +2,7 @@
 #include "tw_version.h"
 #include "../config.h"
 
-id ICON "../Binary/tewi.ico"
+TEWI ICON "../Binary/tewi.ico"
 VS_VERSION_INFO VERSIONINFO
        FILEVERSION 1,0,0,0
        PRODUCTVERSION 1,0,0,0
index c3b556a8098769fcbeba645c6753de4c08a29b00..1dc06503e4a6f1badc8f015938f88c8a721c5062 100644 (file)
@@ -13,14 +13,33 @@ int main(int argc, char** argv) {
        if(strcmp(argv[1], "cflags") == 0) {
 #ifndef NO_SSL
                printf("-I %s/openssl/include", argv[2]);
+#endif
+#ifdef BUILD_GUI
+               if(strcmp(argv[3], "WINDOWS_WATCOM") == 0){
+                       printf(" -b nt_win");
+               }else if(strcmp(argv[3], "WINDOWS") == 0){
+                       printf(" -mwindows");
+               }
 #endif
        } else if(strcmp(argv[1], "ldflags") == 0) {
 #ifndef NO_SSL
                printf("-L %s/openssl/lib", argv[2]);
+#endif
+#ifdef BUILD_GUI
+               if(strcmp(argv[3], "WINDOWS_WATCOM") == 0){
+                       printf(" -b nt_win");
+               }else if(strcmp(argv[3], "WINDOWS") == 0){
+                       printf(" -mwindows");
+               }
 #endif
        } else if(strcmp(argv[1], "objs") == 0) {
 #ifndef NO_SSL
-               printf("ssl.o");
+               printf("ssl.%s", argv[4]);
+#endif
+#ifdef BUILD_GUI
+               if(strcmp(argv[3], "WINDOWS") == 0 || strcmp(argv[3], "WINDOWS_WATCOM") == 0){
+                       printf(" gui.%s", argv[4]);
+               }
 #endif
        } else if(strcmp(argv[1], "libs") == 0) {
 #ifndef NO_SSL
@@ -31,12 +50,18 @@ int main(int argc, char** argv) {
                        printf(" -lwsock32");
 #else
                        printf(" -lws2_32");
+#endif
+#ifdef BUILD_GUI
+                       printf(" -lcomctl32");
 #endif
                }else if(strcmp(argv[3], "WINDOWS_WATCOM") == 0){
 #ifdef USE_WINSOCK1
                        printf(" wsock32.lib");
 #else
                        printf(" ws2_32.lib");
+#endif
+#ifdef BUILD_GUI
+                       printf(" comctl32.lib");
 #endif
                }
        }
index 45fabd2edd24df5ff0ac5e76442d85f0eedb15c7..a5e8b095dc978b3aa34d67123b6d6dbc9fc93b33 100644 (file)
@@ -11,6 +11,7 @@
 #define HAS_CHROOT
 #undef NO_GETADDRINFO
 #undef USE_WINSOCK1
+#undef BUILD_GUI
 
 /* DO NOT EDIT BELOW THIS LINE */
 
@@ -22,6 +23,7 @@
 #undef USE_POLL
 /* Force select(2) for Windows */
 #endif
+
 #if (defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)) && defined(USE_WINSOCK1) && !defined(NO_GETADDRINFO)
 #define NO_GETADDRINFO
 /* getaddrinfo is not on winsock 1 */