Live resize ?
Live resize ?
When i resize window with mouse then i get this rectangle that shows new size:
How can i create window that will automatically resize with every mouse move (?), not only when i release mouse button, like in windows.
I have a lot of apps installed on my mac and neither one of them is behaving like this one created in purebasic.
How can i create window that will automatically resize with every mouse move (?), not only when i release mouse button, like in windows.
I have a lot of apps installed on my mac and neither one of them is behaving like this one created in purebasic.
Try this after the OpenWindow statement:
The kWindowLiveResizeAttribute property (whose value is 1 << 28 ) doesn't appear to be enabled by default.
AIR.
Code: Select all
ChangeWindowAttributes_(WindowID(0),(1 << 28),0)
AIR.
"Programming is like Poetry. Sometimes the words just escape you..." -me, to my manager.
That's very interesting. I found the info and was inspired to try this but it didn't work.
[later]
I discovered this thread:
http://www.purebasic.fr/english/viewtop ... d&start=30
and they seem to be covering this territory back in 2005. It appeared that this function was added (by Fred?).
but it doesn't seem to work either.
The links to Carbonx seem to be no longer pointing to it... I assume it is dead?
It's too bad this wasn't all worked out back in '05 with 'pbsoimporter' and the data file. (page one in link above). That seems like the way to go but those links don't work either.
Code: Select all
setwindowmodified_(WindowID(0),1)
I discovered this thread:
http://www.purebasic.fr/english/viewtop ... d&start=30
and they seem to be covering this territory back in 2005. It appeared that this function was added (by Fred?).
Code: Select all
err = SetWindowModified_(WindowID(0),#C_TRUE)
The links to Carbonx seem to be no longer pointing to it... I assume it is dead?
It's too bad this wasn't all worked out back in '05 with 'pbsoimporter' and the data file. (page one in link above). That seems like the way to go but those links don't work either.
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
SetWindowModified is a Carbon API call which allows you to set or clear the modification state of a Window's contents (not the window itself).
From the Developer Documentation:
AIR.
From the Developer Documentation:
You'll need to import it along with IsWindowModified (to check the status):Your application can use the functions SetWindowModified and IsWindowModified instead of maintaining its own separate record of the modification state of the content of a window. The modification state of a window is visually represented by a dot in the window’s close box. If the dot is present, the window is modified; if the dot is absent, the window is not modified.
Your application should distinguish between the modification state of the window and the modification state of the window’s contents, typically a document. The modification state of the window contents are what should affect SetWindowModified. For example, in the case of a word processing document, you call SetWindowModified (passing true in the modified parameter) whenever the user types new characters into the document. However, you do not call SetWindowModified when the user moves the window, because that change does not affect the document contents. If you need to track whether the window position has changed, you need to do this with your own flag.
Code: Select all
ImportC "/System/Library/Frameworks/Carbon.framework/Carbon"
SetWindowModified(WindowRef.l, State.l)
IsWindowModified(WindowRef.l) ; returns Boolean
EndImport
"Programming is like Poetry. Sometimes the words just escape you..." -me, to my manager.
Using 'ImportC' worked fine and the button was set. I'm not sure why ChangeWindowAttributes_ works without the 'ImportC' command but I guess some of the commands are already in PB and others need to be called with 'ImportC'.
So now I can use the whole Carbon toolbox with using your 'ImportC' form?
So now I can use the whole Carbon toolbox with using your 'ImportC' form?
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
For the most part, I believe the answer would be yes.
Since the windows aren't composited, I don't think you can use all of the HIView functions.
A bigger issue is (are?) some of the CF types (CF = CoreFoundation). For example a CFString, which is what is needed for some of the API function parameters. PureBasic uses Cstrings, I think, which need to be converted over before (or during, by doing it "inline") the function call.
Btw, I think you could also provide a linker options file (Compiler>Compiler Options) and do away with the ImportC block(s). Then you should be able to call the functions using the trailing-underscore syntax.
AIR.
Since the windows aren't composited, I don't think you can use all of the HIView functions.
A bigger issue is (are?) some of the CF types (CF = CoreFoundation). For example a CFString, which is what is needed for some of the API function parameters. PureBasic uses Cstrings, I think, which need to be converted over before (or during, by doing it "inline") the function call.
Btw, I think you could also provide a linker options file (Compiler>Compiler Options) and do away with the ImportC block(s). Then you should be able to call the functions using the trailing-underscore syntax.
AIR.
"Programming is like Poetry. Sometimes the words just escape you..." -me, to my manager.
Ok, CFStrings can be handled with:
And you would call it like this:
I originally wrote the CFSTR procedure as a Macro (which is how Carbon does it in it's headers), but for the sake of smaller code converted it to a procedure...
AIR.
Code: Select all
Procedure CFSTR(cString.s)
ProcedureReturn CFStringCreateWithCString_(0, cString, 0)
EndProcedure
Code: Select all
CFPreferencesSetAppValue(CFSTR(key),CFSTR(value),CFSTR(plist))
AIR.
"Programming is like Poetry. Sometimes the words just escape you..." -me, to my manager.
Re: Live resize ?
I use PB for Windows sometimes and now are trying PB 4.40 (x86) for OSX (OSX 10.6.2, Xcode 3.2.1).
So far it's kind of a frustrating experience. Just like in Windows I would like a live resize.
I used the GadgetSplitterAdvanced example that comes with PB to test things.
The unmodified example sometimes works fine but most of the times crashes with a "Invalid memory access." after closing the compiled example.
ChangeWindowAttributes does result in a live resize but the gadgets inside the window aren't resized because the event broadcasted while resizing isn't listened for.
I think InstallWindowEventHandler would be required to install a handler that detects the event but I have no idea how to import this function.
So far it's kind of a frustrating experience. Just like in Windows I would like a live resize.
I used the GadgetSplitterAdvanced example that comes with PB to test things.
The unmodified example sometimes works fine but most of the times crashes with a "Invalid memory access." after closing the compiled example.
ChangeWindowAttributes does result in a live resize but the gadgets inside the window aren't resized because the event broadcasted while resizing isn't listened for.
I think InstallWindowEventHandler would be required to install a handler that detects the event but I have no idea how to import this function.
Re: Live resize ?
Never mind, I got it working.
It works on OSX 10.6.2 . From what I understand so far, it should also work on OSX 10.2 or higher.
If someone has a OSX version from 10.2 to 10.5 and wants to test it, I would appreciate it if you let me know if it works.
It works on OSX 10.6.2 . From what I understand so far, it should also work on OSX 10.2 or higher.
If someone has a OSX version from 10.2 to 10.5 and wants to test it, I would appreciate it if you let me know if it works.
Code: Select all
#kEventClassWindow = 'wind'
#kEventParamCurrentBounds = 'crct'
#kEventParamPreviousBounds = 'prct'
#kEventWindowBoundsChanging = 26
#kWindowNoAttributes = $0
#kWindowLiveResizeAttribute = $10000000
#noErr = 0
#typeHIRect = 'hirc'
ImportC "/System/Library/Frameworks/Carbon.framework/Carbon"
ChangeWindowAttributes (window, setTheseAttributes, clearTheseAttributes)
GetEventParameter (event, name, desiredType, ptrActualType, bufferSize, ptrActualSize, ptrData)
GetWindowEventTarget (target)
InstallEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef)
NewEventHandlerUPP (userRoutine)
SetWindowResizeLimits (window, minLimits, maxLimits)
EndImport
Macro InstallWindowEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef)
InstallEventHandler(GetWindowEventTarget(target), handler, numTypes, ptrList, userData, outHandlerRef)
EndMacro
Structure EventTypeSpec
eventClass.l
eventKind.l
EndStructure
Structure HIRect
x.f
y.f
width.f
height.f
EndStructure
Structure HISize
width.f
height.f
EndStructure
ProcedureC.l ResizeHandler (nextHandler, theEvent, ptrUserData)
GetEventParameter(theEvent, #kEventParamCurrentBounds, #typeHIRect, #Null, SizeOf(HIRect), #Null, @current.HIRect)
GetEventParameter(theEvent, #kEventParamPreviousBounds, #typeHIRect, #Null, SizeOf(HIRect), #Null, @previous.HIRect)
If current\width <> previous\width Or current\height <> previous\height
ResizeGadget(0, 10, 10, current\width - 20, current\height - 50)
EndIf
ProcedureReturn #noErr
EndProcedure
WindowRef.l = OpenWindow(0, 0, 0, 640, 480, "PureBasic - Live Resize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
If WindowRef
minSize.HISize\width = 120
minSize\height = 150
maxSize.HISize\width = 1024
maxSize\height = 768
SetWindowResizeLimits(WindowRef, @minSize, @maxSize)
ChangeWindowAttributes(WindowRef, #kWindowLiveResizeAttribute, #kWindowNoAttributes)
EventList.EventTypeSpec\eventClass = #kEventClassWindow
EventList\eventKind = #kEventWindowBoundsChanging
InstallWindowEventHandler(WindowRef, NewEventHandlerUPP(@ResizeHandler()), 1, @EventList, #Null, #Null)
WebGadget(0, 10, 10, 620, 430, "http://www.purebasic.com")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
EndIf
End
Last edited by wilbert on Sat Dec 26, 2009 7:29 am, edited 1 time in total.
Re: Live resize ?
Nice, it works under 10.5.8 here using PureBasic 4.30 x86.wilbert wrote:Never mind, I got it working.
It works on OSX 10.6.2 . From what I understand so far, it should also work on OSX 10.2 or higher.
If someone has a OSX version from 10.2 to 10.5 and wants to test it, I would appreciate it if you let me know if it works.
The commented API functions don't need to be imported; they're already "included". Just append an underscore when you call the function { for ex, ChangeWindowAttribute_(...) }Code: Select all
ImportC "/System/Library/Frameworks/Carbon.framework/Carbon" ;ChangeWindowAttributes (window, setTheseAttributes, clearTheseAttributes) ;GetEventParameter (event, name, desiredType, ptrActualType, bufferSize, ptrActualSize, ptrData) ;;GetWindowEventTarget (target) ;InstallEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef) SetWindowResizeLimits (window, minLimits, maxLimits) EndImport
If you view the files located in the purelibraries/macos/ folder with a file viewer (an editor might modify the files if you're not careful) you'll see which MacOS specific API functions are already available.
AIR.
"Programming is like Poetry. Sometimes the words just escape you..." -me, to my manager.
Re: Live resize ?
Thanks for mentioning.
I didn't know those files were there.
I didn't know those files were there.
Re: Live resize ?
Great job, thanks for sharingwilbert wrote:Never mind, I got it working.
It works on OSX 10.6.2 . From what I understand so far, it should also work on OSX 10.2 or higher.
If someone has a OSX version from 10.2 to 10.5 and wants to test it, I would appreciate it if you let me know if it works.
Code: Select all
#kEventClassWindow = 'wind' #kEventParamCurrentBounds = 'crct' #kEventParamPreviousBounds = 'prct' #kEventWindowBoundsChanging = 26 #kWindowNoAttributes = $0 #kWindowLiveResizeAttribute = $10000000 #noErr = 0 #typeHIRect = 'hirc' ImportC "/System/Library/Frameworks/Carbon.framework/Carbon" ChangeWindowAttributes (window, setTheseAttributes, clearTheseAttributes) GetEventParameter (event, name, desiredType, ptrActualType, bufferSize, ptrActualSize, ptrData) GetWindowEventTarget (target) InstallEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef) NewEventHandlerUPP (userRoutine) SetWindowResizeLimits (window, minLimits, maxLimits) EndImport Macro InstallWindowEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef) InstallEventHandler(GetWindowEventTarget(target), handler, numTypes, ptrList, userData, outHandlerRef) EndMacro Structure EventTypeSpec eventClass.l eventKind.l EndStructure Structure HIRect x.f y.f width.f height.f EndStructure Structure HISize width.f height.f EndStructure ProcedureC.l ResizeHandler (nextHandler, theEvent, ptrUserData) GetEventParameter(theEvent, #kEventParamCurrentBounds, #typeHIRect, #Null, SizeOf(HIRect), #Null, @current.HIRect) GetEventParameter(theEvent, #kEventParamPreviousBounds, #typeHIRect, #Null, SizeOf(HIRect), #Null, @previous.HIRect) If current\width <> previous\width Or current\height <> previous\height ResizeGadget(0, 10, 10, current\width - 20, current\height - 50) EndIf ProcedureReturn #noErr EndProcedure WindowRef.l = OpenWindow(0, 0, 0, 640, 480, "PureBasic - Live Resize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) If WindowRef minSize.HISize\width = 120 minSize\height = 150 maxSize.HISize\width = 1024 maxSize\height = 768 SetWindowResizeLimits(WindowRef, @minSize, @maxSize) ChangeWindowAttributes(WindowRef, #kWindowLiveResizeAttribute, #kWindowNoAttributes) EventList.EventTypeSpec\eventClass = #kEventClassWindow EventList\eventKind = #kEventWindowBoundsChanging InstallWindowEventHandler(WindowRef, NewEventHandlerUPP(@ResizeHandler()), 1, @EventList, #Null, #Null) WebGadget(0, 10, 10, 620, 430, "http://www.purebasic.com") Repeat EventID = WaitWindowEvent() Until EventID = #PB_Event_CloseWindow EndIf End
Live resizing works on my Mac PPC, 10.4.11
michel51
Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Re: Live resize ?
Thanks for mentioning it also works on PPC.
For myself what I wanted (if possible) is a cross platform ( Win32 / OSX_x86 ) solution so I created a cross-platform userlib.
Since the lib is written in ASM, it isn't working on a PPC. For those who are using OSX_x86 and Win32, here it is
http://www.w73.nl/pb/wxl_Lib.zip
The zip file contains a userlib for Win32 and one for OSX_x86.
Example code that works on both platforms
The handler must be a procedure with two parameters.
The windows lib has the restriction that it can only handle 16 event handlers at the same time and all windows that want to use this function need to be created from the main thread.
For myself what I wanted (if possible) is a cross platform ( Win32 / OSX_x86 ) solution so I created a cross-platform userlib.
Since the lib is written in ASM, it isn't working on a PPC. For those who are using OSX_x86 and Win32, here it is
http://www.w73.nl/pb/wxl_Lib.zip
The zip file contains a userlib for Win32 and one for OSX_x86.
Example code that works on both platforms
Code: Select all
Procedure LiveResizeHandler (newWidth.l, newHeight.l)
ResizeGadget(0, 10, 10, newWidth - 20, newHeight - 50)
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, "PureBasic - Live Resize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
wxl_AddLiveResizeEventHandler(WindowID(0), @LiveResizeHandler())
WindowBounds(0, 120, 150, 1024, 768)
WebGadget(0, 10, 10, 620, 430, "http://www.purebasic.com")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
EndIf
End
The windows lib has the restriction that it can only handle 16 event handlers at the same time and all windows that want to use this function need to be created from the main thread.
Last edited by wilbert on Wed May 31, 2017 3:15 pm, edited 1 time in total.