diff --git a/deps/libui/LICENSE b/deps/libui/LICENSE new file mode 100644 index 0000000000..2351d66d93 --- /dev/null +++ b/deps/libui/LICENSE @@ -0,0 +1,9 @@ +Copyright (c) 2014 Pietro Gagliardi + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(this is called the MIT License or Expat License; see http://www.opensource.org/licenses/MIT) diff --git a/deps/libui/common/CMakeLists.txt b/deps/libui/common/CMakeLists.txt new file mode 100644 index 0000000000..91d794936f --- /dev/null +++ b/deps/libui/common/CMakeLists.txt @@ -0,0 +1,16 @@ +# 3 june 2016 + +list(APPEND _LIBUI_SOURCES + common/areaevents.c + common/control.c + common/debug.c + common/matrix.c + common/shouldquit.c + common/userbugs.c +) +set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) + +list(APPEND _LIBUI_INCLUDEDIRS + common +) +set(_LIBUI_INCLUDEDIRS ${_LIBUI_INCLUDEDIRS} PARENT_SCOPE) diff --git a/deps/libui/common/control.c b/deps/libui/common/control.c index 0f4a9499be..2806646168 100644 --- a/deps/libui/common/control.c +++ b/deps/libui/common/control.c @@ -61,9 +61,11 @@ void uiControlDisable(uiControl *c) uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr) { - uiControl *c = (uiControl *) uiAlloc(size, typenamestr); - c->Signature = uiControlSignature; - c->OSSignature = OSsig; + uiControl *c; + + c = (uiControl *) uiAlloc(size, typenamestr); + c->Signature = uiControlSignature; + c->OSSignature = OSsig; c->TypeSignature = typesig; return c; } @@ -90,11 +92,10 @@ void uiControlVerifySetParent(uiControl *c, uiControl *parent) int uiControlEnabledToUser(uiControl *c) { - while (c != NULL) - { - if (!uiControlEnabled(c)) - return 0; - c = uiControlParent(c); - } + while (c != NULL) { + if (!uiControlEnabled(c)) + return 0; + c = uiControlParent(c); + } return 1; } diff --git a/deps/libui/common/controlsigs.h b/deps/libui/common/controlsigs.h index 14507e7b8d..1cbf18d5da 100644 --- a/deps/libui/common/controlsigs.h +++ b/deps/libui/common/controlsigs.h @@ -1,4 +1,4 @@ -/* 24 april 2016 */ +// 24 april 2016 #define uiAreaSignature 0x41726561 #define uiBoxSignature 0x426F784C diff --git a/deps/libui/common/matrix.c b/deps/libui/common/matrix.c index 4e44681a7b..676885d1bf 100644 --- a/deps/libui/common/matrix.c +++ b/deps/libui/common/matrix.c @@ -1,4 +1,4 @@ -/* 11 october 2015 */ +// 11 october 2015 #include #include "../ui.h" #include "uipriv.h" @@ -13,17 +13,17 @@ void uiDrawMatrixSetIdentity(uiDrawMatrix *m) m->M32 = 0; } -/* The rest of this file provides basic utilities in case the platform doesn't provide any of its own for these tasks. - * Keep these as minimal as possible. They should generally not call other fallbacks. +// The rest of this file provides basic utilities in case the platform doesn't provide any of its own for these tasks. +// Keep these as minimal as possible. They should generally not call other fallbacks. - * see https://msdn.microsoft.com/en-us/library/windows/desktop/ff684171%28v=vs.85%29.aspx#skew_transform - * TODO see if there's a way we can avoid the multiplication */ +// see https://msdn.microsoft.com/en-us/library/windows/desktop/ff684171%28v=vs.85%29.aspx#skew_transform +// TODO see if there's a way we can avoid the multiplication void fallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) { uiDrawMatrix n; uiDrawMatrixSetIdentity(&n); - /* TODO explain this */ + // TODO explain this n.M12 = tan(yamount); n.M21 = tan(xamount); n.M31 = -y * tan(xamount); @@ -37,13 +37,13 @@ void scaleCenter(double xCenter, double yCenter, double *x, double *y) *y = yCenter - (*y * yCenter); } -/* the basic algorithm is from cairo - * but it's the same algorithm as the transform point, - * just without M31 and M32 taken into account, so let's just do that instead */ +// the basic algorithm is from cairo +// but it's the same algorithm as the transform point, just without M31 and M32 taken into account, so let's just do that instead void fallbackTransformSize(uiDrawMatrix *m, double *x, double *y) { - uiDrawMatrix m2 = *m; + uiDrawMatrix m2; + m2 = *m; m2.M31 = 0; m2.M32 = 0; uiDrawMatrixTransformPoint(&m2, x, y); diff --git a/deps/libui/common/uipriv.h b/deps/libui/common/uipriv.h index e7c9940a83..d6b54e89ad 100644 --- a/deps/libui/common/uipriv.h +++ b/deps/libui/common/uipriv.h @@ -1,4 +1,4 @@ -/* 6 april 2015 */ +// 6 april 2015 #ifdef __cplusplus extern "C" { #endif @@ -13,7 +13,7 @@ extern void *uiAlloc(size_t, const char *); extern void *uiRealloc(void *, size_t, const char *); extern void uiFree(void *); -/* ugh, this was only introduced in MSVC 2015... */ +// ugh, this was only introduced in MSVC 2015... #ifdef _MSC_VER #define __func__ __FUNCTION__ #endif @@ -25,17 +25,16 @@ extern void _implbug(const char *file, const char *line, const char *func, const extern void _userbug(const char *file, const char *line, const char *func, const char *format, ...); #define userbug(...) _userbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__) -/* control.c */ +// control.c extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); -/* shouldquit.c */ +// shouldquit.c extern int shouldQuit(void); -/* areaevents.c */ +// areaevents.c typedef struct clickCounter clickCounter; - -/* you should call Reset() to zero-initialize a new instance - * it doesn't matter that all the non-count fields are zero: the first click will fail the curButton test straightaway, so it'll return 1 and set the rest of the structure accordingly */ +// you should call Reset() to zero-initialize a new instance +// it doesn't matter that all the non-count fields are zero: the first click will fail the curButton test straightaway, so it'll return 1 and set the rest of the structure accordingly struct clickCounter { int curButton; int rectX0; @@ -49,7 +48,7 @@ int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, extern void clickCounterReset(clickCounter *); extern int fromScancode(uintptr_t, uiAreaKeyEvent *); -/* matrix.c */ +// matrix.c extern void fallbackSkew(uiDrawMatrix *, double, double, double, double); extern void scaleCenter(double, double, double *, double *); extern void fallbackTransformSize(uiDrawMatrix *, double *, double *); diff --git a/deps/libui/darwin/CMakeLists.txt b/deps/libui/darwin/CMakeLists.txt new file mode 100644 index 0000000000..dbef5d432c --- /dev/null +++ b/deps/libui/darwin/CMakeLists.txt @@ -0,0 +1,79 @@ +# 3 june 2016 + +list(APPEND _LIBUI_SOURCES + darwin/alloc.m + darwin/area.m + darwin/areaevents.m + darwin/autolayout.m + darwin/box.m + darwin/button.m + darwin/checkbox.m + darwin/colorbutton.m + darwin/combobox.m + darwin/control.m + darwin/datetimepicker.m + darwin/debug.m + darwin/draw.m + darwin/drawtext.m + darwin/editablecombo.m + darwin/entry.m + darwin/fontbutton.m + darwin/form.m + darwin/grid.m + darwin/group.m + darwin/image.m + darwin/label.m + darwin/main.m + darwin/map.m + darwin/menu.m + darwin/multilineentry.m + darwin/progressbar.m + darwin/radiobuttons.m + darwin/scrollview.m + darwin/separator.m + darwin/slider.m + darwin/spinbox.m + darwin/stddialogs.m + darwin/tab.m + darwin/text.m + darwin/util.m + darwin/window.m + darwin/winmoveresize.m +) +set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) + +list(APPEND _LIBUI_INCLUDEDIRS + darwin +) +set(_LIBUI_INCLUDEDIRS _LIBUI_INCLUDEDIRS PARENT_SCOPE) + +set(_LIBUINAME libui PARENT_SCOPE) +if(NOT BUILD_SHARED_LIBS) + set(_LIBUINAME libui-temporary PARENT_SCOPE) +endif() +# thanks to Mr-Hide in irc.freenode.net/#cmake +macro(_handle_static) + set_target_properties(${_LIBUINAME} PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") + set(_aname $) + set(_lname libui-combined.list) + set(_oname libui-combined.o) + add_custom_command( + OUTPUT ${_oname} + COMMAND + nm -m ${_aname} | sed -E -n "'s/^[0-9a-f]* \\([A-Z_]+,[a-z_]+\\) external //p'" > ${_lname} + COMMAND + ld -exported_symbols_list ${_lname} -r -all_load ${_aname} -o ${_oname} + COMMENT "Removing hidden symbols") + add_library(libui STATIC ${_oname}) + # otherwise cmake won't know which linker to use + set_target_properties(libui PROPERTIES + LINKER_LANGUAGE C) + set(_aname) + set(_lname) + set(_oname) +endmacro() + +set(_LIBUI_LIBS + objc "-framework Foundation" "-framework AppKit" +PARENT_SCOPE) diff --git a/deps/libui/libui_main.c b/deps/libui/libui_main.c deleted file mode 100644 index 8c54f05849..0000000000 --- a/deps/libui/libui_main.c +++ /dev/null @@ -1,543 +0,0 @@ -/* 2 september 2015 */ -#include -#include -#include "ui.h" -#include "../../verbosity.h" - -static int onClosing(uiWindow *w, void *data) -{ - uiQuit(); - return 1; -} - -static int onShouldQuit(void *data) -{ - uiWindow *mainwin = uiWindow(data); - - uiControlDestroy(uiControl(mainwin)); - return 1; -} - -static uiControl *makeBasicControlsPage(void) -{ - uiBox *vbox; - uiBox *hbox; - uiGroup *group; - uiForm *entryForm; - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - uiBoxAppend(vbox, uiControl(hbox), 0); - - uiBoxAppend(hbox, - uiControl(uiNewButton("Button")), - 0); - uiBoxAppend(hbox, - uiControl(uiNewCheckbox("Checkbox")), - 0); - - uiBoxAppend(vbox, - uiControl(uiNewLabel("This is a label. Right now, labels can only span one line.")), - 0); - - uiBoxAppend(vbox, - uiControl(uiNewHorizontalSeparator()), - 0); - - group = uiNewGroup("Entries"); - uiGroupSetMargined(group, 1); - uiBoxAppend(vbox, uiControl(group), 1); - - entryForm = uiNewForm(); - uiFormSetPadded(entryForm, 1); - uiGroupSetChild(group, uiControl(entryForm)); - - uiFormAppend(entryForm, - "Entry", - uiControl(uiNewEntry()), - 0); - uiFormAppend(entryForm, - "Password Entry", - uiControl(uiNewPasswordEntry()), - 0); - uiFormAppend(entryForm, - "Search Entry", - uiControl(uiNewSearchEntry()), - 0); - uiFormAppend(entryForm, - "Multiline Entry", - uiControl(uiNewMultilineEntry()), - 1); - uiFormAppend(entryForm, - "Multiline Entry No Wrap", - uiControl(uiNewNonWrappingMultilineEntry()), - 1); - - return uiControl(vbox); -} - -// TODO make these not global -static uiSpinbox *spinbox; -static uiSlider *slider; -static uiProgressBar *pbar; - -static void onSpinboxChanged(uiSpinbox *s, void *data) -{ - uiSliderSetValue(slider, uiSpinboxValue(s)); - uiProgressBarSetValue(pbar, uiSpinboxValue(s)); -} - -static void onSliderChanged(uiSlider *s, void *data) -{ - uiSpinboxSetValue(spinbox, uiSliderValue(s)); - uiProgressBarSetValue(pbar, uiSliderValue(s)); -} - -static uiControl *makeNumbersPage() -{ - uiBox *hbox; - uiGroup *group; - uiBox *vbox; - uiProgressBar *ip; - uiCombobox *cbox; - uiEditableCombobox *ecbox; - uiRadioButtons *rb; - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - - group = uiNewGroup("Numbers"); - uiGroupSetMargined(group, 1); - uiBoxAppend(hbox, uiControl(group), 1); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiGroupSetChild(group, uiControl(vbox)); - - spinbox = uiNewSpinbox(0, 100); - slider = uiNewSlider(0, 100); - pbar = uiNewProgressBar(); - uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL); - uiSliderOnChanged(slider, onSliderChanged, NULL); - uiBoxAppend(vbox, uiControl(spinbox), 0); - uiBoxAppend(vbox, uiControl(slider), 0); - uiBoxAppend(vbox, uiControl(pbar), 0); - - ip = uiNewProgressBar(); - uiProgressBarSetValue(ip, -1); - uiBoxAppend(vbox, uiControl(ip), 0); - - group = uiNewGroup("Lists"); - uiGroupSetMargined(group, 1); - uiBoxAppend(hbox, uiControl(group), 1); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiGroupSetChild(group, uiControl(vbox)); - - cbox = uiNewCombobox(); - uiComboboxAppend(cbox, "Combobox Item 1"); - uiComboboxAppend(cbox, "Combobox Item 2"); - uiComboboxAppend(cbox, "Combobox Item 3"); - uiBoxAppend(vbox, uiControl(cbox), 0); - - ecbox = uiNewEditableCombobox(); - uiEditableComboboxAppend(ecbox, "Editable Item 1"); - uiEditableComboboxAppend(ecbox, "Editable Item 2"); - uiEditableComboboxAppend(ecbox, "Editable Item 3"); - uiBoxAppend(vbox, uiControl(ecbox), 0); - - rb = uiNewRadioButtons(); - uiRadioButtonsAppend(rb, "Radio Button 1"); - uiRadioButtonsAppend(rb, "Radio Button 2"); - uiRadioButtonsAppend(rb, "Radio Button 3"); - uiBoxAppend(vbox, uiControl(rb), 0); - - return uiControl(hbox); -} - -// TODO make this not global -static uiWindow *mainwin; - -static void onOpenFileClicked(uiButton *b, void *data) -{ - uiEntry *entry = uiEntry(data); - char *filename; - - filename = uiOpenFile(mainwin); - if (filename == NULL) { - uiEntrySetText(entry, "(cancelled)"); - return; - } - uiEntrySetText(entry, filename); - uiFreeText(filename); -} - -static void onSaveFileClicked(uiButton *b, void *data) -{ - uiEntry *entry = uiEntry(data); - char *filename; - - filename = uiSaveFile(mainwin); - if (filename == NULL) { - uiEntrySetText(entry, "(cancelled)"); - return; - } - uiEntrySetText(entry, filename); - uiFreeText(filename); -} - -static void onMsgBoxClicked(uiButton *b, void *data) -{ - uiMsgBox(mainwin, - "This is a normal message box.", - "More detailed information can be shown here."); -} - -static void onMsgBoxErrorClicked(uiButton *b, void *data) -{ - uiMsgBoxError(mainwin, - "This message box describes an error.", - "More detailed information can be shown here."); -} - -static uiControl *makeDataChoosersPage(void) -{ - uiBox *hbox; - uiBox *vbox; - uiGrid *grid; - uiButton *button; - uiEntry *entry; - uiGrid *msggrid; - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiBoxAppend(hbox, uiControl(vbox), 0); - - uiBoxAppend(vbox, - uiControl(uiNewDatePicker()), - 0); - uiBoxAppend(vbox, - uiControl(uiNewTimePicker()), - 0); - uiBoxAppend(vbox, - uiControl(uiNewDateTimePicker()), - 0); - - uiBoxAppend(vbox, - uiControl(uiNewFontButton()), - 0); - uiBoxAppend(vbox, - uiControl(uiNewColorButton()), - 0); - - uiBoxAppend(hbox, - uiControl(uiNewVerticalSeparator()), - 0); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiBoxAppend(hbox, uiControl(vbox), 1); - - grid = uiNewGrid(); - uiGridSetPadded(grid, 1); - uiBoxAppend(vbox, uiControl(grid), 0); - - button = uiNewButton("Open File"); - entry = uiNewEntry(); - uiEntrySetReadOnly(entry, 1); - uiButtonOnClicked(button, onOpenFileClicked, entry); - uiGridAppend(grid, uiControl(button), - 0, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(grid, uiControl(entry), - 1, 0, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - - button = uiNewButton("Save File"); - entry = uiNewEntry(); - uiEntrySetReadOnly(entry, 1); - uiButtonOnClicked(button, onSaveFileClicked, entry); - uiGridAppend(grid, uiControl(button), - 0, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(grid, uiControl(entry), - 1, 1, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - - msggrid = uiNewGrid(); - uiGridSetPadded(msggrid, 1); - uiGridAppend(grid, uiControl(msggrid), - 0, 2, 2, 1, - 0, uiAlignCenter, 0, uiAlignStart); - - button = uiNewButton("Message Box"); - uiButtonOnClicked(button, onMsgBoxClicked, NULL); - uiGridAppend(msggrid, uiControl(button), - 0, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - button = uiNewButton("Error Box"); - uiButtonOnClicked(button, onMsgBoxErrorClicked, NULL); - uiGridAppend(msggrid, uiControl(button), - 1, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - - return uiControl(hbox); -} - -int libui_main(void) -{ - uiInitOptions options; - const char *err; - uiTab *tab; - - memset(&options, 0, sizeof (uiInitOptions)); - err = uiInit(&options); - if (err != NULL) - { - RARCH_ERR("Failed to initialize uiInit\n"); - fprintf(stderr, "error initializing libui: %s", err); - uiFreeInitError(err); - return 1; - } - - mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1); - uiWindowOnClosing(mainwin, onClosing, NULL); - uiOnShouldQuit(onShouldQuit, mainwin); - - tab = uiNewTab(); - uiWindowSetChild(mainwin, uiControl(tab)); - uiWindowSetMargined(mainwin, 1); - - uiTabAppend(tab, "Basic Controls", makeBasicControlsPage()); - uiTabSetMargined(tab, 0, 1); - - uiTabAppend(tab, "Numbers and Lists", makeNumbersPage()); - uiTabSetMargined(tab, 1, 1); - - uiTabAppend(tab, "Data Choosers", makeDataChoosersPage()); - uiTabSetMargined(tab, 2, 1); - - uiControlShow(uiControl(mainwin)); - uiMain(); - return 0; -} - -#if 0 - -static void openClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - char *filename; - - filename = uiOpenFile(mainwin); - if (filename == NULL) { - uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!"); - return; - } - uiMsgBox(mainwin, "File selected", filename); - uiFreeText(filename); -} - -static void saveClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - char *filename; - - filename = uiSaveFile(mainwin); - if (filename == NULL) { - uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!"); - return; - } - uiMsgBox(mainwin, "File selected (don't worry, it's still there)", filename); - uiFreeText(filename); -} - -static uiSpinbox *spinbox; -static uiSlider *slider; -static uiProgressBar *progressbar; - -static void update(int value) -{ - uiSpinboxSetValue(spinbox, value); - uiSliderSetValue(slider, value); - uiProgressBarSetValue(progressbar, value); -} - -static void onSpinboxChanged(uiSpinbox *s, void *data) -{ - update(uiSpinboxValue(spinbox)); -} - -static void onSliderChanged(uiSlider *s, void *data) -{ - update(uiSliderValue(slider)); -} - -int main(void) -{ - uiInitOptions o; - const char *err; - uiMenu *menu; - uiMenuItem *item; - uiBox *box; - uiBox *hbox; - uiGroup *group; - uiBox *inner; - uiBox *inner2; - uiEntry *entry; - uiCombobox *cbox; - uiEditableCombobox *ecbox; - uiRadioButtons *rb; - uiTab *tab; - - memset(&o, 0, sizeof (uiInitOptions)); - err = uiInit(&o); - if (err != NULL) { - fprintf(stderr, "error initializing ui: %s\n", err); - uiFreeInitError(err); - return 1; - } - - menu = uiNewMenu("File"); - item = uiMenuAppendItem(menu, "Open"); - uiMenuItemOnClicked(item, openClicked, NULL); - item = uiMenuAppendItem(menu, "Save"); - uiMenuItemOnClicked(item, saveClicked, NULL); - item = uiMenuAppendQuitItem(menu); - uiOnShouldQuit(shouldQuit, NULL); - - menu = uiNewMenu("Edit"); - item = uiMenuAppendCheckItem(menu, "Checkable Item"); - uiMenuAppendSeparator(menu); - item = uiMenuAppendItem(menu, "Disabled Item"); - uiMenuItemDisable(item); - item = uiMenuAppendPreferencesItem(menu); - - menu = uiNewMenu("Help"); - item = uiMenuAppendItem(menu, "Help"); - item = uiMenuAppendAboutItem(menu); - - mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1); - uiWindowSetMargined(mainwin, 1); - uiWindowOnClosing(mainwin, onClosing, NULL); - - box = uiNewVerticalBox(); - uiBoxSetPadded(box, 1); - uiWindowSetChild(mainwin, uiControl(box)); - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - uiBoxAppend(box, uiControl(hbox), 1); - - group = uiNewGroup("Basic Controls"); - uiGroupSetMargined(group, 1); - uiBoxAppend(hbox, uiControl(group), 0); - - inner = uiNewVerticalBox(); - uiBoxSetPadded(inner, 1); - uiGroupSetChild(group, uiControl(inner)); - - uiBoxAppend(inner, - uiControl(uiNewButton("Button")), - 0); - uiBoxAppend(inner, - uiControl(uiNewCheckbox("Checkbox")), - 0); - entry = uiNewEntry(); - uiEntrySetText(entry, "Entry"); - uiBoxAppend(inner, - uiControl(entry), - 0); - uiBoxAppend(inner, - uiControl(uiNewLabel("Label")), - 0); - - uiBoxAppend(inner, - uiControl(uiNewHorizontalSeparator()), - 0); - - uiBoxAppend(inner, - uiControl(uiNewDatePicker()), - 0); - uiBoxAppend(inner, - uiControl(uiNewTimePicker()), - 0); - uiBoxAppend(inner, - uiControl(uiNewDateTimePicker()), - 0); - - uiBoxAppend(inner, - uiControl(uiNewFontButton()), - 0); - - uiBoxAppend(inner, - uiControl(uiNewColorButton()), - 0); - - inner2 = uiNewVerticalBox(); - uiBoxSetPadded(inner2, 1); - uiBoxAppend(hbox, uiControl(inner2), 1); - - group = uiNewGroup("Numbers"); - uiGroupSetMargined(group, 1); - uiBoxAppend(inner2, uiControl(group), 0); - - inner = uiNewVerticalBox(); - uiBoxSetPadded(inner, 1); - uiGroupSetChild(group, uiControl(inner)); - - spinbox = uiNewSpinbox(0, 100); - uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL); - uiBoxAppend(inner, uiControl(spinbox), 0); - - slider = uiNewSlider(0, 100); - uiSliderOnChanged(slider, onSliderChanged, NULL); - uiBoxAppend(inner, uiControl(slider), 0); - - progressbar = uiNewProgressBar(); - uiBoxAppend(inner, uiControl(progressbar), 0); - - group = uiNewGroup("Lists"); - uiGroupSetMargined(group, 1); - uiBoxAppend(inner2, uiControl(group), 0); - - inner = uiNewVerticalBox(); - uiBoxSetPadded(inner, 1); - uiGroupSetChild(group, uiControl(inner)); - - cbox = uiNewCombobox(); - uiComboboxAppend(cbox, "Combobox Item 1"); - uiComboboxAppend(cbox, "Combobox Item 2"); - uiComboboxAppend(cbox, "Combobox Item 3"); - uiBoxAppend(inner, uiControl(cbox), 0); - - ecbox = uiNewEditableCombobox(); - uiEditableComboboxAppend(ecbox, "Editable Item 1"); - uiEditableComboboxAppend(ecbox, "Editable Item 2"); - uiEditableComboboxAppend(ecbox, "Editable Item 3"); - uiBoxAppend(inner, uiControl(ecbox), 0); - - rb = uiNewRadioButtons(); - uiRadioButtonsAppend(rb, "Radio Button 1"); - uiRadioButtonsAppend(rb, "Radio Button 2"); - uiRadioButtonsAppend(rb, "Radio Button 3"); - uiBoxAppend(inner, uiControl(rb), 1); - - tab = uiNewTab(); - uiTabAppend(tab, "Page 1", uiControl(uiNewHorizontalBox())); - uiTabAppend(tab, "Page 2", uiControl(uiNewHorizontalBox())); - uiTabAppend(tab, "Page 3", uiControl(uiNewHorizontalBox())); - uiBoxAppend(inner2, uiControl(tab), 1); - - uiControlShow(uiControl(mainwin)); - uiMain(); - uiUninit(); - return 0; -} - -#endif diff --git a/deps/libui/ui.h b/deps/libui/ui.h index b6c9e728a8..5a2069e8a7 100644 --- a/deps/libui/ui.h +++ b/deps/libui/ui.h @@ -1,6 +1,6 @@ -/* 6 april 2015 */ +// 6 april 2015 -/* TODO add a uiVerifyControlType() function that can be used by control implementations to verify controls */ +// TODO add a uiVerifyControlType() function that can be used by control implementations to verify controls #ifndef __LIBUI_UI_H__ #define __LIBUI_UI_H__ @@ -12,7 +12,7 @@ extern "C" { #endif -/* this macro is generated by cmake */ +// this macro is generated by cmake #ifdef libui_EXPORTS #ifdef _WIN32 #define _UI_EXTERN __declspec(dllexport) extern @@ -20,19 +20,19 @@ extern "C" { #define _UI_EXTERN __attribute__((visibility("default"))) extern #endif #else -/* TODO add __declspec(dllimport) on windows, but only if not static */ +// TODO add __declspec(dllimport) on windows, but only if not static #define _UI_EXTERN extern #endif -/* C++ is really really really really really really dumb about enums, so screw that and just make them anonymous - * This has the advantage of being ABI-able should we ever need an ABI... */ +// C++ is really really really really really really dumb about enums, so screw that and just make them anonymous +// This has the advantage of being ABI-able should we ever need an ABI... #define _UI_ENUM(s) typedef unsigned int s; enum -/* This constant is provided because M_PI is nonstandard. - * This comes from Go's math.Pi, which in turn comes from http://oeis.org/A000796. */ +// This constant is provided because M_PI is nonstandard. +// This comes from Go's math.Pi, which in turn comes from http://oeis.org/A000796. #define uiPi 3.14159265358979323846264338327950288419716939937510582097494459 -/* TODO uiBool? */ +// TODO uiBool? typedef struct uiInitOptions uiInitOptions; @@ -73,7 +73,7 @@ struct uiControl { void (*Enable)(uiControl *); void (*Disable)(uiControl *); }; -/* TOOD add argument names to all arguments */ +// TOOD add argument names to all arguments #define uiControl(this) ((uiControl *) (this)) _UI_EXTERN void uiControlDestroy(uiControl *); _UI_EXTERN uintptr_t uiControlHandle(uiControl *); @@ -90,7 +90,7 @@ _UI_EXTERN void uiControlDisable(uiControl *); _UI_EXTERN uiControl *uiAllocControl(size_t n, uint32_t OSsig, uint32_t typesig, const char *typenamestr); _UI_EXTERN void uiFreeControl(uiControl *); -/* TODO make sure all controls have these */ +// TODO make sure all controls have these _UI_EXTERN void uiControlVerifySetParent(uiControl *, uiControl *); _UI_EXTERN int uiControlEnabledToUser(uiControl *); @@ -174,11 +174,10 @@ _UI_EXTERN int uiGroupMargined(uiGroup *g); _UI_EXTERN void uiGroupSetMargined(uiGroup *g, int margined); _UI_EXTERN uiGroup *uiNewGroup(const char *title); -/* spinbox/slider rules: - * setting value outside of range will automatically clamp - * initial value is minimum - * complaint if min >= max? - */ +// spinbox/slider rules: +// setting value outside of range will automatically clamp +// initial value is minimum +// complaint if min >= max? typedef struct uiSpinbox uiSpinbox; #define uiSpinbox(this) ((uiSpinbox *) (this)) @@ -218,7 +217,7 @@ typedef struct uiEditableCombobox uiEditableCombobox; _UI_EXTERN void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text); _UI_EXTERN char *uiEditableComboboxText(uiEditableCombobox *c); _UI_EXTERN void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text); -/* TODO what do we call a function that sets the currently selected item and fills the text field with it? editable comboboxes have no consistent concept of selected item */ +// TODO what do we call a function that sets the currently selected item and fills the text field with it? editable comboboxes have no consistent concept of selected item _UI_EXTERN void uiEditableComboboxOnChanged(uiEditableCombobox *c, void (*f)(uiEditableCombobox *c, void *data), void *data); _UI_EXTERN uiEditableCombobox *uiNewEditableCombobox(void); @@ -236,7 +235,7 @@ _UI_EXTERN uiDateTimePicker *uiNewDateTimePicker(void); _UI_EXTERN uiDateTimePicker *uiNewDatePicker(void); _UI_EXTERN uiDateTimePicker *uiNewTimePicker(void); -/* TODO provide a facility for entering tab stops? */ +// TODO provide a facility for entering tab stops? typedef struct uiMultilineEntry uiMultilineEntry; #define uiMultilineEntry(this) ((uiMultilineEntry *) (this)) _UI_EXTERN char *uiMultilineEntryText(uiMultilineEntry *e); @@ -292,8 +291,7 @@ struct uiAreaHandler { // TODO RTL layouts? // TODO reconcile edge and corner naming -_UI_ENUM(uiWindowResizeEdge) -{ +_UI_ENUM(uiWindowResizeEdge) { uiWindowResizeEdgeLeft, uiWindowResizeEdgeTop, uiWindowResizeEdgeRight, @@ -301,10 +299,10 @@ _UI_ENUM(uiWindowResizeEdge) uiWindowResizeEdgeTopLeft, uiWindowResizeEdgeTopRight, uiWindowResizeEdgeBottomLeft, - uiWindowResizeEdgeBottomRight - /* TODO have one for keyboard resizes? - * TODO GDK doesn't seem to have any others, including for keyboards... - * TODO way to bring up the system menu instead? */ + uiWindowResizeEdgeBottomRight, + // TODO have one for keyboard resizes? + // TODO GDK doesn't seem to have any others, including for keyboards... + // TODO way to bring up the system menu instead? }; #define uiArea(this) ((uiArea *) (this)) @@ -348,29 +346,29 @@ _UI_ENUM(uiDrawBrushType) { uiDrawBrushTypeSolid, uiDrawBrushTypeLinearGradient, uiDrawBrushTypeRadialGradient, - uiDrawBrushTypeImage + uiDrawBrushTypeImage, }; _UI_ENUM(uiDrawLineCap) { uiDrawLineCapFlat, uiDrawLineCapRound, - uiDrawLineCapSquare + uiDrawLineCapSquare, }; _UI_ENUM(uiDrawLineJoin) { uiDrawLineJoinMiter, uiDrawLineJoinRound, - uiDrawLineJoinBevel + uiDrawLineJoinBevel, }; -/* this is the default for botoh cairo and Direct2D (in the latter case, from the C++ helper functions) - * Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value - * so we're good to use it too! */ +// this is the default for botoh cairo and Direct2D (in the latter case, from the C++ helper functions) +// Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value +// so we're good to use it too! #define uiDrawDefaultMiterLimit 10.0 _UI_ENUM(uiDrawFillMode) { uiDrawFillModeWinding, - uiDrawFillModeAlternate + uiDrawFillModeAlternate, }; struct uiDrawMatrix { @@ -385,13 +383,13 @@ struct uiDrawMatrix { struct uiDrawBrush { uiDrawBrushType Type; - /* solid brushes */ + // solid brushes double R; double G; double B; double A; - /* gradient brushes */ + // gradient brushes double X0; // linear: start X, radial: start X double Y0; // linear: start Y, radial: start Y double X1; // linear: end X, radial: outer circle center X @@ -504,13 +502,13 @@ _UI_ENUM(uiDrawTextWeight) { uiDrawTextWeightBold, uiDrawTextWeightUltraBold, uiDrawTextWeightHeavy, - uiDrawTextWeightUltraHeavy + uiDrawTextWeightUltraHeavy, }; _UI_ENUM(uiDrawTextItalic) { uiDrawTextItalicNormal, uiDrawTextItalicOblique, - uiDrawTextItalicItalic + uiDrawTextItalicItalic, }; _UI_ENUM(uiDrawTextStretch) { @@ -522,7 +520,7 @@ _UI_ENUM(uiDrawTextStretch) { uiDrawTextStretchSemiExpanded, uiDrawTextStretchExpanded, uiDrawTextStretchExtraExpanded, - uiDrawTextStretchUltraExpanded + uiDrawTextStretchUltraExpanded, }; struct uiDrawTextFontDescriptor { @@ -563,10 +561,10 @@ _UI_EXTERN void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, int startChar _UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout); _UI_ENUM(uiModifiers) { - uiModifierCtrl = 1 << 0, - uiModifierAlt = 1 << 1, + uiModifierCtrl = 1 << 0, + uiModifierAlt = 1 << 1, uiModifierShift = 1 << 2, - uiModifierSuper = 1 << 3 + uiModifierSuper = 1 << 3, }; // TODO document drag captures @@ -628,7 +626,7 @@ _UI_ENUM(uiExtKey) { uiExtKeyNAdd, uiExtKeyNSubtract, uiExtKeyNMultiply, - uiExtKeyNDivide + uiExtKeyNDivide, }; struct uiAreaKeyEvent { @@ -643,9 +641,9 @@ struct uiAreaKeyEvent { typedef struct uiFontButton uiFontButton; #define uiFontButton(this) ((uiFontButton *) (this)) -/* TODO document this returns a new font */ +// TODO document this returns a new font _UI_EXTERN uiDrawTextFont *uiFontButtonFont(uiFontButton *b); -/* TOOD SetFont, mechanics */ +// TOOD SetFont, mechanics _UI_EXTERN void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data); _UI_EXTERN uiFontButton *uiNewFontButton(void); @@ -668,14 +666,14 @@ _UI_ENUM(uiAlign) { uiAlignFill, uiAlignStart, uiAlignCenter, - uiAlignEnd + uiAlignEnd, }; _UI_ENUM(uiAt) { uiAtLeading, uiAtTop, uiAtTrailing, - uiAtBottom + uiAtBottom, }; typedef struct uiGrid uiGrid; diff --git a/deps/libui/ui_unix.h b/deps/libui/ui_unix.h index 091965e7a7..5a91257bdd 100644 --- a/deps/libui/ui_unix.h +++ b/deps/libui/ui_unix.h @@ -1,4 +1,4 @@ -/* 7 april 2015 */ +// 7 april 2015 /* This file assumes that you have included and "ui.h" beforehand. It provides API-specific functions for interfacing with foreign controls on Unix systems that use GTK+ to provide their UI (currently all except Mac OS X). @@ -19,7 +19,7 @@ struct uiUnixControl { void (*SetContainer)(uiUnixControl *, GtkContainer *, gboolean); }; #define uiUnixControl(this) ((uiUnixControl *) (this)) -/* TODO document */ +// TODO document _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gboolean); #define uiUnixControlDefaultDestroy(type) \ @@ -80,7 +80,7 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool { \ gtk_widget_set_sensitive(type(c)->widget, FALSE); \ } -/* TODO this whole addedBefore stuff is a MASSIVE HACK. */ +// TODO this whole addedBefore stuff is a MASSIVE HACK. #define uiUnixControlDefaultSetContainer(type) \ static void type ## SetContainer(uiUnixControl *c, GtkContainer *container, gboolean remove) \ { \ @@ -112,7 +112,7 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool uiUnixControlDefaultDestroy(type) \ uiUnixControlAllDefaultsExceptDestroy(type) -/* TODO document */ +// TODO document #define uiUnixNewControl(type, var) \ var = type(uiUnixAllocControl(sizeof (type), type ## Signature, #type)); \ uiControl(var)->Destroy = type ## Destroy; \ @@ -127,10 +127,10 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool uiControl(var)->Enable = type ## Enable; \ uiControl(var)->Disable = type ## Disable; \ uiUnixControl(var)->SetContainer = type ## SetContainer; -/* TODO document */ +// TODO document _UI_EXTERN uiUnixControl *uiUnixAllocControl(size_t n, uint32_t typesig, const char *typenamestr); -/* uiUnixStrdupText() takes the given string and produces a copy of it suitable for being freed by uiFreeText(). */ +// uiUnixStrdupText() takes the given string and produces a copy of it suitable for being freed by uiFreeText(). _UI_EXTERN char *uiUnixStrdupText(const char *); #ifdef __cplusplus diff --git a/deps/libui/unix/CMakeLists.txt b/deps/libui/unix/CMakeLists.txt new file mode 100644 index 0000000000..9300bcb701 --- /dev/null +++ b/deps/libui/unix/CMakeLists.txt @@ -0,0 +1,85 @@ +# 3 june 2016 + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED gtk+-3.0) + +list(APPEND _LIBUI_SOURCES + unix/alloc.c + unix/area.c + unix/box.c + unix/button.c + unix/cellrendererbutton.c + unix/checkbox.c + unix/child.c + unix/colorbutton.c + unix/combobox.c + unix/control.c + unix/datetimepicker.c + unix/debug.c + unix/draw.c + unix/drawmatrix.c + unix/drawpath.c + unix/drawtext.c + unix/editablecombo.c + unix/entry.c + unix/fontbutton.c + unix/form.c + unix/future.c + unix/graphemes.c + unix/grid.c + unix/group.c + unix/image.c + unix/label.c + unix/main.c + unix/menu.c + unix/multilineentry.c + unix/progressbar.c + unix/radiobuttons.c + unix/separator.c + unix/slider.c + unix/spinbox.c + unix/stddialogs.c + unix/tab.c + unix/text.c + unix/util.c + unix/window.c +) +set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) + +list(APPEND _LIBUI_INCLUDEDIRS + unix +) +set(_LIBUI_INCLUDEDIRS _LIBUI_INCLUDEDIRS PARENT_SCOPE) + +set(_LIBUINAME libui PARENT_SCOPE) +if(NOT BUILD_SHARED_LIBS) + set(_LIBUINAME libui-temporary PARENT_SCOPE) +endif() +macro(_handle_static) + set_target_properties(${_LIBUINAME} PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") + set(_aname $) + set(_oname libui-combined.o) + add_custom_command( + OUTPUT ${_oname} + COMMAND + ld -r --whole-archive ${_aname} -o ${_oname} + COMMAND + objcopy --localize-hidden ${_oname} + COMMENT "Removing hidden symbols") + add_library(libui STATIC ${_oname}) + # otherwise cmake won't know which linker to use + set_target_properties(libui PROPERTIES + LINKER_LANGUAGE C) + set(_aname) + set(_oname) +endmacro() + +# TODO the other variables don't work? +set(_LIBUI_CFLAGS + ${GTK_CFLAGS} +PARENT_SCOPE) + +set(_LIBUI_LIBS + ${GTK_LDFLAGS} m ${CMAKE_DL_LIBS} +PARENT_SCOPE) diff --git a/deps/libui/gtk/alloc.c b/deps/libui/unix/alloc.c similarity index 89% rename from deps/libui/gtk/alloc.c rename to deps/libui/unix/alloc.c index 53f2e7aa5b..2561efa6e2 100644 --- a/deps/libui/gtk/alloc.c +++ b/deps/libui/unix/alloc.c @@ -1,4 +1,4 @@ -/* 7 april 2015 */ +// 7 april 2015 #include #include "uipriv_unix.h" @@ -20,8 +20,8 @@ void initAlloc(void) static void uninitComplain(gpointer ptr, gpointer data) { - char *str2 = NULL; - char **str = (char **)data; + char **str = (char **) data; + char *str2; if (*str == NULL) *str = g_strdup_printf(""); @@ -34,12 +34,10 @@ void uninitAlloc(void) { char *str = NULL; - if (allocations->len == 0) - { - g_ptr_array_free(allocations, TRUE); - return; - } - + if (allocations->len == 0) { + g_ptr_array_free(allocations, TRUE); + return; + } g_ptr_array_foreach(allocations, uninitComplain, &str); userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", str); g_free(str); @@ -47,8 +45,9 @@ void uninitAlloc(void) void *uiAlloc(size_t size, const char *type) { - void *out = g_malloc0(EXTRA + size); + void *out; + out = g_malloc0(EXTRA + size); *SIZE(out) = size; *TYPE(out) = type; g_ptr_array_add(allocations, out); diff --git a/deps/libui/gtk/area.c b/deps/libui/unix/area.c similarity index 70% rename from deps/libui/gtk/area.c rename to deps/libui/unix/area.c index 11089bbb9a..c46447cc33 100644 --- a/deps/libui/gtk/area.c +++ b/deps/libui/unix/area.c @@ -114,10 +114,10 @@ static void loadAreaSize(uiArea *a, double *width, double *height) static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) { + areaWidget *aw = areaWidget(w); + uiArea *a = aw->a; uiAreaDrawParams dp; double clipX0, clipY0, clipX1, clipY1; - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; dp.Context = newContext(cr); @@ -129,30 +129,25 @@ static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) dp.ClipWidth = clipX1 - clipX0; dp.ClipHeight = clipY1 - clipY0; - /* no need to save or restore the graphics state - * to reset transformations; GTK+ does that for us */ + // no need to save or restore the graphics state to reset transformations; GTK+ does that for us (*(a->ah->Draw))(a->ah, a, &dp); freeContext(dp.Context); return FALSE; } -/* to do this properly for scrolling areas, we need to - * - return the same value for min and nat - * - call gtk_widget_queue_resize() when the size changes - * thanks to Company in irc.gimp.net/#gtk+ */ -static void areaWidget_get_preferred_height(GtkWidget *w, - gint *min, gint *nat) +// to do this properly for scrolling areas, we need to +// - return the same value for min and nat +// - call gtk_widget_queue_resize() when the size changes +// thanks to Company in irc.gimp.net/#gtk+ +static void areaWidget_get_preferred_height(GtkWidget *w, gint *min, gint *nat) { areaWidget *aw = areaWidget(w); uiArea *a = aw->a; // always chain up just in case - GTK_WIDGET_CLASS(areaWidget_parent_class)-> - get_preferred_height(w, min, nat); - - if (a->scrolling) - { + GTK_WIDGET_CLASS(areaWidget_parent_class)->get_preferred_height(w, min, nat); + if (a->scrolling) { *min = a->scrollHeight; *nat = a->scrollHeight; } @@ -163,54 +158,51 @@ static void areaWidget_get_preferred_width(GtkWidget *w, gint *min, gint *nat) areaWidget *aw = areaWidget(w); uiArea *a = aw->a; - /* always chain up just in case */ + // always chain up just in case GTK_WIDGET_CLASS(areaWidget_parent_class)->get_preferred_width(w, min, nat); - if (a->scrolling) - { - *min = a->scrollWidth; - *nat = a->scrollWidth; - } + if (a->scrolling) { + *min = a->scrollWidth; + *nat = a->scrollWidth; + } } static guint translateModifiers(guint state, GdkWindow *window) { - GdkModifierType statetype; + GdkModifierType statetype; - /* GDK doesn't initialize the modifier flags fully; we have to - * explicitly tell it to (thanks to Daniel_S and daniels - * (two different people) in irc.gimp.net/#gtk+) */ - statetype = state; - gdk_keymap_add_virtual_modifiers( - gdk_keymap_get_for_display(gdk_window_get_display(window)), - &statetype); - return statetype; + // GDK doesn't initialize the modifier flags fully; we have to explicitly tell it to (thanks to Daniel_S and daniels (two different people) in irc.gimp.net/#gtk+) + statetype = state; + gdk_keymap_add_virtual_modifiers( + gdk_keymap_get_for_display(gdk_window_get_display(window)), + &statetype); + return statetype; } static uiModifiers toModifiers(guint state) { - uiModifiers m = 0; + uiModifiers m; - if ((state & GDK_CONTROL_MASK) != 0) - m |= uiModifierCtrl; - if ((state & GDK_META_MASK) != 0) - m |= uiModifierAlt; - /* GTK+ itself requires this to be Alt (just read through gtkaccelgroup.c) */ - if ((state & GDK_MOD1_MASK) != 0) - m |= uiModifierAlt; - if ((state & GDK_SHIFT_MASK) != 0) - m |= uiModifierShift; - if ((state & GDK_SUPER_MASK) != 0) - m |= uiModifierSuper; - return m; + m = 0; + if ((state & GDK_CONTROL_MASK) != 0) + m |= uiModifierCtrl; + if ((state & GDK_META_MASK) != 0) + m |= uiModifierAlt; + if ((state & GDK_MOD1_MASK) != 0) // GTK+ itself requires this to be Alt (just read through gtkaccelgroup.c) + m |= uiModifierAlt; + if ((state & GDK_SHIFT_MASK) != 0) + m |= uiModifierShift; + if ((state & GDK_SUPER_MASK) != 0) + m |= uiModifierSuper; + return m; } -/* capture on drag is done automatically on GTK+ */ +// capture on drag is done automatically on GTK+ static void finishMouseEvent(uiArea *a, uiAreaMouseEvent *me, guint mb, gdouble x, gdouble y, guint state, GdkWindow *window) { - /* on GTK+, mouse buttons 4-7 are for scrolling; if we got here, that's a mistake */ + // on GTK+, mouse buttons 4-7 are for scrolling; if we got here, that's a mistake if (mb >= 4 && mb <= 7) return; - /* if the button ID >= 8, continue counting from 4, as in the MouseEvent spec */ + // if the button ID >= 8, continue counting from 4, as in the MouseEvent spec if (me->Down >= 8) me->Down -= 4; if (me->Up >= 8) @@ -219,7 +211,7 @@ static void finishMouseEvent(uiArea *a, uiAreaMouseEvent *me, guint mb, gdouble state = translateModifiers(state, window); me->Modifiers = toModifiers(state); - /* the mb != # checks exclude the Up/Down button from Held */ + // the mb != # checks exclude the Up/Down button from Held me->Held1To64 = 0; if (mb != 1 && (state & GDK_BUTTON1_MASK) != 0) me->Held1To64 |= 1 << 0; @@ -227,19 +219,12 @@ static void finishMouseEvent(uiArea *a, uiAreaMouseEvent *me, guint mb, gdouble me->Held1To64 |= 1 << 1; if (mb != 3 && (state & GDK_BUTTON3_MASK) != 0) me->Held1To64 |= 1 << 2; + // don't check GDK_BUTTON4_MASK or GDK_BUTTON5_MASK because those are for the scrolling buttons mentioned above + // GDK expressly does not support any more buttons in the GdkModifierType; see https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkdevice-xi2.c#n763 (thanks mclasen in irc.gimp.net/#gtk+) - /* don't check GDK_BUTTON4_MASK or GDK_BUTTON5_MASK because those - * are for the scrolling buttons mentioned above - * - * GDK expressly does not support any more buttons in the - * GdkModifierType; see - * https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkdevice-xi2.c#n763 - * (thanks mclasen in irc.gimp.net/#gtk+) - */ - - /* these are already in drawing space coordinates - * the size of drawing space has the same value as the widget allocation - * thanks to tristan in irc.gimp.net/#gtk+ */ + // these are already in drawing space coordinates + // the size of drawing space has the same value as the widget allocation + // thanks to tristan in irc.gimp.net/#gtk+ me->X = x; me->Y = y; @@ -250,43 +235,37 @@ static void finishMouseEvent(uiArea *a, uiAreaMouseEvent *me, guint mb, gdouble static gboolean areaWidget_button_press_event(GtkWidget *w, GdkEventButton *e) { + areaWidget *aw = areaWidget(w); + uiArea *a = aw->a; gint maxTime, maxDistance; + GtkSettings *settings; uiAreaMouseEvent me; - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - GtkSettings *settings = NULL; - /* clicking doesn't automatically transfer keyboard focus; - * we must do so manually (thanks tristan in irc.gimp.net/#gtk+) */ + // clicking doesn't automatically transfer keyboard focus; we must do so manually (thanks tristan in irc.gimp.net/#gtk+) gtk_widget_grab_focus(w); - /* we handle multiple clicks ourselves here, - * in the same way as we do on Windows */ - - /* ignore GDK's generated double-clicks and beyond */ + // we handle multiple clicks ourselves here, in the same way as we do on Windows if (e->type != GDK_BUTTON_PRESS) + // ignore GDK's generated double-clicks and beyond return GDK_EVENT_PROPAGATE; - settings = gtk_widget_get_settings(w); - g_object_get(settings, "gtk-double-click-time", &maxTime, "gtk-double-click-distance", &maxDistance, NULL); - - /* don't unref settings; it's transfer-none (thanks gregier in irc.gimp.net/#gtk+) - * e->time is guint32 - * e->x and e->y are floating-point; just make them 32-bit integers - * maxTime and maxDistance... are gint, which *should* fit, hopefully... */ + // don't unref settings; it's transfer-none (thanks gregier in irc.gimp.net/#gtk+) + // e->time is guint32 + // e->x and e->y are floating-point; just make them 32-bit integers + // maxTime and maxDistance... are gint, which *should* fit, hopefully... me.Count = clickCounterClick(a->cc, me.Down, e->x, e->y, e->time, maxTime, maxDistance, maxDistance); me.Down = e->button; - me.Up = 0; + me.Up = 0; - /* and set things up for window drags */ + // and set things up for window drags a->dragevent = e; finishMouseEvent(a, &me, e->button, e->x, e->y, e->state, e->window); a->dragevent = NULL; @@ -295,37 +274,32 @@ static gboolean areaWidget_button_press_event(GtkWidget *w, GdkEventButton *e) static gboolean areaWidget_button_release_event(GtkWidget *w, GdkEventButton *e) { - uiAreaMouseEvent me; - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; + areaWidget *aw = areaWidget(w); + uiArea *a = aw->a; + uiAreaMouseEvent me; - me.Down = 0; - me.Up = e->button; - me.Count = 0; - finishMouseEvent(a, &me, e->button, e->x, e->y, e->state, e->window); - return GDK_EVENT_PROPAGATE; + me.Down = 0; + me.Up = e->button; + me.Count = 0; + finishMouseEvent(a, &me, e->button, e->x, e->y, e->state, e->window); + return GDK_EVENT_PROPAGATE; } static gboolean areaWidget_motion_notify_event(GtkWidget *w, GdkEventMotion *e) { - uiAreaMouseEvent me; areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; + uiArea *a = aw->a; + uiAreaMouseEvent me; - me.Down = 0; - me.Up = 0; - me.Count = 0; + me.Down = 0; + me.Up = 0; + me.Count = 0; finishMouseEvent(a, &me, 0, e->x, e->y, e->state, e->window); return GDK_EVENT_PROPAGATE; } -/* we want switching away from the control to reset the double-click counter, - * like with WM_ACTIVATE on Windows - * - * according to tristan in irc.gimp.net/#gtk+, doing this on both - * enter-notify-event and leave-notify-event is correct (and it seems to be - * true in my own tests; plus the events DO get sent when switching programs - * with the keyboard (just pointing that out)) */ +// we want switching away from the control to reset the double-click counter, like with WM_ACTIVATE on Windows +// according to tristan in irc.gimp.net/#gtk+, doing this on both enter-notify-event and leave-notify-event is correct (and it seems to be true in my own tests; plus the events DO get sent when switching programs with the keyboard (just pointing that out)) static gboolean onCrossing(areaWidget *aw, int left) { uiArea *a = aw->a; @@ -345,15 +319,11 @@ static gboolean areaWidget_leave_notify_event(GtkWidget *w, GdkEventCrossing *e) return onCrossing(areaWidget(w), 1); } -/* note: there is no equivalent to WM_CAPTURECHANGED on GTK+; there literally - * is no way to break a grab like that (at least not on X11 and Wayland) - * - * even if I invoke the task switcher and switch processes, the mouse grab will - * still be held until I let go of all buttons - * therefore, no DragBroken() - * - * we use GDK_KEY_Print as a sentinel because libui will never support the print screen key; that key belongs to the user - */ +// note: there is no equivalent to WM_CAPTURECHANGED on GTK+; there literally is no way to break a grab like that (at least not on X11 and Wayland) +// even if I invoke the task switcher and switch processes, the mouse grab will still be held until I let go of all buttons +// therefore, no DragBroken() + +// we use GDK_KEY_Print as a sentinel because libui will never support the print screen key; that key belongs to the user static const struct { guint keyval; @@ -382,7 +352,7 @@ static const struct { { GDK_KEY_F10, uiExtKeyF10 }, { GDK_KEY_F11, uiExtKeyF11 }, { GDK_KEY_F12, uiExtKeyF12 }, - /* numpad numeric keys and . are handled in events.c */ + // numpad numeric keys and . are handled in events.c { GDK_KEY_KP_Enter, uiExtKeyNEnter }, { GDK_KEY_KP_Add, uiExtKeyNAdd }, { GDK_KEY_KP_Subtract, uiExtKeyNSubtract }, @@ -424,25 +394,23 @@ static int areaKeyEvent(uiArea *a, int up, GdkEventKey *e) ke.Up = up; for (i = 0; extKeys[i].keyval != GDK_KEY_Print; i++) - if (extKeys[i].keyval == e->keyval) - { + if (extKeys[i].keyval == e->keyval) { ke.ExtKey = extKeys[i].extkey; goto keyFound; } for (i = 0; modKeys[i].keyval != GDK_KEY_Print; i++) - if (modKeys[i].keyval == e->keyval) - { - ke.Modifier = modKeys[i].mod; - /* don't include the modifier in ke.Modifiers */ - ke.Modifiers &= ~ke.Modifier; - goto keyFound; - } + if (modKeys[i].keyval == e->keyval) { + ke.Modifier = modKeys[i].mod; + // don't include the modifier in ke.Modifiers + ke.Modifiers &= ~ke.Modifier; + goto keyFound; + } if (fromScancode(e->hardware_keycode - 8, &ke)) goto keyFound; - /* no supported key found; treat as unhandled */ + // no supported key found; treat as unhandled return 0; keyFound: @@ -452,7 +420,7 @@ keyFound: static gboolean areaWidget_key_press_event(GtkWidget *w, GdkEventKey *e) { areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; + uiArea *a = aw->a; if (areaKeyEvent(a, 0, e)) return GDK_EVENT_STOP; @@ -478,16 +446,15 @@ static GParamSpec *pspecArea; static void areaWidget_set_property(GObject *obj, guint prop, const GValue *value, GParamSpec *pspec) { - areaWidget *aw = areaWidget(obj); + areaWidget *aw = areaWidget(obj); - switch (prop) - { - case pArea: - aw->a = (uiArea *) g_value_get_pointer(value); - aw->a->cc = &(aw->cc); - return; - } - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, pspec); + switch (prop) { + case pArea: + aw->a = (uiArea *) g_value_get_pointer(value); + aw->a->cc = &(aw->cc); + return; + } + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, pspec); } static void areaWidget_get_property(GObject *obj, guint prop, GValue *value, GParamSpec *pspec) @@ -541,8 +508,8 @@ void uiAreaQueueRedrawAll(uiArea *a) void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height) { - /* TODO - * TODO adjust adjustments and find source for that */ + // TODO + // TODO adjust adjustments and find source for that } void uiAreaBeginUserWindowMove(uiArea *a) @@ -551,23 +518,25 @@ void uiAreaBeginUserWindowMove(uiArea *a) if (a->dragevent == NULL) userbug("cannot call uiAreaBeginUserWindowMove() outside of a Mouse() with Down != 0"); - /* TODO don't we have a libui function for this? did I scrap it? - * TODO widget or areaWidget? */ + // TODO don't we have a libui function for this? did I scrap it? + // TODO widget or areaWidget? toplevel = gtk_widget_get_toplevel(a->widget); - // TODO - if (toplevel == NULL) + if (toplevel == NULL) { + // TODO return; - /* the docs say to do this */ - - /* TODO */ - if (!gtk_widget_is_toplevel(toplevel)) + } + // the docs say to do this + if (!gtk_widget_is_toplevel(toplevel)) { + // TODO return; - /* TODO */ - if (!GTK_IS_WINDOW(toplevel)) + } + if (!GTK_IS_WINDOW(toplevel)) { + // TODO return; + } gtk_window_begin_move_drag(GTK_WINDOW(toplevel), a->dragevent->button, - a->dragevent->x_root, /* TODO are these correct? */ + a->dragevent->x_root, // TODO are these correct? a->dragevent->y_root, a->dragevent->time); } @@ -589,25 +558,26 @@ void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge) if (a->dragevent == NULL) userbug("cannot call uiAreaBeginUserWindowResize() outside of a Mouse() with Down != 0"); - /* TODO don't we have a libui function for this? did I scrap it? - * TODO widget or areaWidget? */ + // TODO don't we have a libui function for this? did I scrap it? + // TODO widget or areaWidget? toplevel = gtk_widget_get_toplevel(a->widget); - - /* TODO */ - if (toplevel == NULL) + if (toplevel == NULL) { + // TODO return; - /* the docs say to do this */ - - /* TODO */ - if (!gtk_widget_is_toplevel(toplevel)) + } + // the docs say to do this + if (!gtk_widget_is_toplevel(toplevel)) { + // TODO return; - /* TODO */ - if (!GTK_IS_WINDOW(toplevel)) + } + if (!GTK_IS_WINDOW(toplevel)) { + // TODO return; + } gtk_window_begin_resize_drag(GTK_WINDOW(toplevel), edges[edge], a->dragevent->button, - a->dragevent->x_root, /* TODO are these correct? */ + a->dragevent->x_root, // TODO are these correct? a->dragevent->y_root, a->dragevent->time); } @@ -656,8 +626,7 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height) a->widget = a->swidget; gtk_container_add(a->scontainer, a->areaWidget); - /* and make the area visible; only the scrolled - * window's visibility is controlled by libui */ + // and make the area visible; only the scrolled window's visibility is controlled by libui gtk_widget_show(a->areaWidget); return a; diff --git a/deps/libui/gtk/box.c b/deps/libui/unix/box.c similarity index 76% rename from deps/libui/gtk/box.c rename to deps/libui/unix/box.c index 6c716930e7..23fb7f7c6c 100644 --- a/deps/libui/gtk/box.c +++ b/deps/libui/unix/box.c @@ -1,26 +1,24 @@ // 7 april 2015 #include "uipriv_unix.h" -struct boxChild -{ - uiControl *c; - int stretchy; - gboolean oldhexpand; - GtkAlign oldhalign; - gboolean oldvexpand; - GtkAlign oldvalign; +struct boxChild { + uiControl *c; + int stretchy; + gboolean oldhexpand; + GtkAlign oldhalign; + gboolean oldvexpand; + GtkAlign oldvalign; }; -struct uiBox -{ - uiUnixControl c; - GtkWidget *widget; - GtkContainer *container; - GtkBox *box; - GArray *controls; - int vertical; - int padded; - GtkSizeGroup *stretchygroup; /* ensures all stretchy controls have the same size */ +struct uiBox { + uiUnixControl c; + GtkWidget *widget; + GtkContainer *container; + GtkBox *box; + GArray *controls; + int vertical; + int padded; + GtkSizeGroup *stretchygroup; // ensures all stretchy controls have the same size }; uiUnixControlAllDefaultsExceptDestroy(uiBox) @@ -33,19 +31,18 @@ static void uiBoxDestroy(uiControl *c) struct boxChild *bc; guint i; - /* kill the size group */ + // kill the size group g_object_unref(b->stretchygroup); - /* free all controls */ - for (i = 0; i < b->controls->len; i++) - { - bc = ctrl(b, i); - uiControlSetParent(bc->c, NULL); - /* and make sure the widget itself stays alive */ - uiUnixControlSetContainer(uiUnixControl(bc->c), b->container, TRUE); - uiControlDestroy(bc->c); - } + // free all controls + for (i = 0; i < b->controls->len; i++) { + bc = ctrl(b, i); + uiControlSetParent(bc->c, NULL); + // and make sure the widget itself stays alive + uiUnixControlSetContainer(uiUnixControl(bc->c), b->container, TRUE); + uiControlDestroy(bc->c); + } g_array_free(b->controls, TRUE); - /* and then ourselves */ + // and then ourselves g_object_unref(b->widget); uiFreeControl(uiControl(b)); } @@ -53,7 +50,7 @@ static void uiBoxDestroy(uiControl *c) void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) { struct boxChild bc; - GtkWidget *widget = NULL; + GtkWidget *widget; bc.c = c; bc.stretchy = stretchy; @@ -77,7 +74,7 @@ void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) gtk_widget_set_vexpand(widget, FALSE); else gtk_widget_set_hexpand(widget, FALSE); - /* and make them fill the opposite direction */ + // and make them fill the opposite direction if (b->vertical) { gtk_widget_set_hexpand(widget, TRUE); gtk_widget_set_halign(widget, GTK_ALIGN_FILL); @@ -93,8 +90,11 @@ void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) void uiBoxDelete(uiBox *b, int index) { - struct boxChild *bc = ctrl(b, index); - GtkWidget *widget = GTK_WIDGET(uiControlHandle(bc->c)); + struct boxChild *bc; + GtkWidget *widget; + + bc = ctrl(b, index); + widget = GTK_WIDGET(uiControlHandle(bc->c)); uiControlSetParent(bc->c, NULL); uiUnixControlSetContainer(uiUnixControl(bc->c), b->container, TRUE); diff --git a/deps/libui/gtk/button.c b/deps/libui/unix/button.c similarity index 94% rename from deps/libui/gtk/button.c rename to deps/libui/unix/button.c index 44266ee893..00a87f491a 100644 --- a/deps/libui/gtk/button.c +++ b/deps/libui/unix/button.c @@ -1,8 +1,7 @@ // 10 june 2015 #include "uipriv_unix.h" -struct uiButton -{ +struct uiButton { uiUnixControl c; GtkWidget *widget; GtkButton *button; @@ -21,7 +20,7 @@ static void onClicked(GtkButton *button, gpointer data) static void defaultOnClicked(uiButton *b, void *data) { - /* do nothing */ + // do nothing } char *uiButtonText(uiButton *b) @@ -36,7 +35,7 @@ void uiButtonSetText(uiButton *b, const char *text) void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data) { - b->onClicked = f; + b->onClicked = f; b->onClickedData = data; } diff --git a/deps/libui/gtk/cellrendererbutton.c b/deps/libui/unix/cellrendererbutton.c similarity index 100% rename from deps/libui/gtk/cellrendererbutton.c rename to deps/libui/unix/cellrendererbutton.c diff --git a/deps/libui/gtk/checkbox.c b/deps/libui/unix/checkbox.c similarity index 100% rename from deps/libui/gtk/checkbox.c rename to deps/libui/unix/checkbox.c diff --git a/deps/libui/gtk/child.c b/deps/libui/unix/child.c similarity index 94% rename from deps/libui/gtk/child.c rename to deps/libui/unix/child.c index 636495b97b..b4a0967740 100644 --- a/deps/libui/gtk/child.c +++ b/deps/libui/unix/child.c @@ -28,7 +28,7 @@ struct child { struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parentContainer) { - struct child *c = NULL; + struct child *c; if (child == NULL) return NULL; @@ -51,8 +51,8 @@ struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parent struct child *newChildWithBox(uiControl *child, uiControl *parent, GtkContainer *parentContainer, int margined) { - struct child *c = NULL; - GtkWidget *box = NULL; + struct child *c; + GtkWidget *box; if (child == NULL) return NULL; @@ -87,11 +87,11 @@ void childRemove(struct child *c) void childDestroy(struct child *c) { - uiControl *child = NULL; + uiControl *child; - child = c->c; - childRemove(c); - uiControlDestroy(child); + child = c->c; + childRemove(c); + uiControlDestroy(child); } GtkWidget *childWidget(struct child *c) diff --git a/deps/libui/gtk/colorbutton.c b/deps/libui/unix/colorbutton.c similarity index 100% rename from deps/libui/gtk/colorbutton.c rename to deps/libui/unix/colorbutton.c diff --git a/deps/libui/gtk/combobox.c b/deps/libui/unix/combobox.c similarity index 100% rename from deps/libui/gtk/combobox.c rename to deps/libui/unix/combobox.c diff --git a/deps/libui/gtk/control.c b/deps/libui/unix/control.c similarity index 100% rename from deps/libui/gtk/control.c rename to deps/libui/unix/control.c diff --git a/deps/libui/gtk/datetimepicker.c b/deps/libui/unix/datetimepicker.c similarity index 81% rename from deps/libui/gtk/datetimepicker.c rename to deps/libui/unix/datetimepicker.c index 315150a3d9..19689a2205 100644 --- a/deps/libui/gtk/datetimepicker.c +++ b/deps/libui/unix/datetimepicker.c @@ -14,31 +14,30 @@ typedef struct dateTimePickerWidget dateTimePickerWidget; typedef struct dateTimePickerWidgetClass dateTimePickerWidgetClass; -struct dateTimePickerWidget -{ - GtkToggleButton parent_instance; +struct dateTimePickerWidget { + GtkToggleButton parent_instance; - gulong toggledSignal; + gulong toggledSignal; - gboolean hasTime; - gboolean hasDate; + gboolean hasTime; + gboolean hasDate; - GtkWidget *window; - GtkWidget *box; - GtkWidget *calendar; - GtkWidget *timebox; - GtkWidget *hours; - GtkWidget *minutes; - GtkWidget *seconds; - GtkWidget *ampm; + GtkWidget *window; + GtkWidget *box; + GtkWidget *calendar; + GtkWidget *timebox; + GtkWidget *hours; + GtkWidget *minutes; + GtkWidget *seconds; + GtkWidget *ampm; - gulong hoursBlock; - gulong minutesBlock; - gulong secondsBlock; - gulong ampmBlock; + gulong hoursBlock; + gulong minutesBlock; + gulong secondsBlock; + gulong ampmBlock; - GdkDevice *keyboard; - GdkDevice *mouse; + GdkDevice *keyboard; + GdkDevice *mouse; }; struct dateTimePickerWidgetClass { @@ -49,7 +48,9 @@ G_DEFINE_TYPE(dateTimePickerWidget, dateTimePickerWidget, GTK_TYPE_TOGGLE_BUTTON static int realSpinValue(GtkSpinButton *spinButton) { - GtkAdjustment *adj = gtk_spin_button_get_adjustment(spinButton); + GtkAdjustment *adj; + + adj = gtk_spin_button_get_adjustment(spinButton); return (int) gtk_adjustment_get_value(adj); } @@ -69,14 +70,11 @@ static GDateTime *selected(dateTimePickerWidget *d) guint year = 1970, month = 1, day = 1; guint hour = 0, minute = 0, second = 0; - if (d->hasDate) - { + if (d->hasDate) { gtk_calendar_get_date(GTK_CALENDAR(d->calendar), &year, &month, &day); - month++; /* GtkCalendar/GDateTime differences */ + month++; // GtkCalendar/GDateTime differences } - - if (d->hasTime) - { + if (d->hasTime) { hour = realSpinValue(GTK_SPIN_BUTTON(d->hours)); if (realSpinValue(GTK_SPIN_BUTTON(d->ampm)) != 0) hour += 12; @@ -88,22 +86,21 @@ static GDateTime *selected(dateTimePickerWidget *d) static void setLabel(dateTimePickerWidget *d) { - char *fmt = NULL; - char *msg = NULL; - GDateTime *dt = selected(d); - gboolean free = FALSE; + GDateTime *dt; + char *fmt; + char *msg; + gboolean free; - if (d->hasDate && d->hasTime) - { - /* don't use D_T_FMT; that's too verbose */ - fmt = g_strdup_printf("%s %s", nl_langinfo(D_FMT), nl_langinfo(T_FMT)); + dt = selected(d); + free = FALSE; + if (d->hasDate && d->hasTime) { + // don't use D_T_FMT; that's too verbose + fmt = g_strdup_printf("%s %s", nl_langinfo(D_FMT), nl_langinfo(T_FMT)); free = TRUE; - } - else if (d->hasDate) - fmt = nl_langinfo(D_FMT); + } else if (d->hasDate) + fmt = nl_langinfo(D_FMT); else fmt = nl_langinfo(T_FMT); - msg = g_date_time_format(dt, fmt); gtk_button_set_label(GTK_BUTTON(d), msg); g_free(msg); @@ -147,31 +144,32 @@ static void hidePopup(dateTimePickerWidget *d) // this consolidates a good chunk of what GtkComboBox does static gboolean startGrab(dateTimePickerWidget *d) { + GdkDevice *dev; guint32 time; - GdkWindow *window = NULL; - GdkDevice *keyboard = NULL; - GdkDevice *mouse = NULL; - GdkDevice *dev = gtk_get_current_event_device(); + GdkWindow *window; + GdkDevice *keyboard, *mouse; - if (dev == NULL) - { + dev = gtk_get_current_event_device(); + if (dev == NULL) { // this is what GtkComboBox does // since no device was set, just use the first available "master device" - GdkDisplay *disp = gtk_widget_get_display(GTK_WIDGET(d)); - GdkDeviceManager *dm = gdk_display_get_device_manager(disp); - GList *list = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_MASTER); + GdkDisplay *disp; + GdkDeviceManager *dm; + GList *list; + + disp = gtk_widget_get_display(GTK_WIDGET(d)); + dm = gdk_display_get_device_manager(disp); + list = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_MASTER); dev = (GdkDevice *) (list->data); g_list_free(list); } - time = gtk_get_current_event_time(); + time = gtk_get_current_event_time(); keyboard = dev; - mouse = gdk_device_get_associated_device(dev); - - if (gdk_device_get_source(dev) != GDK_SOURCE_KEYBOARD) - { - dev = mouse; - mouse = keyboard; + mouse = gdk_device_get_associated_device(dev); + if (gdk_device_get_source(dev) != GDK_SOURCE_KEYBOARD) { + dev = mouse; + mouse = keyboard; keyboard = dev; } @@ -198,7 +196,7 @@ static gboolean startGrab(dateTimePickerWidget *d) return TRUE; } -/* based on gtk_combo_box_list_position() in the GTK+ source code */ +// based on gtk_combo_box_list_position() in the GTK+ source code static void allocationToScreen(dateTimePickerWidget *d, gint *x, gint *y) { GdkWindow *window; @@ -279,17 +277,15 @@ static gboolean grabBroken(GtkWidget *w, GdkEventGrabBroken *e, gpointer data) static gboolean buttonReleased(GtkWidget *w, GdkEventButton *e, gpointer data) { + dateTimePickerWidget *d = dateTimePickerWidget(data); int winx, winy; GtkAllocation wina; gboolean in; - dateTimePickerWidget *d = dateTimePickerWidget(data); gtk_widget_get_allocation(d->window, &wina); winx = 0; winy = 0; - - if (!gtk_widget_get_has_window(d->window)) - { + if (!gtk_widget_get_has_window(d->window)) { winx = wina.x; winy = wina.y; } @@ -311,9 +307,11 @@ static gboolean buttonReleased(GtkWidget *w, GdkEventButton *e, gpointer data) static gint hoursSpinboxInput(GtkSpinButton *sb, gpointer ptr, gpointer data) { double *out = (double *) ptr; - const gchar *text = gtk_entry_get_text(GTK_ENTRY(sb)); - int value = (int) g_strtod(text, NULL); + const gchar *text; + int value; + text = gtk_entry_get_text(GTK_ENTRY(sb)); + value = (int) g_strtod(text, NULL); if (value < 0 || value > 12) return GTK_INPUT_ERROR; if (value == 12) // 12 to the user is 0 internally @@ -324,9 +322,10 @@ static gint hoursSpinboxInput(GtkSpinButton *sb, gpointer ptr, gpointer data) static gboolean hoursSpinboxOutput(GtkSpinButton *sb, gpointer data) { - gchar *text = NULL; - int value = realSpinValue(sb); + gchar *text; + int value; + value = realSpinValue(sb); if (value == 0) // 0 internally is 12 to the user value = 12; text = g_strdup_printf("%d", value); @@ -337,9 +336,11 @@ static gboolean hoursSpinboxOutput(GtkSpinButton *sb, gpointer data) static gboolean zeroPadSpinbox(GtkSpinButton *sb, gpointer data) { - int value = realSpinValue(sb); - gchar *text = g_strdup_printf("%02d", value); + gchar *text; + int value; + value = realSpinValue(sb); + text = g_strdup_printf("%02d", value); gtk_entry_set_text(GTK_ENTRY(sb), text); g_free(text); return TRUE; @@ -348,20 +349,19 @@ static gboolean zeroPadSpinbox(GtkSpinButton *sb, gpointer data) // this is really hacky but we can't use GtkCombobox here :( static gint ampmSpinboxInput(GtkSpinButton *sb, gpointer ptr, gpointer data) { - double *out = (double *) ptr; - const gchar *text = gtk_entry_get_text(GTK_ENTRY(sb)); - // LONGTERM don't use ASCII here for case insensitivity - char firstAM = g_ascii_tolower(nl_langinfo(AM_STR)[0]); - char firstPM = g_ascii_tolower(nl_langinfo(PM_STR)[0]); + double *out = (double *) ptr; + const gchar *text; + char firstAM, firstPM; + text = gtk_entry_get_text(GTK_ENTRY(sb)); + // LONGTERM don't use ASCII here for case insensitivity + firstAM = g_ascii_tolower(nl_langinfo(AM_STR)[0]); + firstPM = g_ascii_tolower(nl_langinfo(PM_STR)[0]); for (; *text != '\0'; text++) - if (g_ascii_tolower(*text) == firstAM) - { + if (g_ascii_tolower(*text) == firstAM) { *out = 0; return TRUE; - } - else if (g_ascii_tolower(*text) == firstPM) - { + } else if (g_ascii_tolower(*text) == firstPM) { *out = 1; return TRUE; } @@ -387,21 +387,20 @@ static void spinboxChanged(GtkSpinButton *sb, gpointer data) dateTimeChanged(d); } -static GtkWidget *newSpinbox(dateTimePickerWidget *d, int min, int max, - gint (*input)(GtkSpinButton *, gpointer, gpointer), - gboolean (*output)(GtkSpinButton *, gpointer), gulong *block) +static GtkWidget *newSpinbox(dateTimePickerWidget *d, int min, int max, gint (*input)(GtkSpinButton *, gpointer, gpointer), gboolean (*output)(GtkSpinButton *, gpointer), gulong *block) { - GtkWidget *sb = gtk_spin_button_new_with_range(min, max, 1); + GtkWidget *sb; - gtk_spin_button_set_digits(GTK_SPIN_BUTTON(sb), 0); - gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(sb), TRUE); - gtk_orientable_set_orientation(GTK_ORIENTABLE(sb), GTK_ORIENTATION_VERTICAL); - *block = g_signal_connect(sb, "value-changed", G_CALLBACK(spinboxChanged), d); - if (input != NULL) - g_signal_connect(sb, "input", G_CALLBACK(input), NULL); - if (output != NULL) - g_signal_connect(sb, "output", G_CALLBACK(output), NULL); - return sb; + sb = gtk_spin_button_new_with_range(min, max, 1); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(sb), 0); + gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(sb), TRUE); + gtk_orientable_set_orientation(GTK_ORIENTABLE(sb), GTK_ORIENTATION_VERTICAL); + *block = g_signal_connect(sb, "value-changed", G_CALLBACK(spinboxChanged), d); + if (input != NULL) + g_signal_connect(sb, "input", G_CALLBACK(input), NULL); + if (output != NULL) + g_signal_connect(sb, "output", G_CALLBACK(output), NULL); + return sb; } static void dateChanged(GtkCalendar *c, gpointer data) @@ -537,14 +536,18 @@ static void dateTimePickerWidget_class_init(dateTimePickerWidgetClass *class) static GtkWidget *newDTP(void) { - GtkWidget *w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); + GtkWidget *w; + + w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); setLabel(dateTimePickerWidget(w)); return w; } static GtkWidget *newDP(void) { - GtkWidget *w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); + GtkWidget *w; + + w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); setDateOnly(dateTimePickerWidget(w)); setLabel(dateTimePickerWidget(w)); return w; @@ -552,17 +555,18 @@ static GtkWidget *newDP(void) static GtkWidget *newTP(void) { - GtkWidget *w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); + GtkWidget *w; + + w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); setTimeOnly(dateTimePickerWidget(w)); setLabel(dateTimePickerWidget(w)); return w; } -struct uiDateTimePicker -{ - uiUnixControl c; - GtkWidget *widget; - dateTimePickerWidget *d; +struct uiDateTimePicker { + uiUnixControl c; + GtkWidget *widget; + dateTimePickerWidget *d; }; uiUnixControlAllDefaults(uiDateTimePicker) @@ -574,7 +578,7 @@ uiDateTimePicker *finishNewDateTimePicker(GtkWidget *(*fn)(void)) uiUnixNewControl(uiDateTimePicker, d); d->widget = (*fn)(); - d->d = dateTimePickerWidget(d->widget); + d->d = dateTimePickerWidget(d->widget); return d; } diff --git a/deps/libui/gtk/debug.c b/deps/libui/unix/debug.c similarity index 100% rename from deps/libui/gtk/debug.c rename to deps/libui/unix/debug.c diff --git a/deps/libui/gtk/draw.c b/deps/libui/unix/draw.c similarity index 100% rename from deps/libui/gtk/draw.c rename to deps/libui/unix/draw.c diff --git a/deps/libui/gtk/draw.h b/deps/libui/unix/draw.h similarity index 100% rename from deps/libui/gtk/draw.h rename to deps/libui/unix/draw.h diff --git a/deps/libui/gtk/drawmatrix.c b/deps/libui/unix/drawmatrix.c similarity index 100% rename from deps/libui/gtk/drawmatrix.c rename to deps/libui/unix/drawmatrix.c diff --git a/deps/libui/gtk/drawpath.c b/deps/libui/unix/drawpath.c similarity index 100% rename from deps/libui/gtk/drawpath.c rename to deps/libui/unix/drawpath.c diff --git a/deps/libui/gtk/drawtext.c b/deps/libui/unix/drawtext.c similarity index 100% rename from deps/libui/gtk/drawtext.c rename to deps/libui/unix/drawtext.c diff --git a/deps/libui/gtk/editablecombo.c b/deps/libui/unix/editablecombo.c similarity index 100% rename from deps/libui/gtk/editablecombo.c rename to deps/libui/unix/editablecombo.c diff --git a/deps/libui/gtk/entry.c b/deps/libui/unix/entry.c similarity index 100% rename from deps/libui/gtk/entry.c rename to deps/libui/unix/entry.c diff --git a/deps/libui/gtk/fontbutton.c b/deps/libui/unix/fontbutton.c similarity index 100% rename from deps/libui/gtk/fontbutton.c rename to deps/libui/unix/fontbutton.c diff --git a/deps/libui/gtk/form.c b/deps/libui/unix/form.c similarity index 77% rename from deps/libui/gtk/form.c rename to deps/libui/unix/form.c index c2e479526f..54422b3d40 100644 --- a/deps/libui/gtk/form.c +++ b/deps/libui/unix/form.c @@ -1,27 +1,25 @@ // 8 june 2016 #include "uipriv_unix.h" -struct formChild -{ - uiControl *c; - int stretchy; - GtkWidget *label; - gboolean oldhexpand; - GtkAlign oldhalign; - gboolean oldvexpand; - GtkAlign oldvalign; - GBinding *labelBinding; +struct formChild { + uiControl *c; + int stretchy; + GtkWidget *label; + gboolean oldhexpand; + GtkAlign oldhalign; + gboolean oldvexpand; + GtkAlign oldvalign; + GBinding *labelBinding; }; -struct uiForm -{ - uiUnixControl c; - GtkWidget *widget; - GtkContainer *container; - GtkGrid *grid; - GArray *children; - int padded; - GtkSizeGroup *stretchygroup; /* ensures all stretchy controls have the same size */ +struct uiForm { + uiUnixControl c; + GtkWidget *widget; + GtkContainer *container; + GtkGrid *grid; + GArray *children; + int padded; + GtkSizeGroup *stretchygroup; // ensures all stretchy controls have the same size }; uiUnixControlAllDefaultsExceptDestroy(uiForm) @@ -34,19 +32,18 @@ static void uiFormDestroy(uiControl *c) struct formChild *fc; guint i; - /* kill the size group */ + // kill the size group g_object_unref(f->stretchygroup); - /* free all controls */ - for (i = 0; i < f->children->len; i++) - { - fc = ctrl(f, i); - uiControlSetParent(fc->c, NULL); - uiUnixControlSetContainer(uiUnixControl(fc->c), f->container, TRUE); - uiControlDestroy(fc->c); - gtk_widget_destroy(fc->label); - } + // free all controls + for (i = 0; i < f->children->len; i++) { + fc = ctrl(f, i); + uiControlSetParent(fc->c, NULL); + uiUnixControlSetContainer(uiUnixControl(fc->c), f->container, TRUE); + uiControlDestroy(fc->c); + gtk_widget_destroy(fc->label); + } g_array_free(f->children, TRUE); - /* and then ourselves */ + // and then ourselves g_object_unref(f->widget); uiFreeControl(uiControl(f)); } @@ -71,7 +68,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) gtk_size_group_add_widget(f->stretchygroup, widget); } else gtk_widget_set_vexpand(widget, FALSE); - /* and make them fill horizontally */ + // and make them fill horizontally gtk_widget_set_hexpand(widget, TRUE); gtk_widget_set_halign(widget, GTK_ALIGN_FILL); @@ -88,7 +85,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) gtk_grid_attach(f->grid, fc.label, 0, row, 1, 1); - /* and make them share visibility so if the control is hidden, so is its label */ + // and make them share visibility so if the control is hidden, so is its label fc.labelBinding = g_object_bind_property(GTK_WIDGET(uiControlHandle(fc.c)), "visible", fc.label, "visible", G_BINDING_SYNC_CREATE); @@ -97,7 +94,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) uiUnixControlSetContainer(uiUnixControl(fc.c), f->container, FALSE); g_array_append_val(f->children, fc); - /* move the widget to the correct place */ + // move the widget to the correct place gtk_container_child_set(f->container, widget, "left-attach", 1, "top-attach", row, diff --git a/deps/libui/gtk/future.c b/deps/libui/unix/future.c similarity index 100% rename from deps/libui/gtk/future.c rename to deps/libui/unix/future.c diff --git a/deps/libui/gtk/graphemes.c b/deps/libui/unix/graphemes.c similarity index 100% rename from deps/libui/gtk/graphemes.c rename to deps/libui/unix/graphemes.c diff --git a/deps/libui/gtk/grid.c b/deps/libui/unix/grid.c similarity index 100% rename from deps/libui/gtk/grid.c rename to deps/libui/unix/grid.c diff --git a/deps/libui/gtk/group.c b/deps/libui/unix/group.c similarity index 100% rename from deps/libui/gtk/group.c rename to deps/libui/unix/group.c diff --git a/deps/libui/gtk/image.c b/deps/libui/unix/image.c similarity index 88% rename from deps/libui/gtk/image.c rename to deps/libui/unix/image.c index 742128f4ff..a79e550f93 100644 --- a/deps/libui/gtk/image.c +++ b/deps/libui/unix/image.c @@ -52,10 +52,8 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in cs = cairo_image_surface_create_for_data(buf, CAIRO_FORMAT_ARGB32, pixelWidth, pixelHeight, cstride); - - /* TODO */ - if (cairo_surface_status(cs) != CAIRO_STATUS_SUCCESS) { } - + if (cairo_surface_status(cs) != CAIRO_STATUS_SUCCESS) + /* TODO */; cairo_surface_flush(cs); g_ptr_array_add(i->images, cs); } @@ -69,7 +67,7 @@ struct matcher { gboolean foundLarger; }; -/* TODO is this the right algorithm? */ +// TODO is this the right algorithm? static void match(gpointer surface, gpointer data) { cairo_surface_t *cs = (cairo_surface_t *) surface; @@ -83,11 +81,11 @@ static void match(gpointer surface, gpointer data) goto writeMatch; if (x < m->targetX && y < m->targetY) - if (m->foundLarger) /* always prefer larger ones */ + if (m->foundLarger) + // always prefer larger ones return; - - /* we set foundLarger below */ if (x >= m->targetX && y >= m->targetY && !m->foundLarger) + // we set foundLarger below goto writeMatch; x2 = abs(m->targetX - x); @@ -95,11 +93,11 @@ static void match(gpointer surface, gpointer data) if (x2 < m->distX && y2 < m->distY) goto writeMatch; - /* TODO weight one dimension? threshhold? */ + // TODO weight one dimension? threshhold? return; writeMatch: - /* must set this here too; otherwise the first image will never have ths set */ + // must set this here too; otherwise the first image will never have ths set if (x >= m->targetX && y >= m->targetY && !m->foundLarger) m->foundLarger = TRUE; m->best = cs; diff --git a/deps/libui/gtk/label.c b/deps/libui/unix/label.c similarity index 100% rename from deps/libui/gtk/label.c rename to deps/libui/unix/label.c diff --git a/deps/libui/gtk/main.c b/deps/libui/unix/main.c similarity index 66% rename from deps/libui/gtk/main.c rename to deps/libui/unix/main.c index 199c9184ca..2998bf3194 100644 --- a/deps/libui/gtk/main.c +++ b/deps/libui/unix/main.c @@ -6,15 +6,14 @@ uiInitOptions options; const char *uiInit(uiInitOptions *o) { GError *err = NULL; + const char *msg; - options = *o; - - if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &err) == FALSE) - { - const char *msg = g_strdup(err->message); - g_error_free(err); - return msg; - } + options = *o; + if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &err) == FALSE) { + msg = g_strdup(err->message); + g_error_free(err); + return msg; + } initAlloc(); loadFutures(); return NULL; @@ -41,9 +40,8 @@ void uiMain(void) static gboolean stepsQuit = FALSE; -/* the only difference is we ignore the return value from gtk_main_iteration_do(), - * since it will always be TRUE if gtk_main() was never called - * gtk_main_iteration_do() will still run the main loop regardless */ +// the only difference is we ignore the return value from gtk_main_iteration_do(), since it will always be TRUE if gtk_main() was never called +// gtk_main_iteration_do() will still run the main loop regardless static gboolean stepsIteration(gboolean block) { gtk_main_iteration_do(block); @@ -57,7 +55,9 @@ void uiMainSteps(void) int uiMainStep(int wait) { - gboolean block = FALSE; + gboolean block; + + block = FALSE; if (wait) block = TRUE; return (*iteration)(block) == FALSE; @@ -70,8 +70,7 @@ static gboolean quit(gpointer data) { if (iteration == stepsIteration) stepsQuit = TRUE; - /* TODO run a gtk_main() here just to do the cleanup steps of - * syncing the clipboard and other stuff gtk_main() does before it returns */ + // TODO run a gtk_main() here just to do the cleanup steps of syncing the clipboard and other stuff gtk_main() does before it returns else gtk_main_quit(); return FALSE; @@ -98,12 +97,12 @@ static gboolean doqueued(gpointer data) void uiQueueMain(void (*f)(void *data), void *data) { - struct queued *q = g_new0(struct queued, 1); + struct queued *q; - /* we have to use g_new0()/g_free() because uiAlloc() - * is only safe to call on the main thread - * for some reason it didn't affect me, but it did affect krakjoe */ - q->f = f; + // we have to use g_new0()/g_free() because uiAlloc() is only safe to call on the main thread + // for some reason it didn't affect me, but it did affect krakjoe + q = g_new0(struct queued, 1); + q->f = f; q->data = data; gdk_threads_add_idle(doqueued, q); } diff --git a/deps/libui/gtk/menu.c b/deps/libui/unix/menu.c similarity index 86% rename from deps/libui/gtk/menu.c rename to deps/libui/unix/menu.c index 6f6906a056..5ccb4a51a3 100644 --- a/deps/libui/gtk/menu.c +++ b/deps/libui/unix/menu.c @@ -121,8 +121,10 @@ int uiMenuItemChecked(uiMenuItem *item) void uiMenuItemSetChecked(uiMenuItem *item, int checked) { - /* use explicit values */ - gboolean c = FALSE; + gboolean c; + + // use explicit values + c = FALSE; if (checked) c = TRUE; setChecked(item, c); @@ -130,55 +132,55 @@ void uiMenuItemSetChecked(uiMenuItem *item, int checked) static uiMenuItem *newItem(uiMenu *m, int type, const char *name) { - uiMenuItem *item; + uiMenuItem *item; - if (menusFinalized) - userbug("You cannot create a new menu item after menus have been finalized."); + if (menusFinalized) + userbug("You cannot create a new menu item after menus have been finalized."); - item = uiNew(uiMenuItem); + item = uiNew(uiMenuItem); - g_array_append_val(m->items, item); + g_array_append_val(m->items, item); - item->type = type; - switch (item->type) { - case typeQuit: - item->name = g_strdup("Quit"); - break; - case typePreferences: - item->name = g_strdup("Preferences..."); - break; - case typeAbout: - item->name = g_strdup("About"); - break; - case typeSeparator: - break; - default: - item->name = g_strdup(name); - break; - } + item->type = type; + switch (item->type) { + case typeQuit: + item->name = g_strdup("Quit"); + break; + case typePreferences: + item->name = g_strdup("Preferences..."); + break; + case typeAbout: + item->name = g_strdup("About"); + break; + case typeSeparator: + break; + default: + item->name = g_strdup(name); + break; + } - if (item->type == typeQuit) { - // can't call uiMenuItemOnClicked() here - item->onClicked = onQuitClicked; - item->onClickedData = NULL; - } else - uiMenuItemOnClicked(item, defaultOnClicked, NULL); + if (item->type == typeQuit) { + // can't call uiMenuItemOnClicked() here + item->onClicked = onQuitClicked; + item->onClickedData = NULL; + } else + uiMenuItemOnClicked(item, defaultOnClicked, NULL); - switch (item->type) { - case typeCheckbox: - item->gtype = GTK_TYPE_CHECK_MENU_ITEM; - break; - case typeSeparator: - item->gtype = GTK_TYPE_SEPARATOR_MENU_ITEM; - break; - default: - item->gtype = GTK_TYPE_MENU_ITEM; - break; - } + switch (item->type) { + case typeCheckbox: + item->gtype = GTK_TYPE_CHECK_MENU_ITEM; + break; + case typeSeparator: + item->gtype = GTK_TYPE_SEPARATOR_MENU_ITEM; + break; + default: + item->gtype = GTK_TYPE_MENU_ITEM; + break; + } - item->windows = g_hash_table_new(g_direct_hash, g_direct_equal); + item->windows = g_hash_table_new(g_direct_hash, g_direct_equal); - return item; + return item; } uiMenuItem *uiMenuAppendItem(uiMenu *m, const char *name) diff --git a/deps/libui/gtk/multilineentry.c b/deps/libui/unix/multilineentry.c similarity index 100% rename from deps/libui/gtk/multilineentry.c rename to deps/libui/unix/multilineentry.c diff --git a/deps/libui/gtk/progressbar.c b/deps/libui/unix/progressbar.c similarity index 100% rename from deps/libui/gtk/progressbar.c rename to deps/libui/unix/progressbar.c diff --git a/deps/libui/gtk/radiobuttons.c b/deps/libui/unix/radiobuttons.c similarity index 100% rename from deps/libui/gtk/radiobuttons.c rename to deps/libui/unix/radiobuttons.c diff --git a/deps/libui/gtk/separator.c b/deps/libui/unix/separator.c similarity index 100% rename from deps/libui/gtk/separator.c rename to deps/libui/unix/separator.c diff --git a/deps/libui/gtk/slider.c b/deps/libui/unix/slider.c similarity index 100% rename from deps/libui/gtk/slider.c rename to deps/libui/unix/slider.c diff --git a/deps/libui/gtk/spinbox.c b/deps/libui/unix/spinbox.c similarity index 77% rename from deps/libui/gtk/spinbox.c rename to deps/libui/unix/spinbox.c index 8ca01f774a..90a5d3c1db 100644 --- a/deps/libui/gtk/spinbox.c +++ b/deps/libui/unix/spinbox.c @@ -32,10 +32,9 @@ int uiSpinboxValue(uiSpinbox *s) void uiSpinboxSetValue(uiSpinbox *s, int value) { - /* we need to inhibit sending of ::value-changed - * because this WILL send a ::value-changed otherwise */ + // we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise g_signal_handler_block(s->spinButton, s->onChangedSignal); - /* this clamps for us */ + // this clamps for us gtk_spin_button_set_value(s->spinButton, (gdouble) value); g_signal_handler_unblock(s->spinButton, s->onChangedSignal); } @@ -48,23 +47,22 @@ void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *, void *), void *data uiSpinbox *uiNewSpinbox(int min, int max) { + uiSpinbox *s; int temp; - uiSpinbox *s = NULL; - if (min >= max) - { - temp = min; - min = max; - max = temp; - } + if (min >= max) { + temp = min; + min = max; + max = temp; + } uiUnixNewControl(uiSpinbox, s); - s->widget = gtk_spin_button_new_with_range(min, max, 1); - s->entry = GTK_ENTRY(s->widget); + s->widget = gtk_spin_button_new_with_range(min, max, 1); + s->entry = GTK_ENTRY(s->widget); s->spinButton = GTK_SPIN_BUTTON(s->widget); - /* ensure integers, just to be safe */ + // ensure integers, just to be safe gtk_spin_button_set_digits(s->spinButton, 0); s->onChangedSignal = g_signal_connect(s->spinButton, "value-changed", G_CALLBACK(onChanged), s); diff --git a/deps/libui/gtk/stddialogs.c b/deps/libui/unix/stddialogs.c similarity index 100% rename from deps/libui/gtk/stddialogs.c rename to deps/libui/unix/stddialogs.c diff --git a/deps/libui/gtk/tab.c b/deps/libui/unix/tab.c similarity index 67% rename from deps/libui/gtk/tab.c rename to deps/libui/unix/tab.c index 30699e5c64..552e0e31a5 100644 --- a/deps/libui/gtk/tab.c +++ b/deps/libui/unix/tab.c @@ -15,18 +15,16 @@ uiUnixControlAllDefaultsExceptDestroy(uiTab) static void uiTabDestroy(uiControl *c) { + uiTab *t = uiTab(c); guint i; - uiTab *t = uiTab(c); - struct child *page = NULL; + struct child *page; - for (i = 0; i < t->pages->len; i++) - { + for (i = 0; i < t->pages->len; i++) { page = g_array_index(t->pages, struct child *, i); childDestroy(page); } - g_array_free(t->pages, TRUE); - /* and free ourselves */ + // and free ourselves g_object_unref(t->widget); uiFreeControl(uiControl(t)); } @@ -38,8 +36,10 @@ void uiTabAppend(uiTab *t, const char *name, uiControl *child) void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child) { - /* this will create a tab, because of gtk_container_add() */ - struct child *page = newChildWithBox(child, uiControl(t), t->container, 0); + struct child *page; + + // this will create a tab, because of gtk_container_add() + page = newChildWithBox(child, uiControl(t), t->container, 0); gtk_notebook_set_tab_label_text(t->notebook, childBox(page), name); gtk_notebook_reorder_child(t->notebook, childBox(page), n); @@ -49,10 +49,10 @@ void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child) void uiTabDelete(uiTab *t, int n) { - struct child *page = g_array_index(t->pages, struct child *, n); - /* this will remove the tab, - * because gtk_widget_destroy() calls gtk_container_remove() */ + struct child *page; + page = g_array_index(t->pages, struct child *, n); + // this will remove the tab, because gtk_widget_destroy() calls gtk_container_remove() childRemove(page); g_array_remove_index(t->pages, n); } @@ -64,28 +64,30 @@ int uiTabNumPages(uiTab *t) int uiTabMargined(uiTab *t, int n) { - struct child *page = g_array_index(t->pages, struct child *, n); + struct child *page; + page = g_array_index(t->pages, struct child *, n); return childFlag(page); } void uiTabSetMargined(uiTab *t, int n, int margined) { - struct child *page = g_array_index(t->pages, struct child *, n); + struct child *page; + page = g_array_index(t->pages, struct child *, n); childSetFlag(page, margined); childSetMargined(page, childFlag(page)); } uiTab *uiNewTab(void) { - uiTab *t = NULL;; + uiTab *t; uiUnixNewControl(uiTab, t); - t->widget = gtk_notebook_new(); + t->widget = gtk_notebook_new(); t->container = GTK_CONTAINER(t->widget); - t->notebook = GTK_NOTEBOOK(t->widget); + t->notebook = GTK_NOTEBOOK(t->widget); gtk_notebook_set_scrollable(t->notebook, TRUE); diff --git a/deps/libui/gtk/text.c b/deps/libui/unix/text.c similarity index 100% rename from deps/libui/gtk/text.c rename to deps/libui/unix/text.c diff --git a/deps/libui/gtk/uipriv_unix.h b/deps/libui/unix/uipriv_unix.h similarity index 89% rename from deps/libui/gtk/uipriv_unix.h rename to deps/libui/unix/uipriv_unix.h index 3015c30172..33ff1e3553 100644 --- a/deps/libui/gtk/uipriv_unix.h +++ b/deps/libui/unix/uipriv_unix.h @@ -1,11 +1,11 @@ -/* 22 april 2015 */ +// 22 april 2015 #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40 #define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_40 #define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_10 #define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_10 #include #include -#include /* see drawtext.c */ +#include // see drawtext.c #include #include #include @@ -18,19 +18,19 @@ #define gtkXPadding 12 #define gtkYPadding 6 -/* menu.c */ +// menu.c extern GtkWidget *makeMenubar(uiWindow *); extern void freeMenubar(GtkWidget *); extern void uninitMenus(void); -/* alloc.c */ +// alloc.c extern void initAlloc(void); extern void uninitAlloc(void); -/* util.c */ +// util.c extern void setMargined(GtkContainer *, int); -/* child.c */ +// child.c extern struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parentContainer); extern struct child *newChildWithBox(uiControl *child, uiControl *parent, GtkContainer *parentContainer, int margined); extern void childRemove(struct child *c); @@ -41,25 +41,25 @@ extern void childSetFlag(struct child *c, int flag); extern GtkWidget *childBox(struct child *c); extern void childSetMargined(struct child *c, int margined); -/* draw.c */ +// draw.c extern uiDrawContext *newContext(cairo_t *); extern void freeContext(uiDrawContext *); -/* drawtext.c */ +// drawtext.c extern uiDrawTextFont *mkTextFont(PangoFont *f, gboolean add); extern PangoFont *pangoDescToPangoFont(PangoFontDescription *pdesc); -/* graphemes.c */ +// graphemes.c extern ptrdiff_t *graphemes(const char *text, PangoContext *context); -/* image.c */ +// image.c /*TODO remove this*/typedef struct uiImage uiImage; extern cairo_surface_t *imageAppropriateSurface(uiImage *i, GtkWidget *w); -/* cellrendererbutton.c */ +// cellrendererbutton.c extern GtkCellRenderer *newCellRendererButton(void); -/* future.c */ +// future.c extern void loadFutures(void); extern PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha); extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name); diff --git a/deps/libui/gtk/util.c b/deps/libui/unix/util.c similarity index 100% rename from deps/libui/gtk/util.c rename to deps/libui/unix/util.c diff --git a/deps/libui/gtk/window.c b/deps/libui/unix/window.c similarity index 81% rename from deps/libui/gtk/window.c rename to deps/libui/unix/window.c index 0251f64943..ea9ba370f4 100644 --- a/deps/libui/gtk/window.c +++ b/deps/libui/unix/window.c @@ -1,43 +1,40 @@ // 11 june 2015 #include "uipriv_unix.h" -struct uiWindow -{ - uiUnixControl c; +struct uiWindow { + uiUnixControl c; - GtkWidget *widget; - GtkContainer *container; - GtkWindow *window; + GtkWidget *widget; + GtkContainer *container; + GtkWindow *window; - GtkWidget *vboxWidget; - GtkContainer *vboxContainer; - GtkBox *vbox; + GtkWidget *vboxWidget; + GtkContainer *vboxContainer; + GtkBox *vbox; - GtkWidget *childHolderWidget; - GtkContainer *childHolderContainer; + GtkWidget *childHolderWidget; + GtkContainer *childHolderContainer; - GtkWidget *menubar; + GtkWidget *menubar; - uiControl *child; - int margined; + uiControl *child; + int margined; - int (*onClosing)(uiWindow *, void *); - void *onClosingData; - void (*onContentSizeChanged)(uiWindow *, void *); - void *onContentSizeChangedData; - gboolean fullscreen; + int (*onClosing)(uiWindow *, void *); + void *onClosingData; + void (*onContentSizeChanged)(uiWindow *, void *); + void *onContentSizeChangedData; + gboolean fullscreen; }; static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) { uiWindow *w = uiWindow(data); - /* manually destroy the window ourselves; don't let - * the delete-event handler do it */ + // manually destroy the window ourselves; don't let the delete-event handler do it if ((*(w->onClosing))(w, w->onClosingData)) uiControlDestroy(uiControl(w)); - /* don't continue to the default delete-event handler; - * we destroyed the window by now */ + // don't continue to the default delete-event handler; we destroyed the window by now return TRUE; } @@ -45,7 +42,7 @@ static void onSizeAllocate(GtkWidget *widget, GdkRectangle *allocation, gpointer { uiWindow *w = uiWindow(data); - /* TODO deal with spurious size-allocates */ + // TODO deal with spurious size-allocates (*(w->onContentSizeChanged))(w, w->onContentSizeChangedData); } @@ -56,30 +53,28 @@ static int defaultOnClosing(uiWindow *w, void *data) static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) { - /* do nothing */ + // do nothing } static void uiWindowDestroy(uiControl *c) { uiWindow *w = uiWindow(c); - /* first hide ourselves */ + // first hide ourselves gtk_widget_hide(w->widget); - /* now destroy the child */ - if (w->child != NULL) - { - uiControlSetParent(w->child, NULL); - uiUnixControlSetContainer(uiUnixControl(w->child), w->childHolderContainer, TRUE); - uiControlDestroy(w->child); - } - /* now destroy the menus, if any */ + // now destroy the child + if (w->child != NULL) { + uiControlSetParent(w->child, NULL); + uiUnixControlSetContainer(uiUnixControl(w->child), w->childHolderContainer, TRUE); + uiControlDestroy(w->child); + } + // now destroy the menus, if any if (w->menubar != NULL) freeMenubar(w->menubar); gtk_widget_destroy(w->childHolderWidget); gtk_widget_destroy(w->vboxWidget); - /* and finally free ourselves - * use gtk_widget_destroy() instead of g_object_unref() - * because GTK+ has internal references (see #165) */ + // and finally free ourselves + // use gtk_widget_destroy() instead of g_object_unref() because GTK+ has internal references (see #165) gtk_widget_destroy(w->widget); uiFreeControl(uiControl(w)); } @@ -107,11 +102,9 @@ static void uiWindowShow(uiControl *c) { uiWindow *w = uiWindow(c); - /* don't use gtk_widget_show_all() as that - * will show all children, regardless of user settings - * don't use gtk_widget_show(); that doesn't bring to - * front or give keyboard focus - * (gtk_window_present() does call gtk_widget_show() though) */ + // don't use gtk_widget_show_all() as that will show all children, regardless of user settings + // don't use gtk_widget_show(); that doesn't bring to front or give keyboard focus + // (gtk_window_present() does call gtk_widget_show() though) gtk_window_present(w->window); } @@ -119,8 +112,7 @@ uiUnixControlDefaultHide(uiWindow) uiUnixControlDefaultEnabled(uiWindow) uiUnixControlDefaultEnable(uiWindow) uiUnixControlDefaultDisable(uiWindow) - -/* TODO? */ +// TODO? uiUnixControlDefaultSetContainer(uiWindow) char *uiWindowTitle(uiWindow *w) diff --git a/deps/libui/win32/datetimepicker.cpp b/deps/libui/win32/datetimepicker.cpp deleted file mode 100644 index c14359379d..0000000000 --- a/deps/libui/win32/datetimepicker.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* 22 may 2015 */ -#include "uipriv_windows.hpp" - -struct uiDateTimePicker { - uiWindowsControl c; - HWND hwnd; -}; - -#ifndef DTM_GETIDEALSIZE -#define DTM_GETIDEALSIZE 0x100f -#endif - -/* utility functions */ - -#define GLI(what, buf, n) GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, what, buf, n) - -/* The real date/time picker does a manual replacement of "yy" with "yyyy" for DTS_SHORTDATECENTURYFORMAT. - * Because we're also duplicating its functionality (see below), we have to do it too. */ -static WCHAR *expandYear(WCHAR *dts, int n) -{ - WCHAR *p = NULL; - int ny = 0; - - /* allocate more than we need to be safe */ - WCHAR *out = (WCHAR *) uiAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]"); - WCHAR *q = out; - - for (p = dts; *p != L'\0'; p++) - { - /* first, if the current character is a y, increment the number of consecutive ys - * otherwise, stop counting, and if there were only two, add two more to make four */ - if (*p != L'y') { - if (ny == 2) { - *q++ = L'y'; - *q++ = L'y'; - } - ny = 0; - } else - ny++; - /* next, handle quoted blocks - * we do this AFTER the above so yy'abc' becomes yyyy'abc' and not yy'abc'yy - * this handles the case of 'a''b' elegantly as well */ - if (*p == L'\'') { - /* copy the opening quote */ - *q++ = *p; - /* copy the contents */ - for (;;) { - p++; - if (*p == L'\'') - break; - if (*p == L'\0') - implbug("unterminated quote in system-provided locale date string in expandYear()"); - *q++ = *p; - } - /* and fall through to copy the closing quote */ - } - /* copy the current character */ - *q++ = *p; - } - /* handle trailing yy */ - if (ny == 2) { - *q++ = L'y'; - *q++ = L'y'; - } - *q++ = L'\0'; - return out; -} - -/* Windows has no combined date/time prebuilt constant; - * we have to build the format string ourselves - * TODO use a default format if one fails */ -static void setDateTimeFormat(HWND hwnd) -{ - WCHAR *unexpandedDate, *date; - WCHAR *time; - WCHAR *datetime; - int ntime; - int ndate = GLI(LOCALE_SSHORTDATE, NULL, 0); - - if (ndate == 0) - logLastError(L"error getting date string length"); - date = (WCHAR *) uiAlloc(ndate * sizeof (WCHAR), "WCHAR[]"); - if (GLI(LOCALE_SSHORTDATE, date, ndate) == 0) - logLastError(L"error geting date string"); - unexpandedDate = date; /* so we can free it */ - date = expandYear(unexpandedDate, ndate); - uiFree(unexpandedDate); - - ntime = GLI(LOCALE_STIMEFORMAT, NULL, 0); - if (ndate == 0) - logLastError(L"error getting time string length"); - time = (WCHAR *) uiAlloc(ntime * sizeof (WCHAR), "WCHAR[]"); - if (GLI(LOCALE_STIMEFORMAT, time, ntime) == 0) - logLastError(L"error geting time string"); - - datetime = strf(L"%s %s", date, time); - if (SendMessageW(hwnd, DTM_SETFORMAT, 0, (LPARAM) datetime) == 0) - logLastError(L"error applying format string to date/time picker"); - - uiFree(datetime); - uiFree(time); - uiFree(date); -} - -/* control implementation */ - -static void uiDateTimePickerDestroy(uiControl *c) -{ - uiDateTimePicker *d = uiDateTimePicker(c); - - uiWindowsUnregisterReceiveWM_WININICHANGE(d->hwnd); - uiWindowsEnsureDestroyWindow(d->hwnd); - uiFreeControl(uiControl(d)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiDateTimePicker) - -/* the height returned from DTM_GETIDEALSIZE is unreliable; see http://stackoverflow.com/questions/30626549/what-is-the-proper-use-of-dtm-getidealsize-treating-the-returned-size-as-pixels - * from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing */ -#define entryHeight 14 - -static void uiDateTimePickerMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - SIZE s; - uiWindowsSizing sizing; - uiDateTimePicker *d = uiDateTimePicker(c); - int y; - - s.cx = 0; - s.cy = 0; - SendMessageW(d->hwnd, DTM_GETIDEALSIZE, 0, (LPARAM) (&s)); - *width = s.cx; - - y = entryHeight; - uiWindowsGetSizing(d->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); - *height = y; -} - -static uiDateTimePicker *finishNewDateTimePicker(DWORD style) -{ - uiDateTimePicker *d; - - uiWindowsNewControl(uiDateTimePicker, d); - - d->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, - DATETIMEPICK_CLASSW, L"", - style | WS_TABSTOP, - hInstance, NULL, - TRUE); - - /* automatically update date/time format when user changes locale settings - * for the standard styles, this is in the date-time picker itself - * for our date/time mode, we do it in a subclass assigned in uiNewDateTimePicker() */ - uiWindowsRegisterReceiveWM_WININICHANGE(d->hwnd); - - return d; -} - -static LRESULT CALLBACK datetimepickerSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, - LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - switch (uMsg) - { - case WM_WININICHANGE: - // we can optimize this by only doing it when the real date/time picker does it - // unfortunately, I don't know when that is :/ - // hopefully this won't hurt - setDateTimeFormat(hwnd); - return 0; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, datetimepickerSubProc, uIdSubclass) == FALSE) - logLastError(L"error removing date-time picker locale change handling subclass"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -uiDateTimePicker *uiNewDateTimePicker(void) -{ - uiDateTimePicker *d = finishNewDateTimePicker(0); - - setDateTimeFormat(d->hwnd); - if (SetWindowSubclass(d->hwnd, datetimepickerSubProc, 0, (DWORD_PTR) d) == FALSE) - logLastError(L"error subclassing date-time-picker to assist in locale change handling"); - /* TODO set a suitable default in this case */ - return d; -} - -uiDateTimePicker *uiNewDatePicker(void) -{ - return finishNewDateTimePicker(DTS_SHORTDATECENTURYFORMAT); -} - -uiDateTimePicker *uiNewTimePicker(void) -{ - return finishNewDateTimePicker(DTS_TIMEFORMAT); -} diff --git a/deps/libui/win32/text.cpp b/deps/libui/win32/text.cpp deleted file mode 100644 index d3e0131eab..0000000000 --- a/deps/libui/win32/text.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* 9 april 2015 */ -#include "uipriv_windows.hpp" - -WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len) -{ - WCHAR *text = NULL; - LRESULT n = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); - - if (len != NULL) - *len = n; - /* WM_GETTEXTLENGTH does not include the null terminator */ - text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); - /* note the comparison: the size includes the - * null terminator, but the return does not */ - if (GetWindowTextW(hwnd, text, n + 1) != n) - { - logLastError(L"error getting window text"); - /* on error, return an empty string to be safe */ - *text = L'\0'; - if (len != NULL) - *len = 0; - } - return text; -} - -WCHAR *windowText(HWND hwnd) -{ - return windowTextAndLen(hwnd, NULL); -} - -void setWindowText(HWND hwnd, WCHAR *wtext) -{ - if (SetWindowTextW(hwnd, wtext) == 0) - logLastError(L"error setting window text"); -} - -void uiFreeText(char *text) -{ - uiFree(text); -} - -int uiWindowsWindowTextWidth(HWND hwnd) -{ - LRESULT len; - HDC dc; - HFONT prevfont; - SIZE size; - WCHAR *text = windowTextAndLen(hwnd, &len); - - size.cx = 0; - size.cy = 0; - - if (len == 0) /* no text; nothing to do */ - goto noTextOrError; - - /* now we can do the calculations */ - dc = GetDC(hwnd); - if (dc == NULL) - { - logLastError(L"error getting DC"); - /* on any error, assume no text */ - goto noTextOrError; - } - prevfont = (HFONT) SelectObject(dc, hMessageFont); - if (prevfont == NULL) - { - logLastError(L"error loading control font into device context"); - ReleaseDC(hwnd, dc); - goto noTextOrError; - } - if (GetTextExtentPoint32W(dc, text, len, &size) == 0) - { - logLastError(L"error getting text extent point"); - /* continue anyway, assuming size is 0 */ - size.cx = 0; - size.cy = 0; - } - /* continue on errors; we got what we want */ - if (SelectObject(dc, prevfont) != hMessageFont) - logLastError(L"error restoring previous font into device context"); - if (ReleaseDC(hwnd, dc) == 0) - logLastError(L"error releasing DC"); - - uiFree(text); - return size.cx; - -noTextOrError: - uiFree(text); - return 0; -} - -char *uiWindowsWindowText(HWND hwnd) -{ - WCHAR *wtext = windowText(hwnd); - char *text = toUTF8(wtext); - uiFree(wtext); - return text; -} - -void uiWindowsSetWindowText(HWND hwnd, const char *text) -{ - WCHAR *wtext = toUTF16(text); - setWindowText(hwnd, wtext); - uiFree(wtext); -} diff --git a/deps/libui/win32/utilwin.cpp b/deps/libui/win32/utilwin.cpp deleted file mode 100644 index 9b9a3ac8f4..0000000000 --- a/deps/libui/win32/utilwin.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* 14 may 2015 */ -#include "uipriv_windows.hpp" -#include "../../verbosity.h" - -/* The utility window is a special window that performs certain tasks internal to libui. - * It is not a message-only window, and it is always hidden and disabled. - * Its roles: - * - It is the initial parent of all controls. When a control loses its parent, it also becomes that control's parent. - * - It handles WM_QUERYENDSESSION and console end session requests. - * - It handles WM_WININICHANGE and forwards the message to any child windows that request it. - * - It handles executing functions queued to run by uiQueueMain(). - */ - -#define utilWindowClass L"libui_utilWindowClass" - -HWND utilWindow; - -static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - void (*qf)(void *); - LRESULT lResult; - - if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; - - switch (uMsg) - { - case WM_QUERYENDSESSION: - /* TODO block handler */ - if (shouldQuit()) - { - uiQuit(); - return TRUE; - } - return FALSE; - case WM_WININICHANGE: - issueWM_WININICHANGE(wParam, lParam); - return 0; - case msgQueued: - qf = (void (*)(void *)) wParam; - (*qf)((void *) lParam); - return 0; - } - return DefWindowProcW(hwnd, uMsg, wParam, lParam); -} - -const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor) -{ - WNDCLASSW wc; - - ZeroMemory(&wc, sizeof (WNDCLASSW)); - wc.lpszClassName = utilWindowClass; - wc.lpfnWndProc = utilWindowWndProc; - wc.hInstance = hInstance; - wc.hIcon = hDefaultIcon; - wc.hCursor = hDefaultCursor; - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); - if (RegisterClass(&wc) == 0) - { - RARCH_ERR("Cannot register class.\n"); - /* see init.cpp for an explanation of the =s */ - return "=registering utility window class"; - } - - utilWindow = CreateWindowExW(0, - utilWindowClass, L"libui utility window", - WS_OVERLAPPEDWINDOW, - 0, 0, 100, 100, - NULL, NULL, hInstance, NULL); - if (utilWindow == NULL) - { - RARCH_ERR("Cannot create window.\n"); - return "=creating utility window"; - } - /* and just to be safe */ - EnableWindow(utilWindow, FALSE); - - return NULL; -} - -void uninitUtilWindow(void) -{ - if (DestroyWindow(utilWindow) == 0) - logLastError(L"error destroying utility window"); - if (UnregisterClass(utilWindowClass, hInstance) == 0) - logLastError(L"error unregistering utility window class"); -} diff --git a/deps/libui/win32/winextra.h b/deps/libui/win32/winextra.h deleted file mode 100644 index 6d0bb3ee7d..0000000000 --- a/deps/libui/win32/winextra.h +++ /dev/null @@ -1,150 +0,0 @@ -/* This file contains some Vista SDK stuff that is missing from the current - mingw-w64 headers */ - -#ifndef WINEXTRA_H -#define WINEXTRA_H - -/* winuser.h */ - -#if (_WIN32_WINNT >= 0x0600) - WINUSERAPI WINBOOL WINAPI SetProcessDPIAware(VOID); - WINUSERAPI WINBOOL WINAPI IsProcessDPIAware(VOID); -#endif - -/* commctrl.h */ - -#ifndef NOTASKDIALOG -#if (NTDDI_VERSION >= NTDDI_VISTA) -#include -#define TD_WARNING_ICON MAKEINTRESOURCEW(-1) -#define TD_ERROR_ICON MAKEINTRESOURCEW(-2) -#define TD_INFORMATION_ICON MAKEINTRESOURCEW(-3) -#define TD_SHIELD_ICON MAKEINTRESOURCEW(-4) - - typedef HRESULT (CALLBACK *PFTASKDIALOGCALLBACK)(HWND hwnd,UINT uNotification,WPARAM wParam,LPARAM lParam,LONG_PTR dwRefData); - - enum _TASKDIALOG_FLAGS { - TDF_ENABLE_HYPERLINKS = 0x0001, - TDF_USE_HICON_MAIN = 0x0002, - TDF_USE_HICON_FOOTER = 0x0004, - TDF_ALLOW_DIALOG_CANCELLATION = 0x0008, - TDF_USE_COMMAND_LINKS = 0x0010, - TDF_USE_COMMAND_LINKS_NO_ICON = 0x0020, - TDF_EXPAND_FOOTER_AREA = 0x0040, - TDF_EXPANDED_BY_DEFAULT = 0x0080, - TDF_VERIFICATION_FLAG_CHECKED = 0x0100, - TDF_SHOW_PROGRESS_BAR = 0x0200, - TDF_SHOW_MARQUEE_PROGRESS_BAR = 0x0400, - TDF_CALLBACK_TIMER = 0x0800, - TDF_POSITION_RELATIVE_TO_WINDOW = 0x1000, - TDF_RTL_LAYOUT = 0x2000, - TDF_NO_DEFAULT_RADIO_BUTTON = 0x4000, - TDF_CAN_BE_MINIMIZED = 0x8000, - TDIF_SIZE_TO_CONTENT = 0x1000000, - TDF_SIZE_TO_CONTENT = 0x1000000 - }; - typedef int TASKDIALOG_FLAGS; - - enum _TASKDIALOG_COMMON_BUTTON_FLAGS { - TDCBF_OK_BUTTON = 0x01, - TDCBF_YES_BUTTON = 0x02, - TDCBF_NO_BUTTON = 0x04, - TDCBF_CANCEL_BUTTON = 0x08, - TDCBF_RETRY_BUTTON = 0x10, - TDCBF_CLOSE_BUTTON = 0x20 - }; - typedef int TASKDIALOG_COMMON_BUTTON_FLAGS; - - typedef enum _TASKDIALOG_NOTIFICATIONS { - TDN_CREATED = 0, - TDN_NAVIGATED = 1, - TDN_BUTTON_CLICKED = 2, - TDN_HYPERLINK_CLICKED = 3, - TDN_TIMER = 4, - TDN_DESTROYED = 5, - TDN_RADIO_BUTTON_CLICKED = 6, - TDN_DIALOG_CONSTRUCTED = 7, - TDN_VERIFICATION_CLICKED = 8, - TDN_HELP = 9, - TDN_EXPANDO_BUTTON_CLICKED = 10 - } TASKDIALOG_NOTIFICATIONS; - - typedef enum _TASKDIALOG_MESSAGES { - TDM_NAVIGATE_PAGE = WM_USER + 101, - TDM_CLICK_BUTTON = WM_USER + 102, - TDM_SET_MARQUEE_PROGRESS_BAR = WM_USER + 103, - TDM_SET_PROGRESS_BAR_STATE = WM_USER + 104, - TDM_SET_PROGRESS_BAR_RANGE = WM_USER + 105, - TDM_SET_PROGRESS_BAR_POS = WM_USER + 106, - TDM_SET_PROGRESS_BAR_MARQUEE = WM_USER + 107, - TDM_SET_ELEMENT_TEXT = WM_USER + 108, - TDM_CLICK_RADIO_BUTTON = WM_USER + 110, - TDM_ENABLE_BUTTON = WM_USER + 111, - TDM_ENABLE_RADIO_BUTTON = WM_USER + 112, - TDM_CLICK_VERIFICATION = WM_USER + 113, - TDM_UPDATE_ELEMENT_TEXT = WM_USER + 114, - TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE = WM_USER + 115, - TDM_UPDATE_ICON = WM_USER + 116 - } TASKDIALOG_MESSAGES; - - typedef enum _TASKDIALOG_ELEMENTS { - TDE_CONTENT, - TDE_EXPANDED_INFORMATION, - TDE_FOOTER, - TDE_MAIN_INSTRUCTION - } TASKDIALOG_ELEMENTS; - - typedef enum _TASKDIALOG_ICON_ELEMENTS { - TDIE_ICON_MAIN, - TDIE_ICON_FOOTER - } TASKDIALOG_ICON_ELEMENTS; - - typedef struct _TASKDIALOG_BUTTON { - int nButtonID; - PCWSTR pszButtonText; - } TASKDIALOG_BUTTON; - - typedef struct _TASKDIALOGCONFIG { - UINT cbSize; - HWND hwndParent; - HINSTANCE hInstance; - TASKDIALOG_FLAGS dwFlags; - TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons; - PCWSTR pszWindowTitle; - __C89_NAMELESS union { - HICON hMainIcon; - PCWSTR pszMainIcon; - } DUMMYUNIONNAME; - PCWSTR pszMainInstruction; - PCWSTR pszContent; - UINT cButtons; - const TASKDIALOG_BUTTON *pButtons; - int nDefaultButton; - UINT cRadioButtons; - const TASKDIALOG_BUTTON *pRadioButtons; - int nDefaultRadioButton; - PCWSTR pszVerificationText; - PCWSTR pszExpandedInformation; - PCWSTR pszExpandedControlText; - PCWSTR pszCollapsedControlText; - __C89_NAMELESS union { - HICON hFooterIcon; - PCWSTR pszFooterIcon; - } DUMMYUNIONNAME2; - PCWSTR pszFooter; - PFTASKDIALOGCALLBACK pfCallback; - LONG_PTR lpCallbackData; - UINT cxWidth; - } TASKDIALOGCONFIG; - - WINCOMMCTRLAPI HRESULT WINAPI TaskDialog(HWND hwndParent,HINSTANCE hInstance,PCWSTR pszWindowTitle,PCWSTR pszMainInstruction,PCWSTR pszContent,TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons,PCWSTR pszIcon,int *pnButton); - WINCOMMCTRLAPI HRESULT WINAPI TaskDialogIndirect(const TASKDIALOGCONFIG *pTaskConfig,int *pnButton,int *pnRadioButton,BOOL *pfVerificationFlagChecked); -#include -#endif -#endif - -/* dwmapi.h */ - -HRESULT WINAPI DwmFlush(VOID); - -#endif diff --git a/deps/libui/windows/CMakeLists.txt b/deps/libui/windows/CMakeLists.txt new file mode 100644 index 0000000000..4695eb4f6e --- /dev/null +++ b/deps/libui/windows/CMakeLists.txt @@ -0,0 +1,91 @@ +# 3 june 2016 + +list(APPEND _LIBUI_SOURCES + windows/alloc.cpp + windows/area.cpp + windows/areadraw.cpp + windows/areaevents.cpp + windows/areascroll.cpp + windows/areautil.cpp + windows/box.cpp + windows/button.cpp + windows/checkbox.cpp + windows/colorbutton.cpp + windows/colordialog.cpp + windows/combobox.cpp + windows/container.cpp + windows/control.cpp + windows/d2dscratch.cpp + windows/datetimepicker.cpp + windows/debug.cpp + windows/draw.cpp + windows/drawmatrix.cpp + windows/drawpath.cpp + windows/drawtext.cpp + windows/dwrite.cpp + windows/editablecombo.cpp + windows/entry.cpp + windows/events.cpp + windows/fontbutton.cpp + windows/fontdialog.cpp + windows/form.cpp + windows/graphemes.cpp + windows/grid.cpp + windows/group.cpp + windows/init.cpp + windows/label.cpp + windows/main.cpp + windows/menu.cpp + windows/multilineentry.cpp + windows/parent.cpp + windows/progressbar.cpp + windows/radiobuttons.cpp + windows/separator.cpp + windows/sizing.cpp + windows/slider.cpp + windows/spinbox.cpp + windows/stddialogs.cpp + windows/tab.cpp + windows/tabpage.cpp + windows/text.cpp + windows/utf16.cpp + windows/utilwin.cpp + windows/window.cpp + windows/winpublic.cpp + windows/winutil.cpp + windows/resources.rc +) +set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) + +list(APPEND _LIBUI_INCLUDEDIRS + windows +) +set(_LIBUI_INCLUDEDIRS _LIBUI_INCLUDEDIRS PARENT_SCOPE) + +# Windows won't link resources in static libraries; we need to provide the libui.res file in this case. +set(_LIBUINAME libui PARENT_SCOPE) +if(NOT BUILD_SHARED_LIBS) + set(_LIBUI_STATIC_RES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libui.res PARENT_SCOPE) +endif() +macro(_handle_static) + # TODO this full path feels hacky + add_custom_command( + TARGET libui POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy $/CMakeFiles/libui.dir/windows/resources.rc.* ${_LIBUI_STATIC_RES} + COMMENT "Copying libui.res") +endmacro() + +# notice that usp10 comes before gdi32 +# TODO prune this list +set(_LIBUI_LIBS + user32 kernel32 usp10 gdi32 comctl32 uxtheme msimg32 comdlg32 d2d1 dwrite ole32 oleaut32 oleacc uuid +PARENT_SCOPE) + +if(NOT MSVC) + if(BUILD_SHARED_LIBS) + message(FATAL_ERROR + "Sorry, but libui for Windows can currently only be built as a static library with MinGW. You will need to either build as a static library or switch to MSVC." + ) + endif() +endif() diff --git a/deps/libui/win32/_uipriv_migrate.hpp b/deps/libui/windows/_uipriv_migrate.hpp similarity index 100% rename from deps/libui/win32/_uipriv_migrate.hpp rename to deps/libui/windows/_uipriv_migrate.hpp diff --git a/deps/libui/win32/alloc.cpp b/deps/libui/windows/alloc.cpp similarity index 100% rename from deps/libui/win32/alloc.cpp rename to deps/libui/windows/alloc.cpp diff --git a/deps/libui/win32/area.cpp b/deps/libui/windows/area.cpp similarity index 100% rename from deps/libui/win32/area.cpp rename to deps/libui/windows/area.cpp diff --git a/deps/libui/win32/area.hpp b/deps/libui/windows/area.hpp similarity index 100% rename from deps/libui/win32/area.hpp rename to deps/libui/windows/area.hpp diff --git a/deps/libui/win32/areadraw.cpp b/deps/libui/windows/areadraw.cpp similarity index 100% rename from deps/libui/win32/areadraw.cpp rename to deps/libui/windows/areadraw.cpp diff --git a/deps/libui/win32/areaevents.cpp b/deps/libui/windows/areaevents.cpp similarity index 100% rename from deps/libui/win32/areaevents.cpp rename to deps/libui/windows/areaevents.cpp diff --git a/deps/libui/win32/areascroll.cpp b/deps/libui/windows/areascroll.cpp similarity index 99% rename from deps/libui/win32/areascroll.cpp rename to deps/libui/windows/areascroll.cpp index 1797063a9d..f18d0ad874 100644 --- a/deps/libui/win32/areascroll.cpp +++ b/deps/libui/windows/areascroll.cpp @@ -100,10 +100,11 @@ static void scroll(uiArea *a, int which, struct scrollParams *p, WPARAM wParam, static void wheelscroll(uiArea *a, int which, struct scrollParams *p, WPARAM wParam, LPARAM lParam) { + int delta; int lines; UINT scrollAmount; - int delta = GET_WHEEL_DELTA_WPARAM(wParam); + delta = GET_WHEEL_DELTA_WPARAM(wParam); if (SystemParametersInfoW(p->wheelSPIAction, 0, &scrollAmount, 0) == 0) // TODO use scrollAmount == 3 (for both v and h) instead? logLastError(L"error getting area wheel scroll amount"); diff --git a/deps/libui/win32/areautil.cpp b/deps/libui/windows/areautil.cpp similarity index 100% rename from deps/libui/win32/areautil.cpp rename to deps/libui/windows/areautil.cpp diff --git a/deps/libui/win32/box.cpp b/deps/libui/windows/box.cpp similarity index 100% rename from deps/libui/win32/box.cpp rename to deps/libui/windows/box.cpp diff --git a/deps/libui/win32/button.cpp b/deps/libui/windows/button.cpp similarity index 100% rename from deps/libui/win32/button.cpp rename to deps/libui/windows/button.cpp diff --git a/deps/libui/win32/checkbox.cpp b/deps/libui/windows/checkbox.cpp similarity index 100% rename from deps/libui/win32/checkbox.cpp rename to deps/libui/windows/checkbox.cpp diff --git a/deps/libui/win32/colorbutton.cpp b/deps/libui/windows/colorbutton.cpp similarity index 100% rename from deps/libui/win32/colorbutton.cpp rename to deps/libui/windows/colorbutton.cpp diff --git a/deps/libui/win32/colordialog.cpp b/deps/libui/windows/colordialog.cpp similarity index 100% rename from deps/libui/win32/colordialog.cpp rename to deps/libui/windows/colordialog.cpp diff --git a/deps/libui/win32/combobox.cpp b/deps/libui/windows/combobox.cpp similarity index 100% rename from deps/libui/win32/combobox.cpp rename to deps/libui/windows/combobox.cpp diff --git a/deps/libui/win32/compilerver.hpp b/deps/libui/windows/compilerver.hpp similarity index 100% rename from deps/libui/win32/compilerver.hpp rename to deps/libui/windows/compilerver.hpp diff --git a/deps/libui/win32/container.cpp b/deps/libui/windows/container.cpp similarity index 100% rename from deps/libui/win32/container.cpp rename to deps/libui/windows/container.cpp diff --git a/deps/libui/win32/control.cpp b/deps/libui/windows/control.cpp similarity index 100% rename from deps/libui/win32/control.cpp rename to deps/libui/windows/control.cpp diff --git a/deps/libui/win32/d2dscratch.cpp b/deps/libui/windows/d2dscratch.cpp similarity index 100% rename from deps/libui/win32/d2dscratch.cpp rename to deps/libui/windows/d2dscratch.cpp diff --git a/deps/libui/windows/datetimepicker.cpp b/deps/libui/windows/datetimepicker.cpp new file mode 100644 index 0000000000..e105c2fdb7 --- /dev/null +++ b/deps/libui/windows/datetimepicker.cpp @@ -0,0 +1,191 @@ +// 22 may 2015 +#include "uipriv_windows.hpp" + +struct uiDateTimePicker { + uiWindowsControl c; + HWND hwnd; +}; + +// utility functions + +#define GLI(what, buf, n) GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, what, buf, n) + +// The real date/time picker does a manual replacement of "yy" with "yyyy" for DTS_SHORTDATECENTURYFORMAT. +// Because we're also duplicating its functionality (see below), we have to do it too. +static WCHAR *expandYear(WCHAR *dts, int n) +{ + WCHAR *out; + WCHAR *p, *q; + int ny = 0; + + // allocate more than we need to be safe + out = (WCHAR *) uiAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]"); + q = out; + for (p = dts; *p != L'\0'; p++) { + // first, if the current character is a y, increment the number of consecutive ys + // otherwise, stop counting, and if there were only two, add two more to make four + if (*p != L'y') { + if (ny == 2) { + *q++ = L'y'; + *q++ = L'y'; + } + ny = 0; + } else + ny++; + // next, handle quoted blocks + // we do this AFTER the above so yy'abc' becomes yyyy'abc' and not yy'abc'yy + // this handles the case of 'a''b' elegantly as well + if (*p == L'\'') { + // copy the opening quote + *q++ = *p; + // copy the contents + for (;;) { + p++; + if (*p == L'\'') + break; + if (*p == L'\0') + implbug("unterminated quote in system-provided locale date string in expandYear()"); + *q++ = *p; + } + // and fall through to copy the closing quote + } + // copy the current character + *q++ = *p; + } + // handle trailing yy + if (ny == 2) { + *q++ = L'y'; + *q++ = L'y'; + } + *q++ = L'\0'; + return out; +} + +// Windows has no combined date/time prebuilt constant; we have to build the format string ourselves +// TODO use a default format if one fails +static void setDateTimeFormat(HWND hwnd) +{ + WCHAR *unexpandedDate, *date; + WCHAR *time; + WCHAR *datetime; + int ndate, ntime; + + ndate = GLI(LOCALE_SSHORTDATE, NULL, 0); + if (ndate == 0) + logLastError(L"error getting date string length"); + date = (WCHAR *) uiAlloc(ndate * sizeof (WCHAR), "WCHAR[]"); + if (GLI(LOCALE_SSHORTDATE, date, ndate) == 0) + logLastError(L"error geting date string"); + unexpandedDate = date; // so we can free it + date = expandYear(unexpandedDate, ndate); + uiFree(unexpandedDate); + + ntime = GLI(LOCALE_STIMEFORMAT, NULL, 0); + if (ndate == 0) + logLastError(L"error getting time string length"); + time = (WCHAR *) uiAlloc(ntime * sizeof (WCHAR), "WCHAR[]"); + if (GLI(LOCALE_STIMEFORMAT, time, ntime) == 0) + logLastError(L"error geting time string"); + + datetime = strf(L"%s %s", date, time); + if (SendMessageW(hwnd, DTM_SETFORMAT, 0, (LPARAM) datetime) == 0) + logLastError(L"error applying format string to date/time picker"); + + uiFree(datetime); + uiFree(time); + uiFree(date); +} + +// control implementation + +static void uiDateTimePickerDestroy(uiControl *c) +{ + uiDateTimePicker *d = uiDateTimePicker(c); + + uiWindowsUnregisterReceiveWM_WININICHANGE(d->hwnd); + uiWindowsEnsureDestroyWindow(d->hwnd); + uiFreeControl(uiControl(d)); +} + +uiWindowsControlAllDefaultsExceptDestroy(uiDateTimePicker) + +// the height returned from DTM_GETIDEALSIZE is unreliable; see http://stackoverflow.com/questions/30626549/what-is-the-proper-use-of-dtm-getidealsize-treating-the-returned-size-as-pixels +// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing +#define entryHeight 14 + +static void uiDateTimePickerMinimumSize(uiWindowsControl *c, int *width, int *height) +{ + uiDateTimePicker *d = uiDateTimePicker(c); + SIZE s; + uiWindowsSizing sizing; + int y; + + s.cx = 0; + s.cy = 0; + SendMessageW(d->hwnd, DTM_GETIDEALSIZE, 0, (LPARAM) (&s)); + *width = s.cx; + + y = entryHeight; + uiWindowsGetSizing(d->hwnd, &sizing); + uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); + *height = y; +} + +static uiDateTimePicker *finishNewDateTimePicker(DWORD style) +{ + uiDateTimePicker *d; + + uiWindowsNewControl(uiDateTimePicker, d); + + d->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, + DATETIMEPICK_CLASSW, L"", + style | WS_TABSTOP, + hInstance, NULL, + TRUE); + + // automatically update date/time format when user changes locale settings + // for the standard styles, this is in the date-time picker itself + // for our date/time mode, we do it in a subclass assigned in uiNewDateTimePicker() + uiWindowsRegisterReceiveWM_WININICHANGE(d->hwnd); + + return d; +} + +static LRESULT CALLBACK datetimepickerSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + switch (uMsg) { + case WM_WININICHANGE: + // we can optimize this by only doing it when the real date/time picker does it + // unfortunately, I don't know when that is :/ + // hopefully this won't hurt + setDateTimeFormat(hwnd); + return 0; + case WM_NCDESTROY: + if (RemoveWindowSubclass(hwnd, datetimepickerSubProc, uIdSubclass) == FALSE) + logLastError(L"error removing date-time picker locale change handling subclass"); + break; + } + return DefSubclassProc(hwnd, uMsg, wParam, lParam); +} + +uiDateTimePicker *uiNewDateTimePicker(void) +{ + uiDateTimePicker *d; + + d = finishNewDateTimePicker(0); + setDateTimeFormat(d->hwnd); + if (SetWindowSubclass(d->hwnd, datetimepickerSubProc, 0, (DWORD_PTR) d) == FALSE) + logLastError(L"error subclassing date-time-picker to assist in locale change handling"); + // TODO set a suitable default in this case + return d; +} + +uiDateTimePicker *uiNewDatePicker(void) +{ + return finishNewDateTimePicker(DTS_SHORTDATECENTURYFORMAT); +} + +uiDateTimePicker *uiNewTimePicker(void) +{ + return finishNewDateTimePicker(DTS_TIMEFORMAT); +} diff --git a/deps/libui/win32/debug.cpp b/deps/libui/windows/debug.cpp similarity index 100% rename from deps/libui/win32/debug.cpp rename to deps/libui/windows/debug.cpp diff --git a/deps/libui/win32/draw.cpp b/deps/libui/windows/draw.cpp similarity index 100% rename from deps/libui/win32/draw.cpp rename to deps/libui/windows/draw.cpp diff --git a/deps/libui/win32/draw.hpp b/deps/libui/windows/draw.hpp similarity index 100% rename from deps/libui/win32/draw.hpp rename to deps/libui/windows/draw.hpp diff --git a/deps/libui/win32/drawmatrix.cpp b/deps/libui/windows/drawmatrix.cpp similarity index 100% rename from deps/libui/win32/drawmatrix.cpp rename to deps/libui/windows/drawmatrix.cpp diff --git a/deps/libui/win32/drawpath.cpp b/deps/libui/windows/drawpath.cpp similarity index 100% rename from deps/libui/win32/drawpath.cpp rename to deps/libui/windows/drawpath.cpp diff --git a/deps/libui/win32/drawtext.cpp b/deps/libui/windows/drawtext.cpp similarity index 100% rename from deps/libui/win32/drawtext.cpp rename to deps/libui/windows/drawtext.cpp diff --git a/deps/libui/win32/dwrite.cpp b/deps/libui/windows/dwrite.cpp similarity index 100% rename from deps/libui/win32/dwrite.cpp rename to deps/libui/windows/dwrite.cpp diff --git a/deps/libui/win32/editablecombo.cpp b/deps/libui/windows/editablecombo.cpp similarity index 100% rename from deps/libui/win32/editablecombo.cpp rename to deps/libui/windows/editablecombo.cpp diff --git a/deps/libui/win32/entry.cpp b/deps/libui/windows/entry.cpp similarity index 100% rename from deps/libui/win32/entry.cpp rename to deps/libui/windows/entry.cpp diff --git a/deps/libui/win32/events.cpp b/deps/libui/windows/events.cpp similarity index 100% rename from deps/libui/win32/events.cpp rename to deps/libui/windows/events.cpp diff --git a/deps/libui/win32/fontbutton.cpp b/deps/libui/windows/fontbutton.cpp similarity index 100% rename from deps/libui/win32/fontbutton.cpp rename to deps/libui/windows/fontbutton.cpp diff --git a/deps/libui/win32/fontdialog.cpp b/deps/libui/windows/fontdialog.cpp similarity index 100% rename from deps/libui/win32/fontdialog.cpp rename to deps/libui/windows/fontdialog.cpp diff --git a/deps/libui/win32/form.cpp b/deps/libui/windows/form.cpp similarity index 100% rename from deps/libui/win32/form.cpp rename to deps/libui/windows/form.cpp diff --git a/deps/libui/win32/graphemes.cpp b/deps/libui/windows/graphemes.cpp similarity index 100% rename from deps/libui/win32/graphemes.cpp rename to deps/libui/windows/graphemes.cpp diff --git a/deps/libui/win32/grid.cpp b/deps/libui/windows/grid.cpp similarity index 100% rename from deps/libui/win32/grid.cpp rename to deps/libui/windows/grid.cpp diff --git a/deps/libui/win32/group.cpp b/deps/libui/windows/group.cpp similarity index 100% rename from deps/libui/win32/group.cpp rename to deps/libui/windows/group.cpp diff --git a/deps/libui/win32/init.cpp b/deps/libui/windows/init.cpp similarity index 80% rename from deps/libui/win32/init.cpp rename to deps/libui/windows/init.cpp index a8a7ce05c0..228741653c 100644 --- a/deps/libui/win32/init.cpp +++ b/deps/libui/windows/init.cpp @@ -1,6 +1,5 @@ // 6 april 2015 #include "uipriv_windows.hpp" -#include "../../verbosity.h" HINSTANCE hInstance; int nCmdShow; @@ -75,107 +74,61 @@ const char *uiInit(uiInitOptions *o) hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION); if (hDefaultIcon == NULL) - { - RARCH_ERR("error loading default icon for window classes\n"); return ieLastErr("loading default icon for window classes"); - } hDefaultCursor = LoadCursorW(NULL, IDC_ARROW); if (hDefaultCursor == NULL) - { - RARCH_ERR("error loading default cursor for window classes\n"); return ieLastErr("loading default cursor for window classes"); - } - RARCH_LOG("Initializing initUtilWindow.\n"); ce = initUtilWindow(hDefaultIcon, hDefaultCursor); if (ce != NULL) - { - RARCH_ERR("Failed initializing util window.\n"); return initerr(ce, L"GetLastError() ==", GetLastError()); - } if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) - { - RARCH_ERR("failed registering uiWindow window class.\n"); return ieLastErr("registering uiWindow window class"); - } ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW)); ncm.cbSize = sizeof (NONCLIENTMETRICSW); if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) - { - RARCH_ERR("Error getting default fonts.\n"); return ieLastErr("getting default fonts"); - } hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont)); if (hMessageFont == NULL) - { - RARCH_ERR("loading default messagebox font; this is the default UI font\n"); return ieLastErr("loading default messagebox font; this is the default UI font"); - } if (initContainer(hDefaultIcon, hDefaultCursor) == 0) - { - RARCH_ERR("initializing uiWindowsMakeContainer() window class\n"); return ieLastErr("initializing uiWindowsMakeContainer() window class"); - } hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH); if (hollowBrush == NULL) - { - RARCH_ERR("getting hollow brush\n"); return ieLastErr("getting hollow brush"); - } ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); icc.dwSize = sizeof (INITCOMMONCONTROLSEX); icc.dwICC = wantedICCClasses; if (InitCommonControlsEx(&icc) == 0) - { - RARCH_ERR("initializing Common Controls\n"); return ieLastErr("initializing Common Controls"); - } hr = CoInitialize(NULL); if (hr != S_OK && hr != S_FALSE) - { - RARCH_ERR("initializing COM\n"); return ieHRESULT("initializing COM", hr); - } // LONGTERM initialize COM security // LONGTERM (windows vista) turn off COM exception handling hr = initDraw(); if (hr != S_OK) - { - RARCH_ERR("initializing Direct2D\n"); return ieHRESULT("initializing Direct2D", hr); - } hr = initDrawText(); if (hr != S_OK) - { - RARCH_ERR("initializing DirectWrite\n"); return ieHRESULT("initializing DirectWrite", hr); - } if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0) - { - RARCH_ERR("registering uiArea window class\n"); return ieLastErr("registering uiArea window class"); - } if (registerMessageFilter() == 0) - { - RARCH_ERR("registering libui message filter\n"); return ieLastErr("registering libui message filter"); - } if (registerD2DScratchClass(hDefaultIcon, hDefaultCursor) == 0) - { - RARCH_ERR("initializing D2D scratch window class\n"); return ieLastErr("initializing D2D scratch window class"); - } return NULL; } @@ -205,3 +158,10 @@ void uiFreeInitError(const char *err) if (*(err - 1) == '-') uiFree((void *) (err - 1)); } + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + if (fdwReason == DLL_PROCESS_ATTACH) + hInstance = hinstDLL; + return TRUE; +} diff --git a/deps/libui/win32/label.cpp b/deps/libui/windows/label.cpp similarity index 100% rename from deps/libui/win32/label.cpp rename to deps/libui/windows/label.cpp diff --git a/deps/libui/win32/libui.manifest b/deps/libui/windows/libui.manifest similarity index 100% rename from deps/libui/win32/libui.manifest rename to deps/libui/windows/libui.manifest diff --git a/deps/libui/win32/main.cpp b/deps/libui/windows/main.cpp similarity index 100% rename from deps/libui/win32/main.cpp rename to deps/libui/windows/main.cpp diff --git a/deps/libui/win32/menu.cpp b/deps/libui/windows/menu.cpp similarity index 100% rename from deps/libui/win32/menu.cpp rename to deps/libui/windows/menu.cpp diff --git a/deps/libui/win32/multilineentry.cpp b/deps/libui/windows/multilineentry.cpp similarity index 100% rename from deps/libui/win32/multilineentry.cpp rename to deps/libui/windows/multilineentry.cpp diff --git a/deps/libui/win32/notes b/deps/libui/windows/notes similarity index 100% rename from deps/libui/win32/notes rename to deps/libui/windows/notes diff --git a/deps/libui/win32/parent.cpp b/deps/libui/windows/parent.cpp similarity index 52% rename from deps/libui/win32/parent.cpp rename to deps/libui/windows/parent.cpp index 6de8cda341..bde6fb94e4 100644 --- a/deps/libui/win32/parent.cpp +++ b/deps/libui/windows/parent.cpp @@ -1,26 +1,26 @@ -/* 26 april 2015 */ +// 26 april 2015 #include "uipriv_windows.hpp" -/* This contains code used by all uiControls that contain other controls. - * It also contains the code to draw the background of a container.c container, as that is a variant of the WM_CTLCOLORxxx handler code. */ +// This contains code used by all uiControls that contain other controls. +// It also contains the code to draw the background of a container.c container, as that is a variant of the WM_CTLCOLORxxx handler code. static HBRUSH parentBrush = NULL; static HWND parentWithBackground(HWND hwnd) { - int cls; - HWND parent = hwnd; + HWND parent; + int cls; - for (;;) - { - parent = parentOf(parent); - /* skip groupboxes; they're (supposed to be) transparent - * skip uiContainers; they don't draw anything */ - cls = windowClassOf(parent, L"button", containerClass, NULL); - if (cls != 0 && cls != 1) - break; - } - return parent; + parent = hwnd; + for (;;) { + parent = parentOf(parent); + // skip groupboxes; they're (supposed to be) transparent + // skip uiContainers; they don't draw anything + cls = windowClassOf(parent, L"button", containerClass, NULL); + if (cls != 0 && cls != 1) + break; + } + return parent; } struct parentDraw { @@ -49,7 +49,7 @@ static HRESULT parentDraw(HDC dc, HWND parent, struct parentDraw *pd) static void endParentDraw(struct parentDraw *pd) { - /* continue in case of any error */ + // continue in case of any error if (pd->prevbitmap != NULL) if (((HBITMAP) SelectObject(pd->cdc, pd->prevbitmap)) != pd->bitmap) logLastError(L"error selecting previous bitmap back into compatible DC"); @@ -61,7 +61,7 @@ static void endParentDraw(struct parentDraw *pd) logLastError(L"error deleting compatible DC"); } -/* see http://www.codeproject.com/Articles/5978/Correctly-drawn-themed-dialogs-in-WinXP */ +// see http://www.codeproject.com/Articles/5978/Correctly-drawn-themed-dialogs-in-WinXP static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc) { HWND parent; @@ -83,11 +83,10 @@ static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc) } endParentDraw(&pd); - /* now figure out where the control is relative to the parent - * so we can align the brush properly - * if anything fails, give up and return the brush as-is */ + // now figure out where the control is relative to the parent so we can align the brush properly + // if anything fails, give up and return the brush as-is uiWindowsEnsureGetWindowRect(hwnd, &hwndScreenRect); - /* this will be in screen coordinates; convert to parent coordinates */ + // this will be in screen coordinates; convert to parent coordinates mapWindowRect(NULL, parent, &hwndScreenRect); if (SetBrushOrgEx(dc, -hwndScreenRect.left, -hwndScreenRect.top, NULL) == 0) logLastError(L"error setting brush origin"); @@ -97,18 +96,19 @@ static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc) void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect) { + HWND parent; RECT paintRectParent; struct parentDraw pd; - HWND parent = parentWithBackground(hwnd); - HRESULT hr = parentDraw(dc, parent, &pd); + HRESULT hr; - if (hr != S_OK) /* we couldn't get it; draw nothing */ + parent = parentWithBackground(hwnd); + hr = parentDraw(dc, parent, &pd); + if (hr != S_OK) // we couldn't get it; draw nothing return; paintRectParent = *paintRect; mapWindowRect(hwnd, parent, &paintRectParent); - if (BitBlt(dc, paintRect->left, paintRect->top, - paintRect->right - paintRect->left, paintRect->bottom - paintRect->top, + if (BitBlt(dc, paintRect->left, paintRect->top, paintRect->right - paintRect->left, paintRect->bottom - paintRect->top, pd.cdc, paintRectParent.left, paintRectParent.top, SRCCOPY) == 0) logLastError(L"error drawing parent background over uiContainer"); @@ -116,31 +116,29 @@ void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect) endParentDraw(&pd); } -/* TODO make this public if we want custom containers - * why have this to begin with? http://blogs.msdn.com/b/oldnewthing/archive/2010/03/16/9979112.aspx */ +// TODO make this public if we want custom containers +// why have this to begin with? http://blogs.msdn.com/b/oldnewthing/archive/2010/03/16/9979112.aspx BOOL handleParentMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) { - switch (uMsg) - { - case WM_COMMAND: - return runWM_COMMAND(wParam, lParam, lResult); - case WM_NOTIFY: - return runWM_NOTIFY(wParam, lParam, lResult); - case WM_HSCROLL: - return runWM_HSCROLL(wParam, lParam, lResult); - case WM_CTLCOLORSTATIC: - case WM_CTLCOLORBTN: - if (parentBrush != NULL) - if (DeleteObject(parentBrush) == 0) - logLastError(L"error deleting old background brush()"); /* but continue anyway; we will leak a brush but whatever */ - if (SetBkMode((HDC) wParam, TRANSPARENT) == 0) - logLastError(L"error setting transparent background mode to controls"); /* but continue anyway; text will be wrong */ - parentBrush = getControlBackgroundBrush((HWND) lParam, (HDC) wParam); - if (parentBrush == NULL) /* failed; just do default behavior */ - return FALSE; - *lResult = (LRESULT) parentBrush; - return TRUE; - } - - return FALSE; + switch (uMsg) { + case WM_COMMAND: + return runWM_COMMAND(wParam, lParam, lResult); + case WM_NOTIFY: + return runWM_NOTIFY(wParam, lParam, lResult); + case WM_HSCROLL: + return runWM_HSCROLL(wParam, lParam, lResult); + case WM_CTLCOLORSTATIC: + case WM_CTLCOLORBTN: + if (parentBrush != NULL) + if (DeleteObject(parentBrush) == 0) + logLastError(L"error deleting old background brush()"); // but continue anyway; we will leak a brush but whatever + if (SetBkMode((HDC) wParam, TRANSPARENT) == 0) + logLastError(L"error setting transparent background mode to controls"); // but continue anyway; text will be wrong + parentBrush = getControlBackgroundBrush((HWND) lParam, (HDC) wParam); + if (parentBrush == NULL) // failed; just do default behavior + return FALSE; + *lResult = (LRESULT) parentBrush; + return TRUE; + } + return FALSE; } diff --git a/deps/libui/win32/progressbar.cpp b/deps/libui/windows/progressbar.cpp similarity index 100% rename from deps/libui/win32/progressbar.cpp rename to deps/libui/windows/progressbar.cpp diff --git a/deps/libui/win32/radiobuttons.cpp b/deps/libui/windows/radiobuttons.cpp similarity index 100% rename from deps/libui/win32/radiobuttons.cpp rename to deps/libui/windows/radiobuttons.cpp diff --git a/deps/libui/win32/resources.hpp b/deps/libui/windows/resources.hpp similarity index 100% rename from deps/libui/win32/resources.hpp rename to deps/libui/windows/resources.hpp diff --git a/deps/libui/win32/resources.rc b/deps/libui/windows/resources.rc similarity index 100% rename from deps/libui/win32/resources.rc rename to deps/libui/windows/resources.rc diff --git a/deps/libui/win32/separator.cpp b/deps/libui/windows/separator.cpp similarity index 100% rename from deps/libui/win32/separator.cpp rename to deps/libui/windows/separator.cpp diff --git a/deps/libui/win32/sizing.cpp b/deps/libui/windows/sizing.cpp similarity index 100% rename from deps/libui/win32/sizing.cpp rename to deps/libui/windows/sizing.cpp diff --git a/deps/libui/win32/slider.cpp b/deps/libui/windows/slider.cpp similarity index 96% rename from deps/libui/win32/slider.cpp rename to deps/libui/windows/slider.cpp index b388ebc635..5c671dda09 100644 --- a/deps/libui/win32/slider.cpp +++ b/deps/libui/windows/slider.cpp @@ -1,10 +1,6 @@ // 20 may 2015 #include "uipriv_windows.hpp" -#ifndef TBS_TRANSPARENTBKGND -#define TBS_TRANSPARENTBKGND 0x1000 -#endif - struct uiSlider { uiWindowsControl c; HWND hwnd; diff --git a/deps/libui/win32/spinbox.cpp b/deps/libui/windows/spinbox.cpp similarity index 100% rename from deps/libui/win32/spinbox.cpp rename to deps/libui/windows/spinbox.cpp diff --git a/deps/libui/win32/stddialogs.cpp b/deps/libui/windows/stddialogs.cpp similarity index 69% rename from deps/libui/win32/stddialogs.cpp rename to deps/libui/windows/stddialogs.cpp index 07678542c0..89d26bacd7 100644 --- a/deps/libui/win32/stddialogs.cpp +++ b/deps/libui/windows/stddialogs.cpp @@ -1,26 +1,18 @@ -/* 22 may 2015 */ -#include +// 22 may 2015 #include "uipriv_windows.hpp" -#ifndef _MSC_VER -#include "winextra.h" -#endif -static dylib_t comctl_dll_handle = NULL; /* Handle to Comctl32 */ +// TODO document all this is what we want +// TODO do the same for font and color buttons -/* - * TODO document all this is what we want - * TODO do the same for font and color buttons +// notes: +// - FOS_SUPPORTSTREAMABLEITEMS doesn't seem to be supported on windows vista, or at least not with the flags we use +// - even with FOS_NOVALIDATE the dialogs will reject invalid filenames (at least on Vista, anyway) +// - lack of FOS_NOREADONLYRETURN doesn't seem to matter on Windows 7 - * notes: - * - FOS_SUPPORTSTREAMABLEITEMS doesn't seem to be supported on windows vista, or at least not with the flags we use - * - even with FOS_NOVALIDATE the dialogs will reject invalid filenames (at least on Vista, anyway) - * - lack of FOS_NOREADONLYRETURN doesn't seem to matter on Windows 7 - - * TODO - * - http://blogs.msdn.com/b/wpfsdk/archive/2006/10/26/uncommon-dialogs--font-chooser-and-color-picker-dialogs.aspx - * - when a dialog is active, tab navigation in other windows stops working - * - when adding uiOpenFolder(), use IFileDialog as well - https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx - */ +// TODO +// - http://blogs.msdn.com/b/wpfsdk/archive/2006/10/26/uncommon-dialogs--font-chooser-and-color-picker-dialogs.aspx +// - when a dialog is active, tab navigation in other windows stops working +// - when adding uiOpenFolder(), use IFileDialog as well - https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx #define windowHWND(w) ((HWND) uiControlHandle(uiControl(w))) @@ -109,28 +101,19 @@ char *uiSaveFile(uiWindow *parent) } // TODO switch to TaskDialogIndirect()? -typedef HRESULT (WINAPI *TaskDialogProc)(HWND hwndParent,HINSTANCE hInstance,PCWSTR pszWindowTitle,PCWSTR pszMainInstruction,PCWSTR pszContent,TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons,PCWSTR pszIcon,int *pnButton); -static TaskDialogProc task_dialog_proc; -static void msgbox(HWND parent, const char *title, const char *description, - TASKDIALOG_COMMON_BUTTON_FLAGS buttons, PCWSTR icon) +static void msgbox(HWND parent, const char *title, const char *description, TASKDIALOG_COMMON_BUTTON_FLAGS buttons, PCWSTR icon) { - HRESULT hr = E_FAIL; - WCHAR *wtitle = toUTF16(title); - WCHAR *wdescription = toUTF16(description); + WCHAR *wtitle, *wdescription; + HRESULT hr; - comctl_dll_handle = dylib_load("comctl32.lib"); - - task_dialog_proc = (TaskDialogProc)GetProcAddress((HINSTANCE)comctl_dll_handle, "TaskDialog"); - - if (task_dialog_proc) - hr = task_dialog_proc(parent, NULL, NULL, wtitle, wdescription, buttons, icon, NULL); + wtitle = toUTF16(title); + wdescription = toUTF16(description); + hr = TaskDialog(parent, NULL, NULL, wtitle, wdescription, buttons, icon, NULL); if (hr != S_OK) logHRESULT(L"error showing task dialog", hr); - dylib_close(comctl_dll_handle); - uiFree(wdescription); uiFree(wtitle); } diff --git a/deps/libui/win32/tab.cpp b/deps/libui/windows/tab.cpp similarity index 74% rename from deps/libui/win32/tab.cpp rename to deps/libui/windows/tab.cpp index 505b504926..365f5a1fa9 100644 --- a/deps/libui/win32/tab.cpp +++ b/deps/libui/windows/tab.cpp @@ -1,18 +1,18 @@ -/* 16 may 2015 */ +// 16 may 2015 #include "uipriv_windows.hpp" -/* You don't add controls directly to a tab control on Windows; instead you make them siblings and swap between them on a TCN_SELCHANGING/TCN_SELCHANGE notification pair. - * In addition, you use dialogs because they can be textured properly; other controls cannot. (Things will look wrong if the tab background in the current theme is fancy if you just use the tab background by itself; see http://stackoverflow.com/questions/30087540/why-are-my-programss-tab-controls-rendering-their-background-in-a-blocky-way-b.) */ +// You don't add controls directly to a tab control on Windows; instead you make them siblings and swap between them on a TCN_SELCHANGING/TCN_SELCHANGE notification pair. +// In addition, you use dialogs because they can be textured properly; other controls cannot. (Things will look wrong if the tab background in the current theme is fancy if you just use the tab background by itself; see http://stackoverflow.com/questions/30087540/why-are-my-programss-tab-controls-rendering-their-background-in-a-blocky-way-b.) struct uiTab { uiWindowsControl c; - HWND hwnd; /* of the outer container */ - HWND tabHWND; /* of the tab control itself */ + HWND hwnd; // of the outer container + HWND tabHWND; // of the tab control itself std::vector *pages; HWND parent; }; -/* utility functions */ +// utility functions static LRESULT curpage(uiTab *t) { @@ -26,14 +26,11 @@ static struct tabPage *tabPage(uiTab *t, int i) static void tabPageRect(uiTab *t, RECT *r) { - /* this rect needs to be in parent window coordinates, but TCM_ADJUSTRECT - * wants a window rect, which is screen coordinates - * because we have each page as a sibling of the tab, use the tab's - * own rect as the input rect */ + // this rect needs to be in parent window coordinates, but TCM_ADJUSTRECT wants a window rect, which is screen coordinates + // because we have each page as a sibling of the tab, use the tab's own rect as the input rect uiWindowsEnsureGetWindowRect(t->tabHWND, r); SendMessageW(t->tabHWND, TCM_ADJUSTRECT, (WPARAM) FALSE, (LPARAM) r); - - /* and get it in terms of the container instead of the screen */ + // and get it in terms of the container instead of the screen mapWindowRect(NULL, t->hwnd, r); } @@ -42,11 +39,11 @@ static void tabRelayout(uiTab *t) struct tabPage *page; RECT r; - /* first move the tab control itself */ + // first move the tab control itself uiWindowsEnsureGetClientRect(t->hwnd, &r); uiWindowsEnsureMoveWindowDuringResize(t->tabHWND, r.left, r.top, r.right - r.left, r.bottom - r.top); - /* then the current page */ + // then the current page if (t->pages->size() == 0) return; page = tabPage(t, curpage(t)); @@ -56,22 +53,21 @@ static void tabRelayout(uiTab *t) static void showHidePage(uiTab *t, LRESULT which, int hide) { - struct tabPage *page = NULL; + struct tabPage *page; if (which == (LRESULT) (-1)) return; page = tabPage(t, which); if (hide) ShowWindow(page->hwnd, SW_HIDE); - else - { - ShowWindow(page->hwnd, SW_SHOW); - /* we only resize the current page, so we have to resize it; before we can do that, we need to make sure we are of the right size */ - uiWindowsControlMinimumSizeChanged(uiWindowsControl(t)); - } + else { + ShowWindow(page->hwnd, SW_SHOW); + // we only resize the current page, so we have to resize it; before we can do that, we need to make sure we are of the right size + uiWindowsControlMinimumSizeChanged(uiWindowsControl(t)); + } } -/* control implementation */ +// control implementation static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nm, LRESULT *lResult) { @@ -133,23 +129,22 @@ uiWindowsControlDefaultSetParentHWND(uiTab) static void uiTabMinimumSize(uiWindowsControl *c, int *width, int *height) { + uiTab *t = uiTab(c); + int pagewid, pageht; + struct tabPage *page; RECT r; - struct tabPage *page = NULL; - uiTab *t = uiTab(c); - /* only consider the current page */ - int pagewid = 0; - int pageht = 0; - - if (t->pages->size() != 0) - { + // only consider the current page + pagewid = 0; + pageht = 0; + if (t->pages->size() != 0) { page = tabPage(t, curpage(t)); tabPageMinimumSize(page, &pagewid, &pageht); } - r.left = 0; - r.top = 0; - r.right = pagewid; + r.left = 0; + r.top = 0; + r.right = pagewid; r.bottom = pageht; // this also includes the tabs themselves SendMessageW(t->tabHWND, TCM_ADJUSTRECT, (WPARAM) TRUE, (LPARAM) (&r)); @@ -159,14 +154,13 @@ static void uiTabMinimumSize(uiWindowsControl *c, int *width, int *height) static void uiTabMinimumSizeChanged(uiWindowsControl *c) { - uiTab *t = uiTab(c); + uiTab *t = uiTab(c); - if (uiWindowsControlTooSmall(uiWindowsControl(t))) - { - uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(t)); - return; - } - tabRelayout(t); + if (uiWindowsControlTooSmall(uiWindowsControl(t))) { + uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(t)); + return; + } + tabRelayout(t); } uiWindowsControlDefaultLayoutRect(uiTab) @@ -174,16 +168,16 @@ uiWindowsControlDefaultAssignControlIDZOrder(uiTab) static void uiTabChildVisibilityChanged(uiWindowsControl *c) { - /* TODO eliminate the redundancy */ + // TODO eliminate the redundancy uiWindowsControlMinimumSizeChanged(c); } static void tabArrangePages(uiTab *t) { LONG_PTR controlID = 100; - HWND insertAfter = NULL; + HWND insertAfter = NULL; - /* TODO is this first or last? */ + // TODO is this first or last? uiWindowsEnsureAssignControlIDZOrder(t->tabHWND, &controlID, &insertAfter); for (struct tabPage *&page : *(t->pages)) uiWindowsEnsureAssignControlIDZOrder(page->hwnd, &controlID, &insertAfter); @@ -197,11 +191,12 @@ void uiTabAppend(uiTab *t, const char *name, uiControl *child) void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child) { struct tabPage *page; - LRESULT show; + LRESULT hide, show; TCITEMW item; WCHAR *wname; - /* see below */ - LRESULT hide = curpage(t); + + // see below + hide = curpage(t); if (child != NULL) uiControlSetParent(child, uiControl(t)); @@ -219,12 +214,9 @@ void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child) logLastError(L"error adding tab to uiTab"); uiFree(wname); - /* we need to do this because adding the first tab - * doesn't send a TCN_SELCHANGE; it just shows the page */ + // we need to do this because adding the first tab doesn't send a TCN_SELCHANGE; it just shows the page show = curpage(t); - - if (show != hide) - { + if (show != hide) { showHidePage(t, hide, 1); showHidePage(t, show, 0); } @@ -234,12 +226,12 @@ void uiTabDelete(uiTab *t, int n) { struct tabPage *page; - /* first delete the tab from the tab control - * if this is the current tab, no tab will be selected, which is good */ + // first delete the tab from the tab control + // if this is the current tab, no tab will be selected, which is good if (SendMessageW(t->tabHWND, TCM_DELETEITEM, (WPARAM) n, 0) == FALSE) logLastError(L"error deleting uiTab tab"); - /* now delete the page itself */ + // now delete the page itself page = tabPage(t, n); if (page->child != NULL) uiControlSetParent(page->child, NULL); @@ -259,13 +251,11 @@ int uiTabMargined(uiTab *t, int n) void uiTabSetMargined(uiTab *t, int n, int margined) { - struct tabPage *page = tabPage(t, n); + struct tabPage *page; + page = tabPage(t, n); page->margined = margined; - - /* even if the page doesn't have a child it might still - * have a new minimum size with margins; this is the - * easiest way to verify it */ + // even if the page doesn't have a child it might still have a new minimum size with margins; this is the easiest way to verify it uiWindowsControlMinimumSizeChanged(uiWindowsControl(t)); } diff --git a/deps/libui/win32/tabpage.cpp b/deps/libui/windows/tabpage.cpp similarity index 100% rename from deps/libui/win32/tabpage.cpp rename to deps/libui/windows/tabpage.cpp diff --git a/deps/libui/windows/text.cpp b/deps/libui/windows/text.cpp new file mode 100644 index 0000000000..af79fb8078 --- /dev/null +++ b/deps/libui/windows/text.cpp @@ -0,0 +1,107 @@ +// 9 april 2015 +#include "uipriv_windows.hpp" + +WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len) +{ + LRESULT n; + WCHAR *text; + + n = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); + if (len != NULL) + *len = n; + // WM_GETTEXTLENGTH does not include the null terminator + text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); + // note the comparison: the size includes the null terminator, but the return does not + if (GetWindowTextW(hwnd, text, n + 1) != n) { + logLastError(L"error getting window text"); + // on error, return an empty string to be safe + *text = L'\0'; + if (len != NULL) + *len = 0; + } + return text; +} + +WCHAR *windowText(HWND hwnd) +{ + return windowTextAndLen(hwnd, NULL); +} + +void setWindowText(HWND hwnd, WCHAR *wtext) +{ + if (SetWindowTextW(hwnd, wtext) == 0) + logLastError(L"error setting window text"); +} + +void uiFreeText(char *text) +{ + uiFree(text); +} + +int uiWindowsWindowTextWidth(HWND hwnd) +{ + LRESULT len; + WCHAR *text; + HDC dc; + HFONT prevfont; + SIZE size; + + size.cx = 0; + size.cy = 0; + + text = windowTextAndLen(hwnd, &len); + if (len == 0) // no text; nothing to do + goto noTextOrError; + + // now we can do the calculations + dc = GetDC(hwnd); + if (dc == NULL) { + logLastError(L"error getting DC"); + // on any error, assume no text + goto noTextOrError; + } + prevfont = (HFONT) SelectObject(dc, hMessageFont); + if (prevfont == NULL) { + logLastError(L"error loading control font into device context"); + ReleaseDC(hwnd, dc); + goto noTextOrError; + } + if (GetTextExtentPoint32W(dc, text, len, &size) == 0) { + logLastError(L"error getting text extent point"); + // continue anyway, assuming size is 0 + size.cx = 0; + size.cy = 0; + } + // continue on errors; we got what we want + if (SelectObject(dc, prevfont) != hMessageFont) + logLastError(L"error restoring previous font into device context"); + if (ReleaseDC(hwnd, dc) == 0) + logLastError(L"error releasing DC"); + + uiFree(text); + return size.cx; + +noTextOrError: + uiFree(text); + return 0; +} + +char *uiWindowsWindowText(HWND hwnd) +{ + WCHAR *wtext; + char *text; + + wtext = windowText(hwnd); + text = toUTF8(wtext); + uiFree(wtext); + return text; +} + +void uiWindowsSetWindowText(HWND hwnd, const char *text) +{ + WCHAR *wtext; + + wtext = toUTF16(text); + setWindowText(hwnd, wtext); + uiFree(wtext); +} diff --git a/deps/libui/win32/uipriv_windows.hpp b/deps/libui/windows/uipriv_windows.hpp similarity index 97% rename from deps/libui/win32/uipriv_windows.hpp rename to deps/libui/windows/uipriv_windows.hpp index 8235dd529f..6ffe09f1ad 100644 --- a/deps/libui/win32/uipriv_windows.hpp +++ b/deps/libui/windows/uipriv_windows.hpp @@ -1,4 +1,4 @@ -/* 21 april 2016 */ +// 21 april 2016 #include "winapi.hpp" #include "../ui.h" #include "../ui_windows.h" @@ -6,15 +6,15 @@ #include "resources.hpp" #include "compilerver.hpp" -/* ui internal window messages */ +// ui internal window messages enum { - /* redirected WM_COMMAND and WM_NOTIFY */ + // redirected WM_COMMAND and WM_NOTIFY msgCOMMAND = WM_APP + 0x40, // start offset just to be safe msgNOTIFY, msgHSCROLL, msgQueued, msgD2DScratchPaint, - msgD2DScratchLButtonDown + msgD2DScratchLButtonDown, }; // alloc.cpp diff --git a/deps/libui/win32/utf16.cpp b/deps/libui/windows/utf16.cpp similarity index 61% rename from deps/libui/win32/utf16.cpp rename to deps/libui/windows/utf16.cpp index 1ae7e13489..98954d0ada 100644 --- a/deps/libui/win32/utf16.cpp +++ b/deps/libui/windows/utf16.cpp @@ -1,7 +1,7 @@ -/* 21 april 2016 */ +// 21 april 2016 #include "uipriv_windows.hpp" -/* see http://stackoverflow.com/a/29556509/3408572 */ +// see http://stackoverflow.com/a/29556509/3408572 #define MBTWC(str, wstr, bufsiz) MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, bufsiz) @@ -18,10 +18,9 @@ WCHAR *toUTF16(const char *str) return emptyUTF16(); } wstr = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); - if (MBTWC(str, wstr, n) != n) - { + if (MBTWC(str, wstr, n) != n) { logLastError(L"error converting from UTF-8 to UTF-16"); - /* and return an empty string */ + // and return an empty string *wstr = L'\0'; } return wstr; @@ -34,7 +33,7 @@ char *toUTF8(const WCHAR *wstr) char *str; int n; - if (*wstr == L'\0') /* empty string */ + if (*wstr == L'\0') // empty string return emptyUTF8(); n = WCTMB(wstr, NULL, 0); if (n == 0) { @@ -42,20 +41,21 @@ char *toUTF8(const WCHAR *wstr) return emptyUTF8(); } str = (char *) uiAlloc(n * sizeof (char), "char[]"); - if (WCTMB(wstr, str, n) != n) - { - logLastError(L"error converting from UTF-16 to UTF-8"); - /* and return an empty string */ - *str = '\0'; - } + if (WCTMB(wstr, str, n) != n) { + logLastError(L"error converting from UTF-16 to UTF-8"); + // and return an empty string + *str = '\0'; + } return str; } WCHAR *utf16dup(const WCHAR *orig) { - size_t len = wcslen(orig); - WCHAR *out = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); + WCHAR *out; + size_t len; + len = wcslen(orig); + out = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); wcscpy_s(out, len + 1, orig); return out; } @@ -83,27 +83,27 @@ WCHAR *vstrf(const WCHAR *format, va_list ap) va_copy(ap2, ap); n = _vscwprintf(format, ap2); va_end(ap2); - n++; /* terminating L'\0' */ + n++; // terminating L'\0' buf = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); - /* includes terminating L'\0' according - * to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx */ + // includes terminating L'\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx vswprintf_s(buf, n, format, ap); return buf; } -/* Let's shove these utility routines here too. - * Prerequisite: lfonly is UTF-8. */ +// Let's shove these utility routines here too. +// Prerequisite: lfonly is UTF-8. char *LFtoCRLF(const char *lfonly) { - size_t i; - size_t len = strlen(lfonly); - char *crlf = (char *) uiAlloc((len * 2 + 1) * sizeof (char), "char[]"); - char *out = crlf; + char *crlf; + size_t i, len; + char *out; - for (i = 0; i < len; i++) - { + len = strlen(lfonly); + crlf = (char *) uiAlloc((len * 2 + 1) * sizeof (char), "char[]"); + out = crlf; + for (i = 0; i < len; i++) { if (*lfonly == '\n') *crlf++ = '\r'; *crlf++ = *lfonly++; @@ -112,43 +112,42 @@ char *LFtoCRLF(const char *lfonly) return out; } -/* Prerequisite: s is UTF-8. */ +// Prerequisite: s is UTF-8. void CRLFtoLF(char *s) { char *t = s; - for (; *s != '\0'; s++) - { - /* be sure to preserve \rs that are genuinely there */ + for (; *s != '\0'; s++) { + // be sure to preserve \rs that are genuinely there if (*s == '\r' && *(s + 1) == '\n') continue; *t++ = *s; } *t = '\0'; - /* pad out the rest of t, just to be safe */ + // pad out the rest of t, just to be safe while (t != s) *t++ = '\0'; } -/* std::to_string() always uses %f; we want %g - * fortunately std::iostream seems to use %g by default so */ +// std::to_string() always uses %f; we want %g +// fortunately std::iostream seems to use %g by default so WCHAR *ftoutf16(double d) { std::wostringstream ss; std::wstring s; ss << d; - s = ss.str(); /* to be safe */ + s = ss.str(); // to be safe return utf16dup(s.c_str()); } -/* to complement the above */ +// to complement the above WCHAR *itoutf16(int i) { std::wostringstream ss; std::wstring s; ss << i; - s = ss.str(); /* to be safe */ + s = ss.str(); // to be safe return utf16dup(s.c_str()); } diff --git a/deps/libui/windows/utilwin.cpp b/deps/libui/windows/utilwin.cpp new file mode 100644 index 0000000000..414ae83aba --- /dev/null +++ b/deps/libui/windows/utilwin.cpp @@ -0,0 +1,76 @@ +// 14 may 2015 +#include "uipriv_windows.hpp" + +// The utility window is a special window that performs certain tasks internal to libui. +// It is not a message-only window, and it is always hidden and disabled. +// Its roles: +// - It is the initial parent of all controls. When a control loses its parent, it also becomes that control's parent. +// - It handles WM_QUERYENDSESSION and console end session requests. +// - It handles WM_WININICHANGE and forwards the message to any child windows that request it. +// - It handles executing functions queued to run by uiQueueMain(). + +#define utilWindowClass L"libui_utilWindowClass" + +HWND utilWindow; + +static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + void (*qf)(void *); + LRESULT lResult; + + if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) + return lResult; + switch (uMsg) { + case WM_QUERYENDSESSION: + // TODO block handler + if (shouldQuit()) { + uiQuit(); + return TRUE; + } + return FALSE; + case WM_WININICHANGE: + issueWM_WININICHANGE(wParam, lParam); + return 0; + case msgQueued: + qf = (void (*)(void *)) wParam; + (*qf)((void *) lParam); + return 0; + } + return DefWindowProcW(hwnd, uMsg, wParam, lParam); +} + +const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor) +{ + WNDCLASSW wc; + + ZeroMemory(&wc, sizeof (WNDCLASSW)); + wc.lpszClassName = utilWindowClass; + wc.lpfnWndProc = utilWindowWndProc; + wc.hInstance = hInstance; + wc.hIcon = hDefaultIcon; + wc.hCursor = hDefaultCursor; + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + if (RegisterClass(&wc) == 0) + // see init.cpp for an explanation of the =s + return "=registering utility window class"; + + utilWindow = CreateWindowExW(0, + utilWindowClass, L"libui utility window", + WS_OVERLAPPEDWINDOW, + 0, 0, 100, 100, + NULL, NULL, hInstance, NULL); + if (utilWindow == NULL) + return "=creating utility window"; + // and just to be safe + EnableWindow(utilWindow, FALSE); + + return NULL; +} + +void uninitUtilWindow(void) +{ + if (DestroyWindow(utilWindow) == 0) + logLastError(L"error destroying utility window"); + if (UnregisterClass(utilWindowClass, hInstance) == 0) + logLastError(L"error unregistering utility window class"); +} diff --git a/deps/libui/win32/winapi.hpp b/deps/libui/windows/winapi.hpp similarity index 100% rename from deps/libui/win32/winapi.hpp rename to deps/libui/windows/winapi.hpp diff --git a/deps/libui/win32/window.cpp b/deps/libui/windows/window.cpp similarity index 100% rename from deps/libui/win32/window.cpp rename to deps/libui/windows/window.cpp diff --git a/deps/libui/win32/winpublic.cpp b/deps/libui/windows/winpublic.cpp similarity index 63% rename from deps/libui/win32/winpublic.cpp rename to deps/libui/windows/winpublic.cpp index 1ef77f18f5..397a3b54c9 100644 --- a/deps/libui/win32/winpublic.cpp +++ b/deps/libui/windows/winpublic.cpp @@ -1,4 +1,4 @@ -/* 6 april 2015 */ +// 6 april 2015 #include "uipriv_windows.hpp" void uiWindowsEnsureDestroyWindow(HWND hwnd) @@ -35,30 +35,27 @@ void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, int x, int y, int width, i logLastError(L"error moving window"); } -/* do these function even error out in any case - * other than invalid parameters?! I thought all windows had rects */ +// do these function even error out in any case other than invalid parameters?! I thought all windows had rects void uiWindowsEnsureGetClientRect(HWND hwnd, RECT *r) { - if (GetClientRect(hwnd, r) == 0) - { - logLastError(L"error getting window client rect"); - /* zero out the rect on error just to be safe */ - r->left = 0; - r->top = 0; - r->right = 0; - r->bottom = 0; - } + if (GetClientRect(hwnd, r) == 0) { + logLastError(L"error getting window client rect"); + // zero out the rect on error just to be safe + r->left = 0; + r->top = 0; + r->right = 0; + r->bottom = 0; + } } void uiWindowsEnsureGetWindowRect(HWND hwnd, RECT *r) { - if (GetWindowRect(hwnd, r) == 0) - { - logLastError(L"error getting window rect"); - /* zero out the rect on error just to be safe */ - r->left = 0; - r->top = 0; - r->right = 0; - r->bottom = 0; - } + if (GetWindowRect(hwnd, r) == 0) { + logLastError(L"error getting window rect"); + // zero out the rect on error just to be safe + r->left = 0; + r->top = 0; + r->right = 0; + r->bottom = 0; + } } diff --git a/deps/libui/win32/winutil.cpp b/deps/libui/windows/winutil.cpp similarity index 100% rename from deps/libui/win32/winutil.cpp rename to deps/libui/windows/winutil.cpp