2 Copyright 2005, Francois Revol. All Rights Reserved.
3 This file may be used under the terms of the Be Sample Code License.
15 #include <Application.h>
24 #include <add-ons/input_server/InputServerMethod.h>
32 extern "C" _EXPORT BInputServerMethod
* instantiate_input_method();
41 // modes: =Abc / Abc / 123
42 // flags: Abc / ABC / abc
44 class T9InputServerMethod
: public BInputServerMethod
, public BHandler
47 T9InputServerMethod();
48 virtual ~T9InputServerMethod();
49 virtual filter_result
Filter(BMessage
*message
, BList
*outList
);
50 virtual status_t
MethodActivated(bool active
);
51 virtual void MessageReceived(BMessage
*message
);
53 bool IsEnabled() const { return fEnabled
; };
54 T9Mode
Mode() const { return fMode
; };
55 void SetMode(T9Mode mode
);
61 BString fTyped
; /* what has been typed so far for the current word */
67 BInputServerMethod
* instantiate_input_method()
69 PRINT(("%s\n", __FUNCTION__
));
70 return (new T9InputServerMethod());
74 T9InputServerMethod::T9InputServerMethod()
75 : BInputServerMethod("T9", T9IconData
),
76 BHandler("T9IMHandler"),
82 PRINT(("%s\n", __FUNCTION__
));
86 be_app
->AddHandler(this);
91 fDeskbarMenu
= new BMenu(_T("Mode"));
94 BMessage
*msg
= new BMessage('SetM');
95 msg
->AddInt32("t9mode", WordMode
);
97 item
= new BMenuItem(_T("Word mode"), msg
);
98 item
->SetMarked(true);
99 fDeskbarMenu
->AddItem(item
);
100 msg
= new BMessage('SetM');
101 msg
->AddInt32("t9mode", CharMode
);
102 item
= new BMenuItem(_T("Character mode"), msg
);
103 fDeskbarMenu
->AddItem(item
);
104 msg
= new BMessage('SetM');
105 msg
->AddInt32("t9mode", NumMode
);
106 item
= new BMenuItem(_T("Numeric mode"), msg
);
107 fDeskbarMenu
->AddItem(item
);
108 fDeskbarMenu
->SetFont(be_plain_font
);
109 // doesn't seem to work here
110 //fDeskbarMenu->SetRadioMode(true);
111 //fDeskbarMenu->SetLabelFromMarked(true);
113 SetMenu(fDeskbarMenu
, BMessenger(this));
116 T9InputServerMethod::~T9InputServerMethod()
118 PRINT(("%s\n", __FUNCTION__
));
119 SetMenu(NULL
, BMessenger());
123 be_app
->RemoveHandler(this);
128 filter_result
T9InputServerMethod::Filter(BMessage
*message
, BList
*outList
)
131 filter_result res
= B_DISPATCH_MESSAGE
;
136 return B_DISPATCH_MESSAGE
;
138 switch (message
->what
) {
142 if (message
->FindString("bytes", &bytes
) < B_OK
)
144 if (bytes
.Length() == 1) {
145 BAutolock
l(fLocker
);
147 if (fMode
== NumMode
)
158 status_t
T9InputServerMethod::MethodActivated(bool active
)
161 return BInputServerMethod::MethodActivated(active
);
164 void T9InputServerMethod::MessageReceived(BMessage
*message
)
167 switch (message
->what
) {
169 if (message
->FindInt32("t9mode", &v
) < B_OK
)
177 s << (long) fDeskbarMenu->FindMarked();
179 s << (long) fDeskbarMenu->ItemAt(v);
180 BAlert *a = new BAlert("Plop", s.String(), "OK");
181 a->SetFlags(a->Flags() | B_CLOSE_ON_ESCAPE);
186 BHandler::MessageReceived(message
);
191 void T9InputServerMethod::SetMode(T9Mode mode
)
193 BAutolock
l(fLocker
);
197 item
= fDeskbarMenu
->FindMarked();
199 item
->SetMarked(false);
200 item
= fDeskbarMenu
->ItemAt((int32
)mode
);
202 item
->SetMarked(true);
203 // necessary to update the copy used by the Deskbar icon.
204 SetMenu(fDeskbarMenu
, BMessenger(this));