Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / openurl / prefs / browsereditwin.c
blob97e4376e151d81c2a3d1e653075b4c183042ba08
1 /*
2 ** OpenURL - MUI preferences for openurl.library
3 **
4 ** Written by Troels Walsted Hansen <troels@thule.no>
5 ** Placed in the public domain.
6 **
7 ** Developed by:
8 ** - Alfonso Ranieri <alforan@tin.it>
9 ** - Stefan Kost <ensonic@sonicpulse.de>
11 ** Ported to OS4 by Alexandre Balaban <alexandre@balaban.name>
13 ** Edit browser window
17 #include "OpenURL.h"
18 #define CATCOMP_NUMBERS
19 #include "loc.h"
20 #include "libraries/openurl.h"
22 /**************************************************************************/
24 struct data
27 Object *browserList;
29 Object *name;
30 Object *path;
31 Object *port;
33 Object *show;
34 Object *toFront;
35 Object *openURL;
36 Object *openURLNW;
38 Object *use;
39 Object *cancel;
41 struct URL_BrowserNode *bn;
43 ULONG flags;
46 enum
48 FLG_Notifies = 1<<0,
51 /**************************************************************************/
53 static STRPTR syms[] =
55 "%u",
56 "%p",
57 NULL
60 static STRPTR names[] =
62 (STRPTR)MSG_Edit_PopURL,
63 (STRPTR)MSG_Edit_PopScreen,
64 NULL
67 static ULONG
68 mNew(struct IClass *cl,Object *obj,struct opSet *msg)
70 struct data temp;
71 struct URL_BrowserNode *bn;
72 struct TagItem *attrs = msg->ops_AttrList;
74 memset(&temp,0,sizeof(temp));
76 temp.browserList = (Object *)GetTagData(MUIA_BrowserEditWin_ListObj,(ULONG)NULL,attrs);
77 if (!temp.browserList) return 0;
79 bn = temp.bn = (struct URL_BrowserNode *)GetTagData(MUIA_BrowserEditWin_Browser,(ULONG)NULL,attrs);
80 if (!bn) return 0;
83 if (obj = (Object *)DoSuperNew(cl,obj,
84 MUIA_HelpNode, "BWIN",
85 MUIA_Window_ID, MAKE_ID('E','D','B','R'),
86 MUIA_Window_Title, getString(MSG_Browser_WinTitle),
87 MUIA_Window_ScreenTitle, getString(MSG_App_ScreenTitle),
88 MUIA_Window_AllowTopMenus, FALSE,
90 WindowContents, VGroup,
91 Child, ColGroup(2),
92 GroupFrameT(getString(MSG_Edit_Definitions)),
94 Child, olabel2(MSG_Edit_Name),
95 Child, temp.name = ostring(NAME_LEN,MSG_Edit_Name,MSG_Edit_Name_Help),
97 Child, olabel2(MSG_Edit_Path),
98 Child, temp.path = opopph(syms,names,PATH_LEN,MSG_Edit_Path,TRUE,MSG_Edit_Path_Help),
99 Child, olabel2(MSG_Edit_Port),
100 Child, temp.port = opopport(PORT_LEN,MSG_Edit_Port,MSG_Edit_Port_Help),
101 End,
103 Child, ColGroup(2),
104 GroupFrameT(getString(MSG_Edit_ARexx)),
106 Child, olabel2(MSG_Edit_Show),
107 Child, temp.show = ostring(SHOWCMD_LEN,MSG_Edit_Show,MSG_Edit_Show_Help),
109 Child, olabel2(MSG_Edit_Screen),
110 Child, temp.toFront = ostring(TOFRONTCMD_LEN,MSG_Edit_Screen,MSG_Edit_Screen_Help),
112 Child, olabel2(MSG_Edit_OpenURL),
113 Child, temp.openURL = opopph(syms,names,OPENURLCMD_LEN,MSG_Edit_OpenURL,FALSE,MSG_Edit_OpenURL_Help),
114 Child, olabel2(MSG_Edit_NewWin),
115 Child, temp.openURLNW = opopph(syms,names,OPENURLWCMD_LEN,MSG_Edit_NewWin,FALSE,MSG_Edit_NewWin_Help),
116 End,
118 Child, ColGroup(3),
119 Child, temp.use = obutton(MSG_Edit_Use,MSG_Edit_Use_Help),
120 Child, RectangleObject, End,
121 Child, temp.cancel = obutton(MSG_Edit_Cancel,MSG_Edit_Cancel_Help),
122 End,
123 End,
124 TAG_MORE, attrs))
126 struct data *data = INST_DATA(cl,obj);
128 CopyMem(&temp,data,sizeof(*data));
130 set(data->name,MUIA_String_Contents,bn->ubn_Name);
131 set(data->path,MUIA_String_Contents,bn->ubn_Path);
132 set(data->port,MUIA_String_Contents,bn->ubn_Port);
133 set(data->show,MUIA_String_Contents,bn->ubn_ShowCmd);
134 set(data->toFront,MUIA_String_Contents,bn->ubn_ToFrontCmd);
135 set(data->openURL,MUIA_String_Contents,bn->ubn_OpenURLCmd);
136 set(data->openURLNW,MUIA_String_Contents,bn->ubn_OpenURLWCmd);
139 return (ULONG)obj;
142 /**************************************************************************/
144 static ULONG
145 mGet(struct IClass *cl,Object *obj,struct opGet *msg)
147 struct data *data = INST_DATA(cl,obj);
149 switch (msg->opg_AttrID)
151 case MUIA_BrowserEditWin_Browser: *msg->opg_Storage = (ULONG)data->bn; return TRUE;
152 case MUIA_App_IsSubWin: *msg->opg_Storage = TRUE; return TRUE;
153 default: return DoSuperMethodA(cl,obj,(Msg)msg);
157 /**************************************************************************/
159 static ULONG
160 mWindow_Setup(struct IClass *cl,Object *obj,struct MUIP_Window_Setup *msg)
162 struct data *data = INST_DATA(cl,obj);
164 if (!DoSuperMethodA(cl,obj,(Msg)msg)) return FALSE;
166 if (!(data->flags & FLG_Notifies))
168 DoMethod(data->use,MUIM_Notify,MUIA_Pressed,FALSE,(ULONG)obj,1,MUIM_BrowserEditWin_Use);
169 DoMethod(data->cancel,MUIM_Notify,MUIA_Pressed,FALSE,(ULONG)obj,3,MUIM_Set,MUIA_Window_CloseRequest,TRUE);
171 DoMethod(obj,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,(ULONG)_app(obj),6,MUIM_Application_PushMethod,
172 (ULONG)_app(obj),3,MUIM_App_CloseWin,MUIA_BrowserEditWin_Browser,(ULONG)data->bn);
174 data->flags |= FLG_Notifies;
177 return TRUE;
180 /**************************************************************************/
182 static ULONG
183 mUse(struct IClass *cl,Object *obj,Msg msg)
185 struct data *data = INST_DATA(cl,obj);
186 struct URL_BrowserNode *bn = data->bn;
187 LONG i, visible, first;
189 bn->ubn_Flags &= ~UNF_NEW;
191 strcpy((STRPTR)bn->ubn_Name,(STRPTR)xget(data->name,MUIA_String_Contents));
192 strcpy((STRPTR)bn->ubn_Path,(STRPTR)xget(data->path,MUIA_String_Contents));
193 strcpy((STRPTR)bn->ubn_Port,(STRPTR)xget(data->port,MUIA_String_Contents));
195 strcpy((STRPTR)bn->ubn_ShowCmd,(STRPTR)xget(data->show,MUIA_String_Contents));
196 strcpy((STRPTR)bn->ubn_ToFrontCmd,(STRPTR)xget(data->toFront,MUIA_String_Contents));
197 strcpy((STRPTR)bn->ubn_OpenURLCmd,(STRPTR)xget(data->openURL,MUIA_String_Contents));
198 strcpy((STRPTR)bn->ubn_OpenURLWCmd,(STRPTR)xget(data->openURLNW,MUIA_String_Contents));
200 get(data->browserList,MUIA_List_Visible,&visible);
201 if (visible!=-1)
203 get(data->browserList,MUIA_List_First,&first);
205 for (i = first; i < (first + visible); i++)
207 DoMethod(data->browserList,MUIM_List_GetEntry,i,(ULONG)&bn);
208 if (!bn) break;
210 if (bn==data->bn)
212 DoMethod(data->browserList,MUIM_List_Redraw,i);
213 break;
218 set(obj,MUIA_Window_CloseRequest,TRUE);
220 return TRUE;
223 /**************************************************************************/
225 M_DISP(dispatcher)
227 M_DISPSTART
229 switch (msg->MethodID)
231 case OM_NEW: return mNew(cl,obj,(APTR)msg);
232 case OM_GET: return mGet(cl,obj,(APTR)msg);
234 case MUIM_Window_Setup: return mWindow_Setup(cl,obj,(APTR)msg);
236 case MUIM_BrowserEditWin_Use: return mUse(cl,obj,(APTR)msg);
238 default: return DoSuperMethodA(cl,obj,msg);
242 M_DISPEND(dispatcher)
244 /**************************************************************************/
246 ULONG
247 initBrowserEditWinClass(void)
249 if (g_browserEditWinClass = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct data),DISP(dispatcher)))
251 localizeStrings(names);
253 return TRUE;
256 return FALSE;
259 /**************************************************************************/
261 void
262 disposeBrowserEditWinClass(void)
264 if (g_browserEditWinClass) MUI_DeleteCustomClass(g_browserEditWinClass);
267 /**************************************************************************/