Resizing Window

Mac OSX specific forum
simberr
User
User
Posts: 46
Joined: Sun Jun 10, 2018 12:54 pm

Resizing Window

Post by simberr »

I have created a routine that enables me to reset all the column widths within a ListIconGadget.

If a window is resized then I would like to call this routine but I cannot find any way to do that. If I set the gadget to lock left, right, top and bottom then the Form Designer automatically creates a procedure called "ResizeGadgetsMYWINDOWNAME()" which is called in the event loop:

Code: Select all

Case #PB_Event_SizeWindow
I would naturally add a call to my procedure in here but, of course, the Form Designer overwrites this file on save or switching back to the form view.

The ListIconGadget does not report a #PB_Event for resizing so am unable to check for it in my own event checker for the ListIcon. I can get left click, right click, double clicks etc. as defined in the help file but I don't even get a Change event.

Can someone point me in the right direction, please?
User avatar
mk-soft
Always Here
Always Here
Posts: 5338
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Resizing Window

Post by mk-soft »

Here's my first solution, but still think about...

Code: Select all

;-TOP

;- Module

DeclareModule __MyResizeGadget
  Declare FixResizeGadget(Gadget, x, y, width, height)
EndDeclareModule

Module __MyResizeGadget
  
  EnableExplicit
  
  ; Link https://www.purebasic.fr/english/viewtopic.php?f=24&t=71269
  ; Canvas Gadget Container Bugfix
  Procedure FixResizeGadget(Gadget, x, y, width, height)
    ResizeGadget(Gadget, x, y, width, height)
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      Protected rect.NSRect, sv, container
      sv = CocoaMessage(0, GadgetID(Gadget), "subviews")
      If CocoaMessage(0, sv, "count")
        container = CocoaMessage(0, sv, "objectAtIndex:", 0)
        If container
          CocoaMessage(@rect, GadgetID(Gadget), "frame")
          rect\origin\x = 0
          rect\origin\y = 0
          CocoaMessage(0, container, "setFrame:@", @rect)
        EndIf
      EndIf
    CompilerEndIf
    ; Here not work, because to late :(
    If GadgetType(Gadget) = #PB_GadgetType_ListIcon
    ;  PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_Resize)
    EndIf
  EndProcedure
  
EndModule

; -----------------------------------------------------------------------------

;- Macro

DeclareModule MyResizeGadget
  Macro ResizeGadget(Gadget, x, y, width, height)
    __MyResizeGadget::FixResizeGadget(Gadget, x, y, width, height)
  EndMacro
EndDeclareModule

Module MyResizeGadget
EndModule

; -----------------------------------------------------------------------------

CompilerIf #PB_Compiler_IsMainFile
  
  UseModule MyResizeGadget
  
  Procedure SizeWindow()
    ResizeGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 10)
  EndProcedure
  
  Procedure EventHandlerListIconGadget()
    Select EventType()
      Case #PB_EventType_Resize
        Debug "Resize ListIconGadget"
      Default
        Debug EventType()
    EndSelect
  EndProcedure
  
  If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
    ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(0, 1, "Address", 250)
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
    
    BindGadgetEvent(0, @EventHandlerListIconGadget())
    BindEvent(#PB_Event_SizeWindow, @SizeWindow())
    
    Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_SizeWindow
          ; Here works
          PostEvent(#PB_Event_Gadget, GetActiveWindow(), 0, #PB_EventType_Resize)
      EndSelect
    Until Event = #PB_Event_CloseWindow
  EndIf
  
CompilerEndIf
[/size]
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Resizing Window

Post by wilbert »

BindEvent might be a way but you could also add an observer for a change in frame or bounds of a specific gadget (NSNotificationCenter).
Windows (x64)
Raspberry Pi OS (Arm64)
simberr
User
User
Posts: 46
Joined: Sun Jun 10, 2018 12:54 pm

Re: Resizing Window

Post by simberr »

Thank you mk-soft and wilbert for your prompt answers.

In fact I have solved the problem - my issue in not understanding the flow properly and I have now solved the problem. I was trying to solve the issue within the event loop created by the form designer but, of course, that is overwritten each time I review the form so my code was being lost. I just resolved it by calling this event loop from outside the form designers code and adjusting my own event loop for the window thus:

Code: Select all

Repeat
	evnt = WaitWindowEvent()
	ev = ListViewTest_Events(evnt)                                  ; <-- This is the form designer's event loop
	If evnt = #PB_Event_SizeWindow                                  ; <-- This section of code checks the event and calls my routine.
		LB::Resize(ListIcon_0)                                       ; <-- My recalculation routine
		HideWindow(ListViewTest, #False, #PB_Window_ScreenCentered)  ; <-- Ignore this, just for me!
	EndIf
Until ev = #False
Thanks again.
Post Reply