Инструменты пользователя

Инструменты сайта


blackbox:windowhook

Как сделать изменение высоты окна пропорционально его ширине?

MODULE MyDemo5;

	IMPORT Views, Properties, Ports, HostWindows, Windows, Documents;
	
	TYPE
		View = POINTER TO RECORD (Views.View) END;
		WinHook = POINTER TO RECORD (HostWindows.Hook)
			oldHook: HostWindows.Hook;
			window: HostWindows.Window;
		END;
	
	PROCEDURE (hook: WinHook) Resize (w, h: INTEGER);
	BEGIN
		h := w; (* тут задаем правило, сейчас пропорция 1:1 *)
		hook.window.SetSize(w, h); 
		IF hook.oldHook # NIL THEN hook.oldHook.Resize(w, h) END
	END Resize;

	PROCEDURE (hook: WinHook) Activate (on: BOOLEAN);
	BEGIN IF hook.oldHook # NIL THEN hook.oldHook.Activate(on) END
	END Activate;
	
	PROCEDURE (hook: WinHook) Focus (on: BOOLEAN);
	BEGIN IF hook.oldHook # NIL THEN hook.oldHook.Focus(on) END
	END Focus;
	
	PROCEDURE  (v: View) Restore (f: Views.Frame; l,t,r,b: INTEGER);
	BEGIN f.DrawOval(l, t, r, b, -1, Ports.red)
	END Restore;

	PROCEDURE (v: View) HandlePropMsg (VAR msg: Properties.Message);
	BEGIN
		WITH msg: Properties.SizePref DO
			IF msg.w = Views.undefined THEN
				msg.w := 40 * Ports.mm; msg.h := msg.w;
			END
		| msg: Properties.ResizePref DO
			msg.horFitToWin := TRUE;
			msg.verFitToWin := TRUE;
		ELSE
		END
	END HandlePropMsg;

	PROCEDURE Open*;
	VAR v: View; hook: WinHook; w: Windows.Window; d: Documents.Document;
	BEGIN
		NEW(v);
		d := Documents.dir.New(v, Views.undefined, Views.undefined);
		w := Windows.dir.New();
		Windows.dir.OpenSubWindow(w, d, {}, "Эмулятор");
		NEW(hook);
		hook.window := w(HostWindows.Window);
		hook.oldHook := w(HostWindows.Window).hook;
		w(HostWindows.Window).hook := hook;
	END Open;

END MyDemo5.
blackbox/windowhook.txt · Последнее изменение: 2020/10/29 07:08 (внешнее изменение)