OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4FileSelDlg.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2008-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // file selection dialogs
17 
18 #include "C4Include.h"
19 #include "gui/C4FileSelDlg.h"
20 
21 #include "graphics/C4GraphicsResource.h" // only for single use of ::GraphicsResource.fctOKCancel below...
22 #include "C4Version.h"
23 #include "graphics/C4Draw.h"
24 
25 #ifdef _WIN32
26 #ifndef _WIN32_IE
27 #define _WIN32_IE 0x0400
28 #endif
29 #undef MK_ALT
30 #include <shlobj.h>
31 #ifndef CSIDL_MYPICTURES
32 #define CSIDL_MYPICTURES 0x0027
33 #endif
34 #endif
35 
36 // def 1 if gfx loading works in background thread. Right now, it doesn't
37 // C4Group and C4Surface just don't like it
38 // So for now, the loading will be done in 1/10 of the frames in OnIdle of the dialog
39 #define USE_BACKGROUND_THREAD_LOAD 0
40 
41 
42 // ---------------------------------------------------
43 // C4FileSelDlg::ListItem
44 
45 C4FileSelDlg::ListItem::ListItem(const char *szFilename) : C4GUI::Control(C4Rect(0,0,0,0))
46 {
47  if (szFilename) sFilename.Copy(szFilename); else sFilename.Clear();
48 }
49 
51 {
52 }
53 
54 // ---------------------------------------------------
55 // C4FileSelDlg::DefaultListItem
56 
57 C4FileSelDlg::DefaultListItem::DefaultListItem(const char *szFilename, bool fTruncateExtension, bool fCheckbox, bool fGrayed, C4GUI::Icons eIcon)
58  : C4FileSelDlg::ListItem(szFilename), pLbl(nullptr), pCheck(nullptr), pKeyCheck(nullptr), fGrayed(fGrayed)
59 {
60  StdStrBuf sLabel; if (szFilename) sLabel.Ref(::GetFilename(szFilename)); else sLabel.Ref(LoadResStr("IDS_CTL_NONE"));
61  if (szFilename && fTruncateExtension)
62  {
63  sLabel.Copy();
64  char *szFilename = sLabel.GrabPointer();
65  RemoveExtension(szFilename);
66  sLabel.Take(szFilename);
67  }
69  UpdateSize();
71  int32_t iHeight = caMain.GetInnerHeight();
72  if (fCheckbox)
73  {
74  pCheck = new C4GUI::CheckBox(caMain.GetFromLeft(iHeight), nullptr, false);
75  if (fGrayed) pCheck->SetEnabled(false);
76  AddElement(pCheck);
77  pKeyCheck = new C4KeyBinding(C4KeyCodeEx(K_SPACE), "FileSelToggleFileActive", KEYSCOPE_Gui,
79  }
80  C4GUI::Icon *pIco = new C4GUI::Icon(caMain.GetFromLeft(iHeight), eIcon);
81  AddElement(pIco);
82  pLbl = new C4GUI::Label(sLabel.getData(), caMain.GetAll(), ALeft, fGrayed ? C4GUI_CheckboxDisabledFontClr : C4GUI_CheckboxFontClr);
83  AddElement(pLbl);
84 }
85 
87 {
88  if (pKeyCheck) delete pKeyCheck;
89 }
90 
92 {
94  if (!pLbl) return;
96  caMain.GetFromLeft(caMain.GetInnerHeight()*(1+!!pCheck));
97  pLbl->SetBounds(caMain.GetAll());
98 }
99 
101 {
102  return pCheck ? pCheck->GetChecked() : false;
103 }
104 
106 {
107  // store new state in checkbox
108  if (pCheck) pCheck->SetChecked(fChecked);
109 }
110 
112 {
113  // toggle if possible
114  if (pCheck && !IsGrayed())
115  {
116  pCheck->ToggleCheck(true);
117  return true;
118  }
119  return false;
120 }
121 
122 
123 
124 
125 // ---------------------------------------------------
126 // C4FileSelDlg
127 
128 C4FileSelDlg::C4FileSelDlg(const char *szRootPath, const char *szTitle, C4FileSel_BaseCB *pSelCallback, bool fInitElements)
129  : C4GUI::Dialog(Clamp(C4GUI::GetScreenWdt()*2/3+10, 300,600), Clamp(C4GUI::GetScreenHgt()*2/3+10, 220,500), szTitle, false),
130  pLocationComboBox(nullptr), pFileListBox(nullptr), pSelectionInfoBox(nullptr), btnOK(nullptr), pLocations(nullptr), iLocationCount(0), pSelection(nullptr), pSelCallback(pSelCallback)
131 {
132  sTitle.Copy(szTitle);
133  // key bindings
134  pKeyRefresh = new C4KeyBinding(C4KeyCodeEx(K_F5), "FileSelReload", KEYSCOPE_Gui,
136  pKeyEnterOverride = new C4KeyBinding(C4KeyCodeEx(K_RETURN), "FileSelConfirm", KEYSCOPE_Gui,
138  if (fInitElements) InitElements();
139  sPath.Copy(szRootPath);
140 }
141 
143 {
144  UpdateSize();
145  CStdFont *pUseFont = &(::GraphicsResource.TextFont);
146  // main calcs
147  bool fHasOptions = HasExtraOptions();
148  C4GUI::ComponentAligner caMain(GetClientRect(), 0,0, true);
149  C4Rect rcOptions;
151  if (fHasOptions) rcOptions = caMain.GetFromBottom(pUseFont->GetLineHeight() + 2*C4GUI_DefDlgSmallIndent);
153  // create file selection area
154  if (iLocationCount)
155  {
157  StdStrBuf sText(LoadResStr("IDS_TEXT_LOCATION"));
158  AddElement(new C4GUI::Label(sText.getData(), caLocations.GetFromLeft(pUseFont->GetTextWidth(sText.getData())), ALeft));
159  pLocationComboBox = new C4GUI::ComboBox(caLocations.GetAll());
161  pLocationComboBox->SetText(pLocations[0].sName.getData());
162  }
163  // create file selection area
164  bool fHasPreview = HasPreviewArea();
165  pFileListBox = new C4GUI::ListBox(fHasPreview ? caUpperArea.GetFromLeft(caUpperArea.GetWidth()/2) : caUpperArea.GetAll(), GetFileSelColWidth());
168  if (fHasPreview)
169  {
170  caUpperArea.ExpandLeft(C4GUI_DefDlgIndent);
171  pSelectionInfoBox = new C4GUI::TextWindow(caUpperArea.GetAll());
172  pSelectionInfoBox->SetDecoration(true, true, nullptr, true);
173  }
174  // create button area
175  C4GUI::Button *btnAbort = new C4GUI::CancelButton(caButtonArea.GetFromRight(C4GUI_DefButton2Wdt));
176  btnOK = new C4GUI::OKButton(caButtonArea.GetFromRight(C4GUI_DefButton2Wdt));
177  // add components in tab order
178  if (pLocationComboBox) AddElement(pLocationComboBox);
179  AddElement(pFileListBox);
180  if (pSelectionInfoBox) AddElement(pSelectionInfoBox);
181  if (fHasOptions) AddExtraOptions(rcOptions);
182  AddElement(btnOK);
183  AddElement(btnAbort);
184  SetFocus(pFileListBox, false);
185  // no selection yet
186  UpdateSelection();
187 }
188 
190 {
191  delete [] pLocations;
192  if (pSelCallback) delete pSelCallback;
193  delete pKeyEnterOverride;
194  delete pKeyRefresh;
195 }
196 
198 {
199  // Add all locations
200  for (int32_t i=0; i<iLocationCount; ++i)
201  pFiller->AddEntry(pLocations[i].sName.getData(), i);
202 }
203 
204 bool C4FileSelDlg::OnLocationComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection)
205 {
206  SetCurrentLocation(idNewSelection, true);
207  // No text change by caller; text alread changed by SetCurrentLocation
208  return true;
209 }
210 
211 void C4FileSelDlg::SetPath(const char *szNewPath, bool fRefresh)
212 {
213  sPath.Copy(szNewPath);
214  if (fRefresh && IsShown()) UpdateFileList();
215 }
216 
218 {
220  // load files
221  UpdateFileList();
222 }
223 
225 {
226  if (!fOK || pSelection)
227  {
228  // allow OK only if something is sth is selected
229  Close(fOK);
230  }
231  else
232  {
233  GetScreen()->ShowErrorMessage(LoadResStr("IDS_ERR_PLEASESELECTAFILEFIRST"));
234  }
235 }
236 
238 {
239  if (fOK && pSelection && pSelCallback)
240  pSelCallback->OnFileSelected(pSelection->GetFilename());
241  // base call: Might delete dlg
242  BaseClass::OnClosed(fOK);
243 }
244 
246 {
247  // item double-click: confirms with this file in single mode; toggles selection in multi mode
248  if (IsMultiSelection())
249  {
250  ListItem *pItem = static_cast<ListItem *>(pEl);
251  pItem->UserToggleCheck();
252  }
253  else
254  UserClose(true);
255 }
256 
258 {
259  // Default list item
260  if (szFilename)
261  return new DefaultListItem(szFilename, !!GetFileMask(), IsMultiSelection(), IsItemGrayed(szFilename), GetFileItemIcon());
262  else
263  return new DefaultListItem(nullptr, false, IsMultiSelection(), false, GetFileItemIcon());
264 }
265 
266 void C4FileSelDlg::UpdateFileList()
267 {
269  // reload files
270  C4GUI::Element *pEl;
271  while ((pEl = pFileListBox->GetFirst())) delete pEl;
272  // file items
273  StdStrBuf sSearch;
274  const char *szFileMask = GetFileMask();
275  for (DirectoryIterator iter(sPath.getData()); *iter; ++iter)
276  if (!szFileMask || WildcardListMatch(szFileMask, *iter))
277  pFileListBox->AddElement(CreateListItem(*iter));
278  // none-item?
279  if (HasNoneItem())
280  {
281  pFileListBox->AddElement(CreateListItem(nullptr));
282  }
283  // list now done
285  // path into title
286  const char *szPath = sPath.getData();
287  SetTitle(*szPath ? FormatString("%s [%s]", sTitle.getData(), szPath).getData() : sTitle.getData());
288  // initial no-selection
289  UpdateSelection();
290 }
291 
293 {
294  // update selection from list
295  pSelection = static_cast<ListItem *>(pFileListBox->GetSelectedItem());
296  // OK button only available if selection
297  // SetEnabled would look a lot better here, but it doesn't exist yet :(
298  // selection preview, if enabled
299  if (pSelectionInfoBox)
300  {
301  // default empty
302  pSelectionInfoBox->ClearText(false);
303  if (!pSelection) { pSelectionInfoBox->UpdateHeight(); return; }
304  // add selection description
305  if (pSelection->GetFilename())
306  pSelectionInfoBox->AddTextLine(pSelection->GetFilename(), &::GraphicsResource.TextFont, C4GUI_MessageFontClr, true, false);
307  }
308 }
309 
310 void C4FileSelDlg::SetSelection(const char *szNewSelection, bool fFilenameOnly)
311 {
312  // check all selected definitions
313  for (ListItem *pFileItem = static_cast<ListItem *>(pFileListBox->GetFirst()); pFileItem; pFileItem = static_cast<ListItem *>(pFileItem->GetNext()))
314  {
315  const char *szFileItemFilename = pFileItem->GetFilename();
316  if (fFilenameOnly) szFileItemFilename = GetFilename(szFileItemFilename);
317  pFileItem->SetChecked(SIsModule(szNewSelection, szFileItemFilename));
318  }
319 }
320 
321 StdStrBuf C4FileSelDlg::GetSelection(const char *szFixedSelection, bool fFilenameOnly) const
322 {
323  StdStrBuf sResult;
324  if (!IsMultiSelection())
325  {
326  // get single selected file for single selection dlg
327  if (pSelection) sResult.Copy(fFilenameOnly ? GetFilename(pSelection->GetFilename()) : pSelection->GetFilename());
328  }
329  else
330  {
331  // force fixed selection first
332  if (szFixedSelection) sResult.Append(szFixedSelection);
333  // get ';'-separated list for multi selection dlg
334  for (ListItem *pFileItem = static_cast<ListItem *>(pFileListBox->GetFirst()); pFileItem; pFileItem = static_cast<ListItem *>(pFileItem->GetNext()))
335  if (pFileItem->IsChecked())
336  {
337  const char *szAppendFilename = pFileItem->GetFilename();
338  if (fFilenameOnly) szAppendFilename = GetFilename(szAppendFilename);
339  // prevent adding entries twice (especially those from the fixed selection list)
340  if (!SIsModule(sResult.getData(), szAppendFilename))
341  {
342  if (sResult.getLength()) sResult.AppendChar(';');
343  sResult.Append(szAppendFilename);
344  }
345  }
346  }
347  return sResult;
348 }
349 
350 void C4FileSelDlg::AddLocation(const char *szName, const char *szPath)
351 {
352  // add to list
353  int32_t iNewLocCount = iLocationCount+1;
354  Location *pNewLocations = new Location[iNewLocCount];
355  for (int32_t i=0; i<iLocationCount; ++i) pNewLocations[i] = pLocations[i];
356  pNewLocations[iLocationCount].sName.Copy(szName);
357  pNewLocations[iLocationCount].sPath.Copy(szPath);
358  delete [] pLocations; pLocations = pNewLocations; iLocationCount = iNewLocCount;
359  // first location? Then set path to this
360  if (iLocationCount == 1) SetPath(szPath, false);
361 }
362 
363 void C4FileSelDlg::AddCheckedLocation(const char *szName, const char *szPath)
364 {
365  // check location
366  // path must exit
367  if (!szPath || !*szPath) return;
368  if (!DirectoryExists(szPath)) return;
369  // path must not be in list yet
370  for (int32_t i=0; i<iLocationCount; ++i)
371  if (ItemIdentical(szPath, pLocations[i].sPath.getData()))
372  return;
373  // OK; add it!
374  AddLocation(szName, szPath);
375 }
376 
378 {
379  return iCurrentLocationIndex;
380 }
381 
382 void C4FileSelDlg::SetCurrentLocation(int32_t idx, bool fRefresh)
383 {
384  // safety
385  if (!Inside<int32_t>(idx, 0,iLocationCount)) return;
386  // update ComboBox-text
387  iCurrentLocationIndex = idx;
388  if (pLocationComboBox) pLocationComboBox->SetText(pLocations[idx].sName.getData());
389  // set new path
390  SetPath(pLocations[idx].sPath.getData(), fRefresh);
391 }
392 
393 
394 // ---------------------------------------------------
395 // C4PlayerSelDlg
396 
398  : C4FileSelDlg(Config.General.UserDataPath, LoadResStr("IDS_MSG_SELECTPLR"), pSelCallback)
399 {
400 }
401 
402 
403 // ---------------------------------------------------
404 // C4DefinitionSelDlg
405 
406 C4DefinitionSelDlg::C4DefinitionSelDlg(C4FileSel_BaseCB *pSelCallback, const char *szFixedSelection)
407  : C4FileSelDlg(Config.General.UserDataPath, FormatString(LoadResStr("IDS_MSG_SELECT"), LoadResStr("IDS_DLG_DEFINITIONS")).getData(), pSelCallback)
408 {
409  if (szFixedSelection) sFixedSelection.Copy(szFixedSelection);
410 }
411 
413 {
414  // base call: load file list
416  // initial selection
417  if (sFixedSelection) SetSelection(sFixedSelection.getData(), true);
418 }
419 
420 bool C4DefinitionSelDlg::IsItemGrayed(const char *szFilename) const
421 {
422  // cannot change initial selection
423  if (!sFixedSelection) return false;
424  return SIsModule(sFixedSelection.getData(), GetFilename(szFilename));
425 }
426 
428 {
429  // let the user select definitions by showing a modal selection dialog
430  C4DefinitionSelDlg *pDlg = new C4DefinitionSelDlg(nullptr, pSelection->getData());
431  bool fResult;
432  if ((fResult = pOnScreen->ShowModalDlg(pDlg, false)))
433  {
434  pSelection->Copy(pDlg->GetSelection(pSelection->getData(), true));
435  }
436  delete pDlg;
437  return fResult;
438 }
439 
440 
441 
442 // ---------------------------------------------------
443 // C4PortraitSelDlg::ListItem
444 
445 C4PortraitSelDlg::ListItem::ListItem(const char *szFilename) : C4FileSelDlg::ListItem(szFilename)
446  , fError(false), fLoaded(false)
447 {
448  CStdFont *pUseFont = &(::GraphicsResource.MiniFont);
449  // determine label text
450  StdStrBuf sDisplayLabel;
451  if (szFilename)
452  {
453  sDisplayLabel.Copy(::GetFilename(szFilename));
454  ::RemoveExtension(&sDisplayLabel);
455  }
456  else
457  {
458  sDisplayLabel.Ref(LoadResStr("IDS_MSG_NOPORTRAIT"));
459  }
460  // insert linebreaks into label text
461  int32_t iLineHgt = std::max<int32_t>(pUseFont->BreakMessage(sDisplayLabel.getData(), ImagePreviewSize-6, &sFilenameLabelText, false), 1);
462  // set size
463  SetBounds(C4Rect(0,0,ImagePreviewSize,ImagePreviewSize+iLineHgt));
464 }
465 
466 void C4PortraitSelDlg::ListItem::Load()
467 {
468  if (sFilename)
469  {
470  // safety
471  fLoaded = false;
472  // load image file
473  C4Group SrcGrp;
474  StdStrBuf sParentPath;
475  GetParentPath(sFilename.getData(), &sParentPath);
476  bool fLoadError = true;
477  if (SrcGrp.Open(sParentPath.getData()))
478  if (fctLoadedImage.Load(SrcGrp, ::GetFilename(sFilename.getData()), C4FCT_Full, C4FCT_Full, false, 0))
479  {
480  // image loaded. Can only be put into facet by main thread, because those operations aren't thread safe
481  fLoaded = true;
482  fLoadError = false;
483  }
484  SrcGrp.Close();
485  fError = fLoadError;
486  }
487 }
488 
489 void C4PortraitSelDlg::ListItem::DrawElement(C4TargetFacet &cgo)
490 {
491  // Scale down newly loaded image?
492  if (fLoaded)
493  {
494  fLoaded = false;
495  if (!fctImage.CopyFromSfcMaxSize(fctLoadedImage.GetFace(), ImagePreviewSize))
496  fError = true;
497  fctLoadedImage.GetFace().Clear();
498  fctLoadedImage.Clear();
499  }
500  // Draw picture
501  CStdFont *pUseFont = &(::GraphicsResource.MiniFont);
502  C4Facet cgoPicture(cgo.Surface, cgo.TargetX+rcBounds.x, cgo.TargetY+rcBounds.y, ImagePreviewSize, ImagePreviewSize);
503  if (fError || !sFilename)
504  {
505  C4Facet &fctNoneImg = ::GraphicsResource.fctOKCancel;
506  fctNoneImg.Draw(cgoPicture.Surface, cgoPicture.X+(cgoPicture.Wdt-fctNoneImg.Wdt)/2, cgoPicture.Y+(cgoPicture.Hgt-fctNoneImg.Hgt)/2, 1,0);
507  }
508  else
509  {
510  if (!fctImage.Surface)
511  {
512  // not loaded yet
513  pDraw->TextOut(LoadResStr("IDS_PRC_INITIALIZE"), ::GraphicsResource.MiniFont, 1.0f, cgo.Surface, cgoPicture.X+cgoPicture.Wdt/2, cgoPicture.Y+(cgoPicture.Hgt-::GraphicsResource.MiniFont.GetLineHeight())/2, C4GUI_StatusFontClr, ACenter, false);
514  }
515  else
516  {
517  fctImage.Draw(cgoPicture);
518  }
519  }
520  // draw filename
521  pDraw->TextOut(sFilenameLabelText.getData(), *pUseFont, 1.0f, cgo.Surface, cgoPicture.X+rcBounds.Wdt/2, cgoPicture.Y+cgoPicture.Hgt, C4GUI_MessageFontClr, ACenter, false);
522 }
523 
524 
525 // ---------------------------------------------------
526 // C4PortraitSelDlg::LoaderThread
527 
528 void C4PortraitSelDlg::LoaderThread::ClearLoadItems()
529 {
530  // stop thread so list can be accessed
531  Stop();
532  // clear list
533  LoadItems.clear();
534 }
535 
536 void C4PortraitSelDlg::LoaderThread::AddLoadItem(ListItem *pItem)
537 {
538  // not to be called when thread is running!
539  assert(!IsStarted());
540  LoadItems.push_back(pItem);
541 }
542 
543 void C4PortraitSelDlg::LoaderThread::Execute()
544 {
545  // list empty?
546  if (!LoadItems.size())
547  {
548  // then we're done!
549  SignalStop();
550  return;
551  }
552  // load one item at the time
553  ListItem *pLoadItem = LoadItems.front();
554  pLoadItem->Load();
555  LoadItems.erase(LoadItems.begin());
556 }
557 
558 // ---------------------------------------------------
559 // C4PortraitSelDlg
560 
562  : C4FileSelDlg(Config.General.SystemDataPath, FormatString(LoadResStr("IDS_MSG_SELECT"), LoadResStr("IDS_TYPE_PORTRAIT")).getData(), pSelCallback, false)
563 {
564  char path[_MAX_PATH+1];
565  // add common picture locations
566  StdStrBuf strLocation;
568  strLocation.Format("%s %s", C4ENGINECAPTION, LoadResStr("IDS_TEXT_USERPATH"));
569  AddLocation(strLocation.getData(), path);
571  strLocation.Format("%s %s", C4ENGINECAPTION, LoadResStr("IDS_TEXT_PROGRAMDIRECTORY"));
572  AddCheckedLocation(strLocation.getData(), path);
573 #ifdef _WIN32
574  wchar_t wpath[MAX_PATH+1];
575  if (SHGetSpecialFolderPathW(nullptr, wpath, CSIDL_PERSONAL, false)) AddCheckedLocation(LoadResStr("IDS_TEXT_MYDOCUMENTS"), StdStrBuf(wpath).getData());
576  if (SHGetSpecialFolderPathW(nullptr, wpath, CSIDL_MYPICTURES, false)) AddCheckedLocation(LoadResStr("IDS_TEXT_MYPICTURES"), StdStrBuf(wpath).getData());
577  if (SHGetSpecialFolderPathW(nullptr, wpath, CSIDL_DESKTOPDIRECTORY, false)) AddCheckedLocation(LoadResStr("IDS_TEXT_DESKTOP"), StdStrBuf(wpath).getData());
578 #endif
579 #ifdef __APPLE__
580  AddCheckedLocation(LoadResStr("IDS_TEXT_HOME"), getenv("HOME"));
581 #else
582  AddCheckedLocation(LoadResStr("IDS_TEXT_HOMEFOLDER"), getenv("HOME"));
583 #endif
584 #ifndef _WIN32
585  sprintf(path, "%s%c%s", getenv("HOME"), (char)DirectorySeparator, (const char *)"Desktop");
586  AddCheckedLocation(LoadResStr("IDS_TEXT_DESKTOP"), path);
587 #endif
588  // build dialog
589  InitElements();
590  // select last location
592 }
593 
595 {
596  // remember location
598  // inherited
600 }
601 
603 {
604  // use own list item type
605  ListItem *pNew = new ListItem(szFilename);;
606  // schedule image loading
607  ImageLoader.AddLoadItem(pNew);
608  return pNew;
609 }
610 
612 {
613  // new file list. Stop loading current
614  ImageLoader.ClearLoadItems();
615 }
616 
618 {
619 #if USE_BACKGROUND_THREAD_LOAD
620  // Begin loading images
621  ImageLoader.Start();
622 #endif
623 }
624 
626 {
627 #if !USE_BACKGROUND_THREAD_LOAD
628  // no multithreading? Workaround for image loading then...
629  static int32_t i = 0;
630  if (!(i++%10)) ImageLoader.Execute();
631 #endif
632 }
633 
635 {
636  // let the user select a portrait by showing a modal selection dialog
637  C4PortraitSelDlg *pDlg = new C4PortraitSelDlg(nullptr);
638  bool fResult;
639  if ((fResult = pOnScreen->ShowModalDlg(pDlg, false)))
640  {
641  pSelection->Take(pDlg->GetSelection(nullptr, false));
642  }
643  delete pDlg;
644  return fResult;
645 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
virtual bool HasNoneItem() const
Definition: C4FileSelDlg.h:135
virtual ListItem * CreateListItem(const char *szFilename)
StdStrBuf GetSelection(const char *szFixedSelection, bool fFilenameOnly) const
#define C4GUI_ButtonAreaHgt
Definition: C4Gui.h:113
C4Config Config
Definition: C4Config.cpp:831
char * GrabPointer()
Definition: StdBuf.h:467
int GetLineHeight() const
Definition: C4FontLoader.h:132
C4ConfigStartup Startup
Definition: C4Config.h:261
void SetComboCB(ComboBox_FillCB *pNewFillCallback)
void OnSelDblClick(class C4GUI::Element *pEl)
void TruncateBackslash(char *szFilename)
Definition: StdFile.cpp:276
#define C4GUI_ButtonHgt
Definition: C4Gui.h:111
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
void GetAll(C4Rect &rcOut)
Definition: C4Gui.cpp:1128
int32_t LastPortraitFolderIdx
Definition: C4Config.h:191
void SetDecoration(bool fDrawBG, bool fDrawFrame, ScrollBarFacets *pToGfx, bool fAutoScroll)
Definition: C4Gui.h:1752
virtual C4GUI::Icons GetFileItemIcon() const
Definition: C4FileSelDlg.h:139
#define C4GUI_MessageFontClr
Definition: C4Gui.h:43
int Wdt
Definition: C4Surface.h:67
int32_t GetInnerHeight() const
Definition: C4Gui.h:2806
bool OnLocationComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection)
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:865
virtual void UpdateSelection()
void Clear()
Definition: StdBuf.h:474
C4ConfigGeneral General
Definition: C4Config.h:252
#define sprintf
Definition: Standard.h:171
virtual bool UserToggleCheck()
Definition: C4FileSelDlg.h:73
#define C4GUI_CheckboxFontClr
Definition: C4Gui.h:48
virtual void OnShown()
Definition: C4Gui.h:2208
bool AddElement(Element *pChild, int32_t iIndent=0)
C4PlayerSelDlg(C4FileSel_BaseCB *pSelCallback)
virtual bool IsChecked() const
static bool SelectDefinitions(C4GUI::Screen *pOnScreen, StdStrBuf *pSelection)
#define C4GUI_DefDlgSmallIndent
Definition: C4Gui.h:133
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:570
void InitElements()
int32_t GetCurrentLocationIndex() const
#define C4GUI_DefButton2HSpace
Definition: C4Gui.h:116
void Close(bool fOK)
void OnLocationComboFill(C4GUI::ComboBox_FillCB *pFiller)
Definition: C4Rect.h:29
int32_t GetScreenWdt()
Definition: C4Gui.h:2821
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
virtual C4Rect & GetClientRect()
Definition: C4Gui.h:864
virtual void SetChecked(bool fChecked)
void AddElement(Element *pChild)
virtual int32_t GetFileSelColWidth() const
Definition: C4FileSelDlg.h:140
virtual bool IsItemGrayed(const char *szFilename) const
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:511
Element * GetFirst()
Definition: C4Gui.h:1571
#define C4GUI_StatusFontClr
Definition: C4Gui.h:42
#define _MAX_PATH
virtual void UpdateSize()
Definition: C4Gui.cpp:186
void SetSelectionChangeCallbackFn(BaseCallbackHandler *pToHandler)
Definition: C4Gui.h:1548
C4Rect GetContainedClientRect()
Definition: C4Gui.h:448
int32_t GetTextWidth(const char *szText, bool fCheckMarkup=true)
Definition: C4FontLoader.h:147
C4GraphicsResource GraphicsResource
#define C4GUI_DefButton2Wdt
Definition: C4Gui.h:115
void OnClosed(bool fOK)
virtual bool IsMultiSelection() const
Definition: C4FileSelDlg.h:132
void SetCurrentLocation(int32_t idx, bool fRefresh)
bool IsShown()
Definition: C4Gui.h:2147
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
Element * GetSelectedItem()
Definition: C4Gui.h:1580
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
C4FileSelDlg(const char *szRootPath, const char *szTitle, C4FileSel_BaseCB *pSelCallback, bool fInitElements=true)
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:199
void AppendChar(char cChar)
Definition: StdBuf.h:596
void AddLocation(const char *szName, const char *szPath)
virtual const char * GetFileMask() const
Definition: C4FileSelDlg.h:131
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
const int ACenter
Definition: C4Surface.h:43
C4GameControl Control
bool ShowErrorMessage(const char *szMessage)
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
C4Rect rcBounds
Definition: C4Gui.h:385
virtual bool HasExtraOptions() const
Definition: C4FileSelDlg.h:137
void Take(char *pnData)
Definition: StdBuf.h:465
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
virtual void BeginFileListUpdate()
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
Definition: C4Facet.cpp:154
void UpdateHeight()
Definition: C4Gui.h:1750
static int32_t GetDefaultHeight()
virtual bool IsItemGrayed(const char *szFilename) const
Definition: C4FileSelDlg.h:133
void AddCheckedLocation(const char *szName, const char *szPath)
virtual void OnIdle()
Dialog(int32_t iWdt, int32_t iHgt, const char *szTitle, bool fViewportDlg)
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
bool Close()
Definition: C4Group.cpp:755
C4Draw * pDraw
Definition: C4Draw.cpp:45
virtual void BeginFileListUpdate()
Definition: C4FileSelDlg.h:154
void SetSelection(const char *szNewSelection, bool fFilenameOnly)
void SetPath(const char *szNewPath, bool fRefresh=true)
int32_t GetScreenHgt()
Definition: C4Gui.h:2822
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:316
virtual void OnFileSelected(const char *szFilename)=0
std::tuple< std::string, int > BreakMessage(const char *szMsg, int iWdt, bool fCheckMarkup, float fZoom=1.0f)
Icons
Definition: C4Gui.h:637
void OnSelChange(class C4GUI::Element *pEl)
Definition: C4FileSelDlg.h:142
C4PortraitSelDlg(C4FileSel_BaseCB *pSelCallback)
bool KeyEnter()
Definition: C4Gui.h:2133
virtual void UpdateOwnPos()
void Ref(const char *pnData)
Definition: StdBuf.h:463
void SetEnabled(bool fToVal)
Definition: C4Gui.h:1479
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
float TargetX
Definition: C4Facet.h:167
virtual void EndFileListUpdate()
Definition: C4FileSelDlg.h:155
void SetFocus(Control *pCtrl, bool fByMouse)
static bool SelectPortrait(C4GUI::Screen *pOnScreen, StdStrBuf *pSelection)
virtual bool HasPreviewArea() const
Definition: C4FileSelDlg.h:136
float Hgt
Definition: C4Facet.h:120
void SetBounds(const C4Rect &rcNewBound)
Definition: C4Gui.h:446
const int ALeft
Definition: C4Surface.h:43
virtual void OnClosed(bool fOK)
virtual void OnShown()
void SetTitle(const char *szToTitle, bool fShowCloseButton=true)
virtual void OnClosed(bool fOK)
#define C4GUI_DefDlgIndent
Definition: C4Gui.h:132
virtual ~C4FileSelDlg()
void AddEntry(const char *szText, int32_t id)
void AddTextLine(const char *szText, CStdFont *pFont, DWORD dwClr, bool fDoUpdate, bool fMakeReadableOnBlack, CStdFont *pCaptionFont=nullptr)
Definition: C4Gui.h:1740
bool GetFromRight(int32_t iWdt, int32_t iHgt, C4Rect &rcOut)
Definition: C4Gui.cpp:1096
virtual void EndFileListUpdate()
size_t getLength() const
Definition: StdBuf.h:453
bool ShowModalDlg(Dialog *pDlg, bool fDestruct=true)
virtual Screen * GetScreen()
Definition: C4Gui.cpp:290
int32_t Hgt
Definition: C4Rect.h:32
virtual void UserClose(bool fOK)
C4Surface * Surface
Definition: C4Facet.h:119
bool GetFromLeft(int32_t iWdt, int32_t iHgt, C4Rect &rcOut)
Definition: C4Gui.cpp:1079
float TargetY
Definition: C4Facet.h:167
void SetText(const char *szToText)
DefaultListItem(const char *szFilename, bool fTruncateExtension, bool fCheckbox, bool fGrayed, C4GUI::Icons eIcon)
bool KeyRefresh()
Definition: C4FileSelDlg.h:144
C4DefinitionSelDlg(C4FileSel_BaseCB *pSelCallback, const char *szFixedSelection)
ListItem(const char *szFilename)
#define DirectorySeparator
const int C4FCT_Full
Definition: C4FacetEx.h:26
bool WildcardListMatch(const char *szWildcardList, const char *szString)
Definition: StdFile.cpp:361
void Copy()
Definition: StdBuf.h:475
float Wdt
Definition: C4Facet.h:120
const char * GetFilename()
Definition: C4FileSelDlg.h:67
virtual C4FileSelDlg::ListItem * CreateListItem(const char *szFilename)
virtual void AddExtraOptions(const C4Rect &rcOptionsRect)
Definition: C4FileSelDlg.h:138
bool GetFromBottom(int32_t iHgt, int32_t iWdt, C4Rect &rcOut)
Definition: C4Gui.cpp:1112
virtual void OnShown()
virtual void UpdateSize()
#define C4GUI_CheckboxDisabledFontClr
Definition: C4Gui.h:50
void ClearText(bool fDoUpdate)
Definition: C4Gui.h:1744
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277
void SetSelectionDblClickFn(BaseCallbackHandler *pToHandler)
Definition: C4Gui.h:1553