1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
/********************************************************************************
* *
* D r i v e B o x O b j e c t *
* *
*********************************************************************************
* Copyright (C) 1999,2022 by Jeroen van der Zijp. All Rights Reserved. *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"
#include "fxmath.h"
#include "fxkeys.h"
#include "FXArray.h"
#include "FXHash.h"
#include "FXMutex.h"
#include "FXStream.h"
#include "FXString.h"
#include "FXSize.h"
#include "FXPoint.h"
#include "FXRectangle.h"
#include "FXStringDictionary.h"
#include "FXSettings.h"
#include "FXRegistry.h"
#include "FXAccelTable.h"
#include "FXObjectList.h"
#include "FXEvent.h"
#include "FXWindow.h"
#include "FXApp.h"
#include "FXPath.h"
#include "FXSystem.h"
#include "FXDrawable.h"
#include "FXImage.h"
#include "FXIcon.h"
#include "FXGIFIcon.h"
#include "FXBMPIcon.h"
#include "FXFont.h"
#include "FXWindow.h"
#include "FXComposite.h"
#include "FXShell.h"
#include "FXTopWindow.h"
#include "FXDialogBox.h"
#include "FXMessageBox.h"
#include "FXFrame.h"
#include "FXLabel.h"
#include "FXTextField.h"
#include "FXButton.h"
#include "FXMenuButton.h"
#include "FXComposite.h"
#include "FXPacker.h"
#include "FXShell.h"
#include "FXPopup.h"
#include "FXScrollBar.h"
#include "FXScrollArea.h"
#include "FXList.h"
#include "FXListBox.h"
#include "FXDriveBox.h"
#include "FXDictionary.h"
#include "FXDictionaryOf.h"
#include "FXIconCache.h"
#include "FXFileAssociations.h"
#include "icons.h"
/*
Notes:
- When setting path, it adds all directories from the top down to
the lowest directory.
- It also adds common places in the file system.
- Add API's to set current path [from root down to whereever]
- Add code to read path of selected item
- Add some better icons
*/
using namespace FX;
/*******************************************************************************/
namespace FX {
// Map
FXDEFMAP(FXDriveBox) FXDriveBoxMap[]={
FXMAPFUNC(SEL_CHANGED,FXDriveBox::ID_LIST,FXDriveBox::onListChanged),
FXMAPFUNC(SEL_CLICKED,FXDriveBox::ID_LIST,FXDriveBox::onListClicked),
FXMAPFUNC(SEL_COMMAND,FXWindow::ID_SETVALUE,FXDriveBox::onCmdSetValue),
FXMAPFUNC(SEL_COMMAND,FXWindow::ID_SETSTRINGVALUE,FXDriveBox::onCmdSetStringValue),
FXMAPFUNC(SEL_COMMAND,FXWindow::ID_GETSTRINGVALUE,FXDriveBox::onCmdGetStringValue),
};
// Implementation
FXIMPLEMENT(FXDriveBox,FXListBox,FXDriveBoxMap,ARRAYNUMBER(FXDriveBoxMap))
// Directory box
FXDriveBox::FXDriveBox(FXComposite *p,FXObject* tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):FXListBox(p,tgt,sel,opts,x,y,w,h, pl,pr,pt,pb){
associations=nullptr;
if(!(options&DRIVEBOX_NO_OWN_ASSOC)) associations=new FXFileAssociations(getApp());
foldericon=new FXGIFIcon(getApp(),minifolder);
cdromicon=new FXGIFIcon(getApp(),minicdrom);
harddiskicon=new FXGIFIcon(getApp(),miniharddisk);
netdriveicon=new FXGIFIcon(getApp(),mininetdrive);
floppyicon=new FXGIFIcon(getApp(),minifloppy);
nethoodicon=new FXGIFIcon(getApp(),mininethood);
zipdiskicon=new FXGIFIcon(getApp(),minizipdrive);
setDrive(FXSystem::getCurrentDrive());
}
// Create
void FXDriveBox::create(){
FXListBox::create();
foldericon->create();
cdromicon->create();
harddiskicon->create();
netdriveicon->create();
floppyicon->create();
nethoodicon->create();
zipdiskicon->create();
}
// Detach disconnects the icons
void FXDriveBox::detach(){
FXListBox::detach();
foldericon->detach();
cdromicon->detach();
harddiskicon->detach();
netdriveicon->detach();
floppyicon->detach();
nethoodicon->detach();
zipdiskicon->detach();
}
// Destroy zaps the icons
void FXDriveBox::destroy(){
FXListBox::destroy();
foldericon->destroy();
cdromicon->destroy();
harddiskicon->destroy();
netdriveicon->destroy();
floppyicon->destroy();
nethoodicon->destroy();
zipdiskicon->destroy();
}
// Set the current item's text from the message
long FXDriveBox::onCmdSetValue(FXObject*,FXSelector,void* ptr){
setDrive((char*)ptr);
return 1;
}
// Change value
long FXDriveBox::onCmdSetStringValue(FXObject*,FXSelector,void* ptr){
setDrive(*((FXString*)ptr));
return 1;
}
// Obtain value
long FXDriveBox::onCmdGetStringValue(FXObject*,FXSelector,void* ptr){
*((FXString*)ptr)=getDrive();
return 1;
}
#ifdef WIN32 // Windows flavor
// Fill list with names of available drives
void FXDriveBox::listDrives(){
FXFileAssoc *fileassoc;
FXIcon *icon;
FXchar drivename[10];
FXuint drivemask;
// Remove old drives
clearItems();
// Add all drives
drivemask=GetLogicalDrives();
drivename[1]=':';
drivename[2]=PATHSEP;
drivename[3]='\0';
// Loop over drive letters
for(drivename[0]='A'; drivename[0]<='Z'; drivename[0]++){
if(drivemask&1){
// Default icon based on hardware type
switch(GetDriveTypeA(drivename)){
case DRIVE_REMOVABLE: icon=(drivename[0]<='B') ? floppyicon : zipdiskicon; break;
case DRIVE_FIXED: icon=harddiskicon; break;
case DRIVE_REMOTE: icon=netdriveicon; break;
case DRIVE_CDROM: icon=cdromicon; break;
case DRIVE_RAMDISK: icon=harddiskicon; break;
case DRIVE_UNKNOWN: icon=foldericon; break;
case DRIVE_NO_ROOT_DIR: icon=foldericon; break;
default: icon=foldericon; break;
}
// Maybe override from associations
if(associations){
fileassoc=associations->findDirBinding(drivename);
if(fileassoc && fileassoc->miniicon) icon=fileassoc->miniicon;
}
// Create item
if(id()) icon->create();
// Add another item
appendItem(drivename,icon);
}
drivemask>>=1;
}
}
#else // UNIX flavor
// Fill list with names of available drives
void FXDriveBox::listDrives(){
FXFileAssoc *fileassoc;
FXIcon *icon;
// Remove old items first
clearItems();
// Determine associations, icons and type
icon=foldericon;
if(associations){
fileassoc=associations->findDirBinding("/");
if(fileassoc && fileassoc->miniicon) icon=fileassoc->miniicon;
}
// Create icon
if(id()) icon->create();
// Add item
appendItem("/",icon);
}
#endif
// Forward clicked message from list to target
long FXDriveBox::onListClicked(FXObject*,FXSelector,void* ptr){
button->handle(this,FXSEL(SEL_COMMAND,ID_UNPOST),nullptr); // Unpost the list
if(0<=((FXint)(FXival)ptr)){
field->setText(getItemText((FXint)(FXival)ptr));
field->setIcon(getItemIcon((FXint)(FXival)ptr));
if(target){target->tryHandle(this,FXSEL(SEL_COMMAND,message),(void*)getItemText((FXint)(FXival)ptr).text());}
}
return 1;
}
// List has changed
long FXDriveBox::onListChanged(FXObject*,FXSelector,void* ptr){
return target && target->tryHandle(this,FXSEL(SEL_CHANGED,message),(void*)getItemText((FXint)(FXival)ptr).text());
}
// Set directory
FXbool FXDriveBox::setDrive(const FXString& drive){
listDrives();
setCurrentItem(findItem(FXPath::drive(FXPath::absolute(drive))));
return true;
}
// Return current drive
FXString FXDriveBox::getDrive() const {
return getItemText(getCurrentItem());
}
// Change associations table; force regeneration of the items
// in the tree list so all the new bindings take effect
void FXDriveBox::setAssociations(FXFileAssociations* assocs){
if(associations!=assocs){
associations=assocs;
listDrives();
}
}
// Save object to stream
void FXDriveBox::save(FXStream& store) const {
FXListBox::save(store);
store << associations;
store << foldericon;
store << cdromicon;
store << harddiskicon;
store << netdriveicon;
store << floppyicon;
store << nethoodicon;
store << zipdiskicon;
}
// Load object from stream
void FXDriveBox::load(FXStream& store){
FXListBox::load(store);
store >> associations;
store >> foldericon;
store >> cdromicon;
store >> harddiskicon;
store >> netdriveicon;
store >> floppyicon;
store >> nethoodicon;
store >> zipdiskicon;
}
// Delete it
FXDriveBox::~FXDriveBox(){
clearItems();
if(!(options&DRIVEBOX_NO_OWN_ASSOC)) delete associations;
delete foldericon;
delete cdromicon;
delete harddiskicon;
delete netdriveicon;
delete floppyicon;
delete nethoodicon;
delete zipdiskicon;
associations=(FXFileAssociations*)-1L;
foldericon=(FXIcon*)-1L;
cdromicon=(FXIcon*)-1L;
harddiskicon=(FXIcon*)-1L;
netdriveicon=(FXIcon*)-1L;
floppyicon=(FXIcon*)-1L;
nethoodicon=(FXIcon*)-1L;
zipdiskicon=(FXIcon*)-1L;
}
}
|