summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2011-06-17 15:14:39 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2011-06-17 15:14:39 +0200
commit351d6215a21b53c4c082523d2406814916e0fd6a (patch)
treec23f53edcdeefe1103a39fc3d969260cc7909bab
parentaffe533736abbfbe181ed4da579d143a08905836 (diff)
downloadfpGUI-351d6215a21b53c4c082523d2406814916e0fd6a.tar.xz
Introduced a new property TfpgWindowBase.WindowState
This is an initial implementation for Linux only. Currently this property is read-only, but that alone is already very useful. Next I'll implement the Windows support, and later the read-write support.
-rw-r--r--src/corelib/fpg_base.pas17
-rw-r--r--src/corelib/x11/fpg_x11.pas61
-rw-r--r--src/gui/fpg_form.pas6
3 files changed, 81 insertions, 3 deletions
diff --git a/src/corelib/fpg_base.pas b/src/corelib/fpg_base.pas
index c65d8176..ae745a71 100644
--- a/src/corelib/fpg_base.pas
+++ b/src/corelib/fpg_base.pas
@@ -58,6 +58,8 @@ type
waOneThirdDownPos);
TWindowAttributes = set of TWindowAttribute;
+ TfpgWindowState = (wsNormal, wsMinimized, wsMaximized);
+
TMouseCursor = (mcDefault, mcArrow, mcCross, mcIBeam, mcSizeEW, mcSizeNS,
mcSizeNWSE, mcSizeNESW, mcSizeSWNE, mcSizeSENW, mcMove, mcHourGlass,
mcHand, mcDrag, mcNoDrop);
@@ -444,6 +446,7 @@ type
FMouseCursorIsDirty: Boolean;
FOnDragStartDetected: TNotifyEvent;
FDragActive: boolean;
+ FWindowState: TfpgWindowState;
function HandleIsValid: boolean; virtual; abstract;
procedure DoUpdateWindowPosition; virtual; abstract;
procedure DoAllocateWindowHandle(AParent: TfpgWindowBase); virtual; abstract;
@@ -456,6 +459,8 @@ type
procedure DoSetMouseCursor; virtual; abstract;
procedure DoDNDEnabled(const AValue: boolean); virtual; abstract;
procedure DoAcceptDrops(const AValue: boolean); virtual; abstract;
+ function GetWindowState: TfpgWindowState; virtual;
+ procedure SetWindowState(const AValue: TfpgWindowState); virtual;
procedure DoDragStartDetected; virtual;
procedure SetParent(const AValue: TfpgWindowBase); virtual;
function GetParent: TfpgWindowBase; virtual;
@@ -470,6 +475,7 @@ type
procedure HandleMove(x, y: TfpgCoord); virtual;
procedure HandleResize(AWidth, AHeight: TfpgCoord); virtual;
property OnDragStartDetected: TNotifyEvent read FOnDragStartDetected write FOnDragStartDetected;
+ property WindowState: TfpgWindowState read GetWindowState {write SetWindowState} default wsNormal;
public
// The standard constructor.
constructor Create(AOwner: TComponent); override;
@@ -1151,6 +1157,16 @@ begin
Result := MinHeight;
end;
+function TfpgWindowBase.GetWindowState: TfpgWindowState;
+begin
+ Result := FWindowState;
+end;
+
+procedure TfpgWindowBase.SetWindowState(const AValue: TfpgWindowState);
+begin
+ // do nothing
+end;
+
procedure TfpgWindowBase.DoDragStartDetected;
begin
if Assigned(FOnDragStartDetected) then
@@ -1270,6 +1286,7 @@ begin
FMaxWidth := 0;
FMaxHeight := 0;
FDragActive := False;
+ FWindowState := wsNormal;
end;
procedure TfpgWindowBase.AfterConstruction;
diff --git a/src/corelib/x11/fpg_x11.pas b/src/corelib/x11/fpg_x11.pas
index ff5ac9ce..79f83e6e 100644
--- a/src/corelib/x11/fpg_x11.pas
+++ b/src/corelib/x11/fpg_x11.pas
@@ -235,6 +235,7 @@ type
procedure DoDNDEnabled(const AValue: boolean); override;
procedure DoAcceptDrops(const AValue: boolean); override;
property WinHandle: TfpgWinHandle read FWinHandle;
+ function GetWindowState: TfpgWindowState; override;
public
constructor Create(AOwner: TComponent); override;
procedure ActivateWindow; override;
@@ -2439,6 +2440,66 @@ begin
{ TODO : Remove EnableDrops, then recurse from here to parent top level from, and set XDNDAware property for form. }
end;
+function TfpgX11Window.GetWindowState: TfpgWindowState;
+type
+ TWMStateType = (wms_none, wms_normal, wms_withdrawn, wms_iconic);
+ wmstate = record
+ state: longword;
+ icon: PtrUInt;
+ end;
+ pwmstate = ^wmstate;
+var
+ actualtype: TAtom = None;
+ actualformat: cint;
+ count, remaining: culong;
+ data: pwmstate = nil;
+ lWindowStates: TNetWindowStates;
+ maxh, maxv: boolean;
+begin
+ Result := inherited GetWindowState;
+
+ if XGetWindowProperty(xapplication.Display, FWinHandle, xapplication.xia_wm_state, 0, 1,
+ TBool(False), xapplication.xia_wm_state, @actualtype, @actualformat, @count,
+ @remaining, @data) = Success then
+ begin
+ if (actualformat = 32) and (count = 1) then
+ begin
+ case data^.State of
+ Ord(wms_none):
+ begin
+ // do nothing
+ end;
+ Ord(wms_normal):
+ begin
+ Result := wsNormal;
+ maxh := false;
+ maxv := false;
+ xapplication.netlayer.WindowGetState(FWinHandle, lWindowStates);
+ if nwsFullScreen in lWindowStates then
+ Result := wsMaximized; // not really true, but ok for now
+ if nwsMaxVert in lWindowStates then
+ maxv := True;
+ if nwsMaxHorz in lWindowStates then
+ maxh := True;
+ if (Result = wsNormal) and maxv and maxh then
+ Result := wsMaximized;
+ end;
+ Ord(wms_withdrawn):
+ begin
+ // do nothing
+ end;
+ Ord(wms_iconic):
+ begin
+ Result := wsMinimized;
+ end;
+ end; { case }
+ end; { if }
+ end; { if }
+
+ if data <> nil then
+ XFree(data);
+end;
+
procedure TfpgX11Window.DoSetWindowTitle(const ATitle: string);
var
tp: TXTextProperty;
diff --git a/src/gui/fpg_form.pas b/src/gui/fpg_form.pas
index 0e1dc3c5..1e14d1f8 100644
--- a/src/gui/fpg_form.pas
+++ b/src/gui/fpg_form.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Toolkit
- Copyright (C) 2006 - 2010 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2011 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
@@ -127,6 +127,7 @@ type
property Top;
property Width;
property WindowPosition;
+ property WindowState;
property WindowTitle;
property OnActivate;
property OnClick;
@@ -160,8 +161,7 @@ implementation
uses
fpg_main,
fpg_popupwindow,
- fpg_menu
- ;
+ fpg_menu;
type
// to access protected methods