Archive for the 'NSSegmentedControl' Category

2013/09/10 Window内に縦に配置したNSBoxのサイズと位置を読み取ってサイズ変更

メインウィンドウ内に縦方向に配置した4つのNSBoxのサイズと位置を起動時に取得して、NSSegmentedControlのクリック内容を反映してメインウィンドウを縦方向にアニメーションしつつリサイズするAppleScriptObjCのサンプルです。

boxwin.png

さまざまな機能を提供するパーツをNSBoxでまとめておき、表示範囲をボタンのクリックによって動的に変更するという処理のための実験コードです。

リサイズ後にウィンドウの最小サイズ/最大サイズを設定して、大きさを変更できないようにしたいところです。

→ Xcodeプロジェクトのダウンロード(76KB)

AppleScriptObjCファイル名:AppDelegate.applescript

– AppDelegate.applescript
– boxSizeTest

– Created by Takaaki Naganoya on 2013/09/10.
– Copyright (c) 2013年 Takaaki Naganoya. All rights reserved.


script AppDelegate
  property parent : class “NSObject”
  
  property aWin : missing value
  
  property box1 : missing value
  
property box2 : missing value
  
property box3 : missing value
  
property box4 : missing value
  
  
  
  property bSizeList : {}
  
property aWinWidth : 0
  
  property origY : 0
  
  on applicationWillFinishLaunching_(aNotification)
    
    getWinBoxInfoOnBoot()
    
  end applicationWillFinishLaunching_
  
  
  
  –起動時に(起動が完了する前に)ウィンドウのサイズ、位置、内部のNSBoxの情報などを取得して記憶しておく
  
on getWinBoxInfoOnBoot()
    
    set b0Size to aWin’s frame()
    
set b0Size to b0Size as record
    
set b0X1 to x of origin of b0Size
    
set b0Y1 to y of origin of b0Size
    
set b0X2 to width of |size| of b0Size
    
set b0Y2 to height of |size| of b0Size
    
    set my origY to b0Y1 + b0Y2
    
————————————————
    
set b1Size to box1’s frame()
    
set b1Size to b1Size as record
    
    set b1X1 to x of origin of b1Size
    
set b1Y1 to y of origin of b1Size
    
    set b1X2 to width of |size| of b1Size
    
set b1Y2 to height of |size| of b1Size
    
    set b1Y3 to (my origY) - b1Y1
    
————————————————
    
set b2Size to box2’s frame()
    
set b2Size to b2Size as record
    
    set b2X1 to x of origin of b2Size
    
set b2Y1 to y of origin of b2Size
    
    set b2X2 to width of |size| of b2Size
    
set b2Y2 to height of |size| of b2Size
    
    set b2Y3 to (my origY) - b2Y1
    
————————————————
    
set b3Size to box3’s frame()
    
set b3Size to b3Size as record
    
    set b3X1 to x of origin of b3Size
    
set b3Y1 to y of origin of b3Size
    
    set b3X2 to width of |size| of b3Size
    
set b3Y2 to height of |size| of b3Size
    
    set b3Y3 to (my origY) - b3Y1
    
————————————————
    
set b4Size to box4’s frame()
    
set b4Size to b4Size as record
    
    set b4X1 to x of origin of b4Size
    
set b4Y1 to y of origin of b4Size
    
    set b4X2 to width of |size| of b4Size
    
set b4Y2 to height of |size| of b4Size
    
    set b4Y3 to (my origY) - b4Y1
    
————————————————
    
set my bSizeList to {b1Y3, b2Y3, b3Y3, b4Y3}
    
set my aWinWidth to b0X1
    
  end getWinBoxInfoOnBoot
  
  
  on applicationShouldTerminate_(sender)
    return current application’s NSTerminateNow
  end applicationShouldTerminate_
  
  
  
  on clicked_(sender)
    
    –NSSegmentedControlの選択中のSegmentを求める
    
set aTag to (sender’s selectedSegment()) + 1
    
    
    set b0Size to aWin’s frame()
    
set b0Size to b0Size as record
    
    set b0X1 to x of origin of b0Size
    
set b0Y1 to y of origin of b0Size
    
    set b0X2 to width of |size| of b0Size
    
set b0Y2 to height of |size| of b0Size
    
    set curY to (contents of item aTag of my bSizeList) + 5 –”+5″は単に見た目を整えるための調整値
    
    set aSize to {{b0X1, b0Y1 + b0Y2 - curY}, {b0X2, curY}}
    
    aWin’s setFrame_display_animate_(aSize, true, true)
    
    
  end clicked_
  
end script

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に