Recent

Author Topic: Problem scale form on Linux/GTK2  (Read 3090 times)

Stefano

  • New Member
  • *
  • Posts: 39
Problem scale form on Linux/GTK2
« on: November 22, 2013, 10:02:45 pm »
Hello, I've a problem with a procedure that I use to resize at runtime the form of a projects, in order to adapt them to the screen resolution if major of the base resolution 1024*768.

Code: [Select]
procedure AutoScaleForm(var MyForm: TForm; const MyScale: Double; const MyOpt: SmallInt = 0);
var
  i: LongInt;
begin
  if (MyOpt = 0) then begin
    case FormShowType of //FormShowType is a parameter in order to set the BorderStyle property
      1: begin
        MyForm.BorderStyle := bsDialog;
        MyForm.WindowState := wsNormal;
        MyForm.AutoScroll := False;
      end;
      2: begin
        MyForm.BorderStyle := bsSingle;
        MyForm.WindowState := wsNormal;
        MyForm.AutoScroll := True;
      end;
      3: begin
        MyForm.BorderStyle := bsSingle;
        MyForm.WindowState := wsMaximized;
        MyForm.AutoScroll := True;
      end;
      4: begin
        MyForm.BorderStyle := bsSingle;
        MyForm.WindowState := wsMinimized;
        MyForm.AutoScroll := True;
      end;
      5: begin
        MyForm.BorderStyle := bsSizeable;
        MyForm.WindowState := wsNormal;
        MyForm.AutoScroll := True;
      end;
      6: begin
        MyForm.BorderStyle := bsSizeable;
        MyForm.WindowState := wsMaximized;
        MyForm.AutoScroll := True;
      end;
      7: begin
        MyForm.BorderStyle := bsSizeable;
        MyForm.WindowState := wsMinimized;
        MyForm.AutoScroll := True;
      end;
      else begin
        //Default, no changes of BorderStyle

      end;
    end;
  end;
  //Scale form
  if (FormAutoConf = 0) then exit; //Parameter to choose if do scale form
  if ((MyScale > 1) or (FormScaleWide > 1)) then begin //Scale form to do
    With MyForm do begin
      if (FormWideConf > 1) then begin
        //Wide screen
        Width := Round(Width * MyScale * FormWideConf);
      end
      else begin
        Width := Round(Width * MyScale);
      end;
      if (Width > MaxFrmWidth) and (MaxFrmWidth > 1024) and (MaxFrmHeight > 768) then Width := MaxFrmWidth; //Max width
      Height := Round(Height * MyScale);
      if (Height > MaxFrmHeight) and (MaxFrmWidth > 1024) and (MaxFrmHeight > 768) then Height := MaxFrmHeight; //Max Height
      for i := 0 to ComponentCount - 1 do begin
        //1. Components
        if (Components[i] is TControl) then with (Components[i] as TControl) do begin
          if (FormWideConf > 1) then begin
            Width := Round(Width * MyScale * FormWideConf);
          end
          else begin
            Width := Round(Width * MyScale);
          end;
          Height := Round(Height * MyScale);
          Top := Round(Top * MyScale);
          if (FormWideConf > 1) then begin
            Left := Round(Left * MyScale * FormWideConf);
          end
          else begin
            Left := Round(Left * MyScale);
          end;
        end;
      end;
  end;

The code works good on Lazarus 0.9.28.2 on all platforms, either if the forms are bsDialog, bsSingle or bsSizeable.

With Lazarus 1.0.10/12 the forms are always corretly resized on Windows (Win32), on Linux/GTK2 the forms are not resized if BorderStyle = bsDialog and are only horizontal resized if BorderStyle = bsSingle. With BorderStyle = bsSizeable the code works good also on Linux/GTK2.

The components are instead correctly resized.

All forms have a TPanel, insede the TPanele the are the components.

Have you an advice? Or must I report a bug?

Best regards,

Stefano
Stefano Cortelli
Studio Rag. Cortelli
(Preferred languages: Italiano / Deutsch / Français)

zeljko

  • Hero Member
  • *****
  • Posts: 1998
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Problem scale form on Linux/GTK2
« Reply #1 on: December 01, 2013, 02:09:23 pm »
No it's not bug report. I guess that same thing can happen with qt widgetset.
Win32 ws allows changing of form size in such way, but qt and gtk2 not since changing form style to bsDialog or bsSingle sets fixed size onto forms (when handle is allocated). Yes, that has been changed at 1.0.XX times.
So maybe an solution for you could be:
if FormStyle = bsDialog then
begin
 // calculate newsize
 FormStyle := bsSizeable;
// apply new size
 FormStyle := bsDialog.
end;

Stefano

  • New Member
  • *
  • Posts: 39
Re: Problem scale form on Linux/GTK2
« Reply #2 on: December 04, 2013, 11:29:19 am »
Thank you very much for your help.

Your code works perfectly!

Thank you again, best regards,

Stefano
Stefano Cortelli
Studio Rag. Cortelli
(Preferred languages: Italiano / Deutsch / Français)

 

TinyPortal © 2005-2018