オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Contents of /aquaskk/trunk/platform/mac/src/server/MacInputModeWindow.mm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (show annotations) (download) (as text)
Sat Oct 11 07:47:05 2008 UTC (15 years, 7 months ago) by t-suwa
File MIME type: text/x-objcsrc
File size: 3935 byte(s)
 r506@milonga:  t_suwa | 2008-10-11 01:20:11 +0900
 - 入力メニュー用アイコンを追加
 
 r507@milonga:  t_suwa | 2008-10-11 13:59:25 +0900
 - SKKInputModeListener:入力モードリスナー用インタフェースを追加
 
 r508@milonga:  t_suwa | 2008-10-11 14:00:11 +0900
 - SKKInputModeSelector:入力モードリスナーに対応
 
 r509@milonga:  t_suwa | 2008-10-11 14:14:09 +0900
 - SKKInputModeSelector を SKKInputEngine から SKKRecursiveEditor に移動
 
 r510@milonga:  t_suwa | 2008-10-11 14:25:18 +0900
 - SKKInputSession に SKKRecursiveEditor 初期化用の SKKInputModeSelector を保持
 
 r511@milonga:  t_suwa | 2008-10-11 14:29:47 +0900
 - SKKInputModeWindow が SKKInputModeListener を継承するように修正
 
 r512@milonga:  t_suwa | 2008-10-11 14:31:38 +0900
 - MacInputModeWindow のインタフェースを修正
 
 r513@milonga:  t_suwa | 2008-10-11 14:52:33 +0900
 - SKKInputSession の SKKInputModeSelector をコンストラクタ引数で初期化するように修正
 
 r514@milonga:  t_suwa | 2008-10-11 15:32:04 +0900
 - SKKInputSessionParameter から SKKInputModeWindow を除去
 
 r515@milonga:  t_suwa | 2008-10-11 15:33:50 +0900
 - SKKInputModeWindow を完全に除去
 
 r516@milonga:  t_suwa | 2008-10-11 15:53:19 +0900
 - SKKRecursiveEditor に Activate と Deactivate を実装
 
 r517@milonga:  t_suwa | 2008-10-11 15:58:37 +0900
 - MacInputSessionParameter のインタフェースを修正
 
 r518@milonga:  t_suwa | 2008-10-11 15:59:51 +0900
 - MacInputModeMenu:入力モードリスナを追加
 - SKKInputMenu:入力メニューハンドラを追加
 
 r519@milonga:  t_suwa | 2008-10-11 16:00:19 +0900
 - MacInputModeWindow:入力モードリスナインタフェースに変更
 
 r520@milonga:  t_suwa | 2008-10-11 16:08:44 +0900
 - SKKInputController:入力メニュー関連の改善
 
 r521@milonga:  t_suwa | 2008-10-11 16:10:25 +0900
 - プロジェクトと plist の修正
 
 r522@milonga:  t_suwa | 2008-10-11 16:17:09 +0900
 - plist の修正
 

1 /* -*- ObjC -*-
2
3 MacOS X implementation of the SKK input method.
4
5 Copyright (C) 2008 Tomotaka SUWA <t.suwa@mac.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 */
22
23 #include "MacInputModeWindow.h"
24 #include "SKKFrontEnd.h"
25 #include "InputModeWindowController.h"
26 #include <iostream>
27 #include <vector>
28
29 // MacInputModeWindow::Activate() から呼ばれるユーティリティ群
30 namespace {
31 // 左下原点を左上原点に変換する
32 CGPoint FlipPoint(int x, int y) {
33 NSRect screen = [[NSScreen mainScreen] frame];
34
35 return CGPointMake(x, NSHeight(screen) - y);
36 }
37
38 int ActiveProcessID() {
39 NSDictionary* info = [[NSWorkspace sharedWorkspace] activeApplication];
40 NSNumber* pid = [info objectForKey:@"NSApplicationProcessIdentifier"];
41
42 return [pid intValue];
43 }
44
45 typedef std::vector<CGRect> CGRectContainer;
46
47 // プロセス ID に関連したウィンドウ矩形群の取得
48 CGRectContainer CreateWindowBoundsListOf(int pid) {
49 CGRectContainer result;
50 NSArray* array = (NSArray*)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly,
51 kCGNullWindowID);
52 NSEnumerator* enumerator = [array objectEnumerator];
53
54 while(NSDictionary* window = [enumerator nextObject]) {
55 // 引数のプロセス ID でフィルタ
56 NSNumber* owner = [window objectForKey:(NSString*)kCGWindowOwnerPID];
57 if([owner intValue] != pid) continue;
58
59 // デスクトップ全面を覆う Finder のウィンドウは除外
60 NSNumber* level = [window objectForKey:(NSString*)kCGWindowLayer];
61 if([level intValue] == kCGMinimumWindowLevel) continue;
62
63 CGRect rect;
64 NSDictionary* bounds = [window objectForKey:(NSString*)kCGWindowBounds];
65 if(CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)bounds, &rect)) {
66 result.push_back(rect);
67 }
68 }
69
70 [array release];
71
72 return result;
73 }
74 }
75
76 // ============================================================
77
78 MacInputModeWindow::MacInputModeWindow(SKKFrontEnd* frontend)
79 : active_(false)
80 , frontend_(frontend)
81 , mode_(HirakanaInputMode) {
82 controller_ = [InputModeWindowController sharedController];
83 [controller_ changeMode:mode_];
84 }
85
86 void MacInputModeWindow::SelectInputMode(SKKInputMode mode) {
87 if(mode_ != mode) {
88 mode_ = mode;
89
90 if(active_) Activate();
91 }
92 }
93
94 void MacInputModeWindow::Activate() {
95 active_ = true;
96
97 std::pair<int, int> position = frontend_->WindowPosition();
98
99 CGPoint cursor = FlipPoint(position.first, position.second);
100 CGRectContainer list = CreateWindowBoundsListOf(ActiveProcessID());
101
102 // カーソル位置がウィンドウ矩形に含まれていなければ無視する
103 int count = std::count_if(list.begin(), list.end(),
104 std::bind2nd(std::ptr_fun(CGRectContainsPoint), cursor));
105 if(!count) return;
106
107 [controller_ changeMode:mode_];
108 [controller_ show:NSMakePoint(position.first, position.second)
109 level:frontend_->WindowLevel()];
110 }
111
112 void MacInputModeWindow::Deactivate() {
113 [controller_ hide];
114
115 active_ = false;
116 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26