736ffbb9e9904f12f7fc9d13621ef2f745200c33
[reactos.git] / subsys / system / explorer / winefile / plugins / ex_menu.c
1 //
2 // Explorer Start Menu PlugIn (Example)
3 // 
4 // Alexander Ciobanu
5 // alex@prodidactica.md
6 //
7
8 #include <windows.h>
9 #include <stdio.h>
10
11 #include "ex_bar.h"
12
13 HWND epl_AppButtons[10];
14 char epl_line[10][80];
15 int  epl_Buttons;
16
17 int  ex_x1;
18 int  ex_y1;
19 int  ex_dx;
20 int  ex_dy;
21
22 // Initialize the plugin
23 //
24 static int InitializePlugIn(HWND ExplorerHandle)
25 {
26  FILE* Conf;    // Configuration File;
27  char line[80];  // Blah Blah Blah
28  char ttl[80];   // Title of the button
29  int i;
30  int x;
31
32  HINSTANCE hinst = (HINSTANCE) GetWindowLong(ExplorerHandle, GWL_HINSTANCE);
33
34  fprintf(stderr,"EX_MENU : INITIALIZE PLUGIN call\n");
35
36  CreateWindow(TEXT("BUTTON"), TEXT("Start"), WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
37      2, 2, 50, ex_dy-10, ExplorerHandle, NULL, hinst, 0);
38
39  if (!(Conf=fopen("explorer.lst","r")))   // Error !
40   {
41    fprintf(stderr,"DefaultPlugin : No configuration file found !\n");
42    return 0;
43   }
44  
45  fgets(line,80,Conf);              // Read how many entries are in the file
46  epl_Buttons=atoi(line);           // atoi it !
47
48  for (i=0;i<epl_Buttons;i++)
49  {
50    fgets(ttl,80,Conf);            // Read stuff :)
51    fgets(line,80,Conf);
52
53    for (x=0;ttl[x];x++) if (ttl[x]<14){ttl[x]=0;break;}
54     for (x=0;line[x];x++) if (line[x]<14){line[x]=0;break;}
55    
56    // FIXME : Got to get rid of #13,#10 at the end of the lines !!!!!!!!!!!!!!!!!!!
57
58    strcpy(epl_line[i],line);
59
60    epl_AppButtons[i] = CreateWindow(
61     TEXT("BUTTON"),ttl/*@@*/, WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
62       60+(i*102)+2, 2, 100,  ex_dy-10, ExplorerHandle, NULL, hinst, 0);
63   }
64
65   return 1;
66 }
67
68 // Get Information about the plugin
69 //
70 static char* PlugInInfo(int InfoNmbr)
71 {
72   static char Info[256];
73
74   fprintf(stderr,"EX_MENU : INFORMATION PLUGIN call\n");
75
76   switch(InfoNmbr)
77   {
78     case 0:                                   // PlugIn Name
79      strcpy(Info,"ApplicationLauncher");
80      break;
81
82     case 1:                                   // Version
83      strcpy(Info,"0.1");
84      break;
85
86     case 2:                                   // Vendor name
87      strcpy(Info,"ReactOS team");
88      break;
89
90     default:                                  // Default : Error
91      strcpy(Info,"-");
92      break;
93  
94   }
95
96   return Info;
97 }
98
99 // Reload plugin's configuration
100 //
101 static int ReloadPlugInConfiguration()
102 {
103   fprintf(stderr,"EX_MENU : RELOAD PLUGIN COFIGURATION call\n");
104   return 1;
105 }
106
107 // Quit plugin
108 //
109 static int QuitPlugIn()
110 {
111   fprintf(stderr,"EX_MENU : QUIT PLUGIN call\n");
112   return 1;
113 }
114
115
116  // display a windows error message
117 static void display_error(HWND hwnd, DWORD error)
118 {
119         PTSTR msg;
120
121         if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
122                 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
123                 MessageBox(hwnd, msg, TEXT("ROS Explorer"), MB_OK);
124         else
125                 MessageBox(hwnd, TEXT("Error"), TEXT("ROS Explorer"), MB_OK);
126
127         LocalFree(msg);
128 }
129
130  // launch a program or document file
131 static BOOL launch_file(HWND hwnd, LPSTR cmd, UINT nCmdShow)
132 {
133         HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
134
135         if ((int)hinst <= 32) {
136                 display_error(hwnd, GetLastError());
137                 return FALSE;
138         }
139
140         return TRUE;
141 }
142
143
144 // Callback procedure for plugin
145 //
146 static int PlugInMessageProc(HWND PlgnHandle, UINT Msg, WPARAM wParam, LPARAM lParam)
147 {
148   int i;
149   
150  // The plugin must decide whatever the handle passed is created by it !
151  // Sorry for bad english :-)
152  //
153  switch(Msg)
154   {
155    case WM_COMMAND:
156      for (i=0;i<epl_Buttons;i++)
157       {
158         if ((HWND)lParam==epl_AppButtons[i])
159           {
160             printf("Pressed Button Line : %s\n",epl_line[i]);
161             launch_file(PlgnHandle, epl_line[i], SW_SHOWNORMAL);
162           }
163       }
164     break;
165   }
166
167   return 1;
168 }
169
170 // Callback function to get ExplorerBar's information
171 //
172 static int ExplorerInfo(EXBARINFO* info)
173 {
174   fprintf(stderr,"EX_MENU : EXPLORER INFO PLUGIN call\n");
175   ex_x1=info->x;
176   ex_y1=info->y;
177   ex_dx=info->dx;
178   ex_dy=info->dy;
179
180   return 1;
181 }
182
183
184 #ifdef _PLUGIN
185 BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
186 {
187   fprintf(stderr,"EX_MENU PlugIn loaded succesefully\n");
188   return TRUE;
189 }
190 #endif
191
192
193 struct PluginCalls plugincalls_Menu = {
194         InitializePlugIn,
195         QuitPlugIn,
196         ReloadPlugInConfiguration,
197         PlugInInfo,
198         ExplorerInfo,
199         PlugInMessageProc
200 };
201