source: branches/v2.9/mediafolder/c/helper/windowhelper.cpp

Last change on this file was 2, checked in by stevenhl, 8 years ago

Import sources from cwmm-full.zip dated 2005-03-21

File size: 11.6 KB
Line 
1#define INCL_DOSERRORS
2#include "mediafolder.hh"
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include "mediafolderres.h"
7#include <sys_funcs.h>
8
9/* typedef for somTP_MMAudio_cwmmQueryTrackInfo */
10/* For calling the method in the CWAudio class. Linking to the DLL would require the
11 new audio classes. By dynamically querying the method the media folder works without
12 installing the audio classes. */
13#include "cwmmquerytrackinfo.h"
14
15#define IDINFO_NAME 1
16#define IDINFO_ARTIST 2
17#define IDINFO_ALBUM 3
18#define IDINFO_YEAR 4
19#define IDINFO_COMMENT 5
20#define IDINFO_GENRE 6
21
22#define IDINFO_PLAYTIME 7
23
24/* Pointer into window words */
25extern ULONG ulQWP_CONTAINERPROC;
26extern ULONG ulQWP_THISPTR;
27extern ULONG ulQWL_TOPCTRLHWND;
28extern ULONG ulQWL_BOTTOMCTRLHWND;
29extern ULONG ulQWL_RIGHTCTRLHWND;
30extern ULONG ulQWL_LEFTCTRLHWND;
31
32extern BOOL somhlpQueryCWAudioMethodPtr(CWMediaFolder *thisPtr);
33extern SOMClass* somhlpGetSomClass(char* chrClassName);
34
35extern HMODULE queryResModuleHandle(void);
36
37/*
38
39 Functions to get the frame controls from the folder frame HWND.
40 If anytime the window hierarchy changes only these functions must be
41 changed but not dozens of places all over the source.
42
43 The HWNDs of the controls are saved in the window words of the reregistered frame for
44 easy access. Strivtly spoken no need to have the HWND in the instance data. Only the
45 frame hwnd must be available.
46
47 */
48
49/* Get the HWND of the frame control at the top. That's not the control
50 with the buttons and the time display. The play controls are located on
51 another frame (use playControlDialogFromFrameHWND() to get it). */
52HWND topControlFromFrameHWND(HWND hwndFrame)
53{
54 return WinQueryWindowULong(hwndFrame, ulQWL_TOPCTRLHWND);
55}
56
57/* Get the HWND of the frame control at the bottom (status bar) */
58HWND bottomControlFromFrameHWND(HWND hwndFrame)
59{
60 return WinQueryWindowULong(hwndFrame, ulQWL_BOTTOMCTRLHWND);
61}
62
63/* Get the HWND of the play control dialog. This Dialog is on top of
64 the top frame control. */
65HWND playControlDialogFromFrameHWND(HWND hwndFrame)
66{
67 return WinWindowFromID(topControlFromFrameHWND(hwndFrame), IDDLG_TOPMIDDLE);
68}
69
70/* Get the HWND of the time display static text control. */
71HWND playTimeControlFromFrameHWND(HWND hwndFrame)
72{
73 return WinWindowFromID(playControlDialogFromFrameHWND(hwndFrame), IDST_PLAYTIME);
74}
75
76
77/* Show/hide the text in the playtime area. Useful for blinking. */
78void showPlayTimeDisplay(CWMediaFolder *thisPtr, BOOL bShow)
79{
80 WinShowWindow(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame), bShow);
81}
82
83/* Toggle the visibility of the text in the playtime area. Useful for blinking. */
84void togglePlayTimeDisplayVisibility(CWMediaFolder *thisPtr)
85{
86 if(WinIsWindowVisible(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame)))
87 WinShowWindow(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame), FALSE);
88 else
89 WinShowWindow(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame), TRUE);
90}
91
92static HWND _findOpenMediaFldrView(CWMediaFolder *thisPtr)
93{
94 PVIEWITEM pViewItem;
95
96 pViewItem=thisPtr->wpFindViewItem(VIEW_DETAILS|VIEW_CONTENTS, NULLHANDLE);
97 if(pViewItem)
98 return pViewItem->handle;
99
100 return NULLHANDLE;
101}
102
103/*
104
105 V0.2.8 (08.09.2003)
106 This function sets the window list entry text, the folder frame title and the playtime text.
107
108 */
109static void setAllTitles(CWMediaFolder *thisPtr, char * chrText)
110{
111 HSWITCH hSwitch;
112 char chrBuff[100]={0};
113 SWP swp;
114
115 my_strlcpy(chrBuff, thisPtr->wpQueryTitle(), sizeof(chrBuff));
116 if(chrText && *chrText)
117 {
118 strncat(chrBuff," - ", sizeof(chrBuff)-1-strlen(chrBuff));
119 strncat(chrBuff, chrText, sizeof(chrBuff)-1-strlen(chrBuff));
120 }
121
122 /* Set folder playtimer control */
123 WinSetWindowText(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame), chrText);
124 /*
125 Register as a view so the 'Details view' in folder titles is changed to
126 the given text.
127 Changing the window title is not sufficient because the WPS only displays the number
128 of characters in the switch list the object title had during first registering of a view.
129 If the window title (or the object title) is changed later it will be truncated and the
130 view is appended to the then truncated title. This is even true if the switch list title
131 is directly changed using WinChangeSwitchEntry(). Probably the window list window is
132 subclassed by the WPS to append the current view.
133 */
134 thisPtr->wpRegisterView(thisPtr->hwndMFldrFrame, chrText);
135
136 /*
137 If the window is minimized change also the window text so the info is shown
138 in the minimized view. This will not change the length of the title in the window list entry.
139 The string to be shown is built starting with the object title (as the WPS does) so it
140 doesn't matter the switch list entry length is limited.
141 */
142 WinQueryWindowPos(thisPtr->hwndMFldrFrame, &swp);
143 if(swp.fl & SWP_MINIMIZE)
144 WinSetWindowText(thisPtr->hwndMFldrFrame, chrBuff);
145
146 /* The switch list must also be changed because wpRegisterView()
147 only changes the window list text once. */
148 if((hSwitch=WinQuerySwitchHandle(thisPtr->hwndMFldrFrame,0))!=NULLHANDLE)
149 {
150 SWCNTRL swCtrl;
151
152 if(!WinQuerySwitchEntry(hSwitch, &swCtrl))
153 {
154 strncpy(swCtrl.szSwtitle, chrBuff, MAXNAMEL+4);
155 swCtrl.szSwtitle[MAXNAMEL+3]=0;
156 WinChangeSwitchEntry( hSwitch, &swCtrl);
157 }
158 }
159}
160
161#if 0
162static void setAllTitles(CWMediaFolder *thisPtr, const char * chrText)
163{
164 char chrBuff[100]={0};
165 HSWITCH hSwitch;
166
167 my_strlcpy(chrBuff,thisPtr->wpQueryTitle(), sizeof(chrBuff));
168 strncat(chrBuff," - ", sizeof(chrBuff)-1-strlen(chrBuff));
169 strncat(chrBuff, chrText, sizeof(chrBuff)-1-strlen(chrBuff));
170
171 WinSetWindowText(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame), chrText);
172 // WinSetWindowText(thisPtr->hwndMFldrFrame, chrBuff);
173 thisPtr->wpRegisterView(thisPtr->hwndMFldrFrame, chrBuff);
174 if((hSwitch=WinQuerySwitchHandle(thisPtr->hwndMFldrFrame,0))!=NULLHANDLE)
175 {
176 SWCNTRL swCtrl;
177 if(!WinQuerySwitchEntry(hSwitch, &swCtrl))
178 {
179 strncpy(swCtrl.szSwtitle, chrBuff, MAXNAMEL+4);
180 swCtrl.szSwtitle[MAXNAMEL+3]=0;
181 WinChangeSwitchEntry( hSwitch, &swCtrl);
182 }
183 }
184
185}
186#endif
187
188/* Set the text in the playtime area to 'theText' */
189void setPlayTimeText2(CWMediaFolder *thisPtr, char * theText)
190{
191 setAllTitles(thisPtr, theText);
192 // WinSetWindowText(playControlDialogFromFrameHWND(thisPtr->hwndMFldrFrame), theText);
193}
194
195/* This funktion sets the playtime display according to the user settings.
196 Supported are remaining time, elapsed time and ID3-tag display */
197void setPlayTimeText(CWMediaFolder *thisPtr)
198{
199 char text[100];
200 ULONG ulTemp;
201 MMAudio* cwAudio;
202
203 switch(thisPtr->usWhichDisplay)
204 {
205 case 1:
206 /* Remaining */
207 ulTemp=thisPtr->ulTotalLength/1000-thisPtr->ulPos;
208 sprintf(text,"-%d:%02d",
209 ulTemp/60,
210 ulTemp%60);
211 // WinSetWindowText(WinWindowFromID(thisPtr->hwndTopMiddle, IDST_PLAYTIME), text);
212
213 setAllTitles(thisPtr, text);
214
215 break;
216 case 2:
217 {
218 ULONG ulTemp=WinQueryWindowULong(WinWindowFromID(thisPtr->hwndTopMiddle, IDST_PLAYTIME), QWL_USER);
219 SOMClass *cwAudioClass=somhlpGetSomClass("MMAudio");
220
221 /* Show ID3 tag */
222 cwAudio=thisPtr->cwQueryCurrentlyPlayingObject();
223 if(somIsObj(cwAudio)) {
224 if(!methodPtr)
225 somhlpQueryCWAudioMethodPtr(thisPtr);
226 sprintf(text,"");
227 if(methodPtr && somIsObj(cwAudioClass) && cwAudio->somIsA(cwAudioClass) ){/* Query playtime in secs */
228 char* chrPtr=text;
229 text[0]=0;
230
231 if(ulTemp>=15)
232 text[0]=0;
233 else if(ulTemp>=12)
234 methodPtr(cwAudio, chrPtr, sizeof(text), IDINFO_GENRE);
235 else if(ulTemp>=9)
236 methodPtr(cwAudio, chrPtr, sizeof(text), IDINFO_COMMENT);
237 else if(ulTemp>=6)
238 methodPtr(cwAudio, chrPtr, sizeof(text), IDINFO_ALBUM);
239 else if(ulTemp>=3)
240 methodPtr(cwAudio, chrPtr, sizeof(text), IDINFO_NAME);
241 else if(ulTemp>=0)
242 methodPtr(cwAudio, chrPtr, sizeof(text), IDINFO_ARTIST);
243 }
244 else
245 ulTemp=15; /* Show playtime for midi files */
246
247 if(ulTemp>=15||!strlen(text)) {
248 /* Play time */
249 sprintf(text,"%d:%02d",
250 thisPtr->ulPos/60,
251 thisPtr->ulPos%60);
252 }
253#if 0
254 else
255 if(!(ulTemp%3)) {
256 /* Switch display every 3 secs */
257 }
258#endif
259
260 setAllTitles(thisPtr, text);
261
262 // WinSetWindowText(WinWindowFromID(thisPtr->hwndTopMiddle, IDST_PLAYTIME), text);
263 // WinSetWindowText(WinQueryWindow(WinQueryWindow(thisPtr->hwndTopMiddle, QW_PARENT), QW_PARENT), "12345\n6789");
264
265 ulTemp++;
266 if(ulTemp==18)
267 ulTemp=0;
268 WinSetWindowULong(WinWindowFromID(thisPtr->hwndTopMiddle, IDST_PLAYTIME), QWL_USER, ulTemp);
269 break;
270 }
271 }
272 /* Fall through to playtime */
273 case 0:
274 /* Elapsed time */
275 sprintf(text,"%d:%02d",
276 thisPtr->ulPos/60,
277 thisPtr->ulPos%60);
278
279 setAllTitles(thisPtr, text);
280 // WinSetWindowText(WinWindowFromID(thisPtr->hwndTopMiddle, IDST_PLAYTIME), text);
281 break;
282 default:
283 break;
284 }
285}
286
287void _resetDisplay(CWMediaFolder *thisPtr)
288{
289 setAllTitles(thisPtr, "");
290 WinSetWindowText(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame), "0:00");
291 WinSetWindowULong(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame), QWL_USER, 0);
292 WinPostMsg( WinWindowFromID(playTimeControlFromFrameHWND(thisPtr->hwndMFldrFrame), IDSL_POSBAR),
293 SLM_SETSLIDERINFO,
294 MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),
295 MPFROMLONG(0L));
296 // thisPtr->wpRegisterView(thisPtr->hwndMFldrFrame, "");
297}
298
299/* This function sets the repeat button checkstate */
300void winCheckRepeatButton(CWMediaFolder *thisPtr)
301{
302 if(thisPtr->ulFlags & FLAG_REPEAT)
303 WinCheckButton(playControlDialogFromFrameHWND(thisPtr->hwndMFldrFrame), IDCB_REPEAT, 1);
304 else
305 WinCheckButton(playControlDialogFromFrameHWND(thisPtr->hwndMFldrFrame), IDCB_REPEAT, 0);
306}
307
308/* This function sets the position of the volume slider */
309void winSetVolumeSlider(CWMediaFolder *thisPtr)
310{
311 WinSendMsg( WinWindowFromID(playControlDialogFromFrameHWND(thisPtr->hwndMFldrFrame), IDSL_VOLUME),
312 SLM_SETSLIDERINFO,
313 MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),
314 MPFROMLONG( thisPtr->ulVolume));
315}
316
317
318void contextMenu(HWND hwnd, USHORT usItem, BOOL fCheckItem)
319{
320 POINTL ptl;
321 HWND hwndPopup;
322
323 hwndPopup = WinLoadMenu(hwnd, queryResModuleHandle(), ID_MENUTIMECONTEXT) ;
324 if (hwndPopup == NULLHANDLE) {
325 DosBeep(100,1000);
326 return;
327 }
328 if(fCheckItem)
329 WinSendMsg(hwndPopup,MM_SETITEMATTR,MPFROM2SHORT(usItem, TRUE), MPFROM2SHORT(MIA_CHECKED,MIA_CHECKED));
330
331 WinQueryPointerPos(HWND_DESKTOP, &ptl) ;
332 WinMapWindowPoints(HWND_DESKTOP,hwnd,&ptl,1);
333 WinPopupMenu(hwnd, hwnd, hwndPopup,
334 ptl.x, ptl.y, 0, PU_HCONSTRAIN | PU_VCONSTRAIN |
335 PU_KEYBOARD | PU_MOUSEBUTTON1 | PU_MOUSEBUTTON2 | PU_NONE );
336
337}
338
339
Note: See TracBrowser for help on using the repository browser.