2 * Acess2 GUI v3 User Interface
3 * - By John Hodge (thePowersGang)
10 #include <axwin3/axwin.h>
11 #include <axwin3/widget.h>
12 #include <axwin3/menu.h>
14 #define SIDEBAR_WIDTH 40
19 void create_sidebar(void);
20 void create_mainmenu(void);
21 void create_run_dialog(void);
22 void mainmenu_run_dialog(void *unused);
23 void mainmenu_app_terminal(void *unused);
24 void mainmenu_app_textedit(void *unused);
25 void update_time(void);
29 tAxWin3_Widget *gSidebarRoot;
32 tAxWin3_Widget *gRunInput;
34 tAxWin3_Widget *gWindowList;
35 tAxWin3_Widget *gTimeDisplay;
41 int systembutton_fire(tAxWin3_Widget *Widget)
43 _SysDebug("SystemButton pressed");
44 AxWin3_Menu_ShowAt(gSystemMenu, SIDEBAR_WIDTH, 0);
48 int main(int argc, char *argv[], char **envp)
51 // Connect to AxWin3 Server
54 // TODO: Register to be told when the display layout changes
55 AxWin3_GetDisplayDims(0, NULL, NULL, &giScreenWidth, &giScreenHeight);
61 AxWin3_RegisterAction(gSidebar, "Interface>Run", (tAxWin3_HotkeyCallback)mainmenu_run_dialog);
62 AxWin3_RegisterAction(gSidebar, "Interface>Terminal", (tAxWin3_HotkeyCallback)mainmenu_app_terminal);
63 AxWin3_RegisterAction(gSidebar, "Interface>TextEdit", (tAxWin3_HotkeyCallback)mainmenu_app_textedit);
71 void create_sidebar(void)
73 tAxWin3_Widget *btn, *txt, *ele;
76 gSidebar = AxWin3_Widget_CreateWindow(NULL, SIDEBAR_WIDTH, giScreenHeight, ELEFLAG_VERTICAL);
77 AxWin3_MoveWindow(gSidebar, 0, 0);
78 gSidebarRoot = AxWin3_Widget_GetRoot(gSidebar);
81 btn = AxWin3_Widget_AddWidget(gSidebarRoot, ELETYPE_BUTTON, ELEFLAG_NOSTRETCH, "SystemButton");
82 AxWin3_Widget_SetSize(btn, SIDEBAR_WIDTH);
83 AxWin3_Widget_SetFireHandler(btn, systembutton_fire);
84 txt = AxWin3_Widget_AddWidget(btn, ELETYPE_IMAGE, 0, "SystemLogo");
85 AxWin3_Widget_SetText(txt, "file:///Acess/Apps/AxWin/3.0/AcessLogoSmall.sif");
87 // - Plain <hr/> style spacer
88 ele = AxWin3_Widget_AddWidget(gSidebarRoot, ELETYPE_SPACER, ELEFLAG_NOSTRETCH, "SideBar Spacer Top");
89 AxWin3_Widget_SetSize(ele, 4);
92 gWindowList = AxWin3_Widget_AddWidget(gSidebarRoot, ELETYPE_BOX, ELEFLAG_VERTICAL, "ProgramList");
94 // - Plain <hr/> style spacer
95 ele = AxWin3_Widget_AddWidget(gSidebarRoot, ELETYPE_SPACER, ELEFLAG_NOSTRETCH, "SideBar Spacer Top");
96 AxWin3_Widget_SetSize(ele, 4);
99 ele = AxWin3_Widget_AddWidget(gSidebarRoot,
101 ELEFLAG_VERTICAL|ELEFLAG_ALIGN_CENTER|ELEFLAG_NOSTRETCH,
104 gTimeDisplay = AxWin3_Widget_AddWidget(ele, ELETYPE_TEXT, ELEFLAG_NOSTRETCH, "Time");
105 AxWin3_Widget_SetSize(gTimeDisplay, 20);
106 //AxWin3_Widget_SetText(gTimeDisplay, "--:--");
109 // Turn off decorations
110 AxWin3_DecorateWindow(gSidebar, 0);
113 AxWin3_ShowWindow(gSidebar, 1);
117 void update_time(void)
119 char tmpbuf[2+1+2+1] = "--:--";
120 //strftime(tmpbuf, sizeof(tmpbuf), "%H:%M", NULL);
121 AxWin3_Widget_SetText(gTimeDisplay, tmpbuf);
124 void mainmenu_app_textedit(void *unused)
126 // _SysDebug("TODO: Launch text editor");
127 const char *args[] = {"ate",NULL};
128 _SysSpawn("/Acess/Apps/AxWin/3.0/ate", args, (const char **)gEnvion, 0, NULL, NULL);
131 void mainmenu_app_terminal(void *unused)
133 _SysDebug("Launch terminal emulator");
134 const char *args[] = {"terminal",NULL};
135 _SysSpawn("/Acess/Apps/AxWin/3.0/terminal", args, (const char **)gEnvion, 0, NULL, NULL);
138 void mainmenu_run_dialog(void *unused)
140 AxWin3_ShowWindow(gRunDialog, 1);
141 AxWin3_FocusWindow(gRunDialog);
144 void create_mainmenu(void)
146 gSystemMenu = AxWin3_Menu_Create(NULL);
148 AxWin3_Menu_AddItem(gSystemMenu, "Text &Editor\tWin+E", mainmenu_app_textedit, NULL, 0, NULL);
149 AxWin3_Menu_AddItem(gSystemMenu, "&Terminal Emulator\tWin+T", mainmenu_app_terminal, NULL, 0, NULL);
150 AxWin3_Menu_AddItem(gSystemMenu, NULL, NULL, NULL, 0, NULL);
151 AxWin3_Menu_AddItem(gSystemMenu, "&Run\tWin+R", mainmenu_run_dialog, NULL, 0, NULL);
154 // --------------------------------------------------------------------
156 // --------------------------------------------------------------------
157 int run_dorun(tAxWin3_Widget *unused)
159 _SysDebug("DoRun pressed");
160 char *cmd = AxWin3_Widget_GetText(gRunInput);
161 _SysDebug("Command string '%s'", cmd);
163 // TODO: Parse the command string into components
164 // TODO: Call _SysSpawn
166 AxWin3_ShowWindow(gRunDialog, 0);
170 int run_close(tAxWin3_Widget *unused)
172 _SysDebug("Run diaglog closed");
173 AxWin3_ShowWindow(gRunDialog, 0);
177 tAxWin3_Widget *make_textbutton(tAxWin3_Widget *Parent, const char *Label, tAxWin3_Widget_FireCb handler)
179 tAxWin3_Widget *ret, *txt;
180 ret = AxWin3_Widget_AddWidget(Parent, ELETYPE_BUTTON, ELEFLAG_ALIGN_CENTER, "_btn");
181 AxWin3_Widget_SetFireHandler(ret, handler);
182 AxWin3_Widget_AddWidget(ret, ELETYPE_NONE, 0, "_spacer1");
183 txt = AxWin3_Widget_AddWidget(ret, ELETYPE_TEXT, ELEFLAG_NOSTRETCH|ELEFLAG_NOEXPAND, "_txt");
184 AxWin3_Widget_SetText(txt, Label);
185 AxWin3_Widget_AddWidget(ret, ELETYPE_NONE, 0, "_spacer2");
189 void create_run_dialog(void)
191 tAxWin3_Widget *root, *box;
193 gRunDialog = AxWin3_Widget_CreateWindow(NULL, RUN_WIDTH, RUN_HEIGHT, ELEFLAG_VERTICAL);
194 AxWin3_SetWindowTitle(gRunDialog, "Run Program...");
195 AxWin3_MoveWindow(gRunDialog, giScreenWidth/2-RUN_WIDTH/2, giScreenHeight/2-RUN_HEIGHT/2);
197 root = AxWin3_Widget_GetRoot(gRunDialog);
199 gRunInput = AxWin3_Widget_AddWidget(root, ELETYPE_TEXTINPUT, ELEFLAG_NOSTRETCH, "Input");
200 AxWin3_Widget_SetFireHandler(gRunInput, run_dorun);
202 box = AxWin3_Widget_AddWidget(root, ELETYPE_BOX, ELEFLAG_ALIGN_CENTER, "Button Area");
203 make_textbutton(box, "Ok", run_dorun);
204 make_textbutton(box, "Cancel", run_close);